2013-10-16 19:59:22 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers//wireless/cc3000.h
|
|
|
|
*
|
2014-02-18 21:16:51 +01:00
|
|
|
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
2013-10-16 19:59:22 +02:00
|
|
|
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
* David Sidrane <david_s5@nscdg.com>
|
|
|
|
*
|
|
|
|
* References:
|
|
|
|
* CC30000 from Texas Instruments http://processors.wiki.ti.com/index.php/CC3000
|
|
|
|
*
|
|
|
|
* See also:
|
2013-10-23 17:07:32 +02:00
|
|
|
* http://processors.wiki.ti.com/index.php/CC3000_Host_Driver_Porting_Guide
|
|
|
|
* http://processors.wiki.ti.com/index.php/CC3000_Host_Programming_Guide
|
2013-10-16 19:59:22 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DRIVERS_WIRELESS_WIRELESS_CC3000_H
|
|
|
|
#define __DRIVERS_WIRELESS_WIRELESS_CC3000_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2013-10-26 00:23:53 +02:00
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <mqueue.h>
|
2013-10-26 00:23:53 +02:00
|
|
|
#include <pthread.h>
|
2017-04-28 00:58:30 +02:00
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
#include <nuttx/irq.h>
|
2017-04-28 00:58:30 +02:00
|
|
|
#include <nuttx/wireless/ioctl.h>
|
2013-10-16 19:59:22 +02:00
|
|
|
#include <nuttx/wireless/cc3000.h>
|
2013-10-26 00:23:53 +02:00
|
|
|
#include <nuttx/wireless/cc3000/cc3000_common.h>
|
2013-10-16 19:59:22 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 15:15:32 +02:00
|
|
|
* Pre-processor Definitions
|
2013-10-16 19:59:22 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
#define CONFIG_CC3000_MT /* Indicate multi threaded version */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CC3000_MT
|
|
|
|
# define CONFIG_WL_MAX_SOCKETS 5
|
|
|
|
#endif
|
|
|
|
|
2013-10-23 17:07:32 +02:00
|
|
|
/* CC3000 Interfaces ********************************************************/
|
2013-10-16 19:59:22 +02:00
|
|
|
|
2013-10-23 17:07:32 +02:00
|
|
|
/* Driver support ***********************************************************/
|
2013-10-16 19:59:22 +02:00
|
|
|
/* This format is used to construct the /dev/input[n] device driver path. It
|
|
|
|
* defined here so that it will be used consistently in all places.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define READ 3
|
2013-10-23 17:07:32 +02:00
|
|
|
#define READ_COMMAND {READ, 0 , 0 , 0 , 0}
|
2013-10-16 19:59:22 +02:00
|
|
|
#define READ_OFFSET_TO_LENGTH 3 //cmd dmy dmy lh ll
|
|
|
|
#define WRITE 1
|
|
|
|
|
|
|
|
#define HI(value) (((value) & 0xFF00) >> 8)
|
|
|
|
#define LO(value) ((value) & 0x00FF)
|
|
|
|
|
|
|
|
#define SPI_HEADER_SIZE (5)
|
|
|
|
|
2013-10-23 17:07:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2013-10-16 19:59:22 +02:00
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
#ifdef CONFIG_CC3000_MT
|
2014-11-28 15:52:52 +01:00
|
|
|
/* lock to serialize access to driver (SPI protocol is window size 1) */
|
2014-04-22 20:18:08 +02:00
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
extern pthread_mutex_t g_cc3000_mut;
|
2014-04-22 20:18:08 +02:00
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
/* This structure describes the state of one CC3000 driver instance */
|
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
typedef struct cc3000_socket_ent
|
|
|
|
{
|
2014-02-18 21:16:51 +01:00
|
|
|
volatile int sd;
|
2013-10-26 00:23:53 +02:00
|
|
|
long status;
|
2014-11-28 15:52:52 +01:00
|
|
|
bool received_closed_event:1;
|
|
|
|
bool emptied_and_remotely_closed:1;
|
2013-10-26 00:23:53 +02:00
|
|
|
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
|
|
|
|
|
2013-10-23 17:07:32 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
eSPI_STATE_POWERUP = 0,
|
|
|
|
eSPI_STATE_INITIALIZED,
|
|
|
|
eSPI_STATE_IDLE,
|
|
|
|
eSPI_STATE_WRITE_WAIT_IRQ,
|
|
|
|
eSPI_STATE_WRITE_PROCEED,
|
|
|
|
eSPI_STATE_WRITE_DONE,
|
|
|
|
eSPI_STATE_READ_IRQ,
|
|
|
|
eSPI_STATE_READ_PROCEED,
|
|
|
|
eSPI_STATE_READ_READY,
|
2013-10-16 19:59:22 +02:00
|
|
|
} eDeviceStates;
|
|
|
|
|
|
|
|
struct cc3000_dev_s
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CC3000_MULTIPLE
|
2013-10-23 17:07:32 +02:00
|
|
|
FAR struct cc3000_dev_s *flink; /* Supports a singly linked list of drivers */
|
2013-10-16 19:59:22 +02:00
|
|
|
#endif
|
2013-10-23 17:07:32 +02:00
|
|
|
pthread_t workertid; /* Handle for the worker thread */
|
2013-10-16 19:59:22 +02:00
|
|
|
uint8_t crefs; /* Number of times the device has been opened */
|
|
|
|
uint8_t nwaiters; /* Number of threads waiting for CC3000 data */
|
|
|
|
uint8_t minor; /* minor */
|
|
|
|
sem_t devsem; /* Manages exclusive access to this structure */
|
2013-10-26 00:23:53 +02:00
|
|
|
sem_t *wrkwaitsem; /* Suspend and resume the delivery of messages */
|
2013-10-16 19:59:22 +02:00
|
|
|
sem_t waitsem; /* Used to wait for the availability of data */
|
2013-10-23 17:07:32 +02:00
|
|
|
sem_t irqsem; /* Used to signal irq from cc3000 */
|
|
|
|
sem_t readysem; /* Used to wait for Ready Condition from the cc3000 */
|
2013-10-16 19:59:22 +02:00
|
|
|
|
2013-10-23 17:07:32 +02:00
|
|
|
FAR struct cc3000_config_s *config; /* Board configuration data */
|
2013-10-16 19:59:22 +02:00
|
|
|
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
|
2013-10-23 17:07:32 +02:00
|
|
|
mqd_t queue; /* For unsolicited data delivery */
|
|
|
|
eDeviceStates state; /* The device state */
|
2014-02-18 21:16:51 +01:00
|
|
|
cc3000_buffer_desc rx_buffer;
|
|
|
|
ssize_t rx_buffer_max_len;
|
2013-10-16 19:59:22 +02:00
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
/* 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
|
2014-11-28 15:52:52 +01:00
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
/* 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'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_POLL
|
|
|
|
struct pollfd *fds[CONFIG_CC3000_NPOLLWAITERS];
|
|
|
|
#endif
|
2013-10-30 21:37:13 +01:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_CC3000_PROBES)
|
2013-10-30 21:37:13 +01:00
|
|
|
long guard;
|
|
|
|
#endif
|
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/********************************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2013-10-26 00:23:53 +02:00
|
|
|
static inline void cc3000_lib_lock(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CC3000_MT
|
|
|
|
int status = pthread_mutex_lock(&g_cc3000_mut);
|
|
|
|
DEBUGASSERT(status == 0);
|
2014-04-22 20:18:08 +02:00
|
|
|
UNUSED(status);
|
2013-10-26 00:23:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cc3000_lib_unlock(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CC3000_MT
|
|
|
|
int status = pthread_mutex_unlock(&g_cc3000_mut);
|
|
|
|
DEBUGASSERT(status == 0);
|
2014-04-22 20:18:08 +02:00
|
|
|
UNUSED(status);
|
2013-10-26 00:23:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int cc3000_do_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
|
|
|
|
2013-10-16 19:59:22 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DRIVERS_WIRELESS_WIRELESS_CC3000_H */
|