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

📄 can_api.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 4 页
字号:
* is called, then the CAN controller will be online when the
* routine exits.
*
* <tseg1> and <tseg2> are interpreted according to controller specific
* definitions and, therefore, can be written to directly using this routine.
* In all supported controllers, <tseg2> refers to the segment of bit time
* after the sample point. However, <tseg1> interpretations vary.
*
* In some controllers <tseg1> refers to the segment of bit time from the
* end of the sync segment, up to the sample point. Bit time = 1 + (<tseg1> + 1)
* + (<tseg2> + 1) time quanta.
*
*
* \ss
*  ---------------------------------------------------------
* |sync|<-------tseg1------>|<---------tseg2 -------------->|
*                         sample
*                         point
* \se
*
* For other controllers, <tseg1> refers to the segment of bit time after the
* end of propseg and up to the sample point. Bit time = 1 + (propseg + 1)
* + (<tseg1> + 1) + (<tseg2> + 1) time quanta.
*
*
* \ss
*  ---------------------------------------------------------
* |sync|<--propseg-->|<--tseg1-->|<---------tseg2 --------->|
*                              sample
*                              point
* \se
*
* There is a controller specific function provided to set the propseg of
* these controllers (see TouCAN_SetPropseg(), for example). Also, there
* will be a place holder for the propseg (with the other bit timing
* parameters) in the CAN controller struct.
*
* For TouCAN the default value of propseg is 7.
*
* The number of samples taken at the sample point is decided by the input
* argument <numSamples> to the function. <numSamples> = 0 ('FALSE') indicates
* one sample will be taken. <numSamples> = 1 ('TRUE') indicates three samples
* will be taken.
*
* RETURNS: 'OK', or 'ERROR' if any of the input parameters have invalid values.
*
* ERRNO:   S_can_invalid_parameter
*/
STATUS  CAN_SetBitTiming
    (
    struct WNCAN_Device *pDev,      /* CAN device pointer */
    UCHAR                tseg1,     /* number of time quanta for segment 1 */
    UCHAR                tseg2,     /* number of time quanta for segment 2 */
    UCHAR                brp,       /* baud rate prescaler */
    UCHAR                sjw,       /* syncro jump width */
    BOOL                 numSamples /* number of samples */
    )
    {
       return (pDev->SetBitTiming(pDev,tseg1,tseg2,brp,sjw, numSamples));
    }

/***************************************************************************
* CAN_GetBaudRate - get the programmed baud rate value
*
* This routine returns the programmed baud rate value in bits per second.
* The sample point value is returned by reference in the input parameter
* <samplePoint>. The sample point value is returned as a percentage.
* It is the percentage of the bit time at which the bit is sampled.
*
* RETURNS: The baud rate.
*
* ERRNO:   N/A
*/
UINT CAN_GetBaudRate
    (
    struct WNCAN_Device *pDev, /* CAN device pointer */
    UINT                *samplePoint
    )
    {
        return (pDev->GetBaudRate(pDev, samplePoint));
    }

/***************************************************************************
* CAN_SetIntMask - enable controller level interrupts on the CAN device
*
* This routine enables the specified list of controller level interrupts
* on the CAN controller. Interrupts are not enabled at the CAN board level
* or at the CPU level.
*
* The interrupt masks available are:
*
* \ml
* \m -
* WNCAN_INT_ERROR : Enables interrupts due to errors on the CAN bus.
* This may be implemented as a single or multiple interrupt source on the
* CAN controller.
* \m -
* WNCAN_INT_BUS_OFF: Enables interrupt indicating bus off condition.
* \m -
* WNCAN_INT_WAKE_UP: Enables interrupt on wake up.
* \me
*
*
* In order to be set, all interrupt masks that need to be enabled must be
* specified in the list passed to the routine every time the routine is
* called.
*
* RETURNS: 'OK', or 'ERROR' if interrupt setting not possible.
*
* ERRNO: S_can_hwfeature_not_available, S_can_invalid_parameter
*/
STATUS CAN_SetIntMask
    (
    struct WNCAN_Device *pDev,         /* CAN Device pointer */
    WNCAN_IntType        intMask       /* \'OR\'ed interrupt masks */
    )
    {
       STATUS status;
       status = pDev->SetIntMask(pDev, intMask);
       return (status);
    }

