File indexing completed on 2025-05-11 08:23:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef __GRCAN_H__
0036 #define __GRCAN_H__
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 #include <stdint.h>
0049
0050 #ifdef __cplusplus
0051 extern "C" {
0052 #endif
0053
0054 struct grcan_regs {
0055 volatile unsigned int conf;
0056 volatile unsigned int stat;
0057 volatile unsigned int ctrl;
0058 volatile unsigned int dummy0[3];
0059 volatile unsigned int smask;
0060 volatile unsigned int scode;
0061
0062 volatile unsigned int dummy1[8];
0063
0064 volatile unsigned int nbtr;
0065 volatile unsigned int fdbtr;
0066 volatile unsigned int tdelay;
0067
0068 volatile unsigned int dummy1b[45];
0069
0070 volatile unsigned int pimsr;
0071 volatile unsigned int pimr;
0072 volatile unsigned int pisr;
0073 volatile unsigned int pir;
0074 volatile unsigned int imr;
0075 volatile unsigned int picr;
0076
0077 volatile unsigned int dummy2[58];
0078
0079 volatile unsigned int tx0ctrl;
0080 volatile unsigned int tx0addr;
0081 volatile unsigned int tx0size;
0082 volatile unsigned int tx0wr;
0083 volatile unsigned int tx0rd;
0084 volatile unsigned int tx0irq;
0085
0086 volatile unsigned int dummy3[58];
0087
0088 volatile unsigned int rx0ctrl;
0089 volatile unsigned int rx0addr;
0090 volatile unsigned int rx0size;
0091 volatile unsigned int rx0wr;
0092 volatile unsigned int rx0rd;
0093 volatile unsigned int rx0irq;
0094 volatile unsigned int rx0mask;
0095 volatile unsigned int rx0code;
0096 };
0097
0098 struct grcan_stats {
0099 unsigned int passive_cnt;
0100 unsigned int overrun_cnt;
0101 unsigned int rxsync_cnt;
0102 unsigned int txsync_cnt;
0103 unsigned int txloss_cnt;
0104 unsigned int ahberr_cnt;
0105 unsigned int ints;
0106 unsigned int busoff_cnt;
0107 };
0108
0109 struct grcan_timing {
0110 unsigned char scaler;
0111 unsigned char ps1;
0112 unsigned char ps2;
0113 unsigned char rsj;
0114 unsigned char bpr;
0115 };
0116
0117 struct grcanfd_timing {
0118 unsigned char scaler;
0119 unsigned char ps1;
0120 unsigned char ps2;
0121 unsigned char sjw;
0122 unsigned char resv_zero;
0123 };
0124
0125 struct grcan_selection {
0126 int selection;
0127 int enable0;
0128 int enable1;
0129 };
0130
0131 struct grcan_filter {
0132 unsigned long long mask;
0133 unsigned long long code;
0134 };
0135
0136 #define GRCAN_FDOPT_NOM 0
0137 #define GRCAN_FDOPT_FDBTR 0x01
0138 #define GRCAN_FDOPT_FDFRM 0x02
0139 #define GRCAN_FDMASK (GRCAN_FDOPT_FDBTR | GRCAN_FDOPT_FDFRM)
0140
0141
0142 typedef struct {
0143 char extended;
0144 char rtr;
0145 char unused;
0146 unsigned char len;
0147 unsigned char data[8];
0148 unsigned int id;
0149 } CANMsg;
0150
0151
0152 typedef struct {
0153 uint8_t extended;
0154 uint8_t rtr;
0155 uint8_t fdopts;
0156 uint8_t len;
0157 uint32_t id;
0158 union {
0159 uint64_t dwords[8];
0160 uint8_t bytes[64];
0161 } data;
0162 } CANFDMsg;
0163
0164 enum {
0165 GRCAN_RET_OK = 0,
0166 GRCAN_RET_INVARG = -1,
0167 GRCAN_RET_NOTSTARTED = -2,
0168 GRCAN_RET_TIMEOUT = -3,
0169
0170 GRCAN_RET_BUSOFF = -4,
0171
0172 GRCAN_RET_AHBERR = -5,
0173 };
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 enum grcan_state {
0191 STATE_STOPPED = 0,
0192 STATE_STARTED = 1,
0193 STATE_BUSOFF = 2,
0194 STATE_AHBERR = 3,
0195 };
0196
0197 #define GRCAN_CFG_ABORT 0x00000001
0198 #define GRCAN_CFG_ENABLE0 0x00000002
0199 #define GRCAN_CFG_ENABLE1 0x00000004
0200 #define GRCAN_CFG_SELECTION 0x00000008
0201 #define GRCAN_CFG_SILENT 0x00000010
0202 #define GRCAN_CFG_BPR 0x00000300
0203 #define GRCAN_CFG_RSJ 0x00007000
0204 #define GRCAN_CFG_PS1 0x00f00000
0205 #define GRCAN_CFG_PS2 0x000f0000
0206 #define GRCAN_CFG_SCALER 0xff000000
0207
0208 #define GRCAN_CFG_BPR_BIT 8
0209 #define GRCAN_CFG_RSJ_BIT 12
0210 #define GRCAN_CFG_PS1_BIT 20
0211 #define GRCAN_CFG_PS2_BIT 16
0212 #define GRCAN_CFG_SCALER_BIT 24
0213
0214 #define GRCAN_CTRL_RESET 0x2
0215 #define GRCAN_CTRL_ENABLE 0x1
0216
0217 #define GRCAN_TXCTRL_ENABLE 1
0218 #define GRCAN_TXCTRL_ONGOING 1
0219
0220 #define GRCAN_RXCTRL_ENABLE 1
0221 #define GRCAN_RXCTRL_ONGOING 1
0222
0223 #define GRCANFD_NBTR_SCALER 0x00ff0000
0224 #define GRCANFD_NBTR_PS1 0x0000fc00
0225 #define GRCANFD_NBTR_PS2 0x000003e0
0226 #define GRCANFD_NBTR_SJW 0x0000001f
0227
0228 #define GRCANFD_NBTR_SCALER_BIT 16
0229 #define GRCANFD_NBTR_PS1_BIT 10
0230 #define GRCANFD_NBTR_PS2_BIT 5
0231 #define GRCANFD_NBTR_SJW_BIT 0
0232
0233 #define GRCANFD_FDBTR_SCALER 0x00ff0000
0234 #define GRCANFD_FDBTR_PS1 0x00003c00
0235 #define GRCANFD_FDBTR_PS2 0x000001e0
0236 #define GRCANFD_FDBTR_SJW 0x0000000f
0237
0238 #define GRCANFD_FDBTR_SCALER_BIT 16
0239 #define GRCANFD_FDBTR_PS1_BIT 10
0240 #define GRCANFD_FDBTR_PS2_BIT 5
0241 #define GRCANFD_FDBTR_SJW_BIT 0
0242
0243
0244 #define GRCAN_IRQ_IRQ 0
0245 #define GRCAN_IRQ_TXSYNC 1
0246 #define GRCAN_IRQ_RXSYNC 2
0247
0248 #define GRCAN_ERR_IRQ 0x1
0249 #define GRCAN_OFF_IRQ 0x2
0250 #define GRCAN_OR_IRQ 0x4
0251 #define GRCAN_RXAHBERR_IRQ 0x8
0252 #define GRCAN_TXAHBERR_IRQ 0x10
0253 #define GRCAN_RXIRQ_IRQ 0x20
0254 #define GRCAN_TXIRQ_IRQ 0x40
0255 #define GRCAN_RXFULL_IRQ 0x80
0256 #define GRCAN_TXEMPTY_IRQ 0x100
0257 #define GRCAN_RX_IRQ 0x200
0258 #define GRCAN_TX_IRQ 0x400
0259 #define GRCAN_RXSYNC_IRQ 0x800
0260 #define GRCAN_TXSYNC_IRQ 0x1000
0261 #define GRCAN_RXERR_IRQ 0x2000
0262 #define GRCAN_TXERR_IRQ 0x4000
0263 #define GRCAN_RXMISS_IRQ 0x8000
0264 #define GRCAN_TXLOSS_IRQ 0x10000
0265
0266 #define GRCAN_STAT_PASS 0x1
0267 #define GRCAN_STAT_OFF 0x2
0268 #define GRCAN_STAT_OR 0x4
0269 #define GRCAN_STAT_AHBERR 0x8
0270 #define GRCAN_STAT_ACTIVE 0x10
0271 #define GRCAN_STAT_RXERRCNT 0xff00
0272 #define GRCAN_STAT_TXERRCNT 0xff0000
0273
0274
0275
0276
0277 extern int grcan_dev_count(void);
0278
0279
0280
0281
0282
0283
0284
0285
0286 extern void *grcan_open(int dev_no);
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297 extern void *grcan_open_by_name(char *name, int *dev_no);
0298
0299
0300
0301
0302
0303
0304 extern int grcan_close(void *d);
0305
0306
0307
0308
0309
0310
0311
0312
0313 extern int grcan_canfd_capable(void *d);
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334 extern int grcan_read(
0335 void *d,
0336 CANMsg *msg,
0337 size_t count
0338 );
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359 extern int grcanfd_read(
0360 void *d,
0361 CANFDMsg *msg,
0362 size_t count
0363 );
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384 extern int grcan_write(
0385 void *d,
0386 CANMsg *msg,
0387 size_t count
0388 );
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409 extern int grcanfd_write(
0410 void *d,
0411 CANFDMsg *msg,
0412 size_t ucount
0413 );
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428 extern int grcan_get_state(void *d);
0429
0430
0431
0432
0433
0434
0435
0436 extern int grcan_start(void *d);
0437
0438 extern int grcan_stop(void *d);
0439
0440 extern int grcan_flush(void *d);
0441
0442
0443
0444
0445
0446 extern int grcan_set_silent(void *d, int silent);
0447
0448 extern int grcan_set_abort(void *d, int abort);
0449
0450 extern int grcan_set_selection(void *d, const struct grcan_selection *selection);
0451
0452 extern int grcan_set_speed(void *d, unsigned int hz);
0453
0454 extern int grcan_set_btrs(void *d, const struct grcan_timing *timing);
0455
0456
0457
0458
0459 extern int grcanfd_set_speed(void *d, unsigned int nomhz, unsigned int fdhz);
0460
0461 extern int grcanfd_set_btrs(
0462 void *d,
0463 const struct grcanfd_timing *nominal,
0464 const struct grcanfd_timing *fd);
0465
0466
0467
0468 int grcan_set_rxblock(void* d, int block);
0469
0470 int grcan_set_txblock(void* d, int block);
0471
0472 int grcan_set_txcomplete(void* d, int complete);
0473
0474 int grcan_set_rxcomplete(void* d, int complete);
0475
0476 extern int grcan_get_stats(void *d, struct grcan_stats *stats);
0477
0478 extern int grcan_clr_stats(void *d);
0479
0480 extern int grcan_set_afilter(void *d, const struct grcan_filter *filter);
0481
0482 extern int grcan_set_sfilter(void *d, const struct grcan_filter *filter);
0483
0484 extern int grcan_get_status(void *d, unsigned int *status);
0485
0486 void grcan_register_drv(void);
0487
0488 #ifdef __cplusplus
0489 }
0490 #endif
0491
0492
0493
0494 #endif