Add USBDevice destructor

Add a destructor to USBDevice to ensure that resources have been
properly released. Additionally add an assert in the destructor that
deinit has already been called. If it has not been called then
interrupts can still occur which may cause a crash.
feature-hal-spec-usb-device
Russ Butler 2018-05-01 15:05:17 -05:00
parent 0c52350540
commit beddff36e9
2 changed files with 14 additions and 0 deletions

View File

@ -1248,6 +1248,12 @@ USBDevice::USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
_device.suspended = false;
}
USBDevice::~USBDevice()
{
MBED_ASSERT(!_initialized);
deinit();
}
uint32_t USBDevice::endpoint_max_packet_size(usb_ep_t endpoint)
{
lock();

View File

@ -82,6 +82,14 @@ public:
*/
USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
/**
* Cleanup this USBDevice
*
* This USBDevice must be uninitialized when the destructor is
* called or the behavior is undefined.
*/
virtual ~USBDevice();
/**
* Initialize this instance
*