11 #include PLATFORM_HEADER
14 #ifdef NVM_RAM_EMULATION
16 static int16u calibrationData[32+2]={
18 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
19 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
20 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
21 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
26 halCommonMemCopy(data, ((int8u *) calibrationData) + offset, length);
31 halCommonMemCopy(((int8u *) calibrationData) + offset, data, length);
56 static int8u determineState(
void)
62 if((leftMgmt==0xFFFF0000) && (rightMgmt==0xFFFFFFFF)) {
71 }
else if((leftMgmt==0xFFFF0000) && (rightMgmt==0xFF00FFFF)) {
73 }
else if((leftMgmt==0xFFFF0000) && (rightMgmt==0xFF000000)) {
75 }
else if((leftMgmt==0xFFFF0000) && (rightMgmt==0xFFFFFFFF)) {
77 }
else if((leftMgmt==0xFFFF0000) && (rightMgmt==0xFFFFFF00)) {
79 }
else if((leftMgmt==0xFF000000) && (rightMgmt==0xFFFFFF00)) {
81 }
else if((leftMgmt==0xFF000000) && (rightMgmt==0xFFFF0000)) {
83 }
else if((leftMgmt==0xFFFFFFFF) && (rightMgmt==0xFFFF0000)) {
85 }
else if((leftMgmt==0xFFFFFF00) && (rightMgmt==0xFFFF0000)) {
87 }
else if((leftMgmt==0xFFFFFF00) && (rightMgmt==0xFF000000)) {
103 int16u *ram = (int16u*)data;
110 assert((offset&0x1)==0);
112 assert((length&0x1)==0);
117 switch(determineState()) {
125 for(i=0;i<(length/2);i++) {
134 for(i=0;i<(length/2);i++) {
147 for(i=0;i<(length/2);i++) {
167 assert((offset&0x1)==0);
170 switch(determineState()) {
190 int16u dummy = 0xFFFF;
200 static int8u erasePage(int32u page)
213 address = (page+((i-1)*MFB_PAGE_SIZE_B));
214 flash = (int8u *)address;
218 for(k=0;k<MFB_PAGE_SIZE_B;k++,flash++) {
221 if(status != ST_SUCCESS) {
235 #define ERASE_PAGE(page) \
237 status = erasePage(page); \
238 if(status != ST_SUCCESS) { \
247 #define WRITE_DATA(destPage, srcPage, offset, length) \
250 status = halInternalFlashWrite(destPage+NVM_MGMT_SIZE_B, \
251 (int16u *)(srcPage+NVM_MGMT_SIZE_B), \
252 (offset-NVM_MGMT_SIZE_B)/2); \
253 if(status != ST_SUCCESS) { return status; } \
255 status = halInternalFlashWrite(destPage+offset, \
258 if(status != ST_SUCCESS) { return status; } \
260 status = halInternalFlashWrite(destPage+offset+length, \
261 (int16u *)(srcPage+offset+length), \
264 NVM_MGMT_SIZE_B)/2); \
265 if(status != ST_SUCCESS) { return status; } \
270 #define WRITE_MGMT_16BITS(address, data) \
272 int16u value = data; \
273 status = halInternalFlashWrite((address), &value, 1); \
274 if(status != ST_SUCCESS) { \
283 int8u state, exitState;
287 int16u *ram = (int16u*)data;
294 assert((offset&0x1)==0);
296 assert((length&0x1)==0);
301 state = determineState();
345 ERASE_PAGE(destPage);
346 WRITE_DATA(destPage, srcPage, offset, length);
362 ERASE_PAGE(destPage);
366 WRITE_DATA(destPage, srcPage, offset, length);
382 ERASE_PAGE(destPage);
386 WRITE_DATA(destPage, srcPage, offset, length);
402 #endif // NVM_RAM_EMULATION