nvm.h

Go to the documentation of this file.
00001 /***************************************************************************/
00053 #ifndef __NVM_H
00054 #define __NVM_H
00055 
00056 #include <stdint.h>
00057 #include <stdbool.h>
00058 
00059 /* needed to get CPU flash size and calculate page size */
00060 #include "em_device.h"
00061 
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065 
00066 /***************************************************************************/
00071 /***************************************************************************/
00076 /*******************************************************************************
00077  *******************************   DEFINES   ***********************************
00078  ******************************************************************************/
00079 
00086 #define NVM_FEATURE_WEAR_PAGES_ENABLED               true
00087 
00089 #define NVM_FEATURE_STATIC_WEAR_ENABLED              true
00090 
00092 #define NVM_STATIC_WEAR_THRESHOLD                    100
00093 
00095 #define NVM_FEATURE_READ_VALIDATION_ENABLED          true
00096 
00098 #define NVM_FEATURE_WRITE_VALIDATION_ENABLED         true
00099 
00101 #define NVM_FEATURE_WEARLEVELGET_ENABLED             true
00102 
00104 #define NVM_FEATURE_WRITE_NECESSARY_CHECK_ENABLED    true
00105 
00107 #define NVM_MAX_NUMBER_OF_PAGES                      32
00108 
00110 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
00111 #define NVM_PAGE_SIZE           (FLASH_SIZE < (512 * 1024) ? 2048 : 4096)
00112 #else
00113 /* _EFM32_GECKO_FAMILY || _EFM32_TINY_FAMILY */
00114 #define NVM_PAGE_SIZE           (512)
00115 #endif
00116   
00118 #define NVM_WRITE_ALL_CMD         0xff
00119 
00120 #define NVM_WRITE_NONE_CMD        0xfe
00121 
00122 #define NVM_READ_ALL_CMD          0xff
00123 
00125 #define NVM_ERASE_RETAINCOUNT    0xffffffffUL
00126 
00128 #define NVM_PAGE_TERMINATION    { NULL, 0, (NVM_Object_Ids) 0 }
00129 
00132 /*******************************************************************************
00133  ******************************   TYPEDEFS   ***********************************
00134  ******************************************************************************/
00135 
00137 typedef enum
00138 {
00139   nvmPageTypeNormal = 0, 
00140   nvmPageTypeWear   = 1  
00141 } NVM_Page_Type_t;
00142 
00144 typedef struct
00145 {
00146   uint8_t  * location; 
00147   uint16_t size;       
00148   uint8_t  objectId;   
00149 } NVM_Object_Descriptor_t;
00150 
00152 typedef NVM_Object_Descriptor_t   NVM_Page_t[];
00153 
00154 
00156 typedef struct
00157 {
00158   uint8_t          pageId;     
00159   NVM_Page_t const * page;    
00160   uint8_t          pageType;   
00161 } NVM_Page_Descriptor_t;
00162 
00164 typedef NVM_Page_Descriptor_t   NVM_Page_Table_t[];
00165 
00167 typedef struct
00168 { NVM_Page_Table_t const *nvmPages;  
00169   uint8_t          const pages;      
00170   uint8_t          const userPages;  
00171   uint8_t          const *nvmArea;   
00172 } NVM_Config_t;
00173 
00175 typedef enum
00176 {
00177   nvmResultOk           = 0, 
00178   nvmResultAddrInvalid  = 1, 
00180   nvmResultInputInvalid = 2, 
00181   nvmResultDataInvalid  = 3, 
00182   nvmResultWriteLock    = 4, 
00184   nvmResultNoPages      = 5, 
00185   nvmResultNoPage       = 6, 
00187   nvmResultErrorInitial = 7, 
00188   nvmResultError        = 8  
00189 } NVM_Result_t;
00190 
00191 /*******************************************************************************
00192  ***************************   PROTOTYPES   ************************************
00193  ******************************************************************************/
00194 
00195 NVM_Result_t NVM_Init(NVM_Config_t const *nvmConfig);
00196 NVM_Result_t NVM_Erase(uint32_t erasureCount);
00197 NVM_Result_t NVM_Write(uint16_t pageId, uint8_t objectId);
00198 NVM_Result_t NVM_Read(uint16_t pageId, uint8_t objectId);
00199 
00200 #ifndef NVM_FEATURE_WEARLEVELGET_ENABLED
00201 #define NVM_FEATURE_WEARLEVELGET_ENABLED    true
00202 #endif
00203 #if (NVM_FEATURE_WEARLEVELGET_ENABLED == true)
00204 uint32_t NVM_WearLevelGet(void);
00205 #endif
00206 
00210 #ifdef __cplusplus
00211 }
00212 #endif
00213 
00214 #endif /* __NVM_H */