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

SysTick derived clock. More...

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

+ Inheritance diagram for os::rtos::clock_systick:

Public Types

Types & Constants
using duration_t = port::clock::duration_t
 Type of variables holding clock durations.
 
using timestamp_t = port::clock::timestamp_t
 Type of variables holding clock time stamps.
 
using offset_t = port::clock::offset_t
 Type of variables holding clock offsets.
 

Public Member Functions

Constructors & Destructor
 clock_systick ()
 Construct a SysTick clock object instance.
 
virtual ~clock_systick () override
 Destruct the SysTick clock object instance.
 
Public Member Functions
virtual timestamp_t now (void)
 Tell the current time, possibly adjusted for epoch.
 
timestamp_t steady_now (void)
 Tell the current time since startup.
 
result_t sleep_for (duration_t duration)
 Sleep for a relative duration.
 
virtual result_t sleep_until (timestamp_t timestamp)
 Sleep until an absolute timestamp.
 
result_t wait_for (duration_t timeout)
 Timed wait for an event.
 
timestamp_t update_for_slept_time (duration_t duration)
 Increase the internal count after a deep sleep.
 
virtual offset_t offset (void)
 Get adjustment offset (placeholder).
 
virtual offset_t offset (offset_t value)
 Set adjustment offset (placeholder)
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Attributes

Types & Constants
static constexpr uint32_t frequency_hz = OS_INTEGER_SYSTICK_FREQUENCY_HZ
 SysTick frequency in Hz.
 

Public Member Functions

virtual void start (void) override
 Start the clock.
 
template<typename Rep_T >
static constexpr clock::duration_t ticks_cast (Rep_T microsec)
 Convert microseconds to ticks.
 

Detailed Description

Definition at line 460 of file os-clocks.h.

Constructor & Destructor Documentation

◆ clock_systick()

os::rtos::clock_systick::clock_systick ( )

◆ ~clock_systick()

virtual os::rtos::clock_systick::~clock_systick ( )
overridevirtual

Member Function Documentation

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited
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 753 of file os-decls.h.

754 {
755 return name_;
756 }

