GIU\ZF

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Fork of rtos_basic by mbed official

Committer:
ihexx
Date:
Wed Mar 28 00:47:12 2018 +0000
Revision:
18:d48324fd3440
Parent:
17:a29ce6fc667c
Child:
20:202e0046527e
-finalized simulator; -documented main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ihexx 18:d48324fd3440 1 /*
ihexx 18:d48324fd3440 2 RTOS car interface model. See readme.md
ihexx 18:d48324fd3440 3 Author: Gershom Agim | H00175564
ihexx 18:d48324fd3440 4 2018
ihexx 18:d48324fd3440 5 */
ihexx 12:90b5d8eae5ec 6 #include "core.h"
ihexx 12:90b5d8eae5ec 7
ihexx 18:d48324fd3440 8 DigitalOut led1(LED4);
ihexx 15:524de2b2ef8e 9 Thread thread;
ihexx 12:90b5d8eae5ec 10
ihexx 18:d48324fd3440 11
ihexx 12:90b5d8eae5ec 12 namespace runTimeParams{
ihexx 18:d48324fd3440 13 //Global variables contended by (almost) all tasks
ihexx 12:90b5d8eae5ec 14 Mutex liveAccess;
ihexx 12:90b5d8eae5ec 15 float brakeForce = 0.0f;
ihexx 12:90b5d8eae5ec 16 float accelForce = 0.0f;
ihexx 17:a29ce6fc667c 17 float speed[3] = {0.0f};
ihexx 12:90b5d8eae5ec 18 float avgSpeed = 0.0f;
ihexx 12:90b5d8eae5ec 19 float odometer = 0.0f;
ihexx 16:0ada6cbd41e2 20
ihexx 12:90b5d8eae5ec 21 #if DEBUG_MODE
ihexx 18:d48324fd3440 22 //Debug logs: double buffer so printing to pc doesn't hold up
ihexx 18:d48324fd3440 23 //tasks attempting to log
ihexx 17:a29ce6fc667c 24 Mutex debugAccess;
ihexx 17:a29ce6fc667c 25 string debugLogBuffer1 = "task,execution_time_ms,lastSleep,drift\n\r";
ihexx 17:a29ce6fc667c 26 string debugLogBuffer2 = "";
ihexx 17:a29ce6fc667c 27 string * debugLog = &debugLogBuffer1;
ihexx 12:90b5d8eae5ec 28 #endif
ihexx 18:d48324fd3440 29 }
ihexx 18:d48324fd3440 30
ihexx 18:d48324fd3440 31 int main() {
ihexx 18:d48324fd3440 32 //Launch threads
ihexx 13:ab52f46c98ab 33 task_group_1::thread.start(task_group_1::runTask);
ihexx 15:524de2b2ef8e 34 task_group_2::thread.start(task_group_2::runTask);
ihexx 13:ab52f46c98ab 35 enqueueMail::thread.start(enqueueMail::runTask);
ihexx 13:ab52f46c98ab 36 dequeueMail::thread.start(dequeueMail::runTask);
emilmont 1:491820ee784d 37
emilmont 1:491820ee784d 38 while (true) {
ihexx 18:d48324fd3440 39 //indicate program still running
emilmont 1:491820ee784d 40 led1 = !led1;
mbed_official 11:0309bef74ba8 41 Thread::wait(500);
emilmont 1:491820ee784d 42 }
emilmont 1:491820ee784d 43 }