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

📄 can_api.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 4 页
字号:
*
* RETURNS: The structure containing version information.
*
* ERRNO: N/A
*
*/
const WNCAN_VersionInfo * CAN_GetVersion ()
    {
        return(WNCAN_GetVersion());
    }

/***************************************************************************
* CAN_ReadID - read the CAN ID from the specified controller and channel
*
* This routine reads the CAN ID corresponding to the channel number on
* the controller. The standard or extended flag is set by the routine.
* The mode of the channel can not be WNCAN_CHN_INACTIVE or WNCAN_CHN_INVALID.
* The extended flag is set to 'TRUE' if the ID has extended format, otherwise
* it is set to 'FALSE'.
*
* RETURNS: The CAN ID, or -1 if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config
*/
long CAN_ReadID
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR                channelNum, /* channel number */
    BOOL*                ext         /* extended flag */
    )
    {
       return(pDev->ReadID(pDev,channelNum,ext));
    }

/***************************************************************************
* CAN_WriteID - write the CAN ID to the specified channel
*
* This routine writes the CAN ID to the channel. The type of ID
* (standard or extended) is specified. The behavior of the routine for
* every channel mode is specified as follows:
*
* \ml
* \m -
* WNCAN_CHN_INVALID: Not allowed. 'ERROR' is returned.
* \m -
* WNCAN_CHN_INACTIVE: Not allowed. 'ERROR' is returned.
* \m -
* WNCAN_CHN_RECEIVE: CAN messages with this ID will be received.
* \m -
* WNCAN_CHN_RTR_RESPONDER: The data bytes to respond with must be set up with
* a call to CAN_WriteData() previously. CAN messages with this ID will be
* received and a remote response message sent back.
* \m -
* WNCAN_CHN_RTR_REQUESTER: A CAN message with RTR bit set and the specified ID
* will be transmitted when CAN_Tx() is called.
* \m -
* WNCAN_CHN_TRANSMIT: A CAN message with the specified ID will be transmitted
* when CAN_Tx() is called.
* \me
*
* RETURNS: 'OK', or 'ERROR' if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config
*
*/
STATUS CAN_WriteID
    (
    struct WNCAN_Device *pDev,    /* CAN device pointer   */
    UCHAR                chnNum,  /* channel number       */
    ULONG                canID,   /* CAN ID               */
    BOOL                 ext      /* TRUE = extended CAN msg */
    )
    {
       return(pDev->WriteID(pDev,chnNum,canID,ext));
    }

/***************************************************************************
* CAN_ReadData - read data from the specified channel
*
* This routine reads <len> bytes of data from the channel and sets the value
* of <len> to the number of bytes read. The range of <len> is zero (for zero
* length data) to a maximum of eight. The mode of the channel must not be
* WNCAN_CHN_INVALID or WNCAN_CHN_INACTIVE; however, the newData flag is
* valid only for channels with mode equal to WNCAN_CHN_RECEIVE or
* WNCAN_CHN_RTR_REQUESTER. For receive channels, if no new data has been
* received since the last CAN_ReadData() function call, the newData flag
* is set to 'FALSE'; otherwise, the flag is 'TRUE'. In both cases, the data and
* length of the data currently in the channel are read.
* The parameter <len>, contains length of data buffer on entering the
* routine. On return <len> contains number of bytes copied into data buffer.
*
*
* RETURNS: 'OK', or 'ERROR' if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config,
* S_can_buffer_overflow, S_can_illegal_data_length
*
*/
STATUS CAN_ReadData
    (
    struct WNCAN_Device  *pDev,      /* CAN device pointer */
    UCHAR                 chnNum,    /* channel number */
    UCHAR                *data,      /* pointer to buffer for data */
    UCHAR                *len,       /* length pointer */
    BOOL                 *newData    /* new data pointer */
    )
    {
       return(pDev->ReadData(pDev,chnNum,data,len,newData));
    }

