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 BM 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 __GR1553BM_H__
0031 #define __GR1553BM_H__
0032 
0033 #ifdef __cplusplus
0034 extern "C" {
0035 #endif
0036 
0037 /* Register GR1553B driver needed by BM driver */
0038 extern void gr1553bm_register(void);
0039 
0040 struct gr1553bm_entry {
0041     uint32_t time;  /* bit31=1, bit 30=0 */
0042     uint32_t data;  /* bit31=0, bit 30=0 */
0043 };
0044 
0045 #define GR1553BM_ERROPTS_MANL 0x02
0046 #define GR1553BM_ERROPTS_UDWL 0x04
0047 #define GR1553BM_ERROPTS_IMCL 0x08
0048 #define GR1553BM_ERROPTS_ALL  0x0e
0049 
0050 /* Function used to implement a custom copy routine.
0051  * Returns number of bytes the desctionation address 
0052  * should be incremented with.
0053  *
0054  * \param dst        Optional Destination address
0055  * \param src        Source DMA address
0056  * \param nentires   Number of entries to be processed.
0057  * \param data       Custom Data (set by config)
0058  */
0059 typedef int (*bmcopy_func_t)(
0060     unsigned int dst,
0061     struct gr1553bm_entry *src,
0062     int nentries,
0063     void *data
0064     );
0065 
0066 /* IRQ function callback, called on BM DMA error */
0067 typedef void (*bmisr_func_t)(void *bm, void *data);
0068 
0069 /* BM driver configuration */
0070 struct gr1553bm_config {
0071 
0072     /*** Time options ***/
0073 
0074     /* 8-bit time resolution, the BM will update the time according
0075      * to this setting. 0 will make the time tag be of highest
0076      * resolution (no division), 1 will make the BM increment the
0077      * time tag once for two time ticks (div with 2), etc.
0078      */
0079     uint8_t time_resolution;
0080 
0081     /* Enable Time Overflow IRQ handling. Setting this to 1 
0082      * makes the driver to update the 64-bit time by it self,
0083      * it will use time overflow IRQ to detect when the 64-bit
0084      * time counter must be incremented.
0085      *
0086      * If set to zero, the driver expect the user to call
0087      * gr1553bm_time() regularly, it must be called more often
0088      * than the time overflows to avoid an incorrect time.
0089      */
0090     int time_ovf_irq;
0091 
0092 
0093 
0094     /*** Filtering options ***/
0095 
0096     /* Bus error log options 
0097      *
0098      * bit0,4-31 = reserved, set to zero
0099      * Bit1 = Enables logging of Invalid mode code errors
0100      * Bit2 = Enables logging of Unexpected Data errors
0101      * Bit3 = Enables logging of Manchester/parity errors
0102      */
0103     unsigned int filt_error_options;
0104 
0105     /* RT Address filtering bit mask. Each bit enables (if set)
0106      * logging of a certain RT sub address. Bit 31 enables logging
0107      * of broadcast messages.
0108      */
0109     unsigned int filt_rtadr;
0110 
0111     /* RT Subaddress filtering bit mask, bit definition:
0112      *  31:     Enables logging of mode commands on subadr 31
0113      *  1..30:  BitN enables/disables logging of RT subadr N
0114      *  0:      Enables logging of mode commands on subadr 0
0115      */
0116     unsigned int filt_subadr;
0117 
0118     /* Mode code Filter, is written into "BM RT Mode code filter"
0119      * register, please see hardware manual for bit declarations.
0120      */
0121     unsigned int filt_mc;
0122 
0123 
0124 
0125     /*** Buffer options ***/
0126 
0127     /* Size of buffer in bytes, must be aligned to 8-byte 
0128      * The size is limited to max 4Mb.
0129      */
0130     unsigned int buffer_size;
0131 
0132     /* Custom buffer, must be aligned to 8-byte and be of buffer_size
0133      * length. If NULL dynamic memory allocation is used.
0134      */
0135     void *buffer_custom;
0136 
0137     /* Custom Copy function, may be used to implement a more 
0138      * effective way of copying the DMA buffer. For example
0139      * the DMA log may need to be compressed before copied
0140      * onto a storage, this function can be used to avoid an
0141      * extra copy.
0142      */
0143     bmcopy_func_t copy_func;
0144 
0145     /* Optional Custom Data passed on to copy_func() */
0146     void *copy_func_arg;
0147 
0148 
0149 
0150     /*** Interrupt options ***/
0151 
0152     /* Custom DMA error function, note that this function is called
0153      * from Interrupt Context. Set to NULL to disable this callback.
0154      */
0155     bmisr_func_t dma_error_isr;
0156 
0157     /* Optional Custom Data passed on to dma_error_isr() */
0158     void *dma_error_arg;
0159 };
0160 
0161 /* Open BM device by instance number (minor)
0162  *
0163  * The return value is used as input parameter in all other function calls
0164  * in the A
0165  */
0166 extern void *gr1553bm_open(int minor);
0167 
0168 /* Close previously opened Bm device */
0169 extern void gr1553bm_close(void *bm);
0170 
0171 /* Configure the BM driver before starting */
0172 extern int gr1553bm_config(void *bm, struct gr1553bm_config *cfg);
0173 
0174 /* Start logging */
0175 extern int gr1553bm_start(void *bm);
0176 
0177 /* Get 64-bit 1553 Time. Low 24-bit time is acquired from BM hardware,
0178  * the MSB is taken from a software counter internal to the driver. The
0179  * counter is incremented every time the Time overflows by:
0180  *  - using "Time overflow" IRQ if enabled in user configuration
0181  *  - by checking IRQ flag (IRQ disabled), it is required that user
0182  *    calls this function before the next time overflow.
0183  *
0184  * The BM timer is limited to 24-bits, in order to handle overflows
0185  * correctly and maintain a valid time an Interrupt handler is used
0186  * or this function must be called when IRQ is not used.
0187  *
0188  * Update software time counters and return the current time.
0189  */
0190 extern void gr1553bm_time(void *bm, uint64_t *time);
0191 
0192 /* Return zero when logging has not been started, non-zero when logging
0193  * has been started
0194  */
0195 extern int gr1553bm_started(void *bm);
0196 
0197 /* Check how many entries are currently stored in the BM Log DMA-area */
0198 extern int gr1553bm_available(void *bm, int *nentries);
0199 
0200 /* Stop logging */
0201 extern void gr1553bm_stop(void *bm);
0202 
0203 /* Read a maximum number of entries from LOG buffer. This function
0204  * must be 
0205  *
0206  * Arguments
0207  *  bm           - Private pointer returned by gr1553bm_open()
0208  *  dst          - Address where log data is written
0209  *  max          - (IN/OUT) Maximum number of entires, when successfull
0210  *                 the number of entries actually written is stored
0211  *                 into the address of max.
0212  *
0213  * Result
0214  *  0   = success
0215  *  -1  = fail. (may be due to BM logging not started)
0216  */
0217 extern int gr1553bm_read(void *bm, struct gr1553bm_entry *dst, int *max);
0218 
0219 #ifdef __cplusplus
0220 }
0221 #endif
0222 
0223 #endif /* __GR1553BM_H__ */