µ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::rtos::timer Class Reference

User single-shot or periodic timer. More...

#include <cmsis-plus/rtos/os.h>

+ Inheritance diagram for os::rtos::timer:

Classes

class  attributes
 Timer attributes. More...
 
class  attributes_periodic
 Periodic timer attributes. More...
 
struct  run
 Timer run types. More...
 
struct  state
 Timer states. More...
 

Public Types

using func_args_t = void *
 Timer call back function arguments.
 
using func_t = void(*)(func_args_t args)
 Entry point of a timer call back function.
 
using state_t = uint8_t
 Type of of variables holding timer states.
 
using type_t = uint8_t
 Type of of variables holding timer run types.
 

Public Member Functions

Constructors & Destructor
 timer (func_t function, func_args_t args, const attributes &attr=once_initializer)
 Construct a timer object instance.
 
 timer (const char *name, func_t function, func_args_t args, const attributes &attr=once_initializer)
 Construct a named timer object instance.
 
 ~timer ()
 Destruct the timer object instance.
 
Operators
bool operator== (const timer &rhs) const
 Compare timers.
 
Public Member Functions
result_t start (clock::duration_t period)
 Start or restart the timer.
 
result_t stop (void)
 Stop the timer.
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Member Functions

Operators
static void * operator new (std::size_t bytes)
 Allocate space for a new object instance using the RTOS system allocator.
 
static void * operator new (std::size_t bytes, void *ptr)
 Emplace a new object instance.
 
static void * operator new[] (std::size_t bytes)
 Allocate space for an array of new object instances using the RTOS system allocator.
 
static void * operator new[] (std::size_t bytes, void *ptr)
 Emplace an array of new object instances.
 
