Leon Wehmeier / Mbed OS fiasco_max32630

Dependencies:   SoftSerial MAX14690 Buffer

Fork of rtos_threading_with_callback by mbed_example

main.cpp

Committer:
lwehmeier
Date:
2018-02-25
Revision:
2:bf699e054b34
Parent:
0:d4b2a035ffe3
Child:
3:d7ec6dc025b0

File content as of revision 2:bf699e054b34:

#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

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];

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);
    }
}
int main() {
    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);
}