The current approach is a bit impractical in the upper layer. This patch removes the two fifos that hold the transfer buffers and replaces them with a byte array for the setup packet and a pointer to a data buffer. The data buffer is mandatory for all types of transfers except control without a data stage. The waste of eight unused bytes for non-control transfers should be insignificant, since an additional pointer would be at least half of it, and then there would be the overhead of handling it. This patch also clean up the transfer flags, rename owner to callback as it reflects the upper layer use case, and add an additional member to hold the pointer to the USB device (peripheral on the bus). Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
113 lines
2.9 KiB
C
113 lines
2.9 KiB
C
/*
|
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief Private API for USB host controller (UHC) drivers
|
|
*/
|
|
|
|
#ifndef ZEPHYR_INCLUDE_UHC_COMMON_H
|
|
#define ZEPHYR_INCLUDE_UHC_COMMON_H
|
|
|
|
#include <zephyr/drivers/usb/uhc.h>
|
|
|
|
/**
|
|
* @brief Get driver's private data
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
*
|
|
* @return pointer to driver's private data
|
|
*/
|
|
static inline void *uhc_get_private(const struct device *dev)
|
|
{
|
|
struct uhc_data *data = dev->data;
|
|
|
|
return data->priv;
|
|
}
|
|
|
|
/**
|
|
* @brief Locking function for the drivers.
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
* @param[in] timeout Timeout
|
|
*
|
|
* @return values provided by k_mutex_lock()
|
|
*/
|
|
static inline int uhc_lock_internal(const struct device *dev,
|
|
k_timeout_t timeout)
|
|
{
|
|
struct uhc_data *data = dev->data;
|
|
|
|
return k_mutex_lock(&data->mutex, timeout);
|
|
}
|
|
|
|
/**
|
|
* @brief Unlocking function for the drivers.
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
*
|
|
* @return values provided by k_mutex_lock()
|
|
*/
|
|
static inline int uhc_unlock_internal(const struct device *dev)
|
|
{
|
|
struct uhc_data *data = dev->data;
|
|
|
|
return k_mutex_unlock(&data->mutex);
|
|
}
|
|
|
|
/**
|
|
* @brief Helper function to return UHC transfer to a higher level.
|
|
*
|
|
* Function to dequeue transfer and send UHC event to a higher level.
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
* @param[in] xfer Pointer to UHC transfer
|
|
* @param[in] err Transfer error
|
|
*/
|
|
void uhc_xfer_return(const struct device *dev,
|
|
struct uhc_transfer *const xfer,
|
|
const int err);
|
|
|
|
/**
|
|
* @brief Helper to get next transfer to process.
|
|
*
|
|
* This is currently a draft, and simple picks a transfer
|
|
* from the lists.
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
* @return pointer to the next transfer or NULL on error.
|
|
*/
|
|
struct uhc_transfer *uhc_xfer_get_next(const struct device *dev);
|
|
|
|
/**
|
|
* @brief Helper to append a transfer to internal list.
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
* @param[in] xfer Pointer to UHC transfer
|
|
*
|
|
* @return 0 on success, all other values should be treated as error.
|
|
* @retval -ENOMEM if there is no buffer in the queue
|
|
*/
|
|
int uhc_xfer_append(const struct device *dev,
|
|
struct uhc_transfer *const xfer);
|
|
|
|
/**
|
|
* @brief Helper function to send UHC event to a higher level.
|
|
*
|
|
* The callback would typically sends UHC even to a message queue (k_msgq).
|
|
*
|
|
* @param[in] dev Pointer to device struct of the driver instance
|
|
* @param[in] type Event type
|
|
* @param[in] status Event status
|
|
*
|
|
* @return 0 on success, all other values should be treated as error.
|
|
* @retval -EPERM controller is not initialized
|
|
*/
|
|
int uhc_submit_event(const struct device *dev,
|
|
const enum uhc_event_type type,
|
|
const int status);
|
|
|
|
#endif /* ZEPHYR_INCLUDE_UHC_COMMON_H */
|