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
Diff: tsk_main.cpp
- Revision:
- 11:e89f89c0920b
- Parent:
- 9:645f0e517017
- Child:
- 12:1de8b271e292
--- a/tsk_main.cpp Mon Dec 14 11:36:34 2015 +0000 +++ b/tsk_main.cpp Mon Dec 14 17:15:29 2015 +0000 @@ -6,20 +6,68 @@ #include "tsk_dist.h" #include "tsk_led.h" #include "tsk_temp.h" - + +#define TASKS_NUMBER (sizeof(taskList)/sizeof(taskList[0])) + + uint32_t uiCnt = 0; +struct task_definition_struct { + void(*task)(void const *args); + uint32_t(*init)(void const *args); // 1 = OK, 0 = FAIL + void *task_args; // NULL For DEFAULT (NULL) + void *init_args; // NULL For DEFAULT (NULL) + osPriority priority; +// uint32_t stack_size; // 0 for DEFAULT (DEFAULT_STACK_SIZE) +// unsigned char *stack_pointer; // NULL for DEFAULT (NULL) + uint32_t delay; // Delay on start from previous task + Thread *thread; // To be filled in during runtime + uint32_t retVal; // Return Value - to be filled in during runtime +}; + +static struct task_definition_struct taskList[] = { + { button_thread, NULL, NULL, NULL, osPriorityAboveNormal, 0, NULL, 0 }, + { disp_thread, NULL, NULL, NULL, osPriorityLow, 0, NULL, 0 }, + { dist_thread, NULL, NULL, NULL, osPriorityRealtime, 0, NULL, 0 }, + { temp_thread, &initDS1620Temp, NULL, NULL, osPriorityLow, 0, NULL, 0 }, + { led_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, +}; + +static uint32_t initTasks(void) { + uint32_t i; + + for (i = 0; i < TASKS_NUMBER; i++) { + if (taskList[i].init) { + taskList[i].retVal = ((*taskList[i].init)(taskList[i].init_args)); + } + } + + for (i = 0; i < TASKS_NUMBER; i++) { + Thread::wait(taskList[i].delay); + + if (taskList[i].retVal == 1) { + taskList[i].thread = new Thread(taskList[i].task, taskList[i].task_args, taskList[i].priority ); + } + } + + return 0; +} + + int main() { Thread::wait(1000); - - initDS1620Temp(); +/* + initDS1620Temp(NULL); Thread dispThread(disp_thread, NULL, osPriorityLow); Thread tempThread(temp_thread, NULL, osPriorityLow); Thread distThread(dist_thread, NULL, osPriorityRealtime); - Thread led2Thread(led2_thread, NULL, osPriorityNormal); - Thread ubuttonThread(ubutton_thread, NULL, osPriorityAboveNormal); + Thread led2Thread(led_thread, NULL, osPriorityNormal); + Thread ubuttonThread(button_thread, NULL, osPriorityAboveNormal); +*/ + + initTasks(); Thread::wait(osWaitForever); }