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

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

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

File size: 2.7 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
[570]48        uint32_t type   =         hal_remote_l32 ( XPTR( th_cxy , &th_ptr->txt_cmd.type ) );
49        xptr_t   dev_xp = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->txt_cmd.dev_xp ) );
[100]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 TTY channel index
[570]56        uint32_t   channel = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->channel ) );
[100]57
58        // for now, only channel zero
59        if (channel != 0) {
60                x86_panic("should have been channel zero");
61        }
62
63        if (type == TXT_READ)              // descheduling strategy for calling thread
64        {
65                x86_panic("TXT_READ not handled");
66        }
67        else if (type == TXT_WRITE || type == TXT_SYNC_WRITE) // busy waiting strategy for calling thread
68        {
69                uint32_t   i;
70
71                // get source buffer extended pointer & bytes count
[570]72                uint32_t count  = hal_remote_l32 ( XPTR( th_cxy , &th_ptr->txt_cmd.count ) );
73                xptr_t   buf_xp = hal_remote_l64( XPTR( th_cxy , &th_ptr->txt_cmd.buf_xp ) );
[100]74
75                // loop on characters
76                for (i = 0; i < count; i++)
77                {
78                        // get one byte from command buffer in client cluster
79                        char byte = (char)hal_remote_lb( buf_xp + i );
80
81                        // VGA output (for now)
82                        x86_putc(byte);
83                }
84        }
[75]85}
86
[247]87void txt_rs232_isr(chdev_t *chdev)
[75]88{
[89]89        // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche
90        // est pressée
[247]91        x86_panic("txt_rs232_isr not handled");
[75]92}
93
Note: See TracBrowser for help on using the repository browser.