Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chipflow/common/sim/main.cc.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int main(int argc, char **argv) {
std::cerr << "Waiting for debugger on " << agent.start_debugging() << std::endl;

open_event_log(BUILD_DIR "/sim/events.json");
open_uart_log(PROJECT_ROOT "/uart.log");
open_input_commands(PROJECT_ROOT "/design/tests/input.json");

unsigned timestamp = 0;
Expand Down Expand Up @@ -74,5 +75,6 @@ int main(int argc, char **argv) {
tick();

close_event_log();
close_uart_log();
return 0;
}
26 changes: 24 additions & 2 deletions chipflow/common/sim/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ void open_input_commands(const std::string &filename) {

static std::ofstream event_log;

// UART log file for VS Code extension
static FILE *uart_log = nullptr;

void open_event_log(const std::string &filename) {
event_log.open(filename);
if (!event_log) {
Expand Down Expand Up @@ -135,6 +138,20 @@ void close_event_log() {
}
}

void open_uart_log(const std::string &filename) {
uart_log = fopen(filename.c_str(), "w");
if (!uart_log) {
fprintf(stderr, "WARNING: failed to open UART log file: %s\n", filename.c_str());
}
}

void close_uart_log() {
if (uart_log) {
fclose(uart_log);
uart_log = nullptr;
}
}

namespace models {

// SPI flash
Expand Down Expand Up @@ -246,10 +263,15 @@ void uart::step(unsigned timestamp) {
s.rx_sr = (tx ? 0x80U : 0x00U) | (s.rx_sr >> 1U);
}
if (bit == 8) {
// print to console
// print to console and log file
log_event(timestamp, name, "tx", json(s.rx_sr));
if (name == "uart_0")
if (name == "uart_0") {
fprintf(stderr, "%c", char(s.rx_sr));
if (uart_log) {
fprintf(uart_log, "%c", char(s.rx_sr));
fflush(uart_log); // Flush for real-time watching
}
}
}
if (bit == 9) {
// end
Expand Down
4 changes: 4 additions & 0 deletions chipflow/common/sim/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void log_event(unsigned timestamp, const std::string &peripheral, const std::str
std::vector<action> get_pending_actions(const std::string &peripheral);
void close_event_log();

// UART log file for VS Code extension real-time monitoring
void open_uart_log(const std::string &filename);
void close_uart_log();

namespace models {


Expand Down
Loading