About the use of tasklet_hrtimer_init in hardware interrupt callback function - timer

Comment of function tasklet_hrtimer_init:
Init a tasklet/hrtimer combo for softirq callbacks
There are few routines used in kernel about tasklet_hrtimer_init.
Can tasklet_hrtimer_init be used in the callback function of hardware interrupt?

Related

What is the use of callback function in peripheral driver?

I am reading a book on writing embedded system peripheral drivers and the author wrote a C callback function which i really don't understand and want to know the use of it, is it related to interrupts handling?
The function prototype is as following:
void Spi_CallbackRegister(SpiCallback_t Function, TYPE (*CallbackFunction)(type));
Short Answer: Callback function are function pointers with which you invoke them, when a specific event occurs.
Let us say you have an IO device like ethernet (MAC) device. Driver for such device will always be waiting for an events to occur, these events are either hardware or software interrupts, example:
A new packet has arrived.
A packet is going to dispatch.
Initiate packet transfer from device FIFO to host memory (DMA).
A protocol state has changed/etc.
To handle various interrupt(s) type you need a specific function for each of them, these functions are called Interrupt Service Routine(ISR) or Interrupt handler or a callback function. When an event is mapped to a function, it stores its pointer and thats why the term callback the function.

How to work kernel irq thread in kernel Linux?

I have seen in mmc driver the function devm_request_threaded_irq used to launch sdhci_msm_pwr_irq like following :
ret = devm_request_threaded_irq(&pdev->dev, msm_host->pwr_irq, NULL,
sdhci_msm_pwr_irq, IRQF_ONESHOT,
dev_name(&pdev->dev), host);
But when I call rmmod I have not seen an release or stop of this irq thread. Can you explain me how this thread works ?
Removal of the sdhci-msm module results in the module's module_exit handler function being called, which will call platform_device_unregister to unregister itself as a platform device driver. (Most of that is hidden by the macro call module_platform_driver(sdhci_msm_driver); in "drivers/mmc/host/sdhci-msm.c".)
When the platform driver is unregistered, all devices that were successfully probed will be removed automatically. The driver's "remove" handler sdhci_msm_remove will be called automatically for each successfully probed device.
So you may be wondering why sdhci_msm_remove doesn't free the interrupt allocated by the devm_request_threaded_irq call in the "probe" function sdhci_msm_probe? The answer is that it doesn't need to because the interrupt was allocated as a "managed device resource" (see below).
devm_request_threaded_irq is a "device resource managed" ("devres") wrapper around the request_threaded_irq function. Any devres-managed resources get cleaned up automatically when the probed device is being removed. (The clean-up of devres-managed resources happens after the "remove" handler returns.) For devres-managed interrupt resources, the clean-up results in the free_irq function being called automatically to free the interrupt.

What is the difference between using "EXTI_IRQHandler" and "EXTI_Callback"?

I am using HAL library for my project with STM32 microcontroller.
In the sample code provided by STM, they use HAL_GPIO_EXTI_Callback for a push button interrupt. However, I learned in class that we need to use the IRQHandler to handle the interrupt.
So my question is when we use HAL_GPIO_EXTI_Callback and HAL_GPIO_EXTI_IRQHandler to handle interrupt?
In ST's example projects, there are several function calls for a single interrupt:
the interrupt handler itself is called EXTI15_10_Handler. It is the function whose address is specified in the vector table. It is the generic handler for the interrupt line EXTI15_10 and by default it is "routed" to a default function doing nothing. As it is a weak symbol you can redefine it as you want.
if you are using EXTI15_10 interrupt line with standard GPIOs, EXTI15_10_Handler should call HAL_GPIO_EXTI_IRQHandler. This is a function provided by the HAL.
the latter function is clearing the IT flag and then calls HAL_GPIO_EXTI_Callback, which is also a weak function that is doing nothing by default. This is the function that you need to implement to process your GPIO.

Is there a difference between an ISR and an interrupt handler?

I'm studying operating systems and I encountered both the terms ISR and interrupt handler. Are they two words for the same mechanism? If not, what is the difference?
There is no difference in Interrupt handler and ISR.
Wiki says that:
In computer systems programming, an interrupt handler, also known as an interrupt service routine or ISR, is a callback function [...]
ISR is callback for a specific service pertaining to a device/operation/source. There could be multiple ISRs present in a system depending on addresses available in Interrupt Vector table. Where is Interrupt handler is a common routine which is triggered whenever any interrupt comes. Its job is to understand the source of the interrupt and trigger appropriate ISR mapped in Interrupt Vector table.
When interrupt occurs,
interrupt handler performs minimal operations required to respond to the device where as updating the buffer and all other operations are taken care by ISR

interrupt handling by C code

I am trying to disable interrupts through C code but stuck at request_irq(). One argument to request_irq() is flag and SA_INTERRUPT flag is now deprecated. Can anyone tell me alternative to SA_INTERRUPT?. I am using kernel version 3.8.
Any other alternative to request_irq() for disabling interrupts?
request_irq() does not "disable" an interrupt. It is called by a driver that wants to attach an interrupt service routine to an IRQ. The flag is IRQF_SHARED if the interrupt is shared or 0 otherwise.
Here is an example from a driver for Realtek 8169 PCIe network adapter: http://lxr.free-electrons.com/source/drivers/net/ethernet/realtek/r8169.c
retval = request_irq(pdev->irq, rtl8169_interrupt,
(tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
dev->name, dev);
In the example above, rtl8169_interrupt is the interrupt service routine (ISR) that will be invoked each time an IRQ is raised.
It is the job of the ISR to find out if the interrupt was indeed fired by the "owned" device (relevant for shared interrupts) then if the device indeed fired the interrupt, the ISR reads interrupt status then clears the interrupt.

Resources