Skip to content

Commit 3cb804d

Browse files
author
Daniel Campora
committed
cc3200: Remove NIC abstraction layer.
That layer is nice, but the CC3200 doesn't need it and getting rid of it saves ~200 bytes, which are more than welcome.
1 parent 9f8c545 commit 3cb804d

File tree

11 files changed

+94
-91
lines changed

11 files changed

+94
-91
lines changed

cc3200/fatfs/src/drivers/sflash_diskio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
#include "py/mpconfig.h"
66
#include MICROPY_HAL_H
7+
#include "py/obj.h"
78
#include "simplelink.h"
89
#include "diskio.h"
910
#include "sflash_diskio.h"
1011
#include "debug.h"
12+
#include "modnetwork.h"
1113
#include "modwlan.h"
1214

1315
#define SFLASH_TIMEOUT_MAX_MS 5500

cc3200/ftp/ftp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "pybrtc.h"
4040
#include "ftp.h"
4141
#include "simplelink.h"
42+
#include "modnetwork.h"
4243
#include "modwlan.h"
4344
#include "modusocket.h"
4445
#include "debug.h"

cc3200/ftp/updater.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
#include "py/mpconfig.h"
55
#include MICROPY_HAL_H
6+
#include "py/obj.h"
67
#include "simplelink.h"
78
#include "flc.h"
89
#include "updater.h"
910
#include "shamd5.h"
11+
#include "modnetwork.h"
1012
#include "modwlan.h"
1113
#include "debug.h"
1214

cc3200/mods/modnetwork.h

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,20 @@
2828
#ifndef MODNETWORK_H_
2929
#define MODNETWORK_H_
3030

31+
/******************************************************************************
32+
DEFINE CONSTANTS
33+
******************************************************************************/
3134
#define MOD_NETWORK_IPV4ADDR_BUF_SIZE (4)
3235

33-
// Forward declaration
34-
struct _mod_network_socket_obj_t;
35-
36+
/******************************************************************************
37+
DEFINE TYPES
38+
******************************************************************************/
3639
typedef struct _mod_network_nic_type_t {
3740
mp_obj_type_t base;
38-
39-
// API for non-socket operations
40-
int (*gethostbyname)(const char *name, mp_uint_t len, uint8_t *ip_out, uint8_t family);
41-
42-
// API for socket operations; return -1 on error
43-
int (*socket)(struct _mod_network_socket_obj_t *s, int *_errno);
44-
void (*close)(struct _mod_network_socket_obj_t *socket);
45-
int (*bind)(struct _mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno);
46-
int (*listen)(struct _mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno);
47-
int (*accept)(struct _mod_network_socket_obj_t *s, struct _mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno);
48-
int (*connect)(struct _mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno);
49-
int (*send)(struct _mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno);
50-
int (*recv)(struct _mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno);
51-
int (*sendto)(struct _mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno);
52-
int (*recvfrom)(struct _mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno);
53-
int (*setsockopt)(struct _mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno);
54-
int (*settimeout)(struct _mod_network_socket_obj_t *s, mp_uint_t timeout_ms, int *_errno);
55-
int (*ioctl)(struct _mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno);
5641
} mod_network_nic_type_t;
5742

