?? wncan.c
字號:
/* wnCAN.c - implementation of Windnet CAN Interface */
/* Copyright 2001 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,06oct05,lsg fix warning
09nov01,dnb modified for integration into Tornado
12jul01,jac written
*/
/*
DESCRIPTION
This file contains the functions that implement the interface defined in the
wnCAN.h header file.
*/
/* includes */
#include <vxWorks.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/canBoard.h>
#include <CAN/canController.h>
#include <CAN/canFixedLL.h>
/* global variables */
const static WNCAN_VersionInfo info = {1,3};
/************************************************************************
*
* WNCAN_GetVersion - return current major and minor revision
*
*
* RETURNS:pointer to WNCAN_VersionInfo
*
* ERRNO: N/A
*
*/
const WNCAN_VersionInfo *WNCAN_GetVersion(void)
{
return &info;
}
/************************************************************************
*
* defaultISRCallBack - do nothing but return
*
* The default ISR callback serves as a placeholder and does nothing
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*/
static void defaultISRCallback
(
WNCAN_DEVICE *pDev,
WNCAN_IntType stat,
UCHAR chnNum)
{
return;
}
/************************************************************************
*
* establishLinks - initialize function pointers in the Device structure
*
* This routine connects the function pointers in the CAN_Device
* data structure to the appropriate routines.
*
* RETURNS: OK or ERROR
*
* ERRNO: S_can_invalid_parameter
*
*/
STATUS CAN_DEVICE_establishLinks
(
WNCAN_DEVICE *pDev,
WNCAN_BoardType brdType,
WNCAN_ControllerType ctrlType
)
{
STATUS retCode = OK;
/* check for null pointer */
if(pDev == 0)
{
errnoSet(S_can_invalid_parameter);
retCode = ERROR;
}
else
{
/* save board and controller types */
pDev->pCtrl->ctrlType = ctrlType;
pDev->pBrd->brdType = brdType;
/* establish controller links */
retCode = WNCAN_Controller_establishLinks(pDev, ctrlType);
/* establish board links */
retCode = WNCAN_Board_establishLinks(pDev, brdType);
/* set default isr callback */
pDev->pISRCallback = defaultISRCallback;
}
return retCode;
}
/************************************************************************
*
* CAN_InstallISRCallback - initialize ISR callback
*
* RETURNS: OK or ERROR
*
* ERRNO: S_can_invalid_parameter
*
*/
STATUS CAN_InstallISRCallback
(
struct WNCAN_Device *pDev,
void (*pFun)(struct WNCAN_Device *pDev2,WNCAN_IntType
intStatus, UCHAR channelNum)
)
{
if(!pDev || !pFun)
{
errnoSet(S_can_invalid_parameter);
return ERROR;
}
else
pDev->pISRCallback = pFun;
return OK;
}
/************************************************************************
*
* WNCAN_Open - return a handle to the requested WNCAN_DEVICE
*
* RETURNS: pointer to valid WNCAN_DEVICE, or 0 if an error occurred
*
* ERRNO: N/A
*
*/
struct WNCAN_Device *WNCAN_Open
(
unsigned int brdType,
unsigned int brdNdx,
unsigned int ctrlNdx
)
{
return WNCAN_Board_Open(brdType, brdNdx, ctrlNdx);
}
/************************************************************************
*
* WNCAN_Close - close the handle to the requested WNCAN_DEVICE
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*/
void WNCAN_Close
(
struct WNCAN_Device *pDev
)
{
if(pDev != NULL)
WNCAN_Board_Close(pDev);
return;
}
/************************************************************************
*
* WNCAN_GetMode - get the channel mode
*
* This routine returns the mode of the channel.
*
* RETURNS: the channel mode
*
* ERRNO: N/A
*
*/
WNCAN_ChannelMode WNCAN_GetMode(struct WNCAN_Device *pDev, UCHAR chn)
{
WNCAN_ChannelMode cm = WNCAN_CHN_INVALID;
if(chn < pDev->pCtrl->numChn)
cm = pDev->pCtrl->chnMode[chn];
return cm;
}
/************************************************************************
* WNCAN_SetMode - set the mode of the channel.
*
* This function sets the mode of the channel to one of five values:
* WNCAN_CHN_TRANSMIT, WNCAN_CHN_RECEIVE, WNCAN_CHN_INACTIVE,
* and in addition for advanced controllers,
* WNCAN_CHN_RTR_REQUESTER, or WNCAN_CHN_RTR_RESPONDER.
* All available channels can be configured to be WNCAN_CHN_INACTIVE.
* The channels available for transmitting or receiving messages are
* determined by the device hardware, and therefore ,may or may not be
* configurable with this function call. If an attempt is made to set the mode
* of a channel to WNCAN_CHN_RTR_RESPONDER or WNCAN_CHN_RTR_REQUESTER for a
* simple CAN controller such as SJA1000, WNCAN_CHN_INVALID is returned and an
* and errorno is set to reflect the error.
* The preferred approach is to allow the device driver to manage the channels
* internally using the CAN_GetTxChannel(), CAN_GetRxChannel(),
* CAN_GetRTRRequesterChannel(), CAN_GetRTRResponderChannel() and
* CAN_FreeChannel() function calls.
*
* WNCAN_SetMode, does not affect channel setting in hardware.
*
* RETURNS: ERROR if the requested channel number is out of range,
* OK otherwise
*
* ERRNO: S_can_illegal_channel_no
*
*/
STATUS WNCAN_SetMode(struct WNCAN_Device *pDev, UCHAR channelNum,
WNCAN_ChannelMode mode)
{
STATUS retCode = OK;
if(channelNum >= pDev->pCtrl->numChn)
{
errnoSet(S_can_illegal_channel_no);
retCode = ERROR;
}
else
{
switch(mode)
{
case WNCAN_CHN_TRANSMIT:
if((pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_TRANSMIT) ||
(pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_TRANSMIT_RECEIVE))
{
pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_TRANSMIT;
}
else
{
errnoSet(S_can_illegal_config);
retCode = ERROR;
}
break;
case WNCAN_CHN_RECEIVE:
if((pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_RECEIVE) ||
(pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_TRANSMIT_RECEIVE))
{
pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_RECEIVE;
}
else
{
errnoSet(S_can_illegal_config);
retCode = ERROR;
}
break;
case WNCAN_CHN_RTR_REQUESTER:
/* The hardware type of the channel will be transmit and receive only
in advanced controllers such as TouCAN and I82527 */
if(pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_TRANSMIT_RECEIVE)
{
pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_RTR_REQUESTER;
}
else
{
errnoSet(S_can_rtr_mode_not_supported);
retCode = ERROR;
}
break;
case WNCAN_CHN_RTR_RESPONDER:
/* The hardware type of the channel will be transmit and receive only
in advanced controllers such as TouCAN and I82527 */
if(pDev->pCtrl->chnType[channelNum] == WNCAN_CHN_TRANSMIT_RECEIVE)
{
pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_RTR_RESPONDER;
}
else
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -