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:
Kojto
Date:
Sun Oct 13 11:46:21 2013 +0200
Parent:
43:864437b6c058
Child:
45:50ab13d8f2dc
Commit message:
all _DEBUG_ are set to 0, toggle to enable/disable, doxygen doc for new ethernet interface functions

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
cc3000_spi.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/cc3000.cpp	Sat Oct 12 23:28:22 2013 +0000
+++ b/cc3000.cpp	Sun Oct 13 11:46:21 2013 +0200
@@ -69,7 +69,7 @@
 
 }
 
-#ifdef CC3000_ETH_COMPAT
+#if (CC3000_ETH_COMPAT == 1)
 // Ethernet library compatible, functions return strings
 // Caches the ipconfig from the usync callback
 static char mac_addr[19];
@@ -92,10 +92,9 @@
 char* cc3000::getNetworkMask() {
     return networkmask;
 }
-
 #endif
 
-void cc3000::usync_callback(int32_t event_type, uint8_t * data, uint8_t length) {
+void cc3000::usync_callback(int32_t event_type, uint8_t *data, uint8_t length) {
     if (event_type == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
     {
         DBG_CC("Callback : HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE");
@@ -121,16 +120,13 @@
 
     if (event_type == HCI_EVNT_WLAN_UNSOL_DHCP)
     {
-        #ifdef CC3000_ETH_COMPAT
-        
+#if (CC3000_ETH_COMPAT == 1)
         _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
-        
-        if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
+#endif
+        if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
             _status.dhcp = 1;
             DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP %i.%i.%i.%i", data[3], data[2], data[1], data[0]);
         } else {
@@ -141,7 +137,7 @@
 
     if (event_type == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
     {
-        // Note this means the moudles is idle, so it could be shutdown..
+        // Note this means the modules is idle, so it could be shutdown..
         //DBG_CC("Callback : HCI_EVENT_CC3000_CAN_SHUT_DOWN");
         _status.ok_to_shut_down = 1;
     }
@@ -163,10 +159,9 @@
 }
 
 void cc3000::start_smart_config(const uint8_t *smart_config_key) {
-
     _status.smart_config_complete = 0;
     _wlan.ioctl_set_connection_policy(0, 0, 0);
-    
+
     if (_status.connected == 1)
     {
         disconnect();
@@ -232,21 +227,21 @@
     return ret;
 }
 
-bool cc3000::connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) 
+bool cc3000::connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode)
 {
 bool ret = false;
 
-    if (key == 0) 
+    if (key == 0)
     {
-        if (connect_open(ssid)) 
+        if (connect_open(ssid))
         {
             ret = true;
         }
     }
-    else 
+    else
     {
     #ifndef CC3000_TINY_DRIVER
-        if (connect_secure(ssid,key,security_mode)) 
+        if (connect_secure(ssid,key,security_mode))
         {
             ret = true;
         }
@@ -254,7 +249,7 @@
         /* secure connection not supported with TINY_DRIVER */
     #endif
     }
-    
+
     return ret;
 }
 
--- a/cc3000.h	Sat Oct 12 23:28:22 2013 +0000
+++ b/cc3000.h	Sun Oct 13 11:46:21 2013 +0200
@@ -50,71 +50,57 @@
 #include "cc3000_socket.h"
 
 #define MAX_SOCKETS 4
-#define CC3000_ETH_COMPAT
+// cc3000 Ethernet Interface - enabled by default
+#define CC3000_ETH_COMPAT   1
 
-/** Enable debug messages, remove comment from the ones you want or all.
- */
-
+/** Enable debug messages - set 1  */
 // Debug - Socket interface messages
-//#define CC3000_DEBUG_SOCKET
-
+#define CC3000_DEBUG_SOCKET 0
 // Debug - HCI TX messages
-//#define CC3000_DEBUG_HCI_TX
-
+#define CC3000_DEBUG_HCI_TX 0
 // Debug - HCI Rx messages
-//#define CC3000_DEBUG_HCI_RX
-
+#define CC3000_DEBUG_HCI_RX 0
 // Debug - General Debug
-//#define CC3000_DEBUG
-
+#define CC3000_DEBUG        0
 // Add colour to the debug messages, requires a VT100 terminal like putty, comment out to remove
-//#define VT100_COLOUR
+#define VT100_COLOUR        0
 
-#ifdef CC3000_DEBUG_SOCKET
-
-    #ifdef VT100_COLOUR
+#if (CC3000_DEBUG_SOCKET == 1)
+    #if (VT100_COLOUR == 1)
         #define DBG_SOCKET(x, ...) std::printf("\x1b[2;32;40m[CC3000 : SOCKET] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
     #else
         #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__);
     #endif
-
 #else
     #define DBG_SOCKET(x, ...)
 #endif
 
-#ifdef CC3000_DEBUG_HCI_TX
-
-    #ifdef VT100_COLOUR
+#if (CC3000_DEBUG_HCI_TX == 1)
+    #if (VT100_COLOUR == 1)
         #define DBG_HCI(x, ...) std::printf("\x1b[2;35;40m[CC3000 : HCI RX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
     #else
         #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI RX] "x"\r\n", ##__VA_ARGS__);
     #endif
-
 #else
     #define DBG_HCI(x, ...)
 #endif
 
-#ifdef CC3000_DEBUG_HCI_RX
-
-    #ifdef VT100_COLOUR
+#if (CC3000_DEBUG_HCI_RX == 1)
+    #if (VT100_COLOUR == 1)
         #define DBG_HCI_CMD(x, ...) std::printf("\x1b[2;36;40m[CC3000 : HCI TX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
     #else
         #define DBG_HCI_CMD(x, ...) std::printf("[CC3000 : HCI TX] "x"\r\n", ##__VA_ARGS__);
     #endif
-
 #else
     #define DBG_HCI_CMD(x, ...)
 #endif
 
-
-#ifdef CC3000_DEBUG
-
-    #ifdef VT100_COLOUR
+#if (CC3000_DEBUG == 1)
+    #if (VT100_COLOUR == 1)
         #define DBG_CC(x, ...) std::printf("\x1b[2;32;40m[CC3000] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
     #else
         #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__);
     #endif
-
 #else
     #define DBG_CC(x, ...)
 #endif
@@ -1001,7 +987,7 @@
      */
     int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length);
     /**
-     *  \brief 
+     *  \brief
      *  \param[in] s_addr in host format ( little endian )
      *  \param[in] *buf     buffer to write too
      *  \param[in] buflen   length of supplied buffer
@@ -1706,32 +1692,36 @@
     static cc3000 *get_instance() {
         return _inst;
     }
-#ifdef CC3000_ETH_COMPAT
+#if (CC3000_ETH_COMPAT == 1)
     /**
-     *  \brief 
-     *  \param 
-     *  \return 
+     *  \brief Get the MAC address of your Ethernet interface.
+     *  \param none
+     *  \return
+     *      Pointer to a string containing the MAC address.
      */
     char* getMACAddress();
 
      /**
-     *  \brief 
-     *  \param 
-     *  \return 
+     *  \brief Get the IP address of your Ethernet interface.
+     *  \param none
+     *  \return
+     *      Pointer to a string containing the IP address.
      */
     char* getIPAddress();
 
      /**
-     *  \brief 
-     *  \param
-     *  \return 
+     *  \brief Get the Gateway address of your Ethernet interface
+     *  \param none
+     *  \return
+     *      Pointer to a string containing the Gateway address
      */
     char* getGateway();
 
      /**
-     *  \brief 
-     *  \param 
-     *  \return 
+     *  \brief Get the Network mask of your Ethernet interface
+     *  \param none
+     *  \return
+     *      Pointer to a string containing the Network mask
      */
     char* getNetworkMask();
 #endif
--- a/cc3000_event.cpp	Sat Oct 12 23:28:22 2013 +0000
+++ b/cc3000_event.cpp	Sun Oct 13 11:46:21 2013 +0200
@@ -44,7 +44,7 @@
 
 namespace mbed_cc3000 {
 
-#ifdef CC3000_DEBUG_HCI_RX
+#if (CC3000_DEBUG_HCI_RX == 1)
 const char *HCI_EVENT_STR[] =
 {
     "Socket",
@@ -178,7 +178,7 @@
 
 static void hci_event_debug_print(uint16_t hciEventNo)
 {
-#ifdef CC3000_DEBUG_HCI_RX
+#if (CC3000_DEBUG_HCI_RX == 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]);
@@ -206,9 +206,9 @@
     uint32_t return_value;
     uint8_t * RecvParams;
     uint8_t *RetParams;
-        
+
     while (1)
-    {        
+    {
         if (_simple_link.get_data_received_flag() != 0)
         {
             received_data = _simple_link.get_received_data();
@@ -397,12 +397,12 @@
                         //Read SSID
                         STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
                         break;
-                        
+
                     default :
                         DBG_HCI("UNKNOWN Event Received : 0x%04X ", received_op_code);
                         break;
                     }
- 
+
                 }
                 if (received_op_code == _simple_link.get_op_code())
                 {
--- a/cc3000_spi.cpp	Sat Oct 12 23:28:22 2013 +0000
+++ b/cc3000_spi.cpp	Sun Oct 13 11:46:21 2013 +0200
@@ -63,9 +63,10 @@
 void cc3000_spi::wlan_irq_enable()
 {
     NVIC_EnableIRQ(_irq_port);
-    
-    if(wlan_irq_read() == 0)
-    WLAN_IRQHandler();
+
+    if(wlan_irq_read() == 0) {
+        WLAN_IRQHandler();
+    }
 }
 
 void cc3000_spi::wlan_irq_disable() {
@@ -80,25 +81,10 @@
     wlan_irq_disable();
 }
 
-// void cc3000_spi::SpiReceiveHandler() {
-//     _simple_link.usEventOrDataReceived = 1;
-//     //_simple_link.pucReceivedData = (unsigned char *)pvBuffer;
-
-//     hci_unsolicited_event_handler();
-// }
-
-
-/* TODO
-    pRxPacket, pTxPacket do we need to hold this pointer ?
-    SPIRxHandler - remove?
-*/
 void cc3000_spi::open() {
    _spi_info.spi_state = eSPI_STATE_POWERUP;
-   //_spi_info.SPIRxHandler = pfRxHandler;
    _spi_info.tx_packet_length = 0;
    _spi_info.rx_packet_length = 0;
-   //_rx_buffer[CC3000_RX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
-   //_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
     wlan_irq_enable();
 }