123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #include "lwip.h"
- #include "lwip/init.h"
- #include "lwip/netif.h"
- #if defined ( __CC_ARM )
- #include "lwip/sio.h"
- #endif
- #include "ethernetif.h"
- #include <string.h>
- static void ethernet_link_status_updated(struct netif *netif);
- void Error_Handler(void);
- struct netif gnetif = {0};
- ip4_addr_t ipaddr;
- ip4_addr_t netmask;
- ip4_addr_t gw;
- #define INTERFACE_THREAD_STACK_SIZE ( 1024 )
- osThreadAttr_t attributes;
- static inline void tcpip_init_wrap(tcpip_init_done_fn tcpip_init_done, void *arg){
- tcpip_init(tcpip_init_done, arg);
- LOCK_TCPIP_CORE();
- }
- #define tcpip_init tcpip_init_wrap
- uint8_t is_link_up(void)
- {
- return netif_is_up(&gnetif);
- }
- void MX_LWIP_Init(void)
- {
-
-
- #if !defined(USE_DHCP)
-
- ipaddr_aton(STATIC_IP, &ipaddr);
- ipaddr_aton(STATIC_MASK, &netmask);
- ipaddr_aton(STATIC_GW, &gw);
- #else
- ip_addr_set_zero_ip4(&ipaddr);
- ip_addr_set_zero_ip4(&netmask);
- ip_addr_set_zero_ip4(&gw);
- #endif
-
-
- tcpip_init( NULL, NULL );
-
- netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
-
- netif_set_default(&gnetif);
- if (netif_is_link_up(&gnetif))
- {
-
- netif_set_up(&gnetif);
- }
- else
- {
-
- netif_set_down(&gnetif);
- }
-
- netif_set_link_callback(&gnetif, ethernet_link_status_updated);
-
- memset(&attributes, 0x0, sizeof(osThreadAttr_t));
- attributes.name = "EthLink";
- attributes.stack_size = INTERFACE_THREAD_STACK_SIZE * 2;
- attributes.priority = osPriorityBelowNormal;
- osThreadNew(ethernet_link_thread, &gnetif, &attributes);
-
- #if USE_DHCP
- netif_set_up(&gnetif);
- dhcp_start(&gnetif);
- #else
- netif_set_addr(&gnetif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw));
- #endif
-
- UNLOCK_TCPIP_CORE();
- }
- #ifdef USE_OBSOLETE_USER_CODE_SECTION_4
- #endif
- static void ethernet_link_status_updated(struct netif *netif)
- {
- if (netif_is_up(netif))
- {
- }
- else
- {
- }
- }
- #if defined ( __CC_ARM )
- sio_fd_t sio_open(u8_t devnum)
- {
- sio_fd_t sd;
- sd = 0;
- return sd;
- }
- void sio_send(u8_t c, sio_fd_t fd)
- {
- }
- u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
- {
- u32_t recved_bytes;
- recved_bytes = 0;
- return recved_bytes;
- }
- u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
- {
- u32_t recved_bytes;
- recved_bytes = 0;
- return recved_bytes;
- }
- #endif
|