Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
main.cpp
- Committer:
- lwehmeier
- Date:
- 2018-03-30
- Revision:
- 3:d7ec6dc025b0
- Parent:
- 2:bf699e054b34
File content as of revision 3:d7ec6dc025b0:
#include "mbed.h" #include "rtos.h" #include "global.h" #include "linkLayer.h" #include "txQueue.h" #include "max32630fthr.h" MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); #include "platform/mbed_assert.h" #include "platform/mbed_debug.h" #include "platform/mbed_error.h" #include "platform/mbed_stats.h" #define MAX_THREAD_INFO 10 mbed_stats_heap_t heap_info; mbed_stats_stack_t stack_info[ MAX_THREAD_INFO ]; 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() { set_time(0); 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) {/* printf("\r\nRuntimeStats:"); printf("\r\n\tSystem uptime in s: %d", time(NULL)); printf("\r\nMemoryStats:"); mbed_stats_heap_get( &heap_info ); printf("\r\n\tBytes allocated currently: %d", heap_info.current_size); printf("\r\n\tMax bytes allocated at a given time: %d", heap_info.max_size); printf("\r\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size); printf("\r\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size); printf("\r\n\tCurrent number of allocations: %d", heap_info.alloc_cnt); printf("\r\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt); mbed_stats_stack_get( &stack_info[0] ); printf("\r\nCumulative Stack Info:"); printf("\r\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size); printf("\r\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size); printf("\r\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt); mbed_stats_stack_get_each( stack_info, MAX_THREAD_INFO ); printf("\r\nThread Stack Info:"); for(int i=0;i < MAX_THREAD_INFO; i++) { if(stack_info[i].thread_id != 0) { printf("\r\n\tThread: %d", i); printf("\r\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size); printf("\r\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size); printf("\r\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt); } } */ rtos::Thread::wait(60000); } }