monoZ docs
MZ_i2c_example.c File Reference

This is an example application for i2c. User can use this app for i2c protocol specific requirements. More...

#include "MZ_sys_cmsis_os2.h"
#include "MZ_i2c_example.h"
#include "MZ_timer.h"
#include "MZ_print.h"
#include "MZ_i2c1_instance.h"
#include "MZ_error_handler.h"
#include "MZ_i2c.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "stm32l4xx_hal_i2c.h"

Go to the source code of this file.

Macros

#define I2C_APP_STACK_SIZE   (1024)
 
#define I2C_TX_TIME   (pdMS_TO_TICKS(60000))
 
#define I2C_TX_SIZE   (10)
 
#define RESP_BUF_LEN   10
 
#define SI_SENSOR_BUF_LEN   50
 

Functions

static void timer_cb (TimerHandle_t xTimer)
 Timer callback function for transmission of the data. More...
 
static void i2c_app (void *arg)
 create the timer and starts if main RTOS scheduler started More...
 
mz_error_t i2c_app_init (void)
 
mz_error_t I2C_Write_Reg (uint8_t addr, uint8_t data)
 Function to write into the specific register. More...
 
mz_error_t I2C_Read_Reg (uint8_t addr, uint32_t *buf)
 Function to read from the specific register. More...
 
void reset_resp_counter ()
 Reset register. More...
 
mz_error_t param_table_write (uint8_t addr, uint8_t data)
 Function to read from the specific register. More...
 
mz_error_t SENSOR_Config ()
 Function to config the sensor. More...
 
mz_error_t Sensor_cmd_data_conf (uint8_t addr, uint8_t data)
 Function to write data for Sensor Configuration. More...
 
void SENSOR_Init ()
 Function Sensor Initialisation. More...
 
mz_error_t Sensor_ReadID (uint8_t *buf)
 Function to read the content from ID register of SENSOR. More...
 
SISER_RCVD SI_Read_UV ()
 Function to read the data from SENSOR. More...
 
int32_t SENSOR_getUv (int32_t uv, SENSOR_Coeff_TypeDef *uk)
 Function to Conversion of Raw Data. More...
 
int32_t SENSOR_calcPolyInner (int32_t input, int8_t fraction, uint16_t mag, int8_t shift)
 Function to Conversion of Raw Data. More...
 
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. More...
 
void calib_uv_index (float uv_raw_data)
 Function to calibrate the raw data. More...
 
uint16_t string_copy (uint8_t *dststr, uint8_t *srcstr)
 Function to Copy the data from source to destination. More...
 
uint8_t string_append (uint8_t *srcstr, uint8_t *apstr)
 Function to append the string. More...
 
uint16_t Get_String_len (uint8_t *buf)
 Function to get string length. More...
 
void int8buf_to_asciibuf (uint8_t *destbuf, uint8_t *srcbuf, uint16_t len)
 Function to Conversion of Int to ascii data. More...
 

Variables

static mz_thread_t i2c_thread_id = NULL
 
static StaticTask_t i2c_cb_mem
 
static StackType_t i2c_stack [I2C_APP_STACK_SIZE]
 
static mz_semaphore_t i2c_sema_id = NULL
 
static mzUint8 loc_buf [RESP_BUF_LEN]
 
static mzUint8 resp_buf [RESP_BUF_LEN]
 
static mzUint8 err_code
 
static mzUint8 write_sucess
 
static mzUint8 localBuf1 [SI_SENSOR_BUF_LEN]
 
static mzUint8 i2cLocBuf [SI_SENSOR_BUF_LEN]
 
static mzUint8 locstr1 [50]
 
static mzUint8 send_data [I2C_TX_SIZE]
 
mzUint8 buf [10]
 
mzUint32 uv_val
 
mzUint32 als_val1
 
mzUint32 als_val2
 
mzUint32 als_val3
 
SISER_RCVD SI_resp_rcvd = SISER_NONE_RCVD
 
mzUint8 cnt =0
 

Detailed Description

This is an example application for i2c. User can use this app for i2c protocol specific requirements.

Date
Jul 14, 2021
Author
Mahendra & Kafeel

Definition in file MZ_i2c_example.c.

Macro Definition Documentation

◆ I2C_APP_STACK_SIZE

#define I2C_APP_STACK_SIZE   (1024)

Definition at line 20 of file MZ_i2c_example.c.

◆ I2C_TX_TIME

