can.h File Reference


Detailed Description

CAN Service for AVR32 UC3.

This file contains basic functions for the AVR32 CAN, with support for all modes, settings and clock speeds.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file can.h.

#include "conf_can.h"
#include "canif.h"
#include "compiler.h"
#include "preprocessor.h"

Go to the source code of this file.

Data Structures

struct  can_mob_t

Defines

#define CAN_CMD_ACCEPTED   0x00
 This constant is used as return value for "can_cmd" function.
#define CAN_CMD_REFUSED   0xFF
 This constant is used as return value for "can_cmd" function.
#define CAN_DATA_FRAME   0
 This constant is used for MOB Initialization request.
#define CAN_MOB_NOT_ALLOCATED   0xFF
 This constant is used for MOB Allocation status.
#define CAN_REMOTE_FRAME   1
 This constant is used for MOB Initialization request.
#define CAN_STATUS_BUSOFF   0x04
 This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_COMPLETED   0x00
 This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_ERROR   0x02
 This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_NOT_COMPLETED   0x01
 This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_WAKEUP   0x03
 This constant is used as return value for "can_get_status" function.

Functions

Union64 can_get_mob_data (U8 ch, U8 handle)
 Get Mob data from a selected MOB.
U8 can_get_mob_dlc (U8 ch, U8 handle)
 Get Mob dlc from a selected MOB.
U32 can_get_mob_id (U8 ch, U8 handle)
 Get Mob ID from a selected MOB.
U8 can_init (U8 ch, U32 can_msg_ram_add, U8 operating_mode, void(*can_msg_callback)(U8, U8))
 Initialize CAN channel.
U8 can_mob_alloc (U8 ch)
 Allocate one MOB in a specific CAN Channel.
U8 can_mob_free (U8 ch, U8 handle)
 Free one specific MOB in a specific CAN Channel.
U8 can_mob_get_status (U8 ch, U8 handle)
 Get Mob status from a selected MOB.
U8 can_rx (U8 ch, U8 handle, U8 req_type, const can_msg_t *can_msg)
 Start Reception.
U8 can_tx (U8 ch, U8 handle, U8 dlc, U8 req_type, const can_msg_t *can_msg)
 Start Transmission.


Define Documentation

#define CAN_CMD_ACCEPTED   0x00

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

Definition at line 63 of file can.h.

Referenced by can_enable_interrupt(), can_init(), can_mob_free(), can_rx(), and can_tx().

#define CAN_CMD_REFUSED   0xFF

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

Definition at line 60 of file can.h.

Referenced by can_enable_interrupt(), can_init(), can_mob_alloc(), can_mob_free(), can_mob_get_status(), can_rx(), and can_tx().

#define CAN_DATA_FRAME   0

This constant is used for MOB Initialization request.

Definition at line 84 of file can.h.

#define CAN_MOB_NOT_ALLOCATED   0xFF

This constant is used for MOB Allocation status.

Definition at line 81 of file can.h.

#define CAN_REMOTE_FRAME   1

This constant is used for MOB Initialization request.

Definition at line 86 of file can.h.

Referenced by can_rx(), and can_tx().

#define CAN_STATUS_BUSOFF   0x04

This constant is used as return value for "can_get_status" function.

Definition at line 78 of file can.h.

Referenced by can0_int_busoff_handler(), and can1_int_busoff_handler().

#define CAN_STATUS_COMPLETED   0x00

This constant is used as return value for "can_get_status" function.

Definition at line 66 of file can.h.

Referenced by can0_int_rx_handler(), can0_int_tx_handler(), can1_int_rx_handler(), can1_int_tx_handler(), and can_mob_get_status().

#define CAN_STATUS_ERROR   0x02

This constant is used as return value for "can_get_status" function.

Definition at line 72 of file can.h.

Referenced by can0_int_cerr_handler(), can1_int_cerr_handler(), and can_mob_get_status().

#define CAN_STATUS_NOT_COMPLETED   0x01

This constant is used as return value for "can_get_status" function.

Definition at line 69 of file can.h.

Referenced by can_mob_get_status().

#define CAN_STATUS_WAKEUP   0x03

This constant is used as return value for "can_get_status" function.

Definition at line 75 of file can.h.

Referenced by can0_int_wakeup_handler(), and can1_int_wakeup_handler().


Function Documentation

Union64 can_get_mob_data ( U8  ch,
U8  handle 
)

Get Mob data from a selected MOB.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
Returns:
Union64 See compiler.h file for type return definition

Definition at line 420 of file can.c.

References CANIF_mob_get_ptr_data.

Referenced by can_out_callback_channel0().

00422 {
00423     return ((CANIF_mob_get_ptr_data(ch,handle)->data));
00424 }           

U8 can_get_mob_dlc ( U8  ch,
U8  handle 
)

