-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat(cortex-m4): 重定向 rt_interrupt_get_nest() 函数优化获取实现 #10614
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ | |||||||||||||||||||||||||||||||||
* 2018-07-24 aozima enhancement hard fault exception handler. | ||||||||||||||||||||||||||||||||||
* 2019-07-03 yangjie add __rt_ffs() for armclang. | ||||||||||||||||||||||||||||||||||
* 2022-06-12 jonas fixed __rt_ffs() for armclang. | ||||||||||||||||||||||||||||||||||
* 2025-08-18 wdfk_prog add rt_interrupt_get_nest() and __get_IPSR() support. | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#include <rtthread.h> | ||||||||||||||||||||||||||||||||||
|
@@ -436,6 +437,42 @@ void rt_hw_cpu_reset(void) | |||||||||||||||||||||||||||||||||
SCB_AIRCR = SCB_RESET_VALUE; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||
\brief Get IPSR Register | ||||||||||||||||||||||||||||||||||
\details Returns the content of the IPSR Register. | ||||||||||||||||||||||||||||||||||
\return IPSR Register value | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
rt_inline rt_uint32_t __get_IPSR(void) | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
#if defined(__CC_ARM) | ||||||||||||||||||||||||||||||||||
register uint32_t __regIPSR __asm("ipsr"); | ||||||||||||||||||||||||||||||||||
return(__regIPSR); | ||||||||||||||||||||||||||||||||||
#elif defined(__clang__) | ||||||||||||||||||||||||||||||||||
uint32_t result; | ||||||||||||||||||||||||||||||||||
__asm volatile ("MRS %0, ipsr" : "=r" (result) ); | ||||||||||||||||||||||||||||||||||
return(result); | ||||||||||||||||||||||||||||||||||
#elif defined(__IAR_SYSTEMS_ICC__) | ||||||||||||||||||||||||||||||||||
return __iar_builtin_rsr("IPSR"); | ||||||||||||||||||||||||||||||||||
#elif defined ( __GNUC__ ) | ||||||||||||||||||||||||||||||||||
uint32_t result; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||
__asm volatile ("MRS %0, ipsr" : "=r" (result) ); | ||||||||||||||||||||||||||||||||||
return(result); | ||||||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||
* @brief This function will return the nest of interrupt. | ||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||
* User application can invoke this function to get whether current | ||||||||||||||||||||||||||||||||||
* context is interrupt context. | ||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||
* @return the number of nested interrupts. | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
rt_uint8_t rt_interrupt_get_nest(void) | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
return (__get_IPSR() != 0); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function return type is Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wdfk-prog 这块应该返回__get_IPSR()的数值? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
![]()
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rt_interrupt_get_nest 这种用法可能更好一些 我看到ut里面有类似使用 rt_interrupt_get_nest 的代码:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#ifdef RT_USING_CPU_FFS | ||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||
* This function finds the first bit set (beginning with the least significant bit) | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
rt_uint32_t
instead ofuint32_t
to maintain consistency with RT-Thread's type naming conventions used elsewhere in the codebase.Copilot uses AI. Check for mistakes.