robotics/include/comm.h File Reference

Go to the source code of this file.

Functions

void divvy_packet (void)
uint8 CommGetInDataUInt8Error (void)
uint8 CommGetInDataIsValid (void)
void CommGetInDataClearError (void)
uint8 CommGetInDataUInt8 (void)
int8 CommGetInDataInt8 (void)
uint16 CommGetInDataUInt16 (void)
int16 CommGetInDataInt16 (void)
uint32 CommGetInDataUInt32 (void)
int32 CommGetInDataInt32 (void)
void CommPutOutDataUInt8 (uint8)
void CommPutOutDataInt8 (int8)
void CommPutOutDataUInt16 (uint16)
void CommPutOutDataInt16 (int16)
void CommPutOutDataUInt32 (uint32)
void CommPutOutDataInt32 (int32)
 ESOS_USER_TASK (comm)
void initialize_comm (void)
 Initializes the comm library This function initializes the comm library. It will set the outbound packet's header and trailer, as specified by OUT_PACKET_HEADER_1 and OUT_PACKET_HEADER_2. Additionally, the commError structure is zeroed, and the "comm" task is registered with ESOS.


Detailed Description

Author:
Thomas Donaldson

Definition in file comm.h.


Function Documentation

void CommGetInDataClearError ( void   ) 

Clears all error flags.

Definition at line 98 of file comm.c.

int16 CommGetInDataInt16 ( void   ) 

This function returns the value of the next int16 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever an int16 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE). Of note, the PIC is a little-endian device, and thus some data martialing may be required from the sending machine.

int32 CommGetInDataInt32 ( void   ) 

This function returns the value of the next int32 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever a int32 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE). Of note, the PIC is a little-endian device, and thus some data martialing may be required from the sending machine.

int8 CommGetInDataInt8 ( void   ) 

This function returns the value of the next int8 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever an int8 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE).

uint8 CommGetInDataIsValid ( void   ) 

Returns 1 if the current packet contains valid data and 0 if not.

Definition at line 90 of file comm.c.

uint16 CommGetInDataUInt16 ( void   ) 

This function returns the value of the next uint16 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever a uint16 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE). Of note, the PIC is a little-endian device, and thus some data martialing may be required from the sending machine.

uint32 CommGetInDataUInt32 ( void   ) 

This function returns the value of the next uint32 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever a uint32 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE). Of note, the PIC is a little-endian device, and thus some data martialing may be required from the sending machine.

uint8 CommGetInDataUInt8 ( void   ) 

This function returns the value of the next uint8 in au8_inPacket. An internal index is kept automatically, so this function is meant to be called whenever a uint8 needs to be retreived. It will ASSERT if a value past the payload boundary is attempted to be retreived (see IN_PACKET_SIZE).

uint8 CommGetInDataUInt8Error ( void   ) 

Returns a uint8 representing any errors detected while receiving. The bit field for the uint8 is:

 [ NA | NA | Bad State | Trailer 2 Error | Trailer 1 Error | Header 2 Error | Duplicate Header 1 | Header 1 Error ] 
If desired, bit masks can be used to check for specific errors or use CommGetInDataIsValid.

Definition at line 81 of file comm.c.

void CommPutOutDataInt16 ( int16   ) 

This function inserts the value of the passed int16 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE). The receiver should keep in mind that the PIC is a little-endian device.

void CommPutOutDataInt32 ( int32   ) 

This function inserts the value of the passed int32 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE). The receiver should keep in mind that the PIC is a little-endian device.

void CommPutOutDataInt8 ( int8   ) 

This function inserts the value of the passed int8 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE).

void CommPutOutDataUInt16 ( uint16   ) 

This function inserts the value of the passed uint8 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE). The receiver should keep in mind that the PIC is a little-endian device.

void CommPutOutDataUInt32 ( uint32   ) 

This function inserts the value of the passed uint32 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE). The receiver should keep in mind that the PIC is a little-endian device.

void CommPutOutDataUInt8 ( uint8   ) 

This function inserts the value of the passed uint8 into the outbound packet and moves the internal index appropriately. It will ASSERT if the call will write data past the specified payload boundary (see OUT_PACKET_SIZE).

void divvy_packet ( void   ) 

The user should define their own divvy_packet function. That way, it is tailored to their application of the comm library. The function is called each time an incoming packet is successfully captured. It is the responsibility of the user to distribute the contents of au8_inPacket and fill the au8_outPacket with information. The packets are not to be accessed directly, but rather through the provided functions. See CommGetInDataUInt8 and CommPutOutDataUInt8 for details. With these functions, the packets are meant to be read once-through.

This function demonstrates the use of the comm library's various get and put functions. It reads in the all the possible variables, increments them, and echos them back (prepending an error byte). For example, sending (alignment is for better representation):

 0x55 AA    11 22 3333 4444 55555555 66666666 AA 55 
will return:
 0x66 BB 00 12 23 3433 4544 56555555 67666666 BB 66 

Definition at line 44 of file esos_comm_example.c.

ESOS_USER_TASK ( comm   ) 

Precondition:
initialize_comm() must be called first. This ESOS user task parses the incoming communication with a finite state machine. It specifically looks for the IN_PACKET_HEADER_1 and IN_PACKET_HEADER_2 before it accepts the remaining information as valid. The last two bytes are looked at, and a flag byte is set if the trailer does not match. The task then calls the user-defined divvy_packet() function in order to let the user distribute the current inbound packet and assemble the next outbound packet. Once divvy_packet() returns, the outbound packet is sent.

Definition at line 103 of file comm.c.


Generated on Sun Mar 15 11:14:22 2009 for PIC24 Support Libraries by  doxygen 1.5.8