diff --git a/Samples/AZX_Docs/html/annotated.html b/Samples/AZX_Docs/html/annotated.html
index b00cd54..05013a9 100644
--- a/Samples/AZX_Docs/html/annotated.html
+++ b/Samples/AZX_Docs/html/annotated.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/app__cfg_8h.html b/Samples/AZX_Docs/html/app__cfg_8h.html
index 4ec2dd2..e0f3863 100644
--- a/Samples/AZX_Docs/html/app__cfg_8h.html
+++ b/Samples/AZX_Docs/html/app__cfg_8h.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/app__cfg_8h_source.html b/Samples/AZX_Docs/html/app__cfg_8h_source.html
index 46d3d6b..47754e5 100644
--- a/Samples/AZX_Docs/html/app__cfg_8h_source.html
+++ b/Samples/AZX_Docs/html/app__cfg_8h_source.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__log_8h.html b/Samples/AZX_Docs/html/azx__log_8h.html
index 423045e..4fd44ee 100644
--- a/Samples/AZX_Docs/html/azx__log_8h.html
+++ b/Samples/AZX_Docs/html/azx__log_8h.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__log_8h_source.html b/Samples/AZX_Docs/html/azx__log_8h_source.html
index 1e09a0c..2fe7594 100644
--- a/Samples/AZX_Docs/html/azx__log_8h_source.html
+++ b/Samples/AZX_Docs/html/azx__log_8h_source.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__tasks_8h.html b/Samples/AZX_Docs/html/azx__tasks_8h.html
index a4dd9dd..8c6ec66 100644
--- a/Samples/AZX_Docs/html/azx__tasks_8h.html
+++ b/Samples/AZX_Docs/html/azx__tasks_8h.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__tasks_8h_source.html b/Samples/AZX_Docs/html/azx__tasks_8h_source.html
index 341fcd7..9162527 100644
--- a/Samples/AZX_Docs/html/azx__tasks_8h_source.html
+++ b/Samples/AZX_Docs/html/azx__tasks_8h_source.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__utils_8h.html b/Samples/AZX_Docs/html/azx__utils_8h.html
index 4c49792..168b34e 100644
--- a/Samples/AZX_Docs/html/azx__utils_8h.html
+++ b/Samples/AZX_Docs/html/azx__utils_8h.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx__utils_8h_source.html b/Samples/AZX_Docs/html/azx__utils_8h_source.html
index 64ea6f9..37c4db2 100644
--- a/Samples/AZX_Docs/html/azx__utils_8h_source.html
+++ b/Samples/AZX_Docs/html/azx__utils_8h_source.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/azx_tasks_example_8c-example.html b/Samples/AZX_Docs/html/azx_tasks_example_8c-example.html
index 6dfe189..7d27798 100644
--- a/Samples/AZX_Docs/html/azx_tasks_example_8c-example.html
+++ b/Samples/AZX_Docs/html/azx_tasks_example_8c-example.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/classes.html b/Samples/AZX_Docs/html/classes.html
index 03d5103..01c2d3b 100644
--- a/Samples/AZX_Docs/html/classes.html
+++ b/Samples/AZX_Docs/html/classes.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/dir_0045f852bf8045b6d5abd9c9eb54a446.html b/Samples/AZX_Docs/html/dir_0045f852bf8045b6d5abd9c9eb54a446.html
index 5bc8e94..800d670 100644
--- a/Samples/AZX_Docs/html/dir_0045f852bf8045b6d5abd9c9eb54a446.html
+++ b/Samples/AZX_Docs/html/dir_0045f852bf8045b6d5abd9c9eb54a446.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/examples.html b/Samples/AZX_Docs/html/examples.html
index 84fd605..26746fb 100644
--- a/Samples/AZX_Docs/html/examples.html
+++ b/Samples/AZX_Docs/html/examples.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/files.html b/Samples/AZX_Docs/html/files.html
index 77271b2..e5af532 100644
--- a/Samples/AZX_Docs/html/files.html
+++ b/Samples/AZX_Docs/html/files.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/functions.html b/Samples/AZX_Docs/html/functions.html
index 7ed0c6b..3ffe585 100644
--- a/Samples/AZX_Docs/html/functions.html
+++ b/Samples/AZX_Docs/html/functions.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/functions_vars.html b/Samples/AZX_Docs/html/functions_vars.html
index 06a6469..2424691 100644
--- a/Samples/AZX_Docs/html/functions_vars.html
+++ b/Samples/AZX_Docs/html/functions_vars.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals.html b/Samples/AZX_Docs/html/globals.html
index 1a58669..88539bb 100644
--- a/Samples/AZX_Docs/html/globals.html
+++ b/Samples/AZX_Docs/html/globals.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals_defs.html b/Samples/AZX_Docs/html/globals_defs.html
index a337886..67910a7 100644
--- a/Samples/AZX_Docs/html/globals_defs.html
+++ b/Samples/AZX_Docs/html/globals_defs.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals_enum.html b/Samples/AZX_Docs/html/globals_enum.html
index c308613..ec8e183 100644
--- a/Samples/AZX_Docs/html/globals_enum.html
+++ b/Samples/AZX_Docs/html/globals_enum.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals_eval.html b/Samples/AZX_Docs/html/globals_eval.html
index 0a36fc0..c8e6d4a 100644
--- a/Samples/AZX_Docs/html/globals_eval.html
+++ b/Samples/AZX_Docs/html/globals_eval.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals_func.html b/Samples/AZX_Docs/html/globals_func.html
index 0478647..53c66b4 100644
--- a/Samples/AZX_Docs/html/globals_func.html
+++ b/Samples/AZX_Docs/html/globals_func.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/globals_type.html b/Samples/AZX_Docs/html/globals_type.html
index 3a4ef7a..90784bb 100644
--- a/Samples/AZX_Docs/html/globals_type.html
+++ b/Samples/AZX_Docs/html/globals_type.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/graph_legend.html b/Samples/AZX_Docs/html/graph_legend.html
index 2a1c3b9..9e7972f 100644
--- a/Samples/AZX_Docs/html/graph_legend.html
+++ b/Samples/AZX_Docs/html/graph_legend.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/group__log_conf.html b/Samples/AZX_Docs/html/group__log_conf.html
index c92726d..a957be7 100644
--- a/Samples/AZX_Docs/html/group__log_conf.html
+++ b/Samples/AZX_Docs/html/group__log_conf.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/group__log_usage.html b/Samples/AZX_Docs/html/group__log_usage.html
index ba96e6a..507de1d 100644
--- a/Samples/AZX_Docs/html/group__log_usage.html
+++ b/Samples/AZX_Docs/html/group__log_usage.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/group__task_usage.html b/Samples/AZX_Docs/html/group__task_usage.html
index 86c50c0..9bb638d 100644
--- a/Samples/AZX_Docs/html/group__task_usage.html
+++ b/Samples/AZX_Docs/html/group__task_usage.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/index.html b/Samples/AZX_Docs/html/index.html
index 30b0e60..21b5ee6 100644
--- a/Samples/AZX_Docs/html/index.html
+++ b/Samples/AZX_Docs/html/index.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/modules.html b/Samples/AZX_Docs/html/modules.html
index 3acc08f..9d4e343 100644
--- a/Samples/AZX_Docs/html/modules.html
+++ b/Samples/AZX_Docs/html/modules.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/struct_a_z_x___l_o_g___c_f_g___t.html b/Samples/AZX_Docs/html/struct_a_z_x___l_o_g___c_f_g___t.html
index b2f3188..6ddb5ef 100644
--- a/Samples/AZX_Docs/html/struct_a_z_x___l_o_g___c_f_g___t.html
+++ b/Samples/AZX_Docs/html/struct_a_z_x___l_o_g___c_f_g___t.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/AZX_Docs/html/struct_a_z_x___t_a_s_k_s___m_e_s_s_a_g_e___t.html b/Samples/AZX_Docs/html/struct_a_z_x___t_a_s_k_s___m_e_s_s_a_g_e___t.html
index f1151ff..db494f4 100644
--- a/Samples/AZX_Docs/html/struct_a_z_x___t_a_s_k_s___m_e_s_s_a_g_e___t.html
+++ b/Samples/AZX_Docs/html/struct_a_z_x___t_a_s_k_s___m_e_s_s_a_g_e___t.html
@@ -34,7 +34,7 @@
 |
