nrf_svc.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
  16. * contributors to this software may be used to endorse or promote products
  17. * derived from this software without specific prior written permission.
  18. *
  19. * 4. This software must only be used in a processor manufactured by Nordic
  20. * Semiconductor ASA, or in a processor manufactured by a third party that
  21. * is used in combination with a processor manufactured by Nordic Semiconductor.
  22. *
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #ifndef NRF_SVC__
  37. #define NRF_SVC__
  38. #include "stdint.h"
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #ifdef SVCALL_AS_NORMAL_FUNCTION
  43. #define SVCALL(number, return_type, signature) return_type signature
  44. #else
  45. #ifndef SVCALL
  46. #if defined (__CC_ARM)
  47. #define SVCALL(number, return_type, signature) return_type __svc(number) signature
  48. #elif defined (__GNUC__)
  49. #ifdef __cplusplus
  50. #define GCC_CAST_CPP (uint8_t)
  51. #else
  52. #define GCC_CAST_CPP
  53. #endif
  54. #define SVCALL(number, return_type, signature) \
  55. _Pragma("GCC diagnostic push") \
  56. _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
  57. __attribute__((naked)) \
  58. __attribute__((unused)) \
  59. static return_type signature \
  60. { \
  61. __asm( \
  62. "svc %0\n" \
  63. "bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \
  64. ); \
  65. } \
  66. _Pragma("GCC diagnostic pop")
  67. #elif defined (__ICCARM__)
  68. #define PRAGMA(x) _Pragma(#x)
  69. #define SVCALL(number, return_type, signature) \
  70. PRAGMA(swi_number = (number)) \
  71. __swi return_type signature;
  72. #else
  73. #define SVCALL(number, return_type, signature) return_type signature
  74. #endif
  75. #endif // SVCALL
  76. #endif // SVCALL_AS_NORMAL_FUNCTION
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif // NRF_SVC__