23#define MEMS_SIGN "MTK0001"
24#define MEMS_SIGN_BLOCK "TM"
25#define MEMS_MAINBLOCK_ADDR 0
26#define MEMS_DATA_BITS_BOUNDARY 5
68 HAL_StatusTypeDef status;
104 writeLog(
"flash12 data: Init %s", (status == HAL_OK) ?
"OK" :
"failed");
105 if (status == HAL_OK)
115 writeLog(
"flash12 data: MainBlock %s", (status == HAL_OK) ?
"OK" :
"failed");
121 HAL_StatusTypeDef status;
125 if (status == HAL_OK)
134 writeLog(
"data: MainBlock default write %s", (status == HAL_OK) ?
"OK" :
"failed");
144 HAL_StatusTypeDef status = HAL_OK;
154 HAL_StatusTypeDef status;
155 const char buf[] =
"XXXX";
169 writeLog(
"mems_MoveAddr: module is not 0!");
197 HAL_StatusTypeDef status = HAL_ERROR;
223 HAL_StatusTypeDef status = HAL_BUSY;
231 if (memBlock != NULL)
242 HAL_StatusTypeDef status = HAL_OK;
246 for (i = 0; i <
_memsMainBlock.Data_CountCurrent && HAL_OK == status; i++)
275 int16_t count = fromEndTo + 1;
378 return HAL_RTCEx_BKUPRead(&
hrtc, backupRegister);
402 HAL_RTCEx_BKUPWrite(&
hrtc, backupRegister, value);
Header for ADC interface configuration.
uint16_t SYS_GetBatteryLevel(void)
Get the current battery level.
HAL_StatusTypeDef flash_at25_Read(const flash_at25CS_t *s, uint32_t addr, void *buffer, uint16_t size)
Fast read from flash memory Uses fast read command (0x0B) for improved performance in frequent read o...
HAL_StatusTypeDef flash_at25_Write(const flash_at25CS_t *s, uint32_t addr, const void *data, uint16_t size)
Write to flash memory with sector preservation Handles page-aligned writes efficiently with proper ve...
HAL_StatusTypeDef flash_at25_Init(flash_at25CS_t *s)
Initialization for AT25EU0041A flash chip Performs proper device identification and verification Suit...
: Header for main.c file. This file contains the common defines of the application....
void Error_Handler(void)
This function is executed in case of error occurrence.
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
#define SPI1_CS_GPIO_Port
#define CLAMP(val, minVal, maxVal)
Clamp val to the closed interval [minVal, maxVal]. All three arguments are evaluated exactly once via...
#define INX_GET(nInx, nMax)
The circular index GET - for circular queue both direction Example usage:
void mems_RemoveLastData(uint8_t fromEndTo)
remove last data
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,...
static flash_at25CS_t _flash
uint8_t mems_WriteToSystemParams()
write data from memory to systemParams
void mems_ReadFromSystemParams()
read data from NFC to mems block
#define MEMS_DATA_BITS_BOUNDARY
void mems_Init()
Initialise NFC and external flash; load the main block and system parameters. Verifies the flash sign...
static void mens_MainBlockInit()
static uint8_t mems_CheckCRC()
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
mems_DataBlock_t * mems_InicBuffer(mems_DataType_t type)
Initialize the work buffer - _memsDataBlock.
HAL_StatusTypeDef mems_Reset()
memory reset - remove sign from chip
void setBackUpRegister(uint32_t backupRegister, uint32_t value)
Write a value to an RTC backup register.
#define MEMS_MAINBLOCK_ADDR
static mems_DataBlock_t _memsDataBlock
static void mems_SetCRC()
HAL_StatusTypeDef mems_WriteMainBlock()
writing the main block on flash. The main block is stored on address 0
void nfc_st25r3_OnMailboxData(uint8_t *data, uint16_t len)
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)
uint32_t getBackUpRegister(uint32_t backupRegister)
Read a value from an RTC backup register.
HAL_StatusTypeDef mems_Check(int8_t correct)
Check the memory consist.
HAL_StatusTypeDef mems_ReadMainBlock()
reading of main block from flash. If there is not valid MEMS_SIGN, the structure is initialize to 0 T...
#define SZ_MAINBLOCK
Size in bytes of the mems_MainBlock_t structure written at flash address 0.
#define SZ_DATABLOCK
Size in bytes of one mems_DataBlock_t entry in the circular data queue. Equals 5 bytes of header plus...
mems_MainBlock_t _memsMainBlock
Global instance of the main flash control block; loaded by mems_ReadMainBlock().
mems_DataType_t
Type tag stored in each mems_DataBlock_t to identify the payload format. Used when reading back block...
systemParams_t _systemParams
This file contains all the function prototypes for the rtc.c file.
This file contains all the function prototypes for the spi.c file.
Configuration and state descriptor for one AT25EU0041A flash chip. Pass a pointer to this struct to e...
Sensor data record stored as one element in the flash circular queue.
Master control block stored at flash address 0.
Function prototypes for sys_app.c file.
uint8_t GetBatteryLevel(void)
callback to get the battery level in % of full charge (254 full charge, 0 no charge)
uint8_t calculateCrc(uint8_t *data, uint8_t len)
Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C res...