Thread: What exactly is an interupt?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132

    What exactly is an interupt?

    What exactly is an interrupt (for example hardware interrupt or software interrupt). Hear me out. Most sources define an interrupt as when a device sends a signal to the CPU telling it what to do. 1)Anything connected to the computer sends a signal 2)the CPU is always being told what to do. That's what a program is.

    So I find the definition basically says nothing.
    Last edited by c_weed; 09-30-2014 at 01:49 AM. Reason: added links

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    A hardware interrupt sequence stops the currently running program and invokes something similar to a call to an interrupt function. A software interrupt is similar to a call being made by the currently running program to call an interrupt function. The details vary depending on the processor. For X86 architecture, there's an array of addresses to handle both hardware and software invoked interrupts. With the early Intel processors, the interrupt handler chip actually emitted two instruction bytes, the first was an interrupt opcode, followed by a single byte value. Later processors ignored the first instruction byte, but had to perform the handshake with the interrupt controller chip which still emitted the interrupt opcode. Current processors just deal with the byte value. IBM mainframes have an array of program control words in low memory in pairs. One of the control words is used to save the current state, and the other control word is used to set the new state (which includes an address). ARM processors switch states from the current state to interrupt or fast interrupt state, which includes some dedicated "shadow" registers.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Many microprocessors have specialized pins that are used trigger a hardware interrupt being generated by "external" hardware, disk drives for example. A software interrupt is generated by software by writing values to addresses designated by the operating system or processor.

    You may find this link interesting.


    Jim
    Last edited by jimblumberg; 09-30-2014 at 06:10 AM.

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    An interrupt is a seporate bit of program that will execute when a condition is met.

    For PIC microprocessors there are lots of different interrupts you can have code for; such as...
    Pin Interrupts
    Timer Interrupts
    Compritor change
    USART interrupts (input detected, byte sent)
    A/D convertion complete
    To name a few...

    Here is an example for a UART receive detected:
    Code:
    void interrupt isr(void)
    {
        if (PIR1bits.RCIF == 1)
        {
            rx_buffer[rx_in_pointer] = RCREG;
            rx_in_pointer = (rx_in_pointer + 1) % RX_BUFSIZE;
        }
    }
    No matter where my code is, if the hardware detects a UART byte has been received, that code will execute.
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by jimblumberg View Post
    A software interrupt is generated by software by writing values to addresses designated by the operating system or processor.
    Some processors, like the X86 family of processors have a interrupt instruction called INT which has single byte operand. As I mentioned in my previous post, for the early X86 processors, like the 8088 or 8086, it was common to use the 8259 chip to handle interrupts. During the interrupt handshake between the 8088/8086 and the 8259, two read cycles occur but the first one is ignored (it may have been the INT opcode in very early chips or prototypes), and on the second read, an 8 bit value is sent from the 8259 to the 8088/8086, which is used to index into an interrupt table. On the older still 8080/8085 cpu's, the 8259 was programmed to work with the 8080/8085, and three read cycles occurred, which was a CALL opcode, followed by two reads to supply a 16 bit address. Getting back to X86 machines in real mode, BIOS and MSDOS "calls" are implemented using the INT instruction.

    The 68000 family of processors has a TRAP (with immediate value for operand) instruction which generates an exception, which is similar to an interrupt. The ARM family of processors has a SWI (SoftWare Interrupt) (with immediate value for operand) instruction. These are mostly used to switch out of user mode into system mode to make operating system calls.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Click_here View Post
    An interrupt is a seporate bit of program that will execute when a condition is met.
    False. What you describe is an interrupt service routine, which is a subroutine typically executed when an interrupt occurs, but does not necessarily have to.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by Click_here View Post
    An interrupt is a seporate bit of program that will execute when a condition is met.

    For PIC microprocessors there are lots of different interrupts you can have code for; such as...
    Pin Interrupts
    Timer Interrupts
    Compritor change
    USART interrupts (input detected, byte sent)
    A/D convertion complete
    To name a few...

    Here is an example for a UART receive detected:
    Code:
    void interrupt isr(void)
    {
        if (PIR1bits.RCIF == 1)
        {
            rx_buffer[rx_in_pointer] = RCREG;
            rx_in_pointer = (rx_in_pointer + 1) % RX_BUFSIZE;
        }
    }
    No matter where my code is, if the hardware detects a UART byte has been received, that code will execute.
    I was wondering where in the code you specify which type of interrupt is associated with the function above? I did some research on the interrupt keyword, and learned about the interrupt vector table, but I couldn't understand how it knows to call your function for a particular interrupt.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I was wondering where in the code you specify which type of interrupt is associated with the function above?
    This will vary depending upon compiler, operating system, etc., but it appears in the above code the "interrupt" is the keyword.

    but I couldn't understand how it knows to call your function for a particular interrupt.
    Again this varies with compiler, operating system, etc.. But for DOS you need to "install" the interrupt handler, basically placing the address of your function in the interrupt vector table.

    Jim

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Usually there is only one interrupt handler that the processor calls at interrupt as far as I know. Of course, many operating systems keep their own "interrupt tables," containing addresses of subroutines that should be called for specific interrupts and delegates them there. Again, this depends on the system in question. This may not hold true for ever system.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by c_weed View Post
    What exactly is an interrupt (for example hardware interrupt or software interrupt). Hear me out. Most sources define an interrupt as when a device sends a signal to the CPU telling it what to do. 1)Anything connected to the computer sends a signal 2)the CPU is always being told what to do. That's what a program is.
    If you read it carefully, the first paragraph on the wikipedia link should answer this. It's all about the need to pause execution and give priority to a high-priority request that must take place before execution resumes. They are all signals. But some signals are more important than others.

    An interrupt is the old lady or the mother carrying a baby on the bank deposits queue.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by Alpo View Post
    I was wondering where in the code you specify which type of interrupt is associated with the function above? I did some research on the interrupt keyword, and learned about the interrupt vector table, but I couldn't understand how it knows to call your function for a particular interrupt.
    When a UART interupt occurs on the PIC microcontroller, the RCIF flag is set in the PIR1 register.
    The actual byte is in a register called "RCREG"
    I just throw it in a buffer and deal with the input when my processor has time.

    This code was for a PIC16F648A
    If you wanted to read about this more, look at 12.2.2 here http://ww1.microchip.com/downloads/e...Doc/40044E.pdf

    [edit]
    And the compiler which I used was the XC8 (it makes a difference how the interupt function is declared)
    Section 5.9 http://ww1.microchip.com/downloads/e...Doc/52053B.pdf
    [/edit]
    Last edited by Click_here; 10-02-2014 at 05:57 AM.
    Fact - Beethoven wrote his first symphony in C

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by c_weed View Post
    What exactly is an interupt?
    It's what Kanye West does when literally anyone else is talking.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Usually there is only one interrupt handler that the processor calls at interrupt as far as I know.
    There is usually one interrupt handler for every possible interrupt, if the interrupt is unused then the default handler may be just a "no op" followed a return from interrupt.
    Of course, many operating systems keep their own "interrupt tables," containing addresses of subroutines that should be called for specific interrupts and delegates them there.
    On a Windows PC the the BIOS initially handles the interrupt vector table, when the processor is switched to protected mode the operating system takes over this duty with it's own version of the vector table.


    Jim

  14. #14
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    The PIC has a routine that covers all interrupts (forgetting about priority), and you just look through all the flags to see which one has occured (as explained earlier)

    I really like this definition of an interrupt from Gooligum (A tutorial series on how to program PIC microprocessors), even though it is PIC specific...
    Quote Originally Posted by Gooligum
    An interrupt is a means of interrupting the main program flow in response to an event, so that the event can be handled, or serviced. The event (referred to an interrupt source) can be internal to the PIC, such as a timer overflowing, or external, such as a change on an input pin
    I thought that I would go through some of the differences in how interrupts are handled in the non-hosted environments.

    For something different, I went back to look at the original microcontroller that I learnt on -> The Motorola 68HC11. Freescale 68HC11 - Wikipedia, the free encyclopedia

    To set up interrupts on that device, you would put the opcode "JUMP" (7E) and then address of your interrupt service routines in a "interrupt vector". The interrupt takes the program counter to the correct place in the vector table and executes the code. Here is a good explination http://web.alfredstate.edu/albaflr/F...interrupts.pdf

    Details on interrupt on that device are here (Section 5.5): http://www.freescale.com/files/micro...t/M68HC11E.pdf

    (Note that the chip we were required to use had 256 bytes of EEPROM memory(where your program went) and 512bytes of RAM, so you would always program in assembly language. I have to say that if I had to program in assembly language, I would choose Motorola's instruction set, because of the massive instruction set, it was very easy to make small programs.)

    Another example of interrupt is with the AVR.
    When programming this, you need to specify the interrupt vector in your ISR (Interrupt Service Routine) -> <avr/interrupt.h>: Interrupts
    Code:
    #include <avr/interrupt.h>
    ISR(ADC_vect)
    {
      // user code here
    }
    Behind the scenes, the Atmel behaves like the motorola http://www.atmel.com/Images/io.pdf

    And the Arduino (which was built on top of the AVR), All you have to do is attach the interrupt to a function
    Arduino - AttachInterrupt

    The underlining theme for using interrupts is that the device stops excecuting the program (because of some event), and then using some implementation of interrupt vector table run a ISR, and then return to the main program.
    Last edited by Click_here; 10-02-2014 at 07:21 PM.
    Fact - Beethoven wrote his first symphony in C

  15. #15
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by jimblumberg View Post

    On a Windows PC the the BIOS initially handles the interrupt vector table, when the processor is switched to protected mode the operating system takes over this duty with it's own version of the vector table.


    Jim
    That's interesting. It makes me think of the stuff I've learned studying the Win32 api. I'm guessing that since every window has to register itself, that the ISR involves filling out a message structure, and adding it to the queue of whichever windows are applicable.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 16450 UART interupt issue
    By abachler in forum Networking/Device Communication
    Replies: 4
    Last Post: 04-25-2008, 12:50 PM
  2. Assembly Interupt in C++
    By histevenk in forum C++ Programming
    Replies: 9
    Last Post: 12-15-2007, 07:08 PM
  3. Key hit interupt?
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 09-26-2006, 12:02 AM
  4. interupt
    By ammar in forum C++ Programming
    Replies: 2
    Last Post: 10-22-2002, 12:39 PM