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