[75] | 1 | /* |
---|
| 2 | * soclib_tty.c - soclib tty driver definition. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016) |
---|
| 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 soclib_multi_tty component. |
---|
| 31 | * 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 | ***************************************************************************************/ |
---|
| 35 | |
---|
| 36 | /**************************************************************************************** |
---|
| 37 | * SOCLIB_TTY registers offsets |
---|
| 38 | ***************************************************************************************/ |
---|
| 39 | |
---|
[407] | 40 | #define TTY_WRITE 0 |
---|
| 41 | #define TTY_STATUS 1 |
---|
| 42 | #define TTY_READ 2 |
---|
| 43 | #define TTY_RX_IRQ_ENABLE 3 |
---|
| 44 | #define TTY_TX_IRQ_ENABLE 4 |
---|
[75] | 45 | |
---|
[407] | 46 | #define TTY_SPAN 8 // number of registers per channel |
---|
[75] | 47 | |
---|
| 48 | /**************************************************************************************** |
---|
| 49 | * masks for TTY_STATUS_REG |
---|
| 50 | ***************************************************************************************/ |
---|
| 51 | |
---|
| 52 | #define TTY_STATUS_RX_FULL 1 // TTY_READ_REG full if 1 |
---|
| 53 | #define TTY_STATUS_TX_FULL 2 // TTY_WRITE_REG full if 1 |
---|
| 54 | |
---|
| 55 | /**************************************************************************************** |
---|
| 56 | * This function masks both the TTY_RX and TTY_TX IRQs. |
---|
| 57 | * These IRQs are unmasked by the soclib_tty_cmd() function. |
---|
| 58 | **************************************************************************************** |
---|
| 59 | * @ chdev : pointer on the TXT chdev descriptor. |
---|
| 60 | ***************************************************************************************/ |
---|
| 61 | void soclib_tty_init( chdev_t * chdev ); |
---|
| 62 | |
---|
| 63 | /**************************************************************************************** |
---|
[407] | 64 | * This function implements the TXT_READ & TXT_WRITE commands registered in the client |
---|
| 65 | * thread descriptor (in the txt_cmd field), identified by the <xp_thread> argument. |
---|
| 66 | * Depending on the command type, it only unmasks the relevant TTY_RX / TTY_TX IRQ, |
---|
| 67 | * and blocks the TXT device server thread on the THREAD_BLOCKED_DEV_ISR, as the data |
---|
| 68 | * transfer is done by the ISR. |
---|
| 69 | * **************************************************************************************** |
---|
[75] | 70 | * @ thread_xp : extended pointer on client thread descriptor. |
---|
| 71 | ***************************************************************************************/ |
---|
| 72 | void soclib_tty_cmd( xptr_t thread_xp ); |
---|
| 73 | |
---|
| 74 | /**************************************************************************************** |
---|
[407] | 75 | * This function implements the TXT_SYNC_WRITE command registered in the txt_aux_t |
---|
| 76 | * structure, using a busy waiting policy, without using the TTY IRQ. |
---|
| 77 | * It is used by the kernel do display debug messages on TXT0 terminal, without |
---|
| 78 | * interference with another TXT access to another terminal done by the same thread. |
---|
| 79 | **************************************************************************************** |
---|
| 80 | * @ thread_xp : pointer on the txt_aux_t structure containing the arguments. |
---|
| 81 | ***************************************************************************************/ |
---|
| 82 | void soclib_tty_aux( void * args ); |
---|
| 83 | |
---|
| 84 | /**************************************************************************************** |
---|
[424] | 85 | * This ISR is executed to handle both the TTY_TX_IRQ and the TTY_RX_IRQ. |
---|
| 86 | * - the TTY_RX_IRQ is activated as soon as the TTY_STATUS_RX_FULL bit is set in the |
---|
| 87 | * TTY status register, indicating a character registered in the TTY_READ register. |
---|
| 88 | * |
---|
| 89 | * . if it exist a TXT_READ command registered in the command queue, and thit copies the |
---|
| 90 | * character to the command buffer, acknowledges the TTY_RX_IRQ, and unblock the |
---|
| 91 | * associated server thread. |
---|
| 92 | |
---|
| 93 | * . the control characters are directly handled by the txt ^C / ^D / and the this IRQ ca |
---|
| 94 | * |
---|
| 95 | the TXT_READ and TXT_WRITE commands. |
---|
[75] | 96 | * It gets the command arguments from the first client thread in the TXT chdev queue: |
---|
| 97 | * - if TXT_READ, it transfers one byte from the TTY_READ_REG to the command buffer. |
---|
| 98 | * It simply returns for retry if TTY_READ_REG is empty. |
---|
| 99 | * - if TXT_WRITE, it tries to transfer several bytes from the command buffer to the |
---|
| 100 | * TTY_WRITE_REG. If the TTY_WRITE_REG is full, it updates the "count" and "buffer" |
---|
| 101 | * command arguments and returns for retry. |
---|
| 102 | * When the I/O operation is completed, it sets the status field in the command, unblocks |
---|
| 103 | * the server thread, and unblocks the client thread. |
---|
| 104 | **************************************************************************************** |
---|
| 105 | * @ chdev : local pointer on TXT chdev descriptor. |
---|
| 106 | ***************************************************************************************/ |
---|
| 107 | void soclib_tty_isr( chdev_t * chdev ); |
---|
| 108 | |
---|