|
| 1 | +/* h316_imp.h- BBN ARPAnet IMP/TIP Definitions |
| 2 | +
|
| 3 | + Copyright (c) 2013, Robert Armstrong, bob@jfcl.com |
| 4 | +
|
| 5 | + Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | + copy of this software and associated documentation files (the "Software"), |
| 7 | + to deal in the Software without restriction, including without limitation |
| 8 | + the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | + and/or sell copies of the Software, and to permit persons to whom the |
| 10 | + Software is furnished to do so, subject to the following conditions: |
| 11 | +
|
| 12 | + The above copyright notice and this permission notice shall be included in |
| 13 | + all copies or substantial portions of the Software. |
| 14 | +
|
| 15 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | + ROBERT ARMSTRONG BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 19 | + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | +
|
| 22 | + Except as contained in this notice, the name of Robert Armstrong shall not be |
| 23 | + used in advertising or otherwise to promote the sale, use or other dealings |
| 24 | + in this Software without prior written authorization from Robert Armstrong. |
| 25 | +
|
| 26 | + 21-May-13 RLA New file. |
| 27 | +*/ |
| 28 | +#ifdef VM_IMPTIP |
| 29 | +#ifndef H316_IMP_H_ |
| 30 | +#define H316_IMP_H_ 0 |
| 31 | +#include "sim_defs.h" |
| 32 | + |
| 33 | +// Common modem and host parameters ... |
| 34 | +#define MI_NUM 5 // number of modem interfaces |
| 35 | +#define HI_NUM 4 // number of host interfaces |
| 36 | +#define MI_MAX_MSG 256 // longest possible modem message (words!) |
| 37 | +#define HI_MAX_MSG 256 // longest possible host message (words!) |
| 38 | +#define MI_RXPOLL 100 // RX polling delay for UDP messages |
| 39 | +#define MI_TXBPS 56000UL // default modem TX speed (bits per second) |
| 40 | +#define HI_TXBPS 100000UL // default host TX speed (bits per second) |
| 41 | +#define HI_POLL_DELAY 1000 // polling delay for messages |
| 42 | + |
| 43 | +// Modem interface, line #1 ... |
| 44 | +#define MI1 071 // IO address for modem interface #1 |
| 45 | +#define MI1_RX_DMC (DMC1-1+ 1) // DMC channel for modem 1 receive |
| 46 | +#define MI1_TX_DMC (DMC1-1+ 6) // DMC channel for modem 1 transmit |
| 47 | +#define INT_V_MI1RX (INT_V_EXTD+15) // modem 1 receive interrupt |
| 48 | +#define INT_V_MI1TX (INT_V_EXTD+10) // modem 1 transmit interrupt |
| 49 | + |
| 50 | +// Modem interface, line #2 ... |
| 51 | +#define MI2 072 // IO address for modem interface #2 |
| 52 | +#define MI2_RX_DMC (DMC1-1+ 2) // DMC channel for modem 2 receive |
| 53 | +#define MI2_TX_DMC (DMC1-1+ 7) // DMC channel for modem 2 transmit |
| 54 | +#define INT_V_MI2RX (INT_V_EXTD+14) // modem 2 receive interrupt |
| 55 | +#define INT_V_MI2TX (INT_V_EXTD+ 9) // modem 2 transmit interrupt |
| 56 | + |
| 57 | +// Modem interface, line #3 ... |
| 58 | +#define MI3 073 // IO address for modem interface #3 |
| 59 | +#define MI3_RX_DMC (DMC1-1+ 3) // DMC channel for modem 3 receive |
| 60 | +#define MI3_TX_DMC (DMC1-1+ 8) // DMC channel for modem 3 transmit |
| 61 | +#define INT_V_MI3RX (INT_V_EXTD+13) // modem 3 receive interrupt |
| 62 | +#define INT_V_MI3TX (INT_V_EXTD+ 8) // modem 3 transmit interrupt |
| 63 | + |
| 64 | +// Modem interface, line #4 ... |
| 65 | +#define MI4 074 // IO address for modem interface #4 |
| 66 | +#define MI4_RX_DMC (DMC1-1+ 4) // DMC channel for modem 4 receive |
| 67 | +#define MI4_TX_DMC (DMC1-1+ 9) // DMC channel for modem 4 transmit |
| 68 | +#define INT_V_MI4RX (INT_V_EXTD+12) // modem 4 receive interrupt |
| 69 | +#define INT_V_MI4TX (INT_V_EXTD+ 7) // modem 4 transmit interrupt |
| 70 | + |
| 71 | +// Modem interface, line #5 ... |
| 72 | +#define MI5 075 // IO address for modem interface #5 |
| 73 | +#define MI5_RX_DMC (DMC1-1+ 5) // DMC channel for modem 5 receive |
| 74 | +#define MI5_TX_DMC (DMC1-1+10) // DMC channel for modem 5 transmit |
| 75 | +#define INT_V_MI5RX (INT_V_EXTD+11) // modem 5 receive interrupt |
| 76 | +#define INT_V_MI5TX (INT_V_EXTD+ 6) // modem 5 transmit interrupt |
| 77 | + |
| 78 | +// Host interface, line #1 ... |
| 79 | +#define HI1 070 // device address for host interface #1 |
| 80 | +#define HI1_RX_DMC (DMC1+13-1) // DMC channel for host 1 receive |
| 81 | +#define HI1_TX_DMC (DMC1+11-1) // DMC channel for host 1 transmit |
| 82 | +#define INT_V_HI1RX (INT_V_EXTD+ 3) // host 1 receive interrupt |
| 83 | +#define INT_V_HI1TX (INT_V_EXTD+ 5) // host 1 transmit interrupt |
| 84 | + |
| 85 | +// Host interface, line #2 ... |
| 86 | +#define HI2 060 // device address for host interface #2 |
| 87 | +#define HI2_RX_DMC (DMC1-1+14) // DMC channel for host 2 receive |
| 88 | +#define HI2_TX_DMC (DMC1-1+12) // DMC channel for host 2 transmit |
| 89 | +#define INT_V_HI2RX (INT_V_EXTD+ 2) // host 2 receive interrupt |
| 90 | +#define INT_V_HI2TX (INT_V_EXTD+ 4) // host 2 transmit interrupt |
| 91 | + |
| 92 | +// Host interface, line #3 ... |
| 93 | +#define HI3 051 // device address for host interface #3 |
| 94 | +#define HI3_RX_DMC (DMC1-1+16) // DMC channel for host 3 receive |
| 95 | +#define HI3_TX_DMC (DMC1-1+15) // DMC channel for host 3 transmit |
| 96 | +#define INT_V_HI3RX (INT_V_EXTD+ 6) // host 3 receive interrupt |
| 97 | +#define INT_V_HI3TX (INT_V_EXTD+11) // host 3 transmit interrupt |
| 98 | + |
| 99 | +// Host interface, line #4 ... |
| 100 | +#define HI4 050 // device address for host interface #4 |
| 101 | +#define HI4_RX_DMC (DMC1-1+10) // DMC channel for host 4 receive |
| 102 | +#define HI4_TX_DMC (DMC1-1+ 5) // DMC channel for host 4 transmit |
| 103 | +#define INT_V_HI4RX (INT_V_EXTD+ 7) // host 4 receive interrupt |
| 104 | +#define INT_V_HI4TX (INT_V_EXTD+12) // host 4 transmit interrupt |
| 105 | + |
| 106 | +// IMP defaults ... |
| 107 | +#define IMP 041 // IMP device IO address (41 & 42 actually!) |
| 108 | +#define INT_V_TASK (INT_V_EXTD+ 0) // task switch interrupt number |
| 109 | +#define IMP_STATION 1 // default station number |
| 110 | + |
| 111 | +// RTC defaults ... |
| 112 | +#define RTC 040 // real time clock IO address |
| 113 | +#define INT_V_RTC (INT_V_EXTD+ 1) // RTC interrupt number |
| 114 | +#define RTC_INTERVAL 20UL // default RTC interval (20us == 50kHz) |
| 115 | +#define RTC_QUANTUM 32UL // default RTC quantum (32 ticks) |
| 116 | + |
| 117 | +// WDT defaults ... |
| 118 | +#define WDT 026 // watchdog timer IO address |
| 119 | +#define WDT_VECTOR 000062 // WDT timeout vector |
| 120 | +#define WDT_DELAY 0 // default WDT timeout (in milliseconds) |
| 121 | + |
| 122 | +// Debugging flags ... |
| 123 | +// In general, these bits are used as arguments for sim_debug(). Bits that |
| 124 | +// begin with "IMP_DBG_xyz" are shared by more than one device (e.g. IMP_DBG_UDP) |
| 125 | +// and must have unique bit assignments. Bits prefixed with a device name (e.g. |
| 126 | +// "MI_DBG_xyz") apply to that device only. |
| 127 | +#define IMP_DBG_WARN 0x0001 // all: print warnings |
| 128 | +#define IMP_DBG_IOT 0x0002 // all: trace all program I/O instructions |
| 129 | +#define IMP_DBG_UDP 0x0004 // all: trace UDP packets |
| 130 | +#define MI_DBG_MSG 0x8000 // modem: decode and print all messages |
| 131 | +#define HI_DBG_MSG 0x8000 // host interface: decode and print all messages |
| 132 | +#define WDT_DBG_LIGHTS 0x8000 // wdt: show status light changes |
| 133 | + |
| 134 | +// Synonyms for DIB and UNIT fields ... |
| 135 | +#define rxdmc chan // dib->rxdmc |
| 136 | +#define txdmc chan2 // dib->txdmc |
| 137 | +#define rxint inum // dib->rxint |
| 138 | +#define txint inum2 // dib->txint |
| 139 | + |
| 140 | +// This constant determines the longest possible IMP data payload that can be |
| 141 | +// sent. Most IMP messages are trivially small - 68 words or so - but, when one |
| 142 | +// IMP asks for a reload the neighbor IMP sends the entire memory image in a |
| 143 | +// single message! That message is about 14K words long. |
| 144 | +// The next thing you should worry about is whether the underlying IP network |
| 145 | +// can actually send a UDP packet of this size. It turns out that there's no |
| 146 | +// simple answer to that - it'll be fragmented for sure, but as long as all |
| 147 | +// the fragments arrive intact then the destination should reassemble them. |
| 148 | +#define MAXDATA 16384 // longest possible IMP packet (in H316 words) |
| 149 | + |
| 150 | +// Modem interface data block .... |
| 151 | +// One of these is allocated to every modem interface to keep track of the |
| 152 | +// current state, COM port, UDP connection , etc... |
| 153 | +struct _MIDB { |
| 154 | + // Receiver data ... |
| 155 | + t_bool rxpending; // TRUE if a read is pending on this line |
| 156 | + t_bool rxerror; // TRUE if any modem error detected |
| 157 | + uint32 rxtotal; // total number of H316 words received |
| 158 | + // Transmitter data ... |
| 159 | + uint32 txtotal; // total number of H316 words transmitted |
| 160 | + uint32 txdelay; // RTC ticks until TX done interrupt |
| 161 | + // Other data ... |
| 162 | + t_bool lloop; // line loop back enabled |
| 163 | + t_bool iloop; // interface loop back enabled |
| 164 | + int32 link; // h316_udp link number |
| 165 | + uint32 bps; // simulated line speed or COM port baud rate |
| 166 | +}; |
| 167 | +typedef struct _MIDB MIDB; |
| 168 | + |
| 169 | +// Host interface data block ... |
| 170 | +// One of these is allocated to every host interface ... |
| 171 | +struct _HIDB { |
| 172 | + // Receiver (HOST -> IMP) data ... |
| 173 | + t_bool rxpending; // TRUE if a read is pending on this line |
| 174 | + t_bool rxerror; // TRUE if any modem error detected |
| 175 | + uint32 rxtotal; // total host messages received |
| 176 | + uint16 rxdata[MAXDATA]; // UDP packet received. |
| 177 | + uint16 rxnext; // Index to next word in UDP packet. |
| 178 | + uint16 rxsize; // Size of UDP packet. |
| 179 | + // Transmitter (IMP -> HOST) data ... |
| 180 | + uint32 txdelay; // RTC ticks until TX done interrupt |
| 181 | + uint32 txtotal; // total host messages sent |
| 182 | + // Other data ... |
| 183 | + t_bool iloop; // local loop back enabled |
| 184 | + t_bool enabled; // TRUE if the host is enabled |
| 185 | + t_bool error; // TRUE for any host error |
| 186 | + t_bool ready; // TRUE if the host is ready |
| 187 | + t_bool full; // TRUE if the host buffer is full |
| 188 | + t_bool eom; // TRUE when end of message is reached |
| 189 | + int32 link; // h316_udp link number |
| 190 | + uint32 bps; // simulated line speed or COM port baud rate |
| 191 | +}; |
| 192 | +typedef struct _HIDB HIDB; |
| 193 | + |
| 194 | +// I can't believe Bob managed to live without these, but I can't! |
| 195 | +#ifndef LOBYTE // these are in winsock.h too! |
| 196 | +#define LOBYTE(x) ((uint8) ( (x) & 0xFF)) |
| 197 | +#define HIBYTE(x) ((uint8) (((x) >> 8) & 0xFF)) |
| 198 | +#define MKWORD(h,l) ((uint16) ( (((h)&0xFF) << 8) | ((l)&0xFF) )) |
| 199 | +#define LOWORD(x) ((uint16) ( (x) & 0xFFFF)) |
| 200 | +#define HIWORD(x) ((uint16) (((x) >> 16) & 0xFFFF)) |
| 201 | +#define MKLONG(h,l) ((uint32) ( (((h)&0xFFFF) << 16) | ((l)&0xFFFF) )) |
| 202 | +#endif |
| 203 | + |
| 204 | +// Prototypes for the RTC module ... |
| 205 | +// I really hate sharing things like this, but it's the only way to get the |
| 206 | +// modem transmitter timing exactly right! |
| 207 | +extern uint32 rtc_interval; |
| 208 | +extern t_stat mi_tx_service (uint32 quantum); |
| 209 | +extern t_stat hi_tx_service (uint32 quantum); |
| 210 | + |
| 211 | +// Prototypes for UDP modem/host interface emulation routines ... |
| 212 | +#define NOLINK (-1) |
| 213 | +t_stat udp_create (DEVICE *pdtr, const char *premote, int32 *plink); |
| 214 | +t_stat udp_release (DEVICE *dptr, int32 link); |
| 215 | +t_stat udp_send (DEVICE *pdtr, int32 link, uint16 *pdata, uint16 count); |
| 216 | +t_stat udp_set_link_loopback (DEVICE *dptr, int32 link, t_bool enable_loopback); |
| 217 | +int32 udp_receive (DEVICE *dptr, int32 link, uint16 *pdata, uint16 maxbufg); |
| 218 | + |
| 219 | +#endif // #ifndef _H316_IMP_H_ |
| 220 | +#endif // #ifdef VM_IMPTIP |
0 commit comments