HT32SX Monarch Scan
Monarch Scan application for HT32SX
nvm_api.h
Go to the documentation of this file.
1 
13 #ifndef __NVM_API_H
14 #define __NVM_API_H
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <stdint.h>
21 
23 #ifdef ERASE_VALUE_IS_FF
24  #define NVM_BLOCK_INVALID 0xFFFFFFFCFFFFFF0E
25  #define NVM_BLOCK_VALID 0xFFFFFF0CFFFFFF0E
26  #define NVM_BLOCK_EMPTY 0xFFFFFFFFFFFFFFFF
27 
28  #define NVM_BLOCK_INVALID_1 0xFFFFFFFF
29  #define NVM_BLOCK_INVALID_2 0xFFFFFF0E
30 
31  #define NVM_BLOCK_VALID_1 0xFFFFFF0E
32  #define NVM_BLOCK_VALID_2 0xFFFFFF0C
33 #else
34  #define NVM_BLOCK_INVALID 0x00000000000000FE
35  #define NVM_BLOCK_VALID 0x000000FC000000FE
36  #define NVM_BLOCK_EMPTY 0x00
37 
38  #define NVM_BLOCK_INVALID_1 0x00000000
39  #define NVM_BLOCK_INVALID_2 0x000000FE
40 
41  #define NVM_BLOCK_VALID_1 0x000000FE
42  #define NVM_BLOCK_VALID_2 0x000000FC
43 #endif
44 
45 #define BLOCK_HEADER_SIZE 8 /* To preserve data integrity, 2 words are reserved for record validation */
46 #define BLOCK_BODY_SIZE 8 /* NVM data size */
47 
48 #define EEPROM_NVDATA_ADDRESS 0x600
49 #define RCZ_MASK 0x000000FF
50 
56 typedef enum
57 {
58  NVM_TYPE_EEPROM = 0,
59  NVM_TYPE_FLASH = 1
60 } NVM_TYPE;
61 
62 
68 typedef enum
69 {
73 
74 
79 typedef enum
80 {
81  NVM_RW_OK = 0,
82  NVM_WRITE_ERROR,
83  NVM_READ_ERROR,
84  NVM_WRITE_RECORD_ERROR,
85  NVM_READ_RECORD_ERROR,
86  NVM_WRITE_HEADER_ERROR,
87  NVM_NO_RECORDS
89 
90 
95 typedef enum
96 {
97  NVM_FREQ_OFFSET = 0,
98  NVM_RSSI_OFFSET = 1,
99  NVM_LBT_OFFSET = 2
101 
102 
108 typedef struct
109 {
112  uint32_t sfxDataAddress;
115 
116 
118 #define INIT_NVM_CONFIG(X) NVM_ConfigType X = { .nvmType = NVM_TYPE_EEPROM, \
119 .boardDataAddress = 0, .sfxDataAddress = EEPROM_NVDATA_ADDRESS, .messageSequenceNumber = 0x00 }
120 
122 
127 typedef struct
128 {
129  uint16_t pn;
130  uint16_t seqNumber;
131  uint16_t fh;
132  uint16_t rl;
134 
135 
140 typedef struct
141 {
142  uint32_t id;
143  uint8_t rcz;
144  uint8_t pac[8];
145  int32_t freqOffset;
146  int32_t rssiOffset;
147  int32_t lbtOffset;
149 
150 
151 /*-------------------------------------FUNCTION PROTOTYPES------------------------------------*/
152 
158 void SetNVMInitial(NVM_ConfigType *config);
159 
160 
166 NVM_TYPE GetNVMType(void);
167 
168 
174 uint32_t GetNVMBoardDataAddress(void);
175 
176 
182 uint32_t GetNVMSigfoxDataAddress(void);
183 
184 
193 NVM_RW_RESULTS NVM_Read(uint32_t nAddress, uint8_t cNbBytes, uint8_t* pcBuffer);
194 
195 
205 NVM_RW_RESULTS NVM_Write(uint32_t nAddress, uint8_t cNbBytes, uint8_t* pcBuffer, NVM_WRITE_MODE writeMode);
206 
207 
215 NVM_RW_RESULTS NVM_ReadRecord(uint8_t* nvmRecord, uint32_t recordSize);
216 
217 
225 NVM_RW_RESULTS NVM_WriteRecord(uint8_t* nvmRecord, uint32_t recordSize);
226 
227 
235 NVM_RW_RESULTS NVM_UpdateOffset(NVM_UPDATE_OFFSET updateWhat, int32_t data);
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif
242 
243 /******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE*****/
GetNVMType
NVM_TYPE GetNVMType(void)
Returns the configured NVM Type.
Definition: nvm_api.c:94
NVM_Read
NVM_RW_RESULTS NVM_Read(uint32_t nAddress, uint8_t cNbBytes, uint8_t *pcBuffer)
Reads data from NVM.
Definition: nvm_api.c:109
NVM_UPDATE_OFFSET
NVM_UPDATE_OFFSET
Board Data update modes.
Definition: nvm_api.h:95
NVM_ConfigType
NVM API configuration structure.
Definition: nvm_api.h:108
NVM_RecurrentDataType
Record for Sigfox recurrent data, like messages counter.
Definition: nvm_api.h:127
GetNVMBoardDataAddress
uint32_t GetNVMBoardDataAddress(void)
Returns the Board Data Address.
Definition: nvm_api.c:99
NVM_TYPE
NVM_TYPE
Describes NVM Type. Possible values reference FLASH or EEPROM memory.
Definition: nvm_api.h:56
NVM_Write
NVM_RW_RESULTS NVM_Write(uint32_t nAddress, uint8_t cNbBytes, uint8_t *pcBuffer, NVM_WRITE_MODE writeMode)
Writes data to NVM.
Definition: nvm_api.c:122
NVM_ConfigType::sfxDataAddress
uint32_t sfxDataAddress
Definition: nvm_api.h:112
NVM_UpdateOffset
NVM_RW_RESULTS NVM_UpdateOffset(NVM_UPDATE_OFFSET updateWhat, int32_t data)
Update Board Offsets (Frequency, RSSI and LBT offsets)
Definition: nvm_api.c:236
NVM_WriteRecord
NVM_RW_RESULTS NVM_WriteRecord(uint8_t *nvmRecord, uint32_t recordSize)
Writes record in the last available slot in the userSpace page. If no space left, the page will be er...
Definition: nvm_api.c:189
NVM_ConfigType::messageSequenceNumber
uint8_t messageSequenceNumber
Definition: nvm_api.h:113
NVM_ConfigType::boardDataAddress
uint32_t boardDataAddress
Definition: nvm_api.h:111
NVM_ReadRecord
NVM_RW_RESULTS NVM_ReadRecord(uint8_t *nvmRecord, uint32_t recordSize)
Reads last record stored at userSpaceAddress.
Definition: nvm_api.c:135
GetNVMSigfoxDataAddress
uint32_t GetNVMSigfoxDataAddress(void)
Returns the Sigfox Data Address.
Definition: nvm_api.c:104
NVM_WRITE_MODE_ERASE
Definition: nvm_api.h:71
NVM_RW_RESULTS
NVM_RW_RESULTS
Return values for NVM Read/Write functions.
Definition: nvm_api.h:79
NVM_WRITE_MODE
NVM_WRITE_MODE
Describes write mode operation.
Definition: nvm_api.h:68
NVM_WRITE_MODE_WRITEOVER
Definition: nvm_api.h:70
SetNVMInitial
void SetNVMInitial(NVM_ConfigType *config)
Initialize NVM API.
Definition: nvm_api.c:73
NVM_BoardDataType
Record for board data.
Definition: nvm_api.h:140
NVM_ConfigType::nvmType
NVM_TYPE nvmType
Definition: nvm_api.h:110