mirror of https://github.com/rusefi/openblt.git
Refs #316. Completed the XCP on CAN transport layer implementation.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@317 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
9137744377
commit
d858aaa856
|
@ -40,10 +40,10 @@
|
|||
* Local data declarations
|
||||
****************************************************************************************/
|
||||
/** \brief Flag to determine if the critical section object was already initialized. */
|
||||
static volatile bool criticalSectionInitialized = false;
|
||||
static bool criticalSectionInitialized = false;
|
||||
|
||||
/** \brief Crital section nesting counter. ***/
|
||||
static volatile uint32_t criticalSectionNesting;
|
||||
static uint32_t criticalSectionNesting;
|
||||
|
||||
/** \brief Critical section object. */
|
||||
static pthread_mutex_t mtxCritSect;
|
||||
|
|
|
@ -40,13 +40,13 @@
|
|||
* Local data declarations
|
||||
****************************************************************************************/
|
||||
/** \brief Flag to determine if the critical section object was already initialized. */
|
||||
static volatile bool criticalSectionInitialized = false;
|
||||
static bool criticalSectionInitialized = false;
|
||||
|
||||
/** \brief Crital section nesting counter. ***/
|
||||
static volatile uint32_t criticalSectionNesting;
|
||||
static uint32_t criticalSectionNesting;
|
||||
|
||||
/** \brief Critical section object. */
|
||||
static volatile CRITICAL_SECTION criticalSection;
|
||||
static CRITICAL_SECTION criticalSection;
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
|
|
|
@ -87,6 +87,18 @@ static const tCanEvents canEvents =
|
|||
/** \brief The settings to use in this transport layer. */
|
||||
static tXcpTpCanSettings tpCanSettings;
|
||||
|
||||
/** \brief Flag to indicate that a response packet was received via CAN. Made volatile
|
||||
* because it is shared with an event callback function that could be called from
|
||||
* a different thread.
|
||||
*/
|
||||
static volatile bool tpCanResponseMessageReceived;
|
||||
|
||||
/** \brief Buffer for storing the CAN message with response packet data. Made volatile
|
||||
* because it is shared with an event callback function that could be called from
|
||||
* a different thread.
|
||||
*/
|
||||
static volatile tCanMsg tpCanResponseMessage;
|
||||
|
||||
|
||||
/***********************************************************************************//**
|
||||
** \brief Obtains a pointer to the transport layer structure, so that it can be
|
||||
|
@ -306,6 +318,14 @@ static bool XcpTpCanSendPacket(tXcpTransportPacket const * txPacket,
|
|||
{
|
||||
canMsg.data[idx] = txPacket->data[idx];
|
||||
}
|
||||
/* Enter critical section. */
|
||||
UtilCriticalSectionEnter();
|
||||
/* Reset packet received flag before transmitting the packet, to be able to detect
|
||||
* its response packet.
|
||||
*/
|
||||
tpCanResponseMessageReceived = false;
|
||||
/* Exit critical section. */
|
||||
UtilCriticalSectionExit();
|
||||
/* Submit the packet for transmission on the CAN bus. */
|
||||
if (!CanTransmit(&canMsg))
|
||||
{
|
||||
|
@ -321,9 +341,36 @@ static bool XcpTpCanSendPacket(tXcpTransportPacket const * txPacket,
|
|||
*/
|
||||
while (UtilTimeGetSystemTimeMs() < responseTimeoutTime)
|
||||
{
|
||||
/* ##Vg TODO Implement packet reception. */
|
||||
break;
|
||||
/* Enter critical section. */
|
||||
UtilCriticalSectionEnter();
|
||||
/* Response received? */
|
||||
if (tpCanResponseMessageReceived)
|
||||
{
|
||||
/* Copy the response packet. */
|
||||
rxPacket->len = tpCanResponseMessage.dlc;
|
||||
for (uint8_t idx = 0; idx < rxPacket->len; idx++)
|
||||
{
|
||||
rxPacket->data[idx] = tpCanResponseMessage.data[idx];
|
||||
}
|
||||
/* Exit critical section. */
|
||||
UtilCriticalSectionExit();
|
||||
/* Response packet receive so no need to continue loop. */
|
||||
break;
|
||||
}
|
||||
/* Exit critical section. */
|
||||
UtilCriticalSectionExit();
|
||||
/* Wait a little bit to not starve the CPU. */
|
||||
UtilTimeDelayMs(1);
|
||||
}
|
||||
/* Enter critical section. */
|
||||
UtilCriticalSectionEnter();
|
||||
/* Check if a timeout occurred and no response was received. */
|
||||
if (!tpCanResponseMessageReceived)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
/* Exit critical section. */
|
||||
UtilCriticalSectionExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +411,19 @@ static void XcpTpCanEventMessageReceived(tCanMsg const * msg)
|
|||
/* Check if the identifier matches the one for XCP on CAN. */
|
||||
if (msg->id == tpCanRxId)
|
||||
{
|
||||
/* ##Vg TODO process CAN message reception. */
|
||||
/* Enter critical section. */
|
||||
UtilCriticalSectionEnter();
|
||||
/* Copy to the packet response message buffer. */
|
||||
tpCanResponseMessage.id = msg->id;
|
||||
tpCanResponseMessage.dlc = msg->dlc;
|
||||
for (uint8_t idx = 0; idx < msg->dlc; idx++)
|
||||
{
|
||||
tpCanResponseMessage.data[idx] = msg->data[idx];
|
||||
}
|
||||
/* Set packet received flag. */
|
||||
tpCanResponseMessageReceived = true;
|
||||
/* Exit critical section. */
|
||||
UtilCriticalSectionExit();
|
||||
}
|
||||
} /*** end of XcpTpCanEventMessageReceived ***/
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue