Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/drivers/tty/ttyio.c

Go to the documentation of this file.
00001 /*  src_experimental/drivers/tty/ttyio.c
00002    CubeOS Version 0.4.90 experimental
00003    Copyright (C) 1999,2000 Holger Kenn
00004 
00005    CubeOS is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or any later version.
00009 
00010    CubeOS is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015  */
00016 #include <stddef.h>
00017 #include <mc68681.h>
00018 #include <cubeos.h>
00019 #include <sys_var.h>
00020 #include <iobuf.h>
00021 #include <kerror.h>
00022 #include <io_sci.h>
00023 #include <io_duart.h>
00024 #include <stdio.h>
00025 
00026 struct TTY_tty_dev TTY_tty[3];
00027 struct iobuf TTY_tty_in[3];
00028 struct iobuf TTY_tty_out[3];
00029 
00030 void TTY_outchar (char byte);
00031 
00036 char _TTY_console_echo;
00037 
00042 int _TTY_contty;
00043 
00052 void TTY_setcontty (int whichtty)
00053 {
00054         _TTY_contty = whichtty;
00055 }
00056 
00060 void TTY_conecho_on ()
00061 {
00062         _TTY_console_echo = 1;
00063 }
00064 
00068 void TTY_conecho_off ()
00069 {
00070         _TTY_console_echo = 0;
00071 }
00072 
00073 
00081 int TTY_setbps(struct TTY_tty_dev *tty, int bps)
00082 {
00083         return(tty->setbps(bps));
00084 }
00085 
00097 void TTY_setmode (struct TTY_tty_dev *tty, char mode)
00098 {
00099         tty->mode = mode;
00100 }
00101 
00102 
00108 char TTY_getmode (struct TTY_tty_dev *tty)
00109 {
00110         return (tty->mode);
00111 }
00112 
00121 char TTY_getstate (struct TTY_tty_dev *tty)
00122 {
00123         return (tty->state);
00124 }
00125 
00126 
00133 char TTY_readchar (struct TTY_tty_dev *tty)
00134 {
00135 
00136         char c;
00137 
00138         /* Block until char is there */
00139         if (tty->mode & TTY_MODE_RXBLOCKING) {
00140                 while (tty->inq->cnt == 0);
00141         } else {
00142                 if (tty->inq->cnt == 0)
00143                         tty->state |= TTY_STATE_RXEMPTY;
00144                 return (0);
00145         }
00146         tty->state &= (0xff - TTY_STATE_RXEMPTY);
00147 
00148         disable ();
00149         c = tty->inq->data[tty->inq->tail];
00150         tty->inq->tail = (tty->inq->tail + 1) % tty->inq->buflen;
00151         tty->inq->cnt--;
00152         if (tty->inq->cnt > tty->inq->buflen) {
00153                 KERN_complain (ERR_PANIC, "More than inq->buflen bytes in the buffer");
00154         }
00155         if (tty->hsmode == TTY_HS_RTSCTS) {
00156                 /* handle rts enable case */
00157                 if (tty->inq->cnt < (tty->inq->buflen - TTY_RTS_TRESHOLD))
00158                         tty->setrts (1);
00159         }
00160         enable ();
00161 //      printf("\n<%x\n",c);fflush(stdout);
00162         return (c);
00163 }
00164 
00165 
00170 void TTY_writechar (struct TTY_tty_dev *tty, char byte)
00171 {
00172 
00173 //      printf("\n>%x\n",byte);fflush(stdout);
00174 
00175         disable ();
00176 
00177         if (tty->mode | TTY_MODE_TXUNBUF) {
00178                 tty->dis_tx_irq ();
00179                 while (tty->outq->cnt > 0) {
00180                         tty->txchar (tty->outq->data[tty->outq->tail]);
00181                         tty->outq->tail = (tty->outq->tail + 1) % tty->outq->buflen;
00182                         tty->outq->cnt--;
00183                 }
00184                 tty->txchar (byte);
00185         } else {
00186 
00187                 if (tty->outq->cnt == tty->outq->buflen) {
00188                         /* buffer is full */
00189                         tty->en_tx_irq ();      /* in case it was off for any reason */
00190                         if (tty->mode | TTY_MODE_TXBLOCKING) {
00191                                 enable ();
00192                                 while (tty->outq->cnt == tty->outq->buflen);
00193                                 disable ();
00194                         } else {
00195                                 tty->state |= TTY_STATE_TXFULL;
00196                                 enable ();
00197                                 // here, we have to block the I/O-doing thread
00198                                 // until there is space in the TX buffer
00199                                 // then we have to restart the I/O
00200                                 // recursively.
00201 //                              KERN_ssleep();
00202                                 return;
00203                         }
00204                 }
00205                 tty->outq->data[tty->outq->head] = byte;
00206                 tty->outq->head = (tty->outq->head + 1) % tty->outq->buflen;
00207                 tty->outq->cnt++;
00208 
00209                 /* enable pending transmitter interrupt */
00210                 if (tty->outq->cnt > 0)
00211                         tty->en_tx_irq ();
00212         }
00213         enable ();
00214 }
00215 
00216 
00222 char TTY_inchar (void)
00223 {
00224         char c;
00225 
00226         /* Block until char is there */
00227         while (TTY_tty[_TTY_contty].inq->cnt == 0);
00228         disable ();
00229         c = TTY_tty[_TTY_contty].inq->data[TTY_tty[_TTY_contty].inq->tail];
00230         TTY_tty[_TTY_contty].inq->tail = (TTY_tty[_TTY_contty].inq->tail + 1) % TTY_tty[_TTY_contty].inq->buflen;
00231         TTY_tty[_TTY_contty].inq->cnt--;
00232         if (TTY_tty[_TTY_contty].inq->cnt > TTY_tty[_TTY_contty].inq->buflen) {
00233                 KERN_complain (ERR_PANIC, "More than inq->buflen bytes in the buffer");
00234         }
00235         enable ();
00236         if (_TTY_console_echo)
00237                 TTY_outchar (c);
00238         return (c);
00239 }
00240 
00245 void TTY_soutchar(char byte)
00246 {
00247 TTY_tty[_TTY_contty].dis_tx_irq ();
00248 while (TTY_tty[_TTY_contty].outq->cnt > 0) {
00249         TTY_tty[_TTY_contty].txchar (TTY_tty[_TTY_contty].outq->data[TTY_tty[_TTY_contty].outq->tail]);
00250         TTY_tty[_TTY_contty].outq->tail = (TTY_tty[_TTY_contty].outq->tail + 1) % TTY_tty[_TTY_contty].outq->buflen;
00251         TTY_tty[_TTY_contty].outq->cnt--;
00252         }
00253 TTY_tty[_TTY_contty].txchar (byte);
00254 }
00255 
00259 void TTY_outchar (char byte)
00260 {
00261 
00262 //      KERN_usleep (1000);
00263 
00264 if (TTY_Blocking_Serial_Out){
00265         TTY_soutchar(byte);
00266         return;
00267 }
00268         while (TTY_tty[_TTY_contty].outq->cnt == TTY_tty[_TTY_contty].outq->buflen);
00269 
00270         disable ();
00271 
00272 
00273                 if (TTY_tty[_TTY_contty].outq->cnt == TTY_tty[_TTY_contty].outq->buflen) {
00274                         TTY_tty[_TTY_contty].en_tx_irq ();
00275                         enable ();
00276                         return;
00277                 }               /* Ignore overflow */
00278                 TTY_tty[_TTY_contty].outq->data[TTY_tty[_TTY_contty].outq->head] = byte;
00279                 TTY_tty[_TTY_contty].outq->head = (TTY_tty[_TTY_contty].outq->head + 1) % TTY_tty[_TTY_contty].outq->buflen;
00280                 TTY_tty[_TTY_contty].outq->cnt++;
00281 
00282                 /* enable pending transmitter interrupt */
00283                 if (TTY_tty[_TTY_contty].outq->cnt > 0)
00284                         TTY_tty[_TTY_contty].en_tx_irq ();
00285         enable ();
00286 }
00287 
00288 void dummy ()
00289 {
00290         return;
00291 }
00296 void TTY_init (void)
00297 {
00298         int i;
00299 
00300 /*      init_LED ();
00301    LED_OFF ();
00302    for (i = 0; i < 100000; i++);
00303    LED_ON ();
00304    for (i = 0; i < 100000; i++);
00305    LED_OFF (); */
00306 
00307         for (i = 0; i < 3; i++) {
00308                 TTY_tty[i].inq = &TTY_tty_in[i];
00309                 TTY_tty[i].outq = &TTY_tty_out[i];
00310         }
00311 
00312 
00313 //#ifdef CUBE3
00314         //      TTY_setcontty (1);          /* DUART */
00315         //#else
00316         //      TTY_setcontty (0);              /* DUART */
00317         //#endif
00318 #ifdef DUART_BASE
00319         DUART_duart (&TTY_tty[1], &TTY_tty[2]);
00320 #else
00321 
00322         TTY_tty[1].txchar = dummy;
00323         TTY_tty[1].en_tx_irq = dummy;
00324         TTY_tty[1].dis_tx_irq = dummy;
00325         TTY_tty[1].en_rx_irq = dummy;
00326         TTY_tty[1].dis_rx_irq = dummy;
00327         TTY_tty[1].sethandshake = dummy;
00328         TTY_tty[1].setbps = dummy;
00329         TTY_tty[1].setrts = dummy;
00330         TTY_tty[1].hsmode = TTY_HS_NONE;
00331         TTY_tty[1].mode = 0;
00332         TTY_tty[1].state = 0;
00333         TTY_tty[1].char_process = NULL;
00334         TTY_tty[1].break_process = NULL;
00335 
00336         iobuf_init (TTY_tty[1].inq, BUFLEN);
00337         iobuf_init (TTY_tty[1].outq, BUFLEN);
00338 
00339         TTY_tty[2].txchar = dummy;
00340         TTY_tty[2].en_tx_irq = dummy;
00341         TTY_tty[2].dis_tx_irq = dummy;
00342         TTY_tty[2].en_rx_irq = dummy;
00343         TTY_tty[2].dis_rx_irq = dummy;
00344         TTY_tty[2].sethandshake = dummy;
00345         TTY_tty[2].setbps = dummy;
00346         TTY_tty[2].setrts = dummy;
00347         TTY_tty[2].hsmode = TTY_HS_NONE;
00348         TTY_tty[2].mode = 0;
00349         TTY_tty[2].state = 0;
00350         TTY_tty[2].char_process = NULL;
00351         TTY_tty[2].break_process = NULL;
00352 
00353         iobuf_init (TTY_tty[2].inq, BUFLEN);
00354         iobuf_init (TTY_tty[2].outq, BUFLEN);
00355 
00356 #endif
00357         QSM_sciinit (&TTY_tty[0]);
00358         TTY_setcontty (0);
00359         TTY_conecho_on ();
00360 
00361 }

Generated on Thu Feb 20 15:38:44 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002