NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
Nasungil
Date:
Fri Nov 24 00:45:21 2017 +0000
Revision:
14:0264a9975d3d
Parent:
13:e756b6e50853
Child:
15:4acc28dbd9fe
111

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nasungil 8:c41405662e53 1 #include "mbed.h"
Nasungil 8:c41405662e53 2 #include "NM500.h"
Nasungil 13:e756b6e50853 3 #include "Test.h"
Nasungil 8:c41405662e53 4
Nasungil 13:e756b6e50853 5
Nasungil 12:c8fbe49527e7 6 void data_classify(void);
Nasungil 12:c8fbe49527e7 7 void NSR_Test(void);
Nasungil 13:e756b6e50853 8 void Connection_test(void);
Nasungil 13:e756b6e50853 9 void Memory_Test(void);
Nasungil 13:e756b6e50853 10
Nasungil 13:e756b6e50853 11 //connection
Nasungil 13:e756b6e50853 12 int NSR_Conn_fail = 0;
Nasungil 13:e756b6e50853 13 int GCR_Conn_fail = 0;
Nasungil 13:e756b6e50853 14 int MINIF_Conn_fail = 0;
Nasungil 13:e756b6e50853 15 int MAXIF_Conn_fail = 0;
Nasungil 13:e756b6e50853 16 int NCR_Conn_fail = 0;
Nasungil 13:e756b6e50853 17 int INDEX_Conn_fail = 0;
Nasungil 13:e756b6e50853 18 int DIST_Conn_fail = 0;
Nasungil 13:e756b6e50853 19 int CAT_Conn_fail = 0;
Nasungil 13:e756b6e50853 20 int AIF_Conn_fail = 0;
Nasungil 13:e756b6e50853 21 int NID_Conn_fail = 0;
Nasungil 13:e756b6e50853 22 int Connection = 0;
Nasungil 13:e756b6e50853 23
Nasungil 13:e756b6e50853 24 //reset Test
Nasungil 13:e756b6e50853 25 int Reset_fail = 0;
Nasungil 13:e756b6e50853 26
Nasungil 13:e756b6e50853 27 //memory test
Nasungil 13:e756b6e50853 28 int Memory_fail = 0;
Nasungil 12:c8fbe49527e7 29
Nasungil 12:c8fbe49527e7 30 int id_fail = 0;
Nasungil 12:c8fbe49527e7 31 int nsr_fail = 0;
Nasungil 12:c8fbe49527e7 32
Nasungil 12:c8fbe49527e7 33 int CMN_Maxif = 0;
Nasungil 12:c8fbe49527e7 34 int CMN_Nsr = 0;
Nasungil 12:c8fbe49527e7 35 int CMN_Ncount = 0;
Nasungil 12:c8fbe49527e7 36 int CMN_RC = 0;
Nasungil 12:c8fbe49527e7 37 int CMN = 0;
Nasungil 12:c8fbe49527e7 38
Nasungil 12:c8fbe49527e7 39 int Gcr1 = 0;
Nasungil 12:c8fbe49527e7 40 int Gcr2 = 0;
Nasungil 12:c8fbe49527e7 41 int Minif1 = 0;
Nasungil 12:c8fbe49527e7 42 int Minif2 = 0;
Nasungil 12:c8fbe49527e7 43 int Maxif1 = 0;
Nasungil 12:c8fbe49527e7 44 int Maxif2 = 0;
Nasungil 12:c8fbe49527e7 45 int Aif1 = 0;
Nasungil 12:c8fbe49527e7 46 int Aif2 = 0;
Nasungil 12:c8fbe49527e7 47 int Cat1 = 0;
Nasungil 12:c8fbe49527e7 48 int Cat2 = 0;
Nasungil 12:c8fbe49527e7 49
Nasungil 12:c8fbe49527e7 50 int Nid1 = 0;
Nasungil 12:c8fbe49527e7 51 int Nid2 = 0;
Nasungil 12:c8fbe49527e7 52 int Dist1 = 0;
Nasungil 12:c8fbe49527e7 53 int Dist2 = 0;
Nasungil 12:c8fbe49527e7 54
Nasungil 12:c8fbe49527e7 55 int Learn1 = 0;
Nasungil 12:c8fbe49527e7 56 int Learn2 = 0;
Nasungil 12:c8fbe49527e7 57
Nasungil 12:c8fbe49527e7 58 int Memory1 = 0;
Nasungil 12:c8fbe49527e7 59 int Memory2 = 0;
Nasungil 12:c8fbe49527e7 60
Nasungil 12:c8fbe49527e7 61 int NM1 = 0;
Nasungil 12:c8fbe49527e7 62 int NM2 = 0;
Nasungil 12:c8fbe49527e7 63
Nasungil 13:e756b6e50853 64 unsigned char array1[NEURONSIZE];
Nasungil 13:e756b6e50853 65 unsigned char array2[NEURONSIZE];
Nasungil 10:74e762848659 66
Nasungil 10:74e762848659 67 Timer t, st;
Nasungil 13:e756b6e50853 68 Serial pc(SERIAL_TX, SERIAL_RX);
Nasungil 13:e756b6e50853 69
Nasungil 8:c41405662e53 70
Nasungil 11:6a81bde51be5 71 int main() {
Nasungil 12:c8fbe49527e7 72
Nasungil 13:e756b6e50853 73 pc.printf("\nPress any key to start\n");
Nasungil 13:e756b6e50853 74 int data = pc.getc();
Nasungil 13:e756b6e50853 75
Nasungil 14:0264a9975d3d 76 pc.printf("\nTest Board V2.0 \n");
Nasungil 13:e756b6e50853 77 //SPI Setting
Nasungil 14:0264a9975d3d 78 //time measure start
Nasungil 14:0264a9975d3d 79 t.start();
Nasungil 13:e756b6e50853 80 SPI_Init();
Nasungil 13:e756b6e50853 81 SD_Init();
Nasungil 13:e756b6e50853 82 //reset Test
Nasungil 14:0264a9975d3d 83 st.start();
Nasungil 13:e756b6e50853 84 RESET_Test();
Nasungil 14:0264a9975d3d 85 st.stop();
Nasungil 14:0264a9975d3d 86 pc.printf("Reset Test Time : %d ms\n\n",st.read_ms());
Nasungil 13:e756b6e50853 87 //NM500 Init
Nasungil 12:c8fbe49527e7 88 if(begin() == 0){
Nasungil 13:e756b6e50853 89 pc.printf("NM500 Init\n");
Nasungil 12:c8fbe49527e7 90 }
Nasungil 12:c8fbe49527e7 91 else{
Nasungil 14:0264a9975d3d 92 error("IC Fail\n");
Nasungil 14:0264a9975d3d 93
Nasungil 12:c8fbe49527e7 94 }
Nasungil 13:e756b6e50853 95 //connection Test
Nasungil 14:0264a9975d3d 96 st.start();
Nasungil 13:e756b6e50853 97 Connection_test();
Nasungil 14:0264a9975d3d 98 st.stop();
Nasungil 14:0264a9975d3d 99 pc.printf("Connection Test Time : %d ms\n\n",st.read_ms());
Nasungil 11:6a81bde51be5 100
Nasungil 13:e756b6e50853 101 //Memory Test
Nasungil 14:0264a9975d3d 102 st.start();
Nasungil 13:e756b6e50853 103 Memory_Test();
Nasungil 14:0264a9975d3d 104 st.stop();
Nasungil 14:0264a9975d3d 105 pc.printf("Memory Test Time : %d ms\n\n",st.read_ms());
Nasungil 13:e756b6e50853 106 forget();
Nasungil 13:e756b6e50853 107
Nasungil 12:c8fbe49527e7 108 //memory array init
Nasungil 12:c8fbe49527e7 109 for(int i=0;i<NEURONSIZE;i=i+1){
Nasungil 12:c8fbe49527e7 110 array1[i]=0x0a;
Nasungil 12:c8fbe49527e7 111 array2[i]=0x05;
Nasungil 12:c8fbe49527e7 112 }
Nasungil 12:c8fbe49527e7 113 NSR_Test();
Nasungil 12:c8fbe49527e7 114
Nasungil 14:0264a9975d3d 115
Nasungil 12:c8fbe49527e7 116 //NCOUNT Test
Nasungil 12:c8fbe49527e7 117 int ncount_fail = read(NM_NCOUNT);
Nasungil 11:6a81bde51be5 118
Nasungil 12:c8fbe49527e7 119 if(ncount_fail != 0){
Nasungil 12:c8fbe49527e7 120 CMN_Ncount = 1;
Nasungil 12:c8fbe49527e7 121 error("NCOUNT Fail\n");
Nasungil 12:c8fbe49527e7 122 }
Nasungil 12:c8fbe49527e7 123
Nasungil 8:c41405662e53 124 //minif test
Nasungil 10:74e762848659 125 write(NM_MINIF,3);
Nasungil 12:c8fbe49527e7 126 // int minif = read(NM_MINIF);
Nasungil 12:c8fbe49527e7 127 // if(minif != 3)
Nasungil 12:c8fbe49527e7 128 // CMN_Minif = 1;
Nasungil 11:6a81bde51be5 129
Nasungil 8:c41405662e53 130 //maxif test
Nasungil 9:7970a5638913 131 write(NM_MAXIF,10000);
Nasungil 10:74e762848659 132 int maxif = read(NM_MAXIF);
Nasungil 12:c8fbe49527e7 133 if(maxif != 10000)
Nasungil 12:c8fbe49527e7 134 CMN_Maxif = 1;
Nasungil 8:c41405662e53 135
Nasungil 8:c41405662e53 136 //GCR test
Nasungil 9:7970a5638913 137 write(NM_GCR,5);
Nasungil 12:c8fbe49527e7 138 // int gcr = read(NM_GCR);
Nasungil 13:e756b6e50853 139 // //pc.printf("gcr : %d",gcr);
Nasungil 12:c8fbe49527e7 140 // if(gcr != 5)
Nasungil 12:c8fbe49527e7 141 // CMN_Gcr = 1;
Nasungil 10:74e762848659 142
Nasungil 10:74e762848659 143 st.start();
Nasungil 8:c41405662e53 144 //Neuron learn
Nasungil 13:e756b6e50853 145 pc.printf("\nLearn Start\n");
Nasungil 12:c8fbe49527e7 146
Nasungil 12:c8fbe49527e7 147
Nasungil 12:c8fbe49527e7 148 int daisy = data_learn();
Nasungil 12:c8fbe49527e7 149
Nasungil 10:74e762848659 150 st.stop();
Nasungil 13:e756b6e50853 151 pc.printf("Learn Complete\n");
Nasungil 14:0264a9975d3d 152 pc.printf("Learn Time : %d ms\n\n",st.read_ms());
Nasungil 11:6a81bde51be5 153 st.reset();
Nasungil 8:c41405662e53 154
Nasungil 9:7970a5638913 155 //data save
Nasungil 10:74e762848659 156 st.start();
Nasungil 13:e756b6e50853 157 pc.printf("Save Start\n");
Nasungil 12:c8fbe49527e7 158
Nasungil 9:7970a5638913 159 int save = NeuronToSD();
Nasungil 12:c8fbe49527e7 160 if(save == 0xFFFF || save == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 161 save = MAXNEURONS;
Nasungil 10:74e762848659 162 st.stop();
Nasungil 13:e756b6e50853 163 pc.printf("Save Complete\n");
Nasungil 14:0264a9975d3d 164 pc.printf("Save Time : %d ms\n\n",st.read_ms());
Nasungil 11:6a81bde51be5 165 st.reset();
Nasungil 9:7970a5638913 166
Nasungil 10:74e762848659 167 //forget
Nasungil 9:7970a5638913 168 forget();
Nasungil 12:c8fbe49527e7 169
Nasungil 10:74e762848659 170
Nasungil 10:74e762848659 171 //restore
Nasungil 10:74e762848659 172 st.start();
Nasungil 13:e756b6e50853 173 pc.printf("Restore Start\n");
Nasungil 12:c8fbe49527e7 174
Nasungil 10:74e762848659 175 int restore = SDToNeurons();
Nasungil 12:c8fbe49527e7 176
Nasungil 12:c8fbe49527e7 177 if(restore == 0xFFFF || restore == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 178 restore = MAXNEURONS;
Nasungil 10:74e762848659 179 st.stop();
Nasungil 13:e756b6e50853 180 pc.printf("Restore Complete\n");
Nasungil 14:0264a9975d3d 181 pc.printf("Restore Time : %d ms\n\n",st.read_ms());
Nasungil 11:6a81bde51be5 182 st.reset();
Nasungil 10:74e762848659 183
Nasungil 10:74e762848659 184 setKNN();
Nasungil 10:74e762848659 185 //classify
Nasungil 10:74e762848659 186 st.start();
Nasungil 13:e756b6e50853 187 pc.printf("Classify Start\n");
Nasungil 12:c8fbe49527e7 188
Nasungil 12:c8fbe49527e7 189 data_classify();
Nasungil 10:74e762848659 190 st.stop();
Nasungil 13:e756b6e50853 191 pc.printf("Classify Complete\n");
Nasungil 14:0264a9975d3d 192 pc.printf("classify Time : %d ms\n\n",st.read_ms());
Nasungil 10:74e762848659 193
Nasungil 9:7970a5638913 194
Nasungil 13:e756b6e50853 195 pc.printf("\n****************Test Result****************\n");
Nasungil 12:c8fbe49527e7 196 //nsr result
Nasungil 12:c8fbe49527e7 197 if(CMN_Nsr ==1){
Nasungil 13:e756b6e50853 198 pc.printf("NSR Register Fail\n");
Nasungil 12:c8fbe49527e7 199 CMN++;
Nasungil 12:c8fbe49527e7 200 }
Nasungil 10:74e762848659 201
Nasungil 12:c8fbe49527e7 202 //NCOUNT Result
Nasungil 12:c8fbe49527e7 203 if(CMN_Ncount ==1){
Nasungil 13:e756b6e50853 204 pc.printf("NCOUNT Register Fail\n");
Nasungil 12:c8fbe49527e7 205 CMN++;
Nasungil 10:74e762848659 206 }
Nasungil 10:74e762848659 207
Nasungil 12:c8fbe49527e7 208 //MAXIF Result
Nasungil 12:c8fbe49527e7 209 if(CMN_Maxif ==1){
Nasungil 13:e756b6e50853 210 pc.printf("MAXIF Register Fail\n");
Nasungil 12:c8fbe49527e7 211 CMN++;
Nasungil 12:c8fbe49527e7 212 }
Nasungil 12:c8fbe49527e7 213
Nasungil 12:c8fbe49527e7 214 //MINIF Result
Nasungil 12:c8fbe49527e7 215 if(Minif1 ==1){
Nasungil 13:e756b6e50853 216 pc.printf("#1 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 217 NM1++;
Nasungil 10:74e762848659 218 }
Nasungil 12:c8fbe49527e7 219 if(Minif2 ==1){
Nasungil 13:e756b6e50853 220 pc.printf("#2 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 221 NM2++;
Nasungil 12:c8fbe49527e7 222 }
Nasungil 12:c8fbe49527e7 223
Nasungil 12:c8fbe49527e7 224 //learn result
Nasungil 12:c8fbe49527e7 225 if(Learn1 == 1){
Nasungil 13:e756b6e50853 226 pc.printf("#1 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 227 NM1++;
Nasungil 12:c8fbe49527e7 228 }
Nasungil 12:c8fbe49527e7 229 if(Learn2 == 1){
Nasungil 13:e756b6e50853 230 pc.printf("#2 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 231 NM2++;
Nasungil 10:74e762848659 232 }
Nasungil 10:74e762848659 233
Nasungil 12:c8fbe49527e7 234 //Daisy Chain result
Nasungil 12:c8fbe49527e7 235 if(daisy == 1){
Nasungil 13:e756b6e50853 236 pc.printf("#1 NM500 Daisy Chain Fail\n");
Nasungil 12:c8fbe49527e7 237 NM1++;
Nasungil 12:c8fbe49527e7 238 }
Nasungil 12:c8fbe49527e7 239
Nasungil 12:c8fbe49527e7 240 //GCR result
Nasungil 12:c8fbe49527e7 241 if(Gcr1 == 1){
Nasungil 13:e756b6e50853 242 pc.printf("#1 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 243 NM1++;
Nasungil 12:c8fbe49527e7 244 }
Nasungil 12:c8fbe49527e7 245 if(Gcr2 == 1){
Nasungil 13:e756b6e50853 246 pc.printf("#2 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 247 NM2++;
Nasungil 12:c8fbe49527e7 248 }
Nasungil 12:c8fbe49527e7 249 //AIF result
Nasungil 12:c8fbe49527e7 250 if(Aif1 == 1){
Nasungil 13:e756b6e50853 251 pc.printf("#1 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 252 NM1++;
Nasungil 12:c8fbe49527e7 253 }
Nasungil 12:c8fbe49527e7 254 if(Aif2 == 1){
Nasungil 13:e756b6e50853 255 pc.printf("#2 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 256 NM2++;
Nasungil 10:74e762848659 257 }
Nasungil 12:c8fbe49527e7 258 //Cat result
Nasungil 12:c8fbe49527e7 259 if(Cat1 == 1){
Nasungil 13:e756b6e50853 260 pc.printf("#1 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 261 NM1++;
Nasungil 12:c8fbe49527e7 262 }
Nasungil 12:c8fbe49527e7 263 if(Cat2 == 1){
Nasungil 13:e756b6e50853 264 pc.printf("#2 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 265 NM2++;
Nasungil 12:c8fbe49527e7 266 }
Nasungil 12:c8fbe49527e7 267 if(save != MAXNEURONS){
Nasungil 13:e756b6e50853 268 pc.printf("NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 269 CMN++;
Nasungil 10:74e762848659 270 }
Nasungil 12:c8fbe49527e7 271 if(restore != MAXNEURONS){
Nasungil 13:e756b6e50853 272 pc.printf("NM500 Restore Function Fail\n");
Nasungil 12:c8fbe49527e7 273 CMN++;
Nasungil 12:c8fbe49527e7 274 }
Nasungil 12:c8fbe49527e7 275 //NID result
Nasungil 12:c8fbe49527e7 276 if(Nid1 == 1){
Nasungil 13:e756b6e50853 277 pc.printf("#1 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 278 NM1++;
Nasungil 12:c8fbe49527e7 279 }
Nasungil 12:c8fbe49527e7 280 if(Nid2 == 1){
Nasungil 13:e756b6e50853 281 pc.printf("#2 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 282 NM2++;
Nasungil 10:74e762848659 283 }
Nasungil 10:74e762848659 284
Nasungil 12:c8fbe49527e7 285 //Dist result
Nasungil 12:c8fbe49527e7 286 if(Dist1 == 1){
Nasungil 13:e756b6e50853 287 pc.printf("#1 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 288 NM1++;
Nasungil 12:c8fbe49527e7 289 }
Nasungil 12:c8fbe49527e7 290 if(Dist2 == 1){
Nasungil 13:e756b6e50853 291 pc.printf("#2 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 292 NM2++;
Nasungil 12:c8fbe49527e7 293 }
Nasungil 12:c8fbe49527e7 294 if(Memory1 == 1){
Nasungil 13:e756b6e50853 295 pc.printf("#1 Memory Fail\n");
Nasungil 12:c8fbe49527e7 296 NM1++;
Nasungil 12:c8fbe49527e7 297 }
Nasungil 12:c8fbe49527e7 298 if(Memory2 == 1){
Nasungil 13:e756b6e50853 299 pc.printf("#2 NM500 Memory Fail\n");
Nasungil 12:c8fbe49527e7 300 NM2++;
Nasungil 12:c8fbe49527e7 301 }
Nasungil 12:c8fbe49527e7 302
Nasungil 12:c8fbe49527e7 303 //final result
Nasungil 13:e756b6e50853 304 if(Reset_fail == 1)
Nasungil 13:e756b6e50853 305 pc.printf("Resest Test Fail\n");
Nasungil 14:0264a9975d3d 306 else
Nasungil 14:0264a9975d3d 307 pc.printf("Resest Test Pass\n");
Nasungil 12:c8fbe49527e7 308
Nasungil 13:e756b6e50853 309 if(Connection == 1)
Nasungil 13:e756b6e50853 310 pc.printf("Connection Test Fail\n");
Nasungil 14:0264a9975d3d 311 else
Nasungil 14:0264a9975d3d 312 pc.printf("Connection Test Pass\n");
Nasungil 13:e756b6e50853 313
Nasungil 13:e756b6e50853 314 if(Memory_fail == 1)
Nasungil 13:e756b6e50853 315 pc.printf("Memory Test Fail \n");
Nasungil 14:0264a9975d3d 316 else
Nasungil 14:0264a9975d3d 317 pc.printf("Memory Test Pass\n");
Nasungil 13:e756b6e50853 318 if(NM1 !=0)
Nasungil 13:e756b6e50853 319 pc.printf("#1 NM500 Function Test Fail\n");
Nasungil 13:e756b6e50853 320 if(NM2 != 0)
Nasungil 13:e756b6e50853 321 pc.printf("#2 NM500 Function Test Fail\n");
Nasungil 13:e756b6e50853 322 if(NM1 == 0 && NM2 == 0)
Nasungil 14:0264a9975d3d 323 pc.printf("NM500 Function Test PASS\n");
Nasungil 12:c8fbe49527e7 324
Nasungil 13:e756b6e50853 325 // pc.printf("POWER SAVE ON\n");
Nasungil 12:c8fbe49527e7 326 // write(NM_POWER_SAVE,0);
Nasungil 13:e756b6e50853 327
Nasungil 10:74e762848659 328 t.stop();
Nasungil 13:e756b6e50853 329 pc.printf("Total Time : %d ms\n",t.read_ms());
Nasungil 12:c8fbe49527e7 330
Nasungil 12:c8fbe49527e7 331 }
Nasungil 14:0264a9975d3d 332
Nasungil 14:0264a9975d3d 333
Nasungil 14:0264a9975d3d 334