mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2024-12-29 13:03:36 +01:00
usb: hide USB_LOG() behind a compile-time debug option
This commit is contained in:
parent
3192078c4c
commit
feb74a38ec
8 changed files with 40 additions and 26 deletions
|
@ -9,6 +9,7 @@ include(Fxconv)
|
||||||
option(GINT_NO_OS_STACK "Do not use the OS stack as a memory pool (fx-CG only)")
|
option(GINT_NO_OS_STACK "Do not use the OS stack as a memory pool (fx-CG only)")
|
||||||
option(GINT_STATIC_GRAY "Use static memory instead of malloc for gray buffers (fx-9860G only)")
|
option(GINT_STATIC_GRAY "Use static memory instead of malloc for gray buffers (fx-9860G only)")
|
||||||
option(GINT_KMALLOC_DEBUG "Enable debug functions for kmalloc")
|
option(GINT_KMALLOC_DEBUG "Enable debug functions for kmalloc")
|
||||||
|
option(GINT_USB_DEBUG "Enable debug functions for the USB driver")
|
||||||
|
|
||||||
set(CMAKE_INSTALL_MESSAGE LAZY)
|
set(CMAKE_INSTALL_MESSAGE LAZY)
|
||||||
|
|
||||||
|
|
|
@ -38,4 +38,7 @@
|
||||||
enabled or disabled at runtime. */
|
enabled or disabled at runtime. */
|
||||||
#cmakedefine GINT_KMALLOC_DEBUG
|
#cmakedefine GINT_KMALLOC_DEBUG
|
||||||
|
|
||||||
|
/* GINT_USB_DEBUG: Selects whether USB debug functions are enabled */
|
||||||
|
#cmakedefine GINT_USB_DEBUG
|
||||||
|
|
||||||
#endif /* GINT_CONFIG */
|
#endif /* GINT_CONFIG */
|
||||||
|
|
|
@ -12,6 +12,7 @@ extern "C" {
|
||||||
#include <gint/defs/types.h>
|
#include <gint/defs/types.h>
|
||||||
#include <gint/defs/timeout.h>
|
#include <gint/defs/timeout.h>
|
||||||
#include <gint/gint.h>
|
#include <gint/gint.h>
|
||||||
|
#include <gint/config.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
|
|
||||||
|
@ -271,6 +272,9 @@ int usb_commit_async(int pipe, gint_call_t callback);
|
||||||
// USB debugging log
|
// USB debugging log
|
||||||
//---
|
//---
|
||||||
|
|
||||||
|
#ifdef GINT_USB_DEBUG
|
||||||
|
#define USB_LOG(...) usb_log(__VA_ARGS__)
|
||||||
|
|
||||||
/* usb_set_log(): Set the logging function for the USB driver
|
/* usb_set_log(): Set the logging function for the USB driver
|
||||||
|
|
||||||
The USB driver can produce logs, which are mostly useful to troubleshoot
|
The USB driver can produce logs, which are mostly useful to troubleshoot
|
||||||
|
@ -284,6 +288,10 @@ void usb_set_log(void (*logger)(char const *format, va_list args));
|
||||||
/* usb_log(): Send a message to the USB log */
|
/* usb_log(): Send a message to the USB log */
|
||||||
void usb_log(char const *format, ...);
|
void usb_log(char const *format, ...);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define USB_LOG(...) do {} while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
//---
|
//---
|
||||||
// Standard descriptors
|
// Standard descriptors
|
||||||
//---
|
//---
|
||||||
|
|
|
@ -177,25 +177,27 @@ int usb_configure_solve(usb_interface_t const **interfaces)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* usb_configure_log(): Print configuration results in the usb_log() */
|
/* usb_configure_log(): Print configuration results in the USB_LOG() */
|
||||||
void usb_configure_log(void)
|
void usb_configure_log(void)
|
||||||
{
|
{
|
||||||
|
#ifdef GINT_USB_DEBUG
|
||||||
/* Log the final configuration */
|
/* Log the final configuration */
|
||||||
for(int i = 0; i < 16 && conf_if[i]; i++)
|
for(int i = 0; i < 16 && conf_if[i]; i++)
|
||||||
usb_log("Interface #%d: %p\n", i, conf_if[i]);
|
USB_LOG("Interface #%d: %p\n", i, conf_if[i]);
|
||||||
|
|
||||||
for(int i = 0; i < 32; i++)
|
for(int i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
if(!conf_ep[i].intf) continue;
|
if(!conf_ep[i].intf) continue;
|
||||||
|
|
||||||
endpoint_t *ep = &conf_ep[i];
|
endpoint_t *ep = &conf_ep[i];
|
||||||
usb_log("Endpoint %02x\n",
|
USB_LOG("Endpoint %02x\n",
|
||||||
(i & 15) + (i >= 16 ? 0x80 : 0));
|
(i & 15) + (i >= 16 ? 0x80 : 0));
|
||||||
usb_log(" Interface %p address %02x\n",
|
USB_LOG(" Interface %p address %02x\n",
|
||||||
ep->intf, ep->dc->bEndpointAddress);
|
ep->intf, ep->dc->bEndpointAddress);
|
||||||
usb_log(" Pipe %d (FIFO: %02x..%02x)\n",
|
USB_LOG(" Pipe %d (FIFO: %02x..%02x)\n",
|
||||||
ep->pipe, ep->bufnmb, ep->bufnmb + ep->bufsize);
|
ep->pipe, ep->bufnmb, ep->bufnmb + ep->bufsize);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* usb_configure(): Load the generated configuration to the USB module */
|
/* usb_configure(): Load the generated configuration to the USB module */
|
||||||
|
|
|
@ -76,7 +76,7 @@ static fifo_t fifo_access(int pipe)
|
||||||
if(pipe == 0) return CF;
|
if(pipe == 0) return CF;
|
||||||
/* Find a free controller */
|
/* Find a free controller */
|
||||||
if(USB.D0FIFOSEL.CURPIPE == 0) return D0F;
|
if(USB.D0FIFOSEL.CURPIPE == 0) return D0F;
|
||||||
usb_log("Wait D0 is unavailable\n");
|
USB_LOG("Wait D0 is unavailable\n");
|
||||||
if(USB.D1FIFOSEL.CURPIPE == 0) return D1F;
|
if(USB.D1FIFOSEL.CURPIPE == 0) return D1F;
|
||||||
|
|
||||||
return NOF;
|
return NOF;
|
||||||
|
@ -295,7 +295,7 @@ static void write_round(struct transfer volatile *t, int pipe)
|
||||||
|
|
||||||
bool ok = dma_transfer_async(channel, block_size, size,
|
bool ok = dma_transfer_async(channel, block_size, size,
|
||||||
t->data, DMA_INC, (void *)FIFO, DMA_FIXED, callback);
|
t->data, DMA_INC, (void *)FIFO, DMA_FIXED, callback);
|
||||||
if(!ok) usb_log("DMA async failed on channel %d!\n", channel);
|
if(!ok) USB_LOG("DMA async failed on channel %d!\n", channel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -349,7 +349,7 @@ int usb_write_sync_timeout(int pipe, void const *data, int size, int unit_size,
|
||||||
if(rc == 0)
|
if(rc == 0)
|
||||||
break;
|
break;
|
||||||
if(rc == USB_WRITE_NOFIFO)
|
if(rc == USB_WRITE_NOFIFO)
|
||||||
usb_log("USB_WRITE_NOFIFO\n");
|
USB_LOG("USB_WRITE_NOFIFO\n");
|
||||||
if(rc != USB_WRITE_BUSY)
|
if(rc != USB_WRITE_BUSY)
|
||||||
return rc;
|
return rc;
|
||||||
if(timeout_elapsed(timeout))
|
if(timeout_elapsed(timeout))
|
||||||
|
@ -401,7 +401,7 @@ int usb_commit_async(int pipe, gint_call_t callback)
|
||||||
fifo_bind(t->ct, pipe, FIFO_WRITE, t->unit_size);
|
fifo_bind(t->ct, pipe, FIFO_WRITE, t->unit_size);
|
||||||
if(t->ct == D0F) USB.D0FIFOCTR.BVAL = 1;
|
if(t->ct == D0F) USB.D0FIFOCTR.BVAL = 1;
|
||||||
if(t->ct == D1F) USB.D1FIFOCTR.BVAL = 1;
|
if(t->ct == D1F) USB.D1FIFOCTR.BVAL = 1;
|
||||||
usb_log("[PIPE%d] Committed transfer\n", pipe);
|
USB_LOG("[PIPE%d] Committed transfer\n", pipe);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ static void write_configuration_descriptor(int wLength)
|
||||||
uint8_t const *dc = interfaces[i]->dc[k];
|
uint8_t const *dc = interfaces[i]->dc[k];
|
||||||
total_length += dc[0];
|
total_length += dc[0];
|
||||||
}
|
}
|
||||||
usb_log("Configuration descriptor size: %d\n", (int)total_length);
|
USB_LOG("Configuration descriptor size: %d\n", (int)total_length);
|
||||||
|
|
||||||
/* Write the configuration descriptor */
|
/* Write the configuration descriptor */
|
||||||
dc_configuration.wTotalLength = htole16(total_length);
|
dc_configuration.wTotalLength = htole16(total_length);
|
||||||
|
@ -127,9 +127,9 @@ static void req_get_descriptor(int wValue, int wLength)
|
||||||
int type = (wValue >> 8) & 0xff;
|
int type = (wValue >> 8) & 0xff;
|
||||||
int num = (wValue & 0xff);
|
int num = (wValue & 0xff);
|
||||||
|
|
||||||
static char const *strs[] = {
|
GUNUSED static char const *strs[] = {
|
||||||
"DEV","CONFIG","STR","INTF","ENDP","DEVQ","OSC","POWER" };
|
"DEV","CONFIG","STR","INTF","ENDP","DEVQ","OSC","POWER" };
|
||||||
usb_log("GET_DESCRIPTOR: %s #%d len:%d\n", strs[type-1], num, wLength);
|
USB_LOG("GET_DESCRIPTOR: %s #%d len:%d\n", strs[type-1], num, wLength);
|
||||||
|
|
||||||
if(type == USB_DC_DEVICE && num == 0)
|
if(type == USB_DC_DEVICE && num == 0)
|
||||||
dcp_write(&dc_device, dc_device.bLength);
|
dcp_write(&dc_device, dc_device.bLength);
|
||||||
|
@ -150,13 +150,13 @@ static void req_get_descriptor(int wValue, int wLength)
|
||||||
|
|
||||||
static void req_get_configuration(void)
|
static void req_get_configuration(void)
|
||||||
{
|
{
|
||||||
usb_log("GET_CONFIGURATION -> %d\n", 1);
|
USB_LOG("GET_CONFIGURATION -> %d\n", 1);
|
||||||
dcp_write("\x01", 1);
|
dcp_write("\x01", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void req_set_configuration(int wValue)
|
static void req_set_configuration(int wValue)
|
||||||
{
|
{
|
||||||
usb_log("SET_CONFIGURATION: %d\n", wValue);
|
USB_LOG("SET_CONFIGURATION: %d\n", wValue);
|
||||||
/* Ok for (wValue == 1) only */
|
/* Ok for (wValue == 1) only */
|
||||||
USB.DCPCTR.PID = (wValue == 1) ? 1 : 2;
|
USB.DCPCTR.PID = (wValue == 1) ? 1 : 2;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ void usb_req_setup(void)
|
||||||
int bRequest = USB.USBREQ.BREQUEST;
|
int bRequest = USB.USBREQ.BREQUEST;
|
||||||
int bmRequestType = USB.USBREQ.BMREQUEST;
|
int bmRequestType = USB.USBREQ.BMREQUEST;
|
||||||
int wValue = USB.USBVAL.word;
|
int wValue = USB.USBVAL.word;
|
||||||
int wIndex = USB.USBINDX.word;
|
GUNUSED int wIndex = USB.USBINDX.word;
|
||||||
int wLength = USB.USBLENG.word;
|
int wLength = USB.USBLENG.word;
|
||||||
|
|
||||||
USB.INTSTS0.VALID = 0;
|
USB.INTSTS0.VALID = 0;
|
||||||
|
@ -185,7 +185,7 @@ void usb_req_setup(void)
|
||||||
req_set_configuration(wValue);
|
req_set_configuration(wValue);
|
||||||
|
|
||||||
/* TODO: Other standard SETUP requests */
|
/* TODO: Other standard SETUP requests */
|
||||||
else usb_log("SETUP: bRequest=%02x bmRequestType=%02x wValue=%04x\n"
|
else USB_LOG("SETUP: bRequest=%02x bmRequestType=%02x wValue=%04x\n"
|
||||||
" wIndex=%04x wLength=%d -> ???\n",
|
" wIndex=%04x wLength=%d -> ???\n",
|
||||||
bRequest, bmRequestType, wValue, wIndex, wLength);
|
bRequest, bmRequestType, wValue, wIndex, wLength);
|
||||||
|
|
||||||
|
|
|
@ -111,14 +111,14 @@ static void hpoweroff(void)
|
||||||
|
|
||||||
int usb_open(usb_interface_t const **interfaces, gint_call_t callback)
|
int usb_open(usb_interface_t const **interfaces, gint_call_t callback)
|
||||||
{
|
{
|
||||||
usb_log("---- usb_open ----\n");
|
USB_LOG("---- usb_open ----\n");
|
||||||
|
|
||||||
int rc = usb_configure_solve(interfaces);
|
int rc = usb_configure_solve(interfaces);
|
||||||
usb_configure_log();
|
usb_configure_log();
|
||||||
|
|
||||||
if(rc != 0)
|
if(rc != 0)
|
||||||
{
|
{
|
||||||
usb_log("configure failure: %d\n", rc);
|
USB_LOG("configure failure: %d\n", rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ void usb_close(void)
|
||||||
{
|
{
|
||||||
intc_priority(INTC_USB, 0);
|
intc_priority(INTC_USB, 0);
|
||||||
hpoweroff();
|
hpoweroff();
|
||||||
usb_log("---- usb_close ----\n");
|
USB_LOG("---- usb_close ----\n");
|
||||||
|
|
||||||
usb_open_callback = GINT_CALL_NULL;
|
usb_open_callback = GINT_CALL_NULL;
|
||||||
usb_open_status = false;
|
usb_open_status = false;
|
||||||
|
@ -201,7 +201,7 @@ void usb_close(void)
|
||||||
|
|
||||||
static void usb_interrupt_handler(void)
|
static void usb_interrupt_handler(void)
|
||||||
{
|
{
|
||||||
static char const * const device_st[] = {
|
GUNUSED static char const * const device_st[] = {
|
||||||
"powered", "default", "address", "configured",
|
"powered", "default", "address", "configured",
|
||||||
"suspended-powered", "suspended-default", "suspended-address",
|
"suspended-powered", "suspended-default", "suspended-address",
|
||||||
"suspended-configured",
|
"suspended-configured",
|
||||||
|
@ -212,7 +212,7 @@ static void usb_interrupt_handler(void)
|
||||||
if(USB.INTSTS0.VBINT)
|
if(USB.INTSTS0.VBINT)
|
||||||
{
|
{
|
||||||
INTSTS0_clear(VBINT);
|
INTSTS0_clear(VBINT);
|
||||||
usb_log("VBUS %s\n", USB.INTSTS0.VBSTS ? "up" : "down");
|
USB_LOG("VBUS %s\n", USB.INTSTS0.VBSTS ? "up" : "down");
|
||||||
}
|
}
|
||||||
else if(USB.INTSTS0.CTRT)
|
else if(USB.INTSTS0.CTRT)
|
||||||
{
|
{
|
||||||
|
@ -222,9 +222,9 @@ static void usb_interrupt_handler(void)
|
||||||
else if(USB.INTSTS0.DVST)
|
else if(USB.INTSTS0.DVST)
|
||||||
{
|
{
|
||||||
INTSTS0_clear(DVST);
|
INTSTS0_clear(DVST);
|
||||||
usb_log("DVST %s", device_st[USB.INTSTS0.DVSQ]);
|
USB_LOG("DVST %s", device_st[USB.INTSTS0.DVSQ]);
|
||||||
if(USB.INTSTS0.DVSQ == 2) usb_log(": %04x\n",USB.USBADDR.word);
|
if(USB.INTSTS0.DVSQ == 2) USB_LOG(": %04x\n",USB.USBADDR.word);
|
||||||
else usb_log("\n");
|
else USB_LOG("\n");
|
||||||
|
|
||||||
/* When configured, run the callback for usb_open() */
|
/* When configured, run the callback for usb_open() */
|
||||||
if(USB.INTSTS0.DVSQ == 3)
|
if(USB.INTSTS0.DVSQ == 3)
|
||||||
|
@ -248,7 +248,7 @@ static void usb_interrupt_handler(void)
|
||||||
if(status & (1 << i)) usb_pipe_write_bemp(i);
|
if(status & (1 << i)) usb_pipe_write_bemp(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else usb_log("<%04X> -> ???\n", USB.INTSTS0.word);
|
else USB_LOG("<%04X> -> ???\n", USB.INTSTS0.word);
|
||||||
|
|
||||||
/* Restore PIPESEL which can have been used for transfers */
|
/* Restore PIPESEL which can have been used for transfers */
|
||||||
USB.PIPESEL.word = pipesel;
|
USB.PIPESEL.word = pipesel;
|
||||||
|
|
|
@ -131,7 +131,7 @@ void usb_pipe_init_transfers(void);
|
||||||
GINT_CALL_SET_STOP(&__f)); \
|
GINT_CALL_SET_STOP(&__f)); \
|
||||||
if(__t >= 0) timer_start(__t); \
|
if(__t >= 0) timer_start(__t); \
|
||||||
while((condition) && __f == 0) {} \
|
while((condition) && __f == 0) {} \
|
||||||
if(__f) usb_log("%s: %d: (" #condition ") holds\n", \
|
if(__f) USB_LOG("%s: %d: (" #condition ") holds\n", \
|
||||||
__FUNCTION__, __LINE__); \
|
__FUNCTION__, __LINE__); \
|
||||||
if(__t >= 0) timer_stop(__t); \
|
if(__t >= 0) timer_stop(__t); \
|
||||||
__f != 0; \
|
__f != 0; \
|
||||||
|
|
Loading…
Reference in a new issue