diff --git a/src/sdk/mocksdkwrapper.hpp b/src/sdk/mocksdkwrapper.hpp index 1a859fb..4315582 100644 --- a/src/sdk/mocksdkwrapper.hpp +++ b/src/sdk/mocksdkwrapper.hpp @@ -156,6 +156,13 @@ class MockSdkWrapper : public SdkWrapper { exception_handler_t handler)); MOCK_METHOD2(exception_set_priority, bool(uint num, uint8_t hardware_priority)); + MOCK_METHOD3(flash_do_cmd, + void(const uint8_t* txbuf, uint8_t* rxbuf, size_t count)); + MOCK_METHOD0(flash_flush_cache, void()); + MOCK_METHOD1(flash_get_unique_id, void(uint8_t* id_out)); + MOCK_METHOD2(flash_range_erase, void(uint32_t flash_offs, size_t count)); + MOCK_METHOD3(flash_range_program, + void(uint32_t flash_offs, const uint8_t* data, size_t count)); MOCK_METHOD1(i2c_deinit, void(i2c_inst_t* i2c)); MOCK_METHOD2(i2c_get_dreq, uint(i2c_inst_t* i2c, bool is_tx)); MOCK_METHOD1(i2c_get_hw, i2c_hw_t*(i2c_inst_t* i2c)); diff --git a/src/sdk/pico_sdk_apistub.cpp b/src/sdk/pico_sdk_apistub.cpp index 3fd774f..d7b2912 100644 --- a/src/sdk/pico_sdk_apistub.cpp +++ b/src/sdk/pico_sdk_apistub.cpp @@ -2684,6 +2684,121 @@ extern "C" bool _weak_exception_set_priority(uint num, #endif // _MSC_VER // -------------------------------------------------- #if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, + size_t count); +__attribute__((weak)) void flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, + size_t count) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, + size_t count) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_flash 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:_flash_do_cmd=__weak_flash_do_cmd") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:flash_do_cmd=_weak_flash_do_cmd") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void flash_flush_cache(void); +__attribute__((weak)) void flash_flush_cache(void) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_flash_flush_cache(void) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_flash 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:_flash_flush_cache=__weak_flash_flush_cache") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:flash_flush_cache=_weak_flash_flush_cache") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void flash_get_unique_id(uint8_t* id_out); +__attribute__((weak)) void flash_get_unique_id(uint8_t* id_out) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_flash_get_unique_id(uint8_t* id_out) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_flash 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:_flash_get_unique_id=__weak_flash_get_unique_id") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, "/alternatename:flash_get_unique_id=_weak_flash_get_unique_id") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void flash_range_erase(uint32_t flash_offs, size_t count); +__attribute__((weak)) void flash_range_erase(uint32_t flash_offs, size_t count) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_flash_range_erase(uint32_t flash_offs, size_t count) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_flash 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:_flash_range_erase=__weak_flash_range_erase") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:flash_range_erase=_weak_flash_range_erase") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void flash_range_program(uint32_t flash_offs, const uint8_t* data, + size_t count); +__attribute__((weak)) void flash_range_program(uint32_t flash_offs, + const uint8_t* data, + size_t count) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_flash_range_program(uint32_t flash_offs, + const uint8_t* data, size_t count) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_flash 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:_flash_range_program=__weak_flash_range_program") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, "/alternatename:flash_range_program=_weak_flash_range_program") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection extern "C" void i2c_deinit(i2c_inst_t* i2c); __attribute__((weak)) void i2c_deinit(i2c_inst_t* i2c) #elif defined(_MSC_VER) // Microsoft Visual C diff --git a/src/sdk/pico_sdk_headers.h b/src/sdk/pico_sdk_headers.h index f5d0d7a..aee1b6f 100644 --- a/src/sdk/pico_sdk_headers.h +++ b/src/sdk/pico_sdk_headers.h @@ -24,6 +24,10 @@ #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 fd33dc9..23388c6 100644 --- a/src/sdk/scripts/api_dirs.txt +++ b/src/sdk/scripts/api_dirs.txt @@ -2,6 +2,7 @@ hardware adc hardware divider hardware dma hardware exception +hardware flash hardware i2c hardware pio hardware gpio diff --git a/src/sdk/sdkwrapper.cpp b/src/sdk/sdkwrapper.cpp index 13b1f18..b8950ee 100644 --- a/src/sdk/sdkwrapper.cpp +++ b/src/sdk/sdkwrapper.cpp @@ -633,6 +633,38 @@ bool rpp_driver::SdkWrapper::exception_set_priority(uint num, #endif // __has_include() || // __has_include() +#if __has_include() || __has_include() +// -------------------------------------------------- +extern "C" void flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, + size_t count); +void rpp_driver::SdkWrapper::flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, + size_t count) { + ::flash_do_cmd(txbuf, rxbuf, count); +} +// -------------------------------------------------- +extern "C" void flash_flush_cache(void); +void rpp_driver::SdkWrapper::flash_flush_cache(void) { ::flash_flush_cache(); } +// -------------------------------------------------- +extern "C" void flash_get_unique_id(uint8_t* id_out); +void rpp_driver::SdkWrapper::flash_get_unique_id(uint8_t* id_out) { + ::flash_get_unique_id(id_out); +} +// -------------------------------------------------- +extern "C" void flash_range_erase(uint32_t flash_offs, size_t count); +void rpp_driver::SdkWrapper::flash_range_erase(uint32_t flash_offs, + size_t count) { + ::flash_range_erase(flash_offs, count); +} +// -------------------------------------------------- +extern "C" void flash_range_program(uint32_t flash_offs, const uint8_t* data, + size_t count); +void rpp_driver::SdkWrapper::flash_range_program(uint32_t flash_offs, + const uint8_t* data, + size_t count) { + ::flash_range_program(flash_offs, data, count); +} +#endif // __has_include() || __has_include() + #if __has_include() || __has_include() // -------------------------------------------------- extern "C" void i2c_deinit(i2c_inst_t* i2c); diff --git a/src/sdk/sdkwrapper.hpp b/src/sdk/sdkwrapper.hpp index d78c7e7..7e66d54 100644 --- a/src/sdk/sdkwrapper.hpp +++ b/src/sdk/sdkwrapper.hpp @@ -232,6 +232,15 @@ virtual void adc_fifo_drain ( void ); #endif // __has_include() || // __has_include() +#if __has_include() || __has_include() + virtual void flash_do_cmd(const uint8_t* txbuf, uint8_t* rxbuf, size_t count); + virtual void flash_flush_cache(void); + virtual void flash_get_unique_id(uint8_t* id_out); + virtual void flash_range_erase(uint32_t flash_offs, size_t count); + virtual void flash_range_program(uint32_t flash_offs, const uint8_t* data, + size_t count); +#endif // __has_include() || __has_include() + #if __has_include() || __has_include() virtual void i2c_deinit(i2c_inst_t* i2c); virtual uint i2c_get_dreq(i2c_inst_t* i2c, bool is_tx); diff --git a/test/test_sdkwrapper.cpp b/test/test_sdkwrapper.cpp index 3b1434c..df9dfc1 100644 --- a/test/test_sdkwrapper.cpp +++ b/test/test_sdkwrapper.cpp @@ -70,6 +70,7 @@ FAKE_VALUE_FUNC(uint16_t, adc_read); FAKE_VALUE_FUNC(int32_t, hw_divider_quotient_s32, int32_t, int32_t); FAKE_VALUE_FUNC(dma_channel_config, dma_channel_get_default_config, uint); FAKE_VALUE_FUNC(uint, exception_get_priority, uint); +FAKE_VOID_FUNC(flash_range_erase, uint32_t, size_t); } // The cpp file of the library to test. #include "../src/sdk/sdkwrapper.cpp" @@ -1577,43 +1578,46 @@ TEST(SdkWrapper, dma_channel_get_default_config) { } RESET_FAKE(dma_channel_get_default_config); } // TEST(SdkWrapper, dma_channel_get_default_config) + // ----------------------------------------------------------- // -// hardware_exception +// hardware_flash +// virtual void flash_range_erase(uint32_t flash_offs, size_t count); // // ----------------------------------------------------------- -TEST(SdkWrapper, exception_get_priority) { +TEST(SdkWrapper, flash_range_erase) { std::random_device rng; ::rpp_driver::SdkWrapper pico; // uniform distribution - std::uniform_int_distribution dist(0, UINT_MAX); - uint param_array0[] = {dist(rng), dist(rng)}; - uint retval_array[std::size(param_array0)] = {dist(rng), dist(rng)}; + std::uniform_int_distribution dist0(0, UINT32_MAX); + std::uniform_int_distribution dist1(0, SIZE_MAX); + uint32_t param_array0[] = {dist0(rng), dist0(rng)}; + size_t param_array1[] = {dist1(rng), dist1(rng)}; FFF_RESET_HISTORY(); - RESET_FAKE(exception_get_priority); - - SET_RETURN_SEQ(exception_get_priority, retval_array, std::size(retval_array)); + RESET_FAKE(flash_range_erase); - // Check whether return values are correctly passed to wrapper. - int index = 0; for (auto &¶m0 : param_array0) { - ASSERT_EQ(pico.exception_get_priority(param0), retval_array[index]); - index++; + for (auto &¶m1 : param_array1) { + pico.flash_range_erase(param0, param1); + } } - // Check the data from test spy. How many time called? - ASSERT_EQ(exception_get_priority_fake.call_count, std::size(retval_array)); + ASSERT_EQ(flash_range_erase_fake.call_count, + std::size(param_array0) * std::size(param_array1)); // Check whether parameters were correctly passed from wrapper. - index = 0; + int index = 0; for (auto &¶m0 : param_array0) { - // Check the data from test spy. Call order. - ASSERT_EQ(fff.call_history[index], (void *)exception_get_priority); - // Check the data from test spy. : Parameters. - ASSERT_EQ(exception_get_priority_fake.arg0_history[index], param0); - index++; + for (auto &¶m1 : param_array1) { + // Check the data from test spy. Call order. + ASSERT_EQ(fff.call_history[index], (void *)flash_range_erase); + // Check the data from test spy. : Parameters. + ASSERT_EQ(flash_range_erase_fake.arg0_history[index], param0); + ASSERT_EQ(flash_range_erase_fake.arg1_history[index], param1); + index++; + } } - RESET_FAKE(exception_get_priority); -} // TEST(SdkWrapper, exception_get_priority) + RESET_FAKE(flash_range_erase); +} // TEST(SdkWrapper, flash_range_erase) diff --git a/test/todo/test_sdkwrapper.md b/test/todo/test_sdkwrapper.md index 69fbc96..8a37ff8 100644 --- a/test/todo/test_sdkwrapper.md +++ b/test/todo/test_sdkwrapper.md @@ -1,5 +1,13 @@ # test_SdkWrapper TDD + +## SdkWrapper::flash_range_erase() +- [x] Implement member function . +- [x] Create test case to fail. +- [x] Make it success. +- [x] Remove the duplication. + + ## SdkWrapper::dma_channel_get_default_config() - [x] Implement member function . - [x] Create test case to fail.