
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
tsk_main.cpp@12:1de8b271e292, 2015-12-14 (annotated)
- Committer:
- dzoni
- Date:
- Mon Dec 14 18:15:57 2015 +0000
- Revision:
- 12:1de8b271e292
- Parent:
- 11:e89f89c0920b
- Child:
- 13:f62b10a6e1c5
Compiles OK. Testing fails (display).
Who changed what in which revision?
User | Revision | Line number | New 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 | 11:e89f89c0920b | 14 | struct task_definition_struct { |
dzoni | 11:e89f89c0920b | 15 | void(*task)(void const *args); |
dzoni | 11:e89f89c0920b | 16 | uint32_t(*init)(void const *args); // 1 = OK, 0 = FAIL |
dzoni | 11:e89f89c0920b | 17 | void *task_args; // NULL For DEFAULT (NULL) |
dzoni | 11:e89f89c0920b | 18 | void *init_args; // NULL For DEFAULT (NULL) |
dzoni | 11:e89f89c0920b | 19 | osPriority priority; |
dzoni | 11:e89f89c0920b | 20 | // uint32_t stack_size; // 0 for DEFAULT (DEFAULT_STACK_SIZE) |
dzoni | 11:e89f89c0920b | 21 | // unsigned char *stack_pointer; // NULL for DEFAULT (NULL) |
dzoni | 11:e89f89c0920b | 22 | uint32_t delay; // Delay on start from previous task |
dzoni | 11:e89f89c0920b | 23 | Thread *thread; // To be filled in during runtime |
dzoni | 11:e89f89c0920b | 24 | uint32_t retVal; // Return Value - to be filled in during runtime |
dzoni | 11:e89f89c0920b | 25 | }; |
dzoni | 11:e89f89c0920b | 26 | |
dzoni | 11:e89f89c0920b | 27 | static struct task_definition_struct taskList[] = { |
dzoni | 12:1de8b271e292 | 28 | { dist_thread, NULL, NULL, NULL, osPriorityRealtime, 0, NULL, 0 }, |
dzoni | 12:1de8b271e292 | 29 | { temp_thread, &initDS1620Temp, NULL, NULL, osPriorityLow, 0, NULL, 0 }, |
dzoni | 12:1de8b271e292 | 30 | { button_thread, NULL, NULL, NULL, osPriorityAboveNormal, 0, NULL, 0 }, |
dzoni | 12:1de8b271e292 | 31 | { led_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, |
dzoni | 12:1de8b271e292 | 32 | { disp_thread, NULL, NULL, NULL, osPriorityLow, 0, NULL, 0 }, |
dzoni | 11:e89f89c0920b | 33 | }; |
dzoni | 11:e89f89c0920b | 34 | |
dzoni | 11:e89f89c0920b | 35 | static uint32_t initTasks(void) { |
dzoni | 12:1de8b271e292 | 36 | uint32_t i; |
dzoni | 12:1de8b271e292 | 37 | uint32_t retval = 1; |
dzoni | 11:e89f89c0920b | 38 | |
dzoni | 11:e89f89c0920b | 39 | for (i = 0; i < TASKS_NUMBER; i++) { |
dzoni | 12:1de8b271e292 | 40 | if (taskList[i].init != NULL) { |
dzoni | 12:1de8b271e292 | 41 | if ((taskList[i].retVal = ((*taskList[i].init)(taskList[i].init_args))) == 0) |
dzoni | 12:1de8b271e292 | 42 | retval = 0; |
dzoni | 11:e89f89c0920b | 43 | } |
dzoni | 11:e89f89c0920b | 44 | } |
dzoni | 11:e89f89c0920b | 45 | |
dzoni | 11:e89f89c0920b | 46 | for (i = 0; i < TASKS_NUMBER; i++) { |
dzoni | 11:e89f89c0920b | 47 | Thread::wait(taskList[i].delay); |
dzoni | 11:e89f89c0920b | 48 | |
dzoni | 11:e89f89c0920b | 49 | if (taskList[i].retVal == 1) { |
dzoni | 11:e89f89c0920b | 50 | taskList[i].thread = new Thread(taskList[i].task, taskList[i].task_args, taskList[i].priority ); |
dzoni | 11:e89f89c0920b | 51 | } |
dzoni | 11:e89f89c0920b | 52 | } |
dzoni | 11:e89f89c0920b | 53 | |
dzoni | 12:1de8b271e292 | 54 | return retval; |
dzoni | 11:e89f89c0920b | 55 | } |
dzoni | 11:e89f89c0920b | 56 | |
dzoni | 11:e89f89c0920b | 57 | |
dzoni | 9:645f0e517017 | 58 | int main() { |
dzoni | 9:645f0e517017 | 59 | |
dzoni | 12:1de8b271e292 | 60 | // Thread::wait(1000); |
dzoni | 11:e89f89c0920b | 61 | |
dzoni | 12:1de8b271e292 | 62 | // initDS1620Temp(NULL); |
dzoni | 12:1de8b271e292 | 63 | initDisplay(NULL); |
dzoni | 12:1de8b271e292 | 64 | |
dzoni | 12:1de8b271e292 | 65 | // Thread tempThread(temp_thread, NULL, osPriorityLow); |
dzoni | 12:1de8b271e292 | 66 | // Thread distThread(dist_thread, NULL, osPriorityRealtime); |
dzoni | 12:1de8b271e292 | 67 | // Thread ledThread(led_thread, NULL, osPriorityNormal); |
dzoni | 12:1de8b271e292 | 68 | // Thread buttonThread(button_thread, NULL, osPriorityAboveNormal); |
dzoni | 12:1de8b271e292 | 69 | // Thread dispThread(disp_thread, NULL, osPriorityNormal); |
dzoni | 12:1de8b271e292 | 70 | |
dzoni | 12:1de8b271e292 | 71 | |
dzoni | 12:1de8b271e292 | 72 | // initTasks(); |
dzoni | 9:645f0e517017 | 73 | |
dzoni | 9:645f0e517017 | 74 | Thread::wait(osWaitForever); |
dzoni | 9:645f0e517017 | 75 | } |
dzoni | 9:645f0e517017 | 76 |