2 Debug Agent timer lib for OMAP 35xx.
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/IoLib.h>
12 #include <Library/OmapLib.h>
13 #include <Library/ArmLib.h>
14 #include <Library/PcdLib.h>
16 #include <Omap3530/Omap3530.h>
19 volatile UINT32 gVector
;
22 volatile UINT32 gTISR
;
23 volatile UINT32 gTCLR
;
24 volatile UINT32 gTLDR
;
25 volatile UINT32 gTCRR
;
26 volatile UINT32 gTIER
;
29 EnableInterruptSource (
36 // Map vector to FIQ, IRQ is default
37 MmioWrite32 (INTCPS_ILR (gVector
), 1);
40 Bit
= 1UL << (gVector
% 32);
42 MmioWrite32 (INTCPS_MIR_CLEAR(Bank
), Bit
);
46 DisableInterruptSource (
54 Bit
= 1UL << (gVector
% 32);
56 MmioWrite32 (INTCPS_MIR_SET(Bank
), Bit
);
62 Setup all the hardware needed for the debug agents timer.
64 This function is used to set up debug enviroment. It may enable interrupts.
69 DebugAgentTimerIntialize (
73 UINT32 TimerBaseAddress
;
76 TimerNumber
= PcdGet32(PcdOmap35xxDebugAgentTimer
);
77 gVector
= InterruptVectorForTimer (TimerNumber
);
79 // Set up the timer registers
80 TimerBaseAddress
= TimerBase (TimerNumber
);
81 gTISR
= TimerBaseAddress
+ GPTIMER_TISR
;
82 gTCLR
= TimerBaseAddress
+ GPTIMER_TCLR
;
83 gTLDR
= TimerBaseAddress
+ GPTIMER_TLDR
;
84 gTCRR
= TimerBaseAddress
+ GPTIMER_TCRR
;
85 gTIER
= TimerBaseAddress
+ GPTIMER_TIER
;
87 if ((TimerNumber
< 2) || (TimerNumber
> 9)) {
88 // This code assumes one the General Purpose timers is used
92 // Set source clock for GPT2 - GPT9 to SYS_CLK
93 MmioOr32 (CM_CLKSEL_PER
, 1 << (TimerNumber
- 2));
99 Set the period for the debug agent timer. Zero means disable the timer.
101 @param[in] TimerPeriodMilliseconds Frequency of the debug agent timer.
106 DebugAgentTimerSetPeriod (
107 IN UINT32 TimerPeriodMilliseconds
113 if (TimerPeriodMilliseconds
== 0) {
115 MmioWrite32 (gTCLR
, TCLR_ST_OFF
);
117 DisableInterruptSource ();
119 // Calculate required timer count
120 TimerCount
= DivU64x32(TimerPeriodMilliseconds
* 1000000, PcdGet32(PcdDebugAgentTimerFreqNanoSeconds
));
122 // Set GPTIMER5 Load register
123 LoadValue
= (INT32
) -TimerCount
;
124 MmioWrite32 (gTLDR
, LoadValue
);
125 MmioWrite32 (gTCRR
, LoadValue
);
127 // Enable Overflow interrupt
128 MmioWrite32 (gTIER
, TIER_TCAR_IT_DISABLE
| TIER_OVF_IT_ENABLE
| TIER_MAT_IT_DISABLE
);
130 // Turn on GPTIMER3, it will reload at overflow
131 MmioWrite32 (gTCLR
, TCLR_AR_AUTORELOAD
| TCLR_ST_ON
);
133 EnableInterruptSource ();
139 Perform End Of Interrupt for the debug agent timer. This is called in the
140 interrupt handler after the interrupt has been processed.
145 DebugAgentTimerEndOfInterrupt (
149 // Clear all timer interrupts
150 MmioWrite32 (gTISR
, TISR_CLEAR_ALL
);
152 // Poll interrupt status bits to ensure clearing
153 while ((MmioRead32 (gTISR
) & TISR_ALL_INTERRUPT_MASK
) != TISR_NO_INTERRUPTS_PENDING
);
155 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWFIQAGR
);
156 ArmDataSynchronizationBarrier ();