D:/pic/ecsedesign/can.c File Reference

routines for using the CAN controller with the PIC18F25K80. More...

#include <system.h>
#include "can.h"

Functions

void can_init ()
 can_init: initialize CAN peripheral This function is responsible for all CAN initialization.
void can_set_address_std (CAN_BUFFER buf, unsigned long addr)
 can_set_address_std: assign an 11-bit ID to a CAN buffer.
void can_set_address_ext (CAN_BUFFER buf, unsigned long addr)
 can_set_address_ext: assign a 29-bit ID to a CAN buffer.
void can_initialize_tx_buf (CAN_BUFFER buf)
 can_initialize_tx_buf: Initialize transmit buffer.
void can_set_buffer_data (CAN_BUFFER buf, unsigned char *data_in, unsigned char length)
 can_set_buffer_data: Set CAN message buffer data and length.
void can_send_tx_buf (CAN_BUFFER buf)
 can_send_tx_buf: Initiate transmission of a CAN transmit buffer.
void can_send_rtr (CAN_BUFFER buf)
 can_send_rtr: Initiate transmission of a CAN transmit buffer with RTR bit.
CAN_BUFFER can_get_tx_buf ()
 can_get_tx_buf: Retrieve a free CAN transmit buffer handle.
CAN_BUFFER can_get_rx_msg ()
 can_get_rx_msg: Get a handle to the next message in the queue of incoming messages.
void can_free_rx_buf (CAN_BUFFER buf)
 can_free_rx_buf: Free a CAN receive buffer to receive another message.
unsigned char can_get_dlc (CAN_BUFFER buf)
 can_get_dlc: get CAN Data Length Code from a receive buffer.
unsigned char can_get_data_byte (CAN_BUFFER buf, unsigned char index)
 can_get_data_byte: get data byte from a CAN receive buffer.


Detailed Description

routines for using the CAN controller on the PIC18F2680.

These routines simplify the usage of CAN on the PIC18F2680 and other controllers of the same family. The routines have been designed for portability to other controllers, and therefore use the concept of an opaque pointer to a CAN buffer. Objects of the CAN_BUFFER type should be considered opaque except for the following: CAN_BUFFERs may be tested for truth to determine whether or not they are valid. With this exception, they should only be passed between the routines defined in this file to perform various CAN operations and extract and modify data.


Function Documentation

void can_free_rx_buf ( CAN_BUFFER  buf  ) 

can_free_rx_buf: Free a CAN receive buffer to receive another message.

Parameters:

  • buf: A handle to the receive buffer to be freed.
Precondition:
  • buf is a CAN buffer retrieved from can_get_rx_msg.
Postcondition:
  • buf is free to receive another message from the CAN bus NOTE: buf is no longer valid for further operations
Return Value: None

unsigned char can_get_data_byte ( CAN_BUFFER  buf,
unsigned char  index 
)

can_get_data_byte: get data byte from a CAN receive buffer.

Parameters:

  • buf: the CAN receive buffer to retrieve data from
  • index: the offset of the data byte to retrieve
Precondition:
  • buf is a valid CAN receive buffer from can_get_rx_msg
  • index is a value less than the length of the message (see can_get_dlc)
Postcondition: The data byte at offset index is extracted and returned.

Return Value: The message data byte at offset index into the message.

unsigned char can_get_dlc ( CAN_BUFFER  buf  ) 

can_get_dlc: get CAN Data Length Code from a receive buffer.

Parameters:

  • buf: a CAN receive buffer obtained from can_get_rx_msg
Precondition:
  • buf is a CAN receive buffer obtained from can_get_rx_msg
Postcondition: the Data Length Code is extracted and returned from the buffer

Return Value: Data Length Code from the buffer

CAN_BUFFER can_get_rx_msg (  ) 

can_get_rx_msg: Get a handle to the next message in the queue of incoming messages.

Parameters:

  • None
