cc3000 hostdriver with the mbed socket interface

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Mon Apr 06 18:23:37 2015 +0000
Parent:
50:04e43d8059b8
Commit message:
Added 2 optional parameters to the constructor : set TX and RX buffer size

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_common.h Show annotated file Show diff for this revision Revisions of this file
cc3000_simplelink.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	Sun Apr 05 14:25:45 2015 +0000
+++ b/cc3000.cpp	Mon Apr 06 18:23:37 2015 +0000
@@ -47,11 +47,12 @@
 static uint8_t cc3000_prefix[] = {'T', 'T', 'T'};
 cc3000 *cc3000::_inst;
 
-cc3000::cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi)
+cc3000::cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, uint32_t max_tx_size, uint32_t max_rx_size)
              : _event(_simple_link, _hci, _spi, *this), _socket(_simple_link, _hci, _event),
-               _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link), _hci(_spi),
+               _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link, max_tx_size, max_rx_size), _hci(_spi),
                _nvmem(_hci, _event, _simple_link), _netapp(_simple_link, _nvmem, _hci, _event),
                _wlan(_simple_link, _event, _spi, _hci) {
+    _simple_link.create_txrx_buffers(max_tx_size, max_rx_size);
     _simple_link.set_tx_complete_signal(1);
     memset(&_status, 0, sizeof(_status));
     _inst = this;
@@ -62,11 +63,12 @@
 
 #if (CC3000_ETH_COMPAT == 1)
 cc3000::cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid,
-               const char *phrase, Security sec, bool smart_config)
+               const char *phrase, Security sec, bool smart_config, uint32_t max_tx_size, uint32_t max_rx_size)
              : _event(_simple_link, _hci, _spi, *this), _socket(_simple_link, _hci, _event),
-               _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link), _hci(_spi),
+               _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link, max_tx_size, max_rx_size), _hci(_spi),
                _nvmem(_hci, _event, _simple_link), _netapp(_simple_link, _nvmem, _hci, _event),
                _wlan(_simple_link, _event, _spi, _hci), _sec(sec), _smart_config(smart_config) {
+    _simple_link.create_txrx_buffers(max_tx_size, max_rx_size);
     _simple_link.set_tx_complete_signal(1);
     memset(&_status, 0, sizeof(_status));
     strcpy((char *)_ssid, ssid);
--- a/cc3000.h	Sun Apr 05 14:25:45 2015 +0000
+++ b/cc3000.h	Mon Apr 06 18:23:37 2015 +0000
@@ -152,6 +152,13 @@
      *  \return none
      */
     ~cc3000_simple_link();
+
+    /**
+     *  \brief Init TX and RX buffers.
+     *  \return none.
+     */
+    void create_txrx_buffers(uint32_t tx_size, uint32_t rx_size);
+
     /**
      *  \brief Returns data received flag.
      *  \return Data received flag.
@@ -313,8 +320,8 @@
     uint16_t _released_packets;
     int32_t  _transmit_data_error;
     uint8_t  *_received_data;
-    uint8_t  _rx_buffer[CC3000_RX_BUFFER_SIZE];
-    uint8_t  _tx_buffer[CC3000_TX_BUFFER_SIZE];
+    uint8_t  *_rx_buffer;
+    uint8_t  *_tx_buffer;
 private:
     /* Not used currently */
     int8_t *(* _fFWPatches)(uint32_t *length);
@@ -1079,9 +1086,11 @@
      *  \param irq_port    Port for IRQ pin (needed for enable/disable interrupts)
      *  \param event       Reference to the event object.
      *  \param simple_link Reference to the simple link object.
+     *  \param max_tx      Max. TX buffer size
+     *  \param max_rx      Max. RX buffer size
      *  \return none
      */
-     cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link);
+     cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link, uint32_t max_tx, uint32_t max_rx);
     /**
      *  \brief Dtor
      *  \param none
@@ -1177,6 +1186,8 @@
     SPI                 _wlan_spi;
     cc3000_event        &_event;
     cc3000_simple_link  &_simple_link;
+    uint32_t            _max_tx;
+    uint32_t            _max_rx;
     bool                _process_irq;
 };
 
@@ -1554,8 +1565,14 @@
      *  \param cc3000_en  Enable pin
      *  \param cc3000_cs  Chip select pin
      *  \param cc3000_spi SPI interface
+     *  \param max_tx_size  TX buffer size (optional, default = 1520)
+     *  \param max_rx_size  RX buffer size (optional, default = 512)
      */
-    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi);
+#ifndef CC3000_TINY_DRIVER
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, uint32_t max_tx_size = 1520, uint32_t max_rx_size = 512);
+#else
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, uint32_t max_tx_size = 59, uint32_t max_rx_size = 44);
+#endif
     /**
      *  \brief Dtor.
      */
@@ -1705,8 +1722,14 @@
      *  \param phrase       Password
      *  \param sec          Security of the AP
      *  \param smart_config Smart config selection
+     *  \param max_tx_size  TX buffer size (optional, default = 1520)
+     *  \param max_rx_size  RX buffer size (optional, default = 512)
      */
-    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, const char *phrase, Security sec, bool smart_config);
+#ifndef CC3000_TINY_DRIVER
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, const char *phrase, Security sec, bool smart_config, uint32_t max_tx_size = 1520, uint32_t max_rx_size = 512);
+#else
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, const char *phrase, Security sec, bool smart_config, uint32_t max_tx_size = 59, uint32_t max_rx_size = 44);
+#endif
     /**
      *  \brief Disconnect wlan device.
      *  \param none
--- a/cc3000_common.h	Sun Apr 05 14:25:45 2015 +0000
+++ b/cc3000_common.h	Mon Apr 06 18:23:37 2015 +0000
@@ -80,8 +80,6 @@
   The 1 is used for the overrun detection
 */
 