Referenced by os::memory::lifo::lifo(), os::memory::malloc_memory_resource::malloc_memory_resource(), os::rtos::message_queue_typed< T, Allocator >::message_queue_typed(), os::memory::block_pool::~block_pool(), os::rtos::event_flags::~event_flags(), os::memory::first_fit_top::~first_fit_top(), os::memory::lifo::~lifo(), os::memory::malloc_memory_resource::~malloc_memory_resource(), os::rtos::memory_pool::~memory_pool(), os::rtos::message_queue::~message_queue(), os::rtos::mutex::~mutex(), os::rtos::semaphore::~semaphore(), os::rtos::thread::~thread(), os::rtos::timer::~timer(), os::rtos::memory_pool::alloc(), os::rtos::thread::cancel(), os::rtos::event_flags::clear(), os::rtos::mutex::consistent(), os::rtos::thread::detach(), os::memory::new_delete_memory_resource::do_allocate(), os::memory::block_pool::do_allocate(), os::memory::first_fit_top::do_allocate(), os::memory::lifo::do_allocate(), os::memory::malloc_memory_resource::do_allocate(), os::rtos::thread::flags_raise(), os::rtos::memory_pool::free(), os::rtos::event_flags::get(), os::rtos::thread::interrupt(), os::rtos::thread::join(), os::rtos::thread::kill(), os::rtos::internal::terminated_threads_list::link(), os::rtos::mutex::lock(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::rtos::semaphore::post(), os::rtos::mutex::prio_ceiling(), os::rtos::mutex::prio_ceiling(), os::rtos::thread::priority(), os::rtos::thread::priority_inherited(), os::rtos::event_flags::raise(), os::rtos::message_queue::receive(), os::rtos::memory_pool::reset(), os::rtos::message_queue::reset(), os::rtos::mutex::reset(), os::rtos::semaphore::reset(), os::rtos::thread::resume(), os::rtos::message_queue::send(), os::rtos::clock::sleep_for(), os::rtos::timer::start(), os::rtos::timer::stop(), os::rtos::memory_pool::timed_alloc(), os::rtos::mutex::timed_lock(), os::rtos::message_queue::timed_receive(), os::rtos::message_queue::timed_send(), os::rtos::semaphore::timed_wait(), os::rtos::event_flags::timed_wait(), os::rtos::memory::memory_resource::trace_print_statistics(), os::rtos::memory_pool::try_alloc(), os::rtos::mutex::try_lock(), os::rtos::message_queue::try_receive(), os::rtos::message_queue::try_send(), os::rtos::event_flags::try_wait(), os::rtos::semaphore::try_wait(), os::rtos::internal::ready_threads_list::unlink_head(), os::rtos::mutex::unlock(), os::rtos::event_flags::wait(), os::rtos::semaphore::wait(), and os::rtos::event_flags::waiting().

◆ now()

clock::timestamp_t os::rtos::clock::now ( void  )
virtualinherited
Parameters
None.
Returns
The clock current timestamp (time units from startup plus the epoch offset).
Note
Can be invoked from Interrupt Service Routines.

Reimplemented in os::rtos::adjustable_clock, and os::rtos::clock_highres.

Definition at line 147 of file os-clocks.cpp.

148 {
149 // ----- Enter critical section -----------------------------------------
151
152 // Prevent inconsistent values using the critical section.
153 return steady_count_;
154 // ----- Exit critical section ------------------------------------------
155 }
Interrupts critical section RAII helper.
Definition os-sched.h:502

Referenced by os::rtos::internal::clock_timestamps_list::check_timestamp(), os::estd::chrono::systick_clock::now(), os::estd::chrono::system_clock::now(), os_sysclock_now(), and os::rtos::clock::sleep_until().

◆ offset() [1/2]

virtual offset_t os::rtos::clock::offset ( offset_t  value)
virtualinherited
Parameters
[in]valueIgnored for steady clocks.
Returns
0 for steady clocks.

Reimplemented in os::rtos::adjustable_clock.

◆ offset() [2/2]

clock::offset_t os::rtos::clock::offset ( void  )
virtualinherited
Parameters
None.
Returns
0 for steady clocks.

Reimplemented in os::rtos::adjustable_clock.

Definition at line 335 of file os-clocks.cpp.

336 {
337 return 0;
338 }

◆ sleep_for()

result_t os::rtos::clock::sleep_for ( duration_t  duration)
inherited
Parameters
[in]durationThe number of clock units (ticks or seconds) to sleep.
Return values
ETIMEDOUTThe sleep lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 175 of file os-clocks.cpp.

176 {
177#if defined(OS_TRACE_RTOS_CLOCKS)
178
179#pragma GCC diagnostic push
180#if defined(__clang__)
181#elif defined(__GNUC__)
182#pragma GCC diagnostic ignored "-Wuseless-cast"
183#endif
184 trace::printf ("%s(%u) %p %s\n", __func__,
185 static_cast<unsigned int> (duration),
187#pragma GCC diagnostic pop
188
189#endif // defined(OS_TRACE_RTOS_CLOCKS)
190
191 // Don't call this from interrupt handlers.
193 // Don't call this from critical regions.
194 os_assert_err (!scheduler::locked (), EPERM);
195
196 clock::timestamp_t timestamp = steady_now () + duration;
197 for (;;)
198 {
199 result_t res;
200 res = internal_wait_until_ (timestamp, steady_list_);
201
202 timestamp_t n = steady_now ();
203 if (n >= timestamp)
204 {
205 return ETIMEDOUT;
206 }
207
208 if (this_thread::thread ().interrupted ())
209 {
210 return EINTR;
211 }
212
213 if (res != result::ok)
214 {
215 return res;
216 }
217 }
218 return ENOTRECOVERABLE;
219 }
timestamp_t steady_now(void)
Tell the current time since startup.
const char * name(void) const
Get object name.
Definition os-decls.h:753
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:88
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1101
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:858
thread & thread(void)
Get the current running thread.
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1101

References os::rtos::interrupts::in_handler_mode(), os::rtos::scheduler::locked(), os::rtos::internal::object_named::name(), os::rtos::result::ok, os_assert_err, os::trace::printf(), os::rtos::clock::steady_now(), and os::rtos::this_thread::thread().

Referenced by os_sysclock_sleep_for(), and osDelay().

◆ sleep_until()

result_t os::rtos::clock::sleep_until ( timestamp_t  timestamp)
virtualinherited
Parameters
[in]timestampThe absolute moment in time, in clock units.
Return values
ETIMEDOUTThe sleep lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Reimplemented in os::rtos::adjustable_clock.

Definition at line 225 of file os-clocks.cpp.

226 {
227#if defined(OS_TRACE_RTOS_CLOCKS)
228 trace::printf ("%s()\n", __func__);
229#endif
230
231 // Don't call this from interrupt handlers.
233 // Don't call this from critical regions.
234 os_assert_err (!scheduler::locked (), EPERM);
235
236 for (;;)
237 {
238 result_t res;
239 res = internal_wait_until_ (timestamp, steady_list_);
240
241 timestamp_t nw = now ();
242 if (nw >= timestamp)
243 {
244 return ETIMEDOUT;
245 }
246
247 if (this_thread::thread ().interrupted ())
248 {
249 return EINTR;
250 }
251
252 if (res != result::ok)
253 {
254 return res;
255 }
256 }
257 return ENOTRECOVERABLE;
258 }
virtual timestamp_t now(void)
Tell the current time, possibly adjusted for epoch.

References os::rtos::interrupts::in_handler_mode(), os::rtos::scheduler::locked(), os::rtos::clock::now(), os::rtos::result::ok, os_assert_err, os::trace::printf(), and os::rtos::this_thread::thread().

Referenced by os_sysclock_sleep_until().

◆ start()

virtual void os::rtos::clock_systick::start ( void  )
overridevirtual
Parameters
None.
Returns
Nothing.

For system clocks it is called from the system startup code.

Implements os::rtos::clock.

Referenced by os::rtos::scheduler::start().

◆ steady_now()

clock::timestamp_t os::rtos::clock::steady_now ( void  )
inherited
Parameters
None.
Returns
The clock current steady timestamp (time units from startup).
Note
Can be invoked from Interrupt Service Routines.

Definition at line 161 of file os-clocks.cpp.

162 {
163 // ----- Enter critical section -----------------------------------------
165
166 // Prevent inconsistent values using the critical section.
167 return steady_count_;
168 // ----- Exit critical section ------------------------------------------
169 }

Referenced by os::rtos::clock::sleep_for(), and os::rtos::clock::wait_for().

◆ ticks_cast()

template<typename Rep_T >
static constexpr clock::duration_t os::rtos::clock_systick::ticks_cast ( Rep_T  microsec)
staticconstexpr
Template Parameters
Rep_TType of input, auto deduced (usually uint32_t or uin64_t)
Parameters
[in]microsecThe number of microseconds.
Returns
The number of ticks.

Referenced by osDelay(), osMutexWait(), osSignalWait(), and osTimerStart().

◆ update_for_slept_time()

clock::timestamp_t os::rtos::clock::update_for_slept_time ( duration_t  duration)
inherited
Parameters
durationNumber of ticks lost during sleep.
Returns
The clock current steady timestamp (time units from startup).

During deep sleep the interrupts used to count clock ticks are usually disabled and an external RTC is configured to wake-up the device, so a number of clock ticks are lost.

To keep the clocks accurate, it is recommended to sample the external RTC before entering deep sleep and again when the device is back to life, compute the time slept as difference, and use this function to update the internal clock counter.

Definition at line 315 of file os-clocks.cpp.

316 {
317 // ----- Enter critical section -----------------------------------------
319
320#pragma GCC diagnostic push
321#if defined(__clang__)
322#pragma clang diagnostic ignored "-Wdeprecated-volatile"
323#elif defined(__GNUC__)
324#pragma GCC diagnostic ignored "-Wvolatile"
325#endif
326 steady_count_ += duration;
327#pragma GCC diagnostic pop
328
329 internal_check_timestamps ();
330 return steady_count_;
331 // ----- Exit critical section ------------------------------------------
332 }

◆ wait_for()

result_t os::rtos::clock::wait_for ( duration_t  timeout)
inherited
Parameters
[in]timeoutThe timeout in clock units.
Return values
result::okAn event occurred before the timeout.
ETIMEDOUTThe wait lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 264 of file os-clocks.cpp.

265 {
266#if defined(OS_TRACE_RTOS_CLOCKS)
267
268#pragma GCC diagnostic push
269#if defined(__clang__)
270#elif defined(__GNUC__)
271#pragma GCC diagnostic ignored "-Wuseless-cast"
272#endif
273 trace::printf ("%s(%u)\n", __func__,
274 static_cast<unsigned int> (timeout));
275#pragma GCC diagnostic pop
276
277#endif // defined(OS_TRACE_RTOS_CLOCKS)
278
279 // Don't call this from interrupt handlers.
281 // Don't call this from critical regions.
282 os_assert_err (!scheduler::locked (), EPERM);
283
284 clock::timestamp_t timestamp = steady_now () + timeout;
285
286 result_t res;
287 res = internal_wait_until_ (timestamp, steady_list_);
288
289 timestamp_t nw = steady_now ();
290 if (nw >= timestamp)
291 {
292 return ETIMEDOUT;
293 }
294
295 if (this_thread::thread ().interrupted ())
296 {
297 return EINTR;
298 }
299
300 return res;
301 }

References os::rtos::interrupts::in_handler_mode(), os::rtos::scheduler::locked(), os_assert_err, os::trace::printf(), os::rtos::clock::steady_now(), and os::rtos::this_thread::thread().

Referenced by os_sysclock_wait_for().

Member Data Documentation

◆ frequency_hz

constexpr uint32_t os::rtos::clock_systick::frequency_hz = OS_INTEGER_SYSTICK_FREQUENCY_HZ
staticconstexpr

Definition at line 471 of file os-clocks.h.

Referenced by main(), and os_systick_handler().


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