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

SPI communication to the master processor. More...

#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "vex.h"

Macros

#define SPI_BATTERY_SCALE   59
 Scale factor for getting battery level in mV. More...
 

Functions

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

Detailed Description

SPI communication to the master processor.

Macro Definition Documentation

#define SPI_BATTERY_SCALE   59

Scale factor for getting battery level in mV.

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
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 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 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
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 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