Exemple #1
0
int main(void)
{
    fscc_handle h;
    unsigned status;

    fscc_connect(0, &h);

    fscc_get_rx_multiple(h, &status);

    fscc_enable_rx_multiple(h);
    fscc_disable_rx_multiple(h);

    fscc_disconnect(h);

    return 0;
}
Exemple #2
0
int init(fscc_handle h)
{
    struct fscc_registers r;
    struct fscc_memory_cap m;
    int e = 0;

    m.input = 1000000;
    m.output = 1000000;

    e = fscc_set_memory_cap(h, &m);
    if (e != 0) {
        fprintf(stderr, "fscc_set_memory_cap failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_disable_rx_multiple(h);
    if (e != 0) {
        fprintf(stderr, "fscc_disable_rx_multiple failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_disable_append_status(h);
    if (e != 0) {
        fprintf(stderr, "fscc_disable_append_status failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_disable_append_timestamp(h);
    if (e != 0) {
        fprintf(stderr, "fscc_disable_append_timestamp failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_set_tx_modifiers(h, XF);
    if (e != 0) {
        fprintf(stderr, "fscc_set_tx_modifiers failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_disable_ignore_timeout(h);
    if (e != 0) {
        fprintf(stderr, "fscc_disable_ignore_timeout failed with %d\n", e);
        return EXIT_FAILURE;
    }

    FSCC_REGISTERS_INIT(r);

    r.FIFOT = 0x08001000;
    r.CCR0 = 0x0011201c;
    r.CCR1 = 0x00000018;
    r.CCR2 = 0x00000000;
    r.BGR = 0x00000000;
    r.SSR = 0x0000007e;
    r.SMR = 0x00000000;
    r.TSR = 0x0000007e;
    r.TMR = 0x00000000;
    r.RAR = 0x00000000;
    r.RAMR = 0x00000000;
    r.PPR = 0x00000000;
    r.TCR = 0x00000000;
    r.IMR = 0x0f000000;
    r.DPLLR = 0x00000004;
    r.FCR = 0x00000000;

    e = fscc_set_registers(h, &r);
    if (e != 0) {
        fprintf(stderr, "fscc_set_registers failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_set_clock_frequency(h, 18432000);
    if (e != 0) {
        fprintf(stderr, "fscc_set_clock_frequency failed with %d\n", e);
        return EXIT_FAILURE;
    }

    e = fscc_purge(h, 1, 1);
    if (e != 0) {
        fprintf(stderr, "fscc_purge failed with %d\n", e);
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
int main(void)
{
  fscc_handle h;

  struct fscc_registers regs;
  unsigned rx_multiple_status;

  int e = 0;
  char idata[DATA_LENGTH] = {0};

  int port = 0;
    
  int i;
  unsigned bytes_stored = 0;
  unsigned bytes_read = 0;
  unsigned total_bytes_read = 0;

  /* unsigned tmp; */
  unsigned timeout = 1000;
  struct fscc_memory_cap memcap;
  char fname[] = "/home/spencerh/data/transp_test.data";

  FILE *fp;
  fp = fopen(fname,"wb");
  if (fp == NULL) {
    fprintf(stderr, "cannot open output file %s\n", fname);
    return EXIT_FAILURE;
  }

  e = fscc_connect(port, &h);
  if (e != 0) {
    fprintf(stderr, "fscc_connect failed with %d\n", e);
    return EXIT_FAILURE;
  }


  /*Deal with memory cap*/
  FSCC_MEMORY_CAP_INIT(memcap);

  memcap.input = 750000; /* ~1MB */
  memcap.output = 50000; /* ~50kB */

  fscc_set_memory_cap(h, &memcap);

  /* Initialize our registers structure */
  FSCC_REGISTERS_INIT(regs);

  /* ####CCR0#### */
  /* #(0-1)TRANSPARENT MODE (10) */
  /* #(2-4)CLOCK = MODE 2 (RxClk) (010) */
  /* #(7-5)LINE ENCODING = NRZ (000) */
  /* #(10-8)FSC = MODE 4 (100) (Sync signal found at beginning[mode 2=010] and end[mode 3=011] of data) */
  /* #(11)SHARED FLAGS (0) */
  /* #(12)ITF  0 */
  /* #(13-15)Num sync bytes = 0 (NSB = 000) */
  /* #(16-18)Num term bytes = 0 (NTB = 000) */
  /* #(22) Order of bit transmission = 1 (1 = MSB first--totally crucial...) */
  regs.CCR0 = 0x40040a;

  /* ####CCR1#### */
  /* #(3)CTSC = 0 */
  /* #(4)ZINS = 0 */
  /* #(7)SYNC2F = 0 (1 =Transfer SYNC characters to RxFIFO) */
  /* #(8)TERM2F = 0 (0 = DO NOT Transfer TERM bytes to RxFIFO) */
  /* #(12)DRCRC = 1 (Disable receive CRC checking) */
  /* p.registers.CCR1=0b1000000000000 */
  regs.CCR1 = 0x00001000;

  /* ####CCR2#### */
  /* #(0-3) Frame Sync Receive Offset = 0b1111 (data aligned with FSR signal) */
  regs.CCR2 = 0x0;


  /* Set the CCR{0,1,2} register values */
  e = fscc_set_registers(h, &regs);
  if (e != 0) {
    fscc_disconnect(h);
    fprintf(stderr, "fscc_set_registers failed with %d\n", e);
    return EXIT_FAILURE;
  }

  /* Set clock frequency (necessary?) */
  e = fscc_set_clock_frequency(h, 18432000);
  if (e != 0) {
    fscc_disconnect(h);
    fprintf(stderr, "fscc_set_clock_frequency failed with %d\n", e);
    return EXIT_FAILURE;
  }

  e = fscc_disable_append_status(h);
  if (e != 0) {
    fscc_disconnect(h);
    fprintf(stderr, "fscc_disable_append_status failed with %d\n", e);
    return EXIT_FAILURE;
  }

  e = fscc_disable_append_timestamp(h);
  if (e != 0) {
    fscc_disconnect(h);
    fprintf(stderr, "fscc_disable_append_timestamp failed with %d\n", e);
    return EXIT_FAILURE;
  }


  /* Enable reading of multiple "frames" (as defined by FSR signal) at once */
  e = fscc_disable_rx_multiple(h);
  if (e !=0) {
	fscc_disconnect(h);
	fprintf(stderr, "fscc_enable_rx_multiple failed with %d\n", e);
	return EXIT_FAILURE;
  }

  /* Purge, because we've changed to TRANSPARENT mode */
  printf("Purging...\n");
  e = fscc_purge( h, 1, 1);
  if( e == 16000) {
    fscc_disconnect(h);
    fprintf(stderr,"Timed out--are you sure you're providing a clock signal?\n");
    fprintf(stderr,"Laterz...\n");
    return EXIT_FAILURE;
  } 
  else if(e != 0) {
    fscc_disconnect(h);
    fprintf(stderr, "fscc_purge failed with %d\n", e);
    return EXIT_FAILURE;    
  }

  regs.CCR0 = FSCC_UPDATE_VALUE;
  regs.CCR1 = FSCC_UPDATE_VALUE;
  regs.CCR2 = FSCC_UPDATE_VALUE;

  regs.SSR = FSCC_UPDATE_VALUE;
  regs.SMR = FSCC_UPDATE_VALUE;

  regs.TSR = FSCC_UPDATE_VALUE;
  regs.TMR = FSCC_UPDATE_VALUE;

  fscc_get_registers(h, &regs); 

  fscc_get_rx_multiple(h, &rx_multiple_status);

  printf("Status of FSCC-LVDS registers for port %i:\n", port);
  printf("CCR0: %" PRIx64 "\n", regs.CCR0);
  printf("CCR1: %" PRIx64 "\n", regs.CCR1);
  printf("CCR2: %" PRIx64 "\n", regs.CCR2);
  printf("\n");
  printf("SSR: %" PRIx64 "\n", regs.SSR);
  printf("SMR: %" PRIx64 "\n", regs.SMR);
  printf("\n");
  printf("TSR: %" PRIx64 "\n", regs.TSR);
  printf("TMR: %" PRIx64 "\n", regs.TMR);
  printf("\n");
  printf("Rx-Multiple status: %u\n", rx_multiple_status);

#ifdef TRY_SINGLE
  for ( i = 0; i < 2; i++){

    memset(&idata, 0, sizeof(idata));


    /* Do some reading */
    e = fscc_read_with_timeout(h, idata, sizeof(idata), &bytes_read, timeout);
    if( e == 16001) {
      fscc_disconnect(h);
      fprintf(stderr,"FSCC_INCRORRECT_MODE\n");
      return EXIT_FAILURE;
    }
    else if( e == 16002 ) { 
      fscc_disconnect(h); 
      fprintf(stderr,"FSCC_BUFFER_TOO_SMALL\n");
      return EXIT_FAILURE; 
    } 
    else if( e != 0) { 
      fscc_disconnect(h);
      fprintf(stderr,"Some error or other. Tough to say.\n");
    }
    
    /* Write the data */
    printf("Got some data, gonna write it out...\n");
    fwrite(idata, sizeof(idata[0]), sizeof(idata)/sizeof(idata[0]), fp);
  }
#endif


  //ifdef TRY_LOOP
  fprintf(stdout, "Press any key to stop collecting data...\n");

  while (_kbhit() == 0) {
    /* while (i < 10) { */
    bytes_read = 0;
    bytes_stored = 0;

    memset(&idata, 0, sizeof(idata));

    e = fscc_read_with_timeout(h, idata, sizeof(idata), &bytes_read, timeout);
    if( e == 16001) {
      fscc_disconnect(h);
      fprintf(stderr,"FSCC_INCRORRECT_MODE\n");
      return EXIT_FAILURE;
    }
    else if( e == 16002 ) {
      fscc_disconnect(h);
      fprintf(stderr,"FSCC_BUFFER_TOO_SMALL\n");
      return EXIT_FAILURE;
    }
    else if( e != 0) {
      fscc_disconnect(h);
      fprintf(stderr,"Some error or other. Tough to say.\n");
      return EXIT_FAILURE; 
    } 
    
    if (bytes_read) {
      total_bytes_read += bytes_read;
      bytes_stored = fwrite(idata, 1, bytes_read, fp);
      if (bytes_stored != bytes_read)
	fprintf(stderr, "error writing to file\n");
      else if ((i++ % 1000) == 0) 
	printf("Read %i bytes of data\n", bytes_stored);
    }
  }

  fprintf(stdout, "Total: Read %i bytes of data\n", total_bytes_read);
  //#endif

  fscc_disconnect(h);
  fclose(fp);
    
  return EXIT_SUCCESS;
}