Type fixes, new debug macro, debug bug fixes.

This commit is contained in:
Andrew J. Kroll 2013-12-18 15:18:28 -05:00
parent 6e70087f0b
commit 5785115cdb
10 changed files with 69 additions and 67 deletions

View file

@ -70,8 +70,8 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
}
}
}
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { // l2cap_control - Channel ID for ACL-U
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);

View file

@ -97,8 +97,8 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
}
}
}
if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000U))) { // acl_handle_ok
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);

View file

@ -70,7 +70,7 @@ uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr)
if (!p)
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
p->address = addr;
p->address.devAddress = addr;
p->epinfo = eprecord_ptr;
p->epcount = epcount;
@ -210,7 +210,9 @@ uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t*
uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
if (rcode) {
//printf("SetAddress Failed");
USBTRACE3("(USB::InTransfer) SetAddress Failed ", rcode, 0x81);
USBTRACE3("(USB::InTransfer) addr requested ", addr, 0x81);
USBTRACE3("(USB::InTransfer) ep requested ", ep, 0x81);
return rcode;
}
return InTransfer(pep, nak_limit, nbytesptr, data);

View file

@ -144,8 +144,8 @@ void WII::ACLData(uint8_t* l2capinbuf) {
}
}
}
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);

View file

@ -258,11 +258,11 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; // Successful configuration
/* Diagnostic messages */
#ifdef DEBUG_USB_HOST
FailGetDevDescr:
NotifyFailGetDevDescr();
goto Fail;
#endif
//#ifdef DEBUG_USB_HOST
//FailGetDevDescr:
// NotifyFailGetDevDescr();
// goto Fail;
//#endif
FailSetDevTblEntry:
#ifdef DEBUG_USB_HOST

View file

