1 /******************************************************************************
2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3 * All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************/
18
19 /********************************************************************************************************
20 * @file plic.c
21 *
22 * @brief This is the source file for B91
23 *
24 * @author Driver Group
25 *
26 *******************************************************************************************************/
27 #include "plic.h"
28 unsigned char g_plic_preempt_en=0;
29
30 /**
31 * @brief This function serves to config plic when enter some function process such as flash.
32 * @param[in] preempt_en - 1 can disturb by interrupt, 0 can't disturb by interrupt.
33 * @param[in] threshold - interrupt threshold.when the interrupt priority> interrupt threshold,the function process will be disturb by interrupt.
34 * @return none
35 */
plic_enter_critical_sec(unsigned char preempt_en,unsigned char threshold)36 _attribute_ram_code_sec_noinline_ unsigned int plic_enter_critical_sec(unsigned char preempt_en ,unsigned char threshold)
37 {
38 unsigned int r;
39 if(g_plic_preempt_en&&preempt_en)
40 {
41 plic_set_threshold(threshold);
42 r=0;
43 }
44 else
45 {
46 r = core_interrupt_disable();
47 }
48 return r ;
49 }
50
51 /**
52 * @brief This function serves to config plic when exit some function process such as flash.
53 * @param[in] preempt_en - 1 can disturb by interrupt, 0 can disturb by interrupt.
54 * @param[in] r - the value of mie register to restore.
55 * @return none
56 */
plic_exit_critical_sec(unsigned char preempt_en,unsigned int r)57 _attribute_ram_code_sec_noinline_ void plic_exit_critical_sec(unsigned char preempt_en ,unsigned int r)
58 {
59 if (g_plic_preempt_en&&preempt_en)
60 {
61 plic_set_threshold(0);
62 }
63 else
64 {
65 core_restore_interrupt(r);
66 }
67 }
68
69