?? i82527.c
字號(hào):
else if((pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RECEIVE) && (pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RTR_REQUESTER)) { errnoSet(S_can_illegal_config); } else { /* reset the msg lost bit */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1),0xf7); retCode = OK; } return retCode;}/************************************************************************** I82527_IsRTR - test if the message has the RTR bit set* The RTR bit of an incoming remote request is not stored in the channel* registers on the I82527. CAN_IsRTR cannot be implemented directly. The* TouCAN has an automatic response feature, that must be used to respond * to incoming remote requests.* To do this:* 1. Select channel mode WNCAN_CHN_RTR_RESPONDER * 2. On this channel call CAN_WriteID and set up matching id for incoming* remote request* 3. Set up response data by calling CAN_WriteData** RETURNS: -1 * * ERRNO: S_can_use_auto_response_feature**/static int I82527_IsRTR ( struct WNCAN_Device *pDev, UCHAR channelNum ){ errnoSet(S_can_use_auto_response_feature); return -1;}/************************************************************************** I82527_SetRTR - Sets RTR bit** The TouCAN supports transmitting and receiving a message in the same * channel. The driver supports special channel modes namely * WNCAN_CHN_RTR_REQUESTER and WMCAN_CHN_RTR_RESPONDER to handle setting up* RTR messages easier. * ** RETURNS: ERROR* * ERRNO: S_can_use_rtr_requester_channel_mode**/static STATUS I82527_SetRTR ( struct WNCAN_Device *pDev, UCHAR channelNum, BOOL rtr ){ errnoSet(S_can_use_rtr_requester_channel_mode); return ERROR;}/************************************************************************** I82527_TxAbort - abort the current CAN transmission** This routine aborts any current CAN transmissions on the controller.** RETURNS: N/A* * ERRNO: N/A**/static void I82527_TxAbort ( struct WNCAN_Device *pDev ){ unsigned int i; volatile UCHAR value; for (i = 0; i < I82527_MAX_MSG_OBJ; i++) { if((pDev->pCtrl->chnMode[i] == WNCAN_CHN_TRANSMIT) && ~(pDev->pCtrl->chnMode[i] & WNCAN_IS_CHN_RTR)) { value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * i) + I82527_OFFS_CTRL1)); /*check if TxRqst is set*/ if(value & 0x20) { /*yes, reset TxRqst*/ value |= 0xdf; pDev->pBrd->canOutByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * i) + I82527_OFFS_CTRL1),value); } } } return;}/************************************************************************** I82527_Sleep - put the CAN controller to sleep** This routine puts the CAN controller of the device into sleep mode* if the hardware supports this functionality; otherwise, this function* is a no-op.aborts any current CAN transmissions on the controller** RETURNS: OK always* * ERRNO: N/A**/static STATUS I82527_Sleep ( struct WNCAN_Device *pDev ){ UCHAR value; value = pDev->pBrd->canInByte(pDev, I82527_R_INFR); value |= 0x08; pDev->pBrd->canOutByte(pDev, I82527_R_INFR, value); return OK;}/************************************************************************** I82527_WakeUp - brings CAN controller out of sleep mode** Auto awake feature is always enabled** RETURNS: OK always* * ERRNO: N/A*/static STATUS I82527_WakeUp ( struct WNCAN_Device *pDev ){ volatile UCHAR value; value = pDev->pBrd->canInByte(pDev, I82527_R_INFR); value &= 0xf7; pDev->pBrd->canOutByte(pDev, I82527_R_INFR, value); return OK;}/************************************************************************* I82527_EnableChannel - make channel active** If the mode of the channel is WNCAN_CHN_RECEIVE the channel is ready to* receive messages matching the filter + id combination, when this function* exits.* If the mode of the channel is WNCAN_CHN_RTR_RESPONDER the channel is* ready to receive matching remote requests, when this function exits.* ** RETURNS: OK if successful, ERROR otherwise* * ERRNO: S_can_illegal_channel_no*/static STATUS I82527_EnableChannel ( struct WNCAN_Device *pDev, UCHAR channelNum, WNCAN_IntType useInterrupts ){ STATUS retCode = ERROR; /* pessimistic */ UCHAR value = 0; if (channelNum >= I82527_MAX_MSG_OBJ) { errnoSet(S_can_illegal_channel_no); return retCode; } switch(pDev->pCtrl->chnMode[channelNum]) { case WNCAN_CHN_TRANSMIT: /* mark message object as invalid: MsgVal = 0 1 set tranmit interrupt enable: TXIE = 1 0 reset receive interrrupt enable: RXIE = 0 1 unchanged interrupt pending: IntPnd = 0 1 7 6 5 4 3 2 1 0 MsgVal TXIE RXIE IntPnd */ if(useInterrupts) value = 0x65; else value = 0x55; pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), value); /* reset remote transmission pending: RmtPnd = 0 1 reset transmit request: TxRqst = 0 1 new data unchanged: NewDat = 1 1 set CPU update : CPUUpd = 1 0 7 6 5 4 3 2 1 0 RmtPnd TxRqst NewDat CPUUpd */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1), 0x5e); /* Set direction to transmit */ value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR)); value |= 0x8; pDev->pBrd->canOutByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR),value); /* mark message object as valid: MsgVal = 1 0 */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0xbf); retCode = OK; break; case WNCAN_CHN_RECEIVE: /* mark message object as invalid: MsgVal = 0 1 unset tranmit interrupt enable: TXIE = 0 1 set receive interrrupt enable: RXIE = 1 0 unchanged interrupt pending: IntPnd = 0 1 7 6 5 4 3 2 1 0 MsgVal TXIE RXIE IntPnd */ if(useInterrupts) value = 0x59; else value = 0x55; pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), value); /* reset remote transmission pending: RmtPnd = 0 1 reset transmit request: TxRqst = 0 1 unchanged new data: NewDat = 1 1 reset CPU update: CPUUpd = 0 1 7 6 5 4 3 2 1 0 RmtPnd TxRqst NewDat CPUUpd */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1), 0x5d); /* Set direction to receive */ value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR)); value &= ~0x8; pDev->pBrd->canOutByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR),value); /* mark message object as valid: MsgVal = 1 0 */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0xbf); retCode = OK; break; case WNCAN_CHN_RTR_REQUESTER: /* mark message object as invalid: MsgVal = 0 1 set tranmit interrupt enable: TXIE = 1 0 reset receive interrrupt enable: RXIE = 0 1 unchanged interrupt pending: IntPnd = 0 1 7 6 5 4 3 2 1 0 MsgVal TXIE RXIE IntPnd */ if(useInterrupts == WNCAN_INT_NONE) value |= 0x55; else { if(useInterrupts & WNCAN_INT_TX) value |= 0x65; if(useInterrupts & WNCAN_INT_RX) value |= 0x59; } pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), value); /* reset remote transmission pending: RmtPnd = 0 1 reset transmit request: TxRqst = 0 1 new data unchanged: NewDat = 1 1 set CPU update : CPUUpd = 1 0 7 6 5 4 3 2 1 0 RmtPnd TxRqst NewDat CPUUpd */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1), 0x5e); /* Set direction to receive */ value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR)); value &= ~0x8; pDev->pBrd->canOutByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR),value); /* mark message object as valid: MsgVal = 1 0 */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0xbf); retCode = OK; break; case WNCAN_CHN_RTR_RESPONDER: /* mark message object as invalid: MsgVal = 0 1 set tranmit interrupt enable: TXIE = 1 0 reset receive interrrupt enable: RXIE = 0 1 unchanged interrupt pending: IntPnd = 0 1 7 6 5 4 3 2 1 0 MsgVal TXIE RXIE IntPnd */ if(useInterrupts == WNCAN_INT_NONE) value |= 0x55; else { if(useInterrupts & WNCAN_INT_TX) value |= 0x65; if(useInterrupts & WNCAN_INT_RX) value |= 0x59; } pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), value); /* reset remote transmission pending: RmtPnd = 0 1 reset transmit request: TxRqst = 0 1 new data unchanged: NewDat = 1 1 set CPU update : CPUUpd = 1 0 7 6 5 4 3 2 1 0 RmtPnd TxRqst NewDat CPUUpd */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1), 0x5e); /* Set direction to transmit */ value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR)); value |= 0x8; pDev->pBrd->canOutByte(pDev,(I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR),value); /* mark message object as valid: MsgVal = 1 0 */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0xbf); retCode = OK; break; default: errnoSet(S_can_illegal_config); break; } return retCode;}/************************************************************************** I82527_DisableChannel - make channel inactive* ** RETURNS: OK if successful, ERROR otherwise* * ERRNO: S_can_illegal_channel_no**/static STATUS I82527_DisableChannel( struct WNCAN_Device *pDev, UCHAR channelNum){ STATUS retCode = ERROR; /* pessimistic */ if (channelNum >= I82527_MAX_MSG_OBJ) { errnoSet(S_can_illegal_channel_no); } else { /* mark message object as invalid: MsgVal = 0 1 reset interrupt enable: TXIE = 0 1 reset interrrupt enable: RXIE = 0 1 reset interrupt pending: IntPnd = 0 1 7 6 5 4 3 2 1 0 MsgVal TXIE RXIE IntPnd */ pDev->pBrd->canOutByte(pDev, (I82527_R_XMT + (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0x55); retCode = OK; } return retCode;}/******************************************************************************* I82527_WriteReg - Access hardware register and write data* * This function accesses the CAN controller memory at the offset specified. * A list of valid offsets are defined as macros in a CAN controller specific* header file, named as controllerOffsets.h (e.g. toucanOffsets.h or sja1000Offsets.h)* A pointer to the data buffer holding the data to be written is passed to the* function in UBYTE *data. The number of data bytes to be copied from the data* buffer to the CAN controller's memory area is specified by the length parameter.** RETURNS: OK or ERROR** ERRNO: S_can_illegal_offset**/static STATUS I82527_WriteReg( struct WNCAN_Device *pDev, UINT offset, UCHAR * data, UINT length ){ STATUS retCode = ERROR; UINT i; if((offset + length) > I82527_MAX_OFFSET) { errnoSet(S_can_illegal_
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -