blob: 95ec2ea7b943f149a862b7049939be325d1bc324 [file]
// Copyright 2022 Google LLC
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#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_