Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

can_lib.h File Reference

#include "can_drv.h"

Go to the source code of this file.

Data Structures

union  can_id_t
 This union defines a CAN identifier and allows to access it in mode standart, extended or throught a table. More...

struct  can_ctrl_t
 This structure defines some specific information as rtr bit and ide bit. More...

struct  st_cmd_t
 This structure allows to define a specific action on CAN network. handle: manage by the library. More...


Defines

#define CAN_CMD_REFUSED   0xFF
 This constant is used as return value for the function can_cmd.

#define CAN_CMD_ACCEPTED   0x00
 This constant is used as return value for the function can_cmd.

#define CAN_STATUS_COMPLETED   0x00
 This constant is used as return value for the function can_getstatus.

#define CAN_STATUS_NOT_COMPLETED   0x01
 This constant is used as return value for the function can_getstatus.

#define CAN_STATUS_DISABLED   0x02
 This constant is used as return value for the function can_getstatus.


Enumerations

enum  can_cmd_t { CMD_TX, CMD_TX_REMOTE, CMD_RX, CMD_ABORT }
 This enum is used to select an action for a specific message declare on structure st_cmd_t. More...


Functions

void can_init (void)
 This function configures the bit timing of the CAN controller following the constant definition of CAN_BAUDRATE; clears the Mailbox content and enables the CAN controller.

Uchar can_cmd (st_cmd_t *)
 This function allows to select an action on the CAN bus and to define the CAN message to send or to receive. This function returns a status if the action is accepted or refused. in this case the must be retry by the application.

Uchar can_getstatus (st_cmd_t *)
 This function allows to return if the command is performed or not. In an reception case, all the CAN message is stored in the structure.


Define Documentation

#define CAN_CMD_ACCEPTED   0x00
 

This constant is used as return value for the function can_cmd.

Definition at line 35 of file can_lib.h.

Referenced by can_cmd().

#define CAN_CMD_REFUSED   0xFF
 

This constant is used as return value for the function can_cmd.

Definition at line 30 of file can_lib.h.

Referenced by can_cmd().

#define CAN_STATUS_COMPLETED   0x00
 

This constant is used as return value for the function can_getstatus.

Definition at line 41 of file can_lib.h.

Referenced by can_getstatus().

#define CAN_STATUS_DISABLED   0x02
 

This constant is used as return value for the function can_getstatus.

Definition at line 51 of file can_lib.h.

Referenced by can_getstatus().

#define CAN_STATUS_NOT_COMPLETED   0x01
 

This constant is used as return value for the function can_getstatus.

Definition at line 46 of file can_lib.h.


Enumeration Type Documentation

enum can_cmd_t
 

This enum is used to select an action for a specific message declare on structure st_cmd_t.

Enumeration values:
CMD_TX 
CMD_TX_REMOTE 
CMD_RX 
CMD_ABORT 

Definition at line 60 of file can_lib.h.


Function Documentation

Uchar can_cmd st_cmd_t  ) 
 

This function allows to select an action on the CAN bus and to define the CAN message to send or to receive. This function returns a status if the action is accepted or refused. in this case the must be retry by the application.

Parameters:
*cmd pointer on can_cmd_t structure to select the action to do.
Returns:
command is accepted (CAN_CMD_ACCEPTED) or refused (CAN_CMD_REFUSED).
Precondition:
A variable must be define on the stucture type can_cmd_t, and some field must be entered as: filed cmd and pt_data.
Example
To send : Id 103h with 5 data (01h, 02h, 03h, 04h, 05h)
  • Declare the structure can_cm_t msg1; Uchar tab[5]={0x01, 0x02, 0x03, 0x04, 0x05};
  • Initialize the structure msg1.id.std = 0x103; msg1.cmd = CMD_TX; msg1.dlc = 5; msg1.pt_data= &tab[0];
  • Call the can_cmd function while(can_cmd(&msg1)!=CAN_CMD_ACCEPTED);

Definition at line 40 of file can_lib.c.

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, st_cmd_t::cmd, CMD_ABORT, CMD_RX, CMD_TX, CMD_TX_REMOTE, st_cmd_t::ctrl, st_cmd_t::dlc, can_id_t::ext, st_cmd_t::handle, st_cmd_t::id, can_ctrl_t::ide, st_cmd_t::pt_data, st_cmd_t::status, STATUS_MOB_AVAILABLE, STATUS_MOB_USED, and can_id_t::std.

Uchar can_getstatus st_cmd_t  ) 
 

This function allows to return if the command is performed or not. In an reception case, all the CAN message is stored in the structure.

Parameters:
*cmd pointer on msg structure.
Returns:
command is completed (CMD_COMPLETED) or not completed (CMD_NOTCOMPLETED).

Definition at line 94 of file can_lib.c.

References CAN_STATUS_COMPLETED, CAN_STATUS_DISABLED, st_cmd_t::ctrl, st_cmd_t::dlc, can_id_t::ext, st_cmd_t::handle, st_cmd_t::id, can_ctrl_t::ide, st_cmd_t::pt_data, can_ctrl_t::rtr, st_cmd_t::status, STATUS_MOB_AVAILABLE, and can_id_t::std.

void can_init void   ) 
 

This function configures the bit timing of the CAN controller following the constant definition of CAN_BAUDRATE; clears the Mailbox content and enables the CAN controller.

Precondition:
before calling this function some declaration must be define in config.h:
  • FOSC Frequency of crystal in kHz (mandatory)Standard crystals available:
    • 8000 -> Fosc = 8000.000 kHz
  • CAN_BAUDRATE Baudrate in bit per second used for CAN configuration (mandatory)
    Standard baudrates available:
    • CANAUTOBAUD or 0 for Automatic baudrate Détection and configuration (need external module autobaud).
    • 100 -> 100 Kbps Serial Speed.

Definition at line 31 of file can_lib.c.


Generated on Thu Apr 1 15:49:28 2004 for Library CAN by doxygen 1.3.6