mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
CC3000 driver update from David Sidrane
This commit is contained in:
@@ -38,7 +38,7 @@ ifeq ($(CONFIG_WL_CC3000),y)
|
||||
# Include cc3000 drivers
|
||||
|
||||
CSRCS += cc3000.c cc3000_common.c evnt_handler.c hci.c netapp.c nvmem.c
|
||||
CSRCS += security.c socket.c spi.c wlan.c
|
||||
CSRCS += security.c socket.c socket_imp.c spi.c wlan.c
|
||||
|
||||
# Include wireless devices build support
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,20 +47,29 @@
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <mqueue.h>
|
||||
#include <pthread.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
#include <nuttx/wireless/cc3000.h>
|
||||
#include <nuttx/wireless/cc3000/cc3000_common.h>
|
||||
#include "spi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_CC3000_MT /* Indicate multi threaded version */
|
||||
|
||||
#ifdef CONFIG_CC3000_MT
|
||||
# define CONFIG_WL_MAX_SOCKETS 5
|
||||
#endif
|
||||
|
||||
/* CC3000 Interfaces ********************************************************/
|
||||
|
||||
/* Driver support ***********************************************************/
|
||||
@@ -82,8 +91,26 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_CC3000_MT
|
||||
/* lock to serialze access to driver (spi protocol is window size 1) */
|
||||
extern pthread_mutex_t g_cc3000_mut;
|
||||
/* This structure describes the state of one CC3000 driver instance */
|
||||
|
||||
typedef struct cc3000_socket_ent
|
||||
{
|
||||
int sd;
|
||||
long status;
|
||||
sem_t semwait;
|
||||
} cc3000_socket_ent;
|
||||
|
||||
typedef struct cc3000_accept_ent
|
||||
{
|
||||
cc3000_socket_ent acc;
|
||||
struct sockaddr addr;
|
||||
socklen_t addrlen;
|
||||
} cc3000_accept_ent;
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
eSPI_STATE_POWERUP = 0,
|
||||
@@ -107,7 +134,7 @@ struct cc3000_dev_s
|
||||
uint8_t nwaiters; /* Number of threads waiting for CC3000 data */
|
||||
uint8_t minor; /* minor */
|
||||
sem_t devsem; /* Manages exclusive access to this structure */
|
||||
sem_t wrkwaitsem; /* Suspend and resume the delivery of messages */
|
||||
sem_t *wrkwaitsem; /* Suspend and resume the delivery of messages */
|
||||
sem_t waitsem; /* Used to wait for the availability of data */
|
||||
sem_t irqsem; /* Used to signal irq from cc3000 */
|
||||
sem_t readysem; /* Used to wait for Ready Condition from the cc3000 */
|
||||
@@ -122,6 +149,15 @@ struct cc3000_dev_s
|
||||
uint8_t tx_buffer[CC3000_TX_BUFFER_SIZE];
|
||||
ssize_t tx_buffer_len;
|
||||
|
||||
/* The following is a list if socket structures of threads waiting
|
||||
* long operations to finish;
|
||||
*/
|
||||
#ifdef CONFIG_CC3000_MT
|
||||
pthread_t selecttid; /* Handle for the select thread */
|
||||
sem_t selectsem; /* Used to sleep the select thread */
|
||||
cc3000_socket_ent sockets[CONFIG_WL_MAX_SOCKETS];
|
||||
cc3000_accept_ent accepting_socket;
|
||||
#endif
|
||||
/* The following is a list if poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
@@ -143,6 +179,28 @@ extern "C" {
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
static inline void cc3000_lib_lock(void)
|
||||
{
|
||||
#ifdef CONFIG_CC3000_MT
|
||||
int status = pthread_mutex_lock(&g_cc3000_mut);
|
||||
DEBUGASSERT(status == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void cc3000_lib_unlock(void)
|
||||
{
|
||||
#ifdef CONFIG_CC3000_MT
|
||||
int status = pthread_mutex_unlock(&g_cc3000_mut);
|
||||
DEBUGASSERT(status == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int cc3000_do_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int cc3000_wait_data(int sockfd, int minor);
|
||||
int cc3000_accept_socket(int sd, int minor, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int cc3000_add_socket(int sd, int minor);
|
||||
int cc3000_remove_socket(int sd, int minor);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/wireless/cc3000/cc3000_common.h>
|
||||
#include <nuttx/wireless/cc3000/include/sys/socket.h>
|
||||
#include <nuttx/wireless/cc3000/wlan.h>
|
||||
#include <nuttx/wireless/cc3000/evnt_handler.h>
|
||||
|
||||
/*****************************************************************************
|
||||
* Name:__error__
|
||||
*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
@@ -46,7 +47,7 @@
|
||||
#include <nuttx/wireless/cc3000/hci.h>
|
||||
#include <nuttx/wireless/cc3000/evnt_handler.h>
|
||||
#include <nuttx/wireless/cc3000/wlan.h>
|
||||
#include <nuttx/wireless/cc3000/include/sys/socket.h>
|
||||
#include "cc3000_socket.h"
|
||||
#include <nuttx/wireless/cc3000/netapp.h>
|
||||
|
||||
#include "spi.h"
|
||||
@@ -344,7 +345,7 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen)
|
||||
|
||||
memcpy((uint8_t *)pRetParams,
|
||||
pucReceivedParams + ACCEPT_ADDRESS__OFFSET,
|
||||
sizeof(sockaddr));
|
||||
sizeof(struct sockaddr));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -910,21 +911,22 @@ void SimpleLinkWaitEvent(uint16_t usOpcode, void *pRetParams)
|
||||
|
||||
do
|
||||
{
|
||||
nllvdbg("SpiWait\n");
|
||||
tSLInformation.pucReceivedData = SpiWait();
|
||||
tSLInformation.usEventOrDataReceived = 1;
|
||||
STREAM_TO_UINT16((char *)tSLInformation.pucReceivedData, HCI_EVENT_OPCODE_OFFSET,event_type);
|
||||
|
||||
if (*tSLInformation.pucReceivedData == HCI_TYPE_EVNT)
|
||||
{
|
||||
nllvdbg("Evtn:0x%x\n",event_type);
|
||||
}
|
||||
nllvdbg("Evtn:0x%x\n",event_type);
|
||||
}
|
||||
|
||||
if (event_type != usOpcode)
|
||||
{
|
||||
if (hci_unsolicited_event_handler() == 1)
|
||||
{
|
||||
nllvdbg("Processed Event 0x%x want 0x%x\n",event_type, usOpcode);
|
||||
}
|
||||
if (hci_unsolicited_event_handler() == 1)
|
||||
{
|
||||
nllvdbg("Processed Event 0x%x want 0x%x\n",event_type, usOpcode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,7 +36,11 @@
|
||||
* Included Files
|
||||
******************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/wireless/cc3000/cc3000_common.h>
|
||||
#include <nuttx/wireless/cc3000/hci.h>
|
||||
#include "spi.h"
|
||||
@@ -74,6 +78,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLen
|
||||
|
||||
stream = (pucBuff + SPI_HEADER_SIZE);
|
||||
|
||||
nllvdbg("Send 0x%x\n",usOpcode);
|
||||
UINT8_TO_STREAM(stream, HCI_TYPE_CMND);
|
||||
stream = UINT16_TO_STREAM(stream, usOpcode);
|
||||
UINT8_TO_STREAM(stream, ucArgsLength);
|
||||
@@ -81,6 +86,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLen
|
||||
/* Update the opcode of the event we will be waiting for */
|
||||
|
||||
SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);
|
||||
nllvdbg("Send of 0x%x Completed\n",usOpcode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,12 +37,15 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/wireless/cc3000/netapp.h>
|
||||
#include <nuttx/wireless/cc3000/hci.h>
|
||||
#include <nuttx/wireless/cc3000/include/sys/socket.h>
|
||||
#include <nuttx/wireless/cc3000/evnt_handler.h>
|
||||
#include <nuttx/wireless/cc3000/nvmem.h>
|
||||
|
||||
#include "cc3000.h"
|
||||
#include "cc3000_socket.h"
|
||||
|
||||
/******************************************************************************
|
||||
* Pre-processor Definitions
|
||||
******************************************************************************/
|
||||
@@ -118,6 +121,8 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -138,6 +143,8 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_DHCP, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return(scRet);
|
||||
}
|
||||
|
||||
@@ -200,6 +207,8 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -226,11 +235,12 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_SET_TIMERS, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return scRet;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Name: netapp_ping_send
|
||||
*
|
||||
@@ -262,6 +272,8 @@ long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts,
|
||||
int8_t scRet;
|
||||
uint8_t *ptr, *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -281,6 +293,8 @@ long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_PING_SEND, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return scRet;
|
||||
}
|
||||
#endif
|
||||
@@ -319,6 +333,8 @@ void netapp_ping_report(void)
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
int8_t scRet;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
|
||||
/* Initiate a HCI command */
|
||||
@@ -328,6 +344,8 @@ void netapp_ping_report(void)
|
||||
/* Wait for command complete event */
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_PING_REPORT, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -351,6 +369,8 @@ long netapp_ping_stop(void)
|
||||
int8_t scRet;
|
||||
uint8_t *ptr;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
@@ -362,6 +382,8 @@ long netapp_ping_stop(void)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_PING_STOP, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return(scRet);
|
||||
}
|
||||
#endif
|
||||
@@ -401,6 +423,8 @@ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
/* Initiate a HCI command */
|
||||
@@ -410,6 +434,8 @@ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig)
|
||||
/* Wait for command complete event */
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_IPCONFIG, ipconfig);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
}
|
||||
#else
|
||||
void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig)
|
||||
@@ -437,6 +463,9 @@ long netapp_arp_flush(void)
|
||||
int8_t scRet;
|
||||
uint8_t *ptr;
|
||||
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
@@ -448,6 +477,8 @@ long netapp_arp_flush(void)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_ARP_FLUSH, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return scRet;
|
||||
}
|
||||
#endif
|
||||
@@ -484,6 +515,8 @@ long netapp_set_debug_level(unsigned long ulLevel)
|
||||
int8_t scRet;
|
||||
uint8_t *ptr, *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
scRet = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -500,6 +533,8 @@ long netapp_set_debug_level(unsigned long ulLevel)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_NETAPP_SET_DEBUG_LEVEL, &scRet);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return scRet;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
|
||||
#include <nuttx/wireless/cc3000/nvmem.h>
|
||||
#include <nuttx/wireless/cc3000/hci.h>
|
||||
#include <nuttx/wireless/cc3000/include/sys/socket.h>
|
||||
#include <nuttx/wireless/cc3000/evnt_handler.h>
|
||||
#include "cc3000.h"
|
||||
|
||||
/******************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -88,6 +88,8 @@ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -113,6 +115,8 @@ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength,
|
||||
|
||||
SimpleLinkWaitData(buff, 0, 0);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ucStatus;
|
||||
}
|
||||
|
||||
@@ -146,6 +150,8 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
iRes = EFAIL;
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
@@ -168,6 +174,8 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_EVNT_NVMEM_WRITE, &iRes);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return iRes;
|
||||
}
|
||||
|
||||
@@ -285,6 +293,8 @@ uint8_t nvmem_read_sp_version(uint8_t *patchVer)
|
||||
/* 1st byte is the status and the rest is the SP version */
|
||||
uint8_t retBuf[5];
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
/* Initiate a HCI command, no args are required */
|
||||
@@ -300,6 +310,8 @@ uint8_t nvmem_read_sp_version(uint8_t *patchVer)
|
||||
|
||||
*(patchVer+1) = retBuf[4];
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return retBuf[0];
|
||||
}
|
||||
#endif
|
||||
@@ -332,6 +344,8 @@ signed long nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
|
||||
uint8_t *args;
|
||||
uint16_t retval;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -346,5 +360,7 @@ signed long nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_NVMEM_CREATE_ENTRY, &retval);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
+515
-985
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -71,6 +71,7 @@ static struct
|
||||
bool run;
|
||||
uint8_t rx_buffer[CC3000_RX_BUFFER_SIZE];
|
||||
mqd_t queue;
|
||||
sem_t *done;
|
||||
|
||||
} spiconf;
|
||||
|
||||
@@ -95,12 +96,9 @@ static struct
|
||||
|
||||
void SpiResumeSpi(void)
|
||||
{
|
||||
DEBUGASSERT(spiconf.cc3000fd);
|
||||
|
||||
if (ioctl(spiconf.cc3000fd,CC3000IOC_COMPLETE,0))
|
||||
{
|
||||
printf("ioctl:CC3000IOC_COMPLETE failed: %s\n", strerror(errno));
|
||||
}
|
||||
DEBUGASSERT(spiconf.cc3000fd && spiconf.done);
|
||||
sem_post(spiconf.done);
|
||||
nllvdbg("Done\n");
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -158,10 +156,9 @@ long SpiRead(uint8_t *pUserBuffer, uint16_t usLength)
|
||||
|
||||
uint8_t *SpiWait(void)
|
||||
{
|
||||
int nbytes;
|
||||
DEBUGASSERT(spiconf.cc3000fd);
|
||||
|
||||
nbytes = mq_receive(spiconf.queue, spiconf.rx_buffer, CC3000_RX_BUFFER_SIZE, 0);
|
||||
mq_receive(spiconf.queue, spiconf.rx_buffer, CC3000_RX_BUFFER_SIZE, 0);
|
||||
return spiconf.rx_buffer;
|
||||
}
|
||||
|
||||
@@ -181,14 +178,19 @@ uint8_t *SpiWait(void)
|
||||
|
||||
static void *unsoliced_thread_func(void *parameter)
|
||||
{
|
||||
char queuename[QUEUE_NAMELEN];
|
||||
char buff[QUEUE_NAMELEN];
|
||||
int status = 0;
|
||||
int nbytes = 0;
|
||||
int minor = 0;
|
||||
|
||||
ioctl(spiconf.cc3000fd, CC3000IOC_GETQUEID, (unsigned long)&minor);
|
||||
snprintf(queuename, QUEUE_NAMELEN, QUEUE_FORMAT, minor);
|
||||
spiconf.queue = mq_open(queuename,O_RDONLY);
|
||||
ioctl(spiconf.cc3000fd, CC3000IOC_GETQUESEMID, (unsigned long)&minor);
|
||||
snprintf(buff, QUEUE_NAMELEN, QUEUE_FORMAT, minor);
|
||||
spiconf.queue = mq_open(buff,O_RDONLY);
|
||||
DEBUGASSERT(spiconf.queue != (mqd_t) -1);
|
||||
DEBUGASSERT(SEM_NAMELEN == QUEUE_NAMELEN);
|
||||
snprintf(buff, SEM_NAMELEN, SEM_FORMAT, minor);
|
||||
spiconf.done = sem_open(buff,O_RDONLY);
|
||||
DEBUGASSERT(spiconf.done != (sem_t *)-1);
|
||||
|
||||
while(spiconf.run)
|
||||
{
|
||||
@@ -196,12 +198,13 @@ static void *unsoliced_thread_func(void *parameter)
|
||||
nbytes = mq_receive(spiconf.queue, spiconf.rx_buffer, CC3000_RX_BUFFER_SIZE, 0);
|
||||
if (nbytes > 0)
|
||||
{
|
||||
spivdbg("%d Processed\n",nbytes);
|
||||
nlldbg("%d Processed\n",nbytes);
|
||||
spiconf.pfRxHandler(spiconf.rx_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
mq_close(spiconf.queue);
|
||||
sem_close(spiconf.done);
|
||||
pthread_exit((pthread_addr_t)status);
|
||||
return (pthread_addr_t)status;
|
||||
}
|
||||
@@ -223,9 +226,11 @@ static void *unsoliced_thread_func(void *parameter)
|
||||
void SpiOpen(gcSpiHandleRx pfRxHandler)
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
|
||||
DEBUGASSERT(spiconf.cc3000fd == 0);
|
||||
int fd = open("/dev/wireless0",O_RDWR|O_BINARY);
|
||||
|
||||
fd = open("/dev/wireless0",O_RDWR|O_BINARY);
|
||||
if (fd > 0)
|
||||
{
|
||||
spiconf.pfRxHandler = pfRxHandler;
|
||||
|
||||
@@ -41,16 +41,18 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wireless/cc3000/cc3000_common.h>
|
||||
#include <nuttx/wireless/cc3000/wlan.h>
|
||||
#include <nuttx/wireless/cc3000/hci.h>
|
||||
#include "spi.h"
|
||||
#include <nuttx/wireless/cc3000/include/sys/socket.h>
|
||||
#include <nuttx/wireless/cc3000/nvmem.h>
|
||||
#include <nuttx/wireless/cc3000/security.h>
|
||||
#include <nuttx/wireless/cc3000/evnt_handler.h>
|
||||
|
||||
#include "spi.h"
|
||||
#include "cc3000.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Preprocessor Definitions
|
||||
*****************************************************************************/
|
||||
@@ -137,7 +139,8 @@ static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost)
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
UINT8_TO_STREAM(args, ((usPatchesAvailableAtHost) ? SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT));
|
||||
UINT8_TO_STREAM(args, ((usPatchesAvailableAtHost) ?
|
||||
SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT));
|
||||
|
||||
/* IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000 */
|
||||
|
||||
@@ -194,23 +197,14 @@ static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost)
|
||||
|
||||
void wlan_init(tWlanCB sWlanCB, tFWPatches sFWPatches,
|
||||
tDriverPatches sDriverPatches,
|
||||
tBootLoaderPatches sBootLoaderPatches,
|
||||
tWlanReadInteruptPin sReadWlanInterruptPin,
|
||||
tWlanInterruptEnable sWlanInterruptEnable,
|
||||
tWlanInterruptDisable sWlanInterruptDisable,
|
||||
tWriteWlanPin sWriteWlanPin)
|
||||
tBootLoaderPatches sBootLoaderPatches)
|
||||
{
|
||||
cc3000_lib_lock();
|
||||
tSLInformation.sFWPatches = sFWPatches;
|
||||
tSLInformation.sDriverPatches = sDriverPatches;
|
||||
tSLInformation.sBootLoaderPatches = sBootLoaderPatches;
|
||||
|
||||
/* Init I/O callback */
|
||||
|
||||
tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin;
|
||||
tSLInformation.WlanInterruptEnable = sWlanInterruptEnable;
|
||||
tSLInformation.WlanInterruptDisable = sWlanInterruptDisable;
|
||||
tSLInformation.WriteWlanPin = sWriteWlanPin;
|
||||
|
||||
/* Init asynchronous events callback */
|
||||
|
||||
tSLInformation.sWlanCB= sWlanCB;
|
||||
@@ -218,6 +212,7 @@ void wlan_init(tWlanCB sWlanCB, tFWPatches sFWPatches,
|
||||
/* By default TX Complete events are routed to host too */
|
||||
|
||||
tSLInformation.InformHostOnTxComplete = 1;
|
||||
cc3000_lib_unlock();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -237,8 +232,12 @@ void wlan_init(tWlanCB sWlanCB, tFWPatches sFWPatches,
|
||||
|
||||
void SpiReceiveHandler(void *pvBuffer)
|
||||
{
|
||||
tSLInformation.usEventOrDataReceived = 1;
|
||||
tSLInformation.pucReceivedData = (uint8_t *)pvBuffer;
|
||||
tSLInformation.usEventOrDataReceived = 1;
|
||||
|
||||
uint16_t event_type;
|
||||
STREAM_TO_UINT16((char *)tSLInformation.pucReceivedData, HCI_EVENT_OPCODE_OFFSET,event_type);
|
||||
nllvdbg("Evtn:0x%x\n", event_type);
|
||||
|
||||
hci_unsolicited_event_handler();
|
||||
}
|
||||
@@ -272,7 +271,7 @@ void SpiReceiveHandler(void *pvBuffer)
|
||||
|
||||
void wlan_start(uint16_t usPatchesAvailableAtHost)
|
||||
{
|
||||
unsigned long ulSpiIRQState;
|
||||
cc3000_lib_lock();
|
||||
|
||||
tSLInformation.NumberOfSentPackets = 0;
|
||||
tSLInformation.NumberOfReleasedPackets = 0;
|
||||
@@ -293,41 +292,13 @@ void wlan_start(uint16_t usPatchesAvailableAtHost)
|
||||
|
||||
SpiOpen(SpiReceiveHandler);
|
||||
|
||||
/* Check the IRQ line */
|
||||
|
||||
ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();
|
||||
|
||||
/* ASIC 1273 chip enable: toggle WLAN EN line */
|
||||
|
||||
tSLInformation.WriteWlanPin(WLAN_ENABLE);
|
||||
|
||||
if (ulSpiIRQState)
|
||||
{
|
||||
/* Wait till the IRQ line goes low */
|
||||
|
||||
while (tSLInformation.ReadWlanInterruptPin() != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait till the IRQ line goes high and than low */
|
||||
|
||||
while (tSLInformation.ReadWlanInterruptPin() == 0)
|
||||
{
|
||||
}
|
||||
|
||||
while (tSLInformation.ReadWlanInterruptPin() != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
SimpleLink_Init_Start(usPatchesAvailableAtHost);
|
||||
|
||||
/* Read Buffer's size and finish */
|
||||
|
||||
hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
|
||||
SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
|
||||
cc3000_lib_unlock();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -346,24 +317,9 @@ void wlan_start(uint16_t usPatchesAvailableAtHost)
|
||||
|
||||
void wlan_stop(void)
|
||||
{
|
||||
/* ASIC 1273 chip disable */
|
||||
|
||||
tSLInformation.WriteWlanPin(WLAN_DISABLE);
|
||||
|
||||
/* Wait till IRQ line goes high... */
|
||||
|
||||
while (tSLInformation.ReadWlanInterruptPin() == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Free the used by WLAN Driver memory */
|
||||
|
||||
if (tSLInformation.pucTxCommandBuffer)
|
||||
{
|
||||
tSLInformation.pucTxCommandBuffer = 0;
|
||||
}
|
||||
|
||||
cc3000_lib_lock();
|
||||
SpiClose();
|
||||
cc3000_lib_unlock();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -407,6 +363,8 @@ long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
|
||||
uint8_t *args;
|
||||
uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -447,7 +405,7 @@ long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
|
||||
errno = ret;
|
||||
|
||||
cc3000_lib_unlock();
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
@@ -458,6 +416,8 @@ long wlan_connect(char *ssid, long ssid_len)
|
||||
uint8_t *args;
|
||||
uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -486,6 +446,8 @@ long wlan_connect(char *ssid, long ssid_len)
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
|
||||
errno = ret;
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -509,6 +471,8 @@ long wlan_disconnect(void)
|
||||
long ret;
|
||||
uint8_t *ptr;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
@@ -519,6 +483,8 @@ long wlan_disconnect(void)
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret);
|
||||
errno = ret;
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -562,6 +528,8 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
|
||||
@@ -581,6 +549,7 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -628,6 +597,8 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid,
|
||||
uint8_t *args;
|
||||
uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -733,7 +704,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid,
|
||||
/* Wait for command complete event */
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
@@ -770,6 +741,8 @@ long wlan_ioctl_del_profile(unsigned long ulIndex)
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -787,6 +760,8 @@ long wlan_ioctl_del_profile(unsigned long ulIndex)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -829,6 +804,8 @@ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -845,6 +822,8 @@ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -900,6 +879,8 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable,
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
@@ -926,6 +907,8 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable,
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return uiRes;
|
||||
}
|
||||
#endif
|
||||
@@ -960,6 +943,8 @@ long wlan_set_event_mask(unsigned long ulMask)
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
if ((ulMask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE)
|
||||
{
|
||||
tSLInformation.InformHostOnTxComplete = 0;
|
||||
@@ -998,6 +983,8 @@ long wlan_set_event_mask(unsigned long ulMask)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_EVENT_MASK, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1022,6 +1009,8 @@ long wlan_ioctl_statusget(void)
|
||||
long ret;
|
||||
uint8_t *ptr;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
@@ -1032,6 +1021,8 @@ long wlan_ioctl_statusget(void)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -1063,6 +1054,8 @@ long wlan_smart_config_start(unsigned long algoEncryptedFlag)
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
|
||||
@@ -1079,6 +1072,7 @@ long wlan_smart_config_start(unsigned long algoEncryptedFlag)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1101,6 +1095,8 @@ long wlan_smart_config_stop(void)
|
||||
long ret;
|
||||
uint8_t *ptr;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
@@ -1110,6 +1106,7 @@ long wlan_smart_config_stop(void)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1136,6 +1133,8 @@ long wlan_smart_config_set_prefix(char* cNewPrefix)
|
||||
uint8_t *ptr;
|
||||
uint8_t *args;
|
||||
|
||||
cc3000_lib_lock();
|
||||
|
||||
ret = EFAIL;
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
@@ -1163,6 +1162,8 @@ long wlan_smart_config_set_prefix(char* cNewPrefix)
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret);
|
||||
|
||||
cc3000_lib_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user