2 <!DOCTYPE book PUBLIC "-//Norman Walsh//DTD DocBk XML V4.1.2//EN"
3 "/usr/lib/sgml/dtd/docbook-xml/docbookx.dtd">
5 <book id="CANDeviceDriver">
7 <title>CAN Device Driver</title>
11 <firstname>Pavel</firstname>
12 <surname>Pisa</surname>
15 <email>pisa@cmp.felk.cvut.cz</email>
23 <holder>Pavel Pisa</holder>
28 This documentation is free software; you can redistribute
29 it and/or modify it under the terms of the GNU General Public
30 License as published by the Free Software Foundation; either
31 version 2 of the License, or (at your option) any later
36 This program is distributed in the hope that it will be
37 useful, but WITHOUT ANY WARRANTY; without even the implied
38 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
39 See the GNU General Public License for more details.
43 You should have received a copy of the GNU General Public
44 License along with this program; if not, write to the Free
45 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
50 For more details see the file COPYING in the source
51 distribution of CAN driver.
60 <title>Introduction</title>
67 <title>Driver Basics</title>
68 <sect1><title>Driver Entry and Exit points</title>
71 <refentrytitle><phrase id="API-template-request-io">template_request_io</phrase></refentrytitle>
74 <refname>template_request_io</refname>
80 <title>Synopsis</title>
81 <funcsynopsis><funcprototype>
82 <funcdef>int <function>template_request_io </function></funcdef>
83 <paramdef>unsigned long <parameter>io_addr</parameter></paramdef>
84 </funcprototype></funcsynopsis>
87 <title>Arguments</title>
90 <term><parameter>io_addr</parameter></term>
93 The reserved memory starts at <parameter>io_addr</parameter>, wich is the module
94 parameter <parameter>io</parameter>.
101 <title>Description</title>
103 The function <function>template_request_io</function> is used to reserve the io-memory. If your
104 hardware uses a dedicated memory range as hardware control registers you
105 will have to add the code to reserve this memory as well.
106 <constant>IO_RANGE</constant> is the io-memory range that gets reserved, please adjust according
107 your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
108 #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
112 <title>Return Value</title>
114 The function returns zero on success or <constant>-ENODEV</constant> on failure
127 <refentrytitle><phrase id="API-template-release-io">template_release_io</phrase></refentrytitle>
130 <refname>template_release_io</refname>
132 free reserved io-memory
136 <title>Synopsis</title>
137 <funcsynopsis><funcprototype>
138 <funcdef>int <function>template_release_io </function></funcdef>
139 <paramdef>unsigned long <parameter>io_addr</parameter></paramdef>
140 </funcprototype></funcsynopsis>
143 <title>Arguments</title>
146 <term><parameter>io_addr</parameter></term>
149 Start of the memory range to be released.
156 <title>Description</title>
158 The function <function>template_release_io</function> is used to free reserved io-memory.
159 In case you have reserved more io memory, don't forget to free it here.
160 IO_RANGE is the io-memory range that gets released, please adjust according
161 your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
162 #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
166 <title>Return Value</title>
168 The function always returns zero
181 <refentrytitle><phrase id="API-template-reset">template_reset</phrase></refentrytitle>
184 <refname>template_reset</refname>
186 hardware reset routine
190 <title>Synopsis</title>
191 <funcsynopsis><funcprototype>
192 <funcdef>int <function>template_reset </function></funcdef>
193 <paramdef>int <parameter>card</parameter></paramdef>
194 </funcprototype></funcsynopsis>
197 <title>Arguments</title>
200 <term><parameter>card</parameter></term>
203 Number of the hardware card.
210 <title>Description</title>
212 The function <function>template_reset</function> is used to give a hardware reset. This is
213 rather hardware specific so I haven't included example code. Don't forget to
214 check the reset status of the chip before returning.
218 <title>Return Value</title>
220 The function returns zero on success or <constant>-ENODEV</constant> on failure
233 <refentrytitle><phrase id="API-template-init-hw-data">template_init_hw_data</phrase></refentrytitle>
236 <refname>template_init_hw_data</refname>
238 Initialze hardware cards
242 <title>Synopsis</title>
243 <funcsynopsis><funcprototype>
244 <funcdef>int <function>template_init_hw_data </function></funcdef>
245 <paramdef>int <parameter>card</parameter></paramdef>
246 </funcprototype></funcsynopsis>
249 <title>Arguments</title>
252 <term><parameter>card</parameter></term>
255 Number of the hardware card.
262 <title>Description</title>
264 The function <function>template_init_hw_data</function> is used to initialize the hardware
265 structure containing information about the installed CAN-board.
266 <constant>RESET_ADDR</constant> represents the io-address of the hardware reset register.
267 <constant>NR_82527</constant> represents the number of intel 82527 chips on the board.
268 <constant>NR_SJA1000</constant> represents the number of philips sja1000 chips on the board.
269 The flags entry can currently only be <constant>PROGRAMMABLE_IRQ</constant> to indicate that
270 the hardware uses programmable interrupts.
274 <title>Return Value</title>
276 The function always returns zero
289 <refentrytitle><phrase id="API-template-init-chip-data">template_init_chip_data</phrase></refentrytitle>
292 <refname>template_init_chip_data</refname>
298 <title>Synopsis</title>
299 <funcsynopsis><funcprototype>
300 <funcdef>int <function>template_init_chip_data </function></funcdef>
301 <paramdef>int <parameter>card</parameter></paramdef>
302 <paramdef>int <parameter>chipnr</parameter></paramdef>
303 </funcprototype></funcsynopsis>
306 <title>Arguments</title>
309 <term><parameter>card</parameter></term>
312 Number of the hardware card
317 <term><parameter>chipnr</parameter></term>
320 Number of the CAN chip on the hardware card
327 <title>Description</title>
329 The function <function>template_init_chip_data</function> is used to initialize the hardware
330 structure containing information about the CAN chips.
331 <constant>CHIP_TYPE</constant> represents the type of CAN chip. <constant>CHIP_TYPE</constant> can be <quote>i82527</quote> or
332 <quote>sja1000</quote>.
333 The <parameter>chip_base_addr</parameter> entry represents the start of the 'official' memory map
334 of the installed chip. It's likely that this is the same as the <parameter>io_addr</parameter>
335 argument supplied at module loading time.
336 The <parameter>clock</parameter> entry holds the chip clock value in Hz.
337 The entry <parameter>sja_cdr_reg</parameter> holds hardware specific options for the Clock Divider
338 register. Options defined in the <constant>sja1000</constant>.h file:
339 <constant>CDR_CLKOUT_MASK</constant>, <constant>CDR_CLK_OFF</constant>, <constant>CDR_RXINPEN</constant>, <constant>CDR_CBP</constant>, <constant>CDR_PELICAN</constant>
340 The entry <parameter>sja_ocr_reg</parameter> holds hardware specific options for the Output Control
341 register. Options defined in the <constant>sja1000</constant>.h file:
342 <constant>OCR_MODE_BIPHASE</constant>, <constant>OCR_MODE_TEST</constant>, <constant>OCR_MODE_NORMAL</constant>, <constant>OCR_MODE_CLOCK</constant>,
343 <constant>OCR_TX0_LH</constant>, <constant>OCR_TX1_ZZ</constant>.
344 The entry <parameter>int_clk_reg</parameter> holds hardware specific options for the Clock Out
345 register. Options defined in the <constant>i82527</constant>.h file:
346 <constant>iCLK_CD0</constant>, <constant>iCLK_CD1</constant>, <constant>iCLK_CD2</constant>, <constant>iCLK_CD3</constant>, <constant>iCLK_SL0</constant>, <constant>iCLK_SL1</constant>.
347 The entry <parameter>int_bus_reg</parameter> holds hardware specific options for the Bus
348 Configuration register. Options defined in the <constant>i82527</constant>.h file:
349 <constant>iBUS_DR0</constant>, <constant>iBUS_DR1</constant>, <constant>iBUS_DT1</constant>, <constant>iBUS_POL</constant>, <constant>iBUS_CBY</constant>.
350 The entry <parameter>int_cpu_reg</parameter> holds hardware specific options for the cpu interface
351 register. Options defined in the <constant>i82527</constant>.h file:
352 <constant>iCPU_CEN</constant>, <constant>iCPU_MUX</constant>, <constant>iCPU_SLP</constant>, <constant>iCPU_PWD</constant>, <constant>iCPU_DMC</constant>, <constant>iCPU_DSC</constant>, <constant>iCPU_RST</constant>.
356 <title>Return Value</title>
358 The function always returns zero
371 <refentrytitle><phrase id="API-template-init-obj-data">template_init_obj_data</phrase></refentrytitle>
374 <refname>template_init_obj_data</refname>
376 Initialize message buffers
380 <title>Synopsis</title>
381 <funcsynopsis><funcprototype>
382 <funcdef>int <function>template_init_obj_data </function></funcdef>
383 <paramdef>int <parameter>chipnr</parameter></paramdef>
384 <paramdef>int <parameter>objnr</parameter></paramdef>
385 </funcprototype></funcsynopsis>
388 <title>Arguments</title>
391 <term><parameter>chipnr</parameter></term>
394 Number of the CAN chip
399 <term><parameter>objnr</parameter></term>
402 Number of the message buffer
409 <title>Description</title>
411 The function <function>template_init_obj_data</function> is used to initialize the hardware
412 structure containing information about the different message objects on the
413 CAN chip. In case of the sja1000 there's only one message object but on the
414 i82527 chip there are 15.
415 The code below is for a i82527 chip and initializes the object base addresses
416 The entry <parameter>obj_base_addr</parameter> represents the first memory address of the message
417 object. In case of the sja1000 <parameter>obj_base_addr</parameter> is taken the same as the chips
419 Unless the hardware uses a segmented memory map, flags can be set zero.
423 <title>Return Value</title>
425 The function always returns zero
438 <refentrytitle><phrase id="API-template-program-irq">template_program_irq</phrase></refentrytitle>
441 <refname>template_program_irq</refname>
447 <title>Synopsis</title>
448 <funcsynopsis><funcprototype>
449 <funcdef>int <function>template_program_irq </function></funcdef>
450 <paramdef>int <parameter>card</parameter></paramdef>
451 </funcprototype></funcsynopsis>
454 <title>Arguments</title>
457 <term><parameter>card</parameter></term>
460 Number of the hardware card.
467 <title>Description</title>
469 The function <function>template_program_irq</function> is used for hardware that uses
470 programmable interrupts. If your hardware doesn't use programmable interrupts
471 you should not set the <parameter>candevices_t</parameter>->flags entry to <constant>PROGRAMMABLE_IRQ</constant> and
472 leave this function unedited. Again this function is hardware specific so
473 there's no example code.
477 <title>Return value</title>
479 The function returns zero on success or <constant>-ENODEV</constant> on failure
492 <refentrytitle><phrase id="API-template-write-register">template_write_register</phrase></refentrytitle>
495 <refname>template_write_register</refname>
497 Low level write register routine
501 <title>Synopsis</title>
502 <funcsynopsis><funcprototype>
503 <funcdef>void <function>template_write_register </function></funcdef>
504 <paramdef>unsigned char <parameter>data</parameter></paramdef>
505 <paramdef>unsigned long <parameter>address</parameter></paramdef>
506 </funcprototype></funcsynopsis>
509 <title>Arguments</title>
512 <term><parameter>data</parameter></term>
520 <term><parameter>address</parameter></term>
523 memory address to write to
530 <title>Description</title>
532 The function <function>template_write_register</function> is used to write to hardware registers
533 on the CAN chip. You should only have to edit this function if your hardware
534 uses some specific write process.
538 <title>Return Value</title>
540 The function does not return a value
553 <refentrytitle><phrase id="API-template-read-register">template_read_register</phrase></refentrytitle>
556 <refname>template_read_register</refname>
558 Low level read register routine
562 <title>Synopsis</title>
563 <funcsynopsis><funcprototype>
564 <funcdef>unsigned <function>template_read_register </function></funcdef>
565 <paramdef>unsigned long <parameter>address</parameter></paramdef>
566 </funcprototype></funcsynopsis>
569 <title>Arguments</title>
572 <term><parameter>address</parameter></term>
575 memory address to read from
582 <title>Description</title>
584 The function <function>template_read_register</function> is used to read from hardware registers
585 on the CAN chip. You should only have to edit this function if your hardware
586 uses some specific read process.
590 <title>Return Value</title>
592 The function returns the value stored in <parameter>address</parameter>