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

Interrupt Hooks #202

Open
BlakeFreer opened this issue Oct 2, 2024 · 0 comments
Open

Interrupt Hooks #202

BlakeFreer opened this issue Oct 2, 2024 · 0 comments
Assignees

Comments

@BlakeFreer
Copy link
Contributor

BlakeFreer commented Oct 2, 2024

Interrupt Hooks

Number of members: 1

Relevant skills: C++, microcontroller interrupts

Timeline: Mid November

Description

Current State

We do not use interrupts in our code, but they are necessary for features like Direct Memory Access and efficient communication message buffering.

Our entire firmware architecture has a top-down function call model: the app level calls functions in the platform level. Interrupts are fundamentally different as they are platform hardware events triggering an app-level response.

Desired State

A cross platform mechanism for calling app level functions from the platform layer's interrupt handlers.

  • Linux C uses signal() to register functions as interrupt handlers and kill() to trigger those interrupts.
  • STM32 devices have Interrupt Handler functions which can be overridden to execute the app level function.

Your solution must connect the app-level function to either platform's interrupt handler.

I am not sure exactly what this will look like, but it likely will involve adding the app function to bindings.h and calling it in the platforms' bindings.cc file within an interrupt handler.

/***** bindings.h *****/
void AppLevelFunction(void);

/***** main.cc *****/
#include "bindings.h"

void AppLevelFunction(void) {
    do_stuff_on_interrupt();
}

/***** platforms/linux/bindings.cc *****/
#include "bindings.h"

signal(INTERRUPT_NUMBER, &AppLevelFunction)l

/***** platforms/stm32f767/bindings.cc *****/
#include "bindings.h"

void HAL_InterruptHandler(void) { // there is one of these for every interrupt
    AppLevelFunction();
}

Tasks

1. Understand the existing project structure (few hours)

See these two articles

  1. https://macformula.github.io/racecar/firmware/architecture/
  2. https://macformula.github.io/racecar/firmware/project-structure/

2. Research (~1 week)

Are there any existing methods for cross-platform interrupt handling? Document any findings in a Markdown document for https://macformula.github.io/racecar/

3. Prototype (~4 weeks)

Make branch in racecar/ and start a new project (see instruction article above). Get interrupts working for that project. Start with the cli / linux platform since you can run it locally. Once that is working, implement it for STM32f767.

4. Merge to main

Make a PR with your demo project from step 3. Include a README in the project explaining how it works, and add to the docs/docs documentation to add your findings to our website.

Open Questions

Is there a "clean" way to guarantee (at compile time) that the bindings.cc file has included the app-level function in an interrupt handler?

  • This might be possible by defining an "InterruptHandler" peripheral class which accepts a function pointer in its constructor. This would be a cool solution, but IDK if it will work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Selected for Development
Development

No branches or pull requests

2 participants