|  | 
| 52 | 52 | 
 | 
| 53 | 53 | #include <string.h> | 
| 54 | 54 | 
 | 
|  | 55 | +#include "py/mpthread.h" | 
| 55 | 56 | #include "socket.h" | 
| 56 | 57 | 
 | 
| 57 |  | -extern void HAL_Delay(uint32_t); | 
| 58 |  | - | 
| 59 | 58 | #define SOCK_ANY_PORT_NUM  0xC000; | 
| 60 | 59 | 
 | 
| 61 | 60 | static uint16_t sock_any_port = SOCK_ANY_PORT_NUM; | 
| @@ -242,7 +241,7 @@ int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port) | 
| 242 | 241 |          #endif | 
| 243 | 242 |          return SOCKERR_TIMEOUT; | 
| 244 | 243 | 		} | 
| 245 |  | -        HAL_Delay(1); | 
|  | 244 | +        MICROPY_THREAD_YIELD(); | 
| 246 | 245 | 	} | 
| 247 | 246 |    #if _WIZCHIP_ == 5200   // for W5200 ARP errata  | 
| 248 | 247 |       setSUBR((uint8_t*)"\x00\x00\x00\x00"); | 
| @@ -317,6 +316,7 @@ int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len) | 
| 317 | 316 |       } | 
| 318 | 317 |       if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY; | 
| 319 | 318 |       if(len <= freesize) break; | 
|  | 319 | +      MICROPY_THREAD_YIELD(); | 
| 320 | 320 |    } | 
| 321 | 321 |    wiz_send_data(sn, buf, len); | 
| 322 | 322 |    #if _WIZCHIP_ == 5200 | 
| @@ -368,7 +368,7 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len) | 
| 368 | 368 |       } | 
| 369 | 369 |       if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY; | 
| 370 | 370 |       if(recvsize != 0) break; | 
| 371 |  | -      HAL_Delay(1); | 
|  | 371 | +      MICROPY_THREAD_YIELD(); | 
| 372 | 372 |    }; | 
| 373 | 373 |    if(recvsize < len) len = recvsize; | 
| 374 | 374 |    wiz_recv_data(sn, buf, len); | 
| @@ -416,7 +416,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t | 
| 416 | 416 |       if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED; | 
| 417 | 417 |       if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY; | 
| 418 | 418 |       if(len <= freesize) break; | 
| 419 |  | -      HAL_Delay(1); | 
|  | 419 | +      MICROPY_THREAD_YIELD(); | 
| 420 | 420 |    }; | 
| 421 | 421 | 	wiz_send_data(sn, buf, len); | 
| 422 | 422 | 
 | 
| @@ -446,7 +446,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t | 
| 446 | 446 |          return SOCKERR_TIMEOUT; | 
| 447 | 447 |       } | 
| 448 | 448 |       //////////// | 
| 449 |  | -      HAL_Delay(1); | 
|  | 449 | +      MICROPY_THREAD_YIELD(); | 
| 450 | 450 |    } | 
| 451 | 451 |    #if _WIZCHIP_ == 5200   // for W5200 ARP errata  | 
| 452 | 452 |       setSUBR((uint8_t*)"\x00\x00\x00\x00"); | 
| @@ -486,6 +486,7 @@ int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_ | 
| 486 | 486 |          if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED; | 
| 487 | 487 |          if( (sock_io_mode & (1<<sn)) && (pack_len == 0) ) return SOCK_BUSY; | 
| 488 | 488 |          if(pack_len != 0) break; | 
|  | 489 | +         MICROPY_THREAD_YIELD(); | 
| 489 | 490 |       }; | 
| 490 | 491 |    } | 
| 491 | 492 |    sock_pack_info[sn] = PACK_COMPLETED; | 
|  | 
0 commit comments