compiler_abstraction.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 ( __ICCARM__ )
  52. #ifndef __ASM
  53. #define __ASM __asm
  54. #endif
  55. #ifndef __INLINE
  56. #define __INLINE inline
  57. #endif
  58. #ifndef __WEAK
  59. #define __WEAK __weak
  60. #endif
  61. #ifndef __ALIGN
  62. #define STRING_PRAGMA(x) _Pragma(#x)
  63. #define __ALIGN(n) STRING_PRAGMA(data_alignment = n)
  64. #endif
  65. #ifndef __PACKED
  66. #define __PACKED __packed
  67. #endif
  68. #define GET_SP() __get_SP()
  69. #elif defined ( __GNUC__ )
  70. #ifndef __ASM
  71. #define __ASM __asm
  72. #endif
  73. #ifndef __INLINE
  74. #define __INLINE inline
  75. #endif
  76. #ifndef __WEAK
  77. #define __WEAK __attribute__((weak))
  78. #endif
  79. #ifndef __ALIGN
  80. #define __ALIGN(n) __attribute__((aligned(n)))
  81. #endif
  82. #ifndef __PACKED
  83. #define __PACKED __attribute__((packed))
  84. #endif
  85. #define GET_SP() gcc_current_sp()
  86. static inline unsigned int gcc_current_sp(void)
  87. {
  88. register unsigned sp __ASM("sp");
  89. return sp;
  90. }
  91. #elif defined ( __TASKING__ )
  92. #ifndef __ASM
  93. #define __ASM __asm
  94. #endif
  95. #ifndef __INLINE
  96. #define __INLINE inline
  97. #endif
  98. #ifndef __WEAK
  99. #define __WEAK __attribute__((weak))
  100. #endif
  101. #ifndef __ALIGN
  102. #define __ALIGN(n) __align(n)
  103. #endif
  104. /* Not defined for TASKING. */
  105. #ifndef __PACKED
  106. #define __PACKED
  107. #endif
  108. #define GET_SP() __get_MSP()
  109. #endif
  110. /*lint --flb "Leave library region" */
  111. #endif