version_2.0
Dependents: cc3000_ping_demo_try_2
Fork of cc3000_hostdriver_mbedsocket by
Revision 42:bd2c631a031a, committed 2013-10-12
- Comitter:
- SolderSplashLabs
- Date:
- Sat Oct 12 21:53:28 2013 +0000
- Parent:
- 41:eb1999bd50fb
- Child:
- 43:864437b6c058
- Commit message:
- Added David's IRQ checking before re-enabling the IRQ.; Modified the is_connected function, connect + dhcp are needed ; Moved inet_ntoa_r to the socket class, not sure this is the best place, but other conversion functions live here.
Changed in this revision
--- a/cc3000.cpp Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000.cpp Sat Oct 12 21:53:28 2013 +0000
@@ -93,41 +93,6 @@
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) {
@@ -158,10 +123,10 @@
{
#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);
+ _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17);
+ _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17);
+ _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17);
+ _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19);
#endif
@@ -169,7 +134,7 @@
_status.dhcp = 1;
DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP %i.%i.%i.%i", data[3], data[2], data[1], data[0]);
} else {
- DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP - Disconnected");
+ DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP - Disconnecting");
_status.dhcp = 0;
}
}
@@ -201,6 +166,11 @@
_status.smart_config_complete = 0;
_wlan.ioctl_set_connection_policy(0, 0, 0);
+
+ if (_status.connected == 1)
+ {
+ disconnect();
+ }
//Wait until CC3000 is disconected
while (_status.connected == 1)
@@ -251,7 +221,7 @@
bool cc3000::connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) {
uint32_t ret;
- _wlan.disconnect();
+ //_wlan.disconnect();
wait_ms(3);
ret = _wlan.connect(security_mode, ssid, strlen((const char *)ssid), 0, (uint8_t *)key, strlen((const char *)key));
if (ret == 0) { /* TODO static internal cc3000 state 0 to TRUE */
@@ -364,7 +334,14 @@
}
bool cc3000::is_connected() {
- return _status.connected;
+ if (( _status.connected ) && ( _status.dhcp ))
+ {
+ return( 1 );
+ }
+ else
+ {
+ return( 0 );
+ }
}
bool cc3000::is_dhcp_configured() {
--- a/cc3000.h Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000.h Sat Oct 12 21:53:28 2013 +0000
@@ -1000,6 +1000,14 @@
* return SOC_ERROR if socket was not opened successfully, or if an error occurred.\n
*/
int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length);
+ /**
+ * \brief
+ * \param[in] s_addr in host format ( little endian )
+ * \param[in] *buf buffer to write too
+ * \param[in] buflen length of supplied buffer
+ * \return pointer to buf \n
+ */
+ char * inet_ntoa_r(uint32_t s_addr, char *buf, int buflen);
#ifndef CC3000_TINY_DRIVER
/**
* \brief Get host IP by name.\n
--- a/cc3000_event.cpp Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000_event.cpp Sat Oct 12 21:53:28 2013 +0000
@@ -208,7 +208,7 @@
uint8_t *RetParams;
while (1)
- {
+ {
if (_simple_link.get_data_received_flag() != 0)
{
received_data = _simple_link.get_received_data();
--- a/cc3000_socket.cpp Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000_socket.cpp Sat Oct 12 21:53:28 2013 +0000
@@ -600,4 +600,39 @@
#endif
+char * cc3000_socket::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;
+}
+
} /* end of cc3000 namespace */
--- a/cc3000_spi.cpp Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000_spi.cpp Sat Oct 12 21:53:28 2013 +0000
@@ -63,6 +63,9 @@
void cc3000_spi::wlan_irq_enable()
{
NVIC_EnableIRQ(_irq_port);
+
+ if(wlan_irq_read() == 0)
+ WLAN_IRQHandler();
}
void cc3000_spi::wlan_irq_disable() {
