summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/madge/driver/ftk_poke.c
blob: a9074dd76c14d3ba60393d9277d08a9d8efb7bfe (plain) (blame)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/****************************************************************************
*
* FTK_POKE.C
*
* Part of the FastMAC Toolkit.
* Copyright (c) Madge Networks Ltd 1995
*
* This module provides some functions that will send tracing information
* to either serial port (COM1 or COM2) on a standard IBM PC clone.
*
*****************************************************************************/

#include "ftk_defs.h"
#include "ftk_intr.h"
#include "ftk_extr.h"

#ifdef FTK_POKEOUTS

/*---------------------------------------------------------------------------
|
| Private constants.
|
---------------------------------------------------------------------------*/

#ifdef USE_COM2
#define COM_BASE    0x0200  /* Base address for COM2. */
#else
#define COM_BASE    0x0300  /* Base address for COM1. */
#endif

#define THR         (COM_BASE + 0x0f8) /* Transmit holding register. */
#define IER         (COM_BASE + 0x0f9) /* IRQ enable register. */
#define IDR         (COM_BASE + 0x0fa) /* IRQ identification register. */
#define LCR         (COM_BASE + 0x0fb) /* Line control register. */
#define MCR         (COM_BASE + 0x0fc) /* Modem control register. */
#define LSR         (COM_BASE + 0x0fd) /* Line status register. */
#define MSR         (COM_BASE + 0x0fe) /* Modem status register. */

#define TX_RDY      0x020     /* THR empty flag bit in LSR. */
#define BAUD_MASK   0x080     /* Baud rate mask in LCR. */
#define PARAMS_MASK 0x07f     /* Parameter mask in LCR. */
#define EOUT2       0x008     /* EOUT2 flag in MCR. */
#define CMCR        0x0f0     /* Clear MCR command. */ 
#define DTR         0x001     /* DTR flag in MCR. */

#define PARITY_TYPE 0
#define STOP_BITS   1
#define DATA_BITS   8
#define BAUD_RATE   9600


/*----------------------------------------------------------------------------
|
| Private global variables.
|
----------------------------------------------------------------------------*/

int  ftk_poke_initialised = FALSE;
char ftk_hex_chars[16]    = "0123456789abcdef";


/*----------------------------------------------------------------------------
|
| Function   - ftk_poke_init
|
| Parameters - Node.
|
| Purpose    - Initialise the serial port.
|
| Returns    - Nothing.
|
----------------------------------------------------------------------------*/

void
ftk_poke_init(void)
{
    unsigned t;
    unsigned v;

    /* 
     * Data, stop and parity bits.
     */

    t = DATA_BITS - 5;
    if (STOP_BITS == 2)
    {
        t |= 0x04;
    }
    if (PARITY_TYPE > 0)
    {
        t |= ((PARITY_TYPE << 1) - 1) << 3;
    }

    OUTB(LCR, (BYTE) (INB(LCR) & PARAMS_MASK));
    OUTB(LCR, (BYTE) t);

    /*
     * Set up the baud rate.
     */

    t = 115200L / BAUD_RATE;
    v = INB(LCR) | BAUD_MASK;
    OUTB(LCR, (BYTE) v);
    OUTB(THR, (BYTE) (t & 0xff));
    OUTB(IER, (BYTE) ((t >> 8) & 0xff));
    OUTB(LCR, (BYTE) (v & PARAMS_MASK));

    /*
     * Empty the transmit buffer.
     */

    INB(THR);

    /*
     * Clear the modem control register and enable OUT2.
     */

    OUTB(MCR, (BYTE) ((INB(MCR) & CMCR) | EOUT2));

    /*
     * Turn DTR on.
     */

    OUTB(MCR, (BYTE) (INB(MCR) | DTR));
}


/*****************************************************************************
* 
* Function   - _ftk_poke_char
*
* Parameters - ch -> Character to poke out.
*
* Purpose    - Poke a single character to the serial port.
*
* Returns    - Nothing.
*
*****************************************************************************/

void
_ftk_poke_char(int ch)
{
    /*
     * Initialise the serial port if this is the first access.
     */

    if (!ftk_poke_initialised)
    {
        ftk_poke_init();
        ftk_poke_initialised = TRUE;
    }

    /*
     * Wait until the transmit holding register is empty.
     */

    while ((INB(LSR) & TX_RDY) == 0);

    /*
     * And transmit the character.
     */

    OUTB(THR, (unsigned char) ch);
}


/*****************************************************************************
* 
* Function   - _ftk_poke_string
*
* Parameters - str -> String to poke out.
*
* Purpose    - Poke a string to the serial port.
*
* Returns    - Nothing.
*
*****************************************************************************/

void
_ftk_poke_string(char *str)
{
    while (*str != '\0')
    {
        if (*str == '\n')
        {
            _ftk_poke_char('\n');
            _ftk_poke_char('\r');
        }
        else
        {
            _ftk_poke_char(*str);
        }
        str++;
    }
}


/*****************************************************************************
* 
* Function   - _ftk_poke_byte
*
* Parameters - byte -> The byte to poke out.
*
* Purpose    - Poke the hex string for a byte to the serial port.
*
* Returns    - Nothing.
*
*****************************************************************************/

void
_ftk_poke_byte(int byte)
{
    _ftk_poke_char(ftk_hex_chars[(byte >> 4) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(byte     ) & 0x000f]);
}


/*****************************************************************************
* 
* Function   - _ftk_poke_word
*
* Parameters - word -> The word to poke out.
*
* Purpose    - Poke the hex string for a word to the serial port.
*
* Returns    - Nothing.
*
*****************************************************************************/

void
_ftk_poke_word(int word)
{
    _ftk_poke_char(ftk_hex_chars[(word >> 12) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(word >>  8) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(word >>  4) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(word      ) & 0x000f]);
}


/*****************************************************************************
* 
* Function   - _ftk_poke_dword
*
* Parameters - dword -> The dword to poke out.
*
* Purpose    - Poke the hex string for a dword to the serial port.
*
* Returns    - Nothing.
*
*****************************************************************************/

void
_ftk_poke_dword(long dword)
{
    _ftk_poke_char(ftk_hex_chars[(dword >> 28) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >> 24) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >> 20) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >> 16) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >> 12) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >>  8) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword >>  4) & 0x000f]);
    _ftk_poke_char(ftk_hex_chars[(dword      ) & 0x000f]);
}

#endif