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 19:38:24 2015 +0000
Parent:
12:1de8b271e292
Child:
14:bd01b5240dee
Commit message:
Now works. Too big fluctuations in distance measurement values. Change to RTOS interrupt on EDGE pin change.

Changed in this revision

tsk_display.cpp Show annotated file Show diff for this revision Revisions of this file
tsk_display.h Show annotated file Show diff for this revision Revisions of this file
tsk_dist.cpp 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
--- a/tsk_display.cpp	Mon Dec 14 18:15:57 2015 +0000
+++ b/tsk_display.cpp	Mon Dec 14 19:38:24 2015 +0000
@@ -8,17 +8,25 @@
 #include "tsk_dist.h"
 #include "tsk_main.h"
 
-static TextLCD lcd(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2);
+static TextLCD *lcd = NULL;
 
 uint32_t initDisplay(void const *args) {
-    
-        lcd.cls();
-//        lcd.printf("Raw:%3u % 5.0f mm", temp_data.temp_raw, dist_data.distance);
-        lcd.printf("Row 1");
-        lcd.locate(0, 1);    
-//        lcd.printf("Float: %3.2f%cC", temp_data.temperature, 0xdf);
-        lcd.printf("Row 2");
-    
+
+    lcd = new TextLCD(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2);
+
+    lcd->cls();
+    lcd->printf("Row 1");
+    lcd->locate(0, 1);    
+    lcd->printf("Row 2");
+       
+    return 1;
+}
+
+uint32_t disposeDisplay(void const *args) {
+
+    delete lcd;
+    lcd = NULL;
+       
     return 1;
 }
 
@@ -26,15 +34,12 @@
 void disp_thread(void const *args) {
 
     while (true) {
-        lcd.cls();
-//        lcd.printf("Raw:%3u % 5.0f mm", temp_data.temp_raw, dist_data.distance);
-        lcd.printf("Row 1");
+        lcd->cls();
+        lcd->printf("Raw:%3u % 5.0f mm", temp_data.temp_raw, dist_data.distance);
         uiCnt += 2;
-        lcd.locate(0, 1);    
-//        lcd.printf("Float: %3.2f%cC", temp_data.temperature, 0xdf);
-        lcd.printf("Row 2");
+        lcd->locate(0, 1);    
+        lcd->printf("Float: %3.2f%cC", temp_data.temperature, 0xdf);
 
-        Thread::wait(5000);
+        Thread::wait(2000);
     }
-}
-
+}
\ No newline at end of file
--- a/tsk_display.h	Mon Dec 14 18:15:57 2015 +0000
+++ b/tsk_display.h	Mon Dec 14 19:38:24 2015 +0000
@@ -2,6 +2,7 @@
 #define TSK_DISPLAY_H
 
 extern uint32_t initDisplay(void const *args);
+extern uint32_t disposeDisplay(void const *args);
 extern void disp_thread(void const *args);
 
 #endif
--- a/tsk_dist.cpp	Mon Dec 14 18:15:57 2015 +0000
+++ b/tsk_dist.cpp	Mon Dec 14 19:38:24 2015 +0000
@@ -48,6 +48,6 @@
             dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f;
         }
         
-        Thread::wait(500);
+        Thread::wait(1000);
     }
 }
--- a/tsk_main.cpp	Mon Dec 14 18:15:57 2015 +0000
+++ b/tsk_main.cpp	Mon Dec 14 19:38:24 2015 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "TextLCD.h"
 
 #include "tsk_button.h"
 #include "tsk_display.h"
@@ -11,6 +12,7 @@
 
 uint32_t uiCnt = 0;
 
+
 struct task_definition_struct {
     void(*task)(void const *args);
     uint32_t(*init)(void const *args); // 1 = OK, 0 = FAIL
@@ -29,7 +31,7 @@
     { temp_thread,   &initDS1620Temp, NULL, NULL, osPriorityLow,         0, NULL, 0 },
     { button_thread, NULL,            NULL, NULL, osPriorityAboveNormal, 0, NULL, 0 },
     { led_thread,    NULL,            NULL, NULL, osPriorityNormal,      0, NULL, 0 },
-    { disp_thread,   NULL,            NULL, NULL, osPriorityLow,         0, NULL, 0 },
+    { disp_thread,   &initDisplay,    NULL, NULL, osPriorityLow,         0, NULL, 0 },
 };
 
 static uint32_t initTasks(void) {
@@ -40,6 +42,8 @@
         if (taskList[i].init != NULL) {
             if ((taskList[i].retVal = ((*taskList[i].init)(taskList[i].init_args))) == 0)
                 retval = 0;
+        } else {
+            taskList[i].retVal = 1;
         }
     }
             
@@ -56,21 +60,25 @@
 
 
 int main() {
+
     
-//    Thread::wait(1000);
+    Thread::wait(1000);
+
+    initDS1620Temp(NULL);
+    initDisplay(NULL);
 
-//    initDS1620Temp(NULL);
-      initDisplay(NULL);
-      
-//    Thread tempThread(temp_thread, NULL, osPriorityLow);
-//    Thread distThread(dist_thread, NULL, osPriorityRealtime);
-//    Thread ledThread(led_thread, NULL, osPriorityNormal);
-//    Thread buttonThread(button_thread, NULL, osPriorityAboveNormal);
-//    Thread dispThread(disp_thread, NULL, osPriorityNormal);
+/*      
+    Thread tempThread(temp_thread, NULL, osPriorityLow);
+    Thread distThread(dist_thread, NULL, osPriorityRealtime);
+    Thread ledThread(led_thread, NULL, osPriorityNormal);
+    Thread buttonThread(button_thread, NULL, osPriorityAboveNormal);
+    Thread dispThread(disp_thread, NULL, osPriorityNormal);
+*/
 
-
-//    initTasks();
+    initTasks();
 
     Thread::wait(osWaitForever);
+
+    disposeDisplay(NULL);
 }
  
\ No newline at end of file