From 392d6af30057db0b36ae02e5ca940691c382fd23 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Mon, 30 Sep 2019 18:33:46 -0300 Subject: USBH: rework debug framework --- os/hal/include/hal_usbh.h | 40 +++++++-- os/hal/include/usbh/debug.h | 49 +++++++++-- os/hal/include/usbh/debug_helpers.h | 163 ++++++++++++++++++++++++++++++++++++ os/hal/include/usbh/dev/uvc.h | 4 +- 4 files changed, 240 insertions(+), 16 deletions(-) create mode 100644 os/hal/include/usbh/debug_helpers.h (limited to 'os/hal/include') diff --git a/os/hal/include/hal_usbh.h b/os/hal/include/hal_usbh.h index aa49205..6e83a44 100644 --- a/os/hal/include/hal_usbh.h +++ b/os/hal/include/hal_usbh.h @@ -242,6 +242,31 @@ struct usbh_port { _usbh_port_ll_data }; + +#if USBH_DEBUG_ENABLE +struct usbh_dq { + int rem; + int sz; + uint8_t *first; + uint8_t *next; + uint8_t *start; + uint8_t *end; +}; + +typedef struct usbh_dq usbh_dq_t; + +struct usbh_debug_helper { + uint8_t buff[USBH_DEBUG_BUFFER]; + THD_WORKING_AREA(thd_wa, 512); + usbh_dq_t dq; + systime_t first; + systime_t last; + bool ena; + bool on; + thread_reference_t tr; +}; +#endif + struct USBHDriver { usbh_status_t status; uint8_t address_bitmap[(USBH_MAX_ADDRESSES + 7) / 8]; @@ -255,15 +280,16 @@ struct USBHDriver { /* Low level part */ _usbhdriver_ll_data -#if USBH_DEBUG_ENABLE +#if USBH_DEBUG_ENABLE && USBH_DEBUG_MULTI_HOST /* debug */ - uint8_t dbg_buff[USBH_DEBUG_BUFFER]; - THD_WORKING_AREA(waDebug, 512); - input_queue_t iq; + struct usbh_debug_helper debug; #endif }; - +#if USBH_DEBUG_ENABLE && !USBH_DEBUG_MULTI_HOST +/* debug */ +extern struct usbh_debug_helper usbh_debug; +#endif /*===========================================================================*/ /* External declarations. */ @@ -289,10 +315,10 @@ extern "C" { /* Device-related */ #if USBH_DEBUG_ENABLE && USBH_DEBUG_ENABLE_INFO void usbhDevicePrintInfo(usbh_device_t *dev); - void usbhDevicePrintConfiguration(const uint8_t *descriptor, uint16_t rem); + void usbhDevicePrintConfiguration(const usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem); #else # define usbhDevicePrintInfo(dev) do {} while(0) -# define usbhDevicePrintConfiguration(descriptor, rem) do {} while(0) +# define usbhDevicePrintConfiguration(dev, descriptor, rem) do {} while(0) #endif bool usbhDeviceReadString(usbh_device_t *dev, char *dest, uint8_t size, uint8_t index, uint16_t langID); diff --git a/os/hal/include/usbh/debug.h b/os/hal/include/usbh/debug.h index 41319b9..f90a11a 100644 --- a/os/hal/include/usbh/debug.h +++ b/os/hal/include/usbh/debug.h @@ -24,18 +24,53 @@ #if HAL_USE_USBH #if USBH_DEBUG_ENABLE +#if USBH_DEBUG_MULTI_HOST + /* output callback */ + void USBH_DEBUG_OUTPUT_CALLBACK(USBHDriver *host, const uint8_t *buff, size_t len); + + /* printing functions */ + void usbDbgPrintf(USBHDriver *host, const char *fmt, ...); + void usbDbgPuts(USBHDriver *host, const char *s); + void usbDbgInit(USBHDriver *host); +#else + /* output callback */ + void USBH_DEBUG_OUTPUT_CALLBACK(const uint8_t *buff, size_t len); + + /* printing functions */ void usbDbgPrintf(const char *fmt, ...); void usbDbgPuts(const char *s); - void usbDbgInit(USBHDriver *host); + void usbDbgInit(void); +#endif + void usbDbgReset(void); - void usbDbgSystemHalted(void); #else -#define usbDbgPrintf(fmt, ...) do {} while(0) -#define usbDbgPuts(s) do {} while(0) -#define usbDbgInit(host) do {} while(0) -#define usbDbgReset() do {} while(0) -#define usbDbgSystemHalted() do {} while(0) + +#if USBH_DEBUG_MULTI_HOST +# define usbDbgPrintf(host, fmt, ...) do {} while(0) +# define usbDbgPuts(host, s) do {} while(0) +# define usbDbgInit(host) do {} while(0) +#else +# define usbDbgPrintf(fmt, ...) do {} while(0) +# define usbDbgPuts(s) do {} while(0) +# define usbDbgInit() do {} while(0) +#endif +# define usbDbgReset() do {} while(0) +#endif + +#if USBH_DEBUG_MULTI_HOST +#define _usbh_dbg(host, s) usbDbgPuts(host, s) +#define _usbh_dbgf(host, f, ...) usbDbgPrintf(host, f, ##__VA_ARGS__) +#define _usbh_ldbg(host, lvl, n, s) do {if (lvl >= n) usbDbgPuts(host, s); } while(0) +#define _usbh_ldbgf(host, lvl, n, f, ...) do {if (lvl >= n) usbDbgPrintf(host, f, ##__VA_ARGS__); } while(0) +#else + +#define _usbh_dbg(host, s) usbDbgPuts(s) +#define _usbh_dbgf(host, f, ...) usbDbgPrintf(f, ##__VA_ARGS__) +#define _usbh_ldbg(host, lvl, n, s) do {if (lvl >= n) usbDbgPuts(s); } while(0) +#define _usbh_ldbgf(host, lvl, n, f, ...) do {if (lvl >= n) usbDbgPrintf(f, ##__VA_ARGS__); } while(0) + #endif + #endif diff --git a/os/hal/include/usbh/debug_helpers.h b/os/hal/include/usbh/debug_helpers.h new file mode 100644 index 0000000..b09bd0a --- /dev/null +++ b/os/hal/include/usbh/debug_helpers.h @@ -0,0 +1,163 @@ +#ifndef USBH_INTERNAL_H_ +#error "Internal use only" +#endif + +#ifndef _USBH_DEBUG_HELPER_ENABLE_TRACE +#error "_USBH_DEBUG_HELPER_ENABLE_TRACE must be set" +#endif +#ifndef _USBH_DEBUG_HELPER_ENABLE_INFO +#error "_USBH_DEBUG_HELPER_ENABLE_INFO must be set" +#endif +#ifndef _USBH_DEBUG_HELPER_ENABLE_WARNINGS +#error "_USBH_DEBUG_HELPER_ENABLE_WARNINGS must be set" +#endif +#ifndef _USBH_DEBUG_HELPER_ENABLE_ERRORS +#error "_USBH_DEBUG_HELPER_ENABLE_ERRORS must be set" +#endif + +#define _usbh_dbg_host(s) _usbh_dbg(host, s) +#define _usbh_dbg_port(s) _usbh_dbg(port->device.host, s) +#define _usbh_dbg_dev(s) _usbh_dbg(dev->host, s) +#define _usbh_dbg_ep(lvl, s) _usbh_ldbg(ep->device->host, ep->trace_level, lvl, s) +#define _usbh_dbg_urb(lvl, s) _usbh_ldbg(urb->ep->device->host, urb->ep->trace_level, lvl, s) + +#define _usbh_dbgf_host(f, ...) _usbh_dbgf(host, f, ##__VA_ARGS__) +#define _usbh_dbgf_port(f, ...) _usbh_dbgf(port->device.host, f, ##__VA_ARGS__) +#define _usbh_dbgf_dev(f, ...) _usbh_dbgf(dev->host, f, ##__VA_ARGS__) +#define _usbh_dbgf_ep(f, lvl, ...) _usbh_ldbgf(ep->device->host, ep->trace_level, lvl, "\t%s: " f, ep->name, ##__VA_ARGS__) +#define _usbh_dbgf_urb(f, lvl, ...) _usbh_ldbgf(urb->ep->device->host, urb->ep->trace_level, lvl, "\t%s: " f, urb->ep->name, ##__VA_ARGS__) + +#if defined(_USBH_DEBUG_HELPER_CLASS_DRIVER) +#define _usbh_dbg_classdrv(drv, s) _usbh_dbg(drv->dev->host, s) +#define _usbh_dbgf_classdrv(drv, f, ...) _usbh_dbgf(drv->dev->host, f, ##__VA_ARGS__) +#endif + +#define _usbh_dbg_dummy do {} while(0) + +#if _USBH_DEBUG_HELPER_ENABLE_TRACE +#define udbg(s) _usbh_dbg_host(s) +#define uportdbg(s) _usbh_dbg_port(s) +#define udevdbg(s) _usbh_dbg_dev(s) +#define uepdbg(s) _usbh_dbg_ep(4, s) +#define uurbdbg(s) _usbh_dbg_urb(4, s) +#define udbgf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__) +#define uportdbgf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__) +#define udevdbgf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__) +#define uepdbgf(f, ...) _usbh_dbgf_ep(f, 4, ##__VA_ARGS__) +#define uurbdbgf(f, ...) _usbh_dbgf_urb(f, 4, ##__VA_ARGS__) +#else +#define udbg(s) _usbh_dbg_dummy +#define uportdbg(s) _usbh_dbg_dummy +#define udevdbg(s) _usbh_dbg_dummy +#define uurbdbg(s) _usbh_dbg_dummy +#define uepdbg(s) _usbh_dbg_dummy +#define udbgf(f, ...) _usbh_dbg_dummy +#define uportdbgf(f, ...) _usbh_dbg_dummy +#define udevdbgf(f, ...) _usbh_dbg_dummy +#define uepdbgf(f, ...) _usbh_dbg_dummy +#define uurbdbgf(f, ...) _usbh_dbg_dummy +#endif + +#if _USBH_DEBUG_HELPER_ENABLE_INFO +#define uinfo(s) _usbh_dbg_host(s) +#define uportinfo(s) _usbh_dbg_port(s) +#define udevinfo(s) _usbh_dbg_dev(s) +#define uepinfo(s) _usbh_dbg_ep(3, s) +#define uurbinfo(s) _usbh_dbg_urb(3, s) +#define uinfof(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__) +#define uportinfof(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__) +#define udevinfof(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__) +#define uepinfof(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__) +#define uurbinfof(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__) +#else +#define uinfo(s) _usbh_dbg_dummy +#define udevinfo(s) _usbh_dbg_dummy +#define uportinfo(s) _usbh_dbg_dummy +#define uepinfo(s) _usbh_dbg_dummy +#define uurbinfo(s) _usbh_dbg_dummy +#define uinfof(f, ...) _usbh_dbg_dummy +#define uportinfof(f, ...) _usbh_dbg_dummy +#define udevinfof(f, ...) _usbh_dbg_dummy +#define uepinfof(f, ...) _usbh_dbg_dummy +#define uurbinfof(f, ...) _usbh_dbg_dummy +#endif + +#if _USBH_DEBUG_HELPER_ENABLE_WARNINGS +#define uwarn(s) _usbh_dbg_host(s) +#define uportwarn(s) _usbh_dbg_port(s) +#define udevwarn(s) _usbh_dbg_dev(s) +#define uepwarn(s) _usbh_dbg_ep(3, s) +#define uurbwarn(s) _usbh_dbg_urb(3, s) +#define uwarnf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__) +#define uportwarnf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__) +#define udevwarnf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__) +#define uepwarnf(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__) +#define uurbwarnf(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__) +#else +#define uwarn(s) _usbh_dbg_dummy +#define udevwarn(s) _usbh_dbg_dummy +#define uportwarn(s) _usbh_dbg_dummy +#define uepwarn(s) _usbh_dbg_dummy +#define uurbwarn(s) _usbh_dbg_dummy +#define uwarnf(f, ...) _usbh_dbg_dummy +#define uportwarnf(f, ...) _usbh_dbg_dummy +#define udevwarnf(f, ...) _usbh_dbg_dummy +#define uepwarnf(f, ...) _usbh_dbg_dummy +#define uurbwarnf(f, ...) _usbh_dbg_dummy +#endif + + +#if _USBH_DEBUG_HELPER_ENABLE_ERRORS +#define uerr(s) _usbh_dbg_host(s) +#define uporterr(s) _usbh_dbg_port(s) +#define udeverr(s) _usbh_dbg_dev(s) +#define ueperr(s) _usbh_dbg_ep(3, s) +#define uurberr(s) _usbh_dbg_urb(3, s) +#define uerrf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__) +#define uporterrf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__) +#define udeverrf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__) +#define ueperrf(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__) +#define uurberrf(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__) +#else +#define uerr(s) _usbh_dbg_dummy +#define udeverr(s) _usbh_dbg_dummy +#define uporterr(s) _usbh_dbg_dummy +#define ueperr(s) _usbh_dbg_dummy +#define uurberr(s) _usbh_dbg_dummy +#define uerrf(f, ...) _usbh_dbg_dummy +#define uporterrf(f, ...) _usbh_dbg_dummy +#define udeverrf(f, ...) _usbh_dbg_dummy +#define ueperrf(f, ...) _usbh_dbg_dummy +#define uurberrf(f, ...) _usbh_dbg_dummy +#endif + +#if defined(_USBH_DEBUG_HELPER_CLASS_DRIVER) +#if _USBH_DEBUG_HELPER_ENABLE_TRACE +#define uclassdrvdbg(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s) +#define uclassdrvdbgf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__) +#else +#define uclassdrvdbg(s) _usbh_dbg_dummy +#define uclassdrvdbgf(f, ...) _usbh_dbg_dummy +#endif +#if _USBH_DEBUG_HELPER_ENABLE_INFO +#define uclassdrvinfo(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s) +#define uclassdrvinfof(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__) +#else +#define uclassdrvinfo(s) _usbh_dbg_dummy +#define uclassdrvinfof(f, ...) _usbh_dbg_dummy +#endif +#if _USBH_DEBUG_HELPER_ENABLE_WARNINGS +#define uclassdrvwarn(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s) +#define uclassdrvwarnf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__) +#else +#define uclassdrvwarn(s) _usbh_dbg_dummy +#define uclassdrvwarnf(f, ...) _usbh_dbg_dummy +#endif +#if _USBH_DEBUG_HELPER_ENABLE_ERRORS +#define uclassdrverr(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s) +#define uclassdrverrf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__) +#else +#define uclassdrverr(s) _usbh_dbg_dummy +#define uclassdrverrf(f, ...) _usbh_dbg_dummy +#endif +#endif diff --git a/os/hal/include/usbh/dev/uvc.h b/os/hal/include/usbh/dev/uvc.h index 713d16c..7116c91 100644 --- a/os/hal/include/usbh/dev/uvc.h +++ b/os/hal/include/usbh/dev/uvc.h @@ -408,9 +408,9 @@ extern "C" { const uint8_t *framedesc, uint32_t dwFrameInterval); #if USBH_DEBUG_ENABLE && USBHUVC_DEBUG_ENABLE_INFO - void usbhuvcPrintProbeCommit(const usbh_uvc_ctrl_vs_probecommit_data_t *pc); + void usbhuvcPrintProbeCommit(USBHUVCDriver *uvcdp, const usbh_uvc_ctrl_vs_probecommit_data_t *pc); #else -# define usbhuvcPrintProbeCommit(pc) do {} while(0) +# define usbhuvcPrintProbeCommit(uvcdp, pc) do {} while(0) #endif bool usbhuvcProbe(USBHUVCDriver *uvcdp); bool usbhuvcCommit(USBHUVCDriver *uvcdp); -- cgit v1.2.3 From 77021bb6466f731a572985cebe65d139c212d88d Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Mon, 30 Sep 2019 17:47:30 -0300 Subject: USBH: add helper macros to MSD, FTDI, AOA --- os/hal/include/usbh/dev/aoa.h | 1 + os/hal/include/usbh/dev/ftdi.h | 2 +- os/hal/include/usbh/dev/msd.h | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'os/hal/include') diff --git a/os/hal/include/usbh/dev/aoa.h b/os/hal/include/usbh/dev/aoa.h index 8205dd5..1f36370 100644 --- a/os/hal/include/usbh/dev/aoa.h +++ b/os/hal/include/usbh/dev/aoa.h @@ -130,6 +130,7 @@ typedef bool (*usbhaoa_filter_callback_t)(usbh_device_t *dev, const uint8_t *des #define usbhaoaGetState(aoap) ((aoap)->state) #define usbhaoaGetChannelState(aoap) ((aoap)->channel.state) +#define usbhaoaGetHost(aoap) ((aoap)->dev->host) /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/include/usbh/dev/ftdi.h b/os/hal/include/usbh/dev/ftdi.h index 84ea4bc..fdd767d 100644 --- a/os/hal/include/usbh/dev/ftdi.h +++ b/os/hal/include/usbh/dev/ftdi.h @@ -127,7 +127,7 @@ struct USBHFTDIDriver { /* Driver macros. */ /*===========================================================================*/ #define usbhftdipGetState(ftdipp) ((ftdipp)->state) - +#define usbhftdipGetHost(ftdipp) ((ftdipp)->ftdip->dev->host) /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/include/usbh/dev/msd.h b/os/hal/include/usbh/dev/msd.h index b245bfc..113f523 100644 --- a/os/hal/include/usbh/dev/msd.h +++ b/os/hal/include/usbh/dev/msd.h @@ -72,7 +72,6 @@ struct USBHMassStorageLUNDriver { /* Driver macros. */ /*===========================================================================*/ - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -95,6 +94,8 @@ extern "C" { bool usbhmsdLUNGetInfo(USBHMassStorageLUNDriver *lunp, BlockDeviceInfo *bdip); bool usbhmsdLUNIsInserted(USBHMassStorageLUNDriver *lunp); bool usbhmsdLUNIsProtected(USBHMassStorageLUNDriver *lunp); + + USBHDriver *usbhmsdLUNGetHost(const USBHMassStorageLUNDriver *lunp); #ifdef __cplusplus } #endif -- cgit v1.2.3