Added mutex for multiple SPI devices on the same SPI bus
Fork of cc3000_hostdriver_mbedsocket by
Diff: Socket/Socket.cpp
- Revision:
- 4:15b58c119a0a
- Parent:
- 0:615c697c33b0
- Child:
- 5:245ac5b73132
--- a/Socket/Socket.cpp Thu Sep 19 08:04:22 2013 +0000 +++ b/Socket/Socket.cpp Sat Sep 21 15:01:05 2013 +0000 @@ -26,6 +26,29 @@ } } +int Socket::init_socket(int type, int protocol) { + if (_sock_fd != -1) { +#if (CC3000_DEBUG == 1) + printf("DEBUG: Socket was initialized previously.\n"); +#endif + return -1; + } + + int fd = _cc3000_module->_socket.socket(AF_INET, type, protocol); + if (fd < -1) { +#if (CC3000_DEBUG == 1) + printf("DEBUG: Failed to create new socket (type:%d, protocol:%d).\n",type, protocol); +#endif + return -1; + } +#if (CC3000_DEBUG == 1) + printf("DEBUG: Socket created (fd: %d type: %d, protocol: %d).\n",fd, type, protocol); +#endif + _sock_fd = fd; + + return 0; +} + void Socket::set_blocking(bool blocking, unsigned int timeout) { _blocking = blocking; _timeout = timeout; @@ -40,7 +63,7 @@ } int Socket::select(struct timeval *timeout, bool read, bool write) { - if (_sock_fd < 0 ) { + if (_sock_fd < 0) { return -1; } @@ -52,7 +75,15 @@ fd_set* writeset = (write) ? (&fdSet) : (NULL); int ret = _cc3000_module->_socket.select(_sock_fd+1, readset, writeset, NULL, timeout); - return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0); +#if (CC3000_DEBUG == 1) + printf("DEBUG: Select on sock_fd: %d, returns %d. fdSet: %d\n",_sock_fd, ret, fdSet); +#endif + //return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0); + if (FD_ISSET(_sock_fd, &fdSet)) { + return 0; + } else { + return -1; + } } int Socket::wait_readable(TimeInterval& timeout) {