1*05890ca0SHans Petter Selasky /*-
2*05890ca0SHans Petter Selasky * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
3*05890ca0SHans Petter Selasky *
4*05890ca0SHans Petter Selasky * Redistribution and use in source and binary forms, with or without
5*05890ca0SHans Petter Selasky * modification, are permitted provided that the following conditions
6*05890ca0SHans Petter Selasky * are met:
7*05890ca0SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
8*05890ca0SHans Petter Selasky * notice, this list of conditions and the following disclaimer.
9*05890ca0SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
10*05890ca0SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
11*05890ca0SHans Petter Selasky * documentation and/or other materials provided with the distribution.
12*05890ca0SHans Petter Selasky *
13*05890ca0SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*05890ca0SHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*05890ca0SHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*05890ca0SHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*05890ca0SHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*05890ca0SHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*05890ca0SHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*05890ca0SHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*05890ca0SHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*05890ca0SHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*05890ca0SHans Petter Selasky * SUCH DAMAGE.
24*05890ca0SHans Petter Selasky */
25*05890ca0SHans Petter Selasky
26*05890ca0SHans Petter Selasky #include <stdio.h>
27*05890ca0SHans Petter Selasky #include <stdint.h>
28*05890ca0SHans Petter Selasky #include <stdlib.h>
29*05890ca0SHans Petter Selasky #include <time.h>
30*05890ca0SHans Petter Selasky
31*05890ca0SHans Petter Selasky extern int usleep(int);
32*05890ca0SHans Petter Selasky extern void callout_process(int);
33*05890ca0SHans Petter Selasky extern void usb_idle(void);
34*05890ca0SHans Petter Selasky extern void usb_init(void);
35*05890ca0SHans Petter Selasky extern void usb_uninit(void);
36*05890ca0SHans Petter Selasky
37*05890ca0SHans Petter Selasky #define hz 1000
38*05890ca0SHans Petter Selasky
39*05890ca0SHans Petter Selasky #ifdef HAVE_MALLOC
40*05890ca0SHans Petter Selasky void *
usb_malloc(size_t size)41*05890ca0SHans Petter Selasky usb_malloc(size_t size)
42*05890ca0SHans Petter Selasky {
43*05890ca0SHans Petter Selasky return (malloc(size));
44*05890ca0SHans Petter Selasky }
45*05890ca0SHans Petter Selasky
46*05890ca0SHans Petter Selasky void
usb_free(void * ptr)47*05890ca0SHans Petter Selasky usb_free(void *ptr)
48*05890ca0SHans Petter Selasky {
49*05890ca0SHans Petter Selasky free(ptr);
50*05890ca0SHans Petter Selasky }
51*05890ca0SHans Petter Selasky #endif
52*05890ca0SHans Petter Selasky
53*05890ca0SHans Petter Selasky void
DELAY(unsigned int delay)54*05890ca0SHans Petter Selasky DELAY(unsigned int delay)
55*05890ca0SHans Petter Selasky {
56*05890ca0SHans Petter Selasky usleep(delay);
57*05890ca0SHans Petter Selasky }
58*05890ca0SHans Petter Selasky
59*05890ca0SHans Petter Selasky void
delay(unsigned int delay)60*05890ca0SHans Petter Selasky delay(unsigned int delay)
61*05890ca0SHans Petter Selasky {
62*05890ca0SHans Petter Selasky usleep(delay);
63*05890ca0SHans Petter Selasky }
64*05890ca0SHans Petter Selasky
65*05890ca0SHans Petter Selasky int
pause(const char * what,int timeout)66*05890ca0SHans Petter Selasky pause(const char *what, int timeout)
67*05890ca0SHans Petter Selasky {
68*05890ca0SHans Petter Selasky if (timeout == 0)
69*05890ca0SHans Petter Selasky timeout = 1;
70*05890ca0SHans Petter Selasky
71*05890ca0SHans Petter Selasky usleep((1000000 / hz) * timeout);
72*05890ca0SHans Petter Selasky
73*05890ca0SHans Petter Selasky return (0);
74*05890ca0SHans Petter Selasky }
75*05890ca0SHans Petter Selasky
76*05890ca0SHans Petter Selasky int
main(int argc,char ** argv)77*05890ca0SHans Petter Selasky main(int argc, char **argv)
78*05890ca0SHans Petter Selasky {
79*05890ca0SHans Petter Selasky uint32_t time;
80*05890ca0SHans Petter Selasky
81*05890ca0SHans Petter Selasky usb_init();
82*05890ca0SHans Petter Selasky
83*05890ca0SHans Petter Selasky time = 0;
84*05890ca0SHans Petter Selasky
85*05890ca0SHans Petter Selasky while (1) {
86*05890ca0SHans Petter Selasky
87*05890ca0SHans Petter Selasky usb_idle();
88*05890ca0SHans Petter Selasky
89*05890ca0SHans Petter Selasky usleep(1000);
90*05890ca0SHans Petter Selasky
91*05890ca0SHans Petter Selasky if (++time >= (1000 / hz)) {
92*05890ca0SHans Petter Selasky time = 0;
93*05890ca0SHans Petter Selasky callout_process(1);
94*05890ca0SHans Petter Selasky }
95*05890ca0SHans Petter Selasky }
96*05890ca0SHans Petter Selasky
97*05890ca0SHans Petter Selasky usb_uninit();
98*05890ca0SHans Petter Selasky
99*05890ca0SHans Petter Selasky return (0);
100*05890ca0SHans Petter Selasky }
101