From c1fcd5f401be43c79ca1e6fc30e383252cf0dff0 Mon Sep 17 00:00:00 2001 From: Seiichi Horie <26223147+suikan4github@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:59:36 +0900 Subject: [PATCH] Issue #25 : Add wider API support of RasPi Pico SDK hardware_watchdog. --- src/sdk/mocksdkwrapper.hpp | 3 ++ src/sdk/pico_sdk_apistub.cpp | 57 +++++++++++++++++++++++++++++++++ src/sdk/pico_sdk_headers.h | 62 +++++++++++++++++++----------------- src/sdk/scripts/api_dirs.txt | 1 + src/sdk/sdkwrapper.cpp | 12 +++++++ src/sdk/sdkwrapper.hpp | 6 ++++ test/test_sdkwrapper.cpp | 22 +++++++++++++ test/todo/test_sdkwrapper.md | 6 ++++ 8 files changed, 139 insertions(+), 30 deletions(-) diff --git a/src/sdk/mocksdkwrapper.hpp b/src/sdk/mocksdkwrapper.hpp index ff875ac..28580a3 100644 --- a/src/sdk/mocksdkwrapper.hpp +++ b/src/sdk/mocksdkwrapper.hpp @@ -961,6 +961,9 @@ class MockSdkWrapper : public SdkWrapper { void(uint32_t pc, uint32_t sp, uint32_t delay_ms)); MOCK_METHOD1(watchdog_start_tick, void(uint cycles)); MOCK_METHOD0(watchdog_update, void()); + MOCK_METHOD0(xosc_disable, void()); + MOCK_METHOD0(xosc_dormant, void()); + MOCK_METHOD0(xosc_init, void()); } // class MockSdkWrapper : public SdkWrapper ; // GCOVR_EXCL_STOP diff --git a/src/sdk/pico_sdk_apistub.cpp b/src/sdk/pico_sdk_apistub.cpp index 2e75837..12f31a2 100644 --- a/src/sdk/pico_sdk_apistub.cpp +++ b/src/sdk/pico_sdk_apistub.cpp @@ -12957,3 +12957,60 @@ extern "C" void _weak_watchdog_update ( void ) #pragma comment(linker, "/alternatename:watchdog_update=_weak_watchdog_update") #endif // x86 or amd64 #endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void xosc_disable ( void ); +__attribute__((weak)) void xosc_disable ( void ) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_xosc_disable ( void ) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert( false && "Error : The hardware_xosc 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:_xosc_disable=__weak_xosc_disable") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:xosc_disable=_weak_xosc_disable") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void xosc_dormant ( void ); +__attribute__((weak)) void xosc_dormant ( void ) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_xosc_dormant ( void ) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert( false && "Error : The hardware_xosc 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:_xosc_dormant=__weak_xosc_dormant") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:xosc_dormant=_weak_xosc_dormant") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void xosc_init ( void ); +__attribute__((weak)) void xosc_init ( void ) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_xosc_init ( void ) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert( false && "Error : The hardware_xosc 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:_xosc_init=__weak_xosc_init") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:xosc_init=_weak_xosc_init") +#endif // x86 or amd64 +#endif // _MSC_VER diff --git a/src/sdk/pico_sdk_headers.h b/src/sdk/pico_sdk_headers.h index a5b75c0..9aa81c6 100644 --- a/src/sdk/pico_sdk_headers.h +++ b/src/sdk/pico_sdk_headers.h @@ -8,111 +8,113 @@ */ #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || - // __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || - // __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || __has_include() +#endif // __has_include() || __has_include() #if __has_include() || __has_include() #include -#endif // __has_include() || - // __has_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 0f22494..f9f84e0 100644 --- a/src/sdk/scripts/api_dirs.txt +++ b/src/sdk/scripts/api_dirs.txt @@ -25,3 +25,4 @@ hardware timer hardware uart hardware vreg hardware watchdog +hardware xosc diff --git a/src/sdk/sdkwrapper.cpp b/src/sdk/sdkwrapper.cpp index 476b0c9..e7a730b 100644 --- a/src/sdk/sdkwrapper.cpp +++ b/src/sdk/sdkwrapper.cpp @@ -4001,3 +4001,15 @@ extern "C" void watchdog_update(void); void rpp_driver::SdkWrapper::watchdog_update(void) { ::watchdog_update(); } #endif // __has_include() || // __has_include() + +#if __has_include() || __has_include() +// -------------------------------------------------- +extern "C" void xosc_disable(void); +void rpp_driver::SdkWrapper::xosc_disable(void) { ::xosc_disable(); } +// -------------------------------------------------- +extern "C" void xosc_dormant(void); +void rpp_driver::SdkWrapper::xosc_dormant(void) { ::xosc_dormant(); } +// -------------------------------------------------- +extern "C" void xosc_init(void); +void rpp_driver::SdkWrapper::xosc_init(void) { ::xosc_init(); } +#endif // __has_include() || __has_include() diff --git a/src/sdk/sdkwrapper.hpp b/src/sdk/sdkwrapper.hpp index 1cdea53..f0118c9 100644 --- a/src/sdk/sdkwrapper.hpp +++ b/src/sdk/sdkwrapper.hpp @@ -1037,6 +1037,12 @@ class SdkWrapper { #endif // __has_include() || // __has_include() +#if __has_include() || __has_include() + virtual void xosc_disable(void); + virtual void xosc_dormant(void); + virtual void xosc_init(void); +#endif // __has_include() || __has_include() + }; // class SdkWrapper #include "mocksdkwrapper.hpp" diff --git a/test/test_sdkwrapper.cpp b/test/test_sdkwrapper.cpp index ad84e85..c450408 100644 --- a/test/test_sdkwrapper.cpp +++ b/test/test_sdkwrapper.cpp @@ -87,6 +87,7 @@ FAKE_VALUE_FUNC(bool, time_reached, absolute_time_t); FAKE_VALUE_FUNC(char, uart_getc, uart_inst_t *); FAKE_VOID_FUNC(vreg_set_voltage, enum vreg_voltage); FAKE_VOID_FUNC(watchdog_start_tick, uint); +FAKE_VOID_FUNC(xosc_init); } // The cpp file of the library to test. #include "../src/sdk/sdkwrapper.cpp" @@ -2281,3 +2282,24 @@ TEST(SdkWrapper, watchdog_start_tick) { } RESET_FAKE(watchdog_start_tick); } // TEST(SdkWrapper, watchdog_start_tick) + +// ----------------------------------------------------------- +// +// hardware_xosc +// virtual void xosc_init(void); +// +// ----------------------------------------------------------- + +TEST(SdkWrapper, xosc_init) { + std::random_device rng; + ::rpp_driver::SdkWrapper pico; + + FFF_RESET_HISTORY(); + RESET_FAKE(xosc_init); + + pico.xosc_init(); + + // Check the data from test spy. Call order. + ASSERT_EQ(fff.call_history[0], (void *)xosc_init); + RESET_FAKE(xosc_init); +} // TEST(SdkWrapper, xosc_init) diff --git a/test/todo/test_sdkwrapper.md b/test/todo/test_sdkwrapper.md index 51a3dae..f9ec755 100644 --- a/test/todo/test_sdkwrapper.md +++ b/test/todo/test_sdkwrapper.md @@ -1,5 +1,11 @@ # test_SdkWrapper TDD +## SdkWrapper::xosc_init() +- [x] Implement member function . +- [x] Create test case to fail. +- [x] Make it success. +- [x] Remove the duplication. + ## SdkWrapper::watchdog_start_tick() - [x] Implement member function . - [x] Create test case to fail.