@@ -317,23 +317,33 @@ int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, m
317
317
}
318
318
}
319
319
320
- static void wiznet5k_try_dhcp (void ) {
321
- DHCP_INIT_BUFFER_TYPE dhcp_buf [DHCP_INIT_BUFFER_SIZE ];
320
+ void wiznet5k_socket_timer_tick (mod_network_socket_obj_t * socket ) {
321
+ if (wiznet5k_obj .dhcp_active ) {
322
+ DHCP_time_handler ();
323
+ DHCP_run ();
324
+ }
325
+ }
322
326
323
- // Set up the socket to listen on UDP 68 before calling DHCP_init
324
- WIZCHIP_EXPORT (socket )(0 , MOD_NETWORK_SOCK_DGRAM , DHCP_CLIENT_PORT , 0 );
325
- DHCP_init (0 , dhcp_buf );
327
+ static void wiznet5k_start_dhcp (void ) {
328
+ static DHCP_INIT_BUFFER_TYPE dhcp_buf [DHCP_INIT_BUFFER_SIZE ];
326
329
327
- // try a few times for DHCP ... XXX this should be asynchronous.
328
- for (int i = 0 ; i < 10 ; i ++ ) {
329
- DHCP_time_handler ();
330
- int dhcp_state = DHCP_run ();
331
- if (dhcp_state == DHCP_IP_LEASED || dhcp_state == DHCP_IP_CHANGED ) break ;
332
- mp_hal_delay_ms (1000 );
330
+ if (!wiznet5k_obj .dhcp_active ) {
331
+ // Set up the socket to listen on UDP 68 before calling DHCP_init
332
+ WIZCHIP_EXPORT (socket )(0 , MOD_NETWORK_SOCK_DGRAM , DHCP_CLIENT_PORT , 0 );
333
+ DHCP_init (0 , dhcp_buf );
334
+ wiznet5k_obj .dhcp_active = 1 ;
335
+ }
336
+ }
337
+
338
+ #if 0
339
+ static void wiznet5k_stop_dhcp (void ) {
340
+ if (wiznet5k_obj .dhcp_active ) {
341
+ wiznet5k_obj .dhcp_active = 0 ;
342
+ DHCP_stop ();
343
+ WIZCHIP_EXPORT (close )(0 );
333
344
}
334
- DHCP_stop ();
335
- WIZCHIP_EXPORT (close )(0 );
336
345
}
346
+ #endif
337
347
338
348
/// Create and return a WIZNET5K object.
339
349
mp_obj_t wiznet5k_create (mp_obj_t spi_in , mp_obj_t cs_in , mp_obj_t rst_in ) {
@@ -382,7 +392,7 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) {
382
392
// seems we need a small delay after init
383
393
mp_hal_delay_ms (250 );
384
394
385
- wiznet5k_try_dhcp ();
395
+ wiznet5k_start_dhcp ();
386
396
387
397
// register with network module
388
398
network_module_register_nic (& wiznet5k_obj );
0 commit comments