Skip to content

Commit 99d6ce3

Browse files
authored
Merge pull request ARMmbed#49 from linlingao/wifi_debug
Stubbed out some functions to get WIFI code to build with wifi example
2 parents 4d7e986 + d87246a commit 99d6ce3

File tree

14 files changed

+1378
-28
lines changed

14 files changed

+1378
-28
lines changed

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_LAUNCHXL.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include <ti/devices/cc32xx/driverlib/wdt.h>
6060

6161
#include "CC3220SF_LAUNCHXL.h"
62-
62+
const uint_least8_t SPI_count = CC3220SF_LAUNCHXL_SPICOUNT;
6363
/*
6464
* =============================== General ===============================
6565
*/

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_WiFiInterface.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#include "ti/drivers/net/wifi/wlan.h"
2424
#include "EMAC.h"
25-
//#include "wifi_constants.h"
26-
//#include "wifi_conf.h"
2725

2826
#include "OnboardNetworkStack.h"
2927
#include "EMACMemoryManager.h"
@@ -81,15 +79,15 @@ static cc3220_result_t scan_result_handler( cc3220_scan_handler_result_t* malloc
8179
return CC3220SF_SUCCESS;
8280
}
8381
#endif
84-
CC3220SFInterface::CC3220SFInterface(/*CC3220SF_EMAC &get_cc3220_emac, OnboardNetworkStack &get_cc3220_obn_stack*/) //:
85-
//cc3220_emac(get_cc3220_emac),
86-
//cc3220_obn_stack(get_cc3220_obn_stack),
87-
//cc3220_interface(NULL),
88-
//_dhcp(true),
89-
//_ip_address(),
90-
//_netmask(),
91-
//_gateway(),
92-
//_mac_address()
82+
CC3220SFInterface::CC3220SFInterface(CC3220_EMAC &get_cc3220_emac, OnboardNetworkStack &get_cc3220_obn_stack) :
83+
cc3220_emac(get_cc3220_emac),
84+
cc3220_obn_stack(get_cc3220_obn_stack),
85+
cc3220_interface(NULL),
86+
_dhcp(true),
87+
_ip_address(),
88+
_netmask(),
89+
_gateway(),
90+
_mac_address()
9391
{
9492
sl_Start(NULL, NULL, NULL);
9593
}
@@ -149,6 +147,7 @@ nsapi_error_t CC3220SFInterface::connect()
149147
{
150148
_i16 ret;
151149
SlWlanSecParams_t sec_params;
150+
memset((void*)&sec_params, 0, sizeof(sec_params));
152151

153152
if (!_ssid || (!_pass && _security != NSAPI_SECURITY_NONE)) {
154153
printf("Invalid credentials\r\n");
@@ -208,6 +207,7 @@ nsapi_error_t CC3220SFInterface::connect()
208207

209208
nsapi_error_t CC3220SFInterface::scan(WiFiAccessPoint *res, unsigned count)
210209
{
210+
211211
_i16 resultsCount = sl_WlanGetNetworkList( 0,10,&netEntries[0]);
212212
if (count == 0 || res == NULL)
213213
{
@@ -321,8 +321,7 @@ const char *CC3220SFInterface::get_gateway()
321321
return 0;
322322
}
323323

324-
//NetworkStack *CC3220SFInterface::get_stack()
325-
//{
326-
//return &cc3220_obn_stack;
327-
// return 0;
328-
//}
324+
NetworkStack *CC3220SFInterface::get_stack()
325+
{
326+
return &cc3220_obn_stack;
327+
}

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_WiFiInterface.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "nsapi.h"
2323
#include "rtos.h"
2424
#include "netif.h"
25-
//#include "cc3220_emac.h"
25+
#include "CC3220SF_emac.h"
2626
#include "OnboardNetworkStack.h"
2727
#include "LWIPStack.h"
2828

@@ -38,8 +38,8 @@ class CC3220SFInterface: public WiFiInterface
3838
/** CC3220SFWlanInterface lifetime
3939
*/
4040
CC3220SFInterface(
41-
/*CC3220SF_EMAC &cc3220_emac = CC3220SF_EMAC::get_instance(),
42-
OnboardNetworkStack &cc3220_lwip_stack = OnboardNetworkStack::get_default_instance()*/);
41+
CC3220_EMAC &cc3220_emac = CC3220_EMAC::get_instance(),
42+
OnboardNetworkStack &cc3220_lwip_stack = OnboardNetworkStack::get_default_instance());
4343

4444
~CC3220SFInterface();
4545

@@ -149,7 +149,7 @@ class CC3220SFInterface: public WiFiInterface
149149
*/
150150
virtual const char *get_gateway();
151151

152-
//CC3220SF_EMAC &get_emac() const { return cc3220_emac; }
152+
CC3220_EMAC &get_emac() const { return cc3220_emac; }
153153

154154
virtual CC3220SFInterface *cc3220Interface() { return this; }
155155

@@ -158,10 +158,10 @@ class CC3220SFInterface: public WiFiInterface
158158
*
159159
* @return The underlying network stack
160160
*/
161-
//virtual NetworkStack *get_stack();
162-
//CC3220_EMAC &cc3220sf_emac;
163-
//OnboardNetworkStack &cc3220_obn_stack;
164-
//OnboardNetworkStack::Interface *cc3220_interface;
161+
virtual NetworkStack *get_stack();
162+
CC3220_EMAC &cc3220_emac;
163+
OnboardNetworkStack &cc3220_obn_stack;
164+
OnboardNetworkStack::Interface *cc3220_interface;
165165
bool _dhcp;
166166
char _ssid[256];
167167
char _pass[256];
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2016 Realtek Semiconductor Corp.
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+
#if DEVICE_EMAC
18+
19+
#include <stdio.h>
20+
#include "mbed_assert.h"
21+
#include "mbed_events.h"
22+
23+
#include "CC3220SF_emac.h"
24+
#include "EMACMemoryManager.h"
25+
26+
#include "rtos.h"
27+
#include "lwip/pbuf.h"
28+
#include "netif/etharp.h"
29+
30+
//#include "lwip_intf.h"
31+
#include "ti/drivers/net/wifi/netcfg.h"
32+
33+
#define CC3220_EMAC_MTU_SIZE (1500U)
34+
35+
CC3220_EMAC::CC3220_EMAC()
36+
{
37+
//set_callback_func((emac_callback)(&CC3220_EMAC::wlan_emac_recv), this);
38+
}
39+
40+
uint32_t CC3220_EMAC::get_mtu_size() const
41+
{
42+
return CC3220_EMAC_MTU_SIZE;
43+
}
44+
45+
uint32_t CC3220_EMAC::get_align_preference() const
46+
{
47+
return true;
48+
}
49+
50+
void CC3220_EMAC::get_ifname(char *name, uint8_t size) const
51+
{
52+
MBED_ASSERT(name != NULL);
53+
strncpy(name, "r0", size);
54+
}
55+
56+
uint8_t CC3220_EMAC::get_hwaddr_size() const
57+
{
58+
return ETH_HWADDR_LEN;
59+
}
60+
61+
bool CC3220_EMAC::get_hwaddr(uint8_t *addr) const
62+
{
63+
_u8 macAddressVal[SL_MAC_ADDR_LEN];
64+
_u16 macAddressLen = SL_MAC_ADDR_LEN;
65+
_u16 ConfigOpt = 0;
66+
67+
if (0 == sl_NetCfgGet(SL_NETCFG_MAC_ADDRESS_GET,&ConfigOpt,&macAddressLen,(_u8 *)macAddressVal))
68+
{
69+
for (int i = 0; i < SL_MAC_ADDR_LEN; i++) {
70+
addr[i] = (unsigned char) macAddressVal[i];
71+
}
72+
return true;
73+
} else {
74+
printf("Get HW address failed\r\n");
75+
return false;
76+
}
77+
}
78+
79+
void CC3220_EMAC::set_hwaddr(const uint8_t *addr)
80+
{
81+
sl_NetCfgSet(SL_NETCFG_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(_u8 *)addr);
82+
sl_Stop(0);
83+
sl_Start(NULL,NULL,NULL);
84+
}
85+
86+
bool CC3220_EMAC::link_out(emac_mem_buf_t *buf)
87+
{
88+
#if 0
89+
struct eth_drv_sg *sg_list;
90+
int sg_len = 0;
91+
int tot_len;
92+
emac_mem_buf_t *p;
93+
bool ret = true;
94+
if (!rltk_wlan_running(0)) {
95+
memory_manager->free(buf);
96+
return false;
97+
}
98+
99+
sg_list = (struct eth_drv_sg *)malloc(sizeof(struct eth_drv_sg)*MAX_ETH_DRV_SG);
100+
if (sg_list == 0) {
101+
memory_manager->free(buf);
102+
return false;
103+
}
104+
105+
p = buf;
106+
tot_len = memory_manager->get_total_len(p);
107+
for (; p != NULL && sg_len < MAX_ETH_DRV_SG; p = memory_manager->get_next(p)) {
108+
sg_list[sg_len].buf = (unsigned int)(static_cast<uint8_t *>(memory_manager->get_ptr(p)));
109+
sg_list[sg_len].len = memory_manager->get_len(p);
110+
sg_len++;
111+
}
112+
if (sg_len) {
113+
if (rltk_wlan_send(0, sg_list, sg_len, tot_len) != 0) {
114+
ret = false;
115+
}
116+
}
117+
118+
memory_manager->free(buf);
119+
free(sg_list);
120+
return ret;
121+
#endif
122+
return true;
123+
}
124+
125+
bool CC3220_EMAC::power_up()
126+
{
127+
sl_Start(NULL,NULL,NULL);
128+
return true;
129+
}
130+
131+
void CC3220_EMAC::power_down()
132+
{
133+
sl_Stop(0);
134+
}
135+
136+
void CC3220_EMAC::set_link_input_cb(emac_link_input_cb_t input_cb)
137+
{
138+
emac_link_input_cb = input_cb;
139+
}
140+
141+
void CC3220_EMAC::set_link_state_cb(emac_link_state_change_cb_t state_cb)
142+
{
143+
emac_link_state_cb = state_cb;
144+
}
145+
146+
void CC3220_EMAC::add_multicast_group(const uint8_t *addr)
147+
{
148+
}
149+
150+
void CC3220_EMAC::remove_multicast_group(const uint8_t *addr)
151+
{
152+
}
153+
154+
void CC3220_EMAC::set_all_multicast(bool all)
155+
{
156+
}
157+
158+
void CC3220_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
159+
{
160+
memory_manager = &mem_mngr;
161+
}
162+
163+
void CC3220_EMAC::wlan_emac_recv(void *param, struct netif *netif, uint32_t len)
164+
{
165+
#if 0
166+
struct eth_drv_sg sg_list[MAX_ETH_DRV_SG] = {0};
167+
emac_mem_buf_t *buf;
168+
CC3220_EMAC *enet = static_cast<CC3220_EMAC *>(param);
169+
emac_mem_buf_t *p;
170+
int sg_len = 0;
171+
if (!rltk_wlan_running(0)) {
172+
return;
173+
}
174+
175+
if (len > MAX_ETH_MSG || len < 0) {
176+
len = MAX_ETH_MSG;
177+
}
178+
179+
buf = enet->memory_manager->alloc_heap(len, 0);
180+
if (buf == NULL) {
181+
return;
182+
}
183+
184+
enet->memory_manager->set_len(buf, len);
185+
p = buf;
186+
for (; p != NULL && sg_len < MAX_ETH_DRV_SG; p = enet->memory_manager->get_next(p)) {
187+
sg_list[sg_len].buf = (unsigned int)(static_cast<uint8_t *>(enet->memory_manager->get_ptr(p)));
188+
sg_list[sg_len].len = enet->memory_manager->get_len(p);
189+
sg_len++;
190+
}
191+
192+
rltk_wlan_recv(0, sg_list, sg_len);
193+
if (enet->emac_link_input_cb) {
194+
enet->emac_link_input_cb(buf);
195+
}
196+
#endif
197+
}
198+
199+
void mbed_default_mac_address(char *mac) {
200+
unsigned char RTK_mac_addr[3] = {0x00, 0xE0, 0x4C}; // default Realtek mac address
201+
mac[0] = RTK_mac_addr[0];
202+
mac[1] = RTK_mac_addr[1];
203+
mac[2] = RTK_mac_addr[2];
204+
mac[3] = 0x87;
205+
mac[4] = 0x00;
206+
mac[5] = 0x01;
207+
return;
208+
}
209+
210+
void mbed_mac_address(char *mac)
211+
{
212+
int i;
213+
_u8 macAddressVal[SL_MAC_ADDR_LEN];
214+
_u16 macAddressLen = SL_MAC_ADDR_LEN;
215+
_u16 ConfigOpt = 0;
216+
if (0 == sl_NetCfgGet(SL_NETCFG_MAC_ADDRESS_GET,&ConfigOpt,&macAddressLen,(_u8 *)macAddressVal))
217+
{
218+
for (i = 0; i < SL_MAC_ADDR_LEN; i++) {
219+
mac[i] = (unsigned char) macAddressVal[i];
220+
}
221+
} else {
222+
printf("Get HW address failed\r\n");
223+
mbed_default_mac_address(mac);
224+
}
225+
}
226+
227+
void CC3220_EMAC::wlan_emac_link_change(bool up)
228+
{
229+
if (emac_link_state_cb) {
230+
emac_link_state_cb(up);
231+
}
232+
}
233+
234+
CC3220_EMAC &CC3220_EMAC::get_instance() {
235+
static CC3220_EMAC cc3220_emac;
236+
return cc3220_emac;
237+
}
238+
// Weak so a module can override
239+
MBED_WEAK EMAC &EMAC::get_default_instance() {
240+
return CC3220_EMAC::get_instance();
241+
}
242+
#endif

0 commit comments

Comments
 (0)