Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
utest_shim.cpp
00001 /**************************************************************************** 00002 * Copyright (c) 2015, 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 00019 #include "utest/utest_shim.h" 00020 #include "utest/utest_stack_trace.h" 00021 00022 #if UTEST_SHIM_SCHEDULER_USE_MINAR 00023 #include "minar/minar.h" 00024 00025 static int32_t utest_minar_init() 00026 { 00027 return 0; 00028 } 00029 static void *utest_minar_post(const utest_v1_harness_callback_t callback, const uint32_t delay_ms) 00030 { 00031 void *handle = minar::Scheduler::postCallback(callback).delay(minar::milliseconds(delay_ms)).getHandle(); 00032 return handle; 00033 } 00034 static int32_t utest_minar_cancel(void *handle) 00035 { 00036 int32_t ret = minar::Scheduler::cancelCallback(handle); 00037 return ret; 00038 } 00039 static int32_t utest_minar_run() 00040 { 00041 return 0; 00042 } 00043 extern "C" { 00044 static const utest_v1_scheduler_t utest_v1_scheduler = 00045 { 00046 utest_minar_init, 00047 utest_minar_post, 00048 utest_minar_cancel, 00049 utest_minar_run 00050 }; 00051 utest_v1_scheduler_t utest_v1_get_scheduler() 00052 { 00053 return utest_v1_scheduler; 00054 } 00055 } 00056 00057 #elif UTEST_SHIM_SCHEDULER_USE_US_TICKER 00058 #ifdef YOTTA_MBED_HAL_VERSION_STRING 00059 # include "mbed-hal/us_ticker_api.h" 00060 #else 00061 #include "platform/SingletonPtr.h" 00062 #include "Timeout.h" 00063 using mbed::Timeout; 00064 #endif 00065 00066 // only one callback is active at any given time 00067 static volatile utest_v1_harness_callback_t minimal_callback; 00068 static volatile utest_v1_harness_callback_t ticker_callback; 00069 00070 // Timeout object used to control the scheduling of test case callbacks 00071 SingletonPtr<Timeout> utest_timeout_object; 00072 00073 static void ticker_handler() 00074 { 00075 UTEST_LOG_FUNCTION(); 00076 minimal_callback = ticker_callback; 00077 } 00078 00079 static int32_t utest_us_ticker_init() 00080 { 00081 UTEST_LOG_FUNCTION(); 00082 // initialize the Timeout object to makes sure it is not initialized in 00083 // interrupt context. 00084 utest_timeout_object.get(); 00085 return 0; 00086 } 00087 static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms) 00088 { 00089 UTEST_LOG_FUNCTION(); 00090 timestamp_t delay_us = delay_ms *1000; 00091 00092 if (delay_ms) { 00093 ticker_callback = callback; 00094 // fire the interrupt in 1000us * delay_ms 00095 utest_timeout_object->attach_us(ticker_handler, delay_us); 00096 00097 } 00098 else { 00099 minimal_callback = callback; 00100 } 00101 00102 // return a bogus handle 00103 return (void*)1; 00104 } 00105 static int32_t utest_us_ticker_cancel(void *handle) 00106 { 00107 UTEST_LOG_FUNCTION(); 00108 (void) handle; 00109 utest_timeout_object->detach(); 00110 return 0; 00111 } 00112 static int32_t utest_us_ticker_run() 00113 { 00114 UTEST_LOG_FUNCTION(); 00115 while(1) 00116 { 00117 // check if a new callback has been set 00118 if (minimal_callback) 00119 { 00120 // copy the callback 00121 utest_v1_harness_callback_t callback = minimal_callback; 00122 // reset the shared callback 00123 minimal_callback = NULL; 00124 // execute the copied callback 00125 callback(); 00126 } 00127 } 00128 } 00129 00130 00131 extern "C" { 00132 static const utest_v1_scheduler_t utest_v1_scheduler = 00133 { 00134 utest_us_ticker_init, 00135 utest_us_ticker_post, 00136 utest_us_ticker_cancel, 00137 utest_us_ticker_run 00138 }; 00139 utest_v1_scheduler_t utest_v1_get_scheduler() 00140 { 00141 UTEST_LOG_FUNCTION(); 00142 return utest_v1_scheduler; 00143 } 00144 } 00145 #endif 00146 00147 #ifdef YOTTA_CORE_UTIL_VERSION_STRING 00148 // their functionality is implemented using the CriticalSectionLock class 00149 void utest_v1_enter_critical_section(void) {} 00150 void utest_v1_leave_critical_section(void) {} 00151 #endif
Generated on Tue Jul 12 2022 20:53:02 by
1.7.2