#define I2C_TX_TIME   (pdMS_TO_TICKS(60000))

Definition at line 21 of file MZ_i2c_example.c.

◆ I2C_TX_SIZE

#define I2C_TX_SIZE   (10)

Definition at line 22 of file MZ_i2c_example.c.

◆ RESP_BUF_LEN

#define RESP_BUF_LEN   10

Definition at line 23 of file MZ_i2c_example.c.

◆ SI_SENSOR_BUF_LEN

#define SI_SENSOR_BUF_LEN   50

Definition at line 24 of file MZ_i2c_example.c.

Function Documentation

◆ timer_cb()

void timer_cb ( TimerHandle_t  xTimer)
static

Timer callback function for transmission of the data.

Note
This function will notifies the user when timer expires

Definition at line 48 of file MZ_i2c_example.c.

◆ i2c_app()

void i2c_app ( void *  arg)
static

create the timer and starts if main RTOS scheduler started

Parameters
argvoid
Note
User can write the code for process the read data from I2C

Definition at line 60 of file MZ_i2c_example.c.

◆ i2c_app_init()

mz_error_t i2c_app_init ( void  )

Definition at line 88 of file MZ_i2c_example.c.

◆ I2C_Write_Reg()

mz_error_t I2C_Write_Reg ( uint8_t  addr,
uint8_t  data 
)

Function to write into the specific register.

Parameters
addr- address of the register
data- data to be write
Return values
MZ_OKor MZ_FAIL

Definition at line 125 of file MZ_i2c_example.c.

◆ I2C_Read_Reg()

mz_error_t I2C_Read_Reg ( uint8_t  addr,
uint32_t *  buf 
)

Function to read from the specific register.

Parameters
addr- address of the register
buf- buffer which receives data from the register
Return values
MZ_OKor MZ_FAIL

Definition at line 148 of file MZ_i2c_example.c.

◆ reset_resp_counter()

void reset_resp_counter ( void  )

Reset register.

Parameters
None
Return values
None

Definition at line 174 of file MZ_i2c_example.c.

◆ param_table_write()

mz_error_t param_table_write ( uint8_t  addr,
uint8_t  data 
)

Function to read from the specific register.

Parameters
addr- address of the register
data- buffer which receives data from the register
Return values
MZ_OKor MZ_FAIL

Definition at line 188 of file MZ_i2c_example.c.

◆ SENSOR_Config()

mz_error_t SENSOR_Config ( )

Function to config the sensor.

Parameters
None
Return values
MZ_OK/MZ_FAIL

Definition at line 248 of file MZ_i2c_example.c.

◆ Sensor_cmd_data_conf()

mz_error_t Sensor_cmd_data_conf ( uint8_t  addr,
uint8_t  data 
)

Function to write data for Sensor Configuration.

Parameters
addr- address of the register
data- buffer which receives data from the register
Return values
MZ_OKor MZ_FAIL

Definition at line 341 of file MZ_i2c_example.c.

◆ SENSOR_Init()

void SENSOR_Init ( )

Function Sensor Initialisation.

Parameters
NONE
Return values
NONE

Definition at line 358 of file MZ_i2c_example.c.

◆ Sensor_ReadID()

mz_error_t Sensor_ReadID ( uint8_t *  buf)

Function to read the content from ID register of SENSOR.

Parameters
buf- buffer which receives data from the ID register
Return values
MZ_OKor MZ_FAIL

Definition at line 374 of file MZ_i2c_example.c.

◆ SI_Read_UV()

SISER_RCVD SI_Read_UV ( void  )

Function to read the data from SENSOR.

Parameters
NONE
Return values
SISER_VALID_RESP_RCVDor SISER_INVALID_RESP_RCVD

Definition at line 400 of file MZ_i2c_example.c.

◆ SENSOR_getUv()

int32_t SENSOR_getUv ( int32_t  uv,
SENSOR_Coeff_TypeDef uk 
)

Function to Conversion of Raw Data.

Parameters
uv-Raw data.
uk- Sensor Coefficient.
Return values
uvi-Sensor Converted Data.

Definition at line 452 of file MZ_i2c_example.c.

◆ SENSOR_calcPolyInner()

int32_t SENSOR_calcPolyInner ( int32_t  input,
int8_t  fraction,
uint16_t  mag,
int8_t  shift 
)

Function to Conversion of Raw Data.

Parameters
input-Raw data.
fraction- Sensor fraction.
mag- Sensor magnitude.
shift- Sensor shifted.
Return values
value-Sensor data converted with polyInner.

