µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef CMSIS_PLUS_RTOS_OS_TIMER_H_
29#define CMSIS_PLUS_RTOS_OS_TIMER_H_
30
31// ----------------------------------------------------------------------------
32
33#if defined(__cplusplus)
34
35// ----------------------------------------------------------------------------
36
38
39// ----------------------------------------------------------------------------
40
41#pragma GCC diagnostic push
42
43#if defined(__clang__)
44#pragma clang diagnostic ignored "-Wc++98-compat"
45#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
46#endif
47
48// ----------------------------------------------------------------------------
49
50namespace os
51{
52 namespace rtos
53 {
54 // ========================================================================
55
56#pragma GCC diagnostic push
57#pragma GCC diagnostic ignored "-Wpadded"
58
65 {
66 public:
67
72 using func_args_t = void*;
73
78 using func_t = void (*) (func_args_t args);
79
84 using type_t = uint8_t;
85
90 struct run
91 {
92 enum
93 : type_t
94 {
98 once = 0,
99
103 periodic = 1 //
104 };
105 };
106
111 using state_t = uint8_t;
112
118 struct state
119 {
120 enum
121 : state_t
122 {
131 destroyed = 5
132 };
133 };
134
135 // ======================================================================
136
143 {
144 public:
145
156 constexpr
157 attributes ();
158
159 protected:
160
165 constexpr
166 attributes (type_t type);
167
172 public:
173
174 // The rule of five.
175 attributes (const attributes&) = default;
176 attributes (attributes&&) = default;
178 operator= (const attributes&) = default;
180 operator= (attributes&&) = default;
181
185 ~attributes () = default;
186
191 public:
192
198 // Public members; no accessors and mutators required.
199 // Warning: must match the type & order of the C file header.
204
205 // Add more attributes.
206
211 }; /* class attributes */
212
217
224 {
225 public:
226
237 constexpr
239
240 // The rule of five.
247
252
257 }; /* class attributes_periodic */
258
264
276 timer (func_t function, func_args_t args, const attributes& attr =
278
286 timer (const char* name, func_t function, func_args_t args,
287 const attributes& attr = once_initializer);
288
293 timer (const timer&) = delete;
294 timer (timer&&) = delete;
295 timer&
296 operator= (const timer&) = delete;
297 timer&
298 operator= (timer&&) = delete;
299
307 ~timer ();
308
323 bool
324 operator== (const timer& rhs) const;
325
330 public:
331
345 start (clock::duration_t period);
346
357 stop (void);
358
363 protected:
364
374 friend class internal::timer_node;
375
384 protected:
385
395#if !defined(OS_USE_RTOS_PORT_TIMER)
396
397 void
398 internal_interrupt_service_routine (void);
399
400#endif
401
410 protected:
411
421 func_t func_;
422 func_args_t func_args_;
423
424#if !defined(OS_USE_RTOS_PORT_TIMER)
425 clock* clock_ = nullptr;
426 internal::timer_node timer_node_
427 { 0, *this };
428 clock::duration_t period_ = 0;
429#endif
430
431#if defined(OS_USE_RTOS_PORT_TIMER)
432 friend class port::timer;
433 os_timer_port_data_t port_;
434#endif
435
436 type_t type_ = run::once;
437 state_t state_ = state::undefined;
438
439 // Add more internal data.
440
449 };
450
451#pragma GCC diagnostic pop
452
453 } /* namespace rtos */
454} /* namespace os */
455
456// ===== Inline & template implementations ====================================
457
458namespace os
459{
460 namespace rtos
461 {
462 // ========================================================================
463
464 constexpr
466 {
467 ;
468 }
469
474 constexpr
476 tm_type (type)
477 {
478 ;
479 }
480
485 // ========================================================================
486 constexpr
489 { run::periodic }
490 {
491 ;
492 }
493
498 inline bool
499 timer::operator== (const timer& rhs) const
500 {
501 return this == &rhs;
502 }
503
504 } /* namespace rtos */
505} /* namespace os */
506
507#pragma GCC diagnostic pop
508
509// ----------------------------------------------------------------------------
510
511#endif /* __cplusplus */
512
513// ----------------------------------------------------------------------------
514
515#endif /* CMSIS_PLUS_RTOS_OS_TIMER_H_ */
Generic clock.
Definition os-clocks.h:66
Base class for attributes.
Definition os-decls.h:577
Base class for named system objects.
Definition os-decls.h:459
const char * name(void) const
Get object name.
Definition os-decls.h:774
Double linked list node, with time stamp and timer.
Definition os-lists.h:316
Periodic timer attributes.
Definition os-timer.h:224
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:487
attributes_periodic(attributes_periodic &&)=default
Timer attributes.
Definition os-timer.h:143
type_t tm_type
Timer type attribute.
Definition os-timer.h:203
constexpr attributes()
Construct a timer attributes object instance.
Definition os-timer.h:465
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:65
bool operator==(const timer &rhs) const
Compare timers.
Definition os-timer.h:499
~timer()
Destruct the timer object instance.
Definition os-timer.cpp:227
static const attributes once_initializer
Default one shot timer initialiser.
Definition os-timer.h:216
result_t stop(void)
Stop the timer.
Definition os-timer.cpp:319
result_t start(clock::duration_t period)
Start or restart the timer.
Definition os-timer.cpp:261
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:83
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:72
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:78
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:84
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:111
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:263
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
System namespace.
Timer run types.
Definition os-timer.h:91
@ once
Run only once.
Definition os-timer.h:98
@ periodic
Run periodically.
Definition os-timer.h:103
Timer states.
Definition os-timer.h:119
@ undefined
Used to catch uninitialised threads.
Definition os-timer.h:126