Esempio n. 1
0
int main(int argc, char **argv)
{
	int		c;
	int		readcount = 0;
	int		msglen = 0;
	int		fd;
	const char	*name;

	while ((c = getopt(argc, argv, "hm:r:v")) != EOF) {
		switch (c) {
		case 'm':
			msglen = atoi(optarg);
			if (msglen < 0)
				goto usage;
			continue;
		case 'r':
			readcount = atoi(optarg);
			if (readcount < 0)
				goto usage;
			continue;
		case 'v':
			verbose++;
			continue;
		case 'h':
		case '?':
usage:
			fprintf(stderr,
				"usage: %s [-h] [-m N] [-r N] /dev/spidevB.D\n",
				argv[0]);
			return 1;
		}
	}

	if ((optind + 1) != argc)
		goto usage;
	name = argv[optind];

	fd = open(name, O_RDWR);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	dumpstat(name, fd);

	if (msglen)
		do_msg(fd, msglen);

	if (readcount)
		do_read(fd, readcount);

	close(fd);
	return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	if (argc < 2) { fprintf(stderr, "Need spi device\n"); return 1; }

	int fd = open(argv[1], O_RDWR);
	if (fd < 0) { perror("open"); return 1;	}

	dumpstat(argv[1], fd);

	dumpregs(fd);

	close(fd);
}
Esempio n. 3
0
/* fdp_tLayout:
 * Given graph g with ports nodes, layout g respecting ports.
 * If some node have position information, it may be useful to
 * reset temperature and other parameters to reflect this.
 */
void
fdp_tLayout (graph_t* g, xparams* xpms)
{
  int       i;
  int       reset;
  bport_t*  pp = PORTS(g);
  double    temp;
  Grid*     grid;
  pointf    ctr;
  Agnode_t* n;

  reset = init_params(g, xpms);
  temp = T0;

  ctr = initPositions (g, pp);
  
  if (T_useGrid) {
    grid = mkGrid (agnnodes (g));
    adjustGrid (grid, agnnodes (g));
    for (i = 0; i < loopcnt; i++) {
      temp = cool (temp, i);
      gAdjust (g, temp, pp, grid);
    }
    delGrid (grid);
  }
  else {
    for (i = 0; i < loopcnt; i++) {
      temp = cool (temp, i);
      adjust (g, temp, pp);
    }
  }

  if ((ctr.x != 0.0) || (ctr.y != 0.0)) {
    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
      ND_pos(n)[0] += ctr.x;
      ND_pos(n)[1] += ctr.y;
    }
  }
dumpstat (g);
  if (reset) reset_params ();
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    int c, v = 0;
    int fd, fd_done, fd_int_b, fd_prog_b;
    char *name;
    char *spidev = DEFAULT_SPIDEV;
    char byte[2], mode = SPI_MODE_2;

    while ((c = getopt(argc, argv, "hm:d:v")) != EOF) {
        switch (c) {
        case 'd':
            spidev = optarg;
            continue;
        case 'm':
            mode = atoi(optarg);
            continue;
        case 'v':
            v++;
            break;
        case 'h':
        case '?':
usage:
            fprintf(stderr,
                    "usage: %s [-hv] [-d /dev/spidevB.D] [-m SPI_MODE] infile\n",
                    argv[0]);
            return 1;
        }
    }

    if ((optind + 1) != argc)
        goto usage;
    name = argv[optind];

    if (v) {
        printf("Config File\t\t: %s\n", name);
        printf("SPI device\t\t: %s\n", spidev);
    }

    fd = open(spidev, O_RDWR);
    if (fd < 0) {
        perror(spidev);
        return errno;
    }

    ioctl(fd, SPI_IOC_WR_MODE, &mode);

    fd_done = open(DEFAULT_DONE, O_RDWR);
    if (fd_done < 0) {
        perror(DEFAULT_DONE);
        return errno;
    }

    fd_int_b = open(DEFAULT_INT_B, O_RDWR);
    if (fd_int_b < 0) {
        perror(DEFAULT_INT_B);
        return errno;
    }

    fd_prog_b = open(DEFAULT_PROG_B, O_RDWR);
    if (fd_prog_b < 0) {
        perror(DEFAULT_PROG_B);
        return errno;
    }

    dumpstat(spidev, fd);

    write(fd_int_b, "I", 1);
    write(fd_done, "I", 1);

    /*
     * PROG_B should never be driven high by Blackfin.
     * Simulate open drain output. Configure as input
     * for HI and drive 0 for LOW.
     */

    write(fd_prog_b, "O0", 2);

    /*
     * Pulse PROG_B to initiate configuration sequence
     */

    usleep(1);
    write(fd_prog_b, "I", 1);
    close(fd_prog_b);

    if (v)
        printf("Waiting INT_B -> HIGH\n");

    alarm(TIMEOUT);

    /*
     * Monitor INIT_B pin goes High,
     * indicating that the FPGA is ready to receive its first data.
     */

    while (1) {
        if (read(fd_int_b, byte, 1) != 1)
            perror("unable to read device");

        if (byte[0] == '1')
            break;
        usleep(10);
    }

    close(fd_int_b);

    transfer(fd, name); /* Send FPGA bitfile by SPI */

    alarm(TIMEOUT);

    /*
     * Continue supplying data and clock signals
     * until either the DONE pin goes High, indicating a successful
     * configuration, or until the INIT_B pin goes Low, indicating a
     * configuration error.
     */

    if (v)
        printf("\nWaiting CONFIG DONE\n");

    while (1) {
        if (read(fd_done, byte, 1) != 1)
            perror("unable to read device");

        if (byte[0] == '1')
            break;
        /*
         * The configuration process requires
         * more clock cycles than indicated from the configuration file
         * size. Additional clocks are required during the FPGA's
         * start-up sequence.
         */

        write(fd, copybuf, sizeof(copybuf));
    }

    close(fd);
    close(fd_done);

    alarm(0);

    if (v)
        printf(" DONE!\n");
    else
        printf("\n");

    return 0;
}
Esempio n. 5
0
int main(){



	int fd = spi_open("/dev/spidev0.0");
	spi_mode(fd, SPI_MODE_1);
	// spi_mode(fd,  SPI_NO_CS | SPI_MODE_2);
	spi_speed(fd, MHZ_32);
	dumpstat("SPI device 0: ",fd);

	// uint16_t command = MCP3208_START_BIT | MCP3208_SINGLE_ENDED

	printf("size %d\n", sizeof(MCP_CHAN_7));

	// uint32_t foo = MCP_CHAN_7;
	// uint32_t mcp_tx = ((uint32_t)MCP_CHAN_7) << 14;
	// uint32_t mcp_rx = 0;

	uint8_t tx[] = {1,8 + 0 << 4,0,0};
	uint8_t rx[4] = {0}; 


	struct spi_ioc_transfer mcp_tr ={
		.tx_buf = (unsigned long)&tx,
		.rx_buf = (unsigned long)&rx,
		.len = 4,
		.delay_usecs = 0,
		.speed_hz = KHZ_500,
		.bits_per_word = 8,
	};


	while(1){
		spi_transfer(fd, &mcp_tr, 1);

		// printf ("B "BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_tx >> 24));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_tx >> 16));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_tx >> 8));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_tx));
		// printf("\tbuf_tx: %u\n", mcp_tx);

		// mcp_rx |= 0xff000000;
		// mcp_rx &= 0x00ffffff;
		// mcp_rx = mcp_rx >> 0;

		uint32_t ret = 0;
		ret |= (uint32_t)rx[3];
		ret |= (uint32_t)rx[2] << 8;
		ret |= (uint32_t)rx[1] << 16;
		// ret |= (uint32_t)rx[0] << 24;

		print_byte(rx[0]);
		print_byte(rx[1]);
		print_byte(rx[2]);
		print_byte(rx[3]);
		printf(" rx %d", ret >> 6);
		printf("\n");

		// printf("%d\n", rx);

		// printf ("\nA "BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_rx >> 24));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_rx >> 16));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_rx >> 8));
		// printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(mcp_rx));
		// printf("\tbuf_rx: %u\n", mcp_rx);

		nanosleep(&requested,&remaining);
	}

	// uint16_t command = get_mcp_channel_command(0);
	// printf ("Byte 00 "BYTETOBINARYPATTERN"\n", BYTETOBINARY((uint8_t)command));
	// printf ("Byte 01 "BYTETOBINARYPATTERN"\n", BYTETOBINARY((uint8_t)command >> 8));

	// printf ("Byte 00 "BYTETOBINARYPATTERN"\n", BYTETOBINARY((uint8_t)0x8));
	// printf ("Byte 01 "BYTETOBINARYPATTERN"\n", BYTETOBINARY((uint8_t)0x10));
	// printf("command %d %s\n", command, &buf);

	// dumpstat("SPI device 0: ",fd);

	spi_close(fd);

}

static void print_byte(uint8_t byte){
	printf (""BYTETOBINARYPATTERN" ", BYTETOBINARY(byte));
} 
Esempio n. 6
0
SPI::SPI(){
    dumpstat();
    setupSPI();
    dumpstat();
}