Interconnected OCERA configuration options with LinCAN boardlist.c compilation.
authorppisa <ppisa>
Sun, 14 Mar 2004 00:13:02 +0000 (00:13 +0000)
committerppisa <ppisa>
Sun, 14 Mar 2004 00:13:02 +0000 (00:13 +0000)
lincan/include/unican_cl2.h [new file with mode: 0644]
lincan/src/Makefile.omk
lincan/src/Makefile.std
lincan/src/boardlist.c
lincan/src/supported_cards.h [deleted file]
lincan/src/unican_cl2.c [new file with mode: 0644]
lincan/utils/Makefile.omk

diff --git a/lincan/include/unican_cl2.h b/lincan/include/unican_cl2.h
new file mode 100644 (file)
index 0000000..ffd6bec
--- /dev/null
@@ -0,0 +1,949 @@
+/******************************************************************************
+
+Cl2.H - PCAN and VCAN cards hardware access library
+""""""""
+                   (C) Copyright 1997   Unicontrols a.s.
+
+PROJEKT            :    CANopen
+AUTOR              :    F.Spurny
+FIRMA              :    CVUT FEL, Dept. of Measurement
+PORTING            :    Adapted for LinCAN driver by Pavel Pisa, OCERA team member
+
+DULEZITE UPOZORNENI:
+
+ARCHIVACNI INFORMACE:
+$Log$
+Revision 1.1  2004/03/13 23:13:31  ppisa
+Interconnected OCERA configuration options with LinCAN boardlist.c compilation.
+
+
+27.1.1999 - corected value of CL2_ERROR_WARNING and CL2_ERROR_BUS_OFF constants
+
+12.12.2000 - CL2_STATUS_RESET_CARD, CL2_ERROR_RESET_CARD added
+             fields of sCAN_MESSAGE aligned
+
+10.8.2001 - PCI PCAN ID registers content defined
+       - cl2_find_card function prototype added
+       - cl2_get_ID function prototype added
+
+10.2.2004 - Start of PCAN support porting to RT-Linux and Linux environment
+
+===============================================================================
+
+UCEL A FUNKCE:
+
+******************************************************************************/
+
+#ifndef __INC_CL2_H
+#define __INC_CL2_H
+
+
+/****** includes ******/
+
+#ifndef __INC_ANCTYPES_H
+#include "anctypes.h"
+#endif
+
+/****** Definitions of constants  ******/
+
+/* PCI card Configuration Space Constants */
+#define PCANDeviceID                   0x0101
+#define PCANVendorID                   0xFA3C
+#define PCANSubsystemID                        0x0001
+#define PCANSubsystemVendorID          0x7A52
+
+
+/* Description of card and card registers location. Registers location are
+ * mapped relative to card base address (BA) */
+
+#define CL2_RAM_SIZE                   0x1000  /* size of dual-port RAM */
+#define CL2_RX_BUFFER_DEFAULT          0x800   /* off(BA->rx buffer) */
+#define CL2_SYNC_BUFFER_DEFAULT                0x400   /* off(BA->sync buffer) */
+#define CL2_ASYNC_BUFFER_DEFAULT       0x600   /* off(BA->async buffer) */
+#define CL2_COMMAND_REGISTER           0x3FE   /* off(BA->command register )*/
+#define CL2_VERSION_REGISTER           0x3F6   /* off(BA->version register )*/
+#define CL2_ID_REGISTER                        0x3EE   /* off(BA->ID register) */
+#define CL2_GEN_INT_REGISTER           0x3E4   /* off(BA->generate interrupt reg.)*/
+#define CL2_CLEAR_INT_REGISTER         0x3E2   /* off(BA->clear interrupt reg)*/
+#define CL2_RESET_REGISTER             0x3E0   /* off(BA->reset register)*/
+#define CL2_ERROR_REGISTER             0x3F8   /* off(BA->error register)*/
+#define CL2_TIME_REGISTER                      0x3FC   /* currently not used */
+#define CL2_START_IT_REGISTER          0x3E6   /* off(BA->start inhibit time reg.) */
+#define CL2_STATUS_REGISTER            0x3FA   /* off(BA->status register)*/
+#define CL2_VME_INT_VECTOR             0x3F0
+#define CL2_DATA_BUFFER                        0x100   /* off(BA->data buffer)*/
+
+/* Default sizes of buffers (in messages)
+ * FYI: 1 message needs 16 bytes to be stored */
+#define CL2_RX_BUFFER_SIZE                             128     /* size of receive (rx) buffer */
+#define CL2_TX_SYNC_BUFFER_SIZE                32              /* size of synchronnous buffer */
+#define CL2_TX_ASYNC_BUFFER_SIZE               32              /* size of asynchronnous buffer*/
+
+/* Command valid flag */
+#define CL2_COMMAND_VALID                       0x0080
+
+/* Message flags */
+#define CL2_MESSAGE_VALID         0x0001
+
+/* status bits */
+#define CL2_DATA_IN_RBUF          0x0001   /* message is in rx buffer*/
+#define CL2_X_DATA_IN_RBUF        0x0002   /* more than LIMIT messages are in
+                                                                                                                 * rx buffer*/
+#define CL2_RBUF_OVERFLOW         0x0004   /* owerflow of rx buffer, some
+                                            * messages are lost*/
+#define CL2_SYNC_QUEUE_EMPTY      0x0010   /* sync queue is empty */
+#define CL2_ASYNC_QUEUE_EMPTY     0x0020   /* async queue is empty */
+#define CL2_CARD_ERROR            0x0040   /* card reports an error */
+#define CL2_STATUS_VALID_FLAG     0x0080   /* bit indicating that status
+                                            * register contains valid data*/
+#define CL2_CARD_READY            0x0100   /* card is ready */
+#define CL2_SYNC_PASSIVE          0x0200   /* passive SYNC mode */
+#define CL2_SYNC_ACTIVE           0x0400   /* active SYNC mode */
+#define CL2_RTR_LIST              0x0800   /* RTR list sending */
+#define CL2_STATUS_RESET_CARD     0x8000   /* card reset occurred */
+
+/* error bits */
+#define CL2_ERROR_LL              0x0007   /*  */
+#define CL2_ERROR_WARNING         0x0040   /* bus warning detected */
+#define CL2_ERROR_BUS_OFF         0x0080   /* bus error detected */
+#define CL2_ERROR_RESET_CARD      0x0100   /* card reset occurred */\r
+#define CL2_ERROR_FIRMWARE        0x1000   /* firmware error detected */
+#define CL2_ERROR_DPRAM           0x2000   /* dual port RAM error detected */
+#define CL2_ERROR_RAM             0x4000   /* internal RAM error detected */
+#define CL2_ERROR_CAN             0x8000   /* CAN controller error detected */
+
+/* interrupt generation */
+#define INT_MODE_RX               0x01     /* if data are in receive buffer*/
+#define INT_MODE_ERROR            0x02     /* if any error occurs */
+#define INT_MODE_SYNC_EMPTY       0x04     /* if tx sync. queue is empty*/
+#define INT_MODE_ASYNC_EMPTY      0x08     /* if tx async. queue is empty*/
+#define INT_MODE_ALL              0x0F     /* if any event occurs*/
+
+/* CAN message types */
+#define CL2_REMOTE_FRAME          0x08     /* frame is a remote frame*/
+#define CL2_LINE_FLAG             0x80
+#define CL2_EXT_FRAME             0x04     /* frame is extended format*/
+
+/* Receive message flags */
+#define CL2_FRAME_VALID           0x01     /* message in buffer is valid */
+#define CL2_RX_OVERFLOW           0x02     /* stored unread message was
+                                            * overwritten by another one */
+
+/* Bitrates */
+#define CL2_BITRATE_5K            0x7f7f   /* bit-rate 5 kb/s */
+#define CL2_BITRATE_10K           0x5c67   /* bit-rate 10 kb/s */
+#define CL2_BITRATE_20K           0x5c53   /* bit-rate 20 kb/s */
+#define CL2_BITRATE_50K           0x5c47   /* bit-rate 50 kb/s */
+#define CL2_BITRATE_100K          0x5c43   /* bit-rate 100 kb/s */
+#define CL2_BITRATE_125K          0x6743   /* bit-rate 125 kb/s */
+#define CL2_BITRATE_200K          0x5c41   /* bit-rate 200 kb/s */
+#define CL2_BITRATE_250K          0x6741   /* bit-rate 250 kb/s */
+#define CL2_BITRATE_500K          0x6740   /* bit-rate 500 kb/s */
+#define CL2_BITRATE_800K          0x3440   /* bit-rate 800 kb/s */
+#define CL2_BITRATE_1M            0x2340   /* bit-rate 1 Mb/s */
+
+
+/****** Definition of structures  ******/
+
+typedef struct  /*** card definition structure ***/
+       {
+       U16  intNumber;         /* Card interrupt (IRQ) number */
+       U8   *baseAddressPtr;   /* Pointer to card base address (BA) */
+       U8   *rxBufPtr;         /* Pointer to receive buffer */
+       U8   *rxBufBase;        /* Pointer to empty receive buffer */
+       U8   *asyncTxBufPtr;    /* Pointer to async transmit buffer */
+       U8   *asyncTxBufBase;   /* Pointer to empty async. transmit buffer */
+       U8   *syncTxBufPtr;     /* Pointer to sync. transmit buffer */
+       U8   *syncTxBufBase;    /* Pointer to empty sync. transmit buffer */
+       U8   *commandRegister;  /* Pointer to command register */
+       U8   *dataPtr;          /* Pointer to command data buffer */
+       U16  rxBufSize;         /* size of receive buffer (x16 bytes) */
+       U16  syncTxBufSize;     /* size of sync. transmit buffer (x16 bytes)*/
+       U16  asyncTxBufSize;    /* size of async. transmit buffer (x 16 bytes)*/
+       U16  status;            /* last card status */
+       U16  error;             /* last not reported card error */
+       U32 rtrSub[10];
+       } sCAN_CARD;
+
+//typedef struct  /*** CAN message formet ***/
+//     {
+//     U8   data[8];           /* Data message buffer (8 bytes) */
+//     U8   dataLength;        /* Data length (in bytes) */
+//     U32  COB_ID;            /* COB_ID */
+//     U16  timeStamp;         /* Message time stamp */
+//     U8   dataType;          /* Message data type */
+//     } sCAN_MESSAGE;
+
+typedef struct
+   {
+   U32  COB_ID;             /* COB identifier */
+   U8   dataType;          /* Message data type */
+   U8   dataLength;        /* Data length (in bytes) */
+   U8   data[8];           /* Data message buffer (8 bytes) */
+   U16  timeStamp;         /* Message time stamp [us] */
+   } sCAN_MESSAGE;
+
+
+typedef        struct  /*** Remote Request RTR frame ***/
+   {
+   U32  cob_id;           /* RTR frame ID */
+   U16  period;           /* RTR period */
+   U16  subperiod;        /* RTR subperiod */
+   } sRTR_FRAME;
+
+typedef struct  /*** Remote Request (RTR) list ***/
+       {
+       sRTR_FRAME *data;       /* RTR data */
+       U32 nb;                 /* Number of RTR definitions */
+       } sRTR_LIST;
+
+typedef enum  /*** CL2 functions return codes ***/
+       {
+       CL2_OK = 0,           /* OK */
+       CL2_NO_REQUEST,       /* No request*/
+       CL2_HW_FAILURE,       /* HW failure */
+       CL2_HW_QUEUE_FULL,    /* Transmit queue full */
+       CL2_BAD_PARAM,        /* Bad number of parameters */
+   CL2_HW_QUEUE_EMPTY,   /* Receive queue empty */
+       CL2_COMMAND_BUSY,     /* Command busy - previous command not completed */
+       CL2_UNKNOWN_COMMAND,  /* Unknown command */
+       CL2_NO_PCI_BIOS          /* missing PCI BIOS support */
+   } eCL2_RESULT;
+
+typedef enum  /*** CL2 commands ***/
+   {
+   cmCL2_INT_MODE = 0x01,            /**01 - Set Interrupt mode */
+   cmCL2_IIT_MODE,                   /**02 - Inhibit Interrupt Time mode */
+   cmCL2_SYNC_MODE,                  /**03 - SYNC mode */
+       cmCL2_RTR_MODE,                   /**04 - RTR list mode */
+       cmCL2_BUF_SIZE,                   /**05 - Set buffers sizes */
+   cmCL2_SET_IIT,                    /**06 - Start Inhibit Interrupt Time */
+   cmCL2_START_FIRMWARE,             /**07 - Start firmware */
+   cmCL2_LOAD_FIRMWARE,              /* 08 - Load firmware */
+       cmCL2_SET_REC_MODE,               /**09 - Set Receive mode */
+
+   cmCL2_CLR_RX_BUFFER = 0x10,       /**10 - Clear receive buffer */
+   cmCL2_CLR_SYNC_BUFFER,            /**11 - Clear synchronous buffer */
+   cmCL2_CLR_ASYNC_BUFFER,           /**12 - Clear asynchronous buffer */
+       cmCL2_SEND_TIME_SYNC,             /**13 - Sends time synchronization */
+       cmCL2_SET_TIME_COBID,             /**14 - Sets time frames COB-ID */
+   cmCL2_SET_RECEIVE_LIMIT,          /* 15 - Sets receive limit */
+
+       cmCL2_DOWNLOAD_RTR_LIST = 0x20,   /**20 - Download RTR list */
+   cmCL2_SUBSCRIBE_RTR,              /**21 - Subscribe RTR */
+   cmCL2_DESUBSCRIBE_RTR,            /* 22 - Desubscribe RTR */
+
+   cmCL2_SET_COBID = 0x30,           /**30 - Set COB-ID */
+   cmCL2_SET_SYNC_PERIOD,            /**31 - Set SYNC period */
+   cmCL2_SET_SYNC_WINDOW,            /**32 - Set SYNC period window */
+
+       cmCL2_SET_BITRATE = 0x40,         /**40 - Set CAN bit rate */
+       cmCL2_BUS_RESET                   /* 41 - CAN controller reset */
+
+       } eCLU2_COMMAND;
+
+
+/****** prototypes ******/
+
+
+/*******************************************************************************
+* cl2_find_card - find PCIPCAN card
+* """""""""""""
+*
+* Searches for PCIPCAN cards in the system. The mapping (memory and interrupt)
+* of the card is found. An index parameter specifies how many PCIPCAN cards have
+* to be skipped in search.
+*
+* RETURNS:
+*   CL2_OK - card found and mapped under 1 MB
+*   CL2_HW_FAILURE - card not found or not mapped under 1 MB
+*/
+eCL2_RESULT cl2_find_card
+        (
+        U16 *baseAddress,               /* card's physical base address */
+        U16 *intNumber,                 /* card's interrupt level */
+        U16 index                  /* number of PCIPCAN cards to be skipped */
+        );
+
+
+/*******************************************************************************
+* cl2_init_card - initialize card to default parameters
+* """""""""""""
+*
+* Command installs card. The data in sCAN_CARD structure pointed
+* by *card are initialized to their predefined default values.
+* Command must be called before any operation with sCAN_CARD
+* structure.
+*
+* RETURNS:
+*   CL2_OK - command completed succesfuly
+*
+*/
+eCL2_RESULT cl2_init_card
+       (
+       sCAN_CARD *card,            /* Pointer to card structure */
+       void *baseAddress,          /* Card base address pointer */
+       U16 intNumber               /* Card interrupt number */
+       );
+
+
+/*******************************************************************************
+* cl2_test_card - test card
+* """""""""""""
+*
+* Test whether the card is installed in system and working properly
+* or not. If this function fails (return value is CL2_HW_FAILURE)
+* check if the card is present and card base address.
+*
+* RETURNS:
+*   CL2_OK - card is present and working properly
+*   CL2_HW_FAILURE - card not found or card error
+*
+*/
+eCL2_RESULT cl2_test_card
+       (
+       sCAN_CARD *card           /* Pointer to card structure */
+       );
+
+
+/*******************************************************************************
+* cl2_reset_card - reset card
+* """"""""""""""
+*
+* Card pointed by *card gets hardware reset. This command resets
+* card processor, card settings are restored to their default
+* values.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_reset_card
+   (
+   sCAN_CARD *card             /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_get_version - read card version
+* """""""""""""""
+*
+* Fucntion reads a value from card version register.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_get_version
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 *version                /* returns card version */
+   );
+
+
+/*******************************************************************************
+* cl2_get_ID - read card ID
+* """""""""""""""
+*
+* Fucntion reads a value from card ID register.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_get_ID
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U32 *IDlow,
+   U32 *IDhigh                         /* returns card version */
+   );
+
+
+/*******************************************************************************
+* cl2_gen_interrupt - request for interrupt
+* """""""""""""""""
+*
+* CAN card is requested to generate interrupt if there is any reason
+* to do it. The condition for interrupt generation is defined by
+* cl2_int_mode command.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_gen_interrupt
+   (
+   sCAN_CARD *card           /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_start_it - start inhibit time
+* """"""""""""
+*
+* Command starts interrupt inhibit time. If there is any reason for
+* interrupt geneation, the card generates interrupt after end of
+* specified time interval. Time interval is set by cl2_set_iit command.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_start_it
+   (
+   sCAN_CARD *card           /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_clear_interrupt - clear interrupt
+* """""""""""""""""""
+*
+* Comand clears interrupt (IRQ) generated by a card.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_clear_interrupt
+   (
+   sCAN_CARD *card          /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_int_mode - set interrupt mode
+* """"""""""""
+*
+* Command controls, which event will generate interrupt. Constants
+* CL2_INT_XXXX are used for setting of interrupt mode.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_BAD_PARAM - bad command parameter
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_int_mode
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 mode                    /* Interrupt mode */
+   );
+
+
+/*******************************************************************************
+* cl2_iit_mode - inhibit interrupt time mode
+* """"""""""""
+*
+* Command enables/disables inhibit interupt time mode.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_iit_mode
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   BOOLEAN1 onoff              /* IIT mode - TRUE=on, FALSE=off */
+   );
+
+
+/*******************************************************************************
+* cl2_sync_mode - sync mode
+* """""""""""""
+*
+* Command enables/disables transmission of SYNC frames.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_sync_mode
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   BOOLEAN1 onoff              /* Sync mode - TRUE=on, FALSE=off */
+   );
+
+
+/*******************************************************************************
+* cl2_rtr_mode - rtr mode
+* """"""""""""
+*
+* Command enables/disables automatic transmission of RTR frames
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_rtr_mode
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   BOOLEAN1 onoff              /* RTR mode - TRUE=on, FALSE=off */
+   );
+
+
+/*******************************************************************************
+* cl2_buf_size - size of synchronous queue
+* """"""""""""
+*
+* Command sets the size of synchronous send buffer. The size is
+* in numbers of messages. Default buffer size is 32 messages.
+* The sum of synchronous_buffer_size and asynchronous_buffer_size
+* is constant and equal to 64. So, if the size od synchronous
+* buffer increases, the size of asynchronous buffer decreases and
+* vice versa.
+* NOTE: 1 message = 16 bytes
+*
+* RETURNS:
+*   CL2_OK - command completed successfully
+*   CL2_COMMAND_BUSY - previous command not completed
+*   CL2_BAD_PARAM - bad command parameter (bufSize>64)
+*
+*/
+eCL2_RESULT cl2_buf_size
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 bufSize                 /* Size of synchronous buffer */
+   );
+
+
+/*******************************************************************************
+* cl2_set_iit - set value of inhibit interrupt time
+* """""""""""
+*
+* Command sets value of inhibit interrupt time. If inhibit
+* interrupt time mode is enabled and started, generation of
+* interrupt (IRQ) is disabled during this time period.
+* Inhibit interrupt time can be set from 100 us to 6.5535 s
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_iit
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 iit                     /* time period in x100 us */
+   );
+
+
+/*******************************************************************************
+* cl2_start_firmware - start firmware
+* """"""""""""""""""
+*
+* Command starts card firmware
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_start_firmware
+   (
+   sCAN_CARD *card             /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_set_rec_mode - set receive mode
+* """"""""""""""""
+*
+* Command sets card receive mode. This enable reception of standard
+* or extended frames according to CAN 2.0A and 2.0B specifications.
+* If value of mode is TRUE, card receives extended frames, if mode
+* is FALSE, card receives standard massage format (default).
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_rec_mode
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   BOOLEAN1 mode              /* Mode - TRUE=ext, FALSE=std */
+   );
+
+
+/*******************************************************************************
+* cl2_clr_rx_buffer - clear RX buffer
+* """""""""""""""""
+*
+* Command clears receive (rx) buffer. All messages stored in
+* rx buffer will be lost.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_clr_rx_buffer
+   (
+   sCAN_CARD *card            /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_clr_sync_buffer - clear synchronous buffer
+* """""""""""""""""""
+*
+* Command clears synchronous send buffer. All messages stored
+* in synchronous buffer will be lost.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_clr_sync_buffer
+   (
+   sCAN_CARD *card             /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_clr_async_buffer - clear asynchronous buffer
+* """"""""""""""""""""
+*
+* Command clears asynchronnous send buffer. All messages stored
+* in async buffer will be lost.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_clr_async_buffer
+   (
+   sCAN_CARD *card            /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_send_time_sync - send time synchronization
+* """"""""""""""""""
+*
+* Command forces the card to start the High Resolution Synchronization
+* Protocol according to the CANopen Communication profile. The SYNC
+* mode has to be enabled (cl2_sync_mode) otherwise this command has
+* no effect.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_send_time_sync
+   (
+   sCAN_CARD *card             /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_set_time_cobid - set time COB-ID
+* """"""""""""""""""
+*
+* Command sets the COB-ID for high resolution synchronization
+* frame. The synchronization can be then made by means of
+* cl2_send_time_sync command.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_time_cobid
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   U32 COBID                  /* HRS frame COB-ID */
+   );
+
+
+/*******************************************************************************
+* cl2_set_receive_limit - set limit for receive signaling
+* """""""""""""""""""""
+*
+* Command is used to set the receive limit signalized by bit
+* RL (in CL2.H CL2_X_DATA_IN_RBUF) of the Status Register.
+* This bit is set when more then the limit number of frames
+* was received since the last interrupt was generated (in interrupt
+* mode) or since the Status Register was last time read.
+*
+* RETURNS:
+*   CL2_OK
+*   CL2_COMMAND_BUSY - previous command not completed
+*   CL2_BAD_PARAM - bad command parameter
+*/
+eCL2_RESULT cl2_set_receive_limit
+   (
+   sCAN_CARD *card,          /* pointer to card structure */
+   U16 limit                 /* limit of messages in receive buffer */
+   );
+
+
+/*******************************************************************************
+* cl2_download_rtr_list - download rtr list
+* """""""""""""""""""""
+*
+* Command downloads a list of up to 64 RTR frames. These frames are
+* periodically transmitted by the card. The parameters, how often
+* frames are send and in which SYNC period is defined by period and
+* subperiod in sRTR_FRAME structure.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*   CL2_BAD_PARAM - bad command parameter
+*
+*/
+eCL2_RESULT cl2_download_rtr_list
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   sRTR_LIST *rtrList         /* RTR list */
+   );
+
+
+/*******************************************************************************
+* cl2_subscribe_rtr - subscribe RTR frame
+* """""""""""""""""
+*
+* Command subscribes RTR frame. Incoming RTR frames which were
+* subscribed are accepted, while other are ignored. Up to 10
+* RTR frames can be subscribed.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*   CL2_BAD_PARAM - bad command parameter
+*
+*/
+eCL2_RESULT cl2_subscribe_rtr
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   sCAN_MESSAGE *canMessage,   /* RTR frame */
+   U16 RTRnumber               /* number of RTR */
+   );
+
+
+/*******************************************************************************
+* cl2_desubscribe_rtr - desubscribe rtr frame
+* """""""""""""""""""
+*
+* Command desubscribes RTR frame. Card will not accept RTR frames
+* with this identifier.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*   CL2_BAD_PARAM - bad command parameter
+*
+*/
+eCL2_RESULT cl2_desubscribe_rtr
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   sCAN_MESSAGE *canMessage    /* RTR frame */
+   );
+
+
+/*******************************************************************************
+* cl2_set_sync_cobid - set COB-ID
+* """"""""""""""""""
+*
+* Command sets COB-ID of SYNC frame. In active SYNC mode, the SYNC
+* frame with this COB-ID is periodically sent with period defined
+* by cl2_set_sync_period command.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_sync_cobid
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U32 COBID                   /* COB-ID */
+   );
+
+
+/*******************************************************************************
+* cl2_set_sync_period - set SYNC period
+* """""""""""""""""""
+*
+* Coomand sets the SYNC frame send period in active SYNC mode in
+* x100 us. The period range is from 0 to 0xFFFF (SYNC period can
+* be set from 100us to 6.5535s).
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_sync_period
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 period                  /* period in x100 us */
+   );
+
+
+/*******************************************************************************
+* cl2_set_sync_window - set SYNC window
+* """""""""""""""""""
+*
+* Command sets the SYNC window length. Only during this time period
+* after SYNC frame was send or receive the frames from the synchronous
+* send buffer can be sent.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_sync_window
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 window                  /* period in x100 us */
+   );
+
+
+/*******************************************************************************
+* cl2_set_bitrate - set CAN bit-rate
+* """""""""""""""
+*
+* Command switches the bus bit-rate. There are some predefined
+* constants CL2_BITRATE_XXXX.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previous command not completed
+*
+*/
+eCL2_RESULT cl2_set_bitrate
+   (
+   sCAN_CARD *card,            /* Pointer to card structure */
+   U16 bitrate                 /* CAN bitrate */
+   );
+
+
+/*******************************************************************************
+* cl2_bus_reset - resets CAN controller
+* """""""""""""
+*
+* Command resets CAN controller
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_COMMAND_BUSY - previously command not completed
+*
+*/
+eCL2_RESULT cl2_bus_reset
+   (
+   sCAN_CARD *card            /* Pointer to card structure */
+   );
+
+
+/*******************************************************************************
+* cl2_send_sync - sends synchronous frame
+* """""""""""""
+*
+* Command stores massage in synchronous send buffer.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_HW_QUEUE_FULL - synchronous send buffer is full
+*   CL2_BAD_PARAM - bad command parameter
+*   CL2_HW_FAILURE - error in HW configuration
+*
+*/
+eCL2_RESULT cl2_send_sync
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   sCAN_MESSAGE *message      /* message to be sent */
+   );
+
+
+/*******************************************************************************
+* cl2_send_async - sends asynchronous frame
+* """"""""""""""
+*
+* Command stores message in asynchronous send buffer.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_HW_QUEUE_FULL - asynchronous buffer full
+*   CL2_HW_FAILURE - error in HW configuration
+*   CL2_BAD_PARAM - bad command parameter
+*
+*/
+eCL2_RESULT cl2_send_async
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   sCAN_MESSAGE *message      /* message */
+   );
+
+
+/*******************************************************************************
+* cl2_get_status - reads card status
+* """"""""""""""
+*
+* Command reads card status register. If data in status register
+* are valid (status valid flag is set), the value of status is read
+* and stored in status and sCAN_CARD structure.
+*
+* RETURNS:
+*   CL2_OK - command completed successfuly
+*   CL2_NO_REQUEST - status is not valid
+*
+*/
+eCL2_RESULT cl2_get_status
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   U16 *status                /* Returned status */
+   );
+
+
+/*******************************************************************************
+* cl2_get_error - reads card error
+* """""""""""""
+*
+* Command reads card error register. If data in error register
+* are valid (error register valid flag is set), the value of error
+* register is read and stored in error and sCAN_CARD structure.
+*
+* RETURNS:
+*   Cl2_OK - command completed successfuly
+*
+*/
+eCL2_RESULT cl2_get_error
+   (
+   sCAN_CARD *card,           /* Pointer to card structure */
+   U16 *error                 /* Returned card error code */
+   );
+
+
+/*******************************************************************************
+* cl2_receive_data - reads received frame
+* """"""""""""""""
+*
+* Command reads new messages received by a card.
+*
+* RETURNS:
+*   CL2_OK - command commpleted successfuly
+*   CL2_NO_REQUEST - there is no new message
+*
+*/
+eCL2_RESULT cl2_receive_data
+   (
+   sCAN_CARD *card,             /* Pointer to card structure */
+   sCAN_MESSAGE *canMessage     /* Message */
+   );
+
+
+/* *********************************************************************** *
+ * END OF CL2.H                                                            *
+ * *********************************************************************** */
+
+#endif /* ifndef __INC_CL2_H */
index e736d3d..2ed2632 100644 (file)
@@ -1,21 +1,35 @@
-default_CONFIG = CONFIG_OC_LINCAN=y CONFIG_OC_LINCANRTL=y
+lincan_cards_NAMES = pip pccan smartcan nsi cc_can104 \
+               pc_i03 pcm3680 aim104 m437 pcccan ssv \
+               bfadcan pikronisa kv_pcican msmcan unican virtual template
+
+default_CONFIG = CONFIG_OC_LINCAN=y CONFIG_OC_LINCANRTL=n
+default_CONFIG += CONFIG_OC_LINCAN_PORTIO_ONLY=n CONFIG_OC_LINCAN_MEMIO_ONLY=n
+default_CONFIG += $(foreach n, $(lincan_cards_NAMES), CONFIG_OC_LINCAN_CARD_$(n)=y)
+
+
+lincan_cards_SELECTED =        $(filter %.y, $(foreach x, $(lincan_cards_NAMES), $(x).$(CONFIG_OC_LINCAN_CARD_$(x))))
+lincan_cards_SELECTED := $(lincan_cards_SELECTED:%.y=%)
+
+
+LOCAL_CONFIG_H = lincan_config.h
 
 ifeq ($(CONFIG_OC_LINCAN),y)
 
