Interrupts in baremetal:
void ISR_UART1(void) {
task_a();
task_b();
task_c();
}
void ISR_ADC1(void) {
task_1();
task_2();
task_3();
}
void ISR_ADC2(void) {
task_10();
task_20();
task_30();
}
Interrupt vector table
SrNo | Address | Callback function |
1 | 0x00000000 | RESET |
2 | 0x00000014 | ISR_UART1 |
3 | 0x00000018 | ISR_ADC1 |
4 | 0x0000001C | ISR_ADC2 |
Here, ISR_UART1(), ISR_ADC1(), ISR_ADC2() are callback functions. They are getting called whenever and Interrupt occurred. When Interrupt occurs, the Program counter is filled with address from above vector table as per the interrupt type. Next step, it interprets the value at this location as function pointer and goes to particular location as mentioned by user.
After RESET, the program counter(PC) gets the next value as per the BOOT pin configuration. So after the Reset, the PC can get value which can be address of start location of FLASH/SRAM/Bootloader etc. as per the MCU specification.
Considering it enters the usercode, the startup code starts executing which is even before main(). Here the STACK, HEAP and instructions to fill vector table with appropriate callback function pointers is done. So the Stack pointer is initialized, Heap pointer is also initialized.
Once this process is done, the program counter is directed to main()
Conclusion: Interrupt service routines are actually callback functions whose address is passed to interrupt vector table. They get called back whenever interrupt occurs.
No comments:
Post a Comment