NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
Nasungil
Date:
Tue Jul 18 07:32:50 2017 +0000
Revision:
13:e756b6e50853
Parent:
12:c8fbe49527e7
Child:
14:0264a9975d3d
Nm500 Test

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 13:e756b6e50853 76 pc.printf("\nTest Board V1.1 \n");
Nasungil 13:e756b6e50853 77 //SPI Setting
Nasungil 13:e756b6e50853 78 SPI_Init();
Nasungil 13:e756b6e50853 79 SD_Init();
Nasungil 13:e756b6e50853 80 //reset Test
Nasungil 13:e756b6e50853 81 RESET_Test();
Nasungil 13:e756b6e50853 82 //NM500 Init
Nasungil 12:c8fbe49527e7 83 if(begin() == 0){
Nasungil 13:e756b6e50853 84 pc.printf("NM500 Init\n");
Nasungil 12:c8fbe49527e7 85 }
Nasungil 12:c8fbe49527e7 86 else{
Nasungil 13:e756b6e50853 87 error("Init error\n");
Nasungil 13:e756b6e50853 88 pc.printf("\nFORGET error\n");
Nasungil 12:c8fbe49527e7 89 }
Nasungil 13:e756b6e50853 90 //connection Test
Nasungil 13:e756b6e50853 91 Connection_test();
Nasungil 11:6a81bde51be5 92
Nasungil 13:e756b6e50853 93 //Memory Test
Nasungil 13:e756b6e50853 94 Memory_Test();
Nasungil 13:e756b6e50853 95 forget();
Nasungil 13:e756b6e50853 96
Nasungil 12:c8fbe49527e7 97 //memory array init
Nasungil 12:c8fbe49527e7 98 for(int i=0;i<NEURONSIZE;i=i+1){
Nasungil 12:c8fbe49527e7 99 array1[i]=0x0a;
Nasungil 12:c8fbe49527e7 100 array2[i]=0x05;
Nasungil 12:c8fbe49527e7 101 }
Nasungil 12:c8fbe49527e7 102 NSR_Test();
Nasungil 12:c8fbe49527e7 103
Nasungil 11:6a81bde51be5 104 //time measure start
Nasungil 11:6a81bde51be5 105 t.start();
Nasungil 12:c8fbe49527e7 106 //NCOUNT Test
Nasungil 12:c8fbe49527e7 107 int ncount_fail = read(NM_NCOUNT);
Nasungil 11:6a81bde51be5 108
Nasungil 12:c8fbe49527e7 109 if(ncount_fail != 0){
Nasungil 12:c8fbe49527e7 110 CMN_Ncount = 1;
Nasungil 12:c8fbe49527e7 111 error("NCOUNT Fail\n");
Nasungil 12:c8fbe49527e7 112 }
Nasungil 12:c8fbe49527e7 113
Nasungil 8:c41405662e53 114 //minif test
Nasungil 10:74e762848659 115 write(NM_MINIF,3);
Nasungil 12:c8fbe49527e7 116 // int minif = read(NM_MINIF);
Nasungil 12:c8fbe49527e7 117 // if(minif != 3)
Nasungil 12:c8fbe49527e7 118 // CMN_Minif = 1;
Nasungil 11:6a81bde51be5 119
Nasungil 8:c41405662e53 120 //maxif test
Nasungil 9:7970a5638913 121 write(NM_MAXIF,10000);
Nasungil 10:74e762848659 122 int maxif = read(NM_MAXIF);
Nasungil 12:c8fbe49527e7 123 if(maxif != 10000)
Nasungil 12:c8fbe49527e7 124 CMN_Maxif = 1;
Nasungil 8:c41405662e53 125
Nasungil 8:c41405662e53 126 //GCR test
Nasungil 9:7970a5638913 127 write(NM_GCR,5);
Nasungil 12:c8fbe49527e7 128 // int gcr = read(NM_GCR);
Nasungil 13:e756b6e50853 129 // //pc.printf("gcr : %d",gcr);
Nasungil 12:c8fbe49527e7 130 // if(gcr != 5)
Nasungil 12:c8fbe49527e7 131 // CMN_Gcr = 1;
Nasungil 10:74e762848659 132
Nasungil 10:74e762848659 133 st.start();
Nasungil 8:c41405662e53 134 //Neuron learn
Nasungil 13:e756b6e50853 135 pc.printf("\nLearn Start\n");
Nasungil 12:c8fbe49527e7 136
Nasungil 12:c8fbe49527e7 137
Nasungil 12:c8fbe49527e7 138 int daisy = data_learn();
Nasungil 12:c8fbe49527e7 139
Nasungil 10:74e762848659 140 st.stop();
Nasungil 13:e756b6e50853 141 pc.printf("Learn Complete\n");
Nasungil 13:e756b6e50853 142 pc.printf("Learn Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 143 st.reset();
Nasungil 8:c41405662e53 144
Nasungil 9:7970a5638913 145 //data save
Nasungil 10:74e762848659 146 st.start();
Nasungil 13:e756b6e50853 147 pc.printf("Save Start\n");
Nasungil 12:c8fbe49527e7 148
Nasungil 9:7970a5638913 149 int save = NeuronToSD();
Nasungil 12:c8fbe49527e7 150 if(save == 0xFFFF || save == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 151 save = MAXNEURONS;
Nasungil 10:74e762848659 152 st.stop();
Nasungil 13:e756b6e50853 153 pc.printf("Save Complete\n");
Nasungil 13:e756b6e50853 154 pc.printf("Save Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 155 st.reset();
Nasungil 9:7970a5638913 156
Nasungil 10:74e762848659 157 //forget
Nasungil 9:7970a5638913 158 forget();
Nasungil 12:c8fbe49527e7 159
Nasungil 10:74e762848659 160
Nasungil 10:74e762848659 161 //restore
Nasungil 10:74e762848659 162 st.start();
Nasungil 13:e756b6e50853 163 pc.printf("Restore Start\n");
Nasungil 12:c8fbe49527e7 164
Nasungil 10:74e762848659 165 int restore = SDToNeurons();
Nasungil 12:c8fbe49527e7 166
Nasungil 12:c8fbe49527e7 167 if(restore == 0xFFFF || restore == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 168 restore = MAXNEURONS;
Nasungil 10:74e762848659 169 st.stop();
Nasungil 13:e756b6e50853 170 pc.printf("Restore Complete\n");
Nasungil 13:e756b6e50853 171 pc.printf("Restore Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 172 st.reset();
Nasungil 10:74e762848659 173
Nasungil 10:74e762848659 174 setKNN();
Nasungil 10:74e762848659 175 //classify
Nasungil 10:74e762848659 176 st.start();
Nasungil 13:e756b6e50853 177 pc.printf("Classify Start\n");
Nasungil 12:c8fbe49527e7 178
Nasungil 12:c8fbe49527e7 179 data_classify();
Nasungil 10:74e762848659 180 st.stop();
Nasungil 13:e756b6e50853 181 pc.printf("Classify Complete\n");
Nasungil 13:e756b6e50853 182 pc.printf("classify Time : %d ms\n",st.read_ms());
Nasungil 10:74e762848659 183
Nasungil 9:7970a5638913 184
Nasungil 13:e756b6e50853 185 pc.printf("\n****************Test Result****************\n");
Nasungil 12:c8fbe49527e7 186 //nsr result
Nasungil 12:c8fbe49527e7 187 if(CMN_Nsr ==1){
Nasungil 13:e756b6e50853 188 pc.printf("NSR Register Fail\n");
Nasungil 12:c8fbe49527e7 189 CMN++;
Nasungil 12:c8fbe49527e7 190 }
Nasungil 10:74e762848659 191
Nasungil 12:c8fbe49527e7 192 //NCOUNT Result
Nasungil 12:c8fbe49527e7 193 if(CMN_Ncount ==1){
Nasungil 13:e756b6e50853 194 pc.printf("NCOUNT Register Fail\n");
Nasungil 12:c8fbe49527e7 195 CMN++;
Nasungil 10:74e762848659 196 }
Nasungil 10:74e762848659 197
Nasungil 12:c8fbe49527e7 198 //MAXIF Result
Nasungil 12:c8fbe49527e7 199 if(CMN_Maxif ==1){
Nasungil 13:e756b6e50853 200 pc.printf("MAXIF Register Fail\n");
Nasungil 12:c8fbe49527e7 201 CMN++;
Nasungil 12:c8fbe49527e7 202 }
Nasungil 12:c8fbe49527e7 203
Nasungil 12:c8fbe49527e7 204 //MINIF Result
Nasungil 12:c8fbe49527e7 205 if(Minif1 ==1){
Nasungil 13:e756b6e50853 206 pc.printf("#1 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 207 NM1++;
Nasungil 10:74e762848659 208 }
Nasungil 12:c8fbe49527e7 209 if(Minif2 ==1){
Nasungil 13:e756b6e50853 210 pc.printf("#2 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 211 NM2++;
Nasungil 12:c8fbe49527e7 212 }
Nasungil 12:c8fbe49527e7 213
Nasungil 12:c8fbe49527e7 214 //learn result
Nasungil 12:c8fbe49527e7 215 if(Learn1 == 1){
Nasungil 13:e756b6e50853 216 pc.printf("#1 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 217 NM1++;
Nasungil 12:c8fbe49527e7 218 }
Nasungil 12:c8fbe49527e7 219 if(Learn2 == 1){
Nasungil 13:e756b6e50853 220 pc.printf("#2 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 221 NM2++;
Nasungil 10:74e762848659 222 }
Nasungil 10:74e762848659 223
Nasungil 12:c8fbe49527e7 224 //Daisy Chain result
Nasungil 12:c8fbe49527e7 225 if(daisy == 1){
Nasungil 13:e756b6e50853 226 pc.printf("#1 NM500 Daisy Chain Fail\n");
Nasungil 12:c8fbe49527e7 227 NM1++;
Nasungil 12:c8fbe49527e7 228 }
Nasungil 12:c8fbe49527e7 229
Nasungil 12:c8fbe49527e7 230 //GCR result
Nasungil 12:c8fbe49527e7 231 if(Gcr1 == 1){
Nasungil 13:e756b6e50853 232 pc.printf("#1 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 233 NM1++;
Nasungil 12:c8fbe49527e7 234 }
Nasungil 12:c8fbe49527e7 235 if(Gcr2 == 1){
Nasungil 13:e756b6e50853 236 pc.printf("#2 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 237 NM2++;
Nasungil 12:c8fbe49527e7 238 }
Nasungil 12:c8fbe49527e7 239 //AIF result
Nasungil 12:c8fbe49527e7 240 if(Aif1 == 1){
Nasungil 13:e756b6e50853 241 pc.printf("#1 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 242 NM1++;
Nasungil 12:c8fbe49527e7 243 }
Nasungil 12:c8fbe49527e7 244 if(Aif2 == 1){
Nasungil 13:e756b6e50853 245 pc.printf("#2 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 246 NM2++;
Nasungil 10:74e762848659 247 }
Nasungil 12:c8fbe49527e7 248 //Cat result
Nasungil 12:c8fbe49527e7 249 if(Cat1 == 1){
Nasungil 13:e756b6e50853 250 pc.printf("#1 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 251 NM1++;
Nasungil 12:c8fbe49527e7 252 }
Nasungil 12:c8fbe49527e7 253 if(Cat2 == 1){
Nasungil 13:e756b6e50853 254 pc.printf("#2 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 255 NM2++;
Nasungil 12:c8fbe49527e7 256 }
Nasungil 12:c8fbe49527e7 257 if(save != MAXNEURONS){
Nasungil 13:e756b6e50853 258 pc.printf("NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 259 CMN++;
Nasungil 10:74e762848659 260 }
Nasungil 12:c8fbe49527e7 261 if(restore != MAXNEURONS){
Nasungil 13:e756b6e50853 262 pc.printf("NM500 Restore Function Fail\n");
Nasungil 12:c8fbe49527e7 263 CMN++;
Nasungil 12:c8fbe49527e7 264 }
Nasungil 12:c8fbe49527e7 265 //NID result
Nasungil 12:c8fbe49527e7 266 if(Nid1 == 1){
Nasungil 13:e756b6e50853 267 pc.printf("#1 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 268 NM1++;
Nasungil 12:c8fbe49527e7 269 }
Nasungil 12:c8fbe49527e7 270 if(Nid2 == 1){
Nasungil 13:e756b6e50853 271 pc.printf("#2 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 272 NM2++;
Nasungil 10:74e762848659 273 }
Nasungil 10:74e762848659 274
Nasungil 12:c8fbe49527e7 275 //Dist result
Nasungil 12:c8fbe49527e7 276 if(Dist1 == 1){
Nasungil 13:e756b6e50853 277 pc.printf("#1 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 278 NM1++;
Nasungil 12:c8fbe49527e7 279 }
Nasungil 12:c8fbe49527e7 280 if(Dist2 == 1){
Nasungil 13:e756b6e50853 281 pc.printf("#2 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 282 NM2++;
Nasungil 12:c8fbe49527e7 283 }
Nasungil 12:c8fbe49527e7 284 if(Memory1 == 1){
Nasungil 13:e756b6e50853 285 pc.printf("#1 Memory Fail\n");
Nasungil 12:c8fbe49527e7 286 NM1++;
Nasungil 12:c8fbe49527e7 287 }
Nasungil 12:c8fbe49527e7 288 if(Memory2 == 1){
Nasungil 13:e756b6e50853 289 pc.printf("#2 NM500 Memory Fail\n");
Nasungil 12:c8fbe49527e7 290 NM2++;
Nasungil 12:c8fbe49527e7 291 }
Nasungil 12:c8fbe49527e7 292
Nasungil 12:c8fbe49527e7 293 //final result
Nasungil 13:e756b6e50853 294 if(Reset_fail == 1)
Nasungil 13:e756b6e50853 295 pc.printf("Resest Test Fail\n");
Nasungil 12:c8fbe49527e7 296
Nasungil 13:e756b6e50853 297 if(Connection == 1)
Nasungil 13:e756b6e50853 298 pc.printf("Connection Test Fail\n");
Nasungil 13:e756b6e50853 299
Nasungil 13:e756b6e50853 300 if(Memory_fail == 1)
Nasungil 13:e756b6e50853 301 pc.printf("Memory Test Fail \n");
Nasungil 12:c8fbe49527e7 302
Nasungil 13:e756b6e50853 303 if(NM1 !=0)
Nasungil 13:e756b6e50853 304 pc.printf("#1 NM500 Function Test Fail\n");
Nasungil 13:e756b6e50853 305 if(NM2 != 0)
Nasungil 13:e756b6e50853 306 pc.printf("#2 NM500 Function Test Fail\n");
Nasungil 13:e756b6e50853 307 if(NM1 == 0 && NM2 == 0)
Nasungil 13:e756b6e50853 308 pc.printf("#1, #2 NM500 Function Test PASS\n");
Nasungil 12:c8fbe49527e7 309
Nasungil 13:e756b6e50853 310 // pc.printf("POWER SAVE ON\n");
Nasungil 12:c8fbe49527e7 311 // write(NM_POWER_SAVE,0);
Nasungil 13:e756b6e50853 312
Nasungil 10:74e762848659 313 t.stop();
Nasungil 13:e756b6e50853 314 pc.printf("Total Time : %d ms\n",t.read_ms());
Nasungil 12:c8fbe49527e7 315
Nasungil 12:c8fbe49527e7 316 }