RTEMS
6.1-rc1
bsps
include
grlib
gr1553rt.h
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
3
/* GR1553B RT driver
4
*
5
* COPYRIGHT (c) 2010.
6
* Cobham Gaisler AB.
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
10
* are met:
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* 2. Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
* POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
#ifndef __GR1553RT_H__
31
#define __GR1553RT_H__
32
33
/* CONFIG OPTION: Maximum number of LIST IDs supported.
34
* There are two lists per RT subaddress, one for RX one
35
* for TX.
36
*/
37
#define RTLISTID_MAX 64
38
39
/* CONFIG OPTION: Maximum number of Interrupt handlers per device supported
40
* max is 256 supported, and minimum is 1.
41
*/
42
#define RTISR_MAX 64
43
44
/* CONFIG OPTION: Maximum number of transfer (RX/TX) descriptors supported.
45
*
46
* Set this option to zero to allow flexible number of descriptors,
47
* requires dynamically allocation of driver structures.
48
*/
49
/*#define RTBD_MAX 4096*/
50
#define RTBD_MAX 0
51
52
#ifdef __cplusplus
53
extern
"C"
{
54
#endif
55
56
/* Register GR1553B driver needed by RT driver */
57
extern
void
gr1553rt_register(
void
);
58
59
struct
gr1553rt_list
;
60
61
/* Descriptor read/written by hardware.
62
*
63
* Must be aligned to 16 byte boundary
64
*/
65
struct
gr1553rt_bd
{
66
volatile
unsigned
int
ctrl;
/* 0x00 Control/Status word */
67
volatile
unsigned
int
dptr;
/* 0x04 Data Pointer */
68
volatile
unsigned
int
next;
/* 0x08 Next Descriptor in list */
69
volatile
unsigned
int
unused;
/* 0x0C UNUSED BY HARDWARE */
70
};
71
72
/* Sub address table entry, the hardware access */
73
struct
gr1553rt_sa
{
74
volatile
unsigned
int
ctrl;
/* 0x00 SUBADDRESS CONTROL WORD */
75
volatile
unsigned
int
txptr;
/* 0x04 TRANSMIT BD POINTER */
76
volatile
unsigned
int
rxptr;
/* 0x08 RECEIVE BD POINTER */
77
volatile
unsigned
int
unused;
/* 0x0C UNUSED BY HARDWARE */
78
};
79
80
/* Configuration of a RT-SubAddress-List */
81
struct
gr1553rt_list_cfg
{
82
unsigned
int
bd_cnt;
/* Number of hw-descriptors in list */
83
};
84
85
/* A TX or RX subaddress descriptor list */
86
struct
gr1553rt_list
{
87
short
listid;
/* ID/NUMBER of List. -1 unassigned */
88
short
subadr;
/* SubAddress. -1 when not scheduled */
89
void
*rt;
/* Scheduled on Device */
90
struct
gr1553rt_list_cfg
*cfg;
/* List configuration */
91
int
bd_cnt;
/* Number of Descriptors */
92
93
/* !!Must be last in data structure!!
94
* !!Array must at least be of length bd_cnt!!
95
*/
96
unsigned
short
bds[0];
/* Array of BDIDs */
97
};
98
99
/* GR1553B-RT Driver configuration options used when calling gr1553rt_config().
100
*
101
* Note that if not custom addresses are given the driver will dynamically
102
* allocate memory for buffers.
103
* Note that if custom addresses with the LSB set, the address will be
104
* interpreted as a address accessible by hardware, and translated
105
* into an address used by CPU.
106
*/
107
struct
gr1553rt_cfg
{
108
unsigned
char
rtaddress;
/* RT Address 0..30 */
109
110
/*** MODE CODE CONFIG ***/
111
unsigned
int
modecode;
/* Mode codes enable/disable/IRQ/EV-Log.
112
* Each modecode has a 2-bit cfg field.
113
* See Mode Code Control Register in
114
* hardware manual.
115
*/
116
117
/*** TIME CONFIG ***/
118
unsigned
short
time_res;
/* Time tag resolution in us */
119
120
/*** SUBADDRESS TABLE CONFIG ***/
121
void
*satab_buffer;
/* Optional Custom buffer. Must be
122
* At least 16*32 bytes, and be aligned
123
* to 10-bit (1KB) boundary. Set to NULL
124
* to make driver allocate buffer.
125
*/
126
127
/*** EVENT LOG CONFIG ***/
128
void
*evlog_buffer;
/* Optional Custom buffer */
129
int
evlog_size;
/* Length, must be a multiple of 2.
130
* If set to ZERO event log is disabled
131
*/
132
133
/*** TRANSFER DESCRIPTOR CONFIG ***/
134
int
bd_count;
/* Number of transfer descriptors shared
135
* by all RX/TX sub-addresses */
136
void
*bd_buffer;
/* Optional Custom descriptor area.
137
* Must hold bd_count*32 bytes.
138
* If NULL, descriptors will be
139
* allocated dynamically. */
140
};
141
142
/* GR1553B-RT status indication, copied from the RT registers and stored
143
* here. Used when calling the gr1553rt_status() function.
144
*/
145
struct
gr1553rt_status
{
146
unsigned
int
status;
/* RT Status word */
147
unsigned
int
bus_status;
/* BUS Status */
148
unsigned
short
synctime;
/* Time Tag of last sync with data */
149
unsigned
short
syncword;
/* Data of last mode code synchronize
150
* with data. */
151
unsigned
short
time_res;
/* Time resolution (set by config) */
152
unsigned
short
time;
/* Current Time Tag */
153
};
154
155
/* ISR callback definition for ERRORs detected in the GR1553B-RT interrupt
156
* handler.
157
*
158
* \param err Inidicate Error type. The IRQ flag register bit mask:
159
* Bit 9 - RT DMA ERROR
160
* Bit 10 - RT Table access error
161
* \param data Custom data assigned by user
162
*/
163
typedef
void (*gr1553rt_irqerr_t)(
int
err,
void
*data);
164
165
/* ISR callback definition for modecodes that are configured to generate
166
* an IRQ. The callback is called from within the GR1553B-RT interrupt
167
* handler.
168
*
169
* \param mcode Mode code that caused this IRQ
170
* \param entry The raw Eventlog Entry
171
* \param data Custom data assigned by user
172
*/
173
typedef
void (*gr1553rt_irqmc_t)(
int
mcode,
unsigned
int
entry
,
void
*data);
174
175
/* Transfer ISR callback definition. Called from GR1553B-RT interrupt handler
176
* when an interrupt has been generated and a event logged due to a 1553
177
* transfer to this RT.
178
*
179
* \param list List (Subaddress/TransferType) that caused IRQ
180
* \param entry The raw Eventlog Entry
181
* \param bd_next Next Descriptor-entry index in the list (Subaddress/tr-type)
182
* This can be used to process all descriptors upto entry_next.
183
* \param data Custom data assigned by user
184
*/
185
typedef
void (*gr1553rt_irq_t)(
186
struct
gr1553rt_list
*list,
187
unsigned
int
entry
,
188
int
bd_next,
189
void
*data
190
);
191
192
/* Configure a list according to configuration. Assign the list
193
* to a device, however not to a RT sub address yet. The rt
194
* is stored within list.
195
*
196
* \param rt RT Device driver identification, stored within list.
197
* \param list The list to configure
198
* \param cfg Configuration for list. Pointer to configuration is
199
* stored within list for later use.
200
*/
201
extern
int
gr1553rt_list_init
202
(
203
void
*rt,
204
struct
gr1553rt_list
**plist,
205
struct
gr1553rt_list_cfg
*cfg
206
);
207
208
/* Assign an Error Interrupt handler. Before the handler is called the
209
* RT hardware is stopped/disabled. The handler is optional, if not assigned
210
* the ISR will still stop the RT upon error.
211
*
212
* Errors detected by the interrupt handler:
213
* - DMA error
214
* - Subaddress table access error
215
*
216
* \param func ISR called when an error causes an interrupt.
217
* \param data Custom data given as an argument when calling ISR
218
*/
219
extern
int
gr1553rt_irq_err
220
(
221
void
*rt,
222
gr1553rt_irqerr_t func,
223
void
*data
224
);
225
226
/* Assign a ModeCode Interrupt handler callback. Called when a 1553 modecode
227
* transfer is logged and cause an IRQ. The modecode IRQ generation is
228
* configured from "struct gr1553rt_cfg" when calling gr1553rt_config().
229
*
230
* \param func ISR called when a modecode causes an interrupt.
231
* \param data Custom data given as an argument when calling ISR
232
*/
233
extern
int
gr1553rt_irq_mc
234
(
235
void
*rt,
236
gr1553rt_irqmc_t func,
237
void
*data
238
);
239
240
/* Assign transfer interrupt handler callback. Called when a RX or TX
241
* transfer is logged and cause an interrupt, the function is called
242
* from the GR1553B-RT driver's ISR, in interrupt context.
243
*
244
* The callback can be installed per subaddress and transfer type.
245
* Subaddress 0 and 31 are not valid (gr1553rt_irq_mc() for modecodes).
246
*
247
* \param subadr Select subaddress (1-30)
248
* \param tx 1=TX subaddress, 0=RX subaddress
249
* \param func ISR called when subaddress of spcified transfer type
250
* causes an interrupt.
251
* \param data Custom data given as an argument when calling ISR
252
*/
253
extern
int
gr1553rt_irq_sa
254
(
255
void
*rt,
256
int
subadr,
257
int
tx,
258
gr1553rt_irq_t func,
259
void
*data
260
);
261
262
#define GR1553RT_BD_FLAGS_IRQEN (1<<30)
263
/* Initialize a descriptor entry in a list. This is typically done
264
* prior to scheduling the list.
265
*
266
* \param entry_no Entry number in list (descriptor index in list)
267
* \param flags Enable IRQ when descriptor is accessed by setting
268
* argument GR1553RT_BD_FLAGS_IRQEN. Enabling IRQ on a
269
* descriptor basis will override SA-table IRQ config.
270
* \param dptr Data Pointer to RX or TX operation. The LSB indicate
271
* if the address must be translated into Hardware address
272
* - this is useful when a buffer close to CPU is used
273
* as a data pointer and the RT core is located over PCI.
274
* \param next Next Entry in list. Set to 0xffff for end of list. Set
275
* 0xfffe for next entry in list, wrap around to entry
276
* zero if entry_no is last descriptor in list (circular).
277
*/
278
extern
int
gr1553rt_bd_init(
279
struct
gr1553rt_list
*list,
280
unsigned
short
entry_no,
281
unsigned
int
flags,
282
uint16_t *dptr,
283
unsigned
short
next
284
);
285
286
/* Manipulate/Read Control/Status and Data Pointer words of a buffer descriptor.
287
* If status is zero, the control/status word is accessed. If dptr is non-zero
288
* the data pointer word is accessed.
289
*
290
* \param list The list that the descriptor is located at
291
*
292
* \param entry_no The descriptor number accessed
293
*
294
* \param status IN/OUT. If zero no effect. If pointer is non-zero the
295
* value pointed to:
296
* IN: Written to Control/Status
297
* OUT: the value of the Control/Status word before writing.
298
*
299
* \param dptr IN/OUT. If zero no effect. If pointer is non-zero, the
300
* value pointed to:
301
* IN: non-zero: Descriptor data pointer will be updated with
302
* this value. Note that the LSB indicate if the address
303
* must be translated into hardware-aware address.
304
* OUT: The old data pointer is stored here.
305
*/
306
extern
int
gr1553rt_bd_update(
307
struct
gr1553rt_list
*list,
308
int
entry_no,
309
unsigned
int
*status,
310
uint16_t **dptr
311
);
312
313
/* Get the next/current descriptor processed of a RT sub-address.
314
*
315
* \param subadr RT Subaddress
316
* \param txeno Pointer to where TX descriptor number is stored.
317
* \param rxeno Pointer to where RX descriptor number is stored.
318
*/
319
extern
int
gr1553rt_indication(
void
*rt,
int
subadr,
int
*txeno,
int
*rxeno);
320
321
/* Take a GR1553RT hardware device identified by minor.
322
* A pointer is returned that is used internally by the GR1553RT
323
* driver, it is used as an input parameter 'rt' to all other
324
* functions that manipulate the hardware.
325
*
326
* This function initializes the RT hardware to a stopped/disable level.
327
*/
328
extern
void
*gr1553rt_open(
int
minor);
329
330
/* Close and stop/disable the RT hardware. */
331
extern
void
gr1553rt_close(
void
*rt);
332
333
/* Configure the RT. The RT device must be configured once before
334
* started. A started RT device can not be configured.
335
*
336
* \param rt The RT to configure
337
* \param cfg Configuration parameters
338
*/
339
extern
int
gr1553rt_config(
void
*rt,
struct
gr1553rt_cfg
*cfg);
340
341
/* Schedule a RX or TX list on a sub address. If a list has already been
342
* schduled on the subaddress and on the same transfer type (RX/TX), the
343
* old list is replaced with the list given here.
344
*
345
* \param subadr Subaddress to schedule list on
346
* \param tx Subaddress transfer type: 1=TX, 0=RX
347
* \param list Preconfigued RT list scheduled
348
*/
349
extern
void
gr1553rt_sa_schedule(
350
void
*rt,
351
int
subadr,
352
int
tx,
353
struct
gr1553rt_list
*list
354
);
355
356
/* Set SubAdress options. One may for example Enable or Disable a sub
357
* address RX and/or TX. See hardware manual for SA-Table configuration
358
* options.
359
*
360
* \param subadr SubAddress to configure
361
* \param mask Bit mask of option-bits written to subaddress config
362
* \param options The new options written to subaddress config.
363
*
364
*/
365
extern
void
gr1553rt_sa_setopts(
366
void
*rt,
367
int
subadr,
368
unsigned
int
mask,
369
unsigned
int
options
370
);
371
372
/* Get The Subaddress and transfer type of a scheduled list. Normally the
373
* application knows which subaddress the list is for.
374
*
375
* \param list List to lookup information for
376
* \param subadr Pointer to where the subaddress is stored
377
* \param tx Transfer type is stored here. 1=TX, 0=RX.
378
*/
379
extern
void
gr1553rt_list_sa(
380
struct
gr1553rt_list
*list,
381
int
*subadr,
382
int
*tx
383
);
384
385
/* Start RT Communication
386
*
387
* Interrupts will be enabled. The RT enabled and the "RT-run-time"
388
* part of the API will be opened for the user and parts that need the
389
* RT to be stopped are no longer available. After the RT has been
390
* started the configuration function can not be called.
391
*/
392
extern
int
gr1553rt_start(
void
*rt);
393
394
/* Get Status of the RT core. See data structure gr1553rt_status for more
395
* information about the result. It can be used to read out:
396
* - time information
397
* - sync information
398
* - bus & RT status
399
*
400
* \param status Pointer to where the status words will be stored. They
401
* are stored according to the gr1553rt_status data structure.
402
*/
403
extern
void
gr1553rt_status
(
void
*rt,
struct
gr1553rt_status
*status);
404
405
/* Stop RT communication. Only possible to stop an already started RT device.
406
* Interrupts are disabled and the RT Enable bit cleared.
407
*/
408
extern
void
gr1553rt_stop(
void
*rt);
409
410
/* Set RT vector and/or bit word.
411
*
412
* - Vector Word is used in response to "Transmit vector word" BC commands
413
* - Bit Word is used in response to "Transmit bit word" BC commands
414
*
415
*
416
* \param mask Bit-Mask, bits that are 1 will result in that bit in the
417
* words register being overwritten with the value of words
418
* \param words Bits 31..16: Bit Word. Bits 15..0: Vector Word.
419
*
420
* Operation:
421
* hw_words = (hw_words & ~mask) | (words & mask)
422
*/
423
extern
void
gr1553rt_set_vecword(
424
void
*rt,
425
unsigned
int
mask,
426
unsigned
int
words
427
);
428
429
/* Set selectable bits of the "Bus Status Register". The bits written
430
* is determined by the "mask" bit-mask. Operation:
431
*
432
* bus_status = (bus_status & ~mask) | (sts & mask)
433
*
434
*/
435
extern
void
gr1553rt_set_bussts(
void
*rt,
unsigned
int
mask,
unsigned
int
sts);
436
437
/* Read up to MAX number of entries in eventlog log.
438
*
439
* \param dst Destination address for event log entries
440
* \param max Maximal number of event log entries that an be stored into dst
441
*
442
* Return
443
* negative Failure
444
* zero No entries available at the moment
445
* positive Number of entries copied into dst
446
*/
447
extern
int
gr1553rt_evlog_read(
void
*rt,
unsigned
int
*dst,
int
max);
448
449
#ifdef __cplusplus
450
}
451
#endif
452
453
#endif
entry
Definition:
mmu-config.c:53
gr1553rt_bd
Definition:
gr1553rt.h:65
gr1553rt_cfg
Definition:
gr1553rt.h:107
gr1553rt_list_cfg
Definition:
gr1553rt.h:81
gr1553rt_list
Definition:
gr1553rt.h:86
gr1553rt_sa
Definition:
gr1553rt.h:73
gr1553rt_status
Definition:
gr1553rt.h:145
Generated by
1.9.4