1f9f848faSopenharmony_ci/*- 2f9f848faSopenharmony_ci * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. 3f9f848faSopenharmony_ci * 4f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 5f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 6f9f848faSopenharmony_ci * are met: 7f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 8f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer. 9f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 10f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 11f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 12f9f848faSopenharmony_ci * 13f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16f9f848faSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23f9f848faSopenharmony_ci * SUCH DAMAGE. 24f9f848faSopenharmony_ci */ 25f9f848faSopenharmony_ci 26f9f848faSopenharmony_ci#include "implementation/global_implementation.h" 27f9f848faSopenharmony_ci 28f9f848faSopenharmony_ci#ifdef LOSCFG_DRIVERS_USB_HOST_DRIVER 29f9f848faSopenharmony_ciextern volatile uint8_t g_device_is_ready; 30f9f848faSopenharmony_ci#endif 31f9f848faSopenharmony_ci 32f9f848faSopenharmony_ci#undef USB_DEBUG_VAR 33f9f848faSopenharmony_ci#define USB_DEBUG_VAR usb_debug 34f9f848faSopenharmony_ci 35f9f848faSopenharmony_ci/*------------------------------------------------------------------------* 36f9f848faSopenharmony_ci * Implementation of mutex API 37f9f848faSopenharmony_ci *------------------------------------------------------------------------*/ 38f9f848faSopenharmony_ci 39f9f848faSopenharmony_cistruct mtx Giant = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; 40f9f848faSopenharmony_cistruct mtx Gcall = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; 41f9f848faSopenharmony_ci 42f9f848faSopenharmony_ci/*------------------------------------------------------------------------* 43f9f848faSopenharmony_ci * Implementation of device API 44f9f848faSopenharmony_ci *------------------------------------------------------------------------*/ 45f9f848faSopenharmony_ci 46f9f848faSopenharmony_ci#ifdef LOSCFG_USB_DEBUG 47f9f848faSopenharmony_cistatic uint8_t 48f9f848faSopenharmony_cidevclass_equal(const char *a, const char *b) 49f9f848faSopenharmony_ci{ 50f9f848faSopenharmony_ci char ta, tb; 51f9f848faSopenharmony_ci 52f9f848faSopenharmony_ci if (a == b) 53f9f848faSopenharmony_ci return (1); 54f9f848faSopenharmony_ci if(!a || !b) 55f9f848faSopenharmony_ci return (0); 56f9f848faSopenharmony_ci while (1) { 57f9f848faSopenharmony_ci ta = *a; 58f9f848faSopenharmony_ci tb = *b; 59f9f848faSopenharmony_ci if (ta != tb) 60f9f848faSopenharmony_ci return (0); 61f9f848faSopenharmony_ci if (ta == 0) 62f9f848faSopenharmony_ci break; 63f9f848faSopenharmony_ci a++; 64f9f848faSopenharmony_ci b++; 65f9f848faSopenharmony_ci } 66f9f848faSopenharmony_ci return (1); 67f9f848faSopenharmony_ci} 68f9f848faSopenharmony_ci 69f9f848faSopenharmony_cistatic TAILQ_HEAD(, debug_module_data) debug_module_head = 70f9f848faSopenharmony_ci TAILQ_HEAD_INITIALIZER(debug_module_head); 71f9f848faSopenharmony_ci 72f9f848faSopenharmony_civoid 73f9f848faSopenharmony_cidebug_module_register(void *data) 74f9f848faSopenharmony_ci{ 75f9f848faSopenharmony_ci struct debug_module_data *mdata = data; 76f9f848faSopenharmony_ci TAILQ_INSERT_TAIL(&debug_module_head, mdata, entry); 77f9f848faSopenharmony_ci} 78f9f848faSopenharmony_ci 79f9f848faSopenharmony_civoid 80f9f848faSopenharmony_cidebug_module_unregister(void *data) 81f9f848faSopenharmony_ci{ 82f9f848faSopenharmony_ci struct debug_module_data *mdata = data; 83f9f848faSopenharmony_ci TAILQ_REMOVE(&debug_module_head, mdata, entry); 84f9f848faSopenharmony_ci} 85f9f848faSopenharmony_ci 86f9f848faSopenharmony_cistruct debug_module_data * 87f9f848faSopenharmony_ciget_debug_module(const char *modname) 88f9f848faSopenharmony_ci{ 89f9f848faSopenharmony_ci static struct debug_module_data *mod; 90f9f848faSopenharmony_ci 91f9f848faSopenharmony_ci TAILQ_FOREACH(mod, &debug_module_head, entry) { 92f9f848faSopenharmony_ci if (devclass_equal(mod->mod_name, modname)) { 93f9f848faSopenharmony_ci return (mod); 94f9f848faSopenharmony_ci } 95f9f848faSopenharmony_ci } 96f9f848faSopenharmony_ci return (NULL); 97f9f848faSopenharmony_ci} 98f9f848faSopenharmony_ci 99f9f848faSopenharmony_civoid 100f9f848faSopenharmony_cidebug_module_dump(void) 101f9f848faSopenharmony_ci{ 102f9f848faSopenharmony_ci const struct debug_module_data *mod; 103f9f848faSopenharmony_ci 104f9f848faSopenharmony_ci TAILQ_FOREACH(mod, &debug_module_head, entry) { 105f9f848faSopenharmony_ci PRINTK("%s\n", mod->mod_name); 106f9f848faSopenharmony_ci } 107f9f848faSopenharmony_ci} 108f9f848faSopenharmony_ci#endif 109f9f848faSopenharmony_ci#undef USB_DEBUG_VAR 110