Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:44

0001 /**
0002  * @file
0003  *
0004  * @ingroup RTEMSBSPsARMCycVContrib
0005  */
0006 
0007 /******************************************************************************
0008  *
0009  * Copyright 2013 Altera Corporation. All Rights Reserved.
0010  *
0011  * Redistribution and use in source and binary forms, with or without
0012  * modification, are permitted provided that the following conditions are met:
0013  *
0014  * 1. Redistributions of source code must retain the above copyright notice,
0015  * this list of conditions and the following disclaimer.
0016  *
0017  * 2. Redistributions in binary form must reproduce the above copyright notice,
0018  * this list of conditions and the following disclaimer in the documentation
0019  * and/or other materials provided with the distribution.
0020  *
0021  * 3. The name of the author may not be used to endorse or promote products
0022  * derived from this software without specific prior written permission.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
0025  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0026  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO
0027  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0028  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
0029  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0032  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
0033  * OF SUCH DAMAGE.
0034  *
0035  ******************************************************************************/
0036 
0037 
0038 /*! \file Altera - ALT_SOCAL */
0039 
0040 #ifndef __ALTERA_SOCAL_H__
0041 #define __ALTERA_SOCAL_H__
0042 
0043 #ifndef __ASSEMBLY__
0044 #ifdef __cplusplus
0045 #include <cstddef>
0046 #include <cstdbool>
0047 #include <cstdint>
0048 #else   /* __cplusplus */
0049 #include <stddef.h>
0050 #include <stdbool.h>
0051 #include <stdint.h>
0052 #endif  /* __cplusplus */
0053 #endif  /* __ASSEMBLY__ */
0054 
0055 #ifdef __cplusplus
0056 extern "C"
0057 {
0058 #endif  /* __cplusplus */
0059 
0060 /*!
0061  * \addtogroup ALT_SOCAL_UTIL SoCAL Utilities
0062  *
0063  * This file contains utility and support functions for the Altera SoCAL.
0064  * @{
0065  */
0066 
0067 #ifdef __ASSEMBLY__
0068 #define ALT_CAST(type, ptr)  ptr
0069 #else   /* __ASSEMBLY__ */
0070 /*! Cast the pointer to specified pointer type.
0071  *
0072  *  Note: This macro expands to \e ptr value only for assembler language 
0073  *        targets.
0074  *
0075  *  \param type     The pointer type to cast to
0076  *  \param ptr      The pointer to apply the type cast to
0077  */
0078 #define ALT_CAST(type, ptr)  ((type) (ptr))
0079 #endif  /* __ASSEMBLY__ */
0080 
0081 /*!
0082  * \addtogroup ALT_SOCAL_UTIL_RW_FUNC SoCAL Memory Read/Write Utilities
0083  *
0084  * This section implements read and write functionality for various
0085  * memory untis. The memory unit terms used for these functions are
0086  * consistent with those used in the ARM Architecture Reference Manual
0087  * ARMv7-A and ARMv7-R edition manual. The terms used for units of memory are:
0088  *
0089  *  Unit of Memory | Abbreviation | Size in Bits
0090  * :---------------|:-------------|:------------:
0091  *  Byte           | byte         |       8
0092  *  Half Word      | hword        |      16
0093  *  Word           | word         |      32
0094  *  Double Word    | dword        |      64
0095  *
0096  * @{
0097  */
0098 
0099 /*! Write the 8 bit byte to the destination address in device memory.
0100  *  \param dest - Write destination pointer address
0101  *  \param src  - 8 bit data byte to write to memory
0102  */
0103 #define alt_write_byte(dest, src)       (*ALT_CAST(volatile uint8_t *, (dest)) = (src))
0104 
0105 /*! Read and return the 8 bit byte from the source address in device memory.
0106  *  \param src    Read source pointer address
0107  *  \returns      8 bit data byte value
0108  */
0109 #define alt_read_byte(src)              (*ALT_CAST(volatile uint8_t *, (src)))
0110 
0111 /*! Write the 16 bit half word to the destination address in device memory.
0112  *  \param dest - Write destination pointer address
0113  *  \param src  - 16 bit data half word to write to memory
0114  */
0115 #define alt_write_hword(dest, src)      (*ALT_CAST(volatile uint16_t *, (dest)) = (src))
0116 
0117 /*! Read and return the 16 bit half word from the source address in device memory.
0118  *  \param src    Read source pointer address
0119  *  \returns      16 bit data half word value
0120  */
0121 #define alt_read_hword(src)             (*ALT_CAST(volatile uint16_t *, (src)))
0122 
0123 /*! Write the 32 bit word to the destination address in device memory.
0124  *  \param dest - Write destination pointer address
0125  *  \param src  - 32 bit data word to write to memory
0126  */
0127 #define alt_write_word(dest, src)       (*ALT_CAST(volatile uint32_t *, (dest)) = (src))
0128 
0129 /*! Read and return the 32 bit word from the source address in device memory.
0130  *  \param src    Read source pointer address
0131  *  \returns      32 bit data word value
0132  */
0133 #define alt_read_word(src)              (*ALT_CAST(volatile uint32_t *, (src)))
0134 
0135 /*! Write the 64 bit double word to the destination address in device memory.
0136  *  \param dest - Write destination pointer address
0137  *  \param src  - 64 bit data double word to write to memory
0138  */
0139 #define alt_write_dword(dest, src)      (*ALT_CAST(volatile uint64_t *, (dest)) = (src))
0140 
0141 /*! Read and return the 64 bit double word from the source address in device memory.
0142  *  \param src    Read source pointer address
0143  *  \returns      64 bit data double word value
0144  */
0145 #define alt_read_dword(src)             (*ALT_CAST(volatile uint64_t *, (src)))
0146 
0147 /*! @} */
0148 
0149 /*!
0150  * \addtogroup ALT_SOCAL_UTIL_SC_FUNC SoCAL Memory Bit Set/Clr/XOR/Replace Utilities
0151  *
0152  * This section implements useful macros to set, clear, change, and replace
0153  * selected bits within a word in memory or a memory-mapped register.
0154  * @{
0155  *
0156  */
0157 
0158 /*! Set selected bits in the 8 bit byte at the destination address in device memory.
0159  *  \param dest - Destination pointer address
0160  *  \param bits - Bits to set in destination byte
0161  */
0162 #define     alt_setbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) | (bits)))
0163 
0164 /*! Clear selected bits in the 8 bit byte at the destination address in device memory.
0165  *  \param dest - Destination pointer address
0166  *  \param bits - Bits to clear in destination byte
0167  */
0168 #define     alt_clrbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) & ~(bits)))
0169 
0170 /*! Change or toggle selected bits in the 8 bit byte at the destination address in device memory.
0171  *  \param dest - Destination pointer address
0172  *  \param bits - Bits to change in destination byte
0173  */
0174 #define     alt_xorbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) ^ (bits)))
0175 
0176 /*! Replace selected bits in the 8 bit byte at the destination address in device memory.
0177  *  \param  dest - Destination pointer address
0178  *  \param  msk  - Bits to replace in destination byte
0179  *  \param  src  - Source bits to write to cleared bits in destination byte
0180  */
0181 #define     alt_replbits_byte(dest, msk, src)   (alt_write_byte(dest,(alt_read_byte(dest) & ~(msk)) | ((src) & (msk))))
0182 
0183 /*! Set selected bits in the 16 bit halfword at the destination address in device memory.
0184  *  \param dest - Destination pointer address
0185  *  \param bits - Bits to set in destination halfword
0186  */
0187 #define     alt_setbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) | (bits)))
0188 
0189 /*! Clear selected bits in the 16 bit halfword at the destination address in device memory.
0190  *  \param dest - Destination pointer address
0191  *  \param bits - Bits to clear in destination halfword
0192  */
0193 #define     alt_clrbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) & ~(bits)))
0194 
0195 /*! Change or toggle selected bits in the 16 bit halfword at the destination address in device memory.
0196  *  \param dest - Destination pointer address
0197  *  \param bits - Bits to change in destination halfword
0198  */
0199 #define     alt_xorbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) ^ (bits)))
0200 
0201 /*! Replace selected bits in the 16 bit halfword at the destination address in device memory.
0202  *  \param  dest - Destination pointer address
0203  *  \param  msk  - Bits to replace in destination halfword
0204  *  \param  src  - Source bits to write to cleared bits in destination halfword
0205  */
0206 #define     alt_replbits_hword(dest, msk, src)   (alt_write_hword(dest,(alt_read_hword(dest) & ~(msk)) | ((src) & (msk))))
0207 
0208 /*! Set selected bits in the 32 bit word at the destination address in device memory.
0209  *  \param dest - Destination pointer address
0210  *  \param bits - Bits to set in destination word
0211  */
0212 #define     alt_setbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) | (bits)))
0213 
0214 /*! Clear selected bits in the 32 bit word at the destination address in device memory.
0215  *  \param dest - Destination pointer address
0216  *  \param bits - Bits to clear in destination word
0217  */
0218 #define     alt_clrbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) & ~(bits)))
0219 
0220 /*! Change or toggle selected bits in the 32 bit word at the destination address in device memory.
0221  *  \param dest - Destination pointer address
0222  *  \param bits - Bits to change in destination word
0223  */
0224 #define     alt_xorbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) ^ (bits)))
0225 
0226 /*! Replace selected bits in the 32 bit word at the destination address in device memory.
0227  *  \param  dest - Destination pointer address
0228  *  \param  msk  - Bits to replace in destination word
0229  *  \param  src  - Source bits to write to cleared bits in destination word
0230  */
0231 #define     alt_replbits_word(dest, msk, src)   (alt_write_word(dest,(alt_read_word(dest) & ~(msk)) | ((src) & (msk))))
0232 
0233 /*! Set selected bits in the 64 bit doubleword at the destination address in device memory.
0234  *  \param dest - Destination pointer address
0235  *  \param bits - Bits to set in destination doubleword
0236  */
0237 #define     alt_setbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) | (bits)))
0238 
0239 /*! Clear selected bits in the 64 bit doubleword at the destination address in device memory.
0240  *  \param dest - Destination pointer address
0241  *  \param bits - Bits to clear in destination doubleword
0242  */
0243 #define     alt_clrbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) & ~(bits)))
0244 
0245 /*! Change or toggle selected bits in the 64 bit doubleword at the destination address in device memory.
0246  *  \param dest - Destination pointer address
0247  *  \param bits - Bits to change in destination doubleword
0248  */
0249 #define     alt_xorbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) ^ (bits)))
0250 
0251 /*! Replace selected bits in the 64 bit doubleword at the destination address in device memory.
0252  *  \param  dest - Destination pointer address
0253  *  \param  msk  - Bits to replace in destination doubleword
0254  *  \param  src  - Source bits to write to cleared bits in destination word
0255  */
0256 #define     alt_replbits_dword(dest, msk, src)   (alt_write_dword(dest,(alt_read_dword(dest) & ~(msk)) | ((src) & (msk))))
0257 
0258 /*! @} */
0259 
0260 /*! @} */
0261 
0262 #ifdef __cplusplus
0263 }
0264 #endif  /* __cplusplus */
0265 #endif  /* __ALTERA_SOCAL_H__ */