nmsis_compiler.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2019 Nuclei Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef __NMSIS_COMPILER_H
  19. #define __NMSIS_COMPILER_H
  20. #include <stdint.h>
  21. /*!
  22. * @file nmsis_compiler.h
  23. * @brief NMSIS compiler generic header file
  24. */
  25. #if defined ( __GNUC__ )
  26. /* GNU GCC Compiler */
  27. #include "nmsis_gcc.h"
  28. #elif defined ( __ICCRISCV__ )
  29. /* IAR Compiler */
  30. #include "nmsis_iar.h"
  31. #else
  32. #error Unknown compiler.
  33. #endif
  34. /* IO definitions (access restrictions to peripheral registers) */
  35. /**
  36. * \defgroup NMSIS_Core_PeriphAccess Peripheral Access
  37. * \brief Naming conventions and optional features for accessing peripherals.
  38. *
  39. * The section below describes the naming conventions, requirements, and optional features
  40. * for accessing device specific peripherals.
  41. * Most of the rules also apply to the core peripherals.
  42. *
  43. * The **Device Header File <device.h>** contains typically these definition
  44. * and also includes the core specific header files.
  45. *
  46. * @{
  47. */
  48. /** \brief Defines 'read only' permissions */
  49. #ifdef __cplusplus
  50. #define __I volatile
  51. #else
  52. #define __I volatile const
  53. #endif
  54. /** \brief Defines 'write only' permissions */
  55. #define __O volatile
  56. /** \brief Defines 'read / write' permissions */
  57. #define __IO volatile
  58. /* following defines should be used for structure members */
  59. /** \brief Defines 'read only' structure member permissions */
  60. #define __IM volatile const
  61. /** \brief Defines 'write only' structure member permissions */
  62. #define __OM volatile
  63. /** \brief Defines 'read/write' structure member permissions */
  64. #define __IOM volatile
  65. /**
  66. * \brief Mask and shift a bit field value for use in a register bit range.
  67. * \details The macro \ref _VAL2FLD uses the #define's _Pos and _Msk of the related bit
  68. * field to shift bit-field values for assigning to a register.
  69. *
  70. * **Example**:
  71. * \code
  72. * ECLIC->CFG = _VAL2FLD(CLIC_CLICCFG_NLBIT, 3);
  73. * \endcode
  74. * \param[in] field Name of the register bit field.
  75. * \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
  76. * \return Masked and shifted value.
  77. */
  78. #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
  79. /**
  80. * \brief Mask and shift a register value to extract a bit filed value.
  81. * \details The macro \ref _FLD2VAL uses the #define's _Pos and _Msk of the related bit
  82. * field to extract the value of a bit field from a register.
  83. *
  84. * **Example**:
  85. * \code
  86. * nlbits = _FLD2VAL(CLIC_CLICCFG_NLBIT, ECLIC->CFG);
  87. * \endcode
  88. * \param[in] field Name of the register bit field.
  89. * \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
  90. * \return Masked and shifted bit field value.
  91. */
  92. #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
  93. /** @} */ /* end of group NMSIS_Core_PeriphAccess */
  94. #endif /* __NMSIS_COMPILER_H */