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 #include <mc1322x.h>
00037 #include <board.h>
00038 #include <stdio.h>
00039
00040 #include "tests.h"
00041 #include "config.h"
00042
00043 void asm_isr(void) {
00044 printf("asm isr\n\r");
00045 ASM->CONTROL0bits.CLEAR_IRQ = 1;
00046 }
00047
00048
00049 void main(void) {
00050 volatile int i;
00051
00052
00053 trim_xtal();
00054
00055 uart_init(INC, MOD, SAMP);
00056
00057 vreg_init();
00058
00059 enable_irq(ASM);
00060
00061 print_welcome("asm");
00062
00063 printf("ASM Control 0: %08x\n\r", (unsigned int)ASM->CONTROL0);
00064 printf("ASM Control 1: %08x\n\r", (unsigned int)ASM->CONTROL1);
00065 printf("ASM Status: %08x\n\r", (unsigned int)ASM->STATUS);
00066 printf("ASM Test pass: %d\n\r", ASM->STATUSbits.TEST_PASS);
00067
00068
00069 printf("\n\r*** ASM self-test ***\n\r");
00070
00071 ASM->CONTROL1bits.ON = 1;
00072 ASM->CONTROL1bits.SELF_TEST = 1;
00073 ASM->CONTROL0bits.START = 1;
00074
00075
00076
00077
00078 for(i = 0; i < 3330; i++) { continue; }
00079
00080 printf("ASM Test pass: %d\n\r", ASM->STATUSbits.TEST_PASS);
00081
00082
00083 ASM->CONTROL1bits.SELF_TEST = 0;
00084
00085
00086
00087
00088
00089 ASM->CONTROL1bits.NORMAL_MODE = 1;
00090
00091
00092
00093 ASM->CONTROL1bits.BYPASS = 0;
00094
00095 printf("\n\r*** set ASM key ***\n\r");
00096 ASM->KEY0 = 0xccddeeff;
00097 ASM->KEY1 = 0x8899aabb;
00098 ASM->KEY2 = 0x44556677;
00099 ASM->KEY3 = 0x00112233;
00100
00101
00102
00103 printf("ASM Key [3,2,1,0] : 0x%08x%08x%08x%08x\n",
00104 (unsigned int) ASM->KEY3,
00105 (unsigned int) ASM->KEY2,
00106 (unsigned int) ASM->KEY1,
00107 (unsigned int) ASM->KEY0);
00108
00109 printf("\n\r*** CTR test ***\n\r");
00110 printf("Encrypt\n\r");
00111 ASM->CONTROL1bits.CTR = 1;
00112
00113 ASM->DATA0 = 0xdeaddead;
00114 ASM->DATA1 = 0xbeefbeef;
00115 ASM->DATA2 = 0xfaceface;
00116 ASM->DATA3 = 0x01234567;
00117
00118 printf("ASM Data [3,2,1,0] : 0x%08x%08x%08x%08x\n",
00119 (unsigned int) ASM->DATA3,
00120 (unsigned int) ASM->DATA2,
00121 (unsigned int) ASM->DATA1,
00122 (unsigned int) ASM->DATA0);
00123
00124 ASM->CTR0 = 0x33333333;
00125 ASM->CTR1 = 0x22222222;
00126 ASM->CTR2 = 0x11111111;
00127 ASM->CTR3 = 0x00000000;
00128
00129 printf("ASM CTR [3,2,1,0] : 0x%08x%08x%08x%08x\n",
00130 (unsigned int) ASM->CTR3,
00131 (unsigned int) ASM->CTR2,
00132 (unsigned int) ASM->CTR1,
00133 (unsigned int) ASM->CTR0);
00134
00135 ASM->CONTROL0bits.START = 1;
00136 while(ASM->STATUSbits.DONE == 0) { continue; }
00137
00138 printf("ASM CTR RESULT [3,2,1,0]: 0x%08x%08x%08x%08x\n",
00139 (unsigned int) ASM->CTR3_RESULT,
00140 (unsigned int) ASM->CTR2_RESULT,
00141 (unsigned int) ASM->CTR1_RESULT,
00142 (unsigned int) ASM->CTR0_RESULT);
00143
00144 printf("Decrypt\n\r");
00145
00146 ASM->DATA0 = ASM->CTR0_RESULT;
00147 ASM->DATA1 = ASM->CTR1_RESULT;
00148 ASM->DATA2 = ASM->CTR2_RESULT;
00149 ASM->DATA3 = ASM->CTR3_RESULT;
00150
00151 ASM->CONTROL0bits.START = 1;
00152 while(ASM->STATUSbits.DONE == 0) { continue; }
00153
00154 printf("ASM CTR RESULT [3,2,1,0]: 0x%08x%08x%08x%08x\n",
00155 (unsigned int) ASM->CTR3_RESULT,
00156 (unsigned int) ASM->CTR2_RESULT,
00157 (unsigned int) ASM->CTR1_RESULT,
00158 (unsigned int) ASM->CTR0_RESULT);
00159
00160 printf("\n\r*** CBC MAC generation ***\n\r");
00161
00162 ASM->CONTROL1bits.CTR = 0;
00163 ASM->CONTROL1bits.CBC = 1;
00164
00165
00166
00167
00168
00169
00170 ASM->DATA0 = 0xdeaddead;
00171 ASM->DATA1 = 0xbeefbeef;
00172 ASM->DATA2 = 0xfaceface;
00173 ASM->DATA3 = 0x01234567;
00174
00175 ASM->CONTROL0bits.CLEAR = 1;
00176
00177 ASM->CONTROL0bits.START = 1;
00178 while(ASM->STATUSbits.DONE == 0) { continue; }
00179
00180 printf("ASM CBC RESULT [3,2,1,0]: 0x%08x%08x%08x%08x\n",
00181 (unsigned int) ASM->CBC3_RESULT,
00182 (unsigned int) ASM->CBC2_RESULT,
00183 (unsigned int) ASM->CBC1_RESULT,
00184 (unsigned int) ASM->CBC0_RESULT);
00185
00186 printf("\n\r*** CCM (CTR+CBC) ***\n\r");
00187
00188 ASM->CONTROL1bits.CTR = 1;
00189 ASM->CONTROL1bits.CBC = 1;
00190 ASM->CONTROL0bits.CLEAR = 1;
00191
00192 ASM->CONTROL0bits.START = 1;
00193 while(ASM->STATUSbits.DONE == 0) { continue; }
00194
00195 printf("ASM CTR RESULT [3,2,1,0]: 0x%08x%08x%08x%08x\n",
00196 (unsigned int) ASM->CTR3_RESULT,
00197 (unsigned int) ASM->CTR2_RESULT,
00198 (unsigned int) ASM->CTR1_RESULT,
00199 (unsigned int) ASM->CTR0_RESULT);
00200
00201 printf("ASM CBC RESULT [3,2,1,0]: 0x%08x%08x%08x%08x\n",
00202 (unsigned int) ASM->CBC3_RESULT,
00203 (unsigned int) ASM->CBC2_RESULT,
00204 (unsigned int) ASM->CBC1_RESULT,
00205 (unsigned int) ASM->CBC0_RESULT);
00206
00207 while(1) {
00208 }
00209 }