This is GR_PEACH_WlanBP3595 class library. The base library is EthernetInterface.
Dependents: GR-PEACH_WlanBP3595AP GR-PEACH_WlanBP3595STA
lwip-wifi/arch/rza1_bp3595_emac.c@0:41941ba775eb, 2016-05-24 (annotated)
- Committer:
- tousaki
- Date:
- Tue May 24 10:17:15 2016 +0000
- Revision:
- 0:41941ba775eb
Created 1st version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tousaki | 0:41941ba775eb | 1 | #include "lwip/opt.h" |
tousaki | 0:41941ba775eb | 2 | #include "lwip/def.h" |
tousaki | 0:41941ba775eb | 3 | #include "lwip/mem.h" |
tousaki | 0:41941ba775eb | 4 | #include "lwip/pbuf.h" |
tousaki | 0:41941ba775eb | 5 | #include "lwip/sys.h" |
tousaki | 0:41941ba775eb | 6 | #include "lwip/stats.h" |
tousaki | 0:41941ba775eb | 7 | #include "lwip/snmp.h" |
tousaki | 0:41941ba775eb | 8 | #include "lwip/tcpip.h" |
tousaki | 0:41941ba775eb | 9 | #include "netif/etharp.h" |
tousaki | 0:41941ba775eb | 10 | #include "netif/ppp_oe.h" |
tousaki | 0:41941ba775eb | 11 | #include "mbed_interface.h" |
tousaki | 0:41941ba775eb | 12 | |
tousaki | 0:41941ba775eb | 13 | #include <string.h> |
tousaki | 0:41941ba775eb | 14 | #include "rza1_bp3595_emac.h" |
tousaki | 0:41941ba775eb | 15 | #include "WlanBP3595.h" |
tousaki | 0:41941ba775eb | 16 | |
tousaki | 0:41941ba775eb | 17 | /* Static variable */ |
tousaki | 0:41941ba775eb | 18 | static struct netif * volatile target_netif = NULL; |
tousaki | 0:41941ba775eb | 19 | static volatile int init_sts = 0; /* 0: not initialized, 1:initialized */ |
tousaki | 0:41941ba775eb | 20 | static int connect_sts = 0; /* 0: disconnected, 1:connected */ |
tousaki | 0:41941ba775eb | 21 | |
tousaki | 0:41941ba775eb | 22 | /* Static function */ |
tousaki | 0:41941ba775eb | 23 | static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr); |
tousaki | 0:41941ba775eb | 24 | static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p); |
tousaki | 0:41941ba775eb | 25 | |
tousaki | 0:41941ba775eb | 26 | /* This function is called from the receiving thread of WlanBP3595 library. */ |
tousaki | 0:41941ba775eb | 27 | void rza1_bp3595_input(void *buff, u16_t recv_size) { |
tousaki | 0:41941ba775eb | 28 | struct eth_hdr *ethhdr; |
tousaki | 0:41941ba775eb | 29 | struct pbuf *p; |
tousaki | 0:41941ba775eb | 30 | |
tousaki | 0:41941ba775eb | 31 | if (recv_size != 0) { |
tousaki | 0:41941ba775eb | 32 | p = pbuf_alloc(PBUF_RAW, recv_size, PBUF_RAM); |
tousaki | 0:41941ba775eb | 33 | if (p != NULL) { |
tousaki | 0:41941ba775eb | 34 | /* Copy data */ |
tousaki | 0:41941ba775eb | 35 | memcpy(p->payload, buff, recv_size); |
tousaki | 0:41941ba775eb | 36 | /* Check Ethernet frame type */ |
tousaki | 0:41941ba775eb | 37 | ethhdr = p->payload; |
tousaki | 0:41941ba775eb | 38 | switch (htons(ethhdr->type)) { |
tousaki | 0:41941ba775eb | 39 | case ETHTYPE_IP: |
tousaki | 0:41941ba775eb | 40 | case ETHTYPE_ARP: |
tousaki | 0:41941ba775eb | 41 | #if PPPOE_SUPPORT |
tousaki | 0:41941ba775eb | 42 | case ETHTYPE_PPPOEDISC: |
tousaki | 0:41941ba775eb | 43 | case ETHTYPE_PPPOE: |
tousaki | 0:41941ba775eb | 44 | #endif /* PPPOE_SUPPORT */ |
tousaki | 0:41941ba775eb | 45 | /* full packet send to tcpip_thread to process */ |
tousaki | 0:41941ba775eb | 46 | if (target_netif->input(p, target_netif) != ERR_OK) { |
tousaki | 0:41941ba775eb | 47 | /* Free buffer */ |
tousaki | 0:41941ba775eb | 48 | pbuf_free(p); |
tousaki | 0:41941ba775eb | 49 | } |
tousaki | 0:41941ba775eb | 50 | break; |
tousaki | 0:41941ba775eb | 51 | default: |
tousaki | 0:41941ba775eb | 52 | /* Free buffer */ |
tousaki | 0:41941ba775eb | 53 | pbuf_free(p); |
tousaki | 0:41941ba775eb | 54 | break; |
tousaki | 0:41941ba775eb | 55 | } |
tousaki | 0:41941ba775eb | 56 | } |
tousaki | 0:41941ba775eb | 57 | } |
tousaki | 0:41941ba775eb | 58 | } |
tousaki | 0:41941ba775eb | 59 | |
tousaki | 0:41941ba775eb | 60 | void rza1_bp3595_connected(void) { |
tousaki | 0:41941ba775eb | 61 | /* 0: not initialized, 1:initialized */ |
tousaki | 0:41941ba775eb | 62 | if (init_sts == 1) { |
tousaki | 0:41941ba775eb | 63 | /* 0: disconnected, 1:connected */ |
tousaki | 0:41941ba775eb | 64 | if (connect_sts == 0) { |
tousaki | 0:41941ba775eb | 65 | tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*)target_netif, 1); |
tousaki | 0:41941ba775eb | 66 | connect_sts = 1; |
tousaki | 0:41941ba775eb | 67 | } |
tousaki | 0:41941ba775eb | 68 | } |
tousaki | 0:41941ba775eb | 69 | } |
tousaki | 0:41941ba775eb | 70 | |
tousaki | 0:41941ba775eb | 71 | void rza1_bp3595_disconnected(void) { |
tousaki | 0:41941ba775eb | 72 | /* 0: not initialized, 1:initialized */ |
tousaki | 0:41941ba775eb | 73 | if (init_sts == 1) { |
tousaki | 0:41941ba775eb | 74 | /* 0: disconnected, 1:connected */ |
tousaki | 0:41941ba775eb | 75 | if (connect_sts == 1) { |
tousaki | 0:41941ba775eb | 76 | tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*)target_netif, 1); |
tousaki | 0:41941ba775eb | 77 | connect_sts = 0; |
tousaki | 0:41941ba775eb | 78 | } |
tousaki | 0:41941ba775eb | 79 | } |
tousaki | 0:41941ba775eb | 80 | } |
tousaki | 0:41941ba775eb | 81 | |
tousaki | 0:41941ba775eb | 82 | static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr) { |
tousaki | 0:41941ba775eb | 83 | if (netif->flags & NETIF_FLAG_LINK_UP) { |
tousaki | 0:41941ba775eb | 84 | return etharp_output(netif, q, ipaddr); |
tousaki | 0:41941ba775eb | 85 | } |
tousaki | 0:41941ba775eb | 86 | |
tousaki | 0:41941ba775eb | 87 | return ERR_CONN; |
tousaki | 0:41941ba775eb | 88 | } |
tousaki | 0:41941ba775eb | 89 | |
tousaki | 0:41941ba775eb | 90 | static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p) { |
tousaki | 0:41941ba775eb | 91 | err_t err = ERR_MEM; |
tousaki | 0:41941ba775eb | 92 | int ret; |
tousaki | 0:41941ba775eb | 93 | |
tousaki | 0:41941ba775eb | 94 | ret = WlanBP3595_Output(p); |
tousaki | 0:41941ba775eb | 95 | if (ret == 0) { |
tousaki | 0:41941ba775eb | 96 | err = ERR_OK; |
tousaki | 0:41941ba775eb | 97 | } |
tousaki | 0:41941ba775eb | 98 | |
tousaki | 0:41941ba775eb | 99 | return err; |
tousaki | 0:41941ba775eb | 100 | } |
tousaki | 0:41941ba775eb | 101 | |
tousaki | 0:41941ba775eb | 102 | err_t wifi_arch_enetif_init(struct netif *netif) { |
tousaki | 0:41941ba775eb | 103 | grp_wld_byte_array tBAWidData; /* byte array wid data */ |
tousaki | 0:41941ba775eb | 104 | int ret; |
tousaki | 0:41941ba775eb | 105 | |
tousaki | 0:41941ba775eb | 106 | /* Set MAC hardware address */ |
tousaki | 0:41941ba775eb | 107 | tBAWidData.pucData = (grp_u8 *)netif->hwaddr; |
tousaki | 0:41941ba775eb | 108 | tBAWidData.ulSize = 6; |
tousaki | 0:41941ba775eb | 109 | |
tousaki | 0:41941ba775eb | 110 | ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_GET_MAC_ADDRESS, &tBAWidData); |
tousaki | 0:41941ba775eb | 111 | if (ret != 0) { |
tousaki | 0:41941ba775eb | 112 | /* error(return a default MAC hardware address) */ |
tousaki | 0:41941ba775eb | 113 | netif->hwaddr[0] = 0x00; |
tousaki | 0:41941ba775eb | 114 | netif->hwaddr[1] = 0x02; |
tousaki | 0:41941ba775eb | 115 | netif->hwaddr[2] = 0xF7; |
tousaki | 0:41941ba775eb | 116 | netif->hwaddr[3] = 0xF0; |
tousaki | 0:41941ba775eb | 117 | netif->hwaddr[4] = 0x00; |
tousaki | 0:41941ba775eb | 118 | netif->hwaddr[5] = 0x00; |
tousaki | 0:41941ba775eb | 119 | } |
tousaki | 0:41941ba775eb | 120 | |
tousaki | 0:41941ba775eb | 121 | /* Set MAC hardware address length */ |
tousaki | 0:41941ba775eb | 122 | netif->hwaddr_len = ETHARP_HWADDR_LEN; |
tousaki | 0:41941ba775eb | 123 | |
tousaki | 0:41941ba775eb | 124 | /* Set maximum transfer unit */ |
tousaki | 0:41941ba775eb | 125 | netif->mtu = 1500; |
tousaki | 0:41941ba775eb | 126 | |
tousaki | 0:41941ba775eb | 127 | /* Set device capabilities */ |
tousaki | 0:41941ba775eb | 128 | netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; |
tousaki | 0:41941ba775eb | 129 | |
tousaki | 0:41941ba775eb | 130 | #if LWIP_NETIF_HOSTNAME |
tousaki | 0:41941ba775eb | 131 | /* Initialize interface hostname */ |
tousaki | 0:41941ba775eb | 132 | netif->hostname = "lwiprza1"; |
tousaki | 0:41941ba775eb | 133 | #endif /* LWIP_NETIF_HOSTNAME */ |
tousaki | 0:41941ba775eb | 134 | |
tousaki | 0:41941ba775eb | 135 | netif->name[0] = 'e'; |
tousaki | 0:41941ba775eb | 136 | netif->name[1] = 'n'; |
tousaki | 0:41941ba775eb | 137 | |
tousaki | 0:41941ba775eb | 138 | netif->output = rza1_bp3595_etharp_output; |
tousaki | 0:41941ba775eb | 139 | netif->linkoutput = rza1_bp3595_low_level_output; |
tousaki | 0:41941ba775eb | 140 | |
tousaki | 0:41941ba775eb | 141 | target_netif = netif; |
tousaki | 0:41941ba775eb | 142 | |
tousaki | 0:41941ba775eb | 143 | init_sts = 1; /* 0: not initialized, 1:initialized */ |
tousaki | 0:41941ba775eb | 144 | |
tousaki | 0:41941ba775eb | 145 | return ERR_OK; |
tousaki | 0:41941ba775eb | 146 | } |
tousaki | 0:41941ba775eb | 147 | |
tousaki | 0:41941ba775eb | 148 | void wifi_arch_enable_interrupts(void) { |
tousaki | 0:41941ba775eb | 149 | WlanBP3595_RecvEnable(); |
tousaki | 0:41941ba775eb | 150 | } |
tousaki | 0:41941ba775eb | 151 | |
tousaki | 0:41941ba775eb | 152 | void wifi_arch_disable_interrupts(void) { |
tousaki | 0:41941ba775eb | 153 | WlanBP3595_RecvDisable(); |
tousaki | 0:41941ba775eb | 154 | } |
tousaki | 0:41941ba775eb | 155 |