Some USB debug output (packet dump) changes

- rewrite of usb_dump_packet(), execute code only if debug output is enabled.
- OHCI: removed packet dump, it should be done in the devices code if necessary.
This commit is contained in:
Volker Ruppert 2015-09-06 06:54:07 +00:00
parent a536aa8286
commit 6dbd4c37a9
2 changed files with 14 additions and 28 deletions

View File

@ -232,20 +232,21 @@ void bx_usb_devctl_c::usb_send_msg(void *dev, int msg)
// Dumps the contents of a buffer to the log file
void usb_device_c::usb_dump_packet(Bit8u *data, unsigned size)
{
char the_packet[256], str[16];
strcpy(the_packet, "Packet contents (in hex):");
unsigned offset = 0;
for (unsigned p=0; p<size; p++) {
if (!(p & 0x0F)) {
BX_DEBUG(("%s", the_packet));
sprintf(the_packet, " 0x%04X ", offset);
offset += 16;
char buf_str[1025], temp_str[17];
if (getonoff(LOGLEV_DEBUG) == ACT_REPORT) {
BX_DEBUG(("packet hexdump (%i bytes)", size));
buf_str[0] = 0;
for (unsigned i = 0; i < size; i++) {
sprintf(temp_str, "%02X ", data[i]);
strcat(buf_str, temp_str);
if ((i % 16) == 15) {
BX_DEBUG(("%s", buf_str));
buf_str[0] = 0;
}
}
sprintf(str, " %02X", data[p]);
strcat(the_packet, str);
if (strlen(buf_str) > 0) BX_DEBUG(("%s", buf_str));
}
if (strlen(the_packet))
BX_DEBUG(("%s", the_packet));
}
int usb_device_c::set_usb_string(Bit8u *buf, const char *str)

View File

@ -1187,8 +1187,7 @@ void bx_usb_ohci_c::process_ed(struct OHCI_ED *ed, const Bit32u ed_address)
bx_bool bx_usb_ohci_c::process_td(struct OHCI_TD *td, struct OHCI_ED *ed)
{
unsigned pid = 0, len = 0, len1, len2;
int ilen, r, ret = 0;
char buf_str[1025], temp_str[17];
int ilen, ret = 0;
// The td->cc field should be 111x if it hasn't been processed yet.
if (TD_GET_CC(td) < NotAccessed) {
@ -1278,20 +1277,6 @@ bx_bool bx_usb_ohci_c::process_td(struct OHCI_TD *td, struct OHCI_ED *ed)
if (ret == USB_RET_ASYNC) {
BX_ERROR(("Async packet handling not implemented yet"));
}
// print the buffer used, to the log file
if (ret > 0) {
BX_DEBUG(("buffer dump (%i bytes)", ret));
buf_str[0] = 0;
for (r=0; r<ret; r++) {
sprintf(temp_str, "%02X ", device_buffer[r]);
strcat(buf_str, temp_str);
if ((r % 16) == 15) {
BX_DEBUG(("%s", buf_str));
buf_str[0] = 0;
}
}
if (strlen(buf_str) > 0) BX_DEBUG(("%s", buf_str));
}
if ((ret == (int)len) || ((pid == USB_TOKEN_IN) && (ret >= 0) &&
TD_GET_R(td)) || ((pid == USB_TOKEN_OUT) && (ret >= 0) &&