XINU
ttyhandle_out.c
Go to the documentation of this file.
1 /* ttyhandle_out.c - ttyhandle_out */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * ttyhandle_out - Handle an output on a tty device by sending more
7  * characters to the device FIFO (interrupts disabled)
8  *------------------------------------------------------------------------
9  */
11  struct ttycblk *typtr, /* Ptr to ttytab entry */
12  struct uart_csreg *csrptr /* Address of UART's CSRs */
13  )
14 {
15 
16  int32 ochars; /* Number of output chars sent */
17  /* to the UART */
18  int32 avail; /* Available chars in output buf*/
19  int32 uspace; /* Space left in onboard UART */
20  /* output FIFO */
21  uint32 ier = 0;
22 
23  /* If output is currently held, simply ignore the call */
24 
25  if (typtr->tyoheld) {
26  return;
27  }
28 
29  /* If echo and output queues empty, turn off interrupts */
30 
31  if ( (typtr->tyehead == typtr->tyetail) &&
32  (semcount(typtr->tyosem) >= TY_OBUFLEN) ) {
33  ier = csrptr->ier;
34  csrptr->ier = ier & ~UART_IER_ETBEI;
35  return;
36  }
37 
38  /* Initialize uspace to the available space in the Tx FIFO */
39 
40  uspace = UART_FIFO_SIZE - csrptr->txfifo_lvl;
41 
42  /* While onboard FIFO is not full and the echo queue is */
43  /* nonempty, xmit chars from the echo queue */
44 
45  while ( (uspace>0) && typtr->tyehead != typtr->tyetail) {
46  csrptr->buffer = *typtr->tyehead++;
47  if (typtr->tyehead >= &typtr->tyebuff[TY_EBUFLEN]) {
48  typtr->tyehead = typtr->tyebuff;
49  }
50  uspace--;
51  }
52 
53  /* While onboard FIFO is not full and the output queue is */
54  /* nonempty, transmit chars from the output queue */
55 
56  ochars = 0;
57  avail = TY_OBUFLEN - semcount(typtr->tyosem);
58  while ( (uspace>0) && (avail > 0) ) {
59  csrptr->buffer = *typtr->tyohead++;
60  if (typtr->tyohead >= &typtr->tyobuff[TY_OBUFLEN]) {
61  typtr->tyohead = typtr->tyobuff;
62  }
63  avail--;
64  uspace--;
65  ochars++;
66  }
67  if (ochars > 0) {
68  signaln(typtr->tyosem, ochars);
69  }
70 
71  if ( (typtr->tyehead == typtr->tyetail) &&
72  (semcount(typtr->tyosem) >= TY_OBUFLEN) ) {
73  ier = csrptr->ier;
74  csrptr->ier = (ier & ~UART_IER_ETBEI);
75  }
76  return;
77 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
#define TY_EBUFLEN
Definition: tty.h:5
#define UART_IER_ETBEI
Definition: uart.h:66
volatile uint32 buffer
Definition: uart.h:15
volatile uint32 txfifo_lvl
Definition: uart.h:32
syscall signaln(sid32, int32)
セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。 ...
Definition: signaln.c:16
全てのシステムヘッダファイルをインクルードする。
void ttyhandle_out(struct ttycblk *typtr, struct uart_csreg *csrptr)
Definition: ttyhandle_out.c:10
volatile uint32 ier
Definition: uart.h:17
bool8 tyoheld
Definition: tty.h:53
Definition: tty.h:26
char * tyehead
Definition: tty.h:35
char tyobuff[TY_OBUFLEN]
Definition: tty.h:33
char * tyetail
Definition: tty.h:36
char * tyohead
Definition: tty.h:31
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define TY_OBUFLEN
Definition: tty.h:16
#define UART_FIFO_SIZE
Definition: uart.h:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
char tyebuff[TY_EBUFLEN]
Definition: tty.h:37
sid32 tyosem
Definition: tty.h:34