bsd_usbloader_test.c revision 266887
1246145Shselasky/* $FreeBSD: head/sys/boot/usb/bsd_usbloader_test.c 266887 2014-05-30 14:30:52Z hselasky $ */
2246145Shselasky/*-
3246145Shselasky * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
4246145Shselasky *
5246145Shselasky * Redistribution and use in source and binary forms, with or without
6246145Shselasky * modification, are permitted provided that the following conditions
7246145Shselasky * are met:
8246145Shselasky * 1. Redistributions of source code must retain the above copyright
9246145Shselasky *    notice, this list of conditions and the following disclaimer.
10246145Shselasky * 2. Redistributions in binary form must reproduce the above copyright
11246145Shselasky *    notice, this list of conditions and the following disclaimer in the
12246145Shselasky *    documentation and/or other materials provided with the distribution.
13246145Shselasky *
14246145Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15246145Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16246145Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17246145Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18246145Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19246145Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20246145Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21246145Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22246145Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23246145Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24246145Shselasky * SUCH DAMAGE.
25246145Shselasky */
26246145Shselasky
27246145Shselasky#include <stdio.h>
28246145Shselasky#include <stdint.h>
29266887Shselasky#include <stdlib.h>
30246145Shselasky#include <time.h>
31246145Shselasky
32246145Shselaskyextern int usleep(int);
33246145Shselaskyextern void callout_process(int);
34246145Shselaskyextern void usb_idle(void);
35246145Shselaskyextern void usb_init(void);
36246145Shselaskyextern void usb_uninit(void);
37246145Shselasky
38246145Shselasky#define	hz 1000
39246145Shselasky
40266887Shselaskyvoid *
41266887Shselaskyusb_malloc(size_t size)
42266887Shselasky{
43266887Shselasky	return (malloc(size));
44266887Shselasky}
45266887Shselasky
46246145Shselaskyvoid
47266887Shselaskyusb_free(void *ptr)
48266887Shselasky{
49266887Shselasky	free(ptr);
50266887Shselasky}
51266887Shselasky
52266887Shselaskyvoid
53246145ShselaskyDELAY(unsigned int delay)
54246145Shselasky{
55246145Shselasky	usleep(delay);
56246145Shselasky}
57246145Shselasky
58246145Shselaskyint
59246145Shselaskypause(const char *what, int timeout)
60246145Shselasky{
61246145Shselasky	if (timeout == 0)
62246145Shselasky		timeout = 1;
63246145Shselasky
64246145Shselasky	usleep((1000000 / hz) * timeout);
65246145Shselasky
66246145Shselasky	return (0);
67246145Shselasky}
68246145Shselasky
69246145Shselaskyint
70246145Shselaskymain(int argc, char **argv)
71246145Shselasky{
72246145Shselasky	uint32_t time;
73246145Shselasky
74246145Shselasky	usb_init();
75246145Shselasky
76246145Shselasky	time = 0;
77246145Shselasky
78246145Shselasky	while (1) {
79246145Shselasky
80246145Shselasky		usb_idle();
81246145Shselasky
82246145Shselasky		usleep(1000);
83246145Shselasky
84246145Shselasky		if (++time >= (1000 / hz)) {
85246145Shselasky			time = 0;
86246145Shselasky			callout_process(1);
87246145Shselasky		}
88246145Shselasky	}
89246145Shselasky
90246145Shselasky	usb_uninit();
91246145Shselasky
92246145Shselasky	return (0);
93246145Shselasky}
94