Definition at line 467 of file MZ_i2c_example.c.

◆ SENSOR_calcEvalPoly()

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.

Parameters
xint32_t -Raw data.
yint32_t - Sensor fraction.
input_fractionuint8_t
output_fractionuint8_t
num_coeffuint8_t
kp*SENSOR_Coeff_TypeDef.
Return values
value-Sensor data converted with calcEvalPoly.

Definition at line 493 of file MZ_i2c_example.c.

◆ calib_uv_index()

void calib_uv_index ( float  uv_raw_data)

Function to calibrate the raw data.

Parameters
uv_raw_datafloat.
Return values
value-None.

Definition at line 560 of file MZ_i2c_example.c.

◆ string_copy()

uint16_t string_copy ( uint8_t *  dststr,
uint8_t *  srcstr 
)

Function to Copy the data from source to destination.

Parameters
dststr-destination string.
srcstr-source string.
Return values
value-string index.

Definition at line 580 of file MZ_i2c_example.c.

◆ string_append()

uint8_t string_append ( uint8_t *  srcstr,
uint8_t *  apstr 
)

Function to append the string.

Parameters
apstr-append string.
srcstr-source string.
Return values
value-string index.

Definition at line 596 of file MZ_i2c_example.c.

◆ Get_String_len()

uint16_t Get_String_len ( uint8_t *  buf)

Function to get string length.

Parameters
buf-string.
Return values
len-string length.

Definition at line 617 of file MZ_i2c_example.c.

◆ int8buf_to_asciibuf()

void int8buf_to_asciibuf ( uint8_t *  destbuf,
uint8_t *  srcbuf,
uint16_t  len 
)

Function to Conversion of Int to ascii data.

Parameters
destbuf-destination string.
srcbuf-source string.
len-string.
Return values
None.

Definition at line 633 of file MZ_i2c_example.c.

Variable Documentation

◆ i2c_thread_id

mz_thread_t i2c_thread_id = NULL
static

Definition at line 26 of file MZ_i2c_example.c.

◆ i2c_cb_mem

StaticTask_t i2c_cb_mem
static

Definition at line 27 of file MZ_i2c_example.c.

◆ i2c_stack

StackType_t i2c_stack[I2C_APP_STACK_SIZE]
static

Definition at line 28 of file MZ_i2c_example.c.

◆ i2c_sema_id

mz_semaphore_t i2c_sema_id = NULL
static

Definition at line 29 of file MZ_i2c_example.c.

◆ loc_buf

mzUint8 loc_buf[RESP_BUF_LEN]
static

Definition at line 30 of file MZ_i2c_example.c.

◆ resp_buf

mzUint8 resp_buf[RESP_BUF_LEN]
static

Definition at line 31 of file MZ_i2c_example.c.

◆ err_code

mzUint8 err_code
static

Definition at line 32 of file MZ_i2c_example.c.

◆ write_sucess

mzUint8 write_sucess
static

Definition at line 33 of file MZ_i2c_example.c.

◆ localBuf1

mzUint8 localBuf1[SI_SENSOR_BUF_LEN]
static

Definition at line 34 of file MZ_i2c_example.c.

◆ i2cLocBuf

mzUint8 i2cLocBuf[SI_SENSOR_BUF_LEN]
static

Definition at line 35 of file MZ_i2c_example.c.

◆ locstr1

mzUint8 locstr1[50]
static

Definition at line 36 of file MZ_i2c_example.c.

◆ send_data

mzUint8 send_data[I2C_TX_SIZE]
static

Definition at line 37 of file MZ_i2c_example.c.

◆ buf

mzUint8 buf[10]

Definition at line 38 of file MZ_i2c_example.c.

◆ uv_val

mzUint32 uv_val

Definition at line 39 of file MZ_i2c_example.c.

◆ als_val1

mzUint32 als_val1

Definition at line 39 of file MZ_i2c_example.c.

◆ als_val2

mzUint32 als_val2

Definition at line 39 of file MZ_i2c_example.c.

◆ als_val3

mzUint32 als_val3

Definition at line 39 of file MZ_i2c_example.c.

◆ SI_resp_rcvd

SISER_RCVD SI_resp_rcvd = SISER_NONE_RCVD

Definition at line 40 of file MZ_i2c_example.c.

◆ cnt

mzUint8 cnt =0

Definition at line 41 of file MZ_i2c_example.c.