|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "mymems.h"#include "main.h"#include "flash_at25.h"#include "spi.h"#include "rtc.h"#include "mysensors_base.h"#include "mysensors.h"#include "nfc.h"#include "sys_app.h"#include "adc_if.h"#include "utils/mydefs.h"#include "utils/utils.h"#include <string.h>Go to the source code of this file.
Macros | |
| #define | MEMS_SIGN "MTK0001" |
| #define | MEMS_SIGN_BLOCK "TM" |
| #define | MEMS_MAINBLOCK_ADDR 0 |
| #define | MEMS_DATA_BITS_BOUNDARY 5 |
Functions | |
| static void | mems_SetCRC () |
| static uint8_t | mems_CheckCRC () |
| static void | mens_MainBlockInit () |
| 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 | |
| static uint32_t | mems_SetOffset (uint32_t offset, int16_t count) |
| move the offset in circular queue | |
| static uint32_t | mems_GetAddr (uint32_t offset) |
| 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 | |
| void | mems_ReadFromSystemParams () |
| read data from NFC to mems block | |
| void | nfc_st25r3_OnMailboxData (uint8_t *data, uint16_t len) |
| 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(). | |
| static flash_at25CS_t | _flash |
| static mems_DataBlock_t | _memsDataBlock = {} |
| #define MEMS_DATA_BITS_BOUNDARY 5 |
Definition at line 26 of file mymems.c.
Referenced by mens_MainBlockInit().
| #define MEMS_MAINBLOCK_ADDR 0 |
Definition at line 25 of file mymems.c.
Referenced by mems_ReadMainBlock(), mems_Reset(), mems_WriteMainBlock(), and mens_MainBlockInit().
| #define MEMS_SIGN "MTK0001" |
Definition at line 23 of file mymems.c.
Referenced by mems_ReadMainBlock(), and mens_MainBlockInit().
| #define MEMS_SIGN_BLOCK "TM" |
Definition at line 24 of file mymems.c.
Referenced by mems_Check(), and mems_InicBuffer().
| 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 376 of file mymems.c.
References hrtc.
| 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 for save, 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 195 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 240 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().
|
static |
Definition at line 41 of file mymems.c.
References _memsMainBlock, and calculateCrc().
Referenced by mems_ReadMainBlock().
|
static |
Definition at line 181 of file mymems.c.
References _memsMainBlock.
Referenced by mems_AddData(), mems_Check(), and mems_GetLastData().
| 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 221 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 187 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 66 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().
| void mems_ReadFromSystemParams | ( | ) |
read data from NFC to mems block
Definition at line 331 of file mymems.c.
References _memsMainBlock, and _systemParams.
Referenced by main().
| HAL_StatusTypeDef mems_ReadMainBlock | ( | ) |
| HAL_OK | or error |
Definition at line 119 of file mymems.c.
References _flash, _memsMainBlock, CLAMP, flash_at25_Read(), mems_Check(), mems_CheckCRC(), 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 269 of file mymems.c.
References _memsMainBlock, mems_SetOffset(), and mems_WriteMainBlock().
Referenced by OnLoRaWANRxData().
| HAL_StatusTypeDef mems_Reset | ( | ) |
memory reset - remove sign from chip
| status |
Definition at line 152 of file mymems.c.
References _flash, flash_at25_Write(), and MEMS_MAINBLOCK_ADDR.
Referenced by checkResetRestart().
|
static |
Definition at line 36 of file mymems.c.
References _memsMainBlock, and calculateCrc().
Referenced by mems_WriteMainBlock(), and mens_MainBlockInit().
|
static |
move the offset in circular queue
Definition at line 164 of file mymems.c.
References _memsMainBlock, Error_Handler(), INX_GET, and writeLog().
Referenced by mems_AddData(), mems_Check(), mems_GetLastData(), and mems_RemoveLastData().
| 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 142 of file mymems.c.
References _flash, _memsMainBlock, flash_at25_Write(), MEMS_MAINBLOCK_ADDR, and mems_SetCRC().
Referenced by bar_bmp585_On(), mems_AddData(), mems_Check(), mems_ReadMainBlock(), mems_RemoveLastData(), sensors_CayennelFromBckData(), and tmphm_sht45_On().
| uint8_t mems_WriteToSystemParams | ( | ) |
write data from memory to systemParams
.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 295 of file mymems.c.
References _memsMainBlock, _systemParams, GetBatteryLevel(), and SYS_GetBatteryLevel().
Referenced by main().
|
static |
Definition at line 47 of file mymems.c.
References _memsMainBlock, AT25_MEMSIZE, MEMS_DATA_BITS_BOUNDARY, MEMS_MAINBLOCK_ADDR, mems_SetCRC(), and MEMS_SIGN.
Referenced by mems_Check(), mems_Init(), and mems_ReadMainBlock().
| void nfc_st25r3_OnMailboxData | ( | uint8_t * | data, |
| uint16_t | len ) |
| 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.
do not call HAL_PWR_EnableBkUpAccess and HAL_PWR_DisableBkUpAccess, the HAL_PWR_EnableBkUpAccess is calling in SystemClock_Config
| 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 399 of file mymems.c.
References hrtc.
|
static |
Definition at line 31 of file mymems.c.
Referenced by mems_AddData(), mems_Check(), mems_GetLastData(), mems_Init(), mems_ReadMainBlock(), mems_Reset(), and mems_WriteMainBlock().
|
static |
Definition at line 34 of file mymems.c.
Referenced by mems_AddData(), mems_Check(), mems_GetLastData(), and mems_InicBuffer().
| mems_MainBlock_t _memsMainBlock = {} |
Global instance of the main flash control block; loaded by mems_ReadMainBlock().
Definition at line 29 of file mymems.c.
Referenced by bar_bmp585_On(), mems_AddData(), mems_Check(), mems_CheckCRC(), mems_GetAddr(), mems_GetLastData(), mems_Init(), mems_ReadFromSystemParams(), mems_ReadMainBlock(), mems_RemoveLastData(), mems_SetCRC(), mems_SetOffset(), mems_WriteMainBlock(), mems_WriteToSystemParams(), mens_MainBlockInit(), myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), sensors_CayennelFromBckData(), and tmphm_sht45_On().