📄 wncan.c
字号:
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 { errnoSet(S_can_rtr_mode_not_supported); retCode = ERROR; } break; case WNCAN_CHN_INVALID: pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_INVALID; break; case WNCAN_CHN_INACTIVE: pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_INACTIVE; break; default: errnoSet(S_can_illegal_config); retCode = ERROR; break; } } return retCode;}/************************************************************************** WNCAN_GetTxChannel - get a free transmit channel** This function 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.** By default, channel is disabled. User must call CAN_EnableChannel, to make the* channel valid in hardware and enable channel interrupts** RETURNS: ERROR if no channels are available, OK otherwise.** ERRNO: S_can_no_available_channels, S_can_chn_in_use**/STATUS WNCAN_GetTxChannel(struct WNCAN_Device *pDev, UCHAR *channelNum){ UCHAR i; STATUS retCode = ERROR; /* assume failure */ for(i = 0; i < pDev->pCtrl->numChn; i++) { if(pDev->pCtrl->chnMode[i] == WNCAN_CHN_INVALID) { if(WNCAN_SetMode(pDev,i,WNCAN_CHN_TRANSMIT) == OK) { *channelNum = i; retCode = OK; return retCode; } } } errnoSet(S_can_no_available_channels); return retCode;}/************************************************************************* WNCAN_GetRxChannel - get a free receive channel.** 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.** By default, channel is disabled. User must call CAN_EnableChannel, to make the* channel valid in hardware and enable channel interrupts** RETURNS: ERROR if no channel is available, OK otherwise.** ERRNO: S_can_no_available_channels**/STATUS WNCAN_GetRxChannel(struct WNCAN_Device *pDev, UCHAR *channelNum){ UCHAR i; STATUS retCode = ERROR; /* assume failure */ for(i = 0; i < pDev->pCtrl->numChn; i++) { if(pDev->pCtrl->chnMode[i] == WNCAN_CHN_INVALID) { if(WNCAN_SetMode(pDev,i,WNCAN_CHN_RECEIVE) == OK) { *channelNum = i; retCode = OK; return retCode; } } } errnoSet(S_can_no_available_channels); return retCode;}/************************************************************************* WNCAN_GetRTRResponderChannel - get a free channel for programming an automatic* response to an incoming remote request** This function 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 function will return an error and set an error number, for simple * controllers such as the SJA1000. In 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 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.** By default, channel is disabled. User must call CAN_EnableChannel, to make the* channel valid in hardware and enable channel interrupts** RETURNS: for advanced controllers such as the TouCAN and I82527:* ERROR if no channels are available, OK otherwise.** 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 WNCAN_GetRTRResponderChannel(struct WNCAN_Device *pDev, UCHAR *channelNum){ UCHAR i; STATUS retCode = ERROR; /* assume failure */ for(i = 0; i < pDev->pCtrl->numChn; i++) { if(pDev->pCtrl->chnMode[i] == WNCAN_CHN_INVALID) { if(pDev->pCtrl->chnType[i] == WNCAN_CHN_TRANSMIT_RECEIVE) { pDev->pCtrl->chnMode[i] = WNCAN_CHN_RTR_RESPONDER; *channelNum = i; retCode = OK; return retCode; } else errnoSet(S_can_rtr_mode_not_supported); } else errnoSet(S_can_no_available_channels); } return retCode;}/************************************************************************* WNCAN_GetRTRRequesterChannel - get a free channel for sending an RTR request* and receiving the response in the same channel ** This function is relevant to advanced controllers only. Advanced controllers, * are controllers such as TouCAN that, have channels with 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 function will return an error* and set an error number, for simple controllers such as the SJA1000. * In 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.** By default, channel is disabled. User must call CAN_EnableChannel, to make the* channel valid in hardware and enable channel interrupts** RETURNS: for advanced controllers such as the TouCAN and I82527:* ERROR if no channels are available, OK otherwise.** 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 WNCAN_GetRTRRequesterChannel(struct WNCAN_Device *pDev, UCHAR *channelNum){ UCHAR i; STATUS retCode = ERROR; /* assume failure */ for(i = 0; i < pDev->pCtrl->numChn; i++) { if(pDev->pCtrl->chnMode[i] == WNCAN_CHN_INVALID) { if(pDev->pCtrl->chnType[i] == WNCAN_CHN_TRANSMIT_RECEIVE) { pDev->pCtrl->chnMode[i] = WNCAN_CHN_RTR_REQUESTER; *channelNum = i; retCode = OK; return retCode; } else errnoSet(S_can_rtr_mode_not_supported); } else errnoSet(S_can_no_available_channels); } return retCode;}/************************************************************************** WNCAN_FreeChannel - free the channel** This routine frees the channel such that a WNCAN_GetTxChannel() or* WNCAN_GetRxChannel() call can use the channel number. The mode of the* channel is set to WNCAN_CHN_INVALID.** RETURNS: OK, or ERROR** ERRNO: S_can_illegal_channel_no**/STATUS WNCAN_FreeChannel(struct WNCAN_Device *pDev, UCHAR channelNum){ STATUS retCode = ERROR; /* assume failure */ if(channelNum >= pDev->pCtrl->numChn) { errnoSet(S_can_illegal_channel_no); return retCode; } pDev->pCtrl->chnMode[channelNum] = WNCAN_CHN_INVALID; retCode =OK; return retCode;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -