LTlib LaurTec Library  4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
module_CAN.c File Reference
#include "module_CAN.h"

Go to the source code of this file.

Functions

void CAN_open (BYTE propSeg, BYTE phaseSeg1, BYTE phaseSeg2, BYTE SJW, BYTE BRP, enum CAN_CONFIG_FLAGS flags)
 
void CAN_close (void)
 
void CAN_write_message (unsigned long identifier, BYTE *data, BYTE dataLength, enum CAN_TX_MSG_FLAGS flags)
 
unsigned char CAN_read_message (CANmessage *msg)
 
void CAN_set_mask (enum CAN_MASK mask_number, unsigned long mask, enum CAN_CONFIG_FLAGS type)
 
void CAN_set_filter (enum CAN_FILTER filter_number, unsigned long filter, enum CAN_CONFIG_FLAGS type)
 
void CAN_operation_mode (enum CAN_OP_MODE mode)
 
void CAN_abort_messages (void)
 
BYTE CAN_is_BUS_OFF (void)
 
BYTE CAN_is_TX_passive (void)
 
BYTE CAN_is_RX_passive (void)
 
BYTE CAN_is_TX_warning_ON (void)
 
BYTE CAN_is_RX_warning_ON (void)
 
BYTE CAN_get_TX_error_count (void)
 
BYTE CAN_get_RX_error_count (void)
 
BYTE CAN_is_TX_ready (void)
 
BYTE CAN_is_RX_ready (void)
 

Function Documentation

void CAN_abort_messages ( void  )

This function let the CAN module discard all the TX messages.

Parameters
none
Returns
none

Definition at line 1034 of file module_CAN.c.

void CAN_close ( void  )

This function disable the CAN module setting it in SLEEP mode.

Parameters
void
Returns
void

Definition at line 138 of file module_CAN.c.

References CAN_OP_MODE_SLEEP, and CAN_operation_mode().

BYTE CAN_get_RX_error_count ( void  )

This function returns the number of RX errors.

Parameters
none
Returns
error Number of errors

Definition at line 1087 of file module_CAN.c.

BYTE CAN_get_TX_error_count ( void  )

This function returns the number of TX errors.

Parameters
none
Returns
error Number of errors

Definition at line 1079 of file module_CAN.c.

BYTE CAN_is_BUS_OFF ( void  )

This function is used to check if the mdoule is in BUS OFF. The module gets to BUSS OFF once the error counter reaches 255.

Parameters
none
Returns
status 1: BUS is off 0: Normal Operation

Definition at line 1042 of file module_CAN.c.

BYTE CAN_is_RX_passive ( void  )

This function returns the RX BUS passive status. The device gets in passive mode once the error counter has exceeded the error limit of 127.

Parameters
none
Returns
status 1: CAN Module is passive 0: Normal Operation

Definition at line 1057 of file module_CAN.c.

BYTE CAN_is_RX_ready ( void  )

This function checks if there is any data within the RX buffer.

Parameters
none
Returns
status 1: One or more messages are in the buffer 0: RX buffer is empty

Definition at line 1104 of file module_CAN.c.

BYTE CAN_is_RX_warning_ON ( void  )

This function returns RX warning status.It gets ON once the error counter reaches the value 96. While the warning is ON the CAN modules still operates properly.

Parameters
none
Returns
status 1: RX Warning is ON 0: Normal Operation

Definition at line 1071 of file module_CAN.c.

BYTE CAN_is_TX_passive ( void  )

This function returns the TX BUS passive status. The device gets in passive mode once the error counter has exceeded the error limit of 127.

Parameters
none
Returns
status 1: CAN Module is passive 0: Normal Operation

Definition at line 1049 of file module_CAN.c.

BYTE CAN_is_TX_ready ( void  )

This function checks if there is any free slot within the TX buffer.

Parameters
none
Returns
status 1: One or more message slot are available 0: TX buffer is full.

Definition at line 1095 of file module_CAN.c.

BYTE CAN_is_TX_warning_ON ( void  )

This function returns TX warning status. It gets ON once the error counter reaches the value 96. While the warning is ON the CAN modules still operates properly.

Parameters
none
Returns
status 1: TX Warning is ON 0: Normal Operation

Definition at line 1064 of file module_CAN.c.

void CAN_open ( BYTE  propSeg,
BYTE  phaseSeg1,
BYTE  phaseSeg2,
BYTE  SJW,
BYTE  BRP,
enum CAN_CONFIG_FLAGS  flags 
)

This function is used to initialize the module. It should be the first function to be calles.

