]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/ThirdParty/XCC/Xtensa/xtensa_timer.h
Add Xtensa port
[freertos] / FreeRTOS / Source / portable / ThirdParty / XCC / Xtensa / xtensa_timer.h
1 /*******************************************************************************\r
2 // Copyright (c) 2003-2015 Cadence Design Systems, Inc.\r
3 //\r
4 // Permission is hereby granted, free of charge, to any person obtaining\r
5 // a copy of this software and associated documentation files (the\r
6 // "Software"), to deal in the Software without restriction, including\r
7 // without limitation the rights to use, copy, modify, merge, publish,\r
8 // distribute, sublicense, and/or sell copies of the Software, and to\r
9 // permit persons to whom the Software is furnished to do so, subject to\r
10 // the following conditions:\r
11 //\r
12 // The above copyright notice and this permission notice shall be included\r
13 // in all copies or substantial portions of the Software.\r
14 //\r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
18 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r
19 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
20 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
21 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 --------------------------------------------------------------------------------\r
23 \r
24         XTENSA INFORMATION FOR RTOS TICK TIMER AND CLOCK FREQUENCY\r
25 \r
26 This header contains definitions and macros for use primarily by Xtensa\r
27 RTOS assembly coded source files. It includes and uses the Xtensa hardware\r
28 abstraction layer (HAL) to deal with config specifics. It may also be\r
29 included in C source files.\r
30 \r
31 User may edit to modify timer selection and to specify clock frequency and\r
32 tick duration to match timer interrupt to the real-time tick duration.\r
33 \r
34 If the RTOS has no timer interrupt, then there is no tick timer and the\r
35 clock frequency is irrelevant, so all of these macros are left undefined\r
36 and the Xtensa core configuration need not have a timer.\r
37 \r
38 *******************************************************************************/\r
39 \r
40 #ifndef XTENSA_TIMER_H\r
41 #define XTENSA_TIMER_H\r
42 \r
43 #ifdef __ASSEMBLER__\r
44 #include    <xtensa/coreasm.h>\r
45 #endif\r
46 \r
47 #include    <xtensa/corebits.h>\r
48 #include    <xtensa/config/system.h>\r
49 \r
50 #include    "xtensa_rtos.h"     /* in case this wasn't included directly */\r
51 \r
52 #include    <FreeRTOSConfig.h>\r
53 \r
54 /*\r
55 Select timer to use for periodic tick, and determine its interrupt number \r
56 and priority. User may specify a timer by defining XT_TIMER_INDEX with -D,\r
57 in which case its validity is checked (it must exist in this core and must \r
58 not be on a high priority interrupt - an error will be reported in invalid).\r
59 Otherwise select the first low or medium priority interrupt timer available.\r
60 */\r
61 #if XCHAL_NUM_TIMERS == 0\r
62 \r
63   #error "This Xtensa configuration is unsupported, it has no timers."\r
64 \r
65 #else\r
66 \r
67 #ifndef XT_TIMER_INDEX\r
68   #if XCHAL_TIMER3_INTERRUPT != XTHAL_TIMER_UNCONFIGURED\r
69     #if XCHAL_INT_LEVEL(XCHAL_TIMER3_INTERRUPT) <= XCHAL_EXCM_LEVEL\r
70       #undef  XT_TIMER_INDEX\r
71       #define XT_TIMER_INDEX    3\r
72     #endif\r
73   #endif\r
74   #if XCHAL_TIMER2_INTERRUPT != XTHAL_TIMER_UNCONFIGURED\r
75     #if XCHAL_INT_LEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL\r
76       #undef  XT_TIMER_INDEX\r
77       #define XT_TIMER_INDEX    2\r
78     #endif\r
79   #endif\r
80   #if XCHAL_TIMER1_INTERRUPT != XTHAL_TIMER_UNCONFIGURED\r
81     #if XCHAL_INT_LEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL\r
82       #undef  XT_TIMER_INDEX\r
83       #define XT_TIMER_INDEX    1\r
84     #endif\r
85   #endif\r
86   #if XCHAL_TIMER0_INTERRUPT != XTHAL_TIMER_UNCONFIGURED\r
87     #if XCHAL_INT_LEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL\r
88       #undef  XT_TIMER_INDEX\r
89       #define XT_TIMER_INDEX    0\r
90     #endif\r
91   #endif\r
92 #endif\r
93 #ifndef XT_TIMER_INDEX\r
94   #error "There is no suitable timer in this Xtensa configuration."\r
95 #endif\r
96 \r
97 #define XT_CCOMPARE             (CCOMPARE + XT_TIMER_INDEX)\r
98 #define XT_TIMER_INTNUM         XCHAL_TIMER_INTERRUPT(XT_TIMER_INDEX)\r
99 #define XT_TIMER_INTPRI         XCHAL_INT_LEVEL(XT_TIMER_INTNUM)\r
100 #define XT_TIMER_INTEN          (1 << XT_TIMER_INTNUM)\r
101 \r
102 #if XT_TIMER_INTNUM == XTHAL_TIMER_UNCONFIGURED\r
103   #error "The timer selected by XT_TIMER_INDEX does not exist in this core."\r
104 #elif XT_TIMER_INTPRI > XCHAL_EXCM_LEVEL\r
105   #error "The timer interrupt cannot be high priority (use medium or low)."\r
106 #endif\r
107 \r
108 #endif /* XCHAL_NUM_TIMERS */\r
109 \r
110 /*\r
111 Set processor clock frequency, used to determine clock divisor for timer tick.\r
112 User should BE SURE TO ADJUST THIS for the Xtensa platform being used.\r
113 If using a supported board via the board-independent API defined in xtbsp.h,\r
114 this may be left undefined and frequency and tick divisor will be computed \r
115 and cached during run-time initialization.\r
116 \r
117 NOTE ON SIMULATOR:\r
118 Under the Xtensa instruction set simulator, the frequency can only be estimated \r
119 because it depends on the speed of the host and the version of the simulator.\r
120 Also because it runs much slower than hardware, it is not possible to achieve\r
121 real-time performance for most applications under the simulator. A frequency\r
122 too low does not allow enough time between timer interrupts, starving threads.\r
123 To obtain a more convenient but non-real-time tick duration on the simulator, \r
124 compile with xt-xcc option "-DXT_SIMULATOR".\r
125 Adjust this frequency to taste (it's not real-time anyway!).\r
126 */\r
127 #if defined(XT_SIMULATOR) && !defined(XT_CLOCK_FREQ)\r
128 #define XT_CLOCK_FREQ       configCPU_CLOCK_HZ\r
129 #endif\r
130 \r
131 #if !defined(XT_CLOCK_FREQ) && !defined(XT_BOARD)\r
132   #error "XT_CLOCK_FREQ must be defined for the target platform."\r
133 #endif\r
134 \r
135 /*\r
136 Default number of timer "ticks" per second (default 100 for 10ms tick).\r
137 RTOS may define this in its own way (if applicable) in xtensa_rtos.h.\r
138 User may redefine this to an optimal value for the application, either by\r
139 editing this here or in xtensa_rtos.h, or compiling with xt-xcc option\r
140 "-DXT_TICK_PER_SEC=<value>" where <value> is a suitable number.\r
141 */\r
142 #ifndef XT_TICK_PER_SEC\r
143 #define XT_TICK_PER_SEC    configTICK_RATE_HZ        /* 10 ms tick = 100 ticks per second */\r
144 #endif\r
145 \r
146 /*\r
147 Derivation of clock divisor for timer tick and interrupt (one per tick).\r
148 */\r
149 #ifdef XT_CLOCK_FREQ\r
150 #define XT_TICK_DIVISOR     (XT_CLOCK_FREQ / XT_TICK_PER_SEC)\r
151 #endif\r
152 \r
153 #ifndef __ASSEMBLER__\r
154 extern unsigned _xt_tick_divisor;\r
155 extern void     _xt_tick_divisor_init(void);\r
156 #endif\r
157 \r
158 #endif  /* XTENSA_TIMER_H */\r
159 \r