00001
00016 #include <stddef.h>
00017 #include "nvm.h"
00018 #include "nvm_config.h"
00019
00020
00021
00022
00023
00024
00025 uint32_t colorTable[] = { 0x000000, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00,
00026 0x00ffff, 0xff00ff, 0xc0c0c0, 0xffffff };
00027 uint8_t coefficientTable[] = { 11, 12, 13, 14, 15 };
00028 uint8_t primeNumberTable[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
00029 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
00030 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
00031 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
00032 199, 211, 223, 227, 229, 233, 239, 241, 251 };
00033 uint8_t bonusTable[] = { 39, 38, 37, 36 };
00034 uint8_t privateKeyTable[] = { 49, 48, 47, 46 };
00035 uint8_t transformTable[] = { 59, 58, 57, 56 };
00036 int32_t safetyTable[] = { -71, 72, -73, 74, -75, -76, -77, -78, 79, -70 };
00037 uint8_t bigEmptyTable[450];
00038 uint32_t singleVariable = 68;
00039
00040
00041
00042
00043 typedef enum
00044 {
00045 COLOR_TABLE_ID,
00046 COEFFICIENT_TABLE_ID,
00047 PRIME_NUMBER_TABLE_ID,
00048 BONUS_TABLE_ID,
00049 PRIVATE_KEY_TABLE_ID,
00050 TRANSFORM_TABLE_ID,
00051 SINGLE_VARIABLE_ID,
00052 SAFETY_TABLE_ID,
00053 BIG_EMPTY_TABLE_ID
00054 } NVM_Object_Ids;
00055
00056
00057
00058 typedef enum
00059 {
00060 MY_PAGE_1,
00061 MY_PAGE_2,
00062 MY_PAGE_3,
00063 MY_PAGE_4
00064 } NVM_Page_Ids;
00065
00066
00067
00068 NVM_Page_t const myPage1 =
00069 {
00070
00071 { (uint8_t *) colorTable, sizeof(colorTable), COLOR_TABLE_ID },
00072 { (uint8_t *) bonusTable, sizeof(bonusTable), BONUS_TABLE_ID },
00073 { (uint8_t *) &singleVariable, sizeof(singleVariable), SINGLE_VARIABLE_ID },
00074 { (uint8_t *) bigEmptyTable, sizeof(bigEmptyTable), BIG_EMPTY_TABLE_ID },
00075 NVM_PAGE_TERMINATION
00076 };
00077
00078
00079
00080
00081
00082 NVM_Page_t const myPage2 =
00083 {
00084
00085 { (uint8_t *) safetyTable, sizeof(safetyTable), SAFETY_TABLE_ID },
00086 NVM_PAGE_TERMINATION
00087 };
00088
00089
00090
00091 NVM_Page_t const myPage3 =
00092 {
00093
00094 { (uint8_t *) coefficientTable, sizeof(coefficientTable), COEFFICIENT_TABLE_ID },
00095 { (uint8_t *) privateKeyTable, sizeof(privateKeyTable), PRIVATE_KEY_TABLE_ID },
00096 { (uint8_t *) &singleVariable, sizeof(singleVariable), SINGLE_VARIABLE_ID },
00097 NVM_PAGE_TERMINATION
00098 };
00099
00100
00101
00102 NVM_Page_t const myPage4 =
00103 {
00104
00105 { (uint8_t *) primeNumberTable, sizeof(primeNumberTable), PRIME_NUMBER_TABLE_ID },
00106 { (uint8_t *) transformTable, sizeof(transformTable), TRANSFORM_TABLE_ID },
00107 { (uint8_t *) &singleVariable, sizeof(singleVariable), SINGLE_VARIABLE_ID },
00108 NVM_PAGE_TERMINATION
00109 };
00110
00111
00112
00113 NVM_Page_Table_t const nvmPages =
00114 {
00115
00116 { MY_PAGE_1, &myPage1, nvmPageTypeNormal },
00117 { MY_PAGE_2, &myPage2, nvmPageTypeWear },
00118 { MY_PAGE_3, &myPage3, nvmPageTypeNormal },
00119 { MY_PAGE_4, &myPage4, nvmPageTypeNormal }
00120 };
00121
00122
00123
00124
00125
00127
00148 #define NUMBER_OF_USER_PAGES (sizeof(nvmPages) / sizeof(NVM_Page_Descriptor_t))
00149 #define NUMBER_OF_PAGES (NVM_PAGES_SCRATCH + NUMBER_OF_USER_PAGES)
00150
00152
00153 #ifdef __ICCARM__
00154 #pragma data_alignment = NVM_PAGE_SIZE
00155 static const uint8_t nvmData[NVM_PAGE_SIZE * NUMBER_OF_PAGES] @ ".text";
00156 #else
00157 static const uint8_t nvmData[NVM_PAGE_SIZE * NUMBER_OF_PAGES] __attribute__ ((__aligned__(NVM_PAGE_SIZE))) = { 0xFF };
00158 #endif
00159
00160 static NVM_Config_t const nvmConfig =
00161 {
00162 &nvmPages,
00163 NUMBER_OF_PAGES,
00164 NUMBER_OF_USER_PAGES,
00165 nvmData
00166 };
00167
00168
00175 NVM_Config_t const *NVM_ConfigGet(void)
00176 {
00177 return( &nvmConfig );
00178 }
00179