From a3883c4b84e3afce54da4c88e899befa53b20ee4 Mon Sep 17 00:00:00 2001 From: James Zipperer Date: Wed, 20 Dec 2023 13:02:01 -0800 Subject: [PATCH] Add start of frame notification for lpcip3511 This enables the start of frame interrupt. When a start of frame interrupt occurs, a message is created and sent via USB_DeviceNotificationTrigger. Notifications are gated by the define USB_DEVICE_CONFIG_SOF_NOTIFICATIONS. Some upper layers that use this middleware need start of frame notifications for doing isochronous transfers. This fixes the following issue: https://github.com/nxp-mcuxpresso/mcux-sdk-middleware-usb/issues/7 Signed-off-by: James Zipperer --- device/usb_device_dci.h | 1 + device/usb_device_lpcip3511.c | 39 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/device/usb_device_dci.h b/device/usb_device_dci.h index d8f9555..8b4c17e 100644 --- a/device/usb_device_dci.h +++ b/device/usb_device_dci.h @@ -33,6 +33,7 @@ typedef enum _usb_device_notification kUSB_DeviceNotifyError, /*!< Errors happened in bus */ kUSB_DeviceNotifyDetach, /*!< Device disconnected from a host */ kUSB_DeviceNotifyAttach, /*!< Device connected to a host */ + kUSB_DeviceNotifySOF, /*!< Start of Frame */ #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) kUSB_DeviceNotifyDcdDetectFinished, /*!< Device charger detection finished */ #endif diff --git a/device/usb_device_lpcip3511.c b/device/usb_device_lpcip3511.c index f0a4908..3fcf303 100644 --- a/device/usb_device_lpcip3511.c +++ b/device/usb_device_lpcip3511.c @@ -486,6 +486,9 @@ static void USB_DeviceLpc3511IpSetDefaultState(usb_device_lpc3511ip_state_struct (USB_LPC3511IP_INTSTAT_FRAME_INT_MASK | USB_LPC3511IP_MAX_PHY_ENDPOINT_MASK); /* enable interrupts */ lpc3511IpState->registerBase->INTEN = USB_LPC3511IP_INTSTAT_DEV_INT_MASK | USB_LPC3511IP_MAX_PHY_ENDPOINT_MASK; +#if (defined(USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) && (USB_DEVICE_CONFIG_SOF_NOTIFICATIONS > 0)) + lpc3511IpState->registerBase->INTEN |= USB_LPC3511IP_INTSTAT_FRAME_INT_MASK; +#endif /* Clear reset flag */ lpc3511IpState->isResetting = 0U; @@ -2562,6 +2565,39 @@ usb_status_t USB_DeviceLpc3511IpControl(usb_device_controller_handle controllerH return error; } +#if (defined(USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) && (USB_DEVICE_CONFIG_SOF_NOTIFICATIONS > 0)) +/*! + * @brief Handle Start of Frame (SOF) Interrupt + * + * The function is used to notify the upper layer that an SOF has occurred + * + * @param lpc3511IpState Pointer of the controller state structure. + * + * @return A USB error code (if configured for error checking) or kStatus_USB_Success. + */ +static usb_status_t USB_DeviceLpc3511IpInterruptSOF(usb_device_lpc3511ip_state_struct_t *lpc3511IpState) +{ + usb_device_callback_message_struct_t message; + + message.buffer = (uint8_t *)NULL; + message.code = (uint8_t)kUSB_DeviceNotifySOF; + message.length = 0U; + message.isSetup = 0U; + + /* Notify upper layer */ +#if (defined(USB_DEVICE_CONFIG_RETURN_VALUE_CHECK) && (USB_DEVICE_CONFIG_RETURN_VALUE_CHECK > 0U)) + if (kStatus_USB_Success != USB_DeviceNotificationTrigger(lpc3511IpState->deviceHandle, &message)) + { + return kStatus_USB_Error; + } +#else + (void)USB_DeviceNotificationTrigger(lpc3511IpState->deviceHandle, &message); +#endif + + return kStatus_USB_Success; +} +#endif /* (defined(USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) && (USB_DEVICE_CONFIG_SOF_NOTIFICATIONS > 0)) */ + void USB_DeviceLpcIp3511IsrFunction(void *deviceHandle) { usb_device_struct_t *handle = (usb_device_struct_t *)deviceHandle; @@ -2776,9 +2812,10 @@ void USB_DeviceLpcIp3511IsrFunction(void *deviceHandle) } } -#if 0U +#if (defined(USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) && (USB_DEVICE_CONFIG_SOF_NOTIFICATIONS > 0)) if (interruptStatus & USB_LPC3511IP_INTSTAT_FRAME_INT_MASK) { + USB_DeviceLpc3511IpInterruptSOF(lpc3511IpState); } #endif }