source: trunk/hal/tsar_mips32/drivers/soclib_tty.h @ 657

Last change on this file since 657 was 570, checked in by alain, 6 years ago

Introduction of the soclib_mty driver for the TSAR-LETI architecture.

File size: 8.7 KB
Line 
1/*
2 * soclib_tty.c - soclib_tty driver definition (used in the TSAR_IOB architecture).
3 *
4 * Author  Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c)  UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <dev_txt.h>
25#include <chdev.h>
26
27
28/****************************************************************************************
29 * This driver supports the vci_tty_tsar component.
30 *
31 * 1) This hardware component handles several hardware channels, supporting directly
32 *    several kernel TXT channels.
33 * 2) For received characters, the hardware support one RX_IRQ, and one bit
34 *    in the STATUS register to signal that the READ register is full.
35 * 3) For transmitted characters, the hardware supports one RX_IRQ, and one bit
36 *    in STATUS register to signal that the WRITE register is empty.
37 *
38 * It implements the generic TXT device API:
39 * - transfer one single character from TTY to command "buffer" if to_mem is non-zero.
40 * - transfer "count" characters from command "buffer" to TTY if to_mem is zero.
41 *
42 * It handles asynchronous control characters (^C / ^Z), that are translated to signals
43 * transmited to the TXT owner process (foreground process).
44 *
45 * This driver implements one TX_FIFO for the transmited characters, writen by the "cmd"
46 * function, and read by the "isr" function).
47 * This driver implements one RX_FIFO for the received characters, writen by the "isr"
48 * function, and read by the "cmd" function).
49 ***************************************************************************************/
50
51/****************************************************************************************
52 *     SOCLIB_TTY registers offsets
53 ***************************************************************************************/
54
55#define TTY_WRITE              0
56#define TTY_STATUS             1
57#define TTY_READ               2
58#define TTY_RX_IRQ_ENABLE      3
59#define TTY_TX_IRQ_ENABLE      4
60
61#define TTY_SPAN               8       // number of registers per channel
62
63/****************************************************************************************
64 * masks for TTY_STATUS_REG
65 ***************************************************************************************/
66
67#define TTY_STATUS_RX_FULL     1       // TTY_READ_REG full if 1
68#define TTY_STATUS_TX_FULL     2       // TTY_WRITE_REG full if 1
69
70/****************************************************************************************
71 * This structure is used for both the RX_FIFO and the TX_FIFO.
72 ***************************************************************************************/
73
74#define TTY_FIFO_DEPTH  128
75
76typedef struct tty_fifo_s
77{
78    char          data[TTY_FIFO_DEPTH];   // one char per slot
79    unsigned int  ptr;                    // next free slot index
80    unsigned int  ptw;                    // next full slot index
81    unsigned int  sts;                    // number of full slots
82} 
83tty_fifo_t;
84
85/****************************************************************************************
86 * This function masks both the TTY_RX and TTY_TX IRQs.
87 * These IRQs are unmasked by the soclib_tty_cmd() function.
88 ****************************************************************************************
89 * @ chdev     : pointer on the TXT chdev descriptor.
90 ***************************************************************************************/
91void soclib_tty_init( chdev_t * chdev );
92
93/****************************************************************************************
94 * This function implements both the TXT_READ & TXT_WRITE commands registered in the
95 * client thread descriptor (in the txt_cmd field), even if ALMOS-MKH defines two
96 * different chdevs (and consequently two diffeerent server threads) for the RX and TX
97 * directions. The client thread is identified by the <thread_xp> argument.
98 * These functions are supposed to be called by the server thread associated at a
99 * given TXT channel for a given direction (TX or RX).
100 * Depending on the command type, it access the TX_FIFO or RX_FIFO, and blocks the TXT
101 * device server thread on the THREAD_BLOCKED_DEV_ISR, if the RX_FIFO is empty (for a
102 * READ), or if the TX_FIFO is full for a WRITE).
103 * The actual transfer between the FIFOs and the TTY device registers is done by the ISR.
104 * ****************************************************************************************
105 * @ thread_xp : extended pointer on client thread descriptor.
106 ***************************************************************************************/
107void soclib_tty_cmd( xptr_t thread_xp );
108
109/****************************************************************************************
110 * This function implements the TXT_SYNC_WRITE command registered in the txt_aux_t
111 * structure, using a busy waiting policy, without using the TTY IRQ.
112 * It is used by the kernel do display debug messages on TXT0 terminal, without
113 * interference with another TXT access to another terminal done by the same thread.
114 ****************************************************************************************
115 * @ thread_xp : pointer on the txt_aux_t structure containing the arguments.
116 ***************************************************************************************/
117void soclib_tty_aux( void * args );
118
119/****************************************************************************************
120 * This ISR is executed to handle both the TTY_TX_IRQ and the TTY_RX_IRQ, even if
121 * there is two different channel devices for TX and RX transfers.
122 *
123 * As the <chdev> argument is a local pointer, this ISR is always executed by a core
124 * that is in the same cluster as the core running the DEV server thread.
125 *
126 * - The RX_IRQ is activated as soon as the TTY_STATUS_RX_FULL bit is 1 in the
127 *   TTY_STATUS register, when the TTY_RX_IRQ_ENABLE is non zero, indicating that
128 *   the TTY_READ buffer is full and can be read.
129 * - The TX_IRQ is activated as soon as the TTY_STATUS_TX_FULL bit is 0 in the
130 *   TTY_STATUS register, when the TTY_TX_IRQ_ENABLE is non zero, indicating that
131 *   the TTY_WRITE buffer is empty, and can be written.
132 *
133 * The RX_IRQ is always enabled to catch the control characters (^Z / ^C),
134 * but the TX_IRQ is dynamically enabled by the TXT_WRITE command, and disabled when
135 * the command is completed.
136 *
137 * For normal characters The ISR uses two private TTY_RX and TTY_TX software FIFOs
138 * (two FIFOs per channel) to communicates with the DEV server thread executing the
139 * soclib_tty_cmd() function.
140
141 * For an RX transfer, this ISR executes a while loop moving bytes until the source
142 * TTY_READ buffer is empty:
143 *   1) The ISR read one byte from the TTY_READ register and acknowledge the RX_IRQ.
144 *   2) if the byte is a ^Z character, it uses a multicast RPC to block all treads of
145 *      the TXT owner process, and transfer TXT ownership to another process of the group.
146 *   3) if the byte is a ^C character, it removes the process from the TXT group, and send
147 *      a multicast RPC to delete all threads of the TXT owner process.
148 *   4) if the byte is a normal character and the destination TTY_RX_FIFO is not full,
149 *      it writes the byte to this FIFO, unblock the TXT_RX server thread, and send an IPI
150 *      to this server thread (only if it is running on another core than the ISR).
151 *   5) It discards the byte if the TTY_RX_FIFO is full, with a warning message on TXT0.
152 *
153 * For a TX transfer, this ISR executes a while loop moving bytes until the source
154 * TTY_TX_FIFO is empty:
155 *   1) if the destination TTY_WRITE register is not full, it moves the byte from the
156 *      TTY_TX_FIFO to the TTY_WRITE register.
157 *   2) if the TTY_WRITE register is full, it polls (busy waiting) the TTY_STATUS register,
158 *      until the TTY_WRITE register is empty.
159 *   3) when the source TTY_TX_FIFO is empty, this ISR disable the TTY_TX_IRQ, unblock
160 *      the TXT_TX server thread, and send an IPI to this server thread (only if it is
161 *      running on another core than the ISR).
162 ****************************************************************************************
163 * @ chdev     : local pointer on TXT chdev descriptor.
164 ***************************************************************************************/
165void soclib_tty_isr( chdev_t * chdev );
166
Note: See TracBrowser for help on using the repository browser.