µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 
36 
37 // ----------------------------------------------------------------------------
38 
39 namespace os
40 {
41  namespace rtos
42  {
43  // ========================================================================
44 
45 #pragma GCC diagnostic push
46 #pragma GCC diagnostic ignored "-Wpadded"
47 
54  {
55  public:
56 
61  using func_args_t = void*;
62 
67  using func_t = void (*) (func_args_t args);
68 
73  using type_t = uint8_t;
74 
79  struct run
80  {
81  enum
82  : 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
110  : state_t
111  {
115  undefined = 0,
116  initialized = 1,
117  running = 2,
118  completed = 3,
119  stopped = 4,
120  destroyed = 5
121  };
122  };
123 
124  // ======================================================================
125 
132  {
133  public:
134 
145  constexpr
146  attributes ();
147 
148  protected:
149 
154  constexpr
155  attributes (type_t type);
156 
161  public:
162 
163  // The rule of five.
164  attributes (const attributes&) = default;
165  attributes (attributes&&) = default;
166  attributes&
167  operator= (const attributes&) = default;
168  attributes&
169  operator= (attributes&&) = default;
170 
174  ~attributes () = default;
175 
180  public:
181 
187  // Public members; no accessors and mutators required.
188  // Warning: must match the type & order of the C file header.
192  type_t tm_type = run::once;
193 
194  // Add more attributes.
195 
200  }; /* class attributes */
201 
206 
213  {
214  public:
215 
226  constexpr
228 
229  // The rule of five.
230  attributes_periodic (const attributes_periodic&) = default;
231  attributes_periodic (attributes_periodic&&) = default;
232  attributes_periodic&
233  operator= (const attributes_periodic&) = default;
234  attributes_periodic&
235  operator= (attributes_periodic&&) = default;
236 
240  ~attributes_periodic () = default;
241 
246  }; /* class attributes_periodic */
247 
253 
265  timer (func_t function, func_args_t args, const attributes& attr =
266  once_initializer);
267 
275  timer (const char* name, func_t function, func_args_t args,
276  const attributes& attr = once_initializer);
277 
282  timer (const timer&) = delete;
283  timer (timer&&) = delete;
284  timer&
285  operator= (const timer&) = delete;
286  timer&
287  operator= (timer&&) = delete;
288 
296  ~timer ();
297 
312  bool
313  operator== (const timer& rhs) const;
314 
319  public:
320 
333  result_t
334  start (clock::duration_t period);
335 
345  result_t
346  stop (void);
347 
352  protected:
353 
363  friend class internal::timer_node;
364 
373  protected:
374 
384 #if !defined(OS_USE_RTOS_PORT_TIMER)
385 
386  void
387  internal_interrupt_service_routine (void);
388 
389 #endif
390 
399  protected:
400 
410  func_t func_;
411  func_args_t func_args_;
412 
413 #if !defined(OS_USE_RTOS_PORT_TIMER)
414  clock* clock_ = nullptr;
415  internal::timer_node timer_node_
416  { 0, *this };
417  clock::duration_t period_ = 0;
418 #endif
419 
420 #if defined(OS_USE_RTOS_PORT_TIMER)
421  friend class port::timer;
422  os_timer_port_data_t port_;
423 #endif
424 
425  type_t type_ = run::once;
426  state_t state_ = state::undefined;
427 
428  // Add more internal data.
429 
438  };
439 
440 #pragma GCC diagnostic pop
441 
442  } /* namespace rtos */
443 } /* namespace os */
444 
445 // ===== Inline & template implementations ====================================
446 
447 namespace os
448 {
449  namespace rtos
450  {
451  // ========================================================================
452 
453  constexpr
455  {
456  ;
457  }
458 
463  constexpr
465  tm_type (type)
466  {
467  ;
468  }
469 
474  // ========================================================================
475  constexpr
477  attributes
478  { run::periodic }
479  {
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 // ----------------------------------------------------------------------------
497 
498 #endif /* __cplusplus */
499 
500 #endif /* CMSIS_PLUS_RTOS_OS_TIMER_H_ */
uint8_t type_t
Type of of variables holding timer run types.
Definition: os-timer.h:73
result_t start(clock::duration_t period)
Start or restart the timer.
Definition: os-timer.cpp:246
bool operator==(const timer &rhs) const
Compare timers.
Definition: os-timer.h:488
constexpr attributes_periodic()
Construct periodic timer attributes object instance.
Definition: os-timer.h:476
void * func_args_t
Timer call back function arguments.
Definition: os-timer.h:61
Run periodically.
Definition: os-timer.h:92
timer(func_t function, func_args_t args, const attributes &attr=once_initializer)
Construct a timer object instance.
Definition: os-timer.cpp:138
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition: os-timer.h:67
Base class for attributes.
Definition: os-decls.h:562
System namespace.
User single-shot or periodic timer.
Definition: os-timer.h:53
Timer run types.
Definition: os-timer.h:79
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition: os-timer.h:252
Double linked list node, with time stamp and timer.
Definition: os-lists.h:302
const char * name(void) const
Get object name.
Definition: os-decls.h:760
Base class for named system objects.
Definition: os-decls.h:444
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition: os-clocks.h:72
Timer states.
Definition: os-timer.h:107
result_t stop(void)
Stop the timer.
Definition: os-timer.cpp:304
~timer()
Destruct the timer object instance.
Definition: os-timer.cpp:212
Periodic timer attributes.
Definition: os-timer.h:212
Used to catch uninitialised threads.
Definition: os-timer.h:115
Run only once.
Definition: os-timer.h:87
static const attributes once_initializer
Default one shot timer initialiser.
Definition: os-timer.h:205
uint8_t state_t
Type of of variables holding timer states.
Definition: os-timer.h:100
Timer attributes.
Definition: os-timer.h:131
Generic clock.
Definition: os-clocks.h:54
constexpr attributes()
Construct a timer attributes object instance.
Definition: os-timer.h:454
uint32_t result_t
Type of values returned by RTOS functions.
Definition: os-decls.h:96