Another gensh2 questions TERMIOS console.

Correo Fernando-ruiz (E-mail) correo at fernando-ruiz.com
Tue Jan 30 21:06:46 UTC 2001




> -----Mensaje original-----
> De: rajish at ET.PUT.Poznan.PL
> [mailto:rajish at ET.PUT.Poznan.PL]En nombre de Radzislaw Galler
> Enviado el: martes, 30 de enero de 2001 14:41
> Para: jmills at tga.com
> CC: rtems-users at oarcorp.com
> Asunto: Another gensh2 questions
>
>
> Hi,
>
> I have some questions:
>
> 1. What are sections 'monvects' and 'monram' and why they need so much
> space? Looking into *.map file of an application there is nothing in
> these sections. It wastes half of RAM on my EVB.
>
>
> 2. I am hacking the console driver in gensh2 to use termios (with
> success - thanks Fernando!). The question is about
> registering files in
> system. The console driver should be the first entry in drivers table
> (otherwise it doesn't work - don't know why; system uses driver with
> major=0 which is simple SCI driver in current snapshot). When
> I want to
> link /dev/console to /dev/sci0 (serial port) it has to exist. If I
> register it in console_initialize() it will have major number 0. It
> makes no difference to driver routines because the use only
> minor number
> but right now I have /dev/sci0 with major=0 and minor=0 and /dev/sci1
> with major=1 and minor=1. Does it make sense? Is it
> dangerous? I did not
> look into another bsp's but maybe there is no sense to make separate
> drivers for console and serial ports. This wouldn't be an issue if the
> console worked independently from the location in the driver table.
>
> Regards
>
> Radek
>

A newbie story.

Howto Add a new console driver into a new BSP.
---------------------------------------------


In Your BSP directory
(copied from a generic bsp tree)

  /home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552

Note: Don't forget copy gensh1.cfg into vis552.cfg and edit it in
       /home/rtems/rtems-ss-20010126/make/custom directory


create a ~/drivers directory.

/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/drivers


Set the new directory ready to compile in the Makefile.am
adding the drivers directory in SUBDIRS variable

**************************************************************************
* /home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/Makefile.am ***
**************************************************************************

##
## $Id: Makefile.am,v 1.2 2000/06/12 14:59:51 joel Exp $
##

AUTOMAKE_OPTIONS = foreign 1.4
ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal

# wrapup is the one that actually builds and installs the library
#  from the individual .rel files built in other directories
SUBDIRS = include start startup scitab console drivers wrapup

include $(top_srcdir)/../../bsp.am

EXTRA_DIST = bsp_specs times

include $(top_srcdir)/../../../../../../automake/subdirs.am
include $(top_srcdir)/../../../../../../automake/local.am

******************************************************************

Now you need set also configure.in. Adding the new 'drivers/Makefile' in
AC_OUTPUT()

**************************************************************************
* /home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/configure.in***
**************************************************************************
dnl Process this file with autoconf to produce a configure script.
dnl
dnl $Id: configure.in,v 1.2 2000/02/08 22:33:15 joel Exp $

AC_PREREQ(2.13)
AC_INIT(bsp_specs)
RTEMS_TOP(../../../../../..)
AC_CONFIG_AUX_DIR(../../../../../..)

RTEMS_CANONICAL_TARGET_CPU
AM_INIT_AUTOMAKE(rtems-c-src-lib-libbsp-sh-vis552,$RTEMS_VERSION,no)
AM_MAINTAINER_MODE

RTEMS_PROG_CC_FOR_TARGET
RTEMS_CANONICALIZE_TOOLS

RTEMS_ENV_RTEMSBSP
RTEMS_CHECK_CUSTOM_BSP(RTEMS_BSP)
RTEMS_CHECK_BSP_CACHE(RTEMS_BSP)
RTEMS_CANONICAL_HOST

RTEMS_PROJECT_ROOT

# Explicitly list all Makefiles here
AC_OUTPUT(
Makefile
console/Makefile
drivers/Makefile
include/Makefile
scitab/Makefile
start/Makefile
startup/Makefile
wrapup/Makefile)
******************************************************************

After, in wrapup directory you need add the new directory into Makefile.am
adding drivers directory to BSP_PIECES variable

****************************************************************************
**
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/wrapup/Makefile.am
*
****************************************************************************
**
##
## $Id: Makefile.am,v 1.4 2000/09/05 15:53:58 joel Exp $
##
## build and install libbsp
##

AUTOMAKE_OPTIONS = foreign 1.4

#BSP_PIECES = startup scitab console lcd
BSP_PIECES = startup scitab console drivers

# pieces to pick up out of libcpu/sh/sh7032
CPU_PIECES = clock timer delay score

