How to add serial driver to RTEMS?

Yanjun Luo yjluo at panjet.net
Fri Sep 3 05:59:34 UTC 2004


Hi all,
My serial port driver running now!

Thanks for Jay's kindly help, after I clean up the code,
I'll send a patch. If anyone what the code now, I'll send
my mass code to him:-)

As I know before, 9200's USART is very similar with DBGU,
so I port Jay's DBGU code to support USART, acctually I 
only changed part of the DBGU'd driver.

Regards,
Yanjun Luo.


On Wed, 1 Sep 2004 23:46:06 -0500, Jay Monkman wrote
> On Wed, Sep 01, 2004 at 07:14:27PM +0800, Yanjun Luo wrote:
> > my code:
> > -----------------------------------------------------------------
> > #define TEST_STRING	"This is only a USART test!\n"
> > 
> >   fd0 = fopen ("/dev/console", O_RDWR);
> >   if(fd0 == -1) printf("/dev/console open failed!!\n");       
> >   else
> >   	printf("console opened!\n");
> >   fwrite(TEST_STRING,1,sizeof(TEST_STRING),fd0);
> > -----------------------------------------------------------------
> 
> This is wrong. The second argument to fopen() is a string, like "r+"
> or "a". You are using the argument for open(), which takes a number.
> 
> fopen() returns a FILE*, and open() returns an int. On failure, fopen
> returns a NULL, so your test (fd0 == -1) is wrong.
> 
> Your call to open() probably failed because you didn't increase the
> maximum number of file descriptors. The default is 3, just enough for
> stdin, stdout, and stderr. You set the value by defining
> CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS before #include-ing
> confdefs.h.
> 
> Here's my test program:
> 
> #include <bsp.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <string.h>
> 
> rtems_task Init(
>   rtems_task_argument ignored
> )
> {
>     int fd;
>     extern int errno;
>     FILE *fp;
>     char string[] = "   testing ... 1 ... 2 ... 3\n";
> 
>     printf("Starting test\n");
> 
>     printf("Trying open()\n");
>     fd = open("/dev/console", O_RDWR);
>     if (fd < 1) {
>         printf("open() returned an error (%d). errno = %d\n",
>                fd, errno);
>     } else {
>         printf("Going to write() to /dev/console\n");
>         write(fd, string, strlen(string));
>         close(fd);
>     }
>     printf("open() done\n");
> 
>     printf("Trying fopen()\n");
>     fp = fopen("/dev/console", "r+");
>     if (fp == NULL) {
>         printf("fopen() returned NULL. errno = %d\n", errno);
>     } else {
>         printf("Going to fwrite() to /dev/console\n");
>         fwrite(string, strlen(string), 1, fp);
>         fclose(fp);
>     }
>     printf("fopen() done\n");
> 
>     exit( 0 );
> 
> }
> 
> /* configuration information */
> 
> #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10
> 
> #define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
> 
> #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
> 
> #define CONFIGURE_MAXIMUM_TASKS 1
> 
> #define CONFIGURE_INIT
> 
> #include <confdefs.h>




More information about the users mailing list