diff --git a/src/sdk/mocksdkwrapper.hpp b/src/sdk/mocksdkwrapper.hpp index 57de7a6..d060d5f 100644 --- a/src/sdk/mocksdkwrapper.hpp +++ b/src/sdk/mocksdkwrapper.hpp @@ -914,6 +914,41 @@ class MockSdkWrapper : public SdkWrapper { MOCK_METHOD2(timer_time_reached, bool(timer_hw_t* timer, absolute_time_t t)); MOCK_METHOD1(timer_time_us_32, uint32_t(timer_hw_t* timer)); MOCK_METHOD1(timer_time_us_64, uint64_t(timer_hw_t* timer)); + MOCK_METHOD0(uart_default_tx_wait_blocking, void()); + MOCK_METHOD1(uart_deinit, void(uart_inst_t* uart)); + MOCK_METHOD2(uart_get_dreq, uint(uart_inst_t* uart, bool is_tx)); + MOCK_METHOD2(uart_get_dreq_num, uint(uart_inst_t* uart, bool is_tx)); + MOCK_METHOD1(uart_get_hw, uart_hw_t*(uart_inst_t* uart)); + MOCK_METHOD1(uart_get_index, uint(uart_inst_t* uart)); + MOCK_METHOD1(uart_get_instance, uart_inst_t*(uint num)); + MOCK_METHOD1(uart_get_reset_num, uint(uart_inst_t* uart)); + MOCK_METHOD1(uart_getc, char(uart_inst_t* uart)); + MOCK_METHOD2(uart_init, uint(uart_inst_t* uart, uint baudrate)); + MOCK_METHOD1(uart_is_enabled, bool(uart_inst_t* uart)); + MOCK_METHOD1(uart_is_readable, bool(uart_inst_t* uart)); + MOCK_METHOD2(uart_is_readable_within_us, + bool(uart_inst_t* uart, uint32_t us)); + MOCK_METHOD1(uart_is_writable, bool(uart_inst_t* uart)); + MOCK_METHOD2(uart_putc, void(uart_inst_t* uart, char c)); + MOCK_METHOD2(uart_putc_raw, void(uart_inst_t* uart, char c)); + MOCK_METHOD2(uart_puts, void(uart_inst_t* uart, const char* s)); + MOCK_METHOD3(uart_read_blocking, + void(uart_inst_t* uart, uint8_t* dst, size_t len)); + MOCK_METHOD2(uart_set_baudrate, uint(uart_inst_t* uart, uint baudrate)); + MOCK_METHOD2(uart_set_break, void(uart_inst_t* uart, bool en)); + MOCK_METHOD2(uart_set_fifo_enabled, void(uart_inst_t* uart, bool enabled)); + MOCK_METHOD4(uart_set_format, void(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity)); + MOCK_METHOD3(uart_set_hw_flow, void(uart_inst_t* uart, bool cts, bool rts)); + MOCK_METHOD3(uart_set_irq_enables, + void(uart_inst_t* uart, bool rx_has_data, bool tx_needs_data)); + MOCK_METHOD3(uart_set_irqs_enabled, + void(uart_inst_t* uart, bool rx_has_data, bool tx_needs_data)); + MOCK_METHOD2(uart_set_translate_crlf, + void(uart_inst_t* uart, bool translate)); + MOCK_METHOD1(uart_tx_wait_blocking, void(uart_inst_t* uart)); + MOCK_METHOD3(uart_write_blocking, + void(uart_inst_t* uart, const uint8_t* src, size_t len)); } // class MockSdkWrapper : public SdkWrapper ; // GCOVR_EXCL_STOP diff --git a/src/sdk/pico_api_alternate_defs.hpp b/src/sdk/pico_api_alternate_defs.hpp index e9ffb7c..cd32d57 100644 --- a/src/sdk/pico_api_alternate_defs.hpp +++ b/src/sdk/pico_api_alternate_defs.hpp @@ -39,6 +39,12 @@ enum pwm_clkdiv_mode { q, r }; /// @brief Alternate definition for Google Test build. enum sha256_endianness { s, t }; +//// @brief Alternate definition for Google Test build. +typedef int uart_parity_t; +//// @brief Alternate definition for Google Test build. +typedef int uart_inst_t; +//// @brief Alternate definition for Google Test build. +typedef int uart_hw_t; //// @brief Alternate definition for Google Test build. typedef int absolute_time_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 18835bd..75ab037 100644 --- a/src/sdk/pico_sdk_apistub.cpp +++ b/src/sdk/pico_sdk_apistub.cpp @@ -15293,3 +15293,630 @@ extern "C" uint64_t _weak_timer_time_us_64(timer_hw_t* timer) "/alternatename:timer_time_us_64=_weak_timer_time_us_64") #endif // x86 or amd64 #endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_default_tx_wait_blocking(void); +__attribute__((weak)) void uart_default_tx_wait_blocking(void) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_default_tx_wait_blocking(void) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_default_tx_wait_blocking=__weak_uart_default_tx_wait_blocking") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_default_tx_wait_blocking=_weak_uart_default_tx_wait_blocking") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_deinit(uart_inst_t* uart); +__attribute__((weak)) void uart_deinit(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_deinit(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_deinit=__weak_uart_deinit") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_deinit=_weak_uart_deinit") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_get_dreq(uart_inst_t* uart, bool is_tx); +__attribute__((weak)) uint uart_get_dreq(uart_inst_t* uart, bool is_tx) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_get_dreq(uart_inst_t* uart, bool is_tx) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_dreq=__weak_uart_get_dreq") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_get_dreq=_weak_uart_get_dreq") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_get_dreq_num(uart_inst_t* uart, bool is_tx); +__attribute__((weak)) uint uart_get_dreq_num(uart_inst_t* uart, bool is_tx) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_get_dreq_num(uart_inst_t* uart, bool is_tx) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_dreq_num=__weak_uart_get_dreq_num") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_get_dreq_num=_weak_uart_get_dreq_num") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uart_hw_t* uart_get_hw(uart_inst_t* uart); +__attribute__((weak)) uart_hw_t* uart_get_hw(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uart_hw_t* _weak_uart_get_hw(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_hw=__weak_uart_get_hw") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_get_hw=_weak_uart_get_hw") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_get_index(uart_inst_t* uart); +__attribute__((weak)) uint uart_get_index(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_get_index(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_index=__weak_uart_get_index") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_get_index=_weak_uart_get_index") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uart_inst_t* uart_get_instance(uint num); +__attribute__((weak)) uart_inst_t* uart_get_instance(uint num) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uart_inst_t* _weak_uart_get_instance(uint num) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_instance=__weak_uart_get_instance") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_get_instance=_weak_uart_get_instance") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_get_reset_num(uart_inst_t* uart); +__attribute__((weak)) uint uart_get_reset_num(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_get_reset_num(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_get_reset_num=__weak_uart_get_reset_num") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_get_reset_num=_weak_uart_get_reset_num") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" char uart_getc(uart_inst_t* uart); +__attribute__((weak)) char uart_getc(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" char _weak_uart_getc(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_getc=__weak_uart_getc") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_getc=_weak_uart_getc") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_init(uart_inst_t* uart, uint baudrate); +__attribute__((weak)) uint uart_init(uart_inst_t* uart, uint baudrate) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_init(uart_inst_t* uart, uint baudrate) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_init=__weak_uart_init") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_init=_weak_uart_init") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool uart_is_enabled(uart_inst_t* uart); +__attribute__((weak)) bool uart_is_enabled(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_uart_is_enabled(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_is_enabled=__weak_uart_is_enabled") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_is_enabled=_weak_uart_is_enabled") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool uart_is_readable(uart_inst_t* uart); +__attribute__((weak)) bool uart_is_readable(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_uart_is_readable(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_is_readable=__weak_uart_is_readable") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_is_readable=_weak_uart_is_readable") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool uart_is_readable_within_us(uart_inst_t* uart, uint32_t us); +__attribute__((weak)) bool uart_is_readable_within_us(uart_inst_t* uart, + uint32_t us) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_uart_is_readable_within_us(uart_inst_t* uart, uint32_t us) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_is_readable_within_us=__weak_uart_is_readable_within_us") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_is_readable_within_us=_weak_uart_is_readable_within_us") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" bool uart_is_writable(uart_inst_t* uart); +__attribute__((weak)) bool uart_is_writable(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" bool _weak_uart_is_writable(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_is_writable=__weak_uart_is_writable") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_is_writable=_weak_uart_is_writable") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_putc(uart_inst_t* uart, char c); +__attribute__((weak)) void uart_putc(uart_inst_t* uart, char c) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_putc(uart_inst_t* uart, char c) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_putc=__weak_uart_putc") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_putc=_weak_uart_putc") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_putc_raw(uart_inst_t* uart, char c); +__attribute__((weak)) void uart_putc_raw(uart_inst_t* uart, char c) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_putc_raw(uart_inst_t* uart, char c) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_putc_raw=__weak_uart_putc_raw") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_putc_raw=_weak_uart_putc_raw") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_puts(uart_inst_t* uart, const char* s); +__attribute__((weak)) void uart_puts(uart_inst_t* uart, const char* s) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_puts(uart_inst_t* uart, const char* s) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_puts=__weak_uart_puts") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_puts=_weak_uart_puts") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_read_blocking(uart_inst_t* uart, uint8_t* dst, size_t len); +__attribute__((weak)) void uart_read_blocking(uart_inst_t* uart, uint8_t* dst, + size_t len) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_read_blocking(uart_inst_t* uart, uint8_t* dst, + size_t len) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_read_blocking=__weak_uart_read_blocking") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_read_blocking=_weak_uart_read_blocking") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" uint uart_set_baudrate(uart_inst_t* uart, uint baudrate); +__attribute__((weak)) uint uart_set_baudrate(uart_inst_t* uart, uint baudrate) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" uint _weak_uart_set_baudrate(uart_inst_t* uart, uint baudrate) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_baudrate=__weak_uart_set_baudrate") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_set_baudrate=_weak_uart_set_baudrate") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_break(uart_inst_t* uart, bool en); +__attribute__((weak)) void uart_set_break(uart_inst_t* uart, bool en) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_break(uart_inst_t* uart, bool en) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_break=__weak_uart_set_break") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_set_break=_weak_uart_set_break") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_fifo_enabled(uart_inst_t* uart, bool enabled); +__attribute__((weak)) void uart_set_fifo_enabled(uart_inst_t* uart, + bool enabled) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_fifo_enabled(uart_inst_t* uart, bool enabled) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_fifo_enabled=__weak_uart_set_fifo_enabled") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_set_fifo_enabled=_weak_uart_set_fifo_enabled") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity); +__attribute__((weak)) void uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_format=__weak_uart_set_format") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, "/alternatename:uart_set_format=_weak_uart_set_format") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_hw_flow(uart_inst_t* uart, bool cts, bool rts); +__attribute__((weak)) void uart_set_hw_flow(uart_inst_t* uart, bool cts, + bool rts) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_hw_flow(uart_inst_t* uart, bool cts, bool rts) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_hw_flow=__weak_uart_set_hw_flow") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment(linker, \ + "/alternatename:uart_set_hw_flow=_weak_uart_set_hw_flow") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_irq_enables(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); +__attribute__((weak)) void uart_set_irq_enables(uart_inst_t* uart, + bool rx_has_data, + bool tx_needs_data) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_irq_enables(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_irq_enables=__weak_uart_set_irq_enables") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, "/alternatename:uart_set_irq_enables=_weak_uart_set_irq_enables") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_irqs_enabled(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); +__attribute__((weak)) void uart_set_irqs_enabled(uart_inst_t* uart, + bool rx_has_data, + bool tx_needs_data) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_irqs_enabled(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_irqs_enabled=__weak_uart_set_irqs_enabled") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_set_irqs_enabled=_weak_uart_set_irqs_enabled") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_set_translate_crlf(uart_inst_t* uart, bool translate); +__attribute__((weak)) void uart_set_translate_crlf(uart_inst_t* uart, + bool translate) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_set_translate_crlf(uart_inst_t* uart, bool translate) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_set_translate_crlf=__weak_uart_set_translate_crlf") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_set_translate_crlf=_weak_uart_set_translate_crlf") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_tx_wait_blocking(uart_inst_t* uart); +__attribute__((weak)) void uart_tx_wait_blocking(uart_inst_t* uart) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_tx_wait_blocking(uart_inst_t* uart) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_tx_wait_blocking=__weak_uart_tx_wait_blocking") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, \ + "/alternatename:uart_tx_wait_blocking=_weak_uart_tx_wait_blocking") +#endif // x86 or amd64 +#endif // _MSC_VER +// -------------------------------------------------- +#if defined(__GNUC__) || defined(__clang__) // Compiler detection +extern "C" void uart_write_blocking(uart_inst_t* uart, const uint8_t* src, + size_t len); +__attribute__((weak)) void uart_write_blocking(uart_inst_t* uart, + const uint8_t* src, size_t len) +#elif defined(_MSC_VER) // Microsoft Visual C +extern "C" void _weak_uart_write_blocking(uart_inst_t* uart, const uint8_t* src, + size_t len) +#else // Other compilers are not supported +#error "Unknown compiler." +#endif // Compiler detection +{ + assert(false && + "Error : The hardware_uart 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:_uart_write_blocking=__weak_uart_write_blocking") +#elif defined(_M_AMD64) // for AMD64 +#pragma comment( \ + linker, "/alternatename:uart_write_blocking=_weak_uart_write_blocking") +#endif // x86 or amd64 +#endif // _MSC_VER diff --git a/src/sdk/pico_sdk_headers.h b/src/sdk/pico_sdk_headers.h index 04d6f60..8d1db15 100644 --- a/src/sdk/pico_sdk_headers.h +++ b/src/sdk/pico_sdk_headers.h @@ -103,3 +103,7 @@ #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 20d40e8..dda8ff7 100644 --- a/src/sdk/scripts/api_dirs.txt +++ b/src/sdk/scripts/api_dirs.txt @@ -22,3 +22,4 @@ hardware spi hardware sync hardware ticks hardware timer +hardware uart diff --git a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp index e9ffb7c..cd32d57 100644 --- a/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp +++ b/src/sdk/scripts/blocks/pico_api_alternate_defs.hpp @@ -39,6 +39,12 @@ enum pwm_clkdiv_mode { q, r }; /// @brief Alternate definition for Google Test build. enum sha256_endianness { s, t }; +//// @brief Alternate definition for Google Test build. +typedef int uart_parity_t; +//// @brief Alternate definition for Google Test build. +typedef int uart_inst_t; +//// @brief Alternate definition for Google Test build. +typedef int uart_hw_t; //// @brief Alternate definition for Google Test build. typedef int absolute_time_t; //// @brief Alternate definition for Google Test build. diff --git a/src/sdk/sdkwrapper.cpp b/src/sdk/sdkwrapper.cpp index bf6b578..253af52 100644 --- a/src/sdk/sdkwrapper.cpp +++ b/src/sdk/sdkwrapper.cpp @@ -3780,3 +3780,164 @@ uint64_t rpp_driver::SdkWrapper::timer_time_us_64(timer_hw_t* timer) { return ::timer_time_us_64(timer); } #endif // __has_include() || __has_include() + +#if __has_include() || __has_include() +// -------------------------------------------------- +extern "C" void uart_default_tx_wait_blocking(void); +void rpp_driver::SdkWrapper::uart_default_tx_wait_blocking(void) { + ::uart_default_tx_wait_blocking(); +} +// -------------------------------------------------- +extern "C" void uart_deinit(uart_inst_t* uart); +void rpp_driver::SdkWrapper::uart_deinit(uart_inst_t* uart) { + ::uart_deinit(uart); +} +// -------------------------------------------------- +extern "C" uint uart_get_dreq(uart_inst_t* uart, bool is_tx); +uint rpp_driver::SdkWrapper::uart_get_dreq(uart_inst_t* uart, bool is_tx) { + return ::uart_get_dreq(uart, is_tx); +} +// -------------------------------------------------- +extern "C" uint uart_get_dreq_num(uart_inst_t* uart, bool is_tx); +uint rpp_driver::SdkWrapper::uart_get_dreq_num(uart_inst_t* uart, bool is_tx) { + return ::uart_get_dreq_num(uart, is_tx); +} +// -------------------------------------------------- +extern "C" uart_hw_t* uart_get_hw(uart_inst_t* uart); +uart_hw_t* rpp_driver::SdkWrapper::uart_get_hw(uart_inst_t* uart) { + return ::uart_get_hw(uart); +} +// -------------------------------------------------- +extern "C" uint uart_get_index(uart_inst_t* uart); +uint rpp_driver::SdkWrapper::uart_get_index(uart_inst_t* uart) { + return ::uart_get_index(uart); +} +// -------------------------------------------------- +extern "C" uart_inst_t* uart_get_instance(uint num); +uart_inst_t* rpp_driver::SdkWrapper::uart_get_instance(uint num) { + return ::uart_get_instance(num); +} +// -------------------------------------------------- +extern "C" uint uart_get_reset_num(uart_inst_t* uart); +uint rpp_driver::SdkWrapper::uart_get_reset_num(uart_inst_t* uart) { + return ::uart_get_reset_num(uart); +} +// -------------------------------------------------- +extern "C" char uart_getc(uart_inst_t* uart); +char rpp_driver::SdkWrapper::uart_getc(uart_inst_t* uart) { + return ::uart_getc(uart); +} +// -------------------------------------------------- +extern "C" uint uart_init(uart_inst_t* uart, uint baudrate); +uint rpp_driver::SdkWrapper::uart_init(uart_inst_t* uart, uint baudrate) { + return ::uart_init(uart, baudrate); +} +// -------------------------------------------------- +extern "C" bool uart_is_enabled(uart_inst_t* uart); +bool rpp_driver::SdkWrapper::uart_is_enabled(uart_inst_t* uart) { + return ::uart_is_enabled(uart); +} +// -------------------------------------------------- +extern "C" bool uart_is_readable(uart_inst_t* uart); +bool rpp_driver::SdkWrapper::uart_is_readable(uart_inst_t* uart) { + return ::uart_is_readable(uart); +} +// -------------------------------------------------- +extern "C" bool uart_is_readable_within_us(uart_inst_t* uart, uint32_t us); +bool rpp_driver::SdkWrapper::uart_is_readable_within_us(uart_inst_t* uart, + uint32_t us) { + return ::uart_is_readable_within_us(uart, us); +} +// -------------------------------------------------- +extern "C" bool uart_is_writable(uart_inst_t* uart); +bool rpp_driver::SdkWrapper::uart_is_writable(uart_inst_t* uart) { + return ::uart_is_writable(uart); +} +// -------------------------------------------------- +extern "C" void uart_putc(uart_inst_t* uart, char c); +void rpp_driver::SdkWrapper::uart_putc(uart_inst_t* uart, char c) { + ::uart_putc(uart, c); +} +// -------------------------------------------------- +extern "C" void uart_putc_raw(uart_inst_t* uart, char c); +void rpp_driver::SdkWrapper::uart_putc_raw(uart_inst_t* uart, char c) { + ::uart_putc_raw(uart, c); +} +// -------------------------------------------------- +extern "C" void uart_puts(uart_inst_t* uart, const char* s); +void rpp_driver::SdkWrapper::uart_puts(uart_inst_t* uart, const char* s) { + ::uart_puts(uart, s); +} +// -------------------------------------------------- +extern "C" void uart_read_blocking(uart_inst_t* uart, uint8_t* dst, size_t len); +void rpp_driver::SdkWrapper::uart_read_blocking(uart_inst_t* uart, uint8_t* dst, + size_t len) { + ::uart_read_blocking(uart, dst, len); +} +// -------------------------------------------------- +extern "C" uint uart_set_baudrate(uart_inst_t* uart, uint baudrate); +uint rpp_driver::SdkWrapper::uart_set_baudrate(uart_inst_t* uart, + uint baudrate) { + return ::uart_set_baudrate(uart, baudrate); +} +// -------------------------------------------------- +extern "C" void uart_set_break(uart_inst_t* uart, bool en); +void rpp_driver::SdkWrapper::uart_set_break(uart_inst_t* uart, bool en) { + ::uart_set_break(uart, en); +} +// -------------------------------------------------- +extern "C" void uart_set_fifo_enabled(uart_inst_t* uart, bool enabled); +void rpp_driver::SdkWrapper::uart_set_fifo_enabled(uart_inst_t* uart, + bool enabled) { + ::uart_set_fifo_enabled(uart, enabled); +} +// -------------------------------------------------- +extern "C" void uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity); +void rpp_driver::SdkWrapper::uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, + uart_parity_t parity) { + ::uart_set_format(uart, data_bits, stop_bits, parity); +} +// -------------------------------------------------- +extern "C" void uart_set_hw_flow(uart_inst_t* uart, bool cts, bool rts); +void rpp_driver::SdkWrapper::uart_set_hw_flow(uart_inst_t* uart, bool cts, + bool rts) { + ::uart_set_hw_flow(uart, cts, rts); +} +// -------------------------------------------------- +extern "C" void uart_set_irq_enables(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); +void rpp_driver::SdkWrapper::uart_set_irq_enables(uart_inst_t* uart, + bool rx_has_data, + bool tx_needs_data) { + ::uart_set_irq_enables(uart, rx_has_data, tx_needs_data); +} +// -------------------------------------------------- +extern "C" void uart_set_irqs_enabled(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); +void rpp_driver::SdkWrapper::uart_set_irqs_enabled(uart_inst_t* uart, + bool rx_has_data, + bool tx_needs_data) { + ::uart_set_irqs_enabled(uart, rx_has_data, tx_needs_data); +} +// -------------------------------------------------- +extern "C" void uart_set_translate_crlf(uart_inst_t* uart, bool translate); +void rpp_driver::SdkWrapper::uart_set_translate_crlf(uart_inst_t* uart, + bool translate) { + ::uart_set_translate_crlf(uart, translate); +} +// -------------------------------------------------- +extern "C" void uart_tx_wait_blocking(uart_inst_t* uart); +void rpp_driver::SdkWrapper::uart_tx_wait_blocking(uart_inst_t* uart) { + ::uart_tx_wait_blocking(uart); +} +// -------------------------------------------------- +extern "C" void uart_write_blocking(uart_inst_t* uart, const uint8_t* src, + size_t len); +void rpp_driver::SdkWrapper::uart_write_blocking(uart_inst_t* uart, + const uint8_t* src, + size_t len) { + ::uart_write_blocking(uart, src, len); +} +#endif // __has_include() || __has_include() diff --git a/src/sdk/sdkwrapper.hpp b/src/sdk/sdkwrapper.hpp index 4fec589..cdd3b30 100644 --- a/src/sdk/sdkwrapper.hpp +++ b/src/sdk/sdkwrapper.hpp @@ -984,6 +984,41 @@ class SdkWrapper { virtual uint64_t timer_time_us_64(timer_hw_t* timer); #endif // __has_include() || __has_include() +#if __has_include() || __has_include() + virtual void uart_default_tx_wait_blocking(void); + virtual void uart_deinit(uart_inst_t* uart); + virtual uint uart_get_dreq(uart_inst_t* uart, bool is_tx); + virtual uint uart_get_dreq_num(uart_inst_t* uart, bool is_tx); + virtual uart_hw_t* uart_get_hw(uart_inst_t* uart); + virtual uint uart_get_index(uart_inst_t* uart); + virtual uart_inst_t* uart_get_instance(uint num); + virtual uint uart_get_reset_num(uart_inst_t* uart); + virtual char uart_getc(uart_inst_t* uart); + virtual uint uart_init(uart_inst_t* uart, uint baudrate); + virtual bool uart_is_enabled(uart_inst_t* uart); + virtual bool uart_is_readable(uart_inst_t* uart); + virtual bool uart_is_readable_within_us(uart_inst_t* uart, uint32_t us); + virtual bool uart_is_writable(uart_inst_t* uart); + virtual void uart_putc(uart_inst_t* uart, char c); + virtual void uart_putc_raw(uart_inst_t* uart, char c); + virtual void uart_puts(uart_inst_t* uart, const char* s); + virtual void uart_read_blocking(uart_inst_t* uart, uint8_t* dst, size_t len); + virtual uint uart_set_baudrate(uart_inst_t* uart, uint baudrate); + virtual void uart_set_break(uart_inst_t* uart, bool en); + virtual void uart_set_fifo_enabled(uart_inst_t* uart, bool enabled); + virtual void uart_set_format(uart_inst_t* uart, uint data_bits, + uint stop_bits, uart_parity_t parity); + virtual void uart_set_hw_flow(uart_inst_t* uart, bool cts, bool rts); + virtual void uart_set_irq_enables(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); + virtual void uart_set_irqs_enabled(uart_inst_t* uart, bool rx_has_data, + bool tx_needs_data); + virtual void uart_set_translate_crlf(uart_inst_t* uart, bool translate); + virtual void uart_tx_wait_blocking(uart_inst_t* uart); + virtual void uart_write_blocking(uart_inst_t* uart, const uint8_t* src, + size_t len); +#endif // __has_include() || __has_include() + }; // class SdkWrapper #include "mocksdkwrapper.hpp" diff --git a/test/test_sdkwrapper.cpp b/test/test_sdkwrapper.cpp index a629b71..2c57192 100644 --- a/test/test_sdkwrapper.cpp +++ b/test/test_sdkwrapper.cpp @@ -84,6 +84,7 @@ FAKE_VALUE_FUNC(bool, spi_is_readable, const spi_inst_t *); FAKE_VALUE_FUNC(bool, spin_lock_is_claimed, uint); FAKE_VALUE_FUNC(bool, tick_is_running, tick_gen_num_t); FAKE_VALUE_FUNC(bool, time_reached, absolute_time_t); +FAKE_VALUE_FUNC(char, uart_getc, uart_inst_t *); } // The cpp file of the library to test. #include "../src/sdk/sdkwrapper.cpp" @@ -2157,4 +2158,47 @@ TEST(SdkWrapper, time_reached) { index++; } RESET_FAKE(time_reached); -} // TEST(SdkWrapper, time_reached) \ No newline at end of file +} // TEST(SdkWrapper, time_reached) + +// ----------------------------------------------------------- +// +// hardware_uart +// virtual char uart_getc(uart_inst_t *); +// +// ----------------------------------------------------------- + +TEST(SdkWrapper, uart_getc) { + std::random_device rng; + ::rpp_driver::SdkWrapper pico; + // uniform distribution + std::uniform_int_distribution param_dist(0, INT_MAX); + uart_inst_t param_array0[] = {param_dist(rng), param_dist(rng)}; + std::uniform_int_distribution retval_dist(0, CHAR_MAX); + char retval_array[] = {retval_dist(rng), retval_dist(rng)}; + + FFF_RESET_HISTORY(); + RESET_FAKE(uart_getc); + + SET_RETURN_SEQ(uart_getc, retval_array, std::size(retval_array)); + + // Check whether return values are correctly passed to wrapper. + int index = 0; + for (auto &¶m0 : param_array0) { + ASSERT_EQ(pico.uart_getc(¶m_array0[index]), retval_array[index]); + index++; + } + + // Check the data from test spy. How many time called? + ASSERT_EQ(uart_getc_fake.call_count, std::size(retval_array)); + + // 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 *)uart_getc); + // Check the data from test spy. : Parameters. + ASSERT_EQ(uart_getc_fake.arg0_history[index], ¶m_array0[index]); + index++; + } + RESET_FAKE(uart_getc); +} // TEST(SdkWrapper, uart_getc) diff --git a/test/todo/test_sdkwrapper.md b/test/todo/test_sdkwrapper.md index 8846c7e..b6c249c 100644 --- a/test/todo/test_sdkwrapper.md +++ b/test/todo/test_sdkwrapper.md @@ -1,4 +1,12 @@ # test_SdkWrapper TDD + virtual char uart_getc(uart_inst_t* uart); + +## SdkWrapper::uart_getc() +- [x] Implement member function . +- [x] Create test case to fail. +- [x] Make it success. +- [x] Remove the duplication. + ## SdkWrapper::time_reached() - [x] Implement member function . - [x] Create test case to fail.