NXP LPC1768 Ethernet driver for lwip and CMSIS-RTOS

Dependents:   EthernetInterface EthernetInterface EthernetInterface_RSF EthernetInterface ... more

Legacy Networking Libraries

This is an mbed 2 networking library. For mbed 5, the networking libraries have been revised to better support additional network stacks and thread safety here.

This library is based on the code of the NXP LPC port of the Lightweight TCP/IP Stack

Copyright(C) 2011, NXP Semiconductor
All rights reserved.

Software that is described herein is for illustrative purposes only
which provides customers with programming information regarding the
products. This software is supplied "AS IS" without any warranties.
NXP Semiconductors assumes no responsibility or liability for the
use of the software, conveys no license or title under any patent,
copyright, or mask work right to the product. NXP Semiconductors
reserves the right to make changes in the software without
notification. NXP Semiconductors also make no representation or
warranty that such application will be suitable for the specified
use without further testing or modification.
Committer:
mbed_official
Date:
Thu May 26 09:00:26 2016 +0100
Revision:
33:9de8bd8ca1c8
Synchronized with git revision 745ebbf4557f0f3964f73063c1d88ddbcda0ed22

Full URL: https://github.com/mbedmicro/mbed/commit/745ebbf4557f0f3964f73063c1d88ddbcda0ed22/

