#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. |
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.
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.buf
is a CAN buffer retrieved from can_get_rx_msg
.buf
is free to receive another message from the CAN bus NOTE: buf
is no longer valid for further operationsunsigned 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 retrievebuf
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
)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
buf
is a CAN receive buffer obtained from can_get_rx_msg
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:
can_init
CAN_BUFFER can_get_tx_buf | ( | ) |
can_get_tx_buf:
retrieve a free CAN transmit buffer handle.
Parameters:
can_init
Postcondition: 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
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.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 transmittedbuf
has been initialized with an address and data (see can_set_address_std
, can_set_address_ext
, and can_set_buffer_data
)buf
has been transmittedvoid 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 transmittedbuf
has been initialized with an address and data (see can_set_address_std
, can_set_address_ext
, and can_set_buffer_data
)buf
has been transmittedvoid 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 buffercan_init
can_get_tx_buf
addr
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 buffercan_init
can_get_tx_buf
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)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
byteslength
bytes from data_in
are copied to the CAN transmit buffer specified by buf