20#define MEMS_SIGN "MTK0001"
21#define MEMS_SIGN_BLOCK "TM"
22#define MEMS_MAINBLOCK_ADDR 0
23#define MEMS_DATA_BITS_BOUNDARY 5
25#define INX_GET(nInx, nMax) (((nInx)>=0)?((nInx)%(nMax)):((nMax)-((-(nInx))%(nMax))))
54 HAL_StatusTypeDef status;
78 writeLog(
"flash12 data: Init %s", (status == HAL_OK) ?
"OK" :
"failed");
89 writeLog(
"flash12 data: MainBlock %s", (status == HAL_OK) ?
"OK" :
"failed");
95 HAL_StatusTypeDef status;
109 writeLog(
"data: MainBlock default write %s", (status == HAL_OK) ?
"OK" :
"failed");
119 HAL_StatusTypeDef status;
127 HAL_StatusTypeDef status;
128 const char buf[] =
"XXXX";
142 writeLog(
"mems_MoveAddr: module is not 0!");
170 HAL_StatusTypeDef status = HAL_ERROR;
196 HAL_StatusTypeDef status = HAL_BUSY;
204 if (memBlock != NULL)
215 HAL_StatusTypeDef status = HAL_OK;
219 for (i = 0; i <
_memsMainBlock.Data_CountCurrent && HAL_OK == status; i++)
248 int16_t count = fromEndTo + 1;
339 return HAL_RTCEx_BKUPRead(&
hrtc, backupRegister);
360 HAL_PWR_EnableBkUpAccess();
361 HAL_RTCEx_BKUPWrite(&
hrtc, backupRegister, value);
362 HAL_PWR_DisableBkUpAccess();
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)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
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
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
#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()
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
#define INX_GET(nInx, nMax)
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)