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

can_lib.c File Reference

#include "config.h"
#include "lib_mcu/can/can_lib.h"

Go to the source code of this file.

Defines

#define STATUS_MOB_USED   0x01
#define STATUS_MOB_AVAILABLE   0x00

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 *cmd)
 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 *cmd)
 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 STATUS_MOB_AVAILABLE   0x00
 

Definition at line 21 of file can_lib.c.

Referenced by can_cmd(), and can_getstatus().

#define STATUS_MOB_USED   0x01
 

Definition at line 20 of file can_lib.c.

Referenced by can_cmd().


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