Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CC3000HostDriver mbed
CC3000Core.cpp
00001 00002 00003 00004 #include "mbed.h" 00005 #include "wlan.h" 00006 #include "cc3000.h" 00007 #include "CC3000Core.h" 00008 #include "hci.h" 00009 #include "CC3000TestApp.h" 00010 #include "spi.h" 00011 #include "DigitalClass.h" 00012 00013 extern volatile unsigned long ulSmartConfigFinished; 00014 volatile unsigned long //ulSmartConfigFinished, 00015 ulCC3000Connected, 00016 ulCC3000DHCP, 00017 OkToDoShutDown, 00018 ulCC3000DHCP_configured; 00019 00020 volatile unsigned char ucStopSmartConfig; 00021 00022 #define NETAPP_IPCONFIG_MAC_OFFSET (20) 00023 #define CC3000_APP_BUFFER_SIZE (5) 00024 #define CC3000_RX_BUFFER_OVERHEAD_SIZE (20) 00025 00026 DigitalClass Dio(p9, p10); 00027 InterruptIn irq(p9); 00028 /* 00029 unsigned char pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_SIZE]; 00030 */ 00031 00032 /* The original version of the function below had Serial.prints() 00033 to display an event, but since an async event can happen at any time, 00034 even in the middle of another Serial.print(), sometimes the sketch 00035 would lock up because we were trying to print in the middle of 00036 a print. 00037 00038 So now we just set a flag and write to a string, and the master 00039 loop can deal with it when it wants. 00040 */ 00041 int8_t asyncNotificationWaiting=false; 00042 long lastAsyncEvent; 00043 int8_t dhcpIPAddress[4]; 00044 00045 00046 00047 00048 00049 00050 00051 00052 /*------------------------------------------------------------------- 00053 00054 The TI library calls this routine when asynchronous events happen. 00055 00056 For example you tell the CC3000 to turn itself on and connect 00057 to an access point then your code can go on to do its own thing. 00058 When the CC3000 is done configuring itself (e.g. it gets an IP 00059 address from the DHCP server) it will call this routine so you 00060 can take appropriate action. 00061 00062 ---------------------------------------------------------------------*/ 00063 00064 00065 void CC3000_AsynchCallback(long lEventType, char * data, unsigned char length) { 00066 00067 switch (lEventType) { 00068 00069 case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE: 00070 ulSmartConfigFinished = 1; 00071 ucStopSmartConfig = 1; 00072 printf("CC3000 Async event: Simple config done\r\n"); 00073 break; 00074 00075 case HCI_EVNT_WLAN_UNSOL_CONNECT: 00076 ulCC3000Connected = 1; 00077 setCC3000MachineState(CC3000_INIT); 00078 printf("CC3000 Async event: Unsolicited connect\r\n"); 00079 setCC3000MachineState(CC3000_ASSOC); 00080 break; 00081 00082 case HCI_EVNT_WLAN_UNSOL_DISCONNECT: 00083 ulCC3000Connected = 0; 00084 ulCC3000DHCP = 0; 00085 ulCC3000DHCP_configured = 0; 00086 unsetCC3000MachineState(CC3000_ASSOC); 00087 printf("CC3000 Async event: Unsolicted disconnect\r\n"); 00088 break; 00089 00090 case HCI_EVNT_WLAN_UNSOL_DHCP: 00091 // Notes: 00092 // 1) IP config parameters are received swapped 00093 // 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1 00094 // only if status is OK, the flag is set to 1 and the addresses are valid 00095 if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) { 00096 ulCC3000DHCP = 1; 00097 setCC3000MachineState(CC3000_IP_ALLOC); 00098 printf("CC3000 Async event: Got IP address via DHCP: "); 00099 printf("%i",data[3]); printf("."); 00100 printf("%i",data[2]); printf("."); 00101 printf("%i",data[1]); printf("."); 00102 printf("%i",data[0]); 00103 printf("\r\n"); 00104 } 00105 else { 00106 ulCC3000DHCP = 0; 00107 printf("CC3000 Async event: Unsolicited DHCP, no IP address\r\n"); 00108 } 00109 break; 00110 00111 case HCI_EVENT_CC3000_CAN_SHUT_DOWN: 00112 OkToDoShutDown = 1; 00113 printf("CC3000 Async event: OK to shut down\r\n"); 00114 break; 00115 00116 } 00117 } 00118 00119 00120 00121 long ReadWlanInterruptPin(void) { 00122 int8_t val; 00123 //printf("WLAN_IRQ %i \r\n",Dio.WLAN_IRQ.read()); 00124 val = Dio.WLAN_IRQ.read(); 00125 return (long)val; 00126 } 00127 00128 00129 void WriteWlanPin( unsigned char val ) { 00130 00131 if (val) { 00132 Dio.WLAN_EN = 1; 00133 //printf("WLAN_EN %i \r\n",val); 00134 } 00135 else { 00136 Dio.WLAN_EN = 0; 00137 //printf("WLAN_EN %i \r\n",val); 00138 } 00139 } 00140 00141 void WlanInterruptEnable(void) { 00142 00143 int8_t val; 00144 irq.fall(&IntSpi); 00145 00146 //__enable_irq(); //Enable Interrupts 00147 //SPIInterruptsEnabled = 1; 00148 } 00149 00150 00151 void WlanInterruptDisable(void) { 00152 00153 irq.fall(NULL); 00154 00155 //__disable_irq(); //Disable Interrupts 00156 //SPIInterruptsEnabled = 0; 00157 } 00158 00159 char *SendFirmwarePatch(unsigned long *Length) { 00160 *Length = 0; 00161 return NULL; 00162 } 00163 00164 00165 00166 char *SendDriverPatch(unsigned long *Length) { 00167 *Length = 0; 00168 return NULL; 00169 } 00170 00171 00172 char *SendBootloaderPatch(unsigned long *Length) { 00173 *Length = 0; 00174 return NULL; 00175 } 00176 00177
Generated on Sun Jul 24 2022 00:54:51 by
1.7.2