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 | |
---|
31 | void 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 |
---|
41 | void 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_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 ) ); |
---|
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 |
---|
56 | uint32_t channel = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->channel ) ); |
---|
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 |
---|
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 ) ); |
---|
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 | } |
---|
85 | } |
---|
86 | |
---|
87 | void txt_rs232_isr(chdev_t *chdev) |
---|
88 | { |
---|
89 | // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche |
---|
90 | // est pressée |
---|
91 | x86_panic("txt_rs232_isr not handled"); |
---|
92 | } |
---|
93 | |
---|