mfg-token.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include PLATFORM_HEADER
00007 #include "error.h"
00008 #include "hal/micro/cortexm3/flash.h"
00009 #include "mfg-token.h"
00010
00011
00012
00013
00014 #define DEFINETOKENS
00015 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
00016 const int16u TOKEN_##name = TOKEN_##name##_ADDRESS;
00017 #include "hal/micro/cortexm3/token-manufacturing.h"
00018 #undef TOKEN_DEF
00019 #undef TOKEN_MFG
00020 #undef DEFINETOKENS
00021
00022
00023
00024
00025
00026
00027
00028
00029 static const int8u nullEui[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF };
00030
00031
00032 void halInternalGetMfgTokenData(void *data, int16u ID, int8u index, int8u len)
00033 {
00034 int8u *ram = (int8u*)data;
00035
00036
00037 index = (index==0x7F) ? 0 : index;
00038
00039 if(ID == MFG_EUI_64_LOCATION) {
00040
00041
00042
00043
00044
00045 tokTypeMfgEui64 eui64;
00046 halCommonGetMfgToken(&eui64, TOKEN_MFG_CUSTOM_EUI_64);
00047 if(MEMCOMPARE(eui64,nullEui, 8 ) == 0) {
00048 halCommonGetMfgToken(&eui64, TOKEN_MFG_ST_EUI_64);
00049 }
00050 MEMCOPY(ram, eui64, 8 );
00051 } else {
00052
00053
00054
00055
00056 int32u realAddress = (DATA_BIG_INFO_BASE|ID) + (len*index);
00057 int8u *flash = (int8u *)realAddress;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 MEMCOPY(ram, flash, len);
00073 }
00074 }
00075
00076
00077 void halInternalSetMfgTokenData(int16u token, void *data, int8u len)
00078 {
00079 StStatus flashStatus;
00080 int32u realAddress = (DATA_BIG_INFO_BASE|token);
00081 int8u * flash = (int8u *)realAddress;
00082 int32u i;
00083
00084
00085
00086
00087 assert((token&1) != 1);
00088 assert((len&1) != 1);
00089 assert((realAddress>=CIB_BOTTOM) && ((realAddress+len-1)<=CIB_TOP));
00090
00091
00092
00093
00094
00095 for(i=0;i<len;i++) {
00096 assert(flash[i] == 0xFF);
00097 }
00098
00099
00100
00101 flashStatus = halInternalFlashWrite(realAddress, data, (len/2));
00102 assert(flashStatus == ST_SUCCESS);
00103 }
00104