[e16e0ca] | 1 | /* |
---|
| 2 | * Macros used for grcan controller |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 2007. |
---|
| 5 | * Gaisler Research |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.rtems.com/license/LICENSE. |
---|
| 10 | * |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef __GRCAN_H__ |
---|
| 14 | #define __GRCAN_H__ |
---|
| 15 | |
---|
| 16 | #include <ambapp.h> |
---|
| 17 | |
---|
| 18 | #ifdef __cplusplus |
---|
| 19 | extern "C" { |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | struct grcan_regs { |
---|
| 23 | volatile unsigned int conf; /* 0x00 */ |
---|
| 24 | volatile unsigned int stat; /* 0x04 */ |
---|
| 25 | volatile unsigned int ctrl; /* 0x08 */ |
---|
| 26 | volatile unsigned int dummy0[3]; /* 0x0C-0x014 */ |
---|
| 27 | volatile unsigned int smask; /* 0x18 */ |
---|
| 28 | volatile unsigned int scode; /* 0x1C */ |
---|
| 29 | |
---|
| 30 | volatile unsigned int dummy1[56]; /* 0x20-0xFC */ |
---|
| 31 | |
---|
| 32 | volatile unsigned int pimsr; /* 0x100 */ |
---|
| 33 | volatile unsigned int pimr; /* 0x104 */ |
---|
| 34 | volatile unsigned int pisr; /* 0x108 */ |
---|
| 35 | volatile unsigned int pir; /* 0x10C */ |
---|
| 36 | volatile unsigned int imr; /* 0x110 */ |
---|
| 37 | volatile unsigned int picr; /* 0x114 */ |
---|
| 38 | |
---|
| 39 | volatile unsigned int dummy2[58]; /* 0x118-0x1FC */ |
---|
| 40 | |
---|
| 41 | volatile unsigned int tx0ctrl; /* 0x200 */ |
---|
| 42 | volatile unsigned int tx0addr; /* 0x204 */ |
---|
| 43 | volatile unsigned int tx0size; /* 0x208 */ |
---|
| 44 | volatile unsigned int tx0wr; /* 0x20C */ |
---|
| 45 | volatile unsigned int tx0rd; /* 0x210 */ |
---|
| 46 | volatile unsigned int tx0irq; /* 0x214 */ |
---|
| 47 | |
---|
| 48 | volatile unsigned int dummy3[58]; /* 0x218-0x2FC */ |
---|
| 49 | |
---|
| 50 | volatile unsigned int rx0ctrl; /* 0x300 */ |
---|
| 51 | volatile unsigned int rx0addr; /* 0x304 */ |
---|
| 52 | volatile unsigned int rx0size; /* 0x308 */ |
---|
| 53 | volatile unsigned int rx0wr; /* 0x30C */ |
---|
| 54 | volatile unsigned int rx0rd; /* 0x310 */ |
---|
| 55 | volatile unsigned int rx0irq; /* 0x314 */ |
---|
| 56 | volatile unsigned int rx0mask; /* 0x318 */ |
---|
| 57 | volatile unsigned int rx0code; /* 0x31C */ |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | struct grcan_stats { |
---|
| 61 | unsigned int passive_cnt; |
---|
| 62 | unsigned int overrun_cnt; |
---|
| 63 | unsigned int rxsync_cnt; |
---|
| 64 | unsigned int txsync_cnt; |
---|
| 65 | unsigned int txloss_cnt; |
---|
| 66 | unsigned int ahberr_cnt; |
---|
| 67 | unsigned int ints; |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | struct grcan_timing { |
---|
| 71 | unsigned char scaler; |
---|
| 72 | unsigned char ps1; |
---|
| 73 | unsigned char ps2; |
---|
| 74 | unsigned int rsj; |
---|
| 75 | unsigned char bpr; |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | struct grcan_selection { |
---|
| 79 | int selection; |
---|
| 80 | int enable0; |
---|
| 81 | int enable1; |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | struct grcan_filter { |
---|
| 85 | unsigned long long mask; |
---|
| 86 | unsigned long long code; |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | /* CAN MESSAGE */ |
---|
| 90 | typedef struct { |
---|
| 91 | char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */ |
---|
| 92 | char rtr; /* RTR - Remote Transmission Request */ |
---|
| 93 | char unused; /* unused */ |
---|
| 94 | unsigned char len; |
---|
| 95 | unsigned char data[8]; |
---|
| 96 | unsigned int id; |
---|
| 97 | } CANMsg; |
---|
| 98 | |
---|
| 99 | #define GRCAN_CFG_ABORT 0x00000001 |
---|
| 100 | #define GRCAN_CFG_ENABLE0 0x00000002 |
---|
| 101 | #define GRCAN_CFG_ENABLE1 0x00000004 |
---|
| 102 | #define GRCAN_CFG_SELECTION 0x00000008 |
---|
| 103 | #define GRCAN_CFG_SILENT 0x00000010 |
---|
| 104 | #define GRCAN_CFG_BPR 0x00000300 |
---|
| 105 | #define GRCAN_CFG_RSJ 0x00007000 |
---|
| 106 | #define GRCAN_CFG_PS1 0x00f00000 |
---|
| 107 | #define GRCAN_CFG_PS2 0x000f0000 |
---|
| 108 | #define GRCAN_CFG_SCALER 0xff000000 |
---|
| 109 | |
---|
| 110 | #define GRCAN_CFG_BPR_BIT 8 |
---|
| 111 | #define GRCAN_CFG_RSJ_BIT 12 |
---|
| 112 | #define GRCAN_CFG_PS1_BIT 20 |
---|
| 113 | #define GRCAN_CFG_PS2_BIT 16 |
---|
| 114 | #define GRCAN_CFG_SCALER_BIT 24 |
---|
| 115 | |
---|
| 116 | #define GRCAN_CTRL_RESET 0x2 |
---|
| 117 | #define GRCAN_CTRL_ENABLE 0x1 |
---|
| 118 | |
---|
| 119 | #define GRCAN_TXCTRL_ENABLE 1 |
---|
| 120 | #define GRCAN_TXCTRL_ONGOING 1 |
---|
| 121 | |
---|
| 122 | #define GRCAN_RXCTRL_ENABLE 1 |
---|
| 123 | #define GRCAN_RXCTRL_ONGOING 1 |
---|
| 124 | |
---|
| 125 | /* Relative offset of IRQ sources to AMBA Plug&Play */ |
---|
| 126 | #define GRCAN_IRQ_IRQ 0 |
---|
| 127 | #define GRCAN_IRQ_TXSYNC 1 |
---|
| 128 | #define GRCAN_IRQ_RXSYNC 2 |
---|
| 129 | |
---|
| 130 | #define GRCAN_ERR_IRQ 0x1 |
---|
| 131 | #define GRCAN_OFF_IRQ 0x2 |
---|
| 132 | #define GRCAN_OR_IRQ 0x4 |
---|
| 133 | #define GRCAN_RXAHBERR_IRQ 0x8 |
---|
| 134 | #define GRCAN_TXAHBERR_IRQ 0x10 |
---|
| 135 | #define GRCAN_RXIRQ_IRQ 0x20 |
---|
| 136 | #define GRCAN_TXIRQ_IRQ 0x40 |
---|
| 137 | #define GRCAN_RXFULL_IRQ 0x80 |
---|
| 138 | #define GRCAN_TXEMPTY_IRQ 0x100 |
---|
| 139 | #define GRCAN_RX_IRQ 0x200 |
---|
| 140 | #define GRCAN_TX_IRQ 0x400 |
---|
| 141 | #define GRCAN_RXSYNC_IRQ 0x800 |
---|
| 142 | #define GRCAN_TXSYNC_IRQ 0x1000 |
---|
| 143 | #define GRCAN_RXERR_IRQ 0x2000 |
---|
| 144 | #define GRCAN_TXERR_IRQ 0x4000 |
---|
| 145 | #define GRCAN_RXMISS_IRQ 0x8000 |
---|
| 146 | #define GRCAN_TXLOSS_IRQ 0x10000 |
---|
| 147 | |
---|
| 148 | #define GRCAN_STAT_PASS 0x1 |
---|
| 149 | #define GRCAN_STAT_OFF 0x2 |
---|
| 150 | #define GRCAN_STAT_OR 0x4 |
---|
| 151 | #define GRCAN_STAT_AHBERR 0x8 |
---|
| 152 | #define GRCAN_STAT_ACTIVE 0x10 |
---|
| 153 | #define GRCAN_STAT_RXERRCNT 0xff00 |
---|
| 154 | #define GRCAN_STAT_TXERRCNT 0xff0000 |
---|
| 155 | |
---|
| 156 | /* IOCTL Commands controlling operational |
---|
| 157 | * mode |
---|
| 158 | */ |
---|
| 159 | #define GRCAN_IOC_START 1 /* Bring the link up after open or bus-off */ |
---|
| 160 | #define GRCAN_IOC_STOP 2 /* stop to change baud rate/config or closing down */ |
---|
| 161 | #define GRCAN_IOC_ISSTARTED 3 /* return RTEMS_SUCCESSFUL when started, othervise EBUSY */ |
---|
| 162 | #define GRCAN_IOC_FLUSH 4 /* Waits until all TX messages has been sent */ |
---|
| 163 | |
---|
| 164 | /* IOCTL Commands that require connection |
---|
| 165 | * to be stopped |
---|
| 166 | */ |
---|
| 167 | #define GRCAN_IOC_SET_SILENT 16 /* enable silent mode read only state */ |
---|
| 168 | #define GRCAN_IOC_SET_ABORT 17 /* enable/disable stopping link on AHB Error */ |
---|
| 169 | #define GRCAN_IOC_SET_SELECTION 18 /* Set Enable0,Enable1,Selection */ |
---|
| 170 | #define GRCAN_IOC_SET_SPEED 19 /* Set baudrate by using driver's baud rate timing calculation routines */ |
---|
| 171 | #define GRCAN_IOC_SET_BTRS 20 /* Set baudrate by specifying the timing registers manually */ |
---|
| 172 | |
---|
| 173 | /* IOCTL Commands can be called whenever */ |
---|
| 174 | #define GRCAN_IOC_SET_RXBLOCK 32 /* Enable/disable Blocking on reception (until at least one message has been received) */ |
---|
| 175 | #define GRCAN_IOC_SET_TXBLOCK 33 /* Enable/disable Blocking on transmission (until at least one message has been transmitted) */ |
---|
| 176 | #define GRCAN_IOC_SET_TXCOMPLETE 34 /* Enable/disable Blocking until all requested messages has been sent */ |
---|
| 177 | #define GRCAN_IOC_SET_RXCOMPLETE 35 /* Enable/disable Blocking until all requested has been received */ |
---|
| 178 | #define GRCAN_IOC_GET_STATS 36 /* Get Statistics */ |
---|
| 179 | #define GRCAN_IOC_CLR_STATS 37 /* Clear Statistics */ |
---|
| 180 | #define GRCAN_IOC_SET_AFILTER 38 /* Set Acceptance filters, provide pointer to "struct grcan_filter" or NULL to disable filtering (let all messages pass) */ |
---|
| 181 | #define GRCAN_IOC_SET_SFILTER 40 /* Set Sync Messages RX/TX filters, NULL disables the IRQ completely */ |
---|
| 182 | #define GRCAN_IOC_GET_STATUS 41 /* Get status register of GRCAN core */ |
---|
| 183 | |
---|
| 184 | struct grcan_device_info { |
---|
| 185 | unsigned int base_address; |
---|
| 186 | int irq; |
---|
| 187 | }; |
---|
| 188 | |
---|
| 189 | /* Use hard coded addresses and IRQs to find hardware */ |
---|
| 190 | int grcan_register_abs(struct grcan_device_info *devices, int dev_cnt); |
---|
| 191 | |
---|
| 192 | /* Use prescanned AMBA Plug&Play information to find all GRFIFO cores */ |
---|
| 193 | int grcan_register(amba_confarea_type *abus); |
---|
| 194 | #if 0 |
---|
| 195 | void grcan_register(unsigned int baseaddr, unsigned int ram_base); |
---|
| 196 | void grcan_interrupt_handler(rtems_vector_number v); |
---|
| 197 | #endif |
---|
| 198 | |
---|
| 199 | #ifdef __cplusplus |
---|
| 200 | } |
---|
| 201 | #endif |
---|
| 202 | |
---|
| 203 | #endif |
---|