Simple test program to get familiar with functionality of MBED RTOS on ST Nucleo-F411RE. Tasks for LED blinking, user button, temperature measurement with DS1620, temperature measurement with internal temperature sensor of ST32F411RE, ultrasonic distance measurement and displaying result on 16x2 TextLCD.

Dependencies:   DS1620_improved TextLCD_improved mbed-rtos mbed

Committer:
Jan Tetour
Date:
Fri Dec 18 20:00:56 2015 +0100
Revision:
18:be0130c42925
Parent:
17:94c385ff2641
Minor formatting changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jan Tetour 18:be0130c42925 1 /*
Jan Tetour 18:be0130c42925 2 * TSK_DIST.CPP
Jan Tetour 18:be0130c42925 3 */
dzoni 9:645f0e517017 4 #include "mbed.h"
dzoni 9:645f0e517017 5 #include "rtos.h"
dzoni 9:645f0e517017 6
dzoni 17:94c385ff2641 7 #include "tsk_main.h"
dzoni 9:645f0e517017 8 #include "tsk_dist.h"
dzoni 9:645f0e517017 9
dzoni 9:645f0e517017 10
dzoni 17:94c385ff2641 11 struct dist_data_struct dist_data;
dzoni 9:645f0e517017 12
dzoni 9:645f0e517017 13 static DigitalOut trigDist(PB_9);
dzoni 15:a627638edd9c 14 static InterruptIn echoDist(PA_6);
dzoni 9:645f0e517017 15
dzoni 17:94c385ff2641 16 static Timer timer;
dzoni 17:94c385ff2641 17
dzoni 17:94c385ff2641 18 uint32_t initDist(void const *args) {
dzoni 17:94c385ff2641 19
dzoni 17:94c385ff2641 20 dist_data.distance = 0.0f;
dzoni 17:94c385ff2641 21 dist_data.timerTicks = 0;
dzoni 17:94c385ff2641 22
dzoni 17:94c385ff2641 23 trigDist = 0;
dzoni 17:94c385ff2641 24
dzoni 17:94c385ff2641 25 return 1;
dzoni 17:94c385ff2641 26 }
dzoni 9:645f0e517017 27
dzoni 15:a627638edd9c 28 static void rising(void) {
dzoni 15:a627638edd9c 29 timer.start();
dzoni 15:a627638edd9c 30 }
dzoni 15:a627638edd9c 31
dzoni 15:a627638edd9c 32 static void falling(void) {
dzoni 15:a627638edd9c 33 timer.stop();
dzoni 15:a627638edd9c 34 echoDist.rise(0);
dzoni 15:a627638edd9c 35 echoDist.fall(0);
dzoni 15:a627638edd9c 36
dzoni 17:94c385ff2641 37 // mutexDist.lock();
dzoni 15:a627638edd9c 38 dist_data.timerTicks = timer.read_us();
dzoni 15:a627638edd9c 39
dzoni 15:a627638edd9c 40 // 340 ms-1
dzoni 15:a627638edd9c 41 dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f;
dzoni 17:94c385ff2641 42 // mutexDist.unlock();
dzoni 15:a627638edd9c 43
dzoni 15:a627638edd9c 44 // Vynuluj timer
dzoni 15:a627638edd9c 45 timer.reset();
dzoni 15:a627638edd9c 46 }
dzoni 9:645f0e517017 47
dzoni 9:645f0e517017 48 void dist_thread(void const *args) {
dzoni 9:645f0e517017 49
dzoni 9:645f0e517017 50 while (true) {
dzoni 9:645f0e517017 51 // Dej puls na trig
dzoni 9:645f0e517017 52 trigDist = 1;
dzoni 9:645f0e517017 53 Thread::wait(1);
dzoni 9:645f0e517017 54 trigDist = 0;
dzoni 9:645f0e517017 55
dzoni 9:645f0e517017 56 if (echoDist != 0) {
dzoni 17:94c385ff2641 57 mutexDist.lock();
dzoni 9:645f0e517017 58 dist_data.timerTicks = 0;
dzoni 9:645f0e517017 59 dist_data.distance = 0.0f;
dzoni 17:94c385ff2641 60 mutexDist.unlock();
dzoni 9:645f0e517017 61 } else {
dzoni 15:a627638edd9c 62 // Vynuluj timer
dzoni 9:645f0e517017 63 timer.stop();
dzoni 9:645f0e517017 64 timer.reset();
dzoni 9:645f0e517017 65
dzoni 15:a627638edd9c 66 // Cekej na hrany na Echo
dzoni 15:a627638edd9c 67 echoDist.rise(&rising);
dzoni 15:a627638edd9c 68 echoDist.fall(&falling);
dzoni 9:645f0e517017 69 }
dzoni 9:645f0e517017 70
dzoni 17:94c385ff2641 71 Thread::wait(1000);
dzoni 9:645f0e517017 72 }
dzoni 9:645f0e517017 73 }