|
33 | 33 | extern "C" {
|
34 | 34 | #include "rtx_lib.h"
|
35 | 35 |
|
36 |
| -using namespace mbed; |
| 36 | + using namespace mbed; |
37 | 37 |
|
38 | 38 | #if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
39 | 39 |
|
40 | 40 | #include "rtos/TARGET_CORTEX/SysTimer.h"
|
41 | 41 |
|
42 |
| -static rtos::internal::SysTimer *os_timer; |
43 |
| -static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; |
| 42 | + static rtos::internal::SysTimer *os_timer; |
| 43 | + static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; |
44 | 44 |
|
45 |
| -/// Enable System Timer. |
46 |
| -void OS_Tick_Enable(void) |
47 |
| -{ |
48 |
| - // Do not use SingletonPtr since this relies on the RTOS |
49 |
| - if (NULL == os_timer) { |
50 |
| - os_timer = new (os_timer_data) rtos::internal::SysTimer(); |
51 |
| - os_timer->setup_irq(); |
| 45 | + // Enable System Timer. |
| 46 | + void OS_Tick_Enable(void) |
| 47 | + { |
| 48 | + // Do not use SingletonPtr since this relies on the RTOS |
| 49 | + if (NULL == os_timer) { |
| 50 | + os_timer = new (os_timer_data) rtos::internal::SysTimer(); |
| 51 | + os_timer->setup_irq(); |
| 52 | + } |
| 53 | + |
| 54 | + // set to fire interrupt on next tick |
| 55 | + os_timer->schedule_tick(); |
52 | 56 | }
|
53 | 57 |
|
54 |
| - // set to fire interrupt on next tick |
55 |
| - os_timer->schedule_tick(); |
56 |
| -} |
57 |
| - |
58 |
| -/// Disable System Timer. |
59 |
| -void OS_Tick_Disable(void) |
60 |
| -{ |
61 |
| - os_timer->cancel_tick(); |
62 |
| -} |
63 |
| - |
64 |
| -/// Acknowledge System Timer IRQ. |
65 |
| -void OS_Tick_AcknowledgeIRQ(void) |
66 |
| -{ |
67 |
| - |
68 |
| -} |
69 |
| - |
70 |
| -/// Get System Timer count. |
71 |
| -uint32_t OS_Tick_GetCount(void) |
72 |
| -{ |
73 |
| - return os_timer->get_time() & 0xFFFFFFFF; |
74 |
| -} |
75 |
| - |
76 |
| -// Get OS Tick IRQ number. |
77 |
| -int32_t OS_Tick_GetIRQn(void) |
78 |
| -{ |
79 |
| - return -1; |
80 |
| -} |
81 |
| - |
82 |
| -// Get OS Tick overflow status. |
83 |
| -uint32_t OS_Tick_GetOverflow(void) |
84 |
| -{ |
85 |
| - return 0; |
86 |
| -} |
87 |
| - |
88 |
| -// Get OS Tick interval. |
89 |
| -uint32_t OS_Tick_GetInterval(void) |
90 |
| -{ |
91 |
| - return 1000; |
92 |
| -} |
93 |
| - |
94 |
| -static void default_idle_hook(void) |
95 |
| -{ |
96 |
| - uint32_t ticks_to_sleep = osKernelSuspend(); |
97 |
| - const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; |
98 |
| - |
99 |
| - if (block_deep_sleep) { |
100 |
| - sleep_manager_lock_deep_sleep(); |
101 |
| - } else { |
102 |
| - ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; |
| 58 | + // Disable System Timer. |
| 59 | + void OS_Tick_Disable(void) |
| 60 | + { |
| 61 | + os_timer->cancel_tick(); |
103 | 62 | }
|
104 |
| - os_timer->suspend(ticks_to_sleep); |
105 | 63 |
|
106 |
| - bool event_pending = false; |
107 |
| - while (!os_timer->suspend_time_passed() && !event_pending) { |
| 64 | + // Acknowledge System Timer IRQ. |
| 65 | + void OS_Tick_AcknowledgeIRQ(void) |
| 66 | + { |
108 | 67 |
|
109 |
| - core_util_critical_section_enter(); |
110 |
| - if (osRtxInfo.kernel.pendSV) { |
111 |
| - event_pending = true; |
112 |
| - } else { |
113 |
| - sleep(); |
114 |
| - } |
115 |
| - core_util_critical_section_exit(); |
| 68 | + } |
116 | 69 |
|
117 |
| - // Ensure interrupts get a chance to fire |
118 |
| - __ISB(); |
| 70 | + // Get System Timer count. |
| 71 | + uint32_t OS_Tick_GetCount(void) |
| 72 | + { |
| 73 | + return os_timer->get_time() & 0xFFFFFFFF; |
119 | 74 | }
|
120 | 75 |
|
121 |
| - if (block_deep_sleep) { |
122 |
| - sleep_manager_unlock_deep_sleep(); |
| 76 | + // Get OS Tick IRQ number. |
| 77 | + int32_t OS_Tick_GetIRQn(void) |
| 78 | + { |
| 79 | + return -1; |
| 80 | + } |
| 81 | + |
| 82 | + // Get OS Tick overflow status. |
| 83 | + uint32_t OS_Tick_GetOverflow(void) |
| 84 | + { |
| 85 | + return 0; |
| 86 | + } |
| 87 | + |
| 88 | + // Get OS Tick interval. |
| 89 | + uint32_t OS_Tick_GetInterval(void) |
| 90 | + { |
| 91 | + return 1000; |
123 | 92 | }
|
124 | 93 |
|
125 |
| - osKernelResume(os_timer->resume()); |
126 |
| -} |
| 94 | + static void default_idle_hook(void) |
| 95 | + { |
| 96 | + uint32_t ticks_to_sleep = osKernelSuspend(); |
| 97 | + const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; |
| 98 | + |
| 99 | + if (block_deep_sleep) { |
| 100 | + sleep_manager_lock_deep_sleep(); |
| 101 | + } else { |
| 102 | + ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; |
| 103 | + } |
| 104 | + os_timer->suspend(ticks_to_sleep); |
| 105 | + |
| 106 | + bool event_pending = false; |
| 107 | + while (!os_timer->suspend_time_passed() && !event_pending) { |
| 108 | + |
| 109 | + core_util_critical_section_enter(); |
| 110 | + if (osRtxInfo.kernel.pendSV) { |
| 111 | + event_pending = true; |
| 112 | + } else { |
| 113 | + sleep(); |
| 114 | + } |
| 115 | + core_util_critical_section_exit(); |
| 116 | + |
| 117 | + // Ensure interrupts get a chance to fire |
| 118 | + __ISB(); |
| 119 | + } |
| 120 | + |
| 121 | + if (block_deep_sleep) { |
| 122 | + sleep_manager_unlock_deep_sleep(); |
| 123 | + } |
| 124 | + |
| 125 | + osKernelResume(os_timer->resume()); |
| 126 | + } |
127 | 127 |
|
128 | 128 |
|
129 | 129 | #else
|
130 | 130 |
|
131 |
| -static void default_idle_hook(void) |
132 |
| -{ |
133 |
| - // critical section to complete sleep with locked deepsleep |
134 |
| - core_util_critical_section_enter(); |
135 |
| - sleep_manager_lock_deep_sleep(); |
136 |
| - sleep(); |
137 |
| - sleep_manager_unlock_deep_sleep(); |
138 |
| - core_util_critical_section_exit(); |
139 |
| -} |
| 131 | + static void default_idle_hook(void) |
| 132 | + { |
| 133 | + // critical section to complete sleep with locked deepsleep |
| 134 | + core_util_critical_section_enter(); |
| 135 | + sleep_manager_lock_deep_sleep(); |
| 136 | + sleep(); |
| 137 | + sleep_manager_unlock_deep_sleep(); |
| 138 | + core_util_critical_section_exit(); |
| 139 | + } |
140 | 140 |
|
141 | 141 | #endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
142 | 142 |
|
143 |
| -static void (*idle_hook_fptr)(void) = &default_idle_hook; |
| 143 | + static void (*idle_hook_fptr)(void) = &default_idle_hook; |
144 | 144 |
|
145 |
| -void rtos_attach_idle_hook(void (*fptr)(void)) |
146 |
| -{ |
147 |
| - //Attach the specified idle hook, or the default idle hook in case of a NULL pointer |
148 |
| - if (fptr != NULL) { |
149 |
| - idle_hook_fptr = fptr; |
150 |
| - } else { |
151 |
| - idle_hook_fptr = default_idle_hook; |
| 145 | + void rtos_attach_idle_hook(void (*fptr)(void)) |
| 146 | + { |
| 147 | + //Attach the specified idle hook, or the default idle hook in case of a NULL pointer |
| 148 | + if (fptr != NULL) { |
| 149 | + idle_hook_fptr = fptr; |
| 150 | + } else { |
| 151 | + idle_hook_fptr = default_idle_hook; |
| 152 | + } |
152 | 153 | }
|
153 |
| -} |
154 | 154 |
|
155 |
| -MBED_NORETURN void rtos_idle_loop(void) |
156 |
| -{ |
157 |
| - //Continuously call the idle hook function pointer |
158 |
| - while (1) { |
159 |
| - idle_hook_fptr(); |
| 155 | + MBED_NORETURN void rtos_idle_loop(void) |
| 156 | + { |
| 157 | + //Continuously call the idle hook function pointer |
| 158 | + while (1) { |
| 159 | + idle_hook_fptr(); |
| 160 | + } |
160 | 161 | }
|
161 |
| -} |
162 | 162 |
|
163 | 163 | } // extern "C"
|
0 commit comments