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

Last change on this file since 280 was 280, checked in by max@…, 4 years ago

sync

File size: 3.0 KB
Line 
1/*
2 * txt_rs232.c - RS232 driver implementation
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
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 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
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
18 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <dev_txt.h>
23#include <chdev.h>
24#include <txt_rs232.h>
25#include <remote_spinlock.h>
26#include <thread.h>
27#include <hal_special.h>
28
29#include <hal_internal.h> // XXX
30
31void txt_rs232_init(chdev_t *chdev)
32{
33        chdev->cmd = &txt_rs232_cmd;
34        chdev->isr = &txt_rs232_isr;
35
36        // nothing to do
37}
38
39// Pour le write: tout en sync, ça part direct sur le VGA/série
40// Pour le read: là on attend l'ISR
41void txt_rs232_cmd(xptr_t th_xp)
42{
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->txt_cmd.type ) );
49        xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->txt_cmd.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
55        // get extended pointer on base segment
56        xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
57
58        // get base segment cluster and local pointer
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->txt_cmd.count ) );
80                xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->txt_cmd.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        }
92}
93
94void txt_rs232_isr(chdev_t *chdev)
95{
96        // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche
97        // est pressée
98        x86_panic("txt_rs232_isr not handled");
99}
100
Note: See TracBrowser for help on using the repository browser.