-rtlinux_INCLUDES = -I $(srcdir)/../include
-kernel_INCLUDES = -I $(srcdir)/../include
+rtlinux_INCLUDES = -I $(srcdir)/../include -I .
+kernel_INCLUDES = -I $(srcdir)/../include -I .
 #kernel_INCLUDES += -DCAN_DEBUG
 kernel_INCLUDES += -DWITH_DEVFS_FS
 
+lincan_cards_SOURCES = $(lincan_cards_SELECTED:%=%.c)
+
+ifneq ($(CONFIG_OC_LINCANRTL),y)
+
 kernel_MODULES = lincan
 
-#rtlinux_MODULES = lincan
+else #CONFIG_OC_LINCANRTL
 
-lincan_cards_SOURCES = pip.c pccan.c smartcan.c nsi.c cc_can104.c \
-               pc_i03.c pcm3680.c aim104.c m437.c pcccan.c ssv.c \
-               bfadcan.c pikronisa.c kv_pcican.c msmcan.c virtual.c template.c
+rtlinux_MODULES = lincan
 
-ifeq ($(CONFIG_OC_LINCANRTL),y)
 rtlinux_INCLUDES +=  -DCAN_WITH_RTL
 lincan_rtl_SOURCES = open_rtl.c close_rtl.c read_rtl.c write_rtl.c ioctl_rtl.c
 endif #CONFIG_OC_LINCANRTL
