| /* |
| * 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 SW_DEVICE_LIB_TESTING_TEST_ROM_PUPPETEER_H_ |
| #define SW_DEVICE_LIB_TESTING_TEST_ROM_PUPPETEER_H_ |
| #include "sw/device/lib/testing/test_rom/puppeteer_utils/tiny_io.h" |
| |
| struct Args; |
| |
| // Puppeteer is a small, simple console interface to a microcontroller that |
| // requires only a byte-oriented IO port and provides methods to read and write |
| // any address in the address space and to upload and download blocks of memory |
| // as base64-encoded blobs. |
| // |
| // Usage: |
| // TinyIO io { |
| // [](void* user) -> uint8_t { <get_byte lambda> }, |
| // [](void* user, uint8_t b) { <put_byte lambda> }, |
| // <user-provided pointer passed to lambdas above> |
| // }; |
| // |
| // Puppeteer puppeteer(net_io); |
| // puppeteer.console_main(); |
| // |
| struct Puppeteer { |
| explicit Puppeteer(TinyIO io) : io(io) {} |
| |
| int on_help(Args args); |
| int on_echo(Args args); |
| int on_quit(Args args); |
| int on_boot_internal(Args args, bool tock); |
| int on_boot_ottf(Args args); |
| int on_boot_tock(Args args); |
| |
| int on_peekb(Args args); |
| int on_peekd(Args args); |
| int on_pokeb(Args args); |
| int on_poked(Args args); |
| int on_hexb(Args args); |
| int on_hexd(Args args); |
| |
| int on_dump(Args args); |
| int on_write(Args args); |
| int on_err(char* command); |
| int on_test_hmac(Args args); |
| |
| int find_command(char* console_buf); |
| void console_main(); |
| |
| TinyIO io; |
| bool echo = true; |
| bool quit = false; |
| char console_buf[257]; |
| |
| typedef int (Puppeteer::*pc_handler)(Args args); |
| |
| struct Command { |
| const char* name; |
| pc_handler handler; |
| const char* help; |
| }; |
| static const int command_count = 14; |
| static Command commands[command_count]; |
| }; |
| |
| #endif // SW_DEVICE_LIB_TESTING_TEST_ROM_PUPPETEER_H_ |