nrf_svc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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, except as embedded into a Nordic
  12. * Semiconductor ASA integrated circuit in a product or a software update for
  13. * such product, must reproduce the above copyright notice, this list of
  14. * conditions and the following disclaimer in the documentation and/or other
  15. * materials provided with the distribution.
  16. *
  17. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * 4. This software, with or without modification, must only be used with a
  22. * Nordic Semiconductor ASA integrated circuit.
  23. *
  24. * 5. Any software provided in binary form under this license must not be reverse
  25. * engineered, decompiled, modified and/or disassembled.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  28. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  36. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #ifndef NRF_SVC__
  39. #define NRF_SVC__
  40. #include "stdint.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /** @brief Supervisor call declaration.
  45. *
  46. * A call to a function marked with @ref SVCALL, will trigger a Supervisor Call (SVC) Exception.
  47. * The SVCs with SVC numbers 0x00-0x0F are forwared to the application. All other SVCs are handled by the SoftDevice.
  48. *
  49. * @param[in] number The SVC number to be used.
  50. * @param[in] return_type The return type of the SVC function.
  51. * @param[in] signature Function signature. The function can have at most four arguments.
  52. */
  53. #ifdef SVCALL_AS_NORMAL_FUNCTION
  54. #define SVCALL(number, return_type, signature) return_type signature
  55. #else
  56. #ifndef SVCALL
  57. #if defined (__CC_ARM)
  58. #define SVCALL(number, return_type, signature) return_type __svc(number) signature
  59. #elif defined (__GNUC__)
  60. #ifdef __cplusplus
  61. #define GCC_CAST_CPP (uint16_t)
  62. #else
  63. #define GCC_CAST_CPP
  64. #endif
  65. #define SVCALL(number, return_type, signature) \
  66. _Pragma("GCC diagnostic push") \
  67. _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
  68. _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
  69. __attribute__((naked)) \
  70. __attribute__((unused)) \
  71. static return_type signature \
  72. { \
  73. __asm( \
  74. "svc %0\n" \
  75. "bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \
  76. ); \
  77. } \
  78. _Pragma("GCC diagnostic pop")
  79. #elif defined (__ICCARM__)
  80. #define PRAGMA(x) _Pragma(#x)
  81. #define SVCALL(number, return_type, signature) \
  82. PRAGMA(swi_number = (number)) \
  83. __swi return_type signature;
  84. #else
  85. #define SVCALL(number, return_type, signature) return_type signature
  86. #endif
  87. #endif // SVCALL
  88. #endif // SVCALL_AS_NORMAL_FUNCTION
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif // NRF_SVC__