cc3000 hostdriver with the mbed socket interface

Dependents:   cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more

Files at this revision

API Documentation at this revision

Comitter:
SolderSplashLabs
Date:
Wed Oct 02 15:26:41 2013 +0000
Parent:
13:5e36c267e62f
Child:
15:aae737ca3dd2
Commit message:
More debug changes, 3 separate levels of debug

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
cc3000_event.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/cc3000.cpp	Wed Oct 02 15:00:07 2013 +0000
+++ b/cc3000.cpp	Wed Oct 02 15:26:41 2013 +0000
@@ -133,7 +133,7 @@
     // Start the Smart Config process with AES disabled
     _wlan.smart_config_start(0);
 
-    DBG_HCI("Waiting for smartconfig to be completed");
+    DBG_CC("Waiting for smartconfig to be completed");
 
     // Wait for Smart config finished
     while (_status.smart_config_complete == 0)
@@ -142,7 +142,7 @@
 
     }
 
-    DBG_HCI("Smartconfig finished");
+    DBG_CC("Smartconfig finished");
 
 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
     // create new entry for AES encryption key
@@ -205,7 +205,7 @@
         if (t.read_ms() > 10000){
             ret = false;
 
-            DBG_HCI("Connection to AP failed");
+            DBG_CC("Connection to AP failed");
 
             break;
         }
@@ -288,7 +288,7 @@
 
     tcp_socket = _socket.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (tcp_socket == -1) {
-        DBG_HCI("Failed to create new socket (tcp)");
+        DBG_CC("Failed to create new socket (tcp)");
         return cc3000_client(*this);
     }
 
@@ -301,7 +301,7 @@
     socket_address.data[5] = ip_address;
 
     if (_socket.connect(tcp_socket, &socket_address, sizeof(socket_address)) == -1) {
-        DBG_HCI("Failed to connect (tcp)");
+        DBG_CC("Failed to connect (tcp)");
         _socket.closesocket(tcp_socket);
         return cc3000_client(*this);
     }
@@ -314,7 +314,7 @@
 
     udp_socket = _socket.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if (udp_socket == -1) {
-        DBG_HCI("Failed to create new socket (udp)");
+        DBG_CC("Failed to create new socket (udp)");
         return cc3000_client(*this);
     }
 
@@ -327,7 +327,7 @@
     socket_address.data[5] = ip_address;
 
     if (_socket.connect(udp_socket, &socket_address, sizeof(socket_address)) == -1) {
-        DBG_HCI("Failed to connect (udp)");
+        DBG_CC("Failed to connect (udp)");
         _socket.closesocket(udp_socket);
         return cc3000_client(*this);
     }
@@ -341,7 +341,7 @@
 
     tcp_socket = _socket.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (tcp_socket == -1) {
-        DBG_HCI("Failed to create new socket.");
+        DBG_CC("Failed to create new socket.");
         return cc3000_server(*this, socket_address);
     }
 
@@ -354,11 +354,11 @@
     socket_address.data[5] = ip_address;
 
     if (_socket.bind(tcp_socket, &socket_address, sizeof(socket_address)) != 0) {
-        DBG_HCI("Failed to bind the new socket");
+        DBG_CC("Failed to bind the new socket");
         return cc3000_server(*this, socket_address);
     }
     if (_socket.listen(tcp_socket, 1) != 0) { /* 1 client */
-        DBG_HCI("Failed to listen on the new socket");
+        DBG_CC("Failed to listen on the new socket");
         return cc3000_server(*this, socket_address);
     }
 
@@ -393,18 +393,18 @@
 
     _ping_report.packets_received = 0;
     if (_netapp.ping_send(&reversed_ip, attempts, size, timeout) == -1) {
-        DBG_HCI("Failed to send ping");
+        DBG_CC("Failed to send ping");
         return 0;
     }
     wait_ms(timeout*attempts*2);
 
     /* known issue of cc3000 - sent number is send + received */
     // TODO : Remove the Sent/recv'd counts until ti fix the firmware issue?
-    DBG_HCI("Sent: %d \r\n",_ping_report.packets_sent);
-    DBG_HCI("Received: %d \r\n",_ping_report.packets_received);
-    DBG_HCI("Min time: %d \r\n",_ping_report.min_round_time);
-    DBG_HCI("Max time: %d \r\n",_ping_report.max_round_time);
-    DBG_HCI("Avg time: %d \r\n",_ping_report.avg_round_time);
+    DBG_CC("Sent: %d",_ping_report.packets_sent);
+    DBG_CC("Received: %d",_ping_report.packets_received);
+    DBG_CC("Min time: %d",_ping_report.min_round_time);
+    DBG_CC("Max time: %d",_ping_report.max_round_time);
+    DBG_CC("Avg time: %d",_ping_report.avg_round_time);
 
     return _ping_report.packets_received;
 }
