Skip to content

Commit

Permalink
Legacy ETH boards has support for earlier TX of CAN frames (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoaccame authored May 22, 2024
1 parent 3c5a938 commit 5ad3d2b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - #define with internal scope
// --------------------------------------------------------------------------------------------------------------------
// empty-section

// if defined, the CAN flush is done at end of the DO phase, else at the beginning of the TX phase
// #define CANflushMODE_DO_phase


// --------------------------------------------------------------------------------------------------------------------
Expand All @@ -85,8 +86,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - declaration of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission();
static void waitforCANisflushed(const eOreltime_t timeout);

// --------------------------------------------------------------------------------------------------------------------
// - definition (and initialisation) of static variables
Expand Down Expand Up @@ -154,17 +156,22 @@ extern void eom_emsrunner_hid_userdef_taskDO_activity(EOMtheEMSrunner *p)
// TODO: see if i can move all the _Tick() in the do phase.

// eo_ethmonitor_Tick(eo_ethmonitor_GetHandle()); // if we do it in here, then in eb2/eb4 it warns about execution time overflow

#if defined(CANflushMODE_DO_phase)
flushCANtransmission();
#else
// we flush elsewhere
#endif
}


extern void eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission(EOMtheEMSrunner *p)
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;

eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);

eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
#if defined(CANflushMODE_DO_phase)
// we flush elsewhere
#else
flushCANtransmission();
#endif
}


Expand All @@ -191,9 +198,9 @@ extern void eom_emsrunner_hid_userdef_taskTX_activity_afterdatagramtransmission(



// ABSOLUTELY KEEP IT LAST: wait until can tx started by eo_canserv_TXstartAll() in eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission() is all done
const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
// ABSOLUTELY KEEP IT LAST: wait until can tx started by flushCANtransmission() is all done
static const eOreltime_t timeout = 3*EOK_reltime1ms;
waitforCANisflushed(timeout);

return;
}
Expand Down Expand Up @@ -226,8 +233,21 @@ extern void eom_emsrunner_hid_userdef_onemstransceivererror(EOMtheEMStransceiver
// --------------------------------------------------------------------------------------------------------------------
// - definition of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission()
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;
eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);
eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
}

static void waitforCANisflushed(const eOreltime_t timeout)
{
// it lock the thread TX until all CAN frame has exited the board
// const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
}


// --------------------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - #define with internal scope
// --------------------------------------------------------------------------------------------------------------------
// empty-section

// if defined, the CAN flush is done at end of the DO phase, else at the beginning of the TX phase
// #define CANflushMODE_DO_phase


// --------------------------------------------------------------------------------------------------------------------
Expand All @@ -82,7 +84,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - declaration of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission();
static void waitforCANisflushed(const eOreltime_t timeout);

// --------------------------------------------------------------------------------------------------------------------
// - definition (and initialisation) of static variables
Expand All @@ -92,7 +96,7 @@
// --------------------------------------------------------------------------------------------------------------------
// - definition of extern public functions
// --------------------------------------------------------------------------------------------------------------------

// empty-section


// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -141,20 +145,26 @@ extern void eom_emsrunner_hid_userdef_taskDO_activity(EOMtheEMSrunner *p)
// TODO: see if i can move all the _Tick() in the do phase.

// eo_ethmonitor_Tick(eo_ethmonitor_GetHandle()); // if we do it in here, then in eb2/eb4 it warns about execution time overflow

#if defined(CANflushMODE_DO_phase)
flushCANtransmission();
#else
// we flush elsewhere
#endif
}


extern void eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission(EOMtheEMSrunner *p)
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;

eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);

eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
#if defined(CANflushMODE_DO_phase)
// we flush elsewhere
#else
flushCANtransmission();
#endif
}



