NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
Nasungil
Date:
Fri Jun 23 05:37:34 2017 +0000
Revision:
12:c8fbe49527e7
Parent:
11:6a81bde51be5
Child:
13:e756b6e50853
NM500 Test FW Rev0

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 8:c41405662e53 3
Nasungil 8:c41405662e53 4 int data_learn(void);
Nasungil 12:c8fbe49527e7 5 void data_classify(void);
Nasungil 12:c8fbe49527e7 6 void NSR_Test(void);
Nasungil 12:c8fbe49527e7 7
Nasungil 12:c8fbe49527e7 8 int id_fail = 0;
Nasungil 12:c8fbe49527e7 9 int nsr_fail = 0;
Nasungil 12:c8fbe49527e7 10
Nasungil 12:c8fbe49527e7 11 int CMN_Maxif = 0;
Nasungil 12:c8fbe49527e7 12 int CMN_Nsr = 0;
Nasungil 12:c8fbe49527e7 13 int CMN_Ncount = 0;
Nasungil 12:c8fbe49527e7 14 int CMN_RC = 0;
Nasungil 12:c8fbe49527e7 15 int CMN = 0;
Nasungil 12:c8fbe49527e7 16
Nasungil 12:c8fbe49527e7 17 int Gcr1 = 0;
Nasungil 12:c8fbe49527e7 18 int Gcr2 = 0;
Nasungil 12:c8fbe49527e7 19 int Minif1 = 0;
Nasungil 12:c8fbe49527e7 20 int Minif2 = 0;
Nasungil 12:c8fbe49527e7 21 int Maxif1 = 0;
Nasungil 12:c8fbe49527e7 22 int Maxif2 = 0;
Nasungil 12:c8fbe49527e7 23 int Aif1 = 0;
Nasungil 12:c8fbe49527e7 24 int Aif2 = 0;
Nasungil 12:c8fbe49527e7 25 int Cat1 = 0;
Nasungil 12:c8fbe49527e7 26 int Cat2 = 0;
Nasungil 12:c8fbe49527e7 27
Nasungil 12:c8fbe49527e7 28 int Nid1 = 0;
Nasungil 12:c8fbe49527e7 29 int Nid2 = 0;
Nasungil 12:c8fbe49527e7 30 int Dist1 = 0;
Nasungil 12:c8fbe49527e7 31 int Dist2 = 0;
Nasungil 12:c8fbe49527e7 32
Nasungil 12:c8fbe49527e7 33 int Learn1 = 0;
Nasungil 12:c8fbe49527e7 34 int Learn2 = 0;
Nasungil 12:c8fbe49527e7 35
Nasungil 12:c8fbe49527e7 36 int Memory1 = 0;
Nasungil 12:c8fbe49527e7 37 int Memory2 = 0;
Nasungil 12:c8fbe49527e7 38
Nasungil 12:c8fbe49527e7 39 int NM1 = 0;
Nasungil 12:c8fbe49527e7 40 int NM2 = 0;
Nasungil 12:c8fbe49527e7 41
Nasungil 12:c8fbe49527e7 42 char array1[NEURONSIZE];
Nasungil 12:c8fbe49527e7 43 char array2[NEURONSIZE];
Nasungil 10:74e762848659 44
Nasungil 10:74e762848659 45 Timer t, st;
Nasungil 11:6a81bde51be5 46 //Serial pc(SERIAL_TX, SERIAL_RX);
Nasungil 8:c41405662e53 47 unsigned char vector[NEURONSIZE];
Nasungil 8:c41405662e53 48
Nasungil 11:6a81bde51be5 49 int main() {
Nasungil 12:c8fbe49527e7 50
Nasungil 8:c41405662e53 51 //NM500 & SD Card Init
Nasungil 12:c8fbe49527e7 52 if(begin() == 0){
Nasungil 12:c8fbe49527e7 53 printf("\nTest Board V2.0 \n");
Nasungil 12:c8fbe49527e7 54 printf("\n\nNM500 Init \n");
Nasungil 12:c8fbe49527e7 55 }
Nasungil 12:c8fbe49527e7 56 else{
Nasungil 12:c8fbe49527e7 57 printf("\nInit error\n");
Nasungil 12:c8fbe49527e7 58 //int forget = 1;
Nasungil 12:c8fbe49527e7 59 error("\nFORGET error\n");
Nasungil 12:c8fbe49527e7 60 }
Nasungil 11:6a81bde51be5 61
Nasungil 12:c8fbe49527e7 62 //memory array init
Nasungil 12:c8fbe49527e7 63 for(int i=0;i<NEURONSIZE;i=i+1){
Nasungil 12:c8fbe49527e7 64 array1[i]=0x0a;
Nasungil 12:c8fbe49527e7 65 array2[i]=0x05;
Nasungil 12:c8fbe49527e7 66 }
Nasungil 12:c8fbe49527e7 67 NSR_Test();
Nasungil 12:c8fbe49527e7 68
Nasungil 11:6a81bde51be5 69 //time measure start
Nasungil 11:6a81bde51be5 70 t.start();
Nasungil 12:c8fbe49527e7 71 //NCOUNT Test
Nasungil 12:c8fbe49527e7 72 int ncount_fail = read(NM_NCOUNT);
Nasungil 11:6a81bde51be5 73
Nasungil 12:c8fbe49527e7 74 if(ncount_fail != 0){
Nasungil 12:c8fbe49527e7 75 CMN_Ncount = 1;
Nasungil 12:c8fbe49527e7 76 error("NCOUNT Fail\n");
Nasungil 12:c8fbe49527e7 77 }
Nasungil 12:c8fbe49527e7 78
Nasungil 8:c41405662e53 79 //minif test
Nasungil 10:74e762848659 80 write(NM_MINIF,3);
Nasungil 12:c8fbe49527e7 81 // int minif = read(NM_MINIF);
Nasungil 12:c8fbe49527e7 82 // if(minif != 3)
Nasungil 12:c8fbe49527e7 83 // CMN_Minif = 1;
Nasungil 11:6a81bde51be5 84
Nasungil 8:c41405662e53 85 //maxif test
Nasungil 9:7970a5638913 86 write(NM_MAXIF,10000);
Nasungil 10:74e762848659 87 int maxif = read(NM_MAXIF);
Nasungil 12:c8fbe49527e7 88 if(maxif != 10000)
Nasungil 12:c8fbe49527e7 89 CMN_Maxif = 1;
Nasungil 8:c41405662e53 90
Nasungil 8:c41405662e53 91 //GCR test
Nasungil 9:7970a5638913 92 write(NM_GCR,5);
Nasungil 12:c8fbe49527e7 93 // int gcr = read(NM_GCR);
Nasungil 12:c8fbe49527e7 94 // //printf("gcr : %d",gcr);
Nasungil 12:c8fbe49527e7 95 // if(gcr != 5)
Nasungil 12:c8fbe49527e7 96 // CMN_Gcr = 1;
Nasungil 10:74e762848659 97
Nasungil 10:74e762848659 98 st.start();
Nasungil 8:c41405662e53 99 //Neuron learn
Nasungil 11:6a81bde51be5 100 printf("Learn Start\n");
Nasungil 12:c8fbe49527e7 101
Nasungil 12:c8fbe49527e7 102
Nasungil 12:c8fbe49527e7 103 int daisy = data_learn();
Nasungil 12:c8fbe49527e7 104
Nasungil 10:74e762848659 105 st.stop();
Nasungil 11:6a81bde51be5 106 printf("Learn Complete\n");
Nasungil 10:74e762848659 107 printf("Learn Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 108 st.reset();
Nasungil 8:c41405662e53 109
Nasungil 9:7970a5638913 110 //data save
Nasungil 10:74e762848659 111 st.start();
Nasungil 11:6a81bde51be5 112 printf("Save Start\n");
Nasungil 12:c8fbe49527e7 113
Nasungil 9:7970a5638913 114 int save = NeuronToSD();
Nasungil 12:c8fbe49527e7 115 if(save == 0xFFFF || save == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 116 save = MAXNEURONS;
Nasungil 10:74e762848659 117 st.stop();
Nasungil 10:74e762848659 118 printf("Save Complete\n");
Nasungil 10:74e762848659 119 printf("Save Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 120 st.reset();
Nasungil 9:7970a5638913 121
Nasungil 10:74e762848659 122 //forget
Nasungil 9:7970a5638913 123 forget();
Nasungil 12:c8fbe49527e7 124
Nasungil 10:74e762848659 125
Nasungil 10:74e762848659 126 //restore
Nasungil 10:74e762848659 127 st.start();
Nasungil 11:6a81bde51be5 128 printf("Restore Start\n");
Nasungil 12:c8fbe49527e7 129
Nasungil 10:74e762848659 130 int restore = SDToNeurons();
Nasungil 12:c8fbe49527e7 131
Nasungil 12:c8fbe49527e7 132 if(restore == 0xFFFF || restore == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 133 restore = MAXNEURONS;
Nasungil 10:74e762848659 134 st.stop();
Nasungil 10:74e762848659 135 printf("Restore Complete\n");
Nasungil 10:74e762848659 136 printf("Restore Time : %d ms\n",st.read_ms());
Nasungil 11:6a81bde51be5 137 st.reset();
Nasungil 10:74e762848659 138
Nasungil 10:74e762848659 139 setKNN();
Nasungil 10:74e762848659 140 //classify
Nasungil 10:74e762848659 141 st.start();
Nasungil 11:6a81bde51be5 142 printf("Classify Start\n");
Nasungil 12:c8fbe49527e7 143
Nasungil 12:c8fbe49527e7 144 data_classify();
Nasungil 10:74e762848659 145 st.stop();
Nasungil 10:74e762848659 146 printf("Classify Complete\n");
Nasungil 10:74e762848659 147 printf("classify Time : %d ms\n",st.read_ms());
Nasungil 10:74e762848659 148
Nasungil 9:7970a5638913 149
Nasungil 12:c8fbe49527e7 150 printf("\n****************Test Result****************\n");
Nasungil 12:c8fbe49527e7 151 //nsr result
Nasungil 12:c8fbe49527e7 152 if(CMN_Nsr ==1){
Nasungil 12:c8fbe49527e7 153 printf("NSR Register Fail\n");
Nasungil 12:c8fbe49527e7 154 CMN++;
Nasungil 12:c8fbe49527e7 155 }
Nasungil 10:74e762848659 156
Nasungil 12:c8fbe49527e7 157 //NCOUNT Result
Nasungil 12:c8fbe49527e7 158 if(CMN_Ncount ==1){
Nasungil 12:c8fbe49527e7 159 printf("NCOUNT Register Fail\n");
Nasungil 12:c8fbe49527e7 160 CMN++;
Nasungil 10:74e762848659 161 }
Nasungil 10:74e762848659 162
Nasungil 12:c8fbe49527e7 163 //MAXIF Result
Nasungil 12:c8fbe49527e7 164 if(CMN_Maxif ==1){
Nasungil 12:c8fbe49527e7 165 printf("MAXIF Register Fail\n");
Nasungil 12:c8fbe49527e7 166 CMN++;
Nasungil 12:c8fbe49527e7 167 }
Nasungil 12:c8fbe49527e7 168
Nasungil 12:c8fbe49527e7 169 //MINIF Result
Nasungil 12:c8fbe49527e7 170 if(Minif1 ==1){
Nasungil 12:c8fbe49527e7 171 printf("#1 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 172 NM1++;
Nasungil 10:74e762848659 173 }
Nasungil 12:c8fbe49527e7 174 if(Minif2 ==1){
Nasungil 12:c8fbe49527e7 175 printf("#2 NM500 MINIF Register Fail\n");
Nasungil 12:c8fbe49527e7 176 NM2++;
Nasungil 12:c8fbe49527e7 177 }
Nasungil 12:c8fbe49527e7 178
Nasungil 12:c8fbe49527e7 179 //learn result
Nasungil 12:c8fbe49527e7 180 if(Learn1 == 1){
Nasungil 12:c8fbe49527e7 181 printf("#1 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 182 NM1++;
Nasungil 12:c8fbe49527e7 183 }
Nasungil 12:c8fbe49527e7 184 if(Learn2 == 1){
Nasungil 12:c8fbe49527e7 185 printf("#2 NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 186 NM2++;
Nasungil 10:74e762848659 187 }
Nasungil 10:74e762848659 188
Nasungil 12:c8fbe49527e7 189 //Daisy Chain result
Nasungil 12:c8fbe49527e7 190 if(daisy == 1){
Nasungil 12:c8fbe49527e7 191 printf("#1 NM500 Daisy Chain Fail\n");
Nasungil 12:c8fbe49527e7 192 NM1++;
Nasungil 12:c8fbe49527e7 193 }
Nasungil 12:c8fbe49527e7 194
Nasungil 12:c8fbe49527e7 195 //GCR result
Nasungil 12:c8fbe49527e7 196 if(Gcr1 == 1){
Nasungil 12:c8fbe49527e7 197 printf("#1 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 198 NM1++;
Nasungil 12:c8fbe49527e7 199 }
Nasungil 12:c8fbe49527e7 200 if(Gcr2 == 1){
Nasungil 12:c8fbe49527e7 201 printf("#2 NM500 GCR Register Fail\n");
Nasungil 12:c8fbe49527e7 202 NM2++;
Nasungil 12:c8fbe49527e7 203 }
Nasungil 12:c8fbe49527e7 204 //AIF result
Nasungil 12:c8fbe49527e7 205 if(Aif1 == 1){
Nasungil 12:c8fbe49527e7 206 printf("#1 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 207 NM1++;
Nasungil 12:c8fbe49527e7 208 }
Nasungil 12:c8fbe49527e7 209 if(Aif2 == 1){
Nasungil 12:c8fbe49527e7 210 printf("#2 NM500 AIF Register Fail\n");
Nasungil 12:c8fbe49527e7 211 NM2++;
Nasungil 10:74e762848659 212 }
Nasungil 12:c8fbe49527e7 213 //Cat result
Nasungil 12:c8fbe49527e7 214 if(Cat1 == 1){
Nasungil 12:c8fbe49527e7 215 printf("#1 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 216 NM1++;
Nasungil 12:c8fbe49527e7 217 }
Nasungil 12:c8fbe49527e7 218 if(Cat2 == 1){
Nasungil 12:c8fbe49527e7 219 printf("#2 NM500 CAT Register Fail\n");
Nasungil 12:c8fbe49527e7 220 NM2++;
Nasungil 12:c8fbe49527e7 221 }
Nasungil 12:c8fbe49527e7 222 if(save != MAXNEURONS){
Nasungil 12:c8fbe49527e7 223 printf("NM500 Learn Function Fail\n");
Nasungil 12:c8fbe49527e7 224 CMN++;
Nasungil 10:74e762848659 225 }
Nasungil 12:c8fbe49527e7 226 if(restore != MAXNEURONS){
Nasungil 12:c8fbe49527e7 227 printf("NM500 Restore Function Fail\n");
Nasungil 12:c8fbe49527e7 228 CMN++;
Nasungil 12:c8fbe49527e7 229 }
Nasungil 12:c8fbe49527e7 230 //NID result
Nasungil 12:c8fbe49527e7 231 if(Nid1 == 1){
Nasungil 12:c8fbe49527e7 232 printf("#1 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 233 NM1++;
Nasungil 12:c8fbe49527e7 234 }
Nasungil 12:c8fbe49527e7 235 if(Nid2 == 1){
Nasungil 12:c8fbe49527e7 236 printf("#2 NM500 Nid Register Fail\n");
Nasungil 12:c8fbe49527e7 237 NM2++;
Nasungil 10:74e762848659 238 }
Nasungil 10:74e762848659 239
Nasungil 12:c8fbe49527e7 240 //Dist result
Nasungil 12:c8fbe49527e7 241 if(Dist1 == 1){
Nasungil 12:c8fbe49527e7 242 printf("#1 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 243 NM1++;
Nasungil 12:c8fbe49527e7 244 }
Nasungil 12:c8fbe49527e7 245 if(Dist2 == 1){
Nasungil 12:c8fbe49527e7 246 printf("#2 NM500 Dist Register Fail\n");
Nasungil 12:c8fbe49527e7 247 NM2++;
Nasungil 12:c8fbe49527e7 248 }
Nasungil 12:c8fbe49527e7 249 if(Memory1 == 1){
Nasungil 12:c8fbe49527e7 250 printf("#1 NM500 Memory Fail\n");
Nasungil 12:c8fbe49527e7 251 NM1++;
Nasungil 12:c8fbe49527e7 252 }
Nasungil 12:c8fbe49527e7 253 if(Memory2 == 1){
Nasungil 12:c8fbe49527e7 254 printf("#2 NM500 Memory Fail\n");
Nasungil 12:c8fbe49527e7 255 NM2++;
Nasungil 12:c8fbe49527e7 256 }
Nasungil 12:c8fbe49527e7 257
Nasungil 12:c8fbe49527e7 258 //final result
Nasungil 12:c8fbe49527e7 259 if(NM1 >1)
Nasungil 12:c8fbe49527e7 260 printf("#1 NM500 Fail\n");
Nasungil 12:c8fbe49527e7 261 if(NM2 > 1)
Nasungil 12:c8fbe49527e7 262 printf("#2 NM500 Fail\n");
Nasungil 12:c8fbe49527e7 263 if(CMN>1)
Nasungil 12:c8fbe49527e7 264 printf("#1, #2 Fail\n");
Nasungil 12:c8fbe49527e7 265 if(CMN == 0 && NM1 == 0 && NM2 == 0)
Nasungil 12:c8fbe49527e7 266 printf("#1, #2 NM500 PASS\n");
Nasungil 12:c8fbe49527e7 267
Nasungil 12:c8fbe49527e7 268
Nasungil 12:c8fbe49527e7 269
Nasungil 12:c8fbe49527e7 270
Nasungil 12:c8fbe49527e7 271 // //reset chain result
Nasungil 12:c8fbe49527e7 272 // if(CMN_RC == 1)
Nasungil 12:c8fbe49527e7 273 // printf("Reset Chain Register Fail\n");
Nasungil 12:c8fbe49527e7 274
Nasungil 12:c8fbe49527e7 275 // printf("POWER SAVE ON\n");
Nasungil 12:c8fbe49527e7 276 // write(NM_POWER_SAVE,0);
Nasungil 10:74e762848659 277 t.stop();
Nasungil 10:74e762848659 278 printf("Total Time : %d ms\n",t.read_ms());
Nasungil 12:c8fbe49527e7 279
Nasungil 12:c8fbe49527e7 280 }
Nasungil 12:c8fbe49527e7 281 void NSR_Test(void)
Nasungil 12:c8fbe49527e7 282 {
Nasungil 12:c8fbe49527e7 283 //KNN Mode setting
Nasungil 12:c8fbe49527e7 284 setKNN();
Nasungil 12:c8fbe49527e7 285 //read KNN Register
Nasungil 12:c8fbe49527e7 286 int nsr = read(NM_NSR) & 0x20;
Nasungil 12:c8fbe49527e7 287 if(nsr != 32)
Nasungil 12:c8fbe49527e7 288 CMN_Nsr = 1; //fail
Nasungil 12:c8fbe49527e7 289
Nasungil 12:c8fbe49527e7 290 //RBF Mode setting
Nasungil 12:c8fbe49527e7 291 setRBF();
Nasungil 12:c8fbe49527e7 292 nsr = read(NM_NSR) & 0x20;
Nasungil 12:c8fbe49527e7 293 if(nsr != 0)
Nasungil 12:c8fbe49527e7 294 CMN_Nsr = 1; //fail
Nasungil 12:c8fbe49527e7 295
Nasungil 12:c8fbe49527e7 296 int temp_nsr = read(NM_NSR);
Nasungil 12:c8fbe49527e7 297
Nasungil 12:c8fbe49527e7 298 //SR Mode test
Nasungil 12:c8fbe49527e7 299 write(NM_NSR, 0x10);
Nasungil 12:c8fbe49527e7 300 nsr = read(NM_NSR) & 0x10;
Nasungil 12:c8fbe49527e7 301 if(nsr != 16)
Nasungil 12:c8fbe49527e7 302 CMN_Nsr = 1;
Nasungil 12:c8fbe49527e7 303
Nasungil 12:c8fbe49527e7 304 //Nomal Mode Test
Nasungil 12:c8fbe49527e7 305 write(NM_NSR, temp_nsr);
Nasungil 12:c8fbe49527e7 306 nsr = read(NM_NSR) & 0x10;
Nasungil 12:c8fbe49527e7 307 if(nsr != 0)
Nasungil 12:c8fbe49527e7 308 CMN_Nsr = 1;
Nasungil 8:c41405662e53 309 }
Nasungil 8:c41405662e53 310 int data_learn(void)
Nasungil 8:c41405662e53 311 {
Nasungil 12:c8fbe49527e7 312 int ncnt=0,old_ncnt=0; //ncount, old ncount
Nasungil 12:c8fbe49527e7 313
Nasungil 12:c8fbe49527e7 314 //number of neuron 576*2
Nasungil 12:c8fbe49527e7 315 for(int i=1;i<=MAXNEURONS;i++){
Nasungil 12:c8fbe49527e7 316 // ex
Nasungil 12:c8fbe49527e7 317 // 1. 0 1 0 1....
Nasungil 12:c8fbe49527e7 318 // 2. 0 2 0 2....
Nasungil 12:c8fbe49527e7 319 // 3. 0 3 0 3....
Nasungil 12:c8fbe49527e7 320 // .....
Nasungil 12:c8fbe49527e7 321 // 255. 0 255 0 255....
Nasungil 12:c8fbe49527e7 322 // 256. 1 0 1 0....
Nasungil 12:c8fbe49527e7 323 // 257. 1 1 1 1....
Nasungil 12:c8fbe49527e7 324 if(i%2 == 1){
Nasungil 12:c8fbe49527e7 325 for(int j =0;j<DATA_CNT;j=j+2){
Nasungil 12:c8fbe49527e7 326 vector[j] = i>>8; //upper bit save
Nasungil 12:c8fbe49527e7 327 vector[j+1] = i; //low bit save
Nasungil 12:c8fbe49527e7 328 }
Nasungil 12:c8fbe49527e7 329 for(int j =DATA_CNT;j<NEURONSIZE; j++){
Nasungil 12:c8fbe49527e7 330 vector[j] = array1[j]; //upper bit save
Nasungil 12:c8fbe49527e7 331 }
Nasungil 12:c8fbe49527e7 332 }
Nasungil 12:c8fbe49527e7 333 else if(i%2==0){
Nasungil 12:c8fbe49527e7 334 for(int j =0;j<DATA_CNT;j=j+2){
Nasungil 8:c41405662e53 335 vector[j] = i>>8; //upper bit save
Nasungil 8:c41405662e53 336 vector[j+1] = i; //low bit save
Nasungil 8:c41405662e53 337 }
Nasungil 12:c8fbe49527e7 338 for(int j =DATA_CNT;j<NEURONSIZE; j++){
Nasungil 12:c8fbe49527e7 339 vector[j] = array2[j]; //upper bit save
Nasungil 12:c8fbe49527e7 340 }
Nasungil 12:c8fbe49527e7 341 }
Nasungil 12:c8fbe49527e7 342
Nasungil 12:c8fbe49527e7 343 //data learn
Nasungil 12:c8fbe49527e7 344 ncnt = learn(vector, NEURONSIZE, i); //input : data, neuronsize, cat, return : ncount
Nasungil 12:c8fbe49527e7 345 if(ncnt == 0xffff || ncnt == 0x7FFF) //change
Nasungil 12:c8fbe49527e7 346 ncnt = MAXNEURONS;
Nasungil 12:c8fbe49527e7 347 //printf("ncount # %d\n",ncnt);
Nasungil 12:c8fbe49527e7 348
Nasungil 12:c8fbe49527e7 349 if(ncnt == old_ncnt){ //ncount가 변화가 없으면
Nasungil 12:c8fbe49527e7 350 if(ncnt <=576){
Nasungil 12:c8fbe49527e7 351 Learn1 = 1;
Nasungil 12:c8fbe49527e7 352 error("\n Learn Fail NM500 #1\n");
Nasungil 12:c8fbe49527e7 353 }
Nasungil 12:c8fbe49527e7 354 else{
Nasungil 12:c8fbe49527e7 355 Learn2 = 1;
Nasungil 12:c8fbe49527e7 356 error("\n Learn Fail NM500 #2\n");
Nasungil 12:c8fbe49527e7 357 }
Nasungil 12:c8fbe49527e7 358 }
Nasungil 12:c8fbe49527e7 359 //ncount가 증가하였을 경우
Nasungil 12:c8fbe49527e7 360 else
Nasungil 12:c8fbe49527e7 361 old_ncnt = ncnt; //old ncount 갱신
Nasungil 8:c41405662e53 362
Nasungil 12:c8fbe49527e7 363 printf(".");
Nasungil 12:c8fbe49527e7 364 }
Nasungil 12:c8fbe49527e7 365 printf("\n");
Nasungil 12:c8fbe49527e7 366 printf("NCOUNT : %d\n",ncnt);
Nasungil 12:c8fbe49527e7 367 //학습 완료 후 ncount가 MAXNEURONS보다 작을 경우
Nasungil 12:c8fbe49527e7 368 if(ncnt == MAXNEURONS/2)
Nasungil 12:c8fbe49527e7 369 return 1; //데이지체인 불량
Nasungil 12:c8fbe49527e7 370 else if( ncnt != MAXNEURONS)
Nasungil 12:c8fbe49527e7 371 error("NCOUNT Fail\n");
Nasungil 12:c8fbe49527e7 372 return 0; //정상 출력
Nasungil 8:c41405662e53 373 }
Nasungil 8:c41405662e53 374
Nasungil 12:c8fbe49527e7 375 void data_classify(void)
Nasungil 10:74e762848659 376 {
Nasungil 10:74e762848659 377 int distance, cat, nid;
Nasungil 10:74e762848659 378 //number of neuron 1156
Nasungil 10:74e762848659 379 for(int i=1;i<=MAXNEURONS;i++){
Nasungil 10:74e762848659 380 //test 벡터 생성
Nasungil 12:c8fbe49527e7 381 //for(int j =0;j<NEURONSIZE;j=j+2){ //size of neuron 256
Nasungil 12:c8fbe49527e7 382 // vector[j] = i>>8; //upper bit save
Nasungil 12:c8fbe49527e7 383 // vector[j+1] = i; //low bit save
Nasungil 12:c8fbe49527e7 384 // }
Nasungil 12:c8fbe49527e7 385 if(i%2 == 1){
Nasungil 12:c8fbe49527e7 386 for(int j =0;j<DATA_CNT;j=j+2){
Nasungil 12:c8fbe49527e7 387 vector[j] = i>>8; //upper bit save
Nasungil 12:c8fbe49527e7 388 vector[j+1] = i; //low bit save
Nasungil 12:c8fbe49527e7 389 }
Nasungil 12:c8fbe49527e7 390 for(int j =DATA_CNT;j<NEURONSIZE; j++){
Nasungil 12:c8fbe49527e7 391 vector[j] = array1[j]; //upper bit save
Nasungil 12:c8fbe49527e7 392 }
Nasungil 12:c8fbe49527e7 393 }
Nasungil 12:c8fbe49527e7 394 else if(i%2==0){
Nasungil 12:c8fbe49527e7 395 for(int j =0;j<DATA_CNT;j=j+2){
Nasungil 12:c8fbe49527e7 396 vector[j] = i>>8; //upper bit save
Nasungil 12:c8fbe49527e7 397 vector[j+1] = i; //low bit save
Nasungil 12:c8fbe49527e7 398 }
Nasungil 12:c8fbe49527e7 399 for(int j =DATA_CNT;j<NEURONSIZE; j++){
Nasungil 12:c8fbe49527e7 400 vector[j] = array2[j]; //upper bit save
Nasungil 12:c8fbe49527e7 401 }
Nasungil 10:74e762848659 402 }
Nasungil 11:6a81bde51be5 403
Nasungil 10:74e762848659 404 //input : data, data length output : distance, category, Neuron ID return 인식된 데이터 갯수
Nasungil 10:74e762848659 405 int nsr = classify(vector, NEURONSIZE, &distance, &cat, &nid);
Nasungil 12:c8fbe49527e7 406 id_fail = nsr & 0x70;
Nasungil 12:c8fbe49527e7 407 if(id_fail == 0)
Nasungil 12:c8fbe49527e7 408 nsr_fail = 1;
Nasungil 12:c8fbe49527e7 409
Nasungil 11:6a81bde51be5 410 printf(".");
Nasungil 12:c8fbe49527e7 411 // printf(" neuron# %d \t", nid);
Nasungil 12:c8fbe49527e7 412 // printf(" distance = %d,\t ", distance);
Nasungil 12:c8fbe49527e7 413 // printf(" cat = %d\n", cat);
Nasungil 11:6a81bde51be5 414
Nasungil 12:c8fbe49527e7 415 //nid test
Nasungil 12:c8fbe49527e7 416 //cat register pass AND (nid,cat diff)
Nasungil 12:c8fbe49527e7 417 if((nid!=cat) && (Cat1==0 && Cat2==0)){
Nasungil 12:c8fbe49527e7 418 if(nid < 576){
Nasungil 12:c8fbe49527e7 419 Nid1 = 1;
Nasungil 12:c8fbe49527e7 420 printf("\nNID Register Fail # %d\n",nid);
Nasungil 12:c8fbe49527e7 421 }
Nasungil 12:c8fbe49527e7 422 else{
Nasungil 12:c8fbe49527e7 423 Nid2 = 1;
Nasungil 12:c8fbe49527e7 424 printf("\nNID Register Fail # %d\n",nid);
Nasungil 12:c8fbe49527e7 425 }
Nasungil 11:6a81bde51be5 426 }
Nasungil 11:6a81bde51be5 427 if(distance != 0){
Nasungil 12:c8fbe49527e7 428 if(nid < 576){
Nasungil 12:c8fbe49527e7 429 Dist1 = 1;
Nasungil 12:c8fbe49527e7 430 printf("\nDistance Register Fail # %d, Distance # %d\n",nid,distance);
Nasungil 12:c8fbe49527e7 431 }
Nasungil 12:c8fbe49527e7 432 else{
Nasungil 12:c8fbe49527e7 433 Dist2 = 1;
Nasungil 12:c8fbe49527e7 434 printf("\nDistance Register Fail # %d, Distance # %d\n",nid,distance);
Nasungil 12:c8fbe49527e7 435 }
Nasungil 11:6a81bde51be5 436 }
Nasungil 11:6a81bde51be5 437
Nasungil 11:6a81bde51be5 438 }
Nasungil 11:6a81bde51be5 439 printf("\n");
Nasungil 12:c8fbe49527e7 440
Nasungil 10:74e762848659 441 }
Nasungil 8:c41405662e53 442
Nasungil 11:6a81bde51be5 443
Nasungil 11:6a81bde51be5 444
Nasungil 12:c8fbe49527e7 445
Nasungil 12:c8fbe49527e7 446
Nasungil 12:c8fbe49527e7 447