FreeCalypso > hg > fc-sim-tools
diff serial/serport.c @ 38:1d96f3b4f155
serial: started with fcsim-serial-atr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 Mar 2021 19:19:46 +0000 |
parents | |
children | 61a8ac93764f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serial/serport.c Sat Mar 20 19:19:46 2021 +0000 @@ -0,0 +1,57 @@ +#include <sys/types.h> +#include <sys/file.h> +#include <sys/ioctl.h> +#include <asm/ioctls.h> +#include <asm/termbits.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int target_fd; + +open_serial_port(ttyport) + char *ttyport; +{ + target_fd = open(ttyport, O_RDWR|O_NONBLOCK); + if (target_fd < 0) { + perror(ttyport); + exit(1); + } + ioctl(target_fd, TIOCEXCL); + return 0; +} + +set_serial_params(br) +{ + struct termios2 target_termios; + + target_termios.c_iflag = IGNBRK; + target_termios.c_oflag = 0; + target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8|CSTOPB|PARENB; + target_termios.c_lflag = 0; + target_termios.c_cc[VMIN] = 1; + target_termios.c_cc[VTIME] = 0; + target_termios.c_ispeed = br; + target_termios.c_ospeed = br; + if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) { + perror("TCSETSF2"); + exit(1); + } + return 0; +} + +set_serial_nonblock(state) + int state; +{ + ioctl(target_fd, FIONBIO, &state); +} + +serial_card_reset() +{ + int mctl_arg = TIOCM_DTR | TIOCM_RTS; + + ioctl(target_fd, TIOCMBIS, &mctl_arg); + usleep(20000); + ioctl(target_fd, TCFLSH, TCIFLUSH); + ioctl(target_fd, TIOCMBIC, &mctl_arg); +}