Skip net_poll and timers unless their interrupt has fired
This commit is contained in:
@@ -15,6 +15,7 @@ inline bool operator<(const timer_entry& a, const timer_entry& b) {
|
|||||||
struct timer_queue {
|
struct timer_queue {
|
||||||
sorted_list<timer_entry, 16> queue;
|
sorted_list<timer_entry, 16> queue;
|
||||||
alarm_id_t alarm = -1;
|
alarm_id_t alarm = -1;
|
||||||
|
volatile bool irq_pending = false;
|
||||||
|
|
||||||
void schedule(absolute_time_t when, std::function<void()> fn) {
|
void schedule(absolute_time_t when, std::function<void()> fn) {
|
||||||
queue.insert({when, std::move(fn)});
|
queue.insert({when, std::move(fn)});
|
||||||
@@ -26,6 +27,8 @@ struct timer_queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
|
if (!irq_pending) return;
|
||||||
|
irq_pending = false;
|
||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
auto& front = queue.front();
|
auto& front = queue.front();
|
||||||
if (absolute_time_diff_us(get_absolute_time(), front.when) > 0) break;
|
if (absolute_time_diff_us(get_absolute_time(), front.when) > 0) break;
|
||||||
@@ -39,12 +42,15 @@ struct timer_queue {
|
|||||||
bool empty() const { return queue.empty(); }
|
bool empty() const { return queue.empty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int64_t alarm_cb(alarm_id_t, void*) { return 0; }
|
static int64_t alarm_cb(alarm_id_t, void* user_data) {
|
||||||
|
static_cast<timer_queue*>(user_data)->irq_pending = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void arm() {
|
void arm() {
|
||||||
if (alarm >= 0) cancel_alarm(alarm);
|
if (alarm >= 0) cancel_alarm(alarm);
|
||||||
alarm = -1;
|
alarm = -1;
|
||||||
if (!queue.empty())
|
if (!queue.empty())
|
||||||
alarm = add_alarm_at(queue.front().when, alarm_cb, nullptr, false);
|
alarm = add_alarm_at(queue.front().when, alarm_cb, this, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -293,6 +293,8 @@ void net_set_handler(net_handler handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void net_poll() {
|
void net_poll() {
|
||||||
|
if (!w6300::irq_pending) return;
|
||||||
|
w6300::irq_pending = false;
|
||||||
w6300::clear_interrupt(w6300::ik_int_all);
|
w6300::clear_interrupt(w6300::ik_int_all);
|
||||||
if (w6300::get_socket_recv_buf(raw_socket) == 0) return;
|
if (w6300::get_socket_recv_buf(raw_socket) == 0) return;
|
||||||
static uint8_t rx_buf[1518];
|
static uint8_t rx_buf[1518];
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void pio_init() {
|
|||||||
gpio_set_dir(PIN_INT, GPIO_IN);
|
gpio_set_dir(PIN_INT, GPIO_IN);
|
||||||
gpio_pull_up(PIN_INT);
|
gpio_pull_up(PIN_INT);
|
||||||
gpio_set_irq_enabled_with_callback(PIN_INT, GPIO_IRQ_EDGE_FALL, true,
|
gpio_set_irq_enabled_with_callback(PIN_INT, GPIO_IRQ_EDGE_FALL, true,
|
||||||
[](uint, uint32_t){});
|
[](uint, uint32_t){ irq_pending = true; });
|
||||||
|
|
||||||
pio_hw_t *pios[2] = {pio0, pio1};
|
pio_hw_t *pios[2] = {pio0, pio1};
|
||||||
uint pio_index = 1;
|
uint pio_index = 1;
|
||||||
@@ -490,6 +490,8 @@ std::expected<void, sock_error> close(socket_id sid) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
volatile bool irq_pending = false;
|
||||||
|
|
||||||
void clear_interrupt(intr_kind intr) {
|
void clear_interrupt(intr_kind intr) {
|
||||||
set_irclr((uint8_t)intr);
|
set_irclr((uint8_t)intr);
|
||||||
uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
|
uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ void reset();
|
|||||||
void init();
|
void init();
|
||||||
bool check();
|
bool check();
|
||||||
|
|
||||||
|
extern volatile bool irq_pending;
|
||||||
|
|
||||||
void clear_interrupt(intr_kind intr);
|
void clear_interrupt(intr_kind intr);
|
||||||
void set_interrupt_mask(intr_kind intr);
|
void set_interrupt_mask(intr_kind intr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user