Honza T. / Mbed 2 deprecated EXAMPLE_Nucleo_mbed_RTOS_test_code

Dependencies:   DS1620_improved TextLCD_improved mbed-rtos mbed

Committer:
dzoni
Date:
Mon Dec 14 19:38:24 2015 +0000
Revision:
13:f62b10a6e1c5
Parent:
12:1de8b271e292
Child:
15:a627638edd9c
Now works. Too big fluctuations in distance measurement values. Change to RTOS interrupt on EDGE pin change.

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