| /* |
| * Copyright 2023 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #ifndef EXAMPLES_SOUNDSTREAM_COMPAT_H_ |
| #define EXAMPLES_SOUNDSTREAM_COMPAT_H_ |
| |
| // XXX maybe uart_write? |
| // XXX fix var args |
| #define LOG_ERROR(msg, ...) Debug::log("{}", msg) |
| #define LOG_INFO(msg, ...) Debug::log("{}", msg) |
| #define LOG_FATAL(msg, ...) Debug::Assert(false, "{}", msg) |
| |
| /** |
| * Checks that the given condition is true. If the condition is false, this |
| * function logs and then aborts. |
| * |
| * @param condition An expression to check. |
| * @param ... Arguments to a LOG_* macro, which are evaluated if the check |
| * fails. |
| */ |
| #define CHECK(condition, ...) \ |
| do { \ |
| if (!(condition)) { \ |
| /* NOTE: because the condition in this if \ |
| statement can be statically determined, \ |
| only one of the below string constants \ |
| will be included in the final binary.*/ \ |
| if (OT_VA_ARGS_COUNT(_, ##__VA_ARGS__) == 0) { \ |
| LOG_ERROR("CHECK-fail: " #condition); \ |
| } else { \ |
| LOG_ERROR("CHECK-fail: " __VA_ARGS__); \ |
| } \ |
| /* Currently, this macro will call into \ |
| the test failure code, which logs \ |
| "FAIL" and aborts. In the future, \ |
| we will try to condition on whether \ |
| or not this is a test.*/ \ |
| /* XXX fill me in */ \ |
| } \ |
| } while (false) |
| |
| /** |
| * Checks that the given DIF call returns kDifOk. If the DIF call returns a |
| * different dif_result_t value (defined in sw/device/lib/dif/dif_base.h), this |
| * function logs and then aborts. |
| * |
| * @param dif_call DIF call to invoke and check its return value. |
| * @param ... Arguments to a LOG_* macro, which are evaluated if the check |
| * fails. |
| */ |
| #define CHECK_DIF_OK(dif_call, ...) \ |
| do { \ |
| dif_result_t dif_result = dif_call; \ |
| if (dif_result != kDifOk) { \ |
| /* NOTE: because the condition in this if \ |
| statement can be statically determined, \ |
| only one of the below string constants \ |
| will be included in the final binary.*/ \ |
| if (OT_VA_ARGS_COUNT(_, ##__VA_ARGS__) == 0) { \ |
| LOG_ERROR("DIF-fail: " #dif_call " returns %d", dif_result); \ |
| } else { \ |
| LOG_ERROR("DIF-fail: " __VA_ARGS__); \ |
| } \ |
| /* Currently, this macro will call into \ |
| the test failure code, which logs \ |
| "FAIL" and aborts. In the future, \ |
| we will try to condition on whether \ |
| or not this is a test.*/ \ |
| /* XXX fill me in */ \ |
| } \ |
| } while (false) |
| |
| // TODO(sleffler): need a scheduler yield kinda call |
| inline void wait_for_interrupt(void) { asm volatile("wfi"); } |
| |
| #endif // EXAMPLES_SOUNDSTREAM_COMPAT_H_ |