Skip to content

[kernel]add api rt_hw_interrupt_is_disabled #7706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bsp/stm32/stm32f103-dofly-lyc8/rtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
LPATH = ''

if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2 -g'
CFLAGS += ' -O2 -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
Expand Down
9 changes: 9 additions & 0 deletions include/rtdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,29 @@ while (0)
* 1) the scheduler has been started.
* 2) not in interrupt context.
* 3) scheduler is not locked.
* 4) interrupt is not disabled.
*/
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
do \
{ \
if (need_check) \
{ \
rt_bool_t interrupt_disabled; \
rt_base_t level; \
interrupt_disabled = rt_hw_interrupt_is_disabled(); \
level = rt_hw_interrupt_disable(); \
if (rt_critical_level() != 0) \
{ \
rt_kprintf("Function[%s]: scheduler is not available\n", \
__FUNCTION__); \
RT_ASSERT(0) \
} \
if (interrupt_disabled == RT_TRUE) \
{ \
rt_kprintf("Function[%s]: interrupt is disabled\n", \
__FUNCTION__); \
RT_ASSERT(0) \
} \
RT_DEBUG_IN_THREAD_CONTEXT; \
rt_hw_interrupt_enable(level); \
} \
Expand Down
2 changes: 1 addition & 1 deletion include/rthw.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ void rt_hw_local_irq_enable(rt_base_t level);

#define rt_hw_interrupt_disable rt_cpus_lock
#define rt_hw_interrupt_enable rt_cpus_unlock

#else
rt_base_t rt_hw_interrupt_disable(void);
void rt_hw_interrupt_enable(rt_base_t level);
#endif /*RT_USING_SMP*/
rt_bool_t rt_hw_interrupt_is_disabled(void);

/*
* Context interfaces
Expand Down
6 changes: 3 additions & 3 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)

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

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(sem->value == 0 && timeout != 0);

/* disable interrupt */
level = rt_hw_interrupt_disable();

Expand Down Expand Up @@ -532,9 +535,6 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
}
else
{
/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);

/* semaphore is unavailable, push to suspend list */
/* get current thread */
thread = rt_thread_self();
Expand Down
5 changes: 5 additions & 0 deletions src/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,10 @@ RTM_EXPORT(rt_interrupt_get_nest);
RTM_EXPORT(rt_hw_interrupt_disable);
RTM_EXPORT(rt_hw_interrupt_enable);

rt_weak rt_bool_t rt_hw_interrupt_is_disabled(void)
{
return RT_FALSE;
}
RTM_EXPORT(rt_hw_interrupt_is_disabled);
/**@}*/