Synch - fix lwip-eth path

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 33:9de8bd8ca1c8 1 #include "lwip/opt.h"
mbed_official 33:9de8bd8ca1c8 2 #include "lwip/tcpip.h"
mbed_official 33:9de8bd8ca1c8 3 #include "netif/etharp.h"
mbed_official 33:9de8bd8ca1c8 4 #include "mbed_interface.h"
mbed_official 33:9de8bd8ca1c8 5 #include "ethernet_api.h"
mbed_official 33:9de8bd8ca1c8 6 #include "ethernetext_api.h"
mbed_official 33:9de8bd8ca1c8 7
mbed_official 33:9de8bd8ca1c8 8 #define RECV_TASK_PRI (osPriorityNormal)
mbed_official 33:9de8bd8ca1c8 9 #define PHY_TASK_PRI (osPriorityNormal)
mbed_official 33:9de8bd8ca1c8 10 #define PHY_TASK_WAIT (200)
mbed_official 33:9de8bd8ca1c8 11
mbed_official 33:9de8bd8ca1c8 12 /* memory */
mbed_official 33:9de8bd8ca1c8 13 static sys_sem_t recv_ready_sem; /* receive ready semaphore */
mbed_official 33:9de8bd8ca1c8 14
mbed_official 33:9de8bd8ca1c8 15 /* function */
mbed_official 33:9de8bd8ca1c8 16 static void rza1_recv_task(void *arg);
mbed_official 33:9de8bd8ca1c8 17 static void rza1_phy_task(void *arg);
mbed_official 33:9de8bd8ca1c8 18 static err_t rza1_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
mbed_official 33:9de8bd8ca1c8 19 static err_t rza1_low_level_output(struct netif *netif, struct pbuf *p);
mbed_official 33:9de8bd8ca1c8 20 static void rza1_recv_callback(void);
mbed_official 33:9de8bd8ca1c8 21
mbed_official 33:9de8bd8ca1c8 22 static void rza1_recv_task(void *arg) {
mbed_official 33:9de8bd8ca1c8 23 struct netif *netif = (struct netif*)arg;
mbed_official 33:9de8bd8ca1c8 24 struct eth_hdr *ethhdr;
mbed_official 33:9de8bd8ca1c8 25 u16_t recv_size;
mbed_official 33:9de8bd8ca1c8 26 struct pbuf *p;
mbed_official 33:9de8bd8ca1c8 27 int cnt;
mbed_official 33:9de8bd8ca1c8 28
mbed_official 33:9de8bd8ca1c8 29 while (1) {
mbed_official 33:9de8bd8ca1c8 30 sys_arch_sem_wait(&recv_ready_sem, 0);
mbed_official 33:9de8bd8ca1c8 31 for (cnt = 0; cnt < 16; cnt++) {
mbed_official 33:9de8bd8ca1c8 32 recv_size = ethernet_receive();
mbed_official 33:9de8bd8ca1c8 33 if (recv_size != 0) {
mbed_official 33:9de8bd8ca1c8 34 p = pbuf_alloc(PBUF_RAW, recv_size, PBUF_RAM);
mbed_official 33:9de8bd8ca1c8 35 if (p != NULL) {
mbed_official 33:9de8bd8ca1c8 36 (void)ethernet_read((char *)p->payload, p->len);
mbed_official 33:9de8bd8ca1c8 37 ethhdr = p->payload;
mbed_official 33:9de8bd8ca1c8 38 switch (htons(ethhdr->type)) {
mbed_official 33:9de8bd8ca1c8 39 case ETHTYPE_IP:
mbed_official 33:9de8bd8ca1c8 40 case ETHTYPE_ARP:
mbed_official 33:9de8bd8ca1c8 41 #if PPPOE_SUPPORT
mbed_official 33:9de8bd8ca1c8 42 case ETHTYPE_PPPOEDISC:
mbed_official 33:9de8bd8ca1c8 43 case ETHTYPE_PPPOE:
mbed_official 33:9de8bd8ca1c8 44 #endif /* PPPOE_SUPPORT */
mbed_official 33:9de8bd8ca1c8 45 /* full packet send to tcpip_thread to process */
mbed_official 33:9de8bd8ca1c8 46 if (netif->input(p, netif) != ERR_OK) {
mbed_official 33:9de8bd8ca1c8 47 /* Free buffer */
mbed_official 33:9de8bd8ca1c8 48 pbuf_free(p);
mbed_official 33:9de8bd8ca1c8 49 }
mbed_official 33:9de8bd8ca1c8 50 break;
mbed_official 33:9de8bd8ca1c8 51 default:
mbed_official 33:9de8bd8ca1c8 52 /* Return buffer */
mbed_official 33:9de8bd8ca1c8 53 pbuf_free(p);
mbed_official 33:9de8bd8ca1c8 54 break;
mbed_official 33:9de8bd8ca1c8 55 }
mbed_official 33:9de8bd8ca1c8 56 }
mbed_official 33:9de8bd8ca1c8 57 } else {
mbed_official 33:9de8bd8ca1c8 58 break;
mbed_official 33:9de8bd8ca1c8 59 }
mbed_official 33:9de8bd8ca1c8 60 }
mbed_official 33:9de8bd8ca1c8 61 }
mbed_official 33:9de8bd8ca1c8 62 }
mbed_official 33:9de8bd8ca1c8 63
mbed_official 33:9de8bd8ca1c8 64 static void rza1_phy_task(void *arg) {
mbed_official 33:9de8bd8ca1c8 65 struct netif *netif = (struct netif*)arg;
mbed_official 33:9de8bd8ca1c8 66 s32_t connect_sts = 0; /* 0: disconnect, 1:connect */
mbed_official 33:9de8bd8ca1c8 67 s32_t link_sts;
mbed_official 33:9de8bd8ca1c8 68 s32_t link_mode_new = NEGO_FAIL;
mbed_official 33:9de8bd8ca1c8 69 s32_t link_mode_old = NEGO_FAIL;
mbed_official 33:9de8bd8ca1c8 70
mbed_official 33:9de8bd8ca1c8 71 while (1) {
mbed_official 33:9de8bd8ca1c8 72 link_sts = ethernet_link();
mbed_official 33:9de8bd8ca1c8 73 if (link_sts == 1) {
mbed_official 33:9de8bd8ca1c8 74 link_mode_new = ethernetext_chk_link_mode();
mbed_official 33:9de8bd8ca1c8 75 if (link_mode_new != link_mode_old) {
mbed_official 33:9de8bd8ca1c8 76 if (connect_sts == 1) {
mbed_official 33:9de8bd8ca1c8 77 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
mbed_official 33:9de8bd8ca1c8 78 }
mbed_official 33:9de8bd8ca1c8 79 if (link_mode_new != NEGO_FAIL) {
mbed_official 33:9de8bd8ca1c8 80 ethernetext_set_link_mode(link_mode_new);
mbed_official 33:9de8bd8ca1c8 81 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
mbed_official 33:9de8bd8ca1c8 82 connect_sts = 1;
mbed_official 33:9de8bd8ca1c8 83 }
mbed_official 33:9de8bd8ca1c8 84 }
mbed_official 33:9de8bd8ca1c8 85 } else {
mbed_official 33:9de8bd8ca1c8 86 if (connect_sts != 0) {
mbed_official 33:9de8bd8ca1c8 87 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
mbed_official 33:9de8bd8ca1c8 88 link_mode_new = NEGO_FAIL;
mbed_official 33:9de8bd8ca1c8 89 connect_sts = 0;
mbed_official 33:9de8bd8ca1c8 90 }
mbed_official 33:9de8bd8ca1c8 91 }
mbed_official 33:9de8bd8ca1c8 92 link_mode_old = link_mode_new;
mbed_official 33:9de8bd8ca1c8 93 osDelay(PHY_TASK_WAIT);
mbed_official 33:9de8bd8ca1c8 94 }
mbed_official 33:9de8bd8ca1c8 95 }
mbed_official 33:9de8bd8ca1c8 96
mbed_official 33:9de8bd8ca1c8 97 static err_t rza1_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr) {
mbed_official 33:9de8bd8ca1c8 98 /* Only send packet is link is up */
mbed_official 33:9de8bd8ca1c8 99 if (netif->flags & NETIF_FLAG_LINK_UP) {
mbed_official 33:9de8bd8ca1c8 100 return etharp_output(netif, q, ipaddr);
mbed_official 33:9de8bd8ca1c8 101 }
mbed_official 33:9de8bd8ca1c8 102
mbed_official 33:9de8bd8ca1c8 103 return ERR_CONN;
mbed_official 33:9de8bd8ca1c8 104 }
mbed_official 33:9de8bd8ca1c8 105
mbed_official 33:9de8bd8ca1c8 106 static err_t rza1_low_level_output(struct netif *netif, struct pbuf *p) {
mbed_official 33:9de8bd8ca1c8 107 struct pbuf *q;
mbed_official 33:9de8bd8ca1c8 108 s32_t cnt;
mbed_official 33:9de8bd8ca1c8 109 err_t err = ERR_MEM;
mbed_official 33:9de8bd8ca1c8 110 s32_t write_size = 0;
mbed_official 33:9de8bd8ca1c8 111
mbed_official 33:9de8bd8ca1c8 112 if ((p->payload != NULL) && (p->len != 0)) {
mbed_official 33:9de8bd8ca1c8 113 /* If the first data can't be written, transmit descriptor is full. */
mbed_official 33:9de8bd8ca1c8 114 for (cnt = 0; cnt < 100; cnt++) {
mbed_official 33:9de8bd8ca1c8 115 write_size = ethernet_write((char *)p->payload, p->len);
mbed_official 33:9de8bd8ca1c8 116 if (write_size != 0) {
mbed_official 33:9de8bd8ca1c8 117 break;
mbed_official 33:9de8bd8ca1c8 118 }
mbed_official 33:9de8bd8ca1c8 119 osDelay(1);
mbed_official 33:9de8bd8ca1c8 120 }
mbed_official 33:9de8bd8ca1c8 121 if (write_size != 0) {
mbed_official 33:9de8bd8ca1c8 122 for (q = p->next; q != NULL; q = q->next) {
mbed_official 33:9de8bd8ca1c8 123 (void)ethernet_write((char *)q->payload, q->len);
mbed_official 33:9de8bd8ca1c8 124 }
mbed_official 33:9de8bd8ca1c8 125 if (ethernet_send() == 1) {
mbed_official 33:9de8bd8ca1c8 126 err = ERR_OK;
mbed_official 33:9de8bd8ca1c8 127 }
mbed_official 33:9de8bd8ca1c8 128 }
mbed_official 33:9de8bd8ca1c8 129 }
mbed_official 33:9de8bd8ca1c8 130
mbed_official 33:9de8bd8ca1c8 131 return err;
mbed_official 33:9de8bd8ca1c8 132 }
mbed_official 33:9de8bd8ca1c8 133
mbed_official 33:9de8bd8ca1c8 134 static void rza1_recv_callback(void) {
mbed_official 33:9de8bd8ca1c8 135 sys_sem_signal(&recv_ready_sem);
mbed_official 33:9de8bd8ca1c8 136 }
mbed_official 33:9de8bd8ca1c8 137
mbed_official 33:9de8bd8ca1c8 138 err_t eth_arch_enetif_init(struct netif *netif)
mbed_official 33:9de8bd8ca1c8 139 {
mbed_official 33:9de8bd8ca1c8 140 ethernet_cfg_t ethcfg;
mbed_official 33:9de8bd8ca1c8 141
mbed_official 33:9de8bd8ca1c8 142 /* set MAC hardware address */
mbed_official 33:9de8bd8ca1c8 143 #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
mbed_official 33:9de8bd8ca1c8 144 netif->hwaddr[0] = MBED_MAC_ADDR_0;
mbed_official 33:9de8bd8ca1c8 145 netif->hwaddr[1] = MBED_MAC_ADDR_1;
mbed_official 33:9de8bd8ca1c8 146 netif->hwaddr[2] = MBED_MAC_ADDR_2;
mbed_official 33:9de8bd8ca1c8 147 netif->hwaddr[3] = MBED_MAC_ADDR_3;
mbed_official 33:9de8bd8ca1c8 148 netif->hwaddr[4] = MBED_MAC_ADDR_4;
mbed_official 33:9de8bd8ca1c8 149 netif->hwaddr[5] = MBED_MAC_ADDR_5;
mbed_official 33:9de8bd8ca1c8 150 #else
mbed_official 33:9de8bd8ca1c8 151 mbed_mac_address((char *)netif->hwaddr);
mbed_official 33:9de8bd8ca1c8 152 #endif
mbed_official 33:9de8bd8ca1c8 153 netif->hwaddr_len = ETHARP_HWADDR_LEN;
mbed_official 33:9de8bd8ca1c8 154
mbed_official 33:9de8bd8ca1c8 155 /* maximum transfer unit */
mbed_official 33:9de8bd8ca1c8 156 netif->mtu = 1500;
mbed_official 33:9de8bd8ca1c8 157
mbed_official 33:9de8bd8ca1c8 158 /* device capabilities */
mbed_official 33:9de8bd8ca1c8 159 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
mbed_official 33:9de8bd8ca1c8 160
mbed_official 33:9de8bd8ca1c8 161 #if LWIP_NETIF_HOSTNAME
mbed_official 33:9de8bd8ca1c8 162 /* Initialize interface hostname */
mbed_official 33:9de8bd8ca1c8 163 netif->hostname = "lwiprza1";
mbed_official 33:9de8bd8ca1c8 164 #endif /* LWIP_NETIF_HOSTNAME */
mbed_official 33:9de8bd8ca1c8 165
mbed_official 33:9de8bd8ca1c8 166 netif->name[0] = 'e';
mbed_official 33:9de8bd8ca1c8 167 netif->name[1] = 'n';
mbed_official 33:9de8bd8ca1c8 168
mbed_official 33:9de8bd8ca1c8 169 netif->output = rza1_etharp_output;
mbed_official 33:9de8bd8ca1c8 170 netif->linkoutput = rza1_low_level_output;
mbed_official 33:9de8bd8ca1c8 171
mbed_official 33:9de8bd8ca1c8 172 /* Initialize the hardware */
mbed_official 33:9de8bd8ca1c8 173 ethcfg.int_priority = 6;
mbed_official 33:9de8bd8ca1c8 174 ethcfg.recv_cb = &rza1_recv_callback;
mbed_official 33:9de8bd8ca1c8 175 ethcfg.ether_mac = (char *)netif->hwaddr;
mbed_official 33:9de8bd8ca1c8 176 ethernetext_init(&ethcfg);
mbed_official 33:9de8bd8ca1c8 177
mbed_official 33:9de8bd8ca1c8 178 /* semaphore */
mbed_official 33:9de8bd8ca1c8 179 sys_sem_new(&recv_ready_sem, 0);
mbed_official 33:9de8bd8ca1c8 180
mbed_official 33:9de8bd8ca1c8 181 /* task */
mbed_official 33:9de8bd8ca1c8 182 sys_thread_new("rza1_recv_task", rza1_recv_task, netif, DEFAULT_THREAD_STACKSIZE, RECV_TASK_PRI);
mbed_official 33:9de8bd8ca1c8 183 sys_thread_new("rza1_phy_task", rza1_phy_task, netif, DEFAULT_THREAD_STACKSIZE, PHY_TASK_PRI);
mbed_official 33:9de8bd8ca1c8 184
mbed_official 33:9de8bd8ca1c8 185 return ERR_OK;
mbed_official 33:9de8bd8ca1c8 186 }
mbed_official 33:9de8bd8ca1c8 187
mbed_official 33:9de8bd8ca1c8 188 void eth_arch_enable_interrupts(void) {
mbed_official 33:9de8bd8ca1c8 189 ethernetext_start_stop(1);
mbed_official 33:9de8bd8ca1c8 190 }
mbed_official 33:9de8bd8ca1c8 191
mbed_official 33:9de8bd8ca1c8 192 void eth_arch_disable_interrupts(void) {
mbed_official 33:9de8bd8ca1c8 193 ethernetext_start_stop(0);
mbed_official 33:9de8bd8ca1c8 194 }