[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-arm-kernel
Subject:    Re: Regarding Serial Driver on SA1110
From:       pradeep <pradeep () smic ! co ! kr>
Date:       2002-10-29 7:45:19
[Download RAW message or body]

Hi everybody ,

Thanks,

The code works  just fine , now I am able to set the serial terminal
in raw mode and read  a character , but onething I noticed is    that
when  I press return key the  cursor doesnot  return to the start of
newline  but the current cursor position in the new line , How  can
get this woking ?, I tried setting  OCRNL , ONLCR and ONLRET
macros in c_oflag but nothing seems to work .


Thanks,

Pradeep


npat@inaccessnetworks.com wrote:

> On Mon, Oct 28, 2002 at 03:23:00PM +0900, pradeep wrote:
> > I am trying to get  my  board receive a single charater
> > at a time on Serial Port 3 of SA1110, but it seems to receive characters
> > at a time when it receives a carriage return
>
> Seem you haven't set the tty at raw-mode. Try using the following
> functions in you application. Call them before writting to / reading
> from the terminal. tty_raw() sets the tty to raw-mode. tty_reset()
> puts it back to its original mode.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <termios.h>
>
> int save_fd = -1;
>
> void
> tty_reset (void)
> {
>     if ( save_fd >= 0 ) {
>         fprintf(stderr, "Reseting device attributes\n");
>         tcsetattr(save_fd, TCSAFLUSH, &save_tios);
>         save_fd = -1;
>     }
> }
>
> int
> tty_raw (int fd, int baud, char flowc,
>          char databits, char parity, char stopbits)
> {
>     struct termios tios;
>
>     if (tcgetattr(fd, &save_tios) < 0) {
>         perror("Cannot get tty attributes");
>         return -1;
>     }
>
>     /* make sure the device will be reset on exit */
>     save_fd = fd;
>     if ( atexit(tty_reset) < 0 ) {
>         fprintf(stderr, "Cannot arrange for atexit handler\n");
>         return -1;
>     }
>
>     tios = save_tios;
>
>     /* raw device sttings */
>     cfmakeraw(&tios);
>
>     /* character size (databits) */
>     tios.c_cflag &= ~(CSIZE);
>     switch (databits) {
>     case '5':
>         tios.c_cflag |= CS5;
>         break;
>     case '6':
>         tios.c_cflag |= CS6;
>         break;
>     case '7':
>         tios.c_cflag |= CS7;
>         break;
>     case '8':
>         tios.c_cflag |= CS8;
>         break;
>     default:
>         fprintf(stderr,"Invalid databits: %d\n", databits);
>         return -1;
>     }
>
>     /* parity (E = even, O = odd, N = no)  */
>     switch (parity) {
>     case 'E':
>     case 'e':
>         tios.c_cflag |= PARENB;
>         tios.c_cflag &= ~(PARODD);
>         break;
>     case 'O':
>     case 'o':
>         tios.c_cflag |= PARENB;
>         tios.c_cflag |= PARODD;
>         break;
>     case 'N':
>     case 'n':
>         tios.c_cflag &= ~(PARENB);
>         break;
>     default:
>         fprintf(stderr, "Invalid parity: %c\n", parity);
>         return -1;
>     }
>
>     /* stopbits (1 or 2) */
>     switch (stopbits) {
>     case '1':
>         tios.c_cflag &= ~(CSTOPB);
>         break;
>     case '2':
>         tios.c_cflag |= CSTOPB;
>         break;
>     default:
>         fprintf(stderr,"Invalid stopbits: %d\n", stopbits);
>         return -1;
>     }
>
>     /* flow control type (h = RTC/CTS, s = XON/XOFF, n = none) */
>     switch (flowc) {
>     case 'h':
>         tios.c_cflag |= CRTSCTS;
>         tios.c_iflag &= ~(IXON | IXOFF);
>         break;
>     case 's':
>         tios.c_cflag &= ~(CRTSCTS);
>         tios.c_iflag |= (IXON | IXOFF);
>         break;
>     case 'n':
>         tios.c_cflag &= ~(CRTSCTS);
>         tios.c_iflag &= ~(IXON | IXOFF);
>         break;
>     default:
>         fprintf(stderr,"Invalid flow control: %c\n", flowc);
>         return -1;
>     }
>
>     tios.c_cc[VMIN] = 1;
>     tios.c_cc[VTIME] = 0;
>
>     /* baud-rate */
>     switch(baud) {
>     case 1200:
>         baud = B1200;
>         break;
>     case 2400:
>         baud = B2400;
>         break;
>     case 4800:
>         baud = B4800;
>         break;
>     case 9600:
>         baud = B9600;
>         break;
>     case 19200:
>         baud = B19200;
>         break;
>     case 38400:
>         baud = B38400;
>         break;
>     case 57600:
>         baud = B57600;
>         break;
>     case 115200:
>         baud = B115200;
>         break;
>     case 230400:
>         baud = B230400;
>         break;
>     default:
>         fprintf(stderr,"Invalid baud-rate: %d\n", baud);
>         return -1;
>     }
>
>     if ( cfsetospeed(&tios, baud) < 0 ) {
>         perror("Cannot set output speed");
>         return -1;
>     }
>     if ( cfsetispeed(&tios, baud) < 0 ) {
>         perror("Cannot set input speed");
>         return -1;
>     }
>
>     /* set the new attributes. let them take effect now */
>     if ( tcsetattr(fd, TCSANOW, &tios) < 0 ) {
>         perror("Cannot set device attributes");
>         return -1;
>     }
>
>     /* flush the device, of any remains before the switch */
>     if ( tcflush(fd, TCIOFLUSH) < 0 ) {
>         perror("Cannot flush the device");
>         return -1;
>     }
>
>     return 0;
> }
>
> /npat
>
> --
> Morality is always the product of terror; its chains and
> strait-waistcoats are fashioned by those who dare not trust others,
> because they dare not trust themselves, to walk in liberty.
>   -- Aldous Huxley
>
> -------------------------------------------------------------------
> Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
> FAQ/Etiquette:       http://www.arm.linux.org.uk/armlinux/mailinglists.php


-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ/Etiquette:       http://www.arm.linux.org.uk/armlinux/mailinglists.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic