source: trunk/FirmwareFX2/fx2/timer.c@ 5

Last change on this file since 5 was 4, checked in by demin, 15 years ago

initial commit

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