Initial commit
mbed-dev-master/platform/mbed_wait_api_rtos.cpp@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | /* mbed Microcontroller Library |
lypinator | 0:bb348c97df44 | 2 | * Copyright (c) 2006-2013 ARM Limited |
lypinator | 0:bb348c97df44 | 3 | * |
lypinator | 0:bb348c97df44 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
lypinator | 0:bb348c97df44 | 5 | * you may not use this file except in compliance with the License. |
lypinator | 0:bb348c97df44 | 6 | * You may obtain a copy of the License at |
lypinator | 0:bb348c97df44 | 7 | * |
lypinator | 0:bb348c97df44 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
lypinator | 0:bb348c97df44 | 9 | * |
lypinator | 0:bb348c97df44 | 10 | * Unless required by applicable law or agreed to in writing, software |
lypinator | 0:bb348c97df44 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
lypinator | 0:bb348c97df44 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
lypinator | 0:bb348c97df44 | 13 | * See the License for the specific language governing permissions and |
lypinator | 0:bb348c97df44 | 14 | * limitations under the License. |
lypinator | 0:bb348c97df44 | 15 | */ |
lypinator | 0:bb348c97df44 | 16 | |
lypinator | 0:bb348c97df44 | 17 | // This implementation of the wait functions will be compiled only |
lypinator | 0:bb348c97df44 | 18 | // if the RTOS is present. |
lypinator | 0:bb348c97df44 | 19 | #ifdef MBED_CONF_RTOS_PRESENT |
lypinator | 0:bb348c97df44 | 20 | |
lypinator | 0:bb348c97df44 | 21 | #include "platform/mbed_wait_api.h" |
lypinator | 0:bb348c97df44 | 22 | #include "hal/us_ticker_api.h" |
lypinator | 0:bb348c97df44 | 23 | #include "rtos/rtos.h" |
lypinator | 0:bb348c97df44 | 24 | #include "platform/mbed_critical.h" |
lypinator | 0:bb348c97df44 | 25 | #include "platform/mbed_power_mgmt.h" |
lypinator | 0:bb348c97df44 | 26 | |
lypinator | 0:bb348c97df44 | 27 | void wait(float s) |
lypinator | 0:bb348c97df44 | 28 | { |
lypinator | 0:bb348c97df44 | 29 | wait_us(s * 1000000.0f); |
lypinator | 0:bb348c97df44 | 30 | } |
lypinator | 0:bb348c97df44 | 31 | |
lypinator | 0:bb348c97df44 | 32 | void wait_ms(int ms) |
lypinator | 0:bb348c97df44 | 33 | { |
lypinator | 0:bb348c97df44 | 34 | wait_us(ms * 1000); |
lypinator | 0:bb348c97df44 | 35 | } |
lypinator | 0:bb348c97df44 | 36 | |
lypinator | 0:bb348c97df44 | 37 | void wait_us(int us) |
lypinator | 0:bb348c97df44 | 38 | { |
lypinator | 0:bb348c97df44 | 39 | const ticker_data_t *const ticker = get_us_ticker_data(); |
lypinator | 0:bb348c97df44 | 40 | |
lypinator | 0:bb348c97df44 | 41 | uint32_t start = ticker_read(ticker); |
lypinator | 0:bb348c97df44 | 42 | if ((us >= 1000) && core_util_are_interrupts_enabled()) { |
lypinator | 0:bb348c97df44 | 43 | // Use the RTOS to wait for millisecond delays if possible |
lypinator | 0:bb348c97df44 | 44 | sleep_manager_lock_deep_sleep(); |
lypinator | 0:bb348c97df44 | 45 | Thread::wait((uint32_t)us / 1000); |
lypinator | 0:bb348c97df44 | 46 | sleep_manager_unlock_deep_sleep(); |
lypinator | 0:bb348c97df44 | 47 | } |
lypinator | 0:bb348c97df44 | 48 | // Use busy waiting for sub-millisecond delays, or for the whole |
lypinator | 0:bb348c97df44 | 49 | // interval if interrupts are not enabled |
lypinator | 0:bb348c97df44 | 50 | while ((ticker_read(ticker) - start) < (uint32_t)us); |
lypinator | 0:bb348c97df44 | 51 | } |
lypinator | 0:bb348c97df44 | 52 | |
lypinator | 0:bb348c97df44 | 53 | #endif // #if MBED_CONF_RTOS_PRESENT |
lypinator | 0:bb348c97df44 | 54 |