view serial/serport.c @ 93:6041c601304d

fcsim1-mkprov: revert OTA key addition It appears that GrcardSIM2 cards (which is what we got for FCSIM1) do not support OTA after all, contrary to what we were previously led to believe by some tech support emails from Grcard - apparently those support emails and OTA descriptions referred to some other card model(s).
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 21 Apr 2021 05:38:39 +0000
parents fbedb67d234f
children
line wrap: on
line source

/*
 * This module implements the guts of OS-specific serial port handling
 * for our fc-sim-tools serial back end.  The present version is very
 * Linux-specific, using Linux-specific <asm/...> header files,
 * struct termios2 and BOTHER to request arbitrary serial baud rates
 * outside of POSIX Bxxx rigid set.
 */

#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(bps, parity)
{
	struct termios2 target_termios;

	target_termios.c_iflag = IGNBRK|IGNPAR;
	target_termios.c_oflag = 0;
	target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8|CSTOPB|PARENB;
	if (parity == 1)
		target_termios.c_cflag |= PARODD;
	target_termios.c_lflag = 0;
	target_termios.c_cc[VMIN] = 1;
	target_termios.c_cc[VTIME] = 0;
	target_termios.c_ispeed = bps;
	target_termios.c_ospeed = bps;
	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);
}