xtensa_api.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2019 Cadence Design Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
  7. */
  8. /*******************************************************************************
  9. Copyright (c) 2006-2015 Cadence Design Systems Inc.
  10. Permission is hereby granted, free of charge, to any person obtaining
  11. a copy of this software and associated documentation files (the
  12. "Software"), to deal in the Software without restriction, including
  13. without limitation the rights to use, copy, modify, merge, publish,
  14. distribute, sublicense, and/or sell copies of the Software, and to
  15. permit persons to whom the Software is furnished to do so, subject to
  16. the following conditions:
  17. The above copyright notice and this permission notice shall be included
  18. in all copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  22. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. ******************************************************************************/
  27. /******************************************************************************
  28. Xtensa-specific API for RTOS ports.
  29. ******************************************************************************/
  30. #ifndef __XTENSA_API_H__
  31. #define __XTENSA_API_H__
  32. #include <stdbool.h>
  33. #include <xtensa/hal.h>
  34. #include "xtensa_context.h"
  35. /* Typedef for C-callable interrupt handler function */
  36. typedef void (*xt_handler)(void *);
  37. /* Typedef for C-callable exception handler function */
  38. typedef void (*xt_exc_handler)(XtExcFrame *);
  39. /*
  40. -------------------------------------------------------------------------------
  41. Call this function to set a handler for the specified exception. The handler
  42. will be installed on the core that calls this function.
  43. n - Exception number (type)
  44. f - Handler function address, NULL to uninstall handler.
  45. The handler will be passed a pointer to the exception frame, which is created
  46. on the stack of the thread that caused the exception.
  47. If the handler returns, the thread context will be restored and the faulting
  48. instruction will be retried. Any values in the exception frame that are
  49. modified by the handler will be restored as part of the context. For details
  50. of the exception frame structure see xtensa_context.h.
  51. -------------------------------------------------------------------------------
  52. */
  53. extern xt_exc_handler xt_set_exception_handler(int n, xt_exc_handler f);
  54. /*
  55. -------------------------------------------------------------------------------
  56. Call this function to set a handler for the specified interrupt. The handler
  57. will be installed on the core that calls this function.
  58. n - Interrupt number.
  59. f - Handler function address, NULL to uninstall handler.
  60. arg - Argument to be passed to handler.
  61. -------------------------------------------------------------------------------
  62. */
  63. extern xt_handler xt_set_interrupt_handler(int n, xt_handler f, void * arg);
  64. /*
  65. -------------------------------------------------------------------------------
  66. Call this function to enable the specified interrupts on the core that runs
  67. this code.
  68. mask - Bit mask of interrupts to be enabled.
  69. -------------------------------------------------------------------------------
  70. */
  71. extern void xt_ints_on(unsigned int mask);
  72. /*
  73. -------------------------------------------------------------------------------
  74. Call this function to disable the specified interrupts on the core that runs
  75. this code.
  76. mask - Bit mask of interrupts to be disabled.
  77. -------------------------------------------------------------------------------
  78. */
  79. extern void xt_ints_off(unsigned int mask);
  80. /*
  81. -------------------------------------------------------------------------------
  82. Call this function to set the specified (s/w) interrupt.
  83. -------------------------------------------------------------------------------
  84. */
  85. static inline void xt_set_intset(unsigned int arg)
  86. {
  87. xthal_set_intset(arg);
  88. }
  89. /*
  90. -------------------------------------------------------------------------------
  91. Call this function to clear the specified (s/w or edge-triggered)
  92. interrupt.
  93. -------------------------------------------------------------------------------
  94. */
  95. static inline void xt_set_intclear(unsigned int arg)
  96. {
  97. xthal_set_intclear(arg);
  98. }
  99. /*
  100. -------------------------------------------------------------------------------
  101. Call this function to get handler's argument for the specified interrupt.
  102. n - Interrupt number.
  103. -------------------------------------------------------------------------------
  104. */
  105. extern void * xt_get_interrupt_handler_arg(int n);
  106. /*
  107. -------------------------------------------------------------------------------
  108. Call this function to check if the specified interrupt is free to use.
  109. intr - Interrupt number.
  110. cpu - cpu number.
  111. -------------------------------------------------------------------------------
  112. */
  113. bool xt_int_has_handler(int intr, int cpu);
  114. #endif /* __XTENSA_API_H__ */