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_watchdog.
  • Loading branch information
suikan4github committed Dec 13, 2024
1 parent b2cccd6 commit c1fcd5f
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/sdk/mocksdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions src/sdk/pico_sdk_apistub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 32 additions & 30 deletions src/sdk/pico_sdk_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,111 +8,113 @@
*/
#if __has_include(<pico/time.h>) || __has_include(<gmock/gmock.h>)
#include <pico/time.h>
#endif // __has_include(<pico/time.h>) || __has_include(<gmock/gmock.h>)
#endif // __has_include(<pico/time.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<pico/stdio.h>) || __has_include(<gmock/gmock.h>)
#include <pico/stdio.h>
#endif // __has_include(<pico/stdio.h>) || __has_include(<gmock/gmock.h>)
#endif // __has_include(<pico/stdio.h>) || __has_include(<gmock/gmock.h>)

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

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

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

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

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

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

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

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

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

#if __has_include(<hardware/irq.h>) || __has_include(<gmock/gmock.h>)
#include <hardware/irq.h>
#endif // __has_include(<hardware/irq.h>) || __has_include(<gmock/gmock.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>)
#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>)
#endif // __has_include(<hardware/pio.h>) || __has_include(<gmock/gmock.h>)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1 change: 1 addition & 0 deletions src/sdk/scripts/api_dirs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ hardware timer
hardware uart
hardware vreg
hardware watchdog
hardware xosc
12 changes: 12 additions & 0 deletions src/sdk/sdkwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4001,3 +4001,15 @@ extern "C" void watchdog_update(void);
void rpp_driver::SdkWrapper::watchdog_update(void) { ::watchdog_update(); }
#endif // __has_include(<hardware/watchdog.h>) ||
// __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/xosc.h>) || __has_include(<gmock/gmock.h>)
// --------------------------------------------------
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(<hardware/xosc.h>) || __has_include(<gmock/gmock.h>)
6 changes: 6 additions & 0 deletions src/sdk/sdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,12 @@ class SdkWrapper {
#endif // __has_include(<hardware/watchdog.h>) ||
// __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/xosc.h>) || __has_include(<gmock/gmock.h>)
virtual void xosc_disable(void);
virtual void xosc_dormant(void);
virtual void xosc_init(void);
#endif // __has_include(<hardware/xosc.h>) || __has_include(<gmock/gmock.h>)

}; // class SdkWrapper

#include "mocksdkwrapper.hpp"
Expand Down
22 changes: 22 additions & 0 deletions test/test_sdkwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
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::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.
Expand Down

0 comments on commit c1fcd5f

Please sign in to comment.