RTEMS 6.1-rc1
spwcuc.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* SPWCUC - SpaceWire - CCSDS unsegmented Code Transfer Protocol GRLIB core
4 * register driver interface.
5 *
6 * COPYRIGHT (c) 2009.
7 * Cobham Gaisler AB.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __SPWCUC_H__
32#define __SPWCUC_H__
33
34#define PKT_INIT_IRQ 0x1
35#define PKT_ERR_IRQ 0x2
36#define PKT_RX_IRQ 0x4
37#define WRAP_ERR_IRQ 0x8
38#define WRAP_IRQ 0x10
39#define SYNC_ERR_IRQ 0x20
40#define SYNC_IRQ 0x40
41#define TOL_ERR_IRQ 0x80
42#define TICK_RX_ERR_IRQ 0x100
43#define TICK_RX_WRAP_IRQ 0x200
44#define TICK_RX_IRQ 0x400
45#define TICK_TX_WRAP_IRQ 0x800
46#define TICK_TX_IRQ 0x1000
47
48/* SPWCUC Register layout */
50 volatile unsigned int config; /* 00 */
51 volatile unsigned int status; /* 04 */
52 volatile unsigned int control; /* 08 */
53 volatile unsigned int unused0; /* 0c */
54 volatile unsigned int dla; /* 10 */
55 volatile unsigned int pid; /* 14 */
56 volatile unsigned int offset; /* 18 */
57 volatile unsigned int unused1; /* 1c */
58 volatile unsigned int pkt_ct; /* 20 */
59 volatile unsigned int pkt_ft; /* 24 */
60 volatile unsigned int pkt_pf_crc; /* 28 */
61 volatile unsigned int unused2; /* 2c */
62 volatile unsigned int etct; /* 30 */
63 volatile unsigned int etft; /* 34 */
64 volatile unsigned int etct_next; /* 38 */
65 volatile unsigned int etft_next; /* 3c */
66 volatile unsigned int unused3[8]; /* 40-5c */
67 volatile unsigned int pimsr; /* 60 */
68 volatile unsigned int pimr; /* 64 */
69 volatile unsigned int pisr; /* 68 */
70 volatile unsigned int pir; /* 6c */
71 volatile unsigned int imr; /* 70 */
72 volatile unsigned int picr; /* 74 */
73};
74
75struct spwcuc_cfg {
76 unsigned char sel_out; /* Bits 3-0 enable time code transmission on respective output */
77 unsigned char sel_in; /* Select SpW to receive time codes on, 0-3 */
78 unsigned char mapping; /* Define mapping of time code time info into T-field, 0-31 */
79 unsigned char tolerance; /* Define SpaceWire time code reception tolerance, 0-31 */
80 unsigned char tid; /* Define CUC P-Field time code identification, 1 = Level 1, 2 = Level 2 */
81 unsigned char ctf; /* If 1 check time code flags to be all zero */
82 unsigned char cp; /* If 1 check P-Field time code id against tid */
83
84 unsigned char txen; /* Enable SpaceWire time code transmission */
85 unsigned char rxen; /* Enable SpaceWire time code reception */
86 unsigned char pktsyncen; /* Enable SpaceWire time CUC packet sync */
87 unsigned char pktiniten; /* Enable SpaceWire time CUC packet init */
88 unsigned char pktrxen; /* Enable SpaceWire time CUC packet reception */
89
90 unsigned char dla; /* SpaceWire destination logical address */
91 unsigned char dla_mask; /* SpaceWire destination logical address mask */
92 unsigned char pid; /* SpaceWire protocol ID */
93
94 unsigned int offset; /* Packet reception offset */
95};
96
97/* SPWCUC Statistics gathered by driver */
99
100 /* IRQ Stats */
101 unsigned int nirqs;
102 unsigned int tick_tx;
103 unsigned int tick_tx_wrap;
104 unsigned int tick_rx;
105 unsigned int tick_rx_wrap;
106 unsigned int tick_rx_error;
107 unsigned int tolerr;
108 unsigned int sync;
109 unsigned int syncerr;
110 unsigned int wrap;
111 unsigned int wraperr;
112 unsigned int pkt_rx;
113 unsigned int pkt_err;
114 unsigned int pkt_init;
115};
116
117/* Function ISR callback prototype
118 *
119 * pimr - PIMR/PIR register of the SPWCUC core read by ISR
120 * data - Custom data provided by user
121 */
122typedef void (*spwcuc_isr_t)(unsigned int pimr, void *data);
123
124/* Open a SPWCUC device by minor number. A SPWCUC device can only by opened
125 * once. The handle returned must be used as the input parameter 'spwcuc' in
126 * the rest of the calls in the function interface.
127 */
128extern void *spwcuc_open(int minor);
129
130/* Close a previously opened SPWCUC device */
131extern void spwcuc_close(void *spwcuc);
132
133/* Reset SPWCUC Core */
134extern int spwcuc_reset(void *spwcuc);
135
136/* Enable Interrupts at Interrupt controller */
137extern void spwcuc_int_enable(void *spwcuc);
138
139/* Disable Interrupts at Interrupt controller */
140extern void spwcuc_int_disable(void *spwcuc);
141
142/* Clear Statistics gathered by the driver */
143extern void spwcuc_clr_stats(void *spwcuc);
144
145/* Get Statistics gathered by the driver. The statistics are stored into
146 * the location pointed to by 'stats'.
147 */
148extern void spwcuc_get_stats(void *spwcuc, struct spwcuc_stats *stats);
149
150/* Register an Interrupt handler and custom data, the function call is
151 * removed by setting func to NULL.
152 *
153 * The driver's interrupt handler is installed on open(), however the user
154 * callback called from the driver's ISR is installed using this function.
155 */
156extern void spwcuc_int_register(void *spwcuc, spwcuc_isr_t func, void *data);
157
158/* Configure the spwcuc core. The configuration is taken from the data
159 * structure pointed to by 'cfg'. See data structure spwcuc_cfg fields.
160 */
161extern void spwcuc_config(void *spwcuc, struct spwcuc_cfg *cfg);
162
163/* Return elapsed coarse time */
164extern unsigned int spwcuc_get_et_coarse(void *spwcuc);
165
166/* Return elapsed fine time */
167extern unsigned int spwcuc_get_et_fine(void *spwcuc);
168
169/* Return elapsed time (coarse and fine) 64-bit value */
170extern unsigned long long spwcuc_get_et(void *spwcuc);
171
172/* Return next elapsed coarse time (for use when sending SpW time packet) */
173extern unsigned int spwcuc_get_next_et_coarse(void *spwcuc);
174
175/* Return next elapsed fine time (for use when sending SpW time packet) */
176extern unsigned int spwcuc_get_next_et_fine(void *spwcuc);
177
178/* Return next elapsed time (for use when sending SpW time packet) */
179extern unsigned long long spwcuc_get_next_et(void *spwcuc);
180
181/* Force/Set the elapsed time (coarse 32-bit and fine 24-bit) by writing the
182 * T-Field Time Packet Registers then the FORCE bit.
183 */
184extern void spwcuc_force_et(void *spwcuc, unsigned long long time);
185
186/* Return received (from time packet) elapsed coarse time */
187extern unsigned int spwcuc_get_tp_et_coarse(void *spwcuc);
188
189/* Return received (from time packet) elapsed fine time */
190extern unsigned int spwcuc_get_tp_et_fine(void *spwcuc);
191
192/* Return received (from time packet) elapsed time (coarse and fine) */
193extern unsigned long long spwcuc_get_tp_et(void *spwcuc);
194
195/* Clear interrupts */
196extern void spwcuc_clear_irqs(void *spwcuc, int irqs);
197
198/* Enable interrupts */
199extern void spwcuc_enable_irqs(void *spwcuc, int irqs);
200
201/* Get Register */
202extern struct spwcuc_regs *spwcuc_get_regs(void *spwcuc);
203
204/* Register the SPWCUC Driver to the Driver Manager */
205extern void spwcuc_register(void);
206
207#endif
Definition: deflate.c:114
Definition: intercom.c:87
Definition: spwcuc.h:75
Definition: spwcuc.h:49
Definition: spwcuc.h:98