Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Header file for RTEMS GRSLINK SLINK master driver 
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 __GRSLINK_H__
0032 #define __GRSLINK_H__
0033 
0034 #ifdef __cplusplus
0035 extern "C" {
0036 #endif
0037 
0038 /**** Configuration ****/
0039 /* Collect statistics ? */
0040 #define SLINK_COLLECT_STATISTICS
0041 
0042 /* Frequency of SLINK SCLK */
0043 #define SLINK_FREQ_HZ 6000000
0044 /* Number of queues used in driver */
0045 #define SLINK_NUMQUEUES 4
0046 
0047 /* The four values below are only used in the demo software */
0048 #define SLINK_CORE_REGBASE 0x80000600
0049 #define SLINK_CORE_IRQ 6
0050 #define IRQ_CNTRL_REG 0x80000200
0051 #define IRQ_CNTRL_MASK_OFFSET 0x40
0052 
0053 /* 
0054  * Structure returned by SLINK_statistics if SLINK_COLLECT_STATISTCS has
0055  * been defined
0056  */
0057 typedef struct {
0058     unsigned int parerr;     /* Number of parity errors */
0059     unsigned int recov;      /* Number of receive overflows */
0060     unsigned int reads;      /* Number of completed READs */
0061     unsigned int writes;     /* Number of performed WRITES */
0062     unsigned int sequences;  /* Number of started SEQUENCEs */
0063     unsigned int seqcomp;    /* Number of completed SEQUENCEs */
0064     unsigned int interrupts; /* Number of INTERRUPT transfers */
0065     unsigned int lostwords;  /* Number of lost words due to full queue */
0066 } SLINK_stats;
0067 
0068 /**** SLINK status codes ****/
0069 #define SLINK_ABORTED   0
0070 #define SLINK_QFULL     1
0071 #define SLINK_ACTIVE    2
0072 #define SLINK_AMBAERR   3
0073 #define SLINK_COMPLETED 4
0074 #define SLINK_PARERR    5
0075 #define SLINK_ROV       6 /* Only used internally in driver */
0076 
0077 /**** SLINK master register fields *****/
0078 /* Control register */
0079 #define SLINK_C_SLEN_POS 16
0080 #define SLINK_C_SRO  (1 << 8)
0081 #define SLINK_C_SCN_POS 4
0082 #define SLINK_C_PAR  (1 << 3)
0083 #define SLINK_C_AS   (1 << 2)
0084 #define SLINK_C_SE   (1 << 1)
0085 #define SLINK_C_SLE  (1 << 0)
0086 
0087 /* Status register fields */
0088 #define SLINK_S_SI_POS 16
0089 #define SLINK_S_PERR (1 << 7)
0090 #define SLINK_S_AERR (1 << 6)
0091 #define SLINK_S_ROV  (1 << 5)
0092 #define SLINK_S_RNE  (1 << 4)
0093 #define SLINK_S_TNF  (1 << 3)
0094 #define SLINK_S_SC   (1 << 2)
0095 #define SLINK_S_SA   (1 << 1)
0096 #define SLINK_S_SRX  (1 << 0)
0097 
0098 /* Mask register fields */
0099 #define SLINK_M_PERRE (1 << 7)
0100 #define SLINK_M_AERRE (1 << 6)
0101 #define SLINK_M_ROVE  (1 << 5)
0102 #define SLINK_M_RNEE  (1 << 4)
0103 #define SLINK_M_TNFE  (1 << 3)
0104 #define SLINK_M_SCE   (1 << 2)
0105 #define SLINK_M_SAE   (1 << 1)
0106 #define SLINK_M_SRXE  (1 << 0)
0107 
0108 /**** Macros ****/
0109 /* Get channel field from received SLINK word */
0110 #define SLINK_WRD_CHAN(x) ((x >> 16) & 0xF)
0111 /* Get IO card # from received SLINK word */
0112 #define SLINK_WRD_CARDNUM(x) ((x >> 21) & 0x3)
0113 /* Get data part from SLINK word */
0114 #define SLINK_WRD_PAYLOAD(x) (x & 0xFFFF)
0115 
0116 /* Checks status value to see if transmit queue has free slot */
0117 #define SLINK_STS_TRANSFREE(x) (x & SLINK_S_TNF)
0118 /* Get Sequence Index value */
0119 #define SLINK_STS_SI(x) ((x >> 16) & 0xFF)
0120 
0121 /**** Function declarations, driver interface ****/
0122 /* Initializes the SLINK core */
0123 int SLINK_init(unsigned int nullwrd, int parity, int qsize,
0124            void (*interrupt_trans_handler)(int),
0125            void (*sequence_callback)(int));
0126 
0127 /* Enables the core */
0128 void SLINK_start(void);
0129 
0130 /* Disables the core */
0131 void SLINK_stop(void);
0132 
0133 /* Reads one word */
0134 int SLINK_read(int data, int channel, int *reply);
0135 
0136 /* Writes one word */
0137 int SLINK_write(int data, int channel);
0138 
0139 /* Peforms a SEQUENCE */
0140 int SLINK_seqstart(int *a, int *b, int n, int channel, int reconly);
0141 
0142 /* Aborts a SEQUENCE */
0143 void SLINK_seqabort(void);
0144 
0145 /* Status of current or last SEQUENCE */
0146 int SLINK_seqstatus(void);
0147 
0148 /* Number of words transferred in last SEQUENCE */
0149 int SLINK_seqwrds(void);
0150 
0151 /* Returns value of core's status register */
0152 int SLINK_hwstatus(void);
0153 
0154 /* Returns number of elements in queue associated with IO card */
0155 int SLINK_queuestatus(int iocard);
0156 
0157 /* Take first element from queue for IO card # 'iocard' */
0158 int SLINK_dequeue(int iocard, int *elem);
0159 
0160 /* Returns structure containing core driver statistics */
0161 SLINK_stats *SLINK_statistics(void);
0162 
0163 #ifdef __cplusplus
0164 }
0165 #endif
0166 
0167 #endif /* __GRSLINK_H__ */