Helmut Tschemernjak / SX1276GenericLib

Dependents:   DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_USB_Rx ... more

Fork of SX1276Lib by Semtech

Files at this revision

API Documentation at this revision

Comitter:
Helmut Tschemernjak
Date:
Sun Jul 23 15:44:57 2017 +0200
Parent:
69:d440a5b04708
Child:
71:7067e67902a8
Commit message:
Better sleep() support for Arduino D21

Changed in this revision

sx1276/arduino-mbed.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/arduino-mbed.h Show annotated file Show diff for this revision Revisions of this file
sx1276/library.properties Show annotated file Show diff for this revision Revisions of this file
--- a/sx1276/arduino-mbed.cpp	Fri Jul 21 17:09:05 2017 +0200
+++ b/sx1276/arduino-mbed.cpp	Sun Jul 23 15:44:57 2017 +0200
@@ -270,6 +270,16 @@
 uint64_t ticker_ns;
 static bool initTickerDone = false;
 
+uint32_t s_getTicker(void)
+{
+    long long ns = ns_getTicker();
+    ns /= (long long)1000000000; // to secs
+    
+    int secs = ns;
+    return secs;
+}
+
+
 uint32_t ms_getTicker(void)
 {
     uint32_t us = us_getTicker();
@@ -617,12 +627,22 @@
      * when in sleep mode. */
     NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val;
 #endif
-
+    uint32_t saved_ms = ms_getTicker();
+    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // disbale SysTick
+    
     SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;	// clear deep sleep
     PM->SLEEP.reg = 2; // SYSTEM_SLEEPMODE_IDLE_2 IDLE 2 sleep mode.
 
     __DSB(); // ensures the completion of memory accesses
     __WFI(); // wait for interrupt
+    
+    int count = ms_getTicker() - saved_ms;
+    if (count > 0) { // update the Arduino Systicks
+        for (int i = 0; i < count; i++) {
+            SysTick_Handler();
+        }
+    }
+    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // enable SysTick
 }
 
 void deepsleep(void)
@@ -633,10 +653,14 @@
     NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val;
 #endif
 
+    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // disbale SysTick
+    
     SCB->SCR |=  SCB_SCR_SLEEPDEEP_Msk; // standby mode
-
+    
     __DSB(); // ensures the completion of memory accesses
     __WFI(); // wait for interrupt
+
+    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // enable SysTick
 }
 
 
--- a/sx1276/arduino-mbed.h	Fri Jul 21 17:09:05 2017 +0200
+++ b/sx1276/arduino-mbed.h	Sun Jul 23 15:44:57 2017 +0200
@@ -17,11 +17,11 @@
 #undef max
 #undef map
 
-
 typedef int PinName;
 #define NC	-1
 #define	wait_ms	delay
-
+/* we need to redefine out dprintf because stdio.h uses the same name */
+#define dprint	dxprintf
 
 #if ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606
  #define MYdigitalPinToInterrupt(x)	digitalPinToInterrupt(x)
@@ -211,6 +211,7 @@
     Callback<void()> _func;
 };
 
+extern uint32_t s_getTicker(void);
 extern uint32_t ms_getTicker(void);
 extern uint32_t us_getTicker(void);
 extern uint64_t ns_getTicker(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sx1276/library.properties	Sun Jul 23 15:44:57 2017 +0200
@@ -0,0 +1,9 @@
+name=SX1276GenericLib
+version=1.0
+author=Semtech Inc, Helmut Tschemernjak <helmut2009@me.com>
+maintainer=Helmut Tschemernjak <helmut2009@me.com>
+sentence=SX1276GenericLib to support sx1276 bassed LoRa modules, including HopeRF RFM95, Murata CMWX1ZZABZ and Semtech SX1276MB1MAS/SX1276MB1LAS modules
+paragraph=
+category=Communication
+url=http://https://developer.mbed.org/users/Helmut64/code/SX1276GenericLib/
+architectures=samd