Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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
Revision 101:50377edb21c6, committed 2017-11-19
- Comitter:
- Helmut Tschemernjak
- Date:
- Sun Nov 19 17:51:27 2017 +0100
- Parent:
- 100:c80d1416bdf6
- Child:
- 102:3e0f7696f4a5
- Commit message:
- Added a feature to preset the ns_ticker start value
Changed in this revision
--- a/Arduino-mbed-APIs/arduino-d21.cpp Sun Nov 19 17:49:33 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-d21.cpp Sun Nov 19 17:51:27 2017 +0100
@@ -101,6 +101,13 @@
uint64_t ticker_ns;
static bool initTickerDone = false;
+void setTickerStartSecs(int secs)
+{
+ ticker_ns = (uint64_t)1000000 * (uint64_t)secs;
+ ticker_ns *= (uint64_t)1000;
+}
+
+
uint64_t ns_getTicker(void)
{
Tcc *t = TCC_data[USE_TCC_TICKER].tcc_ptr;
--- a/Arduino-mbed-APIs/arduino-esp32.cpp Sun Nov 19 17:49:33 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-esp32.cpp Sun Nov 19 17:51:27 2017 +0100
@@ -10,7 +10,7 @@
#include "arduino-mbed.h"
#include "arduino-util.h"
-
+#include <time.h>
#if defined(ARDUINO_ARCH_ESP32)
@@ -60,6 +60,8 @@
#define USE_TIMER_TIMEOUT 0 // 0, 1, 2 (see ESP32 docs)
#define USE_TIMER_TICKER 1 // 0, 1, 2 (see ESP32 docs)
#define MAX_TIMERS 3
+#define TIMER_DIVIDER 80
+#define TIMER_CLOCK 80
/*
* Calculation of ticks see timerBegin divider
@@ -102,15 +104,14 @@
if (!initTickerDone) {
initTimer(timerID);
initTickerDone = true;
- dprintf("ESP32 Revision: %d (%d MHz)\r\n", ESP.getChipRevision(), ESP.getCpuFreqMHz());
}
hw_timer_t *timer = Timer_data[USE_TIMER_TICKER].timer;
uint64_t ns = timerRead(timer);
uint16_t div = timerGetDivider(timer);
ns *= div; // get to the real clocks
- ns /= 8; // 80 MHz , divide by 8 to keep more NS
- ns *= 100; // us to ns equals 1000, however we divided only by 8 remaing are 1000
+ ns *= 1000; // convert micros to NS.
+ ns /= TIMER_CLOCK; // 80 MHz clock, convert to micro seconds
return ns;
}
@@ -127,11 +128,23 @@
if (timerID > MAX_TIMERS-1)
return;
- cp->timer = timerBegin(timerID, 80, true);
+ cp->timer = timerBegin(timerID, TIMER_DIVIDER, true);
timerWrite(cp->timer, 0);
- if (timerID == USE_TIMER_TICKER)
+ if (timerID == USE_TIMER_TICKER) {
+ time_t t = time(NULL);
+ if (t > 0) {
+ struct tm mytm;
+ uint64_t tstart;
+
+ localtime_r(&t, &mytm);
+ tstart = mytm.tm_sec + (mytm.tm_min * 60) + (mytm.tm_hour * 3600);
+ tstart *= 1000000;
+ tstart *= TIMER_CLOCK;
+ tstart /= TIMER_DIVIDER;
+ timerWrite(cp->timer, tstart);
+ }
timerStart(cp->timer);
- else {
+ } else {
timerAttachInterrupt(cp->timer, &onTimer, true);
timerAlarmWrite(cp->timer, TIMER_INFINITE, true);
timerAlarmEnable(cp->timer);
@@ -142,7 +155,8 @@
* otherwise it will not issue any alarms
* This affects only ESP32 rev 0
*/
- delay(20);
+ if (ESP.getChipRevision() == 0)
+ delay(20);
}
@@ -222,6 +236,7 @@
void deepsleep(void)
{
+ // Light Sleep
asm("waiti 0");
}
--- a/Arduino-mbed-APIs/arduino-mbed.cpp Sun Nov 19 17:49:33 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-mbed.cpp Sun Nov 19 17:51:27 2017 +0100
@@ -296,8 +296,6 @@
}
-
-
uint32_t s_getTicker(void)
{
long long ns = ns_getTicker();
@@ -327,6 +325,13 @@
return us;
}
+#ifdef ARDUINO_ARCH_ESP32
+#undef noInterrupts
+#undef interrupts
+#define noInterrupts() portENTER_CRITICAL(&timerLock)
+#define interrupts() portEXIT_CRITICAL(&timerLock)
+static portMUX_TYPE timerLock = portMUX_INITIALIZER_UNLOCKED;
+#endif
void
Timeout::insert(void)
--- a/Arduino-mbed-APIs/arduino-mbed.h Sun Nov 19 17:49:33 2017 +0100 +++ b/Arduino-mbed-APIs/arduino-mbed.h Sun Nov 19 17:51:27 2017 +0100 @@ -47,6 +47,7 @@ extern void stopTimer(TIMER_REF *t); extern TIMER_REF *getTimeoutTimer(void); extern uint64_t ns_getTicker(void); +extern void setTickerStartSecs(int secs); extern int CPUID(uint8_t *buf, int maxSize, uint32_t xorval); extern void sleep(void); extern void deepsleep(void);

