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
allow external applications to participate in the NuttX
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 <stdbool.h>
#include <nuttx/wireless/cc3000/wlan.h>
#include <nuttx/wireless/cc3000/hci.h>
#include <nuttx/wireless/cc3000/spi.h>
#include <arch/board/kl_wifi.h>
#include <nuttx/wireless/cc3000.h>
volatile unsigned long ulSmartConfigFinished,
ulCC3000Connected,
@ -40,8 +37,6 @@ volatile unsigned long ulSmartConfigFinished,
volatile uint8_t ucStopSmartConfig;
#define NETAPP_IPCONFIG_MAC_OFFSET (20)
#define CC3000_APP_BUFFER_SIZE (5)
#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];
*/
/* The original version of the function below had Serial.prints()
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
@ -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
loop can deal with it when it wants.
*/
uint8_t asyncNotificationWaiting = false;
long lastAsyncEvent;
uint8_t dhcpIPAddress[4];
/*-------------------------------------------------------------------
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)
{
lastAsyncEvent = lEventType;
switch (lEventType) {
switch (lEventType)
{
case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE:
ulSmartConfigFinished = 1;
ucStopSmartConfig = 1;
@ -108,14 +100,17 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
// 1) IP config parameters are received swapped
// 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
if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
{
ulCC3000DHCP = 1;
dhcpIPAddress[0] = data[3];
dhcpIPAddress[1] = data[2];
dhcpIPAddress[2] = data[1];
dhcpIPAddress[3] = data[0];
}
else {
else
{
ulCC3000DHCP = 0;
dhcpIPAddress[0] = 0;
dhcpIPAddress[1] = 0;
@ -136,7 +131,6 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
}
}
/*-------------------------------------------------------------------
The TI library calls these routines on CC3000 startup.
@ -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;
return NULL;
}
char *SendDriverPatch(unsigned long *Length) {
char *SendDriverPatch(unsigned long *Length)
{
*Length = 0;
return NULL;
}
char *SendBootloaderPatch(unsigned long *Length) {
char *SendBootloaderPatch(unsigned long *Length)
{
*Length = 0;
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.
@ -196,21 +168,14 @@ void WlanInterruptDisable(void) {
--------------------------------------------------------------------*/
void CC3000_Init(void) {
void CC3000_Init(void)
{
wireless_archinitialize();
SPIInterruptsEnabled = 0;
Wlan_Setup();
wlan_init( CC3000_AsyncCallback,
CC3000_wlan_init( CC3000_AsyncCallback,
SendFirmwarePatch,
SendDriverPatch,
SendBootloaderPatch,
ReadWlanInterruptPin,
WlanInterruptEnable,
WlanInterruptDisable,
WriteWlanEnablePin);
SendBootloaderPatch);
wlan_start(0);
}

View File

@ -15,8 +15,6 @@
*
****************************************************************************
To connect an Arduino to the CC3000 you'll need to make these 6 connections
(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
called WLAN_EN
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!
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
separate power supply for it (or a voltage regulator like the LD1117V33
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
Arduino you will need a level shifter to convert these signals to 3.3V
so you don't blow up the module.
@ -86,7 +81,6 @@ Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
****************************************************************************/
#include "board.h"
#include <stdio.h>
#include <string.h>
@ -95,7 +89,7 @@ Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
#include <stdbool.h>
#include <sys/time.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/hci.h>
#include <nuttx/wireless/cc3000/security.h>
@ -122,9 +116,10 @@ void ShowInformation(void);
uint8_t isInitialized = false;
void AsyncEventPrint(void) {
switch(lastAsyncEvent) {
void AsyncEventPrint(void)
{
switch(lastAsyncEvent)
{
printf("CC3000 Async event: Simple config done\n");
break;
@ -162,12 +157,10 @@ void AsyncEventPrint(void) {
printf("AsyncCallback called with unhandled event! (0x%X)\n", lastAsyncEvent);
break;
}
}
void helpme(void) {
void helpme(void)
{
printf("\n+-------------------------------------------+\n");
printf("| Arduino CC3000 Demo Program |\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: ");
}
void execute(int cmd)
{
if (asyncNotificationWaiting) {
if (asyncNotificationWaiting)
{
asyncNotificationWaiting = false;
AsyncEventPrint();
}
switch(cmd) {
switch(cmd)
{
case '1':
Initialize();
break;
@ -220,13 +214,12 @@ void execute(int cmd)
return;
}
void Initialize(void)
{
uint8_t fancyBuffer[MAC_ADDR_LEN], i = 0;
if (isInitialized) {
if (isInitialized)
{
printf("CC3000 already initialized. Shutting down and restarting...\n");
wlan_stop();
usleep(1000000); //delay 1s
@ -236,33 +229,42 @@ void Initialize(void)
CC3000_Init();
printf(" CC3000 init complete.\n");
if (nvmem_read_sp_version(fancyBuffer)==0) {
if (nvmem_read_sp_version(fancyBuffer) == 0)
{
printf(" Firmware version is: ");
printf("%d", fancyBuffer[0]);
printf(".");
printf("%d\n", fancyBuffer[1]);
}
else {
else
{
printf("Unable to get firmware version. Can't continue.\n");
return;
}
/*if (nvmem_get_mac_address(fancyBuffer)==0) {
#if 0
if (nvmem_get_mac_address(fancyBuffer) == 0)
{
printf(" MAC address: ");
for (i=0; i<MAC_ADDR_LEN; i++) {
if (i!=0) {
for (i = 0; i < MAC_ADDR_LEN; i++)
{
if (i != 0)
{
printf(":");
}
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
}