Leon Wehmeier / Mbed OS fiasco_max32630

Dependencies:   SoftSerial MAX14690 Buffer

Fork of rtos_threading_with_callback by mbed_example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "global.h"
00004 #include "linkLayer.h"
00005 #include "txQueue.h"
00006 
00007 #include "max32630fthr.h" 
00008 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00009 
00010 
00011 #include "platform/mbed_assert.h"
00012 #include "platform/mbed_debug.h"
00013 #include "platform/mbed_error.h"
00014 #include "platform/mbed_stats.h"
00015 #define MAX_THREAD_INFO 10
00016 mbed_stats_heap_t heap_info;
00017 mbed_stats_stack_t stack_info[ MAX_THREAD_INFO ];
00018 
00019 
00020 SPI spi(P5_1, P5_2, P5_0);
00021 I2C i2c(P5_7, P6_0); //sda, scl
00022 I2C i2c2(P3_4, P3_5); //sda, scl
00023 
00024 TxQueue txQueue;
00025 LinkLayerEncoder linkEnc;
00026 
00027 Thread registeredThreads[15];
00028 threadFunc_t registeredThreadFunctions[15];
00029 unsigned numRegisteredThreads=0;
00030 Thread thread_txRF(osPriorityHigh);
00031 
00032  
00033 float temperature, pressure, altitude, humidity;
00034 float acc1[3];
00035 float acc2[3];
00036 float gyro1[3], gyro2[3];
00037 
00038 bool registerThread(threadFunc_t f)
00039 {
00040     if(numRegisteredThreads >= 14)
00041     {
00042         printf("ERROR: Max registerable threads reached\r\n");
00043         return false;
00044     }
00045     registeredThreadFunctions[numRegisteredThreads++]=f;
00046     printf("registered function\r\n");
00047     return true;
00048 }
00049 void setupTx()
00050 {
00051     spi.frequency(1000);//1kbps
00052 }
00053 void txData() //TODO: evaluate callback async
00054 {
00055     spi.lock();
00056     while(1)
00057     {
00058         uint8_t txBuf[8]={0,0,0,0,0,0,0,0};
00059         for(unsigned i = 0; i < 8; i++)
00060             for(unsigned j=0; j<8;j++)
00061             {
00062                 txBuf[i]|=(linkEnc.getNext()<<j);
00063             }
00064         //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]);
00065         spi.write((char*)txBuf, 8, (char*)0, 0);
00066     }
00067 }
00068 int main() {
00069     set_time(0);
00070     setupTx();
00071     thread_txRF.start(txData);
00072     
00073     for(int i=0; i<numRegisteredThreads; i++)
00074     {
00075         registeredThreads[i].set_priority(osPriorityBelowNormal);
00076         registeredThreads[i].start(registeredThreadFunctions[i]);
00077     }
00078     printf("MAIN: started %u registered application threads\r\n", numRegisteredThreads);
00079     
00080     while(1)
00081     {/*
00082         printf("\r\nRuntimeStats:");
00083         printf("\r\n\tSystem uptime in s: %d", time(NULL));
00084         printf("\r\nMemoryStats:");
00085         mbed_stats_heap_get( &heap_info );
00086         printf("\r\n\tBytes allocated currently: %d", heap_info.current_size);
00087         printf("\r\n\tMax bytes allocated at a given time: %d", heap_info.max_size);
00088         printf("\r\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size);
00089         printf("\r\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size);
00090         printf("\r\n\tCurrent number of allocations: %d", heap_info.alloc_cnt);
00091         printf("\r\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt);
00092         
00093         mbed_stats_stack_get( &stack_info[0] );
00094         printf("\r\nCumulative Stack Info:");
00095         printf("\r\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size);
00096         printf("\r\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size);
00097         printf("\r\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt);
00098         
00099         mbed_stats_stack_get_each( stack_info, MAX_THREAD_INFO );
00100         printf("\r\nThread Stack Info:");
00101         for(int i=0;i < MAX_THREAD_INFO; i++)
00102         {
00103             if(stack_info[i].thread_id != 0)
00104             {
00105                 printf("\r\n\tThread: %d", i);
00106                 printf("\r\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size);
00107                 printf("\r\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size);
00108                 printf("\r\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt); 
00109             }
00110         }
00111         */
00112         rtos::Thread::wait(60000);
00113     }
00114 }
00115