compiler_abstraction.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice, this
  7. list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form, except as embedded into a Nordic
  9. Semiconductor ASA integrated circuit in a product or a software update for
  10. such product, must reproduce the above copyright notice, this list of
  11. conditions and the following disclaimer in the documentation and/or other
  12. materials provided with the distribution.
  13. 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  14. contributors may be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16. 4. This software, with or without modification, must only be used with a
  17. Nordic Semiconductor ASA integrated circuit.
  18. 5. Any software provided in binary form under this license must not be reverse
  19. engineered, decompiled, modified and/or disassembled.
  20. THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  21. OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  26. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  29. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef _COMPILER_ABSTRACTION_H
  32. #define _COMPILER_ABSTRACTION_H
  33. /*lint ++flb "Enter library region" */
  34. #if defined ( __CC_ARM )
  35. #ifndef __ASM
  36. #define __ASM __asm
  37. #endif
  38. #ifndef __INLINE
  39. #define __INLINE __inline
  40. #endif
  41. #ifndef __WEAK
  42. #define __WEAK __weak
  43. #endif
  44. #ifndef __ALIGN
  45. #define __ALIGN(n) __align(n)
  46. #endif
  47. #ifndef __PACKED
  48. #define __PACKED __packed
  49. #endif
  50. #define GET_SP() __current_sp()
  51. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  52. #ifndef __ASM
  53. #define __ASM __asm
  54. #endif
  55. #ifndef __INLINE
  56. #define __INLINE __inline
  57. #endif
  58. #ifndef __WEAK
  59. #define __WEAK __attribute__((weak))
  60. #endif
  61. #ifndef __ALIGN
  62. #define __ALIGN(n) __attribute__((aligned(n)))
  63. #endif
  64. #ifndef __PACKED
  65. #define __PACKED __attribute__((packed, aligned(1)))
  66. #endif
  67. #define GET_SP() __current_sp()
  68. #elif defined ( __ICCARM__ )
  69. #ifndef __ASM
  70. #define __ASM __asm
  71. #endif
  72. #ifndef __INLINE
  73. #define __INLINE inline
  74. #endif
  75. #ifndef __WEAK
  76. #define __WEAK __weak
  77. #endif
  78. #ifndef __ALIGN
  79. #define STRING_PRAGMA(x) _Pragma(#x)
  80. #define __ALIGN(n) STRING_PRAGMA(data_alignment = n)
  81. #endif
  82. #ifndef __PACKED
  83. #define __PACKED __packed
  84. #endif
  85. #define GET_SP() __get_SP()
  86. #elif defined ( __GNUC__ )
  87. #ifndef __ASM
  88. #define __ASM __asm
  89. #endif
  90. #ifndef __INLINE
  91. #define __INLINE inline
  92. #endif
  93. #ifndef __WEAK
  94. #define __WEAK __attribute__((weak))
  95. #endif
  96. #ifndef __ALIGN
  97. #define __ALIGN(n) __attribute__((aligned(n)))
  98. #endif
  99. #ifndef __PACKED
  100. #define __PACKED __attribute__((packed))
  101. #endif
  102. #define GET_SP() gcc_current_sp()
  103. static inline unsigned int gcc_current_sp(void)
  104. {
  105. register unsigned sp __ASM("sp");
  106. return sp;
  107. }
  108. #elif defined ( __TASKING__ )
  109. #ifndef __ASM
  110. #define __ASM __asm
  111. #endif
  112. #ifndef __INLINE
  113. #define __INLINE inline
  114. #endif
  115. #ifndef __WEAK
  116. #define __WEAK __attribute__((weak))
  117. #endif
  118. #ifndef __ALIGN
  119. #define __ALIGN(n) __align(n)
  120. #endif
  121. /* Not defined for TASKING. */
  122. #ifndef __PACKED
  123. #define __PACKED
  124. #endif
  125. #define GET_SP() __get_MSP()
  126. #endif
  127. /*lint --flb "Leave library region" */
  128. #endif