Skip to content

Commit a15f336

Browse files
committed
add mechanism for timer ticks in NICs
1 parent 1f760bd commit a15f336

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ports/atmel-samd/background.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "usb_mass_storage.h"
3232

3333
#include "shared-module/displayio/__init__.h"
34+
#include "shared-module/network/__init__.h"
3435

3536
volatile uint64_t last_finished_tick = 0;
3637

@@ -41,6 +42,9 @@ void run_background_tasks(void) {
4142
#ifdef CIRCUITPY_DISPLAYIO
4243
displayio_refresh_display();
4344
#endif
45+
#ifdef MICROPY_PY_NETWORK
46+
network_module_background();
47+
#endif
4448
usb_msc_background();
4549
usb_cdc_background();
4650
last_finished_tick = ticks_ms;

shared-module/network/__init__.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <stdio.h>
28+
2729
#include "py/objlist.h"
2830
#include "py/runtime.h"
2931
#include "py/mphal.h"
3032
#include "py/mperrno.h"
3133

3234
#include "shared-bindings/random/__init__.h"
3335

36+
#include "shared-module/network/__init__.h"
37+
3438
// mod_network_nic_list needs to be declared in mpconfigport.h
3539

3640

@@ -41,6 +45,19 @@ void network_module_init(void) {
4145
void network_module_deinit(void) {
4246
}
4347

48+
void network_module_background(void) {
49+
static uint32_t next_tick = 0;
50+
uint32_t this_tick = ticks_ms;
51+
if (this_tick < next_tick) return;
52+
next_tick = this_tick + 1000;
53+
54+
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
55+
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
56+
mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
57+
if (nic_type->timer_tick != NULL) nic_type->timer_tick(nic);
58+
}
59+
}
60+
4461
void network_module_register_nic(mp_obj_t nic) {
4562
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
4663
if (MP_STATE_PORT(mod_network_nic_list).items[i] == nic) {

0 commit comments

Comments
 (0)