index 3fde70a..0346c8a 100644 (file)
@@ -167,12 +167,12 @@ dep: make_this_module_dep
 
 install : install_this_module
 
-.supported_cards.h: Makefile
-       echo >.supported_cards.h
+lincan_config.h: Makefile
+       echo >lincan_config.h
        $(foreach card, $(SUPPORTED_CARDS), \
-         echo \#define ENABLE_CARD_$(card) 1 >>.supported_cards.h ;)
+         echo \#define CONFIG_OC_LINCAN_CARD_$(card) 1 >>lincan_config.h ;)
        
-make_this_module: .supported_cards.h
+make_this_module: lincan_config.h
        echo Linux kernel version $(KERNEL_VERSION)
        echo Linux kernel sources $(KERNEL_LOCATION)
        echo Module target $(obj-m)
@@ -187,7 +187,7 @@ install_this_module: make_this_module
 
 clean:
        rm -f $(M_OBJS) $(MX_OBJS) $(O_OBJS) $(OX_OBJS) $(obj-m) \
-             .*.o.flags .*.o.cmd .*.ko.cmd .depend .supported_cards.h *~ \
+             .*.o.flags .*.o.cmd .*.ko.cmd .depend lincan_config.h *~ \
              $(obj-m:%.o=%.mod.o) $(FINAL_MODULE_OBJS) ../$(FINAL_MODULE_OBJS)
 
 distclean: clean
index e452b3e..0f87484 100644 (file)
@@ -10,7 +10,7 @@
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
 
-#include "supported_cards.h"
+#include "lincan_config.h"
 
 extern int template_register(struct hwspecops_t *hwspecops);
 extern int pip5_register(struct hwspecops_t *hwspecops);
@@ -34,61 +34,61 @@ extern int msmcan_register(struct hwspecops_t *hwspecops);
 extern int virtual_register(struct hwspecops_t *hwspecops);
 
 const struct boardtype_t can_boardtypes[]={
-    #ifdef ENABLE_CARD_template
+    #ifdef CONFIG_OC_LINCAN_CARD_template
        {"template", template_register, 1},
     #endif
-    #ifdef ENABLE_CARD_template
+    #ifdef CONFIG_OC_LINCAN_CARD_template
        {"virtual", virtual_register, 0},
     #endif
-    #ifdef ENABLE_CARD_pip
+    #ifdef CONFIG_OC_LINCAN_CARD_pip
        {"pip5", pip5_register, 1},
        {"pip6", pip6_register, 1},
     #endif
-    #ifdef ENABLE_CARD_smartcan
+    #ifdef CONFIG_OC_LINCAN_CARD_smartcan
        {"smartcan", smartcan_register, 1},
     #endif
-    #ifdef ENABLE_CARD_nsi
+    #ifdef CONFIG_OC_LINCAN_CARD_nsi
        {"nsican", nsi_register, 1},
     #endif
-    #ifdef ENABLE_CARD_cc_can104
+    #ifdef CONFIG_OC_LINCAN_CARD_cc_can104
        {"cc104", cc104_register, 1},
     #endif
-    #ifdef ENABLE_CARD_aim104
+    #ifdef CONFIG_OC_LINCAN_CARD_aim104
        {"aim104", aim104_register, 1},
     #endif
-    #ifdef ENABLE_CARD_pc_i03
+    #ifdef CONFIG_OC_LINCAN_CARD_pc_i03
        {"pc-i03", pci03_register, 1},
     #endif
-    #ifdef ENABLE_CARD_pcm3680
+    #ifdef CONFIG_OC_LINCAN_CARD_pcm3680
        {"pcm3680", pcm3680_register, 2},
     #endif
-    #ifdef ENABLE_CARD_pccan
+    #ifdef CONFIG_OC_LINCAN_CARD_pccan
        {"pccan-f", pccanf_register, 1},
        {"pccan-s", pccanf_register, 1},
        {"pccan-d", pccand_register, 2},
        {"pccan-q", pccanq_register, 4},
     #endif
-    #if defined(ENABLE_CARD_kv_pcican)&&defined(CAN_ENABLE_PCI_SUPPORT)
+    #if defined(CONFIG_OC_LINCAN_CARD_kv_pcican)&&defined(CAN_ENABLE_PCI_SUPPORT)
        {"pcican-s", kv_pcican_register, 0},
        {"pcican-d", kv_pcican_register, 0},
        {"pcican-q", kv_pcican_register, 0},
     #endif
-    #ifdef ENABLE_CARD_m437
+    #ifdef CONFIG_OC_LINCAN_CARD_m437
        {"m437", m437_register, 1},
     #endif
-    #ifdef ENABLE_CARD_pcccan
+    #ifdef CONFIG_OC_LINCAN_CARD_pcccan
        {"pcccan", pcccan_register, 1},
     #endif
-    #ifdef ENABLE_CARD_ssv
+    #ifdef CONFIG_OC_LINCAN_CARD_ssv
        {"ssv", ssv_register, 2},
     #endif
-    #ifdef ENABLE_CARD_bfadcan
+    #ifdef CONFIG_OC_LINCAN_CARD_bfadcan
        {"bfadcan", bfadcan_register, 1},
     #endif
-    #ifdef ENABLE_CARD_pikronisa
+    #ifdef CONFIG_OC_LINCAN_CARD_pikronisa
        {"pikronisa", pikronisa_register, 1},
     #endif
-    #ifdef ENABLE_CARD_msmcan
+    #ifdef CONFIG_OC_LINCAN_CARD_msmcan
        {"msmcan", msmcan_register, 1},
     #endif
        {NULL}
diff --git a/lincan/src/supported_cards.h b/lincan/src/supported_cards.h
deleted file mode 100644 (file)
index f801c4a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-
-#define ENABLE_CARD_pip 1
-#define ENABLE_CARD_pccan 1
-#define ENABLE_CARD_smartcan 1
-#define ENABLE_CARD_nsi 1
-#define ENABLE_CARD_cc_can104 1
-#define ENABLE_CARD_pc_i03 1
-#define ENABLE_CARD_pcm3680 1
-#define ENABLE_CARD_aim104 1
-#define ENABLE_CARD_m437 1
-#define ENABLE_CARD_pcccan 1
-#define ENABLE_CARD_ssv 1
-#define ENABLE_CARD_bfadcan 1
-#define ENABLE_CARD_pikronisa 1
-#define ENABLE_CARD_msmcan 1
-#define ENABLE_CARD_kv_pcican 1
-#define ENABLE_CARD_virtual 1
-#define ENABLE_CARD_template 1
diff --git a/lincan/src/unican_cl2.c b/lincan/src/unican_cl2.c
new file mode 100644 (file)
index 0000000..18a78e9
--- /dev/null
@@ -0,0 +1,1279 @@
+/******************************************************************************\r
+\r
+Cl2.C - PCAN and VCAN cards hardware access library\r
+"""""\r
+                   (C) Copyright 1997   Unicontrols a.s.\r
+\r
+PROJEKT            :    CANopen\r
+AUTOR              :    F.Spurny\r
+FIRMA              :    CVUT FEL, Dept. of Measurement\r
+\r
+DULEZITE UPOZORNENI:\r
+\r
+ARCHIVACNI INFORMACE:\r
+$Log$
+Revision 1.1  2004/03/13 23:13:33  ppisa
+Interconnected OCERA configuration options with LinCAN boardlist.c compilation.
+\r
+\r
+12.12.2000, J.B., cl2_receive_data - time stamp for even number of bytes corr.\r
+26.8.1998 - cl2_buf_size - corrected, new function return code CL2_BAD_PARAM\r
+            cl2_clr_async_buffer - corrected\r
+\r
+===============================================================================\r
+\r
+UCEL A FUNKCE:\r
+\r
+******************************************************************************/\r
+\r
+/* Constnt used by CL2 functions */\r
+#define CL2_TMP_RF                0x0800\r
+#define CL2_TMP_EX                0x0400\r
+#define CL2_TMP_EX2               0x0004\r
+#define CL2_TMP_EXHIGH            0x80000000L\r
+\r
+\r
+/* includes */\r
+#include "anctypes.h"\r
+#include "cl2.h"\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_init_card - initialize card to default parameters\r
+* """""""""""""\r
+*\r
+* Command installs card. The data in sCAN_CARD structure pointed\r
+* by *card are initialized to their predefined default values.\r
+* Command must be called before any operation with sCAN_CARD\r
+* structure.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed succesfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_init_card\r
+   (\r
+   sCAN_CARD *card,     /* Pointer to card structure */\r
+   void *baseAddress,   /* Card base address pointer */\r
+   U16 intNumber        /* Card interrupt number */\r
+   )\r
+   {\r
+   int i;\r
+\r
+   card->intNumber = intNumber;\r
+   card->baseAddressPtr = (U8*)baseAddress;\r
+   card->rxBufBase = card->baseAddressPtr + CL2_RX_BUFFER_DEFAULT;\r
+   card->asyncTxBufBase = card->baseAddressPtr + CL2_ASYNC_BUFFER_DEFAULT;\r
+   card->syncTxBufBase = card->baseAddressPtr + CL2_SYNC_BUFFER_DEFAULT;\r
+   card->rxBufPtr = card->rxBufBase;\r
+   card->asyncTxBufPtr = card->asyncTxBufBase;\r
+   card->syncTxBufPtr = card->syncTxBufBase;\r
+   card->commandRegister = card->baseAddressPtr+CL2_COMMAND_REGISTER;\r
+   card->dataPtr = card->baseAddressPtr + CL2_DATA_BUFFER;\r
+   card->rxBufSize = CL2_RX_BUFFER_SIZE;\r
+   card->syncTxBufSize = CL2_TX_SYNC_BUFFER_SIZE;\r
+   card->asyncTxBufSize = CL2_TX_ASYNC_BUFFER_SIZE;\r
+   card->status = 0;\r
+   for ( i = 0; i < 10; i++ ) card->rtrSub[i] = 0xFFFFFFFFL;\r
+   return CL2_OK;\r
+   } /* cl2_init_card */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_test_card - test card\r
+* """""""""""""\r
+*\r
+* Test whether the card is installed in system and working properly\r
+* or not. If this function fails (return value is CL2_HW_FAILURE)\r
+* check if the card is present and card base address.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - card is present and working properly\r
+*   CL2_HW_FAILURE - card not found or card error\r
+*\r
+*/\r
+eCL2_RESULT cl2_test_card\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   BOOLEAN1 isAA = FALSE, is55 = FALSE;\r
+   int i;\r
+   U16 volatile tmpWord;\r
+\r
+   /* timeout for card testing - 1000 read cycles */\r
+   for ( i = 0; i < 10000; i++ )\r
+   {\r
+     if ( isAA && is55 ) return CL2_OK;\r
+     tmpWord = *((U16*)(card->baseAddressPtr));\r
+     if ( (tmpWord & 0x00FF) == 0x00AA ) isAA = TRUE;\r
+     if ( (tmpWord & 0x00FF) == 0x0055 ) is55 = TRUE;\r
+   }\r
+\r
+  return CL2_HW_FAILURE;\r
+   } /* cl2_test_card */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_reset_card - reset card\r
+* """"""""""""""\r
+*\r
+* Card pointed by *card gets hardware reset. This command resets\r
+* card processor, card settings are restored to their default\r
+* values.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_reset_card\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   *((U16*)(card->baseAddressPtr + CL2_RESET_REGISTER)) = 0x0000;\r
+   return CL2_OK;\r
+   } /* cl2_reset_card */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_get_version - read card version\r
+* """""""""""""""\r
+*\r
+* Fucntion reads a value from card version register.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_get_version\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 *version                /* returns card version */\r
+   )\r
+   {\r
+   *version = *((U16*)(card->baseAddressPtr + CL2_VERSION_REGISTER));\r
+   return CL2_OK;\r
+   } /* cl2_get_version */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_gen_interrupt - request for interrupt\r
+* """""""""""""""""\r
+*\r
+* CAN card is requested to generate interrupt if there is any reason\r
+* to do it. The condition for interrupt generation is defined by\r
+* cl2_int_mode command.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_gen_interrupt\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   *((U16*)(card->baseAddressPtr + CL2_GEN_INT_REGISTER)) = 0x0000;\r
+   return CL2_OK;\r
+   } /* cl2_gen_interrupt */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_start_it - start inhibit time\r
+* """"""""""""\r
+*\r
+* Command starts interrupt inhibit time. If there is any reason for\r
+* interrupt geneation, the card generates interrupt after end of\r
+* specified time interval. Time interval is set by cl2_set_iit command.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_start_it\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   *((U16*)(card->baseAddressPtr + CL2_START_IT_REGISTER)) = 0x0000;\r
+   return CL2_OK;\r
+   } /* cl2_start_it */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_clear_interrupt - clear interrupt\r
+* """""""""""""""""""\r
+*\r
+* Comand clears interrupt (IRQ) generated by a card.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_clear_interrupt\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   *((U16*)(card->baseAddressPtr + CL2_CLEAR_INT_REGISTER)) = 0x0000;\r
+   return CL2_OK;\r
+   } /* cl2_clear_interrupt */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_int_mode - set interrupt mode\r
+* """"""""""""\r
+*\r
+* Command controls, which event will generate interrupt. Constants\r
+* CL2_INT_XXXX are used for setting of interrupt mode.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_int_mode\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 mode                    /* Interrupt mode */\r
+   )\r
+   {\r
+   if ( mode > INT_MODE_ALL ) return CL2_BAD_PARAM;\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = mode;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_INT_MODE + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_int_mode */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_iit_mode - inhibit interrupt time mode\r
+* """"""""""""\r
+*\r
+* Command enables/disables inhibit interupt time mode.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_iit_mode\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   BOOLEAN1 onoff              /* IIT mode - TRUE=on, FALSE=off */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return\r
+      CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)onoff;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_IIT_MODE + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_iit_mode */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_sync_mode - sync mode\r
+* """""""""""""\r
+*\r
+* Command enables/disables transmission of SYNC frames.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_sync_mode\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   BOOLEAN1 onoff              /* Sync mode - TRUE=on, FALSE=off */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)onoff;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SYNC_MODE + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_sync_mode */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_rtr_mode - rtr mode\r
+* """"""""""""\r
+*\r
+* Command enables/disables automatic transmission of RTR frames\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_rtr_mode\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   BOOLEAN1 onoff              /* RTR mode - TRUE=on, FALSE=off */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)onoff;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_RTR_MODE + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_rtr_mode */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_buf_size - size of synchronous queue\r
+* """"""""""""\r
+*\r
+* Command sets the size of synchronous send buffer. The size is\r
+* in numbers of messages. Default buffer size is 32 messages.\r
+* The sum of synchronous_buffer_size and asynchronous_buffer_size\r
+* is constant and equal to 64. So, if the size od synchronous\r
+* buffer increases, the size of asynchronous buffer decreases and\r
+* vice versa.\r
+* NOTE: 1 message = 16 bytes\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfully\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*   CL2_BAD_PARAM - bad command parameter (bufSize>64)\r
+*\r
+*/\r
+eCL2_RESULT cl2_buf_size\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 bufSize                 /* Size of synchronous buffer */\r
+   )\r
+   {\r
+   if ( bufSize > 64 ) return CL2_BAD_PARAM;\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = bufSize;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_BUF_SIZE + CL2_COMMAND_VALID);\r
+   card->syncTxBufSize = bufSize;\r
+   card->asyncTxBufSize = 64 - bufSize;\r
+   card->syncTxBufPtr = card->syncTxBufBase;\r
+   card->asyncTxBufPtr = card->asyncTxBufBase = card->syncTxBufBase+bufSize*16;\r
+   return CL2_OK;\r
+   } /* cl2_buf_size */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_iit - set value of inhibit interrupt time\r
+* """""""""""\r
+*\r
+* Command sets value of inhibit interrupt time. If inhibit\r
+* interrupt time mode is enabled and started, generation of\r
+* interrupt (IRQ) is disabled during this time period.\r
+* Inhibit interrupt time can be set from 100 us to 6.5535 s\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_iit\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 iit                     /* time period in x100 us */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = iit;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_IIT + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_iit */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_start_firmware - start firmware\r
+* """"""""""""""""""\r
+*\r
+* Command starts card firmware\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_start_firmware\r
+   (\r
+   sCAN_CARD *card            /* Pointer to card structure */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_START_FIRMWARE +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_start_firmware */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_rec_mode - set receive mode\r
+* """"""""""""""""\r
+*\r
+* Command sets card receive mode. This enable reception of standard\r
+* or extended frames according to CAN 2.0A and 2.0B specifications.\r
+* If value of mode is TRUE, card receives extended frames, if mode\r
+* is FALSE, card receives standard massage format (default).\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_rec_mode\r
+   (\r
+   sCAN_CARD *card,           /* Pointer to card structure */\r
+   BOOLEAN1 mode              /* Mode - TRUE=ext, FALSE=std */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)mode;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_REC_MODE +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_rec_mode */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_clr_rx_buffer - clear RX buffer\r
+* """""""""""""""""\r
+*\r
+* Command clears receive (rx) buffer. All messages stored in\r
+* rx buffer will be lost.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_clr_rx_buffer\r
+   (\r
+   sCAN_CARD *card           /* Pointer to card structure */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   card->rxBufPtr = card->rxBufBase;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_RX_BUFFER +\r
+                                     CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_clr_rx_buffer */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_clr_sync_buffer - clear synchronous buffer\r
+* """""""""""""""""""\r
+*\r
+* Command clears synchronous send buffer. All messages stored\r
+* in synchronous buffer will be lost.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_clr_sync_buffer\r
+   (\r
+   sCAN_CARD *card            /* Pointer to card structure */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   card->syncTxBufPtr = card->syncTxBufBase;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_SYNC_BUFFER +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_clr_sync_buffer */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_clr_async_buffer - clear asynchronous buffer\r
+* """"""""""""""""""""\r
+*\r
+* Command clears asynchronnous send buffer. All messages stored\r
+* in async buffer will be lost.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_clr_async_buffer\r
+   (\r
+   sCAN_CARD *card            /* Pointer to card structure */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   card->asyncTxBufPtr = card->syncTxBufBase + card->syncTxBufSize*16;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_ASYNC_BUFFER +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_clr_async_buffer */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_send_time_sync - send time synchronization\r
+* """"""""""""""""""\r
+*\r
+* Command forces the card to start the High Resolution Synchronization\r
+* Protocol according to the CANopen Communication profile. The SYNC\r
+* mode has to be enabled (cl2_sync_mode) otherwise this command has\r
+* no effect.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_send_time_sync\r
+   (\r
+   sCAN_CARD *card             /* Pointer to card structure */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return\r
+      CL2_COMMAND_BUSY;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SEND_TIME_SYNC +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_send_time_sync */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_time_cobid - set time COB-ID\r
+* """"""""""""""""""\r
+*\r
+* Command sets the COB-ID for high resolution synchronization\r
+* frame. The synchronization can be then made by means of\r
+* cl2_send_time_sync command.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_time_cobid\r
+   (\r
+   sCAN_CARD *card,           /* Pointer to card structure */\r
+   U32 COBID                  /* HRS frame COB-ID */\r
+   )\r
+   {\r
+   U16 cobidL, cobidH;\r
+   U16 *ptr = (U16 *)card->dataPtr;\r
+\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+\r
+   if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */\r
+   { /* 2.0B frame */\r
+     COBID <<= 3;\r
+     cobidL = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = (U16)((COBID & 0xFFFF0000L)>>16);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptr++ = cobidH;\r
+     cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00));\r
+     *ptr++ = cobidL;\r
+     *ptr = CL2_TMP_EX2;\r
+   }\r
+   else\r
+   { /* 2.0A frame */\r
+     COBID <<= 5;\r
+     cobidH = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptr++ = cobidH;\r
+     *ptr++ = 0;\r
+     *ptr = 0;\r
+   }\r
+\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_TIME_COBID +\r
+                                     CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_time_cobid */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_receive_limit - set limit for receive signaling\r
+* """""""""""""""""""""\r
+*\r
+* Command is used to set the receive limit signalized by bit\r
+* RL (in CL2.H CL2_X_DATA_IN_RBUF) of the Status Register.\r
+* This bit is set when more then the limit number of frames\r
+* was received since the last interrupt was generated (in interrupt\r
+* mode) or since the Status Register was last time read.\r
+*\r
+* RETURNS:\r
+*   CL2_OK\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*/\r
+eCL2_RESULT cl2_set_receive_limit\r
+   (\r
+   sCAN_CARD *card,  /* pointer to card structure */\r
+   U16 limit         /* limit of messages in receive buffer */\r
+   )\r
+   {\r
+   if ( limit > 127 ) return CL2_BAD_PARAM;\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = limit;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_RECEIVE_LIMIT +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_receive_limit */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_download_rtr_list - download rtr list\r
+* """""""""""""""""""""\r
+*\r
+* Command downloads a list of up to 64 RTR frames. These frames are\r
+* periodically transmitted by the card. The parameters, how often\r
+* frames are send and in which SYNC period is defined by period and\r
+* subperiod in sRTR_FRAME structure.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*\r
+*/\r
+eCL2_RESULT cl2_download_rtr_list\r
+   (\r
+   sCAN_CARD *card,           /* Pointer to card structure */\r
+   sRTR_LIST *rtrList         /* RTR list */\r
+   )\r
+   {\r
+   U16 *ptrTmp = (U16*)card->dataPtr;\r
+   sRTR_FRAME *ptrRTR = rtrList->data;\r
+   U16 tmpU16;\r
+   U32 COBID;\r
+   U16 cobidH, cobidL, i;\r
+\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return\r
+      CL2_COMMAND_BUSY;\r
+   if ( rtrList->nb > 64 ) return CL2_BAD_PARAM;\r
+\r
+   *ptrTmp++ = (U16)rtrList->nb;\r
+   for ( i = 0; i < rtrList->nb; i++ )\r
+   {\r
+   if ( ptrRTR->period < ptrRTR->subperiod ) return CL2_BAD_PARAM;\r
+   if ( ptrRTR->subperiod == 0 ) ptrRTR->subperiod = 1;\r
+   tmpU16 = (ptrRTR->period & 0x00FF) + ((ptrRTR->subperiod & 0x00FF)<<8);\r
+   *ptrTmp++ = tmpU16;\r
+   COBID = ptrRTR->cob_id;\r
+\r
+   if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */\r
+   { /* 2.0B frame */\r
+     COBID <<= 3;\r
+     cobidL = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = (U16)((COBID & 0xFFFF0000L)>>16);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptrTmp++ = cobidH;\r
+     cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00));\r
+     *ptrTmp++ = cobidL;\r
+   }\r
+   else\r
+   { /* 2.0A frame */\r
+     COBID <<= 5;\r
+     cobidH = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptrTmp++ = cobidH;\r
+     *ptrTmp++ = 0;\r
+   }\r
+\r
+   *ptrTmp++ = 0x0000;  /* rezerva */\r
+   ptrRTR++;\r
+   }\r
+\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_DOWNLOAD_RTR_LIST +\r
+                                     CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_download_rtrlist */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_subscribe_rtr - subscribe RTR frame\r
+* """""""""""""""""\r
+*\r
+* Command subscribes RTR frame. Incoming RTR frames which were\r
+* subscribed are accepted, while other are ignored. Up to 10\r
+* RTR frames can be subscribed.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*\r
+*/\r
+eCL2_RESULT cl2_subscribe_rtr\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   sCAN_MESSAGE *canMessage,   /* RTR frame */\r
+   U16 RTRnumber               /* number of RTR */\r
+   )\r
+   {\r
+   U16 *ptrU16 = (U16*)card->dataPtr;\r
+   U32 COBID;\r
+   U16 cobidH, cobidL;\r
+\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   if ( RTRnumber > 9 ) return CL2_BAD_PARAM;\r
+\r
+   card->rtrSub[RTRnumber] = canMessage->COB_ID;\r
+   *ptrU16 = RTRnumber;\r
+   ptrU16++;\r
+   COBID = canMessage->COB_ID;\r
+\r
+   if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */\r
+   { /* 2.0B frame */\r
+     COBID <<= 3;\r
+     cobidL = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = (U16)((COBID & 0xFFFF0000L)>>16);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptrU16++ = cobidH;\r
+     cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00));\r
+     *ptrU16++ = cobidL;\r
+     *ptrU16 = (U16)CL2_EXT_FRAME;\r
+   }\r
+   else\r
+   { /* 2.0A frame */\r
+     COBID <<= 5;\r
+     cobidH = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptrU16++ = cobidH;\r
+     *ptrU16++ = 0;\r
+     *ptrU16 = 0;\r
+   }\r
+\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SUBSCRIBE_RTR +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_subscribe_rtr */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_desubscribe_rtr - desubscribe rtr frame\r
+* """""""""""""""""""\r
+*\r
+* Command desubscribes RTR frame. Card will not accept RTR frames\r
+* with this identifier.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*\r
+*/\r
+eCL2_RESULT cl2_desubscribe_rtr\r
+   (\r
+   sCAN_CARD *card,           /* Pointer to card structure */\r
+   sCAN_MESSAGE *canMessage   /* RTR frame */\r
+   )\r
+   {\r
+   U16 i;\r
+\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+\r
+   for ( i = 0; i < 10; i++ )\r
+   {\r
+     if ( card->rtrSub[i] == canMessage->COB_ID )\r
+     {\r
+       card->rtrSub[i] = 0xFFFFFFFFL;\r
+       break;\r
+     }\r
+   }\r
+\r
+   if ( i >= 10 ) return CL2_BAD_PARAM;\r
+\r
+   *((U16*)card->dataPtr) = i;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_DESUBSCRIBE_RTR +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_desubscribe_rtr */\r
+\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_sync_cobid - set COB-ID\r
+* """"""""""""""""""\r
+*\r
+* Command sets COB-ID of SYNC frame. In active SYNC mode, the SYNC\r
+* frame with this COB-ID is periodically sent with period defined\r
+* by cl2_set_sync_period command.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_sync_cobid\r
+   (\r
+   sCAN_CARD *card,           /* Pointer to card structure */\r
+   U32 COBID                  /* COB-ID */\r
+   )\r
+   {\r
+   U16 cobidL, cobidH;\r
+   U16 *ptr = (U16 *)card->dataPtr;\r
+\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+\r
+   if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */\r
+   { /* 2.0B frame */\r
+     COBID <<= 3;\r
+     cobidL = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = (U16)((COBID & 0xFFFF0000L)>>16);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptr++ = cobidH;\r
+     cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00));\r
+     *ptr++ = cobidL;\r
+     *ptr = CL2_TMP_EX2;\r
+   }\r
+   else\r
+   { /* 2.0A frame */\r
+     COBID <<= 5;\r
+     cobidH = (U16)(COBID & 0x0000FFFFL);\r
+     cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00));\r
+     *ptr++ = cobidH;\r
+     *ptr++ = 0;\r
+     *ptr = 0;\r
+   }\r
+\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_COBID + CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_sync_cobid */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_sync_period - set SYNC period\r
+* """""""""""""""""""\r
+*\r
+* Coomand sets the SYNC frame send period in active SYNC mode in\r
+* x100 us. The period range is from 0 to 0xFFFF (SYNC period can\r
+* be set from 100us to 6.5535s).\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_sync_period\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 period                  /* period in x100 us */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)period;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_SYNC_PERIOD +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_sync_period */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_sync_window - set SYNC window\r
+* """""""""""""""""""\r
+*\r
+* Command sets the SYNC window length. Only during this time period\r
+* after SYNC frame was send or receive the frames from the synchronous\r
+* send buffer can be sent.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_sync_window\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 window                  /* period in x100 us */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = (U16)window;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_SYNC_WINDOW +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_sync_window */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_set_bitrate - set CAN bit-rate\r
+* """""""""""""""\r
+*\r
+* Command switches the bus bit-rate. There are some predefined\r
+* constants CL2_BITRATE_XXXX.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previous command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_set_bitrate\r
+   (\r
+   sCAN_CARD *card,            /* Pointer to card structure */\r
+   U16 bitrate                 /* CAN bitrate */\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->dataPtr) = bitrate;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_SET_BITRATE +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_set_bitrate */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_bus_reset - resets CAN controller\r
+* """""""""""""\r
+*\r
+* Command resets CAN controller\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_COMMAND_BUSY - previously command not completed\r
+*\r
+*/\r
+eCL2_RESULT cl2_bus_reset\r
+   (\r
+   sCAN_CARD *card\r
+   )\r
+   {\r
+   if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID )\r
+      return CL2_COMMAND_BUSY;\r
+   *((U16*)card->commandRegister) = ((U16)cmCL2_BUS_RESET +\r
+                                    CL2_COMMAND_VALID);\r
+   return CL2_OK;\r
+   } /* cl2_bus_reset */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_send_sync - sends synchronous frame\r
+* """""""""""""\r
+*\r
+* Command stores massage in synchronous send buffer.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_HW_QUEUE_FULL - synchronous send buffer is full\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*   CL2_HW_FAILURE - error in HW configuration\r
+*\r
+*/\r
+eCL2_RESULT cl2_send_sync\r
+   (\r
+   sCAN_CARD *card,           /* pointer to card */\r
+   sCAN_MESSAGE *message      /* massage to be sent */\r
+   )\r
+   {\r
+   U32 cobid;\r
+   U16 cobidL,cobidH;\r
+   U16 *ptrU16 = (U16*)card->syncTxBufPtr;\r
+   U16 tmpU16;\r
+   int i;\r
+   int timeStamp = 0;\r
+\r
+   if ( card->syncTxBufSize==0 ) return CL2_HW_FAILURE;\r
+   if ( message->dataLength > 8 ) return CL2_BAD_PARAM;\r
+   if ( *ptrU16 & CL2_FRAME_VALID ) return CL2_HW_QUEUE_FULL;\r
+\r
+   cobid = message->COB_ID;\r
+   if ( (message->dataType & CL2_EXT_FRAME) || (cobid & CL2_TMP_EXHIGH) )\r
+   {  /* 2.0B frame */\r
+     cobid <<= 3;\r
+     cobidL = (U16)(cobid & 0x0000FFFFL);\r
+     cobidH = (U16)((cobid & 0xFFFF0000L)>>16);\r
+   }\r
+   else\r
+   {  /* 2.0A frame */\r
+     cobid <<= 5;\r
+     cobidL = 0;\r
+     cobidH = (U16)(cobid & 0x0000FFFFL);\r
+   }\r
+   ptrU16++;\r
+   tmpU16 = (cobidH & 0x00FF) + (cobidL & 0xFF00);\r
+   *ptrU16++ = tmpU16;\r
+\r
+   tmpU16 = (((U16)message->dataLength) << 12) + (cobidL & 0x00FF);\r
+   if ( !(message->dataType & CL2_REMOTE_FRAME) ) tmpU16 |= CL2_TMP_RF;\r
+   if ( (message->dataType & CL2_EXT_FRAME) ||\r
+        (message->COB_ID & CL2_TMP_EXHIGH) )\r
+     tmpU16 |= CL2_TMP_EX;\r
+   *ptrU16++ = tmpU16;\r
+\r
+   for ( i = 0; i < message->dataLength; )\r
+      {\r
+      tmpU16 = (U16)message->data[i]; i++;\r
+      if ( i == message->dataLength )\r
+         {\r
+         timeStamp = 1;\r
+         tmpU16 |= ((message->timeStamp & 0x00FF)<<8);\r
+         *ptrU16++ = tmpU16;\r
+         }\r
+      else\r
+         {\r
+         tmpU16 |= ((U16)message->data[i]<<8); i++;\r
+         *ptrU16++ = tmpU16;\r
+         }\r
+      }\r
+   if ( timeStamp )\r
+      {\r
+      tmpU16 = (message->timeStamp>>8) & 0x00FF;\r
+      *ptrU16 = tmpU16;\r
+      }\r
+   else\r
+      {\r
+      *ptrU16 = message->timeStamp;\r
+      }\r
+\r
+   tmpU16 = (((U16)cobidH) & 0xFF00) | CL2_MESSAGE_VALID;\r
+   *(U16*)card->syncTxBufPtr = tmpU16;\r
+\r
+   if ( (card->syncTxBufBase + card->syncTxBufSize*16) <=\r
+        (card->syncTxBufPtr += 16) )\r
+     {\r
+     card->syncTxBufPtr = card->syncTxBufBase;\r
+     }\r
+   return CL2_OK;\r
+   } /* cl2_send_sync */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_send_async - sends asynchronous frame\r
+* """"""""""""""\r
+*\r
+* Command stores message in asynchronous send buffer.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_HW_QUEUE_FULL - asynchronous buffer full\r
+*   CL2_HW_FAILURE - error in HW configuration\r
+*   CL2_BAD_PARAM - bad command parameter\r
+*\r
+*/\r
+eCL2_RESULT cl2_send_async\r
+   (\r
+   sCAN_CARD *card,           /* pointer to card */\r
+   sCAN_MESSAGE *message      /* message to be sent */\r
+   )\r
+   {\r
+   U32 cobid;\r
+   U16 cobidL,cobidH;\r
+   U16 *ptrU16 = (U16*)card->asyncTxBufPtr;\r
+   U16 tmpU16;\r
+   int i;\r
+   int timeStamp = 0;\r
+\r
+   if ( card->asyncTxBufSize==0 ) return CL2_HW_FAILURE;\r
+   if ( message->dataLength > 8 ) return CL2_BAD_PARAM;\r
+   if ( *ptrU16 & CL2_FRAME_VALID ) return CL2_HW_QUEUE_FULL;\r
+\r
+   cobid = message->COB_ID;\r
+   if ( (message->dataType & CL2_EXT_FRAME) || (cobid & CL2_TMP_EXHIGH) )\r
+   {  /* 2.0B frame */\r
+     cobid <<= 3;\r
+     cobidL = (U16)(cobid & 0x0000FFFFL);\r
+     cobidH = (U16)((cobid & 0xFFFF0000L)>>16);\r
+   }\r
+   else\r
+   {  /* 2.0A frame */\r
+     cobid <<= 5;\r
+     cobidL = 0;\r
+     cobidH = (U16)(cobid & 0x0000FFFFL);\r
+   }\r
+   ptrU16++;\r
+   tmpU16 = (cobidH & 0x00FF ) + (cobidL & 0xFF00);\r
+   *ptrU16++ = tmpU16;\r
+\r
+   tmpU16 = (((U16)message->dataLength) << 12) + (cobidL & 0x00FF);\r
+   if ( !(message->dataType & CL2_REMOTE_FRAME) ) tmpU16 |= CL2_TMP_RF;\r
+   if ( (message->dataType & CL2_EXT_FRAME) ||\r
+        (message->COB_ID & CL2_TMP_EXHIGH ) )\r
+      tmpU16 |= CL2_TMP_EX;\r
+   *ptrU16++ = tmpU16;\r
+\r
+   for ( i = 0; i < message->dataLength; )\r
+      {\r
+      tmpU16 = (U16)message->data[i]; i++;\r
+      if ( i == message->dataLength )\r
+         {\r
+         timeStamp = 1;\r
+         tmpU16 |= ((message->timeStamp & 0x00FF)<<8);\r
+         *ptrU16++ = tmpU16;\r
+         }\r
+      else\r
+         {\r
+         tmpU16 |= ((U16)message->data[i]<<8); i++;\r
+         *ptrU16++ = tmpU16;\r
+         }\r
+      }\r
+   if ( timeStamp )\r
+      {\r
+      tmpU16 = (message->timeStamp>>8) & 0x00FF;\r
+      *ptrU16 = tmpU16;\r
+      }\r
+   else\r
+      {\r
+      *ptrU16 = message->timeStamp;\r
+      }\r
+\r
+   tmpU16 = (((U16)cobidH) & 0xFF00) | CL2_MESSAGE_VALID;\r
+   *(U16*)card->asyncTxBufPtr = tmpU16;\r
+\r
+   if ( (card->asyncTxBufBase + card->asyncTxBufSize*16) <=\r
+        (card->asyncTxBufPtr += 16) )\r
+      {\r
+      card->asyncTxBufPtr = card->asyncTxBufBase;\r
+      }\r
+   return CL2_OK;\r
+   } /* cl2_send_async */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_get_status - reads card status\r
+* """"""""""""""\r
+*\r
+* Command reads card status register. If data in status register\r
+* are valid (status valid flag is set), the value of status is read\r
+* and stored in status and sCAN_CARD structure.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command completed successfuly\r
+*   CL2_NO_REQUEST - status is not valid\r
+*\r
+*/\r
+eCL2_RESULT cl2_get_status\r
+   (\r
+   sCAN_CARD *card,          /* pointer to card */\r
+   U16 *status               /* card status word */\r
+   )\r
+   {\r
+   U16 *ptr;\r
+\r
+   ptr = (U16*)(card->baseAddressPtr + CL2_STATUS_REGISTER);\r
+   *status = *ptr;\r
+   if ( (*status & CL2_STATUS_VALID_FLAG) )\r
+      {\r
+      *ptr = *status & ~CL2_STATUS_VALID_FLAG;\r
+      card->status = *status;\r
+      return CL2_OK;\r
+      }\r
+   return CL2_NO_REQUEST;\r
+   } /* cl2_get_status */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_get_error - reads card error\r
+* """""""""""""\r
+*\r
+* Command reads card error register. If data in error register\r
+* are valid (error register valid flag is set), the value of error\r
+* register is read and stored in error and sCAN_CARD structure.\r
+*\r
+* RETURNS:\r
+*   Cl2_OK - command completed successfuly\r
+*\r
+*/\r
+eCL2_RESULT cl2_get_error\r
+   (\r
+   sCAN_CARD *card,          /* pointer to card */\r
+   U16 *error                /* card error word */\r
+   )\r
+   {\r
+   U16 *ptr;\r
+\r
+   ptr = (U16*)(card->baseAddressPtr + CL2_ERROR_REGISTER);\r
+   *error = *ptr;\r
+   card->error |= *error;\r
+   *ptr = 0x0000;\r
+   return CL2_OK;\r
+   } /* cl2_get_error */\r
+\r
+\r
+/*******************************************************************************\r
+* cl2_receive_data - reads received frame\r
+* """"""""""""""""\r
+*\r
+* Command reads new messages received by a card.\r
+*\r
+* RETURNS:\r
+*   CL2_OK - command commpleted successfuly\r
+*   CL2_NO_REQUEST - there is no new message\r
+*\r
+*/\r
+eCL2_RESULT cl2_receive_data\r
+   (\r
+   sCAN_CARD *card,             /* Pointer to card structure */\r
+   sCAN_MESSAGE *canMessage     /* Message */\r
+   )\r
+   {\r
+   U16 *ptrU16 = (U16*)card->rxBufPtr;\r
+   U16 tmpU16;\r
+   U16 i;\r
+\r
+   tmpU16 = *ptrU16++;\r
+   if ( !(tmpU16 & CL2_MESSAGE_VALID) ) return CL2_NO_REQUEST;\r
+   canMessage->COB_ID = ((U32)(tmpU16 & 0xFF00 )) << 16;\r
+   tmpU16 = *ptrU16++;\r
+   canMessage->COB_ID |= ((U32)( tmpU16 & 0x00FF )) << 16;\r
+   canMessage->COB_ID |= (U32)( tmpU16 & 0xFF00 );\r
+   tmpU16 = *ptrU16++;\r
+   canMessage->COB_ID |= (U32)( tmpU16 & 0x00FF );\r
+   canMessage->dataType = (U8)(( tmpU16 & 0xFF00 ) >> 8);\r
+\r
+   if ( canMessage->dataType & CL2_EXT_FRAME )\r
+   {  /* 2.0B frame */\r
+     canMessage->COB_ID >>= 3;\r
+     /* canMessage->COB_ID |= CL2_TMP_EXHIGH; */\r
+   }\r
+   else\r
+   {  /* 2.0A frame */\r
+     canMessage->COB_ID >>= 21;\r
+   }\r
+   canMessage->dataLength = (U8)( (tmpU16 >> 12) & 0x000F );\r
+   /* if ( !(tmpU16 & CL2_TMP_RF) ) canMessage->dataType |= CL2_REMOTE_FRAME; */\r
+   for ( i = 0; i < canMessage->dataLength; )\r
+      {\r
+      tmpU16 = *ptrU16++;\r
+      canMessage->data[i++] = (U8)( tmpU16 );\r
+      canMessage->data[i++] = (U8)( tmpU16 >> 8 );\r
+      }\r
+   if ( canMessage->dataLength & 0x01 )\r
+      {  /* odd */\r
+      canMessage->timeStamp = ( (*ptrU16 & 0x00FF) | (tmpU16 & 0xFF00) );\r
+      }\r
+   else  /* even */\r
+      {\r
+      canMessage->timeStamp = *ptrU16 << 8 | *ptrU16 >> 8;\r
+      }\r
+   *(U16*)card->rxBufPtr = 0x0000;\r
+\r
+   /* increment rx-buffer pointer */\r
+   if ( (card->rxBufBase + card->rxBufSize*16 ) <= (card->rxBufPtr += 16) )\r
+      {\r
+      card->rxBufPtr = card->rxBufBase;\r
+      }\r
+\r
+   return CL2_OK;\r
+   } /* cl2_receive_data */\r
+\r
+\r
+/* **************************************************************** *\r
+ * END OF CL2.C                                                     *\r
+ * **************************************************************** */\r
+\r
+\r
index 8eeb02a..32409d7 100644 (file)
@@ -1,4 +1,4 @@
-default_CONFIG = CONFIG_OC_LINCAN=y CONFIG_OC_LINCANRTL=y
+default_CONFIG = CONFIG_OC_LINCAN=x CONFIG_OC_LINCANRTL=x
 
 ifeq ($(CONFIG_OC_LINCAN),y)