OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [fx2/] [src/] [lib/] [delay.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 wfjm
/* -*- c++ -*- */
2
/* $Id: delay.c 395 2011-07-17 22:02:55Z mueller $ */
3
/*-----------------------------------------------------------------------------
4
 * Delay routines
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
/*
23
 * Delay approximately 1 microsecond (including overhead in udelay).
24
 */
25
static void
26
udelay1 (void) _naked
27
{
28
  _asm                          ; lcall that got us here took 4 bus cycles
29
        ret                     ; 4 bus cycles
30
  _endasm;
31
}
32
 
33
/*
34
 * delay for approximately usecs microseconds
35
 */
36
void
37
udelay (unsigned char usecs)
38
{
39
  do {
40
    udelay1 ();
41
  } while (--usecs != 0);
42
}
43
 
44
 
45
/*
46
 * Delay approximately 1 millisecond.
47
 * We're running at 48 MHz, so we need 48,000 clock cycles.
48
 *
49
 * Note however, that each bus cycle takes 4 clock cycles (not obvious,
50
 * but explains the factor of 4 problem below).
51
 */
52
static void
53
mdelay1 (void) _naked
54
{
55
  _asm
56
        mov     dptr,#(-1200 & 0xffff)
57
002$:
58
        inc     dptr            ; 3 bus cycles
59
        mov     a, dpl          ; 2 bus cycles
60
        orl     a, dph          ; 2 bus cycles
61
        jnz     002$            ; 3 bus cycles
62
 
63
        ret
64
  _endasm;
65
}
66
 
67
void
68
mdelay (unsigned int msecs)
69
{
70
  do {
71
    mdelay1 ();
72
  } while (--msecs != 0);
73
}
74
 
75
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.