-#define CC3000_MINIMAL_RX_SIZE      (118 + 1)
-#define CC3000_MAXIMAL_RX_SIZE      (1519 + 1)
 
 /*Defines for minimal and maximal TX buffer size.
   This buffer is used for sending events and data.
@@ -102,31 +100,10 @@
 
   The 1 is used for the overrun detection */
 
-#define CC3000_MINIMAL_TX_SIZE      (118 + 1)
-#define CC3000_MAXIMAL_TX_SIZE      (1519 + 1)
-
-//TX and RX buffer size - allow to receive and transmit maximum data at lengh 8.
-#ifdef CC3000_TINY_DRIVER
-#define TINY_CC3000_MAXIMAL_RX_SIZE 44
-#define TINY_CC3000_MAXIMAL_TX_SIZE 59
-#endif
-
-/*In order to determine your preferred buffer size,
-  change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
-  the minimal and maximal specified above.
-  Note that the buffers are allocated by SPI.
-*/
-
 #ifndef CC3000_TINY_DRIVER
-
-    #define CC3000_RX_BUFFER_SIZE   (CC3000_MAXIMAL_RX_SIZE)
-    #define CC3000_TX_BUFFER_SIZE   (CC3000_MAXIMAL_TX_SIZE)
     #define SP_PORTION_SIZE         512
-
-//TINY DRIVER: We use smaller rx and tx buffers in order to minimize RAM consumption
+//TINY DRIVER: We use smaller buffers in order to minimize RAM consumption
 #else
-    #define CC3000_RX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_RX_SIZE)
-    #define CC3000_TX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_TX_SIZE)
     #define SP_PORTION_SIZE         32
 #endif
 
--- a/cc3000_simplelink.cpp	Sun Apr 05 14:25:45 2015 +0000
+++ b/cc3000_simplelink.cpp	Mon Apr 06 18:23:37 2015 +0000
@@ -44,13 +44,18 @@
 namespace mbed_cc3000 {
 
 cc3000_simple_link::cc3000_simple_link() {
-    _rx_buffer[CC3000_RX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
-    _tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
 }
 
 cc3000_simple_link::~cc3000_simple_link() {
 }
 
+void cc3000_simple_link::create_txrx_buffers(uint32_t tx_size, uint32_t rx_size) {
+    _rx_buffer = new uint8_t[rx_size];
+    _tx_buffer = new uint8_t[tx_size];
+    _rx_buffer[rx_size - 1] = CC3000_BUFFER_MAGIC_NUMBER;
+    _tx_buffer[tx_size - 1] = CC3000_BUFFER_MAGIC_NUMBER;
+}
+
 uint8_t cc3000_simple_link::get_data_received_flag() {
     return _data_received_flag;
 }
--- a/cc3000_spi.cpp	Sun Apr 05 14:25:45 2015 +0000
+++ b/cc3000_spi.cpp	Mon Apr 06 18:23:37 2015 +0000
@@ -43,8 +43,8 @@
 
 namespace mbed_cc3000 {
 
-cc3000_spi::cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link)
-  : _wlan_irq(cc3000_irq), _wlan_en(cc3000_en), _wlan_cs(cc3000_cs), _wlan_spi(cc3000_spi), _event(event), _simple_link(simple_link) {
+cc3000_spi::cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link, uint32_t max_tx, uint32_t max_rx)
+  : _wlan_irq(cc3000_irq), _wlan_en(cc3000_en), _wlan_cs(cc3000_cs), _wlan_spi(cc3000_spi), _event(event), _simple_link(simple_link), _max_tx(max_tx), _max_rx(max_rx) {
 
     _wlan_spi.format(8,1);
     _wlan_spi.frequency(12000000);
@@ -121,8 +121,8 @@
     // The magic number resides at the end of the TX/RX buffer (1 byte after the allocated size)
     // If the magic number is overwitten - buffer overrun occurred - we will be stuck here forever!
     uint8_t *transmit_buffer = _simple_link.get_transmit_buffer();
-    if (transmit_buffer[CC3000_TX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER) {
-        DBG_CC("System halted - TX buffer overflow detected (buffer size: %d).", CC3000_TX_BUFFER_SIZE);
+    if (transmit_buffer[_max_tx - 1] != CC3000_BUFFER_MAGIC_NUMBER) {
+        DBG_CC("System halted - TX buffer overflow detected (buffer size: %d).", _max_tx);
         while (1);
     }
 
@@ -238,8 +238,8 @@
                 // The magic number resides at the end of the TX/RX buffer (1 byte after the allocated size)
                 // If the magic number is overwitten - buffer overrun occurred - we will be stuck here forever!
                 uint8_t *received_buffer = _simple_link.get_received_buffer();
-                if (received_buffer[CC3000_RX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER) {
-                    DBG_CC("System halted - RX buffer overflow detected (buffer size: %d).", CC3000_RX_BUFFER_SIZE);
+                if (received_buffer[_max_rx - 1] != CC3000_BUFFER_MAGIC_NUMBER) {
+                    DBG_CC("System halted - RX buffer overflow detected (buffer size: %d).", _max_rx);
                     while (1);
                 }