bsd_usbloader_test.c revision 266894
1246145Shselasky/* $FreeBSD: head/sys/boot/usb/bsd_usbloader_test.c 266894 2014-05-30 16:49:12Z 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 40266894Shselasky#ifdef HAVE_MALLOC 41266887Shselaskyvoid * 42266887Shselaskyusb_malloc(size_t size) 43266887Shselasky{ 44266887Shselasky return (malloc(size)); 45266887Shselasky} 46266887Shselasky 47246145Shselaskyvoid 48266887Shselaskyusb_free(void *ptr) 49266887Shselasky{ 50266887Shselasky free(ptr); 51266887Shselasky} 52266894Shselasky#endif 53266887Shselasky 54266887Shselaskyvoid 55246145ShselaskyDELAY(unsigned int delay) 56246145Shselasky{ 57246145Shselasky usleep(delay); 58246145Shselasky} 59246145Shselasky 60246145Shselaskyint 61246145Shselaskypause(const char *what, int timeout) 62246145Shselasky{ 63246145Shselasky if (timeout == 0) 64246145Shselasky timeout = 1; 65246145Shselasky 66246145Shselasky usleep((1000000 / hz) * timeout); 67246145Shselasky 68246145Shselasky return (0); 69246145Shselasky} 70246145Shselasky 71246145Shselaskyint 72246145Shselaskymain(int argc, char **argv) 73246145Shselasky{ 74246145Shselasky uint32_t time; 75246145Shselasky 76246145Shselasky usb_init(); 77246145Shselasky 78246145Shselasky time = 0; 79246145Shselasky 80246145Shselasky while (1) { 81246145Shselasky 82246145Shselasky usb_idle(); 83246145Shselasky 84246145Shselasky usleep(1000); 85246145Shselasky 86246145Shselasky if (++time >= (1000 / hz)) { 87246145Shselasky time = 0; 88246145Shselasky callout_process(1); 89246145Shselasky } 90246145Shselasky } 91246145Shselasky 92246145Shselasky usb_uninit(); 93246145Shselasky 94246145Shselasky return (0); 95246145Shselasky} 96