|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
Go to the source code of this file.
Data Structures | |
| struct | mems_MainBlock_t |
| Master control block stored at flash address 0. More... | |
| struct | mems_DataBlock_t |
| Sensor data record stored as one element in the flash circular queue. More... | |
Macros | |
| #define | SZ_MAINBLOCK 64 |
| Size in bytes of the mems_MainBlock_t structure written at flash address 0. | |
| #define | SZ_DATABLOCK (5+SENSORS_DATASIZE) |
| Size in bytes of one mems_DataBlock_t entry in the circular data queue. Equals 5 bytes of header plus SENSORS_DATASIZE bytes of payload. | |
Enumerations | |
| enum | mems_DataType_t { MEMS_DATATYPE_NON , MEMS_DATATYPE_SENSOR } |
| Type tag stored in each mems_DataBlock_t to identify the payload format. Used when reading back blocks from the circular queue so the caller knows how to interpret the Data[] field. More... | |
Functions | |
| void | mems_Init () |
| Initialise NFC and external flash; load the main block and system parameters. Verifies the flash signature and resets the queue if the block size has changed. | |
| HAL_StatusTypeDef | mems_ReadMainBlock () |
| |
| HAL_StatusTypeDef | mems_WriteMainBlock () |
| writing the main block on flash. The main block is stored on address 0 | |
| HAL_StatusTypeDef | mems_Reset () |
| memory reset - remove sign from chip | |
| mems_DataBlock_t * | mems_InicBuffer (mems_DataType_t type) |
| Initialize the work buffer - _memsDataBlock. | |
| HAL_StatusTypeDef | mems_AddData (const void *data, mems_DataType_t type, uint8_t size) |
| write new data of sensor at the end of queue, if is no space, the most older data start to rewrites | |
| HAL_StatusTypeDef | mems_GetLastData (mems_DataBlock_t **memBlock, uint8_t inxFromEnd) |
| Get the last sensor data if exists. The data and mem block is stored in work buffer, which can be modify by other mems_xxxx function, temporary valid only. | |
| HAL_StatusTypeDef | mems_Check (int8_t correct) |
| Check the memory consist. | |
| void | mems_RemoveLastData (uint8_t fromEndTo) |
| remove last data | |
| uint8_t | mems_WriteToSystemParams () |
| write data from memory to systemParams | |
| uint32_t | getBackUpRegister (uint32_t backupRegister) |
| Read a value from an RTC backup register. | |
| void | setBackUpRegister (uint32_t backupRegister, uint32_t value) |
| Write a value to an RTC backup register. | |
Variables | |
| mems_MainBlock_t | _memsMainBlock |
| Global instance of the main flash control block; loaded by mems_ReadMainBlock(). | |
| #define SZ_DATABLOCK (5+SENSORS_DATASIZE) |
Size in bytes of one mems_DataBlock_t entry in the circular data queue. Equals 5 bytes of header plus SENSORS_DATASIZE bytes of payload.
Definition at line 28 of file mymems.h.
Referenced by mems_Init().
| #define SZ_MAINBLOCK 64 |
Size in bytes of the mems_MainBlock_t structure written at flash address 0.
Definition at line 20 of file mymems.h.
Referenced by mems_Init().
| enum mems_DataType_t |
Type tag stored in each mems_DataBlock_t to identify the payload format. Used when reading back blocks from the circular queue so the caller knows how to interpret the Data[] field.
| Enumerator | |
|---|---|
| MEMS_DATATYPE_NON | Unspecified / uninitialised block – should not appear in valid data |
| MEMS_DATATYPE_SENSOR | Payload contains a packed sensor data record (all active sensors) |
| uint32_t getBackUpRegister | ( | uint32_t | backupRegister | ) |
Read a value from an RTC backup register.
This function reads a 32-bit value from one of the RTC backup registers. These registers are retained during system standby mode and after system reset (as long as VDD is maintained or VBAT is supplied).
| backupRegister | Backup register index (0-19 for STM32WL). Should use RTC_BKP_DRx constants defined in stm32wlxx_hal_rtc_ex.h (e.g., RTC_BKP_DR0=0, RTC_BKP_DR1=1, ..., RTC_BKP_DR19=19) |
Definition at line 337 of file mymems.c.
References hrtc.
Referenced by main().
| HAL_StatusTypeDef mems_AddData | ( | const void * | data, |
| mems_DataType_t | type, | ||
| uint8_t | size ) |
write new data of sensor at the end of queue, if is no space, the most older data start to rewrites
| data | - the buffer, NULL(other parameter are ignored, if used the main default work buffer - _memsDataBlock) |
| type | - type of data, optional |
| size | - buffer, must be <= to SENSORS_DATASIZE (_memsMainBlock.Sens_ItemSize) |
| HAL_OK | or error |
Definition at line 168 of file mymems.c.
References _flash, _memsDataBlock, _memsMainBlock, flash_at25_Write(), mems_GetAddr(), mems_InicBuffer(), mems_SetOffset(), and mems_WriteMainBlock().
Referenced by myloraWan_MeasureFinish().
| HAL_StatusTypeDef mems_Check | ( | int8_t | correct | ) |
Check the memory consist.
| correct | - correct - means to reset all sensor data |
| HAL_OK | - memory is OK, HAL_ERROR - error |
Definition at line 213 of file mymems.c.
References _flash, _memsDataBlock, _memsMainBlock, Error_Handler(), flash_at25_Read(), mems_GetAddr(), mems_SetOffset(), MEMS_SIGN_BLOCK, mems_WriteMainBlock(), mens_MainBlockInit(), and writeLog().
Referenced by mems_ReadMainBlock().
| HAL_StatusTypeDef mems_GetLastData | ( | mems_DataBlock_t ** | memBlock, |
| uint8_t | inxFromEnd ) |
Get the last sensor data if exists. The data and mem block is stored in work buffer, which can be modify by other mems_xxxx function, temporary valid only.
| memBlock | - pointer to mem block with data |
| inxFromEnd | - the index from end of memory, which is reading to buffer (0 - last, 1 - before last, etc) |
| HAL_OK | or error, HAL_BUSY no more data |
Definition at line 194 of file mymems.c.
References _flash, _memsDataBlock, _memsMainBlock, flash_at25_Read(), mems_GetAddr(), and mems_SetOffset().
Referenced by myLoraWan_LastDataSend().
| mems_DataBlock_t * mems_InicBuffer | ( | mems_DataType_t | type | ) |
Initialize the work buffer - _memsDataBlock.
| return | pointer to buffer |
Definition at line 160 of file mymems.c.
References _memsDataBlock, and MEMS_SIGN_BLOCK.
Referenced by mems_AddData(), and myloraWan_MeasureFinish().
| void mems_Init | ( | ) |
Initialise NFC and external flash; load the main block and system parameters. Verifies the flash signature and resets the queue if the block size has changed.
Definition at line 52 of file mymems.c.
References _flash, _memsMainBlock, Error_Handler(), flash_at25_Init(), mems_ReadMainBlock(), mens_MainBlockInit(), SZ_DATABLOCK, SZ_MAINBLOCK, and writeLog().
Referenced by main().
| HAL_StatusTypeDef mems_ReadMainBlock | ( | ) |
| HAL_OK | or error |
Definition at line 93 of file mymems.c.
References _flash, _memsMainBlock, flash_at25_Read(), mems_Check(), MEMS_MAINBLOCK_ADDR, MEMS_SIGN, mems_WriteMainBlock(), mens_MainBlockInit(), and writeLog().
Referenced by mems_Init().
| void mems_RemoveLastData | ( | uint8_t | fromEndTo | ) |
remove last data
| fromEndTo | remove from last to index, 0 - last, 1 - last&before last, etc |
Definition at line 242 of file mymems.c.
References _memsMainBlock, mems_SetOffset(), and mems_WriteMainBlock().
Referenced by OnLoRaWANTxData().
| HAL_StatusTypeDef mems_Reset | ( | ) |
memory reset - remove sign from chip
| status |
Definition at line 125 of file mymems.c.
References _flash, flash_at25_Write(), and MEMS_MAINBLOCK_ADDR.
Referenced by checkResetRestart().
| HAL_StatusTypeDef mems_WriteMainBlock | ( | ) |
writing the main block on flash. The main block is stored on address 0
| HAL_OK | or error |
Definition at line 117 of file mymems.c.
References _flash, _memsMainBlock, flash_at25_Write(), and MEMS_MAINBLOCK_ADDR.
Referenced by amb_tsl2591_On(), bar_bmp585_On(), bar_ils22qs_On(), mems_AddData(), mems_Check(), mems_ReadMainBlock(), mems_RemoveLastData(), scd41_On(), sps30_On(), and tmphm_sht45_On().
| uint8_t mems_WriteToSystemParams | ( | ) |
write data from memory to systemParams
| 0 | - data same-no changes, number is count of different changes |
.MaxSensorData = 0, // will be updated later, according to memory chip .CurrentCountSensorData = 0, // will be updated later, according to memory chip .BatteryLevelStatus = 0, // will be updated later .BatteryMV = 0, // will be updated later, according to memory chip
Definition at line 268 of file mymems.c.
References _memsMainBlock, _systemParams, GetBatteryLevel(), and SYS_GetBatteryLevel().
Referenced by main().
| void setBackUpRegister | ( | uint32_t | backupRegister, |
| uint32_t | value ) |
Write a value to an RTC backup register.
This function writes a 32-bit value to one of the RTC backup registers. These registers are retained during system standby mode and after system reset (as long as VDD is maintained or VBAT is supplied).
Use this function to save critical data before entering standby mode. On restart, read the values using getBackUpRegister() to check system state and restore necessary information.
| backupRegister | Backup register index (0-19 for STM32WL). Should use RTC_BKP_DRx constants defined in stm32wlxx_hal_rtc_ex.h (e.g., RTC_BKP_DR0=0, RTC_BKP_DR1=1, ..., RTC_BKP_DR19=19) |
| value | The 32-bit value to store in the backup register |
Definition at line 358 of file mymems.c.
References hrtc.
Referenced by main(), and PWR_EnterOffMode().
|
extern |
Global instance of the main flash control block; loaded by mems_ReadMainBlock().
Definition at line 27 of file mymems.c.
Referenced by amb_tsl2591_On(), bar_bmp585_On(), bar_ils22qs_On(), mems_AddData(), mems_Check(), mems_GetAddr(), mems_GetLastData(), mems_Init(), mems_ReadMainBlock(), mems_RemoveLastData(), mems_SetOffset(), mems_WriteMainBlock(), mems_WriteToSystemParams(), mens_MainBlockInit(), myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), scd41_On(), sps30_On(), and tmphm_sht45_On().