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