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/* #define TX_SOURCE_CODE  */
23
24
25/* Include necessary system files.  */
26
27/*  #include "tx_api.h"
28    #include "tx_thread.h"  */
29
30RETURN_MASK     DEFINE          0x0000000F
31SET_SR_MASK     DEFINE          0xFFFFFFF0
32
33    SECTION `.text`:CODE:REORDER:NOROOT(2)
34    CODE
35/**************************************************************************/
36/*                                                                        */
37/*  FUNCTION                                               RELEASE        */
38/*                                                                        */
39/*    _tx_thread_interrupt_control                       RISC-V32/IAR     */
40/*                                                           6.1          */
41/*  AUTHOR                                                                */
42/*                                                                        */
43/*    William E. Lamie, Microsoft Corporation                             */
44/*    Tom van Leeuwen, Technolution B.V.                                  */
45/*                                                                        */
46/*  DESCRIPTION                                                           */
47/*                                                                        */
48/*    This function is responsible for changing the interrupt lockout     */
49/*    posture of the system.                                              */
50/*                                                                        */
51/*  INPUT                                                                 */
52/*                                                                        */
53/*    new_posture                           New interrupt lockout posture */
54/*                                                                        */
55/*  OUTPUT                                                                */
56/*                                                                        */
57/*    old_posture                           Old interrupt lockout posture */
58/*                                                                        */
59/*  CALLS                                                                 */
60/*                                                                        */
61/*    None                                                                */
62/*                                                                        */
63/*  CALLED BY                                                             */
64/*                                                                        */
65/*    Application Code                                                    */
66/*                                                                        */
67/*  RELEASE HISTORY                                                       */
68/*                                                                        */
69/*    DATE              NAME                      DESCRIPTION             */
70/*                                                                        */
71/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
72/*                                                                        */
73/**************************************************************************/
74/* UINT   _tx_thread_interrupt_control(UINT new_posture)
75{  */
76    PUBLIC  _tx_thread_interrupt_control
77_tx_thread_interrupt_control:
78    /* Pickup current interrupt lockout posture.  */
79
80    csrr    t0, mstatus
81    mv      t1, t0                                      ; Save original mstatus for return
82
83    /* Apply the new interrupt posture.  */
84
85    li      t2, SET_SR_MASK                             ; Build set SR mask
86    and     t0, t0, t2                                  ; Isolate interrupt lockout bits
87    or      t0, t0, a0                                  ; Put new lockout bits in
88    csrw    mstatus, t0
89    andi    a0, t1, RETURN_MASK                         ; Return original mstatus.
90    ret
91/* }  */
92    END
93