Atmel Evaluation Board using the SAM7SE Microcontroller AT91SAM7SE-EK AT91SAM7SE-EK Data Sheet

Product codes
AT91SAM7SE-EK
Page of 24
10
6295A–ATARM–27-Mar-07
Application Note
3.2.2
Generic Peripheral Usage
3.2.2.1
Initialization
Most peripherals are initialized by performing three actions
• Enabling the peripheral clock in the PMC
• Enabling the control of the peripheral on PIO pins
• Configuring the interrupt source of the peripheral in the AIC
• Enabling the interrupt source at the peripheral level
Most peripherals are not clocked by default. This makes it possible to reduce the power con-
sumption of the system at startup. However, it requires that the programmer explicitly enable the
peripheral clock. This is done in the Power Management Controller (PMC). Exception is made
for the System Controller (which comprises several different controllers), as it is continuously
clocked.
For peripherals which need to use one or more pins of the chip as external inputs/outputs, it is
necessary to configure the Parallel Input/Output controller first. This operation is described in
more detail in 
.
Finally, if an interrupt is to be generated by the peripheral, then the source must be configured
properly in the Advanced Interrupt Controller. Please refer to 
 for more
information.
3.2.3
Using the Advanced Interrupt Controller
3.2.3.1
Purpose
The AIC manages all internal and external interrupts of the system. It enables the definition of
one handler for each interrupt source, i.e., a function which is called whenever the correspond-
ing event occurs. Interrupts can also be individually enabled or masked, and have several
different priority levels.
In the example software, using the AIC is required because several interrupt sources are
present (see 
).
3.2.3.2
Initialization
Unlike most other peripherals, the AIC is always clocked and cannot be shut down. Therefore,
there is no need to enable its peripheral clock in the PMC.
The only mandatory action to perform at this point is to disable and clear all interrupts. This is
done with these two instructions:
// Disable all interrupts
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
// Clear all interrupts
AT91C_BASE_AIC->AIC_ICCR = 0xFFFFFFFF;
For debug purposes, it is good practice to use dummy handlers (i.e., which loop indefinitely) for
all interrupt sources. This way, if an interrupt is triggered before being configured, the debugger
is stuck in the handler instead of jumping to a random address.
In addition, an application which may perform a processor reset (i.e., reset of the ARM core with-
out resetting peripherals) must write the End Of Interrupt Command Register (EOICR) of the AIC