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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 #include "platform/SingletonPtr.h" 00022 #include "Timeout.h" 00023 using mbed::Timeout; 00024 00025 // only one callback is active at any given time 00026 static volatile utest_v1_harness_callback_t minimal_callback; 00027 static volatile utest_v1_harness_callback_t ticker_callback; 00028 00029 // Timeout object used to control the scheduling of test case callbacks 00030 SingletonPtr<Timeout> utest_timeout_object; 00031 00032 static void ticker_handler() 00033 { 00034 UTEST_LOG_FUNCTION(); 00035 minimal_callback = ticker_callback; 00036 } 00037 00038 static int32_t utest_us_ticker_init() 00039 { 00040 UTEST_LOG_FUNCTION(); 00041 // initialize the Timeout object to makes sure it is not initialized in 00042 // interrupt context. 00043 utest_timeout_object.get(); 00044 return 0; 00045 } 00046 static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms) 00047 { 00048 UTEST_LOG_FUNCTION(); 00049 timestamp_t delay_us = delay_ms *1000; 00050 00051 if (delay_ms) { 00052 ticker_callback = callback; 00053 // fire the interrupt in 1000us * delay_ms 00054 utest_timeout_object->attach_us(ticker_handler, delay_us); 00055 00056 } 00057 else { 00058 minimal_callback = callback; 00059 } 00060 00061 // return a bogus handle 00062 return (void*)1; 00063 } 00064 static int32_t utest_us_ticker_cancel(void *handle) 00065 { 00066 UTEST_LOG_FUNCTION(); 00067 (void) handle; 00068 utest_timeout_object->detach(); 00069 return 0; 00070 } 00071 static int32_t utest_us_ticker_run() 00072 { 00073 UTEST_LOG_FUNCTION(); 00074 while(1) 00075 { 00076 // check if a new callback has been set 00077 if (minimal_callback) 00078 { 00079 // copy the callback 00080 utest_v1_harness_callback_t callback = minimal_callback; 00081 // reset the shared callback 00082 minimal_callback = NULL; 00083 // execute the copied callback 00084 callback(); 00085 } 00086 } 00087 } 00088 00089 00090 extern "C" { 00091 static const utest_v1_scheduler_t utest_v1_scheduler = 00092 { 00093 utest_us_ticker_init, 00094 utest_us_ticker_post, 00095 utest_us_ticker_cancel, 00096 utest_us_ticker_run 00097 }; 00098 utest_v1_scheduler_t utest_v1_get_scheduler() 00099 { 00100 UTEST_LOG_FUNCTION(); 00101 return utest_v1_scheduler; 00102 } 00103 }
Generated on Tue Jul 12 2022 13:55:03 by
