⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canio.h

📁 开放源码实时操作系统源码.
💻 H
📖 第 1 页 / 共 2 页
字号:
//
// CAN configuration - at the moment there is only one data member but we are
// prepared for future enhancements
//
typedef struct cyg_can_info_st {
    cyg_can_baud_rate_t   baud;
} cyg_can_info_t;


#define CYG_CAN_INFO_INIT(_baud) \
  { _baud}

//
// buffer configuration - bufsize and count for tx are the number of messages
// and for rx the number of events
//
typedef struct cyg_can_buf_info_st
{  
    cyg_uint32 rx_bufsize; 
    cyg_uint32 rx_count;
    cyg_uint32 tx_bufsize;
    cyg_uint32 tx_count;
} cyg_can_buf_info_t;

//
// Message box configuration
//
typedef struct cyg_can_msgbox_info_st
{
    cyg_uint16 count;    // number of message buffers available for this device
    cyg_uint16 free;     // number of free message buffers
} cyg_can_msgbuf_info;


//
// Timeout configuration
//
typedef struct cyg_can_timeout_info_st
{
    cyg_uint32 rx_timeout; 
    cyg_uint32 tx_timeout;
} cyg_can_timeout_info_t;


//
// this data type defines a handle to a message buffer or message box
// of the CAN hardware device
//
typedef cyg_int32 cyg_can_msgbuf_handle;


//
// structure for configuration of message buffers
//
typedef struct cyg_can_msgbox_cfg_st
{
    cyg_can_msgbuf_cfg_id  cfg_id; // configuration id - cfg. what to do with message buffer
    cyg_can_msgbuf_handle  handle; // handle to message buffer
    cyg_can_message        msg;    // CAN message - for configuration of buffer
} cyg_can_msgbuf_cfg;

//
// this data type defines a CAN message filter. It consits
// of a handle to a message box or message buffer and a CAN message.
// For the filtering only the id and the ext field of the CAN message are
// important. The values of the other fields doesn't matter
//
typedef cyg_can_msgbuf_cfg cyg_can_filter;

//
// this data type defines a remote buffer. It consits
// of a handle to a message box or message buffer and the message data
// to send on reception of a remote request
//
typedef cyg_can_msgbuf_cfg cyg_can_remote_buf;

//
// Values for the handle field of the cyg_can_rtr_buf, cyg_can_filter and
// cyg_can_msgbuf_cfg data structure
//
#define CYGNUM_CAN_MSGBUF_NA    -0x01 // no free message buffer available


//
// The Hardware Description Interface provides a method to gather information
// about the CAN hardware and the functionality of the driver. For
// this purpose the following structure is defined:
//
// Support flags:
// |   7   |   6   |   5   |   4   |   3    |   2   |   1   |   0    |
// +-------+-------+-------+-------+--------+-------+-------+--------+
// | res   |  res  |  res  |timest.|autobaud|FullCAN|   Frametype    |
//
typedef struct cyg_can_hdi_st
{
    cyg_uint8 support_flags;
    cyg_uint8 controller_type;
} cyg_can_hdi;
 
//
// Bit 0 and Bit 1 of the structure member support_flags describe the
// possibities of the CAN controller. The following values are defined: 
//
#define CYGNUM_CAN_HDI_FRAMETYPE_STD           0x00 // standard frame (11-bit identifier), 2.0A
#define CYGNUM_CAN_HDI_FRAMETYPE_EXT_PASSIVE   0x01 // extended frame (29-bit identifier), 2.0B passive
#define CYGNUM_CAN_HDI_FRAMETYPE_EXT_ACTIVE    0x02 // extended frame (29-bit identifier), 2.0B active
#define CYGNUM_CAN_HDI_FULLCAN                 0x04 // controller supports more than one receive and transmit buffer
#define CYGNUM_CAN_HDI_AUTBAUD                 0x08 // driver supports automatic baudrate detection
#define CYGNUM_CAN_HDI_TIMESTAMP               0x10 // driver supports timestamps


//
// Callback configuration structure.
//

typedef void (*cyg_can_event_cb_t)(cyg_uint16, CYG_ADDRWORD);
//
// flag_mask should be set with a combination of CYGNUM_CAN_EVENT_* flags.
// If one of these events happens, the callback function will be called,
// with the actually event flags passed as a parameter.
//
typedef struct cyg_can_callback_cfg_st
{
    cyg_can_event_cb_t callback_func;              // callback function
    cyg_uint16  flag_mask;                         // flags mask
    CYG_ADDRWORD data;                             // data passed to callback
} cyg_can_callback_cfg;