/***************************************************************************
* CAN_EnableInt - enable interrupts from the CAN device to the CPU
*
* This routine enables interrupts from the CAN controller to reach the
* CPU. Typically, it enables a global interrupt mask bit at the CPU level.
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void CAN_EnableInt
    (
    struct WNCAN_Device *pDev  /* CAN Device pointer */
    )
    {
       pDev->EnableInt(pDev);
       return;
    }

/***************************************************************************
* CAN_DisableInt - disable interrupts from the CAN device to the CPU
*
* This routine disables interrupts from the CAN controller from reaching the
* CPU. Typically, it disables a global interrupt mask bit at the CPU level.
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void CAN_DisableInt
    (
    struct WNCAN_Device *pDev  /* CAN Device pointer */
    )
    {
       pDev->DisableInt(pDev);
       return;
    }

/***************************************************************************
* CAN_GetNumChannels - get the number of channels on the CAN controller
*
* This routine returns the number of channels on the controller.
* This number is fixed by the hardware and does not change during operation.
*
* RETURNS: The number of channels on the controller.
*
* ERRNO: N/A
*/
UCHAR CAN_GetNumChannels
    (
    struct WNCAN_Device *pDev     /* CAN Device pointer */
    )
    {
       return(pDev->pCtrl->numChn);
    }

/***************************************************************************
* CAN_GetTxChannel - get a free transmit channel
*
* This routine returns a free channel uniquely identified by the output
* argument <channelNum>. The mode of the assigned channel is
* WNCAN_CHN_TRANSMIT. A subsequent call to CAN_GetTxChannel() assigns the
* next available channel with a different channel number.
* The channel number remains unavailable to subsequent CAN_GetXXChannel()
* calls until a CAN_FreeChannel() call is invoked on the channel.
* CAN_FreeChannel() makes the channel available and resets the mode to
* WNCAN_CHN_INVALID. After the CAN_GetTxChannel() call, the mode of
* the channel can be changed by the CAN_SetMode() function call.
*
* RETURNS:  'OK', or 'ERROR' if no channels are available.
*
* ERRNO: S_can_no_available_channels
*/
STATUS CAN_GetTxChannel
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR               *channelNum  /* channel number */
    )
    {
       return(WNCAN_GetTxChannel(pDev,channelNum));
    }

/***************************************************************************
* CAN_GetRxChannel - get a free receive channel
*
* This routine gets a free receive channel uniquely identified by the output
* argument <channelNum>. The mode of the assigned channel is
* WNCAN_CHN_RECEIVE. A subsequent call to CAN_GetRxChannel() assigns the
* next available receive channel with a different number. The channel number
* remains unavailable to subsequent CAN_GetXXChannel() calls until a
* CAN_FreeChannel() call is invoked on the channel. CAN_FreeChannel() makes
* the channel available and resets the mode to WNCAN_CHN_INVALID. After the
* CAN_GetRxChannel() call, the mode of the channel can be changed by the
* CAN_SetMode() function call.
*
* RETURNS: 'OK', or 'ERROR' if no channel is available.
*
* ERRNO: S_can_no_available_channels
*/
STATUS CAN_GetRxChannel
    (
    struct WNCAN_Device *pDev,        /* CAN device pointer */
    UCHAR               *channelNum   /* channel number */
    )
    {
       return(WNCAN_GetRxChannel(pDev,channelNum));
    }

