COSA
An Object-Oriented Platform for Arduino Programming
HCI Class Reference

#include <HCI.hh>

Inheritance diagram for HCI:
Inheritance graph
Collaboration diagram for HCI:
Collaboration graph

Classes

struct  cmnd_header_t
 
struct  data_header_t
 
class  Event
 
class  IRQPin
 

Public Member Functions

 HCI (Board::DigitalPin cs, Board::ExternalInterruptPin irq, SPI::Clock rate=SPI::DEFAULT_CLOCK)
 
int read (uint16_t &op, void *args, uint8_t len)
 
int write (uint8_t type, uint16_t op, const void *args, uint8_t len)
 
int write_P (uint8_t type, uint16_t op, const void *args, uint8_t len)
 
int write (uint8_t type, uint16_t op, const void *args, uint8_t len, bool progmem)
 
int issue (uint16_t op, const void *args=NULL, uint8_t len=0)
 
int issue_P (uint16_t op, const void *args, uint8_t len)
 
int await (uint16_t op, void *args=NULL, uint8_t len=0)
 
int write_data (uint8_t op, const void *args, uint8_t args_len, const void *data, uint16_t data_len)
 
int write_data_P (uint8_t op, const void *args, uint8_t args_len, const void *data, uint16_t data_len)
 
int write_data (uint8_t op, const void *args, uint8_t args_len, const void *data, uint16_t data_len, bool progmem)
 
int read_data (uint8_t op, void *args, uint8_t args_len, void *data, uint16_t data_len)
 
void enable ()
 
void disable ()
 
bool is_available ()
 
void event_handler (Event::Handler *handler)
 
void set_clock (Clock rate)
 
void set_clock (uint32_t freq)
 

Static Public Member Functions

static Clock clock (uint32_t freq)
 
static Clock cycle (uint16_t ns)
 

Static Public Attributes

static const uint16_t DEFAULT_TIMEOUT = 3000
 

Protected Types

enum  { SPI_OP_WRITE = 0x01, SPI_OP_REPLY = 0x02, SPI_OP_READ = 0x03 }
 
enum  { HCI_TYPE_CMND = 0x01, HCI_TYPE_DATA = 0x02, HCI_TYPE_PATCH = 0x03, HCI_TYPE_EVNT = 0x04 }
 

Protected Attributes

IRQPin m_irq
 
volatile bool m_available
 
uint16_t m_timeout
 
Event::Handlerm_event_handler
 
uint8_t m_evnt [EVNT_MAX]
 
Driverm_next
 List of drivers. More...
 
OutputPin m_cs
 Device chip select pin. More...
 
Pulse m_pulse
 Chip select pulse width. More...
 
uint8_t m_spcr
 SPI/SPCR hardware control register setting. More...
 
uint8_t m_spsr
 SPI/SPSR hardware status register. More...
 

Static Protected Attributes

static const uint8_t EVNT_MAX = 64
 

Detailed Description

Host Control Interface (HCI) Protocol for SPI. Abstraction of the communication with CC3000 WiFi module. Handles command issue, data write, and reply and data read. Writes and reads HCI blocks in SPI frame. SPI frames are in big-endian, HCI frames in little-endian, except som data which are in network order (big-endian).

References

  1. CC3000 Protocol, http://processors.wiki.ti.com/index.php/CC3000_Protocol

Definition at line 38 of file HCI.hh.

Member Enumeration Documentation

anonymous enum
protected

SPI Header Operation Code.

Enumerator
SPI_OP_WRITE 

SPI Write(Payload Length,0).

SPI_OP_REPLY 

SPI Reply(device ready).

SPI_OP_READ 

SPI Read(0,Payload Length).

Definition at line 305 of file HCI.hh.

anonymous enum
protected

HCI Message Types.

Enumerator
HCI_TYPE_CMND 

HCI Command (SPI_OP_WRITE only).

HCI_TYPE_DATA 

HCI Data (both SPI_OP_WRITE/READ).

HCI_TYPE_PATCH 

HCI Patch (SPI_OP_WRITE only).

HCI_TYPE_EVNT 

HCI Event (SPI_OP_READ only).

Definition at line 333 of file HCI.hh.

Constructor & Destructor Documentation

