rp2/mpnetworkport: Refactor out cyw43_has_pending global variable.
A better indication of whether a cyw43 event is pending is the actual flag in the PendSV handler table. (If this fails, could also use the GPIO interrupt enabled register bit). This commit was needed of a previous version of the fix in the parent commit, but it turned out not strictly necessary for the current version. However, it's still a good clean up. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
6fa498cba1
commit
23fb171b80
@@ -140,10 +140,12 @@ uint cyw43_get_pin_wl(cyw43_pin_index_t pin_id);
|
||||
#endif
|
||||
|
||||
void cyw43_post_poll_hook(void);
|
||||
extern volatile int cyw43_has_pending;
|
||||
static inline bool cyw43_poll_is_pending(void) {
|
||||
return pendsv_is_pending(PENDSV_DISPATCH_CYW43);
|
||||
}
|
||||
|
||||
static inline void cyw43_yield(void) {
|
||||
if (!cyw43_has_pending) {
|
||||
if (!cyw43_poll_is_pending()) {
|
||||
best_effort_wfe_or_timeout(make_timeout_time_ms(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
uint32_t my_interrupts = MICROPY_BEGIN_ATOMIC_SECTION();
|
||||
#if MICROPY_PY_NETWORK_CYW43
|
||||
if (cyw43_has_pending && cyw43_poll != NULL) {
|
||||
if (cyw43_poll_is_pending()) {
|
||||
MICROPY_END_ATOMIC_SECTION(my_interrupts);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ static soft_timer_entry_t mp_network_soft_timer;
|
||||
#define CYW43_IRQ_LEVEL GPIO_IRQ_LEVEL_HIGH
|
||||
#define CYW43_SHARED_IRQ_HANDLER_PRIORITY PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY
|
||||
|
||||
volatile int cyw43_has_pending = 0;
|
||||
|
||||
// The Pico SDK only lets us set GPIO wake on the current running CPU, but the
|
||||
// hardware doesn't have this limit. We need to always enable/disable the pin
|
||||
@@ -89,9 +88,8 @@ static void gpio_irq_handler(void) {
|
||||
// cyw43_poll(). It is re-enabled in cyw43_post_poll_hook(), implemented
|
||||
// below.
|
||||
gpio_set_cpu0_host_wake_irq_enabled(false);
|
||||
cyw43_has_pending = 1;
|
||||
__sev();
|
||||
pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll);
|
||||
__sev();
|
||||
CYW43_STAT_INC(IRQ_COUNT);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +104,6 @@ void cyw43_irq_init(void) {
|
||||
|
||||
// This hook will run on whichever CPU serviced the PendSV interrupt
|
||||
void cyw43_post_poll_hook(void) {
|
||||
cyw43_has_pending = 0;
|
||||
gpio_set_cpu0_host_wake_irq_enabled(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,10 @@ static inline int pendsv_suspend_count(void) {
|
||||
|
||||
#endif
|
||||
|
||||
bool pendsv_is_pending(size_t slot) {
|
||||
return pendsv_dispatch_table[slot] != NULL;
|
||||
}
|
||||
|
||||
static inline void pendsv_resume_run_dispatch(void) {
|
||||
// Run pendsv if needed. Find an entry with a dispatch and call pendsv dispatch
|
||||
// with it. If pendsv runs it will service all slots.
|
||||
|
||||
@@ -51,5 +51,6 @@ void pendsv_init(void);
|
||||
void pendsv_suspend(void);
|
||||
void pendsv_resume(void);
|
||||
void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f);
|
||||
bool pendsv_is_pending(size_t slot);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RP2_PENDSV_H
|
||||
|
||||
Reference in New Issue
Block a user