diff options
Diffstat (limited to 'apps/examples/cc3000/board.c')
-rw-r--r-- | apps/examples/cc3000/board.c | 165 |
1 files changed, 81 insertions, 84 deletions
diff --git a/apps/examples/cc3000/board.c b/apps/examples/cc3000/board.c index bca494b7f..009b56663 100644 --- a/apps/examples/cc3000/board.c +++ b/apps/examples/cc3000/board.c @@ -1,27 +1,29 @@ -/************************************************************************** -* -* ArduinoCC3000Core.cpp - Wrapper routines to make interfacing the Arduino -* and the TI CC3000 easier. -* -* This code is based on the TI sample code "Basic WiFi Application" -* and has the callback routines that TI expects for their library. -* -* TI uses callback routines to make their library portable: these routines, -* and the routines in the SPI files, will be different for an Arduino, -* a TI MSP430, a PIC, etc. but the core library shouldn't have to be -* changed. -* -* Version 1.0.1b -* -* Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* -* Don't sue me if my code blows up your board and burns down your house -* -****************************************************************************/ +/**************************************************************************** + * apps/examples/cc3000/board.c + * + * This code is based on the TI sample code "Basic WiFi Application" + * and has the callback routines that TI expects for their library. + * + * TI uses callback routines to make their library portable: these routines, + * and the routines in the SPI files, will be different for an Arduino, + * a TI MSP430, a PIC, etc. but the core library shouldn't have to be + * changed. + * + * Derives from an application to demo an Arduino connected to the TI CC3000 + * + * Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Don't sue me if my code blows up your board and burns down your house + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "board.h" #include <stdbool.h> @@ -29,47 +31,41 @@ #include <nuttx/wireless/cc3000/hci.h> #include <nuttx/wireless/cc3000.h> -volatile unsigned long ulSmartConfigFinished, - ulCC3000Connected, - ulCC3000DHCP, - OkToDoShutDown, - ulCC3000DHCP_configured; - -volatile uint8_t ucStopSmartConfig; +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ #define NETAPP_IPCONFIG_MAC_OFFSET (20) #define CC3000_APP_BUFFER_SIZE (5) #define CC3000_RX_BUFFER_OVERHEAD_SIZE (20) -/* -uint8_t pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_SIZE]; -*/ +/**************************************************************************** + * Public Data + ****************************************************************************/ -/* 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 - would lock up because we were trying to print in the middle of - a print. +volatile unsigned long ulSmartConfigFinished, + ulCC3000Connected, + ulCC3000DHCP, + OkToDoShutDown, + ulCC3000DHCP_configured; - So now we just set a flag and write to a string, and the master - loop can deal with it when it wants. -*/ +volatile uint8_t ucStopSmartConfig; uint8_t asyncNotificationWaiting = false; long lastAsyncEvent; uint8_t dhcpIPAddress[4]; -/*------------------------------------------------------------------- - - The TI library calls this routine when asynchronous events happen. - - For example you tell the CC3000 to turn itself on and connect - to an access point then your code can go on to do its own thing. - When the CC3000 is done configuring itself (e.g. it gets an IP - address from the DHCP server) it will call this routine so you - can take appropriate action. - ----------------------------------------------------------------------*/ +/**************************************************************************** + * Public Functions + ****************************************************************************/ +/* The TI library calls this routine when asynchronous events happen. + * + * For example you tell the CC3000 to turn itself on and connect + * to an access point then your code can go on to do its own thing. + * When the CC3000 is done configuring itself (e.g. it gets an IP + * address from the DHCP server) it will call this routine so you + * can take appropriate action. + */ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length) { @@ -82,24 +78,25 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length) ucStopSmartConfig = 1; asyncNotificationWaiting=true; break; - + case HCI_EVNT_WLAN_UNSOL_CONNECT: ulCC3000Connected = 1; asyncNotificationWaiting=true; break; - + case HCI_EVNT_WLAN_UNSOL_DISCONNECT: ulCC3000Connected = 0; ulCC3000DHCP = 0; - ulCC3000DHCP_configured = 0; + ulCC3000DHCP_configured = 0; asyncNotificationWaiting=true; break; - + case HCI_EVNT_WLAN_UNSOL_DHCP: - // Notes: - // 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 + /* Notes: + * 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) { @@ -119,26 +116,23 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length) } asyncNotificationWaiting=true; break; - + case HCI_EVENT_CC3000_CAN_SHUT_DOWN: OkToDoShutDown = 1; asyncNotificationWaiting=true; break; - + default: asyncNotificationWaiting=true; - break; + break; } } -/*------------------------------------------------------------------- - - The TI library calls these routines on CC3000 startup. - - This library does not send firmware, driver, or bootloader patches - so we do nothing and we return NULL. - ----------------------------------------------------------------------*/ +/* The TI library calls these routines on CC3000 startup. + * + * This library does not send firmware, driver, or bootloader patches + * so we do nothing and we return NULL. + */ char *SendFirmwarePatch(unsigned long *Length) { @@ -158,24 +152,27 @@ char *SendBootloaderPatch(unsigned long *Length) return NULL; } -/*------------------------------------------------------------------- - - This is my routine to simplify CC3000 startup. - - It sets the Arduino pins then calls the normal CC3000 routines - wlan_init() with all the callbacks and wlan_start() with 0 - to indicate we're not sending any patches. - - --------------------------------------------------------------------*/ +/* This is my routine to simplify CC3000 startup. + * + * It sets the Arduino pins then calls the normal CC3000 routines + * wlan_init() with all the callbacks and wlan_start() with 0 + * to indicate we're not sending any patches. + */ void CC3000_Init(void) { - wireless_archinitialize(); - + static bool once = false; + + if (!once) + { + wireless_archinitialize(); + once = true; + } + CC3000_wlan_init( CC3000_AsyncCallback, SendFirmwarePatch, SendDriverPatch, SendBootloaderPatch); - + wlan_start(0); } |