Using TTY Drivers with i386/pc386 BSP
Mike Siers
mikes at poliac.com
Wed Apr 4 17:46:51 UTC 2001
Hi,
I am trying to use the tty serial device drivers for the
pc386 BSP. The code below is my test code to open up the
serial port, configure it, and write out some text data.
I tested this code under OpenBSD with the exact same hardware
and it works fine. When I run the code under RTEMS it says
the /dev/ttyS1 device is initialized but the open command
fails. Any help would be greatly appreciated.
Thanks
Mike Siers
===========================================================
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#define CONFIGURE_INIT
#include <rtems.h>
#include <tty_drv.h>
/* functions */
rtems_task Init(rtems_task_argument argument);
#include <bsp.h>
#define CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE
rtems_driver_address_table Device_drivers[3] = {
CONSOLE_DRIVER_TABLE_ENTRY,
TTY1_DRIVER_TABLE_ENTRY,
{NULL, NULL, NULL, NULL, NULL, NULL}
};
#define CONFIGURE_MAXIMUM_TASKS 4
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
#include <confdefs.h>
rtems_task Init(rtems_task_argument argument)
{
int i;
int iStatus;
int iLength;
int iFile;
struct termios options;
char *pData = "YEP-YEP-YEP\r\n";
puts( "\n\n*** SERIAL TEST ***" );
iFile = open("/dev/ttyS1", O_RDWR|O_NOCTTY);
if ( iFile == -1 ) {
puts("*** PORT /dev/ttyS1 OPEN FAILED ***");
}
else {
fcntl(iFile, F_SETFL, 0);
tcgetattr(iFile, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL|CREAD|CS8);
options.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG);
options.c_oflag &= ~(OPOST);
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
tcsetattr(iFile, TCSANOW, &options);
iLength = strlen(pData);
for (i=0; i<20; i++) {
iStatus = write(iFile, (void *)pData, iLength);
if ( iStatus < iLength ) {
puts("*** PORT /dev/ttyS1 WRITE FAILED ***");
}
}
close(iFile);
iFile = (int)-1;
}
}
===========================================================
More information about the users
mailing list