static void operator delete (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated object instance. using the RTOS system allocator.
 
static void operator delete[] (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.
 

Static Public Attributes

static const attributes once_initializer
 Default one shot timer initialiser.
 
static const attributes_periodic periodic_initializer
 Default periodic timer initialiser.
 

Detailed Description

User single-shot or periodic timer.

The CMISIS++ timer schedules the execution of a user function after a programmable interval. If the timer is periodic, the function is rescheduled automatically until the timer is stopped.

Example
#include <cstdlib>
using namespace os::rtos;
// Thread function.
void
func(void* args)
{
// Do something.
...
}
int
os_main(int argc, char* argv[])
{
// Construct new thread, with function and no arguments.
timer tm { func, nullptr };
// Schedule func() to be executed after 100 ticks.
tm.start(100);
// Do something.
return 0;
}
User single-shot or periodic timer.
Definition os-timer.h:57
result_t start(clock::duration_t period)
Start or restart the timer.
Definition os-timer.cpp:249
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
RTOS namespace.
Definition os-flags.h:38
Single file µOS++ RTOS definitions.
POSIX compatibility
No POSIX similar functionality identified.

Definition at line 56 of file os-timer.h.

Constructor & Destructor Documentation

◆ timer() [1/2]

os::rtos::timer::timer ( func_t  function,
func_args_t  args,
const attributes attr = once_initializer 
)

Construct a timer object instance.

Parameters
[in]functionPointer to timer function.
[in]argsPointer to timer function arguments.
[in]attrReference to attributes.

This constructor shall initialise a timer object with attributes referenced by attr. If the attributes specified by attr are modified later, the timer attributes shall not be affected.

Upon successful initialisation, the state of the timer object shall become initialised.

Only the timer object itself may be used for running the function. It is not allowed to make copies of timer objects.

In cases where default condition variable attributes are appropriate, the variables timer::once_initializer or timer::periodic_initializer can be used to initialise timers. The effect shall be equivalent to creating a timer object with the simple constructor.

If the attr attributes are modified after the timer creation, the timer attributes shall not be affected.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 139 of file os-timer.cpp.

◆ timer() [2/2]

os::rtos::timer::timer ( const char *  name,
func_t  function,
func_args_t  args,
const attributes attr = once_initializer 
)

Construct a named timer object instance.

Parameters
[in]namePointer to name.
[in]functionPointer to timer function.
[in]argsPointer to timer function arguments.
[in]attrReference to attributes.

This constructor shall initialise a named timer object with attributes referenced by attr. If the attributes specified by attr are modified later, the timer attributes shall not be affected.

Upon successful initialisation, the state of the timer object shall become initialised.

Only the timer object itself may be used for running the function. It is not allowed to make copies of timer objects.

In cases where default condition variable attributes are appropriate, the variables timer::once_initializer or timer::periodic_initializer can be used to initialise timers. The effect shall be equivalent to creating a timer object with the simple constructor.

If the attr attributes are modified after the timer creation, the timer attributes shall not be affected.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 171 of file os-timer.cpp.

◆ ~timer()

os::rtos::timer::~timer ( )

Destruct the timer object instance.

This destructor shall destroy the timer object; the object becomes, in effect, uninitialised. An implementation may cause the destructor to set the object to an invalid value.

If the timer is running, it must be automatically stopped.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 215 of file os-timer.cpp.

Member Function Documentation

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited

Get object name.

Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 759 of file os-decls.h.

◆ operator delete()

void os::rtos::internal::object_named_system::operator delete ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated object instance. using the RTOS system allocator.

Parameters
ptrPointer to object.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by a delete-expression to render the value of ptr invalid.

ptr shall be a null pointer or its value shall be a value returned by an earlier call to the (possibly replaced) operator new() which has not been invalidated by an intervening call to operator delete(void*).

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 122 of file os-inlines.h.

◆ operator delete[]()

void os::rtos::internal::object_named_system::operator delete[] ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.

Parameters
ptrPointer to array of objects.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by the array form of a delete-expression to render the value of ptr invalid.

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 143 of file os-inlines.h.

◆ operator new() [1/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes)
inlinestaticinherited

Allocate space for a new object instance using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated object.

The allocation function (3.7.4.1) called by a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 44 of file os-inlines.h.

◆ operator new() [2/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace a new object instance.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced object.

The allocation function (3.7.4.1) called by a placement new-expression to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 81 of file os-inlines.h.

◆ operator new[]() [1/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes)
inlinestaticinherited

Allocate space for an array of new object instances using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated array.

The allocation function (3.7.4.1) called by the array form of a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 62 of file os-inlines.h.

◆ operator new[]() [2/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace an array of new object instances.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced array.

The allocation function (3.7.4.1) called by the array form of a placement new-expression to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 98 of file os-inlines.h.

◆ operator==()

bool os::rtos::timer::operator== ( const timer rhs) const
inline

Compare timers.

Return values
trueThe given timer is the same as this timer.
falseThe timers are different.

Identical timers should have the same memory address.

Definition at line 488 of file os-timer.h.

◆ start()

result_t os::rtos::timer::start ( clock::duration_t  period)

Start or restart the timer.

Parameters
[in]periodTimer period, in clock units (ticks or seconds).
Return values
result::okThe timer has been started or restarted.
ENOTRECOVERABLETimer could not be started.
EPERMCannot be invoked from an Interrupt Service Routines.

If the period is 0, it is automatically adjusted to 1.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 249 of file os-timer.cpp.

◆ stop()

result_t os::rtos::timer::stop ( void  )

Stop the timer.

Parameters
None.
Return values
result::okThe timer has been stopped.
EPERMCannot be invoked from an Interrupt Service Routines.
EAGAINThe timer is not yet started.
ENOTRECOVERABLETimer could not be stopped.

Remove the timer from the clock schedule list, so that the next execution of the function is cancelled.

A stopped timer can be restarted later with start()`.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 313 of file os-timer.cpp.

Member Data Documentation

◆ once_initializer

const timer::attributes os::rtos::timer::once_initializer
static

Default one shot timer initialiser.

This variable can be used to create a single run timer.

Definition at line 208 of file os-timer.h.


The documentation for this class was generated from the following files: