aboutsummaryrefslogtreecommitdiff
path: root/stmhal/cc3k/src
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-09-02 00:05:13 +0100
committerDamien George <damien.p.george@gmail.com>2014-09-02 00:05:13 +0100
commita2ee194612fee8b6c0924f999acf8c41f4207e8d (patch)
tree160750dafb972d62775c2cc17e77b6e3e4fe2c56 /stmhal/cc3k/src
parent6f70542d82c529173161275b0a21f090fecfddb2 (diff)
cc3k: Change configurability of the CC3000 module.iabdalkader-cc3k-update
Optional compiling of the CC3K module is moved from mpconfigboard.h. To enable compiling of the module, set the MICROPY_PY_CC3K variable, either on the command line (make MICROPY_PY_CC3K=1) on in the mpconfigport.mk file. It is enabled by default. Setting of the SPI and pins for the CC3K module is now done dynamically by the arguments to wlan.init().
Diffstat (limited to 'stmhal/cc3k/src')
-rw-r--r--stmhal/cc3k/src/cc3000_common.c3
-rw-r--r--stmhal/cc3k/src/ccspi.c88
-rw-r--r--stmhal/cc3k/src/evnt_handler.c3
-rw-r--r--stmhal/cc3k/src/hci.c3
-rw-r--r--stmhal/cc3k/src/inet_ntop.c4
-rw-r--r--stmhal/cc3k/src/inet_pton.c3
-rw-r--r--stmhal/cc3k/src/netapp.c3
-rw-r--r--stmhal/cc3k/src/nvmem.c3
-rw-r--r--stmhal/cc3k/src/patch_prog.c4
-rw-r--r--stmhal/cc3k/src/security.c3
-rw-r--r--stmhal/cc3k/src/socket.c3
-rw-r--r--stmhal/cc3k/src/wlan.c3
12 files changed, 46 insertions, 77 deletions
diff --git a/stmhal/cc3k/src/cc3000_common.c b/stmhal/cc3k/src/cc3000_common.c
index 7759cb20f..b4c87848c 100644
--- a/stmhal/cc3k/src/cc3000_common.c
+++ b/stmhal/cc3k/src/cc3000_common.c
@@ -43,8 +43,6 @@
* Include files
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "cc3000_common.h"
#include "socket.h"
@@ -164,4 +162,3 @@ UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/ccspi.c b/stmhal/cc3k/src/ccspi.c
index 0352c6e40..2abc637fe 100644
--- a/stmhal/cc3k/src/ccspi.c
+++ b/stmhal/cc3k/src/ccspi.c
@@ -31,8 +31,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
@@ -44,7 +42,6 @@
#include "obj.h"
#include "runtime.h"
#include "pin.h"
-#include "genhdr/pins.h"
#include "led.h"
#include "extint.h"
#include "spi.h"
@@ -58,14 +55,14 @@
#define DEBUG_printf(args...) (void)0
#endif
-#define PIN_CS MICROPY_HW_WLAN_PIN_CS
-#define PIN_EN MICROPY_HW_WLAN_PIN_EN
-#define PIN_IRQ MICROPY_HW_WLAN_PIN_IRQ
-#define SPI_HANDLE MICROPY_HW_WLAN_SPI_HANDLE
-#define IRQ_LINE MICROPY_HW_WLAN_IRQ_LINE
+// these need to be set to valid values before anything in this file will work
+STATIC SPI_HandleTypeDef *SPI_HANDLE = NULL;
+STATIC const pin_obj_t *PIN_CS = NULL;
+STATIC const pin_obj_t *PIN_EN = NULL;
+STATIC const pin_obj_t *PIN_IRQ = NULL;
-#define CS_LOW() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_RESET)
-#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET)
+#define CS_LOW() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_RESET)
+#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET)
#define READ 3
#define WRITE 1
@@ -106,10 +103,19 @@ tSpiInformation sSpiInformation;
char spi_buffer[CC3000_RX_BUFFER_SIZE];
unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE];
-static const mp_obj_fun_native_t irq_callback_obj;
+STATIC const mp_obj_fun_builtin_t irq_callback_obj;
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
+// set the pins to use to communicate with the CC3000
+// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
+void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq) {
+ SPI_HANDLE = spi;
+ PIN_CS = pin_cs;
+ PIN_EN = pin_en;
+ PIN_IRQ = pin_irq;
+}
+
void SpiClose(void)
{
if (sSpiInformation.pRxPacket) {
@@ -118,7 +124,7 @@ void SpiClose(void)
tSLInformation.WlanInterruptDisable();
- //HAL_SPI_DeInit(&SPI_HANDLE);
+ //HAL_SPI_DeInit(SPI_HANDLE);
}
void SpiOpen(gcSpiHandleRx pfRxHandler)
@@ -136,18 +142,18 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
/* SPI configuration */
- SPI_HANDLE.Init.Mode = SPI_MODE_MASTER;
- SPI_HANDLE.Init.Direction = SPI_DIRECTION_2LINES;
- SPI_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
- SPI_HANDLE.Init.CLKPolarity = SPI_POLARITY_LOW;
- SPI_HANDLE.Init.CLKPhase = SPI_PHASE_2EDGE;
- SPI_HANDLE.Init.NSS = SPI_NSS_SOFT;
- SPI_HANDLE.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
- SPI_HANDLE.Init.FirstBit = SPI_FIRSTBIT_MSB;
- SPI_HANDLE.Init.TIMode = SPI_TIMODE_DISABLED;
- SPI_HANDLE.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
- SPI_HANDLE.Init.CRCPolynomial = 7;
- spi_init(&SPI_HANDLE);
+ SPI_HANDLE->Init.Mode = SPI_MODE_MASTER;
+ SPI_HANDLE->Init.Direction = SPI_DIRECTION_2LINES;
+ SPI_HANDLE->Init.DataSize = SPI_DATASIZE_8BIT;
+ SPI_HANDLE->Init.CLKPolarity = SPI_POLARITY_LOW;
+ SPI_HANDLE->Init.CLKPhase = SPI_PHASE_2EDGE;
+ SPI_HANDLE->Init.NSS = SPI_NSS_SOFT;
+ SPI_HANDLE->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
+ SPI_HANDLE->Init.FirstBit = SPI_FIRSTBIT_MSB;
+ SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
+ SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
+ SPI_HANDLE->Init.CRCPolynomial = 7;
+ spi_init(SPI_HANDLE);
// configure wlan CS and EN pins
GPIO_InitTypeDef GPIO_InitStructure;
@@ -156,48 +162,48 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = 0;
- GPIO_InitStructure.Pin = PIN_CS.pin_mask;
- HAL_GPIO_Init(PIN_CS.gpio, &GPIO_InitStructure);
+ GPIO_InitStructure.Pin = PIN_CS->pin_mask;
+ HAL_GPIO_Init(PIN_CS->gpio, &GPIO_InitStructure);
- GPIO_InitStructure.Pin = PIN_EN.pin_mask;
- HAL_GPIO_Init(PIN_EN.gpio, &GPIO_InitStructure);
+ GPIO_InitStructure.Pin = PIN_EN->pin_mask;
+ HAL_GPIO_Init(PIN_EN->gpio, &GPIO_InitStructure);
- HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET);
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask, GPIO_PIN_RESET);
+ HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET);
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask, GPIO_PIN_RESET);
/* do a dummy read, this ensures SCLK is low before
actual communications start, it might be required */
CS_LOW();
uint8_t buf[1];
- HAL_SPI_Receive(&SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
+ HAL_SPI_Receive(SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
CS_HIGH();
// register EXTI
- extint_register((mp_obj_t)&PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
- extint_enable(IRQ_LINE);
+ extint_register((mp_obj_t)PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
+ extint_enable(PIN_IRQ->pin);
- DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ.pin, IRQ_LINE);
+ DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ->pin, PIN_IRQ->pin);
}
void SpiPauseSpi(void)
{
- extint_disable(IRQ_LINE);
+ extint_disable(PIN_IRQ->pin);
}
void SpiResumeSpi(void)
{
- extint_enable(IRQ_LINE);
+ extint_enable(PIN_IRQ->pin);
}
long ReadWlanInterruptPin(void)
{
- return HAL_GPIO_ReadPin(PIN_IRQ.gpio, PIN_IRQ.pin_mask);
+ return HAL_GPIO_ReadPin(PIN_IRQ->gpio, PIN_IRQ->pin_mask);
}
void WriteWlanPin(unsigned char val)
{
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask,
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask,
(WLAN_ENABLE)? GPIO_PIN_SET:GPIO_PIN_RESET);
}
@@ -306,7 +312,7 @@ void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
{
DEBUG_printf("SpiWriteDataSynchronous(data=%p [%x %x %x %x], size=%u)\n", data, data[0], data[1], data[2], data[3], size);
__disable_irq();
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
//BREAK();
}
__enable_irq();
@@ -317,7 +323,7 @@ void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
{
memset(data, READ, size);
__disable_irq();
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
//BREAK();
}
__enable_irq();
@@ -453,5 +459,3 @@ STATIC mp_obj_t irq_callback(mp_obj_t line)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(irq_callback_obj, irq_callback);
-
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/evnt_handler.c b/stmhal/cc3k/src/evnt_handler.c
index 2733408b7..80f34e469 100644
--- a/stmhal/cc3k/src/evnt_handler.c
+++ b/stmhal/cc3k/src/evnt_handler.c
@@ -42,8 +42,6 @@
//******************************************************************************
// INCLUDE FILES
//******************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "cc3000_common.h"
#include "string.h"
@@ -849,4 +847,3 @@ void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/hci.c b/stmhal/cc3k/src/hci.c
index d476b3b33..4391692b8 100644
--- a/stmhal/cc3k/src/hci.c
+++ b/stmhal/cc3k/src/hci.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "cc3000_common.h"
@@ -225,4 +223,3 @@ void hci_patch_send(UINT8 ucOpcode, UINT8 *pucBuff, CHAR *patch, UINT16 usDataLe
//
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/inet_ntop.c b/stmhal/cc3k/src/inet_ntop.c
index 1d03c82b0..1b7e01a23 100644
--- a/stmhal/cc3k/src/inet_ntop.c
+++ b/stmhal/cc3k/src/inet_ntop.c
@@ -15,9 +15,6 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#include <std.h>
#include <string.h>
#include "cc3000_common.h"
@@ -197,4 +194,3 @@ char *inet_ntop(int af, const void *src, char *buf, size_t size)
return NULL;
}
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/inet_pton.c b/stmhal/cc3k/src/inet_pton.c
index 8193d173a..88c785866 100644
--- a/stmhal/cc3k/src/inet_pton.c
+++ b/stmhal/cc3k/src/inet_pton.c
@@ -15,8 +15,6 @@
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "cc3000_common.h"
@@ -216,4 +214,3 @@ static int inet_pton6(const char *src, unsigned char *dst)
return (1);
}
#endif /* ENABLE_IPV6 */
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/netapp.c b/stmhal/cc3k/src/netapp.c
index a0f75894d..a6f60feda 100644
--- a/stmhal/cc3k/src/netapp.c
+++ b/stmhal/cc3k/src/netapp.c
@@ -32,8 +32,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "netapp.h"
@@ -459,4 +457,3 @@ INT32 netapp_set_debug_level(UINT32 ulLevel)
}
#endif
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/nvmem.c b/stmhal/cc3k/src/nvmem.c
index 4897ab3a6..c6e170a74 100644
--- a/stmhal/cc3k/src/nvmem.c
+++ b/stmhal/cc3k/src/nvmem.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "nvmem.h"
@@ -334,4 +332,3 @@ INT32 nvmem_create_entry(UINT32 ulFileId, UINT32 ulNewLen)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/patch_prog.c b/stmhal/cc3k/src/patch_prog.c
index cda312036..fd128928f 100644
--- a/stmhal/cc3k/src/patch_prog.c
+++ b/stmhal/cc3k/src/patch_prog.c
@@ -1,6 +1,3 @@
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#include <stdio.h>
#include <string.h>
#include "cc3000_common.h"
@@ -415,4 +412,3 @@ void patch_prog_start()
// Patch update done
printf("All done, call wlan.patch_version()\n");
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/security.c b/stmhal/cc3k/src/security.c
index e2ddb32da..62b4f8813 100644
--- a/stmhal/cc3k/src/security.c
+++ b/stmhal/cc3k/src/security.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "security.h"
@@ -530,4 +528,3 @@ INT32 aes_write_key(UINT8 *key)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/socket.c b/stmhal/cc3k/src/socket.c
index ea7e59799..bcc608e5f 100644
--- a/stmhal/cc3k/src/socket.c
+++ b/stmhal/cc3k/src/socket.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include <stdlib.h>
@@ -1182,4 +1180,3 @@ UINT16 getmssvalue (INT32 sd)
return ret;
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/wlan.c b/stmhal/cc3k/src/wlan.c
index ff010519f..0514d1150 100644
--- a/stmhal/cc3k/src/wlan.c
+++ b/stmhal/cc3k/src/wlan.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "wlan.h"
@@ -1252,4 +1250,3 @@ INT32 wlan_smart_config_process()
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K