]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/unican_cl2.h
One of many steps to support Unicontrols CAN cards.
[lincan.git] / lincan / include / unican_cl2.h
1 /******************************************************************************
2
3 Cl2.H - PCAN and VCAN cards hardware access library
4 """"""""
5                    (C) Copyright 1997   Unicontrols a.s.
6
7 PROJEKT            :    CANopen
8 AUTOR              :    F.Spurny
9 FIRMA              :    CVUT FEL, Dept. of Measurement
10 PORTING            :    Adapted for LinCAN driver by Pavel Pisa, OCERA team member
11
12 DULEZITE UPOZORNENI:
13
14 ARCHIVACNI INFORMACE:
15 Log: unican_cl2.h,v 
16
17 27.1.1999 - corected value of CL2_ERROR_WARNING and CL2_ERROR_BUS_OFF constants
18
19 12.12.2000 - CL2_STATUS_RESET_CARD, CL2_ERROR_RESET_CARD added
20              fields of sCAN_MESSAGE aligned
21
22 10.8.2001 - PCI PCAN ID registers content defined
23         - cl2_find_card function prototype added
24         - cl2_get_ID function prototype added
25
26 10.2.2004 - Start of PCAN support porting to RT-Linux and Linux environment
27
28 ===============================================================================
29
30 UCEL A FUNKCE:
31
32 ******************************************************************************/
33
34 #ifndef __INC_CL2_H
35 #define __INC_CL2_H
36
37
38 /****** includes ******/
39
40 #ifndef __INC_ANCTYPES_H
41 #include "unican_types.h"
42 #endif
43
44 /****** Definitions of constants  ******/
45
46 /* PCI card Configuration Space Constants */
47 #define PCANDeviceID                    0x0101
48 #define PCANVendorID                    0xFA3C
49 #define PCANSubsystemID                 0x0001
50 #define PCANSubsystemVendorID           0x7A52
51
52
53 /* Description of card and card registers location. Registers location are
54  * mapped relative to card base address (BA) */
55
56 #define CL2_RAM_SIZE                    0x1000  /* size of dual-port RAM */
57 #define CL2_RX_BUFFER_DEFAULT           0x800   /* off(BA->rx buffer) */
58 #define CL2_SYNC_BUFFER_DEFAULT         0x400   /* off(BA->sync buffer) */
59 #define CL2_ASYNC_BUFFER_DEFAULT        0x600   /* off(BA->async buffer) */
60 #define CL2_COMMAND_REGISTER            0x3FE   /* off(BA->command register )*/
61 #define CL2_VERSION_REGISTER            0x3F6   /* off(BA->version register )*/
62 #define CL2_ID_REGISTER                 0x3EE   /* off(BA->ID register) */
63 #define CL2_GEN_INT_REGISTER            0x3E4   /* off(BA->generate interrupt reg.)*/
64 #define CL2_CLEAR_INT_REGISTER          0x3E2   /* off(BA->clear interrupt reg)*/
65 #define CL2_RESET_REGISTER              0x3E0   /* off(BA->reset register)*/
66 #define CL2_ERROR_REGISTER              0x3F8   /* off(BA->error register)*/
67 #define CL2_TIME_REGISTER                       0x3FC   /* currently not used */
68 #define CL2_START_IT_REGISTER           0x3E6   /* off(BA->start inhibit time reg.) */
69 #define CL2_STATUS_REGISTER             0x3FA   /* off(BA->status register)*/
70 #define CL2_VME_INT_VECTOR              0x3F0
71 #define CL2_DATA_BUFFER                 0x100   /* off(BA->data buffer)*/
72
73 /* Default sizes of buffers (in messages)
74  * FYI: 1 message needs 16 bytes to be stored */
75 #define CL2_RX_BUFFER_SIZE                              128     /* size of receive (rx) buffer */
76 #define CL2_TX_SYNC_BUFFER_SIZE         32              /* size of synchronnous buffer */
77 #define CL2_TX_ASYNC_BUFFER_SIZE                32              /* size of asynchronnous buffer*/
78
79 /* Command valid flag */
80 #define CL2_COMMAND_VALID                        0x0080
81
82 /* Message flags */
83 #define CL2_MESSAGE_VALID         0x0001
84
85 /* status bits */
86 #define CL2_DATA_IN_RBUF          0x0001   /* message is in rx buffer*/
87 #define CL2_X_DATA_IN_RBUF        0x0002   /* more than LIMIT messages are in
88                                                                                                                   * rx buffer*/
89 #define CL2_RBUF_OVERFLOW         0x0004   /* owerflow of rx buffer, some
90                                             * messages are lost*/
91 #define CL2_SYNC_QUEUE_EMPTY      0x0010   /* sync queue is empty */
92 #define CL2_ASYNC_QUEUE_EMPTY     0x0020   /* async queue is empty */
93 #define CL2_CARD_ERROR            0x0040   /* card reports an error */
94 #define CL2_STATUS_VALID_FLAG     0x0080   /* bit indicating that status
95                                             * register contains valid data*/
96 #define CL2_CARD_READY            0x0100   /* card is ready */
97 #define CL2_SYNC_PASSIVE          0x0200   /* passive SYNC mode */
98 #define CL2_SYNC_ACTIVE           0x0400   /* active SYNC mode */
99 #define CL2_RTR_LIST              0x0800   /* RTR list sending */
100 #define CL2_STATUS_RESET_CARD     0x8000   /* card reset occurred */
101
102 /* error bits */
103 #define CL2_ERROR_LL              0x0007   /*  */
104 #define CL2_ERROR_WARNING         0x0040   /* bus warning detected */
105 #define CL2_ERROR_BUS_OFF         0x0080   /* bus error detected */
106 #define CL2_ERROR_RESET_CARD      0x0100   /* card reset occurred */\r
107 #define CL2_ERROR_FIRMWARE        0x1000   /* firmware error detected */
108 #define CL2_ERROR_DPRAM           0x2000   /* dual port RAM error detected */
109 #define CL2_ERROR_RAM             0x4000   /* internal RAM error detected */
110 #define CL2_ERROR_CAN             0x8000   /* CAN controller error detected */
111
112 /* interrupt generation */
113 #define INT_MODE_RX               0x01     /* if data are in receive buffer*/
114 #define INT_MODE_ERROR            0x02     /* if any error occurs */
115 #define INT_MODE_SYNC_EMPTY       0x04     /* if tx sync. queue is empty*/
116 #define INT_MODE_ASYNC_EMPTY      0x08     /* if tx async. queue is empty*/
117 #define INT_MODE_ALL              0x0F     /* if any event occurs*/
118
119 /* CAN message types */
120 #define CL2_REMOTE_FRAME          0x08     /* frame is a remote frame*/
121 #define CL2_LINE_FLAG             0x80
122 #define CL2_EXT_FRAME             0x04     /* frame is extended format*/
123
124 /* Receive message flags */
125 #define CL2_FRAME_VALID           0x01     /* message in buffer is valid */
126 #define CL2_RX_OVERFLOW           0x02     /* stored unread message was
127                                             * overwritten by another one */
128
129 /* Bitrates */
130 #define CL2_BITRATE_5K            0x7f7f   /* bit-rate 5 kb/s */
131 #define CL2_BITRATE_10K           0x5c67   /* bit-rate 10 kb/s */
132 #define CL2_BITRATE_20K           0x5c53   /* bit-rate 20 kb/s */
133 #define CL2_BITRATE_50K           0x5c47   /* bit-rate 50 kb/s */
134 #define CL2_BITRATE_100K          0x5c43   /* bit-rate 100 kb/s */
135 #define CL2_BITRATE_125K          0x6743   /* bit-rate 125 kb/s */
136 #define CL2_BITRATE_200K          0x5c41   /* bit-rate 200 kb/s */
137 #define CL2_BITRATE_250K          0x6741   /* bit-rate 250 kb/s */
138 #define CL2_BITRATE_500K          0x6740   /* bit-rate 500 kb/s */
139 #define CL2_BITRATE_800K          0x3440   /* bit-rate 800 kb/s */
140 #define CL2_BITRATE_1M            0x2340   /* bit-rate 1 Mb/s */
141
142
143 /****** Definition of structures  ******/
144
145 typedef struct  /*** card definition structure ***/
146         {
147         U16  intNumber;         /* Card interrupt (IRQ) number */
148         U8   *baseAddressPtr;   /* Pointer to card base address (BA) */
149         U8   *rxBufPtr;         /* Pointer to receive buffer */
150         U8   *rxBufBase;        /* Pointer to empty receive buffer */
151         U8   *asyncTxBufPtr;    /* Pointer to async transmit buffer */
152         U8   *asyncTxBufBase;   /* Pointer to empty async. transmit buffer */
153         U8   *syncTxBufPtr;     /* Pointer to sync. transmit buffer */
154         U8   *syncTxBufBase;    /* Pointer to empty sync. transmit buffer */
155         U8   *commandRegister;  /* Pointer to command register */
156         U8   *dataPtr;          /* Pointer to command data buffer */
157         U16  rxBufSize;         /* size of receive buffer (x16 bytes) */
158         U16  syncTxBufSize;     /* size of sync. transmit buffer (x16 bytes)*/
159         U16  asyncTxBufSize;    /* size of async. transmit buffer (x 16 bytes)*/
160         U16  status;            /* last card status */
161         U16  error;             /* last not reported card error */
162         U32 rtrSub[10];
163         } sCAN_CARD;
164
165 //typedef struct  /*** CAN message formet ***/
166 //      {
167 //      U8   data[8];           /* Data message buffer (8 bytes) */
168 //      U8   dataLength;        /* Data length (in bytes) */
169 //      U32  COB_ID;            /* COB_ID */
170 //      U16  timeStamp;         /* Message time stamp */
171 //      U8   dataType;          /* Message data type */
172 //      } sCAN_MESSAGE;
173
174 typedef struct
175    {
176    U32  COB_ID;             /* COB identifier */
177    U8   dataType;          /* Message data type */
178    U8   dataLength;        /* Data length (in bytes) */
179    U8   data[8];           /* Data message buffer (8 bytes) */
180    U16  timeStamp;         /* Message time stamp [us] */
181    } sCAN_MESSAGE;
182
183
184 typedef struct  /*** Remote Request RTR frame ***/
185    {
186    U32  cob_id;           /* RTR frame ID */
187    U16  period;           /* RTR period */
188    U16  subperiod;        /* RTR subperiod */
189    } sRTR_FRAME;
190
191 typedef struct  /*** Remote Request (RTR) list ***/
192         {
193         sRTR_FRAME *data;       /* RTR data */
194         U32 nb;                 /* Number of RTR definitions */
195         } sRTR_LIST;
196
197 typedef enum  /*** CL2 functions return codes ***/
198         {
199         CL2_OK = 0,           /* OK */
200         CL2_NO_REQUEST,       /* No request*/
201         CL2_HW_FAILURE,       /* HW failure */
202         CL2_HW_QUEUE_FULL,    /* Transmit queue full */
203         CL2_BAD_PARAM,        /* Bad number of parameters */
204    CL2_HW_QUEUE_EMPTY,   /* Receive queue empty */
205         CL2_COMMAND_BUSY,     /* Command busy - previous command not completed */
206         CL2_UNKNOWN_COMMAND,  /* Unknown command */
207         CL2_NO_PCI_BIOS          /* missing PCI BIOS support */
208    } eCL2_RESULT;
209
210 typedef enum  /*** CL2 commands ***/
211    {
212    cmCL2_INT_MODE = 0x01,            /**01 - Set Interrupt mode */
213    cmCL2_IIT_MODE,                   /**02 - Inhibit Interrupt Time mode */
214    cmCL2_SYNC_MODE,                  /**03 - SYNC mode */
215         cmCL2_RTR_MODE,                   /**04 - RTR list mode */
216         cmCL2_BUF_SIZE,                   /**05 - Set buffers sizes */
217    cmCL2_SET_IIT,                    /**06 - Start Inhibit Interrupt Time */
218    cmCL2_START_FIRMWARE,             /**07 - Start firmware */
219    cmCL2_LOAD_FIRMWARE,              /* 08 - Load firmware */
220         cmCL2_SET_REC_MODE,               /**09 - Set Receive mode */
221
222    cmCL2_CLR_RX_BUFFER = 0x10,       /**10 - Clear receive buffer */
223    cmCL2_CLR_SYNC_BUFFER,            /**11 - Clear synchronous buffer */
224    cmCL2_CLR_ASYNC_BUFFER,           /**12 - Clear asynchronous buffer */
225         cmCL2_SEND_TIME_SYNC,             /**13 - Sends time synchronization */
226         cmCL2_SET_TIME_COBID,             /**14 - Sets time frames COB-ID */
227    cmCL2_SET_RECEIVE_LIMIT,          /* 15 - Sets receive limit */
228
229         cmCL2_DOWNLOAD_RTR_LIST = 0x20,   /**20 - Download RTR list */
230    cmCL2_SUBSCRIBE_RTR,              /**21 - Subscribe RTR */
231    cmCL2_DESUBSCRIBE_RTR,            /* 22 - Desubscribe RTR */
232
233    cmCL2_SET_COBID = 0x30,           /**30 - Set COB-ID */
234    cmCL2_SET_SYNC_PERIOD,            /**31 - Set SYNC period */
235    cmCL2_SET_SYNC_WINDOW,            /**32 - Set SYNC period window */
236
237         cmCL2_SET_BITRATE = 0x40,         /**40 - Set CAN bit rate */
238         cmCL2_BUS_RESET                   /* 41 - CAN controller reset */
239
240         } eCLU2_COMMAND;
241
242
243 /****** prototypes ******/
244
245
246 /*******************************************************************************
247 * cl2_find_card - find PCIPCAN card
248 * """""""""""""
249 *
250 * Searches for PCIPCAN cards in the system. The mapping (memory and interrupt)
251 * of the card is found. An index parameter specifies how many PCIPCAN cards have
252 * to be skipped in search.
253 *
254 * RETURNS:
255 *   CL2_OK - card found and mapped under 1 MB
256 *   CL2_HW_FAILURE - card not found or not mapped under 1 MB
257 */
258 eCL2_RESULT cl2_find_card
259          (
260          U16 *baseAddress,               /* card's physical base address */
261          U16 *intNumber,                 /* card's interrupt level */
262          U16 index                  /* number of PCIPCAN cards to be skipped */
263          );
264
265
266 /*******************************************************************************
267 * cl2_init_card - initialize card to default parameters
268 * """""""""""""
269 *
270 * Command installs card. The data in sCAN_CARD structure pointed
271 * by *card are initialized to their predefined default values.
272 * Command must be called before any operation with sCAN_CARD
273 * structure.
274 *
275 * RETURNS:
276 *   CL2_OK - command completed succesfuly
277 *
278 */
279 eCL2_RESULT cl2_init_card
280         (
281         sCAN_CARD *card,            /* Pointer to card structure */
282         void *baseAddress,          /* Card base address pointer */
283         U16 intNumber               /* Card interrupt number */
284         );
285
286
287 /*******************************************************************************
288 * cl2_test_card - test card
289 * """""""""""""
290 *
291 * Test whether the card is installed in system and working properly
292 * or not. If this function fails (return value is CL2_HW_FAILURE)
293 * check if the card is present and card base address.
294 *
295 * RETURNS:
296 *   CL2_OK - card is present and working properly
297 *   CL2_HW_FAILURE - card not found or card error
298 *
299 */
300 eCL2_RESULT cl2_test_card
301         (
302         sCAN_CARD *card           /* Pointer to card structure */
303         );
304
305
306 /*******************************************************************************
307 * cl2_reset_card - reset card
308 * """"""""""""""
309 *
310 * Card pointed by *card gets hardware reset. This command resets
311 * card processor, card settings are restored to their default
312 * values.
313 *
314 * RETURNS:
315 *   CL2_OK - command completed successfuly
316 *
317 */
318 eCL2_RESULT cl2_reset_card
319    (
320    sCAN_CARD *card             /* Pointer to card structure */
321    );
322
323
324 /*******************************************************************************
325 * cl2_get_version - read card version
326 * """""""""""""""
327 *
328 * Fucntion reads a value from card version register.
329 *
330 * RETURNS:
331 *   CL2_OK - command completed successfuly
332 *
333 */
334 eCL2_RESULT cl2_get_version
335    (
336    sCAN_CARD *card,            /* Pointer to card structure */
337    U16 *version                /* returns card version */
338    );
339
340
341 /*******************************************************************************
342 * cl2_get_ID - read card ID
343 * """""""""""""""
344 *
345 * Fucntion reads a value from card ID register.
346 *
347 * RETURNS:
348 *   CL2_OK - command completed successfuly
349 *
350 */
351 eCL2_RESULT cl2_get_ID
352    (
353    sCAN_CARD *card,            /* Pointer to card structure */
354    U32 *IDlow,
355    U32 *IDhigh                         /* returns card version */
356    );
357
358
359 /*******************************************************************************
360 * cl2_gen_interrupt - request for interrupt
361 * """""""""""""""""
362 *
363 * CAN card is requested to generate interrupt if there is any reason
364 * to do it. The condition for interrupt generation is defined by
365 * cl2_int_mode command.
366 *
367 * RETURNS:
368 *   CL2_OK - command completed successfuly
369 *
370 */
371 eCL2_RESULT cl2_gen_interrupt
372    (
373    sCAN_CARD *card           /* Pointer to card structure */
374    );
375
376
377 /*******************************************************************************
378 * cl2_start_it - start inhibit time
379 * """"""""""""
380 *
381 * Command starts interrupt inhibit time. If there is any reason for
382 * interrupt geneation, the card generates interrupt after end of
383 * specified time interval. Time interval is set by cl2_set_iit command.
384 *
385 * RETURNS:
386 *   CL2_OK - command completed successfuly
387 *
388 */
389 eCL2_RESULT cl2_start_it
390    (
391    sCAN_CARD *card           /* Pointer to card structure */
392    );
393
394
395 /*******************************************************************************
396 * cl2_clear_interrupt - clear interrupt
397 * """""""""""""""""""
398 *
399 * Comand clears interrupt (IRQ) generated by a card.
400 *
401 * RETURNS:
402 *   CL2_OK - command completed successfuly
403 *
404 */
405 eCL2_RESULT cl2_clear_interrupt
406    (
407    sCAN_CARD *card          /* Pointer to card structure */
408    );
409
410
411 /*******************************************************************************
412 * cl2_int_mode - set interrupt mode
413 * """"""""""""
414 *
415 * Command controls, which event will generate interrupt. Constants
416 * CL2_INT_XXXX are used for setting of interrupt mode.
417 *
418 * RETURNS:
419 *   CL2_OK - command completed successfuly
420 *   CL2_BAD_PARAM - bad command parameter
421 *   CL2_COMMAND_BUSY - previous command not completed
422 *
423 */
424 eCL2_RESULT cl2_int_mode
425    (
426    sCAN_CARD *card,            /* Pointer to card structure */
427    U16 mode                    /* Interrupt mode */
428    );
429
430
431 /*******************************************************************************
432 * cl2_iit_mode - inhibit interrupt time mode
433 * """"""""""""
434 *
435 * Command enables/disables inhibit interupt time mode.
436 *
437 * RETURNS:
438 *   CL2_OK - command completed successfuly
439 *   CL2_COMMAND_BUSY - previous command not completed
440 *
441 */
442 eCL2_RESULT cl2_iit_mode
443    (
444    sCAN_CARD *card,            /* Pointer to card structure */
445    BOOLEAN1 onoff              /* IIT mode - TRUE=on, FALSE=off */
446    );
447
448
449 /*******************************************************************************
450 * cl2_sync_mode - sync mode
451 * """""""""""""
452 *
453 * Command enables/disables transmission of SYNC frames.
454 *
455 * RETURNS:
456 *   CL2_OK - command completed successfuly
457 *   CL2_COMMAND_BUSY - previous command not completed
458 *
459 */
460 eCL2_RESULT cl2_sync_mode
461    (
462    sCAN_CARD *card,            /* Pointer to card structure */
463    BOOLEAN1 onoff              /* Sync mode - TRUE=on, FALSE=off */
464    );
465
466
467 /*******************************************************************************
468 * cl2_rtr_mode - rtr mode
469 * """"""""""""
470 *
471 * Command enables/disables automatic transmission of RTR frames
472 *
473 * RETURNS:
474 *   CL2_OK - command completed successfuly
475 *   CL2_COMMAND_BUSY - previous command not completed
476 *
477 */
478 eCL2_RESULT cl2_rtr_mode
479    (
480    sCAN_CARD *card,            /* Pointer to card structure */
481    BOOLEAN1 onoff              /* RTR mode - TRUE=on, FALSE=off */
482    );
483
484
485 /*******************************************************************************
486 * cl2_buf_size - size of synchronous queue
487 * """"""""""""
488 *
489 * Command sets the size of synchronous send buffer. The size is
490 * in numbers of messages. Default buffer size is 32 messages.
491 * The sum of synchronous_buffer_size and asynchronous_buffer_size
492 * is constant and equal to 64. So, if the size od synchronous
493 * buffer increases, the size of asynchronous buffer decreases and
494 * vice versa.
495 * NOTE: 1 message = 16 bytes
496 *
497 * RETURNS:
498 *   CL2_OK - command completed successfully
499 *   CL2_COMMAND_BUSY - previous command not completed
500 *   CL2_BAD_PARAM - bad command parameter (bufSize>64)
501 *
502 */
503 eCL2_RESULT cl2_buf_size
504    (
505    sCAN_CARD *card,            /* Pointer to card structure */
506    U16 bufSize                 /* Size of synchronous buffer */
507    );
508
509
510 /*******************************************************************************
511 * cl2_set_iit - set value of inhibit interrupt time
512 * """""""""""
513 *
514 * Command sets value of inhibit interrupt time. If inhibit
515 * interrupt time mode is enabled and started, generation of
516 * interrupt (IRQ) is disabled during this time period.
517 * Inhibit interrupt time can be set from 100 us to 6.5535 s
518 *
519 * RETURNS:
520 *   CL2_OK - command completed successfuly
521 *   CL2_COMMAND_BUSY - previous command not completed
522 *
523 */
524 eCL2_RESULT cl2_set_iit
525    (
526    sCAN_CARD *card,            /* Pointer to card structure */
527    U16 iit                     /* time period in x100 us */
528    );
529
530
531 /*******************************************************************************
532 * cl2_start_firmware - start firmware
533 * """"""""""""""""""
534 *
535 * Command starts card firmware
536 *
537 * RETURNS:
538 *   CL2_OK - command completed successfuly
539 *   CL2_COMMAND_BUSY - previous command not completed
540 *
541 */
542 eCL2_RESULT cl2_start_firmware
543    (
544    sCAN_CARD *card             /* Pointer to card structure */
545    );
546
547
548 /*******************************************************************************
549 * cl2_set_rec_mode - set receive mode
550 * """"""""""""""""
551 *
552 * Command sets card receive mode. This enable reception of standard
553 * or extended frames according to CAN 2.0A and 2.0B specifications.
554 * If value of mode is TRUE, card receives extended frames, if mode
555 * is FALSE, card receives standard massage format (default).
556 *
557 * RETURNS:
558 *   CL2_OK - command completed successfuly
559 *   CL2_COMMAND_BUSY - previous command not completed
560 *
561 */
562 eCL2_RESULT cl2_set_rec_mode
563    (
564    sCAN_CARD *card,           /* Pointer to card structure */
565    BOOLEAN1 mode              /* Mode - TRUE=ext, FALSE=std */
566    );
567
568
569 /*******************************************************************************
570 * cl2_clr_rx_buffer - clear RX buffer
571 * """""""""""""""""
572 *
573 * Command clears receive (rx) buffer. All messages stored in
574 * rx buffer will be lost.
575 *
576 * RETURNS:
577 *   CL2_OK - command completed successfuly
578 *   CL2_COMMAND_BUSY - previous command not completed
579 *
580 */
581 eCL2_RESULT cl2_clr_rx_buffer
582    (
583    sCAN_CARD *card            /* Pointer to card structure */
584    );
585
586
587 /*******************************************************************************
588 * cl2_clr_sync_buffer - clear synchronous buffer
589 * """""""""""""""""""
590 *
591 * Command clears synchronous send buffer. All messages stored
592 * in synchronous buffer will be lost.
593 *
594 * RETURNS:
595 *   CL2_OK - command completed successfuly
596 *   CL2_COMMAND_BUSY - previous command not completed
597 *
598 */
599 eCL2_RESULT cl2_clr_sync_buffer
600    (
601    sCAN_CARD *card             /* Pointer to card structure */
602    );
603
604
605 /*******************************************************************************
606 * cl2_clr_async_buffer - clear asynchronous buffer
607 * """"""""""""""""""""
608 *
609 * Command clears asynchronnous send buffer. All messages stored
610 * in async buffer will be lost.
611 *
612 * RETURNS:
613 *   CL2_OK - command completed successfuly
614 *   CL2_COMMAND_BUSY - previous command not completed
615 *
616 */
617 eCL2_RESULT cl2_clr_async_buffer
618    (
619    sCAN_CARD *card            /* Pointer to card structure */
620    );
621
622
623 /*******************************************************************************
624 * cl2_send_time_sync - send time synchronization
625 * """"""""""""""""""
626 *
627 * Command forces the card to start the High Resolution Synchronization
628 * Protocol according to the CANopen Communication profile. The SYNC
629 * mode has to be enabled (cl2_sync_mode) otherwise this command has
630 * no effect.
631 *
632 * RETURNS:
633 *   CL2_OK - command completed successfuly
634 *   CL2_COMMAND_BUSY - previous command not completed
635 *
636 */
637 eCL2_RESULT cl2_send_time_sync
638    (
639    sCAN_CARD *card             /* Pointer to card structure */
640    );
641
642
643 /*******************************************************************************
644 * cl2_set_time_cobid - set time COB-ID
645 * """"""""""""""""""
646 *
647 * Command sets the COB-ID for high resolution synchronization
648 * frame. The synchronization can be then made by means of
649 * cl2_send_time_sync command.
650 *
651 * RETURNS:
652 *   CL2_OK - command completed successfuly
653 *   CL2_COMMAND_BUSY - previous command not completed
654 *
655 */
656 eCL2_RESULT cl2_set_time_cobid
657    (
658    sCAN_CARD *card,           /* Pointer to card structure */
659    U32 COBID                  /* HRS frame COB-ID */
660    );
661
662
663 /*******************************************************************************
664 * cl2_set_receive_limit - set limit for receive signaling
665 * """""""""""""""""""""
666 *
667 * Command is used to set the receive limit signalized by bit
668 * RL (in CL2.H CL2_X_DATA_IN_RBUF) of the Status Register.
669 * This bit is set when more then the limit number of frames
670 * was received since the last interrupt was generated (in interrupt
671 * mode) or since the Status Register was last time read.
672 *
673 * RETURNS:
674 *   CL2_OK
675 *   CL2_COMMAND_BUSY - previous command not completed
676 *   CL2_BAD_PARAM - bad command parameter
677 */
678 eCL2_RESULT cl2_set_receive_limit
679    (
680    sCAN_CARD *card,          /* pointer to card structure */
681    U16 limit                 /* limit of messages in receive buffer */
682    );
683
684
685 /*******************************************************************************
686 * cl2_download_rtr_list - download rtr list
687 * """""""""""""""""""""
688 *
689 * Command downloads a list of up to 64 RTR frames. These frames are
690 * periodically transmitted by the card. The parameters, how often
691 * frames are send and in which SYNC period is defined by period and
692 * subperiod in sRTR_FRAME structure.
693 *
694 * RETURNS:
695 *   CL2_OK - command completed successfuly
696 *   CL2_COMMAND_BUSY - previous command not completed
697 *   CL2_BAD_PARAM - bad command parameter
698 *
699 */
700 eCL2_RESULT cl2_download_rtr_list
701    (
702    sCAN_CARD *card,           /* Pointer to card structure */
703    sRTR_LIST *rtrList         /* RTR list */
704    );
705
706
707 /*******************************************************************************
708 * cl2_subscribe_rtr - subscribe RTR frame
709 * """""""""""""""""
710 *
711 * Command subscribes RTR frame. Incoming RTR frames which were
712 * subscribed are accepted, while other are ignored. Up to 10
713 * RTR frames can be subscribed.
714 *
715 * RETURNS:
716 *   CL2_OK - command completed successfuly
717 *   CL2_COMMAND_BUSY - previous command not completed
718 *   CL2_BAD_PARAM - bad command parameter
719 *
720 */
721 eCL2_RESULT cl2_subscribe_rtr
722    (
723    sCAN_CARD *card,            /* Pointer to card structure */
724    sCAN_MESSAGE *canMessage,   /* RTR frame */
725    U16 RTRnumber               /* number of RTR */
726    );
727
728
729 /*******************************************************************************
730 * cl2_desubscribe_rtr - desubscribe rtr frame
731 * """""""""""""""""""
732 *
733 * Command desubscribes RTR frame. Card will not accept RTR frames
734 * with this identifier.
735 *
736 * RETURNS:
737 *   CL2_OK - command completed successfuly
738 *   CL2_COMMAND_BUSY - previous command not completed
739 *   CL2_BAD_PARAM - bad command parameter
740 *
741 */
742 eCL2_RESULT cl2_desubscribe_rtr
743    (
744    sCAN_CARD *card,            /* Pointer to card structure */
745    sCAN_MESSAGE *canMessage    /* RTR frame */
746    );
747
748
749 /*******************************************************************************
750 * cl2_set_sync_cobid - set COB-ID
751 * """"""""""""""""""
752 *
753 * Command sets COB-ID of SYNC frame. In active SYNC mode, the SYNC
754 * frame with this COB-ID is periodically sent with period defined
755 * by cl2_set_sync_period command.
756 *
757 * RETURNS:
758 *   CL2_OK - command completed successfuly
759 *   CL2_COMMAND_BUSY - previous command not completed
760 *
761 */
762 eCL2_RESULT cl2_set_sync_cobid
763    (
764    sCAN_CARD *card,            /* Pointer to card structure */
765    U32 COBID                   /* COB-ID */
766    );
767
768
769 /*******************************************************************************
770 * cl2_set_sync_period - set SYNC period
771 * """""""""""""""""""
772 *
773 * Coomand sets the SYNC frame send period in active SYNC mode in
774 * x100 us. The period range is from 0 to 0xFFFF (SYNC period can
775 * be set from 100us to 6.5535s).
776 *
777 * RETURNS:
778 *   CL2_OK - command completed successfuly
779 *   CL2_COMMAND_BUSY - previous command not completed
780 *
781 */
782 eCL2_RESULT cl2_set_sync_period
783    (
784    sCAN_CARD *card,            /* Pointer to card structure */
785    U16 period                  /* period in x100 us */
786    );
787
788
789 /*******************************************************************************
790 * cl2_set_sync_window - set SYNC window
791 * """""""""""""""""""
792 *
793 * Command sets the SYNC window length. Only during this time period
794 * after SYNC frame was send or receive the frames from the synchronous
795 * send buffer can be sent.
796 *
797 * RETURNS:
798 *   CL2_OK - command completed successfuly
799 *   CL2_COMMAND_BUSY - previous command not completed
800 *
801 */
802 eCL2_RESULT cl2_set_sync_window
803    (
804    sCAN_CARD *card,            /* Pointer to card structure */
805    U16 window                  /* period in x100 us */
806    );
807
808
809 /*******************************************************************************
810 * cl2_set_bitrate - set CAN bit-rate
811 * """""""""""""""
812 *
813 * Command switches the bus bit-rate. There are some predefined
814 * constants CL2_BITRATE_XXXX.
815 *
816 * RETURNS:
817 *   CL2_OK - command completed successfuly
818 *   CL2_COMMAND_BUSY - previous command not completed
819 *
820 */
821 eCL2_RESULT cl2_set_bitrate
822    (
823    sCAN_CARD *card,            /* Pointer to card structure */
824    U16 bitrate                 /* CAN bitrate */
825    );
826
827
828 /*******************************************************************************
829 * cl2_bus_reset - resets CAN controller
830 * """""""""""""
831 *
832 * Command resets CAN controller
833 *
834 * RETURNS:
835 *   CL2_OK - command completed successfuly
836 *   CL2_COMMAND_BUSY - previously command not completed
837 *
838 */
839 eCL2_RESULT cl2_bus_reset
840    (
841    sCAN_CARD *card            /* Pointer to card structure */
842    );
843
844
845 /*******************************************************************************
846 * cl2_send_sync - sends synchronous frame
847 * """""""""""""
848 *
849 * Command stores massage in synchronous send buffer.
850 *
851 * RETURNS:
852 *   CL2_OK - command completed successfuly
853 *   CL2_HW_QUEUE_FULL - synchronous send buffer is full
854 *   CL2_BAD_PARAM - bad command parameter
855 *   CL2_HW_FAILURE - error in HW configuration
856 *
857 */
858 eCL2_RESULT cl2_send_sync
859    (
860    sCAN_CARD *card,           /* Pointer to card structure */
861    sCAN_MESSAGE *message      /* message to be sent */
862    );
863
864
865 /*******************************************************************************
866 * cl2_send_async - sends asynchronous frame
867 * """"""""""""""
868 *
869 * Command stores message in asynchronous send buffer.
870 *
871 * RETURNS:
872 *   CL2_OK - command completed successfuly
873 *   CL2_HW_QUEUE_FULL - asynchronous buffer full
874 *   CL2_HW_FAILURE - error in HW configuration
875 *   CL2_BAD_PARAM - bad command parameter
876 *
877 */
878 eCL2_RESULT cl2_send_async
879    (
880    sCAN_CARD *card,           /* Pointer to card structure */
881    sCAN_MESSAGE *message      /* message */
882    );
883
884
885 /*******************************************************************************
886 * cl2_get_status - reads card status
887 * """"""""""""""
888 *
889 * Command reads card status register. If data in status register
890 * are valid (status valid flag is set), the value of status is read
891 * and stored in status and sCAN_CARD structure.
892 *
893 * RETURNS:
894 *   CL2_OK - command completed successfuly
895 *   CL2_NO_REQUEST - status is not valid
896 *
897 */
898 eCL2_RESULT cl2_get_status
899    (
900    sCAN_CARD *card,           /* Pointer to card structure */
901    U16 *status                /* Returned status */
902    );
903
904
905 /*******************************************************************************
906 * cl2_get_error - reads card error
907 * """""""""""""
908 *
909 * Command reads card error register. If data in error register
910 * are valid (error register valid flag is set), the value of error
911 * register is read and stored in error and sCAN_CARD structure.
912 *
913 * RETURNS:
914 *   Cl2_OK - command completed successfuly
915 *
916 */
917 eCL2_RESULT cl2_get_error
918    (
919    sCAN_CARD *card,           /* Pointer to card structure */
920    U16 *error                 /* Returned card error code */
921    );
922
923
924 /*******************************************************************************
925 * cl2_receive_data - reads received frame
926 * """"""""""""""""
927 *
928 * Command reads new messages received by a card.
929 *
930 * RETURNS:
931 *   CL2_OK - command commpleted successfuly
932 *   CL2_NO_REQUEST - there is no new message
933 *
934 */
935 eCL2_RESULT cl2_receive_data
936    (
937    sCAN_CARD *card,             /* Pointer to card structure */
938    sCAN_MESSAGE *canMessage     /* Message */
939    );
940
941
942 /* *********************************************************************** *
943  * END OF CL2.H                                                            *
944  * *********************************************************************** */
945
946 #endif /* ifndef __INC_CL2_H */