//===========================================================================
//                      CAN MESSAGE ACCESS MACROS
//
// An application should not access a cyg_can_message directly instead it
// should use these macros for all manipulations to a CAN message.
//===========================================================================

//---------------------------------------------------------------------------
// Frame type macros
//
#define CYG_CAN_MSG_SET_FRAME_TYPE(_msg_, _type_)  ((_msg_).rtr = (_type_))
#define CYG_CAN_MSG_GET_FRAME_TYPE(_msg_)          ((_msg_).rtr)
#define CYG_CAN_MSG_SET_RTR(_msg_)                 ((_msg_).rtr = CYGNUM_CAN_FRAME_RTR)
#define CYG_CAN_MSG_IS_REMOTE(_msg_)               ((_msg_).rtr == CYGNUM_CAN_FRAME_RTR)


//---------------------------------------------------------------------------
// ID type macros
//
#define CYG_CAN_MSG_SET_ID_TYPE(_msg_, _type_)     ((_msg_).ext = (_type_))
#define CYG_CAN_MSG_GET_ID_TYPE(_msg_)             ((_msg_).ext)
#define CYG_CAN_MSG_SET_EXT(_msg_)                 ((_msg_).ext = CYGNUM_CAN_ID_EXT)
#define CYG_CAN_MSG_SET_STD(_msg_)                 ((_msg_).ext = CYGNUM_CAN_ID_STD)
#define CYG_CAN_MSG_IS_EXT(_msg_)                  ((_msg_).ext == CYGNUM_CAN_ID_EXT)


//---------------------------------------------------------------------------
// Identifier access macros
//
#define CYG_CAN_MSG_GET_ID(_msg_)                  ((_msg_).id)
#define CYG_CAN_MSG_SET_ID(_msg_, _id_)            ((_msg_).id = (_id_))
#define CYG_CAN_MSG_SET_STD_ID(_msg_, _id_)  \
CYG_MACRO_START                              \
    CYG_CAN_MSG_SET_ID(_msg_, _id_);         \
    CYG_CAN_MSG_SET_STD(_msg_);              \
CYG_MACRO_END

#define CYG_CAN_MSG_SET_EXT_ID(_msg_, _id_)  \
CYG_MACRO_START                              \
    CYG_CAN_MSG_SET_ID(_msg_, _id_);         \
    CYG_CAN_MSG_SET_EXT(_msg_);              \
CYG_MACRO_END


//---------------------------------------------------------------------------
// DLC (data length code) access macros
//
#define CYG_CAN_MSG_GET_DATA_LEN(_msg_)             ((_msg_).dlc)
#define CYG_CAN_MSG_SET_DATA_LEN(_msg_, _len_)      ((_msg_).dlc = (_len_))


//---------------------------------------------------------------------------
// CAN message data access
// This macro returns a pointer to a cyg_can_msg_data union
//
#define CYG_CAN_MSG_DATA_PTR(_msg_)                 (&(_msg_).data)
#define CYG_CAN_MSG_GET_DATA(_msg_, _pos_)          ((_msg_).data.bytes[_pos_])
#define CYG_CAN_MSG_SET_DATA(_msg_, _pos_, _val_)   ((_msg_).data.bytes[_pos_] = (_val_)) 


//---------------------------------------------------------------------------
// Access multiple parameters
//
#define CYG_CAN_MSG_SET_PARAM(_msg_, _id_, _ext_, _dlc_, _rtr_)     \
CYG_MACRO_START                                                     \
    CYG_CAN_MSG_SET_ID(_msg_, _id_);                                \
    CYG_CAN_MSG_SET_ID_TYPE(_msg_, _ext_);                          \
    CYG_CAN_MSG_SET_DATA_LEN(_msg_, _dlc_);                         \
    CYG_CAN_MSG_SET_FRAME_TYPE(_msg_, _rtr_);                       \
CYG_MACRO_END

#define CYG_CAN_MSG_INIT(_clabel_, _id_, _ext_, _dlc_, _rtr_)      \
cyg_can_message _clabel_ =                                         \
{                                                                  \
	id  : _id_,                                                    \
    ext : _ext_,                                                   \
    rtr : _rtr_,                                                   \
    dlc : _dlc_,                                                   \
}
                                                       


#ifdef __cplusplus
}
#endif

//---------------------------------------------------------------------------
#endif // CYGONCE_CANIO_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -