Skip to content

Commit 88867ed

Browse files
Usha GUsha G
authored andcommitted
MPAE-13691 Adding client 2 firmware
1 parent 900c0f8 commit 88867ed

30 files changed

+4140
-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: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#include "mcc_generated_files/system/system.h"
2+
#include "mcc_generated_files/adc/adc.h"
3+
#include "application.h"
4+
#include "string.h"
5+
#include "stdlib.h"
6+
#include "stdio.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+
Sensor2_DataProcessing(); //Read Analog Sensor 2 and calibration
27+
Sensor3_DataProcessing(); //Read Analog Sensor 3 and calibration
28+
timerInterruptFlag = CLEAR;
29+
}
30+
else if(SSP1STATbits.I2C_START)
31+
{
32+
#ifdef DEBUG
33+
EUSART1_SendString(" I2C WakeUP\n"); //only for debug
34+
#endif
35+
if(i2cRdDataIndex >= LENGTH)
36+
{
37+
CLOCK_STRETCH_ENABLE();
38+
i2cRxDataLength = i2cRdData[ONE];
39+
i2cRxSensorRegisterAddress = i2cRdData[ZERO];
40+
SensorDataRegisterRead(i2cRxSensorRegisterAddress,i2cRxDataLength);
41+
i2cWrDataIndex = 0;
42+
CLOCK_STRETCH_DISABLE();
43+
i2cRdDataIndex = ZERO;
44+
DELAY_FUNCTION();
45+
}
46+
}
47+
else
48+
{
49+
// SLEEP();
50+
}
51+
52+
}
53+
54+
/*******************************************************************************
55+
* void EUSART1_SendString(const char *str)
56+
*
57+
* API to print a sequence of characters on the terminal window
58+
*
59+
* @param *str - to send a sequence of strings on terminal window
60+
* @return void
61+
******************************************************************************/
62+
void EUSART1_SendString(const char *str)
63+
{
64+
for(uint8_t index = 0; index < strlen(str); index++)
65+
{
66+
EUSART1_Write(str[index]);
67+
}
68+
}
69+
70+
/*******************************************************************************
71+
* void SensorDataRegisterAddrMatch(uint8_t *sensorDataAddress)
72+
*
73+
* API which reads the data stored in static RAM location into an i2cWrData buffer
74+
* which is transmitted to the host through i2c interface
75+
*
76+
* @param *sensorDataAddress - holds the sensor data register address sent from the
77+
* host device
78+
* @return void
79+
******************************************************************************/
80+
void SensorDataRegisterRead(uint8_t *sensorRevdData, uint8_t dataLength)
81+
{
82+
uint8_t index = 0;
83+
84+
//Clears the i2cWrData array
85+
memset((uint8_t*)i2cWrData, 0 , sizeof(i2cWrData));
86+
87+
for( index = 0;index < dataLength;index++)
88+
{
89+
i2cWrData[index] = *(sensorRevdData+index);
90+
}
91+
}
92+
93+
/*******************************************************************************
94+
* void Sensor2_DataProcessing(void)
95+
*
96+
* API to measure the temperature sensor through ADC interface and calculate
97+
* the temperature value using the formula. Store the temperature value in static RAM
98+
* location.
99+
*
100+
* @param void
101+
* @return void
102+
******************************************************************************/
103+
void Sensor2_DataProcessing(void)
104+
{
105+
uint16_t adcBuffer = 0;
106+
float dataBuffer = 0;
107+
float buffer = 0;
108+
109+
adcBuffer = ADC_GetConversion(channel_ANB7);
110+
dataBuffer = (((float)adcBuffer/ADC_MAX_VALUE )* VDD);
111+
buffer = ((dataBuffer / VDD) * TEMP_CONSTANT);
112+
temp_Value = (uint8_t)(TEMP_CONSTANT1 + buffer);
113+
sensor_Data_Register[ZERO]= temp_Value;
114+
}
115+
116+
/*******************************************************************************
117+
* void Sensor3_DataProcessing(void)
118+
*
119+
* API to measure the Soil moisture sensor data through ADC interface and calculate
120+
* the soil moisture value using the formula. Store the soil moisture value in
121+
* static RAM location.
122+
*
123+
* @param void
124+
* @return void
125+
******************************************************************************/
126+
void Sensor3_DataProcessing(void)
127+
{
128+
uint16_t adcBuffer = 0;
129+
float dataBuffer = 0;
130+
float buffer = 0;
131+
132+
adcBuffer = ADC_GetConversion(channel_ANC4);
133+
dataBuffer = ADC_MAX_VALUE - adcBuffer;
134+
buffer = (dataBuffer / (ADC_MAX_VALUE-1));
135+
soilSensor_Value = (uint8_t)(buffer * 100);
136+
sensor_Data_Register[ONE] = soilSensor_Value;
137+
}
138+
139+
/*******************************************************************************
140+
* void TimerInterruptHandler(void)
141+
*
142+
* API to handle Timer interrupt, which generates interrupt for every 5 sec.
143+
*
144+
* @param void
145+
* @return void
146+
******************************************************************************/
147+
void TimerInterruptHandler(void)
148+
{
149+
timerInterruptFlag = SET;
150+
}
151+
152+
/*******************************************************************************
153+
* bool I2C_ClientInterruptHandler(i2c_client_transfer_event_t event)
154+
*
155+
* API to handle I2C Read and Write Interrupt handler
156+
*
157+
* @param void
158+
* @return void
159+
******************************************************************************/
160+
bool I2C_ClientInterruptHandler(i2c_client_transfer_event_t event)
161+
{
162+
163+
switch (event)
164+
{
165+
case I2C_CLIENT_TRANSFER_EVENT_ADDR_MATCH:
166+
167+
if (I2C1_TransferDirGet() == I2C_CLIENT_TRANSFER_DIR_WRITE)
168+
{
169+
if (I2C1_ReadAddr() == CLIENT2_7_BIT_ADDR)
170+
{
171+
currentClient = CLIENT2_7_BIT_ADDR;
172+
}
173+
}
174+
break;
175+
176+
case I2C_CLIENT_TRANSFER_EVENT_RX_READY:
177+
if(currentClient == CLIENT2_7_BIT_ADDR)
178+
{
179+
180+
{
181+
i2cRdData[i2cRdDataIndex++] = I2C1_ReadByte();
182+
}
183+
}
184+
break;
185+
case I2C_CLIENT_TRANSFER_EVENT_TX_READY:
186+
if(currentClient == CLIENT2_7_BIT_ADDR)
187+
{
188+
for( uint8_t index = 0;index < i2cRxDataLength;index++)
189+
{
190+
I2C1_WriteByte(i2cWrData[index]);
191+
}
192+
i2cRxDataLength = 0;
193+
}
194+
break;
195+
196+
case I2C_CLIENT_TRANSFER_EVENT_STOP_BIT_RECEIVED:
197+
// i2cRdDataIndex = 0x00;
198+
break;
199+
200+
default:
201+
break;
202+
}
203+
return true;
204+
}
205+
206+
/**
207+
End of File
208+
*/

0 commit comments

Comments
 (0)