1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-13 01:29:57 +00:00

Make serial device sort of work. One way.

This commit is contained in:
Radosław Kujawa 2017-02-22 22:46:10 +01:00
parent dcf275939b
commit 6f875e13e7

View File

@ -11,7 +11,7 @@
#include "bus.h" #include "bus.h"
#include "device.h" #include "device.h"
const static char *pipepath = "/tmp/serial"; /* should really be configurable */ const static char *pipepath = "/tmp/serial_tx"; /* should really be configurable */
struct device_serial_priv { struct device_serial_priv {
int pipefd; int pipefd;
@ -43,6 +43,8 @@ device_serial_write_1(void *vd, uint16_t offset, uint8_t val)
d = (device_t *) vd; d = (device_t *) vd;
dp = d->aux; dp = d->aux;
/*fprintf(stderr, "writing to fd %d val %x", dp->pipefd, val);*/
write(dp->pipefd, &val, 1); write(dp->pipefd, &val, 1);
fsync(dp->pipefd); fsync(dp->pipefd);
} }
@ -65,8 +67,13 @@ device_serial_init()
dp = (struct device_serial_priv *) malloc(sizeof(struct device_serial_priv)); dp = (struct device_serial_priv *) malloc(sizeof(struct device_serial_priv));
d->aux = dp; d->aux = dp;
if (mkfifo(pipepath, S_IRUSR | S_IWUSR) != 0) {
fprintf(stderr, "Creating FIFO for serial port failed!\n");
/* perror, handle this failure... */
}
dp->pipefd = mkfifo(pipepath, 600); dp->pipefd = open(pipepath, O_RDWR);
return d; return d;
} }
@ -75,6 +82,6 @@ void
device_serial_finish(device_t *d) device_serial_finish(device_t *d)
{ {
free(d->aux); free(d->aux);
//close pipe //close pipe etc.
} }