Browse Source

cc3200: Use simplelink API instead of emulated BSD API.

Most of cc3200 uses explicit simplelink calls anyway, and this means there
are no longer any clashes with macros from the C stdlib.
pull/2399/merge
Damien George 8 years ago
parent
commit
d9f7120af1
  1. 14
      cc3200/ftp/ftp.c
  2. 26
      cc3200/mods/modusocket.c
  3. 38
      cc3200/mods/modwlan.c
  4. 2
      cc3200/simplelink/user.h
  5. 14
      cc3200/telnet/telnet.c

14
cc3200/ftp/ftp.c

@ -500,12 +500,12 @@ static void ftp_wait_for_enabled (void) {
static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) { static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
SlSockNonblocking_t nonBlockingOption; SlSockNonblocking_t nonBlockingOption;
sockaddr_in sServerAddress; SlSockAddrIn_t sServerAddress;
_i16 _sd; _i16 _sd;
_i16 result; _i16 result;
// Open a socket for ftp data listen // Open a socket for ftp data listen
ASSERT ((*sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) > 0); ASSERT ((*sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_IP)) > 0);
_sd = *sd; _sd = *sd;
if (_sd > 0) { if (_sd > 0) {
@ -514,12 +514,12 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
// Enable non-blocking mode // Enable non-blocking mode
nonBlockingOption.NonblockingEnabled = 1; nonBlockingOption.NonblockingEnabled = 1;
ASSERT ((result = sl_SetSockOpt(_sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); ASSERT ((result = sl_SetSockOpt(_sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
// Bind the socket to a port number // Bind the socket to a port number
sServerAddress.sin_family = AF_INET; sServerAddress.sin_family = SL_AF_INET;
sServerAddress.sin_addr.s_addr = INADDR_ANY; sServerAddress.sin_addr.s_addr = SL_INADDR_ANY;
sServerAddress.sin_port = htons(port); sServerAddress.sin_port = sl_Htons(port);
ASSERT ((result |= sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK); ASSERT ((result |= sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
@ -535,7 +535,7 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
} }
static ftp_result_t ftp_wait_for_connection (_i16 l_sd, _i16 *n_sd) { static ftp_result_t ftp_wait_for_connection (_i16 l_sd, _i16 *n_sd) {
sockaddr_in sClientAddress; SlSockAddrIn_t sClientAddress;
SlSocklen_t in_addrSize; SlSocklen_t in_addrSize;
// accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN // accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN

26
cc3200/mods/modusocket.c

@ -95,13 +95,13 @@ void modusocket_socket_delete (int16_t sd) {
} }
void modusocket_enter_sleep (void) { void modusocket_enter_sleep (void) {
fd_set socketset; SlFdSet_t socketset;
int16_t maxfd = 0; int16_t maxfd = 0;
for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) {
int16_t sd; int16_t sd;
if ((sd = modusocket_sockets[i].sd) >= 0) { if ((sd = modusocket_sockets[i].sd) >= 0) {
FD_SET(sd, &socketset); SL_FD_SET(sd, &socketset);
maxfd = (maxfd > sd) ? maxfd : sd; maxfd = (maxfd > sd) ? maxfd : sd;
} }
} }
@ -133,9 +133,9 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// create socket object // create socket object
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t); mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
s->base.type = (mp_obj_t)&socket_type; s->base.type = (mp_obj_t)&socket_type;
s->sock_base.u_param.domain = AF_INET; s->sock_base.u_param.domain = SL_AF_INET;
s->sock_base.u_param.type = SOCK_STREAM; s->sock_base.u_param.type = SL_SOCK_STREAM;
s->sock_base.u_param.proto = IPPROTO_TCP; s->sock_base.u_param.proto = SL_IPPROTO_TCP;
s->sock_base.u_param.fileno = -1; s->sock_base.u_param.fileno = -1;
s->sock_base.has_timeout = false; s->sock_base.has_timeout = false;
s->sock_base.cert_req = false; s->sock_base.cert_req = false;
@ -501,13 +501,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
// ipv4 only // ipv4 only
uint8_t out_ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE]; uint8_t out_ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE];
int32_t result = wlan_gethostbyname(host, hlen, out_ip, AF_INET); int32_t result = wlan_gethostbyname(host, hlen, out_ip, SL_AF_INET);
if (result < 0) { if (result < 0) {
mp_raise_OSError(-result); mp_raise_OSError(-result);
} }
mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL); mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL);
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(AF_INET); tuple->items[0] = MP_OBJ_NEW_SMALL_INT(SL_AF_INET);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SOCK_STREAM); tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0); tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_); tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE); tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE);
@ -525,14 +525,14 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError }, { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError },
// class constants // class constants
{ MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(AF_INET) }, { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SOCK_STREAM) }, { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SOCK_DGRAM) }, { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_DGRAM) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_SEC), MP_OBJ_NEW_SMALL_INT(SL_SEC_SOCKET) }, { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_SEC), MP_OBJ_NEW_SMALL_INT(SL_SEC_SOCKET) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(IPPROTO_TCP) }, { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_TCP) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(IPPROTO_UDP) }, { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_UDP) },
}; };
STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table); STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table);

