{"id":422,"date":"2023-06-28T12:16:48","date_gmt":"2023-06-28T12:16:48","guid":{"rendered":"http:\/\/localhost\/embeddedwala\/?p=422"},"modified":"2023-07-27T04:12:50","modified_gmt":"2023-07-27T04:12:50","slug":"how-interrupt-works","status":"publish","type":"post","link":"https:\/\/embeddedwala.com\/beta\/blogs\/digital-communication\/how-interrupt-works\/","title":{"rendered":"How Interrupt Works ?"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"422\" class=\"elementor elementor-422\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t\t\t\t<section data-particle_enable=\"false\" data-particle-mobile-disabled=\"false\" class=\"elementor-section elementor-top-section elementor-element elementor-element-fc7142c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fc7142c\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a45e999\" data-id=\"a45e999\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<section data-particle_enable=\"false\" data-particle-mobile-disabled=\"false\" class=\"elementor-section elementor-inner-section elementor-element elementor-element-5a9fc94 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5a9fc94\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-444b006\" data-id=\"444b006\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a8c3c1c elementor-widget elementor-widget-text-editor\" data-id=\"a8c3c1c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>In an\u00a0<strong>Embedded System<\/strong>, a Microcontroller or Microprocessor uses the Input\/Output pins to interact with the outer world and the other devices. Output pins take the data or information out and input pins to read the data or information. Software on the\u00a0<strong>microprocessor<\/strong>\u00a0runs at a very high speed than the hardware interactions. A few milliseconds of delay with the hardware could be thousands of instructions for the software. So for optimal hardware and software interaction, there is a mechanism called\u00a0<strong>interrupts<\/strong>.\u00a0<\/p><p>An interrupt is a hardware signal to the\u00a0<strong>CPU<\/strong>, which can pause the program subroutine execution of the CPU and executes another subroutine called ISR (interrupt subroutine). ISR function call is asynchronous means execution of the function will be dependent upon the Interrupt triggering. The location for this\u00a0<strong>ISR function<\/strong>\u00a0in most CPUs is given as an entry value as a function pointer in the<strong>\u00a0Interrupt Vector Table<\/strong>.<\/p><p>The CPU gets the indication of an interrupt trigger via the interrupt controller. Interrupt Controller Handles the interrupt hardware lines and translates the query to the CPU using the ISR instruction set. Based on the Instruction branch offset number CPU execute the function inside the interrupt vector table.<\/p><p>Some MCU also uses the Interrupt controller for multiplexing the multiple hardware signal to interface with the CPU. Interrupt controller also has multiple fixed and programable configurations depending on the Interrupt Controller IP type e.g.\u00a0<strong>NVIC (Nested Vectored Interrupt Controller)<\/strong>,\u00a0<strong>PMC (Programable interrupt Controllers, GIC (Generic Interrupt Controller)<\/strong>\u00a0etc.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-426 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/CPU-internal-bus-image.gif\" alt=\"\" width=\"1440\" height=\"810\" \/><\/p><p><strong>The Interrupt Operation can be divided into three parts as follows :<\/strong><\/p><ol><li>Configuration of an Interrupt<\/li><li>Hardware Event of an Interrupt<\/li><li>Execution of an Interrupt<\/li><\/ol><p><strong>1. Configuration of an Interrupt :<\/strong><\/p><p>An Interrupt signal has various triggering and handling configurations. An Interrupt trigger signal can be configured for digital IPs, e.g. SPI, I2C, Hardware timers etc. Interrupt typically have a sequence number and a sequence number is set for a particular IP configuration, each sequence can have ISR Function linked to it. A sequence number is called the sequence in the vector table input. e.g. (I2C0 has an interrupt sequence no 20, 21 and ISR for I2C0 transactions when Hardware Signal triggered for I2C0 TX done will be using the Sequence number 20 ISR and I2C0 RX done will be handled in the Sequence number 21 ISR.)<\/p><p>Interrupt configuration in code is done along with the initialization of IPs. It ensures that IP Initialization and interrupt configuration are at the same location, to ease the debugging of the code later.<\/p><p><strong>2. Hardware Event of an Interrupt :<\/strong><\/p><p>MCU internally has interrupt lines configured and connected to the IPs e.g. I2C or SPI. IPs directly share a hardware line connected to the interrupt controller. The IPs can be configured to give the trigger signal on the interrupt line, at the end or beginning of a transaction. The interrupt controller raises the system exception to the CPU. Depending upon the exception sequence CPU pauses the current ongoing program execution and starts the execution of the ISR function.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-427 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/Hardware-interupter-imag.png\" alt=\"\" width=\"1920\" height=\"1080\" \/><\/p><p><strong>3. Execution of an interrupt :<\/strong><\/p><p>Interrupt gives the possibility of having the two contexts in our program. First is the main sub-routine and the\u00a0<strong>ISR<\/strong>\u00a0Subroutine. The program stack stores the local variable and return address. When an interrupt is triggered current program stack and the return address information gets stored in a backup register or memory and the program counter (the next address for execution) points to the<strong>\u00a0ISR Function<\/strong>\u00a0address.<\/p><p>In an\u00a0<strong>ARM MCU<\/strong>, we have two stack pointers\u00a0<strong>MSP (Main Stack Pointer)<\/strong>\u00a0and\u00a0<strong>PSP (Process Stack Pointer)<\/strong>. When an interrupt is handled, the PC points to the MSP. The\u00a0<strong>PSP<\/strong>\u00a0points to the main sub-program.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>In an\u00a0Embedded System, a Microcontroller or Microprocessor uses the Input\/Output pins to interact with the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":423,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[108,97,99,106],"class_list":["post-422","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-digital-communication","tag-arm","tag-interrupt","tag-isr","tag-vector-table"],"acf":[],"views":373,"featured_image_urls":{"full":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"thumbnail":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",150,101,false],"medium":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",300,202,false],"medium_large":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"large":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"1536x1536":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"2048x2048":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"tp-image-grid":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"covernews-slider-full":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"covernews-slider-center":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"covernews-featured":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",520,350,false],"covernews-medium":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",505,340,false],"covernews-medium-square":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",371,250,false],"_nx_notification_thumb":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/How-Interrupt-Works.png",100,67,false]},"author_info":{"display_name":"embeddedwala","author_link":"https:\/\/embeddedwala.com\/beta\/author\/embeddedwala\/"},"category_info":"<a href=\"https:\/\/embeddedwala.com\/beta\/category\/blogs\/digital-communication\/\" rel=\"category tag\">Digital Communication<\/a>","tag_info":"Digital Communication","comment_count":"0","_links":{"self":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/comments?post=422"}],"version-history":[{"count":11,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/422\/revisions"}],"predecessor-version":[{"id":8860,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/422\/revisions\/8860"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/media\/423"}],"wp:attachment":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/media?parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/categories?post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/tags?post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}