Skip to content

Commit 23c0fc8

Browse files
committed
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
1 parent f776749 commit 23c0fc8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,18 @@ STATIC mp_obj_t rp2pio_statemachine_obj_clear_rxfifo(mp_obj_t self_in) {
708708
}
709709
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_clear_rxfifo_obj, rp2pio_statemachine_obj_clear_rxfifo);
710710

711+
//| def clear_txstall(self) -> None:
712+
//| """Clears the txstall flag."""
713+
//| ...
714+
//|
715+
STATIC mp_obj_t rp2pio_statemachine_obj_clear_txstall(mp_obj_t self_in) {
716+
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
717+
common_hal_rp2pio_statemachine_clear_txstall(self);
718+
return mp_const_none;
719+
}
720+
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_clear_txstall_obj, rp2pio_statemachine_obj_clear_txstall);
721+
722+
711723
//| frequency: int
712724
//| """The actual state machine frequency. This may not match the frequency requested
713725
//| due to internal limitations."""
@@ -736,6 +748,26 @@ const mp_obj_property_t rp2pio_statemachine_frequency_obj = {
736748
MP_ROM_NONE},
737749
};
738750

751+
//| txstall: bool
752+
//| """True when the state machine has stalled due to a full TX FIFO since the last
753+
//| `clear_txstall` call."""
754+
//|
755+
756+
STATIC mp_obj_t rp2pio_statemachine_obj_get_txstall(mp_obj_t self_in) {
757+
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
758+
check_for_deinit(self);
759+
return MP_OBJ_NEW_SMALL_INT(common_hal_rp2pio_statemachine_get_txstall(self));
760+
}
761+
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_txstall_obj, rp2pio_statemachine_obj_get_txstall);
762+
763+
const mp_obj_property_t rp2pio_statemachine_txstall_obj = {
764+
.base.type = &mp_type_property,
765+
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_txstall_obj,
766+
MP_ROM_NONE,
767+
MP_ROM_NONE},
768+
};
769+
770+
739771
//| rxstall: bool
740772
//| """True when the state machine has stalled due to a full RX FIFO since the last
741773
//| `clear_rxfifo` call."""
@@ -782,6 +814,7 @@ STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
782814
{ MP_ROM_QSTR(MP_QSTR_restart), MP_ROM_PTR(&rp2pio_statemachine_restart_obj) },
783815
{ MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&rp2pio_statemachine_run_obj) },
784816
{ MP_ROM_QSTR(MP_QSTR_clear_rxfifo), MP_ROM_PTR(&rp2pio_statemachine_clear_rxfifo_obj) },
817+
{ MP_ROM_QSTR(MP_QSTR_clear_txstall), MP_ROM_PTR(&rp2pio_statemachine_clear_txstall_obj) },
785818

786819
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&rp2pio_statemachine_readinto_obj) },
787820
{ 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[] = {
793826

794827
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&rp2pio_statemachine_frequency_obj) },
795828
{ MP_ROM_QSTR(MP_QSTR_rxstall), MP_ROM_PTR(&rp2pio_statemachine_rxstall_obj) },
829+
{ MP_ROM_QSTR(MP_QSTR_txstall), MP_ROM_PTR(&rp2pio_statemachine_txstall_obj) },
796830
{ MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&rp2pio_statemachine_in_waiting_obj) },
797831
};
798832
STATIC MP_DEFINE_CONST_DICT(rp2pio_statemachine_locals_dict, rp2pio_statemachine_locals_dict_table);

ports/raspberrypi/bindings/rp2pio/StateMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel
8181

8282
bool common_hal_rp2pio_statemachine_get_rxstall(rp2pio_statemachine_obj_t *self);
8383
void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self);
84+
bool common_hal_rp2pio_statemachine_get_txstall(rp2pio_statemachine_obj_t *self);
85+
void common_hal_rp2pio_statemachine_clear_txstall(rp2pio_statemachine_obj_t *self);
8486
size_t common_hal_rp2pio_statemachine_get_in_waiting(rp2pio_statemachine_obj_t *self);
8587

8688
void common_hal_rp2pio_statemachine_set_interrupt_handler(rp2pio_statemachine_obj_t *self, void (*handler)(void *), void *arg, int mask);

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,18 @@ void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self
848848
self->pio->fdebug = stall_mask;
849849
}
850850

851+
bool common_hal_rp2pio_statemachine_get_txstall(rp2pio_statemachine_obj_t *self) {
852+
uint32_t stall_mask = 1 << (PIO_FDEBUG_TXSTALL_LSB + self->state_machine);
853+
return (self->pio->fdebug & stall_mask) != 0;
854+
}
855+
856+
void common_hal_rp2pio_statemachine_clear_txstall(rp2pio_statemachine_obj_t *self) {
857+
uint8_t level = pio_sm_get_rx_fifo_level(self->pio, self->state_machine);
858+
uint32_t stall_mask = 1 << (PIO_FDEBUG_TXSTALL_LSB + self->state_machine);
859+
self->pio->fdebug = stall_mask;
860+
}
861+
862+
851863
size_t common_hal_rp2pio_statemachine_get_in_waiting(rp2pio_statemachine_obj_t *self) {
852864
uint8_t level = pio_sm_get_rx_fifo_level(self->pio, self->state_machine);
853865
return level;

0 commit comments

Comments
 (0)