Path: blob/main/stand/usb/test/bsd_usbloader_test.c
34878 views
/*-1* Copyright (c) 2013 Hans Petter Selasky. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425#include <stdio.h>26#include <stdint.h>27#include <stdlib.h>28#include <time.h>2930extern int usleep(int);31extern void callout_process(int);32extern void usb_idle(void);33extern void usb_init(void);34extern void usb_uninit(void);3536#define hz 10003738#ifdef HAVE_MALLOC39void *40usb_malloc(size_t size)41{42return (malloc(size));43}4445void46usb_free(void *ptr)47{48free(ptr);49}50#endif5152void53DELAY(unsigned int delay)54{55usleep(delay);56}5758void59delay(unsigned int delay)60{61usleep(delay);62}6364int65pause(const char *what, int timeout)66{67if (timeout == 0)68timeout = 1;6970usleep((1000000 / hz) * timeout);7172return (0);73}7475int76main(int argc, char **argv)77{78uint32_t time;7980usb_init();8182time = 0;8384while (1) {8586usb_idle();8788usleep(1000);8990if (++time >= (1000 / hz)) {91time = 0;92callout_process(1);93}94}9596usb_uninit();9798return (0);99}100101102