1 |
17 |
wfjm |
/* -*- c++ -*- */
|
2 |
|
|
/* $Id: timer.c 395 2011-07-17 22:02:55Z mueller $ */
|
3 |
|
|
/*-----------------------------------------------------------------------------
|
4 |
|
|
* Timer handling for FX2
|
5 |
|
|
*-----------------------------------------------------------------------------
|
6 |
|
|
* Code taken from USRP2 firmware (GNU Radio Project), version 3.0.2,
|
7 |
|
|
* Copyright 2003 Free Software Foundation, Inc.
|
8 |
|
|
*-----------------------------------------------------------------------------
|
9 |
|
|
* This code is part of usbjtag. usbjtag is free software; you can redistribute
|
10 |
|
|
* it and/or modify it under the terms of the GNU General Public License as
|
11 |
|
|
* published by the Free Software Foundation; either version 2 of the License,
|
12 |
|
|
* or (at your option) any later version. usbjtag is distributed in the hope
|
13 |
|
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
14 |
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
* GNU General Public License for more details. You should have received a
|
16 |
|
|
* copy of the GNU General Public License along with this program in the file
|
17 |
|
|
* COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
18 |
|
|
* St, Fifth Floor, Boston, MA 02110-1301 USA
|
19 |
|
|
*-----------------------------------------------------------------------------
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
#include "timer.h"
|
23 |
|
|
#include "fx2regs.h"
|
24 |
|
|
#include "isr.h"
|
25 |
|
|
|
26 |
|
|
/*
|
27 |
|
|
* Arrange to have isr_tick_handler called at 100 Hz.
|
28 |
|
|
*
|
29 |
|
|
* The cpu clock is running at 48e6. The input to the timer
|
30 |
|
|
* is 48e6 / 12 = 4e6.
|
31 |
|
|
*
|
32 |
|
|
* We arrange to have the timer overflow every 40000 clocks == 100 Hz
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
#define RELOAD_VALUE ((unsigned short) -40000)
|
36 |
|
|
|
37 |
|
|
void
|
38 |
|
|
hook_timer_tick (unsigned short isr_tick_handler)
|
39 |
|
|
{
|
40 |
|
|
ET2 = 0; // disable timer 2 interrupts
|
41 |
|
|
hook_sv (SV_TIMER_2, isr_tick_handler);
|
42 |
|
|
|
43 |
|
|
RCAP2H = RELOAD_VALUE >> 8; // setup the auto reload value
|
44 |
|
|
RCAP2L = RELOAD_VALUE & 0xFF;
|
45 |
|
|
|
46 |
|
|
T2CON = 0x04; // interrupt on overflow; reload; run
|
47 |
|
|
ET2 = 1; // enable timer 2 interrupts
|
48 |
|
|
}
|