Jerome Carter Jerome Carter - 2 months ago 15
C Question

How to clear BCM2835 Interrupt Clear Register?

I'm looking into how to make an operating system for Raspberry Pi, and in the OSDev barebones tutorial for the Raspberry Pi, the following code is used to clear any pending interrupts.

// Clear pending interrupts.
mmio_write(UART0_ICR, 0x7FF);


The function
mmio_write
is as follows.

static inline void mmio_write(uint32_t reg, uint32_t data){
*(volatile uint32_t *)reg = data;
}


Why is this value significant, and how does it clear the interrupts?

Answer

This line:

// Clear pending interrupts.
mmio_write(UART0_ICR, 0x7FF);

will write value of 0x7FF to the register at address UART0_ICR. Most likely, UART0_ICR is a value defined some else where in the code, which refers to the address of a corresponding register inside the BCM2835, maybe something similar to this:

#define UART0_ICR (UART0_BASE + 0x44)

Why is this value significant, and how does it clear the interrupts?

To understand this, you need to read the data sheet of the device, which is BCM2835 in your case (a quick search gives me this link). Look at the UART register section, you can see the description for UART_ICR register, which is the Interupt Clear Register.

It's quite obvious from the bit table description of that register: it's a 32-bit register, bit 31-11 is not used, while bit from 0 to 10 (11 bit) is used as flags for clearing various kinds of interrupt. Writing value of 0x7FF to this register is literally setting on all those flags, hence it will clear all the pending UART interrupts.

Comments