GIU\ZF
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Fork of rtos_basic by
tasks/task_group1.cpp@13:ab52f46c98ab, 2018-03-27 (annotated)
- Committer:
- ihexx
- Date:
- Tue Mar 27 15:56:27 2018 +0000
- Revision:
- 13:ab52f46c98ab
- Child:
- 14:8a6c20435523
enqueue and dequeue mail tasks completed.; Improved debug framework; Moved task groups to separate files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ihexx | 13:ab52f46c98ab | 1 | #include "core.h" |
ihexx | 13:ab52f46c98ab | 2 | |
ihexx | 13:ab52f46c98ab | 3 | namespace task_group_1{ |
ihexx | 13:ab52f46c98ab | 4 | Thread thread; |
ihexx | 13:ab52f46c98ab | 5 | const float freq = 2.0f; //hz |
ihexx | 13:ab52f46c98ab | 6 | |
ihexx | 13:ab52f46c98ab | 7 | |
ihexx | 13:ab52f46c98ab | 8 | void runTask(){ |
ihexx | 13:ab52f46c98ab | 9 | Timer executionTimer,sleepTimer; |
ihexx | 13:ab52f46c98ab | 10 | executionTimer.reset(); |
ihexx | 13:ab52f46c98ab | 11 | sleepTimer.reset(); |
ihexx | 13:ab52f46c98ab | 12 | display::init(); |
ihexx | 13:ab52f46c98ab | 13 | |
ihexx | 13:ab52f46c98ab | 14 | const int const_delay = int((1000.0f/freq)+0.5f); |
ihexx | 13:ab52f46c98ab | 15 | int dynamic_delay = const_delay; |
ihexx | 13:ab52f46c98ab | 16 | |
ihexx | 13:ab52f46c98ab | 17 | while(true){ |
ihexx | 13:ab52f46c98ab | 18 | sleepTimer.stop(); |
ihexx | 13:ab52f46c98ab | 19 | executionTimer.start(); |
ihexx | 13:ab52f46c98ab | 20 | |
ihexx | 13:ab52f46c98ab | 21 | |
ihexx | 13:ab52f46c98ab | 22 | int sleepTime = sleepTimer.read_ms(); |
ihexx | 13:ab52f46c98ab | 23 | const int drift = ((sleepTime - dynamic_delay) > 0)? |
ihexx | 13:ab52f46c98ab | 24 | (sleepTime - dynamic_delay) : 0; |
ihexx | 13:ab52f46c98ab | 25 | |
ihexx | 13:ab52f46c98ab | 26 | |
ihexx | 13:ab52f46c98ab | 27 | // Run all tasks |
ihexx | 13:ab52f46c98ab | 28 | display::hotLoop(); |
ihexx | 13:ab52f46c98ab | 29 | |
ihexx | 13:ab52f46c98ab | 30 | |
ihexx | 13:ab52f46c98ab | 31 | executionTimer.stop(); |
ihexx | 13:ab52f46c98ab | 32 | int exec_time = executionTimer.read_ms(); |
ihexx | 13:ab52f46c98ab | 33 | |
ihexx | 13:ab52f46c98ab | 34 | #if DEBUG_MODE |
ihexx | 13:ab52f46c98ab | 35 | runTimeParams::liveAccess.lock(); |
ihexx | 13:ab52f46c98ab | 36 | //runTimeParams::debugLog += "GROUP_1," + to_string(executionTimer.read_ms()) + "," |
ihexx | 13:ab52f46c98ab | 37 | // + to_string(sleepTimer.read_ms()) + ", \n"; |
ihexx | 13:ab52f46c98ab | 38 | runTimeParams::odometer = float(sleepTime); |
ihexx | 13:ab52f46c98ab | 39 | runTimeParams::avgSpeed = float(exec_time); |
ihexx | 13:ab52f46c98ab | 40 | runTimeParams::liveAccess.unlock(); |
ihexx | 13:ab52f46c98ab | 41 | #endif |
ihexx | 13:ab52f46c98ab | 42 | |
ihexx | 13:ab52f46c98ab | 43 | executionTimer.reset(); |
ihexx | 13:ab52f46c98ab | 44 | sleepTimer.reset(); |
ihexx | 13:ab52f46c98ab | 45 | sleepTimer.start(); |
ihexx | 13:ab52f46c98ab | 46 | dynamic_delay = const_delay - (exec_time + drift); |
ihexx | 13:ab52f46c98ab | 47 | Thread::wait(dynamic_delay); |
ihexx | 13:ab52f46c98ab | 48 | } |
ihexx | 13:ab52f46c98ab | 49 | } |
ihexx | 13:ab52f46c98ab | 50 | } |