summaryrefslogtreecommitdiff
path: root/gdb/rdi-share/channels.h
blob: a755b2a9bd164af2883e9d38560c6ec5e0338da9 (plain)
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/* 
 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
 * 
 * This software may be freely used, copied, modified, and distributed
 * provided that the above copyright notice is preserved in all copies of the
 * software.
 */

/* -*-C-*-
 *
 * $Revision: 1.2 $
 *     $Date: 1998/01/08 11:11:40 $
 *
 *
 *   Project: ANGEL
 *
 *     Title: User interface to the channels layer
 */

#ifndef angel_channels_h
#define angel_channels_h

/*
 * This provides the public interface to the channels layer read and write
 * routines, and buffer management routines.
 */

/* Nested header files, if required */

#include "devices.h"
#include "chandefs.h"
#include "adperr.h"

/* General purpose constants, macros, enums, typedefs */

/* use the default device */
#define CH_DEFAULT_DEV ((DeviceID)-1)

/* return codes */
typedef enum ChanError {
  CE_OKAY,                      /* no error */
  CE_ABANDONED,                 /* abandoned due to device switch */
  CE_DEV_ERROR,                 /* unexpected error from device driver */
  CE_BUSY,                      /* channel in use */
  CE_BUFF_ERROR,                /* unable to get buffer */
  CE_PRIVATE                    /* start of internal error codes */
} ChanError;


/* Publically-accessible globals */

/*
 * The following two globals are only valid after angel_InitialiseChannels()
 * has been called.
 */

/* the default size of a channel buffer, for global use */
extern unsigned Angel_ChanBuffSize;

/* the size of a long buffer, for global use */
extern unsigned Angel_ChanLongSize;

#ifdef TARGET
AdpErrs send_resend_msg(DeviceID devid);
#endif

/*
 * Function: angel_InitialiseChannels
 *  Purpose: initialise the channels layer
 *
 *   Params:
 *              Input: -
 *             Output: -
 *             In/Out: -
 *
 *            Returns: -
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 */

void angel_InitialiseChannels( void );

/*
 * Function: adp_init_seq
 *  Purpose: initialise sequence numbers and free anyt leftover buffers
 *
 *   Params:
 *              Input: -
 *             Output: -
 *             In/Out: -
 *
 *            Returns: - adp_ok if things went ok else an error code
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 */

AdpErrs adp_init_seq(void);

/*
 * Function: angel_ChannelAllocBuffer
 *  Purpose: allocate a buffer that is at least req_size bytes long
 *
 *   Params:
 *              Input: req_size        the minimum size required
 *             Output: -
 *             In/Out: -
 *
 *            Returns: pointer to allocated buffer, or
 *                     NULL if unable to allocate suitable buffer
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 */

p_Buffer angel_ChannelAllocBuffer(unsigned req_size);


/*
 * Function: angel_ChannelReleaseBuffer
 *  Purpose: release a buffer back to the free pool
 *
 *   Params:
 *              Input: buffer   the buffer to release
 *             Output: -
 *             In/Out: -
 *
 *            Returns: -
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 */

void angel_ChannelReleaseBuffer(p_Buffer buffer);


/*
 * Function: angel_ChannelSend
 *  Purpose: blocking send of a packet via a channel
 *
 *   Params:
 *              Input: devid         Device to use, or CH_DEFAULT_DEV
 *                     chanid        Channel to use for tx 
 *                     buffer        Pointer to data to send
 *                     len           Length of data to send
 *             Output: -
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Transmission completed
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_ABANDONED  Tx abandoned due to device switch
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 */

ChanError angel_ChannelSend(DeviceID devid, ChannelID chanid,
                            const p_Buffer buffer, unsigned len);


/*
 * Function: angel_ChannelSendAsync
 *  Purpose: asynchronous send of a packet via a channel
 *
 *   Params:
 *              Input: devid         Device to use, or CH_DEFAULT_DEV
 *                     chanid        Channel to use for tx 
 *                     buffer        Pointer to data to send
 *                     len           Length of data to send
 *                     callback      Function to call on completion
 *                     callback_data Pointer to pass to callback
 *             Output: -
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Transmission underway
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_ABANDONED  Tx abandoned due to device switch
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 *
 * register an asynchronous send on the given channel
 * (blocks until send can be commenced)
 */

typedef void (*ChanTx_CB_Fn)(ChannelID  chanid,         /* which channel  */
                             void      *callback_data); /* as supplied... */
                             

ChanError angel_ChannelSendAsync(          DeviceID      devid,
                                           ChannelID     chanid,
                                     const p_Buffer      buffer,
                                           unsigned      len, 
                                           ChanTx_CB_Fn  callback, 
                                           void         *callback_data);


