Driver for CC3000 Wi-Fi module
Dependencies: NVIC_set_all_priorities
Dependents: CC3000_Simple_Socket Wi-Go_IOT_Demo
Information
The current code has been reworked to a full object oriented application and contains an mbed socket compatible API.
CC3000 Wi-Fi module library
Info
This is the low level driver for TI's SimpleLink CC3000 device.
Port from Avnet's Wi-Go KEIL code (based on TI's CC3000 code).
Special thanks to Jim Carver from Avnet for providing the Wi-Go board and for his assistance.
Differences with TI's original code
The code functionality stays exactly the same.
In order to make it easier to use the code, following changes were made :
- Addition of a tool to shift all IRQ priorities to a lower level since it is very important to keep the SPI handler at the highest system priority, the WLAN interrupt the second highest and all other system interrupts at a lower priority, so their handlers can be preempted by the CC3000 interrupts.
- Addition of low level I/O controls and conditional compiler controls in cc3000_common.h.
- CC3000 initialisation, pin declarations, SPI and WLAN irq priorities are set in
Init_HostDriver
, we need to call this function at the start of the main function. - The SPI and HCI code are joined into one file.
- The include list has been rearranged - Only
#include "wlan.h"
is needed in the user API.
- Part of the CC3000's user eeprom memory is used to store additional info (52 bytes in NVMEM_USER_FILE_1):
# bytes | Description | Info |
1 | First time config parameter | Useful when connecting |
2 | Firmware updater version | used with the Firmware update tool |
2 | Service Pack version | used with the Firmware update tool |
3 | Driver Version | used with the Firmware update tool |
3 | Firmware Version | used with the Firmware update tool |
1 | CIK validation (Client Interface Key) | |
40 | CIK data (Client Interface Key) | used with the exosite |
Using the Library
A user API is needed to access the CC3000 functions.
Examples:
- Internet Of Things full WiGo demo (SmartConfig - WebServer - Exosite - Android sensor Fusion App)
- CC3000_Simple_Socket
Using the library with other processors
cc3000_common.cpp
loads the irq tool for all targets:
All current mbed targets are supported by this library.
#include "NVIC_set_all_priorities.h"
All low level settings that need to change are available in cc3000_common.h
//***************************************************************************** // PIN CONTROLS & COMPILE CONTROLS //***************************************************************************** // Compiler control #define CC3000_UNENCRYPTED_SMART_CONFIG // No encryption //#define CC3000_TINY_DRIVER // Driver for small memory model CPUs //Interrupt controls #define NVIC_ALL_IRQ NVIC_set_all_irq_priorities(3); // Set ALL interrupt priorities to level 3 #define NVIC_SPI_IRQ NVIC_SetPriority(SPI0_IRQn, 0x0); // Wi-Fi SPI interrupt must be higher priority than SysTick #define NVIC_PORT_IRQ NVIC_SetPriority(PORTA_IRQn, 0x1); #define NVIC_SYSTICK_IRQ NVIC_SetPriority(SysTick_IRQn, 0x2); // SysTick set to lower priority than Wi-Fi SPI bus interrupt //#define NVIC_ADC_IRQ NVIC_SetPriority(ADC0_IRQn, 0x3); // ADC is the lowest of all // Wlan controls #define WLAN_ISF_PCR PORTA->PCR[16] #define WLAN_ISF_ISFR PORTA->ISFR #define WLAN_ISF_MASK (1<<16) #define WLAN_ASSERT_CS wlan_cs = 0; //CS : active low #define WLAN_DEASSERT_CS wlan_cs = 1; #define WLAN_ASSERT_EN wlan_en = 1; //EN : active high #define WLAN_DEASSERT_EN wlan_en = 0; #define WLAN_READ_IRQ wlan_int #define WLAN_ENABLE_IRQ wlan_int.fall(&WLAN_IRQHandler); #define WLAN_DISABLE_IRQ wlan_int.fall(NULL); #define WLAN_IRQ_PIN_CREATE InterruptIn wlan_int (PTA16); #define WLAN_EN_PIN_CREATE DigitalOut wlan_en (PTA13); #define WLAN_CS_PIN_CREATE DigitalOut wlan_cs (PTD0); #define WLAN_SPI_PORT_CREATE SPI wlan(PTD2, PTD3, PTC5); // mosi, miso, sclk #define WLAN_SPI_PORT_INIT wlan.format(8,1); #define WLAN_SPI_SET_FREQ wlan.frequency(12000000); #define WLAN_SPI_SET_IRQ_HANDLER wlan_int.fall(&WLAN_IRQHandler); #define WLAN_SPI_WRITE wlan.write(*data++); #define WLAN_SPI_READ wlan.write(0x03); // !! DO NOT MODIFY the 0x03 parameter (CC3000 will not respond).
API documentation
Due to a little problem with the links on the mbed site, the API documentation is not directly accessible (will be solved in a next release).
Currently, it is only accessible by adding modules.html
to the API doc link: http://mbed.org/users/frankvnk/code/CC3000_Hostdriver/docs/tip/modules.html
Diff: wlan.h
- Revision:
- 5:854f9b13a0f9
- Parent:
- 4:d8255a5aad46
- Child:
- 6:d733efcc2c56
--- a/wlan.h Mon Jul 15 14:19:46 2013 +0000 +++ b/wlan.h Mon Jul 15 19:54:53 2013 +0000 @@ -44,6 +44,13 @@ #include "security.h" #include "evnt_handler.h" +//***************************************************************************** +// +//! \addtogroup wlan +//! @{ +// +//***************************************************************************** + /** CC3000 Host driver - WLAN * */ @@ -96,37 +103,37 @@ /** * Send HCI_CMND_SIMPLE_LINK_START to CC3000 -* @param usPatchesAvailableAtHost flag to indicate if patches available -* from host or from EEPROM. Due to the -* fact the patches are burn to the EEPROM -* using the patch programmer utility, the -* patches will be available from the EEPROM -* and not from the host. +* @param usPatchesAvailableAtHost flag to indicate if patches available\n +* from host or from EEPROM. Due to the \n +* fact the patches are burn to the EEPROM\n +* using the patch programmer utility, the \n +* patches will be available from the EEPROM\n +* and not from the host.\n * @return none */ static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost); /** * Initialize wlan driver -* @param sWlanCB Asynchronous events callback. -* 0 no event call back. -* -call back parameters: -* 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event, -* HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event, -* HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done, -* HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, -* HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR -* HCI_EVNT_WLAN_KEEPALIVE keepalive. -* 2) data: pointer to extra data that received by the event -* (NULL no data). -* 3) length: data length. -* -Events with extra data: -* HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, -* 4 bytes default gateway, 4 bytes DHCP server and 4 bytes -* for DNS server. -* HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, -* 4 bytes Packets received, 4 bytes Min round time, -* 4 bytes Max round time and 4 bytes for Avg round time. +* @param sWlanCB Asynchronous events callback. \n +* 0 no event call back.\n +* -call back parameters:\n +* 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event,\n +* HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event,\n +* HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done,\n +* HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, \n +* HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR \n +* HCI_EVNT_WLAN_KEEPALIVE keepalive.\n +* 2) data: pointer to extra data that received by the event\n +* (NULL no data).\n +* 3) length: data length.\n +* -Events with extra data:\n +* HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask,\n +* 4 bytes default gateway, 4 bytes DHCP server and 4 bytes\n +* for DNS server.\n +* HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent,\n +* 4 bytes Packets received, 4 bytes Min round time, \n +* 4 bytes Max round time and 4 bytes for Avg round time.\n * @param sFWPatches 0 no patch or pointer to FW patches * @param sDriverPatches 0 no patch or pointer to driver patches * @param sBootLoaderPatches 0 no patch or pointer to bootloader patches @@ -149,8 +156,8 @@ /** * Trigger Received event/data processing - called from the SPI library to receive the data -* @param pvBuffer - pointer to the received data buffer -* The function triggers Received event/data processing +* @param pvBuffer - pointer to the received data buffer\n +* The function triggers Received event/data processing\n * @param Pointer to the received data * @return none */ @@ -158,21 +165,21 @@ /** -* Start WLAN device. This function asserts the enable pin of -* the device (WLAN_EN), starting the HW initialization process. -* The function blocked until device Initialization is completed. -* Function also configure patches (FW, driver or bootloader) -* and calls appropriate device callbacks. -* @param usPatchesAvailableAtHost - flag to indicate if patches available -* from host or from EEPROM. Due to the -* fact the patches are burn to the EEPROM -* using the patch programmer utility, the -* patches will be available from the EEPROM -* and not from the host. +* Start WLAN device. +* This function asserts the enable pin of \n +* the device (WLAN_EN), starting the HW initialization process.\n +* The function blocked until device Initialization is completed.\n +* Function also configure patches (FW, driver or bootloader) \n +* and calls appropriate device callbacks.\n +* @param usPatchesAvailableAtHost - flag to indicate if patches available\n +* from host or from EEPROM. Due to the\n +* fact the patches are burn to the EEPROM\n +* using the patch programmer utility, the \n +* patches will be available from the EEPROM\n +* and not from the host.\n * @return none * @Note Prior calling the function wlan_init shall be called. -* @Warning This function must be called after wlan_init and before any -* other wlan API +* @Warning This function must be called after wlan_init and before any other wlan API * @sa wlan_init , wlan_stop */ extern void wlan_start(unsigned short usPatchesAvailableAtHost); @@ -187,24 +194,24 @@ /** * Connect to AP -* @param sec_type security options: -* WLAN_SEC_UNSEC, -* WLAN_SEC_WEP (ASCII support only), -* WLAN_SEC_WPA or WLAN_SEC_WPA2 +* @param sec_type security options:\n +* WLAN_SEC_UNSEC, \n +* WLAN_SEC_WEP (ASCII support only),\n +* WLAN_SEC_WPA or WLAN_SEC_WPA2\n * @param ssid up to 32 bytes and is ASCII SSID of the AP * @param ssid_len length of the SSID * @param bssid 6 bytes specified the AP bssid * @param key up to 16 bytes specified the AP security key * @param key_len key length -* @return On success, zero is returned. On error, negative is returned. -* Note that even though a zero is returned on success to trigger -* connection operation, it does not mean that CCC3000 is already -* connected. An asynchronous "Connected" event is generated when -* actual association process finishes and CC3000 is connected to -* the AP. If DHCP is set, An asynchronous "DHCP" event is -* generated when DHCP process is finish. -* @warning Please Note that when connection to AP configured with security -* type WEP, please confirm that the key is set as ASCII and not as HEX. +* @return On success, zero is returned. On error, negative is returned.\n +* Note that even though a zero is returned on success to trigger\n +* connection operation, it does not mean that CCC3000 is already\n +* connected. An asynchronous "Connected" event is generated when \n +* actual association process finishes and CC3000 is connected to\n +* the AP. If DHCP is set, An asynchronous "DHCP" event is \n +* generated when DHCP process is finish.\n +* @warning Please Note that when connection to AP configured with security\n +* type WEP, please confirm that the key is set as ASCII and not as HEX.\n * @sa wlan_disconnect */ #ifndef CC3000_TINY_DRIVER @@ -227,13 +234,13 @@ extern long wlan_disconnect(void); /** -* Add profile -* When auto start is enabled, the device connects to -* station from the profiles table. Up to 7 profiles are supported. -* If several profiles configured the device choose the highest -* priority profile, within each priority group, device will choose -* profile based on security policy, signal strength, etc -* parameters. All the profiles are stored in CC3000 NVMEM. +* Add profile. +* When auto start is enabled, the device connects to\n +* station from the profiles table. Up to 7 profiles are supported. \n +* If several profiles configured the device choose the highest \n +* priority profile, within each priority group, device will choose \n +* profile based on security policy, signal strength, etc \n +* parameters. All the profiles are stored in CC3000 NVMEM.\n * * @param ulSecType WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2 * @param ucSsid ssid SSID up to 32 bytes @@ -260,7 +267,7 @@ unsigned long ulPassPhraseLen); /** -* Delete WLAN profile +* Delete WLAN profile. * @param index number of profile to delete * @return On success, zero is returned. On error, -1 is returned * @Note In order to delete all stored profile, set index to 255. @@ -269,17 +276,17 @@ extern long wlan_ioctl_del_profile(unsigned long ulIndex); /** -* Mask event according to bit mask. In case that event is -* masked (1), the device will not send the masked event to host. -* @param mask mask option: -* HCI_EVNT_WLAN_UNSOL_CONNECT connect event -* HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event -* HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done -* HCI_EVNT_WLAN_UNSOL_INIT init done -* HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report -* HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report -* HCI_EVNT_WLAN_KEEPALIVE keepalive -* HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission +* Mask event according to bit mask. +* In case that event is masked (1), the device will not send the masked event to host. +* @param mask mask option:\n +* HCI_EVNT_WLAN_UNSOL_CONNECT connect event\n +* HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event\n +* HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done\n +* HCI_EVNT_WLAN_UNSOL_INIT init done\n +* HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report\n +* HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report\n +* HCI_EVNT_WLAN_KEEPALIVE keepalive\n +* HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission\n * Saved: no. * @return On success, zero is returned. On error, -1 is returned */ @@ -288,34 +295,35 @@ /** * Get wlan status: disconnected, scanning, connecting or connected * @param none -* @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, -* STATUS_CONNECTING or WLAN_STATUS_CONNECTED +* @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING,\n +* STATUS_CONNECTING or WLAN_STATUS_CONNECTED \n */ extern long wlan_ioctl_statusget(void); /** -* Set connection policy -* When auto is enabled, the device tries to connect according the following policy: -* 1) If fast connect is enabled and last connection is valid, -* the device will try to connect to it without the scanning -* procedure (fast). The last connection will be marked as -* invalid, due to adding/removing profile. -* 2) If profile exists, the device will try to connect it -* (Up to seven profiles). -* 3) If fast and profiles are not found, and open mode is -* enabled, the device will try to connect to any AP. -* Note that the policy settings are stored in the CC3000 NVMEM. -* @param should_connect_to_open_ap enable(1), disable(0) connect to any -* available AP. This parameter corresponds to the configuration of -* item # 3 in the brief description. -* @param should_use_fast_connect enable(1), disable(0). if enabled, tries -* to connect to the last connected AP. This parameter corresponds -* to the configuration of item # 1 in the brief description. -* @param auto_start enable(1), disable(0) auto connect -* after reset and periodically reconnect if needed. This -* configuration configures option 2 in the above description. -* @return On success, zero is returned. On error, -1 is returned +* Set connection policy. +* When auto is enabled, the device tries to connect according the following policy:\n +* 1) If fast connect is enabled and last connection is valid, \n +* the device will try to connect to it without the scanning \n +* procedure (fast). The last connection will be marked as\n +* invalid, due to adding/removing profile. \n +* 2) If profile exists, the device will try to connect it \n +* (Up to seven profiles).\n +* 3) If fast and profiles are not found, and open mode is\n +* enabled, the device will try to connect to any AP.\n +* Note that the policy settings are stored in the CC3000 NVMEM.\n +* @param should_connect_to_open_ap enable(1), disable(0) connect to any \n +* available AP. This parameter corresponds to the configuration of \n +* item # 3 in the brief description.\n +* @param should_use_fast_connect enable(1), disable(0). if enabled, tries \n +* to connect to the last connected AP. This parameter corresponds \n +* to the configuration of item # 1 in the brief description.\n +* @param auto_start enable(1), disable(0) auto connect \n +* after reset and periodically reconnect if needed. This \n +* configuration configures option 2 in the above description.\n +* @return On success, zero is returned.\n +* On error, -1 is returned \n * @sa wlan_add_profile , wlan_ioctl_del_profile */ extern long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, @@ -323,19 +331,19 @@ unsigned long ulUseProfiles); /** -* Gets entry from scan result table. -* The scan results are returned one by one, and each entry represents a single AP found in the area. -* The following is a format of the scan result: -* - 4 Bytes: number of networks found -* - 4 Bytes: The status of the scan: 0 - aged results, 1 - results valid, 2 - no results -* - 42 bytes: Result entry, where the bytes are arranged as follows: -* - 1 bit isValid - is result valid or not -* - 7 bits rssi - RSSI value -* - 2 bits securityMode - security mode of the AP: 0 - Open, 1 - WEP, 2 WPA, 3 WPA2 -* - 6 bits SSID name length -* - 2 bytes the time at which the entry has entered into scans result table -* - 32 bytes SSID name -* - 6 bytes BSSID +* Get entry from scan result table. +* The scan results are returned one by one, and each entry represents a single AP found in the area.\n +* The following is a format of the scan result: \n +* - 4 Bytes: number of networks found\n +* - 4 Bytes: The status of the scan: 0 - aged results, 1 - results valid, 2 - no results\n +* - 42 bytes: Result entry, where the bytes are arranged as follows:\n +* - 1 bit isValid - is result valid or not\n +* - 7 bits rssi - RSSI value \n +* - 2 bits securityMode - security mode of the AP: 0 - Open, 1 - WEP, 2 WPA, 3 WPA2\n +* - 6 bits SSID name length\n +* - 2 bytes the time at which the entry has entered into scans result table\n +* - 32 bytes SSID name\n +* - 6 bytes BSSID \n * @param[in] scan_timeout parameter not supported * @param[out] ucResults scan result (_wlan_full_scan_results_args_t) * @return On success, zero is returned. On error, -1 is returned @@ -347,41 +355,41 @@ /** * start and stop scan procedure. Set scan parameters. -* @param uiEnable start/stop application scan: -* 1 = start scan with default interval value of 10 min. -* To set a different scan interval value, apply the value in milliseconds. -* minimum = 1 second. 0=stop. -* Wlan reset (wlan_stop() wlan_start()) is needed when changing scan interval value. -* Saved: No -* @param uiMinDwellTime minimum dwell time value to be used for each channel, in milliseconds. -* Saved: yes -* Recommended Value: 100 -* Default: 20 -* @param uiMaxDwellTime maximum dwell time value to be used for each channel, in milliseconds. -* Saved: yes -* Recommended Value: 100 -* Default: 30 -* @param uiNumOfProbeRequests max probe request between dwell time. -* Saved: yes. -* Recommended Value: 5 -* Default:2 -* @param uiChannelMask bitwise, up to 13 channels (0x1fff). -* Saved: yes. -* Default: 0x7ff -* @param uiRSSIThreshold RSSI threshold. -* Saved: yes -* Default: -80 -* @param uiSNRThreshold NSR threshold. -* Saved: yes -* Default: 0 -* @param uiDefaultTxPower probe Tx power. -* Saved: yes -* Default: 205 -* @param aiIntervalList pointer to array with 16 entries (16 channels) -* Each entry (unsigned long) holds timeout between periodic scan -* and connection scan - in milliseconds. -* Saved: yes. -* Default 2000ms. +* @param uiEnable start/stop application scan: \n +* 1 = start scan with default interval value of 10 min. \n +* To set a different scan interval value, apply the value in milliseconds.\n +* minimum = 1 second. 0=stop.\n +* Wlan reset (wlan_stop() wlan_start()) is needed when changing scan interval value.\n +* Saved: No\n +* @param uiMinDwellTime minimum dwell time value to be used for each channel, in milliseconds.\n +* Saved: yes\n +* Recommended Value: 100\n +* Default: 20\n +* @param uiMaxDwellTime maximum dwell time value to be used for each channel, in milliseconds.\n +* Saved: yes\n +* Recommended Value: 100\n +* Default: 30\n +* @param uiNumOfProbeRequests max probe request between dwell time. \n +* Saved: yes.\n +* Recommended Value: 5\n +* Default:2\n +* @param uiChannelMask bitwise, up to 13 channels (0x1fff). \n +* Saved: yes.\n +* Default: 0x7ff\n +* @param uiRSSIThreshold RSSI threshold.\n +* Saved: yes\n +* Default: -80\n +* @param uiSNRThreshold NSR threshold.\n +* Saved: yes\n +* Default: 0\n +* @param uiDefaultTxPower probe Tx power.\n +* Saved: yes\n +* Default: 205\n +* @param aiIntervalList pointer to array with 16 entries (16 channels) \n +* Each entry (unsigned long) holds timeout between periodic scan \n +* and connection scan - in milliseconds.\n +* Saved: yes.\n +* Default 2000ms.\n * @return On success, zero is returned. On error, -1 is returned * @Note uiDefaultTxPower, is not supported on this version. * @sa wlan_ioctl_get_scan_results @@ -398,13 +406,14 @@ /** -* Start to acquire device profile. The device acquire its own profile, if profile message is found. -* The acquired AP information is stored in CC3000 EEPROM only when AES128 encryption is used. -* When AES128 encryption is not used, a profile is internally created by the device. +* Start to acquire device profile. +* The device will acquires its own profile if a profile message is found.\n +* The acquired AP information is stored in CC3000 EEPROM only when AES128 encryption is used.\n +* When AES128 encryption is not used, a profile is internally created by the device.\n * @param algoEncryptedFlag indicates whether the information is encrypted * @return On success, zero is returned. On error, -1 is returned -* @Note An asynchronous event - Smart Config Done will be generated as soon -* as the process finishes successfully. +* @Note An asynchronous event - Smart Config Done will be generated as soon\n +* as the process finishes successfully.\n * @sa wlan_smart_config_set_prefix , wlan_smart_config_stop */ extern long wlan_smart_config_start(unsigned long algoEncryptedFlag); @@ -418,7 +427,8 @@ extern long wlan_smart_config_stop(void); /** -* Configure station ssid prefix. The prefix is used internally in CC3000. It should always be TTT. +* Configure station ssid prefix. +* The prefix is used internally in CC3000. It should always be TTT.\n * @param newPrefix 3 bytes identify the SSID prefix for the Smart Config. * @return On success, zero is returned. On error, -1 is returned * @Note The prefix is stored in CC3000 NVMEM @@ -429,8 +439,8 @@ /** * Process the acquired data and store it as a profile. * The acquired AP information is stored in CC3000 EEPROM encrypted. -* The encrypted data is decrypted and stored as a profile. -* behavior is as defined by connection policy. +* The encrypted data is decrypted and stored as a profile.\n +* behavior is as defined by connection policy.\n * @param none * @return On success, zero is returned. On error, -1 is returned */ @@ -441,4 +451,11 @@ } #endif // __cplusplus +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + #endif // __WLAN_H__