Skip to content

Commit 683d7b7

Browse files
authored
Merge pull request #2874 from 0xc0170/feature_wifi_ublox
emac HAL API, WiFiInterface additions
2 parents 970c655 + 4f1eded commit 683d7b7

File tree

17 files changed

+779
-304
lines changed

17 files changed

+779
-304
lines changed

features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ int EthernetInterface::set_dhcp(bool dhcp)
4141

4242
int EthernetInterface::connect()
4343
{
44-
return lwip_bringup(_dhcp,
44+
return mbed_lwip_bringup(_dhcp,
4545
_ip_address[0] ? _ip_address : 0,
4646
_netmask[0] ? _netmask : 0,
4747
_gateway[0] ? _gateway : 0);
4848
}
4949

5050
int EthernetInterface::disconnect()
5151
{
52-
return lwip_bringdown();
52+
return mbed_lwip_bringdown();
5353
}
5454

5555
const char *EthernetInterface::get_mac_address()
5656
{
57-
return lwip_get_mac_address();
57+
return mbed_lwip_get_mac_address();
5858
}
5959

6060
const char *EthernetInterface::get_ip_address()
6161
{
62-
if (lwip_get_ip_address(_ip_address, sizeof _ip_address)) {
62+
if (mbed_lwip_get_ip_address(_ip_address, sizeof _ip_address)) {
6363
return _ip_address;
6464
}
6565

@@ -68,7 +68,7 @@ const char *EthernetInterface::get_ip_address()
6868

6969
const char *EthernetInterface::get_netmask()
7070
{
71-
if (lwip_get_netmask(_netmask, sizeof _netmask)) {
71+
if (mbed_lwip_get_netmask(_netmask, sizeof _netmask)) {
7272
return _netmask;
7373
}
7474

@@ -77,7 +77,7 @@ const char *EthernetInterface::get_netmask()
7777

7878
const char *EthernetInterface::get_gateway()
7979
{
80-
if (lwip_get_gateway(_gateway, sizeof _gateway)) {
80+
if (mbed_lwip_get_gateway(_gateway, sizeof _gateway)) {
8181
return _gateway;
8282
}
8383

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

features/FEATURE_LWIP/lwip-interface/eth_arch.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@
2929
extern "C" {
3030
#endif
3131

32+
#if DEVICE_EMAC
33+
err_t emac_lwip_if_init(struct netif *netif);
34+
35+
#else /* DEVICE_EMAC */
3236
void eth_arch_enable_interrupts(void);
3337
void eth_arch_disable_interrupts(void);
3438
err_t eth_arch_enetif_init(struct netif *netif);
39+
#endif
3540

3641
#ifdef __cplusplus
3742
}
3843
#endif
3944

4045
#endif // #ifndef ETHARCHINTERFACE_H_
41-

0 commit comments

Comments
 (0)