GIU\ZF
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Fork of rtos_basic by
tasks/core.h@15:524de2b2ef8e, 2018-03-27 (annotated)
- Committer:
- ihexx
- Date:
- Tue Mar 27 18:55:43 2018 +0000
- Revision:
- 15:524de2b2ef8e
- Parent:
- 13:ab52f46c98ab
- Child:
- 16:0ada6cbd41e2
Created and tested basic car simulator; scheduled accel/brake controls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ihexx | 12:90b5d8eae5ec | 1 | #pragma once |
ihexx | 12:90b5d8eae5ec | 2 | |
ihexx | 12:90b5d8eae5ec | 3 | #include "mbed.h" |
ihexx | 12:90b5d8eae5ec | 4 | #include "rtos.h" |
ihexx | 12:90b5d8eae5ec | 5 | #include "MCP23017.h" |
ihexx | 12:90b5d8eae5ec | 6 | #include "WattBob_TextLCD.h" |
ihexx | 12:90b5d8eae5ec | 7 | #include <string> |
ihexx | 12:90b5d8eae5ec | 8 | #include <sstream> |
ihexx | 12:90b5d8eae5ec | 9 | |
ihexx | 12:90b5d8eae5ec | 10 | //Compile Flags |
ihexx | 12:90b5d8eae5ec | 11 | #define DEBUG_MODE 1 |
ihexx | 12:90b5d8eae5ec | 12 | |
ihexx | 12:90b5d8eae5ec | 13 | //Inputs------------------------- |
ihexx | 15:524de2b2ef8e | 14 | #define PORT_TURN_SIGNAL_SWITCH_RIGHT p17 |
ihexx | 15:524de2b2ef8e | 15 | #define PORT_TURN_SIGNAL_SWITCH_LEFT p18 |
ihexx | 15:524de2b2ef8e | 16 | #define PORT_ACCEL p19 |
ihexx | 12:90b5d8eae5ec | 17 | #define PORT_BRAKE p20 |
ihexx | 12:90b5d8eae5ec | 18 | #define PORT_IGNITION p21 |
ihexx | 15:524de2b2ef8e | 19 | |
ihexx | 12:90b5d8eae5ec | 20 | //Outputs ---------------- |
ihexx | 12:90b5d8eae5ec | 21 | #define PORT_REDBOX_LED1 p22 |
ihexx | 12:90b5d8eae5ec | 22 | #define PORT_REDBOX_LED2 p23 |
ihexx | 12:90b5d8eae5ec | 23 | |
ihexx | 12:90b5d8eae5ec | 24 | #define PORT_SIDE_LIGHTS p5 |
ihexx | 12:90b5d8eae5ec | 25 | #define IGNITION_LED p6 |
ihexx | 12:90b5d8eae5ec | 26 | #define PORT_TURN_SIGNAL_LED_LEFT p25 |
ihexx | 12:90b5d8eae5ec | 27 | #define PORT_TURN_SIGNAL_LED_RIGHT p26 |
ihexx | 12:90b5d8eae5ec | 28 | |
ihexx | 12:90b5d8eae5ec | 29 | //#define PORT_SIDE_LIGHTS LED1 |
ihexx | 12:90b5d8eae5ec | 30 | //#define IGNITION_LED LED4 |
ihexx | 12:90b5d8eae5ec | 31 | //#define PORT_TURN_SIGNAL_LED_LEFT LED2 |
ihexx | 12:90b5d8eae5ec | 32 | //#define PORT_TURN_SIGNAL_LED_RIGHT LED3 |
ihexx | 12:90b5d8eae5ec | 33 | |
ihexx | 12:90b5d8eae5ec | 34 | namespace runTimeParams{ |
ihexx | 12:90b5d8eae5ec | 35 | extern Mutex liveAccess; |
ihexx | 12:90b5d8eae5ec | 36 | extern float brakeForce; |
ihexx | 12:90b5d8eae5ec | 37 | extern float accelForce; |
ihexx | 12:90b5d8eae5ec | 38 | extern float avgSpeed; |
ihexx | 12:90b5d8eae5ec | 39 | extern float odometer; |
ihexx | 15:524de2b2ef8e | 40 | extern float newSpeed; |
ihexx | 12:90b5d8eae5ec | 41 | #if DEBUG_MODE |
ihexx | 12:90b5d8eae5ec | 42 | extern string debugLog; |
ihexx | 12:90b5d8eae5ec | 43 | #endif |
ihexx | 12:90b5d8eae5ec | 44 | } |
ihexx | 15:524de2b2ef8e | 45 | |
ihexx | 15:524de2b2ef8e | 46 | |
ihexx | 15:524de2b2ef8e | 47 | |
ihexx | 12:90b5d8eae5ec | 48 | |
ihexx | 15:524de2b2ef8e | 49 | namespace task_group_1{ |
ihexx | 15:524de2b2ef8e | 50 | //Display, |
ihexx | 15:524de2b2ef8e | 51 | extern Thread thread; |
ihexx | 15:524de2b2ef8e | 52 | extern const float freq; //hz |
ihexx | 15:524de2b2ef8e | 53 | |
ihexx | 15:524de2b2ef8e | 54 | void runTask(); |
ihexx | 15:524de2b2ef8e | 55 | } |
ihexx | 15:524de2b2ef8e | 56 | namespace task_group_2{ |
ihexx | 15:524de2b2ef8e | 57 | //Read Accel/Brake, carSimulator |
ihexx | 12:90b5d8eae5ec | 58 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 59 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 60 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 61 | } |
ihexx | 12:90b5d8eae5ec | 62 | |
ihexx | 12:90b5d8eae5ec | 63 | namespace mailData{ |
ihexx | 12:90b5d8eae5ec | 64 | typedef struct{ |
ihexx | 12:90b5d8eae5ec | 65 | float speed; |
ihexx | 12:90b5d8eae5ec | 66 | float accel; |
ihexx | 12:90b5d8eae5ec | 67 | float brake; |
ihexx | 12:90b5d8eae5ec | 68 | } mail_t; |
ihexx | 12:90b5d8eae5ec | 69 | extern Mail<mail_t, 100> mailBox; |
ihexx | 12:90b5d8eae5ec | 70 | } |
ihexx | 12:90b5d8eae5ec | 71 | namespace getIgnition{ |
ihexx | 12:90b5d8eae5ec | 72 | //Read engine on/off switch and show current state on a LED |
ihexx | 12:90b5d8eae5ec | 73 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 74 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 75 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 76 | } |
ihexx | 12:90b5d8eae5ec | 77 | |
ihexx | 12:90b5d8eae5ec | 78 | namespace filterSpeed{ |
ihexx | 12:90b5d8eae5ec | 79 | //Filter speed with averaging filter |
ihexx | 12:90b5d8eae5ec | 80 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 81 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 82 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 83 | } |
ihexx | 12:90b5d8eae5ec | 84 | |
ihexx | 12:90b5d8eae5ec | 85 | namespace brakeIndicator{ |
ihexx | 12:90b5d8eae5ec | 86 | //Read brake and accelerator values from variable resistors |
ihexx | 12:90b5d8eae5ec | 87 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 88 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 89 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 90 | } |
ihexx | 12:90b5d8eae5ec | 91 | |
ihexx | 12:90b5d8eae5ec | 92 | namespace speedIndicator{ |
ihexx | 12:90b5d8eae5ec | 93 | //Read brake and accelerator values from variable resistors |
ihexx | 12:90b5d8eae5ec | 94 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 95 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 96 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 97 | } |
ihexx | 12:90b5d8eae5ec | 98 | |
ihexx | 12:90b5d8eae5ec | 99 | namespace sideLights{ |
ihexx | 12:90b5d8eae5ec | 100 | //Read brake and accelerator values from variable resistors |
ihexx | 12:90b5d8eae5ec | 101 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 102 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 103 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 104 | } |
ihexx | 12:90b5d8eae5ec | 105 | |
ihexx | 12:90b5d8eae5ec | 106 | namespace turnSignal{ |
ihexx | 12:90b5d8eae5ec | 107 | //Read brake and accelerator values from variable resistors |
ihexx | 12:90b5d8eae5ec | 108 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 109 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 110 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 111 | } |
ihexx | 12:90b5d8eae5ec | 112 | |
ihexx | 13:ab52f46c98ab | 113 | namespace enqueueMail{ |
ihexx | 13:ab52f46c98ab | 114 | //Send speed, accelerometer and brake values to a 100 element |
ihexx | 13:ab52f46c98ab | 115 | //MAIL queue |
ihexx | 13:ab52f46c98ab | 116 | extern Thread thread; |
ihexx | 13:ab52f46c98ab | 117 | extern const float freq; |
ihexx | 13:ab52f46c98ab | 118 | void runTask(); |
ihexx | 13:ab52f46c98ab | 119 | } |
ihexx | 13:ab52f46c98ab | 120 | namespace dequeueMail{ |
ihexx | 12:90b5d8eae5ec | 121 | //Send speed, accelerometer and brake values to a 100 element |
ihexx | 12:90b5d8eae5ec | 122 | //MAIL queue |
ihexx | 12:90b5d8eae5ec | 123 | extern Thread thread; |
ihexx | 12:90b5d8eae5ec | 124 | extern const float freq; |
ihexx | 12:90b5d8eae5ec | 125 | void runTask(); |
ihexx | 12:90b5d8eae5ec | 126 | } |
ihexx | 12:90b5d8eae5ec | 127 | |
ihexx | 12:90b5d8eae5ec | 128 | |
ihexx | 12:90b5d8eae5ec | 129 | template <typename T> |
ihexx | 12:90b5d8eae5ec | 130 | static inline std::string to_string(T value) |
ihexx | 12:90b5d8eae5ec | 131 | { |
ihexx | 12:90b5d8eae5ec | 132 | std::ostringstream os ; |
ihexx | 12:90b5d8eae5ec | 133 | os << value ; |
ihexx | 12:90b5d8eae5ec | 134 | return os.str() ; |
ihexx | 12:90b5d8eae5ec | 135 | } |