diff options
| author | Nick Moore <nick@zoic.org> | 2018-10-16 23:09:25 +1100 |
|---|---|---|
| committer | Nick Moore <nick@zoic.org> | 2018-10-16 23:09:25 +1100 |
| commit | a15f3361aa0182cbefe0aec7376ff56bdcb74aa4 (patch) | |
| tree | 55b1b3a6902c6982d35f7c981edf1629f014ac29 | |
| parent | 1f760bded8d0623c8ef5f846c3fcb4c6f13f0ce0 (diff) | |
add mechanism for timer ticks in NICs
| -rw-r--r-- | ports/atmel-samd/background.c | 4 | ||||
| -rw-r--r-- | shared-module/network/__init__.c | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/ports/atmel-samd/background.c b/ports/atmel-samd/background.c index f25ec7200..385f0c284 100644 --- a/ports/atmel-samd/background.c +++ b/ports/atmel-samd/background.c @@ -31,6 +31,7 @@ #include "usb_mass_storage.h" #include "shared-module/displayio/__init__.h" +#include "shared-module/network/__init__.h" volatile uint64_t last_finished_tick = 0; @@ -41,6 +42,9 @@ void run_background_tasks(void) { #ifdef CIRCUITPY_DISPLAYIO displayio_refresh_display(); #endif + #ifdef MICROPY_PY_NETWORK + network_module_background(); + #endif usb_msc_background(); usb_cdc_background(); last_finished_tick = ticks_ms; diff --git a/shared-module/network/__init__.c b/shared-module/network/__init__.c index 6a955a0c4..a674e8478 100644 --- a/shared-module/network/__init__.c +++ b/shared-module/network/__init__.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#include <stdio.h> + #include "py/objlist.h" #include "py/runtime.h" #include "py/mphal.h" @@ -31,6 +33,8 @@ #include "shared-bindings/random/__init__.h" +#include "shared-module/network/__init__.h" + // mod_network_nic_list needs to be declared in mpconfigport.h @@ -41,6 +45,19 @@ void network_module_init(void) { void network_module_deinit(void) { } +void network_module_background(void) { + static uint32_t next_tick = 0; + uint32_t this_tick = ticks_ms; + if (this_tick < next_tick) return; + next_tick = this_tick + 1000; + + for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) { + mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i]; + mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic); + if (nic_type->timer_tick != NULL) nic_type->timer_tick(nic); + } +} + void network_module_register_nic(mp_obj_t nic) { for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) { if (MP_STATE_PORT(mod_network_nic_list).items[i] == nic) { |
