uint8_t EEPROM_Write(uint8_t AddressToWrite, uint8_t *DataArray, uint8_t BytesToWrite) { unsigned int IAP_Command[5]; unsigned int IAP_Result[5]; IAP_Result[0] = 0; IAP_Command[0] = IAP_EEPROM_WRITE;//EEPROM write command (61) IAP_Command[1] = (unsigned int)AddressToWrite;//EEPROM address IAP_Command[2] = *DataArray;//RAM address IAP_Command[3] = (unsigned int)BytesToWrite; //Number of bytes to write IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz iap_entry(IAP_Command, IAP_Result); return (uint8_t)IAP_Result[0]; } uint8_t EEPROM_Read(uint8_t AddressToRead, uint8_t *DataArray, uint8_t BytesToRead) { unsigned int IAP_Command[5]; unsigned int IAP_Result[5]; IAP_Result[0] = 0; IAP_Command[0] = IAP_EEPROM_READ;//EEPROM read command (62) IAP_Command[1] = (unsigned int)AddressToRead;//EEPROM address IAP_Command[2] = *DataArray;//RAM address IAP_Command[3] = (unsigned int)BytesToRead;//Number of bytes to read IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz iap_entry(IAP_Command, IAP_Result); return (uint8_t)IAP_Result[0]; } |
uint8_t EEPROM_Write(uint8_t AddressToWrite, uint8_t *DataArray, uint8_t BytesToWrite) { EELIB_Command IAP_Command; EELIB_Result IAP_Result; IAP_Result[0] = 0; //TODO: check to make sure the address is valid IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_WRITE;//EEPROM write command IAP_Command[1] = (unsigned int)AddressToWrite;//EEPROM address IAP_Command[2] = *DataArray;//RAM address IAP_Command[3] = (unsigned int)BytesToWrite;//Number of bytes to write IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz EELIB_entry(IAP_Command, IAP_Result); return (uint8_t)IAP_Result[0]; } uint8_t EEPROM_Read(uint8_t AddressToRead, uint8_t *DataArray, uint8_t BytesToRead) { EELIB_Command IAP_Command; EELIB_Result IAP_Result; IAP_Result[0] = 0; //TODO: check to make sure the address is valid IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_READ;//EEPROM read command IAP_Command[1] = (unsigned int)AddressToRead;//EEPROM address IAP_Command[2] = *DataArray;//RAM address IAP_Command[3] = (unsigned int)BytesToRead;//Number of bytes to read IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz EELIB_entry(IAP_Command, IAP_Result); return (uint8_t)IAP_Result[0]; } |
IAP_Command[2] = *DataArray; |
uint8_t EEPROM_Write(uint8_t AddressToWrite, void* DataArray, uint8_t BytesToWrite) { #ifdef USE_EEPROM_LIB EELIB_Command IAP_Command; EELIB_Result IAP_Result; #else uint32_t IAP_Command[5]; uint32_t IAP_Result[4]; #endif IAP_Result[0] = 0; #ifdef USE_EEPROM_LIB IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_WRITE;//EEPROM library write command #else IAP_Command[0] = IAP_EEPROM_WRITE;//IAP EEPROM write command #endif IAP_Command[1] = (uint32_t)AddressToWrite;//EEPROM address to write to IAP_Command[2] = (uint32_t)DataArray;//RAM address of the data to write IAP_Command[3] = (uint32_t)BytesToWrite;//Number of bytes to write IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz #ifdef USE_EEPROM_LIB EELIB_entry(IAP_Command, IAP_Result); #else vPortEnterCritical(); iap_entry(IAP_Command, IAP_Result); vPortExitCritical(); #endif return (uint8_t)IAP_Result[0]; } uint8_t EEPROM_Read(uint8_t AddressToRead, void* DataArray, uint8_t BytesToRead) { #ifdef USE_EEPROM_LIB EELIB_Command IAP_Command; EELIB_Result IAP_Result; #else uint32_t IAP_Command[5]; uint32_t IAP_Result[4]; #endif IAP_Result[0] = 0; #ifdef USE_EEPROM_LIB IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_READ;//EEPROM library read command #else IAP_Command[0] = IAP_EEPROM_READ;//IAP EEPROM read command #endif IAP_Command[1] = (uint32_t)AddressToRead;//EEPROM address to read from IAP_Command[2] = (uint32_t)DataArray;//RAM address to copy the EEPROM data to IAP_Command[3] = (uint32_t)BytesToRead;//Number of bytes to read IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz #ifdef USE_EEPROM_LIB EELIB_entry(IAP_Command, IAP_Result); #else vPortEnterCritical(); iap_entry(IAP_Command, IAP_Result); vPortExitCritical(); #endif return (uint8_t)IAP_Result[0]; } |
uint8_t val = 0; uint8_t DataArray[4]; /* Put data into DataArray */ resp = EEPROM_Write(val, &DataArray, 4); |
typedef struct __attribute__((packed)){ uint8_t EventType; uint8_t EventTime[3]; uint8_t EventOutputState; } TimerEvent; uint8_t val = 0; TimerEvent TestEvent; /* put data in the TestEvent struct */ resp = EEPROM_Write(val, &TestEvent, sizeof(TestEvent)); |
resp = EEPROM_Read(val, &DataArray, 4); resp = EEPROM_Read(0, &TestEvent, sizeof(TestEvent)); |