@ -62,7 +62,7 @@ struct UsbDeviceAddress {
uint8_t bmAddress : 3; // device address/port number
uint8_t bmParent : 3; // parent hub address
uint8_t bmHub : 1; // hub flag
uint8_t bmReserved : 1; // reserved, must be zerro
uint8_t bmReserved : 1; // reserved, must be zero
} __attribute__((packed));
uint8_t devAddress;
};
@ -74,7 +74,7 @@ struct UsbDeviceAddress {
struct UsbDevice {
EpInfo *epinfo; // endpoint info pointer
uint8_t address; // address
UsbDeviceAddress address;
uint8_t epcount; // number of endpoints
bool lowspeed; // indicates if a device is the low speed one
// uint8_t devclass; // device class
@ -104,50 +104,50 @@ class AddressPoolImpl : public AddressPool {
// Initializes address pool entry
void InitEntry(uint8_t index) {
thePool[index].address = 0;
thePool[index].address.devAddress = 0;
thePool[index].epcount = 1;
thePool[index].lowspeed = 0;
thePool[index].epinfo = &dev0ep;
};
// Returns thePool index for a given address
// Returns thePool index for a given address
uint8_t FindAddressIndex(uint8_t address = 0) {
for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
if(thePool[i].address == address)
if(thePool[i].address.devAddress == address)
return i;
}
return 0;
};
// Returns thePool child index for a given parent
// Returns thePool child index for a given parent
uint8_t FindChildIndex(UsbDeviceAddress addr, uint8_t start = 1) {
for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
UsbDeviceAddress* uda = reinterpret_cast<UsbDeviceAddress *>(&thePool[i].address);
if(uda->bmParent == addr.bmAddress)
if(thePool[i].address.bmParent == addr.bmAddress)
return i;
}
return 0;
};
// Frees address entry specified by index parameter
// Frees address entry specified by index parameter
void FreeAddressByIndex(uint8_t index) {
// Zerro field is reserved and should not be affected
// Zero field is reserved and should not be affected
if(index == 0)
return;
UsbDeviceAddress* uda = reinterpret_cast<UsbDeviceAddress *>(& thePool[index].address);
UsbDeviceAddress uda = thePool[index].address;
// If a hub was switched off all port addresses should be freed
if(uda->bmHub == 1) {
for(uint8_t i = 1; (i = FindChildIndex(*uda, i));)
if(uda.bmHub == 1) {
for(uint8_t i = 1; (i = FindChildIndex(uda, i));)
FreeAddressByIndex(i);
// If the hub had the last allocated address, hubCounter should be decremented
if(hubCounter == uda->bmAddress)
if(hubCounter == uda.bmAddress)
hubCounter--;
}
InitEntry(index);
}
// Initializes the whole address pool at once
// Initializes the whole address pool at once
void InitAllAddresses() {
for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
InitEntry(i);
@ -161,7 +161,7 @@ public:
// Zero address is reserved
InitEntry(0);
thePool[0].address = 0;
thePool[0].address.devAddress = 0;
thePool[0].epinfo = &dev0ep;
dev0ep.epAddr = 0;
dev0ep.maxPktSize = 8;
@ -170,8 +170,8 @@ public:
InitAllAddresses();
};
// Returns a pointer to a specified address entry
// Returns a pointer to a specified address entry
virtual UsbDevice* GetUsbDevicePtr(uint8_t addr) {
if(!addr)
return thePool;
@ -182,22 +182,23 @@ public:
};
// Performs an operation specified by pfunc for each addressed device
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
if(!pfunc)
return;
for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
if(thePool[i].address)
if(thePool[i].address.devAddress)
pfunc(thePool + i);
};
// Allocates new address
// Allocates new address
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) {
/* if (parent != 0 && port == 0)
USB_HOST_SERIAL.println("PRT:0"); */
if(parent > 127 || port > 7)
UsbDeviceAddress _parent;
_parent.devAddress = parent;
if(_parent.bmReserved || port > 7)
//if(parent > 127 || port > 7)
return 0;
if(is_hub && hubCounter == 7)
@ -209,22 +210,19 @@ public:
if(!index) // if empty entry is not found
return 0;
if(parent == 0) {
if(_parent.devAddress == 0) {
if(is_hub) {
thePool[index].address = 0x41;
thePool[index].address.devAddress = 0x41;
hubCounter++;
} else
thePool[index].address = 1;
thePool[index].address.devAddress = 1;
return thePool[index].address;
return thePool[index].address.devAddress;
}
UsbDeviceAddress addr;
addr.devAddress = 0; // Ensure all bits are zero
UsbDeviceAddress* uda = reinterpret_cast<UsbDeviceAddress *>(&parent);
//addr.bmParent = ((UsbDeviceAddress*) & parent)->bmAddress;
addr.bmParent = uda->bmAddress;
addr.bmParent = _parent.bmAddress;
if(is_hub) {
addr.bmHub = 1;
addr.bmAddress = ++hubCounter;
@ -232,9 +230,7 @@ public:
addr.bmHub = 0;
addr.bmAddress = port;
}
uint8_t* uaddr = reinterpret_cast<uint8_t*>(&addr);
//thePool[index].address = *((uint8_t*) & addr);
thePool[index].address = *uaddr;
thePool[index].address = addr;
/*
USB_HOST_SERIAL.print("Addr:");
USB_HOST_SERIAL.print(addr.bmHub, HEX);
@ -243,10 +239,10 @@ public:
USB_HOST_SERIAL.print(".");
USB_HOST_SERIAL.println(addr.bmAddress, HEX);
*/
return thePool[index].address;
return thePool[index].address.devAddress;
};
// Empties pool entry
// Empties pool entry
virtual void FreeAddress(uint8_t addr) {
// if the root hub is disconnected all the addresses should be initialized
if(addr == 0x41) {
@ -256,6 +252,7 @@ public:
uint8_t index = FindAddressIndex(addr);
FreeAddressByIndex(index);
};
// Returns number of hubs attached
// It can be rather helpfull to find out if there are hubs attached than getting the exact number of hubs.
//uint8_t GetNumHubs()

View file

@ -372,9 +372,9 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
}
}
USBTRACE2("\r\nbAddr:", bAddress);
USBTRACE2("\r\nbNumEP:", bNumEP);
USBTRACE2("\r\ntotalEndpoints:", totalEndpoints);
USBTRACE2("bAddr:", bAddress);
USBTRACE2("bNumEP:", bNumEP);
USBTRACE2("totalEndpoints:", totalEndpoints);
if(bNumEP != totalEndpoints) {
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
goto Fail;
@ -382,8 +382,8 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
// Assign epInfo to epinfo pointer
rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
USBTRACE2("\r\nCnf:", bConfNum);
USBTRACE2("setEpInfoEntry returned ", rcode);
USBTRACE2("Cnf:", bConfNum);
// Set Configuration Value
rcode = pUsb->setConf(bAddress, 0, bConfNum);
@ -391,7 +391,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
if(rcode)
goto FailSetConfDescr;
USBTRACE2("\r\nIf:", bIfaceNum);
USBTRACE2("If:", bIfaceNum);
rcode = SetProtocol(bIfaceNum, HID_BOOT_PROTOCOL);
@ -422,11 +422,11 @@ FailSetDevTblEntry:
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr();
goto Fail;
#endif
//FailGetConfDescr:
//#ifdef DEBUG_USB_HOST
// NotifyFailGetConfDescr();
// goto Fail;
//#endif
FailSetConfDescr:
#ifdef DEBUG_USB_HOST
@ -503,7 +503,9 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
const uint8_t const_buff_len = 16;
uint8_t buf[const_buff_len];
USBTRACE3("(hidboot.h) i=", i, 0x81);
USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
uint16_t read = (uint16_t) epInfo[epInterruptInIndex + i].maxPktSize;
uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
@ -521,7 +523,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
#endif
} else {
if(rcode != hrNAK) {
USBTRACE2("Poll:", rcode);
USBTRACE3("(hidboot.h) Poll:", rcode, 0x81);
break;
}
}

View file

@ -360,7 +360,7 @@ uint8_t HIDUniversal::Poll() {
if (rcode) {
if (rcode != hrNAK)
USBTRACE2("Poll:", rcode);
USBTRACE3("(hiduniversal.h) Poll:", rcode, 0x81);
return rcode;
}

View file

@ -64,6 +64,7 @@
*/
#define USBTRACE(s) (Notify(PSTR(s), 0x80))
#define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80))
#define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l))
#endif /* MACROS_H */

View file

@ -489,11 +489,11 @@ FailGetMaxLUN:
goto Fail;
#endif
#ifdef DEBUG_USB_HOST
FailInvalidSectorSize:
USBTRACE("Sector Size is NOT VALID: ");
goto Fail;
#endif
//#ifdef DEBUG_USB_HOST
//FailInvalidSectorSize:
// USBTRACE("Sector Size is NOT VALID: ");
// goto Fail;
//#endif
FailSetDevTblEntry:
#ifdef DEBUG_USB_HOST