µOS++ IIIe / CMSIS++ / POSIX++ Reference  v6.3.11
“Perfekt ist nicht gut genug”
The third edition of µOS++ and CMSIS++, a proposal for the next generation CMSIS, written in C++.
os-idle.cpp
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 #include <cmsis-plus/rtos/os.h>
29 
30 // ----------------------------------------------------------------------------
31 
32 using namespace os;
33 using namespace os::rtos;
34 
35 // ----------------------------------------------------------------------------
36 
37 void*
39 
40 void
42 
61 bool
62 __attribute__((weak))
64 {
65  return false;
66 }
67 
68 void
69 __attribute__((weak))
71 {
72  while (!scheduler::terminated_threads_list_.empty ())
73  {
75  {
76  // ----- Enter critical section ---------------------------------
78  node =
79  const_cast<internal::waiting_thread_node*> (scheduler::terminated_threads_list_.head ());
80  node->unlink ();
81  // ----- Exit critical section ----------------------------------
82  }
83  node->thread_->internal_destroy_ ();
84 
86  }
87 
88 #if defined(OS_HAS_INTERRUPTS_STACK)
89  // Simple test to verify that the interrupts
90  // did not underflow the stack.
91  assert(rtos::interrupts::stack ()->check_bottom_magic ());
92 #endif
93 
95  {
96  port::scheduler::wait_for_interrupt ();
97  }
98 }
99 
100 #if !defined(OS_USE_RTOS_PORT_SCHEDULER) || defined(__DOXYGEN__)
101 
105 extern thread* os_idle_thread;
106 
107 thread* os_idle_thread;
108 
109 #pragma GCC diagnostic push
110 #if defined(__clang__)
111 #pragma clang diagnostic ignored "-Wexit-time-destructors"
112 #pragma clang diagnostic ignored "-Wglobal-constructors"
113 #pragma clang diagnostic ignored "-Wmissing-variable-declarations"
114 #endif
115 
116 #if defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
117 
119  { "idle", os_idle, nullptr};
120 
121 #else
122 
123 static std::unique_ptr<thread> os_idle_thread_;
124 
125 #endif /* defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
126 
127 #pragma GCC diagnostic pop
128 
129 void
130 __attribute__((weak))
132 {
133 #if defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
134 
135  // The thread object instance was created by the static constructors.
136  os_idle_thread = &os_idle_thread_;
137 
138 #else
139 
142 
143  // No need for an explicit delete, it is deallocated by the unique_ptr.
144  os_idle_thread_ = std::unique_ptr<thread> (
145  new thread ("idle", os_idle, nullptr, attr));
146 
147  os_idle_thread = os_idle_thread_.get ();
148 
149 #endif /* defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
150 }
151 
152 void*
153 os_idle (thread::func_args_t args __attribute__((unused)))
154 {
155 
156  // The thread was created with the default priority, and the
157  // idle thread must run with th lowest possible priority.
158 
159 #if defined(OS_BOOL_RTOS_THREAD_IDLE_PRIORITY_BELOW_IDLE)
160  // The CMSIS RTOS validator creates threads with `priority::idle`,
161  // so, to be sure that the system idle thread has the lowest priority,
162  // go one step below the idle priority.
164 #else
166 #endif
167 
168  while (true)
169  {
171 
172  // Possibly switch to threads that were resumed during sleep.
174  }
175 }
176 
180 #endif /* !defined(OS_USE_RTOS_PORT_SCHEDULER) */
181 
182 // ----------------------------------------------------------------------------
void * os_idle(thread::func_args_t args)
Thread attributes.
Definition: os-thread.h:769
void os_rtos_idle_actions(void)
Definition: os-idle.cpp:70
class thread::stack * stack(void)
Get the interrupts stack.
Definition: os-core.cpp:528
void yield(void)
Yield execution to the next ready thread.
Definition: os-thread.cpp:1500
bool os_rtos_idle_enter_power_saving_mode_hook(void)
Hook to enter a power saving mode.
Definition: os-idle.cpp:63
Double linked list node, with thread reference.
Definition: os-lists.h:63
void os_startup_create_thread_idle(void)
Create the idle thread.
result_t priority(priority_t prio)
Set the assigned scheduling priority.
Definition: os-thread.cpp:628
Interrupts critical section RAII helper.
Definition: os-sched.h:503
System namespace.
Template of a POSIX compliant thread with local stack.
Definition: os-thread.h:1773
rtos::thread * thread_
Pointer to waiting thread.
Definition: os-lists.h:112
POSIX compliant thread, using the default RTOS allocator.
Definition: os-thread.h:235
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition: os-thread.h:830
Single file CMSIS++ RTOS definitions.
static const attributes initializer
Default thread initialiser.
Definition: os-thread.h:967
RTOS namespace.
Definition: os-flags.h:46
thread & thread(void)
Get the current running thread.
Definition: os-thread.cpp:1481
_func_args_t func_args_t
Type of thread function arguments.
Definition: os-thread.h:388
#define OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES
Define the idle thread stack size.