nrf: Use RUN_BACKGROUND_TASKS
This commit is contained in:
parent
d9ee2d28a0
commit
11dd3a260e
@ -138,9 +138,7 @@ void ble_uart_init(void) {
|
|||||||
m_cccd_enabled = false;
|
m_cccd_enabled = false;
|
||||||
|
|
||||||
while (!m_cccd_enabled) {
|
while (!m_cccd_enabled) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +148,7 @@ bool ble_uart_connected(void) {
|
|||||||
|
|
||||||
char ble_uart_rx_chr(void) {
|
char ble_uart_rx_chr(void) {
|
||||||
while (isBufferEmpty(&m_rx_ring_buffer)) {
|
while (isBufferEmpty(&m_rx_ring_buffer)) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
|
@ -60,7 +60,7 @@ STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_han
|
|||||||
|
|
||||||
// Wait for a discovery event.
|
// Wait for a discovery event.
|
||||||
while (m_discovery_in_process) {
|
while (m_discovery_in_process) {
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
}
|
}
|
||||||
return m_discovery_successful;
|
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.
|
// Wait for a discovery event.
|
||||||
while (m_discovery_in_process) {
|
while (m_discovery_in_process) {
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
}
|
}
|
||||||
return m_discovery_successful;
|
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.
|
// Wait for a discovery event.
|
||||||
while (m_discovery_in_process) {
|
while (m_discovery_in_process) {
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
}
|
}
|
||||||
return m_discovery_successful;
|
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) {
|
while (self->waiting_to_connect) {
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
|
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
|
||||||
|
@ -125,7 +125,7 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp
|
|||||||
// TX buffer is full
|
// TX buffer is full
|
||||||
// We could wait for an event indicating the write is complete, but just retrying is easier.
|
// We could wait for an event indicating the write is complete, but just retrying is easier.
|
||||||
if (err_code == NRF_ERROR_RESOURCES) {
|
if (err_code == NRF_ERROR_RESOURCES) {
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (m_read_characteristic != NULL) {
|
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.
|
// 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) {
|
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.
|
// We could wait for an event indicating the write is complete, but just retrying is easier.
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
continue;
|
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.
|
// 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) {
|
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.
|
// We could wait for an event indicating the write is complete, but just retrying is easier.
|
||||||
MICROPY_VM_HOOK_LOOP;
|
RUN_BACKGROUND_TASKS;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_
|
|||||||
|
|
||||||
// Wait for all bytes received or timeout
|
// Wait for all bytes received or timeout
|
||||||
while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
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.
|
// Allow user to break out of a timeout with a KeyboardInterrupt.
|
||||||
if ( mp_hal_is_interrupted() ) {
|
if ( mp_hal_is_interrupted() ) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -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
|
// Wait for all bytes received or timeout
|
||||||
while ( (ringbuf_count(&self->rbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
while ( (ringbuf_count(&self->rbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP ;
|
|
||||||
// Allow user to break out of a timeout with a KeyboardInterrupt.
|
// Allow user to break out of a timeout with a KeyboardInterrupt.
|
||||||
if ( mp_hal_is_interrupted() ) {
|
if ( mp_hal_is_interrupted() ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent conflict with uart irq
|
// 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
|
// Wait for on-going transfer to complete
|
||||||
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time up
|
// Time up
|
||||||
@ -295,9 +291,7 @@ size_t common_hal_busio_uart_write (busio_uart_obj_t *self, const uint8_t *data,
|
|||||||
(*errcode) = 0;
|
(*errcode) = 0;
|
||||||
|
|
||||||
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
while ( nrfx_uarte_tx_in_progress(self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !nrfx_is_in_ram(data) ) {
|
if ( !nrfx_is_in_ram(data) ) {
|
||||||
|
@ -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.
|
// But we have to wait for the flag to be set.
|
||||||
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
|
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before leave we clear the flag for the event.
|
// Before leave we clear the flag for the event.
|
||||||
|
@ -155,9 +155,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu
|
|||||||
while(pulse_array_index < length) {
|
while(pulse_array_index < length) {
|
||||||
// Do other things while we wait. The interrupts will handle sending the
|
// Do other things while we wait. The interrupts will handle sending the
|
||||||
// signal.
|
// signal.
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nrfx_timer_disable(timer);
|
nrfx_timer_disable(timer);
|
||||||
|
@ -39,9 +39,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
|
|||||||
uint64_t start_tick = ticks_ms;
|
uint64_t start_tick = ticks_ms;
|
||||||
uint64_t duration = 0;
|
uint64_t duration = 0;
|
||||||
while (duration < delay) {
|
while (duration < delay) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
// Check to see if we've been CTRL-Ced by autoreload or the user.
|
// 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)) ||
|
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))) {
|
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
|
||||||
|
@ -37,9 +37,7 @@ void sd_mutex_acquire_check(nrf_mutex_t* p_mutex) {
|
|||||||
|
|
||||||
void sd_mutex_acquire_wait(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) {
|
while (sd_mutex_acquire(p_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
RUN_BACKGROUND_TASKS;
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user