[vc_row][vc_column width=”1/1″][vc_column_text]External interrupt is an important mechanism to handle external event by pcDuino. pcDuino provides two external interrupt pins (pins 2 and 3). If you need to use more than two external interrupt pins, in this post, we are looking at how to make the external interrupt drive.
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”What is interrupt” tab_id=”1388480554-1-12″][vc_column_text]Compared to the speed of CPU or even of memory, I/O devices are considered extremely slow. Printers, keyboards, mice are all very slow devices. They take a long time to respond, and furthermore, they only require occasional handling by the CPU. Even though you may feel you’re using the keyboard or mouse all the time, the CPU runs so much faster than you can, that it’s practically as if you’re not using it at all.
One way for a CPU to communicate with an I/O device is through polling. That’s discussed in a different set of class notes .
However, if the device is slow, and rarely requires servicing, external interrupts are usually a better way to go.
This way of handling I/O devices usually called interrupt driven I/O.
A CPU usually has at least one input pin devoted to interrupts. Whenever a device wants the CPU to pay attention, it sends a a signal to this pin.
The protocol usually runs like this:
I/O device sets the INT pin from 0 to 1.
The CPU completes the current instruction, and then saves the state of the program. For older ISPs, this involved copying registers to the stack. For newer ones ISPs, this usually means switching to a supervisor (operating system) set of registers.
The CPU then determines which kind interrupt has occurred. It can send a signal to the I/O device to ask for an interrupt number.
The I/O device can place the interrupt number on the data bus.
The CPU then runs an interrupt handler (a special function) for that.
Once the interrupt has been handled, the I/O device turns the INT value back to 0, and the CPU resumes running the program that was interrupted.
The detail can be found at: http://www.cs.umd.edu/class/spring2003/cmsc311/Notes/IO/extInt.html[/vc_column_text][/vc_tab][vc_tab title=”A10 External interrupt pins” tab_id=”1388480554-2-9″][vc_column_text]Allwinner A10 has 32 GPIO which support EINT:
- PH0 – PH21 ( correspondence EINT0 – EINT21 )
- PI10 – PI19 ( correspondence EINT22 – EINT31 )
The correspondence between pcDuino’s Arduino hardware and A10:
You can find the correspondence on
Because of the pin’s reuse, GPIO5/GPIO6 are not able to handle external interrupt.[/vc_column_text][/vc_tab][vc_tab title=”External interrupt kernel driver code” tab_id=”1388482403509-2-4″][vc_column_text]
You can download the code here.[/vc_column_text][/vc_tab][vc_tab title=”Compile” tab_id=”1388482544695-3-6″][vc_column_text]Copy the file keypad.c to a folder under kernel, like linux-sunxi/drivers\char,
then modify linux-sunxi/drivers\char\Makefile, add obj-m += keypad.o in it.
Will create file keypad.ko at the some folder when compiling.[/vc_column_text][/vc_tab][vc_tab title=”FAQ” tab_id=”1388482925020-4-9″][vc_column_text]
sb_key_used = 1
key_num = 3
key_pin_0 = port:PH17<6><1><3>
key_code_0 = 158
key_pin_1 = port:PH18<6><1><3>
key_code_1 = 139
key_pin_2 = port:PH19<6><1><3>
key_code_2 = 102