summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2019-08-11 08:39:50 -0500
committerJeff Epler <jepler@gmail.com>2019-08-11 08:53:02 -0500
commit11dd3a260e53852ca3ccaf609040ca26bd56e665 (patch)
tree6bf428b3ca6462608cc7a2d046cf7a064d5fdf5e
parentd9ee2d28a03cdb13b0c6e33a6408293574bcbfef (diff)
nrf: Use RUN_BACKGROUND_TASKS
-rw-r--r--ports/nrf/bluetooth/ble_uart.c8
-rw-r--r--ports/nrf/common-hal/bleio/Central.c8
-rw-r--r--ports/nrf/common-hal/bleio/Characteristic.c8
-rw-r--r--ports/nrf/common-hal/bleio/CharacteristicBuffer.c2
-rw-r--r--ports/nrf/common-hal/busio/UART.c12
-rw-r--r--ports/nrf/common-hal/neopixel_write/__init__.c4
-rw-r--r--ports/nrf/common-hal/pulseio/PulseOut.c4
-rw-r--r--ports/nrf/mphalport.c4
-rw-r--r--ports/nrf/sd_mutex.c4
9 files changed, 18 insertions, 36 deletions
diff --git a/ports/nrf/bluetooth/ble_uart.c b/ports/nrf/bluetooth/ble_uart.c
index 91d10cff1..d83cf3980 100644
--- a/ports/nrf/bluetooth/ble_uart.c
+++ b/ports/nrf/bluetooth/ble_uart.c
@@ -138,9 +138,7 @@ void ble_uart_init(void) {
m_cccd_enabled = false;
while (!m_cccd_enabled) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
}
@@ -150,9 +148,7 @@ bool ble_uart_connected(void) {
char ble_uart_rx_chr(void) {
while (isBufferEmpty(&m_rx_ring_buffer)) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
uint8_t byte;
diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c
index d90737411..72657334c 100644
--- a/ports/nrf/common-hal/bleio/Central.c
+++ b/ports/nrf/common-hal/bleio/Central.c
@@ -60,7 +60,7 @@ STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_han
// Wait for a discovery event.
while (m_discovery_in_process) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
}
return m_discovery_successful;
}
@@ -82,7 +82,7 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi
// Wait for a discovery event.
while (m_discovery_in_process) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
}
return m_discovery_successful;
}
@@ -104,7 +104,7 @@ STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_character
// Wait for a discovery event.
while (m_discovery_in_process) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
}
return m_discovery_successful;
}
@@ -339,7 +339,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o
}
while (self->waiting_to_connect) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
}
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c
index 17417a5e6..8168f4671 100644
--- a/ports/nrf/common-hal/bleio/Characteristic.c
+++ b/ports/nrf/common-hal/bleio/Characteristic.c
@@ -125,7 +125,7 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp
// TX buffer is full
// We could wait for an event indicating the write is complete, but just retrying is easier.
if (err_code == NRF_ERROR_RESOURCES) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
continue;
}
@@ -153,7 +153,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
}
while (m_read_characteristic != NULL) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
}
}
@@ -178,7 +178,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
// Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending.
if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) {
// We could wait for an event indicating the write is complete, but just retrying is easier.
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
continue;
}
@@ -318,7 +318,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
// Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending.
if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) {
// We could wait for an event indicating the write is complete, but just retrying is easier.
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
continue;
}
diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c
index 59eaaf02b..01e0d0c84 100644
--- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c
+++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c
@@ -99,7 +99,7 @@ int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_
// Wait for all bytes received or timeout
while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
- MICROPY_VM_HOOK_LOOP;
+ RUN_BACKGROUND_TASKS;
// Allow user to break out of a timeout with a KeyboardInterrupt.
if ( mp_hal_is_interrupted() ) {
return 0;
diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c
index b9e9e5538..54a66ddbe 100644
--- a/ports/nrf/common-hal/busio/UART.c
+++ b/ports/nrf/common-hal/busio/UART.c
@@ -235,13 +235,11 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
// Wait for all bytes received or timeout
while ( (ringbuf_count(&self->rbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP ;
+ RUN_BACKGROUND_TASKS;
// Allow user to break out of a timeout with a KeyboardInterrupt.
if ( mp_hal_is_interrupted() ) {
return 0;
}
-#endif
}
// prevent conflict with uart irq
@@ -271,9 +269,7 @@ size_t common_hal_busio_uart_write (busio_uart_obj_t *self, const uint8_t *data,
// Wait for on-going transfer to complete
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
// Time up
@@ -295,9 +291,7 @@ size_t common_hal_busio_uart_write (busio_uart_obj_t *self, const uint8_t *data,
(*errcode) = 0;
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
if ( !nrfx_is_in_ram(data) ) {
diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c
index 78e0038e8..3b67778a6 100644
--- a/ports/nrf/common-hal/neopixel_write/__init__.c
+++ b/ports/nrf/common-hal/neopixel_write/__init__.c
@@ -200,9 +200,7 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
// But we have to wait for the flag to be set.
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
// Before leave we clear the flag for the event.
diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c
index be5deca9f..d0433247a 100644
--- a/ports/nrf/common-hal/pulseio/PulseOut.c
+++ b/ports/nrf/common-hal/pulseio/PulseOut.c
@@ -155,9 +155,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu
while(pulse_array_index < length) {
// Do other things while we wait. The interrupts will handle sending the
// signal.
- #ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
- #endif
+ RUN_BACKGROUND_TASKS;
}
nrfx_timer_disable(timer);
diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c
index 7d9463d0b..bcd9fb114 100644
--- a/ports/nrf/mphalport.c
+++ b/ports/nrf/mphalport.c
@@ -39,9 +39,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = ticks_ms;
uint64_t duration = 0;
while (duration < delay) {
- #ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
- #endif
+ RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user.
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
diff --git a/ports/nrf/sd_mutex.c b/ports/nrf/sd_mutex.c
index 7682ffa62..b3162e6af 100644
--- a/ports/nrf/sd_mutex.c
+++ b/ports/nrf/sd_mutex.c
@@ -37,9 +37,7 @@ void sd_mutex_acquire_check(nrf_mutex_t* p_mutex) {
void sd_mutex_acquire_wait(nrf_mutex_t* p_mutex) {
while (sd_mutex_acquire(p_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) {
-#ifdef MICROPY_VM_HOOK_LOOP
- MICROPY_VM_HOOK_LOOP
-#endif
+ RUN_BACKGROUND_TASKS;
}
}