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:
dzoni
Date:
Mon Dec 14 21:46:45 2015 +0000
Revision:
15:a627638edd9c
Parent:
13:f62b10a6e1c5
Child:
17:94c385ff2641
Hangs out in display ("Raw: 20" and that's all)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dzoni 9:645f0e517017 1 #include "mbed.h"
dzoni 9:645f0e517017 2 #include "rtos.h"
dzoni 9:645f0e517017 3
dzoni 9:645f0e517017 4 #include "tsk_button.h"
dzoni 9:645f0e517017 5 #include "tsk_display.h"
dzoni 9:645f0e517017 6 #include "tsk_dist.h"
dzoni 9:645f0e517017 7 #include "tsk_led.h"
dzoni 9:645f0e517017 8 #include "tsk_temp.h"
dzoni 11:e89f89c0920b 9
dzoni 11:e89f89c0920b 10 #define TASKS_NUMBER (sizeof(taskList)/sizeof(taskList[0]))
dzoni 11:e89f89c0920b 11
dzoni 9:645f0e517017 12 uint32_t uiCnt = 0;
dzoni 9:645f0e517017 13
dzoni 13:f62b10a6e1c5 14
dzoni 11:e89f89c0920b 15 struct task_definition_struct {
dzoni 11:e89f89c0920b 16 void(*task)(void const *args);
dzoni 15:a627638edd9c 17 uint32_t(*init)(void const *args); // Result: 1 = OK, 0 = FAIL
dzoni 11:e89f89c0920b 18 void *task_args; // NULL For DEFAULT (NULL)
dzoni 11:e89f89c0920b 19 void *init_args; // NULL For DEFAULT (NULL)
dzoni 11:e89f89c0920b 20 osPriority priority;
dzoni 11:e89f89c0920b 21 // uint32_t stack_size; // 0 for DEFAULT (DEFAULT_STACK_SIZE)
dzoni 11:e89f89c0920b 22 // unsigned char *stack_pointer; // NULL for DEFAULT (NULL)
dzoni 11:e89f89c0920b 23 uint32_t delay; // Delay on start from previous task
dzoni 11:e89f89c0920b 24 Thread *thread; // To be filled in during runtime
dzoni 11:e89f89c0920b 25 uint32_t retVal; // Return Value - to be filled in during runtime
dzoni 11:e89f89c0920b 26 };
dzoni 11:e89f89c0920b 27
dzoni 11:e89f89c0920b 28 static struct task_definition_struct taskList[] = {
dzoni 15:a627638edd9c 29 { dist_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 },
dzoni 15:a627638edd9c 30 { temp_thread, &initDS1620Temp, NULL, NULL, osPriorityLow, 0, NULL, 0 },
dzoni 15:a627638edd9c 31 { button_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 },
dzoni 15:a627638edd9c 32 { led_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 },
dzoni 15:a627638edd9c 33 { disp_thread, &initDisplay, NULL, NULL, osPriorityNormal, 0, NULL, 0 },
dzoni 11:e89f89c0920b 34 };
dzoni 11:e89f89c0920b 35
dzoni 11:e89f89c0920b 36 static uint32_t initTasks(void) {
dzoni 12:1de8b271e292 37 uint32_t i;
dzoni 12:1de8b271e292 38 uint32_t retval = 1;
dzoni 11:e89f89c0920b 39
dzoni 11:e89f89c0920b 40 for (i = 0; i < TASKS_NUMBER; i++) {
dzoni 12:1de8b271e292 41 if (taskList[i].init != NULL) {
dzoni 12:1de8b271e292 42 if ((taskList[i].retVal = ((*taskList[i].init)(taskList[i].init_args))) == 0)
dzoni 12:1de8b271e292 43 retval = 0;
dzoni 13:f62b10a6e1c5 44 } else {
dzoni 13:f62b10a6e1c5 45 taskList[i].retVal = 1;
dzoni 11:e89f89c0920b 46 }
dzoni 11:e89f89c0920b 47 }
dzoni 11:e89f89c0920b 48
dzoni 11:e89f89c0920b 49 for (i = 0; i < TASKS_NUMBER; i++) {
dzoni 11:e89f89c0920b 50 Thread::wait(taskList[i].delay);
dzoni 11:e89f89c0920b 51
dzoni 11:e89f89c0920b 52 if (taskList[i].retVal == 1) {
dzoni 11:e89f89c0920b 53 taskList[i].thread = new Thread(taskList[i].task, taskList[i].task_args, taskList[i].priority );
dzoni 11:e89f89c0920b 54 }
dzoni 11:e89f89c0920b 55 }
dzoni 11:e89f89c0920b 56
dzoni 12:1de8b271e292 57 return retval;
dzoni 11:e89f89c0920b 58 }
dzoni 11:e89f89c0920b 59
dzoni 11:e89f89c0920b 60
dzoni 9:645f0e517017 61 int main() {
dzoni 9:645f0e517017 62
dzoni 13:f62b10a6e1c5 63 Thread::wait(1000);
dzoni 13:f62b10a6e1c5 64
dzoni 13:f62b10a6e1c5 65 initTasks();
dzoni 9:645f0e517017 66
dzoni 9:645f0e517017 67 Thread::wait(osWaitForever);
dzoni 13:f62b10a6e1c5 68
dzoni 13:f62b10a6e1c5 69 disposeDisplay(NULL);
dzoni 9:645f0e517017 70 }
dzoni 9:645f0e517017 71