Get Mob dlc from a selected MOB.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
Returns:
U8 Return the DLC

Definition at line 426 of file can.c.

References CANIF_mob_get_dlc.

Referenced by can_out_callback_channel0().

00428 {
00429     return (CANIF_mob_get_dlc(ch,handle));  
00430 }

U32 can_get_mob_id ( U8  ch,
U8  handle 
)

Get Mob ID from a selected MOB.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
Returns:
U32 Return the ID

Definition at line 432 of file can.c.

References CANIF_get_ext_id.

Referenced by can_out_callback_channel0().

00434 {
00435     return (CANIF_get_ext_id(ch,handle));  
00436 }

U8 can_init ( U8  ch,
U32  can_msg_ram_add,
U8  operating_mode,
void(*)(U8, U8)  can_msg_callback 
)

Initialize CAN channel.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
can_msg_ram_add Adress of the location of MOB Ram Buffer
operating_mode Selection between CAN_CHANNEL_MODE_NORMAL or CAN_CHANNEL_MODE_LISTENING or CAN_CHANNEL_MODE_LOOPBACK
can_msg_callback Callback for hardware interrupt
Returns:
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

U8 can_mob_alloc ( U8  ch  ) 

Allocate one MOB in a specific CAN Channel.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
Returns:
U8 CAN_CMD_REFUSED or the number of the MOB selected

Definition at line 288 of file can.c.

References CAN_CMD_REFUSED, can_mob_alloc_vector0, can_mob_alloc_vector1, CANIF_clr_mob, and NB_MOB_CHANNEL.

Referenced by main().

00289 {
00290   if ((ch > 1))
00291         return  CAN_CMD_REFUSED;  
00292   
00293     if(ch==0)
00294     {
00295           int i;
00296           for (i=0;i<NB_MOB_CHANNEL;i++)
00297           {
00298             if (!((can_mob_alloc_vector0>>i)&0x01))
00299             {
00300               can_mob_alloc_vector0|=(1<<i);
00301               CANIF_clr_mob(0,i);  
00302               return i;
00303             }
00304           }
00305           return CAN_CMD_REFUSED;
00306     }
00307     else{
00308           int i;
00309           for (i=0;i<NB_MOB_CHANNEL;i++)
00310           {
00311             if (!((can_mob_alloc_vector1>>i)&0x01))
00312             {
00313               can_mob_alloc_vector1|=(1<<i);
00314               CANIF_clr_mob(1,i);  
00315               return i;
00316             }
00317           }
00318           return CAN_CMD_REFUSED;      
00319     }
00320 }

U8 can_mob_free ( U8  ch,
U8  handle 
)

Free one specific MOB in a specific CAN Channel.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
Returns:
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

Definition at line 322 of file can.c.

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, can_mob_alloc_vector0, can_mob_alloc_vector1, and NB_MOB_CHANNEL.

Referenced by can_out_callback_channel0().

00323 {
00324   if ((ch > 1)||
00325       (handle > (NB_MOB_CHANNEL-1)))
00326         return  CAN_CMD_REFUSED;  
00327   switch(ch)
00328   {
00329     case 0: 
00330       can_mob_alloc_vector0 &=  (~(1<<handle));
00331       break;
00332     case 1: 
00333       can_mob_alloc_vector1 &=  (~(1<<handle));
00334       break;
00335   }
00336   return CAN_CMD_ACCEPTED;
00337 }

U8 can_mob_get_status ( U8  ch,
U8  handle 
)

Get Mob status from a selected MOB.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
Returns:
U8 CAN_CMD_REFUSED or CAN_STATUS_ERROR or CAN_STATUS_COMPLETED or CAN_STATUS_NOT_COMPLETED

Definition at line 438 of file can.c.

References CAN_CMD_REFUSED, CAN_STATUS_COMPLETED, CAN_STATUS_ERROR, CAN_STATUS_NOT_COMPLETED, CANIF_get_interrupt_error_status, CANIF_mob_get_status, MOB_RX_COMPLETED, MOB_RX_COMPLETED_DLCW, MOB_TX_COMPLETED, and NB_MOB_CHANNEL.

00440 {
00441     U8 status;
00442     if ((ch > 1)||
00443         (handle > (NB_MOB_CHANNEL-1)) )
00444         return  CAN_CMD_REFUSED;
00445 
00446     status = CANIF_get_interrupt_error_status(ch);
00447     if (status!=0)
00448       return CAN_STATUS_ERROR;
00449 
00450     status = CANIF_mob_get_status(ch,handle);
00451     if ( (status & MOB_RX_COMPLETED) ||
00452          (status & MOB_TX_COMPLETED) ||
00453          (status & MOB_RX_COMPLETED_DLCW) )  
00454          return CAN_STATUS_COMPLETED;   
00455     
00456     return CAN_STATUS_NOT_COMPLETED;
00457 }                                                                              

