]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/app/usbcan/can/can.h
Merge branch 'master' into can-usb1
[lincan.git] / embedded / app / usbcan / can / can.h
1 #ifndef SJA1000_CAN_H
2 #define SJA1000_CAN_H
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <cpu_def.h>
7 #include <system_def.h>
8 #include <lt_timer.h>
9 #include <local_config.h>
10 #include <usb/usbdebug.h>
11 #include <usb/usb.h>
12 #include <usb/lpc.h>
13 #include <usb/usb_srq.h>
14 #include <mem_loc.h>
15 #include <hal_machperiph.h>
16
17
18 #include "main.h"
19 #include "sja1000p.h"
20 /* can.h
21  * Header file for the Linux CAN-bus driver.
22  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
23  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
24  * email:pisa@cmp.felk.cvut.cz
25  * This software is released under the GPL-License.
26  * Version lincan-0.3  17 Jun 2004
27  */
28
29  /*
30                 Delay for synchronization with peripheral (SJA1000)
31  */
32         #define SJA1000_CLK (24000000)  /* XTAL frequency */
33         #define SJA1000_PRESC (2)       /* embedded prescaler */
34         #define SJA1000_CCLK (SJA1000_CLK/SJA1000_PRESC)        /* SJA core frequency */
35         #define SJA1000_SCLK (PCLK/SJA1000_CCLK)        /* Clock count to synchronize with LPC */
36
37         #define SJA1000_DELAY(void)     \
38                         ({ \
39                                 volatile int delay; \
40                                 for (delay=0;delay<SJA1000_SCLK;delay++) \
41                                         IO0SET=0; \
42                         })
43         #define SJA1000_INIT_DELAY(void)        \
44                         ({ \
45                                 volatile int delay; \
46                                 for (delay=0;delay<20*SJA1000_SCLK;delay++) \
47                                         IO0SET=0; \
48                         })
49
50 /**
51  * struct can_baudparams_t - datatype for calling CONF_BAUDPARAMS IOCTL
52  * @flags: reserved for additional flags for chip configuration, should be written -1 or 0
53  * @baudrate: baud rate in Hz
54  * @sjw: synchronization jump width (0-3) prescaled clock cycles
55  * @sampl_pt: sample point in % (0-100) sets (TSEG1+1)/(TSEG1+TSEG2+2) ratio
56  *
57  * The structure is used to configure new set of parameters into CAN controller chip.
58  * If default value of some field should be preserved, fill field by value -1.
59  */
60 struct can_baudparams_t {
61         long flags;
62         long baudrate;
63         long sjw;
64         long sample_pt;
65 };
66
67 extern int can_init();
68 extern uint8_t can_read(uint8_t address);
69 extern void can_write(uint8_t data, uint8_t address);
70
71 #endif /* SJA1000_CAN_H */