Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_thread.cpp Source File

mbed_thread.cpp

00001 /*
00002  * Copyright (c) 2019, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "platform/mbed_thread.h"
00019 #include "platform/mbed_critical.h"
00020 #include "platform/source/mbed_os_timer.h"
00021 
00022 /* If the RTOS is present, we call the RTOS API to do the work */
00023 /* If the RTOS is not present, the RTOS API calls us to do the work */
00024 #if MBED_CONF_RTOS_PRESENT
00025 #include "rtos/Kernel.h"
00026 #include "rtos/ThisThread.h"
00027 #endif
00028 
00029 extern "C" {
00030 
00031     uint64_t get_ms_count(void)
00032     {
00033 #if MBED_CONF_RTOS_PRESENT
00034         return rtos::Kernel::get_ms_count();
00035 #else
00036         return mbed::internal::init_os_timer()->update_and_get_tick();
00037 #endif
00038     }
00039 
00040     void thread_sleep_for(uint32_t millisec)
00041     {
00042 #if MBED_CONF_RTOS_PRESENT
00043         rtos::ThisThread::sleep_for(millisec);
00044 #else
00045         // Undocumented, but osDelay(UINT32_MAX) does actually sleep forever
00046         mbed::internal::do_timed_sleep_relative_or_forever(millisec);
00047 #endif
00048     }
00049 
00050     void thread_sleep_until(uint64_t millisec)
00051     {
00052 #if MBED_CONF_RTOS_PRESENT
00053         rtos::ThisThread::sleep_until(millisec);
00054 #else
00055         mbed::internal::do_timed_sleep_absolute(millisec);
00056 #endif
00057     }
00058 
00059 }