diff options
| author | Nick Moore <nick@zoic.org> | 2018-10-25 11:30:59 +1100 |
|---|---|---|
| committer | Nick Moore <nick@zoic.org> | 2018-10-25 11:30:59 +1100 |
| commit | 9c904358a9f80922880596d88942cf1aadac57da (patch) | |
| tree | dd0305059a9a2e86047a43341d73345757bb6755 /shared-module/network | |
| parent | 5bb12793a0c978fc731e29d0dee00cdf86b8234f (diff) | |
| parent | b714f5d650b53aff9fc5bc4efe1bf43eddfc7c24 (diff) | |
Merge branch 'circuitpython/nickzoic/703-wiznet-5500-native-dhcp' into circuitpython/nickzoic/703-wiznet-5500-native
Diffstat (limited to 'shared-module/network')
| -rw-r--r-- | shared-module/network/__init__.c | 17 | ||||
| -rw-r--r-- | shared-module/network/__init__.h | 2 |
2 files changed, 19 insertions, 0 deletions
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) { diff --git a/shared-module/network/__init__.h b/shared-module/network/__init__.h index ce5b4e6d3..00a3c3957 100644 --- a/shared-module/network/__init__.h +++ b/shared-module/network/__init__.h @@ -61,6 +61,7 @@ typedef struct _mod_network_nic_type_t { int (*setsockopt)(struct _mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno); int (*settimeout)(struct _mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno); int (*ioctl)(struct _mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno); + void (*timer_tick)(struct _mod_network_socket_obj_t *socket); } mod_network_nic_type_t; typedef struct _mod_network_socket_obj_t { @@ -82,6 +83,7 @@ extern const mod_network_nic_type_t mod_network_nic_type_cc3k; void network_module_init(void); void network_module_deinit(void); +void network_module_background(void); void network_module_register_nic(mp_obj_t nic); mp_obj_t network_module_find_nic(const uint8_t *ip); |
