1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 | --
-- Author: Brent Seidel
-- Date: 31-Jul-2024
--
-- This file is part of SimCPU.
-- SimCPU is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation, either version 3 of the License, or (at your
-- option) any later version.
--
-- SimCPU is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-- Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with SimCPU. If not, see <https://www.gnu.org/licenses/>.--
--
with GNAT.Sockets;
with Ada.Characters.Latin_1;
-- ----------------------------------------------------------------------
-- This is an I/O device for an 8 line telnet multiplexer. The simulation
-- sees one device that controls 8 serial lines.
--
-- Two addresses are used.
-- base + 0 - Ready (RO)
-- base + 1 - Status
-- base + 2 - Channel 0 Data (R/W)
-- base + 3 - Channel 1 Data (R/W)
-- base + 4 - Channel 2 Data (R/W)
-- base + 5 - Channel 3 Data (R/W)
-- base + 6 - Channel 4 Data (R/W)
-- base + 7 - Channel 5 Data (R/W)
-- base + 8 - Channel 6 Data (R/W)
-- base + 9 - Channel 7 Data (R/W)
-- Status bits:
-- 0 - Enable interrupt (R/W)
-- 1 - Reset (WO)
-- There is one bit in the Ready register for each channel. Bit 0 is
-- for channel 0, and so on.
--
-- Writes to the data port complete immediately as far as the simulator is concerned
-- Reads from the data port return the buffered read character and clear the ready
-- flag.
--
package BBS.Sim_CPU.serial.mux is
--
-- The device object for a network based TTY.
--
type mux_tty is new io_device with private;
type mux_access is access all mux_tty;
--
-- The channel object
--
type mux_channel is limited private;
type channel_access is access all mux_channel;
--
-- Task type for telnet type server.
--
-- Note that the "Start" entry should only be called once. Other
-- calls are ignored.
--
task type mux_server is
entry start(self : mux_access; index : integer; port : GNAT.Sockets.Port_Type; owner : BBS.Sim_CPU.sim_access);
entry write(char : Character);
entry end_task;
end mux_server;
--
-- I/O device actions
--
-- Write to a port address
--
overriding
procedure write(self : in out mux_tty; addr : addr_bus; data : data_bus);
--
-- Read from a port address
--
overriding
function read(self : in out mux_tty; addr : addr_bus) return data_bus;
--
-- How many addresses are used by the port
--
overriding
function getSize(self : in out mux_tty) return addr_bus is (10);
--
-- Get the base address
--
overriding
function getBase(self : in out mux_tty) return addr_bus;
--
-- Set the base address
--
overriding
procedure setBase(self : in out mux_tty; base : addr_bus);
--
-- Set the owner (used mainly for DMA and interrupts)
--
overriding
procedure setOwner(self : in out mux_tty; owner : sim_access);
--
-- Get device name/description
--
overriding
function name(self : in out mux_tty) return string is ("8 Channel Telnet Port");
--
-- Set device port and do the network initialiation. This must be
-- done before using the device.
--
procedure init(self : in out mux_tty; ptr : mux_access; port : GNAT.Sockets.Port_Type);
--
-- Close the network connection and halt the tasks.
--
procedure shutdown(self : in out mux_tty);
--
-- Set which exception to use
--
overriding
procedure setException(self : in out mux_tty; except : long);
--
private
CRLF : constant String := Ada.Characters.Latin_1.CR & Ada.Characters.Latin_1.LF;
--
-- The definition of a single channel of the interface
--
type mux_channel is limited record
ready : Boolean := False;
connected : Boolean := False;
disconnecting : Boolean := False;
char : Character := Character'Val(0);
T : BBS.sim_cpu.serial.mux.mux_server;
end record;
type channels is array (0 .. 7) of mux_channel;
--
-- The definition of the 8 channel interface
--
type mux_tty is new io_device with record
int_e : Boolean := False; -- Interrupt enable
int_code : long;
host : BBS.Sim_CPU.sim_access;
chan : channels;
end record;
--
-- Task for telnet receiver
--
task type mux_rx is
entry start(self : mux_access; index : Integer; sock : GNAT.Sockets.Socket_Type; owner : BBS.Sim_CPU.sim_access);
entry end_task;
end mux_rx;
end;
|