Skip to content

Commit

Permalink
Add task offset calc. helper macro
Browse files Browse the repository at this point in the history
... for `lastRun` struct member.
  • Loading branch information
6arms1leg committed Apr 11, 2022
1 parent 75b80f9 commit f93aff1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions ex-app/TKLtskLst.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ static TKLtyp_tsk_t pv_tskLst[] = {
{.active = true,
.period = 2u * TKLTIMER_1S,
.deadline = 250u * TKLTIMER_1MS,
.lastRun = TKLTIMER_0S - TKLTIMER_1S, /* Offset 1 s */
.lastRun = TKLTYP_CALC_OFFSET(2u * TKLTIMER_1S, TKLTIMER_1S),
/* Offset `0 + 1 s` */
.p_tskRunner = &TKLtsk_blinkRunner},
/* Tsk 1 */
{.active = true,
.period = 2u * TKLTIMER_1S,
.deadline = 250u * TKLTIMER_1MS,
.lastRun = TKLTIMER_0S, /* Offset 2 s */
.lastRun = TKLTIMER_0S, /* Offset `0 + 2 s` */
.p_tskRunner = &TKLtsk_blinkRunner}
};

Expand Down
10 changes: 10 additions & 0 deletions src/TKLtyp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
#include "stdint.h"
#include "stdbool.h"

/**
* \brief Helper to calc. positive offset from `0` for \ref TKLtyp_tsk_t.lastRun
*
* `offset_`, here, specifies time of first task exec.
* `period_` and `offset_` args. must both be of unsigned integer type.
*
* See \ref TKLtyp_tsk_t.lastRun for more details.
*/
#define TKLTYP_CALC_OFFSET(period_, offset_) (0u - (period_) + (offset_))

/** \brief Task runner function signature */
typedef void (* TKLtyp_p_tskRunner_t)(void);

Expand Down
13 changes: 6 additions & 7 deletions test/test_TKLsdlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include "assert.h" /* Sanity checks (Design by Contract); replaced for unit
testing */

Expand Down Expand Up @@ -424,17 +423,17 @@ void test_TKLsdlr_saturateTskOverrun(void) {
{.active = true,
.period = 100u,
.deadline = 10u,
.lastRun = 0u - 100u, /* Offset 0 */
.lastRun = TKLTYP_CALC_OFFSET(100u, 0u),
.p_tskRunner = &TKLtsk_runner}
};
const uint8_t overrunExp = UCHAR_MAX; /* Saturated task overrun count */
const uint8_t overrunExp = UINT8_MAX; /* Saturated task overrun count */

TKLsdlr_setTickSrc(&TKLtick_getTick);
TKLsdlr_setTskLst(tskLst, 1u);

/* Run more scheduler exec. cycles with task overruns than task deadline
overrun counter can hold so it gets saturated */
for (uint16_t i = 0u; i < UCHAR_MAX + 3u; i++) {
for (uint16_t i = 0u; i < UINT8_MAX + 3u; i++) {
/* Task overruns */
TKLtick_getTick_ExpectAndReturn(tskLst[0].period * i);
TKLtsk_runner_Expect();
Expand Down Expand Up @@ -754,19 +753,19 @@ void test_TKLsdlr_execDueToRunTskAtDiffPeriodAndOffsetOn0TickStart(void) {
{.active = true,
.period = 30u,
.deadline = 30u,
.lastRun = 0u - 20u, /* Offset `20` */
.lastRun = TKLTYP_CALC_OFFSET(30u, 10u),
.p_tskRunner = &TKLtsk_runner0},
/* Run at: `30`, `70`, `110`, ... */
{.active = true,
.period = 40u,
.deadline = 40u,
.lastRun = 0u - 10u, /* Offset `10` */
.lastRun = TKLTYP_CALC_OFFSET(40u, 30u),
.p_tskRunner = &TKLtsk_runner1},
/* Run at: `90`, `180`, ... */
{.active = true,
.period = 90u,
.deadline = 90u,
.lastRun = 0u, /* No offset (`0`) */
.lastRun = 0u, /* Offset `0 + 90` */
.p_tskRunner = &TKLtsk_runner2}
};

Expand Down

0 comments on commit f93aff1

Please sign in to comment.