Skip to content

Commit 9230bde

Browse files
Added timer_isActive() (#352)
1 parent 9f8a782 commit 9230bde

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

threadX/inc/u_tx_timers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,12 @@ int timer_restart(timer_t* timer);
6969
*/
7070
int timer_getRemainingTicks(timer_t* timer, uint32_t *remaining);
7171

72+
/**
73+
* @brief Checks whether or not the timer is active.
74+
*
75+
* @param timer Pointer to the timer.
76+
* @param active Buffer to store the information.
77+
*/
78+
int timer_isActive(timer_t* timer, bool* active);
79+
7280
// clang-format on

threadX/src/u_tx_timers.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,6 @@
33

44
// clang-format off
55

6-
/* Check if a timer is active. */
7-
int _is_timer_active(timer_t* timer, bool* active) {
8-
/* Get the active indication. */
9-
UINT is_active;
10-
int status = tx_timer_info_get(&timer->TX_TIMER_, (CHAR**)TX_NULL, &is_active, (ULONG*)TX_NULL, (ULONG*)TX_NULL, (TX_TIMER**)TX_NULL);
11-
if(status != TX_SUCCESS) {
12-
PRINTLN_ERROR("Failed to call tx_timer_info_get (Status: %d/%s, Timer: %s).", status, tx_status_toString(status), timer->name);
13-
return U_ERROR;
14-
}
15-
16-
/* Check the indication. */
17-
if(is_active == TX_TRUE) {
18-
*active = true;
19-
} else {
20-
*active = false;
21-
}
22-
23-
return U_SUCCESS;
24-
}
25-
266
/* Initializes a timer. */
277
int timer_init(timer_t* timer) {
288
/* Set reschedule ticks setting. */
@@ -57,7 +37,7 @@ int timer_init(timer_t* timer) {
5737
int timer_start(timer_t* timer) {
5838
/* Get active status. */
5939
bool is_active = false;
60-
int status = _is_timer_active(timer, &is_active);
40+
int status = timer_isActive(timer, &is_active);
6141
if(status != U_SUCCESS) {
6242
PRINTLN_ERROR("Failed to get the activation status of a timer (Timer: %s).", timer->name);
6343
return U_ERROR;
@@ -153,4 +133,24 @@ int timer_getRemainingTicks(timer_t* timer, uint32_t* remaining) {
153133
return U_SUCCESS;
154134
}
155135

136+
/* Check if a timer is active. */
137+
int timer_isActive(timer_t* timer, bool* active) {
138+
/* Get the active indication. */
139+
UINT is_active;
140+
int status = tx_timer_info_get(&timer->TX_TIMER_, (CHAR**)TX_NULL, &is_active, (ULONG*)TX_NULL, (ULONG*)TX_NULL, (TX_TIMER**)TX_NULL);
141+
if(status != TX_SUCCESS) {
142+
PRINTLN_ERROR("Failed to call tx_timer_info_get (Status: %d/%s, Timer: %s).", status, tx_status_toString(status), timer->name);
143+
return U_ERROR;
144+
}
145+
146+
/* Check the indication. */
147+
if(is_active == TX_TRUE) {
148+
*active = true;
149+
} else {
150+
*active = false;
151+
}
152+
153+
return U_SUCCESS;
154+
}
155+
156156
// clang-format on

0 commit comments

Comments
 (0)