Simon Hawe / D7_MLX_AND_BAT

Dependencies:   X_NUCLEO_IKS01A1 MLX90614 d7a_1x wizzi-utils

Fork of D7A_1x_demo_sensors_OS5 by WizziLab

Revision:
1:711fb7d8127b
Parent:
0:7e1fdc4d6e1c
Child:
3:5f2917933ece
diff -r 7e1fdc4d6e1c -r 711fb7d8127b main.cpp
--- a/main.cpp	Tue Dec 20 14:07:12 2016 +0000
+++ b/main.cpp	Wed Dec 21 14:22:00 2016 +0000
@@ -38,7 +38,27 @@
 #include "DebouncedInterrupt.h"
 #include "files.h"
 
-// Semaphore for notifiying button presses
+// -----------------------------------------------
+// Hardware configuration
+// -----------------------------------------------
+#if defined(TARGET_STM32L152RE)
+    #define D7A_PIN_TX              (D10)
+    #define D7A_PIN_RX              (D2)
+    #define D7A_PIN_RTS             (D13)
+    #define D7A_PIN_CTS             (D9)
+    #define D7A_PIN_RESET           (A3)
+    #define D7A_DEBUG_LED           (NC)
+#elif defined(TARGET_STM32L432KC)
+    #define D7A_PIN_TX              (D5)
+    #define D7A_PIN_RX              (D4)
+    #define D7A_PIN_RTS             (D11)
+    #define D7A_PIN_CTS             (D10)
+    #define D7A_PIN_RESET           (D12)
+    #define D7A_DEBUG_LED           (D13) // LED1
+#else
+    #error "Please choose or add the right platform."
+#endif
+
 Semaphore button_user(0);
 Semaphore thread_ready(0);
 
@@ -138,13 +158,12 @@
 
 // Com configuration for the DASH7 shield
 const d7a_com_config_t shield_config = {
-    .tx  = D10,
-    .rx  = D2,
-    .rts = D13,
-    .cts = D9,
+    .tx  = D7A_PIN_TX,
+    .rx  = D7A_PIN_RX,
+    .rts = D7A_PIN_RTS,
+    .cts = D7A_PIN_CTS,
 };
 
-
 // Check parameters to see if data should be send
 static bool report_needed(sensor_config_t* cfg, int32_t value, int32_t last_value, uint32_t last_report_time)
 {
@@ -201,6 +220,8 @@
 // -----------------------------------------------
 void sensor_thread()
 {
+    FPRINT("(id:0x%08x)\r\n", osThreadGetId());
+    
     // Get thread context
     sensor_thread_ctx_t* th_ctx = g_thread_ctx;
     
@@ -226,7 +247,7 @@
         // Read the sensor values
         bool err = th_ctx->read_value(th_ctx->current_value);
         
-        WARNING(!err, "Failed to read sensor value for FID: %d\r\n", th_ctx->value_file_id);
+        ASSERT(!err, "Failed to read sensor value for FID: %d\r\n", th_ctx->value_file_id);
 
         // Check if data should be send
         for (uint8_t i = 0; i < th_ctx->nb_values; i++)
@@ -390,24 +411,17 @@
 /*** Main function ------------------------------------------------------------- ***/
 int main()
 {
-    PinName DBG_LED = D12;
-        
-    // Go to sleep when idle
-    //rtos_attach_idle_hook(sleep);
-
     // Start & initialize
-    dbg_open(DBG_LED);
+    DBG_OPEN(D7A_DEBUG_LED);
     PRINT("\r\n--- Starting new run ---\r\n");
     
-    DigitalOut myled(DBG_LED);
-    DebouncedInterrupt user_interrupt(USER_BUTTON);
-    user_interrupt.attach(button_push_isr, IRQ_FALL, 200, true);
+    DigitalOut myled(D7A_DEBUG_LED);
     myled = 1;
     
     extern uint16_t const os_maxtaskrun;
     //IPRINT("Max user threads: %d\r\n", os_maxtaskrun-1-9);
 
-    d7a_open(&shield_config, A3, &callbacks);
+    d7a_open(&shield_config, D7A_PIN_RESET, &callbacks);
     d7a_modem_print_infos();
     
     // Create the revision file for the Dash7board
@@ -438,10 +452,10 @@
     osStatus status;
 
     // Start sensors threads
-#define THREAD_START(_name) Thread _name##_th(osPriorityNormal, DEFAULT_STACK_SIZE);\
+#define THREAD_START(_name) Thread _name##_th(osPriorityNormal, 1024, NULL);\
                             g_thread_ctx = &_name##_thread_ctx;\
                             status = _name##_th.start(sensor_thread);\
-                            ASSERT(status == osOK, "Failed to start _name thread (err: %d)\r\n", status);\
+                            ASSERT(status == osOK, "Failed to start ##_name## thread (err: %d)\r\n", status);\
                             thread_ready.wait();
                             
 
@@ -469,12 +483,19 @@
 #endif // _TEM2_EN_
 
     // File modified thread
-    Thread fm_th;
-    fm_th.start(file_modified_thread);
+    Thread fm_th(osPriorityNormal, 512, NULL);
+    status = fm_th.start(file_modified_thread);
+    ASSERT(status == osOK, "Failed to start fm thread (err: %d)\r\n", status);
 
-    // For button irq
-    Thread but_th(osPriorityNormal, DEFAULT_STACK_SIZE*4, NULL);
-    but_th.start(button_user_thread);
+    // For button
+#ifdef USER_BUTTON
+    DebouncedInterrupt user_interrupt(USER_BUTTON);
+    user_interrupt.attach(button_push_isr, IRQ_FALL, 200, true);
+
+    Thread but_th(osPriorityNormal, 512, NULL);
+    status = but_th.start(button_user_thread);
+    ASSERT(status == osOK, "Failed to start but thread (err: %d)\r\n", status);
+#endif
     
     // Set main task to lowest priority
     osThreadSetPriority(osThreadGetId(), osPriorityIdle);