# bummer; have to use $foreach since % pattern subst rules only replace 1x
OBJS = $(foreach piece, $(BSP_PIECES), $(wildcard ../$(piece)/$(ARCH)/*.o))
\
    $(foreach piece, $(CPU_PIECES),
../../../../libcpu/$(RTEMS_CPU)/sh7032/$(piece)/$(ARCH)/$(piece).rel)

LIB = $(ARCH)/libbsp.a

include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
include $(top_srcdir)/../../../../../../automake/compile.am
include $(top_srcdir)/../../../../../../automake/lib.am

#
# (OPTIONAL) Add local stuff here using =
#

$(LIB): $(OBJS)
        $(make-library)

$(PROJECT_RELEASE)/lib/libbsp$(LIB_VARIANT).a: $(LIB)
        $(INSTALL_DATA) $< $@

TMPINSTALL_FILES += $(PROJECT_RELEASE)/lib/libbsp$(LIB_VARIANT).a

all-local: $(ARCH) $(OBJS) $(LIB) $(TMPINSTALL_FILES)

.PRECIOUS: $(LIB)

include $(top_srcdir)/../../../../../../automake/local.am


******************************************************************

Now. You are ready to build the new driver into drivers directory.

How to make this?

Create a new Makefile.am once chdir to drivers directory.

Change the C_FILES to the new C sources (sci.c & com.c in this case)
Change also EXTRA_DIST to the same list.

****************************************************************************
**
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/drivers/Makefile.a
m*
****************************************************************************
**

##
## $Id: Makefile.am,v 1.4 2000/09/05 15:53:58 joel Exp $
##

AUTOMAKE_OPTIONS = foreign 1.4

VPATH = @srcdir@:@srcdir@/../../shared:@srcdir@/../../../shared

PGM = $(ARCH)/drivers.rel

C_FILES = sci.c com.c

C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)

OBJS = $(C_O_FILES)

include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
include $(top_srcdir)/../../../../../../automake/compile.am
include $(top_srcdir)/../../../../../../automake/lib.am

#
# (OPTIONAL) Add local stuff here using +=
#

AM_CPPFLAGS += -DHZ=$(HZ)

$(PGM): $(OBJS)
        $(make-rel)

all-local: $(ARCH) $(OBJS) $(PGM)

.PRECIOUS: $(PGM)

EXTRA_DIST = sci.c com.c

include $(top_srcdir)/../../../../../../automake/local.am

***********************************************************************


Write the new source files sci.c & com.c

***********************************************************************
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/drivers/sci.c
***********************************************************************
*
 * This is a version SCI sh7032 with interrupts
 *
 * Author: Fernando RUIZ CASAS (fernando.ruiz at ctv.es)
 * Nov 2000
 *
 * From sci.c     (Ralf Corsepius)
 *      console.c (W. Eric Norum)
 *      serial.c  (Radstone Tecnology)
 *      cf-uart.c (Chris Johns)
 *      A lot of thanks at all.
 */
/*-----------------------------------------*/
#include <termios.h>
#include <bsp.h>
#include <rtems/libio.h>
#include <rtems/score/sh_io.h>
#include <rtems/score/ispsh7032.h>
#include <rtems/score/iosh7032.h>
#include <bsp_io.h>
#include <drivers.h>
/*-----------------------------------------*/
#define LV_SCI0    8
#define LV_SCI1    8
/*-----------------------------------------*/
struct rtems_termios_tty *sci0_ttyp,
                         *sci1_ttyp;
/*------------------------------------------------------*/
/*- Sorry if you find this here but a little change... -*/
/*- I have added  a baud field to sci_how_baud()       -*/
/*------------------------------------------------------*/
/*
 * Bitrate table for the serial devices (sci) of the SH at 19.660.800 Hz
 */

/*
 * n     .. SMR bits 0,1 : baud rate generator clock source
 * N     .. BRR bits 0..7: setting for baud rate generator
 * error .. percentual error to nominal bitrate
 *   Hitachi's HW manual recommends bitrates with an error less than 1%
 *   We experienced values less than 2% to be stable
 */

static struct sci_bitrate_t {
  unsigned char n ;
  unsigned char N ;
           int  baud;
  tcflag_t      cbaud;
} _sci_bitrates[] = {
/*  n    N      error */
  { 3, 191 ,    50, B50 },
  { 3, 127 ,    75, B75 },
  { 3,  86 ,   110, B110 },
  { 3,  71 ,   134, B134 },
  { 2, 255 ,   150, B150 },
  { 2, 191 ,   200, B200 },
  { 2, 127 ,   300, B300 },
  { 1, 255 ,   600, B600 },
  { 1, 127 ,  1200, B1200 },
  { 1,  84 ,  1800, B1800 },
  { 0, 255 ,  2400, B2400 },
  { 0, 127 ,  4800, B4800 },
  { 0,  63 ,  9600, B9600 },
  { 0,  31 , 19200, B19200 },
  { 0,  15 , 38400, B38400 },
  { 0,  10 , 57600, B57600 },
  { 0,   4 ,115200, B115200 },
  { 0,   2 ,230400, B230400 },
  { 255, 0 ,460800, B460800 }
};

/*-----------------------------------------*/
int _sci_get_brparms(
  tcflag_t      cflag,
  unsigned char *smr,
  unsigned char *brr )
{
  unsigned int offset,max,ofs9600;
  ofs9600=0;
  max=sizeof(_sci_bitrates)/sizeof(_sci_bitrates[0]);
  for (offset=0;offset<max;offset++) {
   if (_sci_bitrates[offset].cbaud==(cflag&CBAUD)) break;
   if (_sci_bitrates[offset].cbaud==B9600) ofs9600=offset;
  };
  if (offset>=max) offset=ofs9600;

  *smr &= ~0x03;
  *smr |= _sci_bitrates[offset].n;
  *brr =  _sci_bitrates[offset].N;

  return 0;
}
/*-----------------------------------------*/
int _sci_how_baud( unsigned char smr,
                   unsigned char brr ) {
  int offset,n,N;
  n=smr&0x03;
  N=brr;
  for
(offset=0;offset<(sizeof(_sci_bitrates)/sizeof(_sci_bitrates[0]));offset++)
{
   if ((n==_sci_bitrates[offset].n) && (N==_sci_bitrates[offset].N))
           return _sci_bitrates[offset].baud;
  };
  return -1;
}
/*-----------------------------------------------------------*/
void sciDummy (void) {
  asm("nop");
}
/*-----------------------------------------------------------*/
void sciDelay(int value) {
        wdc_reset();
        while (value--) sciDummy();
}
/*-----------------------------------------------------------*/
static int sciSetAttributes(int minor,const struct termios *t);
static int sciIntrInitialize(int major,int minor,void * arg) ;
static int sciPollInitialize(int major,int minor,void * arg) ;
static int sciShutdown(int major,int minor,void * arg) ;
static int sciIntrWrite(int minor, const char * buf,int len) ;
static int sciPollWrite(int minor, const char * buf,int len) ;
static int sciPollRead(int minor) ;
static rtems_isr sciInterruptHandler (rtems_vector_number v) ;
const rtems_termios_callbacks * sci_get_termios_handlers(int polled) ;
const rtems_termios_callbacks * sci_get_termios_handlers(int polled) ;
/*-----------------------------------------------------------*/
/* Translate termios' tcflag_t into sci settings */
/*-----------------------------------------------------------*/
static int set_cflags(
  unsigned char *smr,
  unsigned char *brr,
  tcflag_t      c_cflag )
{
  TSMR Smr; /* BSP_IO.H */
  /* Set the baudrate */
  if ( c_cflag & CBAUD )
  {
    if ( _sci_get_brparms( c_cflag, smr, brr ) != 0 )
      return -1 ;
  }
  *((unsigned char *)&Smr)= *smr;
  /* Set the wordlen */
  if ( c_cflag & CSIZE )
  {
    if ( c_cflag & CS8 )
      Smr._CHR=0;
    else if ( c_cflag & CS7 )
      Smr._CHR=1;
    else
      return -1 ;
  }
  /* Set stop bits */
  if ( c_cflag & CSTOPB )
    Smr._STOP=1;
  else
    Smr._STOP=0;
  /* Set Parity */
  if ( c_cflag & PARENB )
    Smr._PE=1;
  else
    Smr._PE=0;
  if ( c_cflag & PARODD )
    Smr._OE=1;
  else
    Smr._OE=0;
  *((TSMR*) smr)=Smr;
  return 0 ;
}
/*-----------------------------------------------------------*/
/*- If you have a lcd driver you can debug a sci port...    -*/
/*-----------------------------------------------------------*/


static void sciDebug(void) {
}
/*-----------------------------------------------------------*/
/* Set the Hardware                                          */
/*-----------------------------------------------------------*/
static int
sciSetAttributes(int minor,const struct termios *t) {
  unsigned char smr;
  unsigned char brr;
  unsigned char rie;
  unsigned char pl ;
  if (set_cflags(&smr,&brr,t->c_cflag)<0) return -1;
  if (minor==0) {
        /* Disable TE, RE */
        SCI0_TE =0;
        SCI0_RE =0;
        /* Clear Priority Level SCI0 */
        pl=PL_SCI0;
        PL_SCI0=0;
        /* Disable Pins TX0,RX0,Sck-Pin */
        SET_PB8_IO();
        SET_PB9_IO();

        SCI0_SMR_=smr;
        SCI0_BRR_=brr;

        /* Async Mode */
        SCI0_CKE=0;

        /* Disable RIE, TIE, ... */
        rie=SCI0_RIE;
        SCI0_RIE=0;
        SCI0_TIE=0;
        SCI0_TEIE=0;
        SCI0_MPIE=0;

        sciDelay(5000);

        /* Enable TE, RE */
        SCI0_TE =1;
        SCI0_RE =1;

        /* Clear source of Interrupts */
        while (SCI0_RDRF || SCI0_ORER || SCI0_FER || SCI0_PER )  {
               if (SCI0_RDRF) SCI0_RDRF=0;
               if (SCI0_ORER) SCI0_ORER=0;
               if (SCI0_FER ) SCI0_FER =0;
               if (SCI0_PER ) SCI0_PER =0;
        };

        SCI0_RIE=rie;
        /* Enable Pins TX0,RX0 */
        SET_PB9_TXD0();
        SET_PB8_RXD0();

        PL_SCI0=pl;
        sciDebug();
  } else
  if (minor==1) {
        SCI1_TE =0;
        SCI1_RE =0;
        /* Clear Priority Level SCI1 */
        pl=PL_SCI1;
        PL_SCI1=0;
        /* Disable Pins TX1,RX1,Sck-Pin */
        SET_PB10_IO();
        SET_PB11_IO();

        /* Disable RIE, TIE, TE, RE */
        SCI1_SMR_=smr;
        SCI1_BRR_=brr;

        /* Async Mode */
        SCI1_CKE=0;

        rie=SCI0_RIE;
        SCI1_RIE=0;
        SCI1_TIE=0;
        SCI0_TEIE=0;
        SCI0_MPIE=0;

        sciDelay(5000);

        /* Enable  TE, RE & Clock Output */
        SCI1_TE =1;
        SCI1_RE =1;

        /* Clear source of Interrupts */
        while (SCI1_RDRF || SCI1_ORER || SCI1_FER || SCI1_PER )  {
               if (SCI1_RDRF) SCI1_RDRF=0;
               if (SCI1_ORER) SCI1_ORER=0;
               if (SCI1_FER ) SCI1_FER =0;
               if (SCI1_PER ) SCI1_PER =0;
        };
        SCI1_RIE=rie;

        /* Enable Pins TX0,RX0 */
        SET_PB11_TXD1();
        SET_PB10_RXD1();

        PL_SCI1=pl;
        sciDebug();
  } else {
          return -1;
  };
  return 0;
}
/*-----------------------------------------------------------*/
static int
sciIntrInitialize(int major,int minor,void * arg) {
        rtems_isr_entry old_vector;
        rtems_libio_open_close_args_t * args = arg;
        struct termios t;

        if (minor==0) {
                sh_set_irq_priority(ERI0_ISP_V,0); /* Disable IRQ SCI0*/
                SCI0_RIE=0;
                sci0_ttyp=args->iop->data1;
                t.c_cflag=B9600|CS8;
                if (sciSetAttributes(minor,&t)<0) return -1;

rtems_interrupt_catch(sciInterruptHandler,ERI0_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,RXI0_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,TXI0_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,TEI0_ISP_V,&old_vector);
                SCI0_RIE=1;
                sh_set_irq_priority(ERI0_ISP_V,LV_SCI0); /* Enable IRQ
SCI0*/
                sciDebug();
        } else
        if (minor==1) {
                sh_set_irq_priority(ERI1_ISP_V,0); /* Disable IRQ SCI1*/
                SCI1_RIE=0;
                sci1_ttyp=args->iop->data1;
                t.c_cflag=B9600|CS8;
                if (sciSetAttributes(minor,&t)<0) return -1;

rtems_interrupt_catch(sciInterruptHandler,ERI1_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,RXI1_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,TXI1_ISP_V,&old_vector);

rtems_interrupt_catch(sciInterruptHandler,TEI1_ISP_V,&old_vector);
                SCI1_RIE=1;
                sh_set_irq_priority(ERI1_ISP_V,LV_SCI1); /* Enable IRQ
SCI1*/
                sciDebug();
        } else {
                return -1;
        };
        return 0;
}
/*-----------------------------------------------------------*/
static int
sciPollInitialize(int major,int minor,void * arg) {
        rtems_libio_open_close_args_t * args = arg;
        struct termios t;

        if (minor==0) {
                sh_set_irq_priority(ERI0_ISP_V,0); /* Disable IRQ SCI0*/
                SCI0_RIE=0;
                SCI0_TIE=0;
                sci0_ttyp=args->iop->data1;
                t.c_cflag=B9600|CS8;
                return sciSetAttributes(minor,&t);
        } else
        if (minor==1) {
                sh_set_irq_priority(ERI1_ISP_V,0); /* Disable IRQ SCI1*/
                SCI1_RIE=0;
                SCI1_TIE=0;
                sci1_ttyp=args->iop->data1;
                t.c_cflag=B9600|CS8;
                return sciSetAttributes(minor,&t);
        } else {
                return -1;
        };
}
/*-----------------------------------------------------------*/
static int
sciShutdown(int major,int minor,void * arg) {

        minor%=2;
        if (minor==0) {
                SCI0_RIE=0;
                SCI0_TIE=0;
                sh_set_irq_priority(ERI0_ISP_V,0); /* Disable IRQ SCI0*/
                sciDebug();
        } else
        if (minor==1) {
                SCI1_TIE=0;
                SCI1_RIE=0;
                sh_set_irq_priority(ERI1_ISP_V,0); /* Disable IRQ SCI1*/
                sciDebug();
        } else {
                return -1;
        };
        return 0;
}
/*-----------------------------------------------------------*/
/* Write Characters into sci device                          */
/*-----------------------------------------------------------*/
static int
sciIntrWrite(int minor, const char * buf,int len) {
        if (len<=0) return 0;
        if (minor==0) {
                SCI0_TDR_=*buf;
                SCI0_TDRE=0;/* Notify TDRE for a new Intr */
                SCI0_TIE=1;
                return 1;
        } else
        if (minor==1) {
                SCI1_TDR_=*buf;
                SCI1_TDRE=0;/* Notify TDRE for a new Intr */
                SCI1_TIE=1;
                return 1;
        } else {
                return 0;
        };
}
/*-----------------------------------------------------------*/
static int
sciPollWrite(int minor, const char * buf,int len) {
        int count=0;
        while (len--) {
         if (minor==0) {
                while (!SCI0_TDRE) sciDummy();
                SCI0_TDR_=*buf++;
                SCI0_TDRE=0;
         } else
         if (minor==1) {
                while (!SCI1_TDRE) sciDummy();
                SCI1_TDR_=*buf++;
                SCI1_TDRE=0;
         } else {
                return 0;
         };
         count++;
        };
        return count;
}
/*-----------------------------------------------------------*/
static int
sciPollRead(int minor) {
        int value=-1;
        if (minor==0) {
               if (SCI0_ORER) SCI0_ORER=0;
               if (SCI0_FER ) SCI0_FER =0;
               if (SCI0_PER ) SCI0_PER =0;
               if (SCI0_RDRF) {
                        SCI0_RDRF=0;
                        value=SCI0_RDR_;
               };
        } else
        if (minor==1) {
               if (SCI1_ORER) SCI1_ORER=0;
               if (SCI1_FER ) SCI1_FER =0;
               if (SCI1_PER ) SCI1_PER =0;
               if (SCI1_RDRF) {
                        SCI1_RDRF=0;
                        value=SCI1_RDR_;
               };
        };
        return value;
}
/*-----------------------------------------------------------*/
/* Interrupt Handler                                         */
/*-----------------------------------------------------------*/
static rtems_isr
sciInterruptHandler (rtems_vector_number v) {
        unsigned char value;
        if (v==ERI0_ISP_V) { /* Line Error */
               if (SCI0_ORER) SCI0_ORER=0;
               if (SCI0_FER ) SCI0_FER =0;
               if (SCI0_PER ) SCI0_PER =0;
        } else
        if (v==ERI1_ISP_V) {  /* Line Error */
               if (SCI1_ORER) SCI1_ORER=0;
               if (SCI1_FER ) SCI1_FER =0;
               if (SCI1_PER ) SCI1_PER =0;
        } else
        if (v==RXI0_ISP_V) {  /* Buffer Received */
                if (SCI0_RDRF) {
                 value=SCI0_RDR_;
                 rtems_termios_enqueue_raw_characters(sci0_ttyp,&value,1);
                 SCI0_RDRF=0;
                } else {
                };
        } else
        if (v==RXI1_ISP_V) {  /* Buffer Received */
                if (SCI1_RDRF) {
                 value=SCI1_RDR_;
                 rtems_termios_enqueue_raw_characters(sci1_ttyp,&value,1);
                 SCI1_RDRF=0;
                } else {
                };
        } else
        if (v==TXI0_ISP_V) {  /* Buffer Transmitted */
                SCI0_TIE=0; /* No Chars left, Stop Transmision */
                if (rtems_termios_dequeue_characters(sci0_ttyp,1)) {
                        SCI0_TIE=1; /* Chars left, Notify a New Intr */
                };
        } else
        if (v==TXI1_ISP_V) { /* Buffer Transmitted */
                SCI1_TIE=0; /* No Chars left, Stop Transmision */
                if (rtems_termios_dequeue_characters(sci1_ttyp,1)) {
                        SCI1_TIE=1; /* Chars left, Notify a New Intr */
                };
        } else
        if (v==TEI0_ISP_V) { /* Transmision End */
                SCI0_TEIE=0;
        } else
        if (v==TEI1_ISP_V) { /* Transmision End */
                SCI1_TEIE=0;
        } else  {
          /* What makes a guy as you in a place like this?*/
          /* Que hace un tipo como tu en un sitio como este? */
        };
}
/*-----------------------------------------------------------*/
/* RTEMS termios().....                                      */
/*-----------------------------------------------------------*/
static const rtems_termios_callbacks sci_intr_callbacks = {
        sciIntrInitialize,      /* FirstOpen*/
        sciShutdown,            /* LastClose*/
        NULL,                   /* PollRead (Not required) */
        sciIntrWrite,           /* Write */
        sciSetAttributes,       /* setAttributes */
        NULL,                   /* stopRemoteTX */
        NULL,                   /* StartRemoteTX */
        1                       /* outputUsesInterrupts */
};

static const rtems_termios_callbacks sci_poll_callbacks = {
        sciPollInitialize,      /* FirstOpen*/
        sciShutdown,            /* LastClose*/
        sciPollRead,            /* PollRead  */
        sciPollWrite,           /* Write */
        sciSetAttributes,       /* setAttributes */
        NULL,                   /* stopRemoteTX */
        NULL,                   /* StartRemoteTX */
        0                       /* outputUsesInterrupts */
};

const rtems_termios_callbacks * sci_get_termios_handlers(int polled) {
        return (polled)?&sci_poll_callbacks:&sci_intr_callbacks;
}


***********************************************************************
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/drivers/com.c
***********************************************************************
/*
 * This is a version COM 16c450 with interrupts
 *
 * Author: Fernando RUIZ CASAS (fernando.ruiz at ctv.es)
 * Nov 2000
 *
 * From sci.c     (Ralf Corsepius)
 *      console.c (W. Eric Norum)
 *      serial.c  (Radstone Tecnology)
 *      cf-uart.c (Chris Johns)
 *      A lot of thanks at all.
 */
/*-----------------------------------------*/
#include <termios.h>
#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/score/sh_io.h>
#include <rtems/score/ispsh7032.h>
#include <rtems/score/iosh7032.h>
#include <bsp.h>
#include <bsp_io.h>
#include <drivers.h>
/*----------------------------------*/
#define schedule() rtems_task_wake_after(RTEMS_YIELD_PROCESSOR)
/*----------------------------------*/
/*-  PRIORITY LEVELS & IRQ ASSIGN  -*/
/*----------------------------------*/
#define  COM0_minor  2
#define  COM1_minor  3
#define  COM2_minor  4
#define  COM3_minor  5
/*----------------------------------*/
#define  LV_COM0  8
#define  LV_COM1  8
#define  LV_COM2  8
#define  LV_COM3  8

#define  PL_COM0  PL_IRQ4
#define  PL_COM1  PL_IRQ5
#define  PL_COM2  PL_IRQ6
#define  PL_COM3  PL_IRQ7

#define  COM0_ISP_V IRQ4_ISP_V
#define  COM1_ISP_V IRQ5_ISP_V
#define  COM2_ISP_V IRQ6_ISP_V
#define  COM3_ISP_V IRQ7_ISP_V

/*---------------------*/
/*--------UART0--------*/
/*---------------------*/
#define RBR0  (* ( volatile unsigned char *)(0x01000000))
#define THR0  (* ( volatile unsigned char *)(0x01000000))
#define IER0  (* ( volatile unsigned char *)(0x01000001))
#define FCR0  (* ( volatile unsigned char *)(0x01000002))
#define IIR0  (* ( volatile unsigned char *)(0x01000002))
#define LCR0  (* ( volatile unsigned char *)(0x01000003))
#define MCR0  (* ( volatile unsigned char *)(0x01000004))
#define LSR0  (* ( volatile unsigned char *)(0x01000005))
#define MSR0  (* ( volatile unsigned char *)(0x01000006))
#define DLL0  (* ( volatile unsigned char *)(0x01000000))
#define DLM0  (* ( volatile unsigned char *)(0x01000001))
#define SCT0  (* ( volatile unsigned char *)(0x01000007))
/*---------------------*/
/*--------UART1--------*/
/*---------------------*/
#define RBR1  (* ( volatile unsigned char *)(0x01000008))
#define THR1  (* ( volatile unsigned char *)(0x01000008))
#define IER1  (* ( volatile unsigned char *)(0x01000009))
#define FCR1  (* ( volatile unsigned char *)(0x0100000A))
#define IIR1  (* ( volatile unsigned char *)(0x0100000A))
#define LCR1  (* ( volatile unsigned char *)(0x0100000B))
#define MCR1  (* ( volatile unsigned char *)(0x0100000C))
#define LSR1  (* ( volatile unsigned char *)(0x0100000D))
#define MSR1  (* ( volatile unsigned char *)(0x0100000E))
#define DLL1  (* ( volatile unsigned char *)(0x01000008))
#define DLM1  (* ( volatile unsigned char *)(0x01000009))
#define SCT1  (* ( volatile unsigned char *)(0x0100000F))

/*---------------------*/
/*--------UART2--------*/
/*---------------------*/
#define RBR2  (* ( volatile unsigned char *)(0x01000010))
#define THR2  (* ( volatile unsigned char *)(0x01000010))
#define IER2  (* ( volatile unsigned char *)(0x01000011))
#define FCR2  (* ( volatile unsigned char *)(0x01000012))
#define IIR2  (* ( volatile unsigned char *)(0x01000012))
#define LCR2  (* ( volatile unsigned char *)(0x01000013))
#define MCR2  (* ( volatile unsigned char *)(0x01000014))
#define LSR2  (* ( volatile unsigned char *)(0x01000015))
#define MSR2  (* ( volatile unsigned char *)(0x01000016))
#define DLL2  (* ( volatile unsigned char *)(0x01000010))
#define DLM2  (* ( volatile unsigned char *)(0x01000011))
#define SCT2  (* ( volatile unsigned char *)(0x01000017))
/*---------------------*/
/*--------UART3--------*/
/*---------------------*/
#define RBR3  (* ( volatile unsigned char *)(0x01000018))
#define THR3  (* ( volatile unsigned char *)(0x01000018))
#define IER3  (* ( volatile unsigned char *)(0x01000019))
#define FCR3  (* ( volatile unsigned char *)(0x0100001A))
#define IIR3  (* ( volatile unsigned char *)(0x0100001A))
#define LCR3  (* ( volatile unsigned char *)(0x0100001B))
#define MCR3  (* ( volatile unsigned char *)(0x0100001C))
#define LSR3  (* ( volatile unsigned char *)(0x0100001D))
#define MSR3  (* ( volatile unsigned char *)(0x0100001E))
#define DLL3  (* ( volatile unsigned char *)(0x01000018))
#define DLM3  (* ( volatile unsigned char *)(0x01000019))
#define SCT3  (* ( volatile unsigned char *)(0x0100001F))

/*-----------------------------------------*/
struct rtems_termios_tty *com0_ttyp;
struct rtems_termios_tty *com1_ttyp;
struct rtems_termios_tty *com2_ttyp;
struct rtems_termios_tty *com3_ttyp;

static struct com_bitrate_t { /* 1.8432 Mhz */
  unsigned char dll ;
  unsigned char dlm ;
  int           baud;
  tcflag_t      cbaud;
} _com_bitrates[] = {
 { 0x00, 0x09,     50, B50     },
 { 0x00, 0x06,     75, B75     },
 { 0x17, 0x04,    110, B110    },
 { 0x5b, 0x03,    134, B134    },
 { 0x00, 0x03,    150, B150    },
 { 0x40, 0x02,    200, B200    },
 { 0x80, 0x01,    300, B300    },
 { 0xc0, 0x00,    600, B600    },
 { 0x60, 0x00,   1200, B1200   },
 { 0x40, 0x00,   1800, B1800   },
 { 0x30, 0x00,   2400, B2400   },
 { 0x18, 0x00,   4800, B4800   },
 { 0x0c, 0x00,   9600, B9600   },
 { 0x06, 0x00,  19200, B19200  },
 { 0x03, 0x00,  38400, B38400  },
 { 0x02, 0x00,  57600, B57600  },
 { 0x01, 0x00, 115200, B115200 },
 { 0x00, 0x00, 230400, B230400 },
 { 0x00, 0x00, 460800, B460800 },
};
/*-----------------------------------------*/
int _com_get_brparms(
  tcflag_t      cflag,
  unsigned char *dll,
  unsigned char *dlm )
{
  unsigned int offset,max,ofs9600;
  ofs9600=0;
  max=sizeof(_com_bitrates)/sizeof(_com_bitrates[0]);
  for (offset=0;offset<max;offset++) {
   if (_com_bitrates[offset].cbaud==(cflag&CBAUD)) break;
   if (_com_bitrates[offset].cbaud==B9600) ofs9600=offset;
  };
  if (offset>=max) offset=ofs9600;

  *dll = _com_bitrates[offset].dll;
  *dlm = _com_bitrates[offset].dlm;

  return 0;
}
/*-----------------------------------------*/
int _com_how_baud( unsigned char dll,
                   unsigned char dlm ) {
    return dll+dlm*0x100/115200;
}
/*-----------------------------------------------------------*/
static int comSetAttributes(int minor,const struct termios *t);
static int comIntrInitialize(int major,int minor,void * arg) ;
static int comPollInitialize(int major,int minor,void * arg) ;
static int comShutdown(int major,int minor,void * arg) ;
static int comIntrWrite(int minor, const char * buf,int len) ;
static int comPollWrite(int minor, const char * buf,int len) ;
static int comPollRead(int minor) ;
static rtems_isr comInterruptHandler (rtems_vector_number v) ;
const rtems_termios_callbacks * com_get_termios_handlers(int polled) ;
/*-----------------------------------------------------------*/
/* Translate termios' tcflag_t into com settings */
/*-----------------------------------------------------------*/
static int com_set_cflags(
  unsigned char *dll,
  unsigned char *dlm,
  unsigned char *lcr,
  tcflag_t      c_cflag )
{

  /* Set the baudrate */
  if ( c_cflag & CBAUD )
  {
    if ( _com_get_brparms( c_cflag, dll, dlm ) != 0 )
      return -1 ;
  }
  /* Set the wordlen */
  *lcr=0;
  if ( c_cflag & CSIZE )
  {
    if      ( c_cflag & CS8 )
     *lcr|=0x03;
    else if ( c_cflag & CS7 )
     *lcr|=0x02;
    else if ( c_cflag & CS6 )
     *lcr|=0x01;
    else if ( c_cflag & CS5 )
     *lcr|=0x00;
    else
      return -1 ;
  }
  /* Set stop bits */
  if ( c_cflag & CSTOPB )
     *lcr|=0x04;
  else
     *lcr|=0x00;
  /* Set Parity */
  if ( c_cflag & PARENB )
     *lcr|=0x08;
  else
     *lcr|=0x00;
  if ( c_cflag & PARODD )
     *lcr|=0x10;
  else
     *lcr|=0x00;
  return 0 ;
}
/*-----------------------------------------------------------*/
/* Set the Hardware                                          */
/*-----------------------------------------------------------*/
static int
comSetAttributes(int minor,const struct termios *t) {
  unsigned char dll;
  unsigned char dlm;
  unsigned char lcr;
  unsigned char pl ;
  unsigned char dummy;
  if (com_set_cflags(&dll,&dlm,&lcr,t->c_cflag)<0) return -1;
  if (minor==COM0_minor) {
        /* Clear Priority Level COM0 */
        pl=PL_COM0;
        PL_COM0=0;
        LCR0|=0x80;
        DLL0=dll;
        DLM0=dlm;
        LCR0=lcr;
        while (LSR0&0x01)  dummy=RBR0;
        while (IIR0!=0x01) dummy=IIR0;
        MCR0=0x08;
        PL_COM0=pl;
  } else
  if (minor==COM1_minor) {
        /* Clear Priority Level COM1 */
        pl=PL_COM1;
        PL_COM1=0;
        LCR1|=0x80;
        DLL1=dll;
        DLM1=dlm;
        LCR1=lcr;
        while (LSR1&0x01)  dummy=RBR1;
        while (IIR1!=0x01) dummy=IIR1;
        MCR1=0x08;
        PL_COM1=pl;
  } else
  if (minor==COM2_minor) {
        /* Clear Priority Level COM2 */
        pl=PL_COM2;
        PL_COM2=0;
        LCR2|=0x80;
        DLL2=dll;
        DLM2=dlm;
        LCR2=lcr;
        while (LSR2&0x01)  dummy=RBR2;
        while (IIR2!=0x01) dummy=IIR2;
        MCR2=0x08;
        PL_COM2=pl;
  } else
  if (minor==COM3_minor) {
        /* Clear Priority Level COM3 */
        pl=PL_COM3;
        PL_COM3=0;
        LCR3|=0x80;
        DLL3=dll;
        DLM3=dlm;
        LCR3=lcr;
        while (LSR3&0x01)  dummy=RBR3;
        while (IIR3!=0x01) dummy=IIR3;
        MCR3=0x08;
        PL_COM3=pl;
  } else {
          return -1;
  };
  return 0;
}
/*-----------------------------------------------------------*/
static int
comIntrInitialize(int major,int minor,void * arg) {
        rtems_isr_entry old_vector;
        rtems_libio_open_close_args_t * args = arg;
        struct termios t;

        if (minor==COM0_minor) {
         PL_COM0=0;  /* Disable IRQ COM0*/
         com0_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8; /* termios default */
         if (comSetAttributes(minor,&t)<0) return -1;
         rtems_interrupt_catch(comInterruptHandler,COM0_ISP_V,&old_vector);
         IER0=0x01; /* RX Interrupt only */
         PL_COM0=LV_COM0;
        } else
        if (minor==COM1_minor) {
         PL_COM1=0;  /* Disable IRQ COM1*/
         com1_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8; /* termios default */
         if (comSetAttributes(minor,&t)<0) return -1;
         rtems_interrupt_catch(comInterruptHandler,COM1_ISP_V,&old_vector);
         IER1=0x01; /* RX Interrupt only */
         PL_COM1=LV_COM1;
        } else
        if (minor==COM2_minor) {
         PL_COM2=0;  /* Disable IRQ COM2*/
         com2_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8; /* termios default */
         if (comSetAttributes(minor,&t)<0) return -1;
         rtems_interrupt_catch(comInterruptHandler,COM2_ISP_V,&old_vector);
         IER2=0x01; /* RX Interrupt only */
         PL_COM2=LV_COM2;
        } else
        if (minor==COM3_minor) {
         PL_COM3=0;  /* Disable IRQ COM3*/
         com3_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8; /* termios default */
         if (comSetAttributes(minor,&t)<0) return -1;
         rtems_interrupt_catch(comInterruptHandler,COM3_ISP_V,&old_vector);
         IER3=0x01; /* RX Interrupt only */
         PL_COM3=LV_COM3;
        } else {
         return -1;
        };
        return 0;
}
/*-----------------------------------------------------------*/
static int
comPollInitialize(int major,int minor,void * arg) {
        rtems_libio_open_close_args_t * args = arg;
        struct termios t;

        if (minor==COM0_minor) {
         PL_COM0=0;  /* Disable IRQ COM0*/
         com0_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8;/* termios default */
         return comSetAttributes(minor,&t);
        } else
        if (minor==COM1_minor) {
         PL_COM1=0;  /* Disable IRQ COM1*/
         com1_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8;/* termios default */
         return comSetAttributes(minor,&t);
        } else
        if (minor==COM2_minor) {
         PL_COM2=0;  /* Disable IRQ COM2*/
         com2_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8;/* termios default */
         return comSetAttributes(minor,&t);
        } else
        if (minor==COM3_minor) {
         PL_COM3=0;  /* Disable IRQ COM2*/
         com3_ttyp=args->iop->data1;
         t.c_cflag=B9600|CS8;/* termios default */
         return comSetAttributes(minor,&t);
        } else {
         return -1;
        };
}
/*-----------------------------------------------------------*/
static int
comShutdown(int major,int minor,void * arg) {
        if (minor==COM0_minor) {
         PL_COM0=0;  /* Disable IRQ COM0*/
         IER0=0;
        } else
        if (minor==COM1_minor) {
         PL_COM1=0;  /* Disable IRQ COM1*/
         IER1=0;
        } else
        if (minor==COM2_minor) {
         PL_COM2=0;  /* Disable IRQ COM2*/
         IER2=0;
        } else
        if (minor==COM3_minor) {
         PL_COM3=0;  /* Disable IRQ COM2*/
         IER3=0;
        } else {
         return -1;
        };
        return 0;
}
/*-----------------------------------------------------------*/
/* Write Characters into com device                          */
/*-----------------------------------------------------------*/
static int
comIntrWrite(int minor, const char * buf,int len) {
        if (len<=0) return 0;
        if (minor==COM0_minor) {
         THR0=*buf;
         IER0|=0x02; /* TX Interrupt Notify for a new Intr */
         return 1;
        } else
        if (minor==COM1_minor) {
         THR1=*buf;
         IER1|=0x02; /* TX Interrupt Notify for a new Intr */
         return 1;
        } else
        if (minor==COM2_minor) {
         THR2=*buf;
         IER2|=0x02; /* TX Interrupt Notify for a new Intr */
         return 1;
        } else
        if (minor==COM3_minor) {
         THR3=*buf;
         IER3|=0x02; /* TX Interrupt Notify for a new Intr */
         return 1;
        } else {
         return 0;
        };
}
/*-----------------------------------------------------------*/
static int
comPollWrite(int minor, const char * buf,int len) {
        int count=0;
        while (len--) {
         if (minor==COM0_minor) {
                while (LSR0&0x20) schedule();
                THR0=*buf++;
         } else
         if (minor==COM1_minor) {
                while (LSR1&0x20) schedule();
                THR1=*buf++;
         } else
         if (minor==COM2_minor) {
                while (LSR2&0x20) schedule();
                THR2=*buf++;
         } else
         if (minor==COM3_minor) {
                while (LSR3&0x20) schedule();
                THR3=*buf++;
         } else {
                return 0;
         };
         count++;
        };
        return count;
}
/*-----------------------------------------------------------*/
static int
comPollRead(int minor) {
        int value=-1;
        if (minor==COM0_minor){if (LSR0&0x01) value=RBR0;} else
        if (minor==COM1_minor){if (LSR1&0x01) value=RBR1;} else
        if (minor==COM2_minor){if (LSR2&0x01) value=RBR2;} else
        if (minor==COM3_minor){if (LSR3&0x01) value=RBR3;};
        return value;
}
/*-----------------------------------------------------------*/
/* Interrupt Handler                                         */
/*-----------------------------------------------------------*/
static rtems_isr
comInterruptHandler (rtems_vector_number v) {
        unsigned char value,dummy;
        if (v==COM0_ISP_V) { /* */
         do {
          value=IIR0;
          switch(value) {
           case 6:dummy=LSR0;break;
           case 0:dummy=MSR0;break;
           case 4:value=RBR0;
                  rtems_termios_enqueue_raw_characters(com0_ttyp,&value,1);
                  break;
           case 2:if (!rtems_termios_dequeue_characters(com0_ttyp,1)) {
                   IER0&=~0x02;/* No Chars left, Stop Transmision */
                  };
                  break;
          };
         } while (value!=0x01);
        } else
        if (v==COM1_ISP_V) { /* */
         do {
          value=IIR1;
          switch(value) {
           case 6:dummy=LSR1;break;
           case 0:dummy=MSR1;break;
           case 4:value=RBR1;
                  rtems_termios_enqueue_raw_characters(com1_ttyp,&value,1);
                  break;
           case 2:if (!rtems_termios_dequeue_characters(com1_ttyp,1)) {
                   IER1&=~0x02;/* No Chars left, Stop Transmision */
                  };
                  break;
          };
         } while (value!=0x01);
        } else
        if (v==COM2_ISP_V) { /* */
         do {
          value=IIR2;
          switch(value) {
           case 6:dummy=LSR2;break;
           case 0:dummy=MSR2;break;
           case 4:value=RBR2;
                  rtems_termios_enqueue_raw_characters(com2_ttyp,&value,1);
                  break;
           case 2:if (!rtems_termios_dequeue_characters(com2_ttyp,1)) {
                   IER2&=~0x02;/* No Chars left, Stop Transmision */
                  };
                  break;
          };
         } while (value!=0x01);
        } else
        if (v==COM3_ISP_V) { /* */
         do {
          value=IIR3;
          switch(value) {
           case 6:dummy=LSR3;break;
           case 0:dummy=MSR3;break;
           case 4:value=RBR3;
                  rtems_termios_enqueue_raw_characters(com3_ttyp,&value,1);
                  break;
           case 2:if (!rtems_termios_dequeue_characters(com3_ttyp,1)) {
                   IER3&=~0x02;/* No Chars left, Stop Transmision */
                  };
                  break;
          };
         } while (value!=0x01);
        } else  {
          /* What makes a guy as you in a place like this?*/
          /* Que hace un tipo como tu en un sitio como este? */
        };
}
/*-----------------------------------------------------------*/
/* RTEMS termios().....                                      */
/*-----------------------------------------------------------*/
static const rtems_termios_callbacks com_intr_callbacks = {
        comIntrInitialize,      /* FirstOpen*/
        comShutdown,            /* LastClose*/
        NULL,                   /* PollRead (Not required) */
        comIntrWrite,           /* Write */
        comSetAttributes,       /* setAttributes */
        NULL,                   /* stopRemoteTX */
        NULL,                   /* StartRemoteTX */
        1                       /* outputUsesInterrupts */
};

static const rtems_termios_callbacks com_poll_callbacks = {
        comPollInitialize,      /* FirstOpen*/
        comShutdown,            /* LastClose*/
        comPollRead,            /* PollRead  */
        comPollWrite,           /* Write */
        comSetAttributes,       /* setAttributes */
        NULL,                   /* stopRemoteTX */
        NULL,                   /* StartRemoteTX */
        0                       /* outputUsesInterrupts */
};

const rtems_termios_callbacks * com_get_termios_handlers(int polled) {
        return (polled)?&com_poll_callbacks:&com_intr_callbacks;
}

****************************************************************************
******


With this two version of serial drivers you can make a powerful console
driver termios.

You need create a new private version of console.c in the new directory
~/console

(This makes a substitution for the shared console.c).


****************************************************************************
*******
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/console/console.c
******
****************************************************************************
*******
/*
 * /dev/console for Hitachi SH 703X
 *
 *  Author: Ralf Corsepius (corsepiu at faw.uni-ulm.de)
 *  Modified: Fernando RUIZ CASAS (fernando.ruiz at ctv.es)
 *
 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 *  COPYRIGHT (c) 1998.
 *  On-Line Applications Research Corporation (OAR).
 *  Copyright assigned to U.S. Government, 1994.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: console.c,v 1.1 2000/11/10 14:03:16 joel Exp $
 */

#include <termios.h>
#include <bsp.h>
#include <bsp_io.h>
#include <rtems/libio.h>
#include <drivers.h>
#include <unistd.h>


/*  console_initialize
 *
 *  This routine initializes the console IO driver.
 *
 *  Input parameters: NONE
 *
 *  Output parameters:  NONE
 *
 *  Return values:
 */

rtems_device_driver console_initialize(
  rtems_device_major_number  major,
  rtems_device_minor_number  minor,
  void                      *arg
)
{
  rtems_status_code status ;

  /*
   * Set up TERMIOS
   */

  rtems_termios_initialize ();

  /*
   * Register the device
   */
  status = rtems_io_register_name( "/dev/sci0", major, 0);  /* major is an
autovalue, minor is choosed by you */
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  status = rtems_io_register_name( "/dev/sci1", major, 1);
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  status = rtems_io_register_name( "/dev/com0", major, 2);
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  status = rtems_io_register_name( "/dev/com1", major, 3);
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  status = rtems_io_register_name( "/dev/com2", major, 4);
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  status = rtems_io_register_name( "/dev/com3", major, 5);
  if (status != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred(status);

  /* Make your link to /dev/console. Using a macro BSP_CONSOLE_NAME is also
possible */

  if (link("/dev/sci1","/dev/console")<0)
    rtems_fatal_error_occurred(RTEMS_IO_ERROR);

  return RTEMS_SUCCESSFUL;
}


/*
 *  Open entry point
 */

rtems_device_driver console_open(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  rtems_status_code sc ;
  const rtems_termios_callbacks * sci_get_termios_handlers(int polled); /*
extern declaration */
  const rtems_termios_callbacks * com_get_termios_handlers(int polled);
  if (minor<2) /* sci internal */
  sc = rtems_termios_open(major,minor,arg,sci_get_termios_handlers(FALSE));
/* Always not polled */
  else         /* uart external */
  sc = rtems_termios_open(major,minor,arg,com_get_termios_handlers(FALSE));
  return sc;
}

/*
 *  Close entry point
 */

rtems_device_driver console_close(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  return rtems_termios_close(arg);
}

/*
 * read bytes from the serial port. We only have stdin.
 */

rtems_device_driver console_read(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  return rtems_termios_read(arg);
}

/*
 * write bytes to the serial port. Stdout and stderr are the same.
 */

rtems_device_driver console_write(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  return rtems_termios_write(arg);
}

/*
 *  IO Control entry point
 */

rtems_device_driver console_control(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  return rtems_termios_ioctl(arg);
}

****************************************************************************
******

Don't forget the Makefile.am...  Set C_FILES & EXTRA_DIST placing console.c

****************************************************************************
******
*/home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552/console/Makefile.a
m
****************************************************************************
******
##
## $Id: Makefile.am,v 1.4 2000/09/05 15:53:58 joel Exp $
##

AUTOMAKE_OPTIONS = foreign 1.4

VPATH = @srcdir@:@srcdir@/../../shared

PGM = $(ARCH)/console.rel

C_FILES = console.c
C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)

OBJS = $(C_O_FILES)

include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
include $(top_srcdir)/../../../../../../automake/compile.am
include $(top_srcdir)/../../../../../../automake/lib.am

#
# (OPTIONAL) Add local stuff here using +=
#

$(PGM): $(OBJS)
        $(make-rel)

# the .rel file built here will be put into libbsp.a by
#       ../wrapup/Makefile

all-local: $(ARCH) $(OBJS) $(PGM)

.PRECIOUS: $(PGM)

EXTRA_DIST = console.c

include $(top_srcdir)/../../../../../../automake/local.am

****************************************************************************
****

What is it necesary now? Changes 'bsp.h' from include directory
making a new clean file like this without tricks for console driver.

****************************************************************************
****

*
 *  This include file contains all board IO definitions.
 *
 *  vis552 sh1
 *
 *  Author: Ralf Corsepius (corsepiu at faw.uni-ulm.de)
 *  Modified:Fernando RUIZ CASAS (fernando.ruiz at ctv.es)
 *
 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 *  COPYRIGHT (c) 1998.
 *  On-Line Applications Research Corporation (OAR).
 *  Copyright assigned to U.S. Government, 1994.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: bsp.h,v 1.8 2000/06/12 14:59:51 joel Exp $
 */

#ifndef __bsp_h
#define __bsp_h

#ifdef __cplusplus
extern "C" {
#endif

#include <rtems.h>
#include <console.h>


/*
 *  confdefs.h overrides for this BSP:
 *   - number of termios serial ports (defaults to 1)
 *   - Interrupt stack space is not minimum if defined.
 */

#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 6
#define CONFIGURE_INTERRUPT_STACK_MEMORY  (4 * 1024)

/*
 *  Define the time limits for RTEMS Test Suite test durations.
 *  Long test and short test duration limits are provided.  These
 *  values are in seconds and need to be converted to ticks for the
 *  application.
 *
 */

#define MAX_LONG_TEST_DURATION       300 /* 5 minutes = 300 seconds */
#define MAX_SHORT_TEST_DURATION      3   /* 3 seconds */

/*
 *  Stuff for Time Test 27
 */

#define MUST_WAIT_FOR_INTERRUPT 0

#define Install_tm27_vector( handler ) \
{ \
  rtems_isr_entry ignored ; \
  rtems_interrupt_catch( (handler), 0, &ignored ) ; \
}

#define Cause_tm27_intr()

#define Clear_tm27_intr()

#define Lower_tm27_intr()

/* Constants */

/*
 *  Simple spin delay in microsecond units for device drivers.
 *  This is very dependent on the clock speed of the target.
 */

#define delay( microseconds ) CPU_delay(microseconds)
#define sh_delay( microseconds ) CPU_delay(microseconds)

/*
 * Defined in the linker script 'linkcmds'
 */

extern unsigned32       HeapStart ;
extern unsigned32       HeapEnd ;
extern unsigned32       WorkSpaceStart ;
extern unsigned32       WorkSpaceEnd ;

extern void *CPU_Interrupt_stack_low ;
extern void *CPU_Interrupt_stack_high ;


/* miscellaneous stuff assumed to exist */

extern rtems_configuration_table BSP_Configuration;

extern void bsp_cleanup( void );

/*
 *  Device Driver Table Entries
 */

/*************************************************************
#define CONFIGURE_APPLICATION_NEEDS_CUSTOM_DRIVER

#define CUSTOM_DRIVER_TABLE_ENTRY \
        LCD_DRIVER_TABLE_ENTRY, \
        FLA_DRIVER_TABLE_ENTRY, \
        KBD_DRIVER_TABLE_ENTRY, \
        E2P_DRIVER_TABLE_ENTRY, \
        NET_DRIVER_TABLE_ENTRY, \
        RTC_DRIVER_TABLE_ENTRY

**************************************************************/
#ifdef __cplusplus
}
#endif

#endif
/* end of include file */

****************************************************************************
*

You can see a macro CUSTOM_DRIVER_TABLE_ENTRY. It is used to add more
drivers
patching 'confdefs.h'. All of these drivers are running in my bsp. But this
is
for another day.

You don't need a console redirection because a
 link("/dev/console","/dev/sci1") makes it for you.

More clean... Now that we can link a file of course..

And now?

The first step is run 'bootstrap' in order to set Makefile.in from
Makefile.am
in every directory of you bsp tree. You can locate bootstrap in

   /home/rtems/rtems-ss-20010126/bootstrap

here (Your bsp base tree)

   /home/rtems/rtems-ss-20010126/c/src/lib/libbsp/sh/vis552

run the next command:

    /home/rtems/rtems-ss-20010126/bootstrap -v (VERBOSE MODE)


Now you can build the bsp library.

   cd $HOME
   ./bit_rtems sh vis552 (To build the bsp)

After add new driver directories is better rebuild from the scratch.

Once you have first build_directory (Done with the last command)
you can make a new build run make into

  cd $HOME/build-sh-rtems
  make all install 2>errors

You can see the errors file to correct the mistakes.

When you have finished the process you can the first step ready.

You have the bsp library into /opt/rtems/vis552.

Now the application side.

In a new account for the new bsp developpements...

****************************************************************
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

RTEMS=/opt/rtems
PATH=$RTEMS/bin:$PATH:$HOME/bin:/opt/sn
BASH_ENV=$HOME/.bashrc
USERNAME=""
HISTIGNORE="[   ]*:&:bg:fg"
RTEMS_MAKEFILE_PATH=$RTEMS/vis552

export USERNAME BASH_ENV PATH HISTIGNORE RTEMS RTEMS_MAKEFILE_PATH
****************************************************************************
*

The makefile

****************************************************************************
*
#
#  Makefile
#

#
#  RTEMS_MAKEFILE_PATH is typically set in an environment variable
#

EXEC=init.exe
PGM=${ARCH}/$(EXEC)

# optional managers required
MANAGERS=all

# C source names
CSRCS = init.c
COBJS_ = $(CSRCS:.c=.o)
COBJS = $(COBJS_:%=${ARCH}/%)

# C++ source names
CXXSRCS =
CXXOBJS_ = $(CXXSRCS:.cc=.o)
CXXOBJS = $(CXXOBJS_:%=${ARCH}/%)

# AS source names
ASSRCS =
ASOBJS_ = $(ASSRCS:.s=.o)
ASOBJS = $(ASOBJS_:%=${ARCH}/%)

# Libraries
LIBS = -lrtemsall -lc

include $(RTEMS_MAKEFILE_PATH)/Makefile.inc

include $(RTEMS_CUSTOM)
include $(PROJECT_ROOT)/make/leaf.cfg

OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)

all:    ${ARCH} $(PGM)

$(PGM): $(OBJS)
        $(make-exe)

****************************************************************************
*


The application file.


****************************************************************************
*
*                     INIT.C
****************************************************************************
*
undef __STRICT_ANSI__
#include <stdio.h>
#include <termios.h>
#include <bsp.h>

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_MAXIMUM_TASKS                  30
#define CONFIGURE_MAXIMUM_TIMERS                 10
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES         10
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM


#define CONFIGURE_INIT

rtems_task Init (rtems_task_argument argument);

#include <confdefs.h>

rtems_task
Init (rtems_task_argument ignored)
{
 char buffer[128];
 /* The standard console termios ports are in B9600|CS8 */
 do {
   printf("Hello! This is a promt>");
   fgets(buffer,sizeof(buffer)-1,stdin);
   printf("You have writed '%s'\n",buffer);
 } while (1);
}
****************************************************************************
**

Run make and load the executable init.exe in the EBV and run the software.

If you connect your PC with the console port choosed at 9600,8,N,1 bauds
this works.
You have now a termios terminal (Canonical, Echo, etc...)


Enjoy it.

Questions? Sugg.?

Fernando RUIZ CASAS
home: correo at fernando-ruiz.com
work: fernando.ruiz at ctv.es







More information about the users mailing list