/*****************************************************************************
* CAN_GetRTRRequesterChannel - get a free channel for remote transmit receive
*
* This routine is relevant to advanced controllers only. Advanced controllers
* are controllers, such as TouCAN, whose channels have the capability in
* hardware to both transmit and receive a message in the same channel.
* When a remote request is sent out from a particular channel, the reply
* will be received in the same channel. This routine will return an error
* and set an error number for simple controllers, such as the SJA1000.
* In the case of simple controllers, the channels do not have the capability
* to both transmit and receive messages in the same channel. The channel has a
* fixed property of either transmitting or receiving a message.
*
* This function returns a free channel uniquely identified by the output
* argument <channelNum>. The mode of the channel is assigned
* WNCAN_CHN_RTR_REQUESTER. A subsequent call to CAN_GetRTRRequesterChannel()
* assigns the next available channel with a different channel number.
* The channel number remains unavailable to subsequent CAN_GetXXChannel()
* calls until a CAN_FreeChannel() call is invoked on the channel.
* CAN_FreeChannel() makes the channel available and resets the mode to
* WNCAN_CHN_INVALID. After the CAN_GetRTRRequesterChannel() call, the mode of
* the channel can be changed by the CAN_SetMode() function call.
*
* RETURNS:  For advanced controllers, such as the TouCAN and I82527:
* 'OK', or 'ERROR' if no channels are available.
*
* For simple controllers, such as the SJA1000: 'ERROR' since this mode cannot
* be assigned.
*
* ERRNO: For advanced controllers, such as the TouCAN and I82527:
* S_can_no_available_channels
*
* For simple controllers, such as the SJA1000: S_can_rtr_mode_not_supported
*/
STATUS CAN_GetRTRRequesterChannel
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR               *channelNum  /* channel number */
    )
    {
       return(WNCAN_GetRTRRequesterChannel(pDev,channelNum));
    }

/******************************************************************************
* CAN_GetRTRResponderChannel - get a free channel for an automatic remote response
*
* This routine is relevant to advanced controllers only. Advanced controllers
* are controllers, such as TouCAN, whose channels have the capability in
* hardware to both transmit and receive a message in the same channel.
* An WNCAN_CHN_RTR_RESPONDER channel, can be programmed with data and ID.
* If a matching remote request is received in the channel, the hardware will
* automatically respond with the programmed data.
*
* This routine will return an error and set an error number for simple
* controllers, such as the SJA1000. In the case of simple controllers, the
* channels do not have the capability to both transmit and receive messages
* in the same channel. The channel has a fixed property of either transmitting
* or receiving a message.
*
* This routine returns a free transmit-receive channel uniquely identified by
* the output argument <channelNum>. The mode assigned to the channel is
* WNCAN_CHN_RTR_RESPONDER. A subsequent call to CAN_GetRTRResponderChannel()
* assigns the next available channel with a different channel number.
* The channel number remains unavailable to subsequent CAN_GetXXChannel() and
* calls until a CAN_FreeChannel() call is invoked on the channel.
* CAN_FreeChannel() makes the channel available and resets the mode to
* WNCAN_CHN_INVALID. After the CAN_GetRTRResponderChannel() call, the mode of
* the channel can be changed by the CAN_SetMode() function call.
*
* RETURNS:  For advanced controllers, such as the TouCAN and I82527:
* 'OK', or 'ERROR' if no channels are available.
*
* For simple controllers, such as the SJA1000: 'ERROR' since this mode cannot
* be assigned.
*
* ERRNO:  For advanced controllers, such as the TouCAN and I82527:
* S_can_no_available_channels
*
* For simple controllers, such as the SJA1000: S_can_rtr_mode_not_supported
*
*/
STATUS CAN_GetRTRResponderChannel
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer */
    UCHAR               *channelNum  /* channel number */
    )
    {
       return(WNCAN_GetRTRResponderChannel(pDev,channelNum));
    }

/***************************************************************************
* CAN_FreeChannel - free the specified channel
*
* This routine frees a channel by setting its mode to WNCAN_CHN_INVALID.
*
* RETURNS: 'OK', or 'ERROR' if requested channel is out of range.
*
* ERRNO: S_can_illegal_channel_no
*/
STATUS CAN_FreeChannel
    (
    struct WNCAN_Device *pDev,       /* CAN device pointer   */
    UCHAR                channelNum  /* channelNum           */
    )
    {
       return(WNCAN_FreeChannel(pDev,channelNum));
    }

/************************************************************************
* CAN_GetVersion - get the version number of the CAN drivers
*
* This routine returns a pointer to the struct WNCAN_VersionInfo,
* which holds the WIND NET CAN API's version number.

⌨️ 快捷键说明

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