2 Debug Agent timer lib for OMAP 35xx.
4 Copyright (c) 2008-2010, Apple Inc. All rights reserved.
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/IoLib.h>
18 #include <Library/OmapLib.h>
19 #include <Library/ArmLib.h>
20 #include <Library/PcdLib.h>
22 #include <Omap3530/Omap3530.h>
25 volatile UINT32 gVector
;
28 volatile UINT32 gTISR
;
29 volatile UINT32 gTCLR
;
30 volatile UINT32 gTLDR
;
31 volatile UINT32 gTCRR
;
32 volatile UINT32 gTIER
;
35 EnableInterruptSource (
42 // Map vector to FIQ, IRQ is default
43 MmioWrite32 (INTCPS_ILR (gVector
), 1);
46 Bit
= 1UL << (gVector
% 32);
48 MmioWrite32 (INTCPS_MIR_CLEAR(Bank
), Bit
);
52 DisableInterruptSource (
60 Bit
= 1UL << (gVector
% 32);
62 MmioWrite32 (INTCPS_MIR_SET(Bank
), Bit
);
68 Setup all the hardware needed for the debug agents timer.
70 This function is used to set up debug enviroment. It may enable interrupts.
75 DebugAgentTimerIntialize (
79 UINT32 TimerBaseAddress
;
82 gVector
= InterruptVectorForTimer (PcdGet32(PcdOmap35xxDebugAgentTimer
));
84 // Set up the timer registers
85 TimerBaseAddress
= TimerBase (PcdGet32(PcdOmap35xxDebugAgentTimer
));
86 gTISR
= TimerBaseAddress
+ GPTIMER_TISR
;
87 gTCLR
= TimerBaseAddress
+ GPTIMER_TCLR
;
88 gTLDR
= TimerBaseAddress
+ GPTIMER_TLDR
;
89 gTCRR
= TimerBaseAddress
+ GPTIMER_TCRR
;
90 gTIER
= TimerBaseAddress
+ GPTIMER_TIER
;
92 DisableInterruptSource ();
97 Set the period for the debug agent timer. Zero means disable the timer.
99 @param[in] TimerPeriodMilliseconds Frequency of the debug agent timer.
104 DebugAgentTimerSetPeriod (
105 IN UINT32 TimerPeriodMilliseconds
111 if (TimerPeriodMilliseconds
== 0) {
113 MmioWrite32 (gTCLR
, TCLR_ST_OFF
);
115 DisableInterruptSource ();
117 // Calculate required timer count
118 TimerCount
= DivU64x32(TimerPeriodMilliseconds
* 1000000, PcdGet32(PcdDebugAgentTimerFreqNanoSeconds
));
120 // Set GPTIMER5 Load register
121 LoadValue
= (INT32
) -TimerCount
;
122 MmioWrite32 (gTLDR
, LoadValue
);
123 MmioWrite32 (gTCRR
, LoadValue
);
125 // Enable Overflow interrupt
126 MmioWrite32 (gTIER
, TIER_TCAR_IT_DISABLE
| TIER_OVF_IT_ENABLE
| TIER_MAT_IT_DISABLE
);
128 // Turn on GPTIMER3, it will reload at overflow
129 MmioWrite32 (gTCLR
, TCLR_AR_AUTORELOAD
| TCLR_ST_ON
);
131 EnableInterruptSource ();
137 Perform End Of Interrupt for the debug agent timer. This is called in the
138 interrupt handler after the interrupt has been processed.
143 DebugAgentTimerEndOfInterrupt (
147 // Clear all timer interrupts
148 MmioWrite32 (gTISR
, TISR_CLEAR_ALL
);
150 // Poll interrupt status bits to ensure clearing
151 while ((MmioRead32 (gTISR
) & TISR_ALL_INTERRUPT_MASK
) != TISR_NO_INTERRUPTS_PENDING
);
153 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWFIQAGR
);
154 ArmDataSyncronizationBarrier ();