Skip to content

Commit

Permalink
Type fixes, new debug macro, debug bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxajk committed Dec 18, 2013
1 parent 6e70087 commit 5785115
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 67 deletions.
4 changes: 2 additions & 2 deletions BTHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions SPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions Usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Wii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions XBOXRECV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 32 additions & 35 deletions address.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -161,7 +161,7 @@ class AddressPoolImpl : public AddressPool {
// 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;
Expand All @@ -170,8 +170,8 @@ class AddressPoolImpl : public AddressPool {

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;
Expand All @@ -182,22 +182,23 @@ class AddressPoolImpl : public AddressPool {
};

// 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)
Expand All @@ -209,32 +210,27 @@ class AddressPoolImpl : public AddressPool {
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;
} else {
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);
Expand All @@ -243,10 +239,10 @@ class AddressPoolImpl : public AddressPool {
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) {
Expand All @@ -256,6 +252,7 @@ class AddressPoolImpl : public AddressPool {
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()
Expand Down
28 changes: 15 additions & 13 deletions hidboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,26 +372,26 @@ 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;
}

// 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);

if(rcode)
goto FailSetConfDescr;

USBTRACE2("\r\nIf:", bIfaceNum);
USBTRACE2("If:", bIfaceNum);

rcode = SetProtocol(bIfaceNum, HID_BOOT_PROTOCOL);

Expand Down Expand Up @@ -422,11 +422,11 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion hiduniversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ uint8_t HIDUniversal::Poll() {

if (rcode) {
if (rcode != hrNAK)
USBTRACE2("Poll:", rcode);
USBTRACE3("(hiduniversal.h) Poll:", rcode, 0x81);
return rcode;
}

Expand Down
1 change: 1 addition & 0 deletions macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 5 additions & 5 deletions masstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
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
Expand Down

0 comments on commit 5785115

Please sign in to comment.