Skip to content

Commit ae885ca

Browse files
author
Seppo Takalo
committed
Implement Ethernet interface for Nanostack.
* New Phy type: NanostackEthernetPhy * New tasklet: enet_tasklet. * New Interface: NanostackEthernetInterface, inherited from MeshInterfaceNanostack
1 parent 7732adb commit ae885ca

File tree

6 files changed

+450
-0
lines changed

6 files changed

+450
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* 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, WITHOUT
12+
* 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 NANOSTACKETHERNETINTERFACE_H
18+
#define NANOSTACKETHERNETINTERFACE_H
19+
20+
#include "MeshInterfaceNanostack.h"
21+
#include "NanostackEthernetPhy.h"
22+
23+
class NanostackEthernetInterface : public MeshInterfaceNanostack {
24+
public:
25+
26+
NanostackEthernetInterface() : MeshInterfaceNanostack() { }
27+
NanostackEthernetInterface(NanostackEthernetPhy *phy) : MeshInterfaceNanostack(phy) { }
28+
29+
nsapi_error_t initialize(NanostackEthernetPhy *phy);
30+
int connect();
31+
int disconnect();
32+
bool getOwnIpAddress(char *address, int8_t len);
33+
bool getRouterIpAddress(char *address, int8_t len);
34+
};
35+
36+
#endif // NANOSTACKETHERNETINTERFACE_H
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* 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, WITHOUT
12+
* 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+
#include "NanostackEthernetInterface.h"
17+
#include "mesh_system.h"
18+
#include "callback_handler.h"
19+
#include "enet_tasklet.h"
20+
21+
nsapi_error_t NanostackEthernetInterface::initialize(NanostackEthernetPhy *phy)
22+
{
23+
nsapi_error_t err = MeshInterfaceNanostack::initialize(phy);
24+
if (err != NSAPI_ERROR_OK)
25+
return err;
26+
27+
nanostack_lock();
28+
29+
if (register_phy() < 0) {
30+
nanostack_unlock();
31+
return NSAPI_ERROR_DEVICE_ERROR;
32+
}
33+
34+
enet_tasklet_init();
35+
__mesh_handler_set_callback(this);
36+
_network_interface_id = enet_tasklet_network_init(_device_id);
37+
38+
nanostack_unlock();
39+
40+
if (_network_interface_id < 0)
41+
return MESH_ERROR_UNKNOWN;
42+
else
43+
return MESH_ERROR_NONE;
44+
}
45+
46+
int NanostackEthernetInterface::connect()
47+
{
48+
nanostack_lock();
49+
int8_t status = enet_tasklet_connect(&__mesh_handler_c_callback, _network_interface_id);
50+
nanostack_unlock();
51+
52+
if (status == -1) {
53+
return MESH_ERROR_PARAM;
54+
} else if (status == -2) {
55+
return MESH_ERROR_MEMORY;
56+
} else if (status == -3) {
57+
return MESH_ERROR_STATE;
58+
} else if (status != 0) {
59+
return MESH_ERROR_UNKNOWN;
60+
}
61+
62+
int32_t count = connect_semaphore.wait(30000);
63+
64+
if (count <= 0) {
65+
return NSAPI_ERROR_DHCP_FAILURE; // sort of...
66+
}
67+
return 0;
68+
}
69+
70+
int NanostackEthernetInterface::disconnect()
71+
{
72+
enet_tasklet_disconnect();
73+
return 0;
74+
}
75+
76+
bool NanostackEthernetInterface::getOwnIpAddress(char *address, int8_t len)
77+
{
78+
return enet_tasklet_get_ip_address(address, len)?false:true;
79+
}
80+
81+
bool NanostackEthernetInterface::getRouterIpAddress(char *address, int8_t len)
82+
{
83+
return false;
84+
}

0 commit comments

Comments
 (0)