add ability to get, clear txstall flag

This can be used to make sure a PIO has actually finished all data
it was schedule to receive via a 'once' background_write
This commit is contained in:
Jeff Epler 2022-05-06 14:42:24 -05:00
parent f776749ca3
commit 23c0fc8354
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
3 changed files with 48 additions and 0 deletions

View File

@ -708,6 +708,18 @@ STATIC mp_obj_t rp2pio_statemachine_obj_clear_rxfifo(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_clear_rxfifo_obj, rp2pio_statemachine_obj_clear_rxfifo);
//| def clear_txstall(self) -> None:
//| """Clears the txstall flag."""
//| ...
//|
STATIC mp_obj_t rp2pio_statemachine_obj_clear_txstall(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_rp2pio_statemachine_clear_txstall(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_clear_txstall_obj, rp2pio_statemachine_obj_clear_txstall);
//| frequency: int
//| """The actual state machine frequency. This may not match the frequency requested
//| due to internal limitations."""
@ -736,6 +748,26 @@ const mp_obj_property_t rp2pio_statemachine_frequency_obj = {
MP_ROM_NONE},
};
//| txstall: bool
//| """True when the state machine has stalled due to a full TX FIFO since the last
//| `clear_txstall` call."""
//|
STATIC mp_obj_t rp2pio_statemachine_obj_get_txstall(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(common_hal_rp2pio_statemachine_get_txstall(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_txstall_obj, rp2pio_statemachine_obj_get_txstall);
const mp_obj_property_t rp2pio_statemachine_txstall_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_txstall_obj,
MP_ROM_NONE,
MP_ROM_NONE},
};
//| rxstall: bool
//| """True when the state machine has stalled due to a full RX FIFO since the last
//| `clear_rxfifo` call."""
@ -782,6 +814,7 @@ STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_restart), MP_ROM_PTR(&rp2pio_statemachine_restart_obj) },
{ MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&rp2pio_statemachine_run_obj) },
{ MP_ROM_QSTR(MP_QSTR_clear_rxfifo), MP_ROM_PTR(&rp2pio_statemachine_clear_rxfifo_obj) },
{ MP_ROM_QSTR(MP_QSTR_clear_txstall), MP_ROM_PTR(&rp2pio_statemachine_clear_txstall_obj) },
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&rp2pio_statemachine_readinto_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&rp2pio_statemachine_write_obj) },
@ -793,6 +826,7 @@ STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&rp2pio_statemachine_frequency_obj) },
{ MP_ROM_QSTR(MP_QSTR_rxstall), MP_ROM_PTR(&rp2pio_statemachine_rxstall_obj) },
{ MP_ROM_QSTR(MP_QSTR_txstall), MP_ROM_PTR(&rp2pio_statemachine_txstall_obj) },
{ MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&rp2pio_statemachine_in_waiting_obj) },
};
STATIC MP_DEFINE_CONST_DICT(rp2pio_statemachine_locals_dict, rp2pio_statemachine_locals_dict_table);

View File

@ -81,6 +81,8 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel
bool common_hal_rp2pio_statemachine_get_rxstall(rp2pio_statemachine_obj_t *self);
void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self);
bool common_hal_rp2pio_statemachine_get_txstall(rp2pio_statemachine_obj_t *self);
void common_hal_rp2pio_statemachine_clear_txstall(rp2pio_statemachine_obj_t *self);
size_t common_hal_rp2pio_statemachine_get_in_waiting(rp2pio_statemachine_obj_t *self);
void common_hal_rp2pio_statemachine_set_interrupt_handler(rp2pio_statemachine_obj_t *self, void (*handler)(void *), void *arg, int mask);

View File

@ -848,6 +848,18 @@ void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self
self->pio->fdebug = stall_mask;
}
bool common_hal_rp2pio_statemachine_get_txstall(rp2pio_statemachine_obj_t *self) {
uint32_t stall_mask = 1 << (PIO_FDEBUG_TXSTALL_LSB + self->state_machine);
return (self->pio->fdebug & stall_mask) != 0;
}
void common_hal_rp2pio_statemachine_clear_txstall(rp2pio_statemachine_obj_t *self) {
uint8_t level = pio_sm_get_rx_fifo_level(self->pio, self->state_machine);
uint32_t stall_mask = 1 << (PIO_FDEBUG_TXSTALL_LSB + self->state_machine);
self->pio->fdebug = stall_mask;
}
size_t common_hal_rp2pio_statemachine_get_in_waiting(rp2pio_statemachine_obj_t *self) {
uint8_t level = pio_sm_get_rx_fifo_level(self->pio, self->state_machine);
return level;