void sim_timer_init(uint8_t scale) { time_scale = scale; then = begin = now_ns(); if (scale==0) sim_info("timer_init: warp-speed"); else if (scale==1) sim_info("timer_init: real-time"); else sim_info("timer_init: 1/%u time", scale); timer_initialised = true; }
/** Simulate min endstops. "on" at -10, "off" at 0. */ static void sim_endstop( int axis ) { bool on ; if (axis == AXIS_NONE) return; else if (pos[axis] <= -20) on = true; else if (pos[axis] >= 0) on = false; else return ; const char * strstate = on ? "ON" : "OFF"; int minpin; switch (axis) { case X_AXIS: #ifdef X_INVERT_MIN on = ! on; #endif minpin = X_MIN_PIN; break; case Y_AXIS: #ifdef Y_INVERT_MIN on = ! on; #endif minpin = Y_MIN_PIN; break; case Z_AXIS: #ifdef Z_INVERT_MIN on = ! on; #endif minpin = Z_MIN_PIN; break; default: return; } // No change if (state[minpin] == on) return; // Change the endstop state and report it state[minpin] = on; record_pin(TRACE_PINS + minpin, on, sim_runtime_ns()); bred(); if (on) sim_tick('A' + minpin); else sim_tick('a' + minpin); fbreset(); sim_info("%c-Endstop: %s", "XYZE???"[axis], strstate); }
static void gdbsim_files_info (struct target_ops *target) { char *file = "nothing"; if (exec_bfd) file = bfd_get_filename (exec_bfd); if (sr_get_debug ()) printf_filtered ("gdbsim_files_info: file \"%s\"\n", file); if (exec_bfd) { printf_filtered ("\tAttached to %s running program %s\n", target_shortname, file); sim_info (gdbsim_desc, 0); } }
// return number of characters in the receive buffer uint8_t serial_rxchars(void) { sim_assert(serial_initialised, "serial interface not initialised"); if (serial_fd) { int rx_chars_nb; ioctl(serial_fd, FIONREAD, &rx_chars_nb); return rx_chars_nb; } // An open file always has more data if (gcode_fd) return 1; // No more gcode data; wait for DDA queue to drain if (mb_tail_dda == NULL) { sim_info("Gcode processing completed."); exit(0); } // Nothing to read from return 0; }
static void open_file() { struct stat st; static int i=1; const char * filename = g_argv[i++]; // Close previous file if (gcode_fd) close(gcode_fd); gcode_fd = 0; // No more files if (i > g_argc) return; sim_info("Opening G-code source %s.", filename); sim_assert(!stat(filename, &st), "Could not stat G-code source."); if (!st.st_rdev) { // Normal file gcode_fd = open(filename, O_RDONLY ); sim_assert(gcode_fd, "Could not open G-code file."); } else { // Some kind of device (treat as TTY) open_tty(filename); } }
int main (int argc, char **argv) { char *name; char **prog_argv = NULL; struct bfd *prog_bfd; enum sim_stop reason; int sigrc = 0; int single_step = 0; RETSIGTYPE (*prev_sigint) (); myname = argv[0] + strlen (argv[0]); while (myname > argv[0] && myname[-1] != '/') --myname; /* INTERNAL: When MYNAME is `step', single step the simulator instead of allowing it to run free. The sole purpose of this HACK is to allow the sim_resume interface's step argument to be tested without having to build/run gdb. */ if (strlen (myname) > 4 && strcmp (myname - 4, "step") == 0) { single_step = 1; } /* Create an instance of the simulator. */ default_callback.init (&default_callback); sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, NULL, argv); if (sd == 0) exit (1); if (STATE_MAGIC (sd) != SIM_MAGIC_NUMBER) { fprintf (stderr, "Internal error - bad magic number in simulator struct\n"); abort (); } /* We can't set the endianness in the callback structure until sim_config is called, which happens in sim_open. */ default_callback.target_endian = (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); /* Was there a program to run? */ prog_argv = STATE_PROG_ARGV (sd); prog_bfd = STATE_PROG_BFD (sd); if (prog_argv == NULL || *prog_argv == NULL) usage (); name = *prog_argv; /* For simulators that don't open prog during sim_open() */ if (prog_bfd == NULL) { prog_bfd = bfd_openr (name, 0); if (prog_bfd == NULL) { fprintf (stderr, "%s: can't open \"%s\": %s\n", myname, name, bfd_errmsg (bfd_get_error ())); exit (1); } if (!bfd_check_format (prog_bfd, bfd_object)) { fprintf (stderr, "%s: \"%s\" is not an object file: %s\n", myname, name, bfd_errmsg (bfd_get_error ())); exit (1); } } if (STATE_VERBOSE_P (sd)) printf ("%s %s\n", myname, name); /* Load the program into the simulator. */ if (sim_load (sd, name, prog_bfd, 0) == SIM_RC_FAIL) exit (1); /* Prepare the program for execution. */ #ifdef HAVE_ENVIRON sim_create_inferior (sd, prog_bfd, prog_argv, environ); #else sim_create_inferior (sd, prog_bfd, prog_argv, NULL); #endif /* To accommodate relative file paths, chdir to sysroot now. We mustn't do this until BFD has opened the program, else we wouldn't find the executable if it has a relative file path. */ if (simulator_sysroot[0] != '\0' && chdir (simulator_sysroot) < 0) { fprintf (stderr, "%s: can't change directory to \"%s\"\n", myname, simulator_sysroot); exit (1); } /* Run/Step the program. */ if (single_step) { do { prev_sigint = signal (SIGINT, cntrl_c); sim_resume (sd, 1/*step*/, 0); signal (SIGINT, prev_sigint); sim_stop_reason (sd, &reason, &sigrc); if ((reason == sim_stopped) && (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) break; /* exit on control-C */ } /* remain on breakpoint or signals in oe mode*/ while (((reason == sim_signalled) && (sigrc == sim_signal_to_host (sd, SIM_SIGTRAP))) || ((reason == sim_stopped) && (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT))); } else { do { #if defined (HAVE_SIGACTION) && defined (SA_RESTART) struct sigaction sa, osa; sa.sa_handler = cntrl_c; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sigaction (SIGINT, &sa, &osa); prev_sigint = osa.sa_handler; #else prev_sigint = signal (SIGINT, cntrl_c); #endif sim_resume (sd, 0, sigrc); signal (SIGINT, prev_sigint); sim_stop_reason (sd, &reason, &sigrc); if ((reason == sim_stopped) && (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) break; /* exit on control-C */ /* remain on signals in oe mode */ } while ((reason == sim_stopped) && (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)); } /* Print any stats the simulator collected. */ if (STATE_VERBOSE_P (sd)) sim_info (sd, 0); /* Shutdown the simulator. */ sim_close (sd, 0); /* If reason is sim_exited, then sigrc holds the exit code which we want to return. If reason is sim_stopped or sim_signalled, then sigrc holds the signal that the simulator received; we want to return that to indicate failure. */ /* Why did we stop? */ switch (reason) { case sim_signalled: case sim_stopped: if (sigrc != 0) fprintf (stderr, "program stopped with signal %d.\n", sigrc); break; case sim_exited: break; default: fprintf (stderr, "program in undefined state (%d:%d)\n", reason, sigrc); break; } return sigrc; }
void sim_timer_stop(void) { sim_info("timer_stop"); timer_reason = 0; // Cancel pending timer; }
void setupTimerInterrupt(void) { disableTimerInterrupt(); sim_info("setupTimerInterrupt"); timer_initialised = true; }
static void print_pos(void) { sim_info("x:%5d y:%5d z:%5d e:%5d", x, y, z, e); }