All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexspi.h File Reference

SPI communication to the master processor, macros and prototypes. More...

Go to the source code of this file.

Data Structures

struct  _jsdata
 joystick data structure More...
 
union  _spiTxPacket
 SPI transmit data packet. More...
 
struct  _spiTxPacket::_spiTxPak
 
union  _spiRxPacket
 SPI receive data packet. More...
 
struct  _spiRxPacket::_spiRxPak
 
struct  _SpiData
 SPI data. More...
 

Macros

#define CONVEX_TEAM_NAME   "CONVEX ";
 default team name More...
 
#define vexTeamnameSet(name)   vexSpiTeamnameSet( name )
 

Typedefs

typedef struct _jsdata jsdata
 joystick data structure More...
 
typedef union _spiTxPacket spiTxPacket
 SPI transmit data packet. More...
 
typedef union _spiRxPacket spiRxPacket
 SPI receive data packet. More...
 
typedef struct _SpiData SpiData
 SPI data. More...
 

Functions

void vexSpiInit (void)
 Init the SPI communication to the master processor. More...
 
void vexSpiTeamnameSet (char *name)
 Set the team name. More...
 
short vexSpiGetOnlineStatus (void)
 We use presence of js_1 as indication of good joystick data. More...
 
void vexSpiSetMotor (int16_t index, int16_t data, bool_t reversed)
 Set motor value in the SPI tx data array. More...
 
void vexSpiSend (void)
 Send/receive one message with the master processor. More...
 
void vexSpiTickDelay (int16_t tick)
 Pause for exactly tick uS. More...
 
jsdatavexSpiGetJoystickDataPtr (int16_t index)
 return a pointer to a raw joystick data structure More...
 
uint16_t vexSpiGetControl (void)
 Get competition and status word. More...
 
uint16_t vexSpiGetMainBattery (void)
 Get main battery level. More...
 
uint16_t vexSpiGetBackupBattery (void)
 Get backup battery level. More...
 
void vexSpiDebug (vexStream *chp, int argc, char *argv[])
 Debug function to dump SPI buffers. More...
 

Detailed Description

SPI communication to the master processor, macros and prototypes.

Macro Definition Documentation

#define CONVEX_TEAM_NAME   "CONVEX ";

default team name

#define vexTeamnameSet (   name)    vexSpiTeamnameSet( name )

Typedef Documentation

typedef struct _jsdata jsdata

joystick data structure

Format of the joystick component of the SPI receive packet The reserved bytes are really used for other purposes but we keep them here in V1.00

typedef union _spiTxPacket spiTxPacket

SPI transmit data packet.

Format of a SPI transmit packet - 16 words

typedef union _spiRxPacket spiRxPacket

SPI receive data packet.

Format of a SPI receive packet - 16 words

typedef struct _SpiData SpiData

SPI data.

All SPI related data collected in this structure

Function Documentation

void vexSpiInit ( void  )

Init the SPI communication to the master processor.

void vexSpiTeamnameSet ( char *  name)

Set the team name.

Parameters
[in]namepointer to string
short vexSpiGetOnlineStatus ( void  )

We use presence of js_1 as indication of good joystick data.

Returns
online status
Return values
1= online
0= offline
void vexSpiSetMotor ( int16_t  index,
int16_t  data,
bool_t  reversed 
)

Set motor value in the SPI tx data array.

Parameters
[in]indexThe index of the motor, range is 0 through 7
[in]dataThe motor command data in the range +/- 127
[in]reversedA flag indicating the motor data is reversed

This function is used to set the data for one of the 3 wire motor ports on the master processor. These correspond to cortex ports 2 through 9 but are indexed here as ports 0 through 7

void vexSpiSend ( void  )

Send/receive one message with the master processor.

Note
This is generally called by the system task

This implementation is based on the EasyC code but with the loop delays/ replaced with the use of a timer so compiler optimization can be used. Timing was then changed so there is really not much resemblance to the original code.

void vexSpiTickDelay ( int16_t  tick)

Pause for exactly tick uS.

Parameters
[in]tickThe delay in uS
Note
New version suspends thread, timer callback wakes thread
Internal SPI driver use only
jsdata* vexSpiGetJoystickDataPtr ( int16_t  index)

return a pointer to a raw joystick data structure

Parameters
[in]indexWhich joystick to use, 1 or 2
Returns
pointer to _jsdata structure
uint16_t vexSpiGetControl ( void  )

Get competition and status word.

Returns
The status word from the spi data
uint16_t vexSpiGetMainBattery ( void  )

Get main battery level.

Returns
The battery level in mV
Note
Battery level has a resolution of 59mV
uint16_t vexSpiGetBackupBattery ( void  )

Get backup battery level.

Returns
The battery level in mV
Note
Battery level has a resolution of 59mV
void vexSpiDebug ( vexStream chp,
int  argc,
char *  argv[] 
)

Debug function to dump SPI buffers.

Parameters
[in]chpA pointer to a vexStream object
[in]argcThe number of command line arguments
[in]argvAn array of pointers to the command line args