add mechanism for timer ticks in NICs
This commit is contained in:
parent
1f760bded8
commit
a15f3361aa
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user