From bc1ee63f64124a3a0e8450f1a822fe2318d5d2ee Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:30:11 +0900 Subject: [PATCH] Issue #25 : Add wider API support of RasPi Pico SDK hardware_sync. --- src/sdk/mocksdkwrapper.hpp | 47 ++ src/sdk/pico_api_alternate_defs.hpp | 6 + src/sdk/pico_sdk_apistub.cpp | 788 ++++++++++++++++++ src/sdk/pico_sdk_headers.h | 4 + src/sdk/scripts/api_dirs.txt | 1 + .../blocks/pico_api_alternate_defs.hpp | 6 + src/sdk/sdkwrapper.cpp | 187 +++++ src/sdk/sdkwrapper.hpp | 43 + test/test_sdkwrapper.cpp | 45 +- test/todo/test_sdkwrapper.md | 6 + 10 files changed, 1132 insertions(+), 1 deletion(-) diff --git a/src/sdk/mocksdkwrapper.hpp b/src/sdk/mocksdkwrapper.hpp index b978b6c..57de7a6 100644 --- a/src/sdk/mocksdkwrapper.hpp +++ b/src/sdk/mocksdkwrapper.hpp @@ -867,6 +867,53 @@ class MockSdkWrapper : public SdkWrapper { MOCK_METHOD1(tick_is_running, bool(tick_gen_num_t tick)); MOCK_METHOD2(tick_start, void(tick_gen_num_t tick, uint cycles)); MOCK_METHOD1(tick_stop, void(tick_gen_num_t tick)); + MOCK_METHOD1(busy_wait_ms, void(uint32_t delay_ms)); + MOCK_METHOD1(busy_wait_until, void(absolute_time_t t)); + MOCK_METHOD1(busy_wait_us, void(uint64_t delay_us)); + MOCK_METHOD1(busy_wait_us_32, void(uint32_t delay_us)); + MOCK_METHOD1(hardware_alarm_cancel, void(uint alarm_num)); + MOCK_METHOD1(hardware_alarm_claim, void(uint alarm_num)); + MOCK_METHOD1(hardware_alarm_claim_unused, int(bool required)); + MOCK_METHOD1(hardware_alarm_force_irq, void(uint alarm_num)); + MOCK_METHOD2(hardware_alarm_get_irq_num, + uint(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD1(hardware_alarm_is_claimed, bool(uint alarm_num)); + MOCK_METHOD2(hardware_alarm_set_callback, + void(uint alarm_num, hardware_alarm_callback_t callback)); + MOCK_METHOD2(hardware_alarm_set_target, + bool(uint alarm_num, absolute_time_t t)); + MOCK_METHOD1(hardware_alarm_unclaim, void(uint alarm_num)); + MOCK_METHOD1(time_reached, bool(absolute_time_t t)); + MOCK_METHOD0(time_us_32, uint32_t()); + MOCK_METHOD0(time_us_64, uint64_t()); + MOCK_METHOD2(timer_busy_wait_ms, void(timer_hw_t* timer, uint32_t delay_ms)); + MOCK_METHOD2(timer_busy_wait_until, + void(timer_hw_t* timer, absolute_time_t t)); + MOCK_METHOD2(timer_busy_wait_us, void(timer_hw_t* timer, uint64_t delay_us)); + MOCK_METHOD2(timer_busy_wait_us_32, + void(timer_hw_t* timer, uint32_t delay_us)); + MOCK_METHOD1(timer_get_index, uint(timer_hw_t* timer)); + MOCK_METHOD1(timer_get_instance, timer_hw_t*(uint timer_num)); + MOCK_METHOD2(timer_hardware_alarm_cancel, + void(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD2(timer_hardware_alarm_claim, + void(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD2(timer_hardware_alarm_claim_unused, + int(timer_hw_t* timer, bool required)); + MOCK_METHOD2(timer_hardware_alarm_force_irq, + void(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD2(timer_hardware_alarm_is_claimed, + bool(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD3(timer_hardware_alarm_set_callback, + void(timer_hw_t* timer, uint alarm_num, + hardware_alarm_callback_t callback)); + MOCK_METHOD3(timer_hardware_alarm_set_target, + bool(timer_hw_t* timer, uint alarm_num, absolute_time_t t)); + MOCK_METHOD2(timer_hardware_alarm_unclaim, + void(timer_hw_t* timer, uint alarm_num)); + MOCK_METHOD2(timer_time_reached, bool(timer_hw_t* timer, absolute_time_t t)); + MOCK_METHOD1(timer_time_us_32, uint32_t(timer_hw_t* timer)); + MOCK_METHOD1(timer_time_us_64, uint64_t(timer_hw_t* timer)); } // class MockSdkWrapper : public SdkWrapper ; // GCOVR_EXCL_STOP diff --git a/src/sdk/pico_api_alternate_defs.hpp b/src/sdk/pico_api_alternate_defs.hpp index 0c3fd2a..e9ffb7c 100644 --- a/src/sdk/pico_api_alternate_defs.hpp +++ b/src/sdk/pico_api_alternate_defs.hpp @@ -39,6 +39,12 @@ enum pwm_clkdiv_mode { q, r }; /// @brief Alternate definition for Google Test build. enum sha256_endianness { s, t }; +//// @brief Alternate definition for Google Test build. +typedef int absolute_time_t; +//// @brief Alternate definition for Google Test build. +typedef int hardware_alarm_callback_t; +//// @brief Alternate definition for Google Test build. +typedef int timer_hw_t; //// @brief Alternate definition for Google Test build. typedef int tick_gen_num_t; //// @brief Alternate definition for Google Test build. diff --git a/src/sdk/pico_sdk_apistub.cpp b/src/sdk/pico_sdk_apistub.cpp index 0e1913f..18835bd 100644 --- a/src/sdk/pico_sdk_apistub.cpp +++ b/src/sdk/pico_sdk_apistub.cpp @@ -14505,3 +14505,791 @@ extern "C" void _weak_tick_stop(tick_gen_num_t tick) #pragma comment(linker, "/alternatename:tick_stop=_weak_tick_stop") #endif // x86 or amd64 #endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void busy_wait_ms(uint32_t delay_ms); +__attribute__((weak)) void busy_wait_ms(uint32_t delay_ms) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_busy_wait_ms(uint32_t delay_ms) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, "/alternatename:_busy_wait_ms=__weak_busy_wait_ms") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:busy_wait_ms=_weak_busy_wait_ms") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void busy_wait_until(absolute_time_t t); +__attribute__((weak)) void busy_wait_until(absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_busy_wait_until(absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, \ + "/alternatename:_busy_wait_until=__weak_busy_wait_until") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:busy_wait_until=_weak_busy_wait_until") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void busy_wait_us(uint64_t delay_us); +__attribute__((weak)) void busy_wait_us(uint64_t delay_us) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_busy_wait_us(uint64_t delay_us) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, "/alternatename:_busy_wait_us=__weak_busy_wait_us") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:busy_wait_us=_weak_busy_wait_us") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void busy_wait_us_32(uint32_t delay_us); +__attribute__((weak)) void busy_wait_us_32(uint32_t delay_us) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_busy_wait_us_32(uint32_t delay_us) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, \ + "/alternatename:_busy_wait_us_32=__weak_busy_wait_us_32") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:busy_wait_us_32=_weak_busy_wait_us_32") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void hardware_alarm_cancel(uint alarm_num); +__attribute__((weak)) void hardware_alarm_cancel(uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_hardware_alarm_cancel(uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_cancel=__weak_hardware_alarm_cancel") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_cancel=_weak_hardware_alarm_cancel") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void hardware_alarm_claim(uint alarm_num); +__attribute__((weak)) void hardware_alarm_claim(uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_hardware_alarm_claim(uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_claim=__weak_hardware_alarm_claim") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, "/alternatename:hardware_alarm_claim=_weak_hardware_alarm_claim") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" int hardware_alarm_claim_unused(bool required); +__attribute__((weak)) int hardware_alarm_claim_unused(bool required) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" int _weak_hardware_alarm_claim_unused(bool required) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_claim_unused=__weak_hardware_alarm_claim_unused") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_claim_unused=_weak_hardware_alarm_claim_unused") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void hardware_alarm_force_irq(uint alarm_num); +__attribute__((weak)) void hardware_alarm_force_irq(uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_hardware_alarm_force_irq(uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_force_irq=__weak_hardware_alarm_force_irq") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_force_irq=_weak_hardware_alarm_force_irq") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint hardware_alarm_get_irq_num(timer_hw_t* timer, uint alarm_num); +__attribute__((weak)) uint hardware_alarm_get_irq_num(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_hardware_alarm_get_irq_num(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_get_irq_num=__weak_hardware_alarm_get_irq_num") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_get_irq_num=_weak_hardware_alarm_get_irq_num") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool hardware_alarm_is_claimed(uint alarm_num); +__attribute__((weak)) bool hardware_alarm_is_claimed(uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_hardware_alarm_is_claimed(uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_is_claimed=__weak_hardware_alarm_is_claimed") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_is_claimed=_weak_hardware_alarm_is_claimed") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void hardware_alarm_set_callback(uint alarm_num, + hardware_alarm_callback_t callback); +__attribute__((weak)) void hardware_alarm_set_callback( + uint alarm_num, hardware_alarm_callback_t callback) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_hardware_alarm_set_callback( + uint alarm_num, hardware_alarm_callback_t callback) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_set_callback=__weak_hardware_alarm_set_callback") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_set_callback=_weak_hardware_alarm_set_callback") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool hardware_alarm_set_target(uint alarm_num, absolute_time_t t); +__attribute__((weak)) bool hardware_alarm_set_target(uint alarm_num, + absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_hardware_alarm_set_target(uint alarm_num, + absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_set_target=__weak_hardware_alarm_set_target") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_set_target=_weak_hardware_alarm_set_target") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void hardware_alarm_unclaim(uint alarm_num); +__attribute__((weak)) void hardware_alarm_unclaim(uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_hardware_alarm_unclaim(uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_hardware_alarm_unclaim=__weak_hardware_alarm_unclaim") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:hardware_alarm_unclaim=_weak_hardware_alarm_unclaim") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool time_reached(absolute_time_t t); +__attribute__((weak)) bool time_reached(absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_time_reached(absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, "/alternatename:_time_reached=__weak_time_reached") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:time_reached=_weak_time_reached") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint32_t time_us_32(void); +__attribute__((weak)) uint32_t time_us_32(void) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint32_t _weak_time_us_32(void) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, "/alternatename:_time_us_32=__weak_time_us_32") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:time_us_32=_weak_time_us_32") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint64_t time_us_64(void); +__attribute__((weak)) uint64_t time_us_64(void) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint64_t _weak_time_us_64(void) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, "/alternatename:_time_us_64=__weak_time_us_64") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:time_us_64=_weak_time_us_64") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_busy_wait_ms(timer_hw_t* timer, uint32_t delay_ms); +__attribute__((weak)) void timer_busy_wait_ms(timer_hw_t* timer, + uint32_t delay_ms) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_busy_wait_ms(timer_hw_t* timer, uint32_t delay_ms) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, "/alternatename:_timer_busy_wait_ms=__weak_timer_busy_wait_ms") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_busy_wait_ms=_weak_timer_busy_wait_ms") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_busy_wait_until(timer_hw_t* timer, absolute_time_t t); +__attribute__((weak)) void timer_busy_wait_until(timer_hw_t* timer, + absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_busy_wait_until(timer_hw_t* timer, + absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_busy_wait_until=__weak_timer_busy_wait_until") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_busy_wait_until=_weak_timer_busy_wait_until") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_busy_wait_us(timer_hw_t* timer, uint64_t delay_us); +__attribute__((weak)) void timer_busy_wait_us(timer_hw_t* timer, + uint64_t delay_us) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_busy_wait_us(timer_hw_t* timer, uint64_t delay_us) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, "/alternatename:_timer_busy_wait_us=__weak_timer_busy_wait_us") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_busy_wait_us=_weak_timer_busy_wait_us") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_busy_wait_us_32(timer_hw_t* timer, uint32_t delay_us); +__attribute__((weak)) void timer_busy_wait_us_32(timer_hw_t* timer, + uint32_t delay_us) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_busy_wait_us_32(timer_hw_t* timer, + uint32_t delay_us) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_busy_wait_us_32=__weak_timer_busy_wait_us_32") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_busy_wait_us_32=_weak_timer_busy_wait_us_32") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint timer_get_index(timer_hw_t* timer); +__attribute__((weak)) uint timer_get_index(timer_hw_t* timer) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_timer_get_index(timer_hw_t* timer) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, \ + "/alternatename:_timer_get_index=__weak_timer_get_index") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:timer_get_index=_weak_timer_get_index") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" timer_hw_t* timer_get_instance(uint timer_num); +__attribute__((weak)) timer_hw_t* timer_get_instance(uint timer_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" timer_hw_t* _weak_timer_get_instance(uint timer_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, "/alternatename:_timer_get_instance=__weak_timer_get_instance") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_get_instance=_weak_timer_get_instance") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_hardware_alarm_cancel(timer_hw_t* timer, uint alarm_num); +__attribute__((weak)) void timer_hardware_alarm_cancel(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_hardware_alarm_cancel(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_cancel=__weak_timer_hardware_alarm_cancel") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_cancel=_weak_timer_hardware_alarm_cancel") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_hardware_alarm_claim(timer_hw_t* timer, uint alarm_num); +__attribute__((weak)) void timer_hardware_alarm_claim(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_hardware_alarm_claim(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_claim=__weak_timer_hardware_alarm_claim") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_claim=_weak_timer_hardware_alarm_claim") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" int timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required); +__attribute__((weak)) int timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" int _weak_timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_claim_unused=__weak_timer_hardware_alarm_claim_unused") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_claim_unused=_weak_timer_hardware_alarm_claim_unused") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num); +__attribute__((weak)) void timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_force_irq=__weak_timer_hardware_alarm_force_irq") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_force_irq=_weak_timer_hardware_alarm_force_irq") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num); +__attribute__((weak)) bool timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_is_claimed=__weak_timer_hardware_alarm_is_claimed") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_is_claimed=_weak_timer_hardware_alarm_is_claimed") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback); +__attribute__((weak)) void timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_set_callback=__weak_timer_hardware_alarm_set_callback") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_set_callback=_weak_timer_hardware_alarm_set_callback") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool timer_hardware_alarm_set_target(timer_hw_t* timer, + uint alarm_num, + absolute_time_t t); +__attribute__((weak)) bool timer_hardware_alarm_set_target(timer_hw_t* timer, + uint alarm_num, + absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_timer_hardware_alarm_set_target(timer_hw_t* timer, + uint alarm_num, + absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_set_target=__weak_timer_hardware_alarm_set_target") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_set_target=_weak_timer_hardware_alarm_set_target") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void timer_hardware_alarm_unclaim(timer_hw_t* timer, uint alarm_num); +__attribute__((weak)) void timer_hardware_alarm_unclaim(timer_hw_t* timer, + uint alarm_num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_timer_hardware_alarm_unclaim(timer_hw_t* timer, + uint alarm_num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, \ + "/alternatename:_timer_hardware_alarm_unclaim=__weak_timer_hardware_alarm_unclaim") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:timer_hardware_alarm_unclaim=_weak_timer_hardware_alarm_unclaim") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool timer_time_reached(timer_hw_t* timer, absolute_time_t t); +__attribute__((weak)) bool timer_time_reached(timer_hw_t* timer, + absolute_time_t t) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_timer_time_reached(timer_hw_t* timer, absolute_time_t t) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment( \ + linker, "/alternatename:_timer_time_reached=__weak_timer_time_reached") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_time_reached=_weak_timer_time_reached") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint32_t timer_time_us_32(timer_hw_t* timer); +__attribute__((weak)) uint32_t timer_time_us_32(timer_hw_t* timer) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint32_t _weak_timer_time_us_32(timer_hw_t* timer) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, \ + "/alternatename:_timer_time_us_32=__weak_timer_time_us_32") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_time_us_32=_weak_timer_time_us_32") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint64_t timer_time_us_64(timer_hw_t* timer); +__attribute__((weak)) uint64_t timer_time_us_64(timer_hw_t* timer) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint64_t _weak_timer_time_us_64(timer_hw_t* timer) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_timer library is missing in the link phase."); +} +#if defined(_MSC_VER) // weak binding in MSVC must be after definition +#if defined(_M_IX86) // for x86 +#pragma comment(linker, \ + "/alternatename:_timer_time_us_64=__weak_timer_time_us_64") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:timer_time_us_64=_weak_timer_time_us_64") +#endif // x86 or amd64 +#endif // _MSC_VER diff --git a/src/sdk/pico_sdk_headers.h b/src/sdk/pico_sdk_headers.h index a1230a6..04d6f60 100644 --- a/src/sdk/pico_sdk_headers.h +++ b/src/sdk/pico_sdk_headers.h @@ -99,3 +99,7 @@ #if __has_include() || __has_include() #include #endif // __has_include() || __has_include() + +#if __has_include() || __has_include() +#include +#endif // __has_include() || __has_include() diff --git a/src/sdk/scripts/api_dirs.txt b/src/sdk/scripts/api_dirs.txt index fb8c5bd..20d40e8 100644 --- a/src/sdk/scripts/api_dirs.txt +++ b/src/sdk/scripts/api_dirs.txt @@ -21,3 +21,4 @@ hardware sha256 hardware spi hardware sync hardware ticks +hardware timer diff --git a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp index 0c3fd2a..e9ffb7c 100644 --- a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp +++ b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp @@ -39,6 +39,12 @@ enum pwm_clkdiv_mode { q, r }; /// @brief Alternate definition for Google Test build. enum sha256_endianness { s, t }; +//// @brief Alternate definition for Google Test build. +typedef int absolute_time_t; +//// @brief Alternate definition for Google Test build. +typedef int hardware_alarm_callback_t; +//// @brief Alternate definition for Google Test build. +typedef int timer_hw_t; //// @brief Alternate definition for Google Test build. typedef int tick_gen_num_t; //// @brief Alternate definition for Google Test build. diff --git a/src/sdk/sdkwrapper.cpp b/src/sdk/sdkwrapper.cpp index 85a513f..bf6b578 100644 --- a/src/sdk/sdkwrapper.cpp +++ b/src/sdk/sdkwrapper.cpp @@ -3593,3 +3593,190 @@ void rpp_driver::SdkWrapper::tick_stop(tick_gen_num_t tick) { ::tick_stop(tick); } #endif // __has_include() || __has_include() + +#if __has_include() || __has_include() +// -------------------------------------------------- +extern "C" void busy_wait_ms(uint32_t delay_ms); +void rpp_driver::SdkWrapper::busy_wait_ms(uint32_t delay_ms) { + ::busy_wait_ms(delay_ms); +} +// -------------------------------------------------- +extern "C" void busy_wait_until(absolute_time_t t); +void rpp_driver::SdkWrapper::busy_wait_until(absolute_time_t t) { + ::busy_wait_until(t); +} +// -------------------------------------------------- +extern "C" void busy_wait_us(uint64_t delay_us); +void rpp_driver::SdkWrapper::busy_wait_us(uint64_t delay_us) { + ::busy_wait_us(delay_us); +} +// -------------------------------------------------- +extern "C" void busy_wait_us_32(uint32_t delay_us); +void rpp_driver::SdkWrapper::busy_wait_us_32(uint32_t delay_us) { + ::busy_wait_us_32(delay_us); +} +// -------------------------------------------------- +extern "C" void hardware_alarm_cancel(uint alarm_num); +void rpp_driver::SdkWrapper::hardware_alarm_cancel(uint alarm_num) { + ::hardware_alarm_cancel(alarm_num); +} +// -------------------------------------------------- +extern "C" void hardware_alarm_claim(uint alarm_num); +void rpp_driver::SdkWrapper::hardware_alarm_claim(uint alarm_num) { + ::hardware_alarm_claim(alarm_num); +} +// -------------------------------------------------- +extern "C" int hardware_alarm_claim_unused(bool required); +int rpp_driver::SdkWrapper::hardware_alarm_claim_unused(bool required) { + return ::hardware_alarm_claim_unused(required); +} +// -------------------------------------------------- +extern "C" void hardware_alarm_force_irq(uint alarm_num); +void rpp_driver::SdkWrapper::hardware_alarm_force_irq(uint alarm_num) { + ::hardware_alarm_force_irq(alarm_num); +} +// -------------------------------------------------- +extern "C" uint hardware_alarm_get_irq_num(timer_hw_t* timer, uint alarm_num); +uint rpp_driver::SdkWrapper::hardware_alarm_get_irq_num(timer_hw_t* timer, + uint alarm_num) { + return ::hardware_alarm_get_irq_num(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" bool hardware_alarm_is_claimed(uint alarm_num); +bool rpp_driver::SdkWrapper::hardware_alarm_is_claimed(uint alarm_num) { + return ::hardware_alarm_is_claimed(alarm_num); +} +// -------------------------------------------------- +extern "C" void hardware_alarm_set_callback(uint alarm_num, + hardware_alarm_callback_t callback); +void rpp_driver::SdkWrapper::hardware_alarm_set_callback( + uint alarm_num, hardware_alarm_callback_t callback) { + ::hardware_alarm_set_callback(alarm_num, callback); +} +// -------------------------------------------------- +extern "C" bool hardware_alarm_set_target(uint alarm_num, absolute_time_t t); +bool rpp_driver::SdkWrapper::hardware_alarm_set_target(uint alarm_num, + absolute_time_t t) { + return ::hardware_alarm_set_target(alarm_num, t); +} +// -------------------------------------------------- +extern "C" void hardware_alarm_unclaim(uint alarm_num); +void rpp_driver::SdkWrapper::hardware_alarm_unclaim(uint alarm_num) { + ::hardware_alarm_unclaim(alarm_num); +} +// -------------------------------------------------- +extern "C" bool time_reached(absolute_time_t t); +bool rpp_driver::SdkWrapper::time_reached(absolute_time_t t) { + return ::time_reached(t); +} +// -------------------------------------------------- +extern "C" uint32_t time_us_32(void); +uint32_t rpp_driver::SdkWrapper::time_us_32(void) { return ::time_us_32(); } +// -------------------------------------------------- +extern "C" uint64_t time_us_64(void); +uint64_t rpp_driver::SdkWrapper::time_us_64(void) { return ::time_us_64(); } +// -------------------------------------------------- +extern "C" void timer_busy_wait_ms(timer_hw_t* timer, uint32_t delay_ms); +void rpp_driver::SdkWrapper::timer_busy_wait_ms(timer_hw_t* timer, + uint32_t delay_ms) { + ::timer_busy_wait_ms(timer, delay_ms); +} +// -------------------------------------------------- +extern "C" void timer_busy_wait_until(timer_hw_t* timer, absolute_time_t t); +void rpp_driver::SdkWrapper::timer_busy_wait_until(timer_hw_t* timer, + absolute_time_t t) { + ::timer_busy_wait_until(timer, t); +} +// -------------------------------------------------- +extern "C" void timer_busy_wait_us(timer_hw_t* timer, uint64_t delay_us); +void rpp_driver::SdkWrapper::timer_busy_wait_us(timer_hw_t* timer, + uint64_t delay_us) { + ::timer_busy_wait_us(timer, delay_us); +} +// -------------------------------------------------- +extern "C" void timer_busy_wait_us_32(timer_hw_t* timer, uint32_t delay_us); +void rpp_driver::SdkWrapper::timer_busy_wait_us_32(timer_hw_t* timer, + uint32_t delay_us) { + ::timer_busy_wait_us_32(timer, delay_us); +} +// -------------------------------------------------- +extern "C" uint timer_get_index(timer_hw_t* timer); +uint rpp_driver::SdkWrapper::timer_get_index(timer_hw_t* timer) { + return ::timer_get_index(timer); +} +// -------------------------------------------------- +extern "C" timer_hw_t* timer_get_instance(uint timer_num); +timer_hw_t* rpp_driver::SdkWrapper::timer_get_instance(uint timer_num) { + return ::timer_get_instance(timer_num); +} +// -------------------------------------------------- +extern "C" void timer_hardware_alarm_cancel(timer_hw_t* timer, uint alarm_num); +void rpp_driver::SdkWrapper::timer_hardware_alarm_cancel(timer_hw_t* timer, + uint alarm_num) { + ::timer_hardware_alarm_cancel(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" void timer_hardware_alarm_claim(timer_hw_t* timer, uint alarm_num); +void rpp_driver::SdkWrapper::timer_hardware_alarm_claim(timer_hw_t* timer, + uint alarm_num) { + ::timer_hardware_alarm_claim(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" int timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required); +int rpp_driver::SdkWrapper::timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required) { + return ::timer_hardware_alarm_claim_unused(timer, required); +} +// -------------------------------------------------- +extern "C" void timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num); +void rpp_driver::SdkWrapper::timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num) { + ::timer_hardware_alarm_force_irq(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" bool timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num); +bool rpp_driver::SdkWrapper::timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num) { + return ::timer_hardware_alarm_is_claimed(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" void timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback); +void rpp_driver::SdkWrapper::timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback) { + ::timer_hardware_alarm_set_callback(timer, alarm_num, callback); +} +// -------------------------------------------------- +extern "C" bool timer_hardware_alarm_set_target(timer_hw_t* timer, + uint alarm_num, + absolute_time_t t); +bool rpp_driver::SdkWrapper::timer_hardware_alarm_set_target( + timer_hw_t* timer, uint alarm_num, absolute_time_t t) { + return ::timer_hardware_alarm_set_target(timer, alarm_num, t); +} +// -------------------------------------------------- +extern "C" void timer_hardware_alarm_unclaim(timer_hw_t* timer, uint alarm_num); +void rpp_driver::SdkWrapper::timer_hardware_alarm_unclaim(timer_hw_t* timer, + uint alarm_num) { + ::timer_hardware_alarm_unclaim(timer, alarm_num); +} +// -------------------------------------------------- +extern "C" bool timer_time_reached(timer_hw_t* timer, absolute_time_t t); +bool rpp_driver::SdkWrapper::timer_time_reached(timer_hw_t* timer, + absolute_time_t t) { + return ::timer_time_reached(timer, t); +} +// -------------------------------------------------- +extern "C" uint32_t timer_time_us_32(timer_hw_t* timer); +uint32_t rpp_driver::SdkWrapper::timer_time_us_32(timer_hw_t* timer) { + return ::timer_time_us_32(timer); +} +// -------------------------------------------------- +extern "C" uint64_t timer_time_us_64(timer_hw_t* timer); +uint64_t rpp_driver::SdkWrapper::timer_time_us_64(timer_hw_t* timer) { + return ::timer_time_us_64(timer); +} +#endif // __has_include() || __has_include() diff --git a/src/sdk/sdkwrapper.hpp b/src/sdk/sdkwrapper.hpp index f0b6e41..4fec589 100644 --- a/src/sdk/sdkwrapper.hpp +++ b/src/sdk/sdkwrapper.hpp @@ -941,6 +941,49 @@ class SdkWrapper { virtual void tick_stop(tick_gen_num_t tick); #endif // __has_include() || __has_include() +#if __has_include() || __has_include() + virtual void busy_wait_ms(uint32_t delay_ms); + virtual void busy_wait_until(absolute_time_t t); + virtual void busy_wait_us(uint64_t delay_us); + virtual void busy_wait_us_32(uint32_t delay_us); + virtual void hardware_alarm_cancel(uint alarm_num); + virtual void hardware_alarm_claim(uint alarm_num); + virtual int hardware_alarm_claim_unused(bool required); + virtual void hardware_alarm_force_irq(uint alarm_num); + virtual uint hardware_alarm_get_irq_num(timer_hw_t* timer, uint alarm_num); + virtual bool hardware_alarm_is_claimed(uint alarm_num); + virtual void hardware_alarm_set_callback(uint alarm_num, + hardware_alarm_callback_t callback); + virtual bool hardware_alarm_set_target(uint alarm_num, absolute_time_t t); + virtual void hardware_alarm_unclaim(uint alarm_num); + virtual bool time_reached(absolute_time_t t); + virtual uint32_t time_us_32(void); + virtual uint64_t time_us_64(void); + virtual void timer_busy_wait_ms(timer_hw_t* timer, uint32_t delay_ms); + virtual void timer_busy_wait_until(timer_hw_t* timer, absolute_time_t t); + virtual void timer_busy_wait_us(timer_hw_t* timer, uint64_t delay_us); + virtual void timer_busy_wait_us_32(timer_hw_t* timer, uint32_t delay_us); + virtual uint timer_get_index(timer_hw_t* timer); + virtual timer_hw_t* timer_get_instance(uint timer_num); + virtual void timer_hardware_alarm_cancel(timer_hw_t* timer, uint alarm_num); + virtual void timer_hardware_alarm_claim(timer_hw_t* timer, uint alarm_num); + virtual int timer_hardware_alarm_claim_unused(timer_hw_t* timer, + bool required); + virtual void timer_hardware_alarm_force_irq(timer_hw_t* timer, + uint alarm_num); + virtual bool timer_hardware_alarm_is_claimed(timer_hw_t* timer, + uint alarm_num); + virtual void timer_hardware_alarm_set_callback( + timer_hw_t* timer, uint alarm_num, hardware_alarm_callback_t callback); + virtual bool timer_hardware_alarm_set_target(timer_hw_t* timer, + uint alarm_num, + absolute_time_t t); + virtual void timer_hardware_alarm_unclaim(timer_hw_t* timer, uint alarm_num); + virtual bool timer_time_reached(timer_hw_t* timer, absolute_time_t t); + virtual uint32_t timer_time_us_32(timer_hw_t* timer); + virtual uint64_t timer_time_us_64(timer_hw_t* timer); +#endif // __has_include() || __has_include() + }; // class SdkWrapper #include "mocksdkwrapper.hpp" diff --git a/test/test_sdkwrapper.cpp b/test/test_sdkwrapper.cpp index efe4e88..a629b71 100644 --- a/test/test_sdkwrapper.cpp +++ b/test/test_sdkwrapper.cpp @@ -83,6 +83,7 @@ FAKE_VOID_FUNC(sha256_set_dma_size, uint); FAKE_VALUE_FUNC(bool, spi_is_readable, const spi_inst_t *); FAKE_VALUE_FUNC(bool, spin_lock_is_claimed, uint); FAKE_VALUE_FUNC(bool, tick_is_running, tick_gen_num_t); +FAKE_VALUE_FUNC(bool, time_reached, absolute_time_t); } // The cpp file of the library to test. #include "../src/sdk/sdkwrapper.cpp" @@ -2114,4 +2115,46 @@ TEST(SdkWrapper, tick_is_running) { index++; } RESET_FAKE(tick_is_running); -} // TEST(SdkWrapper, tick_is_running) \ No newline at end of file +} // TEST(SdkWrapper, tick_is_running) + +// ----------------------------------------------------------- +// +// hardware_timer +// virtual bool time_reached(absolute_time_t t); +// +// ----------------------------------------------------------- + +TEST(SdkWrapper, time_reached) { + std::random_device rng; + ::rpp_driver::SdkWrapper pico; + // uniform distribution + std::uniform_int_distribution param_dist(0, INT_MAX); + absolute_time_t param_array0[] = {param_dist(rng), param_dist(rng)}; + bool retval_array[std::size(param_array0)] = {true, false}; + + FFF_RESET_HISTORY(); + RESET_FAKE(time_reached); + + SET_RETURN_SEQ(time_reached, retval_array, std::size(retval_array)); + + // Check whether return values are correctly passed to wrapper. + int index = 0; + for (auto &¶m0 : param_array0) { + ASSERT_EQ(pico.time_reached(param0), retval_array[index]); + index++; + } + + // Check the data from test spy. How many time called? + ASSERT_EQ(time_reached_fake.call_count, std::size(retval_array)); + + // Check whether parameters were correctly passed from wrapper. + index = 0; + for (auto &¶m0 : param_array0) { + // Check the data from test spy. Call order. + ASSERT_EQ(fff.call_history[index], (void *)time_reached); + // Check the data from test spy. : Parameters. + ASSERT_EQ(time_reached_fake.arg0_history[index], param0); + index++; + } + RESET_FAKE(time_reached); +} // TEST(SdkWrapper, time_reached) \ No newline at end of file diff --git a/test/todo/test_sdkwrapper.md b/test/todo/test_sdkwrapper.md index c6a1c76..8846c7e 100644 --- a/test/todo/test_sdkwrapper.md +++ b/test/todo/test_sdkwrapper.md @@ -1,4 +1,10 @@ # test_SdkWrapper TDD +## SdkWrapper::time_reached() +- [x] Implement member function . +- [x] Create test case to fail. +- [x] Make it success. +- [x] Remove the duplication. + ## SdkWrapper::tick_is_running() - [x] Implement member function . - [x] Create test case to fail.