bbs_simcpu_0.1.0_73ecd6e3/src/io/bbs-sim_cpu-serial-telnet.ads

  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
--
--  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 a simple 8-bit console interface via network.
--  The user can telnet to the specified port to access the device.
--
--  Two addresses are used.
--  base + 0 - Status (R/W)
--  base + 1 - Data (R/W)
--    Status bits:
--      0 - Ready (RO)
--      1 - Connected (RO)
--      2 - Enable interrupt (R/W)
--      3 - Reset (WO)
--
--  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.telnet is
   --
   --  The device object for a network based TTY.
   --
   type tel_tty is new io_device with private;
   type telnet_access is access all tel_tty;
   --
   --  Task type for telnet type server.
   --
   --  Note that the "Start" entry should only be called once.  Other
   --  calls are ignored.
   --
   task type telnet_server is
     entry start(self : telnet_access; port : GNAT.Sockets.Port_Type; owner : BBS.Sim_CPU.sim_access);
     entry write(char : Character);
     entry end_task;
   end telnet_server;
   --
   --  I/O device actions
   --
   --  Write to a port address
   --
   overriding
   procedure write(self : in out tel_tty; addr : addr_bus; data : data_bus);
   --
   --  Read from a port address
   --
   overriding
   function read(self : in out tel_tty; addr : addr_bus) return data_bus;
   --
   --  How many addresses are used by the port
   --
   overriding
   function getSize(self : in out tel_tty) return addr_bus is (2);
   --
   --  Get the base address
   --
   overriding
   function getBase(self : in out tel_tty) return addr_bus;
   --
   --  Set the base address
   --
   overriding
   procedure setBase(self : in out tel_tty; base : addr_bus);
   --
   --  Set the owner (used mainly for DMA and interrupts)
   --
   overriding
   procedure setOwner(self : in out tel_tty; owner : sim_access);
   --
   --  Get device name/description
   --
   overriding
   function name(self : in out tel_tty) return string is ("8 Bit Telnet Port");
   --
   --  Set device port and do the network initialiation.  This must be
   --  done before using the device.
   --
   procedure init(self : in out tel_tty; ptr : telnet_access; port : GNAT.Sockets.Port_Type);
   --
   --  Close the network connection and halt the tasks.
   --
   procedure shutdown(self : in out tel_tty);
   --
   --  Set which exception to use
   --
   overriding
   procedure setException(self : in out tel_tty; except : long);
   --
private
   CRLF : constant String := Ada.Characters.Latin_1.CR & Ada.Characters.Latin_1.LF;
   --
   --  The definition of the 8 bit console object via telnet
   --
   type tel_tty is new io_device with record
      ready     : Boolean := False;  --  Data ready to read
      connected : Boolean := False;
      disconnecting : Boolean := False;
      int_e     : Boolean := False;  --  Interrupt enable
      int_code  : long;
      char      : Character := Character'Val(0);
      host      : BBS.Sim_CPU.sim_access;
      T         : BBS.sim_cpu.serial.telnet.telnet_server;
   end record;
   --
   --  Task for telnet receiver
   --
   task type telnet_rx is
      entry start(self : telnet_access; sock : GNAT.Sockets.Socket_Type; owner : BBS.Sim_CPU.sim_access);
      entry end_task;
   end telnet_rx;

end;