ntcan.h
Go to the documentation of this file.
00001 /* ntcan.h
00002 **
00003 **            Copyright (c) 2001-2006 by electronic system design gmbh
00004 **
00005 **  This software is copyrighted by and is the sole property of
00006 **  esd gmbh.  All rights, title, ownership, or other interests
00007 **  in the software remain the property of esd gmbh. This
00008 **  software may only be used in accordance with the corresponding
00009 **  license agreement.  Any unauthorized use, duplication, transmission,
00010 **  distribution, or disclosure of this software is expressly forbidden.
00011 **
00012 **  This Copyright notice may not be removed or modified without prior
00013 **  written consent of esd gmbh.
00014 **
00015 **  esd gmbh, reserves the right to modify this software without notice.
00016 **
00017 **  electronic system design gmbh          Tel. +49-511-37298-0
00018 **  Vahrenwalder Str 207                   Fax. +49-511-37298-68
00019 **  30165 Hannover                         http://www.esd-electronics.com
00020 **  Germany                                sales@esd-electronics.com
00021 **
00022 **
00023 */
00024 
00025 #ifndef _ntcan_h_
00026 #define _ntcan_h_
00027 
00028 #if ((__GNUC__ > 2) || (__GNUC__ > 2) && (__GNUC_MINOR__ >= 1))
00029 # define NTCAN_GCCATTR_DEPRECATED __attribute__((deprecated))
00030 #else
00031 # define NTCAN_GCCATTR_DEPRECATED
00032 #endif
00033 
00034 #include <stdint.h>
00035 
00036 #ifndef EXPORT
00037 #define EXPORT
00038 #endif
00039 
00040 #ifndef CALLTYPE
00041 #define CALLTYPE
00042 #endif
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif /* __cplusplus */
00047 
00048 /*------------------ Defines ------------------------------------------------*/
00049 #define NTCAN_EV_BASE           0x40000000
00050 #define NTCAN_EV_USER           0x40000080
00051 #define NTCAN_EV_LAST           0x400000FF
00052 
00053 #define NTCAN_20B_BASE          0x20000000
00054 
00055 #define NTCAN_RTR               0x10
00056 #define NTCAN_NO_DATA           0x20     /* only senseful in obj-mode */
00057 #define NTCAN_INTERACTION       0x20     /* only senseful in non obj-mode */
00058 
00059 #define NTCAN_EV_CAN_ERROR      NTCAN_EV_BASE
00060 #define NTCAN_EV_BAUD_CHANGE    (NTCAN_EV_BASE + 0x1)
00061 #define NTCAN_EV_CAN_ERROR_EXT  (NTCAN_EV_BASE + 0x2)
00062 
00063 /* Mode-flags for canOpen() */
00064 #define NTCAN_MODE_OVERLAPPED   0x20000000
00065 #define NTCAN_MODE_OBJECT       0x10000000  /* Open for Rx object mode    */
00066 
00067 /* Queue-Size in canOpen() */
00068 #define NTCAN_MAX_TX_QUEUESIZE  2047
00069 #define NTCAN_MAX_RX_QUEUESIZE  2047
00070 #define NTCAN_NO_QUEUE          -1
00071 
00072 /* No baudrate configured (returned from canGetBaudrate() )*/
00073 #define NTCAN_NO_BAUDRATE       0x7FFFFFFF
00074 #define NTCAN_AUTOBAUD          0x7FFFFFFE
00075 /* Defines to easily use CiA-recommended baudrates
00076  * predefined by esd with canSetBaudrate() */
00077 #define NTCAN_BAUD_1000  0x0
00078 #define NTCAN_BAUD_800   0xE
00079 #define NTCAN_BAUD_500   0x2
00080 #define NTCAN_BAUD_250   0x4
00081 #define NTCAN_BAUD_125   0x6
00082 #define NTCAN_BAUD_100   0x7
00083 #define NTCAN_BAUD_50    0x9
00084 #define NTCAN_BAUD_20    0xB
00085 #define NTCAN_BAUD_10    0xD
00086 /* Defines to use with canSetBaudrate() */
00087 #define NTCAN_USER_BAUD          0x80000000  /* DEPRECATED, please use the define below, as described in CAN-API manual */
00088 #define NTCAN_USER_BAUDRATE      0x80000000
00089 #define NTCAN_LISTEN_ONLY_MODE   0x40000000
00090 #define NTCAN_USER_BAUDRATE_NUM  0x20000000
00091 
00092 /*------------------- error-code-base----------------------------------------*/
00093 #define NTCAN_ERRNO_BASE             0x00000100
00094 /*------------------- error-codes--------------------------------------------*/
00095 #define NTCAN_SUCCESS                0
00096 
00097 #define NTCAN_RX_TIMEOUT             (NTCAN_ERRNO_BASE +1)
00098 #define NTCAN_TX_TIMEOUT             (NTCAN_ERRNO_BASE +2)
00099 /* #define NTCAN_RESERVED            (NTCAN_ERRNO_BASE +3) */
00100 #define NTCAN_TX_ERROR               (NTCAN_ERRNO_BASE +4)
00101 #define NTCAN_CONTR_OFF_BUS          (NTCAN_ERRNO_BASE +5)
00102 #define NTCAN_CONTR_BUSY             (NTCAN_ERRNO_BASE +6)
00103 #define NTCAN_CONTR_WARN             (NTCAN_ERRNO_BASE +7)
00104 #define NTCAN_NO_ID_ENABLED          (NTCAN_ERRNO_BASE +9)
00105 #define NTCAN_ID_ALREADY_ENABLED     (NTCAN_ERRNO_BASE +10)
00106 #define NTCAN_ID_NOT_ENABLED         (NTCAN_ERRNO_BASE +11)
00107 /* #define NTCAN_RESERVED            (NTCAN_ERRNO_BASE +12) */
00108 #define NTCAN_INVALID_FIRMWARE       (NTCAN_ERRNO_BASE +13)
00109 #define NTCAN_MESSAGE_LOST           (NTCAN_ERRNO_BASE +14)
00110 #define NTCAN_INVALID_HARDWARE       (NTCAN_ERRNO_BASE +15)
00111 
00112 #define NTCAN_PENDING_WRITE          (NTCAN_ERRNO_BASE +16)
00113 #define NTCAN_PENDING_READ           (NTCAN_ERRNO_BASE +17)
00114 #define NTCAN_INVALID_DRIVER         (NTCAN_ERRNO_BASE +18)
00115 
00116 #define NTCAN_SOCK_CONN_TIMEOUT      (NTCAN_ERRNO_BASE + 0x80)
00117 #define NTCAN_SOCK_CMD_TIMEOUT       (NTCAN_ERRNO_BASE + 0x81)
00118 #define NTCAN_SOCK_HOST_NOT_FOUND    (NTCAN_ERRNO_BASE + 0x82)  /* gethostbyname() failed */
00119 
00120 #define NTCAN_INVALID_PARAMETER      EINVAL
00121 #define NTCAN_INVALID_HANDLE         EBADFD
00122 /* #define NTCAN_IO_INCOMPLETE       not reasonable under Linux */
00123 /* #define NTCAN_IO_PENDING          not reasonable under Linux */
00124 #define NTCAN_NET_NOT_FOUND          ENODEV
00125 #define NTCAN_INSUFFICIENT_RESOURCES ENOMEM
00126 
00127 #define NTCAN_OPERATION_ABORTED      EINTR
00128 #define NTCAN_WRONG_DEVICE_STATE     (NTCAN_ERRNO_BASE +19)
00129 #define NTCAN_HANDLE_FORCED_CLOSE    (NTCAN_ERRNO_BASE +20)
00130 #define NTCAN_NOT_IMPLEMENTED        ENOSYS
00131 #define NTCAN_NOT_SUPPORTED          (NTCAN_ERRNO_BASE +21)
00132 #define NTCAN_CONTR_ERR_PASSIVE      (NTCAN_ERRNO_BASE +22)
00133 
00134 /*
00135  *  Dear ntcan-user,
00136  *  we regret, that we were forced to change the name of our handle type.
00137  *  This had to be done to keep "inter-system" compatibility of your
00138  *  application sources, after a change in VxWorks 6.0. Please replace all
00139  *  occurrences of HANDLE with NTCAN_HANDLE in your application's source
00140  *  code.
00141  */
00142 typedef int32_t OVERLAPPED;
00143 #ifndef NTCAN_CLEAN_NAMESPACE
00144 typedef int32_t HANDLE NTCAN_GCCATTR_DEPRECATED;
00145 #endif
00146 typedef int32_t NTCAN_RESULT;
00147 typedef int32_t NTCAN_HANDLE;
00148 
00149 #pragma pack(1)
00150 
00151 typedef struct {
00152         int32_t  id;            /* can-id                                     */
00153         uint8_t  len;           /* length of message: 0-8                     */
00154         uint8_t  msg_lost;      /* count of lost rx-messages                  */
00155         uint8_t  reserved[2];   /* reserved                                   */
00156         uint8_t  data[8];       /* 8 data-bytes                               */
00157 } CMSG;
00158 
00159 typedef struct {
00160         int32_t  evid;          /* event-id: possible range:EV_BASE...EV_LAST */
00161         uint8_t  len;           /* length of message: 0-8                     */
00162         uint8_t  reserved[3];   /* reserved                                   */
00163         union {
00164                 uint8_t   c[8];
00165                 uint16_t  s[4];
00166                 uint32_t  l[2];
00167         } evdata;
00168 } EVMSG;
00169 
00170 typedef struct {
00171         int32_t   id;             /* can-id                                   */
00172         uint8_t   len;            /* length of message: 0-8                   */
00173         uint8_t   msg_lost;       /* count of lost rx-messages                */
00174         uint8_t   reserved[2];    /* reserved                                 */
00175         uint8_t   data[8];        /* 8 data-bytes                             */
00176         uint64_t  timestamp;      /* time stamp of this message               */
00177 } CMSG_T;
00178 
00179 typedef struct {
00180         uint16_t  hardware;
00181         uint16_t  firmware;
00182         uint16_t  driver;
00183         uint16_t  dll;
00184         uint32_t  boardstatus;
00185         uint8_t   boardid[14];
00186         uint16_t  features;
00187 } CAN_IF_STATUS;
00188 
00189 
00190 typedef struct
00191 {
00192   int32_t id;
00193   int32_t flags;
00194   uint64_t time_start;
00195   uint64_t time_interval;
00196   uint8_t reserved[8];
00197 } CSCHED;
00198 
00199 #pragma pack()
00200 
00201 
00202 /* Feature-flags returned by canStatus() */
00203 #define NTCAN_FEATURE_FULL_CAN         (1<<0)
00204 #define NTCAN_FEATURE_BASIC_20B        (1<<1)
00205 #define NTCAN_FEATURE_DEVICE_NET       (1<<2)
00206 #define NTCAN_FEATURE_CYCLIC_TX        (1<<3) /* Cyclic Tx support            */
00207 #define NTCAN_FEATURE_RX_OBJECT_MODE   (1<<4) /* Receive object mode support  */
00208 #define NTCAN_FEATURE_TIMESTAMP        (1<<5) /* Timestamp support            */
00209 #define NTCAN_FEATURE_LISTEN_ONLY_MODE (1<<6) /* Listen-only-mode support     */
00210 #define NTCAN_FEATURE_SMART_DISCONNECT (1<<7) /* Leave-bus-after-last-close   */
00211 
00212 /* Bus states delivered by status-event */
00213 #define NTCAN_BUSSTATE_OK           0x00
00214 #define NTCAN_BUSSTATE_WARN         0x40
00215 #define NTCAN_BUSSTATE_ERRPASSIVE   0x80
00216 #define NTCAN_BUSSTATE_BUSOFF       0xC0
00217 
00218 /*
00219  * IOCTL codes for canIoctl()
00220  */
00221 #define NTCAN_IOCTL_FLUSH_RX_FIFO         0x0001   /* Flush Rx FIFO                 */
00222 #define NTCAN_IOCTL_GET_RX_MSG_COUNT      0x0002   /* Ret # CMSG in Rx FIFO         */
00223 #define NTCAN_IOCTL_GET_RX_TIMEOUT        0x0003   /* Ret configured Rx tout        */
00224 #define NTCAN_IOCTL_GET_TX_TIMEOUT        0x0004   /* Ret configured Tx tout        */
00225 
00226 /*
00227  * AB: The following IOCTLs aren't implemented in candev-driver, yet.
00228  *     And probably never will, since candev driver is deprecated.
00229  */
00230 #define NTCAN_IOCTL_SET_20B_HND_FILTER    0x0005   /* Configure 20B filter          */
00231 #define NTCAN_IOCTL_GET_SERIAL            0x0006   /* Get HW serial number          */
00232 #define NTCAN_IOCTL_GET_TIMESTAMP_FREQ    0x0007   /* Get timestamp frequency in Hz */
00233 #define NTCAN_IOCTL_GET_TIMESTAMP         0x0008   /* Get timestamp counter         */
00234 #define NTCAN_IOCTL_ABORT_RX              0x0009   /* Abort a pending read          */
00235 #define NTCAN_IOCTL_ABORT_TX              0x000A   /* Abort pending write           */
00236 #define NTCAN_IOCTL_SET_RX_TIMEOUT        0x000B   /* Change rx-timeout parameter   */
00237 #define NTCAN_IOCTL_SET_TX_TIMEOUT        0x000C   /* Change tx-timeout parameter   */
00238 #define NTCAN_IOCTL_TX_OBJ_CREATE         0x000D   /* Create obj, arg->CMSG          */
00239 #define NTCAN_IOCTL_TX_OBJ_AUTOANSWER_ON  0x000E   /* Switch autoanswer on,arg->CMSG */
00240 #define NTCAN_IOCTL_TX_OBJ_AUTOANSWER_OFF 0x000F   /* Switch autoanswer off,arg->CMSG*/
00241 #define NTCAN_IOCTL_TX_OBJ_UPDATE         0x0010   /* update  obj, arg->CMSG         */
00242 #define NTCAN_IOCTL_TX_OBJ_DESTROY        0x0011   /* Destroy obj, arg->id           */
00243 
00244 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE_START 0x0013   /* Start scheduling for handle    */
00245 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE_STOP  0x0014   /* Stop scheduling for handle     */
00246 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE       0x0015   /* Set sched. for obj,arg->CSCHED */
00247 
00248 
00249 /*...prototypes................................................................*/
00250 EXPORT NTCAN_RESULT CALLTYPE canSetBaudrate(
00251                 NTCAN_HANDLE  handle,      /* nt-handle                        */
00252                 uint32_t      baud );      /* baudrate-constant                */
00253 /*.............................................................................*/
00254 EXPORT NTCAN_RESULT CALLTYPE canGetBaudrate(
00255                 NTCAN_HANDLE  handle,      /* nt-handle                        */
00256                 uint32_t     *baud );      /* Out: baudrate                    */
00257 /*.............................................................................*/
00258 EXPORT NTCAN_RESULT CALLTYPE canOpen(
00259                 int32_t       net,         /* net number                       */
00260                 uint32_t      flags,       /*                                  */
00261                 int32_t       txqueuesize, /* nr of entries in message queue   */
00262                 int32_t       rxqueuesize, /* nr of entries in message queue   */
00263                 int32_t       txtimeout,   /* tx-timeout in miliseconds        */
00264                 int32_t       rxtimeout,   /* rx-timeout in miliseconds        */
00265                 NTCAN_HANDLE *handle );    /* out: nt-handle                   */
00266 /*.............................................................................*/
00267 EXPORT NTCAN_RESULT CALLTYPE canClose(     /* ret NTCAN_OK, if success         */
00268                 NTCAN_HANDLE  handle );    /* handle                           */
00269 /*.............................................................................*/
00270 EXPORT NTCAN_RESULT CALLTYPE canIdAdd(     /* ret NTCAN_OK, if success         */
00271                 NTCAN_HANDLE  handle,      /* read handle                      */
00272                 int32_t       id  );       /* can identifier                   */
00273 /*.............................................................................*/
00274 EXPORT NTCAN_RESULT CALLTYPE canIdDelete(  /* ret 0, if success                */
00275                 NTCAN_HANDLE  handle,      /* read handle                      */
00276                 int32_t       id  );       /* can identifier                   */
00277 /*.............................................................................*/
00278 EXPORT NTCAN_RESULT CALLTYPE canGetOverlappedResult(
00279                 NTCAN_HANDLE  handle,      /* handle                           */
00280                 OVERLAPPED   *ovrlppd,     /* overlapped-structure             */
00281                 int32_t      *len,         /* out: cnt of available CMSG-Buffer*/
00282                 int32_t       bWait );     /* FALSE =>do not wait, else wait   */
00283 /*.............................................................................*/
00284 EXPORT NTCAN_RESULT CALLTYPE canTake(      /* ret 0, if success                */
00285                 NTCAN_HANDLE  handle,      /* handle                           */
00286                 CMSG         *cmsg,        /* ptr to data-buffer               */
00287                 int32_t      *len );       /* out: size of CMSG-Buffer         */
00288                                            /* in:  count of read messages      */
00289 /*.............................................................................*/
00290 EXPORT NTCAN_RESULT CALLTYPE canRead(      /* ret 0, if success                */
00291                 NTCAN_HANDLE  handle,      /* handle                           */
00292                 CMSG         *cmsg,        /* ptr to data-buffer               */
00293                 int32_t      *len,         /* out: size of CMSG-Buffer         */
00294                                            /* in:  count of read messages      */
00295                 OVERLAPPED   *ovrlppd);    /* NULL or overlapped-structure     */
00296 /*.............................................................................*/
00297 EXPORT NTCAN_RESULT CALLTYPE canSend(      /* ret 0, if success                */
00298                 NTCAN_HANDLE  handle,      /* handle                           */
00299                 CMSG         *cmsg,        /* ptr to data-buffer               */
00300                 int32_t      *len );       /* size of CMSG-Buffer              */
00301 /*.............................................................................*/
00302 EXPORT NTCAN_RESULT CALLTYPE canWrite(     /* ret 0, if success                */
00303                 NTCAN_HANDLE  handle,      /* handle                           */
00304                 CMSG         *cmsg,        /* ptr to data-buffer               */
00305                 int32_t      *len,         /* size of CMSG-Buffer              */
00306                 OVERLAPPED   *ovrlppd);    /* NULL or overlapped-structure     */
00307 /*.............................................................................*/
00308 EXPORT NTCAN_RESULT CALLTYPE canSendT(     /* ret 0, if success                */
00309                 NTCAN_HANDLE  handle,      /* handle                           */
00310                 CMSG_T       *cmsg,        /* ptr to data-buffer               */
00311                 int32_t      *len );       /* size of CMSG-Buffer              */
00312 /*.............................................................................*/
00313 EXPORT NTCAN_RESULT CALLTYPE canWriteT(    /* ret 0, if success                */
00314                 NTCAN_HANDLE  handle,      /* handle                           */
00315                 CMSG_T       *cmsg,        /* ptr to data-buffer               */
00316                 int32_t      *len,         /* size of CMSG-Buffer              */
00317                 OVERLAPPED   *ovrlppd);    /* NULL or overlapped-structure     */
00318 /*.............................................................................*/
00319 EXPORT NTCAN_RESULT CALLTYPE canReadEvent(
00320                 NTCAN_HANDLE  handle,      /* handle                           */
00321                 EVMSG        *evmsg,       /* ptr to event-msg-buffer          */
00322                 OVERLAPPED   *ovrlppd);    /* NULL or overlapped-structure     */
00323 /*.............................................................................*/
00324 EXPORT NTCAN_RESULT CALLTYPE canSendEvent(
00325                 NTCAN_HANDLE  handle,      /* handle                           */
00326                 EVMSG        *evmsg );     /* ptr to event-msg-buffer          */
00327 /*.............................................................................*/
00328 EXPORT NTCAN_RESULT CALLTYPE canStatus(
00329                 NTCAN_HANDLE   handle,     /* handle                           */
00330                 CAN_IF_STATUS *cstat );    /* ptr to can-status-buffer         */
00331 /*.............................................................................*/
00332 EXPORT NTCAN_RESULT CALLTYPE canIoctl(
00333                 NTCAN_HANDLE  handle,      /* handle                           */
00334                 uint32_t      ulCmd,       /* Command                          */
00335                 void         *pArg );      /* Ptr to command specific argument */
00336 /*.............................................................................*/
00337 EXPORT NTCAN_RESULT CALLTYPE canTakeT(
00338                 NTCAN_HANDLE  handle,      /* In: handle                       */
00339                 CMSG_T       *cmsg_t,      /* In: ptr to receive buffer        */
00340                 int32_t      *len );       /* out: size of CMSG_T-Buffer       */
00341                                            /* In: count of read messages       */
00342 /*.............................................................................*/
00343 EXPORT NTCAN_RESULT CALLTYPE canReadT(
00344                 NTCAN_HANDLE  handle,      /* In: handle                       */
00345                 CMSG_T       *cmsg_t,      /* Int ptr to receive buffer        */
00346                 int32_t      *len,         /* out: size of CMSG_T-Buffer       */
00347                                            /* In: count of read messages       */
00348                 OVERLAPPED   *ovrlppd);    /* In: always NULL                  */
00349 
00350 #ifdef __cplusplus
00351 }
00352 #endif /* __cplusplus */
00353 #endif /* _ntcan_h_ */


libntcan
Author(s): Florian Weisshardt
autogenerated on Thu Jun 6 2019 20:18:15