--- a/cc3000.h	Wed Oct 02 15:00:07 2013 +0000
+++ b/cc3000.h	Wed Oct 02 15:26:41 2013 +0000
@@ -56,11 +56,19 @@
 #define CC3000_DEBUG      1
 
 #if CC3000_DEBUG == 1
+
+    // DBG_SOCKET, mbed socket specific debug messages
     #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__); 
+    
+    // DBG_HCI, prints a message for every recieved HCI event, quite a lot of debug
     #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI] "x"\r\n", ##__VA_ARGS__); 
+    
+    // DBG_CC, General cc3000 debug messages
+    #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__); 
 #else
     #define DBG_SOCKET(x, ...) 
     #define DBG_HCI(x, ...)
+    #define DBG(x, ...)
 #endif
 
 namespace mbed_cc3000 {
@@ -208,6 +216,7 @@
     ~cc3000_event();
 
     void hci_unsol_handle_patch_request(uint8_t *event_hdr);
+    void hci_event_debug_print ( uint16_t hciEventNo );
     uint8_t *hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen);
     int32_t hci_unsol_event_handler(uint8_t *event_hdr);
     int32_t hci_unsolicited_event_handler(void);
--- a/cc3000_event.cpp	Wed Oct 02 15:00:07 2013 +0000
+++ b/cc3000_event.cpp	Wed Oct 02 15:26:41 2013 +0000
@@ -44,6 +44,61 @@
 
 namespace mbed_cc3000 {
 
+#if CC3000_DEBUG == 1
+const char *HCI_EVENT_STR[] =
+{
+    "Socket",
+    "Bind",
+    "Send",
+    "Recv",
+    "Accept",
+    "Listen",
+    "Connect",
+    "BSD Select",
+    "Set Socket Options",
+    "Get Socket Options",
+    "Close Socket",
+    "Unknown",
+    "Recv From",
+    "Write",
+    "Send To",
+    "Get Hostname",
+    "mDNS Advertise"
+};
+
+const char *HCI_NETAPP_STR[] =
+{
+    "DHCP",
+    "Ping Sent",
+    "Ping Report",
+    "Ping Stop",
+    "IP Config",
+    "ARP Flush",
+    "Unknown",
+    "Set Debug level",
+    "Set Timers"
+};
+
+// from 0-7
+const char *HCI_MISC_STR[] =
+{
+    "BASE - Error?",
+    "Connecting",
+    "Disconnect",
+    "Scan Param",
+    "Connect Policy",
+    "Add Profile",
+    "Del Profile",
+    "Get Scan Res",
+    "Event Mask",
+    "Status Req",
+    "Config Start",
+    "Config Stop",
+    "Config Set Prefix",
+    "Config Patch",
+};
+#endif
+
 cc3000_event::cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000)
     : socket_active_status(SOCKET_STATUS_INIT_VAL), _simple_link(simplelink), _hci(hci), _spi(spi), _cc3000(cc3000) {
 
@@ -121,6 +176,28 @@
     }
 }
 
+void cc3000_event::hci_event_debug_print ( uint16_t hciEventNo )
+{
+#if CC3000_DEBUG == 1
+    if (( hciEventNo > HCI_CMND_SOCKET_BASE) && ( hciEventNo <= HCI_CMND_MDNS_ADVERTISE))
+    {
+        DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_EVENT_STR[hciEventNo-HCI_CMND_SOCKET]);
+    }
+    else if ((hciEventNo > HCI_CMND_NETAPP_BASE) && ( hciEventNo <= HCI_NETAPP_SET_TIMERS))
+    {
+        DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_NETAPP_STR[hciEventNo-HCI_NETAPP_DHCP]);
+    }
+    else if (hciEventNo < HCI_CMND_WLAN_CONFIGURE_PATCH+1)
+    {
+        DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_MISC_STR[hciEventNo]);
+    }
+    else
+    {
+        DBG_HCI("Event Received : 0x%04X", hciEventNo);
+    }
+#endif
+}
+
 uint8_t *cc3000_event::hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen) {
     uint8_t *received_data, argument_size;
     uint16_t length;
@@ -148,6 +225,8 @@
                 {
                     STREAM_TO_UINT8(received_data, HCI_DATA_LENGTH_OFFSET, length);
 
+                    hci_event_debug_print( received_op_code );
+                    
                     switch(received_op_code)
                     {
                     case HCI_CMND_READ_BUFFER_SIZE: