Skip to content

Commit

Permalink
Issue #25 : Add wider API support of RasPi Pico SDK
Browse files Browse the repository at this point in the history
hardware_pll.
  • Loading branch information
suikan4github committed Nov 9, 2024
1 parent f4ceef3 commit f20550a
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sdk/mocksdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/pico_api_alternate_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions src/sdk/pico_sdk_apistub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/pico_sdk_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#include <hardware/irq.h>
#endif // __has_include(<hardware/irq.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)
#include <hardware/pll.h>
#endif // __has_include(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pio.h>) || __has_include(<gmock/gmock.h>)
#include <hardware/pio.h>
#endif // __has_include(<hardware/pio.h>) || __has_include(<gmock/gmock.h>)
Expand Down
1 change: 1 addition & 0 deletions src/sdk/scripts/api_dirs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ hardware flash
hardware i2c
hardware interp
hardware irq
hardware pll
hardware pio
hardware gpio
hardware clocks
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/scripts/blocks/pico_api_alternate_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/sdk/sdkwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,19 @@ void rpp_driver::SdkWrapper::user_irq_unclaim(uint irq_num) {
}
#endif // __has_include(<hardware/irq.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)
// --------------------------------------------------
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(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pio.h>) || __has_include(<gmock/gmock.h>)
// --------------------------------------------------
extern "C" int pio_add_program(PIO pio, const pio_program_t* program);
Expand Down
6 changes: 6 additions & 0 deletions src/sdk/sdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ class SdkWrapper {
virtual void user_irq_unclaim(uint irq_num);
#endif // __has_include(<hardware/irq.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)
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(<hardware/pll.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/pio.h>) || __has_include(<gmock/gmock.h>)
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,
Expand Down
40 changes: 40 additions & 0 deletions test/test_sdkwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<uint> 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 &&param0 : 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 &&param0 : 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)
6 changes: 6 additions & 0 deletions test/todo/test_sdkwrapper.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit f20550a

Please sign in to comment.