Precondition:
  • CAN peripheral has been initialized by can_init
Postcondition:
  • If message is present, it will be returned. Otherwise, 0 will be returned.
Return Value: Handle to buffer containing the next message received, or 0 if no message is present.

CAN_BUFFER can_get_tx_buf (  ) 

can_get_tx_buf: retrieve a free CAN transmit buffer handle.

Parameters:

  • None Precondition:
  • CAN peripheral has been initialized by can_init Postcondition:
  • a free CAN transmit buffer has been obtained Return Value: handle to the free CAN buffer

void can_init (  ) 

can_init: initialize CAN peripheral This function is responsible for all CAN initialization.

Dependencies:

  • can_setup_baud_rate
  • can_setup_buffers
  • can_select_mode
Postconditions:
  • CAN peripheral is ready for use
  • Other CAN functions may be used

void can_initialize_tx_buf ( CAN_BUFFER  buf  ) 

can_initialize_tx_buf: Initialize transmit buffer.

This function is used internally by can_init and should not be called directly.

Parameters:

  • buf: The CAN buffer to be initialized.
Precondition:
  • None.
Postcondition:
  • The CAN buffer is initialized as required by the hardware.
Return Value: None.

void can_send_tx_buf ( CAN_BUFFER  buf  ) 

can_send_tx_buf: Initiate transmission of a CAN transmit buffer.

Parameters:

  • buf: the CAN buffer which is to be transmitted
Precondition:
  • buf has been initialized with an address and data (see can_set_address_std, can_set_address_ext, and can_set_buffer_data)
Postcondition:
  • buf has been transmitted
Return Value: None. Function will block until transmission is complete.

void can_send_rtr ( CAN_BUFFER  buf  ) 

can_send_tx_buf: Initiate transmission of a CAN transmit buffer with RTR request.

Parameters:

  • buf: the CAN buffer which is to be transmitted
Precondition:
  • buf has been initialized with an address and data (see can_set_address_std, can_set_address_ext, and can_set_buffer_data)
Postcondition:
  • buf has been transmitted
Return Value: None. Function will block until transmission is complete.

void can_set_address_ext ( CAN_BUFFER  buf,
unsigned long  addr 
)

can_set_address_ext: assign a 29-bit ID to a CAN buffer.

Parameters:

  • buf: The buffer whose address is to be set
  • addr: The 29-bit address to assign to the buffer
Precondition:
  • The CAN peripheral has been initialized by can_init
  • buf is a valid CAN transmit buffer handle obtained from can_get_tx_buf
Postcondition:
  • The buffer specified by buf contains the 29-bit address addr
Return Value: None

void can_set_address_std ( CAN_BUFFER  buf,
unsigned long  addr 
)

can_set_address_std: assign an 11-bit ID to a CAN buffer.

Parameters:

  • buf: The buffer whose address is to be set
  • addr: The 11-bit address to assign to the buffer
Precondition:
  • The CAN peripheral has been initialized by can_init
  • buf is a valid CAN transmit buffer handle obtained from can_get_tx_buf
Postcondition: The buffer specified by buf contains the 11-bit address addr

Return Value: None

void can_set_buffer_data ( CAN_BUFFER  buf,
unsigned char *  data_in,
unsigned char  length 
)

can_set_buffer_data: Set CAN message buffer data and length.

Parameters:

  • buf: A handle to the transmit buffer which is to receive the data.
  • data_in: A pointer to the data bytes to be copied to the buffer.
  • length: The data length. (If greater than 8, data will be truncated to 8 bytes)
Precondition:
  • buf points to a valid CAN transmit buffer (obtained from can_get_tx_buf)
  • data_in points to a region of data of at least length bytes
Postcondition:
  • length bytes from data_in are copied to the CAN transmit buffer specified by buf
Return Value: None


Generated on Wed Apr 16 12:56:30 2008 for ecsedesign by  doxygen 1.5.5