NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

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