Skip to content

Commit 11dd3a2

Browse files
committed
nrf: Use RUN_BACKGROUND_TASKS
1 parent d9ee2d2 commit 11dd3a2

9 files changed

Lines changed: 18 additions & 36 deletions

File tree

ports/nrf/bluetooth/ble_uart.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ void ble_uart_init(void) {
138138
m_cccd_enabled = false;
139139

140140
while (!m_cccd_enabled) {
141-
#ifdef MICROPY_VM_HOOK_LOOP
142-
MICROPY_VM_HOOK_LOOP
143-
#endif
141+
RUN_BACKGROUND_TASKS;
144142
}
145143
}
146144

@@ -150,9 +148,7 @@ bool ble_uart_connected(void) {
150148

151149
char ble_uart_rx_chr(void) {
152150
while (isBufferEmpty(&m_rx_ring_buffer)) {
153-
#ifdef MICROPY_VM_HOOK_LOOP
154-
MICROPY_VM_HOOK_LOOP
155-
#endif
151+
RUN_BACKGROUND_TASKS;
156152
}
157153

158154
uint8_t byte;

ports/nrf/common-hal/bleio/Central.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_han
6060

6161
// Wait for a discovery event.
6262
while (m_discovery_in_process) {
63-
MICROPY_VM_HOOK_LOOP;
63+
RUN_BACKGROUND_TASKS;
6464
}
6565
return m_discovery_successful;
6666
}
@@ -82,7 +82,7 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi
8282

8383
// Wait for a discovery event.
8484
while (m_discovery_in_process) {
85-
MICROPY_VM_HOOK_LOOP;
85+
RUN_BACKGROUND_TASKS;
8686
}
8787
return m_discovery_successful;
8888
}
@@ -104,7 +104,7 @@ STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_character
104104

105105
// Wait for a discovery event.
106106
while (m_discovery_in_process) {
107-
MICROPY_VM_HOOK_LOOP;
107+
RUN_BACKGROUND_TASKS;
108108
}
109109
return m_discovery_successful;
110110
}
@@ -339,7 +339,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o
339339
}
340340

341341
while (self->waiting_to_connect) {
342-
MICROPY_VM_HOOK_LOOP;
342+
RUN_BACKGROUND_TASKS;
343343
}
344344

345345
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {

ports/nrf/common-hal/bleio/Characteristic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp
125125
// TX buffer is full
126126
// We could wait for an event indicating the write is complete, but just retrying is easier.
127127
if (err_code == NRF_ERROR_RESOURCES) {
128-
MICROPY_VM_HOOK_LOOP;
128+
RUN_BACKGROUND_TASKS;
129129
continue;
130130
}
131131

@@ -153,7 +153,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
153153
}
154154

155155
while (m_read_characteristic != NULL) {
156-
MICROPY_VM_HOOK_LOOP;
156+
RUN_BACKGROUND_TASKS;
157157
}
158158
}
159159

@@ -178,7 +178,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
178178
// Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending.
179179
if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) {
180180
// We could wait for an event indicating the write is complete, but just retrying is easier.
181-
MICROPY_VM_HOOK_LOOP;
181+
RUN_BACKGROUND_TASKS;
182182
continue;
183183
}
184184

@@ -318,7 +318,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
318318
// Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending.
319319
if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) {
320320
// We could wait for an event indicating the write is complete, but just retrying is easier.
321-
MICROPY_VM_HOOK_LOOP;
321+
RUN_BACKGROUND_TASKS;
322322
continue;
323323
}
324324

ports/nrf/common-hal/bleio/CharacteristicBuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_
9999

100100
// Wait for all bytes received or timeout
101101
while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
102-
MICROPY_VM_HOOK_LOOP;
102+
RUN_BACKGROUND_TASKS;
103103
// Allow user to break out of a timeout with a KeyboardInterrupt.
104104
if ( mp_hal_is_interrupted() ) {
105105
return 0;

ports/nrf/common-hal/busio/UART.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,11 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
235235

236236
// Wait for all bytes received or timeout
237237
while ( (ringbuf_count(&self->rbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
238-
#ifdef MICROPY_VM_HOOK_LOOP
239-
MICROPY_VM_HOOK_LOOP ;
238+
RUN_BACKGROUND_TASKS;
240239
// Allow user to break out of a timeout with a KeyboardInterrupt.
241240
if ( mp_hal_is_interrupted() ) {
242241
return 0;
243242
}
244-
#endif
245243
}
246244

247245
// 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,
271269

272270
// Wait for on-going transfer to complete
273271
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
274-
#ifdef MICROPY_VM_HOOK_LOOP
275-
MICROPY_VM_HOOK_LOOP
276-
#endif
272+
RUN_BACKGROUND_TASKS;
277273
}
278274

279275
// Time up
@@ -295,9 +291,7 @@ size_t common_hal_busio_uart_write (busio_uart_obj_t *self, const uint8_t *data,
295291
(*errcode) = 0;
296292

297293
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
298-
#ifdef MICROPY_VM_HOOK_LOOP
299-
MICROPY_VM_HOOK_LOOP
300-
#endif
294+
RUN_BACKGROUND_TASKS;
301295
}
302296

303297
if ( !nrfx_is_in_ram(data) ) {

ports/nrf/common-hal/neopixel_write/__init__.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
200200

201201
// But we have to wait for the flag to be set.
202202
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
203-
#ifdef MICROPY_VM_HOOK_LOOP
204-
MICROPY_VM_HOOK_LOOP
205-
#endif
203+
RUN_BACKGROUND_TASKS;
206204
}
207205

208206
// Before leave we clear the flag for the event.

ports/nrf/common-hal/pulseio/PulseOut.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu
155155
while(pulse_array_index < length) {
156156
// Do other things while we wait. The interrupts will handle sending the
157157
// signal.
158-
#ifdef MICROPY_VM_HOOK_LOOP
159-
MICROPY_VM_HOOK_LOOP
160-
#endif
158+
RUN_BACKGROUND_TASKS;
161159
}
162160

163161
nrfx_timer_disable(timer);

ports/nrf/mphalport.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
3939
uint64_t start_tick = ticks_ms;
4040
uint64_t duration = 0;
4141
while (duration < delay) {
42-
#ifdef MICROPY_VM_HOOK_LOOP
43-
MICROPY_VM_HOOK_LOOP
44-
#endif
42+
RUN_BACKGROUND_TASKS;
4543
// Check to see if we've been CTRL-Ced by autoreload or the user.
4644
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
4745
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {

ports/nrf/sd_mutex.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ void sd_mutex_acquire_check(nrf_mutex_t* p_mutex) {
3737

3838
void sd_mutex_acquire_wait(nrf_mutex_t* p_mutex) {
3939
while (sd_mutex_acquire(p_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) {
40-
#ifdef MICROPY_VM_HOOK_LOOP
41-
MICROPY_VM_HOOK_LOOP
42-
#endif
40+
RUN_BACKGROUND_TASKS;
4341
}
4442
}
4543

0 commit comments

Comments
 (0)