コード例 #1
0
static void
serial_interrupt_checkpoint()
{
  int fd = 0;
  PAUSE_TIME();

  if(SPI_IS_ENABLED()) {
    /* SPI is busy, abort */
    PRINTF_COMMAND("CP:SPIBUSY\n");
    RESUME_TIME();
    return;
  }

  /* Open file */
  cfs_remove("cp");
  cfs_coffee_reserve("cp", checkpoint_arch_size());
  fd = cfs_open("cp", CFS_WRITE);

  if(fd < 0) {
    printf("ERROR: No file access (cp)\n");
    RESUME_TIME();
    return;
  }

  /* Checkpoint */
  preset_cmd = COMMAND_CHECKPOINT;
  preset_fd = fd;
  mt_exec(&checkpoint_thread);

  /* Close file */
  cfs_close(fd);

  RESUME_TIME();
}
コード例 #2
0
ファイル: shell-checkpoint.c プロジェクト: EDAyele/ptunes
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_checkpoint_process, ev, data)
{
  int fd = 0;

  PROCESS_BEGIN();

  /* Make sure file does not already exist */
  cfs_remove(data);

  cfs_coffee_reserve(data, checkpoint_arch_size());
  fd = cfs_open(data, CFS_WRITE);

  if(fd < 0) {
    shell_output_str(&checkpoint_command,
             "checkpoint: could not open file for writing: ", data);
  } else {
    shell_output_str(&rollback_command, "checkpoint to: ", data);
    checkpoint_checkpoint(fd);
    cfs_close(fd);
  }

  PROCESS_END();
}
コード例 #3
0
PROCESS_THREAD(checkpoint_serial_process, ev, data)
{
  static int set_fd = -1;
  static int set_count = -1;

  PROCESS_BEGIN();

  /* Note: 'cp', 'rb', and 'mt' commands are intercepted */
  PROCESS_PAUSE();
  uart1_set_input(serial_input_byte_intercept);

  /* Format Coffee? */
  PRINTF("Formatting Coffee\n");
  cfs_coffee_format();
  PRINTF("Formatting Coffee... done!\n");

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);

    if(strcmp("set", data) == 0) {
      /* TODO Handle set command */
      /* Open file */
      cfs_remove("cp");
      cfs_coffee_reserve("cp", checkpoint_arch_size());
      set_fd = cfs_open("cp", CFS_WRITE);
      set_count = 0;
      if(set_fd < 0) {
        printf("SET:FSBUSY\n");
      } else {
        printf("SET:LINE\n");
      }
    } else if(set_fd >= 0 && strcmp("set:done", data) == 0) {
        cfs_close(set_fd);
        set_fd = -1;
        if(set_count == 9862) {
          printf("SET:DONE\n");
        } else {
          printf("SET:WRONGSIZE\n");
        }
    } else if(set_fd >= 0) {
      /* We are ready for another line */
      printf("SET:LINE\n");
      /* Set command: parse hex data */
      int len = strlen((char*)data);
      if(len > 16 || (len%2)!=0) {
        printf("WARN: bad set data: %s\n", (char*)data);
      } else {
        int i;
        for (i=0; i < len; i+=2) {
          uint8_t b =
            (hex_decode_char(((char*)data)[i]) << 4) +
            (hex_decode_char(((char*)data)[i+1]));

          PRINTF("Parsing set command: writing to CFS: %02x\n", b);
          write_byte(set_fd, b); /* TODO Check return value */
          set_count++;
        }
      }
    } else if(strcmp("", data) == 0 ||
        strcmp("cp", data) == 0 ||
        strcmp("rb", data) == 0 ||
        strcmp("mt", data) == 0) {
      /* ignore commands: handled by interrupt */
    } else if(strcmp("ping", data) == 0) {
      nr_pongs++;
      printf("pong %u\n", nr_pongs);
    } else if(strcmp("get", data) == 0) {
      handle_get_command();
    } else {
      printf("WARN: Unknown command: '%s'\n", (char*)data);
    }
  }

  PROCESS_END();
}