Updated CC30000 example from David Sidrane

This commit is contained in:
Gregory Nutt 2013-10-16 07:30:54 -06:00
parent 9df979417f
commit 081396c18d
3 changed files with 613 additions and 644 deletions

View File

@ -684,4 +684,6 @@
* apps/Makefile: Need to include external/Make.defs if we want * apps/Makefile: Need to include external/Make.defs if we want
allow external applications to participate in the NuttX allow external applications to participate in the NuttX
configuration. Suggested by gdi@embedders.org (2013-10-14). configuration. Suggested by gdi@embedders.org (2013-10-14).
* apps/examplex/cc3300: Updates as part of larger re-organizaion
of CC3000 logic by David Sidrane (2013-10-16).

View File

@ -23,14 +23,11 @@
* *
****************************************************************************/ ****************************************************************************/
#include "board.h" #include "board.h"
#include <stdbool.h> #include <stdbool.h>
#include <nuttx/wireless/cc3000/wlan.h> #include <nuttx/wireless/cc3000/wlan.h>
#include <nuttx/wireless/cc3000/hci.h> #include <nuttx/wireless/cc3000/hci.h>
#include <nuttx/wireless/cc3000/spi.h> #include <nuttx/wireless/cc3000.h>
#include <arch/board/kl_wifi.h>
volatile unsigned long ulSmartConfigFinished, volatile unsigned long ulSmartConfigFinished,
ulCC3000Connected, ulCC3000Connected,
@ -40,8 +37,6 @@ volatile unsigned long ulSmartConfigFinished,
volatile uint8_t ucStopSmartConfig; volatile uint8_t ucStopSmartConfig;
#define NETAPP_IPCONFIG_MAC_OFFSET (20) #define NETAPP_IPCONFIG_MAC_OFFSET (20)
#define CC3000_APP_BUFFER_SIZE (5) #define CC3000_APP_BUFFER_SIZE (5)
#define CC3000_RX_BUFFER_OVERHEAD_SIZE (20) #define CC3000_RX_BUFFER_OVERHEAD_SIZE (20)
@ -50,7 +45,6 @@ volatile uint8_t ucStopSmartConfig;
uint8_t pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_SIZE]; uint8_t pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_SIZE];
*/ */
/* The original version of the function below had Serial.prints() /* The original version of the function below had Serial.prints()
to display an event, but since an async event can happen at any time, to display an event, but since an async event can happen at any time,
even in the middle of another Serial.print(), sometimes the sketch even in the middle of another Serial.print(), sometimes the sketch
@ -60,11 +54,11 @@ uint8_t pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_S
So now we just set a flag and write to a string, and the master So now we just set a flag and write to a string, and the master
loop can deal with it when it wants. loop can deal with it when it wants.
*/ */
uint8_t asyncNotificationWaiting = false; uint8_t asyncNotificationWaiting = false;
long lastAsyncEvent; long lastAsyncEvent;
uint8_t dhcpIPAddress[4]; uint8_t dhcpIPAddress[4];
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
The TI library calls this routine when asynchronous events happen. The TI library calls this routine when asynchronous events happen.
@ -77,14 +71,12 @@ uint8_t dhcpIPAddress[4];
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length) void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
{ {
lastAsyncEvent = lEventType; lastAsyncEvent = lEventType;
switch (lEventType) { switch (lEventType)
{
case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE: case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE:
ulSmartConfigFinished = 1; ulSmartConfigFinished = 1;
ucStopSmartConfig = 1; ucStopSmartConfig = 1;
@ -108,14 +100,17 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
// 1) IP config parameters are received swapped // 1) IP config parameters are received swapped
// 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1 // 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
// only if status is OK, the flag is set to 1 and the addresses are valid // only if status is OK, the flag is set to 1 and the addresses are valid
if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
{
ulCC3000DHCP = 1; ulCC3000DHCP = 1;
dhcpIPAddress[0] = data[3]; dhcpIPAddress[0] = data[3];
dhcpIPAddress[1] = data[2]; dhcpIPAddress[1] = data[2];
dhcpIPAddress[2] = data[1]; dhcpIPAddress[2] = data[1];
dhcpIPAddress[3] = data[0]; dhcpIPAddress[3] = data[0];
} }
else { else
{
ulCC3000DHCP = 0; ulCC3000DHCP = 0;
dhcpIPAddress[0] = 0; dhcpIPAddress[0] = 0;
dhcpIPAddress[1] = 0; dhcpIPAddress[1] = 0;
@ -134,8 +129,7 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
asyncNotificationWaiting=true; asyncNotificationWaiting=true;
break; break;
} }
} }
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
@ -146,46 +140,24 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
char *SendFirmwarePatch(unsigned long *Length) { char *SendFirmwarePatch(unsigned long *Length)
{
*Length = 0; *Length = 0;
return NULL; return NULL;
} }
char *SendDriverPatch(unsigned long *Length)
char *SendDriverPatch(unsigned long *Length) { {
*Length = 0; *Length = 0;
return NULL; return NULL;
} }
char *SendBootloaderPatch(unsigned long *Length)
char *SendBootloaderPatch(unsigned long *Length) { {
*Length = 0; *Length = 0;
return NULL; return NULL;
} }
/*-------------------------------------------------------------------
The TI library calls these routines to enable or disable interrupts
on the WLAN_IRQ pin.
Originally WlanInterruptEnable() called attachInterrupt() and
WlanInterruptDisable() called detachInterrupt() but the library
was occationally locking up here, so now these routines just
set a flag. The interrupt routine will always fire but if the
flag isn't set it just returns immediately.
--------------------------------------------------------------------*/
void WlanInterruptEnable(void) {
SPIInterruptsEnabled = 1;
}
void WlanInterruptDisable(void) {
SPIInterruptsEnabled = 0;
}
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
This is my routine to simplify CC3000 startup. This is my routine to simplify CC3000 startup.
@ -196,21 +168,14 @@ void WlanInterruptDisable(void) {
--------------------------------------------------------------------*/ --------------------------------------------------------------------*/
void CC3000_Init(void) { void CC3000_Init(void)
{
wireless_archinitialize();
SPIInterruptsEnabled = 0; CC3000_wlan_init( CC3000_AsyncCallback,
Wlan_Setup();
wlan_init( CC3000_AsyncCallback,
SendFirmwarePatch, SendFirmwarePatch,
SendDriverPatch, SendDriverPatch,
SendBootloaderPatch, SendBootloaderPatch);
ReadWlanInterruptPin,
WlanInterruptEnable,
WlanInterruptDisable,
WriteWlanEnablePin);
wlan_start(0); wlan_start(0);
} }

View File

@ -15,8 +15,6 @@
* *
**************************************************************************** ****************************************************************************
To connect an Arduino to the CC3000 you'll need to make these 6 connections To connect an Arduino to the CC3000 you'll need to make these 6 connections
(in addition to the WiFi antenna, power etc). (in addition to the WiFi antenna, power etc).
@ -54,17 +52,14 @@ VBAT_SW_EN / 26 / J5-5 Module enable
on. Any pin can be used. In this program it will be on. Any pin can be used. In this program it will be
called WLAN_EN called WLAN_EN
WARNING #1: The CC3000 runs at 3.6V maximum so you can't run it from your WARNING #1: The CC3000 runs at 3.6V maximum so you can't run it from your
regular 5V Arduino power pin. Run it from 3.3V! regular 5V Arduino power pin. Run it from 3.3V!
WARNING #2: When transmitting the CC3000 will use up to 275mA current. Most WARNING #2: When transmitting the CC3000 will use up to 275mA current. Most
Arduinos' 3.3V pins can only supply up to 50mA current, so you'll need a Arduinos' 3.3V pins can only supply up to 50mA current, so you'll need a
separate power supply for it (or a voltage regulator like the LD1117V33 separate power supply for it (or a voltage regulator like the LD1117V33
connected to your Arduino's 5V power pin). connected to your Arduino's 5V power pin).
WARNING #3: The CC3000's IO pins are not 5V tolerant. If you're using a 5V WARNING #3: The CC3000's IO pins are not 5V tolerant. If you're using a 5V
Arduino you will need a level shifter to convert these signals to 3.3V Arduino you will need a level shifter to convert these signals to 3.3V
so you don't blow up the module. so you don't blow up the module.
@ -86,7 +81,6 @@ Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
****************************************************************************/ ****************************************************************************/
#include "board.h" #include "board.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -95,7 +89,7 @@ Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
#include <stdbool.h> #include <stdbool.h>
#include <sys/time.h> #include <sys/time.h>
#include <nuttx/wireless/cc3000/nvmem.h> #include <nuttx/wireless/cc3000/nvmem.h>
#include <nuttx/wireless/cc3000/socket.h> #include <nuttx/wireless/cc3000/include/sys/socket.h>
#include <nuttx/wireless/cc3000/wlan.h> #include <nuttx/wireless/cc3000/wlan.h>
#include <nuttx/wireless/cc3000/hci.h> #include <nuttx/wireless/cc3000/hci.h>
#include <nuttx/wireless/cc3000/security.h> #include <nuttx/wireless/cc3000/security.h>
@ -122,9 +116,10 @@ void ShowInformation(void);
uint8_t isInitialized = false; uint8_t isInitialized = false;
void AsyncEventPrint(void)
void AsyncEventPrint(void) { {
switch(lastAsyncEvent) { switch(lastAsyncEvent)
{
printf("CC3000 Async event: Simple config done\n"); printf("CC3000 Async event: Simple config done\n");
break; break;
@ -162,12 +157,10 @@ void AsyncEventPrint(void) {
printf("AsyncCallback called with unhandled event! (0x%X)\n", lastAsyncEvent); printf("AsyncCallback called with unhandled event! (0x%X)\n", lastAsyncEvent);
break; break;
} }
}
} void helpme(void)
{
void helpme(void) {
printf("\n+-------------------------------------------+\n"); printf("\n+-------------------------------------------+\n");
printf("| Arduino CC3000 Demo Program |\n"); printf("| Arduino CC3000 Demo Program |\n");
printf("+-------------------------------------------+\n\n"); printf("+-------------------------------------------+\n\n");
@ -181,15 +174,16 @@ void helpme(void) {
printf("\n Type 1-7 to select above option or (q/Q) to quit: "); printf("\n Type 1-7 to select above option or (q/Q) to quit: ");
} }
void execute(int cmd) void execute(int cmd)
{ {
if (asyncNotificationWaiting) { if (asyncNotificationWaiting)
{
asyncNotificationWaiting = false; asyncNotificationWaiting = false;
AsyncEventPrint(); AsyncEventPrint();
} }
switch(cmd) { switch(cmd)
{
case '1': case '1':
Initialize(); Initialize();
break; break;
@ -220,13 +214,12 @@ void execute(int cmd)
return; return;
} }
void Initialize(void) void Initialize(void)
{ {
uint8_t fancyBuffer[MAC_ADDR_LEN], i = 0; uint8_t fancyBuffer[MAC_ADDR_LEN], i = 0;
if (isInitialized) { if (isInitialized)
{
printf("CC3000 already initialized. Shutting down and restarting...\n"); printf("CC3000 already initialized. Shutting down and restarting...\n");
wlan_stop(); wlan_stop();
usleep(1000000); //delay 1s usleep(1000000); //delay 1s
@ -236,33 +229,42 @@ void Initialize(void)
CC3000_Init(); CC3000_Init();
printf(" CC3000 init complete.\n"); printf(" CC3000 init complete.\n");
if (nvmem_read_sp_version(fancyBuffer)==0) { if (nvmem_read_sp_version(fancyBuffer) == 0)
{
printf(" Firmware version is: "); printf(" Firmware version is: ");
printf("%d", fancyBuffer[0]); printf("%d", fancyBuffer[0]);
printf("."); printf(".");
printf("%d\n", fancyBuffer[1]); printf("%d\n", fancyBuffer[1]);
} }
else { else
{
printf("Unable to get firmware version. Can't continue.\n"); printf("Unable to get firmware version. Can't continue.\n");
return; return;
} }
/*if (nvmem_get_mac_address(fancyBuffer)==0) { #if 0
if (nvmem_get_mac_address(fancyBuffer) == 0)
{
printf(" MAC address: "); printf(" MAC address: ");
for (i=0; i<MAC_ADDR_LEN; i++) { for (i = 0; i < MAC_ADDR_LEN; i++)
if (i!=0) { {
if (i != 0)
{
printf(":"); printf(":");
} }
printf("%X", fancyBuffer[i]); printf("%X", fancyBuffer[i]);
} }
printf("\n");
*/
isInitialized=true;
/*}
else {
printf("Unable to get MAC address. Can't continue.\n");
}*/
printf("\n");
isInitialized = true;
}
else
{
printf("Unable to get MAC address. Can't continue.\n");
}
#else
isInitialized = true;
#endif
} }