Skip to content

Commit 660a255

Browse files
Usha GUsha G
authored andcommitted
MPAE-13690 Adding client firmware
1 parent 65db06e commit 660a255

40 files changed

+6330
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#include "mcc_generated_files/system/system.h"
2+
#include "mcc_generated_files/adc/adc.h"
3+
#include "string.h"
4+
#include "stdlib.h"
5+
#include "stdio.h"
6+
#include "application.h"
7+
8+
/*******************************************************************************
9+
* void Application(void)
10+
*
11+
* API which measures the connected ph sensor data through ADC interface periodically.
12+
* By default Slave will be in the sleep mode and it wakes up after every 5sec using
13+
* Timer interrupt or whenever I2C start condition is detected.
14+
*
15+
* @param void
16+
* @return void
17+
******************************************************************************/
18+
void Application(void)
19+
{
20+
//To read the sensor data periodically for every 5 sec
21+
if(timerInterruptFlag == SET)
22+
{
23+
#ifdef DEBUG
24+
EUSART1_SendString("Timer WakeUP\n"); // only for debug
25+
#endif
26+
Sensor1_DataProcessing();
27+
timerInterruptFlag = 0;
28+
}
29+
else if(SSP1STATbits.I2C_START)
30+
{
31+
#ifdef DEBUG
32+
EUSART1_SendString(" I2C WakeUP\n"); //only for debug
33+
#endif
34+
if(i2cRdDataIndex >= 2)
35+
{
36+
CLOCK_STRETCH_ENABLE();
37+
i2cRxDataLength = i2cRdData[ONE];
38+
i2cRxSensorRegisterAddress = i2cRdData[ZERO];
39+
SensorDataRegisterRead(i2cRxSensorRegisterAddress,i2cRxDataLength);
40+
CLOCK_STRETCH_DISABLE();
41+
DELAY_FUNCTION();
42+
i2cRdDataIndex = 0;
43+
}
44+
}
45+
else
46+
{
47+
SLEEP();
48+
}
49+
}
50+
51+
/*******************************************************************************
52+
* void EUSART1_SendString(const char *str)
53+
*
54+
* API to print a sequence of characters on the terminal window
55+
*
56+
* @param *str - to send a sequence of strings on terminal window
57+
* @return void
58+
******************************************************************************/
59+
void EUSART1_SendString(const char *str)
60+
{
61+
for(uint8_t index = 0; index < strlen(str); index++)
62+
{
63+
EUSART1_Write(str[index]);
64+
}
65+
}
66+
67+
/*******************************************************************************
68+
* void Sensor1_DataProcessing(void)
69+
*
70+
* API to measure the ph sensor through ADC interface and calculate the ph value
71+
* using the formula. Store the ph value in static RAM location.
72+
*
73+
* @param void
74+
* @return void
75+
******************************************************************************/
76+
void Sensor1_DataProcessing(void)
77+
{
78+
uint16_t adcBuffer = 0;
79+
uint16_t adcSamples = 0;
80+
uint16_t samplesAverage = 0;
81+
float dataBuffer = 0;
82+
uint8_t samplesCount;
83+
84+
for (samplesCount = 0; samplesCount < ADC_SAMPLES; samplesCount++)
85+
{
86+
adcBuffer = ADC_GetConversion(channel_ANC4);
87+
adcSamples += adcBuffer;
88+
}
89+
90+
if(samplesCount >= ADC_SAMPLES)
91+
{
92+
samplesAverage = (adcSamples >> RIGHTSHIFT_COUNT);
93+
dataBuffer = (samplesAverage * VDD)/ ADC_MAX_VALUE;
94+
phValue = (uint8_t)(CONSTANT * dataBuffer);
95+
sensor_Data_Register[0] = phValue;
96+
adcSamples = 0;
97+
samplesCount = 0;
98+
adcBuffer = 0;
99+
}
100+
}
101+
102+
/*******************************************************************************
103+
* void SensorDataRegisterAddrMatch(uint8_t *sensorDataAddress)
104+
*
105+
* API which reads the data stored in static RAM location into an i2cWrData buffer
106+
* which is transmitted to the host through i2c interface
107+
*
108+
* @param *sensorDataAddress - holds the sensor data register address sent from the
109+
* host device
110+
* @return void
111+
******************************************************************************/
112+
void SensorDataRegisterRead(uint8_t *sensorRevdData, uint8_t dataLength)
113+
{
114+
uint8_t index = 0;
115+
116+
//Clears the i2cWrData array
117+
memset((uint8_t*)i2cWrData, 0 , sizeof(i2cWrData));
118+
119+
for(index = 0;index < dataLength;index++)
120+
{
121+
i2cWrData[index] = *(sensorRevdData+index);
122+
}
123+
}
124+
125+
/*******************************************************************************
126+
* bool I2C_ClientInterruptHandler(i2c_client_transfer_event_t event)
127+
*
128+
* API to handle I2C Read and Write Interrupt handler
129+
*
130+
* @param void
131+
* @return void
132+
******************************************************************************/
133+
bool I2C_ClientInterruptHandler(i2c_client_transfer_event_t event)
134+
{
135+
switch (event)
136+
{
137+
case I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH:
138+
139+
if (I2C1_TransferDirGet() == I2C_CLIENT_TRANSFER_DIR_WRITE)
140+
{
141+
if (I2C1_ReadAddr() == CLIENT_7_BIT_ADDR)
142+
{
143+
currentClient = CLIENT_7_BIT_ADDR;
144+
145+
}
146+
}
147+
break;
148+
149+
case I2C_CLIENT_TRANSFER_EVENT_RX_READY:
150+
if(i2cRdDataIndex >= LENGTH)
151+
{
152+
i2cRdDataIndex = 0;
153+
}
154+
else
155+
{
156+
i2cRdData[i2cRdDataIndex++] = I2C1_ReadByte();
157+
}
158+
break;
159+
case I2C_CLIENT_TRANSFER_EVENT_TX_READY:
160+
if(i2cWrDataIndex >= ONE_BYTELENGTH)
161+
{
162+
i2cWrDataIndex = 0;
163+
}
164+
else
165+
{
166+
I2C1_WriteByte(i2cWrData[i2cWrDataIndex++]);
167+
}
168+
169+
break;
170+
171+
case I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED:
172+
i2cRdDataIndex = 0x00;
173+
break;
174+
175+
default:
176+
break;
177+
}
178+
return true;
179+
}
180+
181+
/*******************************************************************************
182+
* void TimerInterruptHandler(void)
183+
*
184+
* API to handle Timer interrupt, which generates interrupt for every 5 sec.
185+
*
186+
* @param void
187+
* @return void
188+
******************************************************************************/
189+
void TimerInterruptHandler(void)
190+
{
191+
timerInterruptFlag= 1;
192+
}
193+
194+
/**
195+
End of File
196+
*/

0 commit comments

Comments
 (0)