📄 conn.c
字号:
* Function: unsigned char _ConnBusOffErr(void)
*
* PreCondition:
*
* Input: none
*
* Output: unsigned char
*
* Side Effects:
*
* Overview: If a bus-off event has occured then return TRUE
*
* Note: None
********************************************************************/
unsigned char _ConnBusOffErr(void)
{
return(uDNet.BusOffCount == 255);
}
/*********************************************************************
* Function: unsigned char _ConnRxManager(void)
*
* PreCondition: CAN (or other I/O) driver must be ready
*
* Input: none
*
* Output: unsigned char
*
* Side Effects:
*
* Overview: This function handles any received data events
* from the driver and dispaches them to the
* appropriate instance.
*
* Note: This function filters through the identifiers.
* Any messages that cannot be processed are ignored.
* This function also returns true if an event was
* generated in an instance.
********************************************************************/
unsigned char _ConnRxManager(void)
{
//NEAR USINT work;
UINT work;
//If there is data in the rx buffer then process
if (CANIsRxRdy())
{
// Decode the CID (group 2 only, filtering assumed)
work.word = CANGetRxCID() & 0xE0;
switch(work.bytes.LSB)
{
#if SUPPORT_BIT_STROBED
case 0x00:
if (!_rxFlag.bits.strobe && _establishFlags.bits.strobe) {_Conn3RxEvent(); return(3);}
break;
#endif
#if SUPPORT_MULTICAST_POLL
case 0x20:
if (!_rxFlag.bits.multi && _establishFlags.bits.multi) {_Conn5RxEvent(); return(5);}
break;
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
case 0x40:
if (!_rxFlag.bits.cos && _establishFlags.bits.cos) {_Conn4RxEvent(); return(4);}
break;
#endif
case 0x80:
if (!_rxFlag.bits.expl && _existentFlags.bits.expl) {_Conn1RxEvent(); return(1);}
break;
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
case 0xA0:
if (!_rxFlag.bits.poll && _establishFlags.bits.poll) {_Conn2RxEvent(); return(2);}
break;
#endif
case 0xC0:
if (!_rxFlag.bits.uexpl) _Conn6RxEvent(); return(6);
case 0xE0:
if (!_rxFlag.bits.dupid) _Conn7RxEvent(); return(7);
}
CANRead();
return(0);
}
}
/*********************************************************************
* Function: void _ConnTxOpenManager(void)
*
* PreCondition: The connection must be open and available.
*
* Input: none
*
* Output: none
*
* Side Effects:
*
* Overview: If a message is queued from any connection and
* the output buffer is available, then this function
* issues an event to the connection instance queued
* to transmit.
*
* Note: The queue is deserialized to eliminate software
* imposed priority on the messages.
********************************************************************/
void _ConnTxOpenManager(void)
{
//If the tx buffer is open and one or more connections are requesting
//to transmit, then procede to transmit
if (_txFlag.byte && CANIsTxRdy())
{
// Set a new entry point into the loop
_deSer++;
// The use of goto in this section is applied to create
// multiple entry points into a loop. This has the affect
// of removing sequencial priority when supporting multiple
// endpoints on an single serial connection.
if (_deSer == 1) goto _ConnTxOpenManagerJp1;
if (_deSer == 2) goto _ConnTxOpenManagerJp2;
if (_deSer == 3) goto _ConnTxOpenManagerJp3;
if (_deSer == 4) goto _ConnTxOpenManagerJp4;
if (_deSer == 5) goto _ConnTxOpenManagerJp5;
if (_deSer == 6) goto _ConnTxOpenManagerJp6;
if (_deSer == 7) {_deSer = 0; goto _ConnTxOpenManagerJp7;}
_deSer = 0;
while (1)
{
_ConnTxOpenManagerJp1:
if (_txFlag.bits.expl)
{
if (_establishFlags.bits.expl) _Conn1TxOpenEvent();
else _txFlag.bits.expl = 0;
return;
}
else
_ConnTxOpenManagerJp2:
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if (_txFlag.bits.poll)
{
if (_establishFlags.bits.poll) _Conn2TxOpenEvent();
else _txFlag.bits.poll = 0;
return;
}
else
#endif
_ConnTxOpenManagerJp3:
#if SUPPORT_BIT_STROBED
if (_txFlag.bits.strobe)
{
if (_establishFlags.bits.strobe) _Conn3TxOpenEvent();
else _txFlag.bits.strobe = 0;
return;
}
else
#endif
_ConnTxOpenManagerJp4:
#if SUPPORT_COS || SUPPORT_CYCLIC
if (_txFlag.bits.cos)
{
if (_establishFlags.bits.cos) _Conn4TxOpenEvent();
else _txFlag.bits.cos = 0;
return;
}
else
#endif
_ConnTxOpenManagerJp5:
#if SUPPORT_MULTICAST_POLL
if (_txFlag.bits.multi)
{
if (_establishFlags.bits.multi) _Conn5TxOpenEvent();
else _txFlag.bits.multi = 0;
return;
}
else
#endif
_ConnTxOpenManagerJp6:
if (_txFlag.bits.uexpl)
{_Conn6TxOpenEvent(); return;}
else
_ConnTxOpenManagerJp7:
if (_txFlag.bits.dupid)
{_Conn7TxOpenEvent(); return;}
}
}
}
/*********************************************************************
* Function: void _ConnTxManager(void)
*
* PreCondition: This function assumes the connection instance has
* been created (enabled).
*
* Input: none
*
* Output: none
*
* Side Effects:
*
* Overview: If a message has finished transmitting, then the
* initiator is traced and notified about the
* transmission.
*
* Note: None
********************************************************************/
void _ConnTxManager(void)
{
unsigned char instance;
instance = CANIsMsgSent();
// If a message has been transmitted on the bus
// then who transmitted
if (instance)
{
if (instance == 1) {_Conn1TxEvent();}
else
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if (instance == 2) {_Conn2TxEvent();}
else
#endif
#if SUPPORT_BIT_STROBED
if (instance == 3) {_Conn3TxEvent();}
else
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
if (instance == 4) {_Conn4TxEvent();}
else
#endif
#if SUPPORT_MULTICAST_POLL
if (instance == 5) {_Conn5TxEvent();}
else
#endif
if (instance == 6) {_Conn6TxEvent();}
else
if (instance == 7) {_Conn7TxEvent();}
}
}
/*********************************************************************
* Function: void _ConnErrorManager(void)
*
* PreCondition:
*
* Input: none
*
* Output: none
*
* Side Effects:
*
* Overview: This function captures any bus-off errors from
* the driver.
*
* Note: None
********************************************************************/
void _ConnErrorManager(void)
{
//If there is a bus off error then
if (CANIsBusOffError())
{
// Increment the counter up to 255
if (uDNet.BusOffCount < 255) uDNet.BusOffCount++;
}
}
/*********************************************************************
* Function: void _ConnTimeManager(void)
*
* PreCondition: This function must be called periodically
* according to the specified tick rate.
*
* Input: none
*
* Output: none
*
* Side Effects:
*
* Overview: Process timer events.
*
* Note: Each connection manages there own timer.
********************************************************************/
void _ConnTimeManager(void)
{
//Process all timer events
if (_establishFlags.bits.expl) _Conn1TimerEvent();
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if (_establishFlags.bits.poll) _Conn2TimerEvent();
#endif
#if SUPPORT_BIT_STROBED
if (_establishFlags.bits.strobe) _Conn3TimerEvent();
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
if (_establishFlags.bits.cos) _Conn4TimerEvent();
#endif
#if SUPPORT_MULTICAST_POLL
if (_establishFlags.bits.multi) _Conn5TimerEvent();
#endif
}
/*********************************************************************
* Function: void _ConnStateManager(void)
*
* PreCondition:
*
* Input: none
*
* Output: none
*
* Side Effects:
*
* Overview: Synchronize all connection states.
*
* Note: Connection may be deleted.
********************************************************************/
void _ConnStateManager(void)
{
BYTE release;
if (_existentFlags.bits.expl)
{
// Process all stale connections
switch (uConn1.attrib.state)
{
// if conn 1 is deferred and all I/O connections no not exist
// or are timed out then delete all connections
case _STATE_DEFERED_DELETE:
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if (_establishFlags.bits.poll) break;
#endif
#if SUPPORT_BIT_STROBED
if (_establishFlags.bits.strobe) break;
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
if (_establishFlags.bits.cos) break;
#endif
#if SUPPORT_MULTICAST_POLL
if (_establishFlags.bits.multi) break;
#endif
// If the explicit messaging connection has transisioned to
// to non-exixtent then delete all other connections
case _STATE_NON_EXISTENT:
release.byte = uDNet.AllocInfo.AllocChoice.byte;
// Release all allocated connections
_DNetCloseConnections(release);
// Kill all allocated connections
uDNet.AllocInfo.AllocChoice.byte = 0;
uDNet.AllocInfo.MasterMACID = 0xFF;
}
}
}
/*********************************************************************
* Function: unsigned char _ConnExplicitEvent()
*
* PreCondition: This function is called from the router.
*
* Input: none
*
* Output: unsigned char
*
* Side Effects:
*
* Overview: Handle explicit messaging.
*
* Note: None
********************************************************************/
unsigned char _ConnExplMsgHandler(void)
{
if (mRouteGetInstanceID() == 0)
{
switch(mRouteGetServiceID())
{
case SRVS_GET_ATTRIB_SINGLE:
return (_ConnInst0GetAttrib());
default:
mRoutePutError(ERR_SERVICE_NOT_SUPPORTED);
break;
}
}
else
if ((mRouteGetInstanceID() == 1) && _existentFlags.bits.expl)
return(_Conn1ExplicitEvent());
else
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if ((mRouteGetInstanceID() == 2) && _existentFlags.bits.poll)
return(_Conn2ExplicitEvent());
else
#endif
#if SUPPORT_BIT_STROBED
if ((mRouteGetInstanceID() == 3) && _existentFlags.bits.strobe)
return(_Conn3ExplicitEvent());
else
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
if ((mRouteGetInstanceID() == 4) && _existentFlags.bits.cos)
return(_Conn4ExplicitEvent());
else
#endif
#if SUPPORT_MULTICAST_POLL
if ((mRouteGetInstanceID() == 5) && _existentFlags.bits.multi)
return(_Conn5ExplicitEvent());
else
#endif
{
mRoutePutError(ERR_OBJECT_DOES_NOT_EXIST);
}
return (1);
}
/*********************************************************************
* Function: unsigned char _ConnInst0GetAttrib(void)
*
* PreCondition:
*
* Input: none
*
* Output: unsigned char
*
* Side Effects:
*
* Overview: Handle explicit messaging get attribute.
*
* Note: None
********************************************************************/
unsigned char _ConnInst0GetAttrib(void)
{
switch (mRouteGetAttributeID())
{
case _ATTRIB_REVISION:
mRoutePutByte(_CONN_REVISION & 0xFF);
mRoutePutByte((_CONN_REVISION & 0xFF00) >> 8);
break;
default:
mRoutePutError(ERR_ATTRIB_NOT_SUPPORTED);
break;
}
return (1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -