Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CalLib.h"
00025 #ifdef __SAM3X8E__
00026
00027
00028
00029 #include "DueFlash.h"
00030
00031 DueFlash flash;
00032
00033 void calLibErase(byte device)
00034 {
00035 uint32_t data = 0;
00036
00037 flash.write(CALLIB_START + sizeof(CALLIB_DATA) * device, &data, 1);
00038 }
00039
00040 void calLibWrite(byte device, CALLIB_DATA *calData)
00041 {
00042 calData->valid = CALLIB_DATA_VALID;
00043
00044 flash.write(CALLIB_START + sizeof(CALLIB_DATA) * device, (uint32_t *)calData, sizeof(CALLIB_DATA) / 4);
00045 }
00046
00047 boolean calLibRead(byte device, CALLIB_DATA *calData)
00048 {
00049 memcpy(calData, CALLIB_START + sizeof(CALLIB_DATA) * device, sizeof(CALLIB_DATA));
00050 return calData->valid == CALLIB_DATA_VALID;
00051 }
00052
00053 #else
00054
00055
00056
00057 #include <EEPROM.h>
00058
00059 void calLibErase(byte device)
00060 {
00061 EEPROM.write(sizeof(CALLIB_DATA) * device, 0);
00062 }
00063
00064 void calLibWrite(byte device, CALLIB_DATA *calData)
00065 {
00066 byte *ptr = (byte *)calData;
00067 byte length = sizeof(CALLIB_DATA);
00068 int eeprom = sizeof(CALLIB_DATA) * device;
00069
00070 calData->valid = CALLIB_DATA_VALID;
00071
00072 for (byte i = 0; i < length; i++)
00073 EEPROM.write(eeprom + i, *ptr++);
00074 }
00075
00076 boolean calLibRead(byte device, CALLIB_DATA *calData)
00077 {
00078 byte *ptr = (byte *)calData;
00079 byte length = sizeof(CALLIB_DATA);
00080 int eeprom = sizeof(CALLIB_DATA) * device;
00081
00082 calData->magValid = false;
00083 calData->accelValid = false;
00084
00085 if ((EEPROM.read(eeprom) != CALLIB_DATA_VALID_LOW) ||
00086 (EEPROM.read(eeprom + 1) != CALLIB_DATA_VALID_HIGH))
00087 return false;
00088
00089 for (byte i = 0; i < length; i++)
00090 *ptr++ = EEPROM.read(eeprom + i);
00091 return true;
00092 }
00093 #endif