#ifndef NVM_H #define NVM_H #include "typedef.h" /** * @brief Virtual address 0 is invalid .we can not use this address * */ typedef enum { MEM_PARTITION_RAM = 0x00, MEM_PARTITION_CODEFLASH = 0x01, MEM_MAX_PARTITION_NUM } MEM_PARTITION_LIST_Te; typedef void (*NVM_OPERATION_COMPLETE_CALLBACK)(uint8_t nvm_operation_type, uint16_t virtureaddr, int8_t success); /* * These defines are the "nvm_operation_type" in the operation complete callback typedef below. */ #define NVM_OP_TYPE_NONE ((uint8_t)0u) /**< no operation */ #define NVM_OP_TYPE_WRITE ((uint8_t)1u) /**< partition write operation */ #define NVM_OP_TYPE_READ ((uint8_t)2u) /**< partition read operation */ #define NVM_OP_TYPE_ERASE ((uint8_t)3u) /**< partition erase operation */ #define NVM_OP_TYPE_FORMAT ((uint8_t)4u) /**< partition format operation */ #define NVM_OP_TYPE_SCAN ((uint8_t)5u) /**< scan (synch with shadow) operation for all partitions */ #define NVM_OP_TYPE_REFRESH ((uint8_t)6u) /**< scan (synch with shadow) for one partition. */ #define NVM_OP_TYPE_SHUTDOWN ((uint8_t)7u) /**< prepare to shutdown, don't allow more operations */ #define NVM_OP_TYPE_HALT ((uint8_t)8u) /**< nvm halt operation, stop doing stuff */ #define NVM_OP_TYPE_RESTORE ((uint8_t)9u) /**< start up again after a halt */ #define NVM_OP_TYPE_RAW_WRITE ((uint8_t)10u) /**< raw write to absolute addr, not a partition write */ #define NVM_OP_TYPE_MAX ((uint8_t)11u) /**< invalid, anything this value or larger */ #define FBL_MEM_SEGMENT_SIZE (0x100) #define MEM_MAX_TEMP_BUFF_NUM (2u) typedef struct { uint8_t shutdown_requested : 1; uint8_t halt_requested : 1; uint8_t force_shutdown : 1; uint8_t halted : 1; uint8_t busy : 1; uint8_t ee_error : 1; uint8_t erased : 1; uint8_t flash_driver_loaded : 1; } NVM_FLAGS_Ts; typedef struct { uint8_t *p_buffer; /**< todo: this can be deleted, only reference for MEM_Read() which isn't implemented. */ uint8_t partition_id; uint8_t current_sequenc; /**< */ uint8_t prev_seqence; uint8_t mem_operation_id; /**< the operation type; read, write, erase, format, scan, refresh */ uint32_t size_in_bytes; /**< size in bytes of the op, maybe for absolute erase or read or write */ uint32_t start_addr; /**< starting addr of absolute read, write or erase */ NVM_OPERATION_COMPLETE_CALLBACK pfn_complete_cbk; /**< pointer to callback function which executes after the operation completes (success or fail) */ } MEM_OPERATION_Ts; #define RAM_FALSH_DRIVE_LENGHT (96u) extern uint8_t flashCode[RAM_FALSH_DRIVE_LENGHT + 4]; extern NVM_FLAGS_Ts Nvm_Flags; extern uint8_t Mem_PartionTempBuff[MEM_MAX_TEMP_BUFF_NUM][FBL_MEM_SEGMENT_SIZE]; extern int8_t NEM_WriteData(MEM_OPERATION_Ts *op); extern int8_t NVM_EraseData(uint32_t startaddr, uint32_t length); extern int8_t NVM_ReInitFlashDriveRam(void); extern void NVM_Init(void); extern bool NVM_Is_Busy(void); extern uint8_t MEM_PartitionCRCOK(uint8_t partionid); extern uint8_t ApplFblIsValidApp(); #endif