sja1000.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 by Ole Reinhardt <ole.reinhardt@kernelconcepts.de>,
00003  *                       Kernelconcepts http://www.kernelconcepts.de
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the copyright holders nor the names of
00015  *    contributors may be used to endorse or promote products derived
00016  *    from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00019  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00022  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00025  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00026  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00028  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  * For additional information see http://www.ethernut.de/
00032  *
00033  */
00034 
00050 
00051 #ifndef _SJA1000_H_
00052 #define _SJA1000_H_
00053 
00054 //Register and bit definitions for the SJA1000
00055 
00056 // address and bit definitions for the Mode & Control Register
00057 #define SJA1000_MODECTRL (*(volatile u_char*) (sja_base+0))
00058 #define RM_RR_Bit   0x01        // reset mode (request) bit
00059 
00060 #define LOM_Bit     0x02        // listen only mode bit
00061 #define STM_Bit     0x04        // self test mode bit
00062 #define AFM_Bit     0x08        // acceptance filter mode bit
00063 #define SM_Bit      0x10        // enter sleep mode bit
00064 
00065 // address and bit definitions for the Interrupt Enable & Control Register
00066 #define SJA1000_IEN (*(volatile u_char*) (sja_base+4))      // PeliCAN mode
00067 #define RIE_Bit     0x01        // receive interrupt enable bit
00068 #define TIE_Bit     0x02        // transmit interrupt enable bit
00069 #define EIE_Bit     0x04        // error warning interrupt enable bit
00070 #define DOIE_Bit    0x08        // data overrun interrupt enable bit
00071 #define WUIE_Bit    0x10        // wake-up interrupt enable bit
00072 #define EPIE_Bit    0x20        // error passive interrupt enable bit
00073 #define ALIE_Bit    0x40        // arbitration lost interr. enable bit
00074 #define BEIE_Bit    0x80        // bus error interrupt enable bit
00075 
00076 // address and bit definitions for the Command Register
00077 #define SJA1000_CMD (*(volatile u_char*) (sja_base+1))
00078 #define TR_Bit      0x01        // transmission request bit
00079 #define AT_Bit      0x02        // abort transmission bit
00080 #define RRB_Bit     0x04        // release receive buffer bit
00081 #define CDO_Bit     0x08        // clear data overrun bit
00082 #define SRR_Bit     0x10        // self reception request bit
00083 
00084 // address and bit definitions for the Status Register
00085 #define SJA1000_STATUS (*(volatile u_char*) (sja_base+2))
00086 #define RBS_Bit     0x01        // receive buffer status bit
00087 #define DOS_Bit     0x02        // data overrun status bit
00088 #define TBS_Bit     0x04        // transmit buffer status bit
00089 #define TCS_Bit     0x08        // transmission complete status bit
00090 #define RS_Bit      0x10        // receive status bit
00091 #define TS_Bit      0x20        // transmit status bit
00092 #define ES_Bit      0x40        // error status bit
00093 #define BS_Bit      0x80        // bus status bit
00094 
00095 // address and bit definitions for the Interrupt Register
00096 #define SJA1000_INT (*(volatile u_char*) (sja_base+3))
00097 #define RI_Bit      0x01        // receive interrupt bit
00098 #define TI_Bit      0x02        // transmit interrupt bit
00099 #define EI_Bit      0x04        // error warning interrupt bit
00100 #define DOI_Bit     0x08        // data overrun interrupt bit
00101 #define WUI_Bit     0x10        // wake-up interrupt bit
00102 
00103 #define EPI_Bit     0x20        // error passive interrupt bit
00104 #define ALI_Bit     0x40        // arbitration lost interrupt bit
00105 #define BEI_Bit     0x80        // bus error interrupt bit
00106 
00107 // address and bit definitions for the Bus Timing Registers
00108 #define SJA1000_BT0 (*(volatile u_char*) (sja_base+6))
00109 #define SJA1000_BT1 (*(volatile u_char*) (sja_base+7))
00110 #define SAM_Bit     0x80        // sample mode bit
00111                                 //   1 == the bus is sampled 3 times
00112                                 //   0 == the bus is sampled once */
00113 
00114 // address and bit definitions for the Output Control Register
00115 #define SJA1000_OUTCTRL (*(volatile u_char*) (sja_base+8))
00116 // OCMODE1, OCMODE0
00117 #define BiPhaseMode 0x00        // bi-phase output mode
00118 #define NormalMode  0x02        // normal output mode
00119 #define ClkOutMode  0x03        // clock output mode
00120 // output pin configuration for TX1
00121 #define OCPOL1_Bit  0x20        // output polarity control bit
00122 #define Tx1Float    0x00        // configured as float
00123 #define Tx1PullDn   0x40        // configured as pull-down
00124 #define Tx1PullUp   0x80        // configured as pull-up
00125 #define Tx1PshPull  0xC0        // configured as push/pull
00126 // output configuration for TX0
00127 #define OCPOLO_Bit  0x04        // output polarity control bit
00128 #define Tx0Float    0x00        // configured as float
00129 #define Tx0PullDn   0x08        // configured as pull-down
00130 #define Tx0PullUp   0x10        // configured as pull-up
00131 #define Tx0PshPull  0x18        // configured as push/pull
00132 
00133 // address definitions of Acceptance Code & Mask Registers
00134 #define SJA1000_AC0 (*(volatile u_char*) (sja_base+16))
00135 #define SJA1000_AC1 (*(volatile u_char*) (sja_base+17))
00136 #define SJA1000_AC2 (*(volatile u_char*) (sja_base+18))
00137 #define SJA1000_AC3 (*(volatile u_char*) (sja_base+19))
00138 #define SJA1000_AM0 (*(volatile u_char*) (sja_base+20))
00139 #define SJA1000_AM1 (*(volatile u_char*) (sja_base+21))
00140 #define SJA1000_AM2 (*(volatile u_char*) (sja_base+22))
00141 #define SJA1000_AM3 (*(volatile u_char*) (sja_base+23))
00142 
00143 // address definitions of the Rx-Buffer
00144 #define SJA1000_RxFrameInfo (*(volatile u_char*) (sja_base+16))
00145 #define SJA1000_Rx1   (*(volatile u_char*) (sja_base+17))
00146 #define SJA1000_Rx2   (*(volatile u_char*) (sja_base+18))
00147 #define SJA1000_Rx3   (*(volatile u_char*) (sja_base+19))
00148 #define SJA1000_Rx4   (*(volatile u_char*) (sja_base+20))
00149 #define SJA1000_Rx5   (*(volatile u_char*) (sja_base+21))
00150 #define SJA1000_Rx6   (*(volatile u_char*) (sja_base+22))
00151 #define SJA1000_Rx7   (*(volatile u_char*) (sja_base+23))
00152 #define SJA1000_Rx8   (*(volatile u_char*) (sja_base+24))
00153 #define SJA1000_Rx9   (*(volatile u_char*) (sja_base+25))
00154 #define SJA1000_Rx10  (*(volatile u_char*) (sja_base+26))
00155 #define SJA1000_Rx11  (*(volatile u_char*) (sja_base+27))
00156 #define SJA1000_Rx12  (*(volatile u_char*) (sja_base+28))
00157 
00158 // address definitions of the Tx-Buffer
00159 /* write only addresses */
00160 #define TestReg (*(volatile u_char*) (sja_base+9))
00161 
00162 #define SJA1000_TxFrameInfo (*(volatile u_char*) (sja_base+16))
00163 #define SJA1000_Tx1   (*(volatile u_char*) (sja_base+17))
00164 #define SJA1000_Tx2   (*(volatile u_char*) (sja_base+18))
00165 #define SJA1000_Tx3   (*(volatile u_char*) (sja_base+19))
00166 #define SJA1000_Tx4   (*(volatile u_char*) (sja_base+20))
00167 #define SJA1000_Tx5   (*(volatile u_char*) (sja_base+21))
00168 #define SJA1000_Tx6   (*(volatile u_char*) (sja_base+22))
00169 #define SJA1000_Tx7   (*(volatile u_char*) (sja_base+23))
00170 #define SJA1000_Tx8   (*(volatile u_char*) (sja_base+24))
00171 #define SJA1000_Tx9   (*(volatile u_char*) (sja_base+25))
00172 #define SJA1000_Tx10  (*(volatile u_char*) (sja_base+26))
00173 #define SJA1000_Tx11  (*(volatile u_char*) (sja_base+27))
00174 #define SJA1000_Tx12  (*(volatile u_char*) (sja_base+28))
00175 
00176 /* read only addresses */
00177 #define SJA1000_TxFrameInfoRd (*(volatile u_char*) (sja_base+96))
00178 #define SJA1000_TxRd1  (*(volatile u_char*) (sja_base+97))
00179 #define SJA1000_TxRd2  (*(volatile u_char*) (sja_base+98))
00180 #define SJA1000_TxRd3  (*(volatile u_char*) (sja_base+99))
00181 #define SJA1000_TxRd4  (*(volatile u_char*) (sja_base+100))
00182 #define SJA1000_TxRd5  (*(volatile u_char*) (sja_base+101))
00183 #define SJA1000_TxRd6  (*(volatile u_char*) (sja_base+102))
00184 #define SJA1000_TxRd7  (*(volatile u_char*) (sja_base+103))
00185 #define SJA1000_TxRd8  (*(volatile u_char*) (sja_base+104))
00186 #define SJA1000_TxRd9  (*(volatile u_char*) (sja_base+105))
00187 #define SJA1000_TxRd10 (*(volatile u_char*) (sja_base+106))
00188 #define SJA1000_TxRd11 (*(volatile u_char*) (sja_base+107))
00189 #define SJA1000_TxRd12 (*(volatile u_char*) (sja_base+108))
00190 
00191 // address definitions of Other Registers
00192 #define SJA1000_ArbLostCap    (*(volatile u_char*) (sja_base+11))
00193 #define SJA1000_ErrCodeCap    (*(volatile u_char*) (sja_base+12))
00194 #define SJA1000_ErrWarnLimit  (*(volatile u_char*) (sja_base+13))
00195 #define SJA1000_RxErrCount    (*(volatile u_char*) (sja_base+14))
00196 #define SJA1000_TxErrCount    (*(volatile u_char*) (sja_base+15))
00197 #define SJA1000_RxMsgCount    (*(volatile u_char*) (sja_base+29))
00198 #define SJA1000_RxBufStartAdr (*(volatile u_char*) (sja_base+30))
00199 
00200 // address and bit definitions for the Clock Divider Register
00201 #define SJA1000_CLK_DIV (*(volatile u_char*) (sja_base+31))
00202 #define DivBy1       0x07       // CLKOUT = oscillator frequency
00203 #define DivBy2       0x00       // CLKOUT = 1/2 oscillator frequency
00204 #define ClkOff_Bit   0x08       // clock off bit, control of the CLK OUT pin
00205 #define RXINTEN_Bit  0x20       // pin TX1 used for receive interrupt
00206 #define CBP_Bit      0x40       // CAN comparator bypass control bit
00207 #define CANMode_Bit  0x80       // CAN mode definition bit
00208 #define ClkOutMode   0x03       // clock output mode
00209 
00210 // output pin configuration for TX1
00211 #define OCPOL1_Bit   0x20       // output polarity control bit
00212 #define Tx1Float     0x00       // configured as float
00213 #define Tx1PullDn    0x40       // configured as pull-down
00214 #define Tx1PullUp    0x80       // configured as pull-up
00215 #define Tx1PshPull   0xC0       // configured as push/pull
00216 
00217 // output pin configuration for TX0
00218 #define OCPOL0_Bit   0x04       // output polarity control bit
00219 #define Tx0Float     0x00       // configured as float
00220 #define Tx0PullDn    0x08       // configured as pull-down
00221 
00222 // Some sample konstants
00223 
00224 /* bus timing values for
00225      - bit-rate : 1 MBit/s
00226      - oscillator frequency : 16 MHz, 0,1%
00227      - maximum tolerated propagation delay : 623 ns
00228      - minimum requested propagation delay : 23 ns
00229 */
00230 
00231 #define Presc_MB_16  0x00       // baud rate prescaler : 1
00232 #define SJW_MB_16    0x00       // SJW : 1
00233 #define TSEG1_MB_16  0x04       // TSEG1 : 5
00234 #define TSEG2_MB_16  0x10       // TSEG2 : 2
00235 
00236 
00237 // Error codes
00238 
00239 #define errCAN_INVALID_BAUD   7
00240 #define CAN_OK                0
00241 #define CAN_ERR               1
00242 #define CAN_INIT_SPEED_ERR    1
00243 #define CAN_NOT_INITIATED     1
00244 #define CAN_NOT_STARTED       1
00245 #define CAN_TXBUF_FULL        2
00246 #define CAN_RXBUF_EMPTY       2
00247 
00248 //  Flag bits
00249 
00250 #define CAN_LOST_FRAME        0x01
00251 #define CAN_BUS_OFF           0x02
00252 
00253 //  Frame Flag bits
00254 
00255 #define CAN_29                0x80
00256 #define CAN_RTR               0x40
00257 
00258 #define ClrIntEnSJA           0x00
00259 
00260 extern NUTDEVICE devSJA1000;
00261 
00262 #endif
00263 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/