OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [disk/] [diskserv/] [diskserv.c] - Diff between revs 46 and 48

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 46 Rev 48
Line 10... Line 10...
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#include <termios.h>
#include <termios.h>
 
 
 
 
#define SERIAL_PORT     "/dev/tty01"
 
 
 
#define SYN             0x16
#define SYN             0x16
#define ACK             0x06
#define ACK             0x06
 
 
#define RESULT_OK       0x00
#define RESULT_OK       0x00
#define RESULT_UNCMD    0x01
#define RESULT_UNCMD    0x01
Line 56... Line 54...
  }
  }
  exit(1);
  exit(1);
}
}
 
 
 
 
void serialOpen(void) {
void serialOpen(char *serialPort) {
  sfd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
  sfd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY);
  if (sfd == -1) {
  if (sfd == -1) {
    error("cannot open serial port '%s'", SERIAL_PORT);
    error("cannot open serial port '%s'", serialPort);
  }
  }
  tcgetattr(sfd, &origOptions);
  tcgetattr(sfd, &origOptions);
  currOptions = origOptions;
  currOptions = origOptions;
  cfsetispeed(&currOptions, B38400);
  cfsetispeed(&currOptions, B38400);
  cfsetospeed(&currOptions, B38400);
  cfsetospeed(&currOptions, B38400);
Line 150... Line 148...
  }
  }
}
}
 
 
 
 
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
 
  char *serialPort;
  char *diskName;
  char *diskName;
  int i;
  int i;
  unsigned char b;
  unsigned char b;
  unsigned char cmd;
  unsigned char cmd;
  unsigned int sector;
  unsigned int sector;
  unsigned char buffer[512];
  unsigned char buffer[512];
 
 
  if (argc != 2) {
  if (argc != 3) {
    printf("Usage: %s <disk image file>\n", argv[0]);
    printf("Usage: %s <serial port> <disk image file>\n", argv[0]);
    exit(1);
    exit(1);
  }
  }
  diskName = argv[1];
  serialPort = argv[1];
 
  diskName = argv[2];
  diskFile = fopen(diskName, "r+b");
  diskFile = fopen(diskName, "r+b");
  if (diskFile == NULL) {
  if (diskFile == NULL) {
    error("cannot open disk image file '%s'", diskName);
    error("cannot open disk image file '%s'", diskName);
  }
  }
  fseek(diskFile, 0, SEEK_END);
  fseek(diskFile, 0, SEEK_END);
  numSectors = ftell(diskFile) / 512;
  numSectors = ftell(diskFile) / 512;
  fseek(diskFile, 0, SEEK_SET);
  fseek(diskFile, 0, SEEK_SET);
  printf("Disk '%s' has 0x%08X sectors.\n", diskName, numSectors);
  printf("Disk '%s' has 0x%08X sectors.\n", diskName, numSectors);
  /* open serial interface */
  /* open serial interface */
  serialOpen();
  serialOpen(serialPort);
  /* wait for client to connect */
  /* wait for client to connect */
  printf("Waiting for client...\n");
  printf("Waiting for client...\n");
  while (1) {
  while (1) {
    if (serialRcv(&b) && b == SYN) {
    if (serialRcv(&b) && b == SYN) {
      break;
      break;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.