µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
os-c-api.h
Go to the documentation of this file.
1 /*
2  * This file is part of the µOS++ distribution.
3  * (https://github.com/micro-os-plus)
4  * Copyright (c) 2016 Liviu Ionescu.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 /*
29  * The code was originally inspired by ARM CMSIS cmsis_os.h file, v1.02,
30  * and tries to remain functionally close to the CMSIS specifications.
31  */
32 
33 #ifndef CMSIS_PLUS_RTOS_OS_C_API_H_
34 #define CMSIS_PLUS_RTOS_OS_C_API_H_
35 
36 // ----------------------------------------------------------------------------
37 
38 // Include the µOS++ C API structures declarations.
40 
42 
43 #include <stdint.h>
44 #include <stddef.h>
45 #include <stdbool.h>
46 
47 // ----------------------------------------------------------------------------
48 
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
59  // --------------------------------------------------------------------------
68  enum
69  {
73  os_ok = 0,
74  };
75 
80  // --------------------------------------------------------------------------
104  int
105  os_main (int argc, char* argv[]);
106 
111  // --------------------------------------------------------------------------
125  os_sched_initialize (void);
126 
134  void
135  __attribute__((noreturn))
136  os_sched_start (void);
137 
145  bool
146  os_sched_is_started (void);
147 
155  os_sched_lock (void);
156 
164  os_sched_unlock (void);
165 
173 
181  bool
182  os_sched_is_locked (void);
183 
191  bool
192  os_sched_is_preemptive (void);
193 
199  bool
200  os_sched_set_preemptive (bool state);
201 
206  // --------------------------------------------------------------------------
212 #if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
213 
221 
222 #endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
223 
224 #if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
225 
233 
234 #endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
235 
240  // --------------------------------------------------------------------------
253  bool
254  os_irq_in_handler_mode (void);
255 
263  os_irq_critical_enter (void);
264 
271  void
273 
274  // --------------------------------------------------------------------------
275 
284 
291  void
293 
294 #if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
295 
303  os_irq_get_stack (void);
304 
305 #endif
306 
315  // --------------------------------------------------------------------------
332  os_thread_t*
333  os_this_thread (void);
334 
342  void
343  os_this_thread_suspend (void);
344 
351  void
352  __attribute__((noreturn))
353  os_this_thread_exit (void* exit_ptr);
354 
371  os_flags_mode_t mode);
372 
388  os_flags_mode_t mode);
389 
409  os_clock_duration_t timeout,
410  os_flags_mask_t* oflags,
411  os_flags_mode_t mode);
412 
424 
436 
441  // --------------------------------------------------------------------------
453  void
455 
475  void
476  os_thread_construct (os_thread_t* thread, const char* name,
477  os_thread_func_t func, const os_thread_func_args_t args,
478  const os_thread_attr_t* attr);
479 
486  void
488 
497  os_thread_t*
498  os_thread_new (const char* name, os_thread_func_t func,
499  const os_thread_func_args_t args,
500  const os_thread_attr_t* attr);
501 
508  void
510 
525  const char*
527 
535 
547 
556  os_thread_join (os_thread_t* thread, void** exit_ptr);
557 
564  void
566 
579  os_flags_mask_t* oflags);
580 
588 
589 #if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
590 
596  os_thread_user_storage_t*
598 
599 #endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
600 
608 
613  // --------------------------------------------------------------------------
619 #define os_thread_create os_thread_construct
620 #define os_thread_destroy os_thread_destruct
621 
626  // --------------------------------------------------------------------------
638  size_t
640 
646  size_t
647  os_thread_stack_set_default_size (size_t size_bytes);
648 
655  size_t
657 
663  size_t
664  os_thread_stack_set_min_size (size_t size_bytes);
665 
673 
681 
687  size_t
689 
695  size_t
697 
704  bool
706 
713  bool
715 
720  // --------------------------------------------------------------------------
726 #if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
727 
735 
736 #endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
737 
738 #if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
739 
747 
748 #endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
749 
754  // --------------------------------------------------------------------------
768 
777 
783  os_thread_t*
785 
793 
802  // --------------------------------------------------------------------------
818  const char*
820 
829 
837 
849 
860 
872 
880 
889 
894  os_clock_t*
895  os_clock_get_sysclock (void);
896 
901  os_clock_t*
902  os_clock_get_rtclock (void);
903 
908  os_clock_t*
909  os_clock_get_hrclock (void);
910 
911  // --------------------------------------------------------------------------
912 
920  os_sysclock_now (void);
921 
932 
942 
953 
954 #pragma GCC diagnostic push
955 #if defined(__cplusplus)
956 #pragma GCC diagnostic ignored "-Wold-style-cast"
957 #endif
958 
964  inline os_clock_duration_t
965  __attribute__((always_inline))
966  os_sysclock_ticks_cast (uint32_t microsec)
967  {
968  return (os_clock_duration_t) ((((microsec)
969  * ((uint32_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint32_t) 1000000ul
970  - 1) / (uint32_t) 1000000ul);
971  }
972 
978  inline os_clock_duration_t
979  __attribute__((always_inline))
980  os_sysclock_ticks_cast_long (uint64_t microsec)
981  {
982  return (os_clock_duration_t) ((((microsec)
983  * ((uint64_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint64_t) 1000000ul
984  - 1) / (uint64_t) 1000000ul);
985  }
986 
987 #pragma GCC diagnostic pop
988 
997  // --------------------------------------------------------------------------
1014  void
1016 
1023  void
1025 
1030  const os_timer_attr_t*
1032 
1052  void
1053  os_timer_construct (os_timer_t* timer, const char* name,
1054  os_timer_func_t function, os_timer_func_args_t args,
1055  const os_timer_attr_t* attr);
1056 
1063  void
1064  os_timer_destruct (os_timer_t* timer);
1065 
1074  os_timer_t*
1075  os_timer_new (const char* name, os_timer_func_t function,
1076  os_timer_func_args_t args, const os_timer_attr_t* attr);
1077 
1084  void
1085  os_timer_delete (os_timer_t* timer);
1086 
1101  const char*
1102  os_timer_get_name (os_timer_t* timer);
1103 
1112  os_result_t
1114 
1123  os_result_t
1124  os_timer_stop (os_timer_t* timer);
1125 
1130  // --------------------------------------------------------------------------
1136 #define os_timer_create os_timer_construct
1137 #define os_timer_destroy os_timer_destruct
1138 
1147  // --------------------------------------------------------------------------
1164  void
1166 
1173  void
1175 
1180  const os_mutex_attr_t*
1182 
1200  void
1201  os_mutex_construct (os_mutex_t* mutex, const char* name,
1202  const os_mutex_attr_t* attr);
1203 
1212  void
1213  os_mutex_recursive_construct (os_mutex_t* mutex, const char* name,
1214  const os_mutex_attr_t* attr);
1215 
1222  void
1223  os_mutex_destruct (os_mutex_t* mutex);
1224 
1231  os_mutex_t*
1232  os_mutex_new (const char* name, const os_mutex_attr_t* attr);
1233 
1240  os_mutex_t*
1241  os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr);
1242 
1249  void
1250  os_mutex_delete (os_mutex_t* mutex);
1251 
1266  const char*
1267  os_mutex_get_name (os_mutex_t* mutex);
1268 
1289  os_result_t
1290  os_mutex_lock (os_mutex_t* mutex);
1291 
1314  os_result_t
1315  os_mutex_try_lock (os_mutex_t* mutex);
1316 
1339  os_result_t
1341 
1352  os_result_t
1353  os_mutex_unlock (os_mutex_t* mutex);
1354 
1362 
1372  os_result_t
1374  os_thread_prio_t* old_prio_ceiling);
1375 
1384  os_result_t
1386 
1392  os_thread_t*
1393  os_mutex_get_owner (os_mutex_t* mutex);
1394 
1401  os_mutex_get_type (os_mutex_t* mutex);
1402 
1410 
1418 
1424  os_result_t
1425  os_mutex_reset (os_mutex_t* mutex);
1426 
1431  // --------------------------------------------------------------------------
1437 #define os_mutex_create os_mutex_construct
1438 #define os_mutex_recursive_create os_mutex_recursive_construct
1439 #define os_mutex_destroy os_mutex_destruct
1440 
1449  // --------------------------------------------------------------------------
1466  void
1468 
1495  void
1496  os_condvar_construct (os_condvar_t* condvar, const char* name,
1497  const os_condvar_attr_t* attr);
1498 
1506  void
1507  os_condvar_destruct (os_condvar_t* condvar);
1508 
1523  os_condvar_t*
1524  os_condvar_new (const char* name, const os_condvar_attr_t* attr);
1525 
1533  void
1534  os_condvar_delete (os_condvar_t* condvar);
1535 
1550  const char*
1551  os_condvar_get_name (os_condvar_t* condvar);
1552 
1561  os_result_t
1562  os_condvar_signal (os_condvar_t* condvar);
1563 
1572  os_result_t
1574 
1593  os_result_t
1594  os_condvar_wait (os_condvar_t* condvar, os_mutex_t* mutex);
1595 
1616  os_result_t
1617  os_condvar_timed_wait (os_condvar_t* condvar, os_mutex_t* mutex,
1618  os_clock_duration_t timeout);
1619 
1624  // --------------------------------------------------------------------------
1630 #define os_condvar_create os_condvar_construct
1631 #define os_condvar_destroy os_condvar_destruct
1632 
1641  // --------------------------------------------------------------------------
1658  void
1660 
1668  void
1670  const os_semaphore_count_t initial_value);
1671 
1678  void
1680  const os_semaphore_count_t max_value,
1681  const os_semaphore_count_t initial_value);
1682 
1687  const os_semaphore_attr_t*
1689 
1707  void
1708  os_semaphore_construct (os_semaphore_t* semaphore, const char* name,
1709  const os_semaphore_attr_t* attr);
1710 
1719  void
1720  os_semaphore_binary_construct (os_semaphore_t* semaphore, const char* name,
1721  const os_semaphore_count_t initial_value);
1722 
1733  void
1734  os_semaphore_counting_construct (os_semaphore_t* semaphore, const char* name,
1735  const os_semaphore_count_t max_value,
1736  const os_semaphore_count_t initial_value);
1737 
1744  void
1746 
1754  os_semaphore_new (const char* name, const os_semaphore_attr_t* attr);
1755 
1763  os_semaphore_binary_new (const char* name,
1764  const os_semaphore_count_t initial_value);
1765 
1774  os_semaphore_counting_new (const char* name,
1775  const os_semaphore_count_t max_value,
1776  const os_semaphore_count_t initial_value);
1777 
1784  void
1785  os_semaphore_delete (os_semaphore_t* semaphore);
1786 
1801  const char*
1803 
1812  os_result_t
1813  os_semaphore_post (os_semaphore_t* semaphore);
1814 
1825  os_result_t
1826  os_semaphore_wait (os_semaphore_t* semaphore);
1827 
1839  os_result_t
1841 
1857  os_result_t
1859  os_clock_duration_t timeout);
1860 
1868 
1875  os_result_t
1876  os_semaphore_reset (os_semaphore_t* semaphore);
1877 
1885 
1893 
1903 #define os_semaphore_create os_semaphore_construct
1904 #define os_semaphore_binary_create os_semaphore_binary_construct
1905 #define os_semaphore_counting_create os_semaphore_counting_construct
1906 #define os_semaphore_destroy os_semaphore_destruct
1907 
1916  // --------------------------------------------------------------------------
1933  void
1935 
1955  void
1956  os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
1957  size_t block_size_bytes, const os_mempool_attr_t* attr);
1958 
1965  void
1966  os_mempool_destruct (os_mempool_t* mempool);
1967 
1976  os_mempool_t*
1977  os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
1978  const os_mempool_attr_t* attr);
1979 
1987  void
1988  os_mempool_delete (os_mempool_t* mempool);
1989 
2004  const char*
2005  os_mempool_get_name (os_mempool_t* mempool);
2006 
2012  void*
2013  os_mempool_alloc (os_mempool_t* mempool);
2014 
2020  void*
2022 
2029  void*
2031 
2039  os_result_t
2040  os_mempool_free (os_mempool_t* mempool, void* block);
2041 
2047  size_t
2049 
2055  size_t
2057 
2063  size_t
2065 
2072  bool
2073  os_mempool_is_empty (os_mempool_t* mempool);
2074 
2081  bool
2082  os_mempool_is_full (os_mempool_t* mempool);
2083 
2090  os_result_t
2091  os_mempool_reset (os_mempool_t* mempool);
2092 
2098  void*
2099  os_mempool_get_pool (os_mempool_t* mempool);
2100 
2110 #define os_mempool_create os_mempool_construct
2111 #define os_mempool_destroy os_mempool_destruct
2112 
2121  // --------------------------------------------------------------------------
2138  void
2140 
2160  void
2161  os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2162  size_t msg_size_bytes, const os_mqueue_attr_t* attr);
2163 
2170  void
2171  os_mqueue_destruct (os_mqueue_t* mqueue);
2172 
2181  os_mqueue_t*
2182  os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2183  const os_mqueue_attr_t* attr);
2184 
2192  void
2193  os_mqueue_delete (os_mqueue_t* mqueue);
2194 
2209  const char*
2210  os_mqueue_get_name (os_mqueue_t* mqueue);
2211 
2228  os_result_t
2229  os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2230  os_mqueue_prio_t mprio);
2231 
2247  os_result_t
2248  os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2249  os_mqueue_prio_t mprio);
2250 
2270  os_result_t
2271  os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2272  os_clock_duration_t timeout, os_mqueue_prio_t mprio);
2273 
2293  os_result_t
2294  os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2295  os_mqueue_prio_t* mprio);
2296 
2315  os_result_t
2316  os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2317  os_mqueue_prio_t* mprio);
2318 
2341  os_result_t
2342  os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2343  os_clock_duration_t timeout,
2344  os_mqueue_prio_t* mprio);
2345 
2351  size_t
2353 
2359  size_t
2361 
2367  size_t
2369 
2376  bool
2377  os_mqueue_is_empty (os_mqueue_t* mqueue);
2378 
2385  bool
2386  os_mqueue_is_full (os_mqueue_t* mqueue);
2387 
2394  os_result_t
2395  os_mqueue_reset (os_mqueue_t* mqueue);
2396 
2406 #define os_mqueue_create os_mqueue_construct
2407 #define os_mqueue_destroy os_mqueue_destruct
2408 
2417  // --------------------------------------------------------------------------
2434  void
2436 
2454  void
2455  os_evflags_construct (os_evflags_t* evflags, const char* name,
2456  const os_evflags_attr_t* attr);
2457 
2464  void
2465  os_evflags_destruct (os_evflags_t* evflags);
2466 
2473  os_evflags_t*
2474  os_evflags_new (const char* name, const os_evflags_attr_t* attr);
2475 
2483  void
2484  os_evflags_delete (os_evflags_t* evflags);
2485 
2500  const char*
2501  os_evflags_get_name (os_evflags_t* evflags);
2502 
2518  os_result_t
2520  os_flags_mask_t* oflags, os_flags_mode_t mode);
2521 
2536  os_result_t
2538  os_flags_mask_t* oflags, os_flags_mode_t mode);
2539 
2558  os_result_t
2560  os_clock_duration_t timeout, os_flags_mask_t* oflags,
2561  os_flags_mode_t mode);
2562 
2573  os_result_t
2575  os_flags_mask_t* oflags);
2576 
2586  os_result_t
2588  os_flags_mask_t* oflags);
2589 
2600  os_flags_mode_t mode);
2601 
2608  bool
2610 
2620 #define os_evflags_create os_evflags_construct
2621 #define os_evflags_destroy os_evflags_destruct
2622 
2631  // --------------------------------------------------------------------------
2646  os_memory_t*
2647  os_memory_get_default (void);
2648 
2655  void*
2656  os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment);
2657 
2665  void
2666  os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
2667  size_t alignment);
2668 
2677  void
2678  os_memory_reset (os_memory_t* memory);
2679 
2688  bool
2689  os_memory_coalesce (os_memory_t* memory);
2690 
2696  size_t
2698 
2704  size_t
2706 
2712  size_t
2714 
2720  size_t
2722 
2728  size_t
2730 
2739 // --------------------------------------------------------------------------
2740 #ifdef __cplusplus
2741 }
2742 #endif
2743 
2744 // ----------------------------------------------------------------------------
2745 
2746 #endif /* CMSIS_PLUS_RTOS_OS_C_API_H_ */
os_result_t os_evflags_clear(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags)
Clear event flags.
size_t os_thread_stack_set_min_size(size_t size_bytes)
Set the min stack size.
os_sched_state_t os_sched_set_locked(os_sched_state_t state)
Lock/unlock the scheduler.
os_sched_state_t os_sched_unlock(void)
Unlock the scheduler.
os_result_t os_mqueue_try_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_mqueue_prio_t mprio)
Try to send a message to the queue.
const os_timer_attr_t * os_timer_attr_get_periodic(void)
Get a periodic timer attributes object instance.
void * os_mempool_timed_alloc(os_mempool_t *mempool, os_clock_duration_t timeout)
Allocate a memory block with timeout.
uint8_t os_mutex_protocol_t
Definition: os-c-decls.h:799
void os_mqueue_delete(os_mqueue_t *mqueue)
Destruct the message queue object instance and deallocate it.
void os_timer_attr_init(os_timer_attr_t *attr)
Initialise the single shot timer attributes.
os_result_t os_mqueue_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_mqueue_prio_t *mprio)
Receive a message from the queue.
class thread::stack * stack(void)
Get the interrupts stack.
Definition: os-core.cpp:562
void os_mutex_construct(os_mutex_t *mutex, const char *name, const os_mutex_attr_t *attr)
Construct a statically allocated mutex object instance.
os_result_t os_thread_join(os_thread_t *thread, void **exit_ptr)
Wait for thread termination.
size_t os_memory_get_free_bytes(os_memory_t *memory)
Get the total size of free chunks.
os_semaphore_t * os_semaphore_counting_new(const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Allocate a counting semaphore object instance and construct it.
const char * os_mqueue_get_name(os_mqueue_t *mqueue)
Get the message queue name.
os_result_t os_thread_flags_raise(os_thread_t *thread, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise thread event flags.
os_clock_t * os_clock_get_rtclock(void)
Get rtclock (the real-time clock).
os_result_t os_mempool_reset(os_mempool_t *mempool)
Reset the memory pool.
void os_semaphore_delete(os_semaphore_t *semaphore)
Destruct the semaphore object instance.
void os_semaphore_destruct(os_semaphore_t *semaphore)
Destruct the statically allocated semaphore object instance.
void os_irq_uncritical_exit(os_irq_state_t state)
Exit the interrupts uncritical section.
const char * os_mempool_get_name(os_mempool_t *mempool)
Get the memory pool name.
os_result_t os_mempool_free(os_mempool_t *mempool, void *block)
Free the memory block.
os_iterator_t os_children_threads_iter_begin(os_thread_t *thread)
Get the beginning of the list of children threads.
os_result_t os_semaphore_try_wait(os_semaphore_t *semaphore)
Try to lock the semaphore.
os_thread_stack_t * os_thread_get_stack(os_thread_t *thread)
Get the thread context stack.
Message queue object storage.
Definition: os-c-decls.h:1307
os_condvar_t * os_condvar_new(const char *name, const os_condvar_attr_t *attr)
Allocate a condition variable object instance and construct it.
void * os_thread_func_args_t
Type of thread function arguments.
Definition: os-c-decls.h:331
os_mutex_type_t os_mutex_get_type(os_mutex_t *mutex)
Get the mutex type.
os_result_t os_clock_sleep_for(os_clock_t *clock, os_clock_duration_t duration)
Sleep for a relative duration.
os_result_t os_mqueue_timed_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_clock_duration_t timeout, os_mqueue_prio_t *mprio)
Receive a message from the queue with timeout.
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_delete(os_timer_t *timer)
Destruct the timer object instance and deallocate it.
Thread attributes.
Definition: os-c-decls.h:489
size_t os_memory_get_allocated_bytes(os_memory_t *memory)
Get the total size of allocated chunks.
void os_evflags_delete(os_evflags_t *evflags)
Destruct the event flags object instance and deallocate it.
size_t os_mempool_get_count(os_mempool_t *mempool)
Get blocks count.
os_mutex_t * os_mutex_new(const char *name, const os_mutex_attr_t *attr)
Allocate a mutex object instance and construct it.
bool os_memory_coalesce(os_memory_t *memory)
Coalesce free blocks.
bool os_thread_stack_check_top_magic(os_thread_stack_t *stack)
Check if top magic word is still there.
bool os_mqueue_is_empty(os_mqueue_t *mqueue)
Check if the queue is empty.
size_t os_memory_get_total_bytes(os_memory_t *memory)
Get the total size of managed memory.
Event flags attributes.
Definition: os-c-decls.h:1375
void os_mutex_attr_init(os_mutex_attr_t *attr)
Initialise the mutex attributes.
Mutex attributes.
Definition: os-c-decls.h:899
os_result_t os_this_thread_flags_try_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for thread event flags.
uint8_t os_mutex_type_t
Definition: os-c-decls.h:798
bool os_sched_is_started(void)
Check if the scheduler was started.
bool os_mempool_is_full(os_mempool_t *mempool)
Check if the memory pool is full.
os_result_t os_mutex_try_lock(os_mutex_t *mutex)
Try to lock/acquire the mutex.
void os_mempool_construct(os_mempool_t *mempool, const char *name, size_t blocks, size_t block_size_bytes, const os_mempool_attr_t *attr)
Construct a statically allocated memory pool object instance.
void os_timer_destruct(os_timer_t *timer)
Destruct the statically allocated timer object instance.
void os_this_thread_exit(void *exit_ptr)
Terminate the current running thread.
os_statistics_duration_t os_thread_stat_get_cpu_cycles(os_thread_t *thread)
Get the thread execution time.
bool os_thread_stack_check_bottom_magic(os_thread_stack_t *stack)
Check if bottom magic word is still there.
os_thread_prio_t os_thread_get_priority(os_thread_t *thread)
Get the thread current scheduling priority.
bool os_sched_is_locked(void)
Check if the scheduler is locked.
os_result_t os_mutex_timed_lock(os_mutex_t *mutex, os_clock_duration_t timeout)
Timed attempt to lock/acquire the mutex.
os_result_t os_mutex_reset(os_mutex_t *mutex)
Reset the mutex.
os_result_t os_clock_sleep_until(os_clock_t *clock, os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
void os_mutex_attr_recursive_init(os_mutex_attr_t *attr)
Initialise the recursive mutex attributes.
size_t os_memory_get_allocated_chunks(os_memory_t *memory)
Get the number of allocated chunks.
os_memory_t * os_memory_get_default(void)
Get the application default memory resource (free store).
os_result_t os_mqueue_try_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_mqueue_prio_t *mprio)
Try to receive a message from the queue.
os_clock_duration_t os_sysclock_ticks_cast(uint32_t microsec)
Convert microseconds to ticks.
Definition: os-c-api.h:966
void os_mutex_recursive_construct(os_mutex_t *mutex, const char *name, const os_mutex_attr_t *attr)
Construct a statically allocated recursive mutex object instance.
void os_mqueue_construct(os_mqueue_t *mqueue, const char *name, size_t msgs, size_t msg_size_bytes, const os_mqueue_attr_t *attr)
Construct a statically allocated message queue object instance.
os_result_t os_sysclock_wait_for(os_clock_duration_t timeout)
Timed wait for an event.
os_result_t os_timer_start(os_timer_t *timer, os_clock_duration_t period)
Start or restart the timer.
os_semaphore_count_t os_semaphore_get_value(os_semaphore_t *semaphore)
Get the semaphore count value.
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition: os-c-decls.h:228
void os_semaphore_counting_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Construct a statically allocated counting semaphore object instance.
os_thread_user_storage_t * os_thread_get_user_storage(os_thread_t *thread)
Get the thread user storage.
Timer object storage.
Definition: os-c-decls.h:764
void os_mempool_attr_init(os_mempool_attr_t *attr)
Initialise the memory pool attributes.
void os_mutex_destruct(os_mutex_t *mutex)
Destruct the statically allocated mutex object instance.
Standard thread.
os_semaphore_t * os_semaphore_binary_new(const char *name, const os_semaphore_count_t initial_value)
Allocate a binary semaphore object instance and construct it.
os_port_irq_state_t os_irq_state_t
Type of variables holding interrupts priority values.
Definition: os-c-decls.h:176
const char * os_semaphore_get_name(os_semaphore_t *semaphore)
Get the semaphore name.
Semaphore attributes.
Definition: os-c-decls.h:1079
uint8_t os_thread_state_t
Type of variables holding thread states.
Definition: os-c-decls.h:350
const char * os_mutex_get_name(os_mutex_t *mutex)
Get the mutex name.
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition: os-c-decls.h:100
void os_mutex_delete(os_mutex_t *mutex)
Destruct the mutex object instance and deallocate it.
void os_irq_critical_exit(os_irq_state_t state)
Exit the interrupts critical section.
os_mutex_robustness_t os_mutex_get_robustness(os_mutex_t *mutex)
Get the mutex robustness.
size_t os_thread_stack_get_size(os_thread_stack_t *stack)
Get the stack size.
bool os_mqueue_is_full(os_mqueue_t *mqueue)
Check if the queue is full.
uint32_t os_flags_mask_t
Type of variables holding flags masks.
Definition: os-c-decls.h:126
os_result_t os_mqueue_reset(os_mqueue_t *mqueue)
Reset the message queue.
void os_semaphore_attr_init(os_semaphore_attr_t *attr)
Initialise the counting semaphore attributes.
os_result_t os_sched_initialize(void)
Initialise the RTOS scheduler.
const char * os_timer_get_name(os_timer_t *timer)
Get the timer name.
os_result_t os_this_thread_flags_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for thread event flags.
Condition variable attributes.
Definition: os-c-decls.h:1005
os_statistics_counter_t os_sched_stat_get_context_switches(void)
Get the total number of context switches.
os_semaphore_t * os_semaphore_new(const char *name, const os_semaphore_attr_t *attr)
Allocated a semaphore object instance and construct it.
Thread object storage.
Definition: os-c-decls.h:554
Function completed; no error or event occurred.
Definition: os-c-api.h:73
os_clock_timestamp_t os_clock_now(os_clock_t *clock)
Tell the current time, possibly adjusted for epoch.
os_flags_mask_t os_evflags_get(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mode_t mode)
Get (and possibly clear) event flags.
int16_t os_semaphore_count_t
Type of variables holding semaphore counts.
Definition: os-c-decls.h:1064
os_statistics_duration_t os_sched_stat_get_cpu_cycles(void)
Get the total duration of all threads.
os_result_t os_semaphore_timed_wait(os_semaphore_t *semaphore, os_clock_duration_t timeout)
Timed wait to lock the semaphore.
os_mutex_protocol_t os_mutex_get_protocol(os_mutex_t *mutex)
Get the mutex protocol.
os_result_t os_condvar_wait(os_condvar_t *condvar, os_mutex_t *mutex)
Wait for a condition variable to be notified.
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition: os-c-decls.h:244
os_clock_timestamp_t os_sysclock_now(void)
Tell the current time since startup.
os_thread_stack_element_t * os_thread_stack_get_top(os_thread_stack_t *stack)
Get the top stack address.
os_result_t os_thread_set_priority(os_thread_t *thread, os_thread_prio_t prio)
Set the thread dynamic scheduling priority.
os_result_t os_clock_wait_for(os_clock_t *clock, os_clock_duration_t timeout)
Timed wait for an event.
os_result_t os_mutex_set_prio_ceiling(os_mutex_t *mutex, os_thread_prio_t prio_ceiling, os_thread_prio_t *old_prio_ceiling)
Change the priority ceiling of a mutex.
const os_semaphore_attr_t * os_semaphore_attr_get_binary(void)
Get a binary semaphore attributes object instance.
os_clock_t * os_clock_get_sysclock(void)
Get sysclock (the system clock).
os_mutex_t * os_mutex_recursive_new(const char *name, const os_mutex_attr_t *attr)
Allocated a recursive mutex object instance and construct it.
const char * os_evflags_get_name(os_evflags_t *evflags)
Get the event flags name.
void os_mqueue_destruct(os_mqueue_t *mqueue)
Destruct the statically allocated message queue object instance.
os_thread_t * os_children_threads_iter_get(os_iterator_t iterator)
Get the thread from the current iterator position.
os_thread_t * os_mutex_get_owner(os_mutex_t *mutex)
Get the thread that owns the mutex.
size_t os_thread_stack_set_default_size(size_t size_bytes)
Set the default stack size.
bool os_evflags_are_waiting(os_evflags_t *evflags)
Check if there are threads waiting.
size_t os_mqueue_get_capacity(os_mqueue_t *mqueue)
Get queue capacity.
os_result_t os_mqueue_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_mqueue_prio_t mprio)
Send a message to the queue.
os_port_clock_duration_t os_clock_duration_t
Type of variables holding clock durations.
Definition: os-c-decls.h:202
Event flags object storage.
Definition: os-c-decls.h:1400
os_clock_offset_t os_clock_get_offset(os_clock_t *clock)
Get adjustment offset.
void * os_mempool_try_alloc(os_mempool_t *mempool)
Try to allocate a memory block.
size_t os_mqueue_get_length(os_mqueue_t *mqueue)
Get queue length.
os_thread_t * os_this_thread(void)
Get the current running thread.
void os_mempool_destruct(os_mempool_t *mempool)
Destruct the statically allocated memory pool object instance.
os_result_t os_mutex_unlock(os_mutex_t *mutex)
Unlock/release the mutex.
os_thread_stack_t * os_irq_get_stack(void)
Get the interrupts stack.
size_t os_mempool_get_capacity(os_mempool_t *mempool)
Get memory pool capacity.
void os_thread_attr_init(os_thread_attr_t *attr)
Initialise the thread attributes.
void os_condvar_destruct(os_condvar_t *condvar)
Destruct the statically allocated condition variable object instance.
os_sched_state_t os_sched_lock(void)
Lock the scheduler.
os_irq_state_t os_irq_critical_enter(void)
Enter an interrupts critical section.
os_irq_state_t os_irq_uncritical_enter(void)
Enter an interrupts uncritical section.
#define OS_INTEGER_SYSTICK_FREQUENCY_HZ
Define the scheduler frequency, in Hz.
os_statistics_counter_t os_thread_stat_get_context_switches(os_thread_t *thread)
Get the number of thread context switches.
Thread stack.
Definition: os-c-decls.h:402
void os_thread_resume(os_thread_t *thread)
Resume the thread.
os_result_t os_this_thread_flags_timed_wait(os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for thread event flags.
os_result_t os_semaphore_wait(os_semaphore_t *semaphore)
Lock the semaphore, possibly waiting.
Memory pool attributes.
Definition: os-c-decls.h:1165
os_result_t os_mutex_lock(os_mutex_t *mutex)
Lock/acquire the mutex.
Timer attributes.
Definition: os-c-decls.h:734
const char * os_thread_get_name(os_thread_t *thread)
Get the thread name.
void * os_memory_allocate(os_memory_t *memory, size_t bytes, size_t alignment)
Allocate a block of memory.
void os_this_thread_suspend(void)
Suspend the current running thread to wait for an event.
void * os_mempool_alloc(os_mempool_t *mempool)
Allocate a memory block.
os_thread_stack_element_t * os_thread_stack_get_bottom(os_thread_stack_t *stack)
Get the stack lowest reserved address.
os_semaphore_count_t os_semaphore_get_max_value(os_semaphore_t *semaphore)
Get the semaphore maximum count value.
Semaphore object storage.
Definition: os-c-decls.h:1114
os_iterator_t os_children_threads_iter_next(os_iterator_t iterator)
Advance the iterator to the next position.
os_flags_mask_t os_this_thread_flags_get(os_flags_mask_t mask, os_flags_mode_t mode)
Get/clear thread event flags.
const char * os_condvar_get_name(os_condvar_t *condvar)
Get the condition variable name.
os_thread_t * os_thread_new(const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Allocate a thread object instance and construct it.
size_t os_thread_stack_get_default_size(void)
Get the default stack size.
os_thread_prio_t os_mutex_get_prio_ceiling(os_mutex_t *mutex)
Get the priority ceiling of a mutex.
void os_thread_destruct(os_thread_t *thread)
Destruct the statically allocated thread object instance.
size_t os_mqueue_get_msg_size(os_mqueue_t *mqueue)
Get message size.
os_result_t os_evflags_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for event flags.
void os_mempool_delete(os_mempool_t *mempool)
Destruct the memory pool object instance and deallocate it.
os_evflags_t * os_evflags_new(const char *name, const os_evflags_attr_t *attr)
Allocate an event flags object instance and construct it.
os_result_t os_semaphore_post(os_semaphore_t *semaphore)
Post (unlock) the semaphore.
size_t os_memory_get_free_chunks(os_memory_t *memory)
Get the number of free chunks.
uint8_t os_mutex_robustness_t
Definition: os-c-decls.h:800
os_mqueue_t * os_mqueue_new(const char *name, size_t msgs, size_t msg_size_bytes, const os_mqueue_attr_t *attr)
Allocate a message queue object instance and construct it.
os_result_t os_timer_stop(os_timer_t *timer)
Stop the timer.
clock_t clock(void)
os_result_t os_evflags_raise(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise event flags.
void os_condvar_delete(os_condvar_t *condvar)
Destruct the condition variable object instance and deallocate it.
void os_mqueue_attr_init(os_mqueue_attr_t *attr)
Initialise the message queue attributes.
os_result_t os_sysclock_sleep_until(os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_result_t os_evflags_timed_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for event flags.
const char * os_clock_get_name(os_clock_t *clock)
Get the clock name.
os_thread_state_t os_thread_get_state(os_thread_t *thread)
Get the thread scheduler state.
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition: os-c-decls.h:237
bool os_sched_is_preemptive(void)
Check if the scheduler is in preemptive mode.
os_result_t os_evflags_try_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for event flags.
void os_evflags_attr_init(os_evflags_attr_t *attr)
Initialise the event flags attributes.
Memory pool object storage.
Definition: os-c-decls.h:1200
void os_evflags_destruct(os_evflags_t *evflags)
Destruct the statically allocated event flags object instance.
os_port_thread_stack_element_t os_thread_stack_element_t
Type of variables holding stack words.
Definition: os-c-decls.h:377
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition: os-c-decls.h:214
os_result_t os_condvar_broadcast(os_condvar_t *condvar)
Notify all threads waiting for a condition variable.
os_clock_timestamp_t os_clock_steady_now(os_clock_t *clock)
Tell the current time since startup.
size_t os_thread_stack_get_min_size(void)
Get the min stack size.
void os_memory_deallocate(os_memory_t *memory, void *addr, size_t bytes, size_t alignment)
Deallocate the previously allocated block of memory.
void(* os_timer_func_t)(os_timer_func_args_t args)
Type of timer function.
Definition: os-c-decls.h:705
os_mempool_t * os_mempool_new(const char *name, size_t blocks, size_t block_size_bytes, const os_mempool_attr_t *attr)
Allocate a memory pool object instance and construct it.
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition: os-c-decls.h:364
void os_semaphore_binary_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t initial_value)
Construct a statically allocated binary semaphore object instance.
void * os_mempool_get_pool(os_mempool_t *mempool)
Get the pool storage address.
uint32_t os_flags_mode_t
Type of variables holding flags modes.
Definition: os-c-decls.h:113
void os_memory_reset(os_memory_t *memory)
Reset the memory manager to the initial state.
os_iterator_t os_children_threads_iter_end(os_thread_t *thread)
Get the end of the list of children threads.
os_clock_t * os_clock_get_hrclock(void)
Get hrclock (the high resolution clock).
os_result_t os_condvar_signal(os_condvar_t *condvar)
Notify one thread waiting for a condition variable.
os_result_t os_mutex_mark_consistent(os_mutex_t *mutex)
Mark mutex as consistent.
void os_thread_delete(os_thread_t *thread)
Destruct the thread object instance and deallocate it.
os_result_t os_semaphore_reset(os_semaphore_t *semaphore)
Reset the semaphore.
const os_mutex_attr_t * os_mutex_attr_get_recursive(void)
Get a recursive mutex attributes object instance.
uint8_t os_mqueue_prio_t
Type of variables holding message queue priorities.
Definition: os-c-decls.h:1257
void os_semaphore_attr_binary_init(os_semaphore_attr_t *attr, const os_semaphore_count_t initial_value)
Initialise the binary semaphore attributes.
void os_condvar_construct(os_condvar_t *condvar, const char *name, const os_condvar_attr_t *attr)
Construct a statically allocated condition variable object instance.
Condition variable object storage.
Definition: os-c-decls.h:1031
void os_sched_start(void)
Start the RTOS scheduler.
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition: os-c-decls.h:191
os_result_t os_sysclock_sleep_for(os_clock_duration_t duration)
Sleep for a relative duration.
void os_semaphore_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_attr_t *attr)
Construct a statically allocated semaphore object instance.
os_semaphore_count_t os_semaphore_get_initial_value(os_semaphore_t *semaphore)
Get the semaphore initial count value.
os_result_t os_condvar_timed_wait(os_condvar_t *condvar, os_mutex_t *mutex, os_clock_duration_t timeout)
Timed wait for a condition variable to be notified.
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.
void os_thread_construct(os_thread_t *thread, const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Construct a statically allocated thread object instance.
Mutex object storage.
Definition: os-c-decls.h:949
os_result_t os_mqueue_timed_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_clock_duration_t timeout, os_mqueue_prio_t mprio)
Send a message to the queue with timeout.
void os_condvar_attr_init(os_condvar_attr_t *attr)
Initialise the condition variable attributes.
void * os_timer_func_args_t
Type of timer function arguments.
Definition: os-c-decls.h:693
void *(* os_thread_func_t)(os_thread_func_args_t args)
Type of thread function.
Definition: os-c-decls.h:343
os_port_scheduler_state_t os_sched_state_t
Type of variables holding scheduler state codes.
Definition: os-c-decls.h:162
size_t os_mempool_get_block_size(os_mempool_t *mempool)
Get block size.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
void os_timer_attr_periodic_init(os_timer_attr_t *attr)
Initialise the periodic timer attributes.
size_t os_thread_stack_get_available(os_thread_stack_t *stack)
Compute how much available stack remains.
Clock object storage.
Definition: os-c-decls.h:631
bool os_mempool_is_empty(os_mempool_t *mempool)
Check if the memory pool is empty.
void os_evflags_construct(os_evflags_t *evflags, const char *name, const os_evflags_attr_t *attr)
Construct a statically allocated event flags object instance.
Memory resource object storage.
Definition: os-c-decls.h:1481
Message queue attributes.
Definition: os-c-decls.h:1272
void os_semaphore_attr_counting_init(os_semaphore_attr_t *attr, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Initialise the counting semaphore attributes.
os_clock_offset_t os_clock_set_offset(os_clock_t *clock, os_clock_offset_t offset)
Set adjustment offset.
os_clock_duration_t os_sysclock_ticks_cast_long(uint64_t microsec)
Convert microseconds to ticks.
Definition: os-c-api.h:980
os_result_t os_this_thread_flags_clear(os_flags_mask_t mask, os_flags_mask_t *oflags)
Clear thread event flags.
bool os_sched_set_preemptive(bool state)
Set the scheduler preemptive mode.
bool os_irq_in_handler_mode(void)
Check if the CPU is in handler mode.