From 8efef967ff91e6d5b92426ffb091842d4e54145d Mon Sep 17 00:00:00 2001 From: ppisa Date: Sun, 14 Mar 2004 00:13:02 +0000 Subject: [PATCH] Interconnected OCERA configuration options with LinCAN boardlist.c compilation. --- lincan/include/unican_cl2.h | 949 +++++++++++++++++++++++++ lincan/src/Makefile.omk | 30 +- lincan/src/Makefile.std | 10 +- lincan/src/boardlist.c | 36 +- lincan/src/supported_cards.h | 18 - lincan/src/unican_cl2.c | 1279 ++++++++++++++++++++++++++++++++++ lincan/utils/Makefile.omk | 2 +- 7 files changed, 2274 insertions(+), 50 deletions(-) create mode 100644 lincan/include/unican_cl2.h delete mode 100644 lincan/src/supported_cards.h create mode 100644 lincan/src/unican_cl2.c diff --git a/lincan/include/unican_cl2.h b/lincan/include/unican_cl2.h new file mode 100644 index 0000000..ffd6bec --- /dev/null +++ b/lincan/include/unican_cl2.h @@ -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 */ +#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 */ diff --git a/lincan/src/Makefile.omk b/lincan/src/Makefile.omk index e736d3d..2ed2632 100644 --- a/lincan/src/Makefile.omk +++ b/lincan/src/Makefile.omk @@ -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 diff --git a/lincan/src/Makefile.std b/lincan/src/Makefile.std index 3fde70a..0346c8a 100644 --- a/lincan/src/Makefile.std +++ b/lincan/src/Makefile.std @@ -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 diff --git a/lincan/src/boardlist.c b/lincan/src/boardlist.c index e452b3e..0f87484 100644 --- a/lincan/src/boardlist.c +++ b/lincan/src/boardlist.c @@ -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 index f801c4a..0000000 --- a/lincan/src/supported_cards.h +++ /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 index 0000000..18a78e9 --- /dev/null +++ b/lincan/src/unican_cl2.c @@ -0,0 +1,1279 @@ +/****************************************************************************** + +Cl2.C - PCAN and VCAN cards hardware access library +""""" + (C) Copyright 1997 Unicontrols a.s. + +PROJEKT : CANopen +AUTOR : F.Spurny +FIRMA : CVUT FEL, Dept. of Measurement + +DULEZITE UPOZORNENI: + +ARCHIVACNI INFORMACE: +$Log$ +Revision 1.1 2004/03/13 23:13:33 ppisa +Interconnected OCERA configuration options with LinCAN boardlist.c compilation. + + +12.12.2000, J.B., cl2_receive_data - time stamp for even number of bytes corr. +26.8.1998 - cl2_buf_size - corrected, new function return code CL2_BAD_PARAM + cl2_clr_async_buffer - corrected + +=============================================================================== + +UCEL A FUNKCE: + +******************************************************************************/ + +/* Constnt used by CL2 functions */ +#define CL2_TMP_RF 0x0800 +#define CL2_TMP_EX 0x0400 +#define CL2_TMP_EX2 0x0004 +#define CL2_TMP_EXHIGH 0x80000000L + + +/* includes */ +#include "anctypes.h" +#include "cl2.h" + + +/******************************************************************************* +* 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 */ + ) + { + int i; + + card->intNumber = intNumber; + card->baseAddressPtr = (U8*)baseAddress; + card->rxBufBase = card->baseAddressPtr + CL2_RX_BUFFER_DEFAULT; + card->asyncTxBufBase = card->baseAddressPtr + CL2_ASYNC_BUFFER_DEFAULT; + card->syncTxBufBase = card->baseAddressPtr + CL2_SYNC_BUFFER_DEFAULT; + card->rxBufPtr = card->rxBufBase; + card->asyncTxBufPtr = card->asyncTxBufBase; + card->syncTxBufPtr = card->syncTxBufBase; + card->commandRegister = card->baseAddressPtr+CL2_COMMAND_REGISTER; + card->dataPtr = card->baseAddressPtr + CL2_DATA_BUFFER; + card->rxBufSize = CL2_RX_BUFFER_SIZE; + card->syncTxBufSize = CL2_TX_SYNC_BUFFER_SIZE; + card->asyncTxBufSize = CL2_TX_ASYNC_BUFFER_SIZE; + card->status = 0; + for ( i = 0; i < 10; i++ ) card->rtrSub[i] = 0xFFFFFFFFL; + return CL2_OK; + } /* cl2_init_card */ + + +/******************************************************************************* +* 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 */ + ) + { + BOOLEAN1 isAA = FALSE, is55 = FALSE; + int i; + U16 volatile tmpWord; + + /* timeout for card testing - 1000 read cycles */ + for ( i = 0; i < 10000; i++ ) + { + if ( isAA && is55 ) return CL2_OK; + tmpWord = *((U16*)(card->baseAddressPtr)); + if ( (tmpWord & 0x00FF) == 0x00AA ) isAA = TRUE; + if ( (tmpWord & 0x00FF) == 0x0055 ) is55 = TRUE; + } + + return CL2_HW_FAILURE; + } /* cl2_test_card */ + + +/******************************************************************************* +* 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 */ + ) + { + *((U16*)(card->baseAddressPtr + CL2_RESET_REGISTER)) = 0x0000; + return CL2_OK; + } /* cl2_reset_card */ + + +/******************************************************************************* +* 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 */ + ) + { + *version = *((U16*)(card->baseAddressPtr + CL2_VERSION_REGISTER)); + return CL2_OK; + } /* cl2_get_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 */ + ) + { + *((U16*)(card->baseAddressPtr + CL2_GEN_INT_REGISTER)) = 0x0000; + return CL2_OK; + } /* cl2_gen_interrupt */ + + +/******************************************************************************* +* 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 */ + ) + { + *((U16*)(card->baseAddressPtr + CL2_START_IT_REGISTER)) = 0x0000; + return CL2_OK; + } /* cl2_start_it */ + + +/******************************************************************************* +* 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 */ + ) + { + *((U16*)(card->baseAddressPtr + CL2_CLEAR_INT_REGISTER)) = 0x0000; + return CL2_OK; + } /* cl2_clear_interrupt */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( mode > INT_MODE_ALL ) return CL2_BAD_PARAM; + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = mode; + *((U16*)card->commandRegister) = ((U16)cmCL2_INT_MODE + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_int_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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return + CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)onoff; + *((U16*)card->commandRegister) = ((U16)cmCL2_IIT_MODE + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_iit_mode */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)onoff; + *((U16*)card->commandRegister) = ((U16)cmCL2_SYNC_MODE + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_sync_mode */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)onoff; + *((U16*)card->commandRegister) = ((U16)cmCL2_RTR_MODE + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_rtr_mode */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( bufSize > 64 ) return CL2_BAD_PARAM; + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = bufSize; + *((U16*)card->commandRegister) = ((U16)cmCL2_BUF_SIZE + CL2_COMMAND_VALID); + card->syncTxBufSize = bufSize; + card->asyncTxBufSize = 64 - bufSize; + card->syncTxBufPtr = card->syncTxBufBase; + card->asyncTxBufPtr = card->asyncTxBufBase = card->syncTxBufBase+bufSize*16; + return CL2_OK; + } /* cl2_buf_size */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = iit; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_IIT + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_iit */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->commandRegister) = ((U16)cmCL2_START_FIRMWARE + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_start_firmware */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)mode; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_REC_MODE + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_rec_mode */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + card->rxBufPtr = card->rxBufBase; + *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_RX_BUFFER + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_clr_rx_buffer */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + card->syncTxBufPtr = card->syncTxBufBase; + *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_SYNC_BUFFER + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_clr_sync_buffer */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + card->asyncTxBufPtr = card->syncTxBufBase + card->syncTxBufSize*16; + *((U16*)card->commandRegister) = ((U16)cmCL2_CLR_ASYNC_BUFFER + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_clr_async_buffer */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return + CL2_COMMAND_BUSY; + *((U16*)card->commandRegister) = ((U16)cmCL2_SEND_TIME_SYNC + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_send_time_sync */ + + +/******************************************************************************* +* 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 */ + ) + { + U16 cobidL, cobidH; + U16 *ptr = (U16 *)card->dataPtr; + + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + + if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */ + { /* 2.0B frame */ + COBID <<= 3; + cobidL = (U16)(COBID & 0x0000FFFFL); + cobidH = (U16)((COBID & 0xFFFF0000L)>>16); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptr++ = cobidH; + cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00)); + *ptr++ = cobidL; + *ptr = CL2_TMP_EX2; + } + else + { /* 2.0A frame */ + COBID <<= 5; + cobidH = (U16)(COBID & 0x0000FFFFL); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptr++ = cobidH; + *ptr++ = 0; + *ptr = 0; + } + + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_TIME_COBID + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_time_cobid */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( limit > 127 ) return CL2_BAD_PARAM; + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = limit; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_RECEIVE_LIMIT + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_receive_limit */ + + +/******************************************************************************* +* 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 */ + ) + { + U16 *ptrTmp = (U16*)card->dataPtr; + sRTR_FRAME *ptrRTR = rtrList->data; + U16 tmpU16; + U32 COBID; + U16 cobidH, cobidL, i; + + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) return + CL2_COMMAND_BUSY; + if ( rtrList->nb > 64 ) return CL2_BAD_PARAM; + + *ptrTmp++ = (U16)rtrList->nb; + for ( i = 0; i < rtrList->nb; i++ ) + { + if ( ptrRTR->period < ptrRTR->subperiod ) return CL2_BAD_PARAM; + if ( ptrRTR->subperiod == 0 ) ptrRTR->subperiod = 1; + tmpU16 = (ptrRTR->period & 0x00FF) + ((ptrRTR->subperiod & 0x00FF)<<8); + *ptrTmp++ = tmpU16; + COBID = ptrRTR->cob_id; + + if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */ + { /* 2.0B frame */ + COBID <<= 3; + cobidL = (U16)(COBID & 0x0000FFFFL); + cobidH = (U16)((COBID & 0xFFFF0000L)>>16); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptrTmp++ = cobidH; + cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00)); + *ptrTmp++ = cobidL; + } + else + { /* 2.0A frame */ + COBID <<= 5; + cobidH = (U16)(COBID & 0x0000FFFFL); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptrTmp++ = cobidH; + *ptrTmp++ = 0; + } + + *ptrTmp++ = 0x0000; /* rezerva */ + ptrRTR++; + } + + *((U16*)card->commandRegister) = ((U16)cmCL2_DOWNLOAD_RTR_LIST + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_download_rtrlist */ + + +/******************************************************************************* +* 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 */ + ) + { + U16 *ptrU16 = (U16*)card->dataPtr; + U32 COBID; + U16 cobidH, cobidL; + + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + if ( RTRnumber > 9 ) return CL2_BAD_PARAM; + + card->rtrSub[RTRnumber] = canMessage->COB_ID; + *ptrU16 = RTRnumber; + ptrU16++; + COBID = canMessage->COB_ID; + + if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */ + { /* 2.0B frame */ + COBID <<= 3; + cobidL = (U16)(COBID & 0x0000FFFFL); + cobidH = (U16)((COBID & 0xFFFF0000L)>>16); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptrU16++ = cobidH; + cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00)); + *ptrU16++ = cobidL; + *ptrU16 = (U16)CL2_EXT_FRAME; + } + else + { /* 2.0A frame */ + COBID <<= 5; + cobidH = (U16)(COBID & 0x0000FFFFL); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptrU16++ = cobidH; + *ptrU16++ = 0; + *ptrU16 = 0; + } + + *((U16*)card->commandRegister) = ((U16)cmCL2_SUBSCRIBE_RTR + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_subscribe_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 */ + ) + { + U16 i; + + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + + for ( i = 0; i < 10; i++ ) + { + if ( card->rtrSub[i] == canMessage->COB_ID ) + { + card->rtrSub[i] = 0xFFFFFFFFL; + break; + } + } + + if ( i >= 10 ) return CL2_BAD_PARAM; + + *((U16*)card->dataPtr) = i; + *((U16*)card->commandRegister) = ((U16)cmCL2_DESUBSCRIBE_RTR + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_desubscribe_rtr */ + + + +/******************************************************************************* +* 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 */ + ) + { + U16 cobidL, cobidH; + U16 *ptr = (U16 *)card->dataPtr; + + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + + if ( COBID & CL2_TMP_EXHIGH ) /* standard or extended format? */ + { /* 2.0B frame */ + COBID <<= 3; + cobidL = (U16)(COBID & 0x0000FFFFL); + cobidH = (U16)((COBID & 0xFFFF0000L)>>16); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptr++ = cobidH; + cobidL = ((cobidL >> 8) & 0x00FF) | (((cobidL << 8) & 0xFF00)); + *ptr++ = cobidL; + *ptr = CL2_TMP_EX2; + } + else + { /* 2.0A frame */ + COBID <<= 5; + cobidH = (U16)(COBID & 0x0000FFFFL); + cobidH = ((cobidH >> 8) & 0x00FF) | (((cobidH << 8) & 0xFF00)); + *ptr++ = cobidH; + *ptr++ = 0; + *ptr = 0; + } + + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_COBID + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_sync_cobid */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)period; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_SYNC_PERIOD + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_sync_period */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = (U16)window; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_SYNC_WINDOW + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_sync_window */ + + +/******************************************************************************* +* 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 */ + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->dataPtr) = bitrate; + *((U16*)card->commandRegister) = ((U16)cmCL2_SET_BITRATE + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_set_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 + ) + { + if ( *(U16*)card->commandRegister & CL2_COMMAND_VALID ) + return CL2_COMMAND_BUSY; + *((U16*)card->commandRegister) = ((U16)cmCL2_BUS_RESET + + CL2_COMMAND_VALID); + return CL2_OK; + } /* cl2_bus_reset */ + + +/******************************************************************************* +* 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 */ + sCAN_MESSAGE *message /* massage to be sent */ + ) + { + U32 cobid; + U16 cobidL,cobidH; + U16 *ptrU16 = (U16*)card->syncTxBufPtr; + U16 tmpU16; + int i; + int timeStamp = 0; + + if ( card->syncTxBufSize==0 ) return CL2_HW_FAILURE; + if ( message->dataLength > 8 ) return CL2_BAD_PARAM; + if ( *ptrU16 & CL2_FRAME_VALID ) return CL2_HW_QUEUE_FULL; + + cobid = message->COB_ID; + if ( (message->dataType & CL2_EXT_FRAME) || (cobid & CL2_TMP_EXHIGH) ) + { /* 2.0B frame */ + cobid <<= 3; + cobidL = (U16)(cobid & 0x0000FFFFL); + cobidH = (U16)((cobid & 0xFFFF0000L)>>16); + } + else + { /* 2.0A frame */ + cobid <<= 5; + cobidL = 0; + cobidH = (U16)(cobid & 0x0000FFFFL); + } + ptrU16++; + tmpU16 = (cobidH & 0x00FF) + (cobidL & 0xFF00); + *ptrU16++ = tmpU16; + + tmpU16 = (((U16)message->dataLength) << 12) + (cobidL & 0x00FF); + if ( !(message->dataType & CL2_REMOTE_FRAME) ) tmpU16 |= CL2_TMP_RF; + if ( (message->dataType & CL2_EXT_FRAME) || + (message->COB_ID & CL2_TMP_EXHIGH) ) + tmpU16 |= CL2_TMP_EX; + *ptrU16++ = tmpU16; + + for ( i = 0; i < message->dataLength; ) + { + tmpU16 = (U16)message->data[i]; i++; + if ( i == message->dataLength ) + { + timeStamp = 1; + tmpU16 |= ((message->timeStamp & 0x00FF)<<8); + *ptrU16++ = tmpU16; + } + else + { + tmpU16 |= ((U16)message->data[i]<<8); i++; + *ptrU16++ = tmpU16; + } + } + if ( timeStamp ) + { + tmpU16 = (message->timeStamp>>8) & 0x00FF; + *ptrU16 = tmpU16; + } + else + { + *ptrU16 = message->timeStamp; + } + + tmpU16 = (((U16)cobidH) & 0xFF00) | CL2_MESSAGE_VALID; + *(U16*)card->syncTxBufPtr = tmpU16; + + if ( (card->syncTxBufBase + card->syncTxBufSize*16) <= + (card->syncTxBufPtr += 16) ) + { + card->syncTxBufPtr = card->syncTxBufBase; + } + return CL2_OK; + } /* cl2_send_sync */ + + +/******************************************************************************* +* 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 */ + sCAN_MESSAGE *message /* message to be sent */ + ) + { + U32 cobid; + U16 cobidL,cobidH; + U16 *ptrU16 = (U16*)card->asyncTxBufPtr; + U16 tmpU16; + int i; + int timeStamp = 0; + + if ( card->asyncTxBufSize==0 ) return CL2_HW_FAILURE; + if ( message->dataLength > 8 ) return CL2_BAD_PARAM; + if ( *ptrU16 & CL2_FRAME_VALID ) return CL2_HW_QUEUE_FULL; + + cobid = message->COB_ID; + if ( (message->dataType & CL2_EXT_FRAME) || (cobid & CL2_TMP_EXHIGH) ) + { /* 2.0B frame */ + cobid <<= 3; + cobidL = (U16)(cobid & 0x0000FFFFL); + cobidH = (U16)((cobid & 0xFFFF0000L)>>16); + } + else + { /* 2.0A frame */ + cobid <<= 5; + cobidL = 0; + cobidH = (U16)(cobid & 0x0000FFFFL); + } + ptrU16++; + tmpU16 = (cobidH & 0x00FF ) + (cobidL & 0xFF00); + *ptrU16++ = tmpU16; + + tmpU16 = (((U16)message->dataLength) << 12) + (cobidL & 0x00FF); + if ( !(message->dataType & CL2_REMOTE_FRAME) ) tmpU16 |= CL2_TMP_RF; + if ( (message->dataType & CL2_EXT_FRAME) || + (message->COB_ID & CL2_TMP_EXHIGH ) ) + tmpU16 |= CL2_TMP_EX; + *ptrU16++ = tmpU16; + + for ( i = 0; i < message->dataLength; ) + { + tmpU16 = (U16)message->data[i]; i++; + if ( i == message->dataLength ) + { + timeStamp = 1; + tmpU16 |= ((message->timeStamp & 0x00FF)<<8); + *ptrU16++ = tmpU16; + } + else + { + tmpU16 |= ((U16)message->data[i]<<8); i++; + *ptrU16++ = tmpU16; + } + } + if ( timeStamp ) + { + tmpU16 = (message->timeStamp>>8) & 0x00FF; + *ptrU16 = tmpU16; + } + else + { + *ptrU16 = message->timeStamp; + } + + tmpU16 = (((U16)cobidH) & 0xFF00) | CL2_MESSAGE_VALID; + *(U16*)card->asyncTxBufPtr = tmpU16; + + if ( (card->asyncTxBufBase + card->asyncTxBufSize*16) <= + (card->asyncTxBufPtr += 16) ) + { + card->asyncTxBufPtr = card->asyncTxBufBase; + } + return CL2_OK; + } /* cl2_send_async */ + + +/******************************************************************************* +* 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 */ + U16 *status /* card status word */ + ) + { + U16 *ptr; + + ptr = (U16*)(card->baseAddressPtr + CL2_STATUS_REGISTER); + *status = *ptr; + if ( (*status & CL2_STATUS_VALID_FLAG) ) + { + *ptr = *status & ~CL2_STATUS_VALID_FLAG; + card->status = *status; + return CL2_OK; + } + return CL2_NO_REQUEST; + } /* cl2_get_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 */ + U16 *error /* card error word */ + ) + { + U16 *ptr; + + ptr = (U16*)(card->baseAddressPtr + CL2_ERROR_REGISTER); + *error = *ptr; + card->error |= *error; + *ptr = 0x0000; + return CL2_OK; + } /* cl2_get_error */ + + +/******************************************************************************* +* 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 */ + ) + { + U16 *ptrU16 = (U16*)card->rxBufPtr; + U16 tmpU16; + U16 i; + + tmpU16 = *ptrU16++; + if ( !(tmpU16 & CL2_MESSAGE_VALID) ) return CL2_NO_REQUEST; + canMessage->COB_ID = ((U32)(tmpU16 & 0xFF00 )) << 16; + tmpU16 = *ptrU16++; + canMessage->COB_ID |= ((U32)( tmpU16 & 0x00FF )) << 16; + canMessage->COB_ID |= (U32)( tmpU16 & 0xFF00 ); + tmpU16 = *ptrU16++; + canMessage->COB_ID |= (U32)( tmpU16 & 0x00FF ); + canMessage->dataType = (U8)(( tmpU16 & 0xFF00 ) >> 8); + + if ( canMessage->dataType & CL2_EXT_FRAME ) + { /* 2.0B frame */ + canMessage->COB_ID >>= 3; + /* canMessage->COB_ID |= CL2_TMP_EXHIGH; */ + } + else + { /* 2.0A frame */ + canMessage->COB_ID >>= 21; + } + canMessage->dataLength = (U8)( (tmpU16 >> 12) & 0x000F ); + /* if ( !(tmpU16 & CL2_TMP_RF) ) canMessage->dataType |= CL2_REMOTE_FRAME; */ + for ( i = 0; i < canMessage->dataLength; ) + { + tmpU16 = *ptrU16++; + canMessage->data[i++] = (U8)( tmpU16 ); + canMessage->data[i++] = (U8)( tmpU16 >> 8 ); + } + if ( canMessage->dataLength & 0x01 ) + { /* odd */ + canMessage->timeStamp = ( (*ptrU16 & 0x00FF) | (tmpU16 & 0xFF00) ); + } + else /* even */ + { + canMessage->timeStamp = *ptrU16 << 8 | *ptrU16 >> 8; + } + *(U16*)card->rxBufPtr = 0x0000; + + /* increment rx-buffer pointer */ + if ( (card->rxBufBase + card->rxBufSize*16 ) <= (card->rxBufPtr += 16) ) + { + card->rxBufPtr = card->rxBufBase; + } + + return CL2_OK; + } /* cl2_receive_data */ + + +/* **************************************************************** * + * END OF CL2.C * + * **************************************************************** */ + + diff --git a/lincan/utils/Makefile.omk b/lincan/utils/Makefile.omk index 8eeb02a..32409d7 100644 --- a/lincan/utils/Makefile.omk +++ b/lincan/utils/Makefile.omk @@ -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) -- 2.39.2