Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  GR1553B RT driver
0004  *
0005  *  COPYRIGHT (c) 2010.
0006  *  Cobham Gaisler AB.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions
0010  * are met:
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  *
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0027  * POSSIBILITY OF SUCH DAMAGE.
0028  */
0029 
0030 #ifndef __GR1553RT_H__
0031 #define __GR1553RT_H__
0032 
0033 /* CONFIG OPTION: Maximum number of LIST IDs supported.
0034  *                There are two lists per RT subaddress, one for RX one
0035  *                for TX.
0036  */
0037 #define RTLISTID_MAX 64
0038 
0039 /* CONFIG OPTION: Maximum number of Interrupt handlers per device supported 
0040  * max is 256 supported, and minimum is 1.
0041  */
0042 #define RTISR_MAX 64
0043 
0044 /* CONFIG OPTION: Maximum number of transfer (RX/TX) descriptors supported.
0045  *
0046  * Set this option to zero to allow flexible number of descriptors,
0047  * requires dynamically allocation of driver structures.
0048  */
0049 /*#define RTBD_MAX 4096*/
0050 #define RTBD_MAX 0
0051 
0052 #ifdef __cplusplus
0053 extern "C" {
0054 #endif
0055 
0056 /* Register GR1553B driver needed by RT driver */
0057 extern void gr1553rt_register(void);
0058 
0059 struct gr1553rt_list;
0060 
0061 /* Descriptor read/written by hardware.
0062  *
0063  * Must be aligned to 16 byte boundary 
0064  */
0065 struct gr1553rt_bd {
0066     volatile unsigned int   ctrl;   /* 0x00 Control/Status word */
0067     volatile unsigned int   dptr;   /* 0x04 Data Pointer */
0068     volatile unsigned int   next;   /* 0x08 Next Descriptor in list */
0069     volatile unsigned int   unused; /* 0x0C UNUSED BY HARDWARE */
0070 };
0071 
0072 /* Sub address table entry, the hardware access */
0073 struct gr1553rt_sa {
0074     volatile unsigned int ctrl; /* 0x00 SUBADDRESS CONTROL WORD */
0075     volatile unsigned int txptr;    /* 0x04 TRANSMIT BD POINTER */
0076     volatile unsigned int rxptr;    /* 0x08 RECEIVE BD POINTER */
0077     volatile unsigned int unused;   /* 0x0C UNUSED BY HARDWARE */
0078 };
0079 
0080 /* Configuration of a RT-SubAddress-List */
0081 struct gr1553rt_list_cfg {
0082     unsigned int bd_cnt;        /* Number of hw-descriptors in list */
0083 };
0084 
0085 /* A TX or RX subaddress descriptor list */
0086 struct gr1553rt_list {
0087     short listid;           /* ID/NUMBER of List. -1 unassigned */
0088     short subadr;           /* SubAddress. -1 when not scheduled */
0089     void *rt;           /* Scheduled on Device */
0090     struct gr1553rt_list_cfg *cfg;  /* List configuration */
0091     int bd_cnt;         /* Number of Descriptors */
0092 
0093     /* !!Must be last in data structure!! 
0094      * !!Array must at least be of length bd_cnt!!
0095      */
0096     unsigned short bds[0];      /* Array of BDIDs */
0097 };
0098 
0099 /* GR1553B-RT Driver configuration options used when calling gr1553rt_config().
0100  *
0101  * Note that if not custom addresses are given the driver will dynamically
0102  *      allocate memory for buffers.
0103  * Note that if custom addresses with the LSB set, the address will be
0104  *      interpreted as a address accessible by hardware, and translated
0105  *      into an address used by CPU.
0106  */
0107 struct gr1553rt_cfg {
0108     unsigned char rtaddress;    /* RT Address 0..30 */
0109 
0110     /*** MODE CODE CONFIG ***/
0111     unsigned int modecode;      /* Mode codes enable/disable/IRQ/EV-Log.
0112                      * Each modecode has a 2-bit cfg field.
0113                      * See Mode Code Control Register in
0114                      * hardware manual.
0115                      */
0116 
0117     /*** TIME CONFIG ***/
0118     unsigned short time_res;    /* Time tag resolution in us */
0119 
0120     /*** SUBADDRESS TABLE CONFIG ***/
0121     void *satab_buffer;     /* Optional Custom buffer. Must be 
0122                      * At least 16*32 bytes, and be aligned
0123                      * to 10-bit (1KB) boundary. Set to NULL
0124                      * to make driver allocate buffer.
0125                      */
0126 
0127     /*** EVENT LOG CONFIG ***/
0128     void *evlog_buffer;     /* Optional Custom buffer */
0129     int evlog_size;         /* Length, must be a multiple of 2.
0130                      * If set to ZERO event log is disabled
0131                      */
0132 
0133     /*** TRANSFER DESCRIPTOR CONFIG ***/
0134     int bd_count;           /* Number of transfer descriptors shared
0135                      * by all RX/TX sub-addresses */
0136     void *bd_buffer;        /* Optional Custom descriptor area.
0137                      * Must hold bd_count*32 bytes.
0138                      * If NULL, descriptors will be     
0139                      * allocated dynamically. */
0140 };
0141 
0142 /* GR1553B-RT status indication, copied from the RT registers and stored
0143  * here. Used when calling the gr1553rt_status() function.
0144  */
0145 struct gr1553rt_status {
0146     unsigned int status;        /* RT Status word */
0147     unsigned int bus_status;    /* BUS Status */
0148     unsigned short synctime;    /* Time Tag of last sync with data */
0149     unsigned short syncword;    /* Data of last mode code synchronize
0150                      * with data. */
0151     unsigned short time_res;    /* Time resolution (set by config) */
0152     unsigned short time;        /* Current Time Tag */
0153 };
0154 
0155 /* ISR callback definition for ERRORs detected in the GR1553B-RT interrupt
0156  * handler.
0157  *
0158  * \param err    Inidicate Error type. The IRQ flag register bit mask:
0159  *                 Bit 9  - RT DMA ERROR
0160  *                 Bit 10 - RT Table access error
0161  * \param data   Custom data assigned by user
0162  */
0163 typedef void (*gr1553rt_irqerr_t)(int err, void *data);
0164 
0165 /* ISR callback definition for modecodes that are configured to generate
0166  * an IRQ. The callback is called from within the GR1553B-RT interrupt
0167  * handler.
0168  *
0169  * \param mcode  Mode code that caused this IRQ
0170  * \param entry  The raw Eventlog Entry
0171  * \param data   Custom data assigned by user
0172  */
0173 typedef void (*gr1553rt_irqmc_t)(int mcode, unsigned int entry, void *data);
0174 
0175 /* Transfer ISR callback definition. Called from GR1553B-RT interrupt handler
0176  * when an interrupt has been generated and a event logged due to a 1553
0177  * transfer to this RT.
0178  *
0179  * \param list     List (Subaddress/TransferType) that caused IRQ
0180  * \param entry    The raw Eventlog Entry
0181  * \param bd_next  Next Descriptor-entry index in the list (Subaddress/tr-type)
0182  *                 This can be used to process all descriptors upto entry_next.
0183  * \param data     Custom data assigned by user
0184  */
0185 typedef void (*gr1553rt_irq_t)(
0186     struct gr1553rt_list *list, 
0187     unsigned int entry,
0188     int bd_next,
0189     void *data
0190     );
0191 
0192 /* Configure a list according to configuration. Assign the list
0193  * to a device, however not to a RT sub address yet. The rt
0194  * is stored within list.
0195  *
0196  * \param rt       RT Device driver identification, stored within list.
0197  * \param list     The list to configure
0198  * \param cfg      Configuration for list. Pointer to configuration is
0199  *                 stored within list for later use.
0200  */
0201 extern int gr1553rt_list_init
0202     (
0203     void *rt,
0204     struct gr1553rt_list **plist,
0205     struct gr1553rt_list_cfg *cfg
0206     );
0207 
0208 /* Assign an Error Interrupt handler. Before the handler is called the 
0209  * RT hardware is stopped/disabled. The handler is optional, if not assigned
0210  * the ISR will still stop the RT upon error.
0211  *
0212  * Errors detected by the interrupt handler:
0213  *  - DMA error
0214  *  - Subaddress table access error
0215  *
0216  * \param func     ISR called when an error causes an interrupt.
0217  * \param data     Custom data given as an argument when calling ISR
0218  */
0219 extern int gr1553rt_irq_err
0220     (
0221     void *rt,
0222     gr1553rt_irqerr_t func,
0223     void *data
0224     );
0225 
0226 /* Assign a ModeCode Interrupt handler callback. Called when a 1553 modecode
0227  * transfer is logged and cause an IRQ. The modecode IRQ generation is
0228  * configured from "struct gr1553rt_cfg" when calling gr1553rt_config().
0229  *
0230  * \param func     ISR called when a modecode causes an interrupt.
0231  * \param data     Custom data given as an argument when calling ISR
0232  */
0233 extern int gr1553rt_irq_mc
0234     (
0235     void *rt,
0236     gr1553rt_irqmc_t func,
0237     void *data
0238     );
0239 
0240 /* Assign transfer interrupt handler callback. Called when a RX or TX
0241  * transfer is logged and cause an interrupt, the function is called
0242  * from the GR1553B-RT driver's ISR, in interrupt context.
0243  *
0244  * The callback can be installed per subaddress and transfer type.
0245  * Subaddress 0 and 31 are not valid (gr1553rt_irq_mc() for modecodes).
0246  *
0247  * \param subadr   Select subaddress (1-30)
0248  * \param tx       1=TX subaddress, 0=RX subaddress
0249  * \param func     ISR called when subaddress of spcified transfer type
0250  *                 causes an interrupt.
0251  * \param data     Custom data given as an argument when calling ISR
0252  */
0253 extern int gr1553rt_irq_sa
0254     (
0255     void *rt,
0256     int subadr,
0257     int tx,
0258     gr1553rt_irq_t func,
0259     void *data
0260     );
0261 
0262 #define GR1553RT_BD_FLAGS_IRQEN (1<<30)
0263 /* Initialize a descriptor entry in a list. This is typically done
0264  * prior to scheduling the list.
0265  *
0266  * \param entry_no  Entry number in list (descriptor index in list)
0267  * \param flags     Enable IRQ when descriptor is accessed by setting 
0268  *                  argument GR1553RT_BD_FLAGS_IRQEN. Enabling IRQ on a
0269  *                  descriptor basis will override SA-table IRQ config.
0270  * \param dptr      Data Pointer to RX or TX operation. The LSB indicate
0271  *                  if the address must be translated into Hardware address
0272  *                  - this is useful when a buffer close to CPU is used
0273  *                  as a data pointer and the RT core is located over PCI.
0274  * \param next      Next Entry in list. Set to 0xffff for end of list. Set
0275  *                  0xfffe for next entry in list, wrap around to entry
0276  *                  zero if entry_no is last descriptor in list (circular).
0277  */
0278 extern int gr1553rt_bd_init(
0279     struct gr1553rt_list *list,
0280     unsigned short entry_no,
0281     unsigned int flags,
0282     uint16_t *dptr,
0283     unsigned short next
0284     );
0285 
0286 /* Manipulate/Read Control/Status and Data Pointer words of a buffer descriptor.
0287  * If status is zero, the control/status word is accessed. If dptr is non-zero
0288  * the data pointer word is accessed.
0289  *
0290  * \param list       The list that the descriptor is located at
0291  *
0292  * \param entry_no   The descriptor number accessed
0293  *
0294  * \param status     IN/OUT. If zero no effect. If pointer is non-zero the
0295  *                   value pointed to:
0296  *                   IN: Written to Control/Status
0297  *                   OUT: the value of the Control/Status word before writing.
0298  *
0299  * \param dptr       IN/OUT. If zero no effect. If pointer is non-zero, the
0300  *                   value pointed to:
0301  *                   IN: non-zero: Descriptor data pointer will be updated with
0302  *                       this value. Note that the LSB indicate if the address
0303  *                       must be translated into hardware-aware address.
0304  *                   OUT: The old data pointer is stored here.
0305  */
0306 extern int gr1553rt_bd_update(
0307     struct gr1553rt_list *list,
0308     int entry_no,
0309     unsigned int *status,
0310     uint16_t **dptr
0311     );
0312 
0313 /* Get the next/current descriptor processed of a RT sub-address.
0314  *
0315  * \param subadr  RT Subaddress
0316  * \param txeno   Pointer to where TX descriptor number is stored.
0317  * \param rxeno   Pointer to where RX descriptor number is stored.
0318  */
0319 extern int gr1553rt_indication(void *rt, int subadr, int *txeno, int *rxeno);
0320 
0321 /* Take a GR1553RT hardware device identified by minor.
0322  * A pointer is returned that is used internally by the GR1553RT
0323  * driver, it is used as an input parameter 'rt' to all other
0324  * functions that manipulate the hardware.
0325  *
0326  * This function initializes the RT hardware to a stopped/disable level.
0327  */
0328 extern void *gr1553rt_open(int minor);
0329 
0330 /* Close and stop/disable the RT hardware. */
0331 extern void gr1553rt_close(void *rt);
0332 
0333 /* Configure the RT. The RT device must be configured once before
0334  * started. A started RT device can not be configured.
0335  *
0336  * \param rt    The RT to configure
0337  * \param cfg   Configuration parameters
0338  */
0339 extern int gr1553rt_config(void *rt, struct gr1553rt_cfg *cfg);
0340 
0341 /* Schedule a RX or TX list on a sub address. If a list has already been
0342  * schduled on the subaddress and on the same transfer type (RX/TX), the 
0343  * old list is replaced with the list given here.
0344  *
0345  * \param subadr   Subaddress to schedule list on
0346  * \param tx       Subaddress transfer type: 1=TX, 0=RX
0347  * \param list     Preconfigued RT list scheduled
0348  */
0349 extern void gr1553rt_sa_schedule(
0350     void *rt,
0351     int subadr,
0352     int tx,
0353     struct gr1553rt_list *list
0354     );
0355 
0356 /* Set SubAdress options. One may for example Enable or Disable a sub 
0357  * address RX and/or TX. See hardware manual for SA-Table configuration
0358  * options.
0359  *
0360  * \param subadr   SubAddress to configure
0361  * \param mask     Bit mask of option-bits written to subaddress config
0362  * \param options  The new options written to subaddress config.
0363  *
0364  */
0365 extern void gr1553rt_sa_setopts(
0366     void *rt,
0367     int subadr,
0368     unsigned int mask,
0369     unsigned int options
0370     );
0371 
0372 /* Get The Subaddress and transfer type of a scheduled list. Normally the
0373  * application knows which subaddress the list is for.
0374  *
0375  * \param list     List to lookup information for
0376  * \param subadr   Pointer to where the subaddress is stored
0377  * \param tx       Transfer type is stored here. 1=TX, 0=RX.
0378  */
0379 extern void gr1553rt_list_sa(
0380     struct gr1553rt_list *list,
0381     int *subadr,
0382     int *tx
0383     );
0384 
0385 /* Start RT Communication
0386  *
0387  * Interrupts will be enabled. The RT enabled and the "RT-run-time" 
0388  * part of the API will be opened for the user and parts that need the
0389  * RT to be stopped are no longer available. After the RT has been
0390  * started the configuration function can not be called.
0391  */
0392 extern int gr1553rt_start(void *rt);
0393 
0394 /* Get Status of the RT core. See data structure gr1553rt_status for more
0395  * information about the result. It can be used to read out:
0396  *  - time information
0397  *  - sync information
0398  *  - bus & RT status
0399  *
0400  * \param status   Pointer to where the status words will be stored. They
0401  *                 are stored according to the gr1553rt_status data structure.
0402  */
0403 extern void gr1553rt_status(void *rt, struct gr1553rt_status *status);
0404 
0405 /* Stop RT communication. Only possible to stop an already started RT device.
0406  * Interrupts are disabled and the RT Enable bit cleared.
0407  */
0408 extern void gr1553rt_stop(void *rt);
0409 
0410 /* Set RT vector and/or bit word.
0411  *
0412  *  - Vector Word is used in response to "Transmit vector word" BC commands
0413  *  - Bit Word is used in response to "Transmit bit word" BC commands
0414  *
0415  *
0416  * \param mask     Bit-Mask, bits that are 1 will result in that bit in the
0417  *                 words register being overwritten with the value of words
0418  * \param words    Bits 31..16: Bit Word. Bits 15..0: Vector Word.
0419  *
0420  * Operation:
0421  *  hw_words = (hw_words & ~mask) | (words & mask)
0422  */
0423 extern void gr1553rt_set_vecword(
0424     void *rt,
0425     unsigned int mask,
0426     unsigned int words
0427     );
0428 
0429 /* Set selectable bits of the "Bus Status Register". The bits written
0430  * is determined by the "mask" bit-mask. Operation:
0431  *
0432  * bus_status = (bus_status & ~mask) | (sts & mask)
0433  * 
0434  */
0435 extern void gr1553rt_set_bussts(void *rt, unsigned int mask, unsigned int sts);
0436 
0437 /* Read up to MAX number of entries in eventlog log. 
0438  *
0439  * \param dst   Destination address for event log entries
0440  * \param max   Maximal number of event log entries that an be stored into dst
0441  *
0442  * Return
0443  *  negative   Failure
0444  *  zero       No entries available at the moment
0445  *  positive   Number of entries copied into dst
0446  */
0447 extern int gr1553rt_evlog_read(void *rt, unsigned int *dst, int max);
0448 
0449 #ifdef __cplusplus
0450 }
0451 #endif
0452 
0453 #endif