PIC24 Support Libraries
Macros | Functions
dataXfer.h File Reference

Routines which implement the uC comm protocol. More...

#include "dataXferImpl.h"

Go to the source code of this file.

Macros

#define RECEIVE_TIMEOUT   (FCY * 1/20 * 0.1)
 
#define SPECIFY_VAR(u_varIndex, data, isWriteable, format, desc)   specifyVar(u_varIndex, &data, sizeof(data), isWriteable, format, #data, desc)
 

Functions

void outCharXfer (char c)
 
void outChar (uint8_t c)
 A system-dependent macro to output one character. More...
 
void initDataXfer ()
 
void specifyVar (uint u_varIndex, volatile void *pv_data, uint u_size, BOOL b_isWriteable, char *psz_format, char *psz_name, char *psz_desc)
 
void sendVar (uint u_varIndex)
 
int formatVar (uint u_varIndex, char *psz_buf, size_t s_len)
 
uint receiveVar (char *c)
 
char inCharXfer ()
 

Detailed Description

Routines which implement the uC comm protocol.

Definition in file dataXfer.h.

Macro Definition Documentation

◆ RECEIVE_TIMEOUT

#define RECEIVE_TIMEOUT   (FCY * 1/20 * 0.1)

Number of for loop iterations which equal a timeout for the microcontroller.

loops = instructions/sec * loops/instruction * seconds

Definition at line 45 of file dataXfer.h.

◆ SPECIFY_VAR

#define SPECIFY_VAR (   u_varIndex,
  data,
  isWriteable,
  format,
  desc 
)    specifyVar(u_varIndex, &data, sizeof(data), isWriteable, format, #data, desc)

For simplicity, define a macro that specifies a variable with default names. uC only.

Parameters
u_varIndexA value from 0-NUM_XFER_VARS, unique for each var
dataA pointer to the data to be sent
isWriteableTrue if the PC is allowed to change this variable; false otherwise. This does NOT restrict the microcontroller to read-only access to this variable.
formatprintf format string to use in displaying the variable
descDescription of this variable.

Definition at line 103 of file dataXfer.h.

Function Documentation

◆ formatVar()

int formatVar ( uint  u_varIndex,
char *  psz_buf,
size_t  s_len 
)

Return a string with the data stored in the given variable formatted using the format string contained in the variable. PC only.

Parameters
u_varIndexThe index of the variable to send; must be from 0 to NUM_XFER_VARS.
psz_bufBuffer to contain the formatted string.
s_lenLength of the buffer.
Returns
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string. On failure, a negative number is returned.

Definition at line 132 of file dataXfer.c.

◆ inCharXfer()

char inCharXfer ( )

Receive a character, while transparently processing any variables sent by the PC. Variables are assigned, but this simple interface does not report these assignments to its caller. This provides a simple wrapper around receiveVar, which also reports on received variables. uC only.

Returns
The character received.

◆ initDataXfer()

void initDataXfer ( )

Initialize the data transfer system. This must be called before calling any of the data transfer functions in the library.

Definition at line 17 of file dataXfer.c.

◆ outChar()

void outChar ( uint8_t  u8_c)

A system-dependent macro to output one character.

Write a character to the serial port. This function blocks until a character is written. The UART used is determined by the __C30_UART variable, which defaults to 1.

Parameters
u8_cCharacter to write

Definition at line 58 of file pic24_serial.c.

◆ outCharXfer()

void outCharXfer ( char  c)

Send one character to the uC, escaping if necessary.

Parameters
cCharacter to send.

Definition at line 27 of file dataXfer.c.

◆ receiveVar()

uint receiveVar ( char *  c)

Receive a character or a variable. Any errors that occur are reported via outString. uC only.

Parameters
cPointer to space for storing the received character, if a character was received (see return value).
Returns
An index to the variable, if a variable was received, or CHAR_RECEIVED_INDEX if a character was received.

◆ sendVar()

void sendVar ( uint  u_varIndex)

Send an already-specified variable;

See also
specifyVar.
Parameters
u_varIndexThe index of the variable to send; must be from 0 to NUM_XFER_VARS.

Definition at line 88 of file dataXfer.c.

◆ specifyVar()

void specifyVar ( uint  u_varIndex,
volatile void *  pv_data,
uint  u_size,
BOOL  b_isWriteable,
char *  psz_format,
char *  psz_name,
char *  psz_desc 
)

Specify a variable to be sent or received. uC only.

Parameters
u_varIndexA value from 0-NUM_XFER_VARS, unique for each var
pv_dataA pointer to the data to be sent
u_sizeSize of the data in bytes; must be from 1 to 256.
b_isWriteableTrue if the PC is allowed to change this variable; false otherwise. This does NOT restrict the microcontroller to read-only access to this variable.
psz_formatprintf format string to use in displaying the Variable.
psz_nameName of this variable, typically the same as used in the code
psz_descDescription of this variable.

Definition at line 36 of file dataXfer.c.