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