Skip to content

Commit 8d2072d

Browse files
authored
[kernel]add api rt_hw_interrupt_is_disabled (#7706)
1 parent 74b1552 commit 8d2072d

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

bsp/stm32/stm32f103-dofly-lyc8/rtconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
LPATH = ''
5353

5454
if BUILD == 'debug':
55-
CFLAGS += ' -O0 -gdwarf-2 -g'
55+
CFLAGS += ' -O2 -gdwarf-2 -g'
5656
AFLAGS += ' -gdwarf-2'
5757
else:
5858
CFLAGS += ' -O2'

include/rtdebug.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,29 @@ while (0)
119119
* 1) the scheduler has been started.
120120
* 2) not in interrupt context.
121121
* 3) scheduler is not locked.
122+
* 4) interrupt is not disabled.
122123
*/
123124
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
124125
do \
125126
{ \
126127
if (need_check) \
127128
{ \
129+
rt_bool_t interrupt_disabled; \
128130
rt_base_t level; \
131+
interrupt_disabled = rt_hw_interrupt_is_disabled(); \
129132
level = rt_hw_interrupt_disable(); \
130133
if (rt_critical_level() != 0) \
131134
{ \
132135
rt_kprintf("Function[%s]: scheduler is not available\n", \
133136
__FUNCTION__); \
134137
RT_ASSERT(0) \
135138
} \
139+
if (interrupt_disabled == RT_TRUE) \
140+
{ \
141+
rt_kprintf("Function[%s]: interrupt is disabled\n", \
142+
__FUNCTION__); \
143+
RT_ASSERT(0) \
144+
} \
136145
RT_DEBUG_IN_THREAD_CONTEXT; \
137146
rt_hw_interrupt_enable(level); \
138147
} \

include/rthw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ void rt_hw_local_irq_enable(rt_base_t level);
126126

127127
#define rt_hw_interrupt_disable rt_cpus_lock
128128
#define rt_hw_interrupt_enable rt_cpus_unlock
129-
130129
#else
131130
rt_base_t rt_hw_interrupt_disable(void);
132131
void rt_hw_interrupt_enable(rt_base_t level);
133132
#endif /*RT_USING_SMP*/
133+
rt_bool_t rt_hw_interrupt_is_disabled(void);
134134

135135
/*
136136
* Context interfaces

src/ipc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
507507

508508
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(sem->parent.parent)));
509509

510+
/* current context checking */
511+
RT_DEBUG_SCHEDULER_AVAILABLE(sem->value == 0 && timeout != 0);
512+
510513
/* disable interrupt */
511514
level = rt_hw_interrupt_disable();
512515

@@ -534,9 +537,6 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
534537
}
535538
else
536539
{
537-
/* current context checking */
538-
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
539-
540540
/* semaphore is unavailable, push to suspend list */
541541
/* get current thread */
542542
thread = rt_thread_self();

src/irq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,10 @@ RTM_EXPORT(rt_interrupt_get_nest);
138138
RTM_EXPORT(rt_hw_interrupt_disable);
139139
RTM_EXPORT(rt_hw_interrupt_enable);
140140

141+
rt_weak rt_bool_t rt_hw_interrupt_is_disabled(void)
142+
{
143+
return RT_FALSE;
144+
}
145+
RTM_EXPORT(rt_hw_interrupt_is_disabled);
141146
/**@}*/
142147

0 commit comments

Comments
 (0)