NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Revision:
8:c41405662e53
Parent:
7:daaefdca1f78
Child:
9:7970a5638913
--- a/main.cpp	Wed Feb 03 07:34:43 2016 +0000
+++ b/main.cpp	Thu May 18 04:34:07 2017 +0000
@@ -1,56 +1,95 @@
-#include "mbed.h"
-#include "SDFileSystem.h"
-
-#if defined(TARGET_WIZwiki_W7500)
-#define MOSI                  PB_3
-#define MISO                  PB_2
-#define CLK                   PB_1
-#define SEL                   PB_0
-#endif
-
-#define MAX_SIZE 100
-
-SDFileSystem sd(MOSI, MISO, CLK, SEL, "sd"); // the pinout on the mbed Cool Components workshop board
-
-
-int main() {
-
-        char str[MAX_SIZE];
-        
-        mkdir("/sd/mydir", 0777);
-        //"w" : {Write) - Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
-        //"a+" :(append/update) -  open (or create if the file does not exist) for update at the end of the file
-        
-        FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); 
-        
-        if(fp == NULL)
-        {
-            error("Could not open file for write\n");
-        }
-        
-        //fprintf(fp, "Hello fun SD Card World!");
-        printf("Insert data:");
-        scanf("%s",str);
-        printf("\r\n");
-        
-        fflush(stdin);
-        fprintf(fp,"%s", str);
-        fclose(fp); 
-        
-        printf("Reading from SD card...\r\n");
-        
-        fp = fopen("/sd/mydir/sdtest.txt", "r");
-        
-        if (fp != NULL)
-        {
-             fgets(str,MAX_SIZE,fp);
-             printf("%s", str);
-             printf("\r\n");
-            fclose(fp);
-        } 
-        else 
-        {
-            printf("failed!\n");
-        }
-        
-}
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "NM500.h"
+
+#define SD_CS      D6    
+#define SD_MOSI    D11    
+#define SD_MISO    D12    
+#define SD_SCK     D13   
+
+#define MAX_SIZE 100
+
+
+int data_learn(void);
+
+unsigned char vector[NEURONSIZE];
+
+int main() {
+    int minif,maxif=0,gcr,learn=0,classify=0;
+
+    //NM500 & SD Card Init
+    if(begin() == 0)
+        printf("\nNM500 Init\n");
+    else
+        error("Init error");
+        
+    //kNN Mode 설정   
+    setKNN();          
+
+    //minif test
+    write(NM_MINIF,3);      
+    minif = read(NM_MINIF);
+    printf("Minif : %d\n", minif);
+    
+    //maxif test
+    write(NM_MAXIF,10000);   
+    maxif = read(NM_MAXIF);
+    
+    //GCR test
+    write(NM_GCR,5);        
+    gcr = read(NM_GCR);
+        
+        
+        
+    //Neuron learn
+    data_learn();
+    
+    NeuronToSD();
+    SDToNeurons();
+       
+
+        
+        
+        
+}
+int data_learn(void)
+{
+        int ncnt=0,old_ncnt=0;  //ncount, old ncount
+        
+        //number of neuron 576*2
+        for(int i=1;i<=MAXNEURONS;i++){ 
+            // ex
+            //      1.      0 1 0 1.... 
+            //      2.      0 2 0 2.... 
+            //      3.      0 3 0 3....
+            //      .....
+            //      255.    0 255 0 255....
+            //      256.    1 0 1 0....
+            //      257.    1 1 1 1....
+            for(int j =0;j<NEURONSIZE;j=j+2){   
+                vector[j] = i>>8;          //upper bit save
+                vector[j+1] = i;           //low bit save
+            }
+            //data learn
+            ncnt = learn(vector, NEURONSIZE, i);    //input : data, neuronsize, cat,   return : ncount
+            printf("ncount # %d\n",ncnt);
+            
+            if(ncnt == old_ncnt)                    //ncount가 변화가 없으면       
+                return 0;       //학습 실패 or ncount 레지스터 불량
+            else                                    //ncount가 증가하였을 경우
+                old_ncnt = ncnt;    //old ncount 갱신
+
+            
+            //test display
+            printf("vector : ");
+            for(int j=0;j<NEURONSIZE;j++)
+                printf(" %d,",vector[j]);
+            printf(" cat : %d\n", i);
+        } 
+        //학습 완료 후 ncount가 MAXNEURONS보다 작을 경우
+        if(ncnt < MAXNEURONS)
+            return 2;       //데이지체인 불량
+        return ncnt;        //정상 출력
+}
+
+