38
cc3200/mods/modwlan.c

@ -122,8 +122,8 @@ typedef enum{
#define WLAN_MAX_RX_SIZE 16000 #define WLAN_MAX_RX_SIZE 16000
#define WLAN_MAX_TX_SIZE 1476 #define WLAN_MAX_TX_SIZE 1476
#define MAKE_SOCKADDR(addr, ip, port) sockaddr addr; \ #define MAKE_SOCKADDR(addr, ip, port) SlSockAddr_t addr; \
addr.sa_family = AF_INET; \ addr.sa_family = SL_AF_INET; \
addr.sa_data[0] = port >> 8; \ addr.sa_data[0] = port >> 8; \
addr.sa_data[1] = port; \ addr.sa_data[1] = port; \
addr.sa_data[2] = ip[3]; \ addr.sa_data[2] = ip[3]; \
@ -1364,8 +1364,8 @@ int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errn
int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) {
// accept incoming connection // accept incoming connection
int16_t sd; int16_t sd;
sockaddr addr; SlSockAddr_t addr;
socklen_t addr_len = sizeof(addr); SlSocklen_t addr_len = sizeof(addr);
sd = sl_Accept(s->sock_base.sd, &addr, &addr_len); sd = sl_Accept(s->sock_base.sd, &addr, &addr_len);
// save the socket descriptor // save the socket descriptor
@ -1413,7 +1413,7 @@ int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int
int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
MAKE_SOCKADDR(addr, ip, port) MAKE_SOCKADDR(addr, ip, port)
int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (sockaddr*)&addr, sizeof(addr)); int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (SlSockAddr_t*)&addr, sizeof(addr));
if (ret < 0) { if (ret < 0) {
*_errno = ret; *_errno = ret;
return -1; return -1;
@ -1422,8 +1422,8 @@ int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t
} }
int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
sockaddr addr; SlSockAddr_t addr;
socklen_t addr_len = sizeof(addr); SlSocklen_t addr_len = sizeof(addr);
mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len); mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len);
if (ret < 0) { if (ret < 0) {
*_errno = ret; *_errno = ret;
@ -1454,14 +1454,14 @@ int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int
// set blocking mode // set blocking mode
option.NonblockingEnabled = 0; option.NonblockingEnabled = 0;
} }
ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_NONBLOCKING, &option, sizeof(option)); ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &option, sizeof(option));
has_timeout = false; has_timeout = false;
} else { } else {
// set timeout // set timeout
struct SlTimeval_t timeVal; struct SlTimeval_t timeVal;
timeVal.tv_sec = timeout_s; // seconds timeVal.tv_sec = timeout_s; // seconds
timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution
ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_RCVTIMEO, &timeVal, sizeof(timeVal)); ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal));
has_timeout = true; has_timeout = true;
} }
@ -1482,20 +1482,20 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t
int32_t sd = s->sock_base.sd; int32_t sd = s->sock_base.sd;
// init fds // init fds
fd_set rfds, wfds, xfds; SlFdSet_t rfds, wfds, xfds;
FD_ZERO(&rfds); SL_FD_ZERO(&rfds);
FD_ZERO(&wfds); SL_FD_ZERO(&wfds);
FD_ZERO(&xfds); SL_FD_ZERO(&xfds);
// set fds if needed // set fds if needed
if (flags & MP_STREAM_POLL_RD) { if (flags & MP_STREAM_POLL_RD) {
FD_SET(sd, &rfds); SL_FD_SET(sd, &rfds);
} }
if (flags & MP_STREAM_POLL_WR) { if (flags & MP_STREAM_POLL_WR) {
FD_SET(sd, &wfds); SL_FD_SET(sd, &wfds);
} }
if (flags & MP_STREAM_POLL_HUP) { if (flags & MP_STREAM_POLL_HUP) {
FD_SET(sd, &xfds); SL_FD_SET(sd, &xfds);
} }
// call simplelink's select with minimum timeout // call simplelink's select with minimum timeout
@ -1511,13 +1511,13 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t
} }
// check return of select // check return of select
if (FD_ISSET(sd, &rfds)) { if (SL_FD_ISSET(sd, &rfds)) {
ret |= MP_STREAM_POLL_RD; ret |= MP_STREAM_POLL_RD;
} }
if (FD_ISSET(sd, &wfds)) { if (SL_FD_ISSET(sd, &wfds)) {
ret |= MP_STREAM_POLL_WR; ret |= MP_STREAM_POLL_WR;
} }
if (FD_ISSET(sd, &xfds)) { if (SL_FD_ISSET(sd, &xfds)) {
ret |= MP_STREAM_POLL_HUP; ret |= MP_STREAM_POLL_HUP;
} }
} else { } else {

2
cc3200/simplelink/user.h

@ -163,7 +163,7 @@ extern "C" {
\warning \warning
*/ */
#define SL_INC_STD_BSD_API_NAMING /* #define SL_INC_STD_BSD_API_NAMING */
/*! /*!

14
cc3200/telnet/telnet.c

@ -296,23 +296,23 @@ static void telnet_wait_for_enabled (void) {
static bool telnet_create_socket (void) { static bool telnet_create_socket (void) {
SlSockNonblocking_t nonBlockingOption; SlSockNonblocking_t nonBlockingOption;
sockaddr_in sServerAddress; SlSockAddrIn_t sServerAddress;
_i16 result; _i16 result;
// Open a socket for telnet // Open a socket for telnet
ASSERT ((telnet_data.sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) > 0); ASSERT ((telnet_data.sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_TCP)) > 0);
if (telnet_data.sd > 0) { if (telnet_data.sd > 0) {
// add the socket to the network administration // add the socket to the network administration
modusocket_socket_add(telnet_data.sd, false); modusocket_socket_add(telnet_data.sd, false);
// Enable non-blocking mode // Enable non-blocking mode
nonBlockingOption.NonblockingEnabled = 1; nonBlockingOption.NonblockingEnabled = 1;
ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
// Bind the socket to a port number // Bind the socket to a port number
sServerAddress.sin_family = AF_INET; sServerAddress.sin_family = SL_AF_INET;
sServerAddress.sin_addr.s_addr = INADDR_ANY; sServerAddress.sin_addr.s_addr = SL_INADDR_ANY;
sServerAddress.sin_port = htons(TELNET_PORT); sServerAddress.sin_port = sl_Htons(TELNET_PORT);
ASSERT ((result |= sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK); ASSERT ((result |= sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
@ -330,7 +330,7 @@ static bool telnet_create_socket (void) {
static void telnet_wait_for_connection (void) { static void telnet_wait_for_connection (void) {
SlSocklen_t in_addrSize; SlSocklen_t in_addrSize;
sockaddr_in sClientAddress; SlSockAddrIn_t sClientAddress;
// accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN // accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN
telnet_data.n_sd = sl_Accept(telnet_data.sd, (SlSockAddr_t *)&sClientAddress, (SlSocklen_t *)&in_addrSize); telnet_data.n_sd = sl_Accept(telnet_data.sd, (SlSockAddr_t *)&sClientAddress, (SlSocklen_t *)&in_addrSize);

Loading…
Cancel
Save