µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#ifndef CMSIS_PLUS_RTOS_OS_TIMER_H_
14#define CMSIS_PLUS_RTOS_OS_TIMER_H_
15
16// ----------------------------------------------------------------------------
17
18#if defined(__cplusplus)
19
20// ----------------------------------------------------------------------------
21
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
24#endif
25
27
28// ----------------------------------------------------------------------------
29
30#pragma GCC diagnostic push
31#if defined(__clang__)
32#pragma clang diagnostic ignored "-Wc++98-compat"
33#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
34#endif
35
36// ----------------------------------------------------------------------------
37
38namespace os
39{
40 namespace rtos
41 {
42 // ========================================================================
43
44#pragma GCC diagnostic push
45#if defined(__clang__)
46#pragma clang diagnostic ignored "-Wpadded"
47#elif defined(__GNUC__)
48#pragma GCC diagnostic ignored "-Wpadded"
49#endif
50
57 {
58 public:
59
64 using func_args_t = void*;
65
70 using func_t = void (*) (func_args_t args);
71
76 using type_t = uint8_t;
77
82 struct run
83 {
84 enum
85 : type_t
86 {
90 once = 0,
91
95 periodic = 1 //
96 };
97 };
98
103 using state_t = uint8_t;
104
110 struct state
111 {
112 enum
113 : state_t
114 {
123 destroyed = 5
124 };
125 };
126
127 // ======================================================================
128
135 {
136 public:
137
148 constexpr
149 attributes ();
150
151 protected:
152
157 constexpr
158 attributes (type_t type);
159
164 public:
165
166 // The rule of five.
167 attributes (const attributes&) = default;
168 attributes (attributes&&) = default;
170 operator= (const attributes&) = default;
172 operator= (attributes&&) = default;
173
177 ~attributes () = default;
178
183 public:
184
190 // Public members; no accessors and mutators required.
191 // Warning: must match the type & order of the C file header.
196
197 // Add more attributes.
198
203 }; /* class attributes */
204
209
216 {
217 public:
218
229 constexpr
231
232 // The rule of five.
239
244
249 }; /* class attributes_periodic */
250
256
268 timer (func_t function, func_args_t args, const attributes& attr =
270
278 timer (const char* name, func_t function, func_args_t args,
279 const attributes& attr = once_initializer);
280
285 timer (const timer&) = delete;
286 timer (timer&&) = delete;
287 timer&
288 operator= (const timer&) = delete;
289 timer&
290 operator= (timer&&) = delete;
291
299 ~timer ();
300
315 bool
316 operator== (const timer& rhs) const;
317
322 public:
323
337 start (clock::duration_t period);
338
349 stop (void);
350
355 protected:
356
366 friend class internal::timer_node;
367
376 protected:
377
387#if !defined(OS_USE_RTOS_PORT_TIMER)
388
389 void
390 internal_interrupt_service_routine (void);
391
392#endif
393
402 protected:
403
413 func_t func_;
414 func_args_t func_args_;
415
416#if !defined(OS_USE_RTOS_PORT_TIMER)
417 clock* clock_ = nullptr;
418 internal::timer_node timer_node_
419 { 0, *this };
420 clock::duration_t period_ = 0;
421#endif
422
423#if defined(OS_USE_RTOS_PORT_TIMER)
424 friend class port::timer;
425 os_timer_port_data_t port_;
426#endif
427
428 type_t type_ = run::once;
429 state_t state_ = state::undefined;
430
431 // Add more internal data.
432
441 };
442
443#pragma GCC diagnostic pop
444
445 } /* namespace rtos */
446} /* namespace os */
447
448// ===== Inline & template implementations ====================================
449
450namespace os
451{
452 namespace rtos
453 {
454 // ========================================================================
455
456 constexpr
458 {
459 }
460
465 constexpr
467 tm_type (type)
468 {
469 }
470
475 // ========================================================================
476 constexpr
479 { run::periodic }
480 {
481 }
482
487 inline bool
488 timer::operator== (const timer& rhs) const
489 {
490 return this == &rhs;
491 }
492
493 } /* namespace rtos */
494} /* namespace os */
495
496#pragma GCC diagnostic pop
497
498// ----------------------------------------------------------------------------
499
500#endif /* __cplusplus */
501
502// ----------------------------------------------------------------------------
503
504#endif /* CMSIS_PLUS_RTOS_OS_TIMER_H_ */
Generic clock.
Definition os-clocks.h:59
Base class for attributes.
Definition os-decls.h:563
Base class for named system objects.
Definition os-decls.h:445
const char * name(void) const
Get object name.
Definition os-decls.h:759
Double linked list node, with time stamp and timer.
Definition os-lists.h:316
Periodic timer attributes.
Definition os-timer.h:216
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:477
attributes_periodic(attributes_periodic &&)=default
Timer attributes.
Definition os-timer.h:135
type_t tm_type
Timer type attribute.
Definition os-timer.h:195
constexpr attributes()
Construct a timer attributes object instance.
Definition os-timer.h:457
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:57
bool operator==(const timer &rhs) const
Compare timers.
Definition os-timer.h:488
~timer()
Destruct the timer object instance.
Definition os-timer.cpp:215
static const attributes once_initializer
Default one shot timer initialiser.
Definition os-timer.h:208
result_t stop(void)
Stop the timer.
Definition os-timer.cpp:313
result_t start(clock::duration_t period)
Start or restart the timer.
Definition os-timer.cpp:249
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:76
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:64
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:70
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:76
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:103
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:255
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
System namespace.
Timer run types.
Definition os-timer.h:83
@ once
Run only once.
Definition os-timer.h:90
@ periodic
Run periodically.
Definition os-timer.h:95
Timer states.
Definition os-timer.h:111
@ undefined
Used to catch uninitialised threads.
Definition os-timer.h:118