µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os-timer.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#ifndef CMSIS_PLUS_RTOS_OS_TIMER_H_
13#define CMSIS_PLUS_RTOS_OS_TIMER_H_
14
15// ----------------------------------------------------------------------------
16
17#if defined(__cplusplus)
18
19// ----------------------------------------------------------------------------
20
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
23#endif
24
26
27// ----------------------------------------------------------------------------
28
29#pragma GCC diagnostic push
30#if defined(__clang__)
31#pragma clang diagnostic ignored "-Wc++98-compat"
32#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
33#endif
34
35// ----------------------------------------------------------------------------
36
37namespace os
38{
39 namespace rtos
40 {
41 // ========================================================================
42
43#pragma GCC diagnostic push
44#if defined(__clang__)
45#pragma clang diagnostic ignored "-Wpadded"
46#elif defined(__GNUC__)
47#pragma GCC diagnostic ignored "-Wpadded"
48#endif
49
56 {
57 public:
62 using func_args_t = void*;
63
68 using func_t = void (*) (func_args_t args);
69
74 using type_t = uint8_t;
75
80 struct run
81 {
82 enum : type_t
83 {
87 once = 0,
88
92 periodic = 1 //
93 };
94 };
95
100 using state_t = uint8_t;
101
107 struct state
108 {
109 enum : state_t
110 {
119 destroyed = 5
120 };
121 };
122
123 // ======================================================================
124
131 {
132 public:
143 constexpr attributes ();
144
145 protected:
150 constexpr attributes (type_t type);
151
156 public:
157 // The rule of five.
158 attributes (const attributes&) = default;
159 attributes (attributes&&) = default;
162 = default;
165 = default;
166
170 ~attributes () = default;
171
176 public:
182 // Public members; no accessors and mutators required.
183 // Warning: must match the type & order of the C file header.
188
189 // Add more attributes.
190
195 }; /* class attributes */
196
201
211 {
212 public:
223 constexpr attributes_periodic ();
224
225 // The rule of five.
230 = default;
233 = default;
234
239
244 }; /* class attributes_periodic */
245
251
263 timer (func_t function, func_args_t args,
264 const attributes& attr = once_initializer);
265
273 timer (const char* name, func_t function, func_args_t args,
274 const attributes& attr = once_initializer);
275
280 timer (const timer&) = delete;
281 timer (timer&&) = delete;
282 timer&
283 operator= (const timer&)
284 = delete;
285 timer&
286 operator= (timer&&)
287 = delete;
288
296 ~timer ();
297
312 bool
313 operator== (const timer& rhs) const;
314
319 public:
333 start (clock::duration_t period);
334
345 stop (void);
346
351 protected:
361 friend class internal::timer_node;
362
371 protected:
381#if !defined(OS_USE_RTOS_PORT_TIMER)
382
383 void
384 internal_interrupt_service_routine (void);
385
386#endif
387
396 protected:
406 func_t func_;
407 func_args_t func_args_;
408
409#if !defined(OS_USE_RTOS_PORT_TIMER)
410 clock* clock_ = nullptr;
411 internal::timer_node timer_node_{ 0, *this };
412 clock::duration_t period_ = 0;
413#endif
414
415#if defined(OS_USE_RTOS_PORT_TIMER)
416 friend class port::timer;
417 os_timer_port_data_t port_;
418#endif
419
420 type_t type_ = run::once;
421 state_t state_ = state::undefined;
422
423 // Add more internal data.
424
432 };
433
434#pragma GCC diagnostic pop
435
436 } /* namespace rtos */
437} /* namespace os */
438
439// ===== Inline & template implementations ====================================
440
441namespace os
442{
443 namespace rtos
444 {
445 // ========================================================================
446
448 {
449 }
450
455 constexpr timer::attributes::attributes (type_t type) : tm_type (type)
456 {
457 }
458
463 // ========================================================================
465 : attributes{ run::periodic }
466 {
467 }
468
473 inline bool
474 timer::operator== (const timer& rhs) const
475 {
476 return this == &rhs;
477 }
478
479 } /* namespace rtos */
480} /* namespace os */
481
482#pragma GCC diagnostic pop
483
484// ----------------------------------------------------------------------------
485
486#endif /* __cplusplus */
487
488// ----------------------------------------------------------------------------
489
490#endif /* CMSIS_PLUS_RTOS_OS_TIMER_H_ */
Generic clock.
Definition os-clocks.h:61
Base class for attributes.
Definition os-decls.h:559
Base class for named system objects.
Definition os-decls.h:443
const char * name(void) const
Get object name.
Definition os-decls.h:753
Double linked list node, with time stamp and timer.
Definition os-lists.h:311
Periodic timer attributes.
Definition os-timer.h:211
attributes_periodic & operator=(const attributes_periodic &)=default
attributes_periodic(const attributes_periodic &)=default
~attributes_periodic()=default
Destruct the periodic timer attributes object instance.
constexpr attributes_periodic()
Construct periodic timer attributes object instance.
Definition os-timer.h:464
attributes_periodic(attributes_periodic &&)=default
Timer attributes.
Definition os-timer.h:131
type_t tm_type
Timer type attribute.
Definition os-timer.h:187
constexpr attributes()
Construct a timer attributes object instance.
Definition os-timer.h:447
attributes & operator=(const attributes &)=default
attributes(attributes &&)=default
~attributes()=default
Destruct the timer attributes object instance.
attributes(const attributes &)=default
User single-shot or periodic timer.
Definition os-timer.h:56
bool operator==(const timer &rhs) const
Compare timers.
Definition os-timer.h:474
~timer()
Destruct the timer object instance.
Definition os-timer.cpp:209
static const attributes once_initializer
Default one shot timer initialiser.
Definition os-timer.h:200
result_t stop(void)
Stop the timer.
Definition os-timer.cpp:307
result_t start(clock::duration_t period)
Start or restart the timer.
Definition os-timer.cpp:243
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:78
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:62
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:68
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:74
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:100
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:250
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
System namespace.
Timer run types.
Definition os-timer.h:81
@ once
Run only once.
Definition os-timer.h:87
@ periodic
Run periodically.
Definition os-timer.h:92
Timer states.
Definition os-timer.h:108
@ undefined
Used to catch uninitialised threads.
Definition os-timer.h:114