1 // intlevel-set.S - Interrupt related assembler code - _xtos_set_intlevel
3 // Copyright (c) 2004-2010 Tensilica Inc.
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <xtensa/coreasm.h>
25 #include <xtensa/config/specreg.h>
26 #include "xtos-internal.h"
29 /***************************************************************************
30 * unsigned _xtos_set_intlevel(int intlevel);
32 * _xtos_set_intlevel() is used to set the current priority from C code;
33 * it can be called from the application or from a C interrupt handler.
35 * NOTE: This version allows the 'intlevel' parameter to be computed
36 * at run-time, and thus is longer. It is much more efficient, and
37 * highly recommented, to use the XTOS_SET_INTLEVEL(intlevel) macro instead
38 * (which requires a constant intlevel).
43 .global _xtos_set_intlevel
44 .type _xtos_set_intlevel,@function
47 #if XCHAL_HAVE_INTERRUPTS
49 /* In XEA2, we can simply safely set PS.INTLEVEL directly: */
50 rsr a3, PS // get old (current) PS.INTLEVEL
52 extui a2, a2, 0, 4 // keep only INTLEVEL bits of parameter
53 and a4, a4, a3 // mask out PS.INTLEVEL
54 or a4, a4, a2 // insert requested INTLEVEL
55 wsr a4, PS // update PS.INTLEVEL
56 extui a2, a3, 0, 4 // return only old PS.INTLEVEL field
57 rsync // wait for WSR to PS to complete
59 /* In XEA1, we have to rely on INTENABLE register virtualization: */
60 movi a4, Xthal_intlevel_andbelow_mask
61 extui a3, a2, 0, 4 // keep only INTLEVEL bits of parameter
62 addx4 a5, a3, a4 // index mask to use
63 l32i a3, a5, 0 // get mask of interrupts at requested intlevel and below
64 movi a5, -1 // all 1's
65 movi a4, _xtos_intstruct
66 xor a3, a3, a5 // mask of interrupts at intlevels above the requested one (to enable)
67 xtos_lock a7 // MUST USE highest address register of function to avoid window overflows in critical section
68 l32i a2, a4, XTOS_VPRI_ENABLED_OFS // return old xtos_vpri_enabled (current vpri)
69 l32i a5, a4, XTOS_ENABLED_OFS // a5 = xtos_enabled
70 s32i a3, a4, XTOS_VPRI_ENABLED_OFS // set new xtos_vpri_enabled (current vpri)
71 and a5, a5, a3 // a5 = xtos_enabled & xtos_vpri_enabled
75 #endif /*XCHAL_HAVE_INTERRUPTS*/
78 .size _xtos_set_intlevel, . - _xtos_set_intlevel