C API clocks definitions.
More...
- For the complete definition, see
- RTOS C++ API
- Examples
int
{
{
ts = os_sysclock_steady_now ();
}
}
os_result_t os_sysclock_wait_for(os_clock_duration_t timeout)
Timed wait for an event.
os_clock_timestamp_t os_sysclock_now(void)
Tell the current time since startup.
os_result_t os_sysclock_sleep_until(os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_result_t os_sysclock_sleep_for(os_clock_duration_t duration)
Sleep for a relative duration.
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
◆ os_clock_t
This C structure has the same size as the C++ os::rtos::clock object.
The members of this structure are hidden and should not be used directly, but only through specific functions.
- See also
- os::rtos::clock
◆ os_clock_get_hrclock()
- Returns
- The address of the clock_highres instance.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::hrclock
Definition at line 1396 of file os-c-wrapper.cpp.
1397{
1399}
clock_highres hrclock
The high resolution clock object instance.
References os::rtos::hrclock.
◆ os_clock_get_name()
| const char * os_clock_get_name |
( |
os_clock_t * |
clock | ) |
|
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
- Returns
- Null terminated string.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::name()
Definition at line 1257 of file os-c-wrapper.cpp.
1258{
1259 assert (
clock !=
nullptr);
1261}
◆ os_clock_get_offset()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
- Returns
- Integer value representing the offset to epoch.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::adjustable_clock::offset()
Definition at line 1340 of file os-c-wrapper.cpp.
1341{
1342 assert (
clock !=
nullptr);
1344 .offset ();
1345}
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
◆ os_clock_get_rtclock()
- Returns
- The address of the clock_rtc instance.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::rtclock
Definition at line 1384 of file os-c-wrapper.cpp.
1385{
1387}
clock_rtc rtclock
The real time clock object instance.
References os::rtos::rtclock.
◆ os_clock_get_sysclock()
- Returns
- The address of the clock_systick instance.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::sysclock
Definition at line 1372 of file os-c-wrapper.cpp.
1373{
1375}
clock_systick sysclock
The system clock object instance.
References os::rtos::sysclock.
◆ os_clock_now()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
- Returns
- The clock current timestamp (time units from startup plus the epoch offset).
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::now()
Definition at line 1270 of file os-c-wrapper.cpp.
1271{
1272 assert (
clock !=
nullptr);
1274 .now ();
1275}
◆ os_clock_set_offset()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
| [in] | offset | Integer representing the offset to epoch (positive). |
- Returns
- Integer value representing the previous offset to epoch.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::adjustable_clock::offset(os::rtos::clock::offset_t)
Definition at line 1357 of file os-c-wrapper.cpp.
1358{
1359 assert (
clock !=
nullptr);
1360 assert (
clock !=
nullptr);
1362 .offset ((clock::offset_t)offset);
1363}
◆ os_clock_sleep_for()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
| [in] | duration | The number of clock units (ticks or seconds) to sleep. |
- Return values
-
| ETIMEDOUT | The sleep lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::sleep_for()
Definition at line 1298 of file os-c-wrapper.cpp.
1299{
1300 assert (
clock !=
nullptr);
1302 .sleep_for (duration);
1303}
uint32_t os_result_t
Type of values returned by RTOS functions.
◆ os_clock_sleep_until()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
| [in] | timestamp | The absolute moment in time, in clock units. |
- Return values
-
| ETIMEDOUT | The sleep lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::sleep_until()
Definition at line 1312 of file os-c-wrapper.cpp.
1313{
1314 assert (
clock !=
nullptr);
1316 .sleep_until (timestamp);
1317}
◆ os_clock_steady_now()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
- Returns
- The clock current timestamp (time units from startup).
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::steady_now()
Definition at line 1284 of file os-c-wrapper.cpp.
1285{
1286 assert (
clock !=
nullptr);
1288 .steady_now ();
1289}
◆ os_clock_wait_for()
- Parameters
-
| [in] | clock | Pointer to clock object instance. |
| [in] | timeout | The timeout in clock units. |
- Return values
-
| os_ok | An event occurred before the timeout. |
| ETIMEDOUT | The wait lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::wait_for()
Definition at line 1326 of file os-c-wrapper.cpp.
1327{
1328 assert (
clock !=
nullptr);
1330 .wait_for (timeout);
1331}
◆ os_rtc_handler()
| void os_rtc_handler |
( |
void |
| ) |
|
◆ os_sysclock_now()
◆ os_sysclock_sleep_for()
- Parameters
-
| [in] | duration | The number of clock units (ticks or seconds) to sleep. |
- Return values
-
| ETIMEDOUT | The sleep lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::sleep_for()
Definition at line 1422 of file os-c-wrapper.cpp.
1423{
1425}
result_t sleep_for(duration_t duration)
Sleep for a relative duration.
References os::rtos::clock::sleep_for(), and os::rtos::sysclock.
◆ os_sysclock_sleep_until()
- Parameters
-
| [in] | timestamp | The absolute moment in time, in clock units. |
- Return values
-
| ETIMEDOUT | The sleep lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::sleep_until()
Definition at line 1434 of file os-c-wrapper.cpp.
1435{
1437}
virtual result_t sleep_until(timestamp_t timestamp)
Sleep until an absolute timestamp.
References os::rtos::clock::sleep_until(), and os::rtos::sysclock.
◆ os_sysclock_ticks_cast()
- Parameters
-
| [in] | microsec | The number of microseconds. |
- Returns
- The number of ticks.
Definition at line 969 of file os-c-api.h.
970 {
971#pragma GCC diagnostic push
972#if defined(__clang__)
973#elif defined(__GNUC__)
974#if defined(__cplusplus)
975#pragma GCC diagnostic ignored "-Wuseless-cast"
976#endif
977#endif
978 return (
981 + (uint32_t)1000000ul - 1)
982 / (uint32_t)1000000ul);
983#pragma GCC diagnostic pop
984 }
#define OS_INTEGER_SYSTICK_FREQUENCY_HZ
Define the scheduler frequency, in Hz.
os_port_clock_duration_t os_clock_duration_t
Type of variables holding clock durations.
References OS_INTEGER_SYSTICK_FREQUENCY_HZ.
◆ os_sysclock_ticks_cast_long()
- Parameters
-
| [in] | microsec | The number of microseconds. |
- Returns
- The number of ticks.
Definition at line 992 of file os-c-api.h.
993 {
994#pragma GCC diagnostic push
995#if defined(__clang__)
996#elif defined(__GNUC__)
997#if defined(__cplusplus)
998#pragma GCC diagnostic ignored "-Wuseless-cast"
999#endif
1000#endif
1001 return (
1004 + (uint64_t)1000000ul - 1)
1005 / (uint64_t)1000000ul);
1006#pragma GCC diagnostic pop
1007 }
References OS_INTEGER_SYSTICK_FREQUENCY_HZ.
◆ os_sysclock_wait_for()
- Parameters
-
| [in] | timeout | The timeout in clock units. |
- Return values
-
| os_ok | An event occurred before the timeout. |
| ETIMEDOUT | The wait lasted the entire duration. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
| EINTR | The sleep was interrupted. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::clock::wait_for()
Definition at line 1446 of file os-c-wrapper.cpp.
1447{
1449}
result_t wait_for(duration_t timeout)
Timed wait for an event.
References os::rtos::sysclock, and os::rtos::clock::wait_for().
◆ os_systick_handler()
| void os_systick_handler |
( |
void |
| ) |
|
Must be called from the physical interrupt handler.
Definition at line 36 of file os-clocks.cpp.
37{
39
40#if defined(OS_USE_RTOS_PORT_SCHEDULER)
41
43 {
45 }
46#endif
47
48#if defined(OS_TRACE_RTOS_SYSCLOCK_TICK)
50#elif defined(OS_TRACE_RTOS_SYSCLOCK_TICK_BRACES)
52#endif
53
54 {
55
57
58 sysclock.internal_increment_count ();
60
61 }
62 sysclock.internal_check_timestamps ();
63 hrclock.internal_check_timestamps ();
64
65#if !defined(OS_INCLUDE_RTOS_REALTIME_CLOCK_DRIVER)
66
67
69
70 if (--ticks == 0)
71 {
73
75 }
76
77#endif
78
79#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
80
82
83#endif
84
85#if defined(OS_TRACE_RTOS_SYSCLOCK_TICK_BRACES)
87#endif
88}
void internal_increment_count(void)
static constexpr uint32_t frequency_hz
SysTick frequency in Hz.
static void internal_interrupt_service_routine(void)
SysTick implementation hook.
int printf(const char *format,...)
Write a formatted string to the trace device.
int putchar(int c)
Write the single character to the trace device.
void os_rtc_handler(void)
RTC interrupt handler.
References os::rtos::clock_systick::frequency_hz, os::rtos::hrclock, os::rtos::clock_highres::internal_increment_count(), os::rtos::port::clock_systick::internal_interrupt_service_routine(), os_rtc_handler(), os::trace::printf(), os::trace::putchar(), os::rtos::port::scheduler::reschedule(), os::rtos::scheduler::started(), and os::rtos::sysclock.