HCI::HCI ( Board::DigitalPin  cs,
Board::ExternalInterruptPin  irq,
SPI::Clock  rate = SPI::DEFAULT_CLOCK 
)
inline

Construct SPI based HCI driver with given chip select and interrupt request pin. May also configure with SPI clock rate.

Parameters
[in]cschip select pin.
[in]irqinterrupt request pin.
[in]rateof communication with device.

Definition at line 69 of file HCI.hh.

Member Function Documentation

int HCI::await ( uint16_t  op,
void *  args = NULL,
uint8_t  len = 0 
)

Await HCI event and arguments. Returns argument length or negative error code. The given argument block must be able to hold incoming event message. A default event block is used when passer NULL.

Parameters
[in]opHCI event code required.
[in]argspointer to argument block.
[in]lenmax number of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 123 of file HCI.cpp.

static Clock SPI::Driver::clock ( uint32_t  freq)
inlinestaticinherited

Calculate SPI clock rate (scale factor) for given frequency.

Parameters
[in]freqdevice max frequency (in Hz).
Returns
clock rate.

Definition at line 117 of file SPI.hh.

static Clock SPI::Driver::cycle ( uint16_t  ns)
inlinestaticinherited

Calculate SPI clock rate (scale factor) for given clock cycle time in nano seconds.

Parameters
[in]nsmin device clock cycle time.
Returns
clock rate.

Definition at line 135 of file SPI.hh.

void HCI::disable ( )
inline

Disable incoming HCI packets (DATA/EVNT).

Definition at line 243 of file HCI.hh.

void HCI::enable ( )
inline

Enable incoming HCI packets (DATA/EVNT).

Definition at line 235 of file HCI.hh.

void HCI::event_handler ( Event::Handler handler)
inline

Set event service handler. Called by service() for incoming events.

Parameters
[in]handler.

Definition at line 262 of file HCI.hh.

bool HCI::is_available ( )
inline

Return true(1) if a packet is available otherwise false(0).

Returns
bool.

Definition at line 252 of file HCI.hh.

int HCI::issue ( uint16_t  op,
const void *  args = NULL,
uint8_t  len = 0 
)
inline

Issue given HCI command message and arguments. Returns argument length or negative error code.

Parameters
[in]opHCI operation command.
[in]argspointer to argument block.
[in]lennumber of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 140 of file HCI.hh.

int HCI::issue_P ( uint16_t  op,
const void *  args,
uint8_t  len 
)
inline

Issue given HCI command message and arguments in program memory block. Returns argument length or negative error code.

Parameters
[in]opHCI operation command.
[in]argspointer to argument block.
[in]lennumber of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 153 of file HCI.hh.

int HCI::read ( uint16_t &  op,
void *  args,
uint8_t  len 
)

Read HCI operation and arguments. Returns argument length or negative error code. The given argument block must be able to hold incoming packet.

Parameters
[out]opHCI operation command.
[in]argspointer to argument block.
[in]lenmax number of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 25 of file HCI.cpp.

int HCI::read_data ( uint8_t  op,
void *  args,
uint8_t  args_len,
void *  data,
uint16_t  data_len 
)

Issue HCI read data command message and arguments. Returns payload length or negative error code.

Parameters
[in]opHCI data operation command.
[in]argspointer to command argument block.
[in]args_lennumber of bytes in command argument block.
[in]datapointer to data block.
[in]data_lennumber of bytes in data block.
Returns
argument length or negative error code.

Definition at line 158 of file HCI.cpp.

void SPI::Driver::set_clock ( Clock  rate)
inherited

Set SPI master clock rate.

Parameters
[in]clockrate.

Definition at line 297 of file SPI.cpp.

void SPI::Driver::set_clock ( uint32_t  freq)
inlineinherited

Set SPI master clock frequency.

Parameters
[in]freqdevice max frequency (in Hz).

Definition at line 157 of file SPI.hh.

int HCI::write ( uint8_t  type,
uint16_t  op,
const void *  args,
uint8_t  len 
)
inline

Write given HCI type operation and arguments. Returns argument length or negative error code.

Parameters
[in]typeHCI message type.
[in]opHCI operation command.
[in]argspointer to argument block.
[in]lennumber of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 100 of file HCI.hh.

