]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/io/can/v2_0/include/can.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / io / can / v2_0 / include / can.h
index 5755810a8e4f292c25ad8891af4acda4e78a6dc7..14de571ff437ce1ad2de7403fd0bb23f429fbbfd 100644 (file)
 #include <cyg/hal/drv_api.h>
 
 
+// define standard and extended id masks
+#define CYG_CAN_STD_ID_MASK 0x7FF
+#define CYG_CAN_EXT_ID_MASK 0x1FFFFFFF
+
+//
+// include device header
+// a device can define its own types of CAN messages and CAN events. It does this
+// in the device header CYGDAT_IO_CAN_DEVICE_INL. Because this header is included
+// here, the device header file can use all definitions in the files included
+// in the include section above
+//
+#ifdef CYGDAT_IO_CAN_DEVICE_INL 
+#include CYGDAT_IO_CAN_DEVICE_INL   // include device header
+#endif
+
+//
+// If the device did not define its own type of CAN message and CAN event, then
+// we define standard types here and use the types cyg_can_message and cyg_can_event
+// from CAN I/O layer
+//
+#ifndef CYG_CAN_MSG_T
+#define CYG_CAN_MSG_T cyg_can_message
+#define CYG_CAN_EVENT_T cyg_can_event
+#define CYG_CAN_WRITE_MSG(_devmsg_ptr_, _iomsg_ptr_) (*(_devmsg_ptr_) = *(_iomsg_ptr_))
+#define CYG_CAN_READ_EVENT(_ioevent_ptr_, _devevent_ptr_) (*(_ioevent_ptr_) = *(_devevent_ptr_))
+#endif
+
+
 //===========================================================================
 //                            FORWARD DECLARATIONS
 //===========================================================================
@@ -140,15 +168,23 @@ typedef struct can_cbuf_st
 //
 struct can_channel 
 {
-    can_lowlevel_funs  *funs;
-    can_callbacks_t    *callbacks;
-    void               *dev_priv;  // Whatever is needed by actual device routines
-    cyg_can_info_t      config;    // Current configuration
-    bool                init;      // true if driver is already initialized
-    can_cbuf_t          out_cbuf;  // buffer for transmit can messages
-    can_cbuf_t          in_cbuf;   // buffer with received can events
+    can_lowlevel_funs   *funs;
+    can_callbacks_t     *callbacks;
+    void                *dev_priv;     // Whatever is needed by actual device routines
+    cyg_can_info_t       config;       // Current configuration
+    bool                 init;         // true if driver is already initialized
+    can_cbuf_t           out_cbuf;     // buffer for transmit can messages
+    can_cbuf_t           in_cbuf;      // buffer with received can events
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+    cyg_can_callback_cfg callback_cfg; // Callback configuration
+#endif
 };
 
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+#define CYG_CAN_CALLBACK_INIT  , {(cyg_can_event_cb_t) 0, 0, 0}
+#else
+#define CYG_CAN_CALLBACK_INIT
+#endif
 
 
 #define CAN_CHANNEL_USING_INTERRUPTS(_l,                                \
@@ -165,6 +201,7 @@ can_channel _l = {                                                      \
     false,                                                              \
     CBUF_INIT(_out_buf, _out_buflen, _TX_TIMEOUT),                      \
     CBUF_INIT(_in_buf, _in_buflen, _RX_TIMEOUT)                         \
+    CYG_CAN_CALLBACK_INIT                                               \
 };
 
 
@@ -175,23 +212,28 @@ can_channel _l = {                                                      \
 //
 struct can_lowlevel_funs 
 {
-    bool (*putmsg)(can_channel *priv, cyg_can_message *pmsg, void *pdata);   // send one can message - return true if consumed
-    bool (*getevent)(can_channel *priv, cyg_can_event *pevent, void *pdata); // fetch one CAN event from device
-    Cyg_ErrNo (*set_config)(can_channel    *priv,                        // Change hardware configuration (baud rate, etc)
+    bool (*putmsg)(can_channel *priv, CYG_CAN_MSG_T *pmsg, void *pdata);       // send one can message - return true if consumed
+    bool (*getevent)(can_channel *priv, CYG_CAN_EVENT_T *pevent, void *pdata); // fetch one CAN event from device
+    Cyg_ErrNo (*get_config)(can_channel    *priv,                              // query hardware configuration (baud rate, etc)
+                            cyg_uint32      key, 
+                            const void     *xbuf,
+                            cyg_uint32     *len);
+    Cyg_ErrNo (*set_config)(can_channel    *priv,                              // Change hardware configuration (baud rate, etc)
                             cyg_uint32      key, 
                             const void     *xbuf,
                             cyg_uint32     *len);
-    void (*start_xmit)(can_channel *priv);                               // Enable the transmit channel and turn on transmit interrupts
-    void (*stop_xmit)(can_channel *priv);                                // Disable the transmit channel and turn transmit interrupts off
+    void (*start_xmit)(can_channel *priv);                                    // Enable the transmit channel and turn on transmit interrupts
+    void (*stop_xmit)(can_channel *priv);                                     // Disable the transmit channel and turn transmit interrupts off
 };
 
-#define CAN_LOWLEVEL_FUNS(_l,_putmsg,_getevent,_set_config,_start_xmit,_stop_xmit)  \
-can_lowlevel_funs _l = {                                                            \
-  _putmsg,                                                                          \
-  _getevent,                                                                        \
-  _set_config,                                                                      \
-  _start_xmit,                                                                      \
-  _stop_xmit                                                                        \
+#define CAN_LOWLEVEL_FUNS(_l,_putmsg,_getevent,_get_config,_set_config,_start_xmit,_stop_xmit)  \
+can_lowlevel_funs _l = {                                                                        \
+  _putmsg,                                                                                      \
+  _getevent,                                                                                    \
+  _get_config,                                                                                  \
+  _set_config,                                                                                  \
+  _start_xmit,                                                                                  \
+  _stop_xmit                                                                                    \
 };
 
 extern cyg_devio_table_t cyg_io_can_devio;