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