bsd_usbloader_test.c revision 246145
1246145Shselasky/* $FreeBSD: head/sys/boot/usb/bsd_usbloader_test.c 246145 2013-01-31 11:00:57Z 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> 29246145Shselasky#include <time.h> 30246145Shselasky 31246145Shselaskyextern int usleep(int); 32246145Shselaskyextern void callout_process(int); 33246145Shselaskyextern void usb_idle(void); 34246145Shselaskyextern void usb_init(void); 35246145Shselaskyextern void usb_uninit(void); 36246145Shselasky 37246145Shselasky#define hz 1000 38246145Shselasky 39246145Shselaskyvoid 40246145ShselaskyDELAY(unsigned int delay) 41246145Shselasky{ 42246145Shselasky usleep(delay); 43246145Shselasky} 44246145Shselasky 45246145Shselaskyint 46246145Shselaskypause(const char *what, int timeout) 47246145Shselasky{ 48246145Shselasky if (timeout == 0) 49246145Shselasky timeout = 1; 50246145Shselasky 51246145Shselasky usleep((1000000 / hz) * timeout); 52246145Shselasky 53246145Shselasky return (0); 54246145Shselasky} 55246145Shselasky 56246145Shselaskyint 57246145Shselaskymain(int argc, char **argv) 58246145Shselasky{ 59246145Shselasky uint32_t time; 60246145Shselasky 61246145Shselasky usb_init(); 62246145Shselasky 63246145Shselasky time = 0; 64246145Shselasky 65246145Shselasky while (1) { 66246145Shselasky 67246145Shselasky usb_idle(); 68246145Shselasky 69246145Shselasky usleep(1000); 70246145Shselasky 71246145Shselasky if (++time >= (1000 / hz)) { 72246145Shselasky time = 0; 73246145Shselasky callout_process(1); 74246145Shselasky } 75246145Shselasky } 76246145Shselasky 77246145Shselasky usb_uninit(); 78246145Shselasky 79246145Shselasky return (0); 80246145Shselasky} 81