Skip to content
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

[p2] fixes INTERRUPTS_01_isisr_willpreempt_servicedirqn test #2486

Merged
merged 4 commits into from
Jul 21, 2022

Conversation

scott-brust
Copy link
Member

Problem

INTERRUPTS_01_isisr_willpreempt_servicedirqn test fails on P2 due to unimplemented HAL

Solution

Use an array to backup any overridden ISR handlers. When override is removed, restore the backup.

There are other parts of the HAL that are still unimplemented, namely HAL_Core_Restore_Interrupt() and the link_interrupt_vectors_location RAM table in general during HAL_Core_Config().

This PR is still a WIP to facilitate discussion on how to approach these problems.

Steps to Test

Run wiring/no_fixture, specifically INTERRUPTS_01_isisr_willpreempt_servicedirqn

Example App

Run wiring/no_fixture

References

Links to the Community, Docs, Other Issues, etc..


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@avtolstoy avtolstoy requested a review from XuGuohui July 21, 2022 06:04

if (handler == nullptr && (flags & HAL_INTERRUPT_DIRECT_FLAG_RESTORE)) {
// Restore
// HAL_Core_Restore_Interrupt(irqn);
uint32_t old_handler = hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit fragile in the fact that you can call this with handler=nullptr and HAL_INTERRUPT_DIRECT_FLAG_RESTORE when there is no backed-up handler and it will nuke the existing entry in VTOR. Consider a few approaches:

  1. Back up entire VTOR on first use if `!memcmp(hal_interrupts_handler_backup, 0, sizeof(hal_interrupts_handler_backup))
  2. Perhaps use some struct for backup instead and store the state along with backed-up ISR function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or considering use std::pair(irqn, handler) along with vector().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid using vector here due to dynamic allocations. VTOR size is known and negligible, so we can keep the whole thing preallocated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a valid use case to have a NULL interrupt handler? Can I just check if the backed up handler is not null, and only restore it if something has been saved?

@scott-brust scott-brust force-pushed the fix/sc-106749/interrupts branch from b0c7539 to 768b834 Compare July 21, 2022 17:52
@scott-brust scott-brust requested a review from avtolstoy July 21, 2022 17:52
isrs[IRQN_TO_IDX(irqn)] = (uint32_t)handler;
// If there is currently a handler backup: Return error
if (hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]) {
error = SYSTEM_ERROR_NOT_SUPPORTED;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might actually simplify the logic if I use goto to bail out rather than have to check for error conditions? I cant return here because I need to re-enable interrupts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CHECK_TRUE/CHECK_FALSE then, much better than goto, so:

CHECK_FALSE(hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)], SYSTEM_ERROR_ALREADY_EXISTS);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, those macros are handy. Unfortunately I need to re-enable interrupts before exiting. ill just do that and return SYSTEM_ERROR_ALREADY_EXISTS. I think thats cleaner than adding a return variable and checking it, etc.

@scott-brust scott-brust force-pushed the fix/sc-106749/interrupts branch 2 times, most recently from 0bc48ae to 1fdc5d2 Compare July 21, 2022 18:32
isrs[IRQN_TO_IDX(irqn)] = (uint32_t)handler;
// If there is currently a handler backup: Return error
if (hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]) {
error = SYSTEM_ERROR_NOT_SUPPORTED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CHECK_TRUE/CHECK_FALSE then, much better than goto, so:

CHECK_FALSE(hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)], SYSTEM_ERROR_ALREADY_EXISTS);

@scott-brust scott-brust force-pushed the fix/sc-106749/interrupts branch from 4f5cea4 to acfb1e1 Compare July 21, 2022 19:04
@scott-brust scott-brust merged commit 2693832 into develop Jul 21, 2022
@scott-brust scott-brust deleted the fix/sc-106749/interrupts branch July 21, 2022 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants