monoZ docs
|
There are certain context variables provided by user to initialize all the context required by the monoZ_Lib.
i. Hardware related context[Mandatory]
ii. Modem related context[Optional]
i. Hardware related context
The definitions of all hardware context variables are present in “MZ_public.h” header file. The sample template for using is also provided in the same header file.
a. Main context variable
User must create this context variable for successful use of the library. In case the context variable is not created by user, The monoZ_Lib will not initialize and a linker error will occur.
monoZ Click tool user
Incase using tool, this variable is created and placed in "MZ_hardware_config.c"
Ambient light Sample code implementation
extern MZ_I2C_INIT_ST uv_i2c2_instance; uart_enable uart_enable_cfg = { .u3 = MZI_UART3, .u3p = 0, .lu1 = MZI_LPUART1, .lu1p = &uv_i2c2_instance, }; i2c_enable i2c_enable_cfg = { .i2 = MZI_I2C2, .i2p = &uv_i2c2_instance, .i4 = MZI_I2C4, .i4p = 0, };
b. I2C2 Peripheral context variable
User must create the peripheral context variable for the desired interface and use it in Main context variable. In case of the UV Addon board, it uses I2C2 interface for sensor communication. monoZ_Lib takes all I2C2 related initialization context through “uart_enable_cfg“ context variable. For the UV application, we need to define a peripheral context variable. Let’s say “uv_i2c2_instance”.
monoZ Click tool user
Incase using tool, this variable is created and placed in "MZ_Addon_board_UV.c"
Ambient light Sample code implementation
MZ_I2C_INIT_ST uv_i2c2_instance = { .Instance = MZ_ADDONUV_INSTANCE, .Init.Timing = MZ_ADDONUV_INIT_TIMING, .Init.OwnAddress1 = MZ_ADDONUV_INIT_OWNADDRESS1, .Init.AddressingMode = MZ_ADDONUV_INIT_ADDRESSINGMODE, .Init.DualAddressMode = MZ_ADDONUV_INIT_DUALADDRESSMODE, .Init.OwnAddress2 = MZ_ADDONUV_INIT_OWNADDRESS2, .Init.OwnAddress2Masks = MZ_ADDONUV_INIT_OWNADDRESS2MASKS, .Init.GeneralCallMode = MZ_ADDONUV_INIT_GENERALCALLMODE, .Init.NoStretchMode = MZ_ADDONUV_INIT_NOSTRETCHMODE };
ii. Modem related context
User must create the modem context functions if wish to initialize modem with specific configuration. There are 2 function definitions present to provide flexibility. The names of the function are fixed. User need to define the function with this exact name. Prototype of the functions are as follows:
Note: User must define the desired AT commands need to be executed during these actions.
monoZ Click tool user
Incase using tool, these functions are created and placed in "MZ_modem_config.c"
Ambient light Sample code implementation
void mz_reset_sequence(void * arg) { (void)arg; mz_power_config(); mz_apn_set(); mz_lwm2m_config(); mz_device_reboot(); mz_device_start(); mz_lwm2m_start(); } Void mz_reboot_sequence(void * arg) { (void)arg; mz_device_reboot(); mz_device_start(); mz_lwm2m_start(); }
User must initialize the monoZ_Lib before it can start using the library features. The monoZ Library can be initialized using the API MZ_init (). “MZ_main. h” header file provides a sample use of how to initialize the library.
monoZ Click tool user
Incase using tool, monoZ Library initialization code is placed inside main() API present in "main.c"
Ambient light Sample code implementation
mz_version ver = { ._major = MZ_SW_VERSION_MAJOR, ._minor = MZ_SW_VERSION_MINOR, ._patch = MZ_SW_VERSION_PATCH }; if(MZ_OK != MZ_init(&ver)) { Error_Handler(); }
The UV Application initialization is done before the Main FreeRTOS kernel starts. User must create a user application using the monoZ Library API’s.
monoZ Click tool user
Incase using tool, the code is generated and placed in MZ_Addon_board_CO2. c and the code is called within main in "main.c"
Ambient light Sample code implementation
Static void uv_app(void * arg) { … }
mz_error_t uv_app_init(void) { … /* Create the UV application thread */ if(!mz_thread_create( &uv_thread_id,"UV reading app",uv_app,NULL,osPriorityNormal,uv_stack,UV_APP_STACK_SIZE,&uv_cb_mem,sizeof(uv_cb_mem))) { _ret = MZ_THREAD_CREATE_FAIL; } … }
/* creation of user task */ if(MZ_OK != uv_app_init()) { Error_Handler(); }
User must design the application based on requirements. Following is the High-level requirement considered for building the Addon-board UV example.
Ambient light Sample code implementation
A. Application should read and send the data
if(MZ_OK == mz_tm_create_start_recursive( "UV Read timer",UV_READ_TIME,uv_read_timer_cb)) { /* initialize the Si1133 sensor */ sensor_init = SI1133_init(); if(SI_OK == sensor_init) { mz_puts("SENSOR Initialization complete...\r\n"); } }
static void uv_read_timer_cb(TimerHandle_t xTimer) { mz_puts("Timer expires - start read of Si1133 sensor\r\n"); /* Set the timer expired flag */ timer_expiry_flag = 1; }
if(1 == timer_expiry_flag) { /* Process the Si1133 sensor read timer expire event */ … }