Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LWIPBP3595Interface_STA
rza1_bp3595_emac.c
00001 #include "lwip/opt.h" 00002 #include "lwip/def.h" 00003 #include "lwip/mem.h" 00004 #include "lwip/pbuf.h" 00005 #include "lwip/sys.h" 00006 #include "lwip/stats.h" 00007 #include "lwip/snmp.h" 00008 #include "lwip/tcpip.h" 00009 #include "netif/etharp.h" 00010 #include "netif/ppp_oe.h" 00011 #include "mbed_interface.h" 00012 00013 #include <string.h> 00014 #include "rza1_bp3595_emac.h" 00015 #include "WlanBP3595.h" 00016 00017 /* Static variable */ 00018 static struct netif * volatile target_netif = NULL; 00019 static volatile int init_sts = 0; /* 0: not initialized, 1:initialized */ 00020 static int connect_sts = 0; /* 0: disconnected, 1:connected */ 00021 00022 /* Static function */ 00023 static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr); 00024 static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p); 00025 00026 /* This function is called from the receiving thread of WlanBP3595 library. */ 00027 void rza1_bp3595_input(void *buff, u16_t recv_size) { 00028 struct eth_hdr *ethhdr; 00029 struct pbuf *p; 00030 00031 if (recv_size != 0) { 00032 p = pbuf_alloc(PBUF_RAW, recv_size, PBUF_RAM); 00033 if (p != NULL) { 00034 /* Copy data */ 00035 memcpy(p->payload, buff, recv_size); 00036 /* Check Ethernet frame type */ 00037 ethhdr = p->payload; 00038 switch (htons(ethhdr->type)) { 00039 case ETHTYPE_IP: 00040 case ETHTYPE_ARP: 00041 #if PPPOE_SUPPORT 00042 case ETHTYPE_PPPOEDISC: 00043 case ETHTYPE_PPPOE: 00044 #endif /* PPPOE_SUPPORT */ 00045 /* full packet send to tcpip_thread to process */ 00046 if (target_netif->input(p, target_netif) != ERR_OK) { 00047 /* Free buffer */ 00048 pbuf_free(p); 00049 } 00050 break; 00051 default: 00052 /* Free buffer */ 00053 pbuf_free(p); 00054 break; 00055 } 00056 } 00057 } 00058 } 00059 00060 void rza1_bp3595_connected(void) { 00061 /* 0: not initialized, 1:initialized */ 00062 if (init_sts == 1) { 00063 /* 0: disconnected, 1:connected */ 00064 if (connect_sts == 0) { 00065 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*)target_netif, 1); 00066 connect_sts = 1; 00067 } 00068 } 00069 } 00070 00071 void rza1_bp3595_disconnected(void) { 00072 /* 0: not initialized, 1:initialized */ 00073 if (init_sts == 1) { 00074 /* 0: disconnected, 1:connected */ 00075 if (connect_sts == 1) { 00076 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*)target_netif, 1); 00077 connect_sts = 0; 00078 } 00079 } 00080 } 00081 00082 static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr) { 00083 if (netif->flags & NETIF_FLAG_LINK_UP) { 00084 return etharp_output(netif, q, ipaddr); 00085 } 00086 00087 return ERR_CONN; 00088 } 00089 00090 static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p) { 00091 err_t err = ERR_MEM; 00092 int ret; 00093 00094 ret = WlanBP3595_Output(p); 00095 if (ret == 0) { 00096 err = ERR_OK; 00097 } 00098 00099 return err; 00100 } 00101 00102 err_t wifi_arch_enetif_init(struct netif *netif) { 00103 grp_wld_byte_array tBAWidData; /* byte array wid data */ 00104 int ret; 00105 00106 /* Set MAC hardware address */ 00107 tBAWidData.pucData = (grp_u8 *)netif->hwaddr; 00108 tBAWidData.ulSize = 6; 00109 00110 ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_GET_MAC_ADDRESS, &tBAWidData); 00111 if (ret != 0) { 00112 /* error(return a default MAC hardware address) */ 00113 netif->hwaddr[0] = 0x00; 00114 netif->hwaddr[1] = 0x02; 00115 netif->hwaddr[2] = 0xF7; 00116 netif->hwaddr[3] = 0xF0; 00117 netif->hwaddr[4] = 0x00; 00118 netif->hwaddr[5] = 0x00; 00119 } 00120 00121 /* Set MAC hardware address length */ 00122 netif->hwaddr_len = ETHARP_HWADDR_LEN; 00123 00124 /* Set maximum transfer unit */ 00125 netif->mtu = 1500; 00126 00127 /* Set device capabilities */ 00128 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; 00129 00130 #if LWIP_NETIF_HOSTNAME 00131 /* Initialize interface hostname */ 00132 netif->hostname = "lwiprza1"; 00133 #endif /* LWIP_NETIF_HOSTNAME */ 00134 00135 netif->name[0] = 'e'; 00136 netif->name[1] = 'n'; 00137 00138 netif->output = rza1_bp3595_etharp_output; 00139 netif->linkoutput = rza1_bp3595_low_level_output; 00140 00141 target_netif = netif; 00142 00143 init_sts = 1; /* 0: not initialized, 1:initialized */ 00144 00145 return ERR_OK; 00146 } 00147 00148 void wifi_arch_enable_interrupts(void) { 00149 WlanBP3595_RecvEnable(); 00150 } 00151 00152 void wifi_arch_disable_interrupts(void) { 00153 WlanBP3595_RecvDisable(); 00154 } 00155
Generated on Thu Jul 14 2022 17:52:49 by
1.7.2