Parameters
propSegPropagation Segment, PROP_SEG as per CAN specifications [value: 1...8]
phaseSeg1PHASE_SEG1 as per CAN specifications [value: 1...8]
phaseSeg2PHASE_SEG2 as per CAN specifications [value: 1...8]
SJWSynchronized Jump Width as per CAN specifications [value: 1...4]
BRPBaud Rate Prescaler [value: 0...63]
flagsCAN Module configuration [use the CAN_CONFIG_FLAGS values]
Returns
void
Note
Refer to the MCU datasheet and CAN specifications for more details.

Definition at line 53 of file module_CAN.c.

References CAN_CONFIG_DBL_BUFFER_BIT, CAN_CONFIG_DBL_BUFFER_ON, CAN_CONFIG_LINE_FILTER_BIT, CAN_CONFIG_MSG_BITS, CAN_CONFIG_PHSEG2_PRG_BIT, CAN_CONFIG_SAMPLE_BIT, CAN_CONFIG_STD_MSG, CAN_CONFIG_VALID_STD_MSG, CAN_CONFIG_VALID_XTD_MSG, CAN_CONFIG_XTD_MSG, CAN_FILTER_B1_F1, CAN_FILTER_B1_F2, CAN_FILTER_B2_F1, CAN_FILTER_B2_F2, CAN_FILTER_B2_F3, CAN_FILTER_B2_F4, CAN_MASK_B1, CAN_MASK_B2, CAN_OP_MODE_CONFIG, CAN_OP_MODE_NORMAL, CAN_operation_mode(), CAN_set_filter(), and CAN_set_mask().

void CAN_operation_mode ( enum CAN_OP_MODE  mode)

This function changes the CAN module operational mode.

Parameters
modeMode to be set for the CAN module [
Returns
void

for the mode you have to use one of the folowing constants: CAN_OP_MODE_NORMAL CAN_OP_MODE_SLEEP, CAN_OP_MODE_LOOP, CAN_OP_MODE_LISTEN, CAN_OP_MODE_CONFIG

Definition at line 1024 of file module_CAN.c.

unsigned char CAN_read_message ( CANmessage msg)

This function reads a message from the RX buffer. The data is stored within a CANmessage structure.

Parameters
msgPointer to a CANmessage structure.
Returns
error Reprots the error out of the COMSTAT register
Note
Refer to the MCU datasheet and CAN specifications for more details.

Definition at line 402 of file module_CAN.c.

References CAN_RX_BUFFER_1_OVFL, CAN_RX_BUFFER_2_OVFL, CANmessage::data, CANmessage::identifier, CANmessage::length, CANmessage::RTR, and CANmessage::type.

void CAN_set_filter ( enum CAN_FILTER  filter_number,
unsigned long  val,
enum CAN_CONFIG_FLAGS  type 
)

This function sets filters used to filter the incoming messages.

Parameters
filter_numberselect the filter number [CAN_FILTER_B1_F1, CAN_FILTER_B1_F2,CAN_FILTER_B2_F1...CAN_FILTER_B2_F4]
valFilter value
typeFilter type, either Standard or Extended [CAN_CONFIG_STD_MSG, CAN_CONFIG_XTD_MSG]
Returns
void
Note
Refer to the MCU datasheet and CAN specifications for more details.

Definition at line 653 of file module_CAN.c.

References CAN_CONFIG_STD_MSG, CAN_CONFIG_XTD_MSG, CAN_FILTER_B1_F1, CAN_FILTER_B1_F2, CAN_FILTER_B2_F1, CAN_FILTER_B2_F2, CAN_FILTER_B2_F3, and CAN_FILTER_B2_F4.

void CAN_set_mask ( enum CAN_MASK  mask_number,
unsigned long  val,
enum CAN_CONFIG_FLAGS  type 
)

This function sets the MASK used to filter the incoming messages.

Parameters
mask_numberselect the mask number [CAN_MASK_B1, CAN_MASK_B2]
valMask value.
typeMask type, either Standard or Extended [CAN_CONFIG_STD_MSG, CAN_CONFIG_XTD_MSG]
Returns
void
Note
Refer to the MCU datasheet and CAN specifications for more details.

Definition at line 539 of file module_CAN.c.

References CAN_CONFIG_STD_MSG, CAN_CONFIG_XTD_MSG, CAN_MASK_B1, and CAN_MASK_B2.

void CAN_write_message ( unsigned long  identifier,
BYTE data,
BYTE  dataLength,
enum CAN_TX_MSG_FLAGS  flags 
)

This function writes a message within the TX buffer.

Parameters
identifierMessage Identifier.
dataData Byte poiter to an array of BYTE [max. 8 Bytes]
dataLengthNumber of bytes to be sent [1...8]
flagsMEssage configuration (Use the CAN_TX_MSG_FLAGS values)
Returns
void
Note
Refer to the MCU datasheet and CAN specifications for more details.

Definition at line 147 of file module_CAN.c.

References CAN_TX_FRAME_MASK.