/*
 * Function: angel_ChannelRead
 *  Purpose: blocking read of a packet from a channel
 *
 *   Params:
 *              Input: devid         Device to use, or CH_DEFAULT_DEV
 *                     chanid        Channel to use for rx
 *             Output: buffer        The buffer, supplied and filled
 *                     len           How many bytes there are in the buffer
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Reception successful
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_ABANDONED  Tx abandoned due to device switch
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 *
 * Note that in the present version, if an asynchronous read has been
 * registered, a blocking read will be refused with CE_BUSY.
 */
ChanError angel_ChannelRead(DeviceID      devid,
                            ChannelID     chanid,
                            p_Buffer     *buffer, 
                            unsigned     *len);


/*
 * Function: angel_ChannelReadAsync
 *  Purpose: asynchronous read of a packet via a channel
 *
 *   Params:
 *              Input: devid         Device to use, or CH_DEFAULT_DEV
 *                     chanid        Channel to wait on
 *                     callback      Function to call on completion, or NULL
 *                     callback_data Pointer to pass to callback
 *             Output: -
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Read request registered
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_BUSY       Someone else is using the channel
 *                                   (in a single threaded world)
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 *
 * Register an asynchronous read on the given channel.  There can only be one
 * async. reader per channel, and blocking reads are not permitted whilst
 * an async. reader is registered.
 *
 * Reader can unregister by specifying NULL as the callback function.
 */

typedef void (*ChanRx_CB_Fn)(DeviceID   devID,   /* ID of receiving device  */
                             ChannelID  chanID,  /* ID of receiving channel */
                             p_Buffer   buff,    /* pointer to buffer       */
                             unsigned   len,     /* length of data          */
                             void      *cb_data  /* callback data           */
                             );

ChanError angel_ChannelReadAsync(DeviceID      devid,
                                 ChannelID     chanid,
                                 ChanRx_CB_Fn  callback, 
                                 void         *callback_data);


/*
 * Function: angel_ChannelReadAll
 *  Purpose: register an asynchronous read across all devices
 *
 *   Params:
 *              Input: chanid        Channel to look for (usually HBOOT)
 *                     callback      Function to call on completion
 *                     callback_data Pointer to pass to callback
 *             Output: -
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Read request registered
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_BUSY       Someone else is reading all devices
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 *
 * Register an asynchronous read across all devices.  This is a 'fallback',
 * which will be superseded (temporarily) by a registered reader or blocking 
 * read on a specific device.
 */

ChanError angel_ChannelReadAll(         ChannelID     chanid,
                                        ChanRx_CB_Fn  callback,
                                        void         *callback_data);



/*
 * Function: angel_ChannelSendThenRead
 *  Purpose: blocking write to followed by read from a channel
 *
 *   Params:
 *              Input: devid         Device to use, or CH_DEFAULT_DEV
 *                     chanid        Channel to use for rx
 *             In/Out: buffer        On entry:  the packet to be sent
 *                                   On return: the packet received
 *                     len           On entry:  length of packet to be sent
 *                                   On return: length of packet rx'd
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Tx and Reception successful
 *                     CE_BAD_CHAN   Channel id invalid
 *                     CE_ABANDONED  Tx abandoned due to device switch
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: -
 *
 * Note that in the present version, if an asynchronous read has been
 * registered, this will be refused with CE_BUSY.
 */
ChanError angel_ChannelSendThenRead(DeviceID      devid,
                                    ChannelID     chanid,
                                    p_Buffer     *buffer, 
                                    unsigned     *len);


/*
 * Function: angel_ChannelSelectDevice
 *  Purpose: select the device to be used for all channel comms
 *
 *   Params:
 *              Input: device        ID of device to use as the default
 *             Output: -
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Default device selected
 *                     CE_BAD_DEV    Invalid device ID
 *
 *      Reads globals: -
 *   Modifies globals: -
 *
 * Other side effects: Any channel operations in progress are
 *                     abandoned.
 *
 * select the device for all channels comms
 */

ChanError angel_ChannelSelectDevice(DeviceID device);


/*
 * Function: angel_ChannelReadActiveDevice
 *  Purpose: reads the device id of the currently active device
 *
 *   Params:
 *              Input: device        address of a DeviceID variable
 *             Output: *device       ID of device currently being used
 *             In/Out: -
 *
 *            Returns: CE_OKAY       Default device selected
 */

ChanError angel_ChannelReadActiveDevice(DeviceID *device);

#endif /* ndef angel_channels_h */

/* EOF channels.h */