Example software of using the mbed-rtos to control a simple vehicle's on board computer

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Committer:
sk398
Date:
Wed Mar 30 03:52:21 2016 +0000
Revision:
5:4f2a072ed289
Parent:
4:b4bcb329a930
Child:
6:572b9755f2c1
All functions now implemented, tested and operational. Further testing to test boundary conditions required.; ; Commenting and final renaming to be also completed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 0:f7d6ed1dfe3e 1 #include "mbed.h"
sk398 0:f7d6ed1dfe3e 2 #include "rtos.h"
sk398 4:b4bcb329a930 3 #include "MCP23017.h"
sk398 4:b4bcb329a930 4 #include "WattBob_TextLCD.h"
sk398 4:b4bcb329a930 5
sk398 4:b4bcb329a930 6 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
sk398 4:b4bcb329a930 7
sk398 4:b4bcb329a930 8 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
sk398 4:b4bcb329a930 9
sk398 4:b4bcb329a930 10 MCP23017 *par_port;
sk398 4:b4bcb329a930 11 WattBob_TextLCD *lcd;
sk398 0:f7d6ed1dfe3e 12
sk398 1:cdf851858518 13 #define TRUE 1
sk398 1:cdf851858518 14 #define FALSE 0
sk398 1:cdf851858518 15
sk398 2:13a9394ba2e0 16 #define HIGH 1
sk398 2:13a9394ba2e0 17 #define LOW 0
sk398 2:13a9394ba2e0 18
sk398 2:13a9394ba2e0 19 // ============================================================================
sk398 2:13a9394ba2e0 20 // MBED Pin Assignments
sk398 2:13a9394ba2e0 21 // ============================================================================
sk398 1:cdf851858518 22 AnalogIn Brake(p19);
sk398 0:f7d6ed1dfe3e 23 AnalogIn Accelerometer(p20);
sk398 0:f7d6ed1dfe3e 24
sk398 1:cdf851858518 25 DigitalIn EngineState(p18);
sk398 1:cdf851858518 26 DigitalIn LeftIndicator(p17);
sk398 1:cdf851858518 27 DigitalIn RightIndicator(p16);
sk398 1:cdf851858518 28 DigitalIn SideLightIndicator(p15);
sk398 1:cdf851858518 29
sk398 1:cdf851858518 30 DigitalOut EngineStateInd(LED1);
sk398 1:cdf851858518 31 DigitalOut SideLightInd(LED2);
sk398 1:cdf851858518 32
sk398 1:cdf851858518 33 PwmOut LeftLightInd(LED3);
sk398 1:cdf851858518 34 PwmOut RightLightInd(LED4);
sk398 2:13a9394ba2e0 35 PwmOut OverSpeedInd(p22);
sk398 2:13a9394ba2e0 36
sk398 2:13a9394ba2e0 37 PwmOut AvSpeedWiper(p21);
sk398 2:13a9394ba2e0 38
sk398 4:b4bcb329a930 39 Serial PCConn(USBTX,USBRX);
sk398 4:b4bcb329a930 40
sk398 4:b4bcb329a930 41
sk398 2:13a9394ba2e0 42 // ============================================================================
sk398 2:13a9394ba2e0 43 // Global Data Structure Declerations
sk398 2:13a9394ba2e0 44 // ============================================================================
sk398 2:13a9394ba2e0 45 typedef struct
sk398 2:13a9394ba2e0 46 {
sk398 2:13a9394ba2e0 47 bool EngineState;
sk398 2:13a9394ba2e0 48 float RawAccelerometer;
sk398 2:13a9394ba2e0 49 float RawBraking;
sk398 2:13a9394ba2e0 50 } CarRawParams;
sk398 2:13a9394ba2e0 51
sk398 2:13a9394ba2e0 52 Mutex rawParamsMutex;
sk398 2:13a9394ba2e0 53 CarRawParams rawParams;
sk398 2:13a9394ba2e0 54
sk398 2:13a9394ba2e0 55
sk398 2:13a9394ba2e0 56 typedef struct
sk398 2:13a9394ba2e0 57 {
sk398 5:4f2a072ed289 58 float rawSpeed[3];
sk398 5:4f2a072ed289 59 int counter;
sk398 5:4f2a072ed289 60 } CarSpeed;
sk398 2:13a9394ba2e0 61
sk398 4:b4bcb329a930 62
sk398 5:4f2a072ed289 63 float lastSpeed;
sk398 5:4f2a072ed289 64 Mutex SpeedMutex;
sk398 5:4f2a072ed289 65 CarSpeed speedParams;
sk398 2:13a9394ba2e0 66
sk398 2:13a9394ba2e0 67
sk398 2:13a9394ba2e0 68 typedef struct
sk398 2:13a9394ba2e0 69 {
sk398 2:13a9394ba2e0 70 float AverageSpeed;
sk398 5:4f2a072ed289 71 float totalDistance;
sk398 2:13a9394ba2e0 72 } CarFilteredParams;
sk398 2:13a9394ba2e0 73
sk398 2:13a9394ba2e0 74 Mutex filteredParamsMutex;
sk398 2:13a9394ba2e0 75 CarFilteredParams filteredParams;
sk398 2:13a9394ba2e0 76
sk398 5:4f2a072ed289 77 float totalDistance;
sk398 4:b4bcb329a930 78
sk398 2:13a9394ba2e0 79 // ============================================================================
sk398 2:13a9394ba2e0 80 // Car Simulation
sk398 2:13a9394ba2e0 81 // ============================================================================
sk398 2:13a9394ba2e0 82
sk398 2:13a9394ba2e0 83 void CarSimulator(void const *arg)
sk398 2:13a9394ba2e0 84 {
sk398 4:b4bcb329a930 85 PCConn.printf("CarSim\r\n");
sk398 5:4f2a072ed289 86
sk398 5:4f2a072ed289 87 float newSpeed;
sk398 5:4f2a072ed289 88
sk398 2:13a9394ba2e0 89 rawParamsMutex.lock();
sk398 2:13a9394ba2e0 90 float currentAccelerometer = rawParams.RawAccelerometer;
sk398 5:4f2a072ed289 91 PCConn.printf("A: %f\r\n",currentAccelerometer);
sk398 2:13a9394ba2e0 92 float currentBrake = rawParams.RawBraking;
sk398 5:4f2a072ed289 93 PCConn.printf("B: %f\r\n",currentBrake);
sk398 2:13a9394ba2e0 94 bool currentEngineState = rawParams.EngineState;
sk398 5:4f2a072ed289 95 rawParamsMutex.unlock();
sk398 2:13a9394ba2e0 96
sk398 5:4f2a072ed289 97 SpeedMutex.unlock();
sk398 5:4f2a072ed289 98 float lastSpeed_copy = lastSpeed;
sk398 5:4f2a072ed289 99 SpeedMutex.lock();
sk398 5:4f2a072ed289 100
sk398 5:4f2a072ed289 101 // Calculate speed in m/s, convert to mph
sk398 5:4f2a072ed289 102 // float Acc = ((lastSpeed_copy/2.23) + ((7*currentAccelerometer)*0.05));
sk398 5:4f2a072ed289 103 // float Dec = ((lastSpeed_copy/2.23) + ((7*currentBrake)*0.05));
sk398 5:4f2a072ed289 104 //
sk398 5:4f2a072ed289 105 // newSpeed = (Acc - Dec)*2.23;
sk398 5:4f2a072ed289 106 #define MAX_SPEED 100
sk398 5:4f2a072ed289 107 newSpeed = currentAccelerometer*MAX_SPEED*(1-currentBrake)*currentEngineState;
sk398 2:13a9394ba2e0 108
sk398 5:4f2a072ed289 109 SpeedMutex.lock();
sk398 5:4f2a072ed289 110 if(speedParams.counter > 2)
sk398 2:13a9394ba2e0 111 {
sk398 5:4f2a072ed289 112 speedParams.counter = 0;
sk398 4:b4bcb329a930 113 }
sk398 4:b4bcb329a930 114
sk398 5:4f2a072ed289 115 speedParams.rawSpeed[speedParams.counter] = newSpeed;
sk398 5:4f2a072ed289 116 SpeedMutex.unlock();
sk398 5:4f2a072ed289 117
sk398 5:4f2a072ed289 118 lastSpeed = newSpeed;
sk398 5:4f2a072ed289 119
sk398 5:4f2a072ed289 120 speedParams.counter = speedParams.counter++;
sk398 5:4f2a072ed289 121
sk398 5:4f2a072ed289 122
sk398 5:4f2a072ed289 123
sk398 2:13a9394ba2e0 124 }
sk398 2:13a9394ba2e0 125
sk398 2:13a9394ba2e0 126
sk398 2:13a9394ba2e0 127 // ============================================================================
sk398 2:13a9394ba2e0 128 // Control System Tasks
sk398 2:13a9394ba2e0 129 // ============================================================================
sk398 2:13a9394ba2e0 130
sk398 5:4f2a072ed289 131
sk398 2:13a9394ba2e0 132 void Task1_ReadRawData(void const *arg)
sk398 2:13a9394ba2e0 133 {
sk398 4:b4bcb329a930 134 PCConn.printf("Task1\r\n");
sk398 2:13a9394ba2e0 135 rawParamsMutex.lock();
sk398 2:13a9394ba2e0 136 rawParams.RawBraking = Brake.read();
sk398 2:13a9394ba2e0 137 rawParams.RawAccelerometer = Accelerometer.read();
sk398 2:13a9394ba2e0 138 rawParamsMutex.unlock();
sk398 2:13a9394ba2e0 139 }
sk398 2:13a9394ba2e0 140
sk398 2:13a9394ba2e0 141
sk398 2:13a9394ba2e0 142
sk398 2:13a9394ba2e0 143 void Task2_ReadEngineState(void const *arg)
sk398 2:13a9394ba2e0 144 {
sk398 4:b4bcb329a930 145 PCConn.printf("Task2\r\n");
sk398 4:b4bcb329a930 146 bool currentEngineState = EngineState.read();
sk398 2:13a9394ba2e0 147 rawParamsMutex.lock();
sk398 4:b4bcb329a930 148 rawParams.EngineState = currentEngineState;
sk398 2:13a9394ba2e0 149 rawParamsMutex.unlock();
sk398 2:13a9394ba2e0 150
sk398 2:13a9394ba2e0 151 if(currentEngineState)
sk398 2:13a9394ba2e0 152 {
sk398 2:13a9394ba2e0 153 EngineStateInd = HIGH;
sk398 2:13a9394ba2e0 154 }
sk398 2:13a9394ba2e0 155 else
sk398 2:13a9394ba2e0 156 {
sk398 2:13a9394ba2e0 157 EngineStateInd = LOW;
sk398 2:13a9394ba2e0 158 }
sk398 2:13a9394ba2e0 159 }
sk398 5:4f2a072ed289 160
sk398 5:4f2a072ed289 161
sk398 2:13a9394ba2e0 162
sk398 4:b4bcb329a930 163 void Task3_CalcAvSpeed(void const *arg)
sk398 4:b4bcb329a930 164 {
sk398 4:b4bcb329a930 165 PCConn.printf("Task3\r\n");
sk398 4:b4bcb329a930 166 float speedTotal = 0.0;
sk398 5:4f2a072ed289 167
sk398 4:b4bcb329a930 168 for(int num = 0; num < 3; num++)
sk398 4:b4bcb329a930 169 {
sk398 5:4f2a072ed289 170 speedTotal = speedTotal + speedParams.rawSpeed[num];
sk398 5:4f2a072ed289 171 PCConn.printf("Total: %f\r\n",speedTotal);
sk398 4:b4bcb329a930 172 }
sk398 2:13a9394ba2e0 173
sk398 4:b4bcb329a930 174 filteredParamsMutex.lock();
sk398 4:b4bcb329a930 175 filteredParams.AverageSpeed = (speedTotal/3);
sk398 5:4f2a072ed289 176 PCConn.printf("Av: %f\r\n",filteredParams.AverageSpeed);
sk398 4:b4bcb329a930 177 filteredParamsMutex.unlock();
sk398 4:b4bcb329a930 178 }
sk398 4:b4bcb329a930 179
sk398 5:4f2a072ed289 180
sk398 5:4f2a072ed289 181
sk398 4:b4bcb329a930 182 void Task4_UpdateRCWiper(void const *arg)
sk398 2:13a9394ba2e0 183 {
sk398 4:b4bcb329a930 184 PCConn.printf("Task4\r\n");
sk398 2:13a9394ba2e0 185 filteredParamsMutex.lock();
sk398 2:13a9394ba2e0 186 float currentAverageSpeed = filteredParams.AverageSpeed;
sk398 2:13a9394ba2e0 187 filteredParamsMutex.unlock();
sk398 2:13a9394ba2e0 188
sk398 5:4f2a072ed289 189 AvSpeedWiper.pulsewidth_us(1000+(10*currentAverageSpeed));
sk398 2:13a9394ba2e0 190 }
sk398 2:13a9394ba2e0 191
sk398 0:f7d6ed1dfe3e 192
sk398 0:f7d6ed1dfe3e 193
sk398 4:b4bcb329a930 194 void Task5_OverspeedLED(void const *arg)
sk398 0:f7d6ed1dfe3e 195 {
sk398 4:b4bcb329a930 196 PCConn.printf("Task5\r\n");
sk398 5:4f2a072ed289 197 SpeedMutex.lock();
sk398 5:4f2a072ed289 198 float currentInstSpeed = speedParams.rawSpeed[speedParams.counter];
sk398 5:4f2a072ed289 199 SpeedMutex.unlock();
sk398 4:b4bcb329a930 200
sk398 4:b4bcb329a930 201 if(currentInstSpeed > 70.0)
sk398 4:b4bcb329a930 202 {
sk398 4:b4bcb329a930 203 OverSpeedInd = HIGH;
sk398 1:cdf851858518 204 }
sk398 1:cdf851858518 205 else
sk398 1:cdf851858518 206 {
sk398 4:b4bcb329a930 207 OverSpeedInd = LOW;
sk398 4:b4bcb329a930 208 }
sk398 4:b4bcb329a930 209
sk398 4:b4bcb329a930 210 }
sk398 4:b4bcb329a930 211
sk398 4:b4bcb329a930 212
sk398 5:4f2a072ed289 213 void Task6_UpdateOdometer(void const *arg)
sk398 5:4f2a072ed289 214 {
sk398 5:4f2a072ed289 215 totalDistance = 50;
sk398 5:4f2a072ed289 216
sk398 5:4f2a072ed289 217 filteredParamsMutex.lock();
sk398 5:4f2a072ed289 218 float currentAverageSpeed = filteredParams.AverageSpeed;
sk398 5:4f2a072ed289 219 filteredParamsMutex.unlock();
sk398 5:4f2a072ed289 220
sk398 5:4f2a072ed289 221 lcd -> cls();
sk398 5:4f2a072ed289 222 lcd -> locate(0,0);
sk398 5:4f2a072ed289 223 lcd -> printf("Dist: %8.2f",totalDistance);
sk398 5:4f2a072ed289 224 lcd -> locate(1,0);
sk398 5:4f2a072ed289 225 lcd -> printf("Speed: %3.1f mph",currentAverageSpeed);
sk398 5:4f2a072ed289 226 }
sk398 5:4f2a072ed289 227
sk398 5:4f2a072ed289 228
sk398 5:4f2a072ed289 229
sk398 5:4f2a072ed289 230 void Task7_SendToMailQueue(void const *arg)
sk398 5:4f2a072ed289 231 {
sk398 5:4f2a072ed289 232
sk398 5:4f2a072ed289 233
sk398 5:4f2a072ed289 234 }
sk398 5:4f2a072ed289 235
sk398 5:4f2a072ed289 236
sk398 5:4f2a072ed289 237
sk398 5:4f2a072ed289 238 void Task8_DumpSerial(void const *arg)
sk398 5:4f2a072ed289 239 {
sk398 5:4f2a072ed289 240
sk398 5:4f2a072ed289 241
sk398 5:4f2a072ed289 242 }
sk398 5:4f2a072ed289 243
sk398 5:4f2a072ed289 244
sk398 5:4f2a072ed289 245
sk398 4:b4bcb329a930 246 void Task9_ReadSideLight(void const *arg)
sk398 4:b4bcb329a930 247 {
sk398 4:b4bcb329a930 248 PCConn.printf("Task9\r\n");
sk398 4:b4bcb329a930 249 if(SideLightIndicator)
sk398 4:b4bcb329a930 250 {
sk398 4:b4bcb329a930 251 SideLightInd = HIGH;
sk398 4:b4bcb329a930 252 }
sk398 4:b4bcb329a930 253 else
sk398 4:b4bcb329a930 254 {
sk398 4:b4bcb329a930 255 SideLightInd = LOW;
sk398 1:cdf851858518 256 }
sk398 1:cdf851858518 257 }
sk398 0:f7d6ed1dfe3e 258
sk398 2:13a9394ba2e0 259
sk398 2:13a9394ba2e0 260
sk398 4:b4bcb329a930 261 void Task10_ReadIndicatorLights(void const *arg)
sk398 0:f7d6ed1dfe3e 262 {
sk398 4:b4bcb329a930 263 PCConn.printf("Task10\r\n");
sk398 1:cdf851858518 264 // Left Indicator Only
sk398 1:cdf851858518 265 if(LeftIndicator && !RightIndicator)
sk398 1:cdf851858518 266 {
sk398 2:13a9394ba2e0 267 LeftLightInd.period(1.0);
sk398 2:13a9394ba2e0 268 LeftLightInd.pulsewidth(0.5);
sk398 2:13a9394ba2e0 269
sk398 2:13a9394ba2e0 270 RightLightInd.period(1.0);
sk398 2:13a9394ba2e0 271 RightLightInd.pulsewidth(0.0);
sk398 1:cdf851858518 272 }
sk398 1:cdf851858518 273
sk398 1:cdf851858518 274 // Right Indicator Only
sk398 1:cdf851858518 275 else if(!LeftIndicator && RightIndicator)
sk398 0:f7d6ed1dfe3e 276 {
sk398 2:13a9394ba2e0 277 LeftLightInd.period(1.0);
sk398 2:13a9394ba2e0 278 LeftLightInd.pulsewidth(0.0);
sk398 2:13a9394ba2e0 279
sk398 2:13a9394ba2e0 280 RightLightInd.period(1.0);
sk398 2:13a9394ba2e0 281 RightLightInd.pulsewidth(0.5);
sk398 1:cdf851858518 282 }
sk398 1:cdf851858518 283
sk398 1:cdf851858518 284 // Left and Right Indicators
sk398 1:cdf851858518 285 else if(LeftIndicator && RightIndicator)
sk398 1:cdf851858518 286 {
sk398 2:13a9394ba2e0 287 LeftLightInd.period(0.5);
sk398 2:13a9394ba2e0 288 RightLightInd.period(0.5);
sk398 0:f7d6ed1dfe3e 289
sk398 2:13a9394ba2e0 290 LeftLightInd.pulsewidth(0.25);
sk398 2:13a9394ba2e0 291 RightLightInd.pulsewidth(0.25);
sk398 2:13a9394ba2e0 292 }
sk398 2:13a9394ba2e0 293
sk398 2:13a9394ba2e0 294 else
sk398 2:13a9394ba2e0 295 {
sk398 2:13a9394ba2e0 296 LeftLightInd.period(1.0);
sk398 2:13a9394ba2e0 297 LeftLightInd.pulsewidth(0.0);
sk398 2:13a9394ba2e0 298
sk398 2:13a9394ba2e0 299 RightLightInd.period(1.0);
sk398 2:13a9394ba2e0 300 RightLightInd.pulsewidth(0.0);
sk398 0:f7d6ed1dfe3e 301 }
sk398 1:cdf851858518 302 }
sk398 3:8192bbde17b3 303
sk398 3:8192bbde17b3 304
sk398 3:8192bbde17b3 305 void InitSystem()
sk398 3:8192bbde17b3 306 {
sk398 4:b4bcb329a930 307 AvSpeedWiper.period_ms(20);
sk398 4:b4bcb329a930 308
sk398 4:b4bcb329a930 309 par_port->write_bit(1,BL_BIT); // turn LCD backlight ON
sk398 3:8192bbde17b3 310
sk398 3:8192bbde17b3 311 rawParams.EngineState = 0;
sk398 3:8192bbde17b3 312 rawParams.RawAccelerometer = 0.0;
sk398 3:8192bbde17b3 313 rawParams.RawBraking = 0.0;
sk398 4:b4bcb329a930 314
sk398 5:4f2a072ed289 315 speedParams.counter = 0;
sk398 5:4f2a072ed289 316 speedParams.rawSpeed[0] = 0.0;
sk398 5:4f2a072ed289 317 speedParams.rawSpeed[1] = 0.0;
sk398 5:4f2a072ed289 318 speedParams.rawSpeed[2] = 0.0;
sk398 3:8192bbde17b3 319
sk398 3:8192bbde17b3 320 filteredParams.AverageSpeed = 0.0;
sk398 4:b4bcb329a930 321 }
sk398 3:8192bbde17b3 322
sk398 3:8192bbde17b3 323
sk398 3:8192bbde17b3 324
sk398 2:13a9394ba2e0 325 // ============================================================================
sk398 2:13a9394ba2e0 326 // Entry Point Thread
sk398 2:13a9394ba2e0 327 // ============================================================================
sk398 1:cdf851858518 328
sk398 1:cdf851858518 329 int main()
sk398 1:cdf851858518 330 {
sk398 4:b4bcb329a930 331 par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip
sk398 4:b4bcb329a930 332 lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display
sk398 4:b4bcb329a930 333
sk398 4:b4bcb329a930 334 PCConn.baud(115200);
sk398 4:b4bcb329a930 335
sk398 3:8192bbde17b3 336 InitSystem();
sk398 3:8192bbde17b3 337
sk398 4:b4bcb329a930 338 RtosTimer CarSim(CarSimulator,osTimerPeriodic);
sk398 2:13a9394ba2e0 339
sk398 4:b4bcb329a930 340 RtosTimer Task1(Task1_ReadRawData,osTimerPeriodic);
sk398 4:b4bcb329a930 341 RtosTimer Task2(Task2_ReadEngineState,osTimerPeriodic);
sk398 4:b4bcb329a930 342 RtosTimer Task3(Task3_CalcAvSpeed,osTimerPeriodic);
sk398 4:b4bcb329a930 343 RtosTimer Task4(Task4_UpdateRCWiper,osTimerPeriodic);
sk398 4:b4bcb329a930 344 RtosTimer Task5(Task5_OverspeedLED,osTimerPeriodic);
sk398 5:4f2a072ed289 345 RtosTimer Task6(Task6_UpdateOdometer,osTimerPeriodic);
sk398 5:4f2a072ed289 346 RtosTimer Task7(Task7_SendToMailQueue,osTimerPeriodic);
sk398 5:4f2a072ed289 347 RtosTimer Task8(Task8_DumpSerial,osTimerPeriodic);
sk398 4:b4bcb329a930 348 RtosTimer Task9(Task9_ReadSideLight,osTimerPeriodic);
sk398 4:b4bcb329a930 349 RtosTimer Task10(Task10_ReadIndicatorLights,osTimerPeriodic);
sk398 4:b4bcb329a930 350
sk398 5:4f2a072ed289 351 CarSim.start(50); // 20Hz
sk398 5:4f2a072ed289 352 Task1.start(100); // 10Hz
sk398 5:4f2a072ed289 353 Task2.start(500); // 2Hz
sk398 5:4f2a072ed289 354 Task3.start(200); // 5Hz
sk398 5:4f2a072ed289 355 Task4.start(1000); // 1Hz
sk398 5:4f2a072ed289 356 Task5.start(2000); // 0.5Hz
sk398 5:4f2a072ed289 357 Task6.start(500); // 2Hz
sk398 5:4f2a072ed289 358 Task7.start(5000); // 0.2Hz
sk398 5:4f2a072ed289 359 Task8.start(20000); // 0.05Hz
sk398 5:4f2a072ed289 360 Task9.start(1000); // 1Hz
sk398 5:4f2a072ed289 361 Task10.start(2000); // 0.5Hz
sk398 1:cdf851858518 362
sk398 1:cdf851858518 363 Thread::wait(osWaitForever);
sk398 1:cdf851858518 364
sk398 0:f7d6ed1dfe3e 365
sk398 0:f7d6ed1dfe3e 366 }
sk398 0:f7d6ed1dfe3e 367
sk398 1:cdf851858518 368 //
sk398 1:cdf851858518 369 //
sk398 1:cdf851858518 370 //Mutex readvalues;
sk398 1:cdf851858518 371 //Semaphore read_s(1);
sk398 1:cdf851858518 372 //
sk398 1:cdf851858518 373 //Mail<value_t, 100> mail_box;
sk398 1:cdf851858518 374 //
sk398 1:cdf851858518 375 //
sk398 1:cdf851858518 376 //float readValue = 1.0;
sk398 1:cdf851858518 377 //
sk398 1:cdf851858518 378 //typedef struct
sk398 1:cdf851858518 379 //{
sk398 1:cdf851858518 380 // float AccelerationRaw;
sk398 1:cdf851858518 381 // float BrakeRaw;
sk398 1:cdf851858518 382 //} value_t;
sk398 1:cdf851858518 383 //
sk398 1:cdf851858518 384 //
sk398 1:cdf851858518 385 //void readAnalogPins(void const *args)
sk398 1:cdf851858518 386 //{
sk398 1:cdf851858518 387 // while(1)
sk398 1:cdf851858518 388 // {
sk398 1:cdf851858518 389 // value_t *ReadValue = mail_box.alloc();
sk398 1:cdf851858518 390 //
sk398 1:cdf851858518 391 // ReadValue -> AccelerationrRaw = Accelerometer.read();
sk398 1:cdf851858518 392 // ReadValue -> BrakeRaw = Brake.read();
sk398 1:cdf851858518 393 //
sk398 1:cdf851858518 394 // mail_box.put(ReadValue);
sk398 1:cdf851858518 395 // Thread::wait(100);
sk398 1:cdf851858518 396 // }
sk398 1:cdf851858518 397 //
sk398 1:cdf851858518 398 //}
sk398 1:cdf851858518 399 //
sk398 1:cdf851858518 400 //void sendToPC(void const *args)
sk398 1:cdf851858518 401 //{
sk398 1:cdf851858518 402 // while(1)
sk398 1:cdf851858518 403 // {
sk398 1:cdf851858518 404 // osEvent evt = mail_box.get();
sk398 1:cdf851858518 405 //
sk398 1:cdf851858518 406 // if(evt.status == osEventMail)
sk398 1:cdf851858518 407 // {
sk398 1:cdf851858518 408 // value_t *ReadValue = (value_t*)evt.value.p;
sk398 1:cdf851858518 409 // printf("Value: %1.3f\r\n", ReadValue-> vale);
sk398 1:cdf851858518 410 // mail_box.free(ReadValue);
sk398 1:cdf851858518 411 // }
sk398 1:cdf851858518 412 // Thread::wait(5000);
sk398 1:cdf851858518 413 // }
sk398 1:cdf851858518 414 //
sk398 1:cdf851858518 415 //}
sk398 1:cdf851858518 416 //
sk398 1:cdf851858518 417 //int main() {
sk398 1:cdf851858518 418 //
sk398 1:cdf851858518 419 // Thread thread_1(readData);
sk398 1:cdf851858518 420 // Thread thread_2(sendToPC);
sk398 1:cdf851858518 421 //
sk398 1:cdf851858518 422 // while(1) {
sk398 1:cdf851858518 423 //
sk398 1:cdf851858518 424 // myled = 1;
sk398 1:cdf851858518 425 // wait(0.2);
sk398 1:cdf851858518 426 // myled = 0;
sk398 1:cdf851858518 427 // wait(0.2);
sk398 1:cdf851858518 428 // }
sk398 1:cdf851858518 429 //}