summaryrefslogtreecommitdiff
path: root/bsp/imxrt
diff options
context:
space:
mode:
authorLeeChunHei <[email protected]>2022-01-26 11:49:22 +0800
committerGitHub <[email protected]>2022-01-26 11:49:22 +0800
commit3000140bfdbe27294e54c16968c05d5efbd2dddb (patch)
tree9c51b9ead39eef9fd2d94671003d8e852c1c2424 /bsp/imxrt
parent2f6f9da5e3fd581f74ed44e233c0df3fd247b63e (diff)
爲imxrt系列添加usb host驅動 (#4377)
* adding fsl_os_abstraction porting * port usbh to imxrt Co-authored-by: guo <[email protected]>
Diffstat (limited to 'bsp/imxrt')
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h812
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h36
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c917
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h130
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c475
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h203
-rw-r--r--bsp/imxrt/libraries/MIMXRT1050/SConscript4
-rw-r--r--bsp/imxrt/libraries/drivers/SConscript8
-rw-r--r--bsp/imxrt/libraries/drivers/drv_usbh.c730
-rw-r--r--bsp/imxrt/libraries/drivers/drv_usbh.h22
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host.h141
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c670
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h41
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c2038
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h230
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c261
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h131
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c341
-rw-r--r--bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h46
-rw-r--r--bsp/imxrt/libraries/drivers/usb/include/usb.h3
-rw-r--r--bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h247
-rw-r--r--bsp/imxrt/libraries/drivers/usb/include/usb_misc.h338
22 files changed, 6067 insertions, 1757 deletions
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h
new file mode 100644
index 0000000000..1efab708fe
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h
@@ -0,0 +1,812 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * Copyright 2016-2020 NXP
+ *
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _FSL_OS_ABSTRACTION_H_
+#define _FSL_OS_ABSTRACTION_H_
+
+#include "fsl_common.h"
+#include "fsl_os_abstraction_config.h"
+#include "generic_list.h"
+
+/*!
+ * @addtogroup osa_adapter
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief Type for the Task Priority*/
+typedef uint16_t osa_task_priority_t;
+/*! @brief Type for a task handler */
+typedef void *osa_task_handle_t;
+/*! @brief Type for the parameter to be passed to the task at its creation */
+typedef void *osa_task_param_t;
+/*! @brief Type for task pointer. Task prototype declaration */
+typedef void (*osa_task_ptr_t)(osa_task_param_t task_param);
+/*! @brief Type for the semaphore handler */
+typedef void *osa_semaphore_handle_t;
+/*! @brief Type for the mutex handler */
+typedef void *osa_mutex_handle_t;
+/*! @brief Type for the event handler */
+typedef void *osa_event_handle_t;
+/*! @brief Type for an event flags group, bit 32 is reserved. */
+typedef uint32_t osa_event_flags_t;
+/*! @brief Message definition. */
+typedef void *osa_msg_handle_t;
+/*! @brief Type for the message queue handler */
+typedef void *osa_msgq_handle_t;
+/*! @brief Type for the Timer handler */
+typedef void *osa_timer_handle_t;
+/*! @brief Type for the Timer callback function pointer. */
+typedef void (*osa_timer_fct_ptr_t)(void const *argument);
+/*! @brief Thread Definition structure contains startup information of a thread.*/
+typedef struct osa_task_def_tag
+{
+ osa_task_ptr_t pthread; /*!< start address of thread function*/
+ uint32_t tpriority; /*!< initial thread priority*/
+ uint32_t instances; /*!< maximum number of instances of that thread function*/
+ uint32_t stacksize; /*!< stack size requirements in bytes; 0 is default stack size*/
+ uint32_t *tstack; /*!< stack pointer*/
+ void *tlink; /*!< link pointer*/
+ uint8_t *tname; /*!< name pointer*/
+ uint8_t useFloat; /*!< is use float*/
+} osa_task_def_t;
+/*! @brief Thread Link Definition structure .*/
+typedef struct osa_thread_link_tag
+{
+ uint8_t link[12]; /*!< link*/
+ osa_task_handle_t osThreadId; /*!< thread id*/
+ osa_task_def_t *osThreadDefHandle; /*!< pointer of thread define handle*/
+ uint32_t *osThreadStackHandle; /*!< pointer of thread stack handle*/
+} osa_thread_link_t, *osa_thread_link_handle_t;
+
+/*! @brief Definition structure contains timer parameters.*/
+typedef struct osa_time_def_tag
+{
+ osa_timer_fct_ptr_t pfCallback; /* < start address of a timer function */
+ void *argument; /* < argument of a timer function */
+} osa_time_def_t;
+
+/*! @brief Type for the timer definition*/
+typedef enum _osa_timer
+{
+ KOSA_TimerOnce = 0, /*!< one-shot timer*/
+ KOSA_TimerPeriodic = 1 /*!< repeating timer*/
+} osa_timer_t;
+
+/*! @brief Defines the return status of OSA's functions */
+typedef enum _osa_status
+{
+ KOSA_StatusSuccess = kStatus_Success, /*!< Success */
+ KOSA_StatusError = MAKE_STATUS(kStatusGroup_OSA, 1), /*!< Failed */
+ KOSA_StatusTimeout = MAKE_STATUS(kStatusGroup_OSA, 2), /*!< Timeout occurs while waiting */
+ KOSA_StatusIdle = MAKE_STATUS(kStatusGroup_OSA, 3), /*!< Used for bare metal only, the wait object is not ready
+ and timeout still not occur */
+} osa_status_t;
+
+#ifdef USE_RTOS
+#undef USE_RTOS
+#endif
+
+#define USE_RTOS (1)
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+#define OSA_TASK_HANDLE_SIZE (12U)
+#else
+#define OSA_TASK_HANDLE_SIZE (16U)
+#endif
+#define OSA_EVENT_HANDLE_SIZE (8U)
+#define OSA_SEM_HANDLE_SIZE (4U)
+#define OSA_MUTEX_HANDLE_SIZE (4U)
+#define OSA_MSGQ_HANDLE_SIZE (4U)
+#define OSA_MSG_HANDLE_SIZE (0U)
+
+/*! @brief Priority setting for OSA. */
+#ifndef OSA_PRIORITY_IDLE
+#define OSA_PRIORITY_IDLE (6)
+#endif
+
+#ifndef OSA_PRIORITY_LOW
+#define OSA_PRIORITY_LOW (5)
+#endif
+
+#ifndef OSA_PRIORITY_BELOW_NORMAL
+#define OSA_PRIORITY_BELOW_NORMAL (4)
+#endif
+
+#ifndef OSA_PRIORITY_NORMAL
+#define OSA_PRIORITY_NORMAL (3)
+#endif
+
+#ifndef OSA_PRIORITY_ABOVE_NORMAL
+#define OSA_PRIORITY_ABOVE_NORMAL (2)
+#endif
+
+#ifndef OSA_PRIORITY_HIGH
+#define OSA_PRIORITY_HIGH (1)
+#endif
+
+#ifndef OSA_PRIORITY_REAL_TIME
+#define OSA_PRIORITY_REAL_TIME (0)
+#endif
+
+#ifndef OSA_TASK_PRIORITY_MAX
+#define OSA_TASK_PRIORITY_MAX (0)
+#endif
+
+#ifndef OSA_TASK_PRIORITY_MIN
+#define OSA_TASK_PRIORITY_MIN (15)
+#endif
+
+#define SIZE_IN_UINT32_UNITS(size) (((size) + sizeof(uint32_t) - 1) / sizeof(uint32_t))
+
+/*! @brief Constant to pass as timeout value in order to wait indefinitely. */
+#define osaWaitForever_c ((uint32_t)(-1))
+#define osaEventFlagsAll_c ((osa_event_flags_t)(0x00FFFFFF))
+#define osThreadStackArray(name) osThread_##name##_stack
+#define osThreadStackDef(name, stacksize, instances) \
+ uint32_t osThreadStackArray(name)[SIZE_IN_UINT32_UNITS(stacksize) * (instances)];
+
+/* ==== Thread Management ==== */
+
+/* Create a Thread Definition with function, priority, and stack requirements.
+ * \param name name of the thread function.
+ * \param priority initial priority of the thread function.
+ * \param instances number of possible thread instances.
+ * \param stackSz stack size (in bytes) requirements for the thread function.
+ * \param useFloat
+ */
+#if defined(FSL_RTOS_MQX)
+#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
+ osa_thread_link_t osThreadLink_##name[instances] = {0}; \
+ osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
+ (name), (priority), (instances), (stackSz), osThreadStackArray(name), osThreadLink_##name, \
+ (uint8_t *)#name, (useFloat)}
+#elif defined(FSL_RTOS_UCOSII)
+#if gTaskMultipleInstancesManagement_c
+#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
+ osa_thread_link_t osThreadLink_##name[instances] = {0}; \
+ osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
+ (name), (priority), (instances), (stackSz), osThreadStackArray(name), osThreadLink_##name, \
+ (uint8_t *)#name, (useFloat)}
+#else
+#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
+ osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
+ (name), (priority), (instances), (stackSz), osThreadStackArray(name), NULL, (uint8_t *)#name, (useFloat)}
+#endif
+#else
+#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
+ osa_task_def_t os_thread_def_##name = {(name), (priority), (instances), (stackSz), \
+ NULL, NULL, (uint8_t *)#name, (useFloat)}
+#endif
+/* Access a Thread defintion.
+ * \param name name of the thread definition object.
+ */
+#define OSA_TASK(name) &os_thread_def_##name
+
+#define OSA_TASK_PROTO(name) externosa_task_def_t os_thread_def_##name
+/* ==== Timer Management ====
+ * Define a Timer object.
+ * \param name name of the timer object.
+ * \param function name of the timer call back function.
+ */
+
+#define OSA_TIMER_DEF(name, function) osa_time_def_t os_timer_def_##name = {(function), NULL}
+
+/* Access a Timer definition.
+ * \param name name of the timer object.
+ */
+#define OSA_TIMER(name) &os_timer_def_##name
+
+/* ==== Buffer Definition ==== */
+
+/*!
+ * @brief Defines the semaphore handle
+ *
+ * This macro is used to define a 4 byte aligned semaphore handle.
+ * Then use "(osa_semaphore_handle_t)name" to get the semaphore handle.
+ *
+ * The macro should be global and could be optional. You could also define semaphore handle by yourself.
+ *
+ * This is an example,
+ * @code
+ * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
+ * @endcode
+ *
+ * @param name The name string of the semaphore handle.
+ */
+#define OSA_SEMAPHORE_HANDLE_DEFINE(name) \
+ uint32_t name[(OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
+
+/*!
+ * @brief Defines the mutex handle
+ *
+ * This macro is used to define a 4 byte aligned mutex handle.
+ * Then use "(osa_mutex_handle_t)name" to get the mutex handle.
+ *
+ * The macro should be global and could be optional. You could also define mutex handle by yourself.
+ *
+ * This is an example,
+ * @code
+ * OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
+ * @endcode
+ *
+ * @param name The name string of the mutex handle.
+ */
+#define OSA_MUTEX_HANDLE_DEFINE(name) uint32_t name[(OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
+
+/*!
+ * @brief Defines the event handle
+ *
+ * This macro is used to define a 4 byte aligned event handle.
+ * Then use "(osa_event_handle_t)name" to get the event handle.
+ *
+ * The macro should be global and could be optional. You could also define event handle by yourself.
+ *
+ * This is an example,
+ * @code
+ * OSA_EVENT_HANDLE_DEFINE(eventHandle);
+ * @endcode
+ *
+ * @param name The name string of the event handle.
+ */
+#define OSA_EVENT_HANDLE_DEFINE(name) uint32_t name[(OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
+
+/*!
+ * @brief Defines the message queue handle
+ *
+ * This macro is used to define a 4 byte aligned message queue handle.
+ * Then use "(osa_msgq_handle_t)name" to get the message queue handle.
+ *
+ * The macro should be global and could be optional. You could also define message queue handle by yourself.
+ *
+ * This is an example,
+ * @code
+ * OSA_MSGQ_HANDLE_DEFINE(msgqHandle, 3, sizeof(msgStruct));
+ * @endcode
+ *
+ * @param name The name string of the message queue handle.
+ * @param numberOfMsgs Number of messages.
+ * @param msgSize Message size.
+ *
+ */
+
+/*< Macro For FREE_RTOS*/
+#define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \
+ uint32_t name[(OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
+
+/*!
+ * @brief Defines the TASK handle
+ *
+ * This macro is used to define a 4 byte aligned TASK handle.
+ * Then use "(osa_task_handle_t)name" to get the TASK handle.
+ *
+ * The macro should be global and could be optional. You could also define TASK handle by yourself.
+ *
+ * This is an example,
+ * @code
+ * OSA_TASK_HANDLE_DEFINE(taskHandle);
+ * @endcode
+ *
+ * @param name The name string of the TASK handle.
+ */
+#define OSA_TASK_HANDLE_DEFINE(name) uint32_t name[(OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
+
+#include "fsl_os_abstraction_rtthread.h"
+
+extern const uint8_t gUseRtos_c;
+
+/*
+ * alloc the temporary memory to store the status
+ */
+#define OSA_SR_ALLOC() uint32_t osaCurrentSr;
+/*
+ * Enter critical mode
+ */
+#define OSA_ENTER_CRITICAL() OSA_EnterCritical(&osaCurrentSr)
+/*
+ * Exit critical mode and retore the previous mode
+ */
+#define OSA_EXIT_CRITICAL() OSA_ExitCritical(osaCurrentSr)
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+/*!
+ * @brief Reserves the requested amount of memory in bytes.
+ *
+ * The function is used to reserve the requested amount of memory in bytes and initializes it to 0.
+ *
+ * @param length Amount of bytes to reserve.
+ *
+ * @return Pointer to the reserved memory. NULL if memory can't be allocated.
+ */
+void *OSA_MemoryAllocate(uint32_t length);
+
+/*!
+ * @brief Frees the memory previously reserved.
+ *
+ * The function is used to free the memory block previously reserved.
+ *
+ * @param p Pointer to the start of the memory block previously reserved.
+ *
+ */
+void OSA_MemoryFree(void *p);
+
+/*!
+ * @brief Enter critical with nesting mode.
+ *
+ * @param sr Store current status and return to caller.
+ */
+void OSA_EnterCritical(uint32_t *sr);
+
+/*!
+ * @brief Exit critical with nesting mode.
+ *
+ * @param sr Previous status to restore.
+ */
+void OSA_ExitCritical(uint32_t sr);
+
+/*!
+ * @name Task management
+ * @{
+ */
+
+/*!
+ * @brief Creates a task.
+ *
+ * This function is used to create task based on the resources defined
+ * by the macro OSA_TASK_DEFINE.
+ *
+ * Example below shows how to use this API to create the task handle.
+ * @code
+ * OSA_TASK_HANDLE_DEFINE(taskHandle);
+ * OSA_TASK_DEFINE( Job1, OSA_PRIORITY_HIGH, 1, 800, 0);
+ * OSA_TaskCreate((osa_task_handle_t)taskHandle, OSA_TASK(Job1), (osa_task_param_t)NULL);
+ * @endcode
+ *
+ * @param taskHandle Pointer to a memory space of size OSA_TASK_HANDLE_SIZE allocated by the caller, task handle.
+ * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
+ * You can define the handle in the following two ways:
+ * #OSA_TASK_HANDLE_DEFINE(taskHandle);
+ * or
+ * uint32_t taskHandle[((OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * @param thread_def pointer to theosa_task_def_t structure which defines the task.
+ * @param task_param Pointer to be passed to the task when it is created.
+ * @retval KOSA_StatusSuccess The task is successfully created.
+ * @retval KOSA_StatusError The task can not be created.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskCreate(osa_task_handle_t taskHandle, osa_task_def_t *thread_def, osa_task_param_t task_param);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Gets the handler of active task.
+ *
+ * @return Handler to current active task.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_task_handle_t OSA_TaskGetCurrentHandle(void);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Puts the active task to the end of scheduler's queue.
+ *
+ * When a task calls this function, it gives up the CPU and puts itself to the
+ * end of a task ready list.
+ *
+ * @retval KOSA_StatusSuccess The function is called successfully.
+ * @retval KOSA_StatusError Error occurs with this function.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskYield(void);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Gets the priority of a task.
+ *
+ * @param taskHandle The handler of the task whose priority is received.
+ *
+ * @return Task's priority.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_task_priority_t OSA_TaskGetPriority(osa_task_handle_t taskHandle);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Sets the priority of a task.
+ *
+ * @param taskHandle The handler of the task whose priority is set.
+ * @param taskPriority The priority to set.
+ *
+ * @retval KOSA_StatusSuccess Task's priority is set successfully.
+ * @retval KOSA_StatusError Task's priority can not be set.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskSetPriority(osa_task_handle_t taskHandle, osa_task_priority_t taskPriority);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Destroys a previously created task.
+ *
+ * @param taskHandle The handler of the task to destroy.
+ *
+ * @retval KOSA_StatusSuccess The task was successfully destroyed.
+ * @retval KOSA_StatusError Task destruction failed or invalid parameter.
+ */
+#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskDestroy(osa_task_handle_t taskHandle);
+#endif /* FSL_OSA_TASK_ENABLE */
+
+/*!
+ * @brief Creates a semaphore with a given value.
+ *
+ * This function creates a semaphore and sets the value to the parameter
+ * initValue.
+ *
+ * Example below shows how to use this API to create the semaphore handle.
+ * @code
+ * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
+ * OSA_SemaphoreCreate((osa_semaphore_handle_t)semaphoreHandle, 0xff);
+ * @endcode
+ *
+ * @param semaphoreHandle Pointer to a memory space of size OSA_SEM_HANDLE_SIZE allocated by the caller.
+ * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
+ * You can define the handle in the following two ways:
+ * #OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
+ * or
+ * uint32_t semaphoreHandle[((OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * @param initValue Initial value the semaphore will be set to.
+ *
+ * @retval KOSA_StatusSuccess the new semaphore if the semaphore is created successfully.
+ * @retval KOSA_StatusError if the semaphore can not be created.
+ */
+osa_status_t OSA_SemaphoreCreate(osa_semaphore_handle_t semaphoreHandle, uint32_t initValue);
+
+/*!
+ * @brief Destroys a previously created semaphore.
+ *
+ * @param semaphoreHandle The semaphore handle.
+ * The macro SEMAPHORE_HANDLE_BUFFER_GET is used to get the semaphore buffer pointer,
+ * and should not be used before the macro SEMAPHORE_HANDLE_BUFFER_DEFINE is used.
+ *
+ * @retval KOSA_StatusSuccess The semaphore is successfully destroyed.
+ * @retval KOSA_StatusError The semaphore can not be destroyed.
+ */
+osa_status_t OSA_SemaphoreDestroy(osa_semaphore_handle_t semaphoreHandle);
+
+/*!
+ * @brief Pending a semaphore with timeout.
+ *
+ * This function checks the semaphore's counting value. If it is positive,
+ * decreases it and returns KOSA_StatusSuccess. Otherwise, a timeout is used
+ * to wait.
+ *
+ * @param semaphoreHandle The semaphore handle.
+ * @param millisec The maximum number of milliseconds to wait if semaphore is not
+ * positive. Pass osaWaitForever_c to wait indefinitely, pass 0
+ * will return KOSA_StatusTimeout immediately.
+ *
+ * @retval KOSA_StatusSuccess The semaphore is received.
+ * @retval KOSA_StatusTimeout The semaphore is not received within the specified 'timeout'.
+ * @retval KOSA_StatusError An incorrect parameter was passed.
+ */
+osa_status_t OSA_SemaphoreWait(osa_semaphore_handle_t semaphoreHandle, uint32_t millisec);
+
+/*!
+ * @brief Signals for someone waiting on the semaphore to wake up.
+ *
+ * Wakes up one task that is waiting on the semaphore. If no task is waiting, increases
+ * the semaphore's counting value.
+ *
+ * @param semaphoreHandle The semaphore handle to signal.
+ *
+ * @retval KOSA_StatusSuccess The semaphore is successfully signaled.
+ * @retval KOSA_StatusError The object can not be signaled or invalid parameter.
+ *
+ */
+osa_status_t OSA_SemaphorePost(osa_semaphore_handle_t semaphoreHandle);
+
+/*!
+ * @brief Create an unlocked mutex.
+ *
+ * This function creates a non-recursive mutex and sets it to unlocked status.
+ *
+ * Example below shows how to use this API to create the mutex handle.
+ * @code
+ * OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
+ * OSA_MutexCreate((osa_mutex_handle_t)mutexHandle);
+ * @endcode
+ *
+ * @param mutexHandle Pointer to a memory space of size OSA_MUTEX_HANDLE_SIZE allocated by the caller.
+ * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
+ * You can define the handle in the following two ways:
+ * #OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
+ * or
+ * uint32_t mutexHandle[((OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * @retval KOSA_StatusSuccess the new mutex if the mutex is created successfully.
+ * @retval KOSA_StatusError if the mutex can not be created.
+ */
+osa_status_t OSA_MutexCreate(osa_mutex_handle_t mutexHandle);
+
+/*!
+ * @brief Waits for a mutex and locks it.
+ *
+ * This function checks the mutex's status. If it is unlocked, locks it and returns the
+ * KOSA_StatusSuccess. Otherwise, waits for a timeout in milliseconds to lock.
+ *
+ * @param mutexHandle The mutex handle.
+ * @param millisec The maximum number of milliseconds to wait for the mutex.
+ * If the mutex is locked, Pass the value osaWaitForever_c will
+ * wait indefinitely, pass 0 will return KOSA_StatusTimeout
+ * immediately.
+ *
+ * @retval KOSA_StatusSuccess The mutex is locked successfully.
+ * @retval KOSA_StatusTimeout Timeout occurred.
+ * @retval KOSA_StatusError Incorrect parameter was passed.
+ *
+ * @note This is non-recursive mutex, a task can not try to lock the mutex it has locked.
+ */
+osa_status_t OSA_MutexLock(osa_mutex_handle_t mutexHandle, uint32_t millisec);
+
+/*!
+ * @brief Unlocks a previously locked mutex.
+ *
+ * @param mutexHandle The mutex handle.
+ *
+ * @retval KOSA_StatusSuccess The mutex is successfully unlocked.
+ * @retval KOSA_StatusError The mutex can not be unlocked or invalid parameter.
+ */
+osa_status_t OSA_MutexUnlock(osa_mutex_handle_t mutexHandle);
+
+/*!
+ * @brief Destroys a previously created mutex.
+ *
+ * @param mutexHandle The mutex handle.
+ *
+ * @retval KOSA_StatusSuccess The mutex is successfully destroyed.
+ * @retval KOSA_StatusError The mutex can not be destroyed.
+ *
+ */
+osa_status_t OSA_MutexDestroy(osa_mutex_handle_t mutexHandle);
+
+/*!
+ * @brief Initializes an event object with all flags cleared.
+ *
+ * This function creates an event object and set its clear mode. If autoClear
+ * is 1, when a task gets the event flags, these flags will be
+ * cleared automatically. Otherwise these flags must
+ * be cleared manually.
+ *
+ * Example below shows how to use this API to create the event handle.
+ * @code
+ * OSA_EVENT_HANDLE_DEFINE(eventHandle);
+ * OSA_EventCreate((osa_event_handle_t)eventHandle, 0);
+ * @endcode
+ *
+ * @param eventHandle Pointer to a memory space of size OSA_EVENT_HANDLE_SIZE allocated by the caller.
+ * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
+ * You can define the handle in the following two ways:
+ * #OSA_EVENT_HANDLE_DEFINE(eventHandle);
+ * or
+ * uint32_t eventHandle[((OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * @param autoClear 1 The event is auto-clear.
+ * 0 The event manual-clear
+ * @retval KOSA_StatusSuccess the new event if the event is created successfully.
+ * @retval KOSA_StatusError if the event can not be created.
+ */
+osa_status_t OSA_EventCreate(osa_event_handle_t eventHandle, uint8_t autoClear);
+
+/*!
+ * @brief Sets one or more event flags.
+ *
+ * Sets specified flags of an event object.
+ *
+ * @param eventHandle The event handle.
+ * @param flagsToSet Flags to be set.
+ *
+ * @retval KOSA_StatusSuccess The flags were successfully set.
+ * @retval KOSA_StatusError An incorrect parameter was passed.
+ */
+osa_status_t OSA_EventSet(osa_event_handle_t eventHandle, osa_event_flags_t flagsToSet);
+
+/*!
+ * @brief Clears one or more flags.
+ *
+ * Clears specified flags of an event object.
+ *
+ * @param eventHandle The event handle.
+ * @param flagsToClear Flags to be clear.
+ *
+ * @retval KOSA_StatusSuccess The flags were successfully cleared.
+ * @retval KOSA_StatusError An incorrect parameter was passed.
+ */
+osa_status_t OSA_EventClear(osa_event_handle_t eventHandle, osa_event_flags_t flagsToClear);
+
+/*!
+ * @brief Get event's flags.
+ *
+ * Get specified flags of an event object.
+ *
+ * @param eventHandle The event handle.
+ * The macro EVENT_HANDLE_BUFFER_GET is used to get the event buffer pointer,
+ * and should not be used before the macro EVENT_HANDLE_BUFFER_DEFINE is used.
+ * @param flagsMask The flags user want to get are specified by this parameter.
+ * @param pFlagsOfEvent The event flags are obtained by this parameter.
+ *
+ * @retval KOSA_StatusSuccess The event flags were successfully got.
+ * @retval KOSA_StatusError An incorrect parameter was passed.
+ */
+osa_status_t OSA_EventGet(osa_event_handle_t eventHandle,
+ osa_event_flags_t flagsMask,
+ osa_event_flags_t *pFlagsOfEvent);
+
+/*!
+ * @brief Waits for specified event flags to be set.
+ *
+ * This function waits for a combination of flags to be set in an event object.
+ * Applications can wait for any/all bits to be set. Also this function could
+ * obtain the flags who wakeup the waiting task.
+ *
+ * @param eventHandle The event handle.
+ * @param flagsToWait Flags that to wait.
+ * @param waitAll Wait all flags or any flag to be set.
+ * @param millisec The maximum number of milliseconds to wait for the event.
+ * If the wait condition is not met, pass osaWaitForever_c will
+ * wait indefinitely, pass 0 will return KOSA_StatusTimeout
+ * immediately.
+ * @param pSetFlags Flags that wakeup the waiting task are obtained by this parameter.
+ *
+ * @retval KOSA_StatusSuccess The wait condition met and function returns successfully.
+ * @retval KOSA_StatusTimeout Has not met wait condition within timeout.
+ * @retval KOSA_StatusError An incorrect parameter was passed.
+ *
+ * @note Please pay attention to the flags bit width, FreeRTOS uses the most
+ * significant 8 bis as control bits, so do not wait these bits while using
+ * FreeRTOS.
+ *
+ */
+osa_status_t OSA_EventWait(osa_event_handle_t eventHandle,
+ osa_event_flags_t flagsToWait,
+ uint8_t waitAll,
+ uint32_t millisec,
+ osa_event_flags_t *pSetFlags);
+
+/*!
+ * @brief Destroys a previously created event object.
+ *
+ * @param eventHandle The event handle.
+ *
+ * @retval KOSA_StatusSuccess The event is successfully destroyed.
+ * @retval KOSA_StatusError Event destruction failed.
+ */
+osa_status_t OSA_EventDestroy(osa_event_handle_t eventHandle);
+
+/*!
+ * @brief Initializes a message queue.
+ *
+ * This function allocates memory for and initializes a message queue. Message queue elements are hardcoded as void*.
+ *
+ * Example below shows how to use this API to create the massage queue handle.
+ * @code
+ * OSA_MSGQ_HANDLE_DEFINE(msgqHandle);
+ * OSA_MsgQCreate((osa_msgq_handle_t)msgqHandle, 5U, sizeof(msg));
+ * @endcode
+ *
+ * @param msgqHandle Pointer to a memory space of size #(OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize) on bare-matel
+ * and #(OSA_MSGQ_HANDLE_SIZE) on FreeRTOS allocated by the caller, message queue handle.
+ * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
+ * You can define the handle in the following two ways:
+ * #OSA_MSGQ_HANDLE_DEFINE(msgqHandle);
+ * or
+ * For bm: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * For freertos: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
+ * @param msgNo :number of messages the message queue should accommodate.
+ * @param msgSize :size of a single message structure.
+ *
+ * @retval KOSA_StatusSuccess Message queue successfully Create.
+ * @retval KOSA_StatusError Message queue create failure.
+ */
+osa_status_t OSA_MsgQCreate(osa_msgq_handle_t msgqHandle, uint32_t msgNo, uint32_t msgSize);
+
+/*!
+ * @brief Puts a message at the end of the queue.
+ *
+ * This function puts a message to the end of the message queue. If the queue
+ * is full, this function returns the KOSA_StatusError;
+ *
+ * @param msgqHandle Message Queue handler.
+ * @param pMessage Pointer to the message to be put into the queue.
+ *
+ * @retval KOSA_StatusSuccess Message successfully put into the queue.
+ * @retval KOSA_StatusError The queue was full or an invalid parameter was passed.
+ */
+osa_status_t OSA_MsgQPut(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage);
+
+/*!
+ * @brief Reads and remove a message at the head of the queue.
+ *
+ * This function gets a message from the head of the message queue. If the
+ * queue is empty, timeout is used to wait.
+ *
+ * @param msgqHandle Message Queue handler.
+ * @param pMessage Pointer to a memory to save the message.
+ * @param millisec The number of milliseconds to wait for a message. If the
+ * queue is empty, pass osaWaitForever_c will wait indefinitely,
+ * pass 0 will return KOSA_StatusTimeout immediately.
+ *
+ * @retval KOSA_StatusSuccess Message successfully obtained from the queue.
+ * @retval KOSA_StatusTimeout The queue remains empty after timeout.
+ * @retval KOSA_StatusError Invalid parameter.
+ */
+osa_status_t OSA_MsgQGet(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage, uint32_t millisec);
+
+/*!
+ * @brief Destroys a previously created queue.
+ *
+ * @param msgqHandle Message Queue handler.
+ *
+ * @retval KOSA_StatusSuccess The queue was successfully destroyed.
+ * @retval KOSA_StatusError Message queue destruction failed.
+ */
+osa_status_t OSA_MsgQDestroy(osa_msgq_handle_t msgqHandle);
+
+/*!
+ * @brief Enable all interrupts.
+ */
+void OSA_InterruptEnable(void);
+
+/*!
+ * @brief Disable all interrupts.
+ */
+void OSA_InterruptDisable(void);
+
+/*!
+ * @brief Enable all interrupts using PRIMASK.
+ */
+void OSA_EnableIRQGlobal(void);
+
+/*!
+ * @brief Disable all interrupts using PRIMASK.
+ */
+void OSA_DisableIRQGlobal(void);
+
+/*!
+ * @brief Delays execution for a number of milliseconds.
+ *
+ * @param millisec The time in milliseconds to wait.
+ */
+void OSA_TimeDelay(uint32_t millisec);
+
+/*!
+ * @brief This function gets current time in milliseconds.
+ *
+ * @retval current time in milliseconds
+ */
+uint32_t OSA_TimeGetMsec(void);
+
+/*!
+ * @brief Installs the interrupt handler.
+ *
+ * @param IRQNumber IRQ number of the interrupt.
+ * @param handler The interrupt handler to install.
+ */
+void OSA_InstallIntHandler(uint32_t IRQNumber, void (*handler)(void));
+
+/*! @}*/
+#ifdef __cplusplus
+}
+#endif
+/*! @}*/
+#endif \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h
new file mode 100644
index 0000000000..11eec49e7d
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h
@@ -0,0 +1,36 @@
+/*!
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * Copyright 2016-2018 NXP
+ *
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _FSL_OS_ABSTRACTION_CONFIG_H_
+#define _FSL_OS_ABSTRACTION_CONFIG_H_
+
+#ifndef gMainThreadStackSize_c
+#define gMainThreadStackSize_c 1024
+#endif
+
+#ifndef gMainThreadPriority_c
+#define gMainThreadPriority_c 1
+#endif
+
+#ifndef gTaskMultipleInstancesManagement_c
+#define gTaskMultipleInstancesManagement_c 0
+#endif
+
+/*! @brief Definition to determine whether enable OSA's TASK module. */
+#ifndef OSA_USED
+#ifndef FSL_OSA_TASK_ENABLE
+#define FSL_OSA_TASK_ENABLE 0U
+#endif
+#else
+#if defined(FSL_OSA_TASK_ENABLE)
+#undef FSL_OSA_TASK_ENABLE
+#endif
+#define FSL_OSA_TASK_ENABLE 1U
+#endif /* OSA_USED */
+
+#endif /* _FSL_OS_ABSTRACTION_CONFIG_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c
new file mode 100644
index 0000000000..4601d5f7bd
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c
@@ -0,0 +1,917 @@
+/*! *********************************************************************************
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * Copyright 2016-2017, 2019 NXP
+ * All rights reserved.
+ *
+ *
+ * This is the source file for the OS Abstraction layer for freertos.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ ********************************************************************************** */
+
+/*! *********************************************************************************
+*************************************************************************************
+* Include
+*************************************************************************************
+********************************************************************************** */
+#include "fsl_common.h"
+#include "fsl_os_abstraction.h"
+#include "fsl_os_abstraction_rtthread.h"
+#include <string.h>
+#include "generic_list.h"
+
+/*! *********************************************************************************
+*************************************************************************************
+* Private macros
+*************************************************************************************
+********************************************************************************** */
+
+/* Weak function. */
+#if defined(__GNUC__)
+#define __WEAK_FUNC __attribute__((weak))
+#elif defined(__ICCARM__)
+#define __WEAK_FUNC __weak
+#elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
+#define __WEAK_FUNC __attribute__((weak))
+#endif
+
+#define millisecToTicks(millisec) (((millisec)*configTICK_RATE_HZ + 999U) / 1000U)
+
+#ifdef DEBUG_ASSERT
+#define OS_ASSERT(condition) \
+ if (!(condition)) \
+ while (1) \
+ ;
+#else
+#define OS_ASSERT(condition) (void)(condition);
+#endif
+
+/*! @brief Converts milliseconds to ticks*/
+#define MSEC_TO_TICK(msec) \
+ (((uint32_t)(msec) + 500uL / (uint32_t)configTICK_RATE_HZ) * (uint32_t)configTICK_RATE_HZ / 1000uL)
+#define TICKS_TO_MSEC(tick) ((uint32_t)((uint64_t)(tick)*1000uL / (uint64_t)configTICK_RATE_HZ))
+/************************************************************************************
+*************************************************************************************
+* Private type definitions
+*************************************************************************************
+************************************************************************************/
+typedef struct osa_freertos_task
+{
+ list_element_t link;
+ rt_thread_t taskHandle;
+} osa_freertos_task_t;
+
+typedef struct _osa_event_struct
+{
+ rt_event_t handle; /* The event handle */
+ uint8_t autoClear; /*!< Auto clear or manual clear */
+} osa_event_struct_t;
+
+/*! @brief State structure for bm osa manager. */
+typedef struct _osa_state
+{
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+ list_label_t taskList;
+ OSA_TASK_HANDLE_DEFINE(mainTaskHandle);
+#endif
+ uint32_t basePriority;
+ int32_t basePriorityNesting;
+ uint32_t interruptDisableCount;
+} osa_state_t;
+
+/*! *********************************************************************************
+*************************************************************************************
+* Private prototypes
+*************************************************************************************
+********************************************************************************** */
+__WEAK_FUNC void main_task(void const *argument);
+__WEAK_FUNC void main_task(void const *argument)
+{
+}
+
+void startup_task(void *argument);
+
+/*! *********************************************************************************
+*************************************************************************************
+* Public memory declarations
+*************************************************************************************
+********************************************************************************** */
+const uint8_t gUseRtos_c = USE_RTOS; // USE_RTOS = 0 for BareMetal and 1 for OS
+
+static osa_state_t s_osaState = {0};
+/*! *********************************************************************************
+*************************************************************************************
+* Private memory declarations
+*************************************************************************************
+********************************************************************************** */
+
+/*! *********************************************************************************
+*************************************************************************************
+* Public functions
+*************************************************************************************
+********************************************************************************** */
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MemoryAllocate
+ * Description : Reserves the requested amount of memory in bytes.
+ *
+ *END**************************************************************************/
+void *OSA_MemoryAllocate(uint32_t length)
+{
+ void *p = rt_malloc(length);
+
+ if (RT_NULL != p)
+ {
+ rt_memset(p, 0, length);
+ }
+
+ return p;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MemoryFree
+ * Description : Frees the memory previously reserved.
+ *
+ *END**************************************************************************/
+void OSA_MemoryFree(void *p)
+{
+ rt_free(p);
+}
+
+void OSA_EnterCritical(uint32_t *sr)
+{
+ if (rt_thread_self() != RT_NULL)
+ rt_enter_critical();
+}
+
+void OSA_ExitCritical(uint32_t sr)
+{
+ if (rt_thread_self() != RT_NULL)
+ rt_exit_critical();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : startup_task
+ * Description : Wrapper over main_task..
+ *
+ *END**************************************************************************/
+void startup_task(void *argument)
+{
+ main_task(argument);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskGetCurrentHandle
+ * Description : This function is used to get current active task's handler.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_task_handle_t OSA_TaskGetCurrentHandle(void)
+{
+ list_element_handle_t list_element;
+ osa_freertos_task_t *ptask;
+
+ list_element = LIST_GetHead(&s_osaState.taskList);
+ while (NULL != list_element)
+ {
+ ptask = (osa_freertos_task_t *)(void *)list_element;
+ if (ptask->taskHandle == xTaskGetCurrentTaskHandle())
+ {
+ return (osa_task_handle_t)ptask;
+ }
+ list_element = LIST_GetNext(list_element);
+ }
+ return NULL;
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskYield
+ * Description : When a task calls this function, it will give up CPU and put
+ * itself to the tail of ready list.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskYield(void)
+{
+ taskYIELD();
+ return KOSA_StatusSuccess;
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskGetPriority
+ * Description : This function returns task's priority by task handler.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_task_priority_t OSA_TaskGetPriority(osa_task_handle_t taskHandle)
+{
+ assert(taskHandle);
+ osa_freertos_task_t *ptask = (osa_freertos_task_t *)taskHandle;
+ return (osa_task_priority_t)(PRIORITY_RTOS_TO_OSA(uxTaskPriorityGet(ptask->taskHandle)));
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskSetPriority
+ * Description : This function sets task's priority by task handler.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskSetPriority(osa_task_handle_t taskHandle, osa_task_priority_t taskPriority)
+{
+ assert(taskHandle);
+ osa_freertos_task_t *ptask = (osa_freertos_task_t *)taskHandle;
+ vTaskPrioritySet((task_handler_t)ptask->taskHandle, PRIORITY_OSA_TO_RTOS(taskPriority));
+ return KOSA_StatusSuccess;
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskCreate
+ * Description : This function is used to create a task and make it ready.
+ * Param[in] : threadDef - Definition of the thread.
+ * task_param - Parameter to pass to the new thread.
+ * Return Thread handle of the new thread, or NULL if failed.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskCreate(osa_task_handle_t taskHandle, osa_task_def_t *thread_def, osa_task_param_t task_param)
+{
+ assert(sizeof(osa_freertos_task_t) == OSA_TASK_HANDLE_SIZE);
+ assert(taskHandle);
+ TaskHandle_t pxCreatedTask;
+ osa_freertos_task_t *ptask = (osa_freertos_task_t *)taskHandle;
+
+ if (xTaskCreate((TaskFunction_t)thread_def->pthread, /* pointer to the task */
+ (char const *)thread_def->tname, /* task name for kernel awareness debugging */
+ (configSTACK_DEPTH_TYPE)thread_def->stacksize / sizeof(portSTACK_TYPE), /* task stack size */
+ (task_param_t)task_param, /* optional task startup argument */
+ PRIORITY_OSA_TO_RTOS(thread_def->tpriority), /* initial priority */
+ &pxCreatedTask /* optional task handle to create */
+ ) == pdPASS)
+ {
+ ptask->taskHandle = pxCreatedTask;
+ OSA_InterruptDisable();
+ (void)LIST_AddTail(&s_osaState.taskList, (list_element_handle_t) & (ptask->link));
+ OSA_InterruptEnable();
+ return KOSA_StatusSuccess;
+ }
+ return KOSA_StatusError;
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TaskDestroy
+ * Description : This function destroy a task.
+ * Param[in] :taskHandle - Thread handle.
+ * Return KOSA_StatusSuccess if the task is destroied, otherwise return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+osa_status_t OSA_TaskDestroy(osa_task_handle_t taskHandle)
+{
+ assert(taskHandle);
+ osa_freertos_task_t *ptask = (osa_freertos_task_t *)taskHandle;
+ osa_status_t status;
+ uint16_t oldPriority;
+ /*Change priority to avoid context switches*/
+ oldPriority = OSA_TaskGetPriority(OSA_TaskGetCurrentHandle());
+ (void)OSA_TaskSetPriority(OSA_TaskGetCurrentHandle(), OSA_PRIORITY_REAL_TIME);
+#if INCLUDE_vTaskDelete /* vTaskDelete() enabled */
+ vTaskDelete((task_handler_t)ptask->taskHandle);
+ status = KOSA_StatusSuccess;
+#else
+ status = KOSA_StatusError; /* vTaskDelete() not available */
+#endif
+ (void)OSA_TaskSetPriority(OSA_TaskGetCurrentHandle(), oldPriority);
+ OSA_InterruptDisable();
+ (void)LIST_RemoveElement(taskHandle);
+ OSA_InterruptEnable();
+ return status;
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TimeDelay
+ * Description : This function is used to suspend the active thread for the given number of milliseconds.
+ *
+ *END**************************************************************************/
+void OSA_TimeDelay(uint32_t millisec)
+{
+ rt_thread_mdelay(millisec);
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_TimeGetMsec
+ * Description : This function gets current time in milliseconds.
+ *
+ *END**************************************************************************/
+uint32_t OSA_TimeGetMsec(void)
+{
+ return rt_tick_get_millisecond();
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_SemaphoreCreate
+ * Description : This function is used to create a semaphore.
+ * Return : Semaphore handle of the new semaphore, or NULL if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_SemaphoreCreate(osa_semaphore_handle_t semaphoreHandle, uint32_t initValue)
+{
+ assert(sizeof(osa_semaphore_handle_t) == OSA_SEM_HANDLE_SIZE);
+ assert(semaphoreHandle);
+
+ union
+ {
+ rt_sem_t sem;
+ uint32_t semhandle;
+ } xSemaHandle;
+
+ xSemaHandle.sem = rt_sem_create("osa_sem", initValue, RT_IPC_FLAG_PRIO);
+ if (NULL != xSemaHandle.sem)
+ {
+ *(uint32_t *)semaphoreHandle = xSemaHandle.semhandle;
+ return KOSA_StatusSuccess;
+ }
+ return KOSA_StatusError;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_SemaphoreDestroy
+ * Description : This function is used to destroy a semaphore.
+ * Return : KOSA_StatusSuccess if the semaphore is destroyed successfully, otherwise return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_SemaphoreDestroy(osa_semaphore_handle_t semaphoreHandle)
+{
+ assert(semaphoreHandle);
+ rt_sem_t sem = (rt_sem_t)(void *)(uint32_t *)(*(uint32_t *)semaphoreHandle);
+
+ rt_sem_delete(sem);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_SemaphoreWait
+ * Description : This function checks the semaphore's counting value, if it is
+ * positive, decreases it and returns KOSA_StatusSuccess, otherwise, timeout
+ * will be used for wait. The parameter timeout indicates how long should wait
+ * in milliseconds. Pass osaWaitForever_c to wait indefinitely, pass 0 will
+ * return KOSA_StatusTimeout immediately if semaphore is not positive.
+ * This function returns KOSA_StatusSuccess if the semaphore is received, returns
+ * KOSA_StatusTimeout if the semaphore is not received within the specified
+ * 'timeout', returns KOSA_StatusError if any errors occur during waiting.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_SemaphoreWait(osa_semaphore_handle_t semaphoreHandle, uint32_t millisec)
+{
+ uint32_t timeoutTicks;
+ assert(semaphoreHandle);
+ rt_sem_t sem = (rt_sem_t)(void *)(uint32_t *)(*(uint32_t *)semaphoreHandle);
+
+ /* Convert timeout from millisecond to tick. */
+ if (millisec == osaWaitForever_c)
+ {
+ timeoutTicks = RT_WAITING_FOREVER;
+ }
+ else
+ {
+ timeoutTicks = rt_tick_from_millisecond(millisec);
+ }
+
+ if (RT_EOK != rt_sem_take(sem, timeoutTicks))
+ {
+ return KOSA_StatusTimeout; /* timeout */
+ }
+ else
+ {
+ return KOSA_StatusSuccess; /* semaphore taken */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_SemaphorePost
+ * Description : This function is used to wake up one task that wating on the
+ * semaphore. If no task is waiting, increase the semaphore. The function returns
+ * KOSA_StatusSuccess if the semaphre is post successfully, otherwise returns
+ * KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_SemaphorePost(osa_semaphore_handle_t semaphoreHandle)
+{
+ assert(semaphoreHandle);
+ rt_sem_t sem = (rt_sem_t)(void *)(uint32_t *)(*(uint32_t *)semaphoreHandle);
+ rt_sem_release(sem);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MutexCreate
+ * Description : This function is used to create a mutex.
+ * Return : Mutex handle of the new mutex, or NULL if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MutexCreate(osa_mutex_handle_t mutexHandle)
+{
+ assert(sizeof(osa_mutex_handle_t) == OSA_MUTEX_HANDLE_SIZE);
+ assert(mutexHandle);
+
+ union
+ {
+ rt_mutex_t mutex;
+ uint32_t pmutexHandle;
+ } xMutexHandle;
+
+ xMutexHandle.mutex = rt_mutex_create("osa_mutex", RT_IPC_FLAG_PRIO);
+ if (RT_NULL != xMutexHandle.mutex)
+ {
+ *(uint32_t *)mutexHandle = xMutexHandle.pmutexHandle;
+ return KOSA_StatusSuccess;
+ }
+ return KOSA_StatusError;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MutexLock
+ * Description : This function checks the mutex's status, if it is unlocked,
+ * lock it and returns KOSA_StatusSuccess, otherwise, wait for the mutex.
+ * This function returns KOSA_StatusSuccess if the mutex is obtained, returns
+ * KOSA_StatusError if any errors occur during waiting. If the mutex has been
+ * locked, pass 0 as timeout will return KOSA_StatusTimeout immediately.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MutexLock(osa_mutex_handle_t mutexHandle, uint32_t millisec)
+{
+ assert(mutexHandle);
+ uint32_t timeoutTicks;
+ rt_mutex_t mutex = (rt_mutex_t)(void *)(uint32_t *)(*(uint32_t *)mutexHandle);
+
+ /* Convert timeout from millisecond to tick. */
+ if (millisec == osaWaitForever_c)
+ {
+ timeoutTicks = RT_WAITING_FOREVER;
+ }
+ else
+ {
+ timeoutTicks = rt_tick_from_millisecond(millisec);
+ }
+
+ if (RT_EOK != rt_mutex_take(mutex, timeoutTicks))
+ {
+ return KOSA_StatusTimeout; /* timeout */
+ }
+ else
+ {
+ return KOSA_StatusSuccess; /* semaphore taken */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MutexUnlock
+ * Description : This function is used to unlock a mutex.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MutexUnlock(osa_mutex_handle_t mutexHandle)
+{
+ assert(mutexHandle);
+ rt_mutex_t mutex = (rt_mutex_t)(void *)(uint32_t *)(*(uint32_t *)mutexHandle);
+ rt_mutex_release(mutex);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MutexDestroy
+ * Description : This function is used to destroy a mutex.
+ * Return : KOSA_StatusSuccess if the lock object is destroyed successfully, otherwise return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MutexDestroy(osa_mutex_handle_t mutexHandle)
+{
+ assert(mutexHandle);
+ rt_mutex_t mutex = (rt_mutex_t)(void *)(uint32_t *)(*(uint32_t *)mutexHandle);
+
+ rt_mutex_delete(mutex);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventCreate
+ * Description : This function is used to create a event object.
+ * Return : Event handle of the new event, or NULL if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventCreate(osa_event_handle_t eventHandle, uint8_t autoClear)
+{
+ assert(eventHandle);
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+
+ pEventStruct->handle = rt_event_create("osa_event", RT_IPC_FLAG_PRIO);
+ if (RT_NULL != pEventStruct->handle)
+ {
+ pEventStruct->autoClear = autoClear;
+ }
+ else
+ {
+ return KOSA_StatusError;
+ }
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventSet
+ * Description : Set one or more event flags of an event object.
+ * Return : KOSA_StatusSuccess if set successfully, KOSA_StatusError if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventSet(osa_event_handle_t eventHandle, osa_event_flags_t flagsToSet)
+{
+ rt_err_t result;
+ assert(eventHandle);
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+
+ if (RT_NULL == pEventStruct->handle)
+ {
+ return KOSA_StatusError;
+ }
+
+ rt_event_send(pEventStruct->handle, (rt_uint32_t)flagsToSet);
+
+ (void)result;
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventClear
+ * Description : Clear one or more event flags of an event object.
+ * Return :KOSA_StatusSuccess if clear successfully, KOSA_StatusError if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventClear(osa_event_handle_t eventHandle, osa_event_flags_t flagsToClear)
+{
+ assert(eventHandle);
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+
+ if (RT_NULL == pEventStruct->handle)
+ {
+ return KOSA_StatusError;
+ }
+
+ rt_uint32_t recved;
+ rt_event_recv(pEventStruct->handle, (rt_uint32_t)flagsToClear, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0, &recved);
+
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventGet
+ * Description : This function is used to get event's flags that specified by prameter
+ * flagsMask, and the flags (user specified) are obatianed by parameter pFlagsOfEvent. So
+ * you should pass the parameter 0xffffffff to specify you want to check all.
+ * Return :KOSA_StatusSuccess if event flags were successfully got, KOSA_StatusError if failed.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventGet(osa_event_handle_t eventHandle, osa_event_flags_t flagsMask, osa_event_flags_t *pFlagsOfEvent)
+{
+ assert(eventHandle);
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+ rt_uint32_t eventFlags;
+
+ if (RT_NULL == pEventStruct->handle)
+ {
+ return KOSA_StatusError;
+ }
+
+ if (RT_NULL == pFlagsOfEvent)
+ {
+ return KOSA_StatusError;
+ }
+
+ if (RT_EOK != rt_event_recv(pEventStruct->handle, (rt_uint32_t)flagsMask, RT_EVENT_FLAG_OR, 0, &eventFlags))
+ {
+ eventFlags = 0;
+ }
+
+ *pFlagsOfEvent = (osa_event_flags_t)eventFlags & flagsMask;
+
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventWait
+ * Description : This function checks the event's status, if it meets the wait
+ * condition, return KOSA_StatusSuccess, otherwise, timeout will be used for
+ * wait. The parameter timeout indicates how long should wait in milliseconds.
+ * Pass osaWaitForever_c to wait indefinitely, pass 0 will return the value
+ * KOSA_StatusTimeout immediately if wait condition is not met. The event flags
+ * will be cleared if the event is auto clear mode. Flags that wakeup waiting
+ * task could be obtained from the parameter setFlags.
+ * This function returns KOSA_StatusSuccess if wait condition is met, returns
+ * KOSA_StatusTimeout if wait condition is not met within the specified
+ * 'timeout', returns KOSA_StatusError if any errors occur during waiting.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventWait(osa_event_handle_t eventHandle,
+ osa_event_flags_t flagsToWait,
+ uint8_t waitAll,
+ uint32_t millisec,
+ osa_event_flags_t *pSetFlags)
+{
+ assert(eventHandle);
+ rt_uint8_t option = 0;
+ rt_uint32_t timeoutTicks;
+ rt_uint32_t flagsSave;
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+
+ /* Clean FreeRTOS cotrol flags */
+ flagsToWait = flagsToWait & 0x00FFFFFFU;
+ if (RT_NULL == pEventStruct->handle)
+ {
+ return KOSA_StatusError;
+ }
+
+ /* Convert timeout from millisecond to tick. */
+ if (millisec == osaWaitForever_c)
+ {
+ timeoutTicks = RT_WAITING_FOREVER;
+ }
+ else
+ {
+ timeoutTicks = rt_tick_from_millisecond(millisec);
+ }
+
+ if (pEventStruct->autoClear != 0U)
+ {
+ option |= RT_EVENT_FLAG_CLEAR;
+ }
+ option |= waitAll ? RT_EVENT_FLAG_AND : RT_EVENT_FLAG_OR;
+
+ rt_err_t status = rt_event_recv(pEventStruct->handle, (rt_uint32_t)flagsToWait, option, timeoutTicks, &flagsSave);
+
+ flagsSave &= (rt_uint32_t)flagsToWait;
+ if (RT_NULL != pSetFlags)
+ {
+ *pSetFlags = (osa_event_flags_t)flagsSave;
+ }
+
+ if (RT_EOK != status)
+ {
+ return KOSA_StatusTimeout;
+ }
+ else
+ {
+ return KOSA_StatusSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EventDestroy
+ * Description : This function is used to destroy a event object. Return
+ * KOSA_StatusSuccess if the event object is destroyed successfully, otherwise
+ * return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_EventDestroy(osa_event_handle_t eventHandle)
+{
+ assert(eventHandle);
+ osa_event_struct_t *pEventStruct = (osa_event_struct_t *)eventHandle;
+
+ if (RT_NULL == pEventStruct->handle)
+ {
+ return KOSA_StatusError;
+ }
+ rt_event_delete(pEventStruct->handle);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MsgQCreate
+ * Description : This function is used to create a message queue.
+ * Return : the handle to the message queue if create successfully, otherwise
+ * return NULL.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MsgQCreate(osa_msgq_handle_t msgqHandle, uint32_t msgNo, uint32_t msgSize)
+{
+ assert(sizeof(osa_msgq_handle_t) == OSA_MSGQ_HANDLE_SIZE);
+ assert(msgqHandle);
+
+ union
+ {
+ rt_mq_t msgq;
+ uint32_t pmsgqHandle;
+ } xMsgqHandle;
+
+ /* Create the message queue where the number and size is specified by msgNo and msgSize */
+ xMsgqHandle.msgq = rt_mq_create("osa_mq", msgSize, msgNo, RT_IPC_FLAG_PRIO);
+ if (RT_NULL != xMsgqHandle.msgq)
+ {
+ *(uint32_t *)msgqHandle = xMsgqHandle.pmsgqHandle;
+ return KOSA_StatusSuccess;
+ }
+ return KOSA_StatusError;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MsgQPut
+ * Description : This function is used to put a message to a message queue.
+ * Return : KOSA_StatusSuccess if the message is put successfully, otherwise return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MsgQPut(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage)
+{
+ assert(msgqHandle);
+ rt_mq_t handler = (rt_mq_t)(void *)(uint32_t *)(*(uint32_t *)msgqHandle);
+
+ if (RT_EOK == rt_mq_send(handler, pMessage, handler->msg_size))
+ {
+ return KOSA_StatusSuccess;
+ }
+ else
+ {
+ return KOSA_StatusError;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MsgQGet
+ * Description : This function checks the queue's status, if it is not empty,
+ * get message from it and return KOSA_StatusSuccess, otherwise, timeout will
+ * be used for wait. The parameter timeout indicates how long should wait in
+ * milliseconds. Pass osaWaitForever_c to wait indefinitely, pass 0 will return
+ * KOSA_StatusTimeout immediately if queue is empty.
+ * This function returns KOSA_StatusSuccess if message is got successfully,
+ * returns KOSA_StatusTimeout if message queue is empty within the specified
+ * 'timeout', returns KOSA_StatusError if any errors occur during waiting.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MsgQGet(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage, uint32_t millisec)
+{
+ osa_status_t osaStatus;
+ assert(msgqHandle);
+ rt_mq_t handler = (rt_mq_t)(void *)(uint32_t *)(*(uint32_t *)msgqHandle);
+
+ uint32_t timeoutTicks;
+
+ if (millisec == osaWaitForever_c)
+ {
+ timeoutTicks = RT_WAITING_FOREVER;
+ }
+ else
+ {
+ timeoutTicks = rt_tick_from_millisecond(millisec);
+ }
+ if (RT_EOK != rt_mq_recv(handler, pMessage, handler->msg_size, timeoutTicks))
+ {
+ osaStatus = KOSA_StatusTimeout; /* not able to send it to the queue? */
+ }
+ else
+ {
+ osaStatus = KOSA_StatusSuccess;
+ }
+ return osaStatus;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_MsgQDestroy
+ * Description : This function is used to destroy the message queue.
+ * Return : KOSA_StatusSuccess if the message queue is destroyed successfully, otherwise return KOSA_StatusError.
+ *
+ *END**************************************************************************/
+osa_status_t OSA_MsgQDestroy(osa_msgq_handle_t msgqHandle)
+{
+ assert(msgqHandle);
+ rt_mq_t handler = (rt_mq_t)(void *)(uint32_t *)(*(uint32_t *)msgqHandle);
+
+ rt_mq_delete(handler);
+ return KOSA_StatusSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_InterruptEnable
+ * Description : self explanatory.
+ *
+ *END**************************************************************************/
+void OSA_InterruptEnable(void)
+{
+ rt_exit_critical();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_InterruptDisable
+ * Description : self explanatory.
+ *
+ *END**************************************************************************/
+void OSA_InterruptDisable(void)
+{
+ rt_enter_critical();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_EnableIRQGlobal
+ * Description : enable interrupts using PRIMASK register.
+ *
+ *END**************************************************************************/
+void OSA_EnableIRQGlobal(void)
+{
+ if (s_osaState.interruptDisableCount > 0U)
+ {
+ s_osaState.interruptDisableCount--;
+
+ if (0U == s_osaState.interruptDisableCount)
+ {
+ __enable_irq();
+ }
+ /* call core API to enable the global interrupt*/
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_DisableIRQGlobal
+ * Description : disable interrupts using PRIMASK register.
+ *
+ *END**************************************************************************/
+void OSA_DisableIRQGlobal(void)
+{
+ /* call core API to disable the global interrupt*/
+ __disable_irq();
+
+ /* update counter*/
+ s_osaState.interruptDisableCount++;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : OSA_InstallIntHandler
+ * Description : This function is used to install interrupt handler.
+ *
+ *END**************************************************************************/
+void OSA_InstallIntHandler(uint32_t IRQNumber, void (*handler)(void))
+{
+#if defined(__IAR_SYSTEMS_ICC__)
+ _Pragma("diag_suppress = Pm138")
+#endif
+#if defined(ENABLE_RAM_VECTOR_TABLE)
+ (void) InstallIRQHandler((IRQn_Type)IRQNumber, (uint32_t) * (uint32_t *)&handler);
+#endif /* ENABLE_RAM_VECTOR_TABLE. */
+#if defined(__IAR_SYSTEMS_ICC__)
+ _Pragma("diag_remark = PM138")
+#endif
+}
+
+/*!*********************************************************************************
+*************************************************************************************
+* Private functions
+*************************************************************************************
+********************************************************************************** */
+#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
+
+static OSA_TASK_DEFINE(startup_task, gMainThreadPriority_c, 1, gMainThreadStackSize_c, 0);
+
+int main(void)
+{
+ extern void BOARD_InitHardware(void);
+ /* Initialize MCU clock */
+ BOARD_InitHardware();
+ LIST_Init((&s_osaState.taskList), 0);
+
+ s_osaState.basePriorityNesting = 0;
+ s_osaState.interruptDisableCount = 0;
+ (void)OSA_TaskCreate((osa_task_handle_t)s_osaState.mainTaskHandle, OSA_TASK(startup_task), NULL);
+
+ vTaskStartScheduler();
+ return 0;
+}
+#endif /* FSL_OSA_TASK_ENABLE */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h
new file mode 100644
index 0000000000..0e0423753f
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h
@@ -0,0 +1,130 @@
+/*! *********************************************************************************
+ * Copyright (c) 2013-2014, Freescale Semiconductor, Inc.
+ * Copyright 2016-2017 NXP
+ * All rights reserved.
+ *
+ * ile
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ ********************************************************************************** */
+#if !defined(__FSL_OS_ABSTRACTION_RTTHREAD_H__)
+#define __FSL_OS_ABSTRACTION_RTTHREAD_H__
+
+#if defined(__IAR_SYSTEMS_ICC__)
+/**
+ * Workaround to disable MISRA C message suppress warnings for IAR compiler.
+ */
+// http://supp.iar.com/Support/?note=24725
+
+#define MISRAC_DISABLE \
+ _Pragma( \
+ "diag_suppress= \
+ Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
+ Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
+ Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
+ Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
+ Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
+ Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
+ Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
+ Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
+ Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
+ Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
+ Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
+ Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
+ Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
+ Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
+ Pm155")
+
+#define MISRAC_ENABLE \
+ _Pragma( \
+ "diag_default= \
+ Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
+ Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
+ Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
+ Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
+ Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
+ Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
+ Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
+ Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
+ Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
+ Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
+ Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
+ Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
+ Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
+ Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
+ Pm155")
+#else
+/* Empty MISRA C macros for other toolchains. */
+#define MISRAC_DISABLE
+#define MISRAC_ENABLE
+#endif
+
+MISRAC_DISABLE
+#include <rtthread.h>
+MISRAC_ENABLE
+
+/*!
+ * @addtogroup os_abstraction_free_rtos
+ * @{
+ */
+
+/*******************************************************************************
+ * Declarations
+ ******************************************************************************/
+/*! @brief Type for a task handler, returned by the OSA_TaskCreate function. */
+typedef rt_thread_t task_handler_t;
+
+/*! @brief Type for a task stack.*/
+typedef rt_uint32_t task_stack_t;
+
+/*! @brief Type for task parameter */
+typedef void *task_param_t;
+
+/*! @brief Type for an event flags object.*/
+typedef rt_uint32_t event_flags_t;
+
+/*! @brief Constant to pass as timeout value in order to wait indefinitely. */
+#define OSA_WAIT_FOREVER 0xFFFFFFFFU
+
+/*! @brief OSA's time range in millisecond, OSA time wraps if exceeds this value. */
+#define FSL_OSA_TIME_RANGE 0xFFFFFFFFU
+
+/*! @brief The default interrupt handler installed in vector table. */
+#define OSA_DEFAULT_INT_HANDLER ((osa_int_handler_t)(&DefaultISR))
+
+extern void DefaultISR(void);
+
+/*!
+ * @name Thread management
+ * @{
+ */
+
+/*!
+ * @brief To provide unified task piority for upper layer, OSA layer makes conversion.
+ */
+#define PRIORITY_OSA_TO_RTOS(osa_prio) ((UBaseType_t)configMAX_PRIORITIES - (osa_prio)-2U)
+#define PRIORITY_RTOS_TO_OSA(rtos_prio) ((UBaseType_t)configMAX_PRIORITIES - (rtos_prio)-2U)
+
+/* @}*/
+
+/*!
+ * @name Message queues
+ * @{
+ */
+
+/*!
+ * @brief This macro statically reserves the memory required for the queue.
+ *
+ * @param name Identifier for the memory region.
+ * @param number Number of elements in the queue.
+ * @param size Size of every elements in words.
+ */
+#define MSG_QUEUE_DECLARE(name, number, size) msg_queue_t *name = NULL
+
+/* @}*/
+
+/*! @}*/
+/*! @}*/
+/*! @}*/
+
+#endif // __FSL_OS_ABSTRACTION_RTTHREAD_H__ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c
new file mode 100644
index 0000000000..4c0984f503
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c
@@ -0,0 +1,475 @@
+/*
+ * Copyright 2018-2019 NXP
+ * All rights reserved.
+ *
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*! *********************************************************************************
+*************************************************************************************
+* Include
+*************************************************************************************
+********************************************************************************** */
+#include "generic_list.h"
+
+static list_status_t LIST_Error_Check(list_handle_t list, list_element_handle_t newElement)
+{
+ list_status_t listStatus = kLIST_Ok;
+ list_element_handle_t element = list->head;
+
+ if ((list->max != 0U) && (list->max == list->size))
+ {
+ listStatus = kLIST_Full; /*List is full*/
+ }
+ else
+ {
+ while (element != NULL) /*Scan list*/
+ {
+ /* Determine if element is duplicated */
+ if (element == newElement)
+ {
+ listStatus = kLIST_DuplicateError;
+ break;
+ }
+ element = element->next;
+ }
+ }
+
+ return listStatus;
+}
+
+/*! *********************************************************************************
+*************************************************************************************
+* Public functions
+*************************************************************************************
+********************************************************************************** */
+/*! *********************************************************************************
+ * \brief Initialises the list descriptor.
+ *
+ * \param[in] list - LIST_ handle to init.
+ * max - Maximum number of elements in list. 0 for unlimited.
+ *
+ * \return void.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+void LIST_Init(list_handle_t list, uint32_t max)
+{
+ list->head = NULL;
+ list->tail = NULL;
+ list->max = (uint16_t)max;
+ list->size = 0;
+}
+
+/*! *********************************************************************************
+ * \brief Gets the list that contains the given element.
+ *
+ * \param[in] element - Handle of the element.
+ *
+ * \return NULL if element is orphan.
+ * Handle of the list the element is inserted into.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_handle_t LIST_GetList(list_element_handle_t element)
+{
+ return element->list;
+}
+
+/*! *********************************************************************************
+ * \brief Links element to the tail of the list.
+ *
+ * \param[in] list - ID of list to insert into.
+ * element - element to add
+ *
+ * \return kLIST_Full if list is full.
+ * kLIST_Ok if insertion was successful.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element)
+{
+ uint32_t regPrimask = DisableGlobalIRQ();
+ list_status_t listStatus = kLIST_Ok;
+
+ listStatus = LIST_Error_Check(list, element);
+ if (listStatus == kLIST_Ok) /* Avoiding list status error */
+ {
+ if (list->size == 0U)
+ {
+ list->head = element;
+ }
+ else
+ {
+ list->tail->next = element;
+ }
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+#else
+ element->prev = list->tail;
+#endif
+ element->list = list;
+ element->next = NULL;
+ list->tail = element;
+ list->size++;
+ }
+
+ EnableGlobalIRQ(regPrimask);
+ return listStatus;
+}
+
+/*! *********************************************************************************
+ * \brief Links element to the head of the list.
+ *
+ * \param[in] list - ID of list to insert into.
+ * element - element to add
+ *
+ * \return kLIST_Full if list is full.
+ * kLIST_Ok if insertion was successful.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element)
+{
+ uint32_t regPrimask = DisableGlobalIRQ();
+ list_status_t listStatus = kLIST_Ok;
+
+ listStatus = LIST_Error_Check(list, element);
+ if (listStatus == kLIST_Ok) /* Avoiding list status error */
+ {
+ /* Links element to the head of the list */
+ if (list->size == 0U)
+ {
+ list->tail = element;
+ }
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+#else
+ else
+ {
+ list->head->prev = element;
+ }
+ element->prev = NULL;
+#endif
+ element->list = list;
+ element->next = list->head;
+ list->head = element;
+ list->size++;
+ }
+
+ EnableGlobalIRQ(regPrimask);
+ return listStatus;
+}
+
+/*! *********************************************************************************
+ * \brief Unlinks element from the head of the list.
+ *
+ * \param[in] list - ID of list to remove from.
+ *
+ * \return NULL if list is empty.
+ * ID of removed element(pointer) if removal was successful.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_element_handle_t LIST_RemoveHead(list_handle_t list)
+{
+ list_element_handle_t element;
+
+ uint32_t regPrimask = DisableGlobalIRQ();
+
+ if ((NULL == list) || (list->size == 0U))
+ {
+ element = NULL; /*LIST_ is empty*/
+ }
+ else
+ {
+ element = list->head;
+ list->size--;
+ if (list->size == 0U)
+ {
+ list->tail = NULL;
+ }
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+#else
+ else
+ {
+ element->next->prev = NULL;
+ }
+#endif
+ element->list = NULL;
+ list->head = element->next; /*Is NULL if element is head*/
+ }
+
+ EnableGlobalIRQ(regPrimask);
+ return element;
+}
+
+/*! *********************************************************************************
+ * \brief Gets head element ID.
+ *
+ * \param[in] list - ID of list.
+ *
+ * \return NULL if list is empty.
+ * ID of head element if list is not empty.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_element_handle_t LIST_GetHead(list_handle_t list)
+{
+ return list->head;
+}
+
+/*! *********************************************************************************
+ * \brief Gets next element ID.
+ *
+ * \param[in] element - ID of the element.
+ *
+ * \return NULL if element is tail.
+ * ID of next element if exists.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_element_handle_t LIST_GetNext(list_element_handle_t element)
+{
+ return element->next;
+}
+
+/*! *********************************************************************************
+ * \brief Gets previous element ID.
+ *
+ * \param[in] element - ID of the element.
+ *
+ * \return NULL if element is head.
+ * ID of previous element if exists.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_element_handle_t LIST_GetPrev(list_element_handle_t element)
+{
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+ return NULL;
+#else
+ return element->prev;
+#endif
+}
+
+/*! *********************************************************************************
+ * \brief Unlinks an element from its list.
+ *
+ * \param[in] element - ID of the element to remove.
+ *
+ * \return kLIST_OrphanElement if element is not part of any list.
+ * kLIST_Ok if removal was successful.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_status_t LIST_RemoveElement(list_element_handle_t element)
+{
+ list_status_t listStatus = kLIST_Ok;
+ uint32_t regPrimask = DisableGlobalIRQ();
+
+ if (element->list == NULL)
+ {
+ listStatus = kLIST_OrphanElement; /*Element was previusly removed or never added*/
+ }
+ else
+ {
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+ list_element_handle_t element_list = element->list->head;
+ while (element_list)
+ {
+ if (element->list->head == element)
+ {
+ element->list->head = element_list->next;
+ break;
+ }
+ if (element_list->next == element)
+ {
+ element_list->next = element->next;
+ break;
+ }
+ element_list = element_list->next;
+ }
+#else
+ if (element->prev == NULL) /*Element is head or solo*/
+ {
+ element->list->head = element->next; /*is null if solo*/
+ }
+ if (element->next == NULL) /*Element is tail or solo*/
+ {
+ element->list->tail = element->prev; /*is null if solo*/
+ }
+ if (element->prev != NULL) /*Element is not head*/
+ {
+ element->prev->next = element->next;
+ }
+ if (element->next != NULL) /*Element is not tail*/
+ {
+ element->next->prev = element->prev;
+ }
+#endif
+ element->list->size--;
+ element->list = NULL;
+ }
+
+ EnableGlobalIRQ(regPrimask);
+ return listStatus;
+}
+
+/*! *********************************************************************************
+ * \brief Links an element in the previous position relative to a given member
+ * of a list.
+ *
+ * \param[in] element - ID of a member of a list.
+ * newElement - new element to insert before the given member.
+ *
+ * \return kLIST_OrphanElement if element is not part of any list.
+ * kLIST_Full if list is full.
+ * kLIST_Ok if insertion was successful.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement)
+{
+ list_status_t listStatus = kLIST_Ok;
+ uint32_t regPrimask = DisableGlobalIRQ();
+
+ if (element->list == NULL)
+ {
+ listStatus = kLIST_OrphanElement; /*Element was previusly removed or never added*/
+ }
+ else
+ {
+ listStatus = LIST_Error_Check(element->list, newElement);
+ if (listStatus == kLIST_Ok)
+ {
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+ list_element_handle_t element_list = element->list->head;
+ while (element_list)
+ {
+ if ((element_list->next == element) || (element_list == element))
+ {
+ if (element_list == element)
+ {
+ element->list->head = newElement;
+ }
+ else
+ {
+ element_list->next = newElement;
+ }
+ newElement->list = element->list;
+ newElement->next = element;
+ element->list->size++;
+ break;
+ }
+ element_list = element_list->next;
+ }
+
+#else
+ if (element->prev == NULL) /*Element is list head*/
+ {
+ element->list->head = newElement;
+ }
+ else
+ {
+ element->prev->next = newElement;
+ }
+ newElement->list = element->list;
+ element->list->size++;
+ newElement->next = element;
+ newElement->prev = element->prev;
+ element->prev = newElement;
+#endif
+ }
+ }
+
+ EnableGlobalIRQ(regPrimask);
+ return listStatus;
+}
+
+/*! *********************************************************************************
+ * \brief Gets the current size of a list.
+ *
+ * \param[in] list - ID of the list.
+ *
+ * \return Current size of the list.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+uint32_t LIST_GetSize(list_handle_t list)
+{
+ return list->size;
+}
+
+/*! *********************************************************************************
+ * \brief Gets the number of free places in the list.
+ *
+ * \param[in] list - ID of the list.
+ *
+ * \return Available size of the list.
+ *
+ * \pre
+ *
+ * \post
+ *
+ * \remarks
+ *
+ ********************************************************************************** */
+uint32_t LIST_GetAvailableSize(list_handle_t list)
+{
+ return ((uint32_t)list->max - (uint32_t)list->size); /*Gets the number of free places in the list*/
+} \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h
new file mode 100644
index 0000000000..0da10d338d
--- /dev/null
+++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2018-2020 NXP
+ * All rights reserved.
+ *
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _GENERIC_LIST_H_
+#define _GENERIC_LIST_H_
+
+#include "fsl_common.h"
+/*!
+ * @addtogroup GenericList
+ * @{
+ */
+
+/*!*********************************************************************************
+*************************************************************************************
+* Include
+*************************************************************************************
+********************************************************************************** */
+
+/*! *********************************************************************************
+*************************************************************************************
+* Public macro definitions
+*************************************************************************************
+********************************************************************************** */
+#ifndef GENERIC_LIST_LIGHT
+#define GENERIC_LIST_LIGHT (0)
+#endif
+/*! *********************************************************************************
+*************************************************************************************
+* Public type definitions
+*************************************************************************************
+********************************************************************************** */
+/*! @brief The list status */
+typedef enum _list_status
+{
+ kLIST_Ok = kStatus_Success, /*!< Success */
+ kLIST_DuplicateError = MAKE_STATUS(kStatusGroup_LIST, 1), /*!< Duplicate Error */
+ kLIST_Full = MAKE_STATUS(kStatusGroup_LIST, 2), /*!< FULL */
+ kLIST_Empty = MAKE_STATUS(kStatusGroup_LIST, 3), /*!< Empty */
+ kLIST_OrphanElement = MAKE_STATUS(kStatusGroup_LIST, 4), /*!< Orphan Element */
+ kLIST_NotSupport = MAKE_STATUS(kStatusGroup_LIST, 5), /*!< Not Support */
+} list_status_t;
+
+/*! @brief The list structure*/
+typedef struct list_label
+{
+ struct list_element_tag *head; /*!< list head */
+ struct list_element_tag *tail; /*!< list tail */
+ uint16_t size; /*!< list size */
+ uint16_t max; /*!< list max number of elements */
+} list_label_t, *list_handle_t;
+#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
+/*! @brief The list element*/
+typedef struct list_element_tag
+{
+ struct list_element_tag *next; /*!< next list element */
+ struct list_label *list; /*!< pointer to the list */
+} list_element_t, *list_element_handle_t;
+#else
+/*! @brief The list element*/
+typedef struct list_element_tag
+{
+ struct list_element_tag *next; /*!< next list element */
+ struct list_element_tag *prev; /*!< previous list element */
+ struct list_label *list; /*!< pointer to the list */
+} list_element_t, *list_element_handle_t;
+#endif
+/*! *********************************************************************************
+*************************************************************************************
+* Public prototypes
+*************************************************************************************
+********************************************************************************** */
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* _cplusplus */
+/*!
+ * @brief Initialize the list.
+ *
+ * This function initialize the list.
+ *
+ * @param list - List handle to initialize.
+ * @param max - Maximum number of elements in list. 0 for unlimited.
+ */
+void LIST_Init(list_handle_t list, uint32_t max);
+
+/*!
+ * @brief Gets the list that contains the given element.
+ *
+ *
+ * @param element - Handle of the element.
+ * @retval NULL if element is orphan, Handle of the list the element is inserted into.
+ */
+list_handle_t LIST_GetList(list_element_handle_t element);
+
+/*!
+ * @brief Links element to the head of the list.
+ *
+ * @param list - Handle of the list.
+ * @param element - Handle of the element.
+ * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
+ */
+list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element);
+
+/*!
+ * @brief Links element to the tail of the list.
+ *
+ * @param list - Handle of the list.
+ * @param element - Handle of the element.
+ * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
+ */
+list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element);
+
+/*!
+ * @brief Unlinks element from the head of the list.
+ *
+ * @param list - Handle of the list.
+ *
+ * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
+ */
+list_element_handle_t LIST_RemoveHead(list_handle_t list);
+
+/*!
+ * @brief Gets head element handle.
+ *
+ * @param list - Handle of the list.
+ *
+ * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
+ */
+list_element_handle_t LIST_GetHead(list_handle_t list);
+
+/*!
+ * @brief Gets next element handle for given element handle.
+ *
+ * @param element - Handle of the element.
+ *
+ * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
+ */
+list_element_handle_t LIST_GetNext(list_element_handle_t element);
+
+/*!
+ * @brief Gets previous element handle for given element handle.
+ *
+ * @param element - Handle of the element.
+ *
+ * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
+ */
+list_element_handle_t LIST_GetPrev(list_element_handle_t element);
+
+/*!
+ * @brief Unlinks an element from its list.
+ *
+ * @param element - Handle of the element.
+ *
+ * @retval kLIST_OrphanElement if element is not part of any list.
+ * @retval kLIST_Ok if removal was successful.
+ */
+list_status_t LIST_RemoveElement(list_element_handle_t element);
+
+/*!
+ * @brief Links an element in the previous position relative to a given member of a list.
+ *
+ * @param list - Handle of the list.
+ * @param element - Handle of the element.
+ * @param newElement - New element to insert before the given member.
+ *
+ * @retval kLIST_OrphanElement if element is not part of any list.
+ * @retval kLIST_Ok if removal was successful.
+ */
+list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement);
+
+/*!
+ * @brief Gets the current size of a list.
+ *
+ * @param list - Handle of the list.
+ *
+ * @retval Current size of the list.
+ */
+uint32_t LIST_GetSize(list_handle_t list);
+
+/*!
+ * @brief Gets the number of free places in the list.
+ *
+ * @param list - Handle of the list.
+ *
+ * @retval Available size of the list.
+ */
+uint32_t LIST_GetAvailableSize(list_handle_t list);
+
+/* @} */
+
+#if defined(__cplusplus)
+}
+#endif
+/*! @}*/
+#endif /*_GENERIC_LIST_H_*/ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/MIMXRT1050/SConscript b/bsp/imxrt/libraries/MIMXRT1050/SConscript
index c774395330..58a2922fe1 100644
--- a/bsp/imxrt/libraries/MIMXRT1050/SConscript
+++ b/bsp/imxrt/libraries/MIMXRT1050/SConscript
@@ -83,6 +83,10 @@ if GetDepend(['BSP_USING_PULSE_ENCODER']):
src += ['MIMXRT1052/drivers/fsl_xbara.c']
src += ['MIMXRT1052/drivers/fsl_xbarb.c']
+#fsl os abstract files
+src += ['MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c']
+src += ['MIMXRT1052/drivers/generic_list.c']
+
if rtconfig.CROSS_TOOL == 'gcc':
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, ASFLAGS = '$ASFLAGS -D __STARTUP_CLEAR_BSS')
else:
diff --git a/bsp/imxrt/libraries/drivers/SConscript b/bsp/imxrt/libraries/drivers/SConscript
index eaefd7c5e1..e166989a24 100644
--- a/bsp/imxrt/libraries/drivers/SConscript
+++ b/bsp/imxrt/libraries/drivers/SConscript
@@ -59,10 +59,14 @@ if GetDepend('BSP_USING_USB_DEVICE'):
src += ['drv_usbd.c']
src += Glob('usb/device/*.c')
-if GetDepend('BSP_USING_USB_DEVICE'):
+if GetDepend('BSP_USING_USB_DEVICE') or GetDepend('RT_USING_USB_HOST'):
src += Glob('usb/phy/*.c')
- CPPDEFINES += ['ENDIANNESS']
+ CPPDEFINES += ['ENDIANNESS','USE_RTOS']
+if GetDepend('RT_USING_USB_HOST'):
+ src += ['drv_usbh.c']
+ src += Glob('usb/host/*.c')
+
if GetDepend('BSP_USING_PULSE_ENCODER'):
src += ['drv_pulse_encoder.c']
diff --git a/bsp/imxrt/libraries/drivers/drv_usbh.c b/bsp/imxrt/libraries/drivers/drv_usbh.c
new file mode 100644
index 0000000000..a7e0ad6062
--- /dev/null
+++ b/bsp/imxrt/libraries/drivers/drv_usbh.c
@@ -0,0 +1,730 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-10-30 ZYH the first version
+ * 2019-12-19 tyustli port to stm32 series
+ * 2021-01-19 Leslie Lee port to imxrt series
+ */
+#include <rtthread.h>
+
+#if defined(BSP_USB0_HOST) || defined(BSP_USB1_HOST)
+#include "drv_usbh.h"
+#include <usb/include/usb_host_config.h>
+#include <usb/include/usb.h>
+#include <usb/phy/usb_phy.h>
+#include <usb/host/usb_host.h>
+#include <usb/host/usb_host_hci.h>
+#include <usb/host/usb_host_ehci.h>
+#include <rtdevice.h>
+
+
+/* USB PHY configuration */
+#ifndef BOARD_USB_PHY_D_CAL
+#define BOARD_USB_PHY_D_CAL (0x0CU)
+#endif
+#ifndef BOARD_USB_PHY_TXCAL45DP
+#define BOARD_USB_PHY_TXCAL45DP (0x06U)
+#endif
+#ifndef BOARD_USB_PHY_TXCAL45DM
+#define BOARD_USB_PHY_TXCAL45DM (0x06U)
+#endif
+
+#define USB_HOST_INTERRUPT_PRIORITY 3
+
+enum
+{
+#ifdef BSP_USB0_HOST
+ USBH0_INDEX,
+#endif
+#ifdef BSP_USB1_HOST
+ USBH1_INDEX,
+#endif
+};
+
+struct imxrt_usb_host_pipe
+{
+ usb_host_pipe_handle pipe_handle;
+ struct rt_completion urb_completion;
+ usb_status_t transfer_status;
+};
+
+struct imxrt_usb_host
+{
+ struct uhcd uhcd;
+ usb_host_handle host_handle;
+ usb_device_handle device_handle;
+ struct imxrt_usb_host_pipe pipes[16];
+ volatile rt_bool_t connect_status;
+ char *name;
+};
+
+static struct imxrt_usb_host imxrt_usb_host_obj[] =
+{
+#ifdef BSP_USB0_HOST
+ {
+ .connect_status = RT_FALSE,
+ .name = "usbh0"
+ },
+#endif
+#ifdef BSP_USB1_HOST
+ {
+ .connect_status = RT_FALSE,
+ .name = "usbh1"
+ },
+#endif
+};
+
+static void _imxrt_usb_host_send_callback(void *param, usb_host_transfer_t *transfer, usb_status_t status)
+{
+ struct imxrt_usb_host_pipe *pipe = (struct imxrt_usb_host_pipe *)param;
+ pipe->transfer_status = status;
+ rt_completion_done(&pipe->urb_completion);
+}
+
+
+/*!
+ * @brief Initializes USB specific setting that was not set by the Clocks tool.
+ */
+static void USB_HostClockInit(usb_controller_index_t controller_id)
+{
+ usb_phy_config_struct_t phyConfig = {
+ BOARD_USB_PHY_D_CAL, BOARD_USB_PHY_TXCAL45DP, BOARD_USB_PHY_TXCAL45DM,
+ };
+ uint32_t notUsed = 0;
+
+ if (controller_id == kUSB_ControllerEhci0)
+ {
+ CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
+ CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, 480000000U);
+ }
+ else
+ {
+ CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
+ CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, 480000000U);
+ }
+
+ USB_EhciPhyInit(controller_id, 24000000U, &phyConfig);
+}
+
+/*!
+ * @brief Enables interrupt service routines for device.
+ */
+void USB_HostIsrEnable(usb_controller_index_t controller_id)
+{
+ uint8_t irqNumber;
+#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
+ IRQn_Type usbHOSTEhciIrq[] = USBHS_IRQS;
+ irqNumber = usbHOSTEhciIrq[controller_id - kUSB_ControllerEhci0];
+#endif
+/* Install isr, set priority, and enable IRQ. */
+#if defined(__GIC_PRIO_BITS)
+ GIC_SetPriority((IRQn_Type)irqNumber, USB_HOST_INTERRUPT_PRIORITY);
+#else
+ NVIC_SetPriority((IRQn_Type)irqNumber, USB_HOST_INTERRUPT_PRIORITY);
+#endif
+ EnableIRQ((IRQn_Type)irqNumber);
+}
+
+#ifdef BSP_USB0_HOST
+void USB_OTG1_IRQHandler(void)
+{
+ /* enter interrupt */
+ rt_interrupt_enter();
+
+ USB_HostEhciIsrFunction(imxrt_usb_host_obj[USBH0_INDEX].host_handle);
+ /* leave interrupt */
+ rt_interrupt_leave();
+}
+
+static rt_err_t _ehci0_reset_port(rt_uint8_t port)
+{
+ // No reset port function available
+ return RT_EOK;
+}
+
+static uint8_t _ehci0_pipe_buf[64];
+static uint8_t _ehci0_pipe_idx;
+
+static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
+{
+ int timeout = timeouts;
+
+ if (!imxrt_usb_host_obj[USBH0_INDEX].connect_status)
+ {
+ return -1;
+ }
+ usb_host_transfer_t *transfer;
+ if (imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
+ return -1;
+ }
+ if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, &transfer) != kStatus_USB_Success)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
+ return -1;
+ }
+ transfer->transferBuffer = buffer;
+ transfer->transferLength = nbytes;
+ transfer->transferSofar = 0;
+ transfer->callbackFn = _imxrt_usb_host_send_callback;
+ transfer->callbackParam = &(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index]);
+ transfer->direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT;
+ if (pipe->ep.bmAttributes == USB_ENDPOINT_CONTROL)
+ {
+ if (token == USBH_PID_SETUP)
+ {
+ struct urequest *setup = (struct urequest *)buffer;
+ transfer->setupStatus = 0;
+ transfer->setupPacket->bmRequestType = setup->request_type;
+ transfer->setupPacket->bRequest = setup->bRequest;
+ transfer->setupPacket->wIndex = setup->wIndex;
+ transfer->setupPacket->wLength = setup->wLength;
+ transfer->setupPacket->wValue = setup->wValue;
+ transfer->transferBuffer = RT_NULL;
+ transfer->transferLength = 0;
+ transfer->next = RT_NULL;
+ if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
+ {
+ transfer->direction = USB_IN;
+ transfer->transferBuffer = _ehci0_pipe_buf;
+ transfer->transferLength = setup->wLength;
+ _ehci0_pipe_idx = 0;
+ }
+ else
+ {
+ transfer->direction = USB_OUT;
+ }
+ }
+ else
+ {
+ rt_memcpy(buffer, _ehci0_pipe_buf + _ehci0_pipe_idx, nbytes);
+ imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].transfer_status = kStatus_USB_Success;
+ transfer->transferSofar = nbytes;
+ _ehci0_pipe_idx += nbytes;
+ if (_ehci0_pipe_idx >= 64)
+ {
+ _ehci0_pipe_idx = 0;
+ }
+ goto _ehci0_pipe_xfer_finish;
+ }
+
+ }
+ rt_completion_init(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion));
+ if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH0_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
+ return -1;
+ }
+ if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
+ return -1;
+ }
+ _ehci0_pipe_xfer_finish:
+ switch (imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].transfer_status)
+ {
+ case kStatus_USB_Success:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
+ pipe->status = UPIPE_STATUS_OK;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ size_t size = transfer->transferSofar;
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
+ if (pipe->ep.bEndpointAddress & 0x80)
+ {
+ return size;
+ }
+ else if (pipe->ep.bEndpointAddress & 0x00)
+ {
+ return size;
+ }
+ return nbytes;
+ break;
+ }
+ case kStatus_USB_TransferStall:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
+ pipe->status = UPIPE_STATUS_STALL;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
+ return -1;
+ break;
+ }
+ case kStatus_USB_TransferFailed:
+ default:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
+ pipe->status = UPIPE_STATUS_ERROR;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
+ return -1;
+ break;
+ }
+ }
+}
+
+static rt_uint16_t _ehci0_pipe_index = 0;
+static rt_uint8_t _ehci0_get_free_pipe_index(void)
+{
+ rt_uint8_t idx;
+ for (idx = 1; idx < 16; idx++)
+ {
+ if (!(_ehci0_pipe_index & (0x01 << idx)))
+ {
+ _ehci0_pipe_index |= (0x01 << idx);
+ return idx;
+ }
+ }
+ return 0xff;
+}
+
+static void _ehci0_free_pipe_index(rt_uint8_t index)
+{
+ _ehci0_pipe_index &= ~(0x01 << index);
+}
+
+static rt_err_t _ehci0_open_pipe(upipe_t pipe)
+{
+ pipe->pipe_index = _ehci0_get_free_pipe_index();
+ if (pipe->pipe_index == 0xFF)
+ {
+ return -RT_ERROR;
+ }
+ usb_host_pipe_init_t pipe_init =
+ {
+ .devInstance = imxrt_usb_host_obj[USBH0_INDEX].device_handle,
+ .pipeType = pipe->ep.bmAttributes,
+ .direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT,
+ .endpointAddress = (pipe->ep.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK),
+ .interval = pipe->ep.bInterval,
+ .maxPacketSize = (uint16_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK),
+ .numberPerUframe = (uint8_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK),
+ .nakCount = USB_HOST_CONFIG_MAX_NAK,
+ };
+ USB_HostOpenPipe(imxrt_usb_host_obj[USBH0_INDEX].host_handle, &imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle, &pipe_init);
+ return RT_EOK;
+}
+
+static rt_err_t _ehci0_close_pipe(upipe_t pipe)
+{
+ (void)USB_HostClosePipe(imxrt_usb_host_obj[USBH0_INDEX].host_handle, imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle);
+ _ehci0_free_pipe_index(pipe->pipe_index);
+ return RT_EOK;
+}
+
+static struct uhcd_ops _ehci0_uhcd_ops =
+{
+ _ehci0_reset_port,
+ _ehci0_pipe_xfer,
+ _ehci0_open_pipe,
+ _ehci0_close_pipe,
+};
+
+static usb_status_t usb0_host_callback(usb_device_handle handle, usb_host_configuration_handle config_handle, rt_uint32_t event_code)
+{
+ usb_status_t status = kStatus_USB_Success;
+
+ switch (event_code)
+ {
+ case kUSB_HostEventAttach:
+ if (!imxrt_usb_host_obj[USBH0_INDEX].connect_status)
+ {
+ imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_TRUE;
+ imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
+ rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT, RT_TRUE);
+ }
+ break;
+
+ case kUSB_HostEventNotSupported:
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
+ break;
+
+ case kUSB_HostEventEnumerationDone:
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
+ break;
+
+ case kUSB_HostEventDetach:
+ if (imxrt_usb_host_obj[USBH0_INDEX].connect_status)
+ {
+ imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_FALSE;
+ imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
+ rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT);
+ (void)USB_HostCloseDeviceInterface(handle, NULL);
+ }
+ break;
+
+ default:
+ break;
+ }
+ return status;
+}
+
+rt_thread_t usbh0_thread;
+
+static void _ehci0_usbh_thread(void* param)
+{
+ while (1)
+ {
+ USB_HostEhciTaskFunction(imxrt_usb_host_obj[USBH0_INDEX].host_handle);
+ }
+}
+
+static rt_err_t _ehci0_usbh_init(rt_device_t device)
+{
+ USB_HostClockInit(kUSB_ControllerEhci0);
+
+ if (kStatus_USB_Success == USB_HostInit(kUSB_ControllerEhci0, &imxrt_usb_host_obj[USBH0_INDEX].host_handle, usb0_host_callback))
+ {
+ usbh0_thread = rt_thread_create("ehci0", _ehci0_usbh_thread, RT_NULL, 500, 4, 9999999);
+ rt_thread_startup(usbh0_thread);
+ USB_HostIsrEnable(kUSB_ControllerEhci0);
+ }
+ else
+ {
+ rt_kprintf("USB_HostInit ehci0 error\r\n");
+ return -RT_ERROR;
+ }
+ return RT_EOK;
+}
+#endif
+
+#ifdef BSP_USB1_HOST
+void USB_OTG2_IRQHandler(void)
+{
+ /* enter interrupt */
+ rt_interrupt_enter();
+
+ USB_HostEhciIsrFunction(imxrt_usb_host_obj[USBH1_INDEX].host_handle);
+ /* leave interrupt */
+ rt_interrupt_leave();
+}
+
+static rt_err_t _ehci1_reset_port(rt_uint8_t port)
+{
+ // No reset port function available
+ return RT_EOK;
+}
+
+static uint8_t _ehci1_pipe_buf[64];
+static uint8_t _ehci1_pipe_idx;
+
+static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
+{
+ int timeout = timeouts;
+
+ if (!imxrt_usb_host_obj[USBH1_INDEX].connect_status)
+ {
+ return -1;
+ }
+ usb_host_transfer_t *transfer;
+ if (imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
+ return -1;
+ }
+ if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, &transfer) != kStatus_USB_Success)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
+ return -1;
+ }
+ transfer->transferBuffer = buffer;
+ transfer->transferLength = nbytes;
+ transfer->transferSofar = 0;
+ transfer->callbackFn = _imxrt_usb_host_send_callback;
+ transfer->callbackParam = &(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index]);
+ transfer->direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT;
+ if (pipe->ep.bmAttributes == USB_ENDPOINT_CONTROL)
+ {
+ if (token == USBH_PID_SETUP)
+ {
+ struct urequest *setup = (struct urequest *)buffer;
+ transfer->setupStatus = 0;
+ transfer->setupPacket->bmRequestType = setup->request_type;
+ transfer->setupPacket->bRequest = setup->bRequest;
+ transfer->setupPacket->wIndex = setup->wIndex;
+ transfer->setupPacket->wLength = setup->wLength;
+ transfer->setupPacket->wValue = setup->wValue;
+ transfer->transferBuffer = RT_NULL;
+ transfer->transferLength = 0;
+ transfer->next = RT_NULL;
+ if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
+ {
+ transfer->direction = USB_IN;
+ transfer->transferBuffer = _ehci1_pipe_buf;
+ transfer->transferLength = setup->wLength;
+ _ehci1_pipe_idx = 0;
+ }
+ else
+ {
+ transfer->direction = USB_OUT;
+ }
+ }
+ else
+ {
+ rt_memcpy(buffer, _ehci1_pipe_buf + _ehci1_pipe_idx, nbytes);
+ imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].transfer_status = kStatus_USB_Success;
+ transfer->transferSofar = nbytes;
+ _ehci1_pipe_idx += nbytes;
+ if (_ehci1_pipe_idx >= 64)
+ {
+ _ehci1_pipe_idx = 0;
+ }
+ goto _ehci1_pipe_xfer_finish;
+ }
+
+ }
+ rt_completion_init(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion));
+ if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH1_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
+ return -1;
+ }
+ if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
+ return -1;
+ }
+ // rt_thread_mdelay(1);
+ _ehci1_pipe_xfer_finish:
+ switch (imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].transfer_status)
+ {
+ case kStatus_USB_Success:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
+ pipe->status = UPIPE_STATUS_OK;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ size_t size = transfer->transferSofar;
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
+ if (pipe->ep.bEndpointAddress & 0x80)
+ {
+ return size;
+ }
+ else if (pipe->ep.bEndpointAddress & 0x00)
+ {
+ return size;
+ }
+ return nbytes;
+ break;
+ }
+ case kStatus_USB_TransferStall:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
+ pipe->status = UPIPE_STATUS_STALL;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
+ return -1;
+ break;
+ }
+ case kStatus_USB_TransferFailed:
+ default:
+ {
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
+ pipe->status = UPIPE_STATUS_ERROR;
+ if (pipe->callback != RT_NULL)
+ {
+ pipe->callback(pipe);
+ }
+ (void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
+ return -1;
+ break;
+ }
+ }
+}
+
+static rt_uint16_t _ehci1_pipe_index = 0;
+static rt_uint8_t _ehci1_get_free_pipe_index(void)
+{
+ rt_uint8_t idx;
+ for (idx = 1; idx < 16; idx++)
+ {
+ if (!(_ehci1_pipe_index & (0x01 << idx)))
+ {
+ _ehci1_pipe_index |= (0x01 << idx);
+ return idx;
+ }
+ }
+ return 0xff;
+}
+
+static void _ehci1_free_pipe_index(rt_uint8_t index)
+{
+ _ehci1_pipe_index &= ~(0x01 << index);
+}
+
+static rt_err_t _ehci1_open_pipe(upipe_t pipe)
+{
+ pipe->pipe_index = _ehci1_get_free_pipe_index();
+ if (pipe->pipe_index == 0xFF)
+ {
+ return -RT_ERROR;
+ }
+ usb_host_pipe_init_t pipe_init =
+ {
+ .devInstance = imxrt_usb_host_obj[USBH1_INDEX].device_handle,
+ .pipeType = pipe->ep.bmAttributes,
+ .direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT,
+ .endpointAddress = (pipe->ep.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK),
+ .interval = pipe->ep.bInterval,
+ .maxPacketSize = (uint16_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK),
+ .numberPerUframe = (uint8_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK),
+ .nakCount = USB_HOST_CONFIG_MAX_NAK,
+ };
+ USB_HostOpenPipe(imxrt_usb_host_obj[USBH1_INDEX].host_handle, &imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle, &pipe_init);
+ return RT_EOK;
+}
+
+static rt_err_t _ehci1_close_pipe(upipe_t pipe)
+{
+ (void)USB_HostClosePipe(imxrt_usb_host_obj[USBH1_INDEX].host_handle, imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle);
+ _ehci1_free_pipe_index(pipe->pipe_index);
+ return RT_EOK;
+}
+
+static struct uhcd_ops _ehci1_uhcd_ops =
+{
+ _ehci1_reset_port,
+ _ehci1_pipe_xfer,
+ _ehci1_open_pipe,
+ _ehci1_close_pipe,
+};
+
+static usb_status_t usb1_host_callback(usb_device_handle handle, usb_host_configuration_handle config_handle, rt_uint32_t event_code)
+{
+ usb_status_t status = kStatus_USB_Success;
+
+ switch (event_code)
+ {
+ case kUSB_HostEventAttach:
+ if (!imxrt_usb_host_obj[USBH1_INDEX].connect_status)
+ {
+ imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_TRUE;
+ imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
+ rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT, RT_TRUE);
+ }
+ break;
+
+ case kUSB_HostEventNotSupported:
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
+ break;
+
+ case kUSB_HostEventEnumerationDone:
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
+ break;
+
+ case kUSB_HostEventDetach:
+ if (imxrt_usb_host_obj[USBH1_INDEX].connect_status)
+ {
+ imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_FALSE;
+ imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
+ RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
+ rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT);
+ (void)USB_HostCloseDeviceInterface(handle, NULL);
+ }
+ break;
+
+ default:
+ break;
+ }
+ return status;
+}
+
+rt_thread_t usbh1_thread;
+
+static void _ehci1_usbh_thread(void* param)
+{
+ while (1)
+ {
+ USB_HostEhciTaskFunction(imxrt_usb_host_obj[USBH1_INDEX].host_handle);
+ }
+}
+
+static rt_err_t _ehci1_usbh_init(rt_device_t device)
+{
+ USB_HostClockInit(kUSB_ControllerEhci1);
+
+ if (kStatus_USB_Success == USB_HostInit(kUSB_ControllerEhci1, &imxrt_usb_host_obj[USBH1_INDEX].host_handle, usb1_host_callback))
+ {
+ usbh1_thread = rt_thread_create("ehci1", _ehci1_usbh_thread, RT_NULL, 500, 4, 9999999);
+ rt_thread_startup(usbh1_thread);
+ USB_HostIsrEnable(kUSB_ControllerEhci1);
+ }
+ else
+ {
+ rt_kprintf("USB_HostInit ehci1 error\r\n");
+ return -RT_ERROR;
+ }
+ return RT_EOK;
+}
+#endif
+
+int imxrt_usbh_register(void)
+{
+ rt_err_t res = -RT_ERROR;
+ struct imxrt_usb_host *usb_host_obj;
+
+#ifdef BSP_USB0_HOST
+ usb_host_obj = &(imxrt_usb_host_obj[USBH0_INDEX]);
+ rt_memset((void *)(&(usb_host_obj->uhcd)), 0, sizeof(struct uhcd));
+ usb_host_obj->uhcd.parent.type = RT_Device_Class_USBHost;
+ usb_host_obj->uhcd.parent.init = _ehci0_usbh_init;
+ usb_host_obj->uhcd.parent.user_data = usb_host_obj;
+ usb_host_obj->uhcd.ops = &_ehci0_uhcd_ops;
+ usb_host_obj->uhcd.num_ports = OTG_PORT;
+ res = rt_device_register(&(usb_host_obj->uhcd.parent), usb_host_obj->name, RT_DEVICE_FLAG_DEACTIVATE);
+ if (res != RT_EOK)
+ {
+ rt_kprintf("register usb0 host failed res = %d\r\n", res);
+ return -RT_ERROR;
+ }
+
+ rt_usb_host_init(usb_host_obj->name);
+#endif
+#ifdef BSP_USB1_HOST
+ usb_host_obj = &(imxrt_usb_host_obj[USBH1_INDEX]);
+ rt_memset((void *)(&(usb_host_obj->uhcd)), 0, sizeof(struct uhcd));
+ usb_host_obj->uhcd.parent.type = RT_Device_Class_USBHost;
+ usb_host_obj->uhcd.parent.init = _ehci1_usbh_init;
+ usb_host_obj->uhcd.parent.user_data = usb_host_obj;
+ usb_host_obj->uhcd.ops = &_ehci1_uhcd_ops;
+ usb_host_obj->uhcd.num_ports = OTG_PORT;
+ res = rt_device_register(&(usb_host_obj->uhcd.parent), usb_host_obj->name, RT_DEVICE_FLAG_DEACTIVATE);
+ if (res != RT_EOK)
+ {
+ rt_kprintf("register usb0 host failed res = %d\r\n", res);
+ return -RT_ERROR;
+ }
+
+ rt_usb_host_init(usb_host_obj->name);
+#endif
+ return RT_EOK;
+}
+INIT_DEVICE_EXPORT(imxrt_usbh_register);
+
+#endif \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/drv_usbh.h b/bsp/imxrt/libraries/drivers/drv_usbh.h
new file mode 100644
index 0000000000..db1f2074f8
--- /dev/null
+++ b/bsp/imxrt/libraries/drivers/drv_usbh.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-12-12 ZYH the first version
+ * 2019-12-19 tyustli port to stm32 series
+ * 2021-01-19 Leslie Lee port to imxrt series
+ */
+#ifndef __DRV_USBH_H__
+#define __DRV_USBH_H__
+#include <rtthread.h>
+
+#define OTG_PORT 1
+
+int imxrt_usbh_register(void);
+
+#endif
+
+/************* end of file ************/ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host.h
index 53be402cd3..6d338bb64b 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host.h
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host.h
@@ -1,31 +1,9 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016 - 2019 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_H_
@@ -68,6 +46,16 @@ typedef enum _usb_host_event
kUSB_HostEventDetach, /*!< Device is detached */
kUSB_HostEventEnumerationDone, /*!< Device's enumeration is done and the device is supported */
kUSB_HostEventNotSupported, /*!< Device's enumeration is done and the device is not supported */
+ /*! Device's enumeration failed due to errors
+ * fail reason is put in the high 2 bytes of callback event code.
+ * kStatus_USB_TransferFailed - the transfer failed.
+ * kStatus_USB_TransferCancel - transfer is canceled by application.
+ * kStatus_USB_Error - parsing descriptor failed, the power cannot satisfy device's requirement,
+ * device addresss allocation failed, transfer is not enough
+ * or the transfer API failed.
+ * kStatus_USB_AllocFail - malloc failed.
+ */
+ kUSB_HostEventEnumerationFail,
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
kUSB_HostEventNotSuspended, /*!< Suspend failed */
kUSB_HostEventSuspended, /*!< Suspend successful */
@@ -103,7 +91,60 @@ typedef enum _usb_host_dev_info
kUSB_HostGetConfigurationDes, /*!< Device's configuration descriptor pointer */
kUSB_HostGetConfigurationLength, /*!< Device's configuration descriptor pointer */
} usb_host_dev_info_t;
+/*! @brief Request type */
+typedef enum _usb_host_request_type
+{
+ kRequestDevice = 1U, /*!< Control request object is device */
+ kRequestInterface, /*!< Control request object is interface */
+ kRequestEndpoint, /*!< Control request object is endpoint */
+} usb_host_request_type_t;
+/*! @brief For USB_REQUEST_STANDARD_GET_DESCRIPTOR and USB_REQUEST_STANDARD_SET_DESCRIPTOR */
+typedef struct _usb_host_process_descriptor_param
+{
+ uint8_t descriptorType; /*!< See the usb_spec.h, such as the USB_DESCRIPTOR_TYPE_DEVICE */
+ uint8_t descriptorIndex; /*!< The descriptor index is used to select a specific descriptor (only for configuration
+ and string descriptors) when several descriptors of the same type are implemented in a
+ device */
+ uint8_t languageId; /*!< It specifies the language ID for string descriptors or is reset to zero for other
+ descriptors */
+ uint8_t *descriptorBuffer; /*!< Buffer pointer */
+ uint16_t descriptorLength; /*!< Buffer data length */
+} usb_host_process_descriptor_param_t;
+/*! @brief For USB_REQUEST_STANDARD_CLEAR_FEATURE and USB_REQUEST_STANDARD_SET_FEATURE */
+typedef struct _usb_host_process_feature_param
+{
+ uint8_t requestType; /*!< See the #usb_host_request_type_t */
+ uint8_t featureSelector; /*!< Set/cleared feature */
+ uint8_t interfaceOrEndpoint; /*!< Interface or end pointer */
+} usb_host_process_feature_param_t;
+/*! @brief For USB_REQUEST_STANDARD_GET_INTERFACE */
+typedef struct _usb_host_get_interface_param
+{
+ uint8_t interface; /*!< Interface number */
+ uint8_t *alternateInterfaceBuffer; /*!< Save the transfer result */
+} usb_host_get_interface_param_t;
+
+/*! @brief For USB_REQUEST_STANDARD_GET_STATUS */
+typedef struct _usb_host_get_status_param
+{
+ uint16_t statusSelector; /*!< Interface number, the end pointer number or OTG status selector */
+ uint8_t requestType; /*!< See the #usb_host_request_type_t */
+ uint8_t *statusBuffer; /*!< Save the transfer result */
+} usb_host_get_status_param_t;
+/*! @brief For USB_REQUEST_STANDARD_SET_INTERFACE */
+typedef struct _usb_host_set_interface_param
+{
+ uint8_t alternateSetting; /*!< Alternate setting value */
+ uint8_t interface; /*!< Interface number */
+} usb_host_set_interface_param_t;
+
+/*! @brief For USB_REQUEST_STANDARD_SYNCH_FRAME */
+typedef struct _usb_host_synch_frame_param
+{
+ uint8_t endpoint; /*!< Endpoint number */
+ uint8_t *frameNumberBuffer; /*!< Frame number data buffer */
+} usb_host_synch_frame_param_t;
/*!
* @brief Host callback function typedef.
*
@@ -243,8 +284,8 @@ typedef struct _usb_host_pipe_init
/*! @brief Cancel transfer parameter structure */
typedef struct _usb_host_cancel_param
{
- usb_host_pipe_handle pipeHandle; /*!< Cancelling pipe handle*/
- usb_host_transfer_t *transfer; /*!< Cancelling transfer*/
+ usb_host_pipe_handle pipeHandle; /*!< Canceling pipe handle*/
+ usb_host_transfer_t *transfer; /*!< Canceling transfer*/
} usb_host_cancel_param_t;
/*******************************************************************************
@@ -342,7 +383,7 @@ extern usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handl
* @retval kStatus_USB_InvalidParameter The deviceHandle instance don't belong to hostHandle instance.
*/
extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);
-
+#if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
/*!
* @brief KHCI task function.
*
@@ -353,7 +394,8 @@ extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_
* @param[in] hostHandle The host handle.
*/
extern void USB_HostKhciTaskFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
/*!
* @brief EHCI task function.
*
@@ -364,7 +406,8 @@ extern void USB_HostKhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostEhciTaskFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
/*!
* @brief OHCI task function.
*
@@ -375,7 +418,8 @@ extern void USB_HostEhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostOhciTaskFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
/*!
* @brief IP3516HS task function.
*
@@ -386,7 +430,8 @@ extern void USB_HostOhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostIp3516HsTaskFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
/*!
* @brief Device KHCI ISR function.
*
@@ -395,7 +440,8 @@ extern void USB_HostIp3516HsTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostKhciIsrFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
/*!
* @brief Device EHCI ISR function.
*
@@ -404,7 +450,8 @@ extern void USB_HostKhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostEhciIsrFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
/*!
* @brief Device OHCI ISR function.
*
@@ -413,7 +460,8 @@ extern void USB_HostEhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostOhciIsrFunction(void *hostHandle);
-
+#endif
+#if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
/*!
* @brief Device IP3516HS ISR function.
*
@@ -422,7 +470,7 @@ extern void USB_HostOhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostIp3516HsIsrFunction(void *hostHandle);
-
+#endif
/*! @}*/
/*!
@@ -566,7 +614,7 @@ extern usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_tr
* This function sends the USB standard request packet.
*
* @param[in] deviceHandle The device handle for control transfer.
- * @param[in] usbRequest A USB standard request code. Se the usb_spec.h.
+ * @param[in] usbRequest A USB standard request code. See the usb_spec.h.
* @param[in] transfer The used transfer.
* @param[in] param The parameter structure is different for different request, see
* usb_host_framework.h.
@@ -694,10 +742,10 @@ extern usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
/*!
* @brief Update the lpm param.
*
- * The function is used to configuure the lpm token.
+ * The function is used to configure the lpm token.
*
* @param[in] hostHandle The host handle.
- * @param[in] lpmParam HIRD vaule and whether enable remotewakeup.
+ * @param[in] lpmParam HIRD value and whether enable remotewakeup.
*
*/
extern usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam);
@@ -715,6 +763,19 @@ extern usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t ti
#endif
+#if ((defined(USB_HOST_CONFIG_BATTERY_CHARGER)) && (USB_HOST_CONFIG_BATTERY_CHARGER > 0U))
+/*!
+ * @brief Set the charger type. It is only supported on RT600 currently.
+ *
+ * The set charger type becomes valid in next attach.
+ *
+ * @param[in] hostHandle The host handle.
+ * @param[in] type.
+ *
+ */
+extern usb_status_t USB_HostSetChargerType(usb_host_handle hostHandle, uint8_t type);
+#endif
+
/*! @}*/
#ifdef __cplusplus
@@ -723,4 +784,4 @@ extern usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t ti
/*! @}*/
-#endif /* _USB_HOST_H_ */
+#endif /* _USB_HOST_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c
index 42b16e071e..1989d6ec76 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c
@@ -1,46 +1,28 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016,2019 NXP
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
-#include <usb/include/usb_device_config.h>
+#include <usb/include/usb_host_config.h>
#include "usb_host.h"
#include "usb_host_hci.h"
#include "usb_host_devices.h"
-
+#include "usb_host_framework.h"
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
#include "usb_host_hub.h"
+#include "usb_host_hub_app.h"
#endif /* USB_HOST_CONFIG_HUB */
/*******************************************************************************
* Definitions
******************************************************************************/
+#ifndef USB_HOST_CONFIG_MAX_CONFIGURATION_DESCRIPTOR_LENGTH
+#define USB_HOST_CONFIG_MAX_CONFIGURATION_DESCRIPTOR_LENGTH (5000U)
+#endif
+
/*******************************************************************************
* Prototypes
******************************************************************************/
@@ -70,7 +52,7 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
*
* @return kStatus_USB_Success or error codes
*/
-static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance);
+static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance, uint32_t dataLength);
/*!
* @brief notify the application event, the callback is registered when initializing host.
@@ -80,7 +62,10 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
*
* @return kStatus_USB_Success or error codes
*/
-static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInstance, uint32_t eventCode);
+static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle,
+ usb_host_device_instance_t *deviceInstance,
+ uint32_t eventCode,
+ uint32_t eventParameter);
/*!
* @brief allocate one address.
@@ -140,68 +125,57 @@ static usb_status_t USB_HostRemoveDeviceInstance(usb_host_handle hostHandle, usb
*/
static usb_status_t USB_HostControlBus(usb_host_handle hostHandle, uint8_t controlType);
-extern usb_status_t USB_HostStandardSetGetDescriptor(usb_host_device_instance_t *deviceInstance,
- usb_host_transfer_t *transfer,
- void *param);
-extern usb_status_t USB_HostStandardSetAddress(usb_host_device_instance_t *deviceInstance,
- usb_host_transfer_t *transfer,
- void *param);
-extern usb_status_t USB_HostCh9RequestCommon(usb_host_device_instance_t *deviceInstance,
- usb_host_transfer_t *transfer,
- uint8_t *buffer,
- uint32_t bufferLen);
-
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
-extern usb_status_t USB_HostHubDeviceEvent(usb_host_handle hostHandle,
- usb_device_handle deviceHandle,
- usb_host_configuration_handle configurationHandle,
- uint32_t eventCode);
-
-extern uint32_t USB_HostHubGetHsHubNumber(usb_host_handle hostHandle, uint8_t parentHubNo);
-
-extern uint32_t USB_HostHubGetHsHubPort(usb_host_handle hostHandle, uint8_t parentHubNo, uint8_t parentPortNo);
-
-extern usb_status_t USB_HostHubRemovePort(usb_host_handle hostHandle, uint8_t hubNumber, uint8_t portNumber);
-
#endif
/*******************************************************************************
* Variables
******************************************************************************/
-extern usb_host_instance_t g_UsbHostInstance[USB_HOST_CONFIG_MAX_HOST];
-
/*! @brief enumeration step process array */
-static const usb_host_enum_process_entry_t s_EnumEntries[] = \
-{
+static const usb_host_enum_process_entry_t s_EnumEntries[] = {
/* kStatus_dev_initial */
{
- 0, 0, NULL,
+ kStatus_DEV_Notinit,
+ kStatus_DEV_Notinit,
+ NULL,
},
/* kStatus_DEV_GetDes8 */
{
- kStatus_DEV_SetAddress, kStatus_DEV_GetDes8, USB_HostProcessCallback,
+ kStatus_DEV_SetAddress,
+ kStatus_DEV_GetDes8,
+ USB_HostProcessCallback,
},
/* kStatus_DEV_SetAddress */
{
- kStatus_DEV_GetDes, kStatus_DEV_SetAddress, USB_HostProcessCallback,
+ kStatus_DEV_GetDes,
+ kStatus_DEV_SetAddress,
+ USB_HostProcessCallback,
},
/* kStatus_DEV_GetDes */
{
- kStatus_DEV_GetCfg9, kStatus_DEV_GetDes, NULL,
+ kStatus_DEV_GetCfg9,
+ kStatus_DEV_GetDes,
+ NULL,
},
/* kStatus_DEV_GetCfg9 */
{
- kStatus_DEV_GetCfg, kStatus_DEV_GetCfg9, USB_HostProcessCallback,
+ kStatus_DEV_GetCfg,
+ kStatus_DEV_GetCfg9,
+ USB_HostProcessCallback,
},
/* kStatus_DEV_GetCfg */
{
- kStatus_DEV_SetCfg, kStatus_DEV_GetCfg9, USB_HostProcessCallback,
+ kStatus_DEV_SetCfg,
+ kStatus_DEV_GetCfg9,
+ USB_HostProcessCallback,
},
/* kStatus_DEV_SetCfg */
{
- kStatus_DEV_EnumDone, kStatus_DEV_SetCfg, NULL,
+ kStatus_DEV_EnumDone,
+ kStatus_DEV_SetCfg,
+ NULL,
},
};
@@ -211,69 +185,66 @@ static const usb_host_enum_process_entry_t s_EnumEntries[] = \
static void USB_HostEnumerationTransferCallback(void *param, usb_host_transfer_t *transfer, usb_status_t status)
{
- uint8_t nextStep = 0;
+ /* 0 - retry current transfer, 1 - transfer success process,
+ * 2 - retry whole process, 3 - fail process
+ */
+ uint8_t nextStep = 0U;
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)param;
+ usb_status_t failReason = kStatus_USB_Success;
+ uint32_t dataLength;
- USB_HostFreeTransfer(deviceInstance->hostHandle, transfer); /* free transfer */
+ dataLength = transfer->transferSofar;
+ (void)USB_HostFreeTransfer(deviceInstance->hostHandle, transfer); /* free transfer */
if (status == kStatus_USB_Success)
{
- nextStep = 1;
+ nextStep = 1U;
}
else if (status == kStatus_USB_TransferStall)
{
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
- usb_echo("no response from device\r\n");
-#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
- if (deviceInstance->stallRetries > 0) /* retry same transfer when stall */
+ (void)usb_echo("no response from device\r\n");
+#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
+ if (deviceInstance->stallRetries > 0U) /* retry same transfer when stall */
{
+ nextStep = 0U;
deviceInstance->stallRetries--;
}
- else /* process next state when all retries stall */
+ else
{
- nextStep = 1;
+ failReason = kStatus_USB_TransferFailed;
+ nextStep = 2U;
}
}
else if (status == kStatus_USB_TransferCancel)
{
- return;
+ failReason = kStatus_USB_TransferCancel;
+ nextStep = 3U;
}
else
{
- if (deviceInstance->enumRetries > 0) /* next whole retry */
- {
- deviceInstance->enumRetries--;
- deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
- deviceInstance->configurationValue = 0;
- deviceInstance->state = kStatus_DEV_GetDes8;
- }
- else
- {
-#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
- usb_echo("Device No Response\r\n");
-#endif
- return;
- }
+ failReason = kStatus_USB_TransferFailed;
+ nextStep = 2U;
}
- if (nextStep == 1)
+ if (nextStep == 1U)
{
deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
- if (s_EnumEntries[deviceInstance->state - 1].process == NULL)
+ if (s_EnumEntries[deviceInstance->state - 1U].process == NULL)
{
- deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].successState; /* next state */
+ deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].successState; /* next state */
}
else
{
- status = s_EnumEntries[deviceInstance->state - 1].process(
- deviceInstance); /* process the previous state result */
+ status = s_EnumEntries[deviceInstance->state - 1U].process(
+ deviceInstance, dataLength); /* process the previous state result */
if (status == kStatus_USB_Success) /* process success */
{
- deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].successState;
+ deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].successState;
}
else if (status == kStatus_USB_Retry) /* need retry */
{
- deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].retryState;
+ deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].retryState;
}
else if (status == kStatus_USB_NotSupported) /* device don't suport by the application */
{
@@ -281,30 +252,48 @@ static void USB_HostEnumerationTransferCallback(void *param, usb_host_transfer_t
}
else /* process error, next retry */
{
- if (deviceInstance->enumRetries > 0) /* next whole retry */
- {
- deviceInstance->enumRetries--;
- deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
- deviceInstance->configurationValue = 0;
- deviceInstance->state = kStatus_DEV_GetDes8;
- }
- else
- {
+ /* kStatus_USB_Error or kStatus_USB_AllocFail */
+ failReason = status;
+ nextStep = 2U;
+ }
+ }
+ }
+
+ if (nextStep == 2U)
+ {
+ if (deviceInstance->enumRetries > 0U) /* next whole retry */
+ {
+ deviceInstance->enumRetries--;
+ deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
+ deviceInstance->configurationValue = 0U;
+ deviceInstance->state = (uint8_t)kStatus_DEV_GetDes8;
+ }
+ else
+ {
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
- usb_echo("Device No Response\r\n");
+ usb_echo("Device No Response\r\n");
#endif
- return; /* unrecoverable fail */
- }
- }
+ nextStep = 3U;
}
}
- if (USB_HostProcessState(deviceInstance) != kStatus_USB_Success) /* process the new state */
+ /* process the state */
+ if (nextStep != 3U)
{
+ if (USB_HostProcessState(deviceInstance) != kStatus_USB_Success)
+ {
#ifdef HOST_ECHO
- usb_echo("enumation setup error\r\n");
+ usb_echo("enumation setup error\r\n");
#endif
- return;
+ failReason = kStatus_USB_Error;
+ nextStep = 3U;
+ }
+ }
+
+ if (nextStep == 3U)
+ {
+ (void)USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)failReason);
}
}
@@ -313,9 +302,11 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
usb_status_t status = kStatus_USB_Success;
usb_host_process_descriptor_param_t getDescriptorParam;
usb_host_transfer_t *transfer;
+ usb_host_device_enumeration_status_t state;
/* malloc transfer */
- if (deviceInstance->state != kStatus_DEV_EnumDone)
+ state = (usb_host_device_enumeration_status_t)deviceInstance->state;
+ if (state != kStatus_DEV_EnumDone)
{
if (USB_HostMallocTransfer(deviceInstance->hostHandle, &transfer) != kStatus_USB_Success)
{
@@ -324,29 +315,29 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
#endif
return kStatus_USB_Error;
}
- transfer->callbackFn = USB_HostEnumerationTransferCallback;
+ transfer->callbackFn = USB_HostEnumerationTransferCallback;
transfer->callbackParam = deviceInstance;
/* reset transfer fields */
- transfer->setupPacket->bmRequestType = 0x00;
- transfer->setupPacket->wIndex = 0;
- transfer->setupPacket->wLength = 0;
- transfer->setupPacket->wValue = 0;
+ transfer->setupPacket->bmRequestType = 0x00U;
+ transfer->setupPacket->wIndex = 0U;
+ transfer->setupPacket->wLength = 0U;
+ transfer->setupPacket->wValue = 0U;
}
- switch (deviceInstance->state)
+ switch (state)
{
case kStatus_DEV_GetDes8:
case kStatus_DEV_GetDes: /* get descriptor state */
getDescriptorParam.descriptorLength = sizeof(usb_descriptor_device_t);
- if (deviceInstance->state == kStatus_DEV_GetDes8)
+ if (deviceInstance->state == (uint8_t)kStatus_DEV_GetDes8)
{
- getDescriptorParam.descriptorLength = 8;
+ getDescriptorParam.descriptorLength = 8U;
}
getDescriptorParam.descriptorBuffer = (uint8_t *)deviceInstance->deviceDescriptor;
- getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE;
- getDescriptorParam.descriptorIndex = 0;
- getDescriptorParam.languageId = 0;
+ getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE;
+ getDescriptorParam.descriptorIndex = 0U;
+ getDescriptorParam.languageId = 0U;
transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
@@ -359,10 +350,10 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
case kStatus_DEV_GetCfg9: /* get 9 bytes configuration state */
getDescriptorParam.descriptorBuffer = deviceInstance->enumBuffer;
- getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_CONFIGURE;
- getDescriptorParam.descriptorIndex = deviceInstance->configurationValue;
+ getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_CONFIGURE;
+ getDescriptorParam.descriptorIndex = deviceInstance->configurationValue;
getDescriptorParam.descriptorLength = 9;
- getDescriptorParam.languageId = 0;
+ getDescriptorParam.languageId = 0;
transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
@@ -371,10 +362,10 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
case kStatus_DEV_GetCfg: /* get configuration state */
getDescriptorParam.descriptorBuffer = deviceInstance->configurationDesc;
- getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_CONFIGURE;
- getDescriptorParam.descriptorIndex = deviceInstance->configurationValue;
+ getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_CONFIGURE;
+ getDescriptorParam.descriptorIndex = deviceInstance->configurationValue;
getDescriptorParam.descriptorLength = deviceInstance->configurationLen;
- getDescriptorParam.languageId = 0;
+ getDescriptorParam.languageId = 0;
transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
@@ -385,52 +376,71 @@ static usb_status_t USB_HostProcessState(usb_host_device_instance_t *deviceInsta
transfer->setupPacket->wValue =
USB_SHORT_TO_LITTLE_ENDIAN(deviceInstance->configuration.configurationDesc->bConfigurationValue);
transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_SET_CONFIGURATION;
- status = USB_HostCh9RequestCommon(deviceInstance, transfer, NULL, 0);
+ status = USB_HostCh9RequestCommon(deviceInstance, transfer, NULL, 0);
break;
case kStatus_DEV_EnumDone: /* enumeration done state */
- status = USB_HostNotifyDevice(deviceInstance,
- kUSB_HostEventEnumerationDone); /* notify device enumeration done */
+ /* notify device enumeration done */
+ status = USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance,
+ (uint32_t)kUSB_HostEventEnumerationDone, (uint32_t)kStatus_USB_Success);
if (status == kStatus_USB_Success)
{
- deviceInstance->state = kStatus_DEV_AppUsed;
+ deviceInstance->state = (uint8_t)kStatus_DEV_AppUsed;
}
break;
default:
+ /*no action*/
break;
}
return status;
}
-static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance)
+static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance, uint32_t dataLength)
{
usb_host_pipe_t *pipe = (usb_host_pipe_t *)deviceInstance->controlPipe;
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_descriptor_configuration_t *configureDesc;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
+ void *temp;
+ usb_host_device_enumeration_status_t state;
- switch (deviceInstance->state)
+ state = (usb_host_device_enumeration_status_t)deviceInstance->state;
+ switch (state)
{
case kStatus_DEV_GetDes8: /* process get 8 bytes descriptor result */
+ if (dataLength != 8u)
+ {
+ return kStatus_USB_Error;
+ }
pipe->maxPacketSize = deviceInstance->deviceDescriptor->bMaxPacketSize0;
- hostInstance->controllerTable->controllerIoctl(
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
+ (void)hostInstance->controllerTable->controllerIoctl(
hostInstance->controllerHandle, kUSB_HostUpdateControlPacketSize, deviceInstance->controlPipe);
break;
case kStatus_DEV_SetAddress: /* process set address result */
deviceInstance->setAddress = deviceInstance->allocatedAddress;
- hostInstance->controllerTable->controllerIoctl(
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
+ (void)hostInstance->controllerTable->controllerIoctl(
hostInstance->controllerHandle, kUSB_HostUpdateControlEndpointAddress, deviceInstance->controlPipe);
break;
- case kStatus_DEV_GetDes: /* process set address result */
- /* NULL */
+ case kStatus_DEV_GetDes: /* process get full device descriptor result */
+ if (dataLength != sizeof(usb_descriptor_device_t))
+ {
+ return kStatus_USB_Error;
+ }
break;
case kStatus_DEV_GetCfg9: /* process get 9 bytes configuration result */
- configureDesc = (usb_descriptor_configuration_t *)&deviceInstance->enumBuffer[0];
+ if (dataLength != 9u)
+ {
+ return kStatus_USB_Error;
+ }
+ temp = (void *)&deviceInstance->enumBuffer[0];
+ configureDesc = (usb_descriptor_configuration_t *)temp;
deviceInstance->configurationLen = USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(configureDesc->wTotalLength);
if (deviceInstance->configurationDesc != NULL)
@@ -438,19 +448,25 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(deviceInstance->configurationDesc);
#else
- USB_OsaMemoryFree(deviceInstance->configurationDesc);
+ OSA_MemoryFree(deviceInstance->configurationDesc);
#endif
deviceInstance->configurationDesc = NULL;
}
+
+ /* fix misra 4.14 */
+ if (deviceInstance->configurationLen > USB_HOST_CONFIG_MAX_CONFIGURATION_DESCRIPTOR_LENGTH)
+ {
+ return kStatus_USB_Error;
+ }
/* for KHCI, the start address and the length should be 4 byte align */
- if ((deviceInstance->configurationLen & 0x03) != 0)
+ if ((deviceInstance->configurationLen & 0x03U) != 0U)
{
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
deviceInstance->configurationDesc =
- (uint8_t *)SDK_Malloc((deviceInstance->configurationLen & 0xFFFFFFFCu) + 4, USB_CACHE_LINESIZE);
+ (uint8_t *)SDK_Malloc((deviceInstance->configurationLen & 0xFFFCu) + 4, USB_CACHE_LINESIZE);
#else
deviceInstance->configurationDesc =
- (uint8_t *)USB_OsaMemoryAllocate((deviceInstance->configurationLen & 0xFFFFFFFCu) + 4);
+ (uint8_t *)OSA_MemoryAllocate((((uint32_t)deviceInstance->configurationLen) & 0xFFFCU) + 4UL);
#endif
}
else
@@ -459,18 +475,22 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
deviceInstance->configurationDesc =
(uint8_t *)SDK_Malloc(deviceInstance->configurationLen, USB_CACHE_LINESIZE);
#else
- deviceInstance->configurationDesc = (uint8_t *)USB_OsaMemoryAllocate(deviceInstance->configurationLen);
+ deviceInstance->configurationDesc = (uint8_t *)OSA_MemoryAllocate(deviceInstance->configurationLen);
#endif
}
if (deviceInstance->configurationDesc == NULL)
{
- return kStatus_USB_Error;
+ return kStatus_USB_AllocFail;
}
break;
- case kStatus_DEV_GetCfg: /* process get cofiguration result */
- if (((usb_descriptor_configuration_t *)deviceInstance->configurationDesc)->bMaxPower >
- USB_HOST_CONFIG_MAX_POWER)
+ case kStatus_DEV_GetCfg: /* process get configuration result */
+ if (dataLength != deviceInstance->configurationLen)
+ {
+ return kStatus_USB_Error;
+ }
+ temp = (void *)deviceInstance->configurationDesc;
+ if (((usb_descriptor_configuration_t *)temp)->bMaxPower > USB_HOST_CONFIG_MAX_POWER)
{
return kStatus_USB_Error;
}
@@ -481,7 +501,8 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
return kStatus_USB_Error;
}
- status = USB_HostNotifyDevice(deviceInstance, kUSB_HostEventAttach);
+ status = USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, (uint32_t)kUSB_HostEventAttach,
+ (uint32_t)kStatus_USB_Success);
if (status != kStatus_USB_Success)
{
@@ -492,8 +513,9 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
}
else
{
- USB_HostNotifyDevice(deviceInstance,
- kUSB_HostEventNotSupported); /* notify application device is not supported */
+ /* notify application device is not supported */
+ (void)USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance,
+ (uint32_t)kUSB_HostEventNotSupported, (uint32_t)kStatus_USB_Success);
return kStatus_USB_NotSupported;
}
}
@@ -504,13 +526,17 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn
break;
default:
+ /*no action*/
break;
}
return status;
}
-static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInstance, uint32_t eventCode)
+static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle,
+ usb_host_device_instance_t *deviceInstance,
+ uint32_t eventCode,
+ uint32_t eventParameter)
{
usb_host_instance_t *hostInstance;
usb_status_t status1 = kStatus_USB_Error;
@@ -521,34 +547,37 @@ static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInsta
uint8_t interfaceIndex;
#endif /* USB_HOST_CONFIG_HUB */
+ eventCode = (((uint32_t)eventParameter << 16U) | (uint32_t)eventCode);
+ hostInstance = (usb_host_instance_t *)hostHandle;
if (deviceInstance == NULL)
{
+ (void)hostInstance->deviceCallback(NULL, NULL, eventCode);
return kStatus_USB_InvalidHandle;
}
- hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
- haveHub = 0;
- haveNoHub = 0;
- for (interfaceIndex = 0; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex)
+ haveHub = 0U;
+ haveNoHub = 0U;
+ for (interfaceIndex = 0U; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex)
{
if (((usb_descriptor_interface_t *)deviceInstance->configuration.interfaceList[interfaceIndex].interfaceDesc)
->bInterfaceClass == USB_HOST_HUB_CLASS_CODE)
{
- haveHub = 1;
+ haveHub = 1U;
}
else
{
- haveNoHub = 1;
+ haveNoHub = 1U;
}
}
- if ((haveNoHub == 1) && (hostInstance->deviceCallback != NULL))
+ if ((hostInstance->deviceCallback != NULL) &&
+ ((haveNoHub == 1U) || (deviceInstance->configuration.interfaceCount == 0U)))
{
- status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration,
- eventCode); /* notify application event */
+ /* call host callback function, function is initialized in USB_HostInit */
+ status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, eventCode);
}
- if (haveHub)
+ if (0U != haveHub)
{
status2 = USB_HostHubDeviceEvent(hostInstance, deviceInstance, &deviceInstance->configuration,
eventCode); /* notify hub event */
@@ -558,7 +587,7 @@ static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInsta
{
return kStatus_USB_Success;
}
- else if (eventCode == kUSB_HostEventAttach) /* attach event */
+ else if (eventCode == (uint32_t)kUSB_HostEventAttach) /* attach event */
{
status1 = kStatus_USB_NotSupported;
}
@@ -569,8 +598,8 @@ static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInsta
#else
if (hostInstance->deviceCallback != NULL)
{
- status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration,
- eventCode); /* call host callback function */
+ /* call host callback function, function is initialized in USB_HostInit */
+ status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, eventCode);
}
#endif
return status1;
@@ -578,24 +607,24 @@ static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInsta
static uint8_t USB_HostAllocateDeviceAddress(usb_host_instance_t *hostInstance)
{
- uint8_t address = 0;
+ uint8_t address = 0U;
uint8_t addressIndex;
uint8_t addressBitIndex;
- for (addressIndex = 0; addressIndex < 8; ++addressIndex) /* find the idle address postion byte */
+ for (addressIndex = 0U; addressIndex < 8U; ++addressIndex) /* find the idle address position byte */
{
- if (hostInstance->addressBitMap[addressIndex] != 0xFF)
+ if (hostInstance->addressBitMap[addressIndex] != 0xFFU)
{
break;
}
}
- if (addressIndex < 8)
+ if (addressIndex < 8U)
{
- for (addressBitIndex = 0; addressBitIndex < 8; ++addressBitIndex) /* find the idle address position bit */
+ for (addressBitIndex = 0U; addressBitIndex < 8U; ++addressBitIndex) /* find the idle address position bit */
{
- if (!(hostInstance->addressBitMap[addressIndex] & (0x01u << addressBitIndex)))
+ if (0U == (hostInstance->addressBitMap[addressIndex] & (0x01U << addressBitIndex)))
{
- hostInstance->addressBitMap[addressIndex] |= (0x01u << addressBitIndex); /* set the allocated bit */
- address = addressIndex * 8 + addressBitIndex + 1; /* the address minimum is 1 */
+ hostInstance->addressBitMap[addressIndex] |= (0x01U << addressBitIndex); /* set the allocated bit */
+ address = addressIndex * 8U + addressBitIndex + 1U; /* the address minimum is 1 */
break;
}
}
@@ -605,10 +634,10 @@ static uint8_t USB_HostAllocateDeviceAddress(usb_host_instance_t *hostInstance)
static void USB_HostReleaseDeviceAddress(usb_host_instance_t *hostInstance, uint8_t address)
{
- USB_HostLock();
- hostInstance->addressBitMap[(uint32_t)(address - 1) >> 3] &=
- (~(0x01u << (((uint32_t)address - 1) & 0x07U))); /* reset the allocated bit */
- USB_HostUnlock();
+ (void)USB_HostLock();
+ hostInstance->addressBitMap[((uint32_t)address - 1U) >> 3U] &=
+ (~(0x01U << (((uint32_t)address - 1U) & 0x07U))); /* reset the allocated bit */
+ (void)USB_HostUnlock();
}
static usb_status_t USB_HostRemoveDeviceInstance(usb_host_handle hostHandle, usb_device_handle deviceHandle)
@@ -640,7 +669,7 @@ static usb_status_t USB_HostRemoveDeviceInstance(usb_host_handle hostHandle, usb
prevInstance->next = currentInstance->next;
return kStatus_USB_Success;
}
- prevInstance = currentInstance;
+ prevInstance = currentInstance;
currentInstance = currentInstance->next;
}
@@ -660,13 +689,13 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb
}
#endif
/* release device's address */
- if (deviceInstance->setAddress != 0)
+ if (deviceInstance->setAddress != 0U)
{
USB_HostReleaseDeviceAddress(hostInstance, deviceInstance->setAddress);
}
else
{
- if (deviceInstance->allocatedAddress != 0)
+ if (deviceInstance->allocatedAddress != 0U)
{
USB_HostReleaseDeviceAddress(hostInstance, deviceInstance->allocatedAddress);
}
@@ -675,7 +704,7 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb
/* close control pipe */
if (deviceInstance->controlPipe != NULL)
{
- USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL);
+ (void)USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL);
if (USB_HostClosePipe(hostInstance, deviceInstance->controlPipe) != kStatus_USB_Success)
{
#ifdef HOST_ECHO
@@ -691,7 +720,7 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(deviceInstance->configurationDesc);
#else
- USB_OsaMemoryFree(deviceInstance->configurationDesc);
+ OSA_MemoryFree(deviceInstance->configurationDesc);
#endif
}
@@ -701,20 +730,20 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(deviceInstance->deviceDescriptor);
#else
- USB_OsaMemoryFree(deviceInstance->deviceDescriptor);
+ OSA_MemoryFree(deviceInstance->deviceDescriptor);
#endif
/* free device instance buffer */
- USB_OsaMemoryFree(deviceInstance);
+ OSA_MemoryFree(deviceInstance);
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
/* enable controller attach if root hub */
- if (level == 1)
+ if (level == 1U)
{
- USB_HostControlBus(hostInstance, kUSB_HostBusEnableAttach);
+ (void)USB_HostControlBus(hostInstance, (uint8_t)kUSB_HostBusEnableAttach);
}
#else
/* enable controller attach */
- USB_HostControlBus(hostInstance, kUSB_HostBusEnableAttach);
+ USB_HostControlBus(hostInstance, (uint8_t)kUSB_HostBusEnableAttach);
#endif
}
@@ -726,35 +755,39 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
usb_host_interface_t *interfaceParse = NULL;
usb_host_ep_t *epParse;
uint8_t *buffer;
+ void *temp;
if (deviceHandle == NULL)
{
return kStatus_USB_InvalidParameter;
}
- buffer = (uint8_t *)&deviceInstance->configuration;
+ temp = (void *)&deviceInstance->configuration;
+ buffer = (uint8_t *)temp;
/* clear the previous parse result, note: end_pos means buffer index here*/
- for (endPos = 0; endPos < sizeof(usb_host_configuration_t); endPos++)
+ for (endPos = 0U; endPos < sizeof(usb_host_configuration_t); endPos++)
{
- buffer[endPos] = 0;
+ buffer[endPos] = 0U;
}
- for (endPos = 0; endPos < USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE; ++endPos)
+ for (endPos = 0U; endPos < USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE; ++endPos)
{
- deviceInstance->interfaceStatus[endPos] = 0;
+ deviceInstance->interfaceStatus[endPos] = 0U;
}
/* parse configuration descriptor */
- unionDes = (usb_descriptor_union_t *)deviceInstance->configurationDesc;
- endPos = (uint32_t)(deviceInstance->configurationDesc + deviceInstance->configurationLen);
+ temp = (void *)deviceInstance->configurationDesc;
+ unionDes = (usb_descriptor_union_t *)temp;
+ endPos = (uint32_t)(deviceInstance->configurationDesc + deviceInstance->configurationLen);
if ((unionDes->common.bLength == USB_DESCRIPTOR_LENGTH_CONFIGURE) &&
(unionDes->common.bDescriptorType == USB_DESCRIPTOR_TYPE_CONFIGURE))
{
/* configuration descriptor */
- deviceInstance->configuration.configurationDesc = (usb_descriptor_configuration_t *)unionDes;
+ temp = (void *)unionDes;
+ deviceInstance->configuration.configurationDesc = (usb_descriptor_configuration_t *)temp;
deviceInstance->configuration.configurationExtensionLength = 0;
- deviceInstance->configuration.configurationExtension = NULL;
- deviceInstance->configuration.interfaceCount = 0;
+ deviceInstance->configuration.configurationExtension = NULL;
+ deviceInstance->configuration.interfaceCount = 0;
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
while ((uint32_t)unionDes < endPos)
{
@@ -764,8 +797,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
{
deviceInstance->configuration.configurationExtension = (uint8_t *)unionDes;
}
- if ((unionDes->common.bDescriptorType == 0x00) ||
- (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */
+ if ((unionDes->common.bDescriptorType == 0x00U) ||
+ (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -779,17 +812,17 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
}
/* interface descriptor */
- deviceInstance->configuration.interfaceCount = 0;
+ deviceInstance->configuration.interfaceCount = 0U;
while ((uint32_t)unionDes < endPos)
{
if (unionDes->common.bDescriptorType == USB_DESCRIPTOR_TYPE_INTERFACE)
{
- if (unionDes->interface.bAlternateSetting == 0x00)
+ if (unionDes->interface.bAlternateSetting == 0x00U)
{
if (deviceInstance->configuration.interfaceCount >= USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE)
{
-#ifdef HOST_ECHO
- usb_echo(
+#if (((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST)) || defined(HOST_ECHO))
+ (void)usb_echo(
"Unsupported Device attached\r\n too many interfaces in one configuration, please increase "
"the USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE value\n");
#endif
@@ -798,13 +831,13 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
interfaceParse =
&deviceInstance->configuration.interfaceList[deviceInstance->configuration.interfaceCount];
deviceInstance->configuration.interfaceCount++;
- interfaceParse->alternateSettingNumber = 0;
- interfaceParse->epCount = 0;
- interfaceParse->interfaceDesc = &unionDes->interface;
+ interfaceParse->alternateSettingNumber = 0;
+ interfaceParse->epCount = 0;
+ interfaceParse->interfaceDesc = &unionDes->interface;
interfaceParse->interfaceExtensionLength = 0;
- interfaceParse->interfaceExtension = NULL;
- interfaceParse->interfaceIndex = unionDes->interface.bInterfaceNumber;
- if (unionDes->common.bLength == 0x00) /* the descriptor data is wrong */
+ interfaceParse->interfaceExtension = NULL;
+ interfaceParse->interfaceIndex = unionDes->interface.bInterfaceNumber;
+ if (unionDes->common.bLength == 0x00U) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -818,8 +851,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
{
interfaceParse->interfaceExtension = (uint8_t *)unionDes;
}
- if ((unionDes->common.bDescriptorType == 0x00) ||
- (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */
+ if ((unionDes->common.bDescriptorType == 0x00U) ||
+ (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -833,7 +866,7 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
}
/* endpoint descriptor */
- if (interfaceParse->interfaceDesc->bNumEndpoints != 0)
+ if (interfaceParse->interfaceDesc->bNumEndpoints != 0U)
{
if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) ||
(interfaceParse->interfaceDesc->bNumEndpoints > USB_HOST_CONFIG_INTERFACE_MAX_EP))
@@ -854,11 +887,13 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
#endif
return kStatus_USB_Error;
}
- epParse = (usb_host_ep_t *)&interfaceParse->epList[interfaceParse->epCount];
- epParse->epDesc = (usb_descriptor_endpoint_t *)unionDes;
- epParse->epExtensionLength = 0;
- epParse->epExtension = NULL;
- if (unionDes->common.bLength == 0x00) /* the descriptor data is wrong */
+ temp = (void *)&interfaceParse->epList[interfaceParse->epCount];
+ epParse = (usb_host_ep_t *)temp;
+ temp = (void *)unionDes;
+ epParse->epDesc = (usb_descriptor_endpoint_t *)temp;
+ epParse->epExtensionLength = 0U;
+ epParse->epExtension = NULL;
+ if (unionDes->common.bLength == 0x00U) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -872,8 +907,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
{
epParse->epExtension = (uint8_t *)unionDes;
}
- if ((unionDes->common.bDescriptorType == 0x00) ||
- (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */
+ if ((unionDes->common.bDescriptorType == 0x00U) ||
+ (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -900,7 +935,7 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
{
interfaceParse->interfaceExtension = (uint8_t *)unionDes;
}
- if (unionDes->common.bLength == 0x00) /* the descriptor data is wrong */
+ if (unionDes->common.bLength == 0x00U) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -910,8 +945,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
{
if (unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_INTERFACE)
{
- if ((unionDes->common.bDescriptorType == 0x00) ||
- (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */
+ if ((unionDes->common.bDescriptorType == 0x00U) ||
+ (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */
{
return kStatus_USB_Error;
}
@@ -932,9 +967,9 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle
}
}
- for (endPos = 0; endPos < deviceInstance->configuration.interfaceCount; ++endPos)
+ for (endPos = 0U; endPos < deviceInstance->configuration.interfaceCount; ++endPos)
{
- deviceInstance->interfaceStatus[endPos] = kStatus_interface_Attached;
+ deviceInstance->interfaceStatus[endPos] = (uint8_t)kStatus_interface_Attached;
}
return kStatus_USB_Success;
@@ -988,28 +1023,29 @@ usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle,
#endif
/* Allocate new device instance */
- newInstance = (usb_host_device_instance_t *)USB_OsaMemoryAllocate(sizeof(usb_host_device_instance_t));
+ newInstance = (usb_host_device_instance_t *)OSA_MemoryAllocate(sizeof(usb_host_device_instance_t));
if (newInstance == NULL)
{
#ifdef HOST_ECHO
usb_echo("allocate dev instance fail\r\n");
#endif
+ (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)kStatus_USB_AllocFail);
return kStatus_USB_AllocFail;
}
/* new instance fields init */
- newInstance->hostHandle = hostHandle;
- newInstance->speed = speed;
- newInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
- newInstance->enumRetries = USB_HOST_CONFIG_ENUMERATION_MAX_RETRIES;
- newInstance->setAddress = 0;
- newInstance->deviceAttachState = kStatus_device_Attached;
+ newInstance->hostHandle = hostHandle;
+ newInstance->speed = speed;
+ newInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES;
+ newInstance->enumRetries = USB_HOST_CONFIG_ENUMERATION_MAX_RETRIES;
+ newInstance->setAddress = 0;
+ newInstance->deviceAttachState = (uint8_t)kStatus_device_Attached;
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
newInstance->deviceDescriptor =
(usb_descriptor_device_t *)SDK_Malloc(sizeof(usb_descriptor_device_t) + 9, USB_CACHE_LINESIZE);
#else
- newInstance->deviceDescriptor =
- (usb_descriptor_device_t *)USB_OsaMemoryAllocate(sizeof(usb_descriptor_device_t) + 9);
+ newInstance->deviceDescriptor = (usb_descriptor_device_t *)OSA_MemoryAllocate(sizeof(usb_descriptor_device_t) + 9U);
#endif
if (newInstance->deviceDescriptor == NULL)
{
@@ -1019,62 +1055,66 @@ usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle,
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(newInstance->deviceDescriptor);
#else
- USB_OsaMemoryFree(newInstance->deviceDescriptor);
+ OSA_MemoryFree(newInstance->deviceDescriptor);
#endif
- USB_OsaMemoryFree(newInstance);
+ OSA_MemoryFree(newInstance);
+ (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)kStatus_USB_AllocFail);
return kStatus_USB_AllocFail;
}
newInstance->enumBuffer = (uint8_t *)((uint8_t *)newInstance->deviceDescriptor + sizeof(usb_descriptor_device_t));
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
- newInstance->hubNumber = hubNumber;
+ newInstance->hubNumber = hubNumber;
newInstance->portNumber = portNumber;
- newInstance->level = level;
+ newInstance->level = level;
- if ((speed != USB_SPEED_HIGH) && (level > 1))
+ if ((speed != USB_SPEED_HIGH) && (level > 1U))
{
- newInstance->hsHubNumber = USB_HostHubGetHsHubNumber(hostHandle, hubNumber);
- newInstance->hsHubPort = USB_HostHubGetHsHubPort(hostHandle, hubNumber, portNumber);
+ newInstance->hsHubNumber = (uint8_t)USB_HostHubGetHsHubNumber(hostHandle, hubNumber);
+ newInstance->hsHubPort = (uint8_t)USB_HostHubGetHsHubPort(hostHandle, hubNumber, portNumber);
}
else
{
newInstance->hsHubNumber = hubNumber;
- newInstance->hsHubPort = portNumber;
+ newInstance->hsHubPort = portNumber;
}
#endif /* USB_HOST_CONFIG_HUB */
- USB_HostLock();
+ (void)USB_HostLock();
/* allocate address && insert to the dev list */
address = USB_HostAllocateDeviceAddress(hostInstance);
- if (address == 0)
+ if (address == 0U)
{
#ifdef HOST_ECHO
usb_echo("allocate address fail\r\n");
#endif
- USB_HostUnlock();
+ (void)USB_HostUnlock();
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(newInstance->deviceDescriptor);
#else
- USB_OsaMemoryFree(newInstance->deviceDescriptor);
+ OSA_MemoryFree(newInstance->deviceDescriptor);
#endif
- USB_OsaMemoryFree(newInstance);
+ OSA_MemoryFree(newInstance);
+ (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)kStatus_USB_Error);
return kStatus_USB_Error;
}
newInstance->allocatedAddress = address;
- newInstance->next = (usb_host_device_instance_t *)hostInstance->deviceList;
+ newInstance->next = (usb_host_device_instance_t *)hostInstance->deviceList;
hostInstance->deviceList = newInstance;
- newInstance->state = kStatus_DEV_Initial;
- USB_HostUnlock();
+ newInstance->state = (uint8_t)kStatus_DEV_Initial;
+ (void)USB_HostUnlock();
/* open control pipe */
- pipeInit.devInstance = newInstance;
- pipeInit.pipeType = USB_ENDPOINT_CONTROL;
- pipeInit.direction = 0;
+ pipeInit.devInstance = newInstance;
+ pipeInit.pipeType = USB_ENDPOINT_CONTROL;
+ pipeInit.direction = 0;
pipeInit.endpointAddress = 0;
- pipeInit.interval = 0;
- pipeInit.maxPacketSize = 8;
+ pipeInit.interval = 0;
+ pipeInit.maxPacketSize = 8;
pipeInit.numberPerUframe = 0;
- pipeInit.nakCount = USB_HOST_CONFIG_MAX_NAK;
+ pipeInit.nakCount = USB_HOST_CONFIG_MAX_NAK;
if (USB_HostOpenPipe(hostHandle, &newInstance->controlPipe, &pipeInit) != kStatus_USB_Success)
{
/* don't need release resource, resource is released when detach */
@@ -1082,15 +1122,22 @@ usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle,
#if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
SDK_Free(newInstance->deviceDescriptor);
#else
- USB_OsaMemoryFree(newInstance->deviceDescriptor);
+ OSA_MemoryFree(newInstance->deviceDescriptor);
#endif
- USB_OsaMemoryFree(newInstance);
+ OSA_MemoryFree(newInstance);
+ (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)kStatus_USB_Error);
return kStatus_USB_Error;
}
/* start enumeration */
- newInstance->state = kStatus_DEV_GetDes8;
- USB_HostProcessState(newInstance); /* process enumeration state machine */
+ newInstance->state = (uint8_t)kStatus_DEV_GetDes8;
+ /* process enumeration state machine */
+ if (USB_HostProcessState(newInstance) != kStatus_USB_Success)
+ {
+ (void)USB_HostNotifyDevice(hostInstance, newInstance, (uint32_t)kUSB_HostEventEnumerationFail,
+ (uint32_t)kStatus_USB_Error);
+ }
*deviceHandle = newInstance;
return kStatus_USB_Success;
@@ -1106,7 +1153,7 @@ usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber,
return kStatus_USB_InvalidHandle;
}
- USB_HostLock();
+ (void)USB_HostLock();
/* search for device instance handle */
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList;
@@ -1121,7 +1168,7 @@ usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber,
#else
deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList;
#endif
- USB_HostUnlock();
+ (void)USB_HostUnlock();
if (deviceInstance != NULL)
{
return USB_HostDetachDeviceInternal(hostHandle, deviceInstance); /* device instance detach */
@@ -1132,31 +1179,33 @@ usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber,
usb_status_t USB_HostDetachDeviceInternal(usb_host_handle hostHandle, usb_device_handle deviceHandle)
{
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
+ usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (deviceHandle == NULL))
{
return kStatus_USB_InvalidHandle;
}
- deviceInstance->deviceAttachState = kStatus_device_Detached; /* mark the device is detached from host */
+ deviceInstance->deviceAttachState = (uint8_t)kStatus_device_Detached; /* mark the device is detached from host */
- if (deviceInstance->state >= kStatus_DEV_Initial) /* device instance is valid */
+ if (deviceInstance->state >= (uint8_t)kStatus_DEV_Initial) /* device instance is valid */
{
/* detach internally */
- if (deviceInstance->state < kStatus_DEV_AppUsed) /* enumeration is not done */
+ if (deviceInstance->state < (uint8_t)kStatus_DEV_AppUsed) /* enumeration is not done */
{
if (deviceInstance->controlPipe != NULL)
{
- USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL);
+ (void)USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL);
}
/* remove device instance from host */
- USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
+ (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
USB_HostReleaseDeviceResource(hostInstance, deviceInstance);
}
- else /* enumeration has be done and notifed application */
+ else /* enumeration has be done and notified application */
{
- USB_HostNotifyDevice(deviceInstance, kUSB_HostEventDetach); /* notify application device detach */
+ /* notify application device detach */
+ (void)USB_HostNotifyDevice(hostInstance, deviceInstance, (uint32_t)kUSB_HostEventDetach,
+ (uint32_t)kStatus_USB_Success);
}
}
@@ -1165,7 +1214,7 @@ usb_status_t USB_HostDetachDeviceInternal(usb_host_handle hostHandle, usb_device
uint8_t USB_HostGetDeviceAttachState(usb_device_handle deviceHandle)
{
- return deviceHandle ? ((usb_host_device_instance_t *)deviceHandle)->deviceAttachState : 0x0;
+ return (NULL != deviceHandle) ? ((usb_host_device_instance_t *)deviceHandle)->deviceAttachState : 0x0U;
}
usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle)
@@ -1183,7 +1232,7 @@ usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handl
searchDev = searchDev->next;
}
- if (searchDev)
+ if (NULL != searchDev)
{
return kStatus_USB_Success;
}
@@ -1192,14 +1241,14 @@ usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handl
static usb_status_t USB_HostControlBus(usb_host_handle hostHandle, uint8_t controlType)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if (hostHandle == NULL)
{
return kStatus_USB_InvalidHandle;
}
-
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl,
&controlType);
@@ -1209,7 +1258,7 @@ static usb_status_t USB_HostControlBus(usb_host_handle hostHandle, uint8_t contr
usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_host_interface_handle interfaceHandle)
{
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- usb_host_instance_t *hostInstance = NULL;
+ usb_host_instance_t *hostInstance = NULL;
uint8_t interfaceIndex;
uint8_t index = 0;
@@ -1219,11 +1268,11 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos
}
hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
- USB_HostLock();
+ (void)USB_HostLock();
/* check host_instance valid? */
for (; index < USB_HOST_CONFIG_MAX_HOST; ++index)
{
- if ((g_UsbHostInstance[index].occupied == 1) &&
+ if ((g_UsbHostInstance[index].occupied == 1U) &&
((usb_host_instance_t *)(&g_UsbHostInstance[index]) == (hostInstance)))
{
break;
@@ -1231,14 +1280,14 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos
}
if (index >= USB_HOST_CONFIG_MAX_HOST)
{
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Error;
}
/* check deviceHandle valid? */
if (USB_HostValidateDevice(hostInstance, deviceHandle) != kStatus_USB_Success)
{
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Error;
}
@@ -1247,11 +1296,11 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos
{
if (&deviceInstance->configuration.interfaceList[interfaceIndex] == interfaceHandle)
{
- deviceInstance->interfaceStatus[interfaceIndex] = kStatus_interface_Opened;
+ deviceInstance->interfaceStatus[interfaceIndex] = (uint8_t)kStatus_interface_Opened;
break;
}
}
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Success;
}
@@ -1259,10 +1308,10 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos
usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_host_interface_handle interfaceHandle)
{
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- usb_host_instance_t *hostInstance = NULL;
+ usb_host_instance_t *hostInstance = NULL;
uint8_t interfaceIndex;
uint8_t removeLabel = 1;
- uint8_t index = 0;
+ uint8_t index = 0;
if (deviceHandle == NULL)
{
@@ -1270,11 +1319,11 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho
}
hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
- USB_HostLock();
+ (void)USB_HostLock();
/* check host_instance valid? */
for (; index < USB_HOST_CONFIG_MAX_HOST; ++index)
{
- if ((g_UsbHostInstance[index].occupied == 1) &&
+ if ((g_UsbHostInstance[index].occupied == 1U) &&
((usb_host_instance_t *)(&g_UsbHostInstance[index]) == (hostInstance)))
{
break;
@@ -1282,14 +1331,14 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho
}
if (index >= USB_HOST_CONFIG_MAX_HOST)
{
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Error;
}
/* check deviceHandle valid? */
if (USB_HostValidateDevice(hostInstance, deviceHandle) != kStatus_USB_Success)
{
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Error;
}
@@ -1300,32 +1349,32 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho
{
if (&deviceInstance->configuration.interfaceList[interfaceIndex] == interfaceHandle)
{
- deviceInstance->interfaceStatus[interfaceIndex] = kStatus_interface_Detached;
+ deviceInstance->interfaceStatus[interfaceIndex] = (uint8_t)kStatus_interface_Detached;
break;
}
}
}
- if (deviceInstance->deviceAttachState == kStatus_device_Detached) /* device is removed from host */
+ if (deviceInstance->deviceAttachState == (uint8_t)kStatus_device_Detached) /* device is removed from host */
{
removeLabel = 1;
/* check all the interfaces of the device are not opened */
for (interfaceIndex = 0; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex)
{
- if (deviceInstance->interfaceStatus[interfaceIndex] == kStatus_interface_Opened)
+ if (deviceInstance->interfaceStatus[interfaceIndex] == (uint8_t)kStatus_interface_Opened)
{
- removeLabel = 0;
+ removeLabel = 0U;
break;
}
}
- if (removeLabel == 1)
+ if (removeLabel == 1U)
{
/* remove device instance from host */
- USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
+ (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
}
- USB_HostUnlock();
+ (void)USB_HostUnlock();
- if (removeLabel == 1)
+ if (removeLabel == 1U)
{
USB_HostReleaseDeviceResource((usb_host_instance_t *)deviceInstance->hostHandle,
deviceInstance); /* release device resource */
@@ -1333,7 +1382,7 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho
}
else
{
- USB_HostUnlock();
+ (void)USB_HostUnlock();
}
return kStatus_USB_Success;
@@ -1341,9 +1390,9 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho
usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle)
{
- usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
+ usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- uint8_t interfaceIndex = 0;
+ uint8_t interfaceIndex = 0;
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
uint8_t level = 0;
uint8_t devHubNo;
@@ -1362,25 +1411,26 @@ usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle
if (USB_HostValidateDevice(hostInstance, deviceInstance) == kStatus_USB_Success) /* device is valid */
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
- devHubNo = deviceInstance->hubNumber;
+ devHubNo = deviceInstance->hubNumber;
devPortNo = deviceInstance->portNumber;
- level = deviceInstance->level;
+ level = deviceInstance->level;
#endif
- deviceInstance->deviceAttachState = kStatus_device_Detached;
- if (deviceInstance->state >= kStatus_DEV_Initial) /* device is valid */
+ deviceInstance->deviceAttachState = (uint8_t)kStatus_device_Detached;
+ if (deviceInstance->state >= (uint8_t)kStatus_DEV_Initial) /* device is valid */
{
- if (deviceInstance->state < kStatus_DEV_AppUsed) /* enumeraion is not done or application don't use */
+ if (deviceInstance->state <
+ (uint8_t)kStatus_DEV_AppUsed) /* enumeration is not done or application don't use */
{
/* detach internally */
- USB_HostDetachDeviceInternal(hostHandle, deviceHandle);
+ (void)USB_HostDetachDeviceInternal(hostHandle, deviceHandle);
}
else /* application use the device */
{
- for (interfaceIndex = 0; interfaceIndex < deviceInstance->configuration.interfaceCount;
+ for (interfaceIndex = 0U; interfaceIndex < deviceInstance->configuration.interfaceCount;
++interfaceIndex)
{
- if (deviceInstance->interfaceStatus[interfaceIndex] == kStatus_interface_Opened)
+ if (deviceInstance->interfaceStatus[interfaceIndex] == (uint8_t)kStatus_interface_Opened)
{
#ifdef HOST_ECHO
usb_echo("error: there is class instance that is not deinited\r\n");
@@ -1389,20 +1439,20 @@ usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle
}
}
/* remove device instance from host */
- USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
+ (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance);
USB_HostReleaseDeviceResource(hostInstance, deviceInstance); /* release resource */
}
}
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
- if (level == 1)
+ if (level == 1U)
{
- USB_HostControlBus(hostHandle, kUSB_HostBusReset); /* reset controller port */
- USB_HostControlBus(hostHandle, kUSB_HostBusRestart); /* restart controller port */
+ (void)USB_HostControlBus(hostHandle, (uint8_t)kUSB_HostBusReset); /* reset controller port */
+ (void)USB_HostControlBus(hostHandle, (uint8_t)kUSB_HostBusRestart); /* restart controller port */
}
else
{
- USB_HostHubRemovePort(hostHandle, devHubNo, devPortNo); /* reset hub port */
+ (void)USB_HostHubRemovePort(hostHandle, devHubNo, devPortNo); /* reset hub port */
}
#else
USB_HostControlBus(hostHandle, kUSB_HostBusReset); /* reset controller port */
@@ -1411,4 +1461,4 @@ usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle
}
return kStatus_USB_Success;
-}
+} \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h
index 422e876a12..5612603cb0 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h
@@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_DEV_MNG_H_
@@ -79,11 +57,11 @@ typedef struct _usb_host_device_instance
usb_descriptor_device_t *deviceDescriptor; /*!< Standard device descriptor */
usb_host_pipe_handle controlPipe; /*!< Device's control pipe */
uint8_t *configurationDesc; /*!< Configuration descriptor pointer */
+ uint8_t *enumBuffer; /*!< Buffer for enumeration */
uint16_t configurationLen; /*!< Configuration descriptor length */
- uint16_t configurationValue; /*!< Configuration index */
uint8_t interfaceStatus[USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE]; /*!< Interfaces' status, please reference to
#usb_host_interface_state_t */
- uint8_t *enumBuffer; /*!< Buffer for enumeration */
+ uint8_t configurationValue; /*!< Configuration index */
uint8_t state; /*!< Device state for enumeration */
uint8_t enumRetries; /*!< Re-enumeration when error in control transfer */
uint8_t stallRetries; /*!< Re-transfer when stall */
@@ -104,11 +82,10 @@ typedef struct _usb_host_device_instance
typedef struct _usb_host_enum_process_entry
{
- uint8_t successState; /*!< When the last step is successful, the next state value */
- uint8_t retryState; /*!< When the last step need retry, the next state value */
- usb_status_t (*process)(usb_host_device_instance_t *deviceInstance); /*!< When the last step transfer is done, the
- function is used to process the transfer
- data */
+ usb_host_device_enumeration_status_t successState; /*!< When the last step is successful, the next state value */
+ usb_host_device_enumeration_status_t retryState; /*!< When the last step need retry, the next state value */
+ /*! When the last step transfer is done, the function is used to process the transfer data */
+ usb_status_t (*process)(usb_host_device_instance_t *deviceInstance, uint32_t dataLength);
} usb_host_enum_process_entry_t;
/*******************************************************************************
@@ -175,4 +152,4 @@ extern uint8_t USB_HostGetDeviceAttachState(usb_device_handle deviceHandle);
extern usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);
/*! @}*/
-#endif /* _USB_HOST_DEV_MNG_H_ */
+#endif /* _USB_HOST_DEV_MNG_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c
index 8a31514b3a..9382aad979 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c
@@ -1,41 +1,22 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016,2019 - 2020 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
-#include <usb/include/usb_device_config.h>
+#include <usb/include/usb_host_config.h>
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
#include "usb_host.h"
#include "usb_host_hci.h"
#include "usb_host_devices.h"
+#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
+#include "usb_host_framework.h"
+#endif
#include "fsl_device_registers.h"
#include "usb_host_ehci.h"
-#include "usb_phy.h"
+#include <usb/phy/usb_phy.h>
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
#include "usb_host.h"
#endif
@@ -50,16 +31,16 @@
#endif
-#define USB_HOST_EHCI_BANDWIDTH_DELAY (3500U)
-#define USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP (333U)
+#define USB_HOST_EHCI_BANDWIDTH_DELAY (3500U)
+#define USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP (333U)
#define USB_HOST_EHCI_BANDWIDTH_FRAME_TOTOAL_TIME (900U)
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
-#define USB_HOST_EHCI_TEST_DESCRIPTOR_LENGTH (18U)
-#define USB_HOST_EHCI_PORTSC_PTC_J_STATE (0x01U)
-#define USB_HOST_EHCI_PORTSC_PTC_K_STATE (0x02U)
-#define USB_HOST_EHCI_PORTSC_PTC_SE0_NAK (0x03U)
-#define USB_HOST_EHCI_PORTSC_PTC_PACKET (0x04U)
+#define USB_HOST_EHCI_TEST_DESCRIPTOR_LENGTH (18U)
+#define USB_HOST_EHCI_PORTSC_PTC_J_STATE (0x01U)
+#define USB_HOST_EHCI_PORTSC_PTC_K_STATE (0x02U)
+#define USB_HOST_EHCI_PORTSC_PTC_SE0_NAK (0x03U)
+#define USB_HOST_EHCI_PORTSC_PTC_PACKET (0x04U)
#define USB_HOST_EHCI_PORTSC_PTC_FORCE_ENABLE_HS (0x05U)
#define USB_HOST_EHCI_PORTSC_PTC_FORCE_ENABLE_FS (0x06U)
#define USB_HOST_EHCI_PORTSC_PTC_FORCE_ENABLE_LS (0x07U)
@@ -102,7 +83,7 @@ static void USB_HostBandwidthFslsHostComputeCurrent(usb_host_ehci_instance_t *eh
static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *ehciInstance,
uint32_t hubNumber,
uint16_t frameIndex,
- uint8_t frameBandwidths[8]);
+ uint16_t frameBandwidths[8]);
/*!
* @brief compute current allocated HS bandwidth when ehci work as hi-speed host.
@@ -113,7 +94,7 @@ static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *
*/
static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t *ehciInstance,
uint16_t frameIndex,
- uint8_t frameBandwidths[8]);
+ uint16_t frameBandwidths[8]);
/*!
* @brief allocate HS bandwidth when host work as high-speed host.
@@ -176,13 +157,6 @@ static void USB_HostEhciZeroMem(uint32_t *buffer, uint32_t length);
static void USB_HostEhciDelay(USBHS_Type *ehciIpBase, uint32_t ms);
/*!
- * @brief host ehci start async schedule.
- *
- * @param ehciInstance ehci instance pointer.
- */
-static void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance);
-
-/*!
* @brief host ehci stop async schedule.
*
* @param ehciInstance ehci instance pointer.
@@ -190,13 +164,6 @@ static void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance);
static void USB_HostEhciStopAsync(usb_host_ehci_instance_t *ehciInstance);
/*!
- * @brief host ehci start periodic schedule.
- *
- * @param ehciInstance ehci instance pointer.
- */
-static void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance);
-
-/*!
* @brief host ehci stop periodic schedule.
*
* @param ehciInstance ehci instance pointer.
@@ -516,36 +483,13 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc
usb_host_transfer_t *transfer);
/*!
- * @brief control ehci bus.
- *
- * @param ehciInstance ehci instance pointer.
- * @param bus_control control code.
- *
- * @return kStatus_USB_Success or error codes.
- */
-static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl);
-
-/*!
* @brief ehci transaction done process function.
*
* @param ehciInstance ehci instance pointer.
*/
void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance);
-/*!
- * @brief ehci port change interrupt process function.
- *
- * @param ehciInstance ehci instance pointer.
- */
-static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance);
-/*!
- * @brief ehci timer0 interrupt process function.
- * cancel control/bulk transfer that time out.
- *
- * @param ehciInstance ehci instance pointer.
- */
-static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance);
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
/*!
@@ -586,71 +530,60 @@ extern usb_status_t USB_HostStandardSetGetDescriptor(usb_host_device_instance_t
USB_RAM_ADDRESS_ALIGNMENT(4096)
USB_CONTROLLER_DATA static uint8_t s_UsbHostEhciFrameList1[USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 4];
-#define USB_HOST_EHCI_FRAME_LIST_ARRAY \
- { \
- &s_UsbHostEhciFrameList1[0] \
- }
+static uint8_t usbHostEhciFramListStatus[1] = {0};
USB_RAM_ADDRESS_ALIGNMENT(64) USB_CONTROLLER_DATA static usb_host_ehci_data_t s_UsbHostEhciData1;
-#define USB_HOST_EHCI_DATA_ARRAY \
- { \
- &s_UsbHostEhciData1 \
- }
-#elif(USB_HOST_CONFIG_EHCI == 2U)
+#elif (USB_HOST_CONFIG_EHCI == 2U)
USB_RAM_ADDRESS_ALIGNMENT(4096)
USB_CONTROLLER_DATA static uint8_t s_UsbHostEhciFrameList1[USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 4];
USB_RAM_ADDRESS_ALIGNMENT(4096)
USB_CONTROLLER_DATA static uint8_t s_UsbHostEhciFrameList2[USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 4];
-#define USB_HOST_EHCI_FRAME_LIST_ARRAY \
- { \
- &s_UsbHostEhciFrameList1[0], &s_UsbHostEhciFrameList2[0] \
- }
+static uint8_t usbHostEhciFramListStatus[2] = {0, 0};
USB_RAM_ADDRESS_ALIGNMENT(64) USB_CONTROLLER_DATA static usb_host_ehci_data_t s_UsbHostEhciData1;
USB_RAM_ADDRESS_ALIGNMENT(64) USB_CONTROLLER_DATA static usb_host_ehci_data_t s_UsbHostEhciData2;
-#define USB_HOST_EHCI_DATA_ARRAY \
- { \
- &s_UsbHostEhciData1, &s_UsbHostEhciData2 \
- }
#else
#error "Please increase the instance count."
#endif
+#define USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE (1024U)
+#define USB_HOST_EHCI_MAX_MICRFRAME_VALUE ((USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE << 3U) - 1U)
-static uint8_t s_SlotMaxBandwidth[8] = {125, 125, 125, 125, 125, 125, 50, 0};
+static uint8_t s_SlotMaxBandwidth[8] = {125, 125, 125, 125, 125, 125, 50, 0};
+static uint8_t s_SlotMaxBandwidthHs[8] = {100, 100, 100, 100, 100, 100, 100, 100};
/*******************************************************************************
* Code
******************************************************************************/
/*!
-* @brief EHCI NC get USB NC bass address.
-*
-* This function is used to get USB NC bass address.
-*
-* @param[in] controllerId EHCI controller ID; See the #usb_controller_index_t.
-*
-* @retval USB NC bass address.
-*/
+ * @brief EHCI NC get USB NC bass address.
+ *
+ * This function is used to get USB NC bass address.
+ *
+ * @param[in] controllerId EHCI controller ID; See the #usb_controller_index_t.
+ *
+ * @retval USB NC bass address.
+ */
#if (defined(USB_HOST_CONFIG_LOW_POWER_MODE) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
#if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
-void *USB_EhciNCGetBase(uint8_t controllerId)
+static void *USB_EhciNCGetBase(uint8_t controllerId)
{
void *usbNCBase = NULL;
#if ((defined FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
uint32_t instance;
- uint32_t newinstance = 0;
+ uint32_t newinstance = 0;
uint32_t usbnc_base_temp[] = USBNC_BASE_ADDRS;
- uint32_t usbnc_base[] = USBNC_BASE_ADDRS;
+ uint32_t usbnc_base[] = USBNC_BASE_ADDRS;
- if (controllerId < kUSB_ControllerEhci0)
+ if (controllerId < (uint8_t)kUSB_ControllerEhci0)
{
return NULL;
}
- controllerId = controllerId - kUSB_ControllerEhci0;
+ controllerId = controllerId - (uint8_t)kUSB_ControllerEhci0;
for (instance = 0; instance < (sizeof(usbnc_base_temp) / sizeof(usbnc_base_temp[0])); instance++)
{
- if (usbnc_base_temp[instance])
+ if (usbnc_base_temp[instance] != 0U)
{
usbnc_base[newinstance++] = usbnc_base_temp[instance];
}
@@ -660,7 +593,7 @@ void *USB_EhciNCGetBase(uint8_t controllerId)
return NULL;
}
- usbNCBase = (void *)usbnc_base[controllerId];
+ usbNCBase = (void *)(uint8_t *)usbnc_base[controllerId];
#endif
return usbNCBase;
}
@@ -729,19 +662,19 @@ static void USB_HostEhciTestSingleStepGetDeviceDesc(usb_host_ehci_instance_t *eh
return;
}
- getDescriptorParam.descriptorLength = sizeof(usb_descriptor_device_t);
- getDescriptorParam.descriptorLength = 18;
- getDescriptorParam.descriptorBuffer = (uint8_t *)&deviceInstance->deviceDescriptor;
- getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE;
- getDescriptorParam.descriptorIndex = 0;
- getDescriptorParam.languageId = 0;
- transfer->callbackFn = USB_HostEhciTestCallback;
- transfer->callbackParam = ehciInstance->hostHandle;
+ getDescriptorParam.descriptorLength = sizeof(usb_descriptor_device_t);
+ getDescriptorParam.descriptorLength = 18;
+ getDescriptorParam.descriptorBuffer = (uint8_t *)&deviceInstance->deviceDescriptor;
+ getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE;
+ getDescriptorParam.descriptorIndex = 0;
+ getDescriptorParam.languageId = 0;
+ transfer->callbackFn = USB_HostEhciTestCallback;
+ transfer->callbackParam = ehciInstance->hostHandle;
transfer->setupPacket->bmRequestType = USB_REQUEST_TYPE_DIR_IN;
- transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
- transfer->setupPacket->wIndex = 0;
- transfer->setupPacket->wLength = 0;
- transfer->setupPacket->wValue = 0;
+ transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
+ transfer->setupPacket->wIndex = 0;
+ transfer->setupPacket->wLength = 0;
+ transfer->setupPacket->wValue = 0;
USB_HostStandardSetGetDescriptor(deviceInstance, transfer, &getDescriptorParam);
}
@@ -774,8 +707,8 @@ static usb_status_t USB_HostEhciSingleStepQtdListInit(usb_host_ehci_instance_t *
{
qtdPointer->nextQtdPointer = (uint32_t)ehciInstance->ehciQtdHead;
}
- qtdPointer = ehciInstance->ehciQtdHead;
- ehciInstance->ehciQtdHead = (usb_host_ehci_qtd_t *)qtdPointer->nextQtdPointer;
+ qtdPointer = ehciInstance->ehciQtdHead;
+ ehciInstance->ehciQtdHead = (usb_host_ehci_qtd_t *)qtdPointer->nextQtdPointer;
qtdPointer->nextQtdPointer = 0;
} while (--qtdNumber);
}
@@ -795,7 +728,7 @@ static usb_status_t USB_HostEhciSingleStepQtdListInit(usb_host_ehci_instance_t *
qtdPointer->transferResults[0] =
((0x00000000 << EHCI_HOST_QTD_DT_SHIFT) | (8 << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
(EHCI_HOST_PID_SETUP << EHCI_HOST_QTD_PID_CODE_SHIFT) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
- dataAddress = (uint32_t)(transfer->setupPacket);
+ dataAddress = (uint32_t)(transfer->setupPacket);
qtdPointer->transferResults[1] = dataAddress; /* current offset is set too */
/* set buffer pointer no matter data length */
for (index = 0; index < 4; ++index)
@@ -816,7 +749,7 @@ static usb_status_t USB_HostEhciSingleStepQtdListInit(usb_host_ehci_instance_t *
((0x00000001U << EHCI_HOST_QTD_DT_SHIFT) | (dataLength << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
(EHCI_HOST_PID_IN << EHCI_HOST_QTD_PID_CODE_SHIFT) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
- dataAddress = (uint32_t)(transfer->transferBuffer);
+ dataAddress = (uint32_t)(transfer->transferBuffer);
qtdPointer->transferResults[1] = dataAddress; /* current offset is set too */
/* set buffer pointer no matter data length */
for (index = 0; index < 4; ++index)
@@ -848,24 +781,24 @@ static usb_status_t USB_HostEhciSingleStepQtdListInit(usb_host_ehci_instance_t *
transfer->next = NULL;
if (vltQhPointer->ehciTransferHead == NULL)
{
- transfer->next = NULL;
+ transfer->next = NULL;
vltQhPointer->ehciTransferHead = vltQhPointer->ehciTransferTail = transfer;
}
else
{
- transfer->next = NULL;
+ transfer->next = NULL;
vltQhPointer->ehciTransferTail->next = transfer;
- vltQhPointer->ehciTransferTail = transfer;
+ vltQhPointer->ehciTransferTail = transfer;
}
USB_HostEhciLock();
/* link qtd to qh (link to end) */
entryPointer = &(vltQhPointer->nextQtdPointer);
- dataAddress = *entryPointer; /* dataAddress variable means entry value here */
+ dataAddress = *entryPointer; /* dataAddress variable means entry value here */
while ((dataAddress) && (!(dataAddress & EHCI_HOST_T_INVALID_VALUE)))
{
entryPointer = (volatile uint32_t *)dataAddress;
- dataAddress = *entryPointer;
+ dataAddress = *entryPointer;
}
*entryPointer = (uint32_t)qtdPointer;
USB_HostEhciUnlock();
@@ -888,11 +821,11 @@ static void USB_HostEhciTestSingleStepGetDeviceDescData(usb_host_ehci_instance_t
{
return;
}
- transfer->callbackFn = USB_HostEhciTestCallback;
- transfer->callbackParam = ehciInstance->hostHandle;
+ transfer->callbackFn = USB_HostEhciTestCallback;
+ transfer->callbackParam = ehciInstance->hostHandle;
transfer->setupPacket->bmRequestType = USB_REQUEST_TYPE_DIR_IN;
- transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
- transfer->setupPacket->wLength = USB_SHORT_TO_LITTLE_ENDIAN(USB_HOST_EHCI_TEST_DESCRIPTOR_LENGTH);
+ transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR;
+ transfer->setupPacket->wLength = USB_SHORT_TO_LITTLE_ENDIAN(USB_HOST_EHCI_TEST_DESCRIPTOR_LENGTH);
transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN((uint16_t)((uint16_t)USB_DESCRIPTOR_TYPE_DEVICE << 8));
transfer->setupPacket->wIndex = 0;
USB_HostEhciSingleStepQtdListInit(ehciInstance, (usb_host_ehci_pipe_t *)(deviceInstance->controlPipe), transfer, 1);
@@ -907,8 +840,8 @@ static void USB_HostEhciTestSingleStepGetDeviceDescData(usb_host_ehci_instance_t
{
return;
}
- transfer->callbackFn = USB_HostEhciTestCallback;
- transfer->callbackParam = ehciInstance->hostHandle;
+ transfer->callbackFn = USB_HostEhciTestCallback;
+ transfer->callbackParam = ehciInstance->hostHandle;
transfer->transferBuffer = buffer;
transfer->transferLength = USB_HOST_EHCI_TEST_DESCRIPTOR_LENGTH;
USB_HostEhciSingleStepQtdListInit(ehciInstance, (usb_host_ehci_pipe_t *)(deviceInstance->controlPipe), transfer, 2);
@@ -917,8 +850,8 @@ static void USB_HostEhciTestSingleStepGetDeviceDescData(usb_host_ehci_instance_t
{
return;
}
- transfer->callbackFn = USB_HostEhciTestCallback;
- transfer->callbackParam = ehciInstance->hostHandle;
+ transfer->callbackFn = USB_HostEhciTestCallback;
+ transfer->callbackParam = ehciInstance->hostHandle;
transfer->transferBuffer = NULL;
transfer->transferLength = 0;
USB_HostEhciSingleStepQtdListInit(ehciInstance, (usb_host_ehci_pipe_t *)(deviceInstance->controlPipe), transfer, 3);
@@ -934,7 +867,7 @@ static void USB_HostEhciTestSingleStepGetDeviceDescData(usb_host_ehci_instance_t
return;
}
-void USB_HostEhciTestModeInit(usb_device_handle deviceHandle)
+static void USB_HostEhciTestModeInit(usb_device_handle deviceHandle)
{
uint32_t productId;
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
@@ -975,6 +908,7 @@ void USB_HostEhciTestModeInit(usb_device_handle deviceHandle)
USB_HostEhciTestSingleStepGetDeviceDescData(ehciInstance, deviceHandle);
break;
default:
+ /*no action */
break;
}
@@ -1014,60 +948,62 @@ static void USB_HostEhciResumeBus(usb_host_ehci_instance_t *ehciInstance)
static uint32_t USB_HostBandwidthComputeTime(uint8_t speed, uint8_t pipeType, uint8_t direction, uint32_t dataLength)
{
- uint32_t result = (3167 + ((1000 * dataLength) * 7U * 8U / 6U)) / 1000;
+ uint32_t result = (3167U + ((1000U * dataLength) * 7U * 8U / 6U)) / 1000U;
if (pipeType == USB_ENDPOINT_ISOCHRONOUS) /* iso */
{
if (speed == USB_SPEED_HIGH)
{
- result = 38 * 8 * 2083 + 2083 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 38U * 8U * 2083U + 2083U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
else if (speed == USB_SPEED_FULL)
{
if (direction == USB_IN)
{
- result = 7268000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 7268000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
else
{
- result = 6265000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 6265000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
}
else
{
+ /*no action*/
}
}
else /* interrupt */
{
if (speed == USB_SPEED_HIGH)
{
- result = 55 * 8 * 2083 + 2083 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 55U * 8U * 2083U + 2083U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
else if (speed == USB_SPEED_FULL)
{
- result = 9107000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 9107000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
else if (speed == USB_SPEED_LOW)
{
if (direction == USB_IN)
{
- result = 64060000 + 2000 * USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP + 676670 * result +
+ result = 64060000U + 2000U * USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP + 676670U * result +
USB_HOST_EHCI_BANDWIDTH_DELAY;
}
else
{
- result = 6265000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
+ result = 6265000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY;
}
}
else
{
+ /*no action*/
}
}
- result /= 1000000;
- if (result == 0)
+ result /= 1000000U;
+ if (result == 0U)
{
- result = 1;
+ result = 1U;
}
return result;
@@ -1078,7 +1014,7 @@ static void USB_HostBandwidthFslsHostComputeCurrent(usb_host_ehci_instance_t *eh
uint16_t *frameBandwidth)
{
usb_host_ehci_pipe_t *ehciPipePointer;
-
+ void *temp;
/* clear the bandwidth */
*frameBandwidth = 0;
@@ -1091,26 +1027,28 @@ static void USB_HostBandwidthFslsHostComputeCurrent(usb_host_ehci_instance_t *eh
{
/* does pipe allocate bandwidth in frameIndex frame? note: interval is power of 2. */
if ((frameIndex >= ehciPipePointer->startFrame) &&
- (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) &
- (uint32_t)(ehciPipePointer->pipeCommon.interval - 1))))
+ (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) &
+ ((uint32_t)ehciPipePointer->pipeCommon.interval - 1U))))
{
*frameBandwidth += ehciPipePointer->dataTime;
}
}
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
}
}
static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *ehciInstance,
uint32_t hubNumber,
uint16_t frameIndex,
- uint8_t frameBandwidths[8])
+ uint16_t frameBandwidths[8])
{
usb_host_ehci_pipe_t *ehciPipePointer;
uint8_t index;
uint32_t deviceInfo;
+ void *temp;
- for (index = 0; index < 8; ++index)
+ for (index = 0; index < 8U; ++index)
{
frameBandwidths[index] = 0;
}
@@ -1124,47 +1062,50 @@ static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *
{
/* compute FS/LS bandwidth that blong to same high-speed hub, because FS/LS bandwidth is allocated from
* first parent high-speed hub */
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
- kUSB_HostGetDeviceHSHubNumber, &deviceInfo);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHSHubNumber, &deviceInfo);
if (deviceInfo != hubNumber)
{
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
continue;
}
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &deviceInfo);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo);
if (deviceInfo == USB_SPEED_HIGH)
{
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
continue;
}
/* does pipe allocate bandwidth in frameIndex frame? note: interval is power of 2. */
if ((frameIndex >= ehciPipePointer->startFrame) &&
- (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) &
- (uint32_t)(ehciPipePointer->pipeCommon.interval - 1))))
+ (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) &
+ ((uint32_t)ehciPipePointer->pipeCommon.interval - 1U))))
{
if (ehciPipePointer->pipeCommon.pipeType ==
USB_ENDPOINT_ISOCHRONOUS) /* iso bandwidth is allocated once */
{
- frameBandwidths[ehciPipePointer->startUframe + 1] += ehciPipePointer->dataTime;
+ frameBandwidths[ehciPipePointer->startUframe + 1U] += ehciPipePointer->dataTime;
}
else /* iso bandwidth is allocated three times */
{
- frameBandwidths[ehciPipePointer->startUframe + 1] += ehciPipePointer->dataTime;
- frameBandwidths[ehciPipePointer->startUframe + 2] += ehciPipePointer->dataTime;
- frameBandwidths[ehciPipePointer->startUframe + 3] += ehciPipePointer->dataTime;
+ frameBandwidths[ehciPipePointer->startUframe + 1U] += ehciPipePointer->dataTime;
+ frameBandwidths[ehciPipePointer->startUframe + 2U] += ehciPipePointer->dataTime;
+ frameBandwidths[ehciPipePointer->startUframe + 3U] += ehciPipePointer->dataTime;
}
}
}
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
}
- for (index = 0; index < 7; ++index) /* */
+ for (index = 0; index < 7U; ++index) /* */
{
if (frameBandwidths[index] > s_SlotMaxBandwidth[index])
{
- frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]);
+ frameBandwidths[index + 1U] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]);
frameBandwidths[index] = s_SlotMaxBandwidth[index];
}
}
@@ -1172,14 +1113,14 @@ static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *
static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t *ehciInstance,
uint16_t frameIndex,
- uint8_t frameBandwidths[8])
+ uint16_t frameBandwidths[8])
{
usb_host_ehci_pipe_t *ehciPipePointer;
- uint8_t index;
+ uint16_t index;
uint32_t deviceInfo;
uint16_t frameInterval;
-
- for (index = 0; index < 8; ++index)
+ void *temp;
+ for (index = 0; index < 8U; ++index)
{
frameBandwidths[index] = 0;
}
@@ -1192,26 +1133,26 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t
(ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_INTERRUPT))
{
frameInterval = ehciPipePointer->pipeCommon.interval;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &deviceInfo);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo);
if (deviceInfo == USB_SPEED_HIGH) /* high-speed data bandwidth */
{
/* frameInterval means micro-frame here */
if (frameIndex >= ehciPipePointer->startFrame)
{
- if ((frameInterval > 8) &&
- (frameIndex * 8 - ehciPipePointer->startFrame * 8 >= ehciPipePointer->startUframe))
+ if ((frameInterval > 8U) &&
+ (frameIndex * 8U - ehciPipePointer->startFrame * 8U >= ehciPipePointer->startUframe))
{
- if (!((uint32_t)(frameIndex * 8 - ehciPipePointer->startFrame * 8 -
- ehciPipePointer->startUframe) &
- (uint32_t)(frameInterval - 1)))
+ if (0U == ((((uint32_t)frameIndex) * 8U - ehciPipePointer->startFrame * 8U -
+ ehciPipePointer->startUframe) &
+ ((uint32_t)frameInterval - 1U)))
{
frameBandwidths[ehciPipePointer->startUframe] += ehciPipePointer->dataTime;
}
}
else
{
- for (index = ehciPipePointer->startUframe; index < 8; index += frameInterval)
+ for (index = ehciPipePointer->startUframe; index < 8U; index += frameInterval)
{
frameBandwidths[index] += ehciPipePointer->dataTime;
}
@@ -1221,17 +1162,18 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t
else /* full-speed split bandwidth */
{
if ((frameIndex >= ehciPipePointer->startFrame) &&
- (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) & (uint32_t)(frameInterval - 1))))
+ (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) &
+ (uint32_t)((uint32_t)frameInterval - 1U))))
{
- for (index = 0; index < 8; ++index)
+ for (index = 0; index < 8U; ++index)
{
- if ((uint32_t)(ehciPipePointer->uframeSmask) &
- (uint32_t)(0x01 << index)) /* start-split micro-frames */
+ if (0U != ((uint32_t)(ehciPipePointer->uframeSmask) &
+ (uint32_t)(0x01UL << index))) /* start-split micro-frames */
{
frameBandwidths[index] += ehciPipePointer->startSplitTime;
}
- if ((uint32_t)(ehciPipePointer->uframeCmask) &
- (uint32_t)(0x01 << index)) /* complete-split micro-frames */
+ if (0U != ((uint32_t)(ehciPipePointer->uframeCmask) &
+ (uint32_t)(0x01UL << index))) /* complete-split micro-frames */
{
frameBandwidths[index] += ehciPipePointer->completeSplitTime;
}
@@ -1239,17 +1181,20 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t
}
}
}
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
}
+#if 0
for (index = 0; index < 7; ++index) /* */
{
- if (frameBandwidths[index] > s_SlotMaxBandwidth[index])
+ if (frameBandwidths[index] > s_SlotMaxBandwidthHs[index])
{
- frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]);
- frameBandwidths[index] = s_SlotMaxBandwidth[index];
+ frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidthHs[index]);
+ frameBandwidths[index] = s_SlotMaxBandwidthHs[index];
}
}
+#endif
}
/*!
@@ -1270,15 +1215,19 @@ static usb_status_t USB_HostBandwidthHsHostAllocateHsCommon(usb_host_ehci_instan
uint16_t uframeIntervalIndex;
uint16_t uframeIndex;
uint16_t frameIndex;
- uint8_t frameTimes[8];
+ uint16_t frameTimes[8];
frameIndex = 0;
+ for (uint8_t i = 0; i < 8U; ++i)
+ {
+ frameTimes[i] = 0U;
+ }
USB_HostBandwidthHsHostComputeCurrentHsAll(
ehciInstance, frameIndex, frameTimes); /* compute the allocated bandwidths in the frameIndex frame */
for (uframeIntervalIndex = 0; (uframeIntervalIndex < uframeInterval); ++uframeIntervalIndex) /* start micro-frame */
{
/* for all the micro-frame in interval uframeInterval */
- for (uframeIndex = uframeIntervalIndex; uframeIndex < (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8);
+ for (uframeIndex = uframeIntervalIndex; uframeIndex < (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8U);
uframeIndex += uframeInterval)
{
if (frameIndex != (uframeIndex >> 3))
@@ -1288,13 +1237,13 @@ static usb_status_t USB_HostBandwidthHsHostAllocateHsCommon(usb_host_ehci_instan
ehciInstance, frameIndex,
frameTimes); /* compute the allocated bandwidths in the new frameIndex frame */
}
- if (frameTimes[uframeIndex & 0x0007] + timeData >
- s_SlotMaxBandwidth[(uframeIndex & 0x0007)]) /* micro-frame has enough idle bandwidth? */
+ if (frameTimes[uframeIndex & 0x0007U] + timeData >
+ s_SlotMaxBandwidthHs[(uframeIndex & 0x0007U)]) /* micro-frame has enough idle bandwidth? */
{
break; /* fail */
}
}
- if (uframeIndex >= (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8)) /* success? */
+ if (uframeIndex >= (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8U)) /* success? */
{
break;
}
@@ -1318,91 +1267,97 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
usb_host_ehci_pipe_t *ehciPipePointer)
{
usb_status_t status;
- uint32_t deviceInfo;
- uint32_t hubNumber;
+ uint32_t deviceInfo = 0;
+ uint32_t hubNumber = 0;
uint16_t uframeIntervalIndex = 0;
- uint16_t frameIntervalIndex = 0;
+ uint16_t frameIntervalIndex = 0;
uint16_t frameIndex;
uint16_t timeCompleteSplit;
uint16_t timeStartSplit;
uint32_t timeData;
uint8_t SsCsNumber = 0;
uint16_t frameInterval;
- uint8_t frameTimes[8];
+ uint16_t frameTimes[8];
uint8_t allocateOk = 1;
- uint8_t index;
+ uint16_t index;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &deviceInfo);
+ for (uint8_t i = 0; i < 8U; ++i)
+ {
+ frameTimes[i] = 0U;
+ }
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo);
timeData = USB_HostBandwidthComputeTime(
- deviceInfo, USB_ENDPOINT_ISOCHRONOUS, ehciPipePointer->pipeCommon.direction,
- ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe);
+ (uint8_t)deviceInfo, USB_ENDPOINT_ISOCHRONOUS, ehciPipePointer->pipeCommon.direction,
+ (((uint32_t)ehciPipePointer->pipeCommon.maxPacketSize) * ehciPipePointer->pipeCommon.numberPerUframe));
/* pipe is high-speed */
if (deviceInfo == USB_SPEED_HIGH)
{
uframeIntervalIndex = 0;
- status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, timeData,
- &uframeIntervalIndex);
+ status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval,
+ (uint16_t)timeData, &uframeIntervalIndex);
if (status == kStatus_USB_Success)
{
- ehciPipePointer->startFrame = (uframeIntervalIndex / 8);
- ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007);
- ehciPipePointer->dataTime = timeData;
+ ehciPipePointer->startFrame = (uframeIntervalIndex / 8U);
+ ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U);
+ ehciPipePointer->dataTime = (uint16_t)timeData;
return kStatus_USB_Success;
}
}
else /* pipe is full-speed or low-speed */
{
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetHubThinkTime,
- &deviceInfo); /* deviceInfo variable means hub think time */
- timeData += (deviceInfo * 7 / (6 * 12));
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubNumber,
- &hubNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetHubThinkTime,
+ &deviceInfo); /* deviceInfo variable means hub think time */
+ timeData += (deviceInfo * 7U / (6U * 12U));
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHSHubNumber, &hubNumber);
frameInterval = ehciPipePointer->pipeCommon.interval;
/* compute start-split and complete-split bandwidth */
if (ehciPipePointer->pipeCommon.direction == USB_OUT)
{
- timeStartSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_OUT,
- ehciPipePointer->pipeCommon.maxPacketSize);
+ timeStartSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_OUT,
+ ehciPipePointer->pipeCommon.maxPacketSize);
timeCompleteSplit = 0;
}
else
{
- timeStartSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_IN, 1);
- timeCompleteSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_IN,
- ehciPipePointer->pipeCommon.maxPacketSize);
+ timeStartSplit =
+ (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_IN, 1);
+ timeCompleteSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_IN,
+ ehciPipePointer->pipeCommon.maxPacketSize);
}
/* note: bandwidth must put in one frame */
- for (uframeIntervalIndex = 0; uframeIntervalIndex <= 5; ++uframeIntervalIndex) /* uframe interval */
+ for (uframeIntervalIndex = 0U; uframeIntervalIndex <= 5U; ++uframeIntervalIndex) /* uframe interval */
{
- for (frameIntervalIndex = 0; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */
+ for (frameIntervalIndex = 0U; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */
{
allocateOk = 1;
for (frameIndex = frameIntervalIndex; frameIndex < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE;
frameIndex += frameInterval) /* check all the frames */
{
/* compute start-split and complete-split number */
- SsCsNumber = (ehciPipePointer->pipeCommon.maxPacketSize + 187) /
- 188; /* ss number for iso out; cs number for iso in */
+ SsCsNumber = (uint8_t)((ehciPipePointer->pipeCommon.maxPacketSize + 187U) /
+ 188U); /* ss number for iso out; cs number for iso in */
if (ehciPipePointer->pipeCommon.direction == USB_OUT) /* ISO OUT */
{
- if (uframeIntervalIndex + SsCsNumber > 8)
+ if (uframeIntervalIndex + SsCsNumber > 8U)
{
- allocateOk = 0;
+ allocateOk = 0U;
}
}
else
{
- if (uframeIntervalIndex + 2 + SsCsNumber >
- 8) /* ISO IN: there are two micro-frame interval between start-split and complete-split */
+ if (uframeIntervalIndex + 2U + SsCsNumber >
+ 8U) /* ISO IN: there are two micro-frame interval between start-split and complete-split */
{
- allocateOk = 0;
+ allocateOk = 0U;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
/* allocate start-split and complete-split bandwidth */
USB_HostBandwidthHsHostComputeCurrentHsAll(ehciInstance, frameIndex, frameTimes);
@@ -1411,9 +1366,9 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
index = uframeIntervalIndex;
for (; index < (uframeIntervalIndex + SsCsNumber); ++index)
{
- if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidth[index])
+ if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidthHs[index])
{
- allocateOk = 0;
+ allocateOk = 0U;
break;
}
}
@@ -1421,20 +1376,20 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
else /* ISO IN */
{
index = uframeIntervalIndex;
- if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidth[index])
+ if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidthHs[index])
{
- allocateOk = 0;
+ allocateOk = 0U;
}
- if (allocateOk)
+ if (0U != allocateOk)
{
index =
uframeIntervalIndex +
- 2; /* there are two micro-frames interval between start-split and complete-split */
- for (; index < (uframeIntervalIndex + 2 + SsCsNumber); ++index)
+ 2U; /* there are two micro-frames interval between start-split and complete-split */
+ for (; index < (uframeIntervalIndex + 2U + SsCsNumber); ++index)
{
- if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidth[index])
+ if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidthHs[index])
{
- allocateOk = 0;
+ allocateOk = 0U;
break;
}
}
@@ -1443,18 +1398,18 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
}
/* allocate data bandwidth */
- if (allocateOk)
+ if (0U != allocateOk)
{
USB_HostBandwidthHsHostComputeCurrentFsls(ehciInstance, hubNumber, frameIndex, frameTimes);
- index = uframeIntervalIndex + 1; /* timeData bandwidth start position */
+ index = uframeIntervalIndex + 1U; /* timeData bandwidth start position */
/* iso must occupy all the uframe bandwidth */
{
deviceInfo = timeData; /* note: deviceInfo variable means bandwidth here */
- while ((index < 8) && (deviceInfo > s_SlotMaxBandwidth[index]))
+ while ((index < 8U) && (deviceInfo > s_SlotMaxBandwidth[index]))
{
- if (frameTimes[index] > 0)
+ if (frameTimes[index] > 0U)
{
- allocateOk = 0;
+ allocateOk = 0U;
break;
}
else
@@ -1465,16 +1420,16 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
}
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
/* data bandwidth can be put in the frame? */
- index = uframeIntervalIndex + 1; /* timeData bandwidth start position */
- frameTimes[index] += timeData;
- for (; index < 7; ++index)
+ index = uframeIntervalIndex + 1U; /* timeData bandwidth start position */
+ frameTimes[index] += (uint16_t)timeData;
+ for (; index < 7U; ++index)
{
if (frameTimes[index] > s_SlotMaxBandwidth[index])
{
- frameTimes[index + 1] += (frameTimes[index] - s_SlotMaxBandwidth[index]);
+ frameTimes[index + 1U] += (frameTimes[index] - s_SlotMaxBandwidth[index]);
frameTimes[index] = s_SlotMaxBandwidth[index];
}
else
@@ -1488,45 +1443,45 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
break;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
break;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
break;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
- ehciPipePointer->startFrame = frameIntervalIndex;
- ehciPipePointer->startUframe = uframeIntervalIndex;
- ehciPipePointer->dataTime = timeData;
- ehciPipePointer->startSplitTime = timeStartSplit;
+ ehciPipePointer->startFrame = frameIntervalIndex;
+ ehciPipePointer->startUframe = (uint8_t)uframeIntervalIndex;
+ ehciPipePointer->dataTime = (uint16_t)timeData;
+ ehciPipePointer->startSplitTime = timeStartSplit;
ehciPipePointer->completeSplitTime = timeCompleteSplit;
if (ehciPipePointer->pipeCommon.direction == USB_OUT)
{
index = uframeIntervalIndex;
for (; index < (uframeIntervalIndex + SsCsNumber); ++index)
{
- ehciPipePointer->uframeSmask = (uint32_t)ehciPipePointer->uframeSmask | (uint32_t)(0x01 << index);
+ ehciPipePointer->uframeSmask = ehciPipePointer->uframeSmask | (uint8_t)(0x01UL << index);
}
}
else
{
- index = uframeIntervalIndex;
- ehciPipePointer->uframeSmask = (uint32_t)ehciPipePointer->uframeSmask | (uint32_t)(0x01 << index);
- index = uframeIntervalIndex + 2;
- for (; index < (uframeIntervalIndex + 2 + SsCsNumber); ++index)
+ index = uframeIntervalIndex;
+ ehciPipePointer->uframeSmask = ehciPipePointer->uframeSmask | (uint8_t)(0x01UL << index);
+ index = uframeIntervalIndex + 2U;
+ for (; index < (uframeIntervalIndex + 2U + SsCsNumber); ++index)
{
- ehciPipePointer->uframeCmask = (uint32_t)ehciPipePointer->uframeCmask | (uint32_t)(0x01 << index);
+ ehciPipePointer->uframeCmask = ehciPipePointer->uframeCmask | (uint8_t)(0x01UL << index);
}
}
@@ -1543,92 +1498,100 @@ static usb_status_t USB_HostBandwidthHsHostAllocateInterrupt(usb_host_ehci_insta
usb_host_ehci_pipe_t *ehciPipePointer)
{
usb_status_t status;
- uint32_t deviceInfo;
- uint32_t hubNumber;
+ uint32_t deviceInfo = 0;
+ uint32_t hubNumber = 0;
uint16_t uframeIntervalIndex = 0;
- uint16_t frameIntervalIndex = 0;
+ uint16_t frameIntervalIndex = 0;
uint16_t frameIndex;
uint16_t timeCompleteSplit;
uint16_t timeStartSplit;
uint32_t timeData;
uint8_t SsCsNumber;
uint16_t frameInterval;
- uint8_t frameTimes[8];
+ uint16_t frameTimes[8];
uint8_t allocateOk = 1;
uint8_t index;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &deviceInfo);
+ for (uint8_t i = 0; i < 8U; ++i)
+ {
+ frameTimes[i] = 0U;
+ }
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo);
timeData = USB_HostBandwidthComputeTime(
- deviceInfo, USB_ENDPOINT_INTERRUPT, ehciPipePointer->pipeCommon.direction,
- ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe);
+ (uint8_t)deviceInfo, USB_ENDPOINT_INTERRUPT, ehciPipePointer->pipeCommon.direction,
+ (uint32_t)ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe);
/* pipe is high-speed */
if (deviceInfo == USB_SPEED_HIGH)
{
uframeIntervalIndex = 0;
- status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, timeData,
- &uframeIntervalIndex);
+ status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval,
+ (uint16_t)timeData, &uframeIntervalIndex);
if (status == kStatus_USB_Success)
{
- ehciPipePointer->startFrame = (uframeIntervalIndex / 8);
- ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007);
+ ehciPipePointer->startFrame = (uframeIntervalIndex / 8U);
+ ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U);
/* for HS interrupt start transaction position */
- if (ehciPipePointer->uframeInterval >= 8)
+ if (ehciPipePointer->uframeInterval >= 8U)
{
- ehciPipePointer->uframeSmask = (0x01 << ehciPipePointer->startUframe);
+ ehciPipePointer->uframeSmask = (0x01U << ehciPipePointer->startUframe);
}
else
{
- ehciPipePointer->uframeSmask = 0x00u;
- for (index = ehciPipePointer->startUframe; index < 8; index += ehciPipePointer->uframeInterval)
+ ehciPipePointer->uframeSmask = 0x00U;
+ for (index = ehciPipePointer->startUframe; index < 8U;
+ index += (uint8_t)ehciPipePointer->uframeInterval)
{
ehciPipePointer->uframeSmask |= (0x01U << index);
}
}
- ehciPipePointer->dataTime = timeData;
+ ehciPipePointer->dataTime = (uint16_t)timeData;
return kStatus_USB_Success;
}
}
else /* pipe is full-speed or low-speed */
{
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetHubThinkTime,
- &deviceInfo);
- timeData += (deviceInfo * 7 / (6 * 12));
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubNumber,
- &hubNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetHubThinkTime, &deviceInfo);
+ timeData += (deviceInfo * 7U / (6U * 12U));
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHSHubNumber, &hubNumber);
frameInterval = ehciPipePointer->pipeCommon.interval;
- SsCsNumber = 3; /* complete split number */
+ SsCsNumber = 3U; /* complete split number */
/* compute start-split and complete-split bandwidth */
if (ehciPipePointer->pipeCommon.direction == USB_OUT)
{
- timeStartSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT,
- ehciPipePointer->pipeCommon.maxPacketSize) +
- USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT, 1);
- timeCompleteSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT, 0);
+ timeStartSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT,
+ ehciPipePointer->pipeCommon.maxPacketSize);
+ timeStartSplit +=
+ (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT, 1U);
+ timeCompleteSplit =
+ (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_OUT, 0U);
}
else
{
- timeStartSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN, 1);
- timeCompleteSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN,
- ehciPipePointer->pipeCommon.maxPacketSize) +
- USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN, 0);
+ timeStartSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN, 1U);
+ timeCompleteSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN,
+ ehciPipePointer->pipeCommon.maxPacketSize);
+ timeCompleteSplit +=
+ (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_INTERRUPT, USB_IN, 0U);
}
/* note: bandwidth must put in one frame */
- for (uframeIntervalIndex = 0; uframeIntervalIndex <= 4; ++uframeIntervalIndex) /* uframe interval */
+ for (uframeIntervalIndex = 0U; uframeIntervalIndex <= 4U; ++uframeIntervalIndex) /* uframe interval */
{
- for (frameIntervalIndex = 0; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */
+ for (frameIntervalIndex = 0U; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */
{
- allocateOk = 1;
+ allocateOk = 1U;
for (frameIndex = frameIntervalIndex; frameIndex < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE;
frameIndex += frameInterval) /* check all the frames */
{
/* allocate data bandwidth */
USB_HostBandwidthHsHostComputeCurrentFsls(ehciInstance, hubNumber, frameIndex, frameTimes);
- index = uframeIntervalIndex + 1;
- for (; index <= (uframeIntervalIndex + 3); ++index) /* data bandwidth number is 3.
+ index = (uint8_t)(uframeIntervalIndex + 1U);
+ for (; index <= (uframeIntervalIndex + 3U); ++index) /* data bandwidth number is 3.
uframeIntervalIndex don't exceed 4, so
index cannot exceed 7 */
{
@@ -1639,60 +1602,61 @@ static usb_status_t USB_HostBandwidthHsHostAllocateInterrupt(usb_host_ehci_insta
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
USB_HostBandwidthHsHostComputeCurrentHsAll(ehciInstance, frameIndex, frameTimes);
/* allocate start_split bandwidth */
- if (frameTimes[uframeIntervalIndex] + timeStartSplit > s_SlotMaxBandwidth[uframeIntervalIndex])
+ if (frameTimes[uframeIntervalIndex] + timeStartSplit >
+ s_SlotMaxBandwidthHs[uframeIntervalIndex])
{
- allocateOk = 0;
+ allocateOk = 0U;
}
- if (allocateOk)
+ if (0U != allocateOk)
{
/* allocate complete_split bandwidth */
- index = uframeIntervalIndex + 2;
+ index = (uint8_t)uframeIntervalIndex + 2U;
/* complete-split number is normal 3. When uframeIntervalIndex is 4, complete-split number
* is 2. */
- for (; (index <= (uframeIntervalIndex + 1 + SsCsNumber)) && (index < 8); ++index)
+ for (; (index <= (uframeIntervalIndex + 1U + SsCsNumber)) && (index < 8U); ++index)
{
- if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidth[index])
+ if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidthHs[index])
{
- allocateOk = 0;
+ allocateOk = 0U;
break;
}
}
}
}
- if (!allocateOk)
+ if (0U == allocateOk)
{
break; /* allocate fail */
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
break;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
break;
}
}
- if (allocateOk)
+ if (0U != allocateOk)
{
- ehciPipePointer->startFrame = frameIntervalIndex;
- ehciPipePointer->startUframe = uframeIntervalIndex;
- ehciPipePointer->uframeSmask = (0x01 << ehciPipePointer->startUframe);
- ehciPipePointer->uframeCmask = 0;
- index = uframeIntervalIndex + 2;
- for (; (index <= (uframeIntervalIndex + 1 + SsCsNumber)) && (index < 8); ++index)
+ ehciPipePointer->startFrame = frameIntervalIndex;
+ ehciPipePointer->startUframe = (uint8_t)uframeIntervalIndex;
+ ehciPipePointer->uframeSmask = (0x01u << ehciPipePointer->startUframe);
+ ehciPipePointer->uframeCmask = 0u;
+ index = (uint8_t)uframeIntervalIndex + 2u;
+ for (; (index <= (uframeIntervalIndex + 1u + SsCsNumber)) && (index < 8u); ++index)
{
- ehciPipePointer->uframeCmask = (uint32_t)ehciPipePointer->uframeCmask | (uint32_t)(0x01 << index);
+ ehciPipePointer->uframeCmask = ehciPipePointer->uframeCmask | (0x01U << index);
}
- ehciPipePointer->dataTime = timeData;
- ehciPipePointer->startSplitTime = timeStartSplit;
+ ehciPipePointer->dataTime = (uint16_t)timeData;
+ ehciPipePointer->startSplitTime = timeStartSplit;
ehciPipePointer->completeSplitTime = timeCompleteSplit;
return kStatus_USB_Success;
@@ -1706,17 +1670,18 @@ static usb_status_t USB_HostBandwidthFslsHostAllocate(usb_host_ehci_instance_t *
usb_host_ehci_pipe_t *ehciPipePointer)
{
uint32_t FslsTime = 0;
- uint32_t speed = 0;
+ uint32_t speed = 0;
uint16_t uframeIntervalIndex;
uint16_t frameIndex;
uint16_t frameInterval;
uint16_t frameTime;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetHubThinkTime,
- &FslsTime);
- FslsTime += (FslsTime * 7 / (6 * 12));
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, &speed);
- FslsTime = FslsTime + USB_HostBandwidthComputeTime(speed, ehciPipePointer->pipeCommon.pipeType,
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetHubThinkTime, &FslsTime);
+ FslsTime += (FslsTime * 7U / (6U * 12U));
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
+ FslsTime = FslsTime + USB_HostBandwidthComputeTime((uint8_t)speed, ehciPipePointer->pipeCommon.pipeType,
ehciPipePointer->pipeCommon.direction,
ehciPipePointer->pipeCommon.maxPacketSize);
@@ -1740,11 +1705,11 @@ static usb_status_t USB_HostBandwidthFslsHostAllocate(usb_host_ehci_instance_t *
}
if (uframeIntervalIndex < ehciPipePointer->uframeInterval)
{
- ehciPipePointer->startFrame = (uframeIntervalIndex >> 3);
- ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007);
+ ehciPipePointer->startFrame = (uframeIntervalIndex >> 3);
+ ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U);
ehciPipePointer->uframeSmask = 0; /* useless */
ehciPipePointer->uframeCmask = 0;
- ehciPipePointer->dataTime = FslsTime;
+ ehciPipePointer->dataTime = (uint16_t)FslsTime;
return kStatus_USB_Success;
}
@@ -1754,46 +1719,46 @@ static usb_status_t USB_HostBandwidthFslsHostAllocate(usb_host_ehci_instance_t *
static uint8_t USB_HostEhciGet2PowerValue(uint8_t value)
{
- if ((value == 0) || (value == 1))
+ if ((value == 0U) || (value == 1U))
{
return value;
}
- if (value & 0xf0)
+ if (0U != (value & 0xf0U))
{
- if (value & 0x80)
+ if (0U != (value & 0x80U))
{
- return 128;
+ return 128U;
}
- else if (value & 0x40)
+ else if (0U != (value & 0x40U))
{
- return 64;
+ return 64U;
}
- else if (value & 0x20)
+ else if (0U != (value & 0x20U))
{
- return 32;
+ return 32U;
}
else
{
- return 16;
+ return 16U;
}
}
else
{
- if (value & 0x08)
+ if (0U != (value & 0x08U))
{
- return 8;
+ return 8U;
}
- else if (value & 0x04)
+ else if (0U != (value & 0x04U))
{
- return 4;
+ return 4U;
}
- else if (value & 0x02)
+ else if (0U != (value & 0x02U))
{
- return 2;
+ return 2U;
}
else
{
- return 1;
+ return 1U;
}
}
}
@@ -1801,8 +1766,9 @@ static uint8_t USB_HostEhciGet2PowerValue(uint8_t value)
static void USB_HostEhciZeroMem(uint32_t *buffer, uint32_t length)
{
/* note: the zero unit is uint32_t */
- while (length--)
+ while (0U != length)
{
+ length--;
*buffer = 0;
buffer++;
}
@@ -1811,24 +1777,24 @@ static void USB_HostEhciZeroMem(uint32_t *buffer, uint32_t length)
static void USB_HostEhciDelay(USBHS_Type *ehciIpBase, uint32_t ms)
{
/* note: the max delay time cannot exceed half of max value (0x4000) */
- int32_t sofStart;
- int32_t SofEnd;
+ uint32_t sofStart;
+ uint32_t SofEnd;
uint32_t distance;
- sofStart = (int32_t)(ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
+ sofStart = (ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
do
{
- SofEnd = (int32_t)(ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
- distance = (uint32_t)(SofEnd - sofStart + EHCI_MAX_UFRAME_VALUE + 1);
- } while ((distance & EHCI_MAX_UFRAME_VALUE) < (ms * 8)); /* compute the distance between sofStart and SofEnd */
+ SofEnd = (ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
+ distance = (SofEnd + EHCI_MAX_UFRAME_VALUE + 1U - sofStart);
+ } while ((distance & EHCI_MAX_UFRAME_VALUE) < (ms * 8U)); /* compute the distance between sofStart and SofEnd */
}
-static void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance)
+void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance)
{
uint32_t stateSync;
- if (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
+ if (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
{
/* the status must be same when change USBCMD->ASE */
do
@@ -1839,7 +1805,7 @@ static void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance)
ehciInstance->ehciIpBase->ASYNCLISTADDR = (uint32_t)(ehciInstance->shedFirstQh);
ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_ASE_MASK;
- while (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
+ while (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
{
}
}
@@ -1857,16 +1823,16 @@ static void USB_HostEhciStopAsync(usb_host_ehci_instance_t *ehciInstance)
} while ((stateSync == USBHS_USBSTS_AS_MASK) || (stateSync == USBHS_USBCMD_ASE_MASK));
ehciInstance->ehciIpBase->USBCMD &= (uint32_t)(~(uint32_t)USBHS_USBCMD_ASE_MASK); /* disable async schedule */
- while (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)
+ while (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
{
}
}
-static void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance)
+void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance)
{
uint32_t stateSync;
- if (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK))
+ if (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK))
{
/* the status must be same when change USBCMD->PSE */
do
@@ -1875,11 +1841,11 @@ static void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance)
(ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_PSE_MASK));
} while ((stateSync == USBHS_USBSTS_PS_MASK) || (stateSync == USBHS_USBCMD_PSE_MASK));
ehciInstance->ehciIpBase->PERIODICLISTBASE = (uint32_t)(ehciInstance->ehciFrameList);
- if (!(ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_PSE_MASK))
+ if (0U == (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_PSE_MASK))
{
ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_PSE_MASK; /* start periodic schedule */
}
- while (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK))
+ while (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK))
{
}
}
@@ -1898,7 +1864,7 @@ static void USB_HostEhciStopPeriodic(usb_host_ehci_instance_t *ehciInstance)
} while ((stateSync == USBHS_USBSTS_PS_MASK) || (stateSync == USBHS_USBCMD_PSE_MASK));
ehciInstance->ehciIpBase->USBCMD &= (~USBHS_USBCMD_PSE_MASK); /* stop periodic schedule */
- while (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)
+ while (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK))
{
}
}
@@ -1908,7 +1874,7 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
usb_host_transfer_t *transfer)
{
volatile usb_host_ehci_qh_t *vltQhPointer;
- usb_host_ehci_qtd_t *qtdPointer = NULL;
+ usb_host_ehci_qtd_t *qtdPointer = NULL;
usb_host_ehci_qtd_t *BaseQtdPointer = NULL;
volatile uint32_t *entryPointer;
uint32_t qtdNumber;
@@ -1921,19 +1887,23 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_CONTROL)
{
/* assume setup data don't exceed one qtd data size, one qtd can transfer least 16k data */
- if (transfer->transferLength == 0)
+ if (transfer->transferLength == 0U)
{
- qtdNumber = 2;
+ qtdNumber = 2U;
}
else
{
- qtdNumber = 3;
+ qtdNumber = 3U;
}
}
else
{
- qtdNumber =
- (((transfer->transferLength) & 0xFFFFC000U) >> 14) + (((transfer->transferLength) & 0x00003FFF) ? 1 : 0);
+ qtdNumber = (((transfer->transferLength) & 0xFFFFC000U) >> 14U) +
+ (0U != ((transfer->transferLength) & 0x00003FFFU) ? 1U : 0U);
+ if (0U == qtdNumber)
+ {
+ qtdNumber = 1U;
+ }
}
vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
@@ -1941,20 +1911,21 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
USB_HostEhciLock();
if (qtdNumber <= ehciInstance->ehciQtdNumber)
{
- ehciInstance->ehciQtdNumber -= qtdNumber;
+ ehciInstance->ehciQtdNumber -= (uint8_t)qtdNumber;
BaseQtdPointer = ehciInstance->ehciQtdHead;
- qtdPointer = NULL;
+ qtdPointer = NULL;
do
{
if (qtdPointer != NULL)
{
qtdPointer->nextQtdPointer = (uint32_t)ehciInstance->ehciQtdHead;
}
- qtdPointer = ehciInstance->ehciQtdHead;
- ehciInstance->ehciQtdHead = (usb_host_ehci_qtd_t *)qtdPointer->nextQtdPointer;
+ qtdPointer = ehciInstance->ehciQtdHead;
+ ehciInstance->ehciQtdHead = (usb_host_ehci_qtd_t *)qtdPointer->nextQtdPointer;
qtdPointer->nextQtdPointer = 0;
- } while (--qtdNumber);
- if (ehciInstance->ehciQtdNumber == 0)
+ --qtdNumber;
+ } while (0U != qtdNumber);
+ if (ehciInstance->ehciQtdNumber == 0U)
{
ehciInstance->ehciQtdTail = NULL;
}
@@ -1970,34 +1941,34 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_CONTROL)
{
/* setup transaction qtd */
- qtdPointer = BaseQtdPointer;
+ qtdPointer = BaseQtdPointer;
qtdPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
/* dt: need set; ioc: 0; C_Page: 0; PID Code: SETUP; Status: Active */
- qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0;
+ qtdPointer->transferResults[1] = 0U;
qtdPointer->transferResults[0] =
- ((0x00000000 << EHCI_HOST_QTD_DT_SHIFT) | (8 << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
+ ((0x00000000UL << EHCI_HOST_QTD_DT_SHIFT) | (8UL << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
(EHCI_HOST_PID_SETUP << EHCI_HOST_QTD_PID_CODE_SHIFT) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
- dataAddress = ((uint32_t)transfer->setupPacket);
+ dataAddress = ((uint32_t)transfer->setupPacket);
qtdPointer->transferResults[1] = dataAddress; /* current offset is set too */
/* set buffer pointer no matter data length */
- for (index = 0; index < 4; ++index)
+ for (index = 0; index < 4U; ++index)
{
- qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 0xFFFFF000U);
+ qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U);
}
/* data transaction qtd */
dataLength = transfer->transferLength;
- if (dataLength != 0)
+ if (dataLength != 0U)
{
qtdPointer = (usb_host_ehci_qtd_t *)(qtdPointer->nextQtdPointer);
qtdPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
/* dt: need set; ioc: 0; C_Page: 0; PID Code: IN/OUT; Status: Active */
- qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0;
+ qtdPointer->transferResults[1] = 0U;
if (transfer->direction == USB_OUT)
{
qtdPointer->transferResults[0] =
- ((0x00000001U << EHCI_HOST_QTD_DT_SHIFT) | (dataLength << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
+ ((0x00000001UL << EHCI_HOST_QTD_DT_SHIFT) | (dataLength << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) |
(EHCI_HOST_PID_OUT << EHCI_HOST_QTD_PID_CODE_SHIFT) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
}
else
@@ -2007,24 +1978,24 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
(EHCI_HOST_PID_IN << EHCI_HOST_QTD_PID_CODE_SHIFT) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
}
- dataAddress = (uint32_t)transfer->transferBuffer;
+ dataAddress = (uint32_t)transfer->transferBuffer;
qtdPointer->transferResults[1] = dataAddress; /* current offset is set too */
/* set buffer pointer no matter data length */
- for (index = 0; index < 4; ++index)
+ for (index = 0; index < 4U; ++index)
{
- qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 0xFFFFF000U);
+ qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U);
}
}
/* status transaction qtd */
- qtdPointer = (usb_host_ehci_qtd_t *)(qtdPointer->nextQtdPointer);
+ qtdPointer = (usb_host_ehci_qtd_t *)(qtdPointer->nextQtdPointer);
qtdPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
/* dt: dont care; ioc: 1; C_Page: 0; PID Code: IN/OUT; Status: Active */
- qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0;
- if ((dataLength == 0) || (transfer->direction == USB_OUT))
+ qtdPointer->transferResults[1] = 0;
+ if ((dataLength == 0U) || (transfer->direction == USB_OUT))
{
qtdPointer->transferResults[0] =
- ((0x00000001U << EHCI_HOST_QTD_DT_SHIFT) | (EHCI_HOST_PID_IN << EHCI_HOST_QTD_PID_CODE_SHIFT) |
+ ((0x00000001UL << EHCI_HOST_QTD_DT_SHIFT) | (EHCI_HOST_PID_IN << EHCI_HOST_QTD_PID_CODE_SHIFT) |
(EHCI_HOST_QTD_IOC_MASK) | (EHCI_HOST_QTD_STATUS_ACTIVE_MASK));
}
else
@@ -2037,12 +2008,11 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
}
else
{
- dataLength = transfer->transferLength;
dataAddress = (uint32_t)transfer->transferBuffer;
- qtdPointer = BaseQtdPointer;
- while (1)
+ qtdPointer = BaseQtdPointer;
+ while (1U == 1U)
{
- endAddress = dataAddress + (16 * 1024);
+ endAddress = dataAddress + (16U * 1024U);
if (endAddress > (uint32_t)(transfer->transferBuffer + transfer->transferLength))
{
endAddress = (uint32_t)(transfer->transferBuffer + transfer->transferLength);
@@ -2050,7 +2020,7 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
qtdPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
/* dt: set; ioc: 0; C_Page: 0; PID Code: IN/OUT; Status: Active */
- qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0;
+ qtdPointer->transferResults[1] = 0U;
if (transfer->direction == USB_OUT)
{
qtdPointer->transferResults[0] =
@@ -2069,13 +2039,13 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
}
qtdPointer->transferResults[1] = dataAddress; /* current offset is set too */
/* set buffer pointer no matter data length */
- for (index = 0; index < 4; ++index)
+ for (index = 0; index < 4U; ++index)
{
- qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 0xFFFFF000U);
+ qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U);
}
dataAddress = endAddress; /* for next qtd */
- if (qtdPointer->nextQtdPointer == 0)
+ if (qtdPointer->nextQtdPointer == 0U)
{
break;
}
@@ -2093,24 +2063,25 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst
transfer->next = NULL;
if (vltQhPointer->ehciTransferHead == NULL)
{
- transfer->next = NULL;
- vltQhPointer->ehciTransferHead = vltQhPointer->ehciTransferTail = transfer;
+ transfer->next = NULL;
+ vltQhPointer->ehciTransferTail = transfer;
+ vltQhPointer->ehciTransferHead = transfer;
}
else
{
- transfer->next = NULL;
+ transfer->next = NULL;
vltQhPointer->ehciTransferTail->next = transfer;
- vltQhPointer->ehciTransferTail = transfer;
+ vltQhPointer->ehciTransferTail = transfer;
}
USB_HostEhciLock();
/* link qtd to qh (link to end) */
entryPointer = &(vltQhPointer->nextQtdPointer);
- dataAddress = *entryPointer; /* dataAddress variable means entry value here */
- while ((dataAddress) && (!(dataAddress & EHCI_HOST_T_INVALID_VALUE)))
+ dataAddress = *entryPointer; /* dataAddress variable means entry value here */
+ while ((0U != dataAddress) && (0U == (dataAddress & EHCI_HOST_T_INVALID_VALUE)))
{
entryPointer = (volatile uint32_t *)dataAddress;
- dataAddress = *entryPointer;
+ dataAddress = *entryPointer;
}
*entryPointer = (uint32_t)BaseQtdPointer;
USB_HostEhciUnlock();
@@ -2126,7 +2097,7 @@ static uint32_t USB_HostEhciQtdListRelease(usb_host_ehci_instance_t *ehciInstanc
uint32_t length = 0;
usb_host_ehci_qtd_t *qtdPointer;
- ehciQtdEnd->nextQtdPointer = 0;
+ ehciQtdEnd->nextQtdPointer = 0U;
/* compute remaining length */
qtdPointer = ehciQtdStart;
@@ -2141,7 +2112,7 @@ static uint32_t USB_HostEhciQtdListRelease(usb_host_ehci_instance_t *ehciInstanc
/* put releasing qtd to idle qtd list */
USB_HostEhciLock();
- if (ehciInstance->ehciQtdNumber == 0)
+ if (ehciInstance->ehciQtdNumber == 0U)
{
ehciInstance->ehciQtdHead = ehciQtdStart;
ehciInstance->ehciQtdTail = ehciQtdEnd;
@@ -2149,7 +2120,7 @@ static uint32_t USB_HostEhciQtdListRelease(usb_host_ehci_instance_t *ehciInstanc
else
{
ehciInstance->ehciQtdTail->nextQtdPointer = (uint32_t)ehciQtdStart;
- ehciInstance->ehciQtdTail = ehciQtdEnd;
+ ehciInstance->ehciQtdTail = ehciQtdEnd;
}
while (ehciQtdStart != ehciQtdEnd)
@@ -2169,37 +2140,41 @@ static usb_status_t USB_HostEhciQhQtdListDeinit(usb_host_ehci_instance_t *ehciIn
volatile usb_host_ehci_qh_t *vltQhPointer;
usb_host_transfer_t *transfer;
usb_host_transfer_t *nextTransfer;
- uint8_t needStop = 0;
+ uint32_t currentQtdPointer;
+ uint8_t needStop = 0U;
vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
USB_HostEhciLock(); /* this API is called from APP, the host task may occupy to access the same resource */
/* remove qtd from qh */
- if ((!((uint32_t)vltQhPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE)) ||
- (!((uint32_t)vltQhPointer->currentQtdPointer & EHCI_HOST_T_INVALID_VALUE)))
+ /*for misra 13.5*/
+ currentQtdPointer = vltQhPointer->currentQtdPointer;
+ if ((0U == ((uint32_t)vltQhPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE)) ||
+ (0U == ((uint32_t)currentQtdPointer & EHCI_HOST_T_INVALID_VALUE)))
{
/* need stop async schedule */
- if ((!(vltQhPointer->horizontalLinkPointer & EHCI_HOST_T_INVALID_VALUE)) &&
+ if ((0U == (vltQhPointer->horizontalLinkPointer & EHCI_HOST_T_INVALID_VALUE)) &&
(ehciPipePointer->pipeCommon.pipeType != USB_ENDPOINT_INTERRUPT))
{
- needStop = 1;
+ needStop = 1U;
}
- if (needStop)
+ if (0U != needStop)
{
USB_HostEhciStopAsync(ehciInstance);
}
vltQhPointer->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE; /* invalid current qtd */
- vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE; /* invalid next qtd */
+ vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE; /* invalid next qtd */
vltQhPointer->transferOverlayResults[0] &= (~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */
- if (needStop)
+ if (0U != needStop)
{
USB_HostEhciStartAsync(ehciInstance);
}
}
/* remove transfer from the QH transfer list */
- transfer = vltQhPointer->ehciTransferHead;
- vltQhPointer->ehciTransferHead = vltQhPointer->ehciTransferTail = NULL;
+ transfer = vltQhPointer->ehciTransferHead;
+ vltQhPointer->ehciTransferTail = NULL;
+ vltQhPointer->ehciTransferHead = NULL;
USB_HostEhciUnlock();
/* release qtd and transfer callback*/
@@ -2210,8 +2185,9 @@ static usb_status_t USB_HostEhciQhQtdListDeinit(usb_host_ehci_instance_t *ehciIn
USB_HostEhciQtdListRelease(ehciInstance, (usb_host_ehci_qtd_t *)(transfer->union1.unitHead),
(usb_host_ehci_qtd_t *)(transfer->union2.unitTail));
transfer->transferSofar = (transfer->transferLength < transfer->transferSofar) ?
- 0 :
+ 0U :
(transfer->transferLength - transfer->transferSofar);
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel);
transfer = nextTransfer;
}
@@ -2233,13 +2209,14 @@ static usb_status_t USB_HostEhciTransferQtdListDeinit(usb_host_ehci_instance_t *
USB_HostEhciLock(); /* this API is called from APP, the host task may occupy to access the same resource */
/* remove qtd from qh */
- qhNextQtdValue = (uint32_t)vltQhPointer->currentQtdPointer;
+ qhNextQtdValue = (uint32_t)vltQhPointer->currentQtdPointer;
qtdPointerEntry = *((uint32_t *)qhNextQtdValue + 2); /* note: qtdPointerEntry means qtd status */
- if ((qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE) || (!(qtdPointerEntry & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)))
+ if ((0U != (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)) ||
+ (0U == (qtdPointerEntry & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)))
{
qhNextQtdValue = (uint32_t)vltQhPointer->nextQtdPointer;
}
- if (!(qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)) /* there is pending qtd in the qh */
+ if (0U == (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)) /* there is pending qtd in the qh */
{
/* this qh don't schedule temporarily */
if (ehciPipePointer->pipeCommon.pipeType != USB_ENDPOINT_INTERRUPT)
@@ -2255,11 +2232,11 @@ static usb_status_t USB_HostEhciTransferQtdListDeinit(usb_host_ehci_instance_t *
/* remove qtd from qh one by one */
qtdPointerEntry = transfer->union1.unitHead;
- while (1)
+ while (1U == 1U)
{
/* search qh's qtd list for qtdPointerEntry */
searchQtdEntryPointer = &qhNextQtdValue;
- while (!((*searchQtdEntryPointer) & EHCI_HOST_T_INVALID_VALUE))
+ while (0U == ((*searchQtdEntryPointer) & EHCI_HOST_T_INVALID_VALUE))
{
if ((*searchQtdEntryPointer) == qtdPointerEntry)
{
@@ -2306,13 +2283,15 @@ static usb_status_t USB_HostEhciTransferQtdListDeinit(usb_host_ehci_instance_t *
transfer->transferSofar =
USB_HostEhciQtdListRelease(ehciInstance, (usb_host_ehci_qtd_t *)(transfer->union1.unitHead),
(usb_host_ehci_qtd_t *)(transfer->union2.unitTail));
- transfer->transferSofar =
- (transfer->transferLength < transfer->transferSofar) ? 0 : (transfer->transferLength - transfer->transferSofar);
+ transfer->transferSofar = (transfer->transferLength < transfer->transferSofar) ?
+ 0U :
+ (transfer->transferLength - transfer->transferSofar);
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel);
/* start this qh schedule */
vltQhPointer->transferOverlayResults[0] &= (~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */
- if ((qhNextQtdValue != 0) && (!(qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)))
+ if ((qhNextQtdValue != 0U) && (0U == (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)))
{
vltQhPointer->nextQtdPointer = qhNextQtdValue;
}
@@ -2323,9 +2302,14 @@ static usb_status_t USB_HostEhciTransferQtdListDeinit(usb_host_ehci_instance_t *
static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, usb_host_ehci_pipe_t *ehciPipePointer)
{
usb_host_ehci_qh_t *qhPointer = NULL;
- uint32_t address, speed, portNumber, hubNumber;
- uint32_t controlBits1 = 0;
- uint32_t controlBits2 = 0;
+ uint32_t address = 0;
+ uint32_t speed = 0;
+ uint32_t portNumber = 0;
+ uint32_t hubNumber = 0;
+ ;
+ uint32_t controlBits1 = 0U;
+ uint32_t controlBits2 = 0U;
+
/* get qh */
USB_HostEhciLock();
if (ehciInstance->ehciQhList != NULL)
@@ -2345,26 +2329,27 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u
ehciPipePointer->ehciQh = (void *)qhPointer;
/* initialize qh */
- USB_HostEhciZeroMem((uint32_t *)qhPointer, sizeof(usb_host_ehci_qh_t) / 4);
- qhPointer->horizontalLinkPointer = EHCI_HOST_T_INVALID_VALUE;
- qhPointer->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE;
- qhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
+ USB_HostEhciZeroMem((void *)qhPointer, sizeof(usb_host_ehci_qh_t) / 4U);
+ qhPointer->horizontalLinkPointer = EHCI_HOST_T_INVALID_VALUE;
+ qhPointer->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE;
+ qhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
qhPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
- qhPointer->ehciPipePointer = ehciPipePointer;
- qhPointer->timeOutLabel = 0;
- qhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, &speed);
+ qhPointer->ehciPipePointer = ehciPipePointer;
+ qhPointer->timeOutLabel = 0;
+ qhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
/* initialize staticEndpointStates[0] */
if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_INTERRUPT)
{
/* Software should set the RL field to zero if the queue head is an interrupt endpoint. */
- controlBits1 |= ((0U << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK);
+ controlBits1 |= ((0UL << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK);
}
else
{
- if (ehciPipePointer->pipeCommon.nakCount >= 16)
+ if (ehciPipePointer->pipeCommon.nakCount >= 16U)
{
- controlBits1 |= ((15U << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK);
+ controlBits1 |= ((15UL << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK);
}
else
{
@@ -2376,15 +2361,15 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u
{
if (speed != USB_SPEED_HIGH)
{
- controlBits1 |= (1 << EHCI_HOST_QH_C_SHIFT);
+ controlBits1 |= (1UL << EHCI_HOST_QH_C_SHIFT);
}
- controlBits1 |= (1 << EHCI_HOST_QH_DTC_SHIFT);
+ controlBits1 |= (1UL << EHCI_HOST_QH_DTC_SHIFT);
}
controlBits1 |= ((uint32_t)ehciPipePointer->pipeCommon.maxPacketSize << EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT);
controlBits1 |= (speed << EHCI_HOST_QH_EPS_SHIFT);
controlBits1 |= ((uint32_t)ehciPipePointer->pipeCommon.endpointAddress << EHCI_HOST_QH_ENDPT_SHIFT);
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress,
- &address);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceAddress, &address);
controlBits1 |= (address << EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT);
qhPointer->staticEndpointStates[0] = controlBits1;
if (speed == USB_SPEED_HIGH)
@@ -2393,22 +2378,22 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u
}
else
{
- controlBits2 |= (0x00000001U << EHCI_HOST_QH_MULT_SHIFT);
+ controlBits2 |= (0x00000001UL << EHCI_HOST_QH_MULT_SHIFT);
}
/*initialize staticEndpointStates[1] */
if (speed != USB_SPEED_HIGH)
{
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubNumber,
- &hubNumber);
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubPort,
- &portNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHSHubNumber, &hubNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHSHubPort, &portNumber);
}
else
{
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHubNumber,
- &hubNumber);
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDevicePortNumber,
- &portNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHubNumber, &hubNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDevicePortNumber, &portNumber);
}
controlBits2 |= (portNumber << EHCI_HOST_QH_PORT_NUMBER_SHIFT);
controlBits2 |= (hubNumber << EHCI_HOST_QH_HUB_ADDR_SHIFT);
@@ -2425,12 +2410,12 @@ static usb_status_t USB_HostEhciQhDeinit(usb_host_ehci_instance_t *ehciInstance,
qhPointer = (usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
/* de-initialize qtd from qh */
- USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer);
+ (void)USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer);
/* release QH */
USB_HostEhciLock();
qhPointer->horizontalLinkPointer = (uint32_t)ehciInstance->ehciQhList;
- ehciInstance->ehciQhList = qhPointer;
+ ehciInstance->ehciQhList = qhPointer;
USB_HostEhciUnlock();
return kStatus_USB_Success;
@@ -2443,17 +2428,19 @@ static void USB_HostEhciAddQhToFrame(usb_host_ehci_instance_t *ehciInstance,
{
volatile uint32_t *frameEntryPointer;
uint32_t frameEntryValue;
+ void *temp;
/* search for the inserting point by interval */
- frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)ehciInstance->ehciFrameList)[framePos]);
- while (frameEntryPointer)
+ temp = (void *)ehciInstance->ehciFrameList;
+ frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)temp)[framePos]);
+ while (NULL != frameEntryPointer)
{
frameEntryValue = *frameEntryPointer;
- if (frameEntryValue & EHCI_HOST_T_INVALID_VALUE)
+ if (0U != (frameEntryValue & EHCI_HOST_T_INVALID_VALUE))
{
/* insert into the end */
*((uint32_t *)entryPointerValue) = EHCI_HOST_T_INVALID_VALUE;
- *frameEntryPointer = (entryPointerValue | EHCI_HOST_POINTER_TYPE_QH);
+ *frameEntryPointer = (entryPointerValue | EHCI_HOST_POINTER_TYPE_QH);
break;
}
@@ -2467,7 +2454,7 @@ static void USB_HostEhciAddQhToFrame(usb_host_ehci_instance_t *ehciInstance,
{
/* insert into this point */
*((uint32_t *)entryPointerValue) = frameEntryValue;
- *frameEntryPointer = (entryPointerValue | EHCI_HOST_POINTER_TYPE_QH);
+ *frameEntryPointer = (entryPointerValue | EHCI_HOST_POINTER_TYPE_QH);
return;
}
else
@@ -2483,14 +2470,15 @@ static void USB_HostEhciRemoveFromFrame(usb_host_ehci_instance_t *ehciInstance,
{
volatile uint32_t *frameEntryPointer;
uint32_t frameEntryValue;
-
+ void *temp;
/* search for the qh/itd/sitd entry */
- frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)ehciInstance->ehciFrameList)[framePos]);
+ temp = (void *)ehciInstance->ehciFrameList;
+ frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)temp)[framePos]);
- while (frameEntryPointer)
+ while (NULL != frameEntryPointer)
{
frameEntryValue = *frameEntryPointer;
- if (frameEntryValue & EHCI_HOST_T_INVALID_VALUE)
+ if (0U != (frameEntryValue & EHCI_HOST_T_INVALID_VALUE))
{
return;
}
@@ -2517,53 +2505,71 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance,
usb_host_ehci_sitd_t *sitdPointer;
uint32_t distance;
uint32_t frameInterval;
- int32_t shouldLinkFrame;
- int32_t currentFrame;
+ uint32_t shouldLinkFrame;
+ uint32_t currentFrame;
+ void *temp;
- frameInterval = (ehciPipePointer->uframeInterval >> 3);
+ frameInterval = ((uint32_t)ehciPipePointer->uframeInterval >> 3U);
- if (isoPointer->lastLinkFrame == 0xFFFF) /* first link */
+ if (isoPointer->lastLinkFrame == 0xFFFFU) /* first link */
{
- currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE) >> 3);
+ currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & USB_HOST_EHCI_MAX_MICRFRAME_VALUE) >> 3U);
currentFrame = ((uint32_t)(currentFrame + USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER) &
- (EHCI_MAX_UFRAME_VALUE >> 3)); /* add USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER */
+ (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U)); /* add USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER */
/* frame should align with interval */
- currentFrame -= ehciPipePointer->startFrame;
- currentFrame =
- ((uint32_t)(currentFrame + frameInterval - 1) & (~(frameInterval - 1))); /* frameInterval is power of 2 */
- currentFrame += ehciPipePointer->startFrame;
+ if (currentFrame <= ehciPipePointer->startFrame)
+ {
+ currentFrame = ehciPipePointer->startFrame;
+ }
+ else
+ {
+ currentFrame -= ehciPipePointer->startFrame;
+ currentFrame = ((currentFrame + frameInterval - 1U) & (~(frameInterval - 1U)));
+ currentFrame += ehciPipePointer->startFrame;
+ }
}
else
{
shouldLinkFrame = isoPointer->lastLinkFrame + frameInterval; /* continuous next should link frame */
- if (shouldLinkFrame > (int32_t)(EHCI_MAX_UFRAME_VALUE >> 3))
+ if (shouldLinkFrame > USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U)
{
- shouldLinkFrame = shouldLinkFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1);
+ shouldLinkFrame = shouldLinkFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U) + 1U);
}
- currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE) >> 3);
- distance = ((shouldLinkFrame - currentFrame + (EHCI_MAX_UFRAME_VALUE >> 3) + 1) &
- (EHCI_MAX_UFRAME_VALUE >> 3)); /* get the distance from shouldLinkFrame to currentFrame */
+ currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & USB_HOST_EHCI_MAX_MICRFRAME_VALUE) >> 3U);
+ distance =
+ ((shouldLinkFrame + (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U) + 1U - currentFrame) &
+ (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3)); /* get the distance from shouldLinkFrame to currentFrame */
/* shouldLinkFrame has add frameInterval, think about the align with interval, so here add (frameInterval *
* 2) */
- if ((distance <= (USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER + frameInterval * 2)) && (distance > 0))
+ if ((distance <=
+ (USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER + frameInterval * USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER)) &&
+ (distance > 0U))
{
currentFrame = shouldLinkFrame;
}
else /* re-link */
{
currentFrame =
- ((uint32_t)(currentFrame + USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER) & (EHCI_MAX_UFRAME_VALUE >> 3));
- if (currentFrame > (int32_t)(EHCI_MAX_UFRAME_VALUE >> 3))
+ ((currentFrame + USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER) & (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3));
+
+ /*if (currentFrame > (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3))
{
- currentFrame = currentFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1);
- }
+ currentFrame = currentFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3) + 1U);
+ }*/
/* frame should align with interval */
- currentFrame -= ehciPipePointer->startFrame;
- currentFrame = ((uint32_t)(currentFrame + frameInterval - 1) & (~(frameInterval - 1)));
- currentFrame += ehciPipePointer->startFrame;
+ if (currentFrame <= ehciPipePointer->startFrame)
+ {
+ currentFrame = ehciPipePointer->startFrame;
+ }
+ else
+ {
+ currentFrame -= ehciPipePointer->startFrame;
+ currentFrame = ((currentFrame + frameInterval - 1U) & (~(frameInterval - 1U)));
+ currentFrame += ehciPipePointer->startFrame;
+ }
}
}
- if (currentFrame >= (int32_t)USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) /* frame turn around */
+ if (currentFrame >= USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) /* frame turn around */
{
shouldLinkFrame =
(currentFrame - USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE); /* shouldLinkFrame means inserted frame position */
@@ -2574,14 +2580,14 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance,
}
sitdPointer = (usb_host_ehci_sitd_t *)startEntryPointer;
- while (sitdPointer)
+ while (NULL != sitdPointer)
{
- sitdPointer->frameEntryIndex = shouldLinkFrame;
+ sitdPointer->frameEntryIndex = (uint16_t)shouldLinkFrame;
/* add to frame list head */
- sitdPointer->nextLinkPointer = ((uint32_t *)ehciInstance->ehciFrameList)[shouldLinkFrame];
- ((uint32_t *)ehciInstance->ehciFrameList)[shouldLinkFrame] =
- ((uint32_t)sitdPointer | EHCI_HOST_POINTER_TYPE_SITD);
- if (sitdPointer->nextSitdIndex == 0xFF) /* 0xFF is invalid value */
+ temp = (void *)ehciInstance->ehciFrameList;
+ sitdPointer->nextLinkPointer = ((uint32_t *)temp)[shouldLinkFrame];
+ ((uint32_t *)temp)[shouldLinkFrame] = ((uint32_t)sitdPointer | EHCI_HOST_POINTER_TYPE_SITD);
+ if (sitdPointer->nextSitdIndex == 0xFFU) /* 0xFF is invalid value */
{
break;
}
@@ -2589,17 +2595,17 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance,
shouldLinkFrame += frameInterval;
currentFrame += frameInterval;
- if (shouldLinkFrame >= (int32_t)USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE)
+ if (shouldLinkFrame >= USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE)
{
shouldLinkFrame = (shouldLinkFrame - USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE);
}
}
- if (currentFrame > (int32_t)(EHCI_MAX_UFRAME_VALUE >> 3))
+ if (currentFrame > (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3))
{
- currentFrame = currentFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1);
+ currentFrame = currentFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3) + 1U);
}
- isoPointer->lastLinkFrame = currentFrame; /* save the last link frame value */
+ isoPointer->lastLinkFrame = (uint16_t)currentFrame; /* save the last link frame value */
}
static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInstance,
@@ -2612,33 +2618,35 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst
uint32_t dataLength = 0;
uint32_t sitdLength = 0;
uint32_t dataBufferValue;
- uint32_t hubNumber;
- uint32_t portNumber;
- uint32_t address;
+ uint32_t hubNumber = 0U;
+ uint32_t portNumber = 0U;
+ uint32_t address = 0U;
uint32_t tmp;
- uint8_t index;
-
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress,
- &address);
+ uint32_t *temp;
+ uint32_t index;
+ int32_t tempIndex;
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceAddress, &address);
- sitdNumber = ((transfer->transferLength - 1 + (ehciPipePointer->pipeCommon.maxPacketSize)) /
+ sitdNumber = ((transfer->transferLength - 1U + (ehciPipePointer->pipeCommon.maxPacketSize)) /
(ehciPipePointer->pipeCommon.maxPacketSize));
/* get sitd array */
- tmp = ehciPipePointer - ehciInstance->ehciPipeIndexBase; /* pipe index */
/* USB_HostEhciLock(); */
if (ehciInstance->ehciSitdNumber >= sitdNumber)
{
- sitdPointer = ehciInstance->ehciSitdList;
+ sitdPointer = ehciInstance->ehciSitdList;
transfer->union1.unitHead = (uint32_t)sitdPointer;
- for (index = 1; index < sitdNumber; ++index)
+ for (index = 1U; index < sitdNumber; ++index)
{
- sitdPointer->nextSitdIndex =
- (((usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer) - ehciInstance->ehciSitdIndexBase);
- sitdPointer = (usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer;
+ /*misra 10.8*/
+ tempIndex = (((usb_host_ehci_sitd_t *)(sitdPointer->nextLinkPointer & 0xFFFFFFFEU)) -
+ ehciInstance->ehciSitdIndexBase);
+ sitdPointer->nextSitdIndex = (uint8_t)tempIndex;
+ sitdPointer = (usb_host_ehci_sitd_t *)(sitdPointer->nextLinkPointer & 0xFFFFFFFEU);
}
sitdPointer->nextSitdIndex = 0xFF;
- ehciInstance->ehciSitdList = (usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer;
- ehciInstance->ehciSitdNumber -= sitdNumber;
+ ehciInstance->ehciSitdList = (usb_host_ehci_sitd_t *)(sitdPointer->nextLinkPointer & 0xFFFFFFFEU);
+ ehciInstance->ehciSitdNumber -= (uint8_t)sitdNumber;
}
else
{
@@ -2648,15 +2656,16 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst
/* USB_HostEhciUnlock(); */
transfer->union2.unitTail = (uint32_t)sitdPointer;
/* initialize sitd array */
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHubNumber,
- &hubNumber);
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDevicePortNumber,
- &portNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceHubNumber, &hubNumber);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDevicePortNumber, &portNumber);
sitdPointer = (usb_host_ehci_sitd_t *)transfer->union1.unitHead;
- dataLength = transfer->transferLength;
- while (sitdNumber--)
+ dataLength = transfer->transferLength;
+ while (0U != sitdNumber)
{
- USB_HostEhciZeroMem((uint32_t *)sitdPointer, 7);
+ sitdNumber--;
+ USB_HostEhciZeroMem((void *)sitdPointer, 7);
sitdLength = dataLength;
if (sitdLength > ehciPipePointer->pipeCommon.maxPacketSize)
{
@@ -2665,7 +2674,7 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst
dataBufferValue = (uint32_t)(transfer->transferBuffer + (transfer->transferLength - dataLength));
dataLength -= sitdLength; /* update left data length */
sitdPointer->transferResults[1] = dataBufferValue;
- sitdPointer->transferResults[2] = ((dataBufferValue + 4 * 1024) & 0xFFFFF000U);
+ sitdPointer->transferResults[2] = ((dataBufferValue + 4U * 1024U) & 0xFFFFF000U);
sitdPointer->endpointStates[0] =
(((uint32_t)ehciPipePointer->pipeCommon.direction << EHCI_HOST_SITD_DIRECTION_SHIFT) |
(portNumber << EHCI_HOST_SITD_PORT_NUMBER_SHIFT) | (hubNumber << EHCI_HOST_SITD_HUB_ADDR_SHIFT) |
@@ -2679,14 +2688,14 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst
sitdPointer->endpointStates[1] = (((uint32_t)ehciPipePointer->uframeCmask << EHCI_HOST_SITD_CMASK_SHIFT) |
((uint32_t)ehciPipePointer->uframeSmask << EHCI_HOST_SITD_SMASK_SHIFT));
- tmp = (sitdLength + 187) / 188;
- if (tmp > 1)
+ tmp = (sitdLength + 187U) / 188U;
+ if (tmp > 1U)
{
- sitdPointer->transferResults[2] |= (0x01 << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */
+ sitdPointer->transferResults[2] |= (0x01U << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */
}
else
{
- sitdPointer->transferResults[2] |= (0x00 << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */
+ sitdPointer->transferResults[2] |= (0x00U << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */
}
sitdPointer->transferResults[2] |= (tmp << EHCI_HOST_SITD_TCOUNT_SHIFT); /* for iso split */
}
@@ -2696,26 +2705,29 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst
sitdPointer = (ehciInstance->ehciSitdIndexBase + sitdPointer->nextSitdIndex);
}
sitdPointer = (usb_host_ehci_sitd_t *)transfer->union2.unitTail;
- sitdPointer->transferResults[0] |= (1U << EHCI_HOST_SITD_IOC_SHIFT); /* last set IOC */
+ sitdPointer->transferResults[0] |= (1UL << EHCI_HOST_SITD_IOC_SHIFT); /* last set IOC */
/* link transfer to usb_host_ehci_iso_t transfer list */
isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh;
USB_HostEhciLock();
if (isoPointer->ehciTransferHead == NULL)
{
- transfer->next = NULL;
- isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = transfer;
+ transfer->next = NULL;
+ isoPointer->ehciTransferTail = transfer;
+ isoPointer->ehciTransferHead = transfer;
}
else
{
- transfer->next = NULL;
+ transfer->next = NULL;
isoPointer->ehciTransferTail->next = transfer;
- isoPointer->ehciTransferTail = transfer;
+ isoPointer->ehciTransferTail = transfer;
}
USB_HostEhciUnlock();
/* link itd to frame list (note: initialize frameEntryIndex)*/
- USB_HostEhciLinkSitd(ehciInstance, ehciPipePointer, (void *)transfer->union1.unitHead);
+ /*misra 11.6*/
+ temp = (uint32_t *)(transfer->union1.unitHead);
+ USB_HostEhciLinkSitd(ehciInstance, ehciPipePointer, (void *)temp);
return kStatus_USB_Success;
}
@@ -2725,9 +2737,9 @@ static uint32_t USB_HostEhciSitdArrayRelease(usb_host_ehci_instance_t *ehciInsta
usb_host_ehci_sitd_t *endSitdPointer)
{
usb_host_ehci_sitd_t *sitdPointer = startSitdPointer;
- uint32_t leftLength = 0;
+ uint32_t leftLength = 0;
/* remove itd from frame list */
- while (1)
+ while (1U == 1U)
{
/* record the transfer's result length */
leftLength +=
@@ -2737,8 +2749,9 @@ static uint32_t USB_HostEhciSitdArrayRelease(usb_host_ehci_instance_t *ehciInsta
/* release itd */
/* USB_HostEhciLock(); */
- sitdPointer->nextLinkPointer = (uint32_t)ehciInstance->ehciSitdList;
- ehciInstance->ehciSitdList = sitdPointer;
+ /*set next link pointer to invalid in case hardware access invalid sitd structure in special case*/
+ sitdPointer->nextLinkPointer = (((uint32_t)ehciInstance->ehciSitdList) | EHCI_HOST_T_INVALID_VALUE);
+ ehciInstance->ehciSitdList = sitdPointer;
ehciInstance->ehciSitdNumber++;
/* USB_HostEhciUnlock(); */
@@ -2762,8 +2775,9 @@ static usb_status_t USB_HostEhciSitdArrayDeinit(usb_host_ehci_instance_t *ehciIn
/* firstly remove the transfer (because host task may occupy to access the resource) */
USB_HostEhciLock();
- transfer = isoPointer->ehciTransferHead;
- isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = NULL;
+ transfer = isoPointer->ehciTransferHead;
+ isoPointer->ehciTransferTail = NULL;
+ isoPointer->ehciTransferHead = NULL;
USB_HostEhciUnlock();
while (transfer != NULL)
@@ -2774,7 +2788,7 @@ static usb_status_t USB_HostEhciSitdArrayDeinit(usb_host_ehci_instance_t *ehciIn
transfer->transferLength - USB_HostEhciSitdArrayRelease(ehciInstance,
(usb_host_ehci_sitd_t *)transfer->union1.unitHead,
(usb_host_ehci_sitd_t *)transfer->union2.unitTail);
- /* transfer callback */
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel);
/* next transfer */
transfer = nextTransfer;
@@ -2790,50 +2804,66 @@ static uint32_t USB_HostEhciGetItdLinkFrame(usb_host_ehci_instance_t *ehciInstan
uint16_t startUframe,
uint16_t uframeInterval)
{
- int32_t shouldLinkUframe;
- int32_t currentUframe;
- int32_t distance;
+ uint32_t shouldLinkUframe;
+ uint32_t currentUframe;
+ uint32_t distance;
- if (lastLinkUframe != 0xFFFF)
+ if (lastLinkUframe != 0xFFFFU)
{
shouldLinkUframe = lastLinkUframe + uframeInterval;
- if (shouldLinkUframe > (int32_t)EHCI_MAX_UFRAME_VALUE)
+ if (shouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE)
{
- shouldLinkUframe = shouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1);
+ shouldLinkUframe = shouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U);
}
- currentUframe = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
- distance = ((shouldLinkUframe - currentUframe + EHCI_MAX_UFRAME_VALUE + 1) &
- EHCI_MAX_UFRAME_VALUE); /* get the distance */
+ currentUframe = (ehciInstance->ehciIpBase->FRINDEX & USB_HOST_EHCI_MAX_MICRFRAME_VALUE);
+ distance = ((shouldLinkUframe + USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U - currentUframe) &
+ USB_HOST_EHCI_MAX_MICRFRAME_VALUE); /* get the distance */
/* shouldLinkUframe has add uframeInterval, think about the align with interval, so here add (uframeInterval
* * 2) */
- if ((distance <= (int32_t)(USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER + (uframeInterval * 2))) && (distance > 2))
+ if ((distance <= ((uint32_t)USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER +
+ ((uint32_t)uframeInterval * USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER))) &&
+ (distance > 2U))
{
currentUframe = shouldLinkUframe;
}
else /* re-link */
{
currentUframe =
- ((uint32_t)(currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & EHCI_MAX_UFRAME_VALUE);
- if (currentUframe > (int32_t)EHCI_MAX_UFRAME_VALUE)
+ ((currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & USB_HOST_EHCI_MAX_MICRFRAME_VALUE);
+ /*if (currentUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE)
{
- currentUframe = currentUframe - (EHCI_MAX_UFRAME_VALUE + 1);
- }
+ currentUframe = currentUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U);
+ }*/
/* uframe should align with interval */
- currentUframe -= startUframe;
- currentUframe = ((uint32_t)(currentUframe + uframeInterval - 1) &
- (~((uint32_t)uframeInterval - 1))); /* uframeInterval is power of 2 */
- currentUframe += startUframe;
+ if (currentUframe <= startUframe)
+ {
+ currentUframe = startUframe;
+ }
+ else
+ {
+ currentUframe -= startUframe;
+ currentUframe = ((uint32_t)(currentUframe + uframeInterval) &
+ (~((uint32_t)uframeInterval - 1U))); /* uframeInterval is power of 2 */
+ currentUframe += startUframe;
+ }
}
}
else
{
- currentUframe = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
- currentUframe = ((uint32_t)(currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & EHCI_MAX_UFRAME_VALUE);
+ currentUframe = (ehciInstance->ehciIpBase->FRINDEX & USB_HOST_EHCI_MAX_MICRFRAME_VALUE);
+ currentUframe = ((currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & USB_HOST_EHCI_MAX_MICRFRAME_VALUE);
/* uframe should align with interval */
- currentUframe -= startUframe;
- currentUframe = ((uint32_t)(currentUframe + uframeInterval - 1) &
- (~((uint32_t)uframeInterval - 1))); /* uframeInterval is power of 2 */
- currentUframe += startUframe;
+ if (currentUframe <= startUframe)
+ {
+ currentUframe = startUframe;
+ }
+ else
+ {
+ currentUframe -= startUframe;
+ currentUframe =
+ ((currentUframe + uframeInterval) & (~(uframeInterval - 1U))); /* uframeInterval is power of 2 */
+ currentUframe += startUframe;
+ }
}
return currentUframe;
@@ -2845,27 +2875,29 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
{
usb_host_ehci_iso_t *isoPointer;
usb_host_ehci_itd_t *itdPointer = NULL;
+ usb_host_ehci_itd_t *itdHead = NULL;
usb_host_ehci_itd_t *tmpItdPointer;
uint32_t dataLength; /* the remaining data for sending */
uint32_t transactionLength; /* the initializing transaction descriptor data length */
uint32_t itdBufferValue;
uint32_t itdBufferBaseValue; /* for calculating PG value */
- uint32_t address;
+ uint32_t address = 0U;
uint32_t lastShouldLinkUframe;
uint32_t linkUframe;
- uint32_t minDataPerItd = ehciPipePointer->pipeCommon.numberPerUframe * ehciPipePointer->pipeCommon.maxPacketSize;
+ uint32_t minDataPerItd =
+ (uint32_t)ehciPipePointer->pipeCommon.numberPerUframe * ehciPipePointer->pipeCommon.maxPacketSize;
uint8_t maxItdNumber;
- uint8_t index = 0;
+ uint16_t index = 0;
isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress,
- &address);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceAddress, &address);
/* max needed itd number, the actual needed number may be less because micro-frame interval may be less than 8 */
- maxItdNumber = ((transfer->transferLength - 1 + minDataPerItd) / minDataPerItd);
- if (ehciPipePointer->uframeInterval < 8)
+ maxItdNumber = (uint8_t)((transfer->transferLength - 1U + minDataPerItd) / minDataPerItd);
+ if (ehciPipePointer->uframeInterval < 8U)
{
- maxItdNumber = ((maxItdNumber * ehciPipePointer->uframeInterval + 7) / 8) + 1;
+ maxItdNumber = (uint8_t)((maxItdNumber * ehciPipePointer->uframeInterval + 7U) / 8U) + 1U;
}
if (maxItdNumber > ehciInstance->ehciItdNumber)
{
@@ -2877,43 +2909,46 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
/* USB_HostEhciLock(); */
if (isoPointer->ehciTransferHead == NULL)
{
- isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = transfer;
+ isoPointer->ehciTransferTail = transfer;
+ isoPointer->ehciTransferHead = transfer;
}
else
{
isoPointer->ehciTransferTail->next = transfer;
- isoPointer->ehciTransferTail = transfer;
+ isoPointer->ehciTransferTail = transfer;
}
/* USB_HostEhciUnlock(); */
- dataLength = transfer->transferLength;
- transfer->union1.unitHead = (uint32_t)NULL;
+ dataLength = transfer->transferLength;
+ transfer->union1.unitHead = 0U;
/* get the link micro-frame */
lastShouldLinkUframe = USB_HostEhciGetItdLinkFrame(
ehciInstance, isoPointer->lastLinkFrame,
(uint16_t)((ehciPipePointer->startFrame << 3) + ehciPipePointer->startUframe), ehciPipePointer->uframeInterval);
- if (lastShouldLinkUframe > EHCI_MAX_UFRAME_VALUE)
+ if (lastShouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE)
{
- linkUframe = lastShouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1);
+ linkUframe = lastShouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U);
}
else
{
linkUframe = lastShouldLinkUframe;
}
- while (dataLength)
+ itdHead = ehciInstance->ehciItdList;
+ while (0U != dataLength)
{
/* get one idle itd */
tmpItdPointer = ehciInstance->ehciItdList;
- ehciInstance->ehciItdList = (usb_host_ehci_itd_t *)tmpItdPointer->nextLinkPointer;
- ehciInstance->ehciItdNumber -= 1;
if (tmpItdPointer == NULL)
{
return kStatus_USB_Error; /* this should not reach */
}
+ ehciInstance->ehciItdList = (usb_host_ehci_itd_t *)tmpItdPointer->nextItdPointer;
+ ehciInstance->ehciItdNumber -= 1U;
+
tmpItdPointer->nextItdPointer = NULL;
/* use the itd */
- if (transfer->union1.unitHead == (uint32_t)NULL) /* first itd */
+ if (transfer->union1.unitHead == 0U) /* first itd */
{
transfer->union1.unitHead = (uint32_t)tmpItdPointer;
}
@@ -2924,11 +2959,11 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
itdPointer = tmpItdPointer;
/* itd has been set to all zero when releasing */
- itdBufferBaseValue = itdBufferValue =
- (uint32_t)(transfer->transferBuffer + (transfer->transferLength - dataLength));
- for (index = 0; index < 7; ++index)
+ itdBufferValue = (uint32_t)(transfer->transferBuffer + (transfer->transferLength - dataLength));
+ itdBufferBaseValue = itdBufferValue;
+ for (index = 0; index < 7U; ++index)
{
- itdPointer->bufferPointers[index] = ((itdBufferBaseValue + (index * 4 * 1024)) & 0xFFFFF000U);
+ itdPointer->bufferPointers[index] = ((itdBufferBaseValue + ((uint32_t)index * 4U * 1024U)) & 0xFFFFF000U);
}
/* initialize iTD common fields */
itdPointer->bufferPointers[0] |=
@@ -2939,7 +2974,7 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
((uint32_t)ehciPipePointer->pipeCommon.maxPacketSize << EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT));
itdPointer->bufferPointers[2] |= (ehciPipePointer->pipeCommon.numberPerUframe);
/* initialize transaction descriptors */
- for (index = (linkUframe & 0x0007); index < 8; index += ehciPipePointer->uframeInterval)
+ for (index = (uint8_t)(linkUframe & 0x0007U); index < 8U; index += ehciPipePointer->uframeInterval)
{
transactionLength = ((dataLength > minDataPerItd) ? minDataPerItd : dataLength);
/* initialize the uframeIndex's transaction descriptor in itd */
@@ -2951,7 +2986,7 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
(itdBufferValue & EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK));
dataLength -= transactionLength;
itdBufferValue += transactionLength;
- if (dataLength <= 0)
+ if (dataLength <= 0U)
{
break;
}
@@ -2959,17 +2994,25 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
}
transfer->union2.unitTail = (uint32_t)itdPointer;
- itdPointer->transactions[index] |= (1 << EHCI_HOST_ITD_IOC_SHIFT); /* last set IOC */
+ itdPointer->transactions[index] |= (1UL << EHCI_HOST_ITD_IOC_SHIFT); /* last set IOC */
+ itdPointer = itdHead;
/* link itd to frame list (note: initialize frameEntryIndex)*/
- while (itdPointer)
+ while (NULL != itdPointer)
{
- itdPointer->frameEntryIndex = linkUframe;
- /* add to frame head */
- itdPointer->nextLinkPointer = ((uint32_t *)ehciInstance->ehciFrameList)[linkUframe >> 3];
- *(uint32_t *)((uint32_t *)ehciInstance->ehciFrameList)[linkUframe >> 3] =
- ((uint32_t)itdPointer | EHCI_HOST_POINTER_TYPE_ITD);
- itdPointer = itdPointer->nextItdPointer;
+ void *temp = (void *)ehciInstance->ehciFrameList;
+ uint32_t *linkPointer = &((uint32_t *)temp)[linkUframe >> 3];
+ uint32_t linkValue = *linkPointer;
+ itdPointer->frameEntryIndex = linkUframe >> 3;
+ while ((0U == (linkValue & EHCI_HOST_T_INVALID_VALUE)) &&
+ ((linkValue & EHCI_HOST_POINTER_TYPE_MASK) == EHCI_HOST_POINTER_TYPE_ITD))
+ {
+ linkPointer = (uint32_t *)(linkValue & EHCI_HOST_POINTER_ADDRESS_MASK);
+ linkValue = *linkPointer;
+ }
+ itdPointer->nextLinkPointer = *linkPointer;
+ *linkPointer = ((uint32_t)itdPointer | EHCI_HOST_POINTER_TYPE_ITD);
+ itdPointer = itdPointer->nextItdPointer;
if (itdPointer == NULL)
{
break;
@@ -2983,11 +3026,11 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta
}
}
- if (lastShouldLinkUframe > EHCI_MAX_UFRAME_VALUE)
+ if (lastShouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE)
{
- lastShouldLinkUframe = lastShouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1);
+ lastShouldLinkUframe = lastShouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U);
}
- isoPointer->lastLinkFrame = lastShouldLinkUframe;
+ isoPointer->lastLinkFrame = (uint16_t)lastShouldLinkUframe;
return kStatus_USB_Success;
}
@@ -3001,23 +3044,24 @@ static uint32_t USB_HostEhciItdArrayRelease(usb_host_ehci_instance_t *ehciInstan
uint32_t doneLength = 0;
/* remove itd from frame list */
- while (1)
+ while (1U == 1U)
{
/* record the transfer's result length */
- for (index = 0; index < 8; ++index)
+ for (index = 0U; index < 8U; ++index)
{
doneLength += ((itdPointer->transactions[index] & EHCI_HOST_ITD_TRANSACTION_LEN_MASK) >>
EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT);
}
USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)itdPointer,
- itdPointer->frameEntryIndex); /* remove from the inserted frame list */
+ (uint16_t)itdPointer->frameEntryIndex); /* remove from the inserted frame list */
/* release itd */
/* USB_HostEhciLock(); */
- USB_HostEhciZeroMem((uint32_t *)itdPointer, sizeof(usb_host_ehci_itd_t) >> 2);
- itdPointer->nextLinkPointer = (uint32_t)ehciInstance->ehciItdList;
- ehciInstance->ehciItdList = itdPointer;
+ /*set next link pointer to invalid in case hardware access invalid itd structure in special case*/
+ itdPointer->nextLinkPointer = EHCI_HOST_T_INVALID_VALUE;
+ itdPointer->nextItdPointer = (usb_host_ehci_itd_t *)ehciInstance->ehciItdList;
+ ehciInstance->ehciItdList = itdPointer;
ehciInstance->ehciItdNumber++;
/* USB_HostEhciUnlock(); */
@@ -3041,14 +3085,15 @@ static usb_status_t USB_HostEhciItdArrayDeinit(usb_host_ehci_instance_t *ehciIns
/* firstly remove the transfer (because host task may occupy to access the resource) */
USB_HostEhciLock();
- transfer = isoPointer->ehciTransferHead;
- isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = NULL;
+ transfer = isoPointer->ehciTransferHead;
+ isoPointer->ehciTransferTail = NULL;
+ isoPointer->ehciTransferHead = NULL;
USB_HostEhciUnlock();
while (transfer != NULL)
{
nextTransfer = transfer->next;
- doneLength = 0;
+ doneLength = 0;
/* remove itd from frame list and release itd */
doneLength = USB_HostEhciItdArrayRelease(ehciInstance, (usb_host_ehci_itd_t *)transfer->union1.unitHead,
(usb_host_ehci_itd_t *)transfer->union2.unitTail);
@@ -3059,6 +3104,7 @@ static usb_status_t USB_HostEhciItdArrayDeinit(usb_host_ehci_instance_t *ehciIns
doneLength = transfer->transferLength;
}
transfer->transferSofar = doneLength;
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel);
/* next transfer */
@@ -3082,7 +3128,7 @@ static usb_status_t USB_HostEhciOpenControlBulk(usb_host_ehci_instance_t *ehciIn
qhPointer = (usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
/* add qh to async */
- qhPointer->horizontalLinkPointer = ehciInstance->shedFirstQh->horizontalLinkPointer;
+ qhPointer->horizontalLinkPointer = ehciInstance->shedFirstQh->horizontalLinkPointer;
ehciInstance->shedFirstQh->horizontalLinkPointer = ((uint32_t)qhPointer | EHCI_HOST_POINTER_TYPE_QH);
return kStatus_USB_Success;
@@ -3093,10 +3139,11 @@ static usb_status_t USB_HostEhciCloseControlBulk(usb_host_ehci_instance_t *ehciI
{
volatile usb_host_ehci_qh_t *vltPrevQhPointer;
uint32_t horizontalLinkValue;
-
+ uint32_t *temp;
/* remove qh from async schedule */
+ temp = (uint32_t *)ehciPipePointer->ehciQh;
if ((ehciInstance->shedFirstQh->horizontalLinkPointer & EHCI_HOST_POINTER_ADDRESS_MASK) ==
- (uint32_t)ehciPipePointer->ehciQh) /* the removing qh is the first qh in the async list */
+ (uint32_t)temp) /* the removing qh is the first qh in the async list */
{
USB_HostEhciStopAsync(ehciInstance);
ehciInstance->shedFirstQh->horizontalLinkPointer =
@@ -3110,8 +3157,8 @@ static usb_status_t USB_HostEhciCloseControlBulk(usb_host_ehci_instance_t *ehciI
while (vltPrevQhPointer != NULL)
{
horizontalLinkValue = vltPrevQhPointer->horizontalLinkPointer;
- if ((horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE) ||
- ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciPipePointer->ehciQh) ||
+ if ((0U != (horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE)) ||
+ ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)temp) ||
((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciInstance->shedFirstQh))
{
break;
@@ -3121,8 +3168,10 @@ static usb_status_t USB_HostEhciCloseControlBulk(usb_host_ehci_instance_t *ehciI
}
/* remove the qh from async list */
- if ((vltPrevQhPointer != NULL) && (!(horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE)) &&
- ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciPipePointer->ehciQh))
+ /*for misra 11.6*/
+ temp = (uint32_t *)ehciPipePointer->ehciQh;
+ if ((vltPrevQhPointer != NULL) && (0U == (horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE)) &&
+ ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)temp))
{
USB_HostEhciStopAsync(ehciInstance);
vltPrevQhPointer->horizontalLinkPointer =
@@ -3140,6 +3189,7 @@ static usb_status_t USB_HostEhciOpenInterrupt(usb_host_ehci_instance_t *ehciInst
{
usb_status_t status = kStatus_USB_Success;
uint32_t frameIndex;
+ uint32_t *temp;
/* allocate bandwidth */
if (ehciInstance->firstDeviceSpeed == USB_SPEED_HIGH)
@@ -3163,10 +3213,10 @@ static usb_status_t USB_HostEhciOpenInterrupt(usb_host_ehci_instance_t *ehciInst
/* insert QH to frame list */
for (frameIndex = ehciPipePointer->startFrame; frameIndex < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE;
- frameIndex += (ehciPipePointer->uframeInterval / 8))
+ frameIndex += (((uint32_t)ehciPipePointer->uframeInterval + 7U) / 8U))
{
- USB_HostEhciAddQhToFrame(ehciInstance, (uint32_t)ehciPipePointer->ehciQh, frameIndex,
- ehciPipePointer->uframeInterval);
+ temp = (uint32_t *)ehciPipePointer->ehciQh;
+ USB_HostEhciAddQhToFrame(ehciInstance, (uint32_t)temp, (uint16_t)frameIndex, ehciPipePointer->uframeInterval);
}
return kStatus_USB_Success;
@@ -3176,12 +3226,13 @@ static usb_status_t USB_HostEhciCloseInterrupt(usb_host_ehci_instance_t *ehciIns
usb_host_ehci_pipe_t *ehciPipePointer)
{
uint32_t frameIndex;
-
+ uint32_t *temp;
/* remove from frame list */
for (frameIndex = ehciPipePointer->startFrame; frameIndex < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE;
- frameIndex += (ehciPipePointer->uframeInterval / 8))
+ frameIndex += (((uint32_t)ehciPipePointer->uframeInterval + 7U) / 8U))
{
- USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)ehciPipePointer->ehciQh, frameIndex);
+ temp = (uint32_t *)ehciPipePointer->ehciQh;
+ USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)temp, (uint16_t)frameIndex);
}
((usb_host_ehci_qh_t *)ehciPipePointer->ehciQh)->horizontalLinkPointer |=
EHCI_HOST_T_INVALID_VALUE; /* invalid next qh link */
@@ -3219,11 +3270,11 @@ static usb_status_t USB_HostEhciOpenIso(usb_host_ehci_instance_t *ehciInstance,
return kStatus_USB_Error;
}
USB_HostEhciLock();
- isoPointer = ehciInstance->ehciIsoList;
+ isoPointer = ehciInstance->ehciIsoList;
ehciInstance->ehciIsoList = ehciInstance->ehciIsoList->next;
USB_HostEhciUnlock();
isoPointer->lastLinkFrame = 0xFFFF;
- ehciPipePointer->ehciQh = isoPointer;
+ ehciPipePointer->ehciQh = isoPointer;
return status;
}
@@ -3231,31 +3282,32 @@ static usb_status_t USB_HostEhciOpenIso(usb_host_ehci_instance_t *ehciInstance,
static usb_status_t USB_HostEhciCloseIso(usb_host_ehci_instance_t *ehciInstance, usb_host_ehci_pipe_t *ehciPipePointer)
{
usb_host_ehci_iso_t *isoPointer;
- uint32_t speed;
+ uint32_t speed = 0U;
isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh;
if (isoPointer->ehciTransferHead != NULL)
{
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &speed);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
if (speed == USB_SPEED_HIGH)
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
- USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd list and free them */
+ (void)USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd list and free them */
#endif
}
else
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD))
- USB_HostEhciSitdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize sitd list and free them */
+ (void)USB_HostEhciSitdArrayDeinit(ehciInstance,
+ ehciPipePointer); /* de-initialize sitd list and free them */
#endif
}
}
/* release usb_host_ehci_iso_t */
USB_HostEhciLock();
- isoPointer->next = ehciInstance->ehciIsoList;
+ isoPointer->next = ehciInstance->ehciIsoList;
ehciInstance->ehciIsoList = isoPointer;
USB_HostEhciUnlock();
return kStatus_USB_Success;
@@ -3267,17 +3319,17 @@ static usb_status_t USB_HostEhciResetIP(usb_host_ehci_instance_t *ehciInstance)
{
/* reset controller */
ehciInstance->ehciIpBase->USBCMD = USBHS_USBCMD_RST_MASK;
- while (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_RST_MASK)
+ while (0U != (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_RST_MASK))
{
}
/* set host mode */
#if (ENDIANNESS == USB_LITTLE_ENDIAN)
- ehciInstance->ehciIpBase->USBMODE |= 0x03;
+ ehciInstance->ehciIpBase->USBMODE |= 0x03U;
#else
- ehciInstance->ehciIpBase->USBMODE |= (0x03 | (0x01 << USBHS_USBMODE_ES_SHIFT));
+ ehciInstance->ehciIpBase->USBMODE |= (0x03U | (0x01U << USBHS_USBMODE_ES_SHIFT));
#endif
/* check frame list size */
- if (!(ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK))
+ if (0U == (ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK))
{
#if ((USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE < 8) || (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE > 1024))
return kStatus_USB_Error;
@@ -3293,7 +3345,7 @@ static usb_status_t USB_HostEhciStartIP(usb_host_ehci_instance_t *ehciInstance)
{
uint32_t tmp = 0;
- if (ehciInstance->ehciIpBase->HCSPARAMS & USBHS_HCSPARAMS_PPC_MASK) /* Ports have power port switches */
+ if (0U != (ehciInstance->ehciIpBase->HCSPARAMS & USBHS_HCSPARAMS_PPC_MASK)) /* Ports have power port switches */
{
/* only has one port */
tmp = ehciInstance->ehciIpBase->PORTSC1;
@@ -3302,41 +3354,41 @@ static usb_status_t USB_HostEhciStartIP(usb_host_ehci_instance_t *ehciInstance)
}
/* set frame list size */
- if (ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK)
+ if (0U != (ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK))
{
#if (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE <= 64)
ehciInstance->ehciIpBase->USBCMD |= (USBHS_USBCMD_FS2_MASK);
#if (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 64)
- ehciInstance->ehciIpBase->USBCMD |= (0x00 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 32)
- ehciInstance->ehciIpBase->USBCMD |= (0x01 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 16)
- ehciInstance->ehciIpBase->USBCMD |= (0x02 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 8)
- ehciInstance->ehciIpBase->USBCMD |= (0x03 << USBHS_USBCMD_FS_SHIFT);
+ ehciInstance->ehciIpBase->USBCMD |= (0x00U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 32)
+ ehciInstance->ehciIpBase->USBCMD |= (0x01U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 16)
+ ehciInstance->ehciIpBase->USBCMD |= (0x02U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 8)
+ ehciInstance->ehciIpBase->USBCMD |= (0x03U << USBHS_USBCMD_FS_SHIFT);
#endif
#else
#if (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 1024)
- ehciInstance->ehciIpBase->USBCMD |= (0x00 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 512)
- ehciInstance->ehciIpBase->USBCMD |= (0x01 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 256)
- ehciInstance->ehciIpBase->USBCMD |= (0x02 << USBHS_USBCMD_FS_SHIFT);
-#elif(USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 128)
- ehciInstance->ehciIpBase->USBCMD |= (0x03 << USBHS_USBCMD_FS_SHIFT);
+ ehciInstance->ehciIpBase->USBCMD |= (0x00U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 512)
+ ehciInstance->ehciIpBase->USBCMD |= (0x01U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 256)
+ ehciInstance->ehciIpBase->USBCMD |= (0x02U << USBHS_USBCMD_FS_SHIFT);
+#elif (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 128)
+ ehciInstance->ehciIpBase->USBCMD |= (0x03U << USBHS_USBCMD_FS_SHIFT);
#endif
#endif
}
/* start the controller */
- ehciInstance->ehciIpBase->USBCMD = USBHS_USBCMD_RS_MASK;
+ ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_RS_MASK;
/* set timer0 */
- ehciInstance->ehciIpBase->GPTIMER0LD = (300 * 1000 - 1); /* 100ms */
+ ehciInstance->ehciIpBase->GPTIMER0LD = (100U * 1000U - 1U); /* 100ms */
/* enable interrupt (USB interrupt enable + USB error interrupt enable + port change detect enable + system error
* enable + interrupt on async advance enable) + general purpos Timer 0 Interrupt enable */
- ehciInstance->ehciIpBase->USBINTR |= (0x1000037);
+ ehciInstance->ehciIpBase->USBINTR |= (0x1000037U);
return kStatus_USB_Success;
}
@@ -3349,7 +3401,7 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc
#if (((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) || \
((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)))
usb_host_ehci_iso_t *isoPointer;
- uint32_t speed;
+ uint32_t speed = 0U;
#endif
uint8_t cancelPipe = 0;
@@ -3368,24 +3420,24 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc
if ((qhPointer->ehciTransferHead == transfer) &&
(qhPointer->ehciTransferHead == qhPointer->ehciTransferTail)) /* only has this one transfer */
{
- cancelPipe = 1;
+ cancelPipe = 1U;
}
else
{
- cancelPipe = 0;
+ cancelPipe = 0U;
}
}
else
{
- cancelPipe = 1;
+ cancelPipe = 1U;
}
- if (cancelPipe == 1) /* cancel all pipe */
+ if (cancelPipe == 1U) /* cancel all pipe */
{
- USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer); /* release all the qtd */
+ (void)USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer); /* release all the qtd */
}
else /* cancel one transfer */
{
- USB_HostEhciTransferQtdListDeinit(ehciInstance, ehciPipePointer, transfer);
+ (void)USB_HostEhciTransferQtdListDeinit(ehciInstance, ehciPipePointer, transfer);
}
break;
@@ -3398,54 +3450,55 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc
return kStatus_USB_Success;
}
/* cancel all pipe, don't implement canceling transfer for iso */
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &speed);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
if (speed == USB_SPEED_HIGH)
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
- USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd */
+ (void)USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd */
#endif
}
else
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD))
- USB_HostEhciSitdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize sitd */
+ (void)USB_HostEhciSitdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize sitd */
#endif
}
break;
#endif
default:
+ /*no action*/
break;
}
return kStatus_USB_Success;
}
-static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl)
+usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl)
{
usb_status_t status = kStatus_USB_Success;
uint32_t portScRegister;
-
- switch (busControl)
+ usb_host_bus_control_t controlCode = (usb_host_bus_control_t)busControl;
+ switch (controlCode)
{
case kUSB_HostBusReset:
/* reset port */
portScRegister = ehciInstance->ehciIpBase->PORTSC1;
portScRegister &= (~EHCI_PORTSC1_W1_BITS);
ehciInstance->ehciIpBase->PORTSC1 = (portScRegister | USBHS_PORTSC1_PR_MASK);
- while (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK)
+ while (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK))
{
}
break;
case kUSB_HostBusRestart:
- ehciInstance->deviceAttached = kEHCIDeviceDetached;
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached;
ehciInstance->ehciIpBase->USBINTR |= (USBHS_USBINTR_PCE_MASK); /* enable ehci port change interrupt */
break;
case kUSB_HostBusEnableAttach: /* enable device attach */
- if (ehciInstance->deviceAttached == kEHCIDeviceDetached)
+ if (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceDetached)
{
ehciInstance->ehciIpBase->USBINTR |= (USBHS_USBINTR_PCE_MASK); /* enable ehci port change interrupt */
}
@@ -3456,7 +3509,7 @@ static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstanc
break;
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
case kUSB_HostBusSuspend:
- if (ehciInstance->ehciIpBase->PORTSC1 && USBHS_PORTSC1_CCS_MASK)
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
/* set timer1 */
ehciInstance->ehciIpBase->GPTIMER1LD = (1 * 1000); /* 1ms */
@@ -3465,9 +3518,9 @@ static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstanc
USB_HostEhciStopAsync(ehciInstance);
USB_HostEhciStopPeriodic(ehciInstance);
- while (ehciInstance->ehciIpBase->USBSTS & (USBHS_USBSTS_PS_MASK | USBHS_USBSTS_AS_MASK))
+ while (0U != (ehciInstance->ehciIpBase->USBSTS & (USBHS_USBSTS_PS_MASK | USBHS_USBSTS_AS_MASK)))
{
- __ASM("nop");
+ __NOP();
}
ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_WKCN_MASK;
ehciInstance->ehciIpBase->PORTSC1 |= USBHS_PORTSC1_WKDS_MASK;
@@ -3485,7 +3538,7 @@ static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstanc
case kUSB_HostBusResume:
ehciInstance->ehciIpBase->PORTSC1 &= ~(USBHS_PORTSC1_SUSP_MASK); /* Clear Suspend bit */
ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_PHCD_MASK;
- if (ehciInstance->deviceAttached != kEHCIDeviceDetached)
+ if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceDetached)
{
ehciInstance->busSuspendStatus = kBus_EhciStartResume;
#if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
@@ -3532,6 +3585,9 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
uint32_t dataLength;
uint32_t speed;
#endif
+ void *temp;
+ uint32_t transferResults;
+ uint32_t transferOverlayResults;
ehciPipePointer = ehciInstance->ehciRunningPipeList; /* check all the running pipes */
while (ehciPipePointer != NULL)
@@ -3542,43 +3598,45 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
case USB_ENDPOINT_INTERRUPT:
case USB_ENDPOINT_CONTROL:
vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh; /* pipe's qh */
- transfer = vltQhPointer->ehciTransferHead; /* qh's transfer */
+ transfer = vltQhPointer->ehciTransferHead; /* qh's transfer */
while (transfer != NULL)
{
nextTransfer = transfer->next;
/* normal case */
- vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail;
- if ((vltQtdPointer->transferResults[0] & (EHCI_HOST_QTD_IOC_MASK)) &&
- (!(vltQtdPointer->transferResults[0] &
- EHCI_HOST_QTD_STATUS_ACTIVE_MASK))) /* transfer is done */
+ vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail;
+ transferResults = vltQtdPointer->transferResults[0];
+ transferOverlayResults = vltQhPointer->transferOverlayResults[0];
+ if ((0U != (transferResults & (EHCI_HOST_QTD_IOC_MASK))) &&
+ (0U == (transferResults & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))) /* transfer is done */
{
- qtdStatus = (vltQtdPointer->transferResults[0] & EHCI_HOST_QTD_STATUS_ERROR_MASK);
+ qtdStatus = (transferResults & EHCI_HOST_QTD_STATUS_ERROR_MASK);
transfer->transferSofar =
USB_HostEhciQtdListRelease(ehciInstance, (usb_host_ehci_qtd_t *)(transfer->union1.unitHead),
(usb_host_ehci_qtd_t *)(transfer->union2.unitTail));
transfer->transferSofar = (transfer->transferLength < transfer->transferSofar) ?
- 0 :
+ 0U :
(transfer->transferLength - transfer->transferSofar);
vltQhPointer->ehciTransferHead = transfer->next;
- vltQhPointer->timeOutLabel = 0;
- vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
- if (qtdStatus) /* has errors */
+ vltQhPointer->timeOutLabel = 0U;
+ vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
+ if (0U != qtdStatus) /* has errors */
{
- if (!(vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))
+ if (0U == (transferOverlayResults & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))
{
vltQhPointer->transferOverlayResults[0] &=
(~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */
}
- if (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK)
+ if (0U != (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK))
{
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_TransferFailed); /* transfer fail */
}
else
{
- transfer->callbackFn(transfer->callbackParam, transfer,
- kStatus_USB_TransferStall); /* transfer stall */
+ /* callback function is different from the current condition */
+ transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferStall);
}
}
else
@@ -3602,8 +3660,8 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
{
break;
}
- ehciClearPipePointer =
- (usb_host_ehci_pipe_t *)ehciClearPipePointer->pipeCommon.next;
+ temp = (void *)ehciClearPipePointer->pipeCommon.next;
+ ehciClearPipePointer = (usb_host_ehci_pipe_t *)temp;
}
if ((ehciClearPipePointer != NULL) &&
@@ -3614,18 +3672,19 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
->transferOverlayResults[0] &= (~EHCI_HOST_QTD_DT_MASK);
}
}
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_Success); /* transfer success */
}
}
- else if ((!(vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) &&
- (vltQhPointer->transferOverlayResults[0] &
- EHCI_HOST_QH_STATUS_ERROR_MASK)) /* there is error and transfer is done */
+ else if ((0U == (transferOverlayResults & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) &&
+ (0U != (transferOverlayResults &
+ EHCI_HOST_QH_STATUS_ERROR_MASK))) /* there is error and transfer is done */
{
- qtdStatus = (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QH_STATUS_ERROR_MASK);
+ qtdStatus = (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QH_STATUS_ERROR_MASK);
vltQtdPointer = (volatile usb_host_ehci_qtd_t *)(vltQhPointer->currentQtdPointer);
- if (((uint32_t)vltQtdPointer & EHCI_HOST_T_INVALID_VALUE) ||
+ if ((0U != ((uint32_t)vltQtdPointer & EHCI_HOST_T_INVALID_VALUE)) ||
(vltQtdPointer == NULL)) /* the error status is unreasonable */
{
vltQhPointer->transferOverlayResults[0] &=
@@ -3634,13 +3693,13 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
else
{
/* remove qtd from qh */
- while ((vltQtdPointer != NULL) && (!(vltQtdPointer->transferResults[0] &
- EHCI_HOST_QTD_IOC_MASK))) /* find the IOC qtd */
+ while ((vltQtdPointer != NULL) &&
+ (0U == (transferResults & EHCI_HOST_QTD_IOC_MASK))) /* find the IOC qtd */
{
vltQtdPointer = (volatile usb_host_ehci_qtd_t *)vltQtdPointer->nextQtdPointer;
}
- vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
+ vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
vltQhPointer->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE;
vltQhPointer->transferOverlayResults[0] &=
(~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */
@@ -3653,18 +3712,20 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
ehciInstance, (usb_host_ehci_qtd_t *)(transfer->union1.unitHead),
(usb_host_ehci_qtd_t *)(transfer->union2.unitTail));
transfer->transferSofar = (transfer->transferLength < transfer->transferSofar) ?
- 0 :
+ 0U :
(transfer->transferLength - transfer->transferSofar);
vltQhPointer->ehciTransferHead = transfer->next;
- vltQhPointer->timeOutLabel = 0;
- vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
- if (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK)
+ vltQhPointer->timeOutLabel = 0U;
+ vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
+ if (0U != (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK))
{
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_TransferFailed); /* transfer fail */
}
else
{
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_TransferStall); /* transfer stall */
}
@@ -3680,41 +3741,42 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
#if (((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) || \
((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)))
case USB_ENDPOINT_ISOCHRONOUS:
- qtdStatus = 0; /* qtdStatus means break here, because there is only one break in while for misra */
+ qtdStatus = 0; /* qtdStatus means break here, because there is only one break in while for misra */
isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh; /* pipe's usb_host_ehci_iso_t */
- transfer = isoPointer->ehciTransferHead; /* usb_host_ehci_iso_t's transfer */
+ transfer = isoPointer->ehciTransferHead; /* usb_host_ehci_iso_t's transfer */
while (transfer != NULL)
{
nextTransfer = transfer->next;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
- kUSB_HostGetDeviceSpeed, &speed);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
if (speed == USB_SPEED_HIGH)
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
vltItdPointer =
(volatile usb_host_ehci_itd_t *)(transfer->union2.unitTail); /* transfer's last itd */
- for (index = 0; index < 8; ++index)
+ for (index = 0; index < 8U; ++index)
{
- if (vltItdPointer->transactions[index] & EHCI_HOST_ITD_STATUS_ACTIVE_MASK)
+ if (0U != (vltItdPointer->transactions[index] & EHCI_HOST_ITD_STATUS_ACTIVE_MASK))
{
break;
}
}
- if (index == 8) /* transfer is done */
+ if (index == 8U) /* transfer is done */
{
/* remove itd from frame list and release itd */
- dataLength = USB_HostEhciItdArrayRelease(ehciInstance,
+ dataLength = USB_HostEhciItdArrayRelease(ehciInstance,
(usb_host_ehci_itd_t *)transfer->union1.unitHead,
(usb_host_ehci_itd_t *)transfer->union2.unitTail);
- transfer->transferSofar = dataLength;
+ transfer->transferSofar = dataLength;
isoPointer->ehciTransferHead = transfer->next;
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_Success); /* transfer callback success */
/* TODO: iso callback error */
}
else
{
- qtdStatus = 1; /* break */
+ qtdStatus = 1U; /* break */
}
#endif
}
@@ -3723,26 +3785,27 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
#if ((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD))
vltSitdPointer =
(volatile usb_host_ehci_sitd_t *)(transfer->union2.unitTail); /* transfer's last sitd */
- if (!(vltSitdPointer->transferResults[0] &
- EHCI_HOST_SITD_STATUS_ACTIVE_MASK)) /* transfer is done */
+ if (0U == (vltSitdPointer->transferResults[0] &
+ EHCI_HOST_SITD_STATUS_ACTIVE_MASK)) /* transfer is done */
{
/* remove sitd from frame list and release itd */
dataLength = USB_HostEhciSitdArrayRelease(
ehciInstance, (usb_host_ehci_sitd_t *)transfer->union1.unitHead,
(usb_host_ehci_sitd_t *)transfer->union2.unitTail);
- transfer->transferSofar = dataLength;
+ transfer->transferSofar = transfer->transferLength - dataLength;
isoPointer->ehciTransferHead = transfer->next;
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer,
kStatus_USB_Success); /* transfer callback success */
/* TODO: iso callback error */
}
else
{
- qtdStatus = 1; /* break */
+ qtdStatus = 1U; /* break */
}
#endif
}
- if (qtdStatus == 1)
+ if (qtdStatus == 1U)
{
break;
}
@@ -3752,38 +3815,40 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance)
#endif
default:
+ /*no action*/
break;
}
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
}
}
-static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
+void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
{
/* note: only has one port */
uint32_t portScRegister = ehciInstance->ehciIpBase->PORTSC1;
- int32_t sofStart = 0;
- int32_t sofCount = 0;
+ uint32_t sofStart = 0;
+ uint32_t sofCount = 0;
uint32_t index;
- if (portScRegister & USBHS_PORTSC1_CSC_MASK) /* connection status change */
+ if (0U != (portScRegister & USBHS_PORTSC1_CSC_MASK)) /* connection status change */
{
- sofStart = (int32_t)(ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
+ sofStart = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
/* process CSC bit */
- while (1)
+ while (1U == 1U)
{
portScRegister = ehciInstance->ehciIpBase->PORTSC1;
- if (portScRegister & USBHS_PORTSC1_CSC_MASK)
+ if (0U != (portScRegister & USBHS_PORTSC1_CSC_MASK))
{
/* clear csc bit */
portScRegister = ehciInstance->ehciIpBase->PORTSC1;
portScRegister &= (~EHCI_PORTSC1_W1_BITS);
ehciInstance->ehciIpBase->PORTSC1 = (portScRegister | USBHS_PORTSC1_CSC_MASK);
}
- sofCount = (int32_t)(ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
- if (((sofCount - sofStart + EHCI_MAX_UFRAME_VALUE + 1) & EHCI_MAX_UFRAME_VALUE) >
- (1 * 8)) /* delay 1ms to clear CSC */
+ sofCount = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE);
+ if (((sofCount + EHCI_MAX_UFRAME_VALUE + 1U - sofStart) & EHCI_MAX_UFRAME_VALUE) >
+ (1U * 8U)) /* delay 1ms to clear CSC */
{
break;
}
@@ -3792,10 +3857,10 @@ static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
/* process CCS bit */
portScRegister = ehciInstance->ehciIpBase->PORTSC1;
- if (portScRegister & USBHS_PORTSC1_CCS_MASK) /* process attach */
+ if (0U != (portScRegister & USBHS_PORTSC1_CCS_MASK)) /* process attach */
{
- if ((ehciInstance->deviceAttached == kEHCIDevicePhyAttached) ||
- (ehciInstance->deviceAttached == kEHCIDeviceAttached))
+ if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDevicePhyAttached) ||
+ (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached))
{
return;
}
@@ -3806,25 +3871,25 @@ static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
for (index = 0; index < USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY; ++index)
{
USB_HostEhciDelay(ehciInstance->ehciIpBase, 1);
- if (!(ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
+ if (0U == (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
break;
}
}
if (index < USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY) /* CCS is cleared */
{
- ehciInstance->deviceAttached = kEHCIDeviceDetached;
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached;
return;
}
/* reset port */
portScRegister = ehciInstance->ehciIpBase->PORTSC1;
portScRegister &= (~EHCI_PORTSC1_W1_BITS);
ehciInstance->ehciIpBase->PORTSC1 = (portScRegister | USBHS_PORTSC1_PR_MASK);
- while (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK)
+ while (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK))
{
}
ehciInstance->firstDeviceSpeed =
- ((ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PSPD_MASK) >> USBHS_PORTSC1_PSPD_SHIFT);
+ (uint8_t)((ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PSPD_MASK) >> USBHS_PORTSC1_PSPD_SHIFT);
/* enable ehci phy disconnection */
if (ehciInstance->firstDeviceSpeed == USB_SPEED_HIGH)
{
@@ -3834,16 +3899,16 @@ static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
/* wait for reset */
USB_HostEhciDelay(ehciInstance->ehciIpBase, USB_HOST_EHCI_PORT_RESET_DELAY);
/* process attach */
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_ATTACH);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_ATTACH);
/* gpt timer start */
ehciInstance->ehciIpBase->GPTIMER0CTL |=
(USBHS_GPTIMER0CTL_RUN_MASK | USBHS_GPTIMER0CTL_MODE_MASK | USBHS_GPTIMER0CTL_RST_MASK);
- ehciInstance->deviceAttached = kEHCIDevicePhyAttached;
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDevicePhyAttached;
}
else
{
- if ((ehciInstance->deviceAttached == kEHCIDevicePhyAttached) ||
- (ehciInstance->deviceAttached == kEHCIDeviceAttached))
+ if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDevicePhyAttached) ||
+ (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached))
{
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
ehciInstance->busSuspendStatus = kBus_EhciIdle;
@@ -3854,19 +3919,20 @@ static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance)
/* disable async and periodic */
USB_HostEhciStopAsync(ehciInstance);
USB_HostEhciStopPeriodic(ehciInstance);
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_DETACH);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_DETACH);
}
}
}
-static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
+void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
{
volatile usb_host_ehci_qh_t *vltQhPointer;
- volatile usb_host_ehci_qtd_t *vltQtdPointer;
+ usb_host_ehci_qtd_t *vltQtdPointer;
usb_host_transfer_t *transfer;
uint32_t backValue;
- volatile uint32_t *totalBytesAddress = NULL;
+ volatile uint32_t *totalBytesAddress = NULL;
usb_host_ehci_pipe_t *ehciPipePointer = ehciInstance->ehciRunningPipeList;
+ void *temp;
uint8_t timeoutLabel;
while (ehciPipePointer != NULL)
@@ -3876,13 +3942,13 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
case USB_ENDPOINT_BULK:
case USB_ENDPOINT_CONTROL:
vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh; /* pipe's qh */
- transfer = vltQhPointer->ehciTransferHead; /* qh's transfer */
+ transfer = vltQhPointer->ehciTransferHead; /* qh's transfer */
if ((transfer != NULL)) /* there is transfering data */
{
- timeoutLabel = 0;
- if (ehciInstance->deviceAttached != kEHCIDeviceAttached)
+ timeoutLabel = 0U;
+ if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceAttached)
{
- vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail;
+ vltQtdPointer = (usb_host_ehci_qtd_t *)transfer->union2.unitTail;
vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE; /* invalid next qtd */
vltQhPointer->transferOverlayResults[0] &=
@@ -3891,15 +3957,15 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
}
else
{
- if (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)
+ if (0U != (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))
{
- vltQtdPointer = (volatile usb_host_ehci_qtd_t *)vltQhPointer->currentQtdPointer;
+ vltQtdPointer = (usb_host_ehci_qtd_t *)vltQhPointer->currentQtdPointer;
totalBytesAddress = &(vltQhPointer->transferOverlayResults[0]);
}
else
{
- vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail;
- totalBytesAddress = ((uint32_t *)vltQtdPointer + 2);
+ vltQtdPointer = (usb_host_ehci_qtd_t *)transfer->union2.unitTail;
+ totalBytesAddress = &(vltQtdPointer->transferResults[0]);
}
backValue =
@@ -3908,7 +3974,7 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
if (vltQhPointer->timeOutLabel != backValue) /* use total bytes to reflect the time out */
{
vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
- vltQhPointer->timeOutLabel = backValue;
+ vltQhPointer->timeOutLabel = (uint16_t)backValue;
}
else
{
@@ -3916,7 +3982,7 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
* USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE
*/
(vltQhPointer->timeOutValue)--;
- if (vltQhPointer->timeOutValue == 0)
+ if (vltQhPointer->timeOutValue == 0U)
{
/* stop the qh schedule */
USB_HostEhciStopAsync(ehciInstance);
@@ -3931,22 +3997,24 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
vltQhPointer->transferOverlayResults[0] &=
(~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */
USB_HostEhciStartAsync(ehciInstance);
- timeoutLabel = 1;
+ timeoutLabel = 1U;
}
}
}
}
- if (timeoutLabel == 1)
+ if (timeoutLabel == 1U)
{
/* remove qtd from qh */
+ temp = (void *)vltQhPointer->ehciTransferTail;
while ((vltQtdPointer != NULL) &&
- (!(vltQtdPointer->transferResults[0] & EHCI_HOST_QTD_IOC_MASK)) &&
- (vltQtdPointer != (usb_host_ehci_qtd_t *)vltQhPointer->ehciTransferTail))
+ (0U == (vltQtdPointer->transferResults[0] & EHCI_HOST_QTD_IOC_MASK)) &&
+ (vltQtdPointer != (usb_host_ehci_qtd_t *)temp))
{
- vltQtdPointer = (volatile usb_host_ehci_qtd_t *)vltQtdPointer->nextQtdPointer;
+ vltQtdPointer = (usb_host_ehci_qtd_t *)vltQtdPointer->nextQtdPointer;
}
- if ((vltQtdPointer != NULL) && (!(vltQtdPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE)))
+ if ((vltQtdPointer != NULL) &&
+ (0U == (vltQtdPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE)))
{
vltQhPointer->nextQtdPointer =
vltQtdPointer->nextQtdPointer; /* start qh if there are other qtd that don't belong to
@@ -3956,38 +4024,41 @@ static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance)
USB_HostEhciQtdListRelease(ehciInstance, (usb_host_ehci_qtd_t *)(transfer->union1.unitHead),
(usb_host_ehci_qtd_t *)(transfer->union2.unitTail));
transfer->transferSofar = (transfer->transferLength < transfer->transferSofar) ?
- 0 :
+ 0U :
(transfer->transferLength - transfer->transferSofar);
vltQhPointer->ehciTransferHead = transfer->next;
- vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
+ vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE;
+ /* callback function is different from the current condition */
transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferFailed);
}
}
break;
default:
+ /*no action*/
break;
}
- ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = (usb_host_ehci_pipe_t *)temp;
}
}
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
static void USB_HostEhciTimer1(usb_host_ehci_instance_t *ehciInstance)
{
- if (ehciInstance->deviceAttached != kEHCIDeviceDetached)
+ if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceDetached)
{
if (kBus_EhciStartSuspend == ehciInstance->busSuspendStatus)
{
usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle;
- if (0 == ehciInstance->matchTick)
+ if (0U == ehciInstance->matchTick)
{
ehciInstance->matchTick = hostPointer->hwTick;
}
else
{
- if ((hostPointer->hwTick - ehciInstance->matchTick) >= 5)
+ if ((hostPointer->hwTick - ehciInstance->matchTick) >= 5U)
{
ehciInstance->ehciIpBase->USBCMD &= ~USBHS_USBCMD_RS_MASK;
ehciInstance->ehciIpBase->USBSTS |= USBHS_USBSTS_SRI_MASK;
@@ -4004,9 +4075,9 @@ static void USB_HostEhciTimer1(usb_host_ehci_instance_t *ehciInstance)
ehciInstance->registerPhyBase->PWD = 0xFFFFFFFFU;
- while (ehciInstance->registerPhyBase->CTRL & (USBPHY_CTRL_UTMI_SUSPENDM_MASK))
+ while (0U != (ehciInstance->registerPhyBase->CTRL & (USBPHY_CTRL_UTMI_SUSPENDM_MASK)))
{
- __ASM("nop");
+ __NOP();
}
#if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
@@ -4018,8 +4089,8 @@ static void USB_HostEhciTimer1(usb_host_ehci_instance_t *ehciInstance)
ehciInstance->ehciIpBase->USBGENCTRL = USBHS_USBGENCTRL_WU_IE_MASK;
#endif
ehciInstance->registerPhyBase->CTRL |= USBPHY_CTRL_CLKGATE_MASK;
- hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
- kUSB_HostEventSuspended); /* call host callback function */
+ (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
+ kUSB_HostEventSuspended); /* call host callback function */
ehciInstance->busSuspendStatus = kBus_EhciSuspended;
}
}
@@ -4027,17 +4098,17 @@ static void USB_HostEhciTimer1(usb_host_ehci_instance_t *ehciInstance)
else if (kBus_EhciStartResume == ehciInstance->busSuspendStatus)
{
usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle;
- if (!(ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK))
+ if (0U == (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK))
{
ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_WKDS_MASK;
- if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
USB_HostEhciStartAsync(ehciInstance);
USB_HostEhciStartPeriodic(ehciInstance);
}
- hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
- kUSB_HostEventResumed); /* call host callback function */
- hostPointer->suspendedDevice = NULL;
+ (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
+ kUSB_HostEventResumed); /* call host callback function */
+ hostPointer->suspendedDevice = NULL;
ehciInstance->busSuspendStatus = kBus_EhciIdle;
ehciInstance->ehciIpBase->USBINTR &= ~(USBHS_USBINTR_TIE1_MASK);
}
@@ -4059,30 +4130,31 @@ usb_status_t USB_HostEhciCreate(uint8_t controllerId,
usb_host_controller_handle *controllerHandle)
{
uint32_t index = 0;
- usb_osa_status_t osaStatus;
+ osa_status_t osaStatus;
usb_host_ehci_instance_t *ehciInstance;
uint32_t usbhsBaseAddrs[] = USBHS_BASE_ADDRS;
- usb_host_ehci_data_t *usbHostEhciData[] = USB_HOST_EHCI_DATA_ARRAY;
- uint8_t *usbHostEhciFrameList[] = USB_HOST_EHCI_FRAME_LIST_ARRAY;
+ usb_host_ehci_data_t *usbHostEhciData[USB_HOST_CONFIG_EHCI];
uint32_t *framePointer;
+ void *temp;
+ uint8_t instanceIndex = 0U;
- if ((uint32_t)(controllerId - kUSB_ControllerEhci0) >= (sizeof(usbhsBaseAddrs) / sizeof(usbhsBaseAddrs[0])))
+ if ((controllerId - (uint8_t)kUSB_ControllerEhci0) >= (sizeof(usbhsBaseAddrs) / sizeof(usbhsBaseAddrs[0])))
{
return kStatus_USB_ControllerNotFound;
}
*controllerHandle = NULL;
- ehciInstance = (usb_host_ehci_instance_t *)USB_OsaMemoryAllocate(
+ ehciInstance = (usb_host_ehci_instance_t *)OSA_MemoryAllocate(
sizeof(usb_host_ehci_instance_t)); /* malloc host ehci instance */
if (ehciInstance == NULL)
{
return kStatus_USB_AllocFail;
}
- ehciInstance->controllerId = controllerId;
- ehciInstance->hostHandle = upperLayerHandle;
- ehciInstance->deviceAttached = kEHCIDeviceDetached;
- ehciInstance->ehciIpBase = (USBHS_Type *)
- usbhsBaseAddrs[controllerId - kUSB_ControllerEhci0]; /* operate ehci ip through the base address */
+ ehciInstance->controllerId = controllerId;
+ ehciInstance->hostHandle = upperLayerHandle;
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached;
+ ehciInstance->ehciIpBase = (USBHS_Type *)
+ usbhsBaseAddrs[controllerId - (uint8_t)kUSB_ControllerEhci0]; /* operate ehci ip through the base address */
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
ehciInstance->busSuspendStatus = kBus_EhciIdle;
@@ -4097,95 +4169,150 @@ usb_status_t USB_HostEhciCreate(uint8_t controllerId,
#endif
- if (USB_HostEhciResetIP(ehciInstance) != kStatus_USB_Success) /* reset ehci ip */
+ if ((USB_HostEhciResetIP(ehciInstance) != kStatus_USB_Success) ||
+ ((ehciInstance->controllerId < (uint8_t)kUSB_ControllerEhci0))) /* reset ehci ip */
+ {
+ OSA_MemoryFree(ehciInstance);
+ return kStatus_USB_Error;
+ }
+
+#if (USB_HOST_CONFIG_EHCI == 1U)
+ if (0U == usbHostEhciFramListStatus[0])
+ {
+ usbHostEhciFramListStatus[0] = 1U;
+ instanceIndex = 0U;
+ ehciInstance->ehciFrameList = &s_UsbHostEhciFrameList1[0];
+ }
+#elif (USB_HOST_CONFIG_EHCI == 2U)
+ if (0U == usbHostEhciFramListStatus[0])
+ {
+ usbHostEhciFramListStatus[0] = 1U;
+ instanceIndex = 0U;
+ ehciInstance->ehciFrameList = &s_UsbHostEhciFrameList1[0];
+ }
+ else if (0U == usbHostEhciFramListStatus[1])
+ {
+ usbHostEhciFramListStatus[1] = 1U;
+ instanceIndex = 1U;
+ ehciInstance->ehciFrameList = &s_UsbHostEhciFrameList2[0];
+ }
+ else
{
- USB_OsaMemoryFree(ehciInstance);
+ /*no action*/
+ }
+#endif
+ if (ehciInstance->ehciFrameList == NULL)
+ {
+ OSA_MemoryFree(ehciInstance);
return kStatus_USB_Error;
}
- /* initialize ehci frame list */
- ehciInstance->ehciFrameList = usbHostEhciFrameList[ehciInstance->controllerId - kUSB_ControllerEhci0];
+#if (USB_HOST_CONFIG_EHCI == 1U)
+ usbHostEhciData[0] = &s_UsbHostEhciData1;
+#elif (USB_HOST_CONFIG_EHCI == 2U)
+ usbHostEhciData[0] = &s_UsbHostEhciData1;
+ usbHostEhciData[1] = &s_UsbHostEhciData2;
+#else
+#error "Please increase the instance count."
+#endif
- /* initialize ehci units */
- ehciInstance->ehciUnitBase = (uint32_t *)(usbHostEhciData[ehciInstance->controllerId - kUSB_ControllerEhci0]);
+ temp = (void *)usbHostEhciData[instanceIndex];
+ ehciInstance->ehciUnitBase = (uint32_t *)(temp);
/* initialize qh/qtd/itd/sitd/iso list */
- ehciInstance->ehciQhList = (usb_host_ehci_qh_t *)((uint32_t)(ehciInstance->ehciUnitBase));
+ ehciInstance->ehciQhList = (usb_host_ehci_qh_t *)((uint32_t)(ehciInstance->ehciUnitBase));
ehciInstance->ehciQtdHead = (usb_host_ehci_qtd_t *)((uint32_t)ehciInstance->ehciQhList +
(sizeof(usb_host_ehci_qh_t) * USB_HOST_CONFIG_EHCI_MAX_QH));
ehciInstance->ehciItdList = (usb_host_ehci_itd_t *)((uint32_t)ehciInstance->ehciQtdHead +
(sizeof(usb_host_ehci_qtd_t) * USB_HOST_CONFIG_EHCI_MAX_QTD));
- ehciInstance->ehciSitdList = ehciInstance->ehciSitdIndexBase =
+#if ((defined(USB_HOST_CONFIG_EHCI_MAX_ITD)) && (USB_HOST_CONFIG_EHCI_MAX_ITD > 0U))
+ /* If one ITD's first 32 bytes and next 32 bytes are in different 4K region,
+ * the ITD need move 32 bytes because the ITD cannot cross over 4K boundary.
+ */
+ index = ((((((uint32_t)(ehciInstance->ehciItdList)) + 4095U) & 0xFFFFF000U) -
+ ((uint32_t)(ehciInstance->ehciItdList))) >>
+ 5U);
+ if (((index / 3U) < USB_HOST_CONFIG_EHCI_MAX_ITD) && ((index % 3U) == 1U))
+ {
+ ehciInstance->ehciItdList = (usb_host_ehci_itd_t *)(((uint32_t)(ehciInstance->ehciItdList)) + 32U);
+ }
+#endif
+ ehciInstance->ehciSitdIndexBase =
(usb_host_ehci_sitd_t *)((uint32_t)ehciInstance->ehciItdList +
(sizeof(usb_host_ehci_itd_t) * USB_HOST_CONFIG_EHCI_MAX_ITD));
- ehciInstance->ehciIsoList = (usb_host_ehci_iso_t *)((uint32_t)ehciInstance->ehciSitdList +
+ ehciInstance->ehciSitdList = ehciInstance->ehciSitdIndexBase;
+ ehciInstance->ehciIsoList = (usb_host_ehci_iso_t *)((uint32_t)ehciInstance->ehciSitdList +
(sizeof(usb_host_ehci_sitd_t) * USB_HOST_CONFIG_EHCI_MAX_SITD));
ehciInstance->ehciPipeIndexBase =
(usb_host_ehci_pipe_t *)((uint32_t)ehciInstance->ehciIsoList +
(sizeof(usb_host_ehci_iso_t) * USB_HOST_EHCI_ISO_NUMBER));
- for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_QH; ++index)
+ for (index = 1U; index < USB_HOST_CONFIG_EHCI_MAX_QH; ++index)
{
- ehciInstance->ehciQhList[index - 1].horizontalLinkPointer = (uint32_t)(&ehciInstance->ehciQhList[index]);
+ ehciInstance->ehciQhList[index - 1U].horizontalLinkPointer = (uint32_t)(&ehciInstance->ehciQhList[index]);
}
- ehciInstance->ehciQhList[USB_HOST_CONFIG_EHCI_MAX_QH - 1].horizontalLinkPointer = (uint32_t)NULL;
+ ehciInstance->ehciQhList[USB_HOST_CONFIG_EHCI_MAX_QH - 1U].horizontalLinkPointer = 0U;
for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_QTD; ++index)
{
- ehciInstance->ehciQtdHead[index - 1].nextQtdPointer = (uint32_t)(&ehciInstance->ehciQtdHead[index]);
+ ehciInstance->ehciQtdHead[index - 1U].nextQtdPointer = (uint32_t)(&ehciInstance->ehciQtdHead[index]);
}
- ehciInstance->ehciQtdNumber = USB_HOST_CONFIG_EHCI_MAX_QTD;
- ehciInstance->ehciQtdHead[USB_HOST_CONFIG_EHCI_MAX_QTD - 1].nextQtdPointer = (uint32_t)NULL;
- ehciInstance->ehciQtdTail = &ehciInstance->ehciQtdHead[USB_HOST_CONFIG_EHCI_MAX_QTD - 1];
+ ehciInstance->ehciQtdNumber = USB_HOST_CONFIG_EHCI_MAX_QTD;
+ ehciInstance->ehciQtdHead[USB_HOST_CONFIG_EHCI_MAX_QTD - 1U].nextQtdPointer = 0U;
+ ehciInstance->ehciQtdTail = &ehciInstance->ehciQtdHead[USB_HOST_CONFIG_EHCI_MAX_QTD - 1U];
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_ITD; ++index)
{
- ehciInstance->ehciItdList[index - 1].nextLinkPointer = (uint32_t)(&ehciInstance->ehciItdList[index]);
+ ehciInstance->ehciItdList[index - 1U].nextItdPointer =
+ (usb_host_ehci_itd_t *)(&ehciInstance->ehciItdList[index]);
}
- ehciInstance->ehciItdNumber = USB_HOST_CONFIG_EHCI_MAX_ITD;
- ehciInstance->ehciItdList[USB_HOST_CONFIG_EHCI_MAX_ITD - 1].nextLinkPointer = (uint32_t)NULL;
+ ehciInstance->ehciItdNumber = USB_HOST_CONFIG_EHCI_MAX_ITD;
+ ehciInstance->ehciItdList[USB_HOST_CONFIG_EHCI_MAX_ITD - 1U].nextItdPointer = NULL;
#endif /* USB_HOST_CONFIG_EHCI_MAX_ITD */
#if ((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD))
for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_SITD; ++index)
{
- ehciInstance->ehciSitdList[index - 1].nextLinkPointer = (uint32_t)(&ehciInstance->ehciSitdList[index]);
+ ehciInstance->ehciSitdList[index - 1U].nextLinkPointer = (uint32_t)(&ehciInstance->ehciSitdList[index]);
}
- ehciInstance->ehciSitdNumber = USB_HOST_CONFIG_EHCI_MAX_SITD;
- ehciInstance->ehciSitdList[USB_HOST_CONFIG_EHCI_MAX_SITD - 1].nextLinkPointer = (uint32_t)NULL;
+ ehciInstance->ehciSitdNumber = USB_HOST_CONFIG_EHCI_MAX_SITD;
+ ehciInstance->ehciSitdList[USB_HOST_CONFIG_EHCI_MAX_SITD - 1U].nextLinkPointer = 0U;
#endif /* USB_HOST_CONFIG_EHCI_MAX_SITD */
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
for (index = 1; index < USB_HOST_EHCI_ISO_NUMBER; ++index)
{
- ehciInstance->ehciIsoList[index - 1].next = &ehciInstance->ehciIsoList[index];
+ ehciInstance->ehciIsoList[index - 1U].next = &ehciInstance->ehciIsoList[index];
}
- ehciInstance->ehciIsoList[USB_HOST_EHCI_ISO_NUMBER - 1].next = NULL;
+ ehciInstance->ehciIsoList[USB_HOST_EHCI_ISO_NUMBER - 1U].next = NULL;
#endif
/* initialize pipes */
ehciInstance->ehciPipeList = ehciInstance->ehciPipeIndexBase;
for (index = 1; index < USB_HOST_CONFIG_MAX_PIPES; ++index)
{
- ehciInstance->ehciPipeList[index - 1].pipeCommon.next = (usb_host_pipe_t *)&ehciInstance->ehciPipeList[index];
+ temp = (void *)&ehciInstance->ehciPipeList[index];
+ ehciInstance->ehciPipeList[index - 1U].pipeCommon.next = (usb_host_pipe_t *)temp;
}
/* initialize mutext */
- osaStatus = USB_OsaMutexCreate(&ehciInstance->ehciMutex);
- if (osaStatus != kStatus_USB_OSA_Success)
+ ehciInstance->ehciMutex = (osa_mutex_handle_t)(&ehciInstance->mutexBuffer[0]);
+ osaStatus = OSA_MutexCreate(ehciInstance->ehciMutex);
+ if (osaStatus != KOSA_StatusSuccess)
{
#ifdef HOST_ECHO
usb_echo("ehci mutex init fail\r\n");
#endif
- USB_OsaMemoryFree(ehciInstance);
+ OSA_MemoryFree(ehciInstance);
return kStatus_USB_Error;
}
/* initialize task event */
- osaStatus = USB_OsaEventCreate(&ehciInstance->taskEventHandle, 1);
- if (osaStatus != kStatus_USB_OSA_Success)
+ ehciInstance->taskEventHandle = (osa_event_handle_t)&ehciInstance->taskEventHandleBuffer[0];
+ osaStatus = OSA_EventCreate(ehciInstance->taskEventHandle, 1);
+ if (osaStatus != KOSA_StatusSuccess)
{
#ifdef HOST_ECHO
usb_echo("ehci event init fail\r\n");
#endif
- USB_OsaMutexDestroy(ehciInstance->ehciMutex);
- USB_OsaMemoryFree(ehciInstance);
+ (void)OSA_MutexDestroy(ehciInstance->ehciMutex);
+ OSA_MemoryFree(ehciInstance);
return kStatus_USB_Error;
}
@@ -4193,22 +4320,23 @@ usb_status_t USB_HostEhciCreate(uint8_t controllerId,
ehciInstance->shedFirstQh = ehciInstance->ehciQhList;
ehciInstance->ehciQhList =
(usb_host_ehci_qh_t *)(ehciInstance->ehciQhList->horizontalLinkPointer & EHCI_HOST_POINTER_ADDRESS_MASK);
- ehciInstance->shedFirstQh->staticEndpointStates[0] |= (1 << EHCI_HOST_QH_H_SHIFT); /* first qh */
- ehciInstance->shedFirstQh->horizontalLinkPointer = EHCI_HOST_T_INVALID_VALUE;
- ehciInstance->shedFirstQh->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE;
- ehciInstance->shedFirstQh->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
+ ehciInstance->shedFirstQh->staticEndpointStates[0] |= (1UL << EHCI_HOST_QH_H_SHIFT); /* first qh */
+ ehciInstance->shedFirstQh->horizontalLinkPointer = EHCI_HOST_T_INVALID_VALUE;
+ ehciInstance->shedFirstQh->currentQtdPointer = EHCI_HOST_T_INVALID_VALUE;
+ ehciInstance->shedFirstQh->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
ehciInstance->shedFirstQh->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE;
ehciInstance->shedFirstQh->horizontalLinkPointer =
(uint32_t)((uint32_t)(ehciInstance->shedFirstQh) | EHCI_HOST_POINTER_TYPE_QH);
/* initialize periodic list */
- framePointer = (uint32_t *)ehciInstance->ehciFrameList;
+ temp = (void *)ehciInstance->ehciFrameList;
+ framePointer = (uint32_t *)temp;
for (index = 0; index < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE; ++index)
{
framePointer[index] = EHCI_HOST_T_INVALID_VALUE;
}
- USB_HostEhciStartIP(ehciInstance); /* start ehci ip */
+ (void)USB_HostEhciStartIP(ehciInstance); /* start ehci ip */
*controllerHandle = ehciInstance;
@@ -4223,10 +4351,29 @@ usb_status_t USB_HostEhciDestory(usb_host_controller_handle controllerHandle)
ehciInstance->ehciIpBase->USBINTR = 0;
/* stop the controller */
ehciInstance->ehciIpBase->USBCMD = 0;
- /* free memory */
- USB_OsaMutexDestroy(ehciInstance->ehciMutex);
- USB_OsaEventDestroy(ehciInstance->taskEventHandle);
- USB_OsaMemoryFree(ehciInstance);
+/* free memory */
+#if (USB_HOST_CONFIG_EHCI == 1U)
+ if (ehciInstance->ehciFrameList == &s_UsbHostEhciFrameList1[0])
+ {
+ usbHostEhciFramListStatus[0] = 0;
+ }
+#elif (USB_HOST_CONFIG_EHCI == 2U)
+ if (ehciInstance->ehciFrameList == &s_UsbHostEhciFrameList1[0])
+ {
+ usbHostEhciFramListStatus[0] = 0;
+ }
+ else if (ehciInstance->ehciFrameList == &s_UsbHostEhciFrameList2[0])
+ {
+ usbHostEhciFramListStatus[1] = 0;
+ }
+ else
+ {
+ /*no action*/
+ }
+#endif
+ (void)OSA_MutexDestroy(ehciInstance->ehciMutex);
+ (void)OSA_EventDestroy(ehciInstance->taskEventHandle);
+ OSA_MemoryFree(ehciInstance);
return kStatus_USB_Success;
}
@@ -4237,15 +4384,17 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
{
usb_host_ehci_pipe_t *ehciPipePointer = NULL;
usb_status_t status;
- uint32_t speed;
+ uint32_t speed = 0;
usb_host_ehci_instance_t *ehciInstance = (usb_host_ehci_instance_t *)controllerHandle;
-
+ uint32_t val32;
+ void *temp;
/* get one pipe */
USB_HostEhciLock();
if (ehciInstance->ehciPipeList != NULL)
{
- ehciPipePointer = ehciInstance->ehciPipeList;
- ehciInstance->ehciPipeList = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next;
+ ehciPipePointer = ehciInstance->ehciPipeList;
+ temp = (void *)ehciPipePointer->pipeCommon.next;
+ ehciInstance->ehciPipeList = (usb_host_ehci_pipe_t *)temp;
}
USB_HostEhciUnlock();
if (ehciPipePointer == NULL)
@@ -4257,43 +4406,53 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
}
/* initialize pipe informations */
- USB_HostEhciZeroMem((uint32_t *)ehciPipePointer, sizeof(usb_host_ehci_pipe_t) / 4);
- ehciPipePointer->pipeCommon.deviceHandle = pipeInit->devInstance;
+ USB_HostEhciZeroMem((void *)ehciPipePointer, sizeof(usb_host_ehci_pipe_t) / 4U);
+ ehciPipePointer->pipeCommon.deviceHandle = pipeInit->devInstance;
ehciPipePointer->pipeCommon.endpointAddress = pipeInit->endpointAddress;
- ehciPipePointer->pipeCommon.direction = pipeInit->direction;
- ehciPipePointer->pipeCommon.interval = pipeInit->interval;
- ehciPipePointer->pipeCommon.maxPacketSize = pipeInit->maxPacketSize;
- ehciPipePointer->pipeCommon.pipeType = pipeInit->pipeType;
- ehciPipePointer->pipeCommon.numberPerUframe = pipeInit->numberPerUframe;
- if (ehciPipePointer->pipeCommon.numberPerUframe == 0)
+ ehciPipePointer->pipeCommon.direction = pipeInit->direction;
+ ehciPipePointer->pipeCommon.interval = pipeInit->interval;
+ ehciPipePointer->pipeCommon.maxPacketSize = pipeInit->maxPacketSize;
+ ehciPipePointer->pipeCommon.pipeType = pipeInit->pipeType;
+ ehciPipePointer->pipeCommon.numberPerUframe = pipeInit->numberPerUframe + 1U;
+ if (ehciPipePointer->pipeCommon.numberPerUframe > 3U)
{
- ehciPipePointer->pipeCommon.numberPerUframe = 1;
+ ehciPipePointer->pipeCommon.numberPerUframe = 3U;
}
- ehciPipePointer->pipeCommon.nakCount = pipeInit->nakCount;
- ehciPipePointer->pipeCommon.nextdata01 = 0;
- ehciPipePointer->ehciQh = NULL;
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, &speed);
- if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_ISOCHRONOUS)
+ ehciPipePointer->pipeCommon.nakCount = pipeInit->nakCount;
+ ehciPipePointer->pipeCommon.nextdata01 = 0U;
+ ehciPipePointer->ehciQh = NULL;
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
+ if ((ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_ISOCHRONOUS) ||
+ (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_INTERRUPT))
{
- ehciPipePointer->pipeCommon.interval =
- (1 << (ehciPipePointer->pipeCommon.interval - 1)); /* iso interval is the power of 2 */
- }
- else if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_INTERRUPT)
- {
- if (speed == USB_SPEED_HIGH)
+ if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_ISOCHRONOUS)
{
ehciPipePointer->pipeCommon.interval =
- (1 << (ehciPipePointer->pipeCommon.interval - 1)); /* HS interrupt interval is the power of 2 */
+ (uint16_t)(1UL << (ehciPipePointer->pipeCommon.interval - 1U)); /* iso interval is the power of 2 */
}
else
{
- ehciPipePointer->pipeCommon.interval = USB_HostEhciGet2PowerValue(
- ehciPipePointer->pipeCommon
- .interval); /* FS/LS interrupt interval should be the power of 2, it is used for ehci bandwidth */
+ if (speed == USB_SPEED_HIGH)
+ {
+ ehciPipePointer->pipeCommon.interval = (uint16_t)(
+ 1UL << (ehciPipePointer->pipeCommon.interval - 1U)); /* HS interrupt interval is the power of 2 */
+ }
+ else
+ {
+ ehciPipePointer->pipeCommon.interval = USB_HostEhciGet2PowerValue(
+ (uint8_t)ehciPipePointer->pipeCommon.interval); /* FS/LS interrupt interval should be the power of
+ 2, it is used for ehci bandwidth */
+ }
+ }
+
+ if ((speed == USB_SPEED_HIGH) && (ehciPipePointer->pipeCommon.interval < 8U))
+ {
+ val32 = ehciInstance->ehciIpBase->USBCMD;
+ val32 &= (~USBHS_USBCMD_ITC_MASK);
+ val32 |= USBHS_USBCMD_ITC((ehciPipePointer->pipeCommon.interval));
+ ehciInstance->ehciIpBase->USBCMD = val32;
}
- }
- else
- {
}
/* save the micro-frame interval, it is convenient for the interval process */
@@ -4303,7 +4462,7 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
}
else
{
- ehciPipePointer->uframeInterval = 8 * ehciPipePointer->pipeCommon.interval;
+ ehciPipePointer->uframeInterval = 8U * ehciPipePointer->pipeCommon.interval;
}
/* open pipe */
@@ -4334,15 +4493,17 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
{
/* release pipe */
USB_HostEhciLock();
- ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciPipeList;
- ehciInstance->ehciPipeList = ehciPipePointer;
+ temp = (void *)ehciInstance->ehciPipeList;
+ ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp;
+ ehciInstance->ehciPipeList = ehciPipePointer;
USB_HostEhciUnlock();
return status;
}
/* add pipe to run pipe list */
USB_HostEhciLock();
- ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciRunningPipeList;
+ temp = (void *)ehciInstance->ehciRunningPipeList;
+ ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp;
ehciInstance->ehciRunningPipeList = ehciPipePointer;
USB_HostEhciUnlock();
@@ -4353,43 +4514,50 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
usb_status_t USB_HostEhciClosePipe(usb_host_controller_handle controllerHandle, usb_host_pipe_handle pipeHandle)
{
usb_host_ehci_instance_t *ehciInstance = (usb_host_ehci_instance_t *)controllerHandle;
- usb_host_ehci_pipe_t *ehciPipePointer = (usb_host_ehci_pipe_t *)pipeHandle;
- usb_host_pipe_t *prevPointer = NULL;
+ usb_host_ehci_pipe_t *ehciPipePointer = (usb_host_ehci_pipe_t *)pipeHandle;
+ usb_host_pipe_t *prevPointer = NULL;
+ void *temp;
+ void *tempCurrent;
switch (ehciPipePointer->pipeCommon.pipeType)
{
case USB_ENDPOINT_BULK:
case USB_ENDPOINT_CONTROL:
- USB_HostEhciCloseControlBulk(ehciInstance, ehciPipePointer);
+ (void)USB_HostEhciCloseControlBulk(ehciInstance, ehciPipePointer);
break;
case USB_ENDPOINT_INTERRUPT:
- USB_HostEhciCloseInterrupt(ehciInstance, ehciPipePointer);
+ (void)USB_HostEhciCloseInterrupt(ehciInstance, ehciPipePointer);
break;
#if (((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) || \
((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)))
case USB_ENDPOINT_ISOCHRONOUS:
- USB_HostEhciCloseIso(ehciInstance, ehciPipePointer);
+ (void)USB_HostEhciCloseIso(ehciInstance, ehciPipePointer);
break;
#endif
default:
+ /*no action*/
break;
}
/* delete pipe from run pipe list */
USB_HostEhciLock();
- prevPointer = (usb_host_pipe_t *)ehciInstance->ehciRunningPipeList;
- if (prevPointer == (usb_host_pipe_t *)ehciPipePointer)
+ temp = (void *)ehciInstance->ehciRunningPipeList;
+ prevPointer = (usb_host_pipe_t *)temp;
+ tempCurrent = (void *)ehciPipePointer;
+ if (prevPointer == (usb_host_pipe_t *)tempCurrent)
{
- ehciInstance->ehciRunningPipeList = (usb_host_ehci_pipe_t *)(prevPointer->next);
+ temp = (void *)prevPointer->next;
+ ehciInstance->ehciRunningPipeList = (usb_host_ehci_pipe_t *)(temp);
}
else
{
while (prevPointer != NULL)
{
- if (prevPointer->next == (usb_host_pipe_t *)ehciPipePointer)
+ temp = (void *)ehciPipePointer;
+ if (prevPointer->next == (usb_host_pipe_t *)temp)
{
prevPointer->next = ehciPipePointer->pipeCommon.next;
break;
@@ -4404,8 +4572,9 @@ usb_status_t USB_HostEhciClosePipe(usb_host_controller_handle controllerHandle,
/* release pipe */
USB_HostEhciLock();
- ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciPipeList;
- ehciInstance->ehciPipeList = ehciPipePointer;
+ temp = (void *)ehciInstance->ehciPipeList;
+ ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp;
+ ehciInstance->ehciPipeList = ehciPipePointer;
USB_HostEhciUnlock();
return kStatus_USB_Success;
@@ -4416,11 +4585,11 @@ usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerHandle,
usb_host_transfer_t *transfer)
{
usb_host_ehci_instance_t *ehciInstance = (usb_host_ehci_instance_t *)controllerHandle;
- usb_host_ehci_pipe_t *ehciPipePointer = (usb_host_ehci_pipe_t *)pipeHandle;
- usb_status_t status = kStatus_USB_Success;
+ usb_host_ehci_pipe_t *ehciPipePointer = (usb_host_ehci_pipe_t *)pipeHandle;
+ usb_status_t status = kStatus_USB_Success;
#if (((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) || \
((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)))
- uint32_t speed;
+ uint32_t speed = 0U;
#endif
switch (ehciPipePointer->pipeCommon.pipeType)
@@ -4435,8 +4604,8 @@ usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerHandle,
#if (((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) || \
((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)))
case USB_ENDPOINT_ISOCHRONOUS:
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed,
- &speed);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceSpeed, &speed);
if (speed == USB_SPEED_HIGH)
{
#if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD))
@@ -4455,6 +4624,7 @@ usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerHandle,
#endif
default:
+ /*no action*/
break;
}
return status;
@@ -4469,22 +4639,22 @@ usb_status_t USB_HostEhciReadpipe(usb_host_controller_handle controllerHandle,
usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandle, uint32_t ioctlEvent, void *ioctlParam)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_ehci_instance_t *ehciInstance = (usb_host_ehci_instance_t *)controllerHandle;
usb_host_cancel_param_t *param;
usb_host_ehci_pipe_t *ehciPipePointer;
volatile usb_host_ehci_qh_t *vltQhPointer;
- uint32_t deviceAddress;
-
+ uint32_t deviceAddress = 0;
+ usb_host_controller_control_t controlCode = (usb_host_controller_control_t)ioctlEvent;
if (controllerHandle == NULL)
{
return kStatus_USB_InvalidHandle;
}
- switch (ioctlEvent)
+ switch (controlCode)
{
case kUSB_HostCancelTransfer: /* cancel pipe or one transfer */
- param = (usb_host_cancel_param_t *)ioctlParam;
+ param = (usb_host_cancel_param_t *)ioctlParam;
status = USB_HostEhciCancelPipe(ehciInstance, (usb_host_ehci_pipe_t *)param->pipeHandle, param->transfer);
break;
@@ -4498,18 +4668,19 @@ usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandle, uint
case kUSB_HostUpdateControlEndpointAddress:
ehciPipePointer = (usb_host_ehci_pipe_t *)ioctlParam;
- vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
+ vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
/* update address */
- USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress,
- &deviceAddress);
+ (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle,
+ (uint32_t)kUSB_HostGetDeviceAddress, &deviceAddress);
vltQhPointer->staticEndpointStates[0] |= deviceAddress;
+ USB_HostEhciDelay(ehciInstance->ehciIpBase, 2U);
break;
case kUSB_HostUpdateControlPacketSize:
ehciPipePointer = (usb_host_ehci_pipe_t *)ioctlParam;
- vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
+ vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh;
USB_HostEhciLock();
- if (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)
+ if (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK))
{
USB_HostEhciStopAsync(ehciInstance);
/* update max packet size */
@@ -4527,8 +4698,13 @@ usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandle, uint
}
USB_HostEhciUnlock();
break;
-
+#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
+ case kUSB_HostTestModeInit: /* test mode control */
+ USB_HostEhciTestModeInit((usb_host_device_instance_t *)ioctlParam);
+ break;
+#endif
default:
+ status = kStatus_USB_NotSupported;
break;
}
return status;
@@ -4546,44 +4722,44 @@ void USB_HostEhciTaskFunction(void *hostHandle)
}
ehciInstance = (usb_host_ehci_instance_t *)((usb_host_instance_t *)hostHandle)->controllerHandle;
- if (USB_OsaEventWait(ehciInstance->taskEventHandle, 0xFF, 0, 0, &bitSet) ==
- kStatus_USB_OSA_Success) /* wait all event */
+ if (OSA_EventWait(ehciInstance->taskEventHandle, 0xFF, 0, USB_OSA_WAIT_TIMEOUT, &bitSet) ==
+ KOSA_StatusSuccess) /* wait all event */
{
- if (bitSet & EHCI_TASK_EVENT_PORT_CHANGE) /* port change */
+ if (0U != (bitSet & EHCI_TASK_EVENT_PORT_CHANGE)) /* port change */
{
USB_HostEhciPortChange(ehciInstance);
}
- if (bitSet & EHCI_TASK_EVENT_TIMER0) /* timer0 */
+ if (0U != (bitSet & EHCI_TASK_EVENT_TIMER0)) /* timer0 */
{
USB_HostEhciTimer0(ehciInstance);
}
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
- if (bitSet & EHCI_TASK_EVENT_TIMER1) /* timer1 */
+ if (0U != (bitSet & EHCI_TASK_EVENT_TIMER1)) /* timer1 */
{
USB_HostEhciTimer1(ehciInstance);
}
#endif
- if (ehciInstance->deviceAttached == kEHCIDeviceAttached)
+ if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached))
{
- if (bitSet & EHCI_TASK_EVENT_TRANSACTION_DONE) /* transaction done */
+ if (0U != (bitSet & EHCI_TASK_EVENT_TRANSACTION_DONE)) /* transaction done */
{
USB_HostEhciTransactionDone(ehciInstance);
}
- if (bitSet & EHCI_TASK_EVENT_DEVICE_DETACH) /* device detach */
+ if (0U != (bitSet & EHCI_TASK_EVENT_DEVICE_DETACH)) /* device detach */
{
ehciInstance->ehciIpBase->USBINTR &=
(~USBHS_USBINTR_PCE_MASK); /* disable attach, enable when the detach process is done */
- ehciInstance->deviceAttached = kEHCIDeviceDetached;
- USB_HostDetachDevice(ehciInstance->hostHandle, 0, 0);
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached;
+ (void)USB_HostDetachDevice(ehciInstance->hostHandle, 0, 0);
}
}
- else if (ehciInstance->deviceAttached != kEHCIDeviceAttached)
+ else if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceAttached)
{
- if (bitSet & EHCI_TASK_EVENT_DEVICE_ATTACH) /* device is attached */
+ if (0U != (bitSet & EHCI_TASK_EVENT_DEVICE_ATTACH)) /* device is attached */
{
USB_HostEhciStartAsync(ehciInstance);
USB_HostEhciStartPeriodic(ehciInstance);
@@ -4591,12 +4767,13 @@ void USB_HostEhciTaskFunction(void *hostHandle)
if (USB_HostAttachDevice(ehciInstance->hostHandle, ehciInstance->firstDeviceSpeed, 0, 0, 1,
&deviceHandle) == kStatus_USB_Success)
{
- ehciInstance->deviceAttached = kEHCIDeviceAttached;
+ ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceAttached;
}
}
}
else
{
+ /*no action*/
}
}
}
@@ -4616,18 +4793,18 @@ void USB_HostEhciIsrFunction(void *hostHandle)
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
#if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
- if (ehciInstance->registerNcBase->USB_OTGn_CTRL & USBNC_USB_OTGn_CTRL_WIE_MASK)
+ if (0U != (ehciInstance->registerNcBase->USB_OTGn_CTRL & USBNC_USB_OTGn_CTRL_WIE_MASK))
{
usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle;
ehciInstance->registerNcBase->USB_OTGn_CTRL &= ~USBNC_USB_OTGn_CTRL_WIE_MASK;
- hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
- kUSB_HostEventDetectResume); /* call host callback function */
-
- while (!(ehciInstance->registerNcBase->USB_OTGn_PHY_CTRL_0 & USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_MASK))
+ (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
+ kUSB_HostEventDetectResume); /* call host callback function */
+#if (defined(USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_MASK))
+ while (0U == (ehciInstance->registerNcBase->USB_OTGn_PHY_CTRL_0 & USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_MASK))
{
}
-
- if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)
+#endif
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
USB_HostEhciStartAsync(ehciInstance);
USB_HostEhciStartPeriodic(ehciInstance);
@@ -4640,25 +4817,27 @@ void USB_HostEhciIsrFunction(void *hostHandle)
}
else
{
+ /*no action*/
}
}
else
{
+ /*no action*/
}
#else
- if (ehciInstance->ehciIpBase->USBGENCTRL & USBHS_USBGENCTRL_WU_IE_MASK)
+ if (0U != (ehciInstance->ehciIpBase->USBGENCTRL & USBHS_USBGENCTRL_WU_IE_MASK))
{
usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle;
- hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
- kUSB_HostEventDetectResume); /* call host callback function */
+ (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
+ kUSB_HostEventDetectResume); /* call host callback function */
- while (!(USBPHY->PLL_SIC & USBPHY_PLL_SIC_PLL_LOCK_MASK))
+ while (0U == (USBPHY->PLL_SIC & USBPHY_PLL_SIC_PLL_LOCK_MASK))
{
}
ehciInstance->ehciIpBase->USBGENCTRL |= USBHS_USBGENCTRL_WU_INT_CLR_MASK;
ehciInstance->ehciIpBase->USBGENCTRL &= ~USBHS_USBGENCTRL_WU_IE_MASK;
- if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
USB_HostEhciStartAsync(ehciInstance);
USB_HostEhciStartPeriodic(ehciInstance);
@@ -4671,10 +4850,12 @@ void USB_HostEhciIsrFunction(void *hostHandle)
}
else
{
+ /*no action*/
}
}
else
{
+ /*no action*/
}
#endif /* FSL_FEATURE_SOC_USBNC_COUNT */
@@ -4682,60 +4863,61 @@ void USB_HostEhciIsrFunction(void *hostHandle)
interruptStatus = ehciInstance->ehciIpBase->USBSTS;
interruptStatus &= ehciInstance->ehciIpBase->USBINTR;
- while (interruptStatus) /* there are usb interrupts */
+ while (0U != interruptStatus) /* there are usb interrupts */
{
ehciInstance->ehciIpBase->USBSTS = interruptStatus; /* clear interrupt */
- if (interruptStatus & USBHS_USBSTS_SRI_MASK) /* SOF interrupt */
+ if (0U != (interruptStatus & USBHS_USBSTS_SRI_MASK)) /* SOF interrupt */
{
}
- if (interruptStatus & USBHS_USBSTS_SEI_MASK) /* system error interrupt */
+ if (0U != (interruptStatus & USBHS_USBSTS_SEI_MASK)) /* system error interrupt */
{
}
- if ((interruptStatus & USBHS_USBSTS_UI_MASK) ||
- (interruptStatus & USBHS_USBSTS_UEI_MASK)) /* USB interrupt or USB error interrupt */
+ if ((0U != (interruptStatus & USBHS_USBSTS_UI_MASK)) ||
+ (0U != (interruptStatus & USBHS_USBSTS_UEI_MASK))) /* USB interrupt or USB error interrupt */
{
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TRANSACTION_DONE);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TRANSACTION_DONE);
}
- if (interruptStatus & USBHS_USBSTS_PCI_MASK) /* port change detect interrupt */
+ if (0U != (interruptStatus & USBHS_USBSTS_PCI_MASK)) /* port change detect interrupt */
{
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle;
- if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK)
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK))
{
if (kBus_EhciStartSuspend == ehciInstance->busSuspendStatus)
{
- if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)
+ if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK))
{
USB_HostEhciStartAsync(ehciInstance);
USB_HostEhciStartPeriodic(ehciInstance);
}
- hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
- kUSB_HostEventNotSuspended); /* call host callback function */
- hostPointer->suspendedDevice = NULL;
+ (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL,
+ kUSB_HostEventNotSuspended); /* call host callback function */
+ hostPointer->suspendedDevice = NULL;
ehciInstance->busSuspendStatus = kBus_EhciIdle;
ehciInstance->ehciIpBase->USBINTR &= ~(USBHS_USBINTR_TIE1_MASK);
}
else
{
+ /*no action */
}
}
#endif
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_PORT_CHANGE);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_PORT_CHANGE);
}
- if (interruptStatus & USBHS_USBSTS_TI0_MASK) /* timer 0 interrupt */
+ if (0U != (interruptStatus & USBHS_USBSTS_TI0_MASK)) /* timer 0 interrupt */
{
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER0);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER0);
}
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
- if (interruptStatus & USBHS_USBSTS_TI1_MASK) /* timer 1 interrupt */
+ if (0U != (interruptStatus & USBHS_USBSTS_TI1_MASK)) /* timer 1 interrupt */
{
- USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER1);
+ (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER1);
}
#endif
@@ -4744,4 +4926,4 @@ void USB_HostEhciIsrFunction(void *hostHandle)
}
}
-#endif /* USB_HOST_CONFIG_EHCI */
+#endif /* USB_HOST_CONFIG_EHCI */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h
index 162d6576cd..c67f8baa40 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h
@@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016,2019 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_CONTROLLER_EHCI_H_
@@ -39,95 +17,95 @@
* Definitions
******************************************************************************/
/* EHCI host macros */
-#define EHCI_HOST_T_INVALID_VALUE (1U)
-#define EHCI_HOST_POINTER_TYPE_ITD (0x00U)
-#define EHCI_HOST_POINTER_TYPE_QH (0x00000002U)
-#define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U)
-#define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U)
-#define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U)
+#define EHCI_HOST_T_INVALID_VALUE (1U)
+#define EHCI_HOST_POINTER_TYPE_ITD (0x00U)
+#define EHCI_HOST_POINTER_TYPE_QH (0x00000002U)
+#define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U)
+#define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U)
+#define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U)
#define EHCI_HOST_POINTER_ADDRESS_MASK (0xFFFFFFE0U)
-#define EHCI_HOST_PID_OUT (0U)
-#define EHCI_HOST_PID_IN (1U)
-#define EHCI_HOST_PID_SETUP (2U)
+#define EHCI_HOST_PID_OUT (0UL)
+#define EHCI_HOST_PID_IN (1UL)
+#define EHCI_HOST_PID_SETUP (2UL)
-#define EHCI_HOST_QH_RL_SHIFT (28U)
-#define EHCI_HOST_QH_RL_MASK (0xF0000000U)
-#define EHCI_HOST_QH_C_SHIFT (27U)
-#define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U)
-#define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U)
-#define EHCI_HOST_QH_H_SHIFT (15U)
-#define EHCI_HOST_QH_DTC_SHIFT (14U)
-#define EHCI_HOST_QH_EPS_SHIFT (12U)
-#define EHCI_HOST_QH_ENDPT_SHIFT (8U)
-#define EHCI_HOST_QH_I_SHIFT (7U)
-#define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U)
-#define EHCI_HOST_QH_MULT_SHIFT (30U)
-#define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U)
-#define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U)
-#define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U)
-#define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U)
-#define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU)
+#define EHCI_HOST_QH_RL_SHIFT (28U)
+#define EHCI_HOST_QH_RL_MASK (0xF0000000U)
+#define EHCI_HOST_QH_C_SHIFT (27U)
+#define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U)
+#define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U)
+#define EHCI_HOST_QH_H_SHIFT (15U)
+#define EHCI_HOST_QH_DTC_SHIFT (14U)
+#define EHCI_HOST_QH_EPS_SHIFT (12U)
+#define EHCI_HOST_QH_ENDPT_SHIFT (8U)
+#define EHCI_HOST_QH_I_SHIFT (7U)
+#define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U)
+#define EHCI_HOST_QH_MULT_SHIFT (30U)
+#define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U)
+#define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U)
+#define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U)
+#define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U)
+#define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK (0x0000003EU)
-#define EHCI_HOST_QTD_DT_SHIFT (31U)
-#define EHCI_HOST_QTD_DT_MASK (0x80000000U)
-#define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U)
-#define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U)
-#define EHCI_HOST_QTD_IOC_MASK (0x00008000U)
-#define EHCI_HOST_QTD_C_PAGE_SHIFT (12U)
-#define EHCI_HOST_QTD_CERR_SHIFT (10U)
-#define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003U)
-#define EHCI_HOST_QTD_PID_CODE_SHIFT (8U)
-#define EHCI_HOST_QTD_STATUS_SHIFT (0U)
-#define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU)
-#define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U)
-#define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U)
-#define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU)
-#define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU)
+#define EHCI_HOST_QTD_DT_SHIFT (31U)
+#define EHCI_HOST_QTD_DT_MASK (0x80000000U)
+#define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U)
+#define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U)
+#define EHCI_HOST_QTD_IOC_MASK (0x00008000U)
+#define EHCI_HOST_QTD_C_PAGE_SHIFT (12U)
+#define EHCI_HOST_QTD_CERR_SHIFT (10U)
+#define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003UL)
+#define EHCI_HOST_QTD_PID_CODE_SHIFT (8U)
+#define EHCI_HOST_QTD_STATUS_SHIFT (0U)
+#define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU)
+#define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U)
+#define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U)
+#define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU)
+#define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QTD_STATUS_STALL_ERROR_MASK (0x00000040U)
-#define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U)
-#define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U)
-#define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U)
-#define EHCI_HOST_ITD_IOC_SHIFT (15U)
-#define EHCI_HOST_ITD_PG_SHIFT (12U)
+#define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U)
+#define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U)
+#define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U)
+#define EHCI_HOST_ITD_IOC_SHIFT (15U)
+#define EHCI_HOST_ITD_PG_SHIFT (12U)
#define EHCI_HOST_ITD_TRANSACTION_OFFSET_SHIFT (0U)
-#define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU)
-#define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U)
-#define EHCI_HOST_ITD_ENDPT_SHIFT (8U)
-#define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U)
-#define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U)
-#define EHCI_HOST_ITD_MULT_SHIFT (0U)
-#define EHCI_HOST_ITD_DIRECTION_SHIFT (11U)
+#define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU)
+#define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U)
+#define EHCI_HOST_ITD_ENDPT_SHIFT (8U)
+#define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U)
+#define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U)
+#define EHCI_HOST_ITD_MULT_SHIFT (0U)
+#define EHCI_HOST_ITD_DIRECTION_SHIFT (11U)
-#define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U)
-#define EHCI_HOST_SITD_DIRECTION_SHIFT (31U)
-#define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U)
-#define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U)
-#define EHCI_HOST_SITD_ENDPT_SHIFT (8U)
+#define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U)
+#define EHCI_HOST_SITD_DIRECTION_SHIFT (31U)
+#define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U)
+#define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U)
+#define EHCI_HOST_SITD_ENDPT_SHIFT (8U)
#define EHCI_HOST_SITD_DEVICE_ADDRESS_SHIFT (0U)
-#define EHCI_HOST_SITD_CMASK_SHIFT (8U)
-#define EHCI_HOST_SITD_SMASK_SHIFT (0U)
-#define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U)
-#define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U)
-#define EHCI_HOST_SITD_TP_SHIFT (3U)
-#define EHCI_HOST_SITD_TCOUNT_SHIFT (0U)
-#define EHCI_HOST_SITD_IOC_SHIFT (31U)
+#define EHCI_HOST_SITD_CMASK_SHIFT (8U)
+#define EHCI_HOST_SITD_SMASK_SHIFT (0U)
+#define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U)
+#define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U)
+#define EHCI_HOST_SITD_TP_SHIFT (3U)
+#define EHCI_HOST_SITD_TCOUNT_SHIFT (0U)
+#define EHCI_HOST_SITD_IOC_SHIFT (31U)
/* register related MACROs */
-#define EHCI_PORTSC1_W1_BITS (0x0000002AU)
+#define EHCI_PORTSC1_W1_BITS (0x0000002AU)
#define EHCI_MAX_UFRAME_VALUE (0x00003FFFU)
/* task event */
-#define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U)
+#define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U)
#define EHCI_TASK_EVENT_TRANSACTION_DONE (0x02U)
-#define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U)
-#define EHCI_TASK_EVENT_PORT_CHANGE (0x08U)
-#define EHCI_TASK_EVENT_TIMER0 (0x10U)
-#define EHCI_TASK_EVENT_TIMER1 (0x20U)
+#define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U)
+#define EHCI_TASK_EVENT_PORT_CHANGE (0x08U)
+#define EHCI_TASK_EVENT_TIMER0 (0x10U)
+#define EHCI_TASK_EVENT_TIMER1 (0x20U)
-#define USB_HostEhciLock() USB_OsaMutexLock(ehciInstance->ehciMutex)
-#define USB_HostEhciUnlock() USB_OsaMutexUnlock(ehciInstance->ehciMutex)
+#define USB_HostEhciLock() (void)OSA_MutexLock(ehciInstance->ehciMutex, USB_OSA_WAIT_TIMEOUT)
+#define USB_HostEhciUnlock() (void)OSA_MutexUnlock(ehciInstance->ehciMutex)
/*******************************************************************************
* KHCI driver public structures, enumerations, macros, functions
@@ -144,6 +122,8 @@
#define USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY (101U)
/*! @brief Delay for port reset */
#define USB_HOST_EHCI_PORT_RESET_DELAY (11U)
+/*! @brief The MAX continuous transfers that application can send. */
+#define USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER (8U)
/*! @brief The SITD inserts a frame interval for putting more SITD continuously.
* There is an interval when an application sends two FS/LS ISO transfers.
* When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two
@@ -171,7 +151,7 @@
*/
#define USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER (16U)
/*! @brief Control or bulk transaction timeout value (unit: 100 ms) */
-#define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (20U)
+#define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (50U)
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
typedef enum _bus_ehci_suspend_request_state
@@ -323,8 +303,10 @@ typedef struct _usb_host_ehci_instance
usb_host_ehci_pipe_t *ehciPipeIndexBase; /*!< Pipe buffer's start pointer*/
usb_host_ehci_pipe_t *ehciPipeList; /*!< Idle pipe list pointer*/
usb_host_ehci_pipe_t *ehciRunningPipeList; /*!< Running pipe list pointer*/
- usb_osa_mutex_handle ehciMutex; /*!< EHCI mutex*/
- usb_osa_event_handle taskEventHandle; /*!< EHCI task event*/
+ osa_mutex_handle_t ehciMutex; /*!< EHCI mutex*/
+ uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< The mutex buffer. */
+ osa_event_handle_t taskEventHandle; /*!< EHCI task event*/
+ uint32_t taskEventHandleBuffer[(OSA_EVENT_HANDLE_SIZE + 3) / 4]; /*!< EHCI task event handle buffer*/
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
uint64_t matchTick;
USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */
@@ -355,6 +337,10 @@ typedef struct _usb_host_ehci_data
#endif
#if ((defined(USB_HOST_CONFIG_EHCI_MAX_ITD)) && (USB_HOST_CONFIG_EHCI_MAX_ITD > 0U))
usb_host_ehci_itd_t ehciItd[USB_HOST_CONFIG_EHCI_MAX_ITD]; /*!< Idle ITD list array*/
+ /* add additional 32bytes because the itd cannot cross over 4K boundary,
+ * If one ITD cross over 4K boundary, the code will move 32 bytes for ITD.
+ */
+ uint32_t reserved[8];
#endif
#if ((defined(USB_HOST_CONFIG_EHCI_MAX_SITD)) && (USB_HOST_CONFIG_EHCI_MAX_SITD > 0U))
usb_host_ehci_sitd_t ehciSitd[USB_HOST_CONFIG_EHCI_MAX_SITD]; /*!< Idle SITD list array*/
@@ -463,7 +449,6 @@ extern usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerH
* @param[in] controllerHandle The controller handle.
* @param[in] pipeHandle The receiving pipe handle.
* @param[in] transfer The transfer information.
-
* @retval kStatus_USB_Success Send successfully.
* @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
* @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
@@ -488,6 +473,45 @@ extern usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandl
uint32_t ioctlEvent,
void *ioctlParam);
+/*!
+ * @brief control ehci bus.
+ *
+ * @param ehciInstance ehci instance pointer.
+ * @param bus_control control code.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+extern usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl);
+
+/*!
+ * @brief ehci port change interrupt process function.
+ *
+ * @param ehciInstance ehci instance pointer.
+ */
+extern void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance);
+
+/*!
+ * @brief ehci timer0 interrupt process function.
+ * cancel control/bulk transfer that time out.
+ *
+ * @param ehciInstance ehci instance pointer.
+ */
+extern void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance);
+
+/*!
+ * @brief host ehci start async schedule.
+ *
+ * @param ehciInstance ehci instance pointer.
+ */
+extern void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance);
+
+/*!
+ * @brief host ehci start periodic schedule.
+ *
+ * @param ehciInstance ehci instance pointer.
+ */
+extern void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance);
+
/*! @}*/
#ifdef __cplusplus
@@ -496,4 +520,4 @@ extern usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandl
/*! @}*/
-#endif /* _USB_HOST_CONTROLLER_EHCI_H_ */
+#endif /* _USB_HOST_CONTROLLER_EHCI_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c
new file mode 100644
index 0000000000..d637a6f3cb
--- /dev/null
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
+ * Copyright 2016 NXP
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <usb/include/usb_host_config.h>
+#include "usb_host.h"
+#include "usb_host_hci.h"
+#include "usb_host_devices.h"
+#include "usb_host_framework.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Component ID definition, used by tools. */
+#ifndef FSL_COMPONENT_ID
+#define FSL_COMPONENT_ID "middleware.usb.host.fatfs_usb_stack"
+#endif
+
+/*******************************************************************************
+ * Prototypes
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+usb_status_t USB_HostCh9RequestCommon(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ uint8_t *buffer,
+ uint32_t bufferLen)
+{
+ /* initialize transfer */
+ transfer->setupPacket->wLength = USB_SHORT_TO_LITTLE_ENDIAN((uint16_t)bufferLen);
+ transfer->transferBuffer = buffer;
+ transfer->transferLength = bufferLen;
+
+ if (USB_HostSendSetup(deviceInstance->hostHandle, deviceInstance->controlPipe, transfer) !=
+ kStatus_USB_Success) /* send setup transfer */
+ {
+#ifdef HOST_ECHO
+ usb_echo("failed for USB_HostSendSetup\r\n");
+#endif
+ (void)USB_HostFreeTransfer(deviceInstance->hostHandle, transfer);
+ return kStatus_USB_Error;
+ }
+ return kStatus_USB_Success;
+}
+
+usb_status_t USB_HostStandardGetStatus(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_get_status_param_t *statusParam;
+ uint8_t length;
+
+ /* initialize transfer */
+ statusParam = (usb_host_get_status_param_t *)param;
+ transfer->setupPacket->bmRequestType = USB_REQUEST_TYPE_DIR_IN | USB_REQUEST_TYPE_TYPE_STANDARD;
+ if (statusParam->requestType == (uint8_t)kRequestDevice)
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_DEVICE;
+ }
+ else if (statusParam->requestType == (uint8_t)kRequestInterface)
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_INTERFACE;
+ }
+ else
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_ENDPOINT;
+ }
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(statusParam->statusSelector);
+
+ length = 2;
+ if (statusParam->statusSelector == USB_REQUEST_STANDARD_GET_STATUS_OTG_STATUS_SELECTOR)
+ {
+ length = 1;
+ }
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, statusParam->statusBuffer, length);
+}
+
+usb_status_t USB_HostStandardSetClearFeature(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_process_feature_param_t *featureParam;
+
+ /* initialize transfer */
+ featureParam = (usb_host_process_feature_param_t *)param;
+ if (featureParam->requestType == (uint8_t)kRequestDevice)
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_DEVICE;
+ }
+ else if (featureParam->requestType == (uint8_t)kRequestInterface)
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_INTERFACE;
+ }
+ else
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_ENDPOINT;
+ }
+ transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN(featureParam->featureSelector);
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(featureParam->interfaceOrEndpoint);
+
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, NULL, 0);
+}
+
+usb_status_t USB_HostStandardSetAddress(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ uint8_t address;
+
+ /* initialize transfer */
+ address = *(uint8_t *)param;
+ transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN(address);
+
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, NULL, 0);
+}
+
+usb_status_t USB_HostStandardSetGetDescriptor(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_process_descriptor_param_t *descriptorParam;
+
+ /* initialize transfer */
+ descriptorParam = (usb_host_process_descriptor_param_t *)param;
+ transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN(
+ (uint16_t)((uint16_t)descriptorParam->descriptorType << 8) | descriptorParam->descriptorIndex);
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(descriptorParam->languageId);
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, descriptorParam->descriptorBuffer,
+ descriptorParam->descriptorLength);
+}
+
+usb_status_t USB_HostStandardGetInterface(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_get_interface_param_t *interfaceParam;
+
+ /* initialize transfer */
+ interfaceParam = (usb_host_get_interface_param_t *)param;
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_INTERFACE;
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(interfaceParam->interface);
+
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, interfaceParam->alternateInterfaceBuffer, 1);
+}
+
+usb_status_t USB_HostStandardSetInterface(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_set_interface_param_t *setParam;
+
+ /* initialize transfer */
+ setParam = (usb_host_set_interface_param_t *)param;
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_INTERFACE;
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(setParam->interface);
+ transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN(setParam->alternateSetting);
+
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, NULL, 0);
+}
+
+usb_status_t USB_HostStandardSyncFrame(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_synch_frame_param_t *frameParam;
+
+ /* initialize transfer */
+ frameParam = (usb_host_synch_frame_param_t *)param;
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_RECIPIENT_ENDPOINT;
+ transfer->setupPacket->wIndex = USB_SHORT_TO_LITTLE_ENDIAN(frameParam->endpoint);
+
+ return USB_HostCh9RequestCommon(deviceInstance, transfer, frameParam->frameNumberBuffer, 2);
+}
+
+usb_status_t USB_HostRequestControl(usb_device_handle deviceHandle,
+ uint8_t usbRequest,
+ usb_host_transfer_t *transfer,
+ void *param)
+{
+ usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
+ usb_status_t status = kStatus_USB_Error;
+
+ if (deviceHandle == NULL)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+
+ /* reset transfer fields */
+ transfer->setupPacket->bmRequestType = 0x00;
+ transfer->setupPacket->bRequest = usbRequest;
+ transfer->setupPacket->wIndex = 0;
+ transfer->setupPacket->wLength = 0;
+ transfer->setupPacket->wValue = 0;
+
+ switch (usbRequest)
+ {
+ case USB_REQUEST_STANDARD_GET_STATUS: /* standard get status request */
+ status = USB_HostStandardGetStatus(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_CLEAR_FEATURE: /* standard clear status request */
+ case USB_REQUEST_STANDARD_SET_FEATURE: /* standard set feature request */
+ status = USB_HostStandardSetClearFeature(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_SET_ADDRESS: /* standard set address request */
+ status = USB_HostStandardSetAddress(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_GET_DESCRIPTOR: /* standard get descriptor request */
+ case USB_REQUEST_STANDARD_SET_DESCRIPTOR: /* standard set descriptor request */
+ if (usbRequest == USB_REQUEST_STANDARD_GET_DESCRIPTOR)
+ {
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
+ }
+ status = USB_HostStandardSetGetDescriptor(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_GET_CONFIGURATION: /* standard get configuration descriptor request */
+ transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN;
+ status =
+ USB_HostCh9RequestCommon((usb_host_device_instance_t *)deviceHandle, transfer, (uint8_t *)param, 1);
+ break;
+
+ case USB_REQUEST_STANDARD_SET_CONFIGURATION: /* standard set configuration request */
+ transfer->setupPacket->wValue = USB_SHORT_TO_LITTLE_ENDIAN(*((uint8_t *)param));
+ status = USB_HostCh9RequestCommon((usb_host_device_instance_t *)deviceHandle, transfer, NULL, 0);
+ break;
+
+ case USB_REQUEST_STANDARD_GET_INTERFACE: /* standard get interface request */
+ status = USB_HostStandardGetInterface(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_SET_INTERFACE: /* standard set interface request */
+ status = USB_HostStandardSetInterface(deviceInstance, transfer, param);
+ break;
+
+ case USB_REQUEST_STANDARD_SYNCH_FRAME: /* standard synch frame request */
+ status = USB_HostStandardSyncFrame(deviceInstance, transfer, param);
+ break;
+
+ default:
+ /*no action*/
+ break;
+ }
+
+ return status;
+} \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h
new file mode 100644
index 0000000000..b0d8d298e3
--- /dev/null
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
+ * Copyright 2016 NXP
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _USB_HOST_CH9_H_
+#define _USB_HOST_CH9_H_
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*!
+ * @addtogroup usb_host_drv
+ * @{
+ */
+
+/*! @}*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+/*!
+ * @brief standard control transfer common code.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param buffer data buffer pointer.
+ * @param bufferLen data length.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostCh9RequestCommon(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ uint8_t *buffer,
+ uint32_t bufferLen);
+
+/*!
+ * @brief standard get status implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardGetStatus(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard set/clear feature implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardSetClearFeature(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard set address implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardSetAddress(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard set/get descriptor implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardSetGetDescriptor(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard get interface implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardGetInterface(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard set interface implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardSetInterface(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+
+/*!
+ * @brief standard sync frame implementation.
+ *
+ * @param deviceInstance device instance handle.
+ * @param transfer transfer.
+ * @param param parameter.
+ *
+ * @return kStatus_USB_Success or error codes.
+ */
+usb_status_t USB_HostStandardSyncFrame(usb_host_device_instance_t *deviceInstance,
+ usb_host_transfer_t *transfer,
+ void *param);
+#endif /* _USB_HOST_CH9_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c
index 927bf8bd9c..a29a4ea08e 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c
@@ -1,34 +1,12 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016 - 2019 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
-#include <usb/include/usb_device_config.h>
+#include <usb/include/usb_host_config.h>
#include "fsl_common.h"
#include "usb_host.h"
#include "usb_host_hci.h"
@@ -42,16 +20,24 @@
* Definitions
******************************************************************************/
+/* Component ID definition, used by tools. */
+#ifndef FSL_COMPONENT_ID
+#define FSL_COMPONENT_ID "middleware.usb.host_stack"
+#endif
+
+#if defined __CORTEX_M && (__CORTEX_M == 7U)
+#if (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
+#warning USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE is not supported.
+#endif
+#endif
+
/*******************************************************************************
* Prototypes
******************************************************************************/
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
-extern uint32_t USB_HostHubGetTotalThinkTime(usb_host_handle hostHandle, uint8_t parentHubNo);
-
-extern usb_status_t USB_HostHubSuspendDevice(usb_host_handle hostHandle);
-
-extern usb_status_t USB_HostHubResumeDevice(usb_host_handle hostHandle);
+#include "usb_host_hub.h"
+#include "usb_host_hub_app.h"
#endif
/*!
@@ -77,15 +63,6 @@ static void USB_HostReleaseInstance(usb_host_instance_t *hostInstance);
static void USB_HostGetControllerInterface(uint8_t controllerId,
const usb_host_controller_interface_t **controllerTable);
-#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
-#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
-extern void USB_HostEhciTestModeInit(usb_device_handle devHandle);
-#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
-#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
-extern void USB_HostIp3516HsTestModeInit(usb_device_handle devHandle);
-#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
-#endif /* USB_HOST_CONFIG_EHCI */
-
/*******************************************************************************
* Variables
******************************************************************************/
@@ -94,8 +71,7 @@ usb_host_instance_t g_UsbHostInstance[USB_HOST_CONFIG_MAX_HOST];
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
#include "usb_host_ehci.h"
-static const usb_host_controller_interface_t s_EhciInterface = \
-{
+static const usb_host_controller_interface_t s_EhciInterface = {
USB_HostEhciCreate, USB_HostEhciDestory, USB_HostEhciOpenPipe, USB_HostEhciClosePipe,
USB_HostEhciWritePipe, USB_HostEhciReadpipe, USB_HostEhciIoctl,
};
@@ -103,8 +79,7 @@ static const usb_host_controller_interface_t s_EhciInterface = \
#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
#include "usb_host_khci.h"
-static const usb_host_controller_interface_t s_KhciInterface = \
-{
+static const usb_host_controller_interface_t s_KhciInterface = {
USB_HostKhciCreate, USB_HostKhciDestory, USB_HostKhciOpenPipe, USB_HostKhciClosePipe,
USB_HostKhciWritePipe, USB_HostKhciReadpipe, USB_HostKciIoctl,
};
@@ -112,8 +87,7 @@ static const usb_host_controller_interface_t s_KhciInterface = \
#if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
#include "usb_host_ohci.h"
-static const usb_host_controller_interface_t s_OhciInterface = \
-{
+static const usb_host_controller_interface_t s_OhciInterface = {
USB_HostOhciCreate, USB_HostOhciDestory, USB_HostOhciOpenPipe, USB_HostOhciClosePipe,
USB_HostOhciWritePipe, USB_HostOhciReadPipe, USB_HostOhciIoctl,
};
@@ -121,65 +95,67 @@ static const usb_host_controller_interface_t s_OhciInterface = \
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
#include "usb_host_ip3516hs.h"
-static const usb_host_controller_interface_t s_Ip3516HsInterface = \
-{
+static const usb_host_controller_interface_t s_Ip3516HsInterface = {
USB_HostIp3516HsCreate, USB_HostIp3516HsDestory, USB_HostIp3516HsOpenPipe, USB_HostIp3516HsClosePipe,
USB_HostIp3516HsWritePipe, USB_HostIp3516HsReadPipe, USB_HostIp3516HsIoctl,
};
#endif /* USB_HOST_CONFIG_IP3516HS */
-USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_Setupbuffer[USB_HOST_CONFIG_MAX_HOST][USB_HOST_CONFIG_MAX_TRANSFERS][USB_DATA_ALIGN_SIZE_MULTIPLE(8)];
+USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
+static uint8_t s_Setupbuffer[USB_HOST_CONFIG_MAX_HOST][USB_HOST_CONFIG_MAX_TRANSFERS][USB_DATA_ALIGN_SIZE_MULTIPLE(8)];
/*******************************************************************************
-* Code
-******************************************************************************/
+ * Code
+ ******************************************************************************/
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
/*FUNCTION*----------------------------------------------------------------
-*
-* Function Name : usb_test_mode_init
-* Returned Value : None
-* Comments :
-* This function is called by common class to initialize the class driver. It
-* is called in response to a select interface call by application
-*
-*END*--------------------------------------------------------------------*/
+ *
+ * Function Name : usb_test_mode_init
+ * Returned Value : None
+ * Comments :
+ * This function is called by common class to initialize the class driver. It
+ * is called in response to a select interface call by application
+ *
+ *END*--------------------------------------------------------------------*/
usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle)
{
#if (((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) || \
((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS)))
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
+ usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
#endif
uint32_t productId;
uint32_t vendorId;
- usb_echo("usb host test init\r\n");
- USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDevicePID, &productId);
- USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceVID, &vendorId);
- usb_echo(" vendor id :0x%x product id:0x%x \r\n", vendorId, productId);
+ (void)usb_echo("usb host test init\r\n");
+ (void)USB_HostHelperGetPeripheralInformation(deviceHandle, (uint32_t)kUSB_HostGetDevicePID, &productId);
+ (void)USB_HostHelperGetPeripheralInformation(deviceHandle, (uint32_t)kUSB_HostGetDeviceVID, &vendorId);
+ (void)usb_echo(" vendor id :0x%x product id:0x%x \r\n", vendorId, productId);
- if ((productId != 0x0200U) && (productId != 0x0101) && (productId != 0x0102) && (productId != 0x0103) &&
- (productId != 0x0104) && (productId != 0x0105) && (productId != 0x0106) && (productId != 0x0107) &&
- (productId != 0x0108))
+ if ((productId != 0x0200U) && (productId != 0x0101U) && (productId != 0x0102U) && (productId != 0x0103U) &&
+ (productId != 0x0104U) && (productId != 0x0105U) && (productId != 0x0106U) && (productId != 0x0107U) &&
+ (productId != 0x0108U))
{
- usb_echo("Unsupported Device\r\n");
+ (void)usb_echo("Unsupported Device\r\n");
}
if (productId == 0x0200U)
{
- usb_echo("PET test device attached\r\n");
+ (void)usb_echo("PET test device attached\r\n");
}
else
{
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
if (hostInstance->controllerTable == &s_EhciInterface)
{
- USB_HostEhciTestModeInit(deviceHandle);
+ (void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit,
+ (void *)deviceHandle);
}
-#elif((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
+#elif ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
if (hostInstance->controllerTable == &s_Ip3516HsInterface)
{
- USB_HostIp3516HsTestModeInit(deviceHandle);
+ (void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit,
+ (void *)deviceHandle);
}
#endif
}
@@ -190,13 +166,14 @@ usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle)
static usb_host_instance_t *USB_HostGetInstance(void)
{
- uint8_t i = 0;
+ uint8_t i = 0;
uint32_t index = 0;
- USB_OSA_SR_ALLOC();
- USB_OSA_ENTER_CRITICAL();
+ void *temp;
+ OSA_SR_ALLOC();
+ OSA_ENTER_CRITICAL();
for (; i < USB_HOST_CONFIG_MAX_HOST; i++)
{
- if (g_UsbHostInstance[i].occupied != 1)
+ if (g_UsbHostInstance[i].occupied != 1U)
{
uint8_t *buffer = (uint8_t *)&g_UsbHostInstance[i];
for (uint32_t j = 0U; j < sizeof(usb_host_instance_t); j++)
@@ -204,53 +181,53 @@ static usb_host_instance_t *USB_HostGetInstance(void)
buffer[j] = 0x00U;
}
g_UsbHostInstance[i].occupied = 1;
- USB_OSA_EXIT_CRITICAL();
+ OSA_EXIT_CRITICAL();
for (index = 0; index < USB_HOST_CONFIG_MAX_TRANSFERS; ++index)
{
- g_UsbHostInstance[i].transferList[index].setupPacket =
- (usb_setup_struct_t *)&(s_Setupbuffer[i][index][0]);
+ temp = (void *)&(s_Setupbuffer[i][index][0]);
+ g_UsbHostInstance[i].transferList[index].setupPacket = (usb_setup_struct_t *)temp;
}
return &g_UsbHostInstance[i];
}
}
- USB_OSA_EXIT_CRITICAL();
+ OSA_EXIT_CRITICAL();
return NULL;
}
static void USB_HostReleaseInstance(usb_host_instance_t *hostInstance)
{
- USB_OSA_SR_ALLOC();
- USB_OSA_ENTER_CRITICAL();
+ OSA_SR_ALLOC();
+ OSA_ENTER_CRITICAL();
hostInstance->occupied = 0;
- USB_OSA_EXIT_CRITICAL();
+ OSA_EXIT_CRITICAL();
}
static void USB_HostGetControllerInterface(uint8_t controllerId,
const usb_host_controller_interface_t **controllerTable)
{
#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
- if (controllerId == kUSB_ControllerKhci0)
+ if (controllerId == (uint8_t)kUSB_ControllerKhci0)
{
*controllerTable = &s_KhciInterface;
}
#endif /* USB_HOST_CONFIG_KHCI */
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
- if ((controllerId == kUSB_ControllerEhci0) || (controllerId == kUSB_ControllerEhci1))
+ if ((controllerId == (uint8_t)kUSB_ControllerEhci0) || (controllerId == (uint8_t)kUSB_ControllerEhci1))
{
*controllerTable = &s_EhciInterface;
}
#endif /* USB_HOST_CONFIG_EHCI */
#if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
- if (controllerId == kUSB_ControllerOhci0)
+ if (controllerId == (uint8_t)kUSB_ControllerOhci0)
{
*controllerTable = &s_OhciInterface;
}
#endif /* USB_HOST_CONFIG_OHCI */
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
- if (controllerId == kUSB_ControllerIp3516Hs0)
+ if (controllerId == (uint8_t)kUSB_ControllerIp3516Hs0)
{
*controllerTable = &s_Ip3516HsInterface;
}
@@ -259,10 +236,10 @@ static void USB_HostGetControllerInterface(uint8_t controllerId,
usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, host_callback_t callbackFn)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = NULL;
usb_host_transfer_t *transferPrev = NULL;
- uint8_t i = 0;
+ uint8_t i = 0;
hostInstance = USB_HostGetInstance(); /* get one host instance */
if (hostInstance == NULL)
@@ -291,10 +268,11 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
}
/* HOST instance init*/
- hostInstance->controllerId = controllerId;
+ hostInstance->controllerId = controllerId;
hostInstance->deviceCallback = callbackFn;
- hostInstance->deviceList = NULL;
- if (kStatus_USB_OSA_Success != USB_OsaMutexCreate(&hostInstance->hostMutex))
+ hostInstance->deviceList = NULL;
+ hostInstance->hostMutex = (osa_mutex_handle_t)(&hostInstance->mutexBuffer[0]);
+ if (KOSA_StatusSuccess != OSA_MutexCreate(hostInstance->hostMutex))
{
USB_HostReleaseInstance(hostInstance);
#ifdef HOST_ECHO
@@ -306,19 +284,19 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
/* initialize transfer list */
hostInstance->transferHead = &hostInstance->transferList[0];
- transferPrev = hostInstance->transferHead;
+ transferPrev = hostInstance->transferHead;
for (i = 1; i < USB_HOST_CONFIG_MAX_TRANSFERS; ++i)
{
transferPrev->next = &hostInstance->transferList[i];
- transferPrev = transferPrev->next;
+ transferPrev = transferPrev->next;
}
- /* controller create */
+ /* controller create, the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerCreate(controllerId, hostInstance, &(hostInstance->controllerHandle));
if ((status != kStatus_USB_Success) || (hostInstance->controllerHandle == NULL))
{
- USB_OsaMutexDestroy(hostInstance->hostMutex);
+ (void)OSA_MutexDestroy(hostInstance->hostMutex);
USB_HostReleaseInstance(hostInstance);
#ifdef HOST_ECHO
usb_echo("host init: controller init fail\r\n");
@@ -332,8 +310,8 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
usb_status_t USB_HostDeinit(usb_host_handle hostHandle)
{
- usb_status_t status = kStatus_USB_Success;
- usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
+ usb_status_t status = kStatus_USB_Success;
+ usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_host_device_instance_t *deviceInstance = NULL;
if (hostHandle == NULL)
@@ -346,23 +324,23 @@ usb_status_t USB_HostDeinit(usb_host_handle hostHandle)
while (deviceInstance != NULL)
{
deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList;
- USB_HostDetachDeviceInternal(hostHandle, deviceInstance);
+ (void)USB_HostDetachDeviceInternal(hostHandle, deviceInstance);
}
- /* controller instance destory */
- status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle);
+ /* controller instance destroy, the callbackFn is initialized in USB_HostGetControllerInterface */
+ status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle);
hostInstance->controllerHandle = NULL;
if (status != kStatus_USB_Success)
{
#ifdef HOST_ECHO
- usb_echo("host controller destory fail\r\n");
+ usb_echo("host controller destroy fail\r\n");
#endif
}
/* resource release */
- if (hostInstance->hostMutex)
+ if (NULL != hostInstance->hostMutex)
{
- USB_OsaMutexDestroy(hostInstance->hostMutex);
+ (void)OSA_MutexDestroy(hostInstance->hostMutex);
hostInstance->hostMutex = NULL;
}
USB_HostReleaseInstance(hostInstance);
@@ -374,7 +352,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
usb_host_pipe_handle *pipeHandle,
usb_host_pipe_init_t *pipeInit)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeInit == NULL))
@@ -382,7 +360,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
return kStatus_USB_InvalidHandle;
}
- /* call controller open pipe interface */
+ /* call controller open pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerOpenPipe(hostInstance->controllerHandle, pipeHandle, pipeInit);
return status;
@@ -390,7 +368,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL))
@@ -398,7 +376,7 @@ usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle
return kStatus_USB_InvalidHandle;
}
- /* call controller close pipe interface */
+ /* call controller close pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerClosePipe(hostInstance->controllerHandle, pipeHandle);
return status;
@@ -406,7 +384,7 @@ usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle
usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@@ -416,9 +394,9 @@ usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
/* initialize transfer */
transfer->transferSofar = 0;
- transfer->direction = USB_OUT;
+ transfer->direction = USB_OUT;
- USB_HostLock(); /* This api can be called by host task and app task */
+ (void)USB_HostLock(); /* This api can be called by host task and app task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@@ -435,9 +413,10 @@ usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
DCACHE_CleanByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerWritePipe(hostInstance->controllerHandle, pipeHandle, transfer);
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return status;
}
@@ -445,7 +424,7 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
usb_host_pipe_handle pipeHandle,
usb_host_transfer_t *transfer)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@@ -455,8 +434,8 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
/* initialize transfer */
transfer->transferSofar = 0;
- transfer->next = NULL;
- transfer->setupStatus = 0;
+ transfer->next = NULL;
+ transfer->setupStatus = 0;
if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
{
transfer->direction = USB_IN;
@@ -466,7 +445,7 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
transfer->direction = USB_OUT;
}
- USB_HostLock(); /* This API can be called by host task and application task */
+ (void)USB_HostLock(); /* This API can be called by host task and application task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@@ -484,15 +463,16 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
DCACHE_CleanInvalidateByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerWritePipe(hostInstance->controllerHandle, pipeHandle, transfer);
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return status;
}
usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@@ -502,9 +482,9 @@ usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
/* initialize transfer */
transfer->transferSofar = 0;
- transfer->direction = USB_IN;
+ transfer->direction = USB_IN;
- USB_HostLock(); /* This API can be called by host task and application task */
+ (void)USB_HostLock(); /* This API can be called by host task and application task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@@ -521,9 +501,10 @@ usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
DCACHE_CleanInvalidateByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerReadPipe(hostInstance->controllerHandle, pipeHandle, transfer);
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return status;
}
@@ -531,7 +512,7 @@ usb_status_t USB_HostCancelTransfer(usb_host_handle hostHandle,
usb_host_pipe_handle pipeHandle,
usb_host_transfer_t *transfer)
{
- usb_status_t status = kStatus_USB_Success;
+ usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_host_cancel_param_t cancelParam;
@@ -542,9 +523,10 @@ usb_status_t USB_HostCancelTransfer(usb_host_handle hostHandle,
/* initialize cancel parameter */
cancelParam.pipeHandle = pipeHandle;
- cancelParam.transfer = transfer;
+ cancelParam.transfer = transfer;
/* USB_HostLock(); This api can be called by host task and app task */
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostCancelTransfer,
&cancelParam);
/* USB_HostUnlock(); */
@@ -562,18 +544,18 @@ usb_status_t USB_HostMallocTransfer(usb_host_handle hostHandle, usb_host_transfe
}
/* get one from the transfer_head */
- USB_HostLock();
+ (void)USB_HostLock();
if (hostInstance->transferHead != NULL)
{
- *transfer = hostInstance->transferHead;
+ *transfer = hostInstance->transferHead;
hostInstance->transferHead = hostInstance->transferHead->next;
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Success;
}
else
{
*transfer = NULL;
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Error;
}
}
@@ -592,10 +574,10 @@ usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_transfer_
}
/* release one to the transfer_head */
- USB_HostLock();
- transfer->next = hostInstance->transferHead;
+ (void)USB_HostLock();
+ transfer->next = hostInstance->transferHead;
hostInstance->transferHead = transfer;
- USB_HostUnlock();
+ (void)USB_HostUnlock();
return kStatus_USB_Success;
}
@@ -604,23 +586,28 @@ usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHand
uint32_t *infoValue)
{
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
+ uint32_t *temp;
+ usb_host_dev_info_t devInfo;
if ((deviceHandle == NULL) || (infoValue == NULL))
{
return kStatus_USB_InvalidParameter;
}
-
- switch (infoCode)
+ devInfo = (usb_host_dev_info_t)infoCode;
+ switch (devInfo)
{
case kUSB_HostGetDeviceAddress: /* device address */
+
*infoValue = (uint32_t)deviceInstance->setAddress;
break;
case kUSB_HostGetDeviceControlPipe: /* device control pipe */
- *infoValue = (uint32_t)deviceInstance->controlPipe;
+ temp = (uint32_t *)deviceInstance->controlPipe;
+ *infoValue = (uint32_t)temp;
break;
case kUSB_HostGetHostHandle: /* device host handle */
- *infoValue = (uint32_t)deviceInstance->hostHandle;
+ temp = (uint32_t *)deviceInstance->hostHandle;
+ *infoValue = (uint32_t)temp;
break;
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
@@ -685,7 +672,8 @@ usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHand
break;
default:
- return kStatus_USB_Error;
+ /*no action*/
+ break;
}
return kStatus_USB_Success;
@@ -698,26 +686,27 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
uint32_t endPosition;
usb_descriptor_union_t *unionDes;
usb_host_ep_t *epParse;
-
+ void *temp;
if (interfaceHandle == NULL)
{
return kStatus_USB_InvalidHandle;
}
- if (alternateSetting == 0)
+ if (alternateSetting == 0U)
{
return kStatus_USB_InvalidParameter;
}
/* parse configuration descriptor */
- unionDes = (usb_descriptor_union_t *)((usb_host_interface_t *)interfaceHandle)
- ->interfaceDesc; /* interface extend descriptor start */
+ temp = (void *)((usb_host_interface_t *)interfaceHandle)->interfaceDesc;
+ ;
+ unionDes = (usb_descriptor_union_t *)temp; /* interface extend descriptor start */
endPosition =
(uint32_t)unionDes +
((usb_host_interface_t *)interfaceHandle)->interfaceExtensionLength; /* interface extend descriptor end */
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
- /* search for the alternate setting interface descritpor */
+ /* search for the alternate setting interface descriptor */
while ((uint32_t)unionDes < endPosition)
{
if (unionDes->interface.bDescriptorType == USB_DESCRIPTOR_TYPE_INTERFACE)
@@ -742,12 +731,12 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
}
/* initialize interface handle structure instance */
- interface->interfaceDesc = &unionDes->interface;
- interface->alternateSettingNumber = 0;
- interface->epCount = 0;
- interface->interfaceExtension = NULL;
- interface->interfaceExtensionLength = 0;
- interface->interfaceIndex = unionDes->interface.bInterfaceNumber;
+ interface->interfaceDesc = &unionDes->interface;
+ interface->alternateSettingNumber = 0U;
+ interface->epCount = 0U;
+ interface->interfaceExtension = NULL;
+ interface->interfaceExtensionLength = 0U;
+ interface->interfaceIndex = unionDes->interface.bInterfaceNumber;
/* search for endpoint descriptor start position */
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
@@ -770,7 +759,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
}
/* parse endpoint descriptor */
- if (interface->interfaceDesc->bNumEndpoints != 0)
+ if (interface->interfaceDesc->bNumEndpoints != 0U)
{
if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) ||
(interface->interfaceDesc->bNumEndpoints > USB_HOST_CONFIG_INTERFACE_MAX_EP))
@@ -790,11 +779,12 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
#endif
return kStatus_USB_Error;
}
- epParse = (usb_host_ep_t *)&interface->epList[interface->epCount];
- epParse->epDesc = (usb_descriptor_endpoint_t *)unionDes;
+ epParse = (usb_host_ep_t *)&interface->epList[interface->epCount];
+ temp = (void *)unionDes;
+ epParse->epDesc = (usb_descriptor_endpoint_t *)temp;
epParse->epExtensionLength = 0;
- epParse->epExtension = NULL;
- unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
+ epParse->epExtension = NULL;
+ unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
while ((uint32_t)unionDes < endPosition)
{
if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) &&
@@ -820,7 +810,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
void USB_HostGetVersion(uint32_t *version)
{
- if (version)
+ if (NULL != version)
{
*version =
(uint32_t)USB_MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX);
@@ -828,12 +818,12 @@ void USB_HostGetVersion(uint32_t *version)
}
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
-/* Send BUS or specific device suepend request */
+/* Send BUS or specific device suspend request */
usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle)
{
usb_host_instance_t *hostInstance;
usb_host_device_instance_t *deviceInstance;
- usb_status_t status = kStatus_USB_Error;
+ usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusSuspend;
if (hostHandle == NULL)
@@ -849,6 +839,7 @@ usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_devic
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
status = USB_HostHubSuspendDevice(hostInstance);
#else
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
#endif
@@ -857,11 +848,12 @@ usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_devic
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- if (0 == deviceInstance->hubNumber)
+ if (0U == deviceInstance->hubNumber)
{
#endif
if (hostInstance->deviceList == deviceHandle)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle,
kUSB_HostBusControl, &type);
}
@@ -888,7 +880,7 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
{
usb_host_instance_t *hostInstance;
usb_host_device_instance_t *deviceInstance;
- usb_status_t status = kStatus_USB_Error;
+ usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusResume;
if (hostHandle == NULL)
@@ -905,6 +897,7 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
if (NULL == deviceHandle)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
}
@@ -912,11 +905,12 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
deviceInstance = (usb_host_device_instance_t *)deviceHandle;
- if (0 == deviceInstance->hubNumber)
+ if (0U == deviceInstance->hubNumber)
{
#endif
if (hostInstance->deviceList == deviceHandle)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle,
kUSB_HostBusControl, &type);
}
@@ -935,13 +929,13 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
return status;
}
#if ((defined(USB_HOST_CONFIG_LPM_L1)) && (USB_HOST_CONFIG_LPM_L1 > 0U))
-/* Send BUS or specific device suepend request */
+/* Send BUS or specific device suspend request */
usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
usb_device_handle deviceHandle,
uint8_t sleepType)
{
usb_host_instance_t *hostInstance;
- usb_status_t status = kStatus_USB_Error;
+ usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusL1Sleep;
if (hostHandle == NULL)
@@ -955,8 +949,9 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
if (1U == sleepType)
{
/*#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))*/
- /*To do, implete hub L1 suspend device*/
+ /*To do, incomplete hub L1 suspend device*/
/*#else*/
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
/*#endif*/
@@ -968,6 +963,7 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
#endif
if (hostInstance->deviceList == deviceHandle)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl,
&type);
}
@@ -978,7 +974,7 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
}
return status;
}
-/* Send BUS or specific device suepend request */
+/* Send BUS or specific device suspend request */
usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam)
{
usb_host_instance_t *hostInstance;
@@ -989,7 +985,7 @@ usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uin
return kStatus_USB_InvalidHandle;
}
hostInstance = (usb_host_instance_t *)hostHandle;
-
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostL1Config, lpmParam);
@@ -1003,7 +999,7 @@ usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
{
usb_host_instance_t *hostInstance;
- usb_status_t status = kStatus_USB_Error;
+ usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusL1Resume;
if (hostHandle == NULL)
@@ -1014,17 +1010,19 @@ usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
if (1U == sleepType)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
}
else
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
-/*To do, if device hub number is 0, need suspend the bus ,else suspend the corresponding device*/
+ /*To do, if device hub number is 0, need suspend the bus ,else suspend the corresponding device*/
#endif
if (hostInstance->deviceList == deviceHandle)
{
+ /* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl,
&type);
}
@@ -1050,3 +1048,18 @@ usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t tick)
return status;
}
#endif
+
+#if ((defined(USB_HOST_CONFIG_BATTERY_CHARGER)) && (USB_HOST_CONFIG_BATTERY_CHARGER > 0U))
+usb_status_t USB_HostSetChargerType(usb_host_handle hostHandle, uint8_t type)
+{
+ usb_host_instance_t *hostInstance;
+
+ if (hostHandle == NULL)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ hostInstance = (usb_host_instance_t *)hostHandle;
+ return hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostSetChargerType,
+ &type);
+}
+#endif \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h
index 26b6d4a9c5..f9ac8b6a7f 100644
--- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h
+++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h
@@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016 - 2019 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_HCI_H_
@@ -36,9 +14,9 @@
******************************************************************************/
/*! @brief USB host lock */
-#define USB_HostLock() USB_OsaMutexLock(hostInstance->hostMutex)
+#define USB_HostLock() OSA_MutexLock(hostInstance->hostMutex, USB_OSA_WAIT_TIMEOUT)
/*! @brief USB host unlock */
-#define USB_HostUnlock() USB_OsaMutexUnlock(hostInstance->hostMutex)
+#define USB_HostUnlock() OSA_MutexUnlock(hostInstance->hostMutex)
/*!
* @addtogroup usb_host_controller_driver
@@ -56,6 +34,10 @@ typedef enum _usb_host_controller_control
kUSB_HostPortAttachDisable, /*!< Disable the port attach event */
kUSB_HostPortAttachEnable, /*!< Enable the port attach event */
kUSB_HostL1Config, /*!< L1 suspend Bus control code */
+ kUSB_HostSetChargerType, /*!< set charger type */
+#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
+ kUSB_HostTestModeInit, /*!< intialize charger type */
+#endif
} usb_host_controller_control_t;
/*! @brief USB host controller bus control code */
@@ -97,7 +79,9 @@ typedef struct _usb_host_controller_interface
uint32_t ioctlEvent,
void *ioctlParam); /*!< Control a controller function prototype*/
} usb_host_controller_interface_t;
-
+#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
+usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle);
+#endif
/*! @}*/
/*!
@@ -110,7 +94,8 @@ typedef struct _usb_host_instance
{
void *controllerHandle; /*!< The low level controller handle*/
host_callback_t deviceCallback; /*!< Device attach/detach callback*/
- usb_osa_mutex_handle hostMutex; /*!< Host layer mutex*/
+ osa_mutex_handle_t hostMutex; /*!< Host layer mutex*/
+ uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< Host layer mutex*/
usb_host_transfer_t transferList[USB_HOST_CONFIG_MAX_TRANSFERS]; /*!< Transfer resource*/
usb_host_transfer_t *transferHead; /*!< Idle transfer head*/
const usb_host_controller_interface_t *controllerTable; /*!< KHCI/EHCI interface*/
@@ -126,6 +111,7 @@ typedef struct _usb_host_instance
uint8_t controllerId; /*!< The controller ID*/
} usb_host_instance_t;
+extern usb_host_instance_t g_UsbHostInstance[USB_HOST_CONFIG_MAX_HOST];
/*! @}*/
-#endif /* _USB_HOST_HCI_H_ */
+#endif /* _USB_HOST_HCI_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb.h b/bsp/imxrt/libraries/drivers/usb/include/usb.h
index 256896b472..a5d0550ce0 100644
--- a/bsp/imxrt/libraries/drivers/usb/include/usb.h
+++ b/bsp/imxrt/libraries/drivers/usb/include/usb.h
@@ -34,6 +34,7 @@
#include <stdint.h>
#include <stdio.h>
#include <fsl_common.h>
+#include <fsl_os_abstraction.h>
#include "usb_misc.h"
#include "usb_spec.h"
@@ -137,4 +138,4 @@ typedef struct _usb_version
/*! @} */
-#endif /* __USB_H__ */
+#endif /* __USB_H__ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h b/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h
new file mode 100644
index 0000000000..73bc46a8e6
--- /dev/null
+++ b/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
+ * Copyright 2016 - 2019 NXP
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _USB_HOST_CONFIG_H_
+#define _USB_HOST_CONFIG_H_
+
+/* Host Controller Enable */
+/*!
+ * @brief host khci instance count, meantime it indicates khci enable or disable.
+ * - if 0, host khci driver is disable.
+ * - if greater than 0, host khci driver is enable.
+ */
+#define USB_HOST_CONFIG_KHCI (0U)
+
+/*!
+ * @brief host ehci instance count, meantime it indicates ehci enable or disable.
+ * - if 0, host ehci driver is disable.
+ * - if greater than 0, host ehci driver is enable.
+ */
+#define USB_HOST_CONFIG_EHCI (2U)
+
+/*!
+ * @brief host ohci instance count, meantime it indicates ohci enable or disable.
+ * - if 0, host ohci driver is disable.
+ * - if greater than 0, host ohci driver is enable.
+ */
+#define USB_HOST_CONFIG_OHCI (0U)
+
+/*!
+ * @brief host ip3516hs instance count, meantime it indicates ohci enable or disable.
+ * - if 0, host ip3516hs driver is disable.
+ * - if greater than 0, host ip3516hs driver is enable.
+ */
+#define USB_HOST_CONFIG_IP3516HS (0U)
+
+/* Common configuration macros for all controllers */
+
+/*!
+ * @brief host driver instance max count.
+ * for example: 2 - one for khci, one for ehci.
+ */
+#define USB_HOST_CONFIG_MAX_HOST \
+ (USB_HOST_CONFIG_KHCI + USB_HOST_CONFIG_EHCI + USB_HOST_CONFIG_OHCI + USB_HOST_CONFIG_IP3516HS)
+
+/*!
+ * @brief host pipe max count.
+ * pipe is the host driver resource for device endpoint, one endpoint need one pipe.
+ */
+#define USB_HOST_CONFIG_MAX_PIPES (16U)
+
+/*!
+ * @brief host transfer max count.
+ * transfer is the host driver resource for data transmission mission, one transmission mission need one transfer.
+ */
+#define USB_HOST_CONFIG_MAX_TRANSFERS (16U)
+
+/*!
+ * @brief the max endpoint for one interface.
+ * the max endpoint descriptor number that one interface descriptor contain.
+ */
+#define USB_HOST_CONFIG_INTERFACE_MAX_EP (4U)
+
+/*!
+ * @brief the max interface for one configuration.
+ * the max interface descriptor number that one configuration descriptor can contain.
+ */
+#define USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE (5U)
+
+/*!
+ * @brief the max power for one device.
+ * the max power the host can provide for one device.
+ */
+#define USB_HOST_CONFIG_MAX_POWER (250U)
+
+/*!
+ * @brief the max retries for enumeration.
+ * retry time when enumeration fail.
+ */
+#define USB_HOST_CONFIG_ENUMERATION_MAX_RETRIES (3U)
+
+/*!
+ * @brief the max retries for enumeration setup stall.
+ * the max times for one transfer can stall.
+ */
+#define USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES (1U)
+
+/*!
+ * @brief the max NAK count for one transaction.
+ * when nak count reach to the value, the transaction fail.
+ */
+#define USB_HOST_CONFIG_MAX_NAK (3000U)
+
+/*! @brief Whether the transfer buffer is cache-enabled or not. */
+#ifndef USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE
+#define USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U)
+#endif
+/*! @brief if 1, enable usb compliance test codes; if 0, disable usb compliance test codes. */
+#define USB_HOST_CONFIG_COMPLIANCE_TEST (0U)
+
+/*! @brief if 1, class driver clear stall automatically; if 0, class driver don't clear stall. */
+#define USB_HOST_CONFIG_CLASS_AUTO_CLEAR_STALL (0U)
+
+/* KHCI configuration */
+#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
+
+/*!
+ * @brief khci dma align fix buffer size.
+ */
+#define USB_HOST_CONFIG_KHCI_DMA_ALIGN_BUFFER (64U)
+
+#endif
+
+/* EHCI configuration */
+#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
+
+/*!
+ * @brief ehci periodic frame list size.
+ * the value can be 1024, 512, 256, 128, 64, 32, 16 or 8.
+ */
+#define USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE (1024U)
+
+/*!
+ * @brief ehci QH max count.
+ */
+#define USB_HOST_CONFIG_EHCI_MAX_QH (8U)
+
+/*!
+ * @brief ehci QTD max count.
+ */
+#define USB_HOST_CONFIG_EHCI_MAX_QTD (8U)
+
+/*!
+ * @brief ehci ITD max count.
+ */
+#define USB_HOST_CONFIG_EHCI_MAX_ITD (0U)
+
+/*!
+ * @brief ehci SITD max count.
+ */
+#define USB_HOST_CONFIG_EHCI_MAX_SITD (0U)
+
+#endif
+
+/* OHCI configuration */
+#if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI))
+
+/*!
+ * @brief ohci ED max count.
+ */
+#define USB_HOST_CONFIG_OHCI_MAX_ED (8U)
+
+/*!
+ * @brief ohci GTD max count.
+ */
+#define USB_HOST_CONFIG_OHCI_MAX_GTD (8U)
+
+/*!
+ * @brief ohci ITD max count.
+ */
+#define USB_HOST_CONFIG_OHCI_MAX_ITD (8U)
+
+#endif
+
+/* OHCI configuration */
+#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
+
+#define USB_HOST_CONFIG_IP3516HS_MAX_PIPE (32U)
+
+/*!
+ * @brief ohci ED max count.
+ */
+#define USB_HOST_CONFIG_IP3516HS_MAX_ATL (32U)
+
+/*!
+ * @brief ohci GTD max count.
+ */
+#define USB_HOST_CONFIG_IP3516HS_MAX_INT (32U)
+
+/*!
+ * @brief ohci ITD max count.
+ */
+#define USB_HOST_CONFIG_IP3516HS_MAX_ISO (0U)
+
+#endif
+
+/*!
+ * @brief host HUB class instance count, meantime it indicates HUB class enable or disable.
+ * - if 0, host HUB class driver is disable.
+ * - if greater than 0, host HUB class driver is enable.
+ */
+#define USB_HOST_CONFIG_HUB (0U)
+
+/*!
+ * @brief host HID class instance count, meantime it indicates HID class enable or disable.
+ * - if 0, host HID class driver is disable.
+ * - if greater than 0, host HID class driver is enable.
+ */
+#define USB_HOST_CONFIG_HID (0U)
+
+/*!
+ * @brief host MSD class instance count, meantime it indicates MSD class enable or disable.
+ * - if 0, host MSD class driver is disable.
+ * - if greater than 0, host MSD class driver is enable.
+ */
+#define USB_HOST_CONFIG_MSD (0U)
+
+/*!
+ * @brief host CDC class instance count, meantime it indicates CDC class enable or disable.
+ * - if 0, host CDC class driver is disable.
+ * - if greater than 0, host CDC class driver is enable.
+ */
+#define USB_HOST_CONFIG_CDC (0U)
+
+/*!
+ * @brief host AUDIO class instance count, meantime it indicates AUDIO class enable or disable.
+ * - if 0, host AUDIO class driver is disable.
+ * - if greater than 0, host AUDIO class driver is enable.
+ */
+#define USB_HOST_CONFIG_AUDIO (0U)
+
+/*!
+ * @brief host PHDC class instance count, meantime it indicates PHDC class enable or disable.
+ * - if 0, host PHDC class driver is disable.
+ * - if greater than 0, host PHDC class driver is enable.
+ */
+#define USB_HOST_CONFIG_PHDC (0U)
+
+/*!
+ * @brief host printer class instance count, meantime it indicates printer class enable or disable.
+ * - if 0, host printer class driver is disable.
+ * - if greater than 0, host printer class driver is enable.
+ */
+#define USB_HOST_CONFIG_PRINTER (0U)
+
+/*!
+ * @brief host charger detect enable or disable. It is only supported on RT600 currently.
+ * - if 0, host charger detect is disable.
+ * - if greater than 0, host charger detect is enable.
+ */
+#define USB_HOST_CONFIG_BATTERY_CHARGER (0U)
+
+#endif /* _USB_HOST_CONFIG_H_ */ \ No newline at end of file
diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h b/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h
index 4e65cfa94b..382c5d3619 100644
--- a/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h
+++ b/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h
@@ -1,46 +1,34 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
+ * Copyright 2016, 2019 NXP
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __USB_MISC_H__
#define __USB_MISC_H__
-#ifndef ENDIANNESS
-
-#error ENDIANNESS should be defined, and then rebulid the project.
-
-#endif
-
/*******************************************************************************
* Definitions
******************************************************************************/
+/*! @brief Define big endian */
+#define USB_BIG_ENDIAN (0U)
+/*! @brief Define little endian */
+#define USB_LITTLE_ENDIAN (1U)
+
+/*! @brief Define current endian */
+#ifndef ENDIANNESS
+#define ENDIANNESS USB_LITTLE_ENDIAN
+#endif
+/*! @brief Define default timeout value */
+#if (defined(USE_RTOS) && (USE_RTOS > 0))
+#define USB_OSA_WAIT_TIMEOUT (osaWaitForever_c)
+#else
+#define USB_OSA_WAIT_TIMEOUT (0U)
+#endif /* (defined(USE_RTOS) && (USE_RTOS > 0)) */
+
/*! @brief Define USB printf */
#if defined(__cplusplus)
extern "C" {
@@ -52,10 +40,14 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
}
#endif /* __cplusplus */
+#ifndef __DSC__
#if defined(SDK_DEBUGCONSOLE) && (SDK_DEBUGCONSOLE < 1)
#define usb_echo printf
#else
-#define usb_echo DbgConsole_Printf
+#define usb_echo rt_kprintf
+#endif
+#else
+#define usb_echo
#endif
#if defined(__ICCARM__)
@@ -78,7 +70,7 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define STRUCT_UNPACKED __attribute__((__packed__))
#endif
-#elif defined(__CC_ARM)
+#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION))
#ifndef STRUCT_PACKED
#define STRUCT_PACKED _Pragma("pack(1U)")
@@ -112,7 +104,7 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define USB_ASSIGN_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
{ \
- *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
+ *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
*((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
*((uint8_t *)&(n) + 2) = *((uint8_t *)&(m) + 2); \
*((uint8_t *)&(n) + 3) = *((uint8_t *)&(m) + 3); \
@@ -120,13 +112,13 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define USB_ASSIGN_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
{ \
- *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
+ *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
*((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
}
#define USB_ASSIGN_MACRO_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
{ \
- *((uint8_t *)&(n)) = (uint8_t)m; \
+ *((uint8_t *)&(n)) = (uint8_t)m; \
*((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
*((uint8_t *)&(n) + 2) = (uint8_t)(m >> 16); \
*((uint8_t *)&(n) + 3) = (uint8_t)(m >> 24); \
@@ -134,7 +126,7 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define USB_ASSIGN_MACRO_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
{ \
- *((uint8_t *)&(n)) = (uint8_t)m; \
+ *((uint8_t *)&(n)) = (uint8_t)m; \
*((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
}
@@ -150,65 +142,66 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define USB_SHORT_FROM_BIG_ENDIAN(n) (n)
#define USB_LONG_FROM_BIG_ENDIAN(n) (n)
-#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
- { \
- m[3] = ((n >> 24U) & 0xFFU); \
- m[2] = ((n >> 16U) & 0xFFU); \
- m[1] = ((n >> 8U) & 0xFFU); \
- m[0] = (n & 0xFFU); \
+#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[3] = (uint8_t)((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ m[2] = (uint8_t)((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ m[1] = (uint8_t)((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ m[0] = (uint8_t)(((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
- ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
- (((uint8_t)n[0]) << 0U)))
+#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
+ ((uint32_t)((((uint32_t)n[3]) << 24U) | (((uint32_t)n[2]) << 16U) | (((uint32_t)n[1]) << 8U) | \
+ (((uint32_t)n[0]) << 0U)))
-#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
- { \
- m[0] = ((n >> 24U) & 0xFFU); \
- m[1] = ((n >> 16U) & 0xFFU); \
- m[2] = ((n >> 8U) & 0xFFU); \
- m[3] = (n & 0xFFU); \
+#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[0] = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ m[1] = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ m[2] = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ m[3] = (((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
- ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
- (((uint8_t)n[3]) << 0U)))
+#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
+ ((uint32_t)((((uint32_t)n[0]) << 24U) | (((uint32_t)n[1]) << 16U) | (((uint32_t)n[2]) << 8U) | \
+ (((uint32_t)n[3]) << 0U)))
-#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
- { \
- m[1] = ((n >> 8U) & 0xFFU); \
- m[0] = (n & 0xFFU); \
+#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ m[0] = (((uint16_t)(n)) & 0xFFU); \
}
-#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
+#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U)))
-#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
- { \
- m[0] = ((n >> 8U) & 0xFFU); \
- m[1] = (n & 0xFFU); \
+#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[0] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ m[1] = (((uint16_t)(n)) & 0xFFU); \
}
-#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
+#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U)))
-#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
- { \
- *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
- *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
- *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
- *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
+#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
+ { \
+ *((uint8_t *)&(m) + 3) = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ *((uint8_t *)&(m) + 2) = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ *((uint8_t *)&(m) + 1) = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ *((uint8_t *)&(m) + 0) = (((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
- ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
- ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
+#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
+ ((uint32_t)(((uint32_t)(*((uint8_t *)&(n) + 3)) << 24U) | ((uint32_t)(*((uint8_t *)&(n) + 2)) << 16U) | \
+ ((uint32_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint32_t)(*((uint8_t *)&(n))) << 0U)))
-#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
- { \
- *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
- *((uint8_t *)&(m)) = ((n)&0xFFU); \
+#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
+ { \
+ *((uint8_t *)&(m) + 1) = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ *((uint8_t *)&(m)) = ((((uint16_t)(n))) & 0xFFU); \
}
-#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
+#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \
+ ((uint16_t)((uint16_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n)))))
#else
@@ -222,75 +215,76 @@ extern int DbgConsole_Printf(const char *fmt_s, ...);
#define USB_SHORT_FROM_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
#define USB_LONG_FROM_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
-#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
- { \
- m[3] = ((n >> 24U) & 0xFFU); \
- m[2] = ((n >> 16U) & 0xFFU); \
- m[1] = ((n >> 8U) & 0xFFU); \
- m[0] = (n & 0xFFU); \
+#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[3] = (uint8_t)((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ m[2] = (uint8_t)((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ m[1] = (uint8_t)((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ m[0] = (uint8_t)(((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
- ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
- (((uint8_t)n[0]) << 0U)))
+#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
+ ((uint32_t)((((uint32_t)n[3]) << 24U) | (((uint32_t)n[2]) << 16U) | (((uint32_t)n[1]) << 8U) | \
+ (((uint32_t)n[0]) << 0U)))
-#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
- { \
- m[0] = ((n >> 24U) & 0xFFU); \
- m[1] = ((n >> 16U) & 0xFFU); \
- m[2] = ((n >> 8U) & 0xFFU); \
- m[3] = (n & 0xFFU); \
+#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[0] = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ m[1] = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ m[2] = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ m[3] = (((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
- ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
- (((uint8_t)n[3]) << 0U)))
+#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
+ ((uint32_t)((((uint32_t)n[0]) << 24U) | (((uint32_t)n[1]) << 16U) | (((uint32_t)n[2]) << 8U) | \
+ (((uint32_t)n[3]) << 0U)))
-#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
- { \
- m[1] = ((n >> 8U) & 0xFFU); \
- m[0] = (n & 0xFFU); \
+#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ m[0] = (((uint16_t)(n)) & 0xFFU); \
}
-#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
+#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U)))
-#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
- { \
- m[0] = ((n >> 8U) & 0xFFU); \
- m[1] = (n & 0xFFU); \
+#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
+ { \
+ m[0] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ m[1] = (((uint16_t)(n)) & 0xFFU); \
}
-#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
+#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U)))
-#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
- { \
- *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
- *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
- *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
- *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
+#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
+ { \
+ *((uint8_t *)&(m) + 3) = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
+ *((uint8_t *)&(m) + 2) = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
+ *((uint8_t *)&(m) + 1) = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
+ *((uint8_t *)&(m) + 0) = (((uint32_t)(n)) & 0xFFU); \
}
-#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
- ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
- ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
+#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
+ ((uint32_t)(((uint32_t)(*((uint8_t *)&(n) + 3)) << 24U) | ((uint32_t)(*((uint8_t *)&(n) + 2)) << 16U) | \
+ ((uint32_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint32_t)(*((uint8_t *)&(n))) << 0U)))
-#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
- { \
- *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
- *((uint8_t *)&(m)) = ((n)&0xFFU); \
+#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
+ { \
+ *((uint8_t *)&(m) + 1) = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
+ *((uint8_t *)&(m)) = ((((uint16_t)(n))) & 0xFFU); \
}
-#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
+#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \
+ ((uint16_t)(((uint16_t)(*(((uint8_t *)&(n)) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n))))))
#endif
/*
* The following MACROs (USB_GLOBAL, USB_BDT, USB_RAM_ADDRESS_ALIGNMENT, etc) are only used for USB device stack.
- * The USB device global variables are put into the section m_usb_global and m_usb_bdt or the section
- * .bss.m_usb_global and .bss.m_usb_bdt by using the MACRO USB_GLOBAL and USB_BDT. In this way, the USB device
+ * The USB device global variables are put into the section m_usb_global and m_usb_bdt
+ * by using the MACRO USB_GLOBAL and USB_BDT. In this way, the USB device
* global variables can be linked into USB dedicated RAM by USB_STACK_USE_DEDICATED_RAM.
* The MACRO USB_STACK_USE_DEDICATED_RAM is used to decide the USB stack uses dedicated RAM or not. The value of
- * the marco can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT.
+ * the macro can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT.
* The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL means USB device global variables, including USB_BDT and
* USB_GLOBAL, are put into the USB dedicated RAM. This feature can only be enabled when the USB dedicated RAM
* is not less than 2K Bytes.
@@ -313,40 +307,63 @@ _Pragma("diag_suppress=Pm120")
#define USB_RAM_ADDRESS_ALIGNMENT(n) USB_ALIGN_PRAGMA(data_alignment = n)
_Pragma("diag_suppress=Pm120")
#define USB_LINK_SECTION_PART(str) _Pragma(#str)
-#define USB_LINK_SECTION_SUB(sec) USB_LINK_SECTION_PART(location = #sec)
+#define USB_LINK_DMA_INIT_DATA(sec) USB_LINK_SECTION_PART(location = #sec)
#define USB_LINK_USB_GLOBAL _Pragma("location = \"m_usb_global\"")
#define USB_LINK_USB_BDT _Pragma("location = \"m_usb_bdt\"")
-#define USB_LINK_USB_GLOBAL_BSS _Pragma("location = \".bss.m_usb_global\"")
-#define USB_LINK_USB_BDT_BSS _Pragma("location = \".bss.m_usb_bdt\"")
+#define USB_LINK_USB_GLOBAL_BSS
+#define USB_LINK_USB_BDT_BSS
_Pragma("diag_default=Pm120")
#define USB_LINK_DMA_NONINIT_DATA _Pragma("location = \"m_usb_dma_noninit_data\"")
#define USB_LINK_NONCACHE_NONINIT_DATA _Pragma("location = \"NonCacheable\"")
-#elif defined(__CC_ARM)
+#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION))
#define USB_WEAK_VAR __attribute__((weak))
-#define USB_WEAK_FUN __weak
+#define USB_WEAK_FUN __attribute__((weak))
#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
-#define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
+#define USB_LINK_DMA_INIT_DATA(sec) __attribute__((section(#sec)))
+#if defined(__CC_ARM)
#define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global"))) __attribute__((zero_init))
+#else
+#define USB_LINK_USB_GLOBAL __attribute__((section(".bss.m_usb_global")))
+#endif
+#if defined(__CC_ARM)
#define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt"))) __attribute__((zero_init))
-#define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global"))) __attribute__((zero_init))
-#define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt"))) __attribute__((zero_init))
+#else
+#define USB_LINK_USB_BDT __attribute__((section(".bss.m_usb_bdt")))
+#endif
+#define USB_LINK_USB_GLOBAL_BSS
+#define USB_LINK_USB_BDT_BSS
+#if defined(__CC_ARM)
#define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data"))) __attribute__((zero_init))
+#else
+#define USB_LINK_DMA_NONINIT_DATA __attribute__((section(".bss.m_usb_dma_noninit_data")))
+#endif
+#if defined(__CC_ARM)
#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable"))) __attribute__((zero_init))
+#else
+#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section(".bss.NonCacheable")))
+#endif
#elif defined(__GNUC__)
#define USB_WEAK_VAR __attribute__((weak))
#define USB_WEAK_FUN __attribute__((weak))
#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
-#define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
+#define USB_LINK_DMA_INIT_DATA(sec) __attribute__((section(#sec)))
#define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global, \"aw\", %nobits @")))
#define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt, \"aw\", %nobits @")))
-#define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global, \"aw\", %nobits @")))
-#define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt, \"aw\", %nobits @")))
+#define USB_LINK_USB_GLOBAL_BSS
+#define USB_LINK_USB_BDT_BSS
#define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data, \"aw\", %nobits @")))
#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable, \"aw\", %nobits @")))
+#elif (defined(__DSC__) && defined(__CW__))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define USB_WEAK_VAR __attribute__((weak))
+#define USB_WEAK_FUN __attribute__((weak))
+#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
+#define USB_LINK_USB_BDT_BSS
+#define USB_LINK_USB_GLOBAL_BSS
#else
#error The tool-chain is not supported.
#endif
@@ -356,28 +373,32 @@ _Pragma("diag_suppress=Pm120")
#if ((defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)) && (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
#define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
-#elif(defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))
+#elif (defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))
#define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, 0)
-#elif(defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))
+#elif (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))
#define USB_CACHE_LINESIZE MAX(0, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
#else
-#define USB_CACHE_LINESIZE 4
+#define USB_CACHE_LINESIZE 4U
#endif
#else
-#define USB_CACHE_LINESIZE 4
+#define USB_CACHE_LINESIZE 4U
#endif
#if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
-#define USB_DATA_ALIGN 64
+#define USB_DATA_ALIGN 64U
#else
-#define USB_DATA_ALIGN 4
+#define USB_DATA_ALIGN 4U
#endif
-#define USB_DATA_ALIGN_SIZE MAX(USB_CACHE_LINESIZE, USB_DATA_ALIGN)
+#if (USB_CACHE_LINESIZE > USB_DATA_ALIGN)
+#define USB_DATA_ALIGN_SIZE USB_CACHE_LINESIZE
+#else
+#define USB_DATA_ALIGN_SIZE USB_DATA_ALIGN
+#endif
-#define USB_DATA_ALIGN_SIZE_MULTIPLE(n) ((n + USB_DATA_ALIGN_SIZE - 1) & (~(USB_DATA_ALIGN_SIZE - 1)))
+#define USB_DATA_ALIGN_SIZE_MULTIPLE(n) (((n) + USB_DATA_ALIGN_SIZE - 1U) & (~(USB_DATA_ALIGN_SIZE - 1U)))
#if defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL)
@@ -387,13 +408,19 @@ _Pragma("diag_suppress=Pm120")
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
-#define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
+#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
+#else
+#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
+#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
#else
#define USB_DMA_DATA_NONINIT_SUB
#define USB_DMA_DATA_INIT_SUB
#define USB_CONTROLLER_DATA USB_LINK_USB_GLOBAL
#endif
+#endif
#elif defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT)
@@ -403,7 +430,13 @@ _Pragma("diag_suppress=Pm120")
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
#define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
-#define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
+#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
+#else
+#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
+#define USB_GLOBAL USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
#else
#define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
@@ -411,6 +444,7 @@ _Pragma("diag_suppress=Pm120")
#define USB_DMA_DATA_INIT_SUB
#define USB_CONTROLLER_DATA
#endif
+#endif
#else
@@ -420,10 +454,18 @@ _Pragma("diag_suppress=Pm120")
#define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
#define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
-#define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
#else
+
+#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
+#define USB_GLOBAL USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
+#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
+#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
+#else
#define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
#define USB_BDT USB_LINK_USB_BDT_BSS
#define USB_DMA_DATA_NONINIT_SUB
@@ -433,6 +475,8 @@ _Pragma("diag_suppress=Pm120")
#endif
+#endif
+
#define USB_DMA_NONINIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_NONINIT_SUB
#define USB_DMA_INIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_INIT_SUB
@@ -449,4 +493,4 @@ _Pragma("diag_suppress=Pm120")
/* #define USB_RAM_ADDRESS_NONCACHEREG_ALIGNMENT(n, var) AT_NONCACHEABLE_SECTION_ALIGN(var, n) */
/* #define USB_RAM_ADDRESS_NONCACHEREG(var) AT_NONCACHEABLE_SECTION(var) */
-#endif /* __USB_MISC_H__ */
+#endif /* __USB_MISC_H__ */ \ No newline at end of file