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

Files at this revision

API Documentation at this revision

Comitter:
dzoni
Date:
Mon Dec 14 17:15:29 2015 +0000
Parent:
10:e21d1da3b900
Child:
12:1de8b271e292
Commit message:
Compiles OK, ready for testing.

Changed in this revision

tsk_button.cpp Show annotated file Show diff for this revision Revisions of this file
tsk_button.h Show annotated file Show diff for this revision Revisions of this file
tsk_led.cpp Show annotated file Show diff for this revision Revisions of this file
tsk_led.h Show annotated file Show diff for this revision Revisions of this file
tsk_main.cpp Show annotated file Show diff for this revision Revisions of this file
tsk_temp.cpp Show annotated file Show diff for this revision Revisions of this file
tsk_temp.h Show annotated file Show diff for this revision Revisions of this file
--- a/tsk_button.cpp	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_button.cpp	Mon Dec 14 17:15:29 2015 +0000
@@ -7,7 +7,7 @@
 static DigitalIn   button1(USER_BUTTON);
 
 
-void ubutton_thread(void const *args) {
+void button_thread(void const *args) {
     static uint32_t last_state = button1;
     uint32_t temp;
             
--- a/tsk_button.h	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_button.h	Mon Dec 14 17:15:29 2015 +0000
@@ -1,6 +1,6 @@
 #ifndef TSK_BUTTON_H
 #define TSK_BUTTON_H
 
-extern void ubutton_thread(void const *args);
+extern void button_thread(void const *args);
 
 #endif
--- a/tsk_led.cpp	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_led.cpp	Mon Dec 14 17:15:29 2015 +0000
@@ -10,7 +10,7 @@
 static DigitalOut  led2(LED2);
 
 
-void led2_thread(void const *args) {
+void led_thread(void const *args) {
 
     while (true) {
         led2 = 1;
--- a/tsk_led.h	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_led.h	Mon Dec 14 17:15:29 2015 +0000
@@ -8,6 +8,6 @@
 
 extern struct led_flash_times_struct led_flash_times;
 
-extern void led2_thread(void const *args);
+extern void led_thread(void const *args);
 
 #endif
--- 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);
 }
--- a/tsk_temp.cpp	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_temp.cpp	Mon Dec 14 17:15:29 2015 +0000
@@ -11,13 +11,19 @@
 static  DS1620 ds1620Sensor(PB_4, PB_10, PB_3);
 
 
-void initDS1620Temp(void) {
+uint32_t initDS1620Temp(void const *args) {
     
     ds1620Sensor.setSerialClockFrequency(freq500k);
     
     if ((ds1620Sensor.readConfig() & 0x03) != 0x03) {
         ds1620Sensor.writeConfig(0x03);
     }
+    
+    if ((ds1620Sensor.readConfig() & 0x03) != 0x03) {
+        return 0;
+    }
+    
+    return 1;
 }
 
 void temp_thread(void const *args) {
--- a/tsk_temp.h	Mon Dec 14 11:36:34 2015 +0000
+++ b/tsk_temp.h	Mon Dec 14 17:15:29 2015 +0000
@@ -8,7 +8,7 @@
 
 extern struct temp_data_struct temp_data;
 
-extern void initDS1620Temp(void);
+extern uint32_t initDS1620Temp(void const *args);
 extern void temp_thread(void const *args);
 
 #endif