extern void eom_emsrunner_hid_userdef_taskTX_activity_afterdatagramtransmission(EOMtheEMSrunner *p)
{
eObool_t prevTXhadRegulars = eom_emsrunner_CycleHasJustTransmittedRegulars(eom_emsrunner_GetHandle());
Expand All @@ -172,9 +182,9 @@ extern void eom_emsrunner_hid_userdef_taskTX_activity_afterdatagramtransmission(



// ABSOLUTELY KEEP IT LAST: wait until can tx started by eo_canserv_TXstartAll() in eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission() is all done
const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
// ABSOLUTELY KEEP IT LAST: wait until can tx started by flushCANtransmission() is all done
static const eOreltime_t timeout = 3*EOK_reltime1ms;
waitforCANisflushed(timeout);

return;
}
Expand Down Expand Up @@ -209,7 +219,21 @@ extern void eom_emsrunner_hid_userdef_onemstransceivererror(EOMtheEMStransceiver
// --------------------------------------------------------------------------------------------------------------------
// - definition of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission()
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;
eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);
eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
}

static void waitforCANisflushed(const eOreltime_t timeout)
{
// it lock the thread TX until all CAN frame has exited the board
// const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
}


// --------------------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - #define with internal scope
// --------------------------------------------------------------------------------------------------------------------
// empty-section

// if defined, the CAN flush is done at end of the DO phase, else at the beginning of the TX phase
// #define CANflushMODE_DO_phase


// --------------------------------------------------------------------------------------------------------------------
Expand All @@ -84,7 +86,9 @@
// --------------------------------------------------------------------------------------------------------------------
// - declaration of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission();
static void waitforCANisflushed(const eOreltime_t timeout);

// --------------------------------------------------------------------------------------------------------------------
// - definition (and initialisation) of static variables
Expand All @@ -94,7 +98,7 @@
// --------------------------------------------------------------------------------------------------------------------
// - definition of extern public functions
// --------------------------------------------------------------------------------------------------------------------

// empty-section


// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -151,20 +155,26 @@ extern void eom_emsrunner_hid_userdef_taskDO_activity(EOMtheEMSrunner *p)
// TODO: see if i can move all the _Tick() in the do phase.

// eo_ethmonitor_Tick(eo_ethmonitor_GetHandle()); // if we do it in here, then in eb2/eb4 it warns about execution time overflow

#if defined(CANflushMODE_DO_phase)
flushCANtransmission();
#else
// we flush elsewhere
#endif
}


extern void eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission(EOMtheEMSrunner *p)
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;

eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);

eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
#if defined(CANflushMODE_DO_phase)
// we flush elsewhere
#else
flushCANtransmission();
#endif
}



extern void eom_emsrunner_hid_userdef_taskTX_activity_afterdatagramtransmission(EOMtheEMSrunner *p)
{
eObool_t prevTXhadRegulars = eom_emsrunner_CycleHasJustTransmittedRegulars(eom_emsrunner_GetHandle());
Expand All @@ -182,9 +192,9 @@ extern void eom_emsrunner_hid_userdef_taskTX_activity_afterdatagramtransmission(



// ABSOLUTELY KEEP IT LAST: wait until can tx started by eo_canserv_TXstartAll() in eom_emsrunner_hid_userdef_taskTX_activity_beforedatagramtransmission() is all done
const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
// ABSOLUTELY KEEP IT LAST: wait until can tx started by flushCANtransmission() is all done
static const eOreltime_t timeout = 3*EOK_reltime1ms;
waitforCANisflushed(timeout);

return;
}
Expand Down Expand Up @@ -219,7 +229,21 @@ extern void eom_emsrunner_hid_userdef_onemstransceivererror(EOMtheEMStransceiver
// --------------------------------------------------------------------------------------------------------------------
// - definition of static functions
// --------------------------------------------------------------------------------------------------------------------
// empty-section

static void flushCANtransmission()
{
uint8_t txcan1frames = 0;
uint8_t txcan2frames = 0;
eo_canserv_TXstartAll(eo_canserv_GetHandle(), &txcan1frames, &txcan2frames);
eom_emsrunner_Set_TXcanframes(eom_emsrunner_GetHandle(), txcan1frames, txcan2frames);
}

static void waitforCANisflushed(const eOreltime_t timeout)
{
// it lock the thread TX until all CAN frame has exited the board
// const eOreltime_t timeout = 3*EOK_reltime1ms;
eo_canserv_TXwaitAllUntilDone(eo_canserv_GetHandle(), timeout);
}


// --------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 5ad3d2b

Please sign in to comment.