How to configure the SPEAr3xx general purpose timers (GPTs)
Introduction
This application note provides information about how to configure the general purpose
timers (GPTs) integrated in the SPEAr3xx embedded MPU family.
General purpose timers (GPTs) play an important role in any system as they provide a
means of calculating time for controlling the execution of various operations. In case of an
operating system, they are used for the system tick generation, usually every 10 ms; in other
applications they can be used to get a finer granularity for controlling the timing of events.
The purpose of this application note is to explain how to read the free running timer counter
and configure the clock source of the various GPTs that are integrated in the SPEAr3xx
architecture. It also describes and proposes a solution for the problem reported during the
Puppy Linux project concerning the status register interrupt bit clear issue.
In the SPEAr3xx architecture, there are three different GPT blocks located in the various
subsystems. Each timer block consists of two independent channels, each one with a 16-bit
counter register.
Table 1.GPTs in SPEAr3xx
SubsystemBase address
GPT1ARM 0xF000_0000
GPT2Basic1 0xFC80_0000
GPT3Basic2 0xFCB0_0000
Each timer has a READ_Clk, input which is the APB clock (PCLK), and a CNT_Clk, which
can be selected by the user from a list of clock sources.
●READ_Clk (PCLK): When SPEAr3xx is in normal mode, it takes the input from PLL1
divided by a programmable prescaler, whose reset values impose the ratio 1:2:4 to the
core_clk, HCLK and PCLK clocks. When SPEAr3xx is in slow mode, it takes directly
the input from the OSCI signal.
●CNT_Clk: The clock source can be selected as either a fixed 48 MHz or the PLL1 itself
divided by a programmable prescaler, which is defined in the PRSC1_CLK_CFG
register (0xFCA8_0044) for GPT1, PRSC2_CLK_CFG register (0xFCA8_0048) for
GPT2 and PRSC3_CLK_CFG register (0xFCA8_004C) for GPT3. The CNT_Clk may
then be further divided by a GPT internal 4-bit prescaler able to divide up to 256 times
(‘/256’).
Figure 1.GPT clock sources
The following table describes the clock selectors (Clock_Sel) for each GPT.
Doc ID 16997 Rev 13/14
MUX
Clock_Sel
int_prsc
General purpose timers (GPTs) in SPEAr3xxAN3140
Table 2.GPTx clock source selector
RegisterAddressValue
GPT1PRPH_CLK_CFG [08] 0xFCA8_0028 (bit8)
GPT2PRPH_CLK_CFG[11]0xFCA8_0028 (bit11)
GPT3PRPH_CLK_CFG[12]0xFCA8_0028 (bit12)
0: PLL3 48 MHz
1: PLL1 (
PRSC1_CLK_CFG)
0: PLL3 48 MHz
1: PLL1 (
PRSC2_CLK_CFG)
0: PLL3 48 MHz
1: PLL1 (
PRSC3_CLK_CFG)
The SPEAr3xx GPTs always generate precise alarm interrupts, for example in the case of a
system tick for a RTOS. Nevertheless, as you can see in
Section 2: Reading a free-running
timer counter, GPTs can return unpredictable read values when they are running and the
input clock is asynchronous (or not in phase).
4/14Doc ID 16997 Rev 1
AN3140Reading a free-running timer counter
CNT_Clk
0 0101
READ_Clk
CNT_Clk
READ_Clk
Bit_N
t0 t1 t2
t0: On CNT_Cl k rising edg e, Bit_N
start a 0->1 tran sitioni ng
t1:
On RE AD_C lk rising edge, Bit_N i s
sam pled in an uns tab le state
t2:
Bit_N reaches a stable state
2 Reading a free-running timer counter
When the GPT interrupt is enabled, the interrupts generated at each timer wrap-around
condition are always triggered at the right frequency, however reading the timer counter
when the timer itself is active and free-running may present some difficulties which are
described below.
In a simplified scenario, a hardware timer block can be seen just as a simple counter
register with two input clocks:CNT_Clk for incrementing/decrementing the counter and
READ_Clk for synchronizing the READ accesses of the bus the timer is connected to.
Figure 2.Simplified timer
…
The two clocks can be either synchronous, coming from the same source PCLK, or
completely asynchronous, for example coming from two different sources.
When the two clocks involved in the scenario are asynchronous, then the value retrieved by
the CPU in a read counter operation is unpredictable, and might be completely different from
the real value in the register.
The situation is due to the fact that the READ_Clk is sampling the counter bits while they are
in a transitioning, unstable phase.
Figure 3.Sampling a counter bit in an unstable state
The above scenario may take place during any kind of transition (0->1 or 1->0) and for any
bit in the register.
If one of the bits impacted has a large weight (significant position) in the counter, then the
difference between the value returned in the read transaction and the real value of the
counter can be very large.
Doc ID 16997 Rev 15/14
Loading...
+ 9 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.