UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]

Dependencies:   mbed SDFileSystem

Revision:
10:db2be22bc2f9
Parent:
9:c81d0df866f5
Child:
12:a45a9c65dc03
--- a/main.cpp	Mon May 13 02:56:39 2019 +0000
+++ b/main.cpp	Sat May 18 03:28:31 2019 +0000
@@ -14,15 +14,86 @@
 Serial pc(SERIAL_TX, SERIAL_RX);
 DigitalOut myled(LED1);
 
+static SPI myspi(SPI_MOSI, SPI_MISO, SPI_SCK); /* D13, D12, D11 */
+static DigitalOut mycs(SPI_CS);   /* D10   */
+static DigitalIn int1(D7);      /* D7/D6 */
+static DigitalIn int2(D5);      /* D5/D4 */
+
+#define SPI_RD  (1)
+#define SPI_WR  (0)
+#define SPI_EMPTY_SEND  (0x00)
+
+static void test()
+{
+#if 0   
+    int devSpiId;
+    int devid_ad;
+    int devid_mst;
+    int devid_part;
+    int devid_rev;
+    
+    pc.printf("#debug start\n");
+
+    /** Init SPI for ADXL372 
+     * CPHA = CPOL = 0, 1MHz(max.10MHz))
+     * CS = inactive 
+     */
+    myspi.format(8,0);
+    myspi.frequency(1000000);
+    mycs = 1;
+    
+    pc.printf("#init spi\n");
+    
+    /* Get DeviceID from SPI */
+    mycs = 0;
+    pc.printf("#spi CS=ACT\n");
+
+    myspi.write(0x00 << 1 | SPI_RD);
+    pc.printf("#spi REG Write\n");
+
+    devid_ad = myspi.write(SPI_EMPTY_SEND);
+    pc.printf("#spi REG Read\n");
+
+    mycs = 1;
+    pc.printf("#spi CS=DAC\n");
+
+    mycs = 0;
+    myspi.write(0x01 << 1 | SPI_RD);
+    devid_mst = myspi.write(SPI_EMPTY_SEND);
+    mycs = 1;
+
+    mycs = 0;
+    myspi.write(0x02 << 1 | SPI_RD);
+    devid_part = myspi.write(SPI_EMPTY_SEND);
+    mycs = 1;
+    
+    mycs = 0;
+    myspi.write(0x03 << 1 | SPI_RD);
+    devid_rev = myspi.write(SPI_EMPTY_SEND);
+    mycs = 1;
+        
+    devSpiId = (devid_ad    << 0) 
+            | (devid_mst    << 8) 
+            | (devid_part   << 16)
+            | (devid_rev    << 24);
+
+    pc.printf("#fini spi=0x%x\n", devSpiId);
+#endif
+}
+
 /** --- main --- */
 int main()
 {
+    int deviceId = 0; 
+    
     /** UART Initalizer */
     /* setup UART 115200, 8bit, Parity=None, stopbit:1bit  */
     /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */
     pc.baud(115200);
     pc.format(8, Serial::None, 1);
     
+    test();
+        
     /* new timer manager */
     pTM = new TimeManager();
     /* Generate SDDataStore */
@@ -31,15 +102,16 @@
     pUR = new UartReceiver(&pc);
     
     /* create Device */
-    pDevRept = new DeviceRepeater(&DummyDev);
+    pDevRept = new DeviceRepeater(deviceId, &DummyDev);
 
     /* Generate Command parser as DeviceID = 0, ParsingRule = rules */
-    pCP = new CommandParser(pUR, 0, rules, getNumOfRules);
+    pCP = new CommandParser(pUR, deviceId, rules, getNumOfRules);
     pCP->run();
         
-    pc.printf(":0 ACK 0004 0000\n");
+    pc.printf(":%d ACK 0004 0000\n", deviceId);
     
     while(1) {
-        wait(1);
+        test();
+        wait(5);
     }
 }