Skip to content

Commit

Permalink
Add start of frame notification for lpcip3511
Browse files Browse the repository at this point in the history
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.

Signed-off-by: James Zipperer <[email protected]>
  • Loading branch information
jzipperer-fb committed Jan 17, 2024
1 parent c8317a3 commit 29e52b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions device/usb_device_dci.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 36 additions & 2 deletions device/usb_device_lpcip3511.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static void USB_DeviceLpc3511IpSetDefaultState(usb_device_lpc3511ip_state_struct
lpc3511IpState->registerBase->INTSTAT =
(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;
lpc3511IpState->registerBase->INTEN = USB_LPC3511IP_INTSTAT_DEV_INT_MASK | USB_LPC3511IP_MAX_PHY_ENDPOINT_MASK | USB_LPC3511IP_INTSTAT_FRAME_INT_MASK;

/* Clear reset flag */
lpc3511IpState->isResetting = 0U;
Expand Down Expand Up @@ -2562,6 +2562,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;
Expand Down Expand Up @@ -2776,9 +2809,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
}
Expand Down

0 comments on commit 29e52b7

Please sign in to comment.