summaryrefslogtreecommitdiff
path: root/shared-module/network
diff options
context:
space:
mode:
authorNick Moore <nick@zoic.org>2018-10-16 23:09:25 +1100
committerNick Moore <nick@zoic.org>2018-10-16 23:09:25 +1100
commita15f3361aa0182cbefe0aec7376ff56bdcb74aa4 (patch)
tree55b1b3a6902c6982d35f7c981edf1629f014ac29 /shared-module/network
parent1f760bded8d0623c8ef5f846c3fcb4c6f13f0ce0 (diff)
add mechanism for timer ticks in NICs
Diffstat (limited to 'shared-module/network')
-rw-r--r--shared-module/network/__init__.c17
1 files changed, 17 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) {