/***************************************************************************
* CAN_GetMessageLength - get the message length
*
* This routine returns the length of the message data in the channel on the
* controller. The minimum value returned is 0, and the maximum value is 8.
* This number is equal to the <len> argument in CAN_ReadData(). If the data
* has zero length, this routine returns zero. The mode of the channel
* must not be WNCAN_CHN_INACTIVE or WNCAN_CHN_INVALID
*
* RETURNS: Length of data, or -1 if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config
*/
int CAN_GetMessageLength
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer   */
    UCHAR                channelNum  /* channelNum           */
    )
    {
       return(pDev->GetMessageLength(pDev,channelNum));
    }

/***************************************************************************
* CAN_WriteData - write the data to the specified channel
*
* This routine writes <len> bytes of data to the channel. An error is
* returned if the number of bytes to be written exceed 8. The mode of the
* channel must WNCAN_CHN_TRANSMIT or WNCAN_CHN_RTR_RESPONDER.
*
* RETURNS: 'OK', or 'ERROR' if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config,
* S_can_illegal_data_length
*
*/
STATUS CAN_WriteData
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR                channelNum, /* channel number */
    UCHAR               *data,       /* pointer to data buffer */
    UCHAR                len         /* length of data buffer */
    )
    {
       return(pDev->WriteData(pDev,channelNum,data,len));
    }

/***************************************************************************
* CAN_Tx - transmit the CAN message on the specified channel
*
* This routine transmits the CAN ID and data currently in the channel of
* the specified controller on the device. The mode of the channel must be
* WNCAN_CHN_TRANSMIT or WNCAN_CHN_RTR_REQUESTER.
*
*
* RETURNS: 'OK', or 'ERROR' if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config
*/
STATUS CAN_Tx
    (
    struct WNCAN_Device *pDev,        /* CAN device pointer */
    UCHAR                channelNum   /* channel number */
    )
    {
       return(pDev->Tx(pDev,channelNum));
    }

/***************************************************************************
* CAN_TxMsg - transmit a CAN message with all parameters specified
*
* This routine performs the same function as the following series
* of function calls:
*     \cs
*     CAN_WriteID(context,channelNum,canID,ext);
*     CAN_WriteData(context,channelNum,data,len);
*     CAN_Tx(context,channel);
*     \ce
* The mode of the channel must be WNCAN_CHN_TRANSMIT or
* WNCAN_CHN_RTR_REQUESTER. If the length specified exceeds 8 bytes an error
* will be returned. The extended flag must be set to 'TRUE' if the ID has
* extended format, or 'FALSE' if the ID has standard format.
*
* RETURNS: 'OK', or 'ERROR' if an input parameter is invalid.
*
* ERRNO: S_can_illegal_channel_no, S_can_illegal_config,
* S_can_illegal_data_length
*
*/
STATUS CAN_TxMsg
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR                channelNum, /* channel number */
    ULONG                canId,      /* CAN ID */
    BOOL                 ext,        /* extended message flag */
    UCHAR               *data,       /* pointer to buffer for data */
    UCHAR                len         /* message length */
    )
    {
       return(pDev->TxMsg(pDev,channelNum,canId,ext,data,len));
    }

/***************************************************************************
* CAN_SetGlobalRxFilter - set the global filter in the controller
*
* This routine sets the global HW filter mask for incoming messages on the
* device controller. If the controller does not have a global filter this
* routine is a no-op. If the <ext> parameter is 'TRUE', the mask value applies
* to extended messages; otherwise, the mask values applies to standard
* messages. A value of 0 for a particular bit position of the mask means
* don't care (for example, the incoming message ID could have a value of
* zero or one for this bit position); otherwise, a value of 1 means the
* corresponding bit of the message ID must match identically.
*
* If the controller does not have a global mask, an error is returned.
*
* RETURNS: 'OK', or 'ERROR'.
*
* ERRNO: S_can_hwfeature_not_available
*
*/
STATUS CAN_SetGlobalRxFilter
    (
        struct WNCAN_Device *pDev,   /* CAN device pointer */
        long                 mask,   /* filter mask value */
        BOOL                 ext     /* extended flag */
    )
    {
       return(pDev->SetGlobalRxFilter(pDev,mask,ext));
    }