int HCI::write ( uint8_t  type,
uint16_t  op,
const void *  args,
uint8_t  len,
bool  progmem 
)

Write given HCI type operation and arguments. Returns argument length or negative error code.

Parameters
[in]typeHCI message type.
[in]opHCI operation command.
[in]argspointer to argument block (program memory).
[in]lennumber of bytes in argument block.
[in]progmemargment block in program memory.
Returns
argument length or negative error code.

Definition at line 81 of file HCI.cpp.

int HCI::write_data ( uint8_t  op,
const void *  args,
uint8_t  args_len,
const void *  data,
uint16_t  data_len 
)
inline

Write data with given data operation code, argument block and data payload. Returns number of bytes written or negative error code.

Parameters
[in]opdata operation code.
[in]argspointer to argument block.
[in]args_lennumber of bytes in argument block.
[in]datapointer to data block
[in]data_lennumber of bytes in data block.
Returns
number of bytes written or negative error code.

Definition at line 181 of file HCI.hh.

int HCI::write_data ( uint8_t  op,
const void *  args,
uint8_t  args_len,
const void *  data,
uint16_t  data_len,
bool  progmem 
)

Write data with given data operation code, argument block and data payload in given memory source. Returns number of bytes written or negative error code.

Parameters
[in]opdata operation code.
[in]argspointer to argument block.
[in]args_lennumber of bytes in argument block.
[in]datapointer to data block.
[in]data_lennumber of bytes in data block.
[in]progmemflag data block in program memory.
Returns
number of bytes written or negative error code.

Definition at line 221 of file HCI.cpp.

int HCI::write_data_P ( uint8_t  op,
const void *  args,
uint8_t  args_len,
const void *  data,
uint16_t  data_len 
)
inline

Write data with given data operation code, argument block and data payload in program memory. Returns number of bytes written or negative error code.

Parameters
[in]opdata operation code.
[in]argspointer to argument block.
[in]args_lennumber of bytes in argument block.
[in]datapointer to data block in program memory.
[in]data_lennumber of bytes in data block.
Returns
number of bytes written or negative error code.

Definition at line 198 of file HCI.hh.

int HCI::write_P ( uint8_t  type,
uint16_t  op,
const void *  args,
uint8_t  len 
)
inline

Write given HCI type operation and arguments in program memory. Returns argument length or negative error code.

Parameters
[in]typeHCI message type.
[in]opHCI operation command.
[in]argspointer to argument block in program memory.
[in]lennumber of bytes in argument block.
Returns
argument length or negative error code.

Definition at line 114 of file HCI.hh.

Member Data Documentation

const uint16_t HCI::DEFAULT_TIMEOUT = 3000
static

Default timeout on command/data reply (in ms).

Definition at line 60 of file HCI.hh.

const uint8_t HCI::EVNT_MAX = 64
staticprotected

Size of default event block.

Definition at line 353 of file HCI.hh.

volatile bool HCI::m_available
protected

Request flag.

Definition at line 344 of file HCI.hh.

OutputPin SPI::Driver::m_cs
protectedinherited

Device chip select pin.

Definition at line 166 of file SPI.hh.

Event::Handler* HCI::m_event_handler
protected

Event handler for unsolicited events.

Definition at line 350 of file HCI.hh.

uint8_t HCI::m_evnt[EVNT_MAX]
protected

Default event block.

Definition at line 356 of file HCI.hh.

IRQPin HCI::m_irq
protected

Interrupt request handler.

Definition at line 341 of file HCI.hh.

Driver* SPI::Driver::m_next
protectedinherited

List of drivers.

Definition at line 164 of file SPI.hh.

Pulse SPI::Driver::m_pulse
protectedinherited

Chip select pulse width.

Definition at line 167 of file SPI.hh.

uint8_t SPI::Driver::m_spcr
protectedinherited

SPI/SPCR hardware control register setting.

Definition at line 173 of file SPI.hh.

uint8_t SPI::Driver::m_spsr
protectedinherited

SPI/SPSR hardware status register.

Definition at line 174 of file SPI.hh.

uint16_t HCI::m_timeout
protected

Reply timeout in milli-seconds.

Definition at line 347 of file HCI.hh.


The documentation for this class was generated from the following files: