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