Added mutex for multiple SPI devices on the same SPI bus
Fork of cc3000_hostdriver_mbedsocket by
Revision 39:03ac37ab34eb, committed 2013-10-12
- Comitter:
- SolderSplashLabs
- Date:
- Sat Oct 12 20:46:19 2013 +0000
- Parent:
- 38:1d374a7f0c0d
- Child:
- 40:acb9324640c4
- Commit message:
- Added mbed ethernet library compatability, get ip, gateway and sub mask functions. Added enabled flag so we know when the module is enabled. Smart config tweaks
Changed in this revision
| cc3000.cpp | Show annotated file Show diff for this revision Revisions of this file |
| cc3000.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/cc3000.cpp Tue Oct 08 22:37:53 2013 +0000
+++ b/cc3000.cpp Sat Oct 12 20:46:19 2013 +0000
@@ -60,6 +60,7 @@
_status.smart_config_complete = 0;
_status.stop_smart_config = 0;
_status.ok_to_shut_down = 0;
+ _status.enabled = 0;
_inst = this;
}
@@ -68,6 +69,67 @@
}
+#ifdef CC3000_ETH_COMPAT
+// Ethernet library compatible, functions return strings
+// Caches the ipconfig from the usync callback
+static char mac_addr[19];
+static char ip_addr[17] = "\0";
+static char gateway[17] = "\0";
+static char networkmask[17] = "\0";
+
+char* cc3000::getMACAddress() {
+ return mac_addr;
+}
+
+char* cc3000::getIPAddress() {
+ return ip_addr;
+}
+
+char* cc3000::getGateway() {
+ return gateway;
+}
+
+char* cc3000::getNetworkMask() {
+ return networkmask;
+}
+
+/* Copied from lwip , modified to accept an uint32*/
+static char *inet_ntoa_r(uint32_t s_addr, char *buf, int buflen)
+{
+ char inv[3];
+ char *rp;
+ uint8_t *ap;
+ uint8_t rem;
+ uint8_t n;
+ uint8_t i;
+ int len = 0;
+
+ rp = buf;
+ ap = (uint8_t *)&s_addr;
+ for(n = 0; n < 4; n++) {
+ i = 0;
+ do {
+ rem = *ap % (uint8_t)10;
+ *ap /= (uint8_t)10;
+ inv[i++] = '0' + rem;
+ } while(*ap);
+ while(i--) {
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = inv[i];
+ }
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = '.';
+ ap++;
+ }
+ *--rp = 0;
+ return buf;
+}
+#endif
+
void cc3000::usync_callback(int32_t event_type, uint8_t * data, uint8_t length) {
if (event_type == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
{
@@ -78,6 +140,8 @@
if (event_type == HCI_EVNT_WLAN_UNSOL_CONNECT)
{
_status.connected = 1;
+ // Connect message is always followed by a DHCP message, connection is not useable until then
+ _status.dhcp = 0;
}
if (event_type == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
@@ -89,6 +153,15 @@
if (event_type == HCI_EVNT_WLAN_UNSOL_DHCP)
{
+ #ifdef CC3000_ETH_COMPAT
+
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19);
+
+ #endif
+
if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
_status.dhcp = 1;
} else {
@@ -116,6 +189,9 @@
}
void cc3000::start_smart_config(const uint8_t *smart_config_key) {
+
+ _status.smart_config_complete = 0;
+
// Reset all the previous configuration
_wlan.ioctl_set_connection_policy(0, 0, 0);
//_wlan.ioctl_del_profile(255);
@@ -155,13 +231,14 @@
// Configure to connect automatically to the AP retrieved in the
// Smart config process
- _wlan.ioctl_set_connection_policy(0, 1, 1);
+ _wlan.ioctl_set_connection_policy(0, 0, 1);
// reset the CC3000
_wlan.stop();
- wait(2);
+ _status.enabled = 0;
+ wait(5);
_wlan.start(0);
- wait(2);
+ _status.enabled = 1;
// Mask out all non-required events
_wlan.set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);
@@ -181,6 +258,32 @@
return ret;
}
+bool cc3000::connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode)
+{
+bool ret = false;
+
+ if (key == 0)
+ {
+ if (connect_open(ssid))
+ {
+ ret = true;
+ }
+ }
+ else
+ {
+ #ifndef CC3000_TINY_DRIVER
+ if (connect_secure(ssid,key,security_mode))
+ {
+ ret = true;
+ }
+ #else
+ /* secure connection not supported with TINY_DRIVER */
+ #endif
+ }
+
+ return ret;
+}
+
bool cc3000::connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) {
Timer t; /* TODO static? */
bool ret = true;
@@ -216,17 +319,21 @@
void cc3000::start(uint8_t patch) {
_wlan.start(patch);
+ _status.enabled = 1;
_wlan.set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_KEEPALIVE);
}
void cc3000::stop(void) {
_wlan.stop();
+ _status.enabled = 0;
}
void cc3000::restart(uint8_t patch) {
_wlan.stop();
+ _status.enabled = 0;
wait_ms(500);
_wlan.start(patch);
+ _status.enabled = 1;
}
bool cc3000::connect_open(const uint8_t *ssid) {
@@ -247,6 +354,11 @@
return ret;
}
+bool cc3000::is_enabled()
+{
+ return _status.enabled;
+}
+
bool cc3000::is_connected() {
return _status.connected;
}
--- a/cc3000.h Tue Oct 08 22:37:53 2013 +0000
+++ b/cc3000.h Sat Oct 12 20:46:19 2013 +0000
@@ -50,6 +50,7 @@
#include "cc3000_socket.h"
#define MAX_SOCKETS 4
+#define CC3000_ETH_COMPAT
/** Enable debug messages, remove comment from the ones you want or all.
*/
@@ -1543,6 +1544,7 @@
bool stop_smart_config;
bool dhcp_configured;
bool ok_to_shut_down;
+ bool enabled;
} tStatus;
/**
* \brief Ctor.
@@ -1584,7 +1586,15 @@
*/
void usync_callback(int32_t event_type, uint8_t *data, uint8_t length);
/**
- * \brief Connect to SSID (open/secured) with timeout (10ms).
+ * \brief Start connection to SSID (open/secured) non-blocking
+ * \param ssid SSID name
+ * \param key Security key (if key = 0, open connection)
+ * \param security_mode Security mode
+ * \return true if connection was established, false otherwise.
+ */
+ bool connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode);
+ /**
+ * \brief Connect to SSID (open/secured) with timeout (10s).
* \param ssid SSID name
* \param key Security key (if key = 0, open connection)
* \param security_mode Security mode
@@ -1606,6 +1616,11 @@
*/
bool connect_open(const uint8_t *ssid);
/**
+ * \brief Status of the cc3000 module.
+ * \return true if it's enabled, false otherwise.
+ */
+ bool is_enabled();
+ /**
* \brief Status of the cc3000 connection.
* \return true if it's connected, false otherwise.
*/
@@ -1683,6 +1698,35 @@
static cc3000 *get_instance() {
return _inst;
}
+#ifdef CC3000_ETH_COMPAT
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getMACAddress();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getIPAddress();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getGateway();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getNetworkMask();
+#endif
public:
cc3000_simple_link _simple_link;
cc3000_event _event;
