1;/***************************************************************************
2; * Copyright (c) 2024 Microsoft Corporation
3; *
4; * This program and the accompanying materials are made available under the
5; * terms of the MIT License which is available at
6; * https://opensource.org/licenses/MIT.
7; *
8; * SPDX-License-Identifier: MIT
9; **************************************************************************/
10;
11;
12;/**************************************************************************/
13;/**************************************************************************/
14;/**                                                                       */
15;/** ThreadX Component                                                     */
16;/**                                                                       */
17;/**   Thread                                                              */
18;/**                                                                       */
19;/**************************************************************************/
20;/**************************************************************************/
21;
22;
23;#define TX_SOURCE_CODE
24;
25;
26;/* Include necessary system files.  */
27;
28;#include "tx_api.h"
29;#include "tx_thread.h"
30;#include "tx_timer.h"
31;
32;
33#ifdef TX_ENABLE_FIQ_SUPPORT
34DISABLE_INTS    DEFINE  0xC0                    ; Disable IRQ & FIQ interrupts
35#else
36DISABLE_INTS    DEFINE  0x80                    ; Disable IRQ interrupts
37#endif
38MODE_MASK       DEFINE  0x1F                    ; Mode mask
39IRQ_MODE_BITS   DEFINE  0x12                    ; IRQ mode bits
40;
41;
42;/**************************************************************************/
43;/*                                                                        */
44;/*  FUNCTION                                               RELEASE        */
45;/*                                                                        */
46;/*    _tx_thread_irq_nesting_end                          ARM11/IAR       */
47;/*                                                            6.1         */
48;/*  AUTHOR                                                                */
49;/*                                                                        */
50;/*    William E. Lamie, Microsoft Corporation                             */
51;/*                                                                        */
52;/*  DESCRIPTION                                                           */
53;/*                                                                        */
54;/*    This function is called by the application from IRQ mode after      */
55;/*    _tx_thread_irq_nesting_start has been called and switches the IRQ   */
56;/*    processing from system mode back to IRQ mode prior to the ISR       */
57;/*    calling _tx_thread_context_restore.  Note that this function        */
58;/*    assumes the system stack pointer is in the same position after      */
59;/*    nesting start function was called.                                  */
60;/*                                                                        */
61;/*    This function assumes that the system mode stack pointer was setup  */
62;/*    during low-level initialization (tx_initialize_low_level.s79).      */
63;/*                                                                        */
64;/*    This function returns with IRQ interrupts disabled.                 */
65;/*                                                                        */
66;/*  INPUT                                                                 */
67;/*                                                                        */
68;/*    None                                                                */
69;/*                                                                        */
70;/*  OUTPUT                                                                */
71;/*                                                                        */
72;/*    None                                                                */
73;/*                                                                        */
74;/*  CALLS                                                                 */
75;/*                                                                        */
76;/*    None                                                                */
77;/*                                                                        */
78;/*  CALLED BY                                                             */
79;/*                                                                        */
80;/*    ISRs                                                                */
81;/*                                                                        */
82;/*  RELEASE HISTORY                                                       */
83;/*                                                                        */
84;/*    DATE              NAME                      DESCRIPTION             */
85;/*                                                                        */
86;/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
87;/*                                                                        */
88;/**************************************************************************/
89;VOID   _tx_thread_irq_nesting_end(VOID)
90;{
91    RSEG    .text:CODE:NOROOT(2)
92    PUBLIC  _tx_thread_irq_nesting_end
93    CODE32
94_tx_thread_irq_nesting_end
95    MOV     r3,lr                               ; Save ISR return address
96    MRS     r0, CPSR                            ; Pickup the CPSR
97    ORR     r0, r0, #DISABLE_INTS               ; Build disable interrupt value
98    MSR     CPSR_cxsf, r0                       ; Disable interrupts
99    LDR     lr, [sp]                            ; Pickup saved lr
100    ADD     sp, sp, #4                          ; Adjust stack pointer
101    BIC     r0, r0, #MODE_MASK                  ; Clear mode bits
102    ORR     r0, r0, #IRQ_MODE_BITS              ; Build IRQ mode CPSR
103    MSR     CPSR_cxsf, r0                       ; Re-enter IRQ mode
104    MOV     pc, r3                              ; Return to ISR
105;}
106;
107;
108    END
109
110