18#include "stm32l4xx_hal_i2c.h"
20#define I2C_APP_STACK_SIZE (1024)
21#define I2C_TX_TIME (pdMS_TO_TICKS(60000))
22#define I2C_TX_SIZE (10)
23#define RESP_BUF_LEN 10
24#define SI_SENSOR_BUF_LEN 50
69 mz_puts(
"SENSOR Initialization...\r\n");
130 uint8_t I2CLocBuf[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
155 uint8_t I2CLocBuf[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
177 mz_puts(
"Initialization of SENSOR FAILED\r\n");
199 pre_resp = pre_resp & 0x1F;
203 }
while((reg_val & 0x20) != 0x20);
214 if((reg_val & 0x1F) != pre_resp){
223 if(reg_val & 0x10 != 0){
252 mz_puts(
"UV Sensor configuration started\r\n");
256 mz_puts(
"SENSOR_PARAM_CH_LIST CONFIG FAILED\r\n");
262 mz_puts(
"SENSOR_PARAM_ADCCONFIG0 CONFIG FAILED\r\n");
268 mz_puts(
"SENSOR_PARAM_ADCSENS0 CONFIG FAILED\r\n");
274 mz_puts(
"SENSOR_PARAM_ADCPOST0 CONFIG FAILED\r\n");
280 mz_puts(
"SENSOR_PARAM_ADCCONFIG1 CONFIG FAILED\r\n");
286 mz_puts(
"SENSOR_PARAM_ADCSENS1 CONFIG FAILED\r\n");
292 mz_puts(
"SENSOR_PARAM_ADCPOST1 CONFIG FAILED\r\n");
298 mz_puts(
"SENSOR_PARAM_ADCCONFIG2 CONFIG FAILED\r\n");
304 mz_puts(
"SENSOR_PARAM_ADCSENS2 CONFIG FAILED\r\n");
310 mz_puts(
"SENSOR_PARAM_ADCPOST2 CONFIG FAILED\r\n");
316 mz_puts(
"SENSOR_PARAM_ADCCONFIG3 CONFIG FAILED\r\n");
322 mz_puts(
"SENSOR_PARAM_ADCSENS3 CONFIG FAILED\r\n");
328 mz_puts(
"SENSOR_PARAM_ADCPOST3 CONFIG FAILED\r\n");
331 mz_puts(
"UV Sensor configuration done\r\n");
344 for(
int i=0;i<2;i++){
364 mz_puts(
"WRONG CHIP ID FOR SENSOR. SKIPPING CONFIGURATION\r\n");
381 uint8_t I2CLocBuf[4] = { 0x00, 0x00, 0x00, 0x00 };
402 uint32_t uv_index_val;
405 uint8_t ch1_msb,ch1_lsb,ch1_middle_byte;
407 mz_puts(
"UV Sensor single-shot measurement\r\n");
430 if(uvi<10 && uvi>=0){
434 }
else if(uvi<100 && uvi>10){
439 mz_puts(
"UV Sensor data got\r\n");
473 value = ( ( input << fraction ) / mag ) >> -shift;
476 value = ( ( input << fraction ) / mag ) << shift;
494 uint8_t info, x_order, y_order, counter;
497 int32_t output = 0, x1, x2, y1, y2;
498 for( counter = 0; counter < num_coeff; counter++ ) {
502 shift = ( (uint16_t) kp->
info & 0xff00 ) >> 8;
512 if( ( x_order == 0 ) && ( y_order == 0 ) ) {
513 output += sign * mag << output_fraction;
543 output += sign * x1 * x2 * y1 * y2;
583 while(srcstr[i]!=
'\0' && srcstr[i]!=
'\r'){
600 while(srcstr[i]!=
'\0' && srcstr[i]!=
'\r'){
603 while(apstr[j]!=
'\0' && apstr[j]!=
'\r'){
620 while(
buf[i]!=
'\r' &&
buf[i]!=
'\0'){
643 destbuf[j] = val + 48;
645 destbuf[j] = val + 55;
652 destbuf[j] = val + 48;
654 destbuf[j] = val + 55;
#define UV_INPUT_FRACTION
#define UV_OUTPUT_FRACTION
unsigned char mzUint8
1 Byte data type
unsigned long int mzUint32
4 Byte data type
mz_error_t
Enumeration of monoZ Error Flags.
mz_error_t I2C1_init(void)
This file contains all the functionalities for I2C protocol.
static mzUint8 localBuf1[SI_SENSOR_BUF_LEN]
mz_error_t I2C_Read_Reg(uint8_t addr, uint32_t *buf)
Function to read from the specific register.
void int8buf_to_asciibuf(uint8_t *destbuf, uint8_t *srcbuf, uint16_t len)
Function to Conversion of Int to ascii data.
static mz_thread_t i2c_thread_id
uint16_t string_copy(uint8_t *dststr, uint8_t *srcstr)
Function to Copy the data from source to destination.
int32_t SENSOR_calcEvalPoly(int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, SENSOR_Coeff_TypeDef *kp)
Function to Conversion of Raw Data.
SISER_RCVD SI_Read_UV()
Function to read the data from SENSOR.
static mz_semaphore_t i2c_sema_id
#define SI_SENSOR_BUF_LEN
uint16_t Get_String_len(uint8_t *buf)
Function to get string length.
static mzUint8 loc_buf[RESP_BUF_LEN]
mz_error_t Sensor_cmd_data_conf(uint8_t addr, uint8_t data)
Function to write data for Sensor Configuration.
static StackType_t i2c_stack[I2C_APP_STACK_SIZE]
void reset_resp_counter()
Reset register.
mz_error_t param_table_write(uint8_t addr, uint8_t data)
Function to read from the specific register.
int32_t SENSOR_calcPolyInner(int32_t input, int8_t fraction, uint16_t mag, int8_t shift)
Function to Conversion of Raw Data.
uint8_t string_append(uint8_t *srcstr, uint8_t *apstr)
Function to append the string.
mz_error_t I2C_Write_Reg(uint8_t addr, uint8_t data)
Function to write into the specific register.
static mzUint8 send_data[I2C_TX_SIZE]
static mzUint8 write_sucess
mz_error_t Sensor_ReadID(uint8_t *buf)
Function to read the content from ID register of SENSOR.
static void timer_cb(TimerHandle_t xTimer)
Timer callback function for transmission of the data.
static StaticTask_t i2c_cb_mem
static mzUint8 i2cLocBuf[SI_SENSOR_BUF_LEN]
void calib_uv_index(float uv_raw_data)
Function to calibrate the raw data.
mz_error_t i2c_app_init(void)
#define I2C_APP_STACK_SIZE
void SENSOR_Init()
Function Sensor Initialisation.
int32_t SENSOR_getUv(int32_t uv, SENSOR_Coeff_TypeDef *uk)
Function to Conversion of Raw Data.
static void i2c_app(void *arg)
create the timer and starts if main RTOS scheduler started
static mzUint8 resp_buf[RESP_BUF_LEN]
mz_error_t SENSOR_Config()
Function to config the sensor.
static mzUint8 locstr1[50]
#define SENSOR_REG_HOSTOUT1
#define SENSOR_PARAM_ADCCONFIG1
#define SENSOR_PARAM_ADCSENS1
#define SENSOR_PARAM_ADCSENS2
#define SENSOR_PARAM_ADCCONFIG2
@ SISER_INVALID_RESP_RCVD
PAYLOAD_ST SENSOR_payload
static SENSOR_Coeff_TypeDef uk[2]
#define SENSOR_PARAM_ADCPOST2
#define SENSOR_REG_RESPONSE0
#define SENSOR_PARAM_CH_LIST
#define SENSOR_PARAM_ADCCONFIG0
#define SENSOR_PARAM_ADCSENS0
#define SENSOR_REG_HOSTOUT2
#define SENSOR_REG_HOSTOUT0
#define SENSOR_PARAM_ADCPOST0
#define SENSOR_PARAM_ADCPOST1
#define SENSOR_PARAM_ADCPOST3
#define SENSOR_REG_COMMAND
#define SENSOR_REG_HOSTIN0
#define SENSOR_PARAM_ADCSENS3
#define SENSOR_PARAM_ADCCONFIG3
#define SENSOR_REG_RESPONSE1
#define SI_ID_REG_PART_ID
monoZ system CMSIS OS2 This is an abstraction layer and includes FreeRTOS configuration,...
osSemaphoreId_t mz_semaphore_t
mz_semaphore_t variable of type osSemaphoreId_t
osThreadId_t mz_thread_t
mz_thread_t variable of type osThreadId_t
This file contains APIs for create,delete,start and stop of timers. Maximum 5 timers can be created....
mz_error_t MZ_I2C_Master_Receive(uint8_t i2c_no, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
This function is used to receive data using I2C in interrupt mode.
mz_error_t MZ_I2C_Master_Transmit_IT(uint8_t i2c_no, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
This function is used to transmit data using I2C in polling mode.
mz_error_t MZ_I2C_Master_Transmit(uint8_t i2c_no, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
This function is used to transmit data using I2C in interrupt mode.
int mz_puts(void *__ch)
This function prints the given string.
uint8_t mz_sem_create(mz_semaphore_t *c, uint8_t cnt, uint8_t init)
This function is used to create and initialize the semaphore object Create and Initialize a Semaphore...
uint8_t mz_thread_create(mz_thread_t *t, const char *name, mz_fn thread_func, void *const arg, mz_thread_prio_t prio, StackType_t *stack_mem, size_t stack_size, StaticTask_t *cb_mem, uint32_t cb_size)
This function is used to check the message queue object validity Create a thread and add it to Active...
mz_error_t mz_tm_create_start_recursive(char *_name, TickType_t _tick, mz_tm_cb _cb)
Function to Create and Start One Shot Timers.