U8 can_rx ( U8  ch,
U8  handle,
U8  req_type,
const can_msg_t can_msg 
)

Start Reception.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
req_type CAN_DATA_FRAME or CAN_REMOTE_FRAME
can_msg CAN Message
Returns:
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

Definition at line 382 of file can.c.

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, CAN_REMOTE_FRAME, CANIF_config_rx, CANIF_mob_enable, CANIF_mob_enable_interrupt, CANIF_mob_set_automode, CANIF_set_data, CANIF_set_ext_id, CANIF_set_ext_idmask, CANIF_set_rtr, CANIF_set_rtrmask, CANIF_set_std_id, CANIF_set_std_idmask, can_msg_t::id, can_msg_t::id_mask, can_msg_t::ide_bit, and NB_MOB_CHANNEL.

Referenced by main().

00386 {
00387     if ((ch > 1) ||
00388         (handle > (NB_MOB_CHANNEL-1)))
00389         return  CAN_CMD_REFUSED;
00390     if (can_msg->ide_bit){
00391         CANIF_set_ext_id(ch,
00392                       handle,
00393                       can_msg->id);
00394         CANIF_set_ext_idmask(ch,
00395                           handle,
00396                           can_msg->id_mask);        
00397     }
00398     else { 
00399         CANIF_set_std_id(ch,
00400                       handle,
00401                       can_msg->id);
00402         CANIF_set_std_idmask(ch,
00403                           handle,
00404                           can_msg->id_mask);        
00405     }
00406     if (req_type == CAN_REMOTE_FRAME){
00407             CANIF_set_rtr(ch,handle);  
00408             CANIF_set_rtrmask(ch,handle);            
00409             CANIF_mob_set_automode(ch,handle);
00410             CANIF_set_data(ch,handle,((can_msg_t *)can_msg)->data.u64);
00411     }    
00412     CANIF_config_rx(ch,handle);
00413     CANIF_mob_enable(ch,handle);
00414 #ifdef CAN_LIB_UNDER_INTERRUPT          
00415     CANIF_mob_enable_interrupt(ch,handle);
00416 #endif 
00417     return CAN_CMD_ACCEPTED;    
00418 }   

U8 can_tx ( U8  ch,
U8  handle,
U8  dlc,
U8  req_type,
const can_msg_t can_msg 
)

Start Transmission.

Parameters:
ch CAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handle CAN MOB number
dlc Datalength
req_type CAN_DATA_FRAME or CAN_REMOTE_FRAME
can_msg CAN Message
Returns:
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

Definition at line 339 of file can.c.

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, CAN_REMOTE_FRAME, CANIF_config_tx, CANIF_mob_enable, CANIF_mob_enable_interrupt, CANIF_mob_set_automode, CANIF_mob_set_dlc, CANIF_set_data, CANIF_set_ext_id, CANIF_set_ext_idmask, CANIF_set_rtr, CANIF_set_rtrmask, CANIF_set_std_id, CANIF_set_std_idmask, can_msg_t::id, can_msg_t::id_mask, can_msg_t::ide_bit, and NB_MOB_CHANNEL.

00344 {
00345     if ((ch > 1) ||
00346         (handle > (NB_MOB_CHANNEL-1)) ||
00347         (dlc > 8))
00348         return  CAN_CMD_REFUSED;
00349     
00350     if (can_msg->ide_bit){        
00351              CANIF_set_ext_id(ch,
00352                             handle,
00353                             can_msg->id);
00354              
00355              CANIF_set_ext_idmask(ch,
00356                                 handle,
00357                                 can_msg->id_mask);
00358     }
00359     else { 
00360              CANIF_set_std_id(ch,
00361                             handle,
00362                             can_msg->id);
00363              CANIF_set_std_idmask(ch,
00364                                 handle,
00365                                 can_msg->id_mask);
00366     }
00367     CANIF_mob_set_dlc(ch,handle,dlc);
00368     if (req_type == CAN_REMOTE_FRAME){
00369             CANIF_set_rtr(ch,handle);  
00370             CANIF_set_rtrmask(ch,handle);            
00371             CANIF_mob_set_automode(ch,handle);
00372     }
00373     CANIF_set_data(ch,handle,((can_msg_t *)can_msg)->data.u64);
00374     CANIF_config_tx(ch,handle);
00375     CANIF_mob_enable(ch,handle);
00376 #ifdef CAN_LIB_UNDER_INTERRUPT          
00377     CANIF_mob_enable_interrupt(ch,handle);
00378 #endif 
00379     return CAN_CMD_ACCEPTED;                   
00380 }           


Generated on Fri Feb 19 02:24:17 2010 for AVR32 - CANIF Driver by  doxygen 1.5.5