AZX (AppZone eXtensions) documentation
- 1.0.10
+ 1.0.12
A set of companion utilities that make AZ development easier
|
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/BOSCH/BME680/bsec_integration.c b/Samples/BRAVO_Environment_BSEC_Demo/BOSCH/BME680/bsec_integration.c
index f045be7..445d978 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/BOSCH/BME680/bsec_integration.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/BOSCH/BME680/bsec_integration.c
@@ -74,11 +74,12 @@
/* header files */
/**********************************************************************************************************************/
-#include "../BME680/bsec_integration.h"
+
#include
#include
#include
+#include "../BME680/bsec_integration.h"
#include
/**********************************************************************************************************************/
@@ -163,9 +164,9 @@ return_values_init bsec_iot_init(float sample_rate, float temperature_offset, bm
return_values_init ret = {BME680_OK, BSEC_OK};
//bsec_library_return_t bsec_status = BSEC_OK;
- uint8_t bsec_state[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint8_t bsec_config[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
- uint8_t work_buffer[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE] = {0};
int bsec_state_len, bsec_config_len;
/* Fixed I2C configuration */
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/Makefile.in b/Samples/BRAVO_Environment_BSEC_Demo/Makefile.in
index fb08eba..460a053 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/Makefile.in
+++ b/Samples/BRAVO_Environment_BSEC_Demo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/M2MB_main.c b/Samples/BRAVO_Environment_BSEC_Demo/src/M2MB_main.c
index 7e65bfc..7966a0f 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/M2MB_main.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/M2MB_main.c
@@ -12,7 +12,7 @@
@description
Environment Demo application. Debug prints on MAIN UART
@version
- 1.0.4
+ 1.0.6
@note
Start of Appzone: Entry point
User code entry is in function M2MB_main()
@@ -68,8 +68,6 @@
Bosch device
*/
#define INT_GPIO_PIN_NUM 6
-#define LED_INDEX_NUM 2 /* GPIO 10 */
-
#define BME680_W_SELF_TEST_FAILED 3
@@ -276,7 +274,7 @@ void M2MB_main( int argc, char **argv )
LWM2M_OBJ_REG_T obj = {ENVIRONMENT_OBJ_ID, 1, instances };
#endif
/* Open GPIO */
- if( open_LED( LED_INDEX_NUM ) != 0 )
+ if( open_LED( DEFAULT_LED_INDEX ) != 0 )
{
AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
return;
@@ -292,7 +290,7 @@ void M2MB_main( int argc, char **argv )
if( 0 != copy_xml_file( XML_NAME ) )
{
AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
-
+
for( int i = 0; i < 10; i++ )
{
write_LED( M2MB_GPIO_HIGH_VALUE );
@@ -362,7 +360,7 @@ void M2MB_main( int argc, char **argv )
return;// (int)ret.bsec_status;
}
}
-
+
write_LED( M2MB_GPIO_HIGH_VALUE );
azx_sleep_ms( 100 );
write_LED( M2MB_GPIO_LOW_VALUE );
@@ -371,7 +369,7 @@ void M2MB_main( int argc, char **argv )
azx_sleep_ms( 100 );
write_LED( M2MB_GPIO_LOW_VALUE );
azx_sleep_ms( 100 );
-
+
/* Call to endless loop function which reads and processes data based on sensor settings */
/* State is saved every 10.000 samples, which means every 10.000 * 3 secs = 500 minutes */
bsec_iot_loop( azx_sleep_ms, get_timestamp_us, output_ready, state_save, 10000 );
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.c b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.h b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.c b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.c
index a5b6d43..e1015c0 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.c
@@ -43,32 +43,20 @@
/* Local statics ================================================================================*/
static INT32 i2c_fd = -1;
-M2MB_OS_SEM_HANDLE I2C_CSSemHandle = NULL;
-
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
/*-----------------------------------------------------------------------------------------------*/
+
+
+
int open_I2C( void )
{
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
-
-
-
/**************
Configuring the IIC device.
@@ -85,7 +73,10 @@ int open_I2C( void )
AZX_LOG_ERROR( "cannot open I2C channel!\r\n" );
return 1;
}
-
+ else
+ {
+ AZX_LOG_DEBUG("i2d_fd: %d\r\n", i2c_fd);
+ }
config.sclPin = I2C_SCL;
config.sdaPin = I2C_SDA;
config.registerId = 0x00; //dummy register
@@ -112,11 +103,12 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
return 1;
}
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -125,18 +117,18 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", size,
reg );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, p_buf, size );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != size )
{
- AZX_LOG_ERROR( "cannot write data! error: %d\r\n", i2c_res );
+ AZX_LOG_ERROR( "cannot write data on %d! error: %d\r\n", i2c_fd, i2c_res );
return 1;
}
else
@@ -159,7 +151,7 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -173,14 +165,14 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
tmpsize = size;
}
-
+
i2c_res = m2mb_i2c_read( i2c_fd, p_buf, tmpsize ); //reading 16 bytes max at a time
if( i2c_res == tmpsize )
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
for( int i = 0; i < i2c_res; i++ )
@@ -208,16 +200,21 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+ if( i2c_fd == -1 )
+ {
+ return 1;
+ }
+
AZX_LOG_TRACE( "I2C read register..." );
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
if( reg == 0 ) // if read FIFO double buffer
{
for( ; size > 50; )
@@ -233,7 +230,28 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
i2c_res = sensor_i2c_read_16( addr, reg, p_buf, size, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+
+int close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BHI160 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.h b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.h
index 0409bac..89f522f 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.h
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/i2c.h
@@ -30,11 +30,10 @@
#define BHY_I2C_160B_ADDR1 (UINT16) 0x28
-extern M2MB_OS_SEM_HANDLE I2C_CSSemHandle;
-
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
+
/**
@brief Opens I2C device at BHI160B default address
@@ -66,5 +65,10 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
*/
int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size );
+/**
+ @brief Closes I2C device channel
+
+*/
+int close_I2C( void );
#endif /* SRC_I2C_H_ */
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/lwm2m.c b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.c b/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.c
index cf18882..9bdf07a 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.c
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.c
@@ -13,7 +13,7 @@
@author WhiteBeard
@author FabioPi
-
+
@date
2020-02-15
*/
@@ -39,7 +39,11 @@
/* Local defines ================================================================================*/
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
+#ifndef BRAVO_REV_B
static INT32 i2c_fd = -1;
+#endif
+
+
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
@@ -79,16 +83,6 @@ int bme680_openI2C( uint8_t dev_id )
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
/**************
Configuring the IIC device.
@@ -129,6 +123,7 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
AZX_LOG_TRACE( "bme680_i2c_write\r\n" );
AZX_LOG_TRACE( "bme680_i2c_write LEN = %d\r\n", len );
+
if( i2c_fd == -1 )
{
i2c_res = bme680_openI2C(dev_id);
@@ -139,6 +134,8 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
}
}
+
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
@@ -153,15 +150,16 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
if( i2c_res != 0 )
{
AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", len,
reg_addr );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, data, len );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != len )
{
@@ -209,13 +207,15 @@ int8_t bme680_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
+
for( int i = 0; i < i2c_res; i++ )
{
AZX_LOG_TRACE( " %02x", p_buf[i] );
}
+
AZX_LOG_TRACE( "\r\n" );
p_buf = p_buf + tmpsize;
@@ -239,6 +239,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+
AZX_LOG_TRACE( "bme680_i2c_read\r\n" );
AZX_LOG_TRACE( "bme680_i2c_read LEN = %d\r\n", len );
@@ -262,7 +263,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
if( reg_addr == 0 ) // if read FIFO double buffer
{
for( ; len > 50; )
@@ -278,8 +279,29 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
{
i2c_res = bme680_i2c_read_16( dev_id, reg_addr, data, len, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+int bme680_close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BME680 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
+
#endif
diff --git a/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.h b/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.h
index 5bac549..213130d 100644
--- a/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.h
+++ b/Samples/BRAVO_Environment_BSEC_Demo/src/i2c_bme680.h
@@ -54,4 +54,9 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len );
+/**
+ @brief Closes I2C bme680device channel
+
+*/
+int bme680_close_I2C( void );
#endif /* SRC_I2C_BME680_H_ */
diff --git a/Samples/BRAVO_LED_Demo/Makefile.in b/Samples/BRAVO_LED_Demo/Makefile.in
index 2f55606..a0ec67f 100644
--- a/Samples/BRAVO_LED_Demo/Makefile.in
+++ b/Samples/BRAVO_LED_Demo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.c b/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.h b/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_LED_Demo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_LED_Demo/src/demo_utils/lwm2m.c b/Samples/BRAVO_LED_Demo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_LED_Demo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_LED_Demo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_MultiSensorsDemo/BOSCH/BME680/bsec_integration.c b/Samples/BRAVO_MultiSensorsDemo/BOSCH/BME680/bsec_integration.c
index f045be7..445d978 100644
--- a/Samples/BRAVO_MultiSensorsDemo/BOSCH/BME680/bsec_integration.c
+++ b/Samples/BRAVO_MultiSensorsDemo/BOSCH/BME680/bsec_integration.c
@@ -74,11 +74,12 @@
/* header files */
/**********************************************************************************************************************/
-#include "../BME680/bsec_integration.h"
+
#include
#include
#include
+#include "../BME680/bsec_integration.h"
#include
/**********************************************************************************************************************/
@@ -163,9 +164,9 @@ return_values_init bsec_iot_init(float sample_rate, float temperature_offset, bm
return_values_init ret = {BME680_OK, BSEC_OK};
//bsec_library_return_t bsec_status = BSEC_OK;
- uint8_t bsec_state[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint8_t bsec_config[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
- uint8_t work_buffer[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE] = {0};
int bsec_state_len, bsec_config_len;
/* Fixed I2C configuration */
diff --git a/Samples/BRAVO_MultiSensorsDemo/Makefile.in b/Samples/BRAVO_MultiSensorsDemo/Makefile.in
index fb08eba..460a053 100644
--- a/Samples/BRAVO_MultiSensorsDemo/Makefile.in
+++ b/Samples/BRAVO_MultiSensorsDemo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_MultiSensorsDemo/hdr/sensors_demo.h b/Samples/BRAVO_MultiSensorsDemo/hdr/sensors_demo.h
index f1216b4..19d374d 100644
--- a/Samples/BRAVO_MultiSensorsDemo/hdr/sensors_demo.h
+++ b/Samples/BRAVO_MultiSensorsDemo/hdr/sensors_demo.h
@@ -63,7 +63,7 @@
#define MAX_PACKET_LENGTH 18
#define TICKS_IN_ONE_SECOND 32000.0F
-#define ROTATION_VECTOR_SAMPLE_RATE 10 /* Hz */
+#define ROTATION_VECTOR_SAMPLE_RATE 5 /* Hz */
/*BME*/
@@ -85,12 +85,20 @@
#define HIGH_TEMP 350
+#define TASK_INIT 0
+#define TASK_LOOP 1
+#define TASK_REINIT 2
+
+#define DO_NOT_RESET 0
+#define DO_RESET 1
+
/* Global typedefs ==============================================================================*/
typedef enum
{
BSENS_SENSOR_ENVIRONM_ID = 1,
BSENS_SENSOR_3D_VECT_ID = 2,
- BSENS_SENSOR_TAMPER_ID = 3
+ BSENS_SENSOR_TAMPER_ID = 3,
+ BSENS_MAX_ID
} BSENS_SENSOR_ID_E;
@@ -141,9 +149,16 @@ typedef enum
/* Global functions =============================================================================*/
/**
- @brief This function is used to run bhy hub
+ @brief This function is used to initialize bhy hub
*/
int init_sensors( void );
+/**
+ @brief This function is used to run bhy hub loop
+*/
+int run_sensors_loop(int reset);
+
+
int read_sensor(BSENS_SENSOR_ID_E id, void **data);
+void WDog_Init(M2MB_OS_TASK_HANDLE TaskWD_H);
#endif /* HDR_SENSORS_DEMO_H_ */
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/M2MB_main.c b/Samples/BRAVO_MultiSensorsDemo/src/M2MB_main.c
index 0a8c646..a4164f5 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/M2MB_main.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/M2MB_main.c
@@ -12,7 +12,7 @@
@description
MultiSensors Demo application. Debug prints on MAIN UART
@version
- 1.0.2
+ 1.0.3
@note
Start of Appzone: Entry point
User code entry is in function M2MB_main()
@@ -55,12 +55,18 @@
#include "sensors_demo.h"
+
+#ifndef BRAVO_REV_B
+#include "i2c_bme680.h"
+#endif
+
+
/* Local defines ================================================================================*/
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
-
-
+INT32 bsens_taskId;
+M2MB_OS_TASK_HANDLE Task_h;
/* Local function prototypes ====================================================================*/
/**
@@ -75,143 +81,170 @@ static INT32 demoTaskCb(INT32 type, INT32 param1, INT32 param2);
static INT32 demoTaskCb(INT32 type, INT32 param1, INT32 param2)
{
- (void) type;
(void) param1;
(void) param2;
-#ifndef SKIP_LWM2M
- int reboot_needed = 0;
-
- INT16 instances[] = {0};
- LWM2M_OBJ_REG_T objs[] ={
- {TAMPERING_OBJ_ID, 1, instances },
- {ROTATION_OBJ_ID, 1, instances },
- {ENVIRONMENT_OBJ_ID, 1, instances }
- };
-#endif
- /* Open GPIO */
- if( open_LED( LED_INDEX_NUM ) != 0 )
- {
- AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
- return -1;
- }
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 5000 );
- write_LED( M2MB_GPIO_LOW_VALUE );
-
-#ifndef SKIP_LWM2M
- /* Copy xml file if not exixting */
- if( 0 != check_xml_file( TAMPER_XML_NAME ) )
+ switch(type)
{
- if( 0 != copy_xml_file( TAMPER_XML_NAME ) )
+ case TASK_INIT:
{
- AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
-
- for( int i = 0; i < 10; i++ )
+#ifndef SKIP_LWM2M
+ int reboot_needed = 0;
+
+ INT16 instances[] = {0};
+ LWM2M_OBJ_REG_T objs[] = {
+ {TAMPERING_OBJ_ID, 1, instances },
+ {ROTATION_OBJ_ID, 1, instances },
+ {ENVIRONMENT_OBJ_ID, 1, instances }
+ };
+#endif
+ /* Open GPIO */
+ if( open_LED( LED_INDEX_NUM ) != 0 )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 200 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 200 );
+ AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
+ return -1;
}
- return -1;
- }
- reboot_needed = 1;
- }
-
- /* Copy xml file if not exixting */
- if( 0 != check_xml_file( ROTATION_XML_NAME ) )
- {
- if( 0 != copy_xml_file( ROTATION_XML_NAME ) )
- {
- AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 5000 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
- for( int i = 0; i < 10; i++ )
+#ifndef SKIP_LWM2M
+ /* Copy xml file if not exixting */
+ if( 0 != check_xml_file( TAMPER_XML_NAME ) )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 200 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 200 );
+ if( 0 != copy_xml_file( TAMPER_XML_NAME ) )
+ {
+ AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
+
+ for( int i = 0; i < 10; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 200 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 200 );
+ }
+
+ return -1;
+ }
+ reboot_needed = 1;
}
- return -1;
- }
- reboot_needed = 1;
- }
-
- if( 0 != check_xml_file( ENVIRONMENT_XML_NAME ) )
- {
- if( 0 != copy_xml_file( ENVIRONMENT_XML_NAME ) )
- {
- AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
-
- for( int i = 0; i < 10; i++ )
+ /* Copy xml file if not exixting */
+ if( 0 != check_xml_file( ROTATION_XML_NAME ) )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 200 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 200 );
+ if( 0 != copy_xml_file( ROTATION_XML_NAME ) )
+ {
+ AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
+
+ for( int i = 0; i < 10; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 200 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 200 );
+ }
+
+ return -1;
+ }
+ reboot_needed = 1;
}
- return -1;
- }
- reboot_needed = 1;
- }
-
- if(reboot_needed)
- {
- M2MB_POWER_HANDLE handle;
- AZX_LOG_DEBUG( "Rebooting to apply xml file\r\n" );
- if( M2MB_RESULT_SUCCESS != m2mb_power_init( &handle, NULL, ( void * ) NULL ) )
- {
- AZX_LOG_CRITICAL( "cannot init power module!\r\n" );
- return -1;
- }
- else
- {
- for( int i = 0; i < 3; i++ )
+ if( 0 != check_xml_file( ENVIRONMENT_XML_NAME ) )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 1000 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 1000 );
+ if( 0 != copy_xml_file( ENVIRONMENT_XML_NAME ) )
+ {
+ AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
+
+ for( int i = 0; i < 10; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 200 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 200 );
+ }
+ return -1;
+ }
+ reboot_needed = 1;
}
- m2mb_power_reboot( handle );
- m2mb_power_deinit( handle );
- return 0;
- }
- }
+ if(reboot_needed)
+ {
+ M2MB_POWER_HANDLE handle;
+ AZX_LOG_DEBUG( "Rebooting to apply xml file\r\n" );
+
+ if( M2MB_RESULT_SUCCESS != m2mb_power_init( &handle, NULL, ( void * ) NULL ) )
+ {
+ AZX_LOG_CRITICAL( "cannot init power module!\r\n" );
+ return -1;
+ }
+ else
+ {
+ for( int i = 0; i < 3; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 1000 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 1000 );
+ }
+
+ m2mb_power_reboot( handle );
+ m2mb_power_deinit( handle );
+ return 0;
+ }
+ }
#endif
- /* Open I2C */
- if( open_I2C() != 0 )
- {
- AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
- return -1;
- }
+ /* Open I2C */
+ if( open_I2C() != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
+ return -1;
+ }
- /* Open GPIO */
- if( open_gpio( INT_GPIO_PIN_NUM ) != 0 )
- {
- AZX_LOG_ERROR( "cannot open gpio channel.\r\n" );
- return -1;
- }
+ /* Open GPIO */
+ if( open_gpio( INT_GPIO_PIN_NUM ) != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open gpio channel.\r\n" );
+ return -1;
+ }
#ifndef SKIP_LWM2M
- if(oneedge_init( objs, 3, NULL ) != 0)
- {
- AZX_LOG_ERROR("Failed enabling LWM2M!\r\n");
- return -1;
- }
+ if(oneedge_init( objs, 3, NULL ) != 0)
+ {
+ AZX_LOG_ERROR("Failed enabling LWM2M!\r\n");
+ return -1;
+ }
#else
- AZX_LOG_INFO( "Will run without LWM2M data publishing\r\n");
+ AZX_LOG_INFO( "Will run without LWM2M data publishing\r\n");
#endif
+ Task_h = m2mb_os_taskGetId();
+ AZX_LOG_DEBUG("init sensors...\r\n");
+ init_sensors();
- AZX_LOG_DEBUG("init sensors...\r\n");
- init_sensors();
-
+ /*Store task handle for watchdog*/
+ WDog_Init( Task_h);
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_LOOP, DO_NOT_RESET, 0);
+ }
+ break;
+ case TASK_LOOP:
+ run_sensors_loop(param1);
+ break;
+ case TASK_REINIT:
+ close_I2C();
+ /* Open I2C */
+ if( open_I2C() != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
+ return -1;
+ }
+ #ifndef BRAVO_REV_B
+ bme680_close_I2C();
+ /*I2C will be reopened by read/write operations*/
+ #endif
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_LOOP, DO_RESET /*reset FIFO and parameters*/, 0);
+ break;
+ }
return 0;
}
/* Global functions =============================================================================*/
@@ -229,7 +262,7 @@ void M2MB_main( int argc, char **argv )
{
( void )argc;
( void )argv;
- INT32 taskId;
+
azx_tasks_init();
/* SET output channel */
@@ -238,11 +271,11 @@ void M2MB_main( int argc, char **argv )
VERSION, __DATE__, __TIME__ );
- taskId = azx_tasks_createTask((char*) "BSENS" , AZX_TASKS_STACK_XL, 1, AZX_TASKS_MBOX_S, demoTaskCb);
- if(taskId > 0)
+ bsens_taskId = azx_tasks_createTask((char*) "BSENS" , AZX_TASKS_STACK_XL, 4, AZX_TASKS_MBOX_S, demoTaskCb);
+ if(bsens_taskId > 0)
{
- azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_INIT, 0, 0);
}
else
{
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.c b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.h b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.c b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.c
index a5b6d43..e1015c0 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.c
@@ -43,32 +43,20 @@
/* Local statics ================================================================================*/
static INT32 i2c_fd = -1;
-M2MB_OS_SEM_HANDLE I2C_CSSemHandle = NULL;
-
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
/*-----------------------------------------------------------------------------------------------*/
+
+
+
int open_I2C( void )
{
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
-
-
-
/**************
Configuring the IIC device.
@@ -85,7 +73,10 @@ int open_I2C( void )
AZX_LOG_ERROR( "cannot open I2C channel!\r\n" );
return 1;
}
-
+ else
+ {
+ AZX_LOG_DEBUG("i2d_fd: %d\r\n", i2c_fd);
+ }
config.sclPin = I2C_SCL;
config.sdaPin = I2C_SDA;
config.registerId = 0x00; //dummy register
@@ -112,11 +103,12 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
return 1;
}
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -125,18 +117,18 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", size,
reg );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, p_buf, size );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != size )
{
- AZX_LOG_ERROR( "cannot write data! error: %d\r\n", i2c_res );
+ AZX_LOG_ERROR( "cannot write data on %d! error: %d\r\n", i2c_fd, i2c_res );
return 1;
}
else
@@ -159,7 +151,7 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -173,14 +165,14 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
tmpsize = size;
}
-
+
i2c_res = m2mb_i2c_read( i2c_fd, p_buf, tmpsize ); //reading 16 bytes max at a time
if( i2c_res == tmpsize )
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
for( int i = 0; i < i2c_res; i++ )
@@ -208,16 +200,21 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+ if( i2c_fd == -1 )
+ {
+ return 1;
+ }
+
AZX_LOG_TRACE( "I2C read register..." );
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
if( reg == 0 ) // if read FIFO double buffer
{
for( ; size > 50; )
@@ -233,7 +230,28 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
i2c_res = sensor_i2c_read_16( addr, reg, p_buf, size, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+
+int close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BHI160 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.h b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.h
index 0409bac..89f522f 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.h
+++ b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/i2c.h
@@ -30,11 +30,10 @@
#define BHY_I2C_160B_ADDR1 (UINT16) 0x28
-extern M2MB_OS_SEM_HANDLE I2C_CSSemHandle;
-
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
+
/**
@brief Opens I2C device at BHI160B default address
@@ -66,5 +65,10 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
*/
int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size );
+/**
+ @brief Closes I2C device channel
+
+*/
+int close_I2C( void );
#endif /* SRC_I2C_H_ */
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/lwm2m.c b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.c b/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.c
index f4a500b..9bdf07a 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.c
@@ -39,7 +39,11 @@
/* Local defines ================================================================================*/
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
+#ifndef BRAVO_REV_B
static INT32 i2c_fd = -1;
+#endif
+
+
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
@@ -79,16 +83,6 @@ int bme680_openI2C( uint8_t dev_id )
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
/**************
Configuring the IIC device.
@@ -129,6 +123,7 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
AZX_LOG_TRACE( "bme680_i2c_write\r\n" );
AZX_LOG_TRACE( "bme680_i2c_write LEN = %d\r\n", len );
+
if( i2c_fd == -1 )
{
i2c_res = bme680_openI2C(dev_id);
@@ -139,6 +134,8 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
}
}
+
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
@@ -153,15 +150,16 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
if( i2c_res != 0 )
{
AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", len,
reg_addr );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, data, len );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != len )
{
@@ -241,6 +239,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+
AZX_LOG_TRACE( "bme680_i2c_read\r\n" );
AZX_LOG_TRACE( "bme680_i2c_read LEN = %d\r\n", len );
@@ -264,7 +263,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
if( reg_addr == 0 ) // if read FIFO double buffer
{
for( ; len > 50; )
@@ -280,8 +279,29 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
{
i2c_res = bme680_i2c_read_16( dev_id, reg_addr, data, len, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+int bme680_close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BME680 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
+
#endif
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.h b/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.h
index 5bac549..213130d 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.h
+++ b/Samples/BRAVO_MultiSensorsDemo/src/i2c_bme680.h
@@ -54,4 +54,9 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len );
+/**
+ @brief Closes I2C bme680device channel
+
+*/
+int bme680_close_I2C( void );
#endif /* SRC_I2C_BME680_H_ */
diff --git a/Samples/BRAVO_MultiSensorsDemo/src/sensors_demo.c b/Samples/BRAVO_MultiSensorsDemo/src/sensors_demo.c
index b315f7e..452e74f 100644
--- a/Samples/BRAVO_MultiSensorsDemo/src/sensors_demo.c
+++ b/Samples/BRAVO_MultiSensorsDemo/src/sensors_demo.c
@@ -50,6 +50,7 @@
#include
#include
#include
+#include
#include
#include "m2mb_types.h"
@@ -62,6 +63,7 @@
#include "m2mb_fs_posix.h"
#include "m2mb_fs_errno.h"
+#include "m2mb_wDog.h"
#include "azx_log.h"
#include "azx_utils.h"
@@ -88,11 +90,12 @@
#include "sensors_demo.h"
-/* Local defines ================================================================================*/
-/*
- Bosch device
- */
+extern INT32 bsens_taskId;
+/* Local defines ================================================================================*/
+#define WAKE_UP_TICKS 10 //to be used in m2mb_wDog_enable
+#define CTRL_TICKS_TO_REBOOT 6 //to be used in m2mb_wDog_enable
+#define WD_TOUT_COUNT 3 //to be used in m2mb_wDog_addTask
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
@@ -106,6 +109,17 @@ static BSENS_TAMPER_T gTAMPER_data;
static BSENS_3DVECT_T g3DVECT_data;
+
+#ifdef BSEC_THREAD
+INT32 bsecTaskId;
+#endif
+
+M2MB_WDOG_HANDLE h_wDog;
+UINT32 wd_tick_s;
+UINT32 wd_kick_delay_ms;
+
+
+
/* Local function prototypes ====================================================================*/
/*-----------------------------------------------------------------------------------------------*/
@@ -192,11 +206,54 @@ static void state_save( const uint8_t *state_buffer, uint32_t length );
static uint32_t config_load( uint8_t *config_buffer, uint32_t n_buffer );
+#ifdef BSEC_THREAD
static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2);
+#endif
+
+
+#ifndef BSEC_THREAD
+/*!
+ * @brief custom version of bsec_iot_loop (defined in bsec_integration.c).
+
+ it has no while loop, so it can be called to run only once, but it is up to caller to define when it must be executed next.
+ the sleep function pointer can be used to provide caller with the amount of time that needs to pass before next execution
+ *
+ * @param[in] get_timestamp_us pointer to the system specific timestamp derivation function
+ * @param[in] output_ready pointer to the function processing obtained BSEC outputs
+ * @param[in] state_save pointer to the system-specific state save function
+ * @param[in] save_intvl interval at which BSEC state should be saved (in samples)
+ *
+ * @return none
+ */
+static void bsec_iot_custom_loop(get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
+ state_save_fct state_save, uint32_t save_intvl);
+#endif
+
+static void WDcallback(M2MB_WDOG_HANDLE hDog, M2MB_WDOG_IND_E wDog_event,UINT16 resp_size, void *resp_struct, void *userdata);
+
/*-----------------------------------------------------------------------------------------------*/
/* Static functions =============================================================================*/
+/**
+ @brief returns the current uptime in ms as an unsigned long long int
+
+ @return number of milliseconds elapsed from startup
+*/
+static UINT64 get_u64_uptime_ms(void)
+{
+
+ UINT32 sysTicks = m2mb_os_getSysTicks();
+
+ FLOAT32 ms_per_tick = m2mb_os_getSysTickDuration_ms();
+
+ return (UINT64) (sysTicks * ms_per_tick); //milliseconds
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------------------------*/
static void sensors_tamper_callback( bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id )
{
@@ -300,14 +357,10 @@ static void sensors_tamper_callback( bhy_data_generic_t *sensor_data, bhy_virtua
#endif
}
- /* activity recognition is not time critical, so let's wait a little bit */
- // int tamper_data = 1;
- // updateLWM2MObject(_obj_tamper_uri, &tamper_data, sizeof(int));
- // sensor_ar_timer = SENSOR_AR_TOUT;
- azx_sleep_ms( 200 );
write_LED( M2MB_GPIO_LOW_VALUE );
}
+/*-----------------------------------------------------------------------------------------------*/
static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
bhy_virtual_sensor_t sensor_id )
@@ -334,7 +387,7 @@ static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
/* emit message only if value is different from previous one and it is new */
- if( ( i++ >= 50 ) && is_new_value )
+ if( ( i++ >= (5 * ROTATION_VECTOR_SAMPLE_RATE) ) && is_new_value )
{
#ifndef SKIP_LWM2M
update_rotation_LWM2MObject( w, x, y, z, sensor_data->data_quaternion.estimated_accuracy );
@@ -359,10 +412,9 @@ static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
/*-----------------------------------------------------------------------------------------------*/
static void timestamp_callback( bhy_data_scalar_u16_t *new_timestamp )
{
- //AZX_LOG_DEBUG("new timestamp for id %u: 0x%08X\r\n", new_timestamp->sensor_id, new_timestamp->data);
/* updates the system timestamp */
bhy_update_system_timestamp( new_timestamp, &bhy_system_timestamp );
- //AZX_LOG_DEBUG("updated timestamp: %u\r\n", bhy_system_timestamp);
+
}
@@ -370,8 +422,7 @@ static void timestamp_callback( bhy_data_scalar_u16_t *new_timestamp )
static int64_t get_timestamp_us( void )
{
- int64_t system_current_time = ( int64_t )m2mb_os_getSysTicks() * 10000L;
- return system_current_time;
+ return get_u64_uptime_ms() * 1000L;
}
/*-----------------------------------------------------------------------------------------------*/
@@ -464,7 +515,58 @@ static uint32_t config_load( uint8_t *config_buffer, uint32_t n_buffer )
}
+/*-----------------------------------------------------------------------------------------------*/
+static void WDcallback(M2MB_WDOG_HANDLE hDog, M2MB_WDOG_IND_E wDog_event,UINT16 resp_size, void *resp_struct, void *userdata)
+{
+ (void)hDog;
+ (void)resp_size;
+ (void)resp_struct;
+
+ M2MB_OS_TASK_HANDLE TaskWD_H = (M2MB_OS_TASK_HANDLE)userdata;
+
+ switch (wDog_event)
+ {
+ case M2MB_WDOG_TIMEOUT_IND:
+ {
+ AZX_LOG_INFO("Watchdog expired!\r\n");
+ //kill the task and restart it.
+ AZX_LOG_INFO("Terminate task and restart it.\r\n");
+ m2mb_os_taskTerminate(TaskWD_H);
+ m2mb_os_taskRestart(TaskWD_H);
+ AZX_LOG_INFO("Send a message %d\r\n", azx_tasks_sendMessageToTask(bsens_taskId, TASK_REINIT, 0, 0));
+ ;
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+#ifndef BSEC_THREAD
+static UINT64 bsec_sleep_ms_resume_ts = 0;
+/*-----------------------------------------------------------------------------------------------*/
+static void bsec_sleep(UINT32 ms)
+{
+ UINT64 tmp_ts = get_u64_uptime_ms() + ms;
+ if(tmp_ts < bsec_sleep_ms_resume_ts )
+ {
+ /*overflow in internal counter, compute the right amount*/
+ AZX_LOG_ERROR("OVERFLOWING when asking to sleep %u ms! current value: %llu, it would become %llu\r\n", ms, bsec_sleep_ms_resume_ts, tmp_ts);
+ bsec_sleep_ms_resume_ts = (ULONG_LONG_MAX - bsec_sleep_ms_resume_ts) + tmp_ts;
+ }
+ else
+ {
+
+ bsec_sleep_ms_resume_ts = tmp_ts;
+ }
+}
+#endif
+
+/*-----------------------------------------------------------------------------------------------*/
+#ifdef BSEC_THREAD
static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2)
{
(void) type;
@@ -476,30 +578,217 @@ static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2)
bsec_iot_loop( azx_sleep_ms, get_timestamp_us, bsec_output_ready, state_save, 10000 );
return 0;
}
+#endif
+
+/*-----------------------------------------------------------------------------------------------*/
+#ifndef BSEC_THREAD
+/*all defined in bsec_integration.c*/
+extern void bme680_bsec_trigger_measurement(bsec_bme_settings_t *sensor_settings, sleep_fct sleep);
+extern void bme680_bsec_read_data(int64_t time_stamp_trigger, bsec_input_t *inputs, uint8_t *num_bsec_inputs,
+ int32_t bsec_process_data);
+extern void bme680_bsec_process_data(bsec_input_t *bsec_inputs, uint8_t num_bsec_inputs, output_ready_fct output_ready);
+
+/*!
+ * @brief custom version of bsec_iot_loop (defined in bsec_integration.c).
+
+ it has no while loop, so it can be called to run only once, but it is up to caller to define when it must be executed next.
+ the sleep function pointer can be used to provide caller with the amount of time that needs to pass before next execution
+ *
+ * @param[in] get_timestamp_us pointer to the system specific timestamp derivation function
+ * @param[in] output_ready pointer to the function processing obtained BSEC outputs
+ * @param[in] state_save pointer to the system-specific state save function
+ * @param[in] save_intvl interval at which BSEC state should be saved (in samples)
+ *
+ * @return none
+ */
+static void bsec_iot_custom_loop(get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
+ state_save_fct state_save, uint32_t save_intvl)
+{
+ /* Timestamp variables */
+ int64_t time_stamp = 0;
+ int64_t time_stamp_interval_ms = 0;
+ /* Allocate enough memory for up to BSEC_MAX_PHYSICAL_SENSOR physical inputs*/
+ bsec_input_t bsec_inputs[BSEC_MAX_PHYSICAL_SENSOR];
+ /* Number of inputs to BSEC */
+ uint8_t num_bsec_inputs = 0;
+
+ /* BSEC sensor settings struct */
+ bsec_bme_settings_t sensor_settings;
+
+ /* Save state variables */
+ uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE];
+ uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE];
+ uint32_t bsec_state_len = 0;
+
+ static uint32_t n_samples = 0;
+
+ bsec_library_return_t bsec_status = BSEC_OK;
+
+ {
+ /* get the timestamp in nanoseconds before calling bsec_sensor_control() */
+ time_stamp = get_timestamp_us() * 1000;
+ /* Retrieve sensor settings to be used in this time instant by calling bsec_sensor_control */
+ bsec_sensor_control(time_stamp, &sensor_settings);
+ /* Trigger a measurement if necessary */
+ bme680_bsec_trigger_measurement(&sensor_settings, azx_sleep_ms);
+ /* Read data from last measurement */
+ num_bsec_inputs = 0;
+ bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
+ /* Time to invoke BSEC to perform the actual processing */
+ bme680_bsec_process_data(bsec_inputs, num_bsec_inputs, output_ready);
+
+ /* Increment sample counter */
+ n_samples++;
+
+ /* Retrieve and store state if the passed save_intvl */
+ if (n_samples >= save_intvl)
+ {
+ bsec_status = bsec_get_state(0, bsec_state, sizeof(bsec_state), work_buffer, sizeof(work_buffer), &bsec_state_len);
+ if (bsec_status == BSEC_OK)
+ {
+ state_save(bsec_state, bsec_state_len);
+ }
+ n_samples = 0;
+ }
+
+
+ /* Compute how long we can sleep until we need to call bsec_sensor_control() next */
+ /* Time_stamp is converted from microseconds to nanoseconds first and then the difference to milliseconds */
+ time_stamp_interval_ms = (sensor_settings.next_call - get_timestamp_us() * 1000) / 1000000;
+ if (time_stamp_interval_ms > 0)
+ {
+ bsec_sleep((uint32_t)time_stamp_interval_ms);
+ }
+ }
+}
+#endif
/*-----------------------------------------------------------------------------------------------*/
-int init_sensors( void )
+int run_sensors_loop(int reset)
{
- /* BHY Variable*/
- uint8_t *fifoptr = NULL;
- uint8_t bytes_left_in_fifo = 0;
- uint16_t bytes_remaining = 0;
- uint16_t bytes_read = 0;
+ /* BHY Variables*/
+ uint8_t *fifoptr = NULL;
+ static uint16_t bytes_left_in_fifo = 0;
+ static uint16_t bytes_remaining = 0;
+ static uint16_t bytes_read = 0;
+
+ UINT64 kick_ts = 0;
+
+ bhy_data_generic_t fifo_packet;
+ bhy_data_type_t packet_type;
+ BHY_RETURN_FUNCTION_TYPE result;
+ uint8_t reset_BHI = reset;
+ /* continuously read and parse the fifo after the push of the button*/
+ AZX_LOG_DEBUG("Starting the loop...\r\n");
+ while(1)
+ {
+
+ if(get_u64_uptime_ms() > kick_ts)
+ {
+ kick_ts = get_u64_uptime_ms() + wd_kick_delay_ms;
+ AZX_LOG_INFO("WD kick!\r\n");
+ m2mb_wDog_kick(h_wDog, m2mb_os_taskGetId());
+ }
+ if(reset_BHI == DO_RESET)
+ {
+ AZX_LOG_INFO("Reset parameters and BHI160 FIFO\r\n");
+ reset_BHI = DO_NOT_RESET;
+ memset(fifo, 0, FIFO_SIZE);
+ bytes_left_in_fifo = 0;
+ bytes_remaining = 0;
+ bytes_read = 0;
+
+ result = bhy_set_host_interface_control(BHY_HOST_ABORT_TRANSFER,1);
+ if(result != BHY_SUCCESS)
+ {
+ AZX_LOG_WARN("Abort transfer result: %d\r\n", result);
+ }
+ }
+ /* wait until the interrupt fires */
+ /* unless we already know there are bytes remaining in the fifo */
+ while( !read_gpio() && !bytes_remaining )
+ {
+ azx_sleep_ms( 10 );
+ }
+ bhy_read_fifo( fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read,
+ &bytes_remaining );
+
+
+ bytes_read += bytes_left_in_fifo;
+ fifoptr = fifo;
+ packet_type = BHY_DATA_TYPE_PADDING;
+
+ do
+ {
+ /* this function will call callbacks that are registered */
+ result = bhy_parse_next_fifo_packet( &fifoptr, &bytes_read, &fifo_packet, &packet_type );
- bhy_data_generic_t fifo_packet;
- bhy_data_type_t packet_type;
- BHY_RETURN_FUNCTION_TYPE result;
+ /* prints all the debug packets */
+ if( packet_type == BHY_DATA_TYPE_DEBUG )
+ {
+ bhy_print_debug_packet( &fifo_packet.data_debug, bhy_printf );
+ }
+ /* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
+ /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
+ /* packet */
+ }
+ while( ( result == BHY_SUCCESS ) && ( bytes_read > ( bytes_remaining ? MAX_PACKET_LENGTH : 0 ) ) );
+
+ if(result == BHY_OUT_OF_RANGE && bytes_read > FIFO_SIZE )
+ {
+ AZX_LOG_WARN("Out of sync, reset everything\r\n");
+ uint16_t to_be_flushed = bytes_remaining;
+ while(to_be_flushed > 0)
+ {
+ bhy_read_fifo( fifo, FIFO_SIZE, &bytes_read, &bytes_remaining );
+ to_be_flushed -= bytes_read;
+ azx_sleep_ms( 10 );
+ }
+
+ memset(fifo, 0, FIFO_SIZE);
+ bytes_left_in_fifo = 0;
+ bytes_remaining = 0;
+ bytes_read = 0;
+ azx_sleep_ms( 10 );
+ }
+
+ bytes_left_in_fifo = 0;
+
+ if( bytes_remaining )
+ {
+ /* shifts the remaining bytes to the beginning of the buffer */
+ while( bytes_left_in_fifo < bytes_read )
+ {
+ fifo[bytes_left_in_fifo++] = *( fifoptr++ );
+ }
+
+ }
+#ifndef BSEC_THREAD
+ if(get_u64_uptime_ms() > bsec_sleep_ms_resume_ts)
+ {
+ bsec_iot_custom_loop( get_timestamp_us, bsec_output_ready, state_save, 10000 );
+ }
+#endif
+
+
+ }
+
+ return BHY_SUCCESS;
+}
+/*-----------------------------------------------------------------------------------------------*/
+int init_sensors( void )
+{
return_values_init ret;
- INT32 bsecTaskId;
+
/* the remapping matrix for BHA or BHI here should be configured according to its placement on customer's PCB. */
/* for details, please check 'Application Notes Axes remapping of BHA250(B)/BHI160(B)' document. */
@@ -535,12 +824,6 @@ int init_sensors( void )
azx_sleep_ms( 10 );
}
- /* To get the customized version number in firmware, it is necessary to read Parameter Page 2, index 125 */
- /* to get this information. This feature is only supported for customized firmware. To get this customized */
- /* firmware, you need to contact your local FAE of Bosch Sensortec. */
- //bhy_read_parameter_page(BHY_PAGE_2, PAGE2_CUS_FIRMWARE_VERSION, (uint8_t*)&bhy_cus_version, sizeof(struct cus_version_t));
- //DEBUG("cus version base:%d major:%d minor:%d\n", bhy_cus_version.base, bhy_cus_version.major, bhy_cus_version.minor);
-
/* enables the activity recognition and assigns the callback */
bhy_enable_virtual_sensor( VS_TYPE_ACTIVITY_RECOGNITION, VS_NON_WAKEUP, 1, 0, VS_FLUSH_NONE, 0, 0 );
bhy_install_sensor_callback( VS_TYPE_ACTIVITY_RECOGNITION, VS_NON_WAKEUP, sensors_tamper_callback );
@@ -593,13 +876,14 @@ int init_sensors( void )
}
}
- bsecTaskId = azx_tasks_createTask((char *)"BSEC_LOOP", AZX_TASKS_STACK_XL, 5, AZX_TASKS_MBOX_S, bsec_loop_taskCB);
+#ifdef BSEC_THREAD
+ bsecTaskId = azx_tasks_createTask((char *)"BSEC_LOOP", AZX_TASKS_STACK_XL, 28, AZX_TASKS_MBOX_S, bsec_loop_taskCB);
if(bsecTaskId <= 0)
{
AZX_LOG_CRITICAL("cannot create BSEC task!\r\n");
return BHY_ERROR;
}
-
+#endif
write_LED( M2MB_GPIO_HIGH_VALUE );
azx_sleep_ms( 100 );
@@ -613,56 +897,10 @@ int init_sensors( void )
AZX_LOG_INFO( "System is now monitoring activity for tampering and rotation changes, move the board to update data.\r\n" );
//START BSEC task
+#ifdef BSEC_THREAD
azx_tasks_sendMessageToTask(bsecTaskId, 0, 0, 0);
+#endif
- /* continuously read and parse the fifo after the push of the button*/
- while(1)
- {
- /* wait until the interrupt fires */
- /* unless we already know there are bytes remaining in the fifo */
-
- while( !read_gpio() && !bytes_remaining )
- {
- azx_sleep_ms( 10 );
- }
-
- bhy_read_fifo( fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read,
- &bytes_remaining );
- bytes_read += bytes_left_in_fifo;
- fifoptr = fifo;
- packet_type = BHY_DATA_TYPE_PADDING;
-
-
- do
- {
- /* this function will call callbacks that are registered */
- result = bhy_parse_next_fifo_packet( &fifoptr, &bytes_read, &fifo_packet, &packet_type );
-
- /* prints all the debug packets */
- if( packet_type == BHY_DATA_TYPE_DEBUG )
- {
- bhy_print_debug_packet( &fifo_packet.data_debug, bhy_printf );
- }
-
- /* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
- /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
- /* packet */
- }
- while( ( result == BHY_SUCCESS ) && ( bytes_read > ( bytes_remaining ? MAX_PACKET_LENGTH : 0 ) ) );
-
- bytes_left_in_fifo = 0;
-
- if( bytes_remaining )
- {
- /* shifts the remaining bytes to the beginning of the buffer */
- while( bytes_left_in_fifo < bytes_read )
- {
- fifo[bytes_left_in_fifo++] = *( fifoptr++ );
- }
- }
-
-
- }
return BHY_SUCCESS;
}
@@ -714,13 +952,83 @@ int read_sensor(BSENS_SENSOR_ID_E id, void **data)
*/
void trace_log( const char *fmt, ... )
{
- char log_buffer[256];
+ char log_buffer[512];
va_list arg;
va_start( arg, fmt );
vsnprintf( log_buffer, sizeof( log_buffer ), fmt, arg );
va_end( arg );
- AZX_LOG_INFO( "%s", log_buffer );
+ AZX_LOG_INFO( "###%s", log_buffer );
+}
+
+
+/*-----------------------------------------------------------------------------------------------*/
+void WDog_Init(M2MB_OS_TASK_HANDLE TaskWD_H)
+{
+M2MB_RESULT_E res;
+MEM_W time_ms;
+
+
+ AZX_LOG_INFO("\r\nInit WatchDog\r\n");
+ res = m2mb_wDog_init(&h_wDog, WDcallback, TaskWD_H);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_init OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_init Fail, error: %d\r\n", res);
+ return;
+ }
+
+ /* Verifying tick duration */
+ res = m2mb_wDog_getItem(h_wDog, M2MB_WDOG_SELECT_CMD_TICK_DURATION_MS, 0, &time_ms);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ wd_tick_s = time_ms/1000;
+ AZX_LOG_INFO("Tick duration: %ds\r\n", wd_tick_s);
+ }
+ else
+ {
+ AZX_LOG_ERROR("Get tick duration Fail, error: %d\r\n", res);
+ }
+
+ wd_kick_delay_ms = (WAKE_UP_TICKS - 1 ) * wd_tick_s * 1000;
+
+ AZX_LOG_INFO("Adding Task under WD control with inactivity timeout of %ds\r\n", WD_TOUT_COUNT * WAKE_UP_TICKS * wd_tick_s);
+ /* wdTimeout (inactivity timeout of the task) is set to WD_TOUT_COUNT (3 in this case).
+ * This counter is decreased every time a control is done and no kick have been received. Control is done every WAKE_UP_TICKS.
+ * When the counter reaches 0 a further control is done and if it's still 0 then callback is called,
+ * so task inactivity timeout will be more or less WD_TOUT_COUNT * WAKE_UP_TICKS * 1s
+ */
+ res = m2mb_wDog_addTask(h_wDog, TaskWD_H, WD_TOUT_COUNT);
+
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_addTask OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_addTask Fail\r\n");
+ }
+
+ AZX_LOG_INFO("Enabling the WatchDog\r\n");
+ /* WAKE_UP_TICKS defines the number of ticks of every control, by default the tick is every 1s
+ * CTRL_TICKS_TO_REBOOT this defines the number of controls the wd does before rebooting the app if no kick are received (or no action is done in watchdog callback )
+ * so timeout to reboot is WAKE_UP_TICKS * CTRL_TICKS_TO_REBOOT * 1s
+ */
+ res = m2mb_wDog_enable(h_wDog, WAKE_UP_TICKS, CTRL_TICKS_TO_REBOOT);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_enable OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_enable Fail, error: %d\r\n", res);
+ }
+
}
+
+
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_Rotation_Demo/Makefile.in b/Samples/BRAVO_Rotation_Demo/Makefile.in
index 6f107db..ab27a29 100644
--- a/Samples/BRAVO_Rotation_Demo/Makefile.in
+++ b/Samples/BRAVO_Rotation_Demo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_Rotation_Demo/src/M2MB_main.c b/Samples/BRAVO_Rotation_Demo/src/M2MB_main.c
index d648a61..11442e3 100644
--- a/Samples/BRAVO_Rotation_Demo/src/M2MB_main.c
+++ b/Samples/BRAVO_Rotation_Demo/src/M2MB_main.c
@@ -12,7 +12,7 @@
@description
Rotation Demo application. Debug prints on MAIN UART
@version
- 1.0.4
+ 1.0.5
@note
Start of Appzone: Entry point
User code entry is in function M2MB_main()
@@ -64,7 +64,6 @@
Bosch device
*/
#define INT_GPIO_PIN_NUM 6
-#define LED_INDEX_NUM 2 /* GPIO 10 */
#define SENSOR_AR_TOUT 100 /* 10 = 1 sec */
@@ -329,7 +328,7 @@ void M2MB_main( int argc, char **argv )
VERSION, __DATE__, __TIME__ );
/* Open GPIO */
- if( open_LED( LED_INDEX_NUM ) != 0 )
+ if( open_LED( DEFAULT_LED_INDEX ) != 0 )
{
AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
return;
diff --git a/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.c b/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.h b/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_Rotation_Demo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.c b/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.c
index a5b6d43..e1015c0 100644
--- a/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.c
+++ b/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.c
@@ -43,32 +43,20 @@
/* Local statics ================================================================================*/
static INT32 i2c_fd = -1;
-M2MB_OS_SEM_HANDLE I2C_CSSemHandle = NULL;
-
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
/*-----------------------------------------------------------------------------------------------*/
+
+
+
int open_I2C( void )
{
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
-
-
-
/**************
Configuring the IIC device.
@@ -85,7 +73,10 @@ int open_I2C( void )
AZX_LOG_ERROR( "cannot open I2C channel!\r\n" );
return 1;
}
-
+ else
+ {
+ AZX_LOG_DEBUG("i2d_fd: %d\r\n", i2c_fd);
+ }
config.sclPin = I2C_SCL;
config.sdaPin = I2C_SDA;
config.registerId = 0x00; //dummy register
@@ -112,11 +103,12 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
return 1;
}
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -125,18 +117,18 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", size,
reg );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, p_buf, size );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != size )
{
- AZX_LOG_ERROR( "cannot write data! error: %d\r\n", i2c_res );
+ AZX_LOG_ERROR( "cannot write data on %d! error: %d\r\n", i2c_fd, i2c_res );
return 1;
}
else
@@ -159,7 +151,7 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -173,14 +165,14 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
tmpsize = size;
}
-
+
i2c_res = m2mb_i2c_read( i2c_fd, p_buf, tmpsize ); //reading 16 bytes max at a time
if( i2c_res == tmpsize )
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
for( int i = 0; i < i2c_res; i++ )
@@ -208,16 +200,21 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+ if( i2c_fd == -1 )
+ {
+ return 1;
+ }
+
AZX_LOG_TRACE( "I2C read register..." );
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
if( reg == 0 ) // if read FIFO double buffer
{
for( ; size > 50; )
@@ -233,7 +230,28 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
i2c_res = sensor_i2c_read_16( addr, reg, p_buf, size, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+
+int close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BHI160 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
diff --git a/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.h b/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.h
index 0409bac..89f522f 100644
--- a/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.h
+++ b/Samples/BRAVO_Rotation_Demo/src/demo_utils/i2c.h
@@ -30,11 +30,10 @@
#define BHY_I2C_160B_ADDR1 (UINT16) 0x28
-extern M2MB_OS_SEM_HANDLE I2C_CSSemHandle;
-
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
+
/**
@brief Opens I2C device at BHI160B default address
@@ -66,5 +65,10 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
*/
int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size );
+/**
+ @brief Closes I2C device channel
+
+*/
+int close_I2C( void );
#endif /* SRC_I2C_H_ */
diff --git a/Samples/BRAVO_Rotation_Demo/src/demo_utils/lwm2m.c b/Samples/BRAVO_Rotation_Demo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_Rotation_Demo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_Rotation_Demo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Tampering_Demo/Makefile.in b/Samples/BRAVO_Tampering_Demo/Makefile.in
index 6f107db..ab27a29 100644
--- a/Samples/BRAVO_Tampering_Demo/Makefile.in
+++ b/Samples/BRAVO_Tampering_Demo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_Tampering_Demo/src/M2MB_main.c b/Samples/BRAVO_Tampering_Demo/src/M2MB_main.c
index 0a56192..bf2100a 100644
--- a/Samples/BRAVO_Tampering_Demo/src/M2MB_main.c
+++ b/Samples/BRAVO_Tampering_Demo/src/M2MB_main.c
@@ -12,7 +12,7 @@
@description
Tampering Demo application. Debug prints on MAIN UART
@version
- 1.0.4
+ 1.0.5
@note
Start of Appzone: Entry point
User code entry is in function M2MB_main()
@@ -80,7 +80,7 @@ typedef enum
Bosch device
*/
#define INT_GPIO_PIN_NUM 6
-#define LED_INDEX_NUM 2 /* GPIO 10 */
+
#define SENSOR_AR_TOUT 100 /* 10 = 1 sec */
#ifndef SKIP_LWM2M
@@ -394,7 +394,7 @@ void M2MB_main( int argc, char **argv )
VERSION, __DATE__, __TIME__ );
/* Open GPIO */
- if( open_LED( LED_INDEX_NUM ) != 0 )
+ if( open_LED( DEFAULT_LED_INDEX ) != 0 )
{
AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
return;
diff --git a/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.c b/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.h b/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_Tampering_Demo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.c b/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.c
index a5b6d43..e1015c0 100644
--- a/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.c
+++ b/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.c
@@ -43,32 +43,20 @@
/* Local statics ================================================================================*/
static INT32 i2c_fd = -1;
-M2MB_OS_SEM_HANDLE I2C_CSSemHandle = NULL;
-
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
/*-----------------------------------------------------------------------------------------------*/
+
+
+
int open_I2C( void )
{
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
-
-
-
/**************
Configuring the IIC device.
@@ -85,7 +73,10 @@ int open_I2C( void )
AZX_LOG_ERROR( "cannot open I2C channel!\r\n" );
return 1;
}
-
+ else
+ {
+ AZX_LOG_DEBUG("i2d_fd: %d\r\n", i2c_fd);
+ }
config.sclPin = I2C_SCL;
config.sdaPin = I2C_SDA;
config.registerId = 0x00; //dummy register
@@ -112,11 +103,12 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
return 1;
}
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -125,18 +117,18 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", size,
reg );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, p_buf, size );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != size )
{
- AZX_LOG_ERROR( "cannot write data! error: %d\r\n", i2c_res );
+ AZX_LOG_ERROR( "cannot write data on %d! error: %d\r\n", i2c_fd, i2c_res );
return 1;
}
else
@@ -159,7 +151,7 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -173,14 +165,14 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
tmpsize = size;
}
-
+
i2c_res = m2mb_i2c_read( i2c_fd, p_buf, tmpsize ); //reading 16 bytes max at a time
if( i2c_res == tmpsize )
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
for( int i = 0; i < i2c_res; i++ )
@@ -208,16 +200,21 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+ if( i2c_fd == -1 )
+ {
+ return 1;
+ }
+
AZX_LOG_TRACE( "I2C read register..." );
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
if( reg == 0 ) // if read FIFO double buffer
{
for( ; size > 50; )
@@ -233,7 +230,28 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
i2c_res = sensor_i2c_read_16( addr, reg, p_buf, size, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+
+int close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BHI160 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
diff --git a/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.h b/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.h
index 0409bac..89f522f 100644
--- a/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.h
+++ b/Samples/BRAVO_Tampering_Demo/src/demo_utils/i2c.h
@@ -30,11 +30,10 @@
#define BHY_I2C_160B_ADDR1 (UINT16) 0x28
-extern M2MB_OS_SEM_HANDLE I2C_CSSemHandle;
-
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
+
/**
@brief Opens I2C device at BHI160B default address
@@ -66,5 +65,10 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
*/
int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size );
+/**
+ @brief Closes I2C device channel
+
+*/
+int close_I2C( void );
#endif /* SRC_I2C_H_ */
diff --git a/Samples/BRAVO_Tampering_Demo/src/demo_utils/lwm2m.c b/Samples/BRAVO_Tampering_Demo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_Tampering_Demo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_Tampering_Demo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Time_Series_Demo/BOSCH/BME680/bsec_integration.c b/Samples/BRAVO_Time_Series_Demo/BOSCH/BME680/bsec_integration.c
index f045be7..445d978 100644
--- a/Samples/BRAVO_Time_Series_Demo/BOSCH/BME680/bsec_integration.c
+++ b/Samples/BRAVO_Time_Series_Demo/BOSCH/BME680/bsec_integration.c
@@ -74,11 +74,12 @@
/* header files */
/**********************************************************************************************************************/
-#include "../BME680/bsec_integration.h"
+
#include
#include
#include
+#include "../BME680/bsec_integration.h"
#include
/**********************************************************************************************************************/
@@ -163,9 +164,9 @@ return_values_init bsec_iot_init(float sample_rate, float temperature_offset, bm
return_values_init ret = {BME680_OK, BSEC_OK};
//bsec_library_return_t bsec_status = BSEC_OK;
- uint8_t bsec_state[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint8_t bsec_config[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
- uint8_t work_buffer[BSEC_MAX_PROPERTY_BLOB_SIZE] = {0};
+ uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE] = {0};
int bsec_state_len, bsec_config_len;
/* Fixed I2C configuration */
diff --git a/Samples/BRAVO_Time_Series_Demo/Makefile.in b/Samples/BRAVO_Time_Series_Demo/Makefile.in
index 92dafbc..1668271 100644
--- a/Samples/BRAVO_Time_Series_Demo/Makefile.in
+++ b/Samples/BRAVO_Time_Series_Demo/Makefile.in
@@ -16,7 +16,7 @@ LWM2M = 1
## ---- do not touch below this line
-SW_VER = 1.0.10
+SW_VER = 1.0.12
CLEAN_BEFORE_BUILD = clean
diff --git a/Samples/BRAVO_Time_Series_Demo/hdr/sensors_demo.h b/Samples/BRAVO_Time_Series_Demo/hdr/sensors_demo.h
index eeda73e..a972bb2 100644
--- a/Samples/BRAVO_Time_Series_Demo/hdr/sensors_demo.h
+++ b/Samples/BRAVO_Time_Series_Demo/hdr/sensors_demo.h
@@ -62,7 +62,7 @@
#define MAX_PACKET_LENGTH 18
#define TICKS_IN_ONE_SECOND 32000.0F
-#define ROTATION_VECTOR_SAMPLE_RATE 10 /* Hz */
+#define ROTATION_VECTOR_SAMPLE_RATE 5 /* Hz */
/*BME*/
@@ -84,12 +84,20 @@
#define HIGH_TEMP 350
+#define TASK_INIT 0
+#define TASK_LOOP 1
+#define TASK_REINIT 2
+
+#define DO_NOT_RESET 0
+#define DO_RESET 1
+
/* Global typedefs ==============================================================================*/
typedef enum
{
BSENS_SENSOR_ENVIRONM_ID = 1,
BSENS_SENSOR_3D_VECT_ID = 2,
- BSENS_SENSOR_TAMPER_ID = 3
+ BSENS_SENSOR_TAMPER_ID = 3,
+ BSENS_MAX_ID
} BSENS_SENSOR_ID_E;
@@ -139,13 +147,18 @@ typedef enum
} BHI_TAMPER_STATUS_E;
-typedef INT32 (*sensors_init_cb)(INT32 res, void *arg);
-
/* Global functions =============================================================================*/
/**
- @brief This function is used to run bhy hub
+ @brief This function is used to initialize bhy hub
*/
-int init_sensors( sensors_init_cb cb );
+int init_sensors( void );
+/**
+ @brief This function is used to run bhy hub loop
+*/
+int run_sensors_loop(int reset);
+
+
int read_sensor(BSENS_SENSOR_ID_E id, void **data);
+void WDog_Init(M2MB_OS_TASK_HANDLE TaskWD_H);
#endif /* HDR_SENSORS_DEMO_H_ */
diff --git a/Samples/BRAVO_Time_Series_Demo/src/M2MB_main.c b/Samples/BRAVO_Time_Series_Demo/src/M2MB_main.c
index 9aec786..f785866 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/M2MB_main.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/M2MB_main.c
@@ -12,7 +12,7 @@
@description
Time Series Demo application. Debug prints on MAIN UART
@version
- 1.0.2
+ 1.0.3
@note
Start of Appzone: Entry point
User code entry is in function M2MB_main()
@@ -59,6 +59,12 @@
#include "sensors_demo.h"
+#ifndef BRAVO_REV_B
+#include "i2c_bme680.h"
+#endif
+
+INT32 bsens_taskId;
+M2MB_OS_TASK_HANDLE Task_h;
/* Local defines ================================================================================*/
#define PDU_SIZE 14
@@ -111,7 +117,6 @@ typedef struct
static BOOLEAN is_a_bravo = TRUE;
static M2MB_OS_EV_HANDLE gBoschInitEvH = NULL;
-
static UINT32 gSamplingRate = DEFAULT_SAMPLE_PERIOD;
#if ONE_EDGE
static UINT32 gSendingRate = DEFAULT_SENDING_PERIOD;
@@ -141,7 +146,8 @@ static INT32 lwm2m_monDataTaskCb(INT32 type, INT32 param1, INT32 param2);
#endif
static INT32 dataReadTaskCb(INT32 type, INT32 param1, INT32 param2);
-static INT32 sensorsInitCB(INT32 res, void *arg);
+
+static INT32 sensorsInitCheck(INT32 res);
/* Static functions =============================================================================*/
static UINT32 get_uptime(void)
@@ -327,7 +333,7 @@ static INT32 dataReadTaskCb(INT32 type, INT32 param1, INT32 param2)
{
entry.humidity = 100;
}
-
+
entry.pressure += sign;
if(entry.pressure > 1100)
{
@@ -445,8 +451,8 @@ static INT32 lwm2m_monDataTaskCb(INT32 type, INT32 param1, INT32 param2)
uri.uriLen = M2MB_LWM2M_URI_3_FIELDS;
uri.resource = p_uri->resource;
-
-
+
+
if(M2MB_RESULT_SUCCESS != read_integer_from_uri(getLwM2mHandle(), &uri, &val))
{
AZX_LOG_ERROR("cannot read integer from uri %u/%u/%u/%u !\r\n",
@@ -506,10 +512,8 @@ static INT32 lwm2m_monDataTaskCb(INT32 type, INT32 param1, INT32 param2)
}
#endif
-static INT32 sensorsInitCB(INT32 res, void *arg)
+static INT32 sensorsInitCheck(INT32 res)
{
- (void) arg;
-
if(0 != res)
{
AZX_LOG_WARN("Not a Bravo board, sensors data will be simulated\r\n");
@@ -522,259 +526,295 @@ static INT32 sensorsInitCB(INT32 res, void *arg)
static INT32 demoTaskCb(INT32 type, INT32 param1, INT32 param2)
{
- (void) type;
(void) param1;
(void) param2;
- INT32 taskId;
+
+ switch(type)
+ {
+ case TASK_INIT:
+ {
+ INT32 taskId;
#if ONE_EDGE
- int reboot_needed = 0;
- INT16 instances[] = {0};
- LWM2M_OBJ_REG_T objs[] = {
- {TIME_SERIES_METERING_INFO_OBJ_ID, 1, instances },
- {TIME_SERIES_METERING_RATES_OBJ_ID, 1, instances }
- };
-#endif
+ int reboot_needed = 0;
- /* Open GPIO */
- if( open_LED( LED_INDEX_NUM ) != 0 )
- {
- AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
- return -1;
- }
+ INT16 instances[] = {0};
+ LWM2M_OBJ_REG_T objs[] = {
+ {TIME_SERIES_METERING_INFO_OBJ_ID, 1, instances },
+ {TIME_SERIES_METERING_RATES_OBJ_ID, 1, instances }
+ };
+#endif
+ /* Open GPIO */
+ if( open_LED( LED_INDEX_NUM ) != 0 )
+ {
+ AZX_LOG_ERROR( "Cannot open gpio channel.\r\n" );
+ return -1;
+ }
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 5000 );
- write_LED( M2MB_GPIO_LOW_VALUE );
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 5000 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
#if ONE_EDGE
- /* Copy xml file if not existing */
- if( 0 != check_xml_file( SENDING_OPTS_XML_NAME ) )
- {
- if( 0 != copy_xml_file( SENDING_OPTS_XML_NAME ) )
- {
- AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
-
- for( int i = 0; i < 10; i++ )
+ /* Copy xml file if not existing */
+ if( 0 != check_xml_file( SENDING_OPTS_XML_NAME ) )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 200 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 200 );
- }
+ if( 0 != copy_xml_file( SENDING_OPTS_XML_NAME ) )
+ {
+ AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
- return -1;
- }
- reboot_needed = 1;
- }
+ for( int i = 0; i < 10; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 200 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 200 );
+ }
- /* Copy xml file if not existing */
- if( 0 != check_xml_file( SAMPLING_OPTS_XML_NAME ) )
- {
- if( 0 != copy_xml_file( SAMPLING_OPTS_XML_NAME ) )
- {
- AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
+ return -1;
+ }
+ reboot_needed = 1;
+ }
- for( int i = 0; i < 10; i++ )
+ /* Copy xml file if not existing */
+ if( 0 != check_xml_file( SAMPLING_OPTS_XML_NAME ) )
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 200 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 200 );
- }
+ if( 0 != copy_xml_file( SAMPLING_OPTS_XML_NAME ) )
+ {
+ AZX_LOG_CRITICAL( "Failed copying file!\r\n" );
- return -1;
- }
- reboot_needed = 1;
- }
+ for( int i = 0; i < 10; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 200 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 200 );
+ }
+ return -1;
+ }
+ reboot_needed = 1;
+ }
- if(reboot_needed)
- {
- M2MB_POWER_HANDLE handle;
- AZX_LOG_DEBUG( "Rebooting to apply xml file(s)\r\n" );
- if( M2MB_RESULT_SUCCESS != m2mb_power_init( &handle, NULL, ( void * ) NULL ) )
- {
- AZX_LOG_CRITICAL( "cannot init power module!\r\n" );
- return -1;
- }
- else
- {
- for( int i = 0; i < 3; i++ )
+ if(reboot_needed)
{
- write_LED( M2MB_GPIO_HIGH_VALUE );
- azx_sleep_ms( 1000 );
- write_LED( M2MB_GPIO_LOW_VALUE );
- azx_sleep_ms( 1000 );
- }
+ M2MB_POWER_HANDLE handle;
+ AZX_LOG_DEBUG( "Rebooting to apply xml file(s)\r\n" );
- m2mb_power_reboot( handle );
- m2mb_power_deinit( handle );
- return 0;
- }
- }
+ if( M2MB_RESULT_SUCCESS != m2mb_power_init( &handle, NULL, ( void * ) NULL ) )
+ {
+ AZX_LOG_CRITICAL( "cannot init power module!\r\n" );
+ return -1;
+ }
+ else
+ {
+ for( int i = 0; i < 3; i++ )
+ {
+ write_LED( M2MB_GPIO_HIGH_VALUE );
+ azx_sleep_ms( 1000 );
+ write_LED( M2MB_GPIO_LOW_VALUE );
+ azx_sleep_ms( 1000 );
+ }
+
+ m2mb_power_reboot( handle );
+ m2mb_power_deinit( handle );
+ return 0;
+ }
+ }
#endif
#if BOSCH_BSEC
- /* Open I2C */
- if( open_I2C() != 0 )
- {
- AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
- return -1;
- }
+ /* Open I2C */
+ if( open_I2C() != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
+ return -1;
+ }
#endif
- /* Open GPIO */
- if( open_gpio( INT_GPIO_PIN_NUM ) != 0 )
- {
- AZX_LOG_ERROR( "cannot open gpio channel.\r\n" );
- return -1;
- }
-
-#if ONE_EDGE
-
- /*skip the instances creation*/
- setAsBootstrapped();
-
- if(oneedge_init( objs, 2, NULL ) != 0)
- {
- AZX_LOG_ERROR("Failed enabling LWM2M!\r\n");
- return -1;
- }
+ /* Open GPIO */
+ if( open_gpio( INT_GPIO_PIN_NUM ) != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open gpio channel.\r\n" );
+ return -1;
+ }
- taskId = azx_tasks_createTask((char*) "MON_DATA", AZX_TASKS_STACK_L, 5, AZX_TASKS_MBOX_S, lwm2m_monDataTaskCb);
- if(taskId > 0)
- {
- lwm2m_ReadTaskRegister(taskId);
- }
- else
- {
- return -1;
- }
+#if ONE_EDGE
+ /*skip the instances creation*/
+ setAsBootstrapped();
- /*read values from time series objects for sampling and sending rates*/
- {
- M2MB_LWM2M_OBJ_URI_T uri;
- INT32 val;
- uri.obj = TIME_SERIES_METERING_RATES_OBJ_ID;
- uri.objInst = 0;
- uri.resourceInst = 0;
- uri.uriLen = M2MB_LWM2M_URI_3_FIELDS;
+ if(oneedge_init( objs, 2, NULL ) != 0)
+ {
+ AZX_LOG_ERROR("Failed enabling LWM2M!\r\n");
+ return -1;
+ }
- uri.resource = 1;
- if(M2MB_RESULT_SUCCESS != read_integer_from_uri(getLwM2mHandle(), &uri, &val))
- {
- AZX_LOG_ERROR("cannot read integer from uri %u/%u/%u/%u !\r\n", uri.obj, uri.objInst, uri.resource, uri.resourceInst );
- }
- else
- {
- AZX_LOG_INFO("sampling rate : %d\r\n", val);
- if(val != 0)
+ taskId = azx_tasks_createTask((char*) "MON_DATA", AZX_TASKS_STACK_L, 5, AZX_TASKS_MBOX_S, lwm2m_monDataTaskCb);
+ if(taskId > 0)
{
- gSamplingRate = val * 1000;
+ lwm2m_ReadTaskRegister(taskId);
}
else
{
- /* overwrite the value with the default */
- write_integer_resource(getLwM2mHandle(), &uri, DEFAULT_SAMPLE_PERIOD / 1000);
- gSamplingRate = DEFAULT_SAMPLE_PERIOD;
+ return -1;
}
- }
- azx_sleep_ms(3000);
-
- uri.resource = 2;
- if(M2MB_RESULT_SUCCESS != read_integer_from_uri(getLwM2mHandle(), &uri, &val))
- {
- AZX_LOG_ERROR("cannot read integer from uri %u/%u/%u/%u !\r\n", uri.obj, uri.objInst, uri.resource, uri.resourceInst );
- }
- else
- {
- AZX_LOG_INFO("sending rate : %d\r\n", val);
- if(val != 0)
+ /*read values from time series objects for sampling and sending rates*/
{
- gSendingRate = val * 1000;
- }
- else
- {
- /* overwrite the value with the default */
- write_integer_resource(getLwM2mHandle(), &uri, DEFAULT_SENDING_PERIOD / 1000);
- gSendingRate = DEFAULT_SENDING_PERIOD;
- }
+ M2MB_LWM2M_OBJ_URI_T uri;
+ INT32 val;
+ uri.obj = TIME_SERIES_METERING_RATES_OBJ_ID;
+ uri.objInst = 0;
+ uri.resourceInst = 0;
+ uri.uriLen = M2MB_LWM2M_URI_3_FIELDS;
+
+ uri.resource = 1;
+ if(M2MB_RESULT_SUCCESS != read_integer_from_uri(getLwM2mHandle(), &uri, &val))
+ {
+ AZX_LOG_ERROR("cannot read integer from uri %u/%u/%u/%u !\r\n", uri.obj, uri.objInst, uri.resource, uri.resourceInst );
+ }
+ else
+ {
+ AZX_LOG_INFO("sampling rate : %d\r\n", val);
+ if(val != 0)
+ {
+ gSamplingRate = val * 1000;
+ }
+ else
+ {
+ /* overwrite the value with the default */
+ write_integer_resource(getLwM2mHandle(), &uri, DEFAULT_SAMPLE_PERIOD / 1000);
+ gSamplingRate = DEFAULT_SAMPLE_PERIOD;
+ }
- }
- }
+ }
+
+ azx_sleep_ms(3000);
+
+ uri.resource = 2;
+ if(M2MB_RESULT_SUCCESS != read_integer_from_uri(getLwM2mHandle(), &uri, &val))
+ {
+ AZX_LOG_ERROR("cannot read integer from uri %u/%u/%u/%u !\r\n", uri.obj, uri.objInst, uri.resource, uri.resourceInst );
+ }
+ else
+ {
+ AZX_LOG_INFO("sending rate : %d\r\n", val);
+ if(val != 0)
+ {
+ gSendingRate = val * 1000;
+ }
+ else
+ {
+ /* overwrite the value with the default */
+ write_integer_resource(getLwM2mHandle(), &uri, DEFAULT_SENDING_PERIOD / 1000);
+ gSendingRate = DEFAULT_SENDING_PERIOD;
+ }
+
+ }
+ }
#else
- AZX_LOG_INFO( "Will run without LWM2M data publishing\r\n");
+ AZX_LOG_INFO( "Will run without LWM2M data publishing\r\n");
#endif
+ {
+ /*Critical Section for opaque buffer*/
+ M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
- {
- /*Critical Section for opaque buffer*/
+ m2mb_os_sem_setAttrItem(&semAttrHandle,
+ CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
+ M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
+ M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
+ m2mb_os_sem_init( &opaque.CSSemH, &semAttrHandle );
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &opaque.CSSemH, &semAttrHandle );
+ /*Init opaque*/
+ memset(opaque.buffer, 0, OPAQUE_SIZE);
+ opaque.p = 0;
+ }
- /*Init opaque*/
- memset(opaque.buffer, 0, OPAQUE_SIZE);
- opaque.p = 0;
- }
+ {
+ M2MB_OS_RESULT_E osRes;
+ M2MB_OS_EV_ATTR_HANDLE evAttrHandle;
+ m2mb_os_ev_setAttrItem( &evAttrHandle, CMDS_ARGS(M2MB_OS_EV_SEL_CMD_CREATE_ATTR, NULL));
+ osRes = m2mb_os_ev_init( &gBoschInitEvH, &evAttrHandle );
+ if ( osRes != M2MB_OS_SUCCESS )
+ {
+ m2mb_os_ev_setAttrItem( &evAttrHandle, M2MB_OS_EV_SEL_CMD_DEL_ATTR, NULL );
+ AZX_LOG_CRITICAL("m2mb_os_ev_init failed!\r\n");
+ return -1;
+ }
+ }
- {
- M2MB_OS_RESULT_E osRes;
- M2MB_OS_EV_ATTR_HANDLE evAttrHandle;
- m2mb_os_ev_setAttrItem( &evAttrHandle, CMDS_ARGS(M2MB_OS_EV_SEL_CMD_CREATE_ATTR, NULL));
- osRes = m2mb_os_ev_init( &gBoschInitEvH, &evAttrHandle );
- if ( osRes != M2MB_OS_SUCCESS )
- {
- m2mb_os_ev_setAttrItem( &evAttrHandle, M2MB_OS_EV_SEL_CMD_DEL_ATTR, NULL );
- AZX_LOG_CRITICAL("m2mb_os_ev_init failed!\r\n");
- return -1;
- }
- }
+ taskId = azx_tasks_createTask((char*) "read" , AZX_TASKS_STACK_L, 2, AZX_TASKS_MBOX_S, dataReadTaskCb);
+ if(taskId > 0)
+ {
+ azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+ }
+ else
+ {
+ return -1;
+ }
+#if ONE_EDGE
+ taskId = azx_tasks_createTask((char*) "read" , AZX_TASKS_STACK_L, 3, AZX_TASKS_MBOX_S, dataSendTaskCb);
+ if(taskId > 0)
+ {
+ azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+ }
+ else
+ {
+ return -1;
+ }
+#endif
- taskId = azx_tasks_createTask((char*) "read" , AZX_TASKS_STACK_L, 2, AZX_TASKS_MBOX_S, dataReadTaskCb);
- if(taskId > 0)
- {
- azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+#if BOSCH_BSEC
+ AZX_LOG_DEBUG("Init sensors...\r\n");
+ sensorsInitCheck(init_sensors());
+ Task_h = m2mb_os_taskGetId();
+ /*Store task handle for watchdog*/
+ WDog_Init( Task_h);
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_LOOP, DO_NOT_RESET, 0);
+#else
+ /*skip the sensors initialization*/
+ sensorsInitCheck(-1);
+#endif
}
- else
+ break;
+
+ case TASK_LOOP:
{
- return -1;
+#if BOSCH_BSEC
+ run_sensors_loop(param1);
+#endif
}
-#if ONE_EDGE
- taskId = azx_tasks_createTask((char*) "read" , AZX_TASKS_STACK_L, 3, AZX_TASKS_MBOX_S, dataSendTaskCb);
- if(taskId > 0)
+ break;
+ case TASK_REINIT:
{
- azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+#if BOSCH_BSEC
+ close_I2C();
+ /* Open I2C */
+ if( open_I2C() != 0 )
+ {
+ AZX_LOG_ERROR( "cannot open I2C channel.\r\n" );
+ return -1;
+ }
+ #ifndef BRAVO_REV_B
+ bme680_close_I2C();
+ /*I2C will be reopened by read/write operations*/
+ #endif
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_LOOP, DO_RESET /*reset FIFO and parameters*/, 0);
+#endif
}
- else
- {
- return -1;
+ break;
}
-#endif
-#if BOSCH_BSEC
- AZX_LOG_DEBUG("Init sensors...\r\n");
- init_sensors(sensorsInitCB);
-#else
- /*skip the sensors initialization*/
- sensorsInitCB(-1, NULL);
-#endif
return 0;
}
/* Global functions =============================================================================*/
@@ -792,7 +832,7 @@ void M2MB_main( int argc, char **argv )
{
( void )argc;
( void )argv;
- INT32 taskId;
+
azx_tasks_init();
/* SET output channel */
@@ -801,11 +841,11 @@ void M2MB_main( int argc, char **argv )
VERSION, __DATE__, __TIME__ );
- taskId = azx_tasks_createTask((char*) "BSENS" , AZX_TASKS_STACK_XL, 1, AZX_TASKS_MBOX_S, demoTaskCb);
- if(taskId > 0)
+ bsens_taskId = azx_tasks_createTask((char*) "BSENS" , AZX_TASKS_STACK_XL, 4, AZX_TASKS_MBOX_S, demoTaskCb);
+ if(bsens_taskId > 0)
{
- azx_tasks_sendMessageToTask(taskId, 0, 0, 0);
+ azx_tasks_sendMessageToTask(bsens_taskId, TASK_INIT, 0, 0);
}
else
{
diff --git a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.c b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.c
index 0c7a008..f04c00a 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.c
@@ -176,7 +176,7 @@ M2MB_GPIO_VALUE_E read_gpio( void )
/*-----------------------------------------------------------------------------------------------*/
void write_LED( M2MB_GPIO_VALUE_E value )
{
- m2mb_gpio_write( led_fd[0], value );
+ m2mb_gpio_write( led_fd[DEFAULT_LED_INDEX], value );
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.h b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.h
index 7b0592e..72a5bce 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.h
+++ b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/gpio.h
@@ -30,6 +30,9 @@
#define YELLOW_LED_GPIO 9
#define GREEN_LED_GPIO 10
+#define DEFAULT_LED_INDEX 2 /* GPIO 10 */
+
+
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
diff --git a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.c b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.c
index a5b6d43..e1015c0 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.c
@@ -43,32 +43,20 @@
/* Local statics ================================================================================*/
static INT32 i2c_fd = -1;
-M2MB_OS_SEM_HANDLE I2C_CSSemHandle = NULL;
-
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
/*-----------------------------------------------------------------------------------------------*/
+
+
+
int open_I2C( void )
{
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
-
-
-
/**************
Configuring the IIC device.
@@ -85,7 +73,10 @@ int open_I2C( void )
AZX_LOG_ERROR( "cannot open I2C channel!\r\n" );
return 1;
}
-
+ else
+ {
+ AZX_LOG_DEBUG("i2d_fd: %d\r\n", i2c_fd);
+ }
config.sclPin = I2C_SCL;
config.sdaPin = I2C_SDA;
config.registerId = 0x00; //dummy register
@@ -112,11 +103,12 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
return 1;
}
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -125,18 +117,18 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", size,
reg );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, p_buf, size );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != size )
{
- AZX_LOG_ERROR( "cannot write data! error: %d\r\n", i2c_res );
+ AZX_LOG_ERROR( "cannot write data on %d! error: %d\r\n", i2c_fd, i2c_res );
return 1;
}
else
@@ -159,7 +151,7 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot set I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot set I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
@@ -173,14 +165,14 @@ int8_t sensor_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
tmpsize = size;
}
-
+
i2c_res = m2mb_i2c_read( i2c_fd, p_buf, tmpsize ); //reading 16 bytes max at a time
if( i2c_res == tmpsize )
{
size = size - tmpsize;
reg = reg + tmpsize;
-
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
for( int i = 0; i < i2c_res; i++ )
@@ -208,16 +200,21 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+ if( i2c_fd == -1 )
+ {
+ return 1;
+ }
+
AZX_LOG_TRACE( "I2C read register..." );
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
{
- AZX_LOG_ERROR( "Cannot get I2C channel configuration\r\n" );
+ AZX_LOG_ERROR( "Cannot get I2C channel configuration on %d\r\n", i2c_fd );
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
if( reg == 0 ) // if read FIFO double buffer
{
for( ; size > 50; )
@@ -233,7 +230,28 @@ int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size
{
i2c_res = sensor_i2c_read_16( addr, reg, p_buf, size, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+
+int close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BHI160 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
diff --git a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.h b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.h
index 0409bac..89f522f 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.h
+++ b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/i2c.h
@@ -30,11 +30,10 @@
#define BHY_I2C_160B_ADDR1 (UINT16) 0x28
-extern M2MB_OS_SEM_HANDLE I2C_CSSemHandle;
-
/* Global typedefs ==============================================================================*/
/* Global functions =============================================================================*/
+
/**
@brief Opens I2C device at BHI160B default address
@@ -66,5 +65,10 @@ int8_t sensor_i2c_write( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t siz
*/
int8_t sensor_i2c_read( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size );
+/**
+ @brief Closes I2C device channel
+
+*/
+int close_I2C( void );
#endif /* SRC_I2C_H_ */
diff --git a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/lwm2m.c b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/lwm2m.c
index 12199e9..5266131 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/demo_utils/lwm2m.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/demo_utils/lwm2m.c
@@ -1056,43 +1056,86 @@ void update_tamper_LWM2MObject(int value)
/*-----------------------------------------------------------------------------------------------*/
void update_environment_LWM2MObject(float _t, float _p, float _rh, INT16 _iaq) {
M2MB_OS_RESULT_E osRes;
+ INT32 iaq = _iaq;
+
m2mb_os_sem_get(lwm2m_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
M2MB_RESULT_E retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_t,
&_t, sizeof(float));
- azx_sleep_ms(10);
+ if (retVal != M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_p, &_p,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
+ }
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_h, &_rh,
sizeof(float));
- azx_sleep_ms(10);
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
- retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &_iaq,
- sizeof(INT16));
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
+ }
+
+ retVal = m2mb_lwm2m_set(lwm2mHandle, &_obj_environment_uri_iaq, &iaq,
+ sizeof(INT32));
if (retVal != M2MB_RESULT_SUCCESS)
{
AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
+ goto end;
}
-
- osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
- M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
- if (osRes != M2MB_OS_SUCCESS) {
- AZX_LOG_ERROR("LWM2M write failure\r\n");
+ else
+ {
+ osRes = m2mb_os_ev_get(eventsHandleLwm2m, EV_LWM2M_SET_RES_BIT,
+ M2MB_OS_EV_GET_ANY_AND_CLEAR, NULL, M2MB_OS_MS2TICKS(10000));
+ if (osRes != M2MB_OS_SUCCESS)
+ {
+ AZX_LOG_ERROR("LWM2M write failure\r\n");
+ goto end;
+ }
}
+
+end:
m2mb_os_sem_put(lwm2m_CSSemHandle);
- if (retVal != M2MB_RESULT_SUCCESS) {
- AZX_LOG_ERROR("m2mb_lwm2m_set returned error %d\r\n", retVal);
- return;
- }
}
/*-----------------------------------------------------------------------------------------------*/
diff --git a/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.c b/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.c
index aac51e0..7399444 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.c
@@ -46,7 +46,11 @@
/* Local defines ================================================================================*/
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
+#ifndef BRAVO_REV_B
static INT32 i2c_fd = -1;
+#endif
+
+
/* Local function prototypes ====================================================================*/
/* Static functions =============================================================================*/
/* Global functions =============================================================================*/
@@ -86,16 +90,6 @@ int bme680_openI2C( uint8_t dev_id )
INT32 res;
CHAR dev_ID[64];
M2MB_I2C_CFG_T config;
- M2MB_OS_SEM_ATTR_HANDLE semAttrHandle;
-
- if (NULL == I2C_CSSemHandle)
- {
- m2mb_os_sem_setAttrItem(&semAttrHandle,
- CMDS_ARGS(M2MB_OS_SEM_SEL_CMD_CREATE_ATTR, NULL,
- M2MB_OS_SEM_SEL_CMD_COUNT, 1 /*CS*/,
- M2MB_OS_SEM_SEL_CMD_TYPE, M2MB_OS_SEM_GEN));
- m2mb_os_sem_init( &I2C_CSSemHandle, &semAttrHandle );
- }
/**************
Configuring the IIC device.
@@ -136,6 +130,7 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
AZX_LOG_TRACE( "bme680_i2c_write\r\n" );
AZX_LOG_TRACE( "bme680_i2c_write LEN = %d\r\n", len );
+
if( i2c_fd == -1 )
{
i2c_res = bme680_openI2C(dev_id);
@@ -146,6 +141,8 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
}
}
+
+
i2c_res = m2mb_i2c_ioctl( i2c_fd, M2MB_I2C_IOCTL_GET_CFG, ( void * )&config );
if( i2c_res != 0 )
@@ -160,15 +157,16 @@ int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16
if( i2c_res != 0 )
{
AZX_LOG_ERROR( "cannot set I2C channel configuration\r\n" );
+
return 1;
}
AZX_LOG_TRACE( "Configuring I2C Registers - Writing %d bytes into 0x%02X register...\r\n", len,
reg_addr );
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
i2c_res = m2mb_i2c_write( i2c_fd, data, len );
- m2mb_os_sem_put(I2C_CSSemHandle);
+
if( i2c_res != len )
{
@@ -216,16 +214,18 @@ int8_t bme680_i2c_read_16( uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t s
{
size = size - tmpsize;
reg = reg + tmpsize;
- p_buf = p_buf + tmpsize;
+
AZX_LOG_TRACE( "Reading Success.\r\n" );
AZX_LOG_TRACE( "i2c->" );
- for( int i = 1; i < i2c_res; i++ )
+ for( int i = 0; i < i2c_res; i++ )
{
AZX_LOG_TRACE( " %02x", p_buf[i] );
}
AZX_LOG_TRACE( "\r\n" );
+
+ p_buf = p_buf + tmpsize;
}
else
{
@@ -246,6 +246,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
INT32 i2c_res;
M2MB_I2C_CFG_T config;
+
AZX_LOG_TRACE( "bme680_i2c_read\r\n" );
AZX_LOG_TRACE( "bme680_i2c_read LEN = %d\r\n", len );
@@ -269,7 +270,7 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
return 1;
}
- m2mb_os_sem_get(I2C_CSSemHandle, M2MB_OS_WAIT_FOREVER);
+
if( reg_addr == 0 ) // if read FIFO double buffer
{
for( ; len > 50; )
@@ -285,8 +286,29 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
{
i2c_res = bme680_i2c_read_16( dev_id, reg_addr, data, len, &config );
}
- m2mb_os_sem_put(I2C_CSSemHandle);
+
return i2c_res;
}
+
+int bme680_close_I2C( void )
+{
+ INT32 res;
+
+ AZX_LOG_INFO( "\r\nClosing the Bosch BME680 I2C channel...\r\n" );
+
+ res = m2mb_i2c_close( i2c_fd);
+
+ if( -1 == res )
+ {
+ AZX_LOG_ERROR( "cannot close I2C channel!\r\n" );
+ return 1;
+ }
+ else
+ {
+ i2c_fd = -1;
+ return 0;
+ }
+}
+
#endif
diff --git a/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.h b/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.h
index 5bac549..213130d 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.h
+++ b/Samples/BRAVO_Time_Series_Demo/src/i2c_bme680.h
@@ -54,4 +54,9 @@ int8_t bme680_i2c_read( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_
int8_t bme680_i2c_write( uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len );
+/**
+ @brief Closes I2C bme680device channel
+
+*/
+int bme680_close_I2C( void );
#endif /* SRC_I2C_BME680_H_ */
diff --git a/Samples/BRAVO_Time_Series_Demo/src/sensors_demo.c b/Samples/BRAVO_Time_Series_Demo/src/sensors_demo.c
index 2d1826c..14adc57 100644
--- a/Samples/BRAVO_Time_Series_Demo/src/sensors_demo.c
+++ b/Samples/BRAVO_Time_Series_Demo/src/sensors_demo.c
@@ -50,6 +50,7 @@
#include
#include
#include
+#include
#include
#include "m2mb_types.h"
@@ -62,6 +63,7 @@
#include "m2mb_fs_posix.h"
#include "m2mb_fs_errno.h"
+#include "m2mb_wDog.h"
#include "azx_log.h"
#include "azx_utils.h"
@@ -95,11 +97,14 @@
#include "sensors_demo.h"
-/* Local defines ================================================================================*/
-/*
- Bosch device
- */
+extern INT32 bsens_taskId;
+/* Local defines ================================================================================*/
+#if BOSCH_BSEC
+#define WAKE_UP_TICKS 10 //to be used in m2mb_wDog_enable
+#define CTRL_TICKS_TO_REBOOT 6 //to be used in m2mb_wDog_enable
+#define WD_TOUT_COUNT 3 //to be used in m2mb_wDog_addTask
+#endif
/* Local typedefs ===============================================================================*/
/* Local statics ================================================================================*/
@@ -114,11 +119,20 @@ static BSENS_TAMPER_T gTAMPER_data;
static BSENS_3DVECT_T g3DVECT_data;
+#if BOSCH_BSEC
+#ifdef BSEC_THREAD
+INT32 bsecTaskId;
+#endif
+M2MB_WDOG_HANDLE h_wDog;
+UINT32 wd_tick_s;
+UINT32 wd_kick_delay_ms;
+#endif
+
/* Local function prototypes ====================================================================*/
/*-----------------------------------------------------------------------------------------------*/
-#if BOSCH_BSEC
+
/**
@brief This is the callback function used to acquire sensor data
@@ -143,7 +157,7 @@ static void timestamp_callback( bhy_data_scalar_u16_t *new_timestamp );
@brief Capture the system time in microseconds
@return system_current_time current system timestamp in microseconds
- */
+*/
static int64_t get_timestamp_us( void );
/**
@@ -161,12 +175,12 @@ static int64_t get_timestamp_us( void );
@param[in] bsec_status value returned by the bsec_do_steps() call
@return none
- */
+*/
static void bsec_output_ready( int64_t timestamp, float iaq, uint8_t iaq_accuracy, float temperature,
- float humidity,
- float pressure, float raw_temperature, float raw_humidity, float gas,
- bsec_library_return_t bsec_status,
- float static_iaq, float co2_equivalent, float breath_voc_equivalent );
+ float humidity,
+ float pressure, float raw_temperature, float raw_humidity, float gas,
+ bsec_library_return_t bsec_status,
+ float static_iaq, float co2_equivalent, float breath_voc_equivalent );
/**
@@ -176,7 +190,7 @@ static void bsec_output_ready( int64_t timestamp, float iaq, uint8_t iaq_accurac
@param[in] n_buffer size of the allocated state buffer
@return number of bytes copied to state_buffer
- */
+*/
static uint32_t state_load( uint8_t *state_buffer, uint32_t n_buffer );
@@ -187,7 +201,7 @@ static uint32_t state_load( uint8_t *state_buffer, uint32_t n_buffer );
@param[in] length length of the state string to be stored
@return none
- */
+*/
static void state_save( const uint8_t *state_buffer, uint32_t length );
@@ -198,15 +212,58 @@ static void state_save( const uint8_t *state_buffer, uint32_t length );
@param[in] n_buffer size of the allocated state buffer
@return number of bytes copied to config_buffer
- */
+*/
static uint32_t config_load( uint8_t *config_buffer, uint32_t n_buffer );
+#ifdef BSEC_THREAD
static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2);
+#endif
+
+
+#ifndef BSEC_THREAD
+/*!
+ * @brief custom version of bsec_iot_loop (defined in bsec_integration.c).
+
+ it has no while loop, so it can be called to run only once, but it is up to caller to define when it must be executed next.
+ the sleep function pointer can be used to provide caller with the amount of time that needs to pass before next execution
+ *
+ * @param[in] get_timestamp_us pointer to the system specific timestamp derivation function
+ * @param[in] output_ready pointer to the function processing obtained BSEC outputs
+ * @param[in] state_save pointer to the system-specific state save function
+ * @param[in] save_intvl interval at which BSEC state should be saved (in samples)
+ *
+ * @return none
+ */
+static void bsec_iot_custom_loop(get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
+ state_save_fct state_save, uint32_t save_intvl);
+#endif
+
+static void WDcallback(M2MB_WDOG_HANDLE hDog, M2MB_WDOG_IND_E wDog_event,UINT16 resp_size, void *resp_struct, void *userdata);
+
/*-----------------------------------------------------------------------------------------------*/
/* Static functions =============================================================================*/
+/**
+ @brief returns the current uptime in ms as an unsigned long long int
+
+ @return number of milliseconds elapsed from startup
+*/
+static UINT64 get_u64_uptime_ms(void)
+{
+
+ UINT32 sysTicks = m2mb_os_getSysTicks();
+
+ FLOAT32 ms_per_tick = m2mb_os_getSysTickDuration_ms();
+
+ return (UINT64) (sysTicks * ms_per_tick); //milliseconds
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------------------------*/
static void sensors_tamper_callback( bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id )
{
@@ -308,14 +365,10 @@ static void sensors_tamper_callback( bhy_data_generic_t *sensor_data, bhy_virtua
}
- /* activity recognition is not time critical, so let's wait a little bit */
- // int tamper_data = 1;
- // updateLWM2MObject(_obj_tamper_uri, &tamper_data, sizeof(int));
- // sensor_ar_timer = SENSOR_AR_TOUT;
- azx_sleep_ms( 200 );
write_LED( M2MB_GPIO_LOW_VALUE );
}
+/*-----------------------------------------------------------------------------------------------*/
static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
bhy_virtual_sensor_t sensor_id )
@@ -342,7 +395,7 @@ static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
/* emit message only if value is different from previous one and it is new */
- if( ( i++ >= 50 ) && is_new_value )
+ if( ( i++ >= (5 * ROTATION_VECTOR_SAMPLE_RATE) ) && is_new_value )
{
i = 0;
AZX_LOG_INFO( "-------> w=%f, x=%f, y=%f, z=%f; acc=%d\r\n",
@@ -364,10 +417,9 @@ static void sensors_callback_rotation_vector( bhy_data_generic_t *sensor_data,
/*-----------------------------------------------------------------------------------------------*/
static void timestamp_callback( bhy_data_scalar_u16_t *new_timestamp )
{
- //AZX_LOG_DEBUG("new timestamp for id %u: 0x%08X\r\n", new_timestamp->sensor_id, new_timestamp->data);
/* updates the system timestamp */
bhy_update_system_timestamp( new_timestamp, &bhy_system_timestamp );
- //AZX_LOG_DEBUG("updated timestamp: %u\r\n", bhy_system_timestamp);
+
}
@@ -375,16 +427,15 @@ static void timestamp_callback( bhy_data_scalar_u16_t *new_timestamp )
static int64_t get_timestamp_us( void )
{
- int64_t system_current_time = ( int64_t )m2mb_os_getSysTicks() * 10000L;
- return system_current_time;
+ return get_u64_uptime_ms() * 1000L;
}
/*-----------------------------------------------------------------------------------------------*/
static void bsec_output_ready( int64_t timestamp, float iaq, uint8_t iaq_accuracy, float temperature,
- float humidity,
- float pressure, float raw_temperature, float raw_humidity, float gas,
- bsec_library_return_t bsec_status,
- float static_iaq, float co2_equivalent, float breath_voc_equivalent )
+ float humidity,
+ float pressure, float raw_temperature, float raw_humidity, float gas,
+ bsec_library_return_t bsec_status,
+ float static_iaq, float co2_equivalent, float breath_voc_equivalent )
{
( void ) timestamp;
( void ) iaq_accuracy;
@@ -405,13 +456,6 @@ static void bsec_output_ready( int64_t timestamp, float iaq, uint8_t iaq_accurac
gENVIRON_data.pressure = pressure / 100;
gENVIRON_data.airQ = iaq;
- // if( demult++ > 2 )
- // {
- // update_environment_LWM2MObject( temperature, pressure / 100., humidity, ( INT16 )iaq );
- // demult = 0;
- // AZX_LOG_INFO( "------>" );
- // }
-
demult++;
if(demult >= 4)
{
@@ -469,7 +513,58 @@ static uint32_t config_load( uint8_t *config_buffer, uint32_t n_buffer )
}
+/*-----------------------------------------------------------------------------------------------*/
+static void WDcallback(M2MB_WDOG_HANDLE hDog, M2MB_WDOG_IND_E wDog_event,UINT16 resp_size, void *resp_struct, void *userdata)
+{
+ (void)hDog;
+ (void)resp_size;
+ (void)resp_struct;
+
+ M2MB_OS_TASK_HANDLE TaskWD_H = (M2MB_OS_TASK_HANDLE)userdata;
+
+ switch (wDog_event)
+ {
+ case M2MB_WDOG_TIMEOUT_IND:
+ {
+ AZX_LOG_INFO("Watchdog expired!\r\n");
+ //kill the task and restart it.
+ AZX_LOG_INFO("Terminate task and restart it.\r\n");
+ m2mb_os_taskTerminate(TaskWD_H);
+ m2mb_os_taskRestart(TaskWD_H);
+ AZX_LOG_INFO("Send a message %d\r\n", azx_tasks_sendMessageToTask(bsens_taskId, TASK_REINIT, 0, 0));
+ ;
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+
+#ifndef BSEC_THREAD
+static UINT64 bsec_sleep_ms_resume_ts = 0;
+/*-----------------------------------------------------------------------------------------------*/
+static void bsec_sleep(UINT32 ms)
+{
+ UINT64 tmp_ts = get_u64_uptime_ms() + ms;
+ if(tmp_ts < bsec_sleep_ms_resume_ts )
+ {
+ /*overflow in internal counter, compute the right amount*/
+ AZX_LOG_ERROR("OVERFLOWING when asking to sleep %u ms! current value: %llu, it would become %llu\r\n", ms, bsec_sleep_ms_resume_ts, tmp_ts);
+ bsec_sleep_ms_resume_ts = (ULONG_LONG_MAX - bsec_sleep_ms_resume_ts) + tmp_ts;
+ }
+ else
+ {
+
+ bsec_sleep_ms_resume_ts = tmp_ts;
+ }
+}
+#endif
+/*-----------------------------------------------------------------------------------------------*/
+#ifdef BSEC_THREAD
static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2)
{
(void) type;
@@ -481,32 +576,219 @@ static INT32 bsec_loop_taskCB(INT32 type, INT32 param1, INT32 param2)
bsec_iot_loop( azx_sleep_ms, get_timestamp_us, bsec_output_ready, state_save, 10000 );
return 0;
}
+#endif
+/*-----------------------------------------------------------------------------------------------*/
+#ifndef BSEC_THREAD
+/*all defined in bsec_integration.c*/
+extern void bme680_bsec_trigger_measurement(bsec_bme_settings_t *sensor_settings, sleep_fct sleep);
+extern void bme680_bsec_read_data(int64_t time_stamp_trigger, bsec_input_t *inputs, uint8_t *num_bsec_inputs,
+ int32_t bsec_process_data);
+extern void bme680_bsec_process_data(bsec_input_t *bsec_inputs, uint8_t num_bsec_inputs, output_ready_fct output_ready);
+/*!
+ * @brief custom version of bsec_iot_loop (defined in bsec_integration.c).
+
+ it has no while loop, so it can be called to run only once, but it is up to caller to define when it must be executed next.
+ the sleep function pointer can be used to provide caller with the amount of time that needs to pass before next execution
+ *
+ * @param[in] get_timestamp_us pointer to the system specific timestamp derivation function
+ * @param[in] output_ready pointer to the function processing obtained BSEC outputs
+ * @param[in] state_save pointer to the system-specific state save function
+ * @param[in] save_intvl interval at which BSEC state should be saved (in samples)
+ *
+ * @return none
+ */
+static void bsec_iot_custom_loop(get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
+ state_save_fct state_save, uint32_t save_intvl)
+{
+ /* Timestamp variables */
+ int64_t time_stamp = 0;
+ int64_t time_stamp_interval_ms = 0;
-#endif /*#if BOSCH_BSEC*/
+ /* Allocate enough memory for up to BSEC_MAX_PHYSICAL_SENSOR physical inputs*/
+ bsec_input_t bsec_inputs[BSEC_MAX_PHYSICAL_SENSOR];
+ /* Number of inputs to BSEC */
+ uint8_t num_bsec_inputs = 0;
+ /* BSEC sensor settings struct */
+ bsec_bme_settings_t sensor_settings;
+ /* Save state variables */
+ uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE];
+ uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE];
+ uint32_t bsec_state_len = 0;
+
+ static uint32_t n_samples = 0;
+
+ bsec_library_return_t bsec_status = BSEC_OK;
+
+ {
+ /* get the timestamp in nanoseconds before calling bsec_sensor_control() */
+ time_stamp = get_timestamp_us() * 1000;
+
+ /* Retrieve sensor settings to be used in this time instant by calling bsec_sensor_control */
+ bsec_sensor_control(time_stamp, &sensor_settings);
+
+ /* Trigger a measurement if necessary */
+ bme680_bsec_trigger_measurement(&sensor_settings, azx_sleep_ms);
+
+ /* Read data from last measurement */
+ num_bsec_inputs = 0;
+ bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
+
+ /* Time to invoke BSEC to perform the actual processing */
+ bme680_bsec_process_data(bsec_inputs, num_bsec_inputs, output_ready);
+
+ /* Increment sample counter */
+ n_samples++;
+
+ /* Retrieve and store state if the passed save_intvl */
+ if (n_samples >= save_intvl)
+ {
+ bsec_status = bsec_get_state(0, bsec_state, sizeof(bsec_state), work_buffer, sizeof(work_buffer), &bsec_state_len);
+ if (bsec_status == BSEC_OK)
+ {
+ state_save(bsec_state, bsec_state_len);
+ }
+ n_samples = 0;
+ }
+
+
+ /* Compute how long we can sleep until we need to call bsec_sensor_control() next */
+ /* Time_stamp is converted from microseconds to nanoseconds first and then the difference to milliseconds */
+ time_stamp_interval_ms = (sensor_settings.next_call - get_timestamp_us() * 1000) / 1000000;
+ if (time_stamp_interval_ms > 0)
+ {
+ bsec_sleep((uint32_t)time_stamp_interval_ms);
+ }
+ }
+}
+#endif
-/*-----------------------------------------------------------------------------------------------*/
-int init_sensors( sensors_init_cb cb )
+/*-----------------------------------------------------------------------------------------------*/
+int run_sensors_loop(int reset)
{
#if BOSCH_BSEC
- /* BHY Variable*/
- uint8_t *fifoptr = NULL;
- uint8_t bytes_left_in_fifo = 0;
- uint16_t bytes_remaining = 0;
- uint16_t bytes_read = 0;
+ /* BHY Variables*/
+ uint8_t *fifoptr = NULL;
+ static uint16_t bytes_left_in_fifo = 0;
+ static uint16_t bytes_remaining = 0;
+ static uint16_t bytes_read = 0;
+
+ UINT64 kick_ts = 0;
+
+ bhy_data_generic_t fifo_packet;
+ bhy_data_type_t packet_type;
+ BHY_RETURN_FUNCTION_TYPE result;
+ uint8_t reset_BHI = reset;
+ /* continuously read and parse the fifo after the push of the button*/
+ AZX_LOG_DEBUG("Starting the loop...\r\n");
+ while(1)
+ {
+
+ if(get_u64_uptime_ms() > kick_ts)
+ {
+ kick_ts = get_u64_uptime_ms() + wd_kick_delay_ms;
+ AZX_LOG_INFO("WD kick!\r\n");
+ m2mb_wDog_kick(h_wDog, m2mb_os_taskGetId());
+ }
+ if(reset_BHI == DO_RESET)
+ {
+ AZX_LOG_INFO("Reset parameters and BHI160 FIFO\r\n");
+ reset_BHI = DO_NOT_RESET;
+ memset(fifo, 0, FIFO_SIZE);
+ bytes_left_in_fifo = 0;
+ bytes_remaining = 0;
+ bytes_read = 0;
+
+ result = bhy_set_host_interface_control(BHY_HOST_ABORT_TRANSFER,1);
+ if(result != BHY_SUCCESS)
+ {
+ AZX_LOG_WARN("Abort transfer result: %d\r\n", result);
+ }
+ }
+ /* wait until the interrupt fires */
+ /* unless we already know there are bytes remaining in the fifo */
+ while( !read_gpio() && !bytes_remaining )
+ {
+ azx_sleep_ms( 10 );
+ }
+ bhy_read_fifo( fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read,
+ &bytes_remaining );
+
+
+ bytes_read += bytes_left_in_fifo;
+ fifoptr = fifo;
+ packet_type = BHY_DATA_TYPE_PADDING;
+
+ do
+ {
+ /* this function will call callbacks that are registered */
+ result = bhy_parse_next_fifo_packet( &fifoptr, &bytes_read, &fifo_packet, &packet_type );
+
+ /* prints all the debug packets */
+ if( packet_type == BHY_DATA_TYPE_DEBUG )
+ {
+ bhy_print_debug_packet( &fifo_packet.data_debug, bhy_printf );
+ }
+
+ /* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
+ /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
+ /* packet */
+ }
+ while( ( result == BHY_SUCCESS ) && ( bytes_read > ( bytes_remaining ? MAX_PACKET_LENGTH : 0 ) ) );
+
+ if(result == BHY_OUT_OF_RANGE && bytes_read > FIFO_SIZE )
+ {
+ AZX_LOG_WARN("Out of sync, reset everything\r\n");
+ uint16_t to_be_flushed = bytes_remaining;
+ while(to_be_flushed > 0)
+ {
+ bhy_read_fifo( fifo, FIFO_SIZE, &bytes_read, &bytes_remaining );
+ to_be_flushed -= bytes_read;
+ azx_sleep_ms( 10 );
+ }
+
+ memset(fifo, 0, FIFO_SIZE);
+ bytes_left_in_fifo = 0;
+ bytes_remaining = 0;
+ bytes_read = 0;
+
+ azx_sleep_ms( 10 );
+ }
+
+ bytes_left_in_fifo = 0;
- bhy_data_generic_t fifo_packet;
- bhy_data_type_t packet_type;
- BHY_RETURN_FUNCTION_TYPE result;
+ if( bytes_remaining )
+ {
+ /* shifts the remaining bytes to the beginning of the buffer */
+ while( bytes_left_in_fifo < bytes_read )
+ {
+ fifo[bytes_left_in_fifo++] = *( fifoptr++ );
+ }
+
+ }
+#ifndef BSEC_THREAD
+ if(get_u64_uptime_ms() > bsec_sleep_ms_resume_ts)
+ {
+ bsec_iot_custom_loop( get_timestamp_us, bsec_output_ready, state_save, 10000 );
+ }
+#endif
+ }
+#endif
+ return BHY_SUCCESS;
+}
+/*-----------------------------------------------------------------------------------------------*/
+int init_sensors( void )
+{
+#if BOSCH_BSEC
return_values_init ret;
- INT32 bsecTaskId;
+
/* the remapping matrix for BHA or BHI here should be configured according to its placement on customer's PCB. */
/* for details, please check 'Application Notes Axes remapping of BHA250(B)/BHI160(B)' document. */
@@ -528,10 +810,6 @@ int init_sensors( sensors_init_cb cb )
if( bhy_driver_init( bhy_firmware_image ) )
{
AZX_LOG_CRITICAL( "Fail to init bhy\r\n" );
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR;
}
@@ -546,12 +824,6 @@ int init_sensors( sensors_init_cb cb )
azx_sleep_ms( 10 );
}
- /* To get the customized version number in firmware, it is necessary to read Parameter Page 2, index 125 */
- /* to get this information. This feature is only supported for customized firmware. To get this customized */
- /* firmware, you need to contact your local FAE of Bosch Sensortec. */
- //bhy_read_parameter_page(BHY_PAGE_2, PAGE2_CUS_FIRMWARE_VERSION, (uint8_t*)&bhy_cus_version, sizeof(struct cus_version_t));
- //DEBUG("cus version base:%d major:%d minor:%d\n", bhy_cus_version.base, bhy_cus_version.major, bhy_cus_version.minor);
-
/* enables the activity recognition and assigns the callback */
bhy_enable_virtual_sensor( VS_TYPE_ACTIVITY_RECOGNITION, VS_NON_WAKEUP, 1, 0, VS_FLUSH_NONE, 0, 0 );
bhy_install_sensor_callback( VS_TYPE_ACTIVITY_RECOGNITION, VS_NON_WAKEUP, sensors_tamper_callback );
@@ -572,10 +844,6 @@ int init_sensors( sensors_init_cb cb )
sensors_callback_rotation_vector ) )
{
AZX_LOG_ERROR( "Fail to install rotation sensor callback\r\n" );
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR;
}
@@ -584,26 +852,18 @@ int init_sensors( sensors_init_cb cb )
VS_FLUSH_NONE, 0, 0 ) )
{
AZX_LOG_ERROR( "Fail to enable rotation sensor id=%d\r\n", VS_TYPE_ROTATION_VECTOR );
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR;
}
/*INIT BSEC for environmental*/
ret = bsec_iot_init( BSEC_SAMPLE_RATE_LP, 0.0f, bme680_i2c_write, bme680_i2c_read, azx_sleep_ms,
- state_load, config_load );
+ state_load, config_load );
if( ret.bme680_status )
{
/* Could not intialize BME680 */
AZX_LOG_CRITICAL( "Could not intialize BME680: %d\r\n", ret.bme680_status );
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR; // (int)ret.bme680_status;
}
else
@@ -612,25 +872,18 @@ int init_sensors( sensors_init_cb cb )
{
/* Could not intialize BSEC library */
AZX_LOG_ERROR( "Could not intialize BSEC library\r\n" );
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR; // (int)ret.bsec_status;
}
}
- bsecTaskId = azx_tasks_createTask((char *)"BSEC_LOOP", AZX_TASKS_STACK_XL, 5, AZX_TASKS_MBOX_S, bsec_loop_taskCB);
+#ifdef BSEC_THREAD
+ bsecTaskId = azx_tasks_createTask((char *)"BSEC_LOOP", AZX_TASKS_STACK_XL, 28, AZX_TASKS_MBOX_S, bsec_loop_taskCB);
if(bsecTaskId <= 0)
{
AZX_LOG_CRITICAL("cannot create BSEC task!\r\n");
- if(cb)
- {
- cb(BHY_ERROR, NULL);
- }
return BHY_ERROR;
}
-
+#endif
write_LED( M2MB_GPIO_HIGH_VALUE );
azx_sleep_ms( 100 );
@@ -644,69 +897,13 @@ int init_sensors( sensors_init_cb cb )
AZX_LOG_INFO( "System is now monitoring activity for tampering and rotation changes, move the board to update data.\r\n" );
//START BSEC task
+#ifdef BSEC_THREAD
azx_tasks_sendMessageToTask(bsecTaskId, 0, 0, 0);
+#endif
- /*signal caller that init has been done*/
-
- if(cb)
- {
- cb(BHY_SUCCESS, NULL);
- }
-
- /* continuously read and parse the fifo after the push of the button*/
- while(1)
- {
- /* wait until the interrupt fires */
- /* unless we already know there are bytes remaining in the fifo */
-
- while( !read_gpio() && !bytes_remaining )
- {
- azx_sleep_ms( 10 );
- }
-
- bhy_read_fifo( fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read,
- &bytes_remaining );
- bytes_read += bytes_left_in_fifo;
- fifoptr = fifo;
- packet_type = BHY_DATA_TYPE_PADDING;
-
-
- do
- {
- /* this function will call callbacks that are registered */
- result = bhy_parse_next_fifo_packet( &fifoptr, &bytes_read, &fifo_packet, &packet_type );
-
- /* prints all the debug packets */
- if( packet_type == BHY_DATA_TYPE_DEBUG )
- {
- bhy_print_debug_packet( &fifo_packet.data_debug, bhy_printf );
- }
-
- /* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
- /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
- /* packet */
- }
- while( ( result == BHY_SUCCESS ) && ( bytes_read > ( bytes_remaining ? MAX_PACKET_LENGTH : 0 ) ) );
-
- bytes_left_in_fifo = 0;
-
- if( bytes_remaining )
- {
- /* shifts the remaining bytes to the beginning of the buffer */
- while( bytes_left_in_fifo < bytes_read )
- {
- fifo[bytes_left_in_fifo++] = *( fifoptr++ );
- }
- }
-
-
- }
-
return BHY_SUCCESS;
#else
- (void) cb;
return 0;
-
#endif /*#if BOSCH_BSEC*/
}
@@ -749,7 +946,7 @@ int read_sensor(BSENS_SENSOR_ID_E id, void **data)
return BHY_SUCCESS;
#else
return 0;
-
+
#endif /*#if BOSCH_BSEC*/
}
@@ -763,13 +960,83 @@ int read_sensor(BSENS_SENSOR_ID_E id, void **data)
*/
void trace_log( const char *fmt, ... )
{
- char log_buffer[256];
+ char log_buffer[512];
va_list arg;
va_start( arg, fmt );
vsnprintf( log_buffer, sizeof( log_buffer ), fmt, arg );
va_end( arg );
- AZX_LOG_INFO( "%s", log_buffer );
+ AZX_LOG_INFO( "###%s", log_buffer );
}
+
+/*-----------------------------------------------------------------------------------------------*/
+void WDog_Init(M2MB_OS_TASK_HANDLE TaskWD_H)
+{
+M2MB_RESULT_E res;
+MEM_W time_ms;
+
+
+ AZX_LOG_INFO("\r\nInit WatchDog\r\n");
+ res = m2mb_wDog_init(&h_wDog, WDcallback, TaskWD_H);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_init OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_init Fail, error: %d\r\n", res);
+ return;
+ }
+
+ /* Verifying tick duration */
+ res = m2mb_wDog_getItem(h_wDog, M2MB_WDOG_SELECT_CMD_TICK_DURATION_MS, 0, &time_ms);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ wd_tick_s = time_ms/1000;
+ AZX_LOG_INFO("Tick duration: %ds\r\n", wd_tick_s);
+ }
+ else
+ {
+ AZX_LOG_ERROR("Get tick duration Fail, error: %d\r\n", res);
+ }
+
+ wd_kick_delay_ms = (WAKE_UP_TICKS - 1 ) * wd_tick_s * 1000;
+
+ AZX_LOG_INFO("Adding Task under WD control with inactivity timeout of %ds\r\n", WD_TOUT_COUNT * WAKE_UP_TICKS * wd_tick_s);
+ /* wdTimeout (inactivity timeout of the task) is set to WD_TOUT_COUNT (3 in this case).
+ * This counter is decreased every time a control is done and no kick have been received. Control is done every WAKE_UP_TICKS.
+ * When the counter reaches 0 a further control is done and if it's still 0 then callback is called,
+ * so task inactivity timeout will be more or less WD_TOUT_COUNT * WAKE_UP_TICKS * 1s
+ */
+ res = m2mb_wDog_addTask(h_wDog, TaskWD_H, WD_TOUT_COUNT);
+
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_addTask OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_addTask Fail\r\n");
+ }
+
+ AZX_LOG_INFO("Enabling the WatchDog\r\n");
+ /* WAKE_UP_TICKS defines the number of ticks of every control, by default the tick is every 1s
+ * CTRL_TICKS_TO_REBOOT this defines the number of controls the wd does before rebooting the app if no kick are received (or no action is done in watchdog callback )
+ * so timeout to reboot is WAKE_UP_TICKS * CTRL_TICKS_TO_REBOOT * 1s
+ */
+ res = m2mb_wDog_enable(h_wDog, WAKE_UP_TICKS, CTRL_TICKS_TO_REBOOT);
+ if (res == M2MB_RESULT_SUCCESS)
+ {
+ AZX_LOG_INFO("m2mb_wDog_enable OK\r\n");
+ }
+ else
+ {
+ AZX_LOG_ERROR("m2mb_wDog_enable Fail, error: %d\r\n", res);
+ }
+
+}
+
+
+
/* Global functions =============================================================================*/
diff --git a/Samples/README.md b/Samples/README.md
index 2de1285..25a2ad5 100644
--- a/Samples/README.md
+++ b/Samples/README.md
@@ -4,7 +4,7 @@
-Package Version: **1.0.10**
+Package Version: **1.0.12**
Firmware Version: **30.01.XX0.0**