source: trunk/hal/x86_64/drivers/txt_rs232.c @ 266

Last change on this file since 266 was 247, checked in by max@…, 7 years ago

Rename soclib_tty->txt_rs232.

File size: 3.0 KB
RevLine 
[75]1/*
[247]2 * txt_rs232.c - RS232 driver implementation
[75]3 *
[247]4 * Copyright (c) 2017 Maxime Villard
[75]5 *
[247]6 * This file is part of ALMOS-MKH.
[75]7 *
[247]8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[75]9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
[247]12 * ALMOS-MKH is distributed in the hope that it will be useful, but
[75]13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
[247]18 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[75]19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <dev_txt.h>
23#include <chdev.h>
[247]24#include <txt_rs232.h>
[75]25#include <remote_spinlock.h>
26#include <thread.h>
27#include <hal_special.h>
28
[100]29#include <hal_internal.h> // XXX
30
[247]31void txt_rs232_init(chdev_t *chdev)
[75]32{
[247]33        chdev->cmd = &txt_rs232_cmd;
34        chdev->isr = &txt_rs232_isr;
[244]35
[100]36        // nothing to do
[75]37}
38
[100]39// Pour le write: tout en sync, ça part direct sur le VGA/série
40// Pour le read: là on attend l'ISR
[247]41void txt_rs232_cmd(xptr_t th_xp)
[75]42{
[100]43        // get client thread cluster and local pointer
44        cxy_t      th_cxy = GET_CXY( th_xp );
45        thread_t * th_ptr = (thread_t *)GET_PTR( th_xp );
46
47        // get command type and extended pointer on TXT device
48        uint32_t type   =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.type ) );
49        xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.dev_xp ) );
50
51        // get TXT device cluster and local pointer
52        cxy_t     dev_cxy = GET_CXY( dev_xp );
53        chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
54
[247]55        // get extended pointer on base segment
[100]56        xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
57
[247]58        // get base segment cluster and local pointer
[100]59        cxy_t      tty_cxy = GET_CXY( tty_xp );
60        uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp );
61
62        // get TTY channel index
63        uint32_t   channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) );
64
65        // for now, only channel zero
66        if (channel != 0) {
67                x86_panic("should have been channel zero");
68        }
69
70        if (type == TXT_READ)              // descheduling strategy for calling thread
71        {
72                x86_panic("TXT_READ not handled");
73        }
74        else if (type == TXT_WRITE || type == TXT_SYNC_WRITE) // busy waiting strategy for calling thread
75        {
76                uint32_t   i;
77
78                // get source buffer extended pointer & bytes count
79                uint32_t count  = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.count ) );
80                xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.buf_xp ) );
81
82                // loop on characters
83                for (i = 0; i < count; i++)
84                {
85                        // get one byte from command buffer in client cluster
86                        char byte = (char)hal_remote_lb( buf_xp + i );
87
88                        // VGA output (for now)
89                        x86_putc(byte);
90                }
91        }
[75]92}
93
[247]94void txt_rs232_isr(chdev_t *chdev)
[75]95{
[89]96        // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche
97        // est pressée
[247]98        x86_panic("txt_rs232_isr not handled");
[75]99}
100
Note: See TracBrowser for help on using the repository browser.