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: blinky_max32630fthr
features/FEATURE_LWIP/lwip-interface/emac_lwip.c@0:5c4d7b2438d3, 2016-11-11 (annotated)
- Committer:
- switches
- Date:
- Fri Nov 11 20:59:50 2016 +0000
- Revision:
- 0:5c4d7b2438d3
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| switches | 0:5c4d7b2438d3 | 1 | /* mbed Microcontroller Library |
| switches | 0:5c4d7b2438d3 | 2 | * Copyright (c) 2016 ARM Limited |
| switches | 0:5c4d7b2438d3 | 3 | * |
| switches | 0:5c4d7b2438d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| switches | 0:5c4d7b2438d3 | 5 | * you may not use this file except in compliance with the License. |
| switches | 0:5c4d7b2438d3 | 6 | * You may obtain a copy of the License at |
| switches | 0:5c4d7b2438d3 | 7 | * |
| switches | 0:5c4d7b2438d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| switches | 0:5c4d7b2438d3 | 9 | * |
| switches | 0:5c4d7b2438d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
| switches | 0:5c4d7b2438d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| switches | 0:5c4d7b2438d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| switches | 0:5c4d7b2438d3 | 13 | * See the License for the specific language governing permissions and |
| switches | 0:5c4d7b2438d3 | 14 | * limitations under the License. |
| switches | 0:5c4d7b2438d3 | 15 | */ |
| switches | 0:5c4d7b2438d3 | 16 | |
| switches | 0:5c4d7b2438d3 | 17 | #if DEVICE_EMAC |
| switches | 0:5c4d7b2438d3 | 18 | |
| switches | 0:5c4d7b2438d3 | 19 | #include "emac_api.h" |
| switches | 0:5c4d7b2438d3 | 20 | #include "emac_stack_mem.h" |
| switches | 0:5c4d7b2438d3 | 21 | #include "lwip/tcpip.h" |
| switches | 0:5c4d7b2438d3 | 22 | #include "lwip/tcp.h" |
| switches | 0:5c4d7b2438d3 | 23 | #include "lwip/ip.h" |
| switches | 0:5c4d7b2438d3 | 24 | #include "netif/etharp.h" |
| switches | 0:5c4d7b2438d3 | 25 | |
| switches | 0:5c4d7b2438d3 | 26 | static err_t emac_lwip_low_level_output(struct netif *netif, struct pbuf *p) |
| switches | 0:5c4d7b2438d3 | 27 | { |
| switches | 0:5c4d7b2438d3 | 28 | emac_interface_t *mac = (emac_interface_t *)netif->state; |
| switches | 0:5c4d7b2438d3 | 29 | bool ret = mac->ops.link_out(mac, (emac_stack_mem_t *)p); |
| switches | 0:5c4d7b2438d3 | 30 | |
| switches | 0:5c4d7b2438d3 | 31 | return ret ? ERR_OK : ERR_IF; |
| switches | 0:5c4d7b2438d3 | 32 | } |
| switches | 0:5c4d7b2438d3 | 33 | |
| switches | 0:5c4d7b2438d3 | 34 | static void emac_lwip_input(void *data, emac_stack_t *buf) |
| switches | 0:5c4d7b2438d3 | 35 | { |
| switches | 0:5c4d7b2438d3 | 36 | struct pbuf *p = (struct pbuf *)buf; |
| switches | 0:5c4d7b2438d3 | 37 | struct netif *netif = (struct netif *)data; |
| switches | 0:5c4d7b2438d3 | 38 | |
| switches | 0:5c4d7b2438d3 | 39 | /* pass all packets to ethernet_input, which decides what packets it supports */ |
| switches | 0:5c4d7b2438d3 | 40 | if (netif->input(p, netif) != ERR_OK) { |
| switches | 0:5c4d7b2438d3 | 41 | LWIP_DEBUGF(NETIF_DEBUG, ("Emac LWIP: IP input error\n")); |
| switches | 0:5c4d7b2438d3 | 42 | |
| switches | 0:5c4d7b2438d3 | 43 | pbuf_free(p); |
| switches | 0:5c4d7b2438d3 | 44 | } |
| switches | 0:5c4d7b2438d3 | 45 | } |
| switches | 0:5c4d7b2438d3 | 46 | |
| switches | 0:5c4d7b2438d3 | 47 | static void emac_lwip_state_change(void *data, bool up) |
| switches | 0:5c4d7b2438d3 | 48 | { |
| switches | 0:5c4d7b2438d3 | 49 | struct netif *netif = (struct netif *)data; |
| switches | 0:5c4d7b2438d3 | 50 | |
| switches | 0:5c4d7b2438d3 | 51 | if (up) { |
| switches | 0:5c4d7b2438d3 | 52 | tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, netif, 1); |
| switches | 0:5c4d7b2438d3 | 53 | } else { |
| switches | 0:5c4d7b2438d3 | 54 | tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, netif, 1); |
| switches | 0:5c4d7b2438d3 | 55 | } |
| switches | 0:5c4d7b2438d3 | 56 | } |
| switches | 0:5c4d7b2438d3 | 57 | |
| switches | 0:5c4d7b2438d3 | 58 | err_t emac_lwip_if_init(struct netif *netif) |
| switches | 0:5c4d7b2438d3 | 59 | { |
| switches | 0:5c4d7b2438d3 | 60 | int err = ERR_OK; |
| switches | 0:5c4d7b2438d3 | 61 | emac_interface_t *mac = (emac_interface_t *)netif->state; |
| switches | 0:5c4d7b2438d3 | 62 | |
| switches | 0:5c4d7b2438d3 | 63 | mac->ops.set_link_input_cb(mac, emac_lwip_input, netif); |
| switches | 0:5c4d7b2438d3 | 64 | mac->ops.set_link_state_cb(mac, emac_lwip_state_change, netif); |
| switches | 0:5c4d7b2438d3 | 65 | |
| switches | 0:5c4d7b2438d3 | 66 | netif->hwaddr_len = mac->ops.get_hwaddr_size(mac); |
| switches | 0:5c4d7b2438d3 | 67 | mac->ops.get_hwaddr(mac, netif->hwaddr); |
| switches | 0:5c4d7b2438d3 | 68 | |
| switches | 0:5c4d7b2438d3 | 69 | netif->mtu = mac->ops.get_mtu_size(mac); |
| switches | 0:5c4d7b2438d3 | 70 | |
| switches | 0:5c4d7b2438d3 | 71 | /* Interface capabilities */ |
| switches | 0:5c4d7b2438d3 | 72 | netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; |
| switches | 0:5c4d7b2438d3 | 73 | |
| switches | 0:5c4d7b2438d3 | 74 | mac->ops.get_ifname(mac, netif->name, 2); |
| switches | 0:5c4d7b2438d3 | 75 | |
| switches | 0:5c4d7b2438d3 | 76 | #if LWIP_IPV4 |
| switches | 0:5c4d7b2438d3 | 77 | netif->output = etharp_output; |
| switches | 0:5c4d7b2438d3 | 78 | #endif /* LWIP_IPV4 */ |
| switches | 0:5c4d7b2438d3 | 79 | |
| switches | 0:5c4d7b2438d3 | 80 | netif->linkoutput = emac_lwip_low_level_output; |
| switches | 0:5c4d7b2438d3 | 81 | |
| switches | 0:5c4d7b2438d3 | 82 | if (!mac->ops.power_up(mac)) { |
| switches | 0:5c4d7b2438d3 | 83 | err = ERR_IF; |
| switches | 0:5c4d7b2438d3 | 84 | } |
| switches | 0:5c4d7b2438d3 | 85 | |
| switches | 0:5c4d7b2438d3 | 86 | return err; |
| switches | 0:5c4d7b2438d3 | 87 | } |
| switches | 0:5c4d7b2438d3 | 88 | |
| switches | 0:5c4d7b2438d3 | 89 | #endif /* DEVICE_EMAC */ |
