InsaneCoder
InsaneCoder

Reputation: 8288

How can I use FIQ in linux to toggle GPIO on press of a button

This is just for educational purpose as I am trying to understand how I can register a FIQ handler, to make a button toggle a LED over GPIO.

I have a Raspi3B+ as development board. I have a push button connected to one of the GPIO and a led connected to another GPIO. I am running vanilla linux kernel 6.6. So far I have created a dummy kernel module, so that the push of a button triggers a normal interrupt and in the interrupt handler I toggle the led gpio. Now, instead of IRQ, I want to use FIQ. How can I do that?

I did lot of google and the answers are either incomplete or very old and in pieces. From this, this and this, I understood that following things are needed :

  1. I need to register a FIQ handler (which should be in assembly). This probably can be done by claim_fiq() and set_fiq_handler() functions of linux kernel. So my handler could look something like this :

     static void test_fiq_handler(void) { 
     asm volatile(".global fiq_start \
     fiq_start:");
    
     //code for GPIO toggle
    
     asm(".global fiq_end");
     asm("fiq_end:"); }
    

and then I can pass test_fiq_handler to set_fiq_handler(). This should register my FIQ handler with the kernel.

  1. Once, handler is registered I need to figure out a way to convert GPIO irq to FIQ, so that when button is pressed it generates FIQ, and not IRQ.

Please confirm on #1 and I am not sure how #2 can be done.

Note : I think we can ignore debouncing for now, because all I am planning to do in handler is to toggle led GPIO high, so it doesn't matter if handler ran once or more number of times. High is going to stay high.

EDIT

If there is an existing sample of code or blog post explaining this end to end that I couldn't discover yet, would be highly appreciated.

Upvotes: 0

Views: 29

Answers (0)

Related Questions