Implemented LED Indicator Patterns

Dependencies:   mbed

Revision:
30:c186bf174348
Parent:
29:ca6caa47ef38
--- a/app/main.cpp	Thu Apr 25 15:49:17 2019 +0000
+++ b/app/main.cpp	Wed Sep 04 15:42:07 2019 +0000
@@ -975,14 +975,14 @@
             break;
     }
     
-    // Measure voltage preval
-    float battery_reading = BAT_PIN.read()*1000;
-    measurements[0] = (uint8_t) rintf(battery_reading/10);
-    
     // Start test
     relayPin = 1;
     AppLedStateOn = 1;
     Led3StateChanged = true;
+    
+    // Measure voltage preval
+    float battery_reading = BAT_PIN.read()*1000;
+    measurements[0] = (uint8_t) rintf(battery_reading/10);
 }
 
 void endTest(uint8_t *measurements) {
@@ -994,9 +994,9 @@
     int rh_reading = RH_PIN.read()*1000 - vce_reading;
     
     measurements[1] = (uint8_t) rintf(battery_reading/10);
-    measurements[2] = (uint8_t) light_1_reading/2;
-    measurements[3] = (uint8_t) light_2_reading/2;
-    measurements[4] = (uint8_t) rh_reading/2;
+    measurements[2] = (uint8_t) (light_1_reading/2);
+    measurements[3] = (uint8_t) (light_2_reading/2);
+    measurements[4] = (uint8_t) (rh_reading/2);
     
     // End test // 
     relayPin = 0;
@@ -1038,6 +1038,12 @@
     RCC_ClkInitTypeDef RCC_ClkInitStruct;
     RCC_OscInitTypeDef RCC_OscInitStruct;
 
+    /* configure RTC clock for HSE */
+    SET_BIT(PWR->CR, PWR_CR_DBP);   // enable RTC register access as they are in backup domain
+    __HAL_RCC_BACKUPRESET_FORCE();  // force reset RTC subsystem
+    __HAL_RCC_BACKUPRESET_RELEASE();
+    __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_HSE_DIV8); // HSE=8MHZ and RTC clock input is 1MHz(when using HSE as source)
+    
     /* Enable HSE and activate PLL with HSE as source */
     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
     RCC_OscInitStruct.HSEState       = RCC_HSE_ON; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
@@ -1070,7 +1076,11 @@
     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
         return (-3); // FAIL
     }
-        
+
+    // enable rtc hardware
+    __HAL_RCC_RTC_ENABLE();
+    wait(1.0);
+
     return 0; // OK
 }
 
@@ -1099,14 +1109,14 @@
     }    
 }
 
-
 int main( void )
 {
-    pc.printf("mbed-os-rev: %d.%d.%d   lib-rev: %d\r\n", \
-            MBED_MAJOR_VERSION, MBED_MINOR_VERSION,MBED_PATCH_VERSION,MBED_LIBRARY_VERSION);
-    pc.printf("BUILD= %s, SysClock= %d, RCC= %0X\r\n", __TIME__, SystemCoreClock, RCC->CR);   
+    pc.printf("BUILD: %s mbed-os-rev: %d.%d.%d lib-rev: %d\r\n", \
+            __TIME__, MBED_MAJOR_VERSION, MBED_MINOR_VERSION,MBED_PATCH_VERSION,MBED_LIBRARY_VERSION);
+    pc.printf("OLD: SysClock= %d RCC= %08X CSR= %08X CIER= %08X\r\n", SystemCoreClock, RCC->CR, RCC->CSR, RCC->CIER);
     my_patch();
-    pc.printf("NEW SysClock= %d, NEW RCC= %0X\r\n", SystemCoreClock, RCC->CR);
+    pc.printf("\r\nNEW: SysClock= %d RCC= %08X CSR= %08X CIER= %08X\r\n", SystemCoreClock, RCC->CR, RCC->CSR, RCC->CIER);
+    
     wait(3);
     LoRaMacPrimitives_t LoRaMacPrimitives;
     LoRaMacCallback_t LoRaMacCallbacks;
@@ -1236,6 +1246,17 @@
                 mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
                 LoRaMacMibSetRequestConfirm( &mibReq );
 
+                // Limiting to just 2nd subband of 8 channels
+                static uint16_t GatewayChannelsMask[] = {0xFF00, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000};
+                mibReq.Type = MIB_CHANNELS_DEFAULT_MASK;
+                mibReq.Param.ChannelsDefaultMask = GatewayChannelsMask;
+                LoRaMacMibSetRequestConfirm( &mibReq );
+
+                mibReq.Type = MIB_CHANNELS_MASK;
+                mibReq.Param.ChannelsMask = GatewayChannelsMask;
+                LoRaMacMibSetRequestConfirm( &mibReq );
+                
+
 #if defined( USE_BAND_868 )
                 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
                 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );