Skip to content

Commit db99e72

Browse files
authored
Merge pull request #2231 from geky/nsapi-lwip
Introduce the lwip-interface into the core mbed repo
2 parents 542fcca + ebf42f0 commit db99e72

File tree

139 files changed

+64027
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+64027
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* LWIP implementation of NetworkInterfaceAPI
2+
* Copyright (c) 2015 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 "EthernetInterface.h"
18+
#include "lwip_stack.h"
19+
20+
21+
/* Interface implementation */
22+
int EthernetInterface::connect()
23+
{
24+
return lwip_bringup();
25+
}
26+
27+
int EthernetInterface::disconnect()
28+
{
29+
lwip_bringdown();
30+
return 0;
31+
}
32+
33+
const char *EthernetInterface::get_ip_address()
34+
{
35+
return lwip_get_ip_address();
36+
}
37+
38+
const char *EthernetInterface::get_mac_address()
39+
{
40+
return lwip_get_mac_address();
41+
}
42+
43+
NetworkStack *EthernetInterface::get_stack()
44+
{
45+
return nsapi_create_stack(&lwip_stack);
46+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* LWIP implementation of NetworkInterfaceAPI
2+
* Copyright (c) 2015 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+
#ifndef ETHERNET_INTERFACE_H
18+
#define ETHERNET_INTERFACE_H
19+
20+
#include "nsapi.h"
21+
#include "rtos.h"
22+
#include "lwip/netif.h"
23+
24+
// Forward declaration
25+
class NetworkStack;
26+
27+
28+
/** EthernetInterface class
29+
* Implementation of the NetworkStack for LWIP
30+
*/
31+
class EthernetInterface : public EthInterface
32+
{
33+
public:
34+
/** Start the interface
35+
* @return 0 on success, negative on failure
36+
*/
37+
virtual int connect();
38+
39+
/** Stop the interface
40+
* @return 0 on success, negative on failure
41+
*/
42+
virtual int disconnect();
43+
44+
/** Get the internally stored IP address
45+
* @return IP address of the interface or null if not yet connected
46+
*/
47+
virtual const char *get_ip_address();
48+
49+
/** Get the internally stored MAC address
50+
* @return MAC address of the interface
51+
*/
52+
virtual const char *get_mac_address();
53+
54+
protected:
55+
/** Provide access to the underlying stack
56+
*
57+
* @return The underlying network stack
58+
*/
59+
virtual NetworkStack *get_stack();
60+
};
61+
62+
63+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* EthernetInterface.h */
2+
/* Copyright (C) 2012 mbed.org, MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
6+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
7+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in all copies or
11+
* substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
*/
19+
20+
// Architecture specific Ethernet interface
21+
// Must be implemented by each target
22+
23+
#ifndef ETHARCH_H_
24+
#define ETHARCH_H_
25+
26+
#include "lwip/netif.h"
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
void eth_arch_enable_interrupts(void);
33+
void eth_arch_disable_interrupts(void);
34+
err_t eth_arch_enetif_init(struct netif *netif);
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
#endif // #ifndef ETHARCHINTERFACE_H_
41+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* o Redistributions of source code must retain the above copyright notice, this list
9+
* of conditions and the following disclaimer.
10+
*
11+
* o Redistributions in binary form must reproduce the above copyright notice, this
12+
* list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16+
* contributors may be used to endorse or promote products derived from this
17+
* software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include "fsl_port.h"
32+
33+
/*******************************************************************************
34+
* Code
35+
******************************************************************************/
36+
void k64f_init_eth_hardware(void)
37+
{
38+
port_pin_config_t configENET = {0};
39+
40+
/* Disable MPU. */
41+
MPU->CESR &= ~MPU_CESR_VLD_MASK;
42+
43+
CLOCK_EnableClock(kCLOCK_PortC);
44+
CLOCK_EnableClock(kCLOCK_PortB);
45+
/* Affects PORTC_PCR16 register */
46+
PORT_SetPinMux(PORTC, 16u, kPORT_MuxAlt4);
47+
/* Affects PORTC_PCR17 register */
48+
PORT_SetPinMux(PORTC, 17u, kPORT_MuxAlt4);
49+
/* Affects PORTC_PCR18 register */
50+
PORT_SetPinMux(PORTC, 18u, kPORT_MuxAlt4);
51+
/* Affects PORTC_PCR19 register */
52+
PORT_SetPinMux(PORTC, 19u, kPORT_MuxAlt4);
53+
/* Affects PORTB_PCR1 register */
54+
PORT_SetPinMux(PORTB, 1u, kPORT_MuxAlt4);
55+
56+
configENET.openDrainEnable = kPORT_OpenDrainEnable;
57+
configENET.mux = kPORT_MuxAlt4;
58+
configENET.pullSelect = kPORT_PullUp;
59+
/* Ungate the port clock */
60+
CLOCK_EnableClock(kCLOCK_PortA);
61+
/* Affects PORTB_PCR0 register */
62+
PORT_SetPinConfig(PORTB, 0u, &configENET);
63+
64+
/* Affects PORTA_PCR13 register */
65+
PORT_SetPinMux(PORTA, 13u, kPORT_MuxAlt4);
66+
/* Affects PORTA_PCR12 register */
67+
PORT_SetPinMux(PORTA, 12u, kPORT_MuxAlt4);
68+
/* Affects PORTA_PCR14 register */
69+
PORT_SetPinMux(PORTA, 14u, kPORT_MuxAlt4);
70+
/* Affects PORTA_PCR5 register */
71+
PORT_SetPinMux(PORTA, 5u, kPORT_MuxAlt4);
72+
/* Affects PORTA_PCR16 register */
73+
PORT_SetPinMux(PORTA, 16u, kPORT_MuxAlt4);
74+
/* Affects PORTA_PCR17 register */
75+
PORT_SetPinMux(PORTA, 17u, kPORT_MuxAlt4);
76+
/* Affects PORTA_PCR15 register */
77+
PORT_SetPinMux(PORTA, 15u, kPORT_MuxAlt4);
78+
/* Affects PORTA_PCR28 register */
79+
PORT_SetPinMux(PORTA, 28u, kPORT_MuxAlt4);
80+
81+
/* Select the Ethernet timestamp clock source */
82+
CLOCK_SetEnetTime0Clock(0x2);
83+
}
84+
85+
/*******************************************************************************
86+
* EOF
87+
******************************************************************************/
88+
89+

0 commit comments

Comments
 (0)