static void open_tty(const char *devname)
{
  struct termios options;
  serial_fd = open(devname, O_RDWR | O_NOCTTY | O_NDELAY);
  sim_assert(serial_fd != -1, "couldn't open serial port");
  sim_assert(isatty(serial_fd), "not a TTY");

  // Get the current options for the port
  if (tcgetattr(serial_fd, &options) != 0) {
    sim_error("tcgetattr");
  }

  // Set the baud rates
  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);

  // Enable the receiver and set local mode
  options.c_cflag |= (CLOCAL | CREAD);

  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  // Set the new options for the port
  if (tcsetattr(serial_fd, TCSANOW, &options) != 0) {
    sim_error("tcsetattr");
  }

  // flush tx and rx buffers
  tcflush(serial_fd, TCIOFLUSH);
}
Exemple #2
0
void sim_assert(bool cond, const char msg[])
{
	if (!cond)
	{
		sim_error(msg);
	}
}
Exemple #3
0
static inline void
WRMEM (unsigned addr, unsigned data)
{
	if (!WRITABLE_P (addr))
		sim_error ("write to read-only location %04X from %s\n", 
			addr, monitor_addr_name (PC));

	if (!IO_ADDR_P (addr) || TARGET_MACHINE.write_byte (addr, data))
      write8 (addr, (UINT8) data);
}
Exemple #4
0
static void cons_initParsing(const char *line,bool isFile) {
	curExecEnv++;
	assert(curExecEnv < MAX_EXEC_ENVS);
	execEnvs[curExecEnv].line = line;
	execEnvs[curExecEnv].isStream = isFile;
	if(isFile) {
		execEnvs[curExecEnv].stream = fopen(line,"r");
		if(execEnvs[curExecEnv].stream == NULL)
			sim_error("Unable to open file '%s'",line);
		execEnvs[curExecEnv].filename = line;
	}
	else
		execEnvs[curExecEnv].filename = "<stdin>";
	cons_reset();
}
Exemple #5
0
// Schedule Timer1 callback useconds from now.
// Zero cancels any pending timer.
static void schedule_timer(uint32_t useconds) {
  struct itimerval itimer;
  struct sigaction sa;

  if (time_scale) {
    sa.sa_sigaction = timer1_callback;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO;
    if (sigaction(SIGALRM, &sa, 0)) {
      sim_error("sigaction");
    }
    itimer.it_interval.tv_sec = 0;
    itimer.it_interval.tv_usec = 0;  // If signal occurs , trigger again in 10us
    itimer.it_value.tv_sec = useconds / 1000000;
    itimer.it_value.tv_usec = useconds % 1000000;
    setitimer(ITIMER_REAL, &itimer, NULL);
  }
}
Exemple #6
0
void setTimer(uint32_t delay)
{
	struct itimerval itimer;
        struct sigaction sa;
	
	sim_assert(timer_initialised, "timer not initialised");

        sa.sa_sigaction = timer1_isr;
        sigemptyset(&sa.sa_mask);
        sa.sa_flags = SA_SIGINFO;
        if (sigaction(SIGPROF, &sa, 0)) {
		sim_error("sigaction");
        }
	itimer.it_interval.tv_sec = 0;
	itimer.it_interval.tv_usec = (long)delay * 8000000 / F_CPU;
	itimer.it_value.tv_sec = 0;
	itimer.it_value.tv_usec = itimer.it_interval.tv_usec;
	setitimer(ITIMER_PROF, &itimer, NULL); 
}
Exemple #7
0
void sim_start(int argc, char** argv) {
  int c;
  int index;
  uint8_t time_scale = DEFAULT_TIME_SCALE;

  while ((c = getopt_long (argc, argv, shortopts, opts, &index)) != -1)
    switch (c) {
    case 'q':
      verbose = 0;
      break;
    case 'g':
      trace_gcode = 1;
      break;
    case 'p':
      trace_pos = 1;
      break;
    case 'v':
      verbose += 1;
      break;
    case 't':
      time_scale = (uint8_t) atoi(optarg);
      break;
    case 'o':
      recorder_init(optarg ? optarg : "datalog.out");
      break;
    default:
      sim_error("Unexpected result in getopt_long handler");
    }

  // Record the command line arguments to the datalog, if active
  record_raw("# commandline:   ");
  for (index = 0; index < argc; index++) {
    record_raw(argv[index]);
    record_raw(" ") ;
  }
  record_raw("\n");

  // Store remaining arguments list for serial sim
  g_argc = argc - optind + 1;
  g_argv = argv + optind - 1;

  if (argc < 2) usage(argv[0]);

  // Initialize timer
  sim_timer_init(time_scale);

  // Record pin names in datalog
#define NAME_PIN_AXES(x) \
  add_trace_var(#x "_X" , TRACE_##x + 0); \
  add_trace_var(#x "_Y" , TRACE_##x + 1); \
  add_trace_var(#x "_Z" , TRACE_##x + 2); \
  add_trace_var(#x "_E" , TRACE_##x + 3);
  NAME_PIN_AXES(POS);

#define NAME_PIN(x) add_trace_var(#x , TRACE_PINS + 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);
}
Exemple #8
0
void intercom_init(void) {
  sim_error("simulated intercom is not supported");
}