How to handle an interrupt

From Milkymist Wiki

Jump to: navigation, search

WIP some snipets from [slides| http://lekernel.net/presentations/masteri2l/conf/mm_i2l.pdf]

Interruptions.

Example : serial port

  • Register at 0xe0000000.
  • Interruption 0 after a character is received
  • Interruption 1 after a character is received sent
void transmit(char c)
{
/* write a character */
*((volatile unsigned int *)0xe0000000) = c;
/* after a character is received */
while(!(lm32_interrupts_pending() & (1 << 0)));
/* acknowledge interrupt */
lm32_interrupt_ack(1 << 0);
}
char receive()
{
/* reception loop */
while(!(lm32_interrupts_pending() & (1 << 1)));
/* acknowledge interruption */
lm32_interrupt_ack(1 << 1);
/* read character */
return *((volatile unsigned int *)0xe0000000);
}


You need some asm at startup https://github.com/milkymist/milkymist/blob/master/software/bios/crt0.S#L63

Then a interrupt service routine, a software routine that is executed in response to an interrupt https://github.com/milkymist/milkymist/blob/master/software/bios/isr.c#L32

And the lib for uart for this example in this case https://github.com/milkymist/milkymist/blob/master/software/libbase/uart.c#L48

Personal tools