GIU\ZF
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Fork of rtos_basic by
tasks/task_group1.cpp
- Committer:
- ihexx
- Date:
- 2018-03-27
- Revision:
- 13:ab52f46c98ab
- Child:
- 14:8a6c20435523
File content as of revision 13:ab52f46c98ab:
#include "core.h" namespace task_group_1{ Thread thread; const float freq = 2.0f; //hz void runTask(){ Timer executionTimer,sleepTimer; executionTimer.reset(); sleepTimer.reset(); display::init(); const int const_delay = int((1000.0f/freq)+0.5f); int dynamic_delay = const_delay; while(true){ sleepTimer.stop(); executionTimer.start(); int sleepTime = sleepTimer.read_ms(); const int drift = ((sleepTime - dynamic_delay) > 0)? (sleepTime - dynamic_delay) : 0; // Run all tasks display::hotLoop(); executionTimer.stop(); int exec_time = executionTimer.read_ms(); #if DEBUG_MODE runTimeParams::liveAccess.lock(); //runTimeParams::debugLog += "GROUP_1," + to_string(executionTimer.read_ms()) + "," // + to_string(sleepTimer.read_ms()) + ", \n"; runTimeParams::odometer = float(sleepTime); runTimeParams::avgSpeed = float(exec_time); runTimeParams::liveAccess.unlock(); #endif executionTimer.reset(); sleepTimer.reset(); sleepTimer.start(); dynamic_delay = const_delay - (exec_time + drift); Thread::wait(dynamic_delay); } } }