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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #include <board.h>
00085 #include <string.h>
00086
00087
00088
00089
00090 #define LEN_STRING_0 3
00091 #define LEN_STRING_1 56
00092 #define LEN_STRING_LONG (1000000)
00093
00094 #define MSG_0_LENGTH 16
00095 #define MSG_1_LENGTH 32
00096 #define MSG_LONG_LENGTH 15626
00097
00098 #define ID_REGION0 0x01
00099 #define ID_REGION1 0x02
00100 #define ID_REGION2 0x04
00101 #define ID_REGION3 0x08
00102
00103
00104
00105
00106 static uint32_t * bufOutput;
00107 static uint32_t * bufContext;
00108 static volatile uint32_t regionHashCompleted, regionDigestMismatch;
00109
00110 static uint8_t msgRegion_0[LEN_STRING_0] = "abc";
00111 static uint8_t msgRegion_1[LEN_STRING_1] =
00112 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
00113 static uint8_t msgRegion_mis1[LEN_STRING_1]=
00114 "aacdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
00115
00116
00117 static uint8_t msgRegion_2 = 'a';
00118
00119
00120
00121
00122
00123
00124
00125
00126 void ICM_Handler(void){
00127 uint32_t status;
00128 status = ICM_GetIntStatus();
00129 if (status & ICM_ISR_RHC_Msk) {
00130 regionHashCompleted |= (status & ICM_ISR_RHC_Msk);
00131 ICM_DisableIt(status & ICM_ISR_RHC_Msk);
00132 }
00133 if (status & ICM_ISR_RDM_Msk) {
00134 regionDigestMismatch |= ((status & ICM_ISR_RDM_Msk)>> ICM_ISR_RDM_Pos);
00135 ICM_DisableIt((status & ICM_ISR_RDM_Msk) >> ICM_ISR_RDM_Pos);
00136 }
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 static void _buildMessage32(uint8_t *M, uint32_t *message, uint32_t length,
00148 uint8_t longMsg)
00149 {
00150 uint32_t l;
00151 uint32_t l_high,l_low;
00152 uint32_t k;
00153 uint8_t *pBuf;
00154 pBuf = (uint8_t *)message;
00155 l = length * 8;
00156 k = ((512 + 448) - ( (l % 512) + 1)) % 512;
00157 if (longMsg)
00158 memset (pBuf, (*M), length);
00159 else
00160 memcpy (pBuf, M, length);
00161 pBuf+= length;
00162
00163 *pBuf++ = 0x80;
00164
00165 memset (pBuf, 0, (k - 7) / 8 );
00166
00167 pBuf += (k - 7 ) / 8;
00168 l_high = 0;
00169 l_low = (uint32_t)(l & 0xffffffff);
00170 *pBuf++ = (l_high >> 24) & 0xFF;
00171 *pBuf++ = (l_high >> 16) & 0xFF;
00172 *pBuf++ = (l_high >> 8) & 0xFF;
00173 *pBuf++ = (l_high ) & 0xFF;
00174 *pBuf++ = (l_low >> 24) & 0xFF;
00175 *pBuf++ = (l_low >> 16) & 0xFF;
00176 *pBuf++ = (l_low >> 8) & 0xFF;
00177 *pBuf++ = (l_low ) & 0xFF;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 int main( void )
00191 {
00192 uint32_t mainListAddr;
00193 LinkedListDescriporIcmRegion *pMainList;
00194
00195 WDT_Disable( WDT ) ;
00196
00197
00198 printf("-- ICM Example %s --\n\r", SOFTPACK_VERSION ) ;
00199 printf("-- %s\n\r", BOARD_NAME);
00200 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00201
00202
00203 BOARD_ConfigureSdram();
00204
00205 bufOutput = (uint32_t*)SDRAM_CS_ADDR;
00206 bufContext= (uint32_t*)(SDRAM_CS_ADDR + 0x100000);
00207 pMainList = (LinkedListDescriporIcmRegion*)((uint32_t*)(SDRAM_CS_ADDR + 0x20000));
00208 mainListAddr = (uint32_t)pMainList;
00209
00210
00211 PMC_EnablePeripheral(ID_ICM);
00212
00213
00214 ICM_SoftReset();
00215
00216 NVIC_ClearPendingIRQ(ICM_IRQn);
00217 NVIC_EnableIRQ(ICM_IRQn);
00218
00219 ICM_GetIntStatus();
00220 ICM_GetStatus();
00221
00222
00223 _buildMessage32(msgRegion_0, bufContext, LEN_STRING_0, 0);
00224 _buildMessage32(msgRegion_1, bufContext + MSG_0_LENGTH, LEN_STRING_1, 0);
00225 _buildMessage32(&msgRegion_2, bufContext + MSG_0_LENGTH + MSG_1_LENGTH, \
00226 LEN_STRING_LONG, 1);
00227
00228 ICM_Configure(ICM_CFG_UALGO_SHA1|ICM_CFG_SLBDIS);
00229 pMainList->icm_raddr = (uint32_t)bufContext;
00230 pMainList->icm_rcfg = ICM_RCFG_ALGO_SHA1;
00231 pMainList->icm_rctrl = MSG_0_LENGTH /16 -1;
00232 pMainList->icm_rnext = 0;
00233 pMainList++;
00234 pMainList->icm_raddr = (uint32_t)(bufContext + MSG_0_LENGTH);
00235 pMainList->icm_rcfg = ICM_RCFG_ALGO_SHA1;
00236 pMainList->icm_rctrl = MSG_1_LENGTH /16 -1;;
00237 pMainList->icm_rnext = 0;
00238 pMainList++;
00239 pMainList->icm_raddr = (uint32_t)(bufContext + MSG_0_LENGTH + MSG_1_LENGTH);
00240 pMainList->icm_rcfg = ICM_RCFG_EOM | ICM_RCFG_ALGO_SHA1;
00241 pMainList->icm_rctrl = LEN_STRING_LONG / 4 /16 - 1;
00242 pMainList->icm_rnext = 0;
00243
00244 ICM_SetDescStartAddress((uint32_t)mainListAddr);
00245 ICM_SetHashStartAddress((uint32_t)bufOutput);
00246 regionHashCompleted = 0;
00247 regionDigestMismatch = 0;
00248 printf("-I- Enable ICM region(0-2)...\n\r");
00249 ICM_EnableIt(ICM_IER_RHC(ID_REGION0 | ID_REGION1 | ID_REGION2));
00250 ICM_Enable();
00251 while(regionHashCompleted != (ID_REGION0 | ID_REGION1 | ID_REGION2));
00252 printf("-I- When the desired number of blocks have been transferred, \
00253 the digest is whether moved to memory (write-back function) \n\r");
00254 ICM_Disable();
00255
00256 regionHashCompleted = 0;
00257 regionDigestMismatch = 0;
00258 printf("-I- Configure ICM region(0-2) with compare function\n\r");
00259 printf("-I- When the desired number of blocks have been transferred, the \
00260 digest is compared with a digest reference located in system memory. \n\r");
00261 ICM_Configure(ICM_CFG_UALGO_SHA1 | ICM_CFG_SLBDIS | ICM_CFG_WBDIS);
00262 ICM_EnableIt(ICM_IER_RHC(ID_REGION0 | ID_REGION1 | ID_REGION2)
00263 |ICM_IER_RDM(ID_REGION0 | ID_REGION1 | ID_REGION2));
00264 printf("-I- Enable ICM region(0-2)...\n\r");
00265 ICM_Enable();
00266 while(regionHashCompleted != (ID_REGION0 | ID_REGION1 | ID_REGION2));
00267 if (regionDigestMismatch == 0)
00268 printf("-I- No digest mismatch occurs!\n\r");
00269 ICM_Disable();
00270
00271 printf("-I- Change the context in region 1 for test...\n\r");
00272 _buildMessage32(msgRegion_mis1, bufContext + MSG_0_LENGTH, LEN_STRING_1, 0);
00273 ICM_Configure(ICM_CFG_UALGO_SHA1 |ICM_CFG_SLBDIS | ICM_CFG_WBDIS);
00274 regionHashCompleted = 0;
00275 regionDigestMismatch = 0;
00276 ICM_EnableMonitor((ID_REGION0 | ID_REGION1 | ID_REGION2));
00277 ICM_EnableIt(ICM_IER_RHC(ID_REGION0 | ID_REGION1 | ID_REGION2)
00278 |ICM_IER_RDM(ID_REGION0 | ID_REGION1 | ID_REGION2));
00279 ICM_Enable();
00280 while(regionHashCompleted != (ID_REGION0 | ID_REGION1 | ID_REGION2));
00281 printf ("-I- Digest mismatch occurs @ region(s) %x \n\r",
00282 (unsigned int)regionDigestMismatch);
00283 ICM_Disable();
00284
00285 printf("\n\r-I- ICM test done!\n\r");
00286 while(1);
00287 }
00288