diff --git a/Chapter07/error_handling/.vscode/settings.json b/Chapter07/error_handling/.vscode/settings.json index b42704e..d9b0cb6 100644 --- a/Chapter07/error_handling/.vscode/settings.json +++ b/Chapter07/error_handling/.vscode/settings.json @@ -1,6 +1,8 @@ { "files.associations": { - "span": "cpp" + "span": "cpp", + "array": "cpp", + "string_view": "cpp" }, "C_Cpp.errorSquiggles": "disabled" } \ No newline at end of file diff --git a/Chapter07/error_handling/app/src/main_exceptions.cpp b/Chapter07/error_handling/app/src/main_exceptions.cpp index 99261dd..34e5d1f 100644 --- a/Chapter07/error_handling/app/src/main_exceptions.cpp +++ b/Chapter07/error_handling/app/src/main_exceptions.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include @@ -8,28 +10,16 @@ #include -void log_pc_and_halt(std::uint32_t pc) { - printf("Assert at 0x%08lX\r\n", pc); - while(true) {} -} +template struct ring_buffer { -#define light_assert(expr) \ - (static_cast (expr) \ - ? void (0) \ - : log_pc_and_halt(hal::get_pc()) \ - ) + std::array arr; + std::size_t write_idx = 0; // Index of the next element to write (push) -enum class option : std::uint8_t { - Option1 = 0, - Option2, - Option3, - Last + void push(T t) { + arr.at(write_idx++) = t; + } }; - -option uint8_to_option(uint8_t num) { - light_assert(num < static_cast(option::Last)); - return static_cast