mercoledì 12 novembre 2025

REPL in emulatore QEMU Esp32

Nell'SDK IDF ' contenuto un emulatore ESP32 QEmu

Non si possono simulare sensori e protocolli di trasmissione ma per cose semplici come REPL sulla seriale funziona piu' che bene

Non sono riuscito a fare partire l'emulatore con la finestra grafica 

 

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define MAX_LINE_LEN 128

void repl_task(void *arg) {
char line[MAX_LINE_LEN];
int pos = 0;
int c;
int echo = 1; // set to 0 to disable echo

printf("REPL started. Type commands:\n> ");
fflush(stdout);

while (true) {
c = fgetc(stdin); // blocking read from UART

if (c == EOF) {
vTaskDelay(10 / portTICK_PERIOD_MS);
continue;
}

// Handle carriage return or newline
if (c == '\r' || c == '\n') {
if (echo) printf("\r\n");
line[pos] = '\0';

if (pos > 0) {
if (strcmp(line, "hello") == 0)
printf("Hi there!\n");
else if (strcmp(line, "echo off") == 0)
echo = 0, printf("Echo disabled.\n");
else if (strcmp(line, "echo on") == 0)
echo = 1, printf("Echo enabled.\n");
else if (strcmp(line, "exit") == 0)
printf("Goodbye!\n");
else
printf("Unknown command: %s\n", line);
}

printf("> ");
fflush(stdout);
pos = 0; // reset buffer
}
// Handle backspace or delete
else if ((c == 8 || c == 127) && pos > 0) {
pos--;
if (echo) {
printf("\b \b"); // erase last char on terminal
fflush(stdout);
}
}
// Normal printable characters
else if (pos < MAX_LINE_LEN - 1 && c >= 32 && c <= 126) {
line[pos++] = (char)c;
if (echo) {
fputc(c, stdout);
fflush(stdout);
}
}
}
}

void app_main() {
xTaskCreate(repl_task, "repl_task", 4096, NULL, 5, NULL);
}


 

Nessun commento:

Posta un commento

SIMD Mandelbrot

 E' tempo che si legge per la scheda tecnica dei processori la presenza di SIMD, SSE, AVX ma non avevo mai capito come voleva dire.   In...