include/AVR/can_drv.h
author Christian Taedcke
Thu, 09 Sep 2010 15:38:20 +0200
changeset 635 30a0e926bb2e
parent 375 03fb0bfccc1f
permissions -rw-r--r--
ADDED: - new callback post_SlaveStateChange so that a master can monitor the state of its slave nodes using a heartbeat.
* * *
CHANGED: - added missing export for _post_SlaveStateChange (for revision #679)
375
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     1
//******************************************************************************
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     2
//! @file $RCSfile$
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     3
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     4
//! Copyright (c) 2007 Atmel.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     5
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     6
//! Use of this program is subject to Atmel's End User License Agreement.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     7
//! Please read file license.txt for copyright notice.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     8
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
     9
//! @brief This file contains the prototypes and the macros of the
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    10
//!        low level functions (drivers) of:
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    11
//!             - CAN (Controller Array Network)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    12
//!             - for AT90CAN128/64/32.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    13
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    14
//! This file can be parsed by Doxygen for automatic documentation generation.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    15
//! This file has been validated with AVRStudio-413528/WinAVR-20070122.
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    16
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    17
//! @version $Revision$ $Name$
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    18
//!
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    19
//! @todo
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    20
//! @bug
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    21
//******************************************************************************
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    22
// Same stuff removed by Peter Christen
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    23
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    24
#ifndef _CAN_DRV_H_
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    25
#define _CAN_DRV_H_
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    26
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    27
typedef unsigned char       U8 ;
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    28
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    29
#define CAN_PORT_IN     PIND
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    30
#define CAN_PORT_DIR    DDRD
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    31
#define CAN_PORT_OUT    PORTD
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    32
#define CAN_INPUT_PIN   6
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    33
#define CAN_OUTPUT_PIN  5
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    34
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    35
#define ERR_GEN_MSK ((1<<SERG)|(1<<CERG)|(1<<FERG)|(1<<AERG))            //! MaSK for GENeral ERRors INTerrupts
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    36
#define INT_GEN_MSK ((1<<BOFFIT)|(1<<BXOK)|(ERR_GEN_MSK))                //! MaSK for GENeral INTerrupts
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    37
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    38
#define BRP_MSK     ((1<<BRP5)|(1<<BRP4)|(1<<BRP3)|(1<<BRP2)|(1<<BRP1)|(1<<BRP0))  //! Mask for BRP in CANBT1
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    39
#define SJW_MSK     ((1<<SJW1)|(1<<SJW0))                                //! MaSK for SJW  in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    40
#define PRS_MSK     ((1<<PRS2)|(1<<PRS1)|(1<<PRS0))                      //! MaSK for PRS  in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    41
#define PHS2_MSK    ((1<<PHS22)|(1<<PHS21)|(1<<PHS20))                   //! MaSK for PHS2 in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    42
#define PHS1_MSK    ((1<<PHS12)|(1<<PHS11)|(1<<PHS10))                   //! MaSK for PHS1 in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    43
#define BRP         (BRP0)                                               //! BRP  in CANBT1
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    44
#define SJW         (SJW0)                                               //! SJW  in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    45
#define PRS         (PRS0)                                               //! PRS  in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    46
#define PHS2        (PHS20)                                              //! PHS2 in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    47
#define PHS1        (PHS10)                                              //! PHS1 in CANBT2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    48
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    49
#define HPMOB_MSK   ((1<<HPMOB3)|(1<<HPMOB2)|(1<<HPMOB1)|(1<<HPMOB0))    //! MaSK for MOb in HPMOB
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    50
#define MOBNB_MSK   ((1<<MOBNB3)|(1<<MOBNB2)|(1<<MOBNB1)|(1<<MOBNB0))    //! MaSK for MOb in CANPAGE
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    51
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    52
#define ERR_MOB_MSK ((1<<BERR)|(1<<SERR)|(1<<CERR)|(1<<FERR)|(1<<AERR))  //! MaSK for MOb ERRors
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    53
#define INT_MOB_MSK ((1<<TXOK)|(1<<RXOK)|(1<<BERR)|(1<<SERR)|(1<<CERR)|(1<<FERR)|(1<<AERR)) //! MaSK for MOb INTerrupts
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    54
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    55
#define CONMOB_MSK  ((1<<CONMOB1)|(1<<CONMOB0))                          //! MaSK for CONfiguration MOb
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    56
#define DLC_MSK     ((1<<DLC3)|(1<<DLC2)|(1<<DLC1)|(1<<DLC0))            //! MaSK for Data Length Coding
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    57
#define CONMOB      (CONMOB0)                                            //! CONfiguration MOb
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    58
#define DLC         (DLC0)                                               //! Data Length Coding
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    59
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    60
#define BRP_MIN     1       //! Prescaler of FOSC (TQ generation)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    61
#define BRP_MAX     64
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    62
#define NTQ_MIN     8       //! Number of TQ in one CAN bit
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    63
#define NTQ_MAX     25
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    64
                            //! True segment values in TQ
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    65
#define PRS_MIN     1       //! Propagation segment
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    66
#define PRS_MAX     8
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    67
#define PHS1_MIN    2       //! Phase segment 1
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    68
#define PHS1_MAX    8
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    69
#define PHS2_MIN    2       //! Phase segment 2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    70
#define PHS2_MAX    8
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    71
#define SJW_MIN     1       //! Synchro jump width
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    72
#define SJW_MAX     4
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    73
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    74
#define NB_MOB       15
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    75
#define NB_DATA_MAX  8
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    76
#define LAST_MOB_NB  (NB_MOB-1)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    77
#define NO_MOB       0xFF
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    78
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    79
typedef enum {
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    80
        MOB_0,  MOB_1, MOB_2,  MOB_3,  MOB_4,  MOB_5,  MOB_6, MOB_7,
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    81
        MOB_8,  MOB_9, MOB_10, MOB_11, MOB_12, MOB_13, MOB_14        } can_mob_t;
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    82
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    83
#define STATUS_CLEARED            0x00
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    84
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    85
#define MOB_NOT_COMPLETED         0x00                                              // 0x00
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    86
#define MOB_TX_COMPLETED        (1<<TXOK)                                           // 0x40
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    87
#define MOB_RX_COMPLETED        (1<<RXOK)                                           // 0x20
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    88
#define MOB_RX_COMPLETED_DLCW  ((1<<RXOK)|(1<<DLCW))                                // 0xA0
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    89
#define MOB_ACK_ERROR           (1<<AERR)                                           // 0x01
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    90
#define MOB_FORM_ERROR          (1<<FERR)                                           // 0x02
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    91
#define MOB_CRC_ERROR           (1<<CERR)                                           // 0x04
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    92
#define MOB_STUFF_ERROR         (1<<SERR)                                           // 0x08
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    93
#define MOB_BIT_ERROR           (1<<BERR)                                           // 0x10
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    94
#define MOB_PENDING            ((1<<RXOK)|(1<<TXOK))                                // 0x60
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    95
#define MOB_NOT_REACHED        ((1<<AERR)|(1<<FERR)|(1<<CERR)|(1<<SERR)|(1<<BERR))  // 0x1F
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    96
#define MOB_DISABLE               0xFF                                              // 0xFF
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    97
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    98
#define MOB_Tx_ENA  1
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
    99
#define MOB_Rx_ENA  2
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   100
#define MOB_Rx_BENA 3
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   101
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   102
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   103
//_____ M A C R O S ____________________________________________________________
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   104
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   105
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   106
#define Can_reset()       ( CANGCON  =  (1<<SWRES) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   107
#define Can_enable()      ( CANGCON |=  (1<<ENASTB))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   108
#define Can_disable()     ( CANGCON &= ~(1<<ENASTB))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   109
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   110
#define Can_full_abort()  { CANGCON |=  (1<<ABRQ); CANGCON &= ~(1<<ABRQ); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   111
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   112
#define Can_conf_bt()     { CANBT1=CONF_CANBT1; CANBT2=CONF_CANBT2; CANBT3=CONF_CANBT3; }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   113
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   114
#define Can_set_mob(mob)       { CANPAGE = ((mob) << 4);}
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   115
#define Can_set_mask_mob()     {  CANIDM4=0xFF; CANIDM3=0xFF; CANIDM2=0xFF; CANIDM1=0xFF; }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   116
#define Can_clear_mask_mob()   {  CANIDM4=0x00; CANIDM3=0x00; CANIDM2=0x00; CANIDM1=0x00; }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   117
#define Can_clear_status_mob() { CANSTMOB=0x00; }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   118
#define Can_clear_mob()        { U8  volatile *__i_; for (__i_=&CANSTMOB; __i_<&CANSTML; __i_++) { *__i_=0x00 ;}}
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   119
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   120
#define Can_mob_abort()   ( DISABLE_MOB )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   121
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   122
#define Can_set_dlc(dlc)  ( CANCDMOB |= (dlc)        )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   123
#define Can_set_ide()     ( CANCDMOB |= (1<<IDE)     )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   124
#define Can_set_rtr()     ( CANIDT4  |= (1<<RTRTAG)  )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   125
#define Can_set_rplv()    ( CANCDMOB |= (1<<RPLV)    )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   126
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   127
#define Can_clear_dlc()   ( CANCDMOB &= ~DLC_MSK     )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   128
#define Can_clear_ide()   ( CANCDMOB &= ~(1<<IDE)    )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   129
#define Can_clear_rtr()   ( CANIDT4  &= ~(1<<RTRTAG) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   130
#define Can_clear_rplv()  ( CANCDMOB &= ~(1<<RPLV)   )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   131
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   132
#define DISABLE_MOB       ( CANCDMOB &= (~CONMOB_MSK) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   133
#define Can_config_tx()        { DISABLE_MOB; CANCDMOB |= (MOB_Tx_ENA  << CONMOB); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   134
#define Can_config_rx()        { DISABLE_MOB; CANCDMOB |= (MOB_Rx_ENA  << CONMOB); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   135
#define Can_config_rx_buffer() {              CANCDMOB |= (MOB_Rx_BENA << CONMOB); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   136
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   137
#define Can_get_dlc()      ((CANCDMOB &  DLC_MSK)     >> DLC   )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   138
#define Can_get_ide()      ((CANCDMOB &  (1<<IDE))    >> IDE   )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   139
#define Can_get_rtr()      ((CANIDT4  &  (1<<RTRTAG)) >> RTRTAG)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   140
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   141
#define Can_set_rtrmsk()   ( CANIDM4 |= (1<<RTRMSK) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   142
#define Can_set_idemsk()   ( CANIDM4 |= (1<<IDEMSK) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   143
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   144
#define Can_clear_rtrmsk() ( CANIDM4 &= ~(1<<RTRMSK) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   145
#define Can_clear_idemsk() ( CANIDM4 &= ~(1<<IDEMSK) )
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   146
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   147
                //!< STD ID TAG Reading
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   148
#define Can_get_std_id(identifier)  { *((U8 *)(&(identifier))+1) =  CANIDT1>>5              ; \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   149
                                      *((U8 *)(&(identifier))  ) = (CANIDT2>>5)+(CANIDT1<<3); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   150
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   151
                //!< EXT ID TAG Reading
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   152
#define Can_get_ext_id(identifier)  { *((U8 *)(&(identifier))+3) =  CANIDT1>>3              ; \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   153
                                      *((U8 *)(&(identifier))+2) = (CANIDT2>>3)+(CANIDT1<<5); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   154
                                      *((U8 *)(&(identifier))+1) = (CANIDT3>>3)+(CANIDT2<<5); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   155
                                      *((U8 *)(&(identifier))  ) = (CANIDT4>>3)+(CANIDT3<<5); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   156
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   157
                //!< STD ID Construction
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   158
#define CAN_SET_STD_ID_10_4(identifier)  (((*((U8 *)(&(identifier))+1))<<5)+((* (U8 *)(&(identifier)))>>3))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   159
#define CAN_SET_STD_ID_3_0( identifier)  (( * (U8 *)(&(identifier))   )<<5)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   160
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   161
                //!< STD ID TAG writing
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   162
#define Can_set_std_id(identifier)  { CANIDT1   = CAN_SET_STD_ID_10_4(identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   163
                                      CANIDT2   = CAN_SET_STD_ID_3_0( identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   164
                                      CANCDMOB &= (~(1<<IDE))                    ; }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   165
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   166
                //!< STD ID MASK writing
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   167
#define Can_set_std_msk(mask)       { CANIDM1   = CAN_SET_STD_ID_10_4(mask); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   168
                                      CANIDM2   = CAN_SET_STD_ID_3_0( mask); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   169
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   170
                //!< EXT ID Construction
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   171
#define CAN_SET_EXT_ID_28_21(identifier)  (((*((U8 *)(&(identifier))+3))<<3)+((*((U8 *)(&(identifier))+2))>>5))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   172
#define CAN_SET_EXT_ID_20_13(identifier)  (((*((U8 *)(&(identifier))+2))<<3)+((*((U8 *)(&(identifier))+1))>>5))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   173
#define CAN_SET_EXT_ID_12_5( identifier)  (((*((U8 *)(&(identifier))+1))<<3)+((* (U8 *)(&(identifier))   )>>5))
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   174
#define CAN_SET_EXT_ID_4_0(  identifier)   ((* (U8 *)(&(identifier))   )<<3)
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   175
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   176
                //!< EXT ID TAG writing
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   177
#define Can_set_ext_id(identifier)  { CANIDT1   = CAN_SET_EXT_ID_28_21(identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   178
                                      CANIDT2   = CAN_SET_EXT_ID_20_13(identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   179
                                      CANIDT3   = CAN_SET_EXT_ID_12_5( identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   180
                                      CANIDT4   = CAN_SET_EXT_ID_4_0(  identifier); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   181
                                      CANCDMOB |= (1<<IDE);                         }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   182
    // ----------
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   183
                //!< EXT ID MASK writing
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   184
#define Can_set_ext_msk(mask)       { CANIDM1   = CAN_SET_EXT_ID_28_21(mask); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   185
                                      CANIDM2   = CAN_SET_EXT_ID_20_13(mask); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   186
                                      CANIDM3   = CAN_SET_EXT_ID_12_5( mask); \
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   187
                                      CANIDM4   = CAN_SET_EXT_ID_4_0(  mask); }
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   188
#endif // _CAN_DRV_H_
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   189
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   190
03fb0bfccc1f AVR port, thanks to Peter Christen, Comat AG.
etisserant
parents:
diff changeset
   191