mirror of https://github.com/ARMmbed/mbed-os.git
Use functions instead of macros for porting.
parent
207660cc86
commit
12a46551a5
|
@ -49,20 +49,25 @@ namespace
|
||||||
|
|
||||||
location_t location = LOCATION_UNKNOWN;
|
location_t location = LOCATION_UNKNOWN;
|
||||||
|
|
||||||
utest_v1_scheduler_t scheduler = utest_v1_scheduler;
|
utest_v1_scheduler_t scheduler = {NULL, NULL, NULL, NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void die() {
|
static void die() {
|
||||||
while(1) ;
|
while(1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_scheduler_valid(const utest_v1_scheduler_t scheduler)
|
||||||
|
{
|
||||||
|
return (scheduler.init && scheduler.post && scheduler.cancel && scheduler.run);
|
||||||
|
}
|
||||||
|
|
||||||
bool Harness::set_scheduler(const utest_v1_scheduler_t scheduler)
|
bool Harness::set_scheduler(const utest_v1_scheduler_t scheduler)
|
||||||
{
|
{
|
||||||
if (!scheduler.init || !scheduler.post || !scheduler.cancel || !scheduler.run)
|
if (is_scheduler_valid(scheduler)) {
|
||||||
return false;
|
::scheduler = scheduler;
|
||||||
|
return true;
|
||||||
::scheduler = scheduler;
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Harness::run(const Specification& specification, size_t)
|
bool Harness::run(const Specification& specification, size_t)
|
||||||
|
@ -76,9 +81,13 @@ bool Harness::run(const Specification& specification)
|
||||||
if (is_busy())
|
if (is_busy())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!scheduler.init || !scheduler.post || !scheduler.cancel || !scheduler.run)
|
// if the scheduler is invalid, this is the first time we are calling
|
||||||
|
if (!is_scheduler_valid(scheduler))
|
||||||
|
scheduler = utest_v1_get_scheduler();
|
||||||
|
// if the scheduler is still invalid, abort
|
||||||
|
if (!is_scheduler_valid(scheduler))
|
||||||
return false;
|
return false;
|
||||||
|
// if the scheduler failed to initialize, abort
|
||||||
if (scheduler.init() != 0)
|
if (scheduler.init() != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "utest/shim.h"
|
#include "utest/shim.h"
|
||||||
|
|
||||||
|
|
||||||
#if UTEST_SHIM_SCHEDULER_USE_MINAR
|
#if UTEST_SHIM_SCHEDULER_USE_MINAR
|
||||||
#include "minar/minar.h"
|
#include "minar/minar.h"
|
||||||
|
|
||||||
|
@ -40,20 +39,26 @@ static int32_t utest_minar_run()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
extern "C" const utest_v1_scheduler_t utest_v1_scheduler =
|
extern "C" {
|
||||||
|
static const utest_v1_scheduler_t utest_v1_scheduler =
|
||||||
{
|
{
|
||||||
utest_minar_init,
|
utest_minar_init,
|
||||||
utest_minar_post,
|
utest_minar_post,
|
||||||
utest_minar_cancel,
|
utest_minar_cancel,
|
||||||
utest_minar_run
|
utest_minar_run
|
||||||
};
|
};
|
||||||
|
utest_v1_scheduler_t utest_v1_get_scheduler()
|
||||||
|
{
|
||||||
|
return utest_v1_scheduler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#elif UTEST_SHIM_SCHEDULER_USE_US_TICKER
|
#elif UTEST_SHIM_SCHEDULER_USE_US_TICKER
|
||||||
// only one callback is active at any given time
|
// only one callback is active at any given time
|
||||||
volatile utest_v1_harness_callback_t minimal_callback;
|
static volatile utest_v1_harness_callback_t minimal_callback;
|
||||||
volatile utest_v1_harness_callback_t ticker_callback;
|
static volatile utest_v1_harness_callback_t ticker_callback;
|
||||||
const ticker_data_t *ticker_data;
|
static const ticker_data_t *ticker_data;
|
||||||
ticker_event_t ticker_event;
|
static ticker_event_t ticker_event;
|
||||||
|
|
||||||
static void ticker_handler(uint32_t)
|
static void ticker_handler(uint32_t)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +69,7 @@ static void ticker_handler(uint32_t)
|
||||||
static int32_t utest_us_ticker_init()
|
static int32_t utest_us_ticker_init()
|
||||||
{
|
{
|
||||||
ticker_data = get_us_ticker_data();
|
ticker_data = get_us_ticker_data();
|
||||||
|
ticker_set_handler(ticker_data, ticker_handler);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, const uint32_t delay_ms)
|
static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, const uint32_t delay_ms)
|
||||||
|
@ -71,8 +77,6 @@ static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, co
|
||||||
// printf("\t\t>>> Schedule %p with %ums delay => %p.\n", callback, (unsigned int)delay_ms, (void*)1);
|
// printf("\t\t>>> Schedule %p with %ums delay => %p.\n", callback, (unsigned int)delay_ms, (void*)1);
|
||||||
if (delay_ms) {
|
if (delay_ms) {
|
||||||
ticker_callback = callback;
|
ticker_callback = callback;
|
||||||
// setup ticker to call the handler manually
|
|
||||||
ticker_set_handler(ticker_data, ticker_handler);
|
|
||||||
// fire the interrupt in 1000us * delay_ms
|
// fire the interrupt in 1000us * delay_ms
|
||||||
ticker_insert_event(ticker_data, &ticker_event, ticker_read(ticker_data) + delay_ms * 1000, 0);
|
ticker_insert_event(ticker_data, &ticker_event, ticker_read(ticker_data) + delay_ms * 1000, 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,19 +111,23 @@ static int32_t utest_us_ticker_run()
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const utest_v1_scheduler_t utest_v1_scheduler =
|
extern "C" {
|
||||||
|
static const utest_v1_scheduler_t utest_v1_scheduler =
|
||||||
{
|
{
|
||||||
utest_us_ticker_init,
|
utest_us_ticker_init,
|
||||||
utest_us_ticker_post,
|
utest_us_ticker_post,
|
||||||
utest_us_ticker_cancel,
|
utest_us_ticker_cancel,
|
||||||
utest_us_ticker_run
|
utest_us_ticker_run
|
||||||
};
|
};
|
||||||
#else
|
utest_v1_scheduler_t utest_v1_get_scheduler()
|
||||||
const utest_v1_scheduler_t utest_v1_scheduler =
|
|
||||||
{
|
{
|
||||||
NULL,
|
return utest_v1_scheduler;
|
||||||
NULL,
|
}
|
||||||
NULL,
|
}
|
||||||
NULL
|
#endif
|
||||||
};
|
|
||||||
|
#ifdef YOTTA_CORE_UTIL_VERSION_STRING
|
||||||
|
// their functionality is implemented using the CriticalSectionLock class
|
||||||
|
void utest_v1_enter_critical_section(void) {}
|
||||||
|
void utest_v1_leave_critical_section(void) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,10 +42,10 @@
|
||||||
# define UTEST_LEAVE_CRITICAL_SECTION
|
# define UTEST_LEAVE_CRITICAL_SECTION
|
||||||
#else
|
#else
|
||||||
# ifndef UTEST_ENTER_CRITICAL_SECTION
|
# ifndef UTEST_ENTER_CRITICAL_SECTION
|
||||||
# error "You must provide a UTEST_ENTER_CRITICAL_SECTION implementation!"
|
# define UTEST_ENTER_CRITICAL_SECTION utest_v1_enter_critical_section()
|
||||||
# endif
|
# endif
|
||||||
# ifndef UTEST_LEAVE_CRITICAL_SECTION
|
# ifndef UTEST_LEAVE_CRITICAL_SECTION
|
||||||
# error "You must provide a UTEST_LEAVE_CRITICAL_SECTION implementation!"
|
# define UTEST_LEAVE_CRITICAL_SECTION utest_v1_leave_critical_section()
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -67,8 +67,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// must be implemented by the port
|
||||||
|
void utest_v1_enter_critical_section(void);
|
||||||
|
void utest_v1_leave_critical_section(void);
|
||||||
|
|
||||||
/// This is the default scheduler implementation used by the harness.
|
/// This is the default scheduler implementation used by the harness.
|
||||||
extern const utest_v1_scheduler_t utest_v1_scheduler;
|
utest_v1_scheduler_t utest_v1_get_scheduler(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue