123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "bus.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "io.h"
- #ifdef __linux__
- #ifndef ARM
- int fifos[128];
- #endif
- #endif
- void write_pin(int pin, int value)
- {
- #ifdef __linux__
- #ifndef ARM
- char c = (value)?'1':'0';
- write(fifos[pin], &c, 1);
- #else
- digitalWrite(pin, value);
- #endif
- #else
- digitalWrite(pin, value);
- #endif
- }
- int read_pin(int pin)
- {
- #ifdef __linux__
- #ifndef ARM
- int f = fifos[pin];
- int c=0;
- while(read(fifos[pin], &c,1)<=0)usleep(10);
- return (c=='0')?0:1;
- #else
- return digitalRead(pin);
- #endif
- #else
- return digitalRead(pin);
- #endif
- }
- void init_read_pin(int d, int clk, int ack)
- {
- #ifdef __linux__
- #ifndef ARM
- fifos[d]=open("/tmp/fifodata", O_RDONLY | O_NONBLOCK);
- fifos[clk]=open("/tmp/fifoclk", O_RDONLY | O_NONBLOCK);
- fifos[ack]=open("/tmp/fifoack", O_WRONLY );
- #else
- pinMode(d, INPUT);
- pinMode(clk, INPUT);
- pinMode(ack, OUTPUT);
- #endif
- #else
- pinMode(d, INPUT);
- pinMode(clk, INPUT);
- pinMode(ack, OUTPUT);
- #endif
- }
- void init_write_pin(int d, int clk, int ack)
- {
- #ifdef __linux__
- #ifndef ARM
- fifos[d]=open("/tmp/fifoack", O_RDONLY | O_NONBLOCK);
- fifos[clk]=open("/tmp/fifodata", O_WRONLY);
- fifos[ack]=open("/tmp/fifoclk", O_WRONLY);
- #else
- pinMode(d, OUTPUT);
- pinMode(clk, OUTPUT);
- pinMode(ack, INPUT);
- #endif
- #else
- pinMode(d, OUTPUT);
- pinMode(clk, OUTPUT);
- pinMode(ack, INPUT);
- #endif
- }
- void free_fifo(int d, int clk, int ack)
- {
- #ifdef __linux__
- #ifndef ARM
- close(fifos[d]);
- close(fifos[clk]);
- close(fifos[ack]);
- #endif
- #endif
- }
|