Leon Wehmeier / Mbed OS fiasco_max32630

Dependencies:   SoftSerial MAX14690 Buffer

Fork of rtos_threading_with_callback by mbed_example

Revision:
2:bf699e054b34
Parent:
0:d4b2a035ffe3
Child:
3:d7ec6dc025b0
--- a/main.cpp	Fri Jun 23 14:21:38 2017 -0500
+++ b/main.cpp	Sun Feb 25 16:40:28 2018 +0000
@@ -1,21 +1,73 @@
 #include "mbed.h"
+#include "rtos.h"
+#include "global.h"
+#include "linkLayer.h"
+#include "txQueue.h"
+
+#include "max32630fthr.h" 
+MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+
+
+SPI spi(P5_1, P5_2, P5_0);
+I2C i2c(P5_7, P6_0); //sda, scl
+I2C i2c2(P3_4, P3_5); //sda, scl
 
-Thread thread;
-DigitalOut led1(LED1);
-volatile bool running = true;
+TxQueue txQueue;
+LinkLayerEncoder linkEnc;
+
+Thread registeredThreads[15];
+threadFunc_t registeredThreadFunctions[15];
+unsigned numRegisteredThreads=0;
+Thread thread_txRF(osPriorityHigh);
+
+ 
+float temperature, pressure, altitude, humidity;
+float acc1[3];
+float acc2[3];
+float gyro1[3], gyro2[3];
 
-// Blink function toggles the led in a long running loop
-void blink(DigitalOut *led) {
-    while (running) {
-        *led = !*led;
-        wait(1);
+bool registerThread(threadFunc_t f)
+{
+    if(numRegisteredThreads >= 14)
+    {
+        printf("ERROR: Max registerable threads reached\r\n");
+        return false;
+    }
+    registeredThreadFunctions[numRegisteredThreads++]=f;
+    printf("registered function\r\n");
+    return true;
+}
+void setupTx()
+{
+    spi.frequency(1000);//1kbps
+}
+void txData() //TODO: evaluate callback async
+{
+    spi.lock();
+    while(1)
+    {
+        uint8_t txBuf[8]={0,0,0,0,0,0,0,0};
+        for(unsigned i = 0; i < 8; i++)
+            for(unsigned j=0; j<8;j++)
+            {
+                txBuf[i]|=(linkEnc.getNext()<<j);
+            }
+        printf("0x%02x%02x%02x%02x%02x%02x%02x%02x\r\n", txBuf[0], txBuf[1], txBuf[2], txBuf[3], txBuf[4], txBuf[5], txBuf[6], txBuf[7]);
+        spi.write((char*)txBuf, 8, (char*)0, 0);
     }
 }
-
-// Spawns a thread to run blink for 5 seconds
 int main() {
-    thread.start(callback(blink, &led1));
-    wait(5);
-    running = false;
-    thread.join();
-}
\ No newline at end of file
+    setupTx();
+    thread_txRF.start(txData);
+    
+    for(int i=0; i<numRegisteredThreads; i++)
+    {
+        registeredThreads[i].set_priority(osPriorityBelowNormal);
+        registeredThreads[i].start(registeredThreadFunctions[i]);
+    }
+    printf("MAIN: started %u registered application threads\r\n", numRegisteredThreads);
+    
+    while(1)
+        wait(1024);
+}
+ 
\ No newline at end of file