[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [microblaze-uclinux] Uartlite timing broken?(trying to grab frames in non-canonical mode)
Hello,
I use the function in the attachment to get a raw serial communication channel between
two devices.
The function uses glib-2.0 calls but the important statements for the initialization
of the serial line are simple libc calls.
Hope this helps,
Johann
Nils Hermansson <Nils.Hermansson@xxxxxxxxxxxxxx> wrote:
> Hello everyone,
> have come across a problem when trying to grab modbus frames on the 2nd uart.
> The problem I am having is that I am unable to grab complete frames going on the uart when using VTIME. I really do not now where to start looking for the problem is it a driver problem or is it the uart IP block which does not work. I have checked with an oscilloscope and with third part hardware that the messages on the line are correct so either it's a hardware problem on my ml505 platform or it's the uartlite driver where timing is broken.
>
> Interesting part is that when i change VTIME there is no big difference at all on the data I get, could it be that non-canonical mode isn't implemented in the uartlite driver?
>
> Has anyone else used the uarts in non-canonical mode and got it to work?
>
> These are my termios settings.
>
> bzero(&my_termios, sizeof(my_termios));
> my_termios.c_cflag=B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
> my_termios.c_lflag = 0;
> my_termios.c_iflag = IGNPAR;
> my_termios.c_oflag = 0;
> my_termios.c_cc[VMIN] = 2;
> my_termios.c_cc[VTIME] = 20;
>
> Best regards
> Nils Hermansson
>
--
Dr. Johann Pfefferl --------------- mailto pfefferl at gmx dot net
==
-o) A computer program does what you tell it to do,
/\\ not what you want it to do.
_\_v-
static gint open_tty_port(const gchar *tty, speed_t baud)
{
gint status;
gint fd;
struct termios newtio;
/* open the tty */
fd = g_open(tty, O_RDWR | O_NOCTTY);
if(0 > fd) {
g_critical("%s: %s open failed: %s", __func__, tty, g_strerror(errno));
return fd;
}
if(0 > fcntl(fd, F_SETFD, FD_CLOEXEC))
g_critical("fcntl FD_CLOEXEC failed: %s", g_strerror(errno));
if(!isatty(fd)) { /* Check if given file is a terminal line */
g_critical("%s `%s' is not a tty", __func__, tty);
close(fd);
return -1;
}
// flush serial port
status = tcflush(fd, TCIFLUSH);
if(0 > status) {
perror("tcflush");
g_critical("%s: `%s' tcflush failed: %s", __func__, tty, g_strerror(errno));
close(fd);
return -1;
}
/* get current terminal state */
tcgetattr(fd,&newtio);
// set to raw terminal type
#if 0
/* Do it yourself method */
newtio.c_cflag = baud | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNBRK | IGNPAR;
newtio.c_oflag = 0;
// Do not echo the input of the serial link back
newtio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL);
// Non canonical mode
newtio.c_lflag &= ~(ICANON|ISIG);
#else
/* Better to use a library function */
g_message("Setting terminal mode to raw");
cfmakeraw(&newtio);
#endif
/* set the speed of the line */
status = cfsetospeed(&newtio, baud);
if(0 > status) {
perror("cfsetospeed");
g_critical("%s: `%s' cfsetospeed failed: %s", __func__, tty, g_strerror(errno));
close(fd);
return -1;
}
status = cfsetispeed(&newtio, baud);
if(0 > status) {
g_critical("%s: `%s' cfsetispeed failed: %s", __func__, tty, g_strerror(errno));
close(fd);
return -1;
}
/* control parameters */
/* TIME is zero but MIN has a nonzero value.
In this case, read waits until at least MIN bytes are available in the queue.
At that time, read returns as many characters as are vailable, up to the number requested.
read can return more than MIN characters if more than MIN happen to be in the queue.
*/
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_iflag |= IXON | IXOFF;
// set its new attrigutes
status = tcsetattr(fd,TCSANOW,&newtio);
if(0 > status) {
g_critical("%s: `%s' tcsetattr failed: %s", __func__, tty, g_strerror(errno));
close(fd);
fd = -1;
}
return fd;
}