WIP: Add simulator data-logging.
Record simulation run-time data in file 'datalog.out' so it can be analyzed after-the-fact or during the run. This feature is evolving. Eventually it should be compatible with some logic analyzer GUIs such as gtkwave or even gnuplot.
This commit is contained in:
parent
a81f35022a
commit
1e2824d56b
|
|
@ -9,3 +9,4 @@ ThermistorTable.h
|
|||
Makefile
|
||||
sim
|
||||
doc
|
||||
datalog.out
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* data_recorder.c
|
||||
*
|
||||
* Record simulator data to a file in real-time.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "simulator.h"
|
||||
#include "data_recorder.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
static FILE *file;
|
||||
|
||||
#define MAX_PINS 100
|
||||
static uint32_t values[MAX_PINS]; ///< Pin and value states
|
||||
static int pin_count; ///< Number of pins we emit
|
||||
|
||||
void recorder_init(const char* filename) {
|
||||
sim_assert( ! file, "Recorder already initialized");
|
||||
|
||||
file = fopen(filename, "w");
|
||||
sim_assert(file, "record_init: failed to create file");
|
||||
|
||||
time_t t = time(NULL);
|
||||
fprintf(file, "; Teacup_Firmware simulator data log on %s\n",
|
||||
asctime(localtime(&t)));
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
void add_trace_var(const char* name, int pin) {
|
||||
sim_assert(file, "add_trace_var: Recorder not initialized");
|
||||
sim_assert(pin < MAX_PINS, "pin number invalid");
|
||||
|
||||
fprintf(file, "; %d - %s\n", pin, name);
|
||||
if (pin >= pin_count)
|
||||
pin_count = pin + 1;
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
// Record a binary signal change
|
||||
void record_pin(int pin, bool state, uint32_t t) {
|
||||
if (state == values[pin]) return;
|
||||
|
||||
sim_assert(file , "record_pin: Recorder not initialized");
|
||||
sim_assert(pin < MAX_PINS, "pin number invalid");
|
||||
|
||||
values[pin] = state;
|
||||
|
||||
// Naive format: each line contains all values, beginning with the time
|
||||
fprintf(file, "%u", t);
|
||||
for (int i = 0; i < pin_count; i++)
|
||||
fprintf(file, "\t%u", values[i]);
|
||||
fprintf(file, "\n");
|
||||
fflush(file);
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* data_recorder.h
|
||||
*/
|
||||
|
||||
#ifndef DATA_RECORDER_H_
|
||||
#define DATA_RECORDER_H_
|
||||
|
||||
void recorder_init(const char* filename);
|
||||
void record_pin(int pin, bool state, uint32_t time);
|
||||
void add_trace_var(const char* name, int pin);
|
||||
|
||||
#endif /* DATA_RECORDER_H_ */
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
#include "simulator.h"
|
||||
#include "data_recorder.h"
|
||||
|
||||
uint8_t ACSR;
|
||||
uint8_t TIMSK1;
|
||||
|
|
@ -35,6 +36,33 @@ void sim_start(int argc, char** argv) {
|
|||
// Save these for the serial_init code
|
||||
g_argc = argc;
|
||||
g_argv = argv;
|
||||
|
||||
recorder_init("datalog.out");
|
||||
|
||||
// Record pin names in datalog
|
||||
#define NAME_PIN(x) add_trace_var(#x , x);
|
||||
NAME_PIN(X_STEP_PIN);
|
||||
NAME_PIN(X_DIR_PIN);
|
||||
NAME_PIN(X_MIN_PIN);
|
||||
NAME_PIN(X_ENABLE_PIN);
|
||||
NAME_PIN(Y_STEP_PIN);
|
||||
NAME_PIN(Y_DIR_PIN);
|
||||
NAME_PIN(Y_MIN_PIN);
|
||||
NAME_PIN(Y_ENABLE_PIN);
|
||||
NAME_PIN(Z_STEP_PIN);
|
||||
NAME_PIN(Z_DIR_PIN);
|
||||
NAME_PIN(Z_MIN_PIN);
|
||||
NAME_PIN(Z_ENABLE_PIN);
|
||||
NAME_PIN(E_STEP_PIN);
|
||||
NAME_PIN(E_DIR_PIN);
|
||||
NAME_PIN(E_ENABLE_PIN);
|
||||
|
||||
NAME_PIN(STEPPER_ENABLE_PIN);
|
||||
|
||||
NAME_PIN(SCK);
|
||||
NAME_PIN(MOSI);
|
||||
NAME_PIN(MISO);
|
||||
NAME_PIN(SS);
|
||||
}
|
||||
|
||||
/* -- debugging ------------------------------------------------------------ */
|
||||
|
|
@ -129,6 +157,8 @@ void WRITE(pin_t pin, bool s) {
|
|||
}
|
||||
|
||||
if (old_state != s) {
|
||||
uint32_t useconds = 0; // TODO
|
||||
record_pin(pin, s, useconds);
|
||||
#ifdef TRACE_ALL_PINS
|
||||
fgreen();
|
||||
for (int i = 0; i < PIN_NB; i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue