This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
stm32f4 IRQ manager correct static members initialization #17
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <platform/irq_manager.hpp> | ||
#include <new> | ||
|
||
IRQ_manager::handler_storage IRQ_manager::m_storage[CONFIG_IRQ_COUNT]; | ||
|
||
|
||
void IRQ_manager::init() | ||
{ | ||
// Initialize storage | ||
for (auto &h : m_storage) { | ||
new (&h) handler_type{default_handler}; | ||
} | ||
|
||
__enable_irq(); | ||
} | ||
|
||
int IRQ_manager::subscribe(IRQn_t irqn, const std::function< void() > &handler) | ||
{ | ||
// TODO: Use platform assert when it will be ready | ||
if (irqn < 0) { | ||
return -1; | ||
} | ||
|
||
auto handlers = extract_handlers(); | ||
|
||
__disable_irq(); | ||
|
||
// Magic here. | ||
// Logical priority of *any* user interrupt that use | ||
// FreeRTOS API must not be greather than | ||
// configMAX_SYSCALL_INTERRUPT_PRIORITY | ||
NVIC_SetPriority(irqn, CONFIG_MAX_ISR_PRIORITY); | ||
handlers[irqn] = handler; | ||
__enable_irq(); | ||
return 0; | ||
} | ||
|
||
int IRQ_manager::unsubscribe(IRQn_t irqn) | ||
{ | ||
// TODO: Use platform assert when it will be ready | ||
if (irqn < 0) { | ||
return -1; | ||
} | ||
|
||
auto handlers = extract_handlers(); | ||
__disable_irq(); | ||
handlers[irqn] = default_handler; | ||
__enable_irq(); | ||
return 0; | ||
} | ||
|
||
int IRQ_manager::mask(IRQn_t irqn) | ||
{ | ||
// TODO: Use platform assert when it will be ready | ||
if (irqn < 0) { | ||
return -1; | ||
} | ||
|
||
NVIC_DisableIRQ(irqn); | ||
return 0; | ||
} | ||
|
||
int IRQ_manager::unmask(IRQn_t irqn) | ||
{ | ||
// TODO: Use platform assert when it will be ready | ||
if (irqn < 0) { | ||
return -1; | ||
} | ||
|
||
// TODO: error check | ||
NVIC_EnableIRQ(irqn); | ||
return 0; | ||
} | ||
|
||
int IRQ_manager::clear(IRQn_t irqn) | ||
{ | ||
// TODO: Use platform assert when it will be ready | ||
if (irqn < 0) { | ||
return -1; | ||
} | ||
|
||
// TODO: error check | ||
NVIC_ClearPendingIRQ(static_cast< IRQn_t > (irqn)); | ||
return 0; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
|
||
void IRQ_manager::isr() | ||
{ | ||
volatile int irqn; | ||
auto handlers = extract_handlers(); | ||
|
||
asm volatile ( | ||
"mrs %0, ipsr" : "=r" (irqn) | ||
); | ||
|
||
// IPSR holds exception numbers starting from 0 | ||
// Valid IRQ number starts from -15 | ||
// See Cortex-M4 processors documentation | ||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDBIBGJ.html | ||
irqn -= 16; | ||
|
||
// TODO: Is it needed? | ||
mask(static_cast< IRQn_t >(irqn)); | ||
handlers[irqn](); | ||
} | ||
|
||
void IRQ_manager::default_handler() | ||
{ | ||
__disable_irq(); | ||
for(;;); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
irqn can be negative (as IRQn_t defined in stm32f4xx.h). Would be nice to add a check at least.
Does this also mean that I can't set a custom handler for first 15 interrupts (say UsageFault_IRQn) ?
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.
IRQ manager in current implementation doesn't support handling of system exceptions. To subscribe for exception events one may override handlers at compile time via the weak symbol mechanism.