diff --git a/src/sdk/mocksdkwrapper.hpp b/src/sdk/mocksdkwrapper.hpp index 36a861a..59ab6c9 100644 --- a/src/sdk/mocksdkwrapper.hpp +++ b/src/sdk/mocksdkwrapper.hpp @@ -276,6 +276,9 @@ class MockSdkWrapper : public SdkWrapper { MOCK_METHOD1(user_irq_claim_unused, int(bool required)); MOCK_METHOD1(user_irq_is_claimed, bool(uint irq_num)); MOCK_METHOD1(user_irq_unclaim, void(uint irq_num)); + MOCK_METHOD1(pll_deinit, void(PLL pll)); + MOCK_METHOD5(pll_init, void(PLL pll, uint ref_div, uint vco_freq, + uint post_div1, uint post_div2)); MOCK_METHOD2(pio_add_program, int(PIO pio, const pio_program_t* program)); MOCK_METHOD3(pio_add_program_at_offset, int(PIO pio, const pio_program_t* program, uint offset)); diff --git a/src/sdk/pico_api_alternate_defs.hpp b/src/sdk/pico_api_alternate_defs.hpp index 10561ba..7e87550 100644 --- a/src/sdk/pico_api_alternate_defs.hpp +++ b/src/sdk/pico_api_alternate_defs.hpp @@ -33,6 +33,8 @@ enum dma_channel_transfer_size { k, l }; /// @brief Alternate definition for Google Test build. enum riscv_vector_num { m, n }; +//// @brief Alternate definition for Google Test build. +typedef int PLL; //// @brief Alternate definition for Google Test build. typedef int irq_handler_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 89d84dd..901058b 100644 --- a/src/sdk/pico_sdk_apistub.cpp +++ b/src/sdk/pico_sdk_apistub.cpp @@ -4636,6 +4636,49 @@ extern "C" void _weak_user_irq_unclaim(uint irq_num) #endif // _MSC_VER // -------------------------------------------------- #if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void pll_deinit(PLL pll); +__attribute__((weak)) void pll_deinit(PLL pll) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_pll_deinit(PLL pll) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_pll 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:_pll_deinit=__weak_pll_deinit") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:pll_deinit=_weak_pll_deinit") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void pll_init(PLL pll, uint ref_div, uint vco_freq, uint post_div1, + uint post_div2); +__attribute__((weak)) void pll_init(PLL pll, uint ref_div, uint vco_freq, + uint post_div1, uint post_div2) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_pll_init(PLL pll, uint ref_div, uint vco_freq, + uint post_div1, uint post_div2) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_pll 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:_pll_init=__weak_pll_init") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:pll_init=_weak_pll_init") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection extern "C" int pio_add_program(PIO pio, const pio_program_t* program); __attribute__((weak)) int pio_add_program(PIO pio, const pio_program_t* program) #elif defined(_MSC_VER) // Microsoft Visual C diff --git a/src/sdk/pico_sdk_headers.h b/src/sdk/pico_sdk_headers.h index 0ce44e3..395680f 100644 --- a/src/sdk/pico_sdk_headers.h +++ b/src/sdk/pico_sdk_headers.h @@ -40,6 +40,10 @@ #include #endif // __has_include() || __has_include() +#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 96afeb4..6c7e643 100644 --- a/src/sdk/scripts/api_dirs.txt +++ b/src/sdk/scripts/api_dirs.txt @@ -6,6 +6,7 @@ hardware flash hardware i2c hardware interp hardware irq +hardware pll hardware pio hardware gpio hardware clocks diff --git a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp index 10561ba..7e87550 100644 --- a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp +++ b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp @@ -33,6 +33,8 @@ enum dma_channel_transfer_size { k, l }; /// @brief Alternate definition for Google Test build. enum riscv_vector_num { m, n }; +//// @brief Alternate definition for Google Test build. +typedef int PLL; //// @brief Alternate definition for Google Test build. typedef int irq_handler_t; //// @brief Alternate definition for Google Test build. diff --git a/src/sdk/sdkwrapper.cpp b/src/sdk/sdkwrapper.cpp index 7f88381..40f071d 100644 --- a/src/sdk/sdkwrapper.cpp +++ b/src/sdk/sdkwrapper.cpp @@ -1136,6 +1136,19 @@ void rpp_driver::SdkWrapper::user_irq_unclaim(uint irq_num) { } #endif // __has_include() || __has_include() +#if __has_include() || __has_include() +// -------------------------------------------------- +extern "C" void pll_deinit(PLL pll); +void rpp_driver::SdkWrapper::pll_deinit(PLL pll) { ::pll_deinit(pll); } +// -------------------------------------------------- +extern "C" void pll_init(PLL pll, uint ref_div, uint vco_freq, uint post_div1, + uint post_div2); +void rpp_driver::SdkWrapper::pll_init(PLL pll, uint ref_div, uint vco_freq, + uint post_div1, uint post_div2) { + ::pll_init(pll, ref_div, vco_freq, post_div1, post_div2); +} +#endif // __has_include() || __has_include() + #if __has_include() || __has_include() // -------------------------------------------------- extern "C" int pio_add_program(PIO pio, const pio_program_t* program); diff --git a/src/sdk/sdkwrapper.hpp b/src/sdk/sdkwrapper.hpp index 9199596..c886446 100644 --- a/src/sdk/sdkwrapper.hpp +++ b/src/sdk/sdkwrapper.hpp @@ -349,6 +349,12 @@ class SdkWrapper { virtual void user_irq_unclaim(uint irq_num); #endif // __has_include() || __has_include() +#if __has_include() || __has_include() + virtual void pll_deinit(PLL pll); + virtual void pll_init(PLL pll, uint ref_div, uint vco_freq, uint post_div1, + uint post_div2); +#endif // __has_include() || __has_include() + #if __has_include() || __has_include() virtual int pio_add_program(PIO pio, const pio_program_t* program); virtual int pio_add_program_at_offset(PIO pio, const pio_program_t* program, diff --git a/test/test_sdkwrapper.cpp b/test/test_sdkwrapper.cpp index d05883a..c1b81b7 100644 --- a/test/test_sdkwrapper.cpp +++ b/test/test_sdkwrapper.cpp @@ -73,6 +73,7 @@ FAKE_VALUE_FUNC(uint, exception_get_priority, uint); FAKE_VOID_FUNC(flash_range_erase, uint32_t, size_t); FAKE_VALUE_FUNC(uint, interp_index, interp_hw_t *); FAKE_VALUE_FUNC(bool, irq_is_enabled, uint); +FAKE_VOID_FUNC(pll_deinit, PLL); } // The cpp file of the library to test. #include "../src/sdk/sdkwrapper.cpp" @@ -1711,3 +1712,42 @@ TEST(SdkWrapper, irq_is_enabled) { } RESET_FAKE(irq_is_enabled); } // TEST(SdkWrapper, irq_is_enabled) + +// ----------------------------------------------------------- +// +// hardware_pll +// virtual void pll_deinit(PLL pll); +// +// ----------------------------------------------------------- + +TEST(SdkWrapper, pll_deinit) { + std::random_device rng; + ::rpp_driver::SdkWrapper pico; + // uniform distribution + std::uniform_int_distribution param_dist(0, UINT_MAX); + uint param_array0[] = {param_dist(rng), param_dist(rng)}; + + FFF_RESET_HISTORY(); + RESET_FAKE(pll_deinit); + + // Check whether return values are correctly passed to wrapper. + int index = 0; + for (auto &¶m0 : param_array0) { + pico.pll_deinit(param0); + index++; + } + + // Check the data from test spy. How many time called? + ASSERT_EQ(pll_deinit_fake.call_count, std::size(param_array0)); + + // 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 *)pll_deinit); + // Check the data from test spy. : Parameters. + ASSERT_EQ(pll_deinit_fake.arg0_history[index], param0); + index++; + } + RESET_FAKE(pll_deinit); +} // TEST(SdkWrapper, pll_deinit) diff --git a/test/todo/test_sdkwrapper.md b/test/todo/test_sdkwrapper.md index f9b3ad5..6ceb8e9 100644 --- a/test/todo/test_sdkwrapper.md +++ b/test/todo/test_sdkwrapper.md @@ -1,5 +1,11 @@ # test_SdkWrapper TDD +## SdkWrapper::pll_deinit() +- [x] Implement member function . +- [x] Create test case to fail. +- [x] Make it success. +- [x] Remove the duplication. + ## SdkWrapper::irq_is_enabled() - [x] Implement member function . - [x] Create test case to fail.