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

Last change on this file since 527 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 7.8 KB
Line 
1/*
2 * soclib_tty.c - soclib tty driver definition.
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#include <spinlock.h>
27
28
29/****************************************************************************************
30 * This driver supports the vci_tty_tsar component.
31 * Regarding read/write request, it implements the generic TXT device API:
32 * - transfer one single character from TTY to command "buffer" if to_mem is non-zero.
33 * - transfer "count" characters from command "buffer" to TTY if "to_mem is zero.
34 * It handles asynchronous control characters (^C / ^Z), that are translated to signals
35 * transmited to the TXT owner process (foreground process).
36 ***************************************************************************************/
37
38/****************************************************************************************
39 *     SOCLIB_TTY registers offsets
40 ***************************************************************************************/
41
42#define TTY_WRITE              0
43#define TTY_STATUS             1
44#define TTY_READ               2
45#define TTY_RX_IRQ_ENABLE      3
46#define TTY_TX_IRQ_ENABLE      4
47
48#define TTY_SPAN               8       // number of registers per channel
49
50/****************************************************************************************
51 * masks for TTY_STATUS_REG
52 ***************************************************************************************/
53
54#define TTY_STATUS_RX_FULL     1       // TTY_READ_REG full if 1
55#define TTY_STATUS_TX_FULL     2       // TTY_WRITE_REG full if 1
56
57/****************************************************************************************
58 * This Rstructure is used by the soclib_tty_isr for the RX channel.
59 ***************************************************************************************/
60
61#define TTY_FIFO_DEPTH  128
62
63typedef struct tty_fifo_s     // 32 bytes
64{
65    char          data[TTY_FIFO_DEPTH];   // one char per slot
66    unsigned int  ptr;                    // next free slot index
67    unsigned int  ptw;                    // next full slot index
68    unsigned int  sts;                    // number of full slots
69} tty_fifo_t;
70 
71
72/****************************************************************************************
73 * This function masks both the TTY_RX and TTY_TX IRQs.
74 * These IRQs are unmasked by the soclib_tty_cmd() function.
75 ****************************************************************************************
76 * @ chdev     : pointer on the TXT chdev descriptor.
77 ***************************************************************************************/
78void soclib_tty_init( chdev_t * chdev );
79
80/****************************************************************************************
81 * This function implements both the TXT_READ & TXT_WRITE commands registered in the
82 * client thread descriptor (in the txt_cmd field), even if ALMOS-MKH defines two
83 * different chdevs (and consequently two diffeerent server threads) for the RX and TX
84 * directions. The client thread is identified by the <thread_xp> argument.
85 * Depending on the command type, it unmasks the relevant TTY_RX / TTY_TX IRQ,
86 * and blocks the TXT device server thread on the THREAD_BLOCKED_DEV_ISR, as the data
87 * transfer is done by the ISR.
88 * ****************************************************************************************
89 * @ thread_xp : extended pointer on client thread descriptor.
90 ***************************************************************************************/
91void soclib_tty_cmd( xptr_t thread_xp );
92
93/****************************************************************************************
94 * This function implements the TXT_SYNC_WRITE command registered in the txt_aux_t
95 * structure, using a busy waiting policy, without using the TTY IRQ.
96 * It is used by the kernel do display debug messages on TXT0 terminal, without
97 * interference with another TXT access to another terminal done by the same thread.
98 ****************************************************************************************
99 * @ thread_xp : pointer on the txt_aux_t structure containing the arguments.
100 ***************************************************************************************/
101void soclib_tty_aux( void * args );
102
103/****************************************************************************************
104 * This ISR is executed to handle both the TTY_TX_IRQ and the TTY_RX_IRQ, even if
105 * there is two different channel devices for TX and RX transfers.
106 *
107 * As the <chdev> argument is a local pointer, this ISR is always executed by a core
108 * that is in the same cluster as the core running the DEV server thread.
109 *
110 * - The RX_IRQ is activated as soon as the TTY_STATUS_RX_FULL bit is 1 in the
111 *   TTY_STATUS register, when the TTY_RX_IRQ_ENABLE is non zero, indicating that
112 *   the TTY_READ buffer is full and can be read.
113 * - The TX_IRQ is activated as soon as the TTY_STATUS_TX_FULL bit is 0 in the
114 *   TTY_STATUS register, when the TTY_TX_IRQ_ENABLE is non zero, indicating that
115 *   the TTY_WRITE buffer is empty, and can be written.
116 *
117 * The RX_IRQ is always enabled to catch the control characters (^Z / ^C),
118 * but the TX_IRQ is dynamically enabled by the TXT_WRITE command, and disabled when
119 * the command is completed.
120 *
121 * For normal characters The ISR uses two private TTY_RX and TTY_TX software FIFOs
122 * (two FIFOs per channel) to communicates with the DEV server thread executing the
123 * soclib_tty_cmd() function.
124
125 * For an RX transfer, this ISR executes a while loop moving bytes until the source
126 * TTY_READ buffer is empty:
127 *   1) The ISR read one byte from the TTY_READ register and acknowledge the RX_IRQ.
128 *   2) if the byte is a ^Z character, it uses a multicast RPC to block all treads of
129 *      the TXT owner process, and transfer TXT ownership to another process of the group.
130 *   3) if the byte is a ^C character, it removes the process from the TXT group, and send
131 *      a multicast RPC to delete all threads of the TXT owner process.
132 *   4) if the byte is a normal character and the destination TTY_RX_FIFO is not full,
133 *      it writes the byte to this FIFO, unblock the TXT_RX server thread, and send an IPI
134 *      to this server thread (only if it is running on another core than the ISR).
135 *   5) It discards the byte if the TTY_RX_FIFO is full, with a warning message on TXT0.
136 *
137 * For a TX transfer, this ISR executes a while loop moving bytes until the source
138 * TTY_TX_FIFO is empty:
139 *   1) if the destination TTY_WRITE register is not full, it moves the byte from the
140 *      TTY_TX_FIFO to the TTY_WRITE register.
141 *   2) if the TTY_WRITE register is full, it polls (busy waiting) the TTY_STATUS register,
142 *      until the TTY_WRITE register is empty.
143 *   3) when the source TTY_TX_FIFO is empty, this ISR disable the TTY_TX_IRQ, unblock
144 *      the TXT_TX server thread, and send an IPI to this server thread (only if it is
145 *      running on another core than the ISR).
146 ****************************************************************************************
147 * @ chdev     : local pointer on TXT chdev descriptor.
148 ***************************************************************************************/
149void soclib_tty_isr( chdev_t * chdev );
150
Note: See TracBrowser for help on using the repository browser.