RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_cycle_ticks.c
Go to the documentation of this file.
1
5#include "ab_gp_cycle_ticks.h"
6
7#include <stddef.h>
8
10{
11 rte_status_t status;
12
13 if (ticks == NULL)
14 {
15 status = RTE_STATUS_INVALID_PARAM;
16 }
17 else
18 {
19 ticks->handle = NULL;
20 ticks->count = 0U;
21 status = rte_mutex_create(&ticks->storage, &ticks->handle);
22 if (status != RTE_STATUS_OK)
23 {
24 ticks->handle = NULL;
25 }
26 }
27 return status;
28}
29
31{
32 rte_status_t status;
33
34 if (ticks == NULL)
35 {
36 status = RTE_STATUS_INVALID_PARAM;
37 }
38 else if (ticks->handle == NULL)
39 {
40 status = RTE_STATUS_INVALID_STATE;
41 }
42 else
43 {
44 status = rte_mutex_lock_timed(ticks->handle, (rte_duration_ms_t)AB_GP_CYCLE_TICKS_LOCK_TIMEOUT_MS);
45 if (status == RTE_STATUS_OK)
46 {
47 if (ticks->count < UINT32_MAX)
48 {
49 ticks->count++;
50 }
51 status = rte_mutex_unlock(ticks->handle);
52 }
53 }
54 return status;
55}
56
57rte_status_t ab_gp_cycle_ticks_take(ab_gp_cycle_ticks_t *ticks, uint32_t *out_pending)
58{
59 rte_status_t status;
60
61 if ((ticks == NULL) || (out_pending == NULL))
62 {
63 status = RTE_STATUS_INVALID_PARAM;
64 }
65 else if (ticks->handle == NULL)
66 {
67 status = RTE_STATUS_INVALID_STATE;
68 }
69 else
70 {
71 status = rte_mutex_lock_timed(ticks->handle, (rte_duration_ms_t)AB_GP_CYCLE_TICKS_LOCK_TIMEOUT_MS);
72 if (status == RTE_STATUS_OK)
73 {
74 /* Read and clear under one lock hold: a tick posted in between cannot exist. */
75 *out_pending = ticks->count;
76 ticks->count = 0U;
77 status = rte_mutex_unlock(ticks->handle);
78 }
79 }
80 return status;
81}
82
84{
85 rte_status_t status;
86
87 if (ticks == NULL)
88 {
89 status = RTE_STATUS_INVALID_PARAM;
90 }
91 else if (ticks->handle == NULL)
92 {
93 status = RTE_STATUS_INVALID_STATE;
94 }
95 else
96 {
97 status = rte_mutex_destroy(ticks->handle);
98 ticks->handle = NULL;
99 }
100 return status;
101}
rte_status_t ab_gp_cycle_ticks_take(ab_gp_cycle_ticks_t *ticks, uint32_t *out_pending)
Returns every pending tick and clears the count, as one critical section (cycle thread side).
rte_status_t ab_gp_cycle_ticks_teardown(ab_gp_cycle_ticks_t *ticks)
Destroys the mutex. Call only when no other task can post or take any more (the posting timer is dest...
rte_status_t ab_gp_cycle_ticks_setup(ab_gp_cycle_ticks_t *ticks)
Creates the mutex and clears the count. Setup phase only (rte_mutex_create() is a setup-only resource...
rte_status_t ab_gp_cycle_ticks_post(ab_gp_cycle_ticks_t *ticks)
Adds one tick (timer callback side). The count saturates at UINT32_MAX.
A/B cycle tick count shared by the cycle timer callback and the cycle thread (ISS-051).
#define AB_GP_CYCLE_TICKS_LOCK_TIMEOUT_MS
Longest wait for the tick count's mutex, in ms (OSA rule R2). Far above the critical section's hold t...
Tick count and the mutex that guards it. Not volatile: every access to count holds the mutex.
rte_mutex_handle_t handle
rte_mutex_storage_t storage