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

Subversion Repositories modular_oscilloscope

[/] [modular_oscilloscope/] [trunk/] [sw/] [src/] [include/] [delay.c] - Blame information for rev 60

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 budinero
/*
2
 * libieee1284 - IEEE 1284 library
3
 * Copyright (C) 2001  Tim Waugh <twaugh@redhat.com>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
 
20
#ifndef _MSC_VER
21
#include <sys/time.h>
22
#endif
23
#ifdef __unix__
24
#include <unistd.h>
25
#endif
26
#if defined __MINGW32__ || defined _MSC_VER
27
#include <sys/timeb.h>
28
#endif
29
 
30
#include "delay.h"
31
 
32
void udelay(unsigned long usec)
33
{
34
#if !(defined __MINGW32__ || defined _MSC_VER)
35
        struct timeval now, deadline;
36
 
37
        gettimeofday(&deadline, NULL);
38
        deadline.tv_usec += usec;
39
        deadline.tv_sec += deadline.tv_usec / 1000000;
40
        deadline.tv_usec %= 1000000;
41
 
42
        do {
43
                gettimeofday(&now, NULL);
44
        } while ((now.tv_sec < deadline.tv_sec) ||
45
                (now.tv_sec == deadline.tv_sec &&
46
                now.tv_usec < deadline.tv_usec));
47
#else
48
        /* MinGW has no gettimeofday(). ftime() seems to be the best alternative as I
49
         * don't know of any standard Windows function with microsecond accuracy. I
50
         * should have a look at the Cygwin source code... - dbjh */
51
        struct timeb tb;
52
        long int now, deadline;
53
 
54
        ftime(&tb);
55
        deadline = tb.time * 1000 + tb.millitm + usec / 1000;
56
 
57
        do {
58
                ftime(&tb);
59
                now = tb.time * 1000 + tb.millitm;
60
        } while (now < deadline);
61
#endif
62
}
63
 

powered by: WebSVN 2.1.0

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