RTC auf true
rtos/Kernel.cpp@2:7aab896b1a3b, 2019-03-13 (annotated)
- Committer:
- kevman
- Date:
- Wed Mar 13 11:03:24 2019 +0000
- Revision:
- 2:7aab896b1a3b
- Parent:
- 0:38ceb79fef03
2019-03-13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2017 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
kevman | 0:38ceb79fef03 | 5 | * of this software and associated documentation files (the "Software"), to deal |
kevman | 0:38ceb79fef03 | 6 | * in the Software without restriction, including without limitation the rights |
kevman | 0:38ceb79fef03 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
kevman | 0:38ceb79fef03 | 8 | * copies of the Software, and to permit persons to whom the Software is |
kevman | 0:38ceb79fef03 | 9 | * furnished to do so, subject to the following conditions: |
kevman | 0:38ceb79fef03 | 10 | * |
kevman | 0:38ceb79fef03 | 11 | * The above copyright notice and this permission notice shall be included in |
kevman | 0:38ceb79fef03 | 12 | * all copies or substantial portions of the Software. |
kevman | 0:38ceb79fef03 | 13 | * |
kevman | 0:38ceb79fef03 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
kevman | 0:38ceb79fef03 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
kevman | 0:38ceb79fef03 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
kevman | 0:38ceb79fef03 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
kevman | 0:38ceb79fef03 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kevman | 0:38ceb79fef03 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
kevman | 0:38ceb79fef03 | 20 | * SOFTWARE. |
kevman | 0:38ceb79fef03 | 21 | */ |
kevman | 0:38ceb79fef03 | 22 | |
kevman | 0:38ceb79fef03 | 23 | #include "rtos/Kernel.h" |
kevman | 0:38ceb79fef03 | 24 | |
kevman | 0:38ceb79fef03 | 25 | #include "mbed.h" |
kevman | 0:38ceb79fef03 | 26 | #include "rtos/rtos_idle.h" |
kevman | 0:38ceb79fef03 | 27 | #include "rtos/rtos_handlers.h" |
kevman | 0:38ceb79fef03 | 28 | |
kevman | 0:38ceb79fef03 | 29 | namespace rtos { |
kevman | 0:38ceb79fef03 | 30 | |
kevman | 0:38ceb79fef03 | 31 | uint64_t Kernel::get_ms_count() |
kevman | 0:38ceb79fef03 | 32 | { |
kevman | 0:38ceb79fef03 | 33 | // CMSIS-RTOS 2.1.0 and 2.1.1 differ in the time type. We assume |
kevman | 0:38ceb79fef03 | 34 | // our header at least matches the implementation, so we don't try looking |
kevman | 0:38ceb79fef03 | 35 | // at the run-time version report. (There's no compile-time version report) |
kevman | 0:38ceb79fef03 | 36 | |
kevman | 0:38ceb79fef03 | 37 | // 2.1.0 uint64_t osKernelGetTickCount(void), not documented as callable from ISR (but RTX does allow) |
kevman | 0:38ceb79fef03 | 38 | // 2.1.1 uint32_t osKernelGetTickCount(void), callable from ISR |
kevman | 0:38ceb79fef03 | 39 | // 2.1.x who knows? We assume could go back to uint64_t |
kevman | 0:38ceb79fef03 | 40 | if (sizeof osKernelGetTickCount() == sizeof(uint64_t)) { |
kevman | 0:38ceb79fef03 | 41 | return osKernelGetTickCount(); |
kevman | 0:38ceb79fef03 | 42 | } else { /* assume 32-bit */ |
kevman | 0:38ceb79fef03 | 43 | // Based on suggestion in CMSIS-RTOS 2.1.1 docs, but with reentrancy |
kevman | 0:38ceb79fef03 | 44 | // protection for the tick memory. We use critical section rather than a |
kevman | 0:38ceb79fef03 | 45 | // mutex, as hopefully this method can be callable from interrupt later - |
kevman | 0:38ceb79fef03 | 46 | // only thing currently preventing it is that pre CMSIS RTOS 2.1.1, it's |
kevman | 0:38ceb79fef03 | 47 | // not defined as safe. |
kevman | 0:38ceb79fef03 | 48 | // We assume this is called multiple times per 32-bit wrap period (49 days). |
kevman | 0:38ceb79fef03 | 49 | static uint32_t tick_h, tick_l; |
kevman | 0:38ceb79fef03 | 50 | |
kevman | 0:38ceb79fef03 | 51 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 52 | // The 2.1.1 API says this is legal from an ISR - we assume this means |
kevman | 0:38ceb79fef03 | 53 | // it's also legal with interrupts disabled. RTX implementation kind |
kevman | 0:38ceb79fef03 | 54 | // of conflates the two. |
kevman | 0:38ceb79fef03 | 55 | uint32_t tick32 = osKernelGetTickCount(); |
kevman | 0:38ceb79fef03 | 56 | if (tick32 < tick_l) { |
kevman | 0:38ceb79fef03 | 57 | tick_h++; |
kevman | 0:38ceb79fef03 | 58 | } |
kevman | 0:38ceb79fef03 | 59 | tick_l = tick32; |
kevman | 0:38ceb79fef03 | 60 | uint64_t ret = ((uint64_t) tick_h << 32) | tick_l; |
kevman | 0:38ceb79fef03 | 61 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 62 | return ret; |
kevman | 0:38ceb79fef03 | 63 | } |
kevman | 0:38ceb79fef03 | 64 | } |
kevman | 0:38ceb79fef03 | 65 | |
kevman | 0:38ceb79fef03 | 66 | void Kernel::attach_idle_hook(void (*fptr)(void)) |
kevman | 0:38ceb79fef03 | 67 | { |
kevman | 0:38ceb79fef03 | 68 | rtos_attach_idle_hook(fptr); |
kevman | 0:38ceb79fef03 | 69 | } |
kevman | 0:38ceb79fef03 | 70 | |
kevman | 0:38ceb79fef03 | 71 | void Kernel::attach_thread_terminate_hook(void (*fptr)(osThreadId_t id)) |
kevman | 0:38ceb79fef03 | 72 | { |
kevman | 0:38ceb79fef03 | 73 | rtos_attach_thread_terminate_hook(fptr); |
kevman | 0:38ceb79fef03 | 74 | } |
kevman | 0:38ceb79fef03 | 75 | |
kevman | 0:38ceb79fef03 | 76 | } |