L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mymems.h File Reference
#include "stm32wlxx_hal.h"
#include "mysensors_base.h"
Include dependency graph for mymems.h:
This graph shows which files directly or indirectly include this file:

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 ()
 
  • reading of main block from flash. If there is not valid MEMS_SIGN, the structure is initialize to 0 The main block it stored on address 0

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_tmems_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().

Macro Definition Documentation

◆ SZ_DATABLOCK

#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.

Warning
This value is critical – any change in the set of active sensors changes SENSORS_DATASIZE and therefore SZ_DATABLOCK, requiring a memory reset.

Definition at line 28 of file mymems.h.

Referenced by mems_Init().

◆ SZ_MAINBLOCK

#define SZ_MAINBLOCK   64

Size in bytes of the mems_MainBlock_t structure written at flash address 0.

Warning
This value is critical – changing it without resetting the flash will cause misaligned reads and data corruption.

Definition at line 20 of file mymems.h.

Referenced by mems_Init().

Enumeration Type Documentation

◆ 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)

Definition at line 64 of file mymems.h.

Function Documentation

◆ getBackUpRegister()

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).

Parameters
backupRegisterBackup 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)
Returns
uint32_t The 32-bit value stored in the backup register

Definition at line 337 of file mymems.c.

References hrtc.

Referenced by main().

Here is the caller graph for this function:

◆ mems_AddData()

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

Parameters
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)
Return values
HAL_OKor 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_Check()

HAL_StatusTypeDef mems_Check ( int8_t correct)

Check the memory consist.

Parameters
correct- correct - means to reset all sensor data
Return values
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
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)
Return values
HAL_OKor 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_InicBuffer()

mems_DataBlock_t * mems_InicBuffer ( mems_DataType_t type)

Initialize the work buffer - _memsDataBlock.

Return values
returnpointer to buffer

Definition at line 160 of file mymems.c.

References _memsDataBlock, and MEMS_SIGN_BLOCK.

Referenced by mems_AddData(), and myloraWan_MeasureFinish().

Here is the caller graph for this function:

◆ mems_Init()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_ReadMainBlock()

HAL_StatusTypeDef mems_ReadMainBlock ( )

  • reading of main block from flash. If there is not valid MEMS_SIGN, the structure is initialize to 0 The main block it stored on address 0

Return values
HAL_OKor 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_RemoveLastData()

void mems_RemoveLastData ( uint8_t fromEndTo)

remove last data

Parameters
fromEndToremove 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_Reset()

HAL_StatusTypeDef mems_Reset ( )

memory reset - remove sign from chip

  • Return values
    status

Definition at line 125 of file mymems.c.

References _flash, flash_at25_Write(), and MEMS_MAINBLOCK_ADDR.

Referenced by checkResetRestart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_WriteMainBlock()

HAL_StatusTypeDef mems_WriteMainBlock ( )

writing the main block on flash. The main block is stored on address 0

Return values
HAL_OKor 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mems_WriteToSystemParams()

uint8_t mems_WriteToSystemParams ( )

write data from memory to systemParams

Return values
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBackUpRegister()

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.

Parameters
backupRegisterBackup 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)
valueThe 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().

Here is the caller graph for this function:

Variable Documentation

◆ _memsMainBlock