/***************************************************************************
* CAN_GetGlobalRxFilter - get the global filter value
*
* This routine returns the programmed value in the Global filter register.
* Based on the value of <ext> passed to the routine, this routine reads the
* appropriate format of the global mask and returns the value in the
* specified extended or standard identifier format. If the controller does
* not have a global mask, a value of -1 is returned. This is not a valid
* CAN ID.
*
* RETURNS: Mask, or -1 on error.
*
* ERRNO:   S_can_hwfeature_not_available
*
*/
long CAN_GetGlobalRxFilter
    (
    struct WNCAN_Device *pDev,   /* CAN device pointer */
    BOOL                 ext     /* extended flag */
    )
    {
       return(pDev->GetGlobalRxFilter(pDev,ext));
    }

/***************************************************************************
* CAN_SetLocalMsgFilter - set a local message object filter
*
* This routine sets a local message object filter for incoming messages on a
* particular channel.
*
* If the <ext> parameter is 'TRUE', the mask value applies to extended messages;
* otherwise, the mask value applies to standard messages. A value of 0 for
* a particular bit position of the mask means don't care (for example, the
* incoming message ID could have a value of zero or one for this bit position);
* otherwise, a value of 1 means the corresponding bit of the message ID must
* match identically. Channel number is provided for controllers that have
* more than one local message object filter.
*
* If the controller does not have a local mask for the channel specified,
* an error is returned.
*
*
* RETURNS: 'OK', 'ERROR'.
*
* ERRNO: S_can_illegal_channel_no, S_can_hwfeature_not_available
*
*
*/
STATUS CAN_SetLocalMsgFilter
    (
    struct WNCAN_Device *pDev,      /* CAN device pointer */
    UCHAR                channel,   /* channel number     */
    long                 mask,      /* filter mask value  */
    BOOL                 ext        /* extended flag      */
    )
    {
       return(pDev->SetLocalMsgFilter(pDev,channel,mask,ext));
    }

/***************************************************************************
* CAN_GetLocalMsgFilter - get the specified local filter value
*
* This routine returns the programmed value in the local filter register.
* Based on the value of <ext> passed to the routine, this routine reads the
* appropriate format of the local mask and returns the value in the
* specified extended or standard identifier format. The channel argument
* identifies the local filter associated with the particular channel number.
*
* If the controller does not have a global mask, a value of -1 is returned.
* This is not a valid CAN ID.
*
* RETURNS: Mask, or -1 on error.
*
* ERRNO: S_can_hwfeature_not_available
*
*/
long CAN_GetLocalMsgFilter
    (
    struct WNCAN_Device *pDev,      /* CAN device pointer */
    UCHAR                channel,   /* channel number */
    BOOL                 ext        /* extended flag */
    )
    {
       return(pDev->GetLocalMsgFilter(pDev, channel, ext));
    }

/***************************************************************************
* CAN_GetIntStatus - get the interrupt status of a CAN interrupt
*
* This routine returns the interrupt status on the controller:
*
*    WNCAN_INT_NONE = no interrupt occurred
*    WNCAN_INT_ERROR = bus error
*    WNCAN_INT_TX = interrupt resulting from a CAN transmission
*    WNCAN_INT_RX = interrupt resulting form message reception
*    WNCAN_INT_BUS_OFF = interrupt resulting from bus off condition
*    WNCAN_INT_WAKE_UP = interrupt resulting from controller waking up after
*    being put in sleep mode
*    WNCAN_INT_SPURIOUS = unknown interrupt
*
* NOTE: If the interrupt was caused by the transmission or reception of a
* message, the channel number that generated the interrupt is set; otherwise,
* this value is undefined.

⌨️ 快捷键说明

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