Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:43

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  SPWCUC - SpaceWire - CCSDS unsegmented Code Transfer Protocol GRLIB core
0004  *  register driver interface.
0005  *
0006  *  COPYRIGHT (c) 2009.
0007  *  Cobham Gaisler AB.
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifndef __SPWCUC_H__
0032 #define __SPWCUC_H__
0033 
0034 #define PKT_INIT_IRQ       0x1
0035 #define PKT_ERR_IRQ        0x2
0036 #define PKT_RX_IRQ         0x4
0037 #define WRAP_ERR_IRQ       0x8
0038 #define WRAP_IRQ           0x10
0039 #define SYNC_ERR_IRQ       0x20
0040 #define SYNC_IRQ           0x40
0041 #define TOL_ERR_IRQ        0x80
0042 #define TICK_RX_ERR_IRQ    0x100
0043 #define TICK_RX_WRAP_IRQ   0x200
0044 #define TICK_RX_IRQ        0x400
0045 #define TICK_TX_WRAP_IRQ   0x800
0046 #define TICK_TX_IRQ        0x1000
0047 
0048 /* SPWCUC Register layout */
0049 struct spwcuc_regs {
0050     volatile unsigned int config;        /* 00 */
0051     volatile unsigned int status;        /* 04 */
0052     volatile unsigned int control;       /* 08 */
0053     volatile unsigned int unused0;       /* 0c */
0054     volatile unsigned int dla;           /* 10 */
0055     volatile unsigned int pid;           /* 14 */
0056     volatile unsigned int offset;        /* 18 */
0057     volatile unsigned int unused1;       /* 1c */
0058     volatile unsigned int pkt_ct;        /* 20 */
0059     volatile unsigned int pkt_ft;        /* 24 */   
0060     volatile unsigned int pkt_pf_crc;    /* 28 */
0061     volatile unsigned int unused2;       /* 2c */
0062     volatile unsigned int etct;          /* 30 */
0063     volatile unsigned int etft;          /* 34 */
0064     volatile unsigned int etct_next;     /* 38 */
0065     volatile unsigned int etft_next;     /* 3c */
0066     volatile unsigned int unused3[8];    /* 40-5c */
0067     volatile unsigned int pimsr;         /* 60 */
0068     volatile unsigned int pimr;          /* 64 */
0069     volatile unsigned int pisr;          /* 68 */
0070     volatile unsigned int pir;           /* 6c */
0071     volatile unsigned int imr;           /* 70 */
0072     volatile unsigned int picr;          /* 74 */
0073 };
0074 
0075 struct spwcuc_cfg {
0076     unsigned char sel_out;         /* Bits 3-0 enable time code transmission on respective output */
0077     unsigned char sel_in;          /* Select SpW to receive time codes on, 0-3 */
0078     unsigned char mapping;         /* Define mapping of time code time info into T-field, 0-31 */
0079     unsigned char tolerance;       /* Define SpaceWire time code reception tolerance, 0-31 */
0080     unsigned char tid;             /* Define CUC P-Field time code identification, 1 = Level 1, 2 = Level 2 */
0081     unsigned char ctf;             /* If 1 check time code flags to be all zero */
0082     unsigned char cp;              /* If 1 check P-Field time code id against tid */
0083 
0084     unsigned char txen;            /* Enable SpaceWire time code transmission */
0085     unsigned char rxen;            /* Enable SpaceWire time code reception */
0086     unsigned char pktsyncen;       /* Enable SpaceWire time CUC packet sync */
0087     unsigned char pktiniten;       /* Enable SpaceWire time CUC packet init */
0088     unsigned char pktrxen;         /* Enable SpaceWire time CUC packet reception */
0089 
0090     unsigned char dla;             /* SpaceWire destination logical address */ 
0091     unsigned char dla_mask;        /* SpaceWire destination logical address mask */ 
0092     unsigned char pid;             /* SpaceWire protocol ID */
0093     
0094     unsigned int offset;           /* Packet reception offset */
0095 };
0096 
0097 /* SPWCUC Statistics gathered by driver */
0098 struct spwcuc_stats {
0099 
0100     /* IRQ Stats */
0101     unsigned int nirqs;
0102     unsigned int tick_tx;
0103     unsigned int tick_tx_wrap;
0104     unsigned int tick_rx;
0105     unsigned int tick_rx_wrap;
0106     unsigned int tick_rx_error;
0107     unsigned int tolerr;
0108     unsigned int sync;
0109     unsigned int syncerr;
0110     unsigned int wrap;
0111     unsigned int wraperr;
0112     unsigned int pkt_rx;
0113     unsigned int pkt_err;
0114     unsigned int pkt_init;
0115 };
0116 
0117 /* Function ISR callback prototype
0118  *
0119  * pimr    - PIMR/PIR register of the SPWCUC core read by ISR
0120  * data    - Custom data provided by user
0121  */
0122 typedef void (*spwcuc_isr_t)(unsigned int pimr, void *data);
0123 
0124 /* Open a SPWCUC device by minor number. A SPWCUC device can only by opened
0125  * once. The handle returned must be used as the input parameter 'spwcuc' in 
0126  * the rest of the calls in the function interface.
0127  */
0128 extern void *spwcuc_open(int minor);
0129 
0130 /* Close a previously opened SPWCUC device */
0131 extern void spwcuc_close(void *spwcuc);
0132 
0133 /* Reset SPWCUC Core */
0134 extern int spwcuc_reset(void *spwcuc);
0135 
0136 /* Enable Interrupts at Interrupt controller */
0137 extern void spwcuc_int_enable(void *spwcuc);
0138 
0139 /* Disable Interrupts at Interrupt controller */
0140 extern void spwcuc_int_disable(void *spwcuc);
0141 
0142 /* Clear Statistics gathered by the driver */
0143 extern void spwcuc_clr_stats(void *spwcuc);
0144 
0145 /* Get Statistics gathered by the driver. The statistics are stored into
0146  * the location pointed to by 'stats'.
0147  */
0148 extern void spwcuc_get_stats(void *spwcuc, struct spwcuc_stats *stats);
0149 
0150 /* Register an Interrupt handler and custom data, the function call is
0151  * removed by setting func to NULL.
0152  *
0153  * The driver's interrupt handler is installed on open(), however the user
0154  * callback called from the driver's ISR is installed using this function.
0155  */
0156 extern void spwcuc_int_register(void *spwcuc, spwcuc_isr_t func, void *data);
0157 
0158 /* Configure the spwcuc core. The configuration is taken from the data
0159  * structure pointed to by 'cfg'. See data structure spwcuc_cfg fields.
0160  */
0161 extern void spwcuc_config(void *spwcuc, struct spwcuc_cfg *cfg);
0162 
0163 /* Return elapsed coarse time */
0164 extern unsigned int spwcuc_get_et_coarse(void *spwcuc);
0165 
0166 /* Return elapsed fine time */
0167 extern unsigned int spwcuc_get_et_fine(void *spwcuc);
0168 
0169 /* Return elapsed time (coarse and fine) 64-bit value */
0170 extern unsigned long long spwcuc_get_et(void *spwcuc);
0171 
0172 /* Return next elapsed coarse time (for use when sending SpW time packet) */
0173 extern unsigned int spwcuc_get_next_et_coarse(void *spwcuc);
0174 
0175 /* Return next elapsed fine time (for use when sending SpW time packet) */
0176 extern unsigned int spwcuc_get_next_et_fine(void *spwcuc);
0177 
0178 /* Return next elapsed time (for use when sending SpW time packet) */
0179 extern unsigned long long spwcuc_get_next_et(void *spwcuc);
0180 
0181 /* Force/Set the elapsed time (coarse 32-bit and fine 24-bit) by writing the
0182  * T-Field Time Packet Registers then the FORCE bit.
0183  */
0184 extern void spwcuc_force_et(void *spwcuc, unsigned long long time);
0185 
0186 /* Return received (from time packet) elapsed coarse time */
0187 extern unsigned int spwcuc_get_tp_et_coarse(void *spwcuc);
0188 
0189 /* Return received (from time packet) elapsed fine time */
0190 extern unsigned int spwcuc_get_tp_et_fine(void *spwcuc);
0191 
0192 /* Return received (from time packet) elapsed time (coarse and fine) */
0193 extern unsigned long long spwcuc_get_tp_et(void *spwcuc);
0194 
0195 /* Clear interrupts */
0196 extern void spwcuc_clear_irqs(void *spwcuc, int irqs);
0197 
0198 /* Enable interrupts */
0199 extern void spwcuc_enable_irqs(void *spwcuc, int irqs);
0200 
0201 /* Get Register */
0202 extern struct spwcuc_regs *spwcuc_get_regs(void *spwcuc);
0203 
0204 /* Register the SPWCUC Driver to the Driver Manager */
0205 extern void spwcuc_register(void);
0206 
0207 #endif