diff --git a/cores/nRF5/Arduino.h b/cores/nRF5/Arduino.h index 66350e72..a957d913 100644 --- a/cores/nRF5/Arduino.h +++ b/cores/nRF5/Arduino.h @@ -34,7 +34,8 @@ void yield( void ) ; /* sketch */ void setup( void ) ; void loop( void ) ; -void setLoopStacksize(uint32_t size); + +uint32_t setLoopStacksize(void); #include "WVariant.h" diff --git a/cores/nRF5/delay.c b/cores/nRF5/delay.c index 6c6dfc85..0e0b53c2 100644 --- a/cores/nRF5/delay.c +++ b/cores/nRF5/delay.c @@ -41,6 +41,7 @@ uint32_t micros( void ) return (ticks * 1000000) / 32768; } +#if 0 void delay( uint32_t ms ) { if ( ms == 0 ) @@ -55,6 +56,29 @@ void delay( uint32_t ms ) yield() ; } while ( millis() - start < ms ) ; } +#else + +void delay_blocking(uint32_t ms) +{ + if ( ms == 0 ) + { + return ; + } + + uint32_t start = millis() ; + + do + { +// yield() ; + } while ( millis() - start < ms ) ; +} + +void delay( uint32_t ms ) +{ + vTaskDelay(ms2tick(ms)); +} + +#endif void RTC1_IRQHandler(void) { diff --git a/cores/nRF5/delay.h b/cores/nRF5/delay.h index 659b13c4..35f9d96e 100644 --- a/cores/nRF5/delay.h +++ b/cores/nRF5/delay.h @@ -58,6 +58,12 @@ extern uint32_t micros( void ) ; */ extern void delay( uint32_t dwMs ) ; +/** + * Delay blocking without using RTOS API to suspend running thread + * @param ms + */ +extern void delay_blocking(uint32_t ms); + /** * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. * diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 62bbcd43..d8a3c74f 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -23,15 +23,14 @@ void initVariant() { } uint32_t _loopStacksize = 1024*2; -void setLoopStacksize(uint32_t size) -{ - _loopStacksize = size; -} +uint32_t setLoopStacksize(void) __attribute__ ((weak)); static void loop_task(void* arg) { (void) arg; + setup(); + while (1) { loop(); @@ -50,9 +49,12 @@ int main( void ) initVariant(); - delay(1); + delay_blocking(1); - setup(); + if (setLoopStacksize) + { + _loopStacksize = setLoopStacksize(); + } // Create a task for loop() TaskHandle_t _loopHandle; diff --git a/cores/nRF5/rtos.h b/cores/nRF5/rtos.h index e96fec04..ec986ab8 100644 --- a/cores/nRF5/rtos.h +++ b/cores/nRF5/rtos.h @@ -48,7 +48,4 @@ #include "queue.h" #include "semphr.h" -#define rtos_delay(ms) vTaskDelay(ms2tick(ms)) - - #endif /* RTOS_H_ */ diff --git a/libraries/Bluefruit52Lib/examples/bleuart/bleuart.ino b/libraries/Bluefruit52Lib/examples/bleuart/bleuart.ino index ad823ecb..25e7c532 100644 --- a/libraries/Bluefruit52Lib/examples/bleuart/bleuart.ino +++ b/libraries/Bluefruit52Lib/examples/bleuart/bleuart.ino @@ -19,10 +19,9 @@ BLEBas blebas; void setup() { - pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); - Serial.println("BLEUART Example"); + Serial.println("Bluefruit52 BLEUART Example"); Bluefruit.begin(); Bluefruit.setName("Bluefruit52"); diff --git a/libraries/Bluefruit52Lib/examples/blinky_ota/blinky_ota.ino b/libraries/Bluefruit52Lib/examples/blinky_ota/blinky_ota.ino index 0b3c5640..29e40cea 100644 --- a/libraries/Bluefruit52Lib/examples/blinky_ota/blinky_ota.ino +++ b/libraries/Bluefruit52Lib/examples/blinky_ota/blinky_ota.ino @@ -16,7 +16,6 @@ void setup() { - pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); Serial.println("Bluefruit52 Blinky Example"); @@ -48,6 +47,6 @@ void loop() digitalToggle(LED_BUILTIN); digitalToggle(LED_CONN); - rtos_delay(1000); + delay(1000); }