µ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

C API timer definitions.

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:785

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

Timer attributes.

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

Type of timer function arguments.

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)

Type of timer function.

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

Type of variables holding timer states.

See also
os::rtos::timer::state_t

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

◆ os_timer_t

typedef struct os_timer_s os_timer_t

Timer object storage.

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

Type of variables holding timer types.

See also
os::rtos::timer::type_t

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

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

An enumeration with the timer types.

Enumerator
os_timer_once 
os_timer_periodic 

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

Function Documentation

◆ os_timer_attr_get_periodic()

const os_timer_attr_t * os_timer_attr_get_periodic ( void  )

Get a periodic timer attributes object instance.

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 1308 of file os-c-wrapper.cpp.

◆ os_timer_attr_init()

void os_timer_attr_init ( os_timer_attr_t attr)

Initialise the single shot timer attributes.

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 1282 of file os-c-wrapper.cpp.

◆ os_timer_attr_periodic_init()

void os_timer_attr_periodic_init ( os_timer_attr_t attr)

Initialise the periodic timer attributes.

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 1295 of file os-c-wrapper.cpp.

◆ 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 
)

Construct a statically allocated timer object instance.

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 1322 of file os-c-wrapper.cpp.

◆ os_timer_delete()

void os_timer_delete ( os_timer_t timer)

Destruct the timer object instance and deallocate it.

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 1391 of file os-c-wrapper.cpp.

◆ os_timer_destruct()

void os_timer_destruct ( os_timer_t timer)

Destruct the statically allocated timer object instance.

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 1345 of file os-c-wrapper.cpp.

◆ os_timer_get_name()

const char * os_timer_get_name ( os_timer_t timer)

Get the timer name.

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 1404 of file os-c-wrapper.cpp.

◆ 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 
)

Allocate a timer object instance and construct it.

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 1365 of file os-c-wrapper.cpp.

◆ os_timer_start()

os_result_t os_timer_start ( os_timer_t timer,
os_clock_duration_t  period 
)

Start or restart the timer.

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 1417 of file os-c-wrapper.cpp.

◆ os_timer_stop()

os_result_t os_timer_stop ( os_timer_t timer)

Stop the 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 1430 of file os-c-wrapper.cpp.