5843
typedef struct _mod_network_socket_obj_t {
5944
mp_obj_base_t base;
60-
mod_network_nic_type_t *nic_type;
6145
union {
6246
struct {
6347
uint8_t domain;
@@ -70,8 +54,14 @@ typedef struct _mod_network_socket_obj_t {
7054
bool closed;
7155
} mod_network_socket_obj_t;
7256

57+
/******************************************************************************
58+
EXPORTED DATA
59+
******************************************************************************/
7360
extern const mod_network_nic_type_t mod_network_nic_type_wlan;
7461

62+
/******************************************************************************
63+
DECLARE FUNCTIONS
64+
******************************************************************************/
7565
void mod_network_init0(void);
7666

7767
#endif // MODNETWORK_H_

cc3200/mods/modpyb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "pybrtc.h"
4545
#include "mpsystick.h"
4646
#include "simplelink.h"
47+
#include "modnetwork.h"
4748
#include "modwlan.h"
4849
#include "moduos.h"
4950
#include "telnet.h"

cc3200/mods/modusocket.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/runtime.h"
3535
#include "netutils.h"
3636
#include "modnetwork.h"
37+
#include "modwlan.h"
3738
#include "modusocket.h"
3839
#include "mpexception.h"
3940

@@ -129,7 +130,6 @@ STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
129130
// create socket object
130131
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
131132
s->base.type = (mp_obj_t)&socket_type;
132-
s->nic_type = (mod_network_nic_type_t *)&mod_network_nic_type_wlan;
133133
s->u_param.domain = AF_INET;
134134
s->u_param.type = SOCK_STREAM;
135135
s->u_param.proto = IPPROTO_TCP;
@@ -149,7 +149,7 @@ STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
149149

150150
// create the socket
151151
int _errno;
152-
if (s->nic_type->socket(s, &_errno) != 0) {
152+
if (wlan_socket_socket(s, &_errno) != 0) {
153153
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
154154
}
155155

@@ -160,7 +160,7 @@ STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
160160
// method socket.close()
161161
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
162162
mod_network_socket_obj_t *self = self_in;
163-
self->nic_type->close(self);
163+
wlan_socket_close(self);
164164
return mp_const_none;
165165
}
166166
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
@@ -175,7 +175,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
175175

176176
// call the NIC to bind the socket
177177
int _errno;
178-
if (self->nic_type->bind(self, ip, port, &_errno) != 0) {
178+
if (wlan_socket_bind(self, ip, port, &_errno) != 0) {
179179
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
180180
}
181181
return mp_const_none;
@@ -187,7 +187,7 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
187187
mod_network_socket_obj_t *self = self_in;
188188

189189
int _errno;
190-
if (self->nic_type->listen(self, mp_obj_get_int(backlog), &_errno) != 0) {
190+
if (wlan_socket_listen(self, mp_obj_get_int(backlog), &_errno) != 0) {
191191
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
192192
}
193193
return mp_const_none;
@@ -199,22 +199,17 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
199199
mod_network_socket_obj_t *self = self_in;
200200

201201
// create new socket object
202-
// starts with empty nic so that the finaliser doesn't run close() method if accept() fails
203202
mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t);
204203
socket2->base.type = (mp_obj_t)&socket_type;
205-
socket2->nic_type = MP_OBJ_NULL;
206204

207205
// accept incoming connection
208206
uint8_t ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE];
209207
mp_uint_t port;
210208
int _errno;
211-
if (self->nic_type->accept(self, socket2, ip, &port, &_errno) != 0) {
209+
if (wlan_socket_accept(self, socket2, ip, &port, &_errno) != 0) {
212210
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
213211
}
214212

215-
// new socket has valid state, so set the nic to the same as parent
216-
socket2->nic_type = self->nic_type;
217-
218213
// add the socket to the list
219214
modusocket_socket_add(socket2->sd, true);
220215

@@ -236,7 +231,7 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
236231

237232
// call the NIC to connect the socket
238233
int _errno;
239-
if (self->nic_type->connect(self, ip, port, &_errno) != 0) {
234+
if (wlan_socket_connect(self, ip, port, &_errno) != 0) {
240235
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
241236
}
242237
return mp_const_none;
@@ -249,7 +244,7 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
249244
mp_buffer_info_t bufinfo;
250245
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
251246
int _errno;
252-
mp_uint_t ret = self->nic_type->send(self, bufinfo.buf, bufinfo.len, &_errno);
247+
mp_uint_t ret = wlan_socket_send(self, bufinfo.buf, bufinfo.len, &_errno);
253248
if (ret == -1) {
254249
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
255250
}
@@ -264,7 +259,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
264259
vstr_t vstr;
265260
vstr_init_len(&vstr, len);
266261
int _errno;
267-
mp_uint_t ret = self->nic_type->recv(self, (byte*)vstr.buf, len, &_errno);
262+
mp_uint_t ret = wlan_socket_recv(self, (byte*)vstr.buf, len, &_errno);
268263
if (ret == -1) {
269264
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
270265
}
@@ -291,7 +286,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
291286

292287
// call the nic to sendto
293288
int _errno;
294-
mp_int_t ret = self->nic_type->sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno);
289+
mp_int_t ret = wlan_socket_sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno);
295290
if (ret == -1) {
296291
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
297292
}
@@ -307,7 +302,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
307302
byte ip[4];
308303
mp_uint_t port;
309304
int _errno;
310-
mp_int_t ret = self->nic_type->recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno);
305+
mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno);
311306
if (ret == -1) {
312307
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
313308
}
@@ -346,7 +341,7 @@ STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
346341
}
347342

348343
int _errno;
349-
if (self->nic_type->setsockopt(self, level, opt, optval, optlen, &_errno) != 0) {
344+
if (wlan_socket_setsockopt(self, level, opt, optval, optlen, &_errno) != 0) {
350345
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
351346
}
352347
return mp_const_none;
@@ -366,7 +361,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
366361
timeout = 1000 * mp_obj_get_int(timeout_in);
367362
}
368363
int _errno;
369-
if (self->nic_type->settimeout(self, timeout, &_errno) != 0) {
364+
if (wlan_socket_settimeout(self, timeout, &_errno) != 0) {
370365
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
371366
}
372367
return mp_const_none;
@@ -403,7 +398,7 @@ STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
403398

404399
mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
405400
mod_network_socket_obj_t *self = self_in;
406-
return self->nic_type->ioctl(self, request, arg, errcode);
401+
return wlan_socket_ioctl(self, request, arg, errcode);
407402
}
408403

409404
STATIC const mp_stream_p_t socket_stream_p = {
@@ -431,7 +426,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
431426

432427
// ipv4 only
433428
uint8_t out_ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE];
434-
int32_t result = mod_network_nic_type_wlan.gethostbyname(host, hlen, out_ip, AF_INET);
429+
int32_t result = wlan_gethostbyname(host, hlen, out_ip, AF_INET);
435430
if (result != 0) {
436431
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(result)));
437432
}

0 commit comments

Comments
 (0)