µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches

C API timer definitions. More...

Classes

struct  os_timer_attr_s
 Timer attributes. More...
 
struct  os_timer_s
 Timer object storage. More...
 

Typedefs

typedef struct os_timer_attr_s os_timer_attr_t
 Timer attributes.
 
typedef void * os_timer_func_args_t
 Type of timer function arguments.
 
typedef void(* os_timer_func_t) (os_timer_func_args_t args)
 Type of timer function.
 
typedef uint8_t os_timer_state_t
 Type of variables holding timer states.
 
typedef struct os_timer_s os_timer_t
 Timer object storage.
 
typedef uint8_t os_timer_type_t
 Type of variables holding timer types.
 

Enumerations

enum  {
  os_timer_once = 0 ,
  os_timer_periodic = 1
}
 An enumeration with the timer types. More...
 

Timer Attribute Functions

void os_timer_attr_init (os_timer_attr_t *attr)
 Initialise the single shot timer attributes.
 
void os_timer_attr_periodic_init (os_timer_attr_t *attr)
 Initialise the periodic timer attributes.
 
const os_timer_attr_tos_timer_attr_get_periodic (void)
 Get a periodic timer attributes object instance.
 

Timer Creation Functions

void os_timer_construct (os_timer_t *timer, const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
 Construct a statically allocated timer object instance.
 
void os_timer_destruct (os_timer_t *timer)
 Destruct the statically allocated timer object instance.
 
os_timer_tos_timer_new (const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
 Allocate a timer object instance and construct it.
 
void os_timer_delete (os_timer_t *timer)
 Destruct the timer object instance and deallocate it.
 

Timer Functions

const char * os_timer_get_name (os_timer_t *timer)
 Get the timer name.
 
os_result_t os_timer_start (os_timer_t *timer, os_clock_duration_t period)
 Start or restart the timer.
 
os_result_t os_timer_stop (os_timer_t *timer)
 Stop the timer.
 

Compatibility Macros

#define os_timer_create   os_timer_construct
 
#define os_timer_destroy   os_timer_destruct
 

Detailed Description

For the complete definition, see
RTOS C++ API
Examples
void
tmfunc (void* args
{
printf ("%s\n", __func__);
}
int
os_main (int argc, char* argv[])
{
{
os_timer_construct (&tm1, "tm1", tmfunc, NULL, NULL);
os_sysclock_sleep_for (1); // Sync
os_timer_start (&tm1, 1);
os_timer_stop (&tm1);
name = os_timer_get_name (&tm1);
assert(strcmp (name, "tm1") == 0);
}
{
// Periodic timer
os_timer_construct (&tm2, "tm2", tmfunc, NULL,
os_sysclock_sleep_for (1); // Sync
os_timer_start (&tm2, 1);
os_timer_stop (&tm2);
name = os_timer_get_name (&tm2);
assert(strcmp (name, "tm2") == 0);
}
}
os_result_t os_sysclock_sleep_for(os_clock_duration_t duration)
Sleep for a relative duration.
const char * os_timer_get_name(os_timer_t *timer)
Get the timer name.
os_result_t os_timer_stop(os_timer_t *timer)
Stop the timer.
void os_timer_destruct(os_timer_t *timer)
Destruct the statically allocated timer object instance.
os_result_t os_timer_start(os_timer_t *timer, os_clock_duration_t period)
Start or restart the timer.
void os_timer_construct(os_timer_t *timer, const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
Construct a statically allocated timer object instance.
const os_timer_attr_t * os_timer_attr_get_periodic(void)
Get a periodic timer attributes object instance.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
Timer object storage.
Definition os-c-decls.h:784

Macro Definition Documentation

◆ os_timer_create

#define os_timer_create   os_timer_construct

Definition at line 1158 of file os-c-api.h.

◆ os_timer_destroy

#define os_timer_destroy   os_timer_destruct

Definition at line 1159 of file os-c-api.h.

Typedef Documentation

◆ os_timer_attr_t

Initialise this structure with os_timer_attr_init() and then set any of the individual members directly.

See also
os::rtos::timer::attributes

◆ os_timer_func_args_t

typedef void* os_timer_func_args_t

Useful to cast other similar types to silence possible compiler warnings.

See also
os::rtos::timer::func_args_t

Definition at line 709 of file os-c-decls.h.

◆ os_timer_func_t

typedef void(* os_timer_func_t) (os_timer_func_args_t args)

Useful to cast other similar types to silence possible compiler warnings.

See also
os::rtos::timer::func_t

Definition at line 720 of file os-c-decls.h.

◆ os_timer_state_t

typedef uint8_t os_timer_state_t
See also
os::rtos::timer::state_t

Definition at line 734 of file os-c-decls.h.

◆ os_timer_t

typedef struct os_timer_s os_timer_t

This C structure has the same size as the C++ os::rtos::timer object and must be initialised with os_timer_create().

Later on a pointer to it can be used both in C and C++ to refer to the timer object instance.

The members of this structure are hidden and should not be used directly, but only through specific functions.

See also
os::rtos::timer

◆ os_timer_type_t

typedef uint8_t os_timer_type_t
See also
os::rtos::timer::type_t

Definition at line 727 of file os-c-decls.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
os_timer_once 
os_timer_periodic 

Definition at line 694 of file os-c-decls.h.

695 {
696 os_timer_once = 0, //
697 os_timer_periodic = 1 //
698 };
@ os_timer_once
Definition os-c-decls.h:696
@ os_timer_periodic
Definition os-c-decls.h:697

Function Documentation

◆ os_timer_attr_get_periodic()

const os_timer_attr_t * os_timer_attr_get_periodic ( void  )
Returns
Pointer to timer attributes object instance.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::periodic_initializer

Definition at line 1486 of file os-c-wrapper.cpp.

1487{
1489}
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:250
Timer attributes.
Definition os-c-decls.h:754

References os::rtos::timer::periodic_initializer.

◆ os_timer_attr_init()

void os_timer_attr_init ( os_timer_attr_t attr)
Parameters
[in]attrPointer to timer attributes object instance.
Returns
Nothing.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::attributes

Definition at line 1460 of file os-c-wrapper.cpp.

1461{
1462 assert (attr != nullptr);
1463 new (attr) timer::attributes ();
1464}
Timer attributes.
Definition os-timer.h:131

◆ os_timer_attr_periodic_init()

void os_timer_attr_periodic_init ( os_timer_attr_t attr)
Parameters
[in]attrPointer to timer attributes object instance.
Returns
Nothing.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::attributes_periodic

Definition at line 1473 of file os-c-wrapper.cpp.

1474{
1475 assert (attr != nullptr);
1476 new (attr) timer::attributes_periodic ();
1477}
Periodic timer attributes.
Definition os-timer.h:211

◆ os_timer_construct()

void os_timer_construct ( os_timer_t timer,
const char *  name,
os_timer_func_t  function,
os_timer_func_args_t  args,
const os_timer_attr_t attr 
)
Parameters
[in]timerPointer to timer object instance storage.
[in]namePointer to name (may be NULL).
[in]functionPointer to timer function.
[in]argsPointer to timer function arguments (may be NULL).
[in]attrPointer to attributes (may be NULL).
Returns
Nothing.
Note
Must be paired with os_timer_destruct().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer

Definition at line 1500 of file os-c-wrapper.cpp.

1503{
1504 assert (timer != nullptr);
1505 if (attr == nullptr)
1506 {
1508 }
1509 new (timer)
1510 rtos::timer (name, (timer::func_t)function, (timer::func_args_t)args,
1511 (const timer::attributes&)*attr);
1512}
User single-shot or periodic timer.
Definition os-timer.h:56
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

References os::rtos::timer::periodic_initializer.

◆ os_timer_delete()

void os_timer_delete ( os_timer_t timer)
Parameters
[in]timerPointer to dynamically allocated timer object instance.
Returns
Nothing.

Destruct the timer and deallocate the dynamically allocated space using the RTOS system allocator.

Note
Equivalent of C++ delete ptr_timer.
Must be paired with os_timer_new().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer

Definition at line 1569 of file os-c-wrapper.cpp.

1570{
1571 assert (timer != nullptr);
1572 delete reinterpret_cast<rtos::timer*> (timer);
1573}

◆ os_timer_destruct()

void os_timer_destruct ( os_timer_t timer)
Parameters
[in]timerPointer to timer object instance.
Returns
Nothing.
Note
Must be paired with os_timer_construct().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer

Definition at line 1523 of file os-c-wrapper.cpp.

1524{
1525 assert (timer != nullptr);
1526 (reinterpret_cast<rtos::timer&> (*timer)).~timer ();
1527}

◆ os_timer_get_name()

const char * os_timer_get_name ( os_timer_t timer)
Parameters
[in]timerPointer to timer object instance.
Returns
Null terminated string.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::name()

Definition at line 1582 of file os-c-wrapper.cpp.

1583{
1584 assert (timer != nullptr);
1585 return (reinterpret_cast<rtos::timer&> (*timer)).name ();
1586}

◆ os_timer_new()

os_timer_t * os_timer_new ( const char *  name,
os_timer_func_t  function,
os_timer_func_args_t  args,
const os_timer_attr_t attr 
)
Parameters
[in]namePointer to name (may be NULL).
[in]functionPointer to timer function.
[in]argsPointer to timer function arguments (may be NULL).
[in]attrPointer to attributes (may be NULL).
Returns
Pointer to new timer object instance.

Dynamically allocate the timer object instance using the RTOS system allocator and construct it.

Note
Equivalent of C++ new timer(...).
Must be paired with os_timer_delete().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer

Definition at line 1543 of file os-c-wrapper.cpp.

1545{
1546 if (attr == nullptr)
1547 {
1549 }
1550 return reinterpret_cast<os_timer_t*> (
1551 new rtos::timer (name, (timer::func_t)function, (timer::func_args_t)args,
1552 (const timer::attributes&)*attr));
1553}

References os::rtos::timer::periodic_initializer.

◆ os_timer_start()

os_result_t os_timer_start ( os_timer_t timer,
os_clock_duration_t  period 
)
Parameters
[in]timerPointer to timer object instance.
[in]periodTimer period, in clock units (ticks or seconds).
Return values
os_okThe timer has been started or restarted.
ENOTRECOVERABLETimer could not be started.
EPERMCannot be invoked from an Interrupt Service Routines.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::start()

Definition at line 1595 of file os-c-wrapper.cpp.

1596{
1597 assert (timer != nullptr);
1598 return (os_result_t)(reinterpret_cast<rtos::timer&> (*timer)).start (period);
1599}
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:94

◆ os_timer_stop()

os_result_t os_timer_stop ( os_timer_t timer)
Parameters
[in]timerPointer to timer object instance.
Return values
os_okThe timer has been stopped.
EPERMCannot be invoked from an Interrupt Service Routines.
EAGAINThe timer is not yet started.
ENOTRECOVERABLETimer could not be stopped.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::timer::stop()

Definition at line 1608 of file os-c-wrapper.cpp.

1609{
1610 assert (timer != nullptr);
1611 return (os_result_t)(reinterpret_cast<rtos::timer&> (*timer)).stop ();
1612}