From 4426af03f8f93ecb1fd7926d18771de5d0dfe9df Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 23 Feb 2021 09:44:27 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0imxrt=E7=9A=84pulse?= =?UTF-8?q?=20encoder=E5=92=8Cusb=20host=E9=A9=85=E5=8B=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MIMXRT1052/drivers/fsl_os_abstraction.h | 813 ------- .../drivers/fsl_os_abstraction_config.h | 36 - .../drivers/fsl_os_abstraction_rtthread.c | 917 -------- .../drivers/fsl_os_abstraction_rtthread.h | 130 -- .../MIMXRT1052/drivers/generic_list.c | 475 ---- .../MIMXRT1052/drivers/generic_list.h | 203 -- .../MIMXRT1052/gcc/startup_MIMXRT1052.S | 2 + bsp/imxrt/libraries/MIMXRT1050/SConscript | 13 +- bsp/imxrt/libraries/drivers/SConscript | 15 +- .../libraries/drivers/drv_pulse_encoder.c | 160 -- bsp/imxrt/libraries/drivers/drv_usbh.c | 730 ------ bsp/imxrt/libraries/drivers/drv_usbh.h | 22 - .../libraries/drivers/usb/host/usb_host.h | 139 +- .../drivers/usb/host/usb_host_devices.c | 678 +++--- .../drivers/usb/host/usb_host_devices.h | 39 +- .../drivers/usb/host/usb_host_ehci.c | 2038 ++++++++--------- .../drivers/usb/host/usb_host_ehci.h | 227 +- .../drivers/usb/host/usb_host_framework.c | 261 --- .../drivers/usb/host/usb_host_framework.h | 131 -- .../libraries/drivers/usb/host/usb_host_hci.c | 341 ++- .../libraries/drivers/usb/host/usb_host_hci.h | 44 +- bsp/imxrt/libraries/drivers/usb/include/usb.h | 1 - .../drivers/usb/include/usb_host_config.h | 247 -- .../libraries/drivers/usb/include/usb_misc.h | 336 ++- .../libraries/m480/rtt_port/drv_usbhost.c | 2 +- bsp/rx/applications/application.c | 2 +- bsp/stm32/libraries/HAL_Drivers/drv_usbh.c | 2 +- components/drivers/Kconfig | 8 - components/drivers/include/drivers/usb_host.h | 7 +- components/drivers/pm/debug.log | 0 components/drivers/usb/usbhost/class/hid.c | 130 +- components/drivers/usb/usbhost/class/hid.h | 10 +- components/drivers/usb/usbhost/class/umouse.c | 25 +- components/drivers/usb/usbhost/core/driver.c | 15 +- components/drivers/usb/usbhost/core/hub.c | 30 +- components/drivers/usb/usbhost/core/usbhost.c | 16 +- 36 files changed, 1854 insertions(+), 6391 deletions(-) delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c delete mode 100644 bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h delete mode 100644 bsp/imxrt/libraries/drivers/drv_pulse_encoder.c delete mode 100644 bsp/imxrt/libraries/drivers/drv_usbh.c delete mode 100644 bsp/imxrt/libraries/drivers/drv_usbh.h delete mode 100644 bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c delete mode 100644 bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h delete mode 100644 bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h delete mode 100644 components/drivers/pm/debug.log diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h deleted file mode 100644 index 2ca7485a0c..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction.h +++ /dev/null @@ -1,813 +0,0 @@ -/* - * 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 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 deleted file mode 100644 index 234cf972bc..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_config.h +++ /dev/null @@ -1,36 +0,0 @@ -/*! - * 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_ */ 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 deleted file mode 100644 index afef3d5fca..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c +++ /dev/null @@ -1,917 +0,0 @@ -/*! ********************************************************************************* - * 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 -#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 */ 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 deleted file mode 100644 index 40bd24271a..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_os_abstraction_rtthread.h +++ /dev/null @@ -1,130 +0,0 @@ -/*! ********************************************************************************* - * 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 -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__ diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c deleted file mode 100644 index 80dd21425d..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.c +++ /dev/null @@ -1,475 +0,0 @@ -/* - * 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*/ -} diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h deleted file mode 100644 index def00efe8e..0000000000 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/generic_list.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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_*/ diff --git a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/gcc/startup_MIMXRT1052.S b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/gcc/startup_MIMXRT1052.S index ae0f797605..73003ff20c 100644 --- a/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/gcc/startup_MIMXRT1052.S +++ b/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/gcc/startup_MIMXRT1052.S @@ -367,6 +367,7 @@ Reset_Handler: blt .LC4 #endif /* __STARTUP_INITIALIZE_NONCACHEDATA */ +#ifdef __STARTUP_CLEAR_BSS /* This part of work usually is done in C library startup code. Otherwise, * define this macro to enable it in this startup. * @@ -384,6 +385,7 @@ Reset_Handler: itt lt strlt r0, [r1], #4 blt .LC5 +#endif /* __STARTUP_CLEAR_BSS */ cpsie i /* Unmask interrupts */ #ifndef __START diff --git a/bsp/imxrt/libraries/MIMXRT1050/SConscript b/bsp/imxrt/libraries/MIMXRT1050/SConscript index 0d90aeebfc..58d5ccef78 100644 --- a/bsp/imxrt/libraries/MIMXRT1050/SConscript +++ b/bsp/imxrt/libraries/MIMXRT1050/SConscript @@ -53,6 +53,9 @@ if GetDepend(['BSP_USING_SDRAM']): if GetDepend(['BSP_USING_LCD']): src += ['MIMXRT1052/drivers/fsl_elcdif.c'] +if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']): + src += ['MIMXRT1052/drivers/fsl_usdhc.c'] + if GetDepend(['BSP_USING_CAN']): src += ['MIMXRT1052/drivers/fsl_flexcan.c'] @@ -74,17 +77,7 @@ if GetDepend(['BSP_USING_DMA']): src += ['MIMXRT1052/drivers/fsl_edma.c'] src += ['MIMXRT1052/drivers/fsl_lpuart_edma.c'] src += ['MIMXRT1052/drivers/fsl_lpspi_edma.c'] - -if GetDepend(['BSP_USING_PULSE_ENCODER']): - src += ['MIMXRT1052/drivers/fsl_enc.c'] -#Adding this as XBAR is used in pin mux -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'] group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path) diff --git a/bsp/imxrt/libraries/drivers/SConscript b/bsp/imxrt/libraries/drivers/SConscript index 6cca919f10..3328d2af08 100644 --- a/bsp/imxrt/libraries/drivers/SConscript +++ b/bsp/imxrt/libraries/drivers/SConscript @@ -54,22 +54,15 @@ if GetDepend('BSP_USING_AUDIO'): if GetDepend('BSP_USING_SDIO'): src += ['drv_sdio.c'] - -if GetDepend('BSP_USING_PULSE_ENCODER'): - src += ['drv_pulse_encoder.c'] - -if GetDepend('RT_USING_USB_DEVICE'): + +if GetDepend('BSP_USING_USB_DEVICE'): src += ['drv_usbd.c'] src += Glob('usb/device/*.c') -if GetDepend('RT_USING_USB_DEVICE') or GetDepend('RT_USING_USB_HOST'): +if GetDepend('BSP_USING_USB_DEVICE'): src += Glob('usb/phy/*.c') - CPPDEFINES += ['ENDIANNESS','USE_RTOS'] + CPPDEFINES += ['ENDIANNESS'] -if GetDepend('RT_USING_USB_HOST'): - src += ['drv_usbh.c'] - src += Glob('usb/host/*.c') - path = [cwd,cwd + '/config'] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES) diff --git a/bsp/imxrt/libraries/drivers/drv_pulse_encoder.c b/bsp/imxrt/libraries/drivers/drv_pulse_encoder.c deleted file mode 100644 index 176508ce48..0000000000 --- a/bsp/imxrt/libraries/drivers/drv_pulse_encoder.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-08-23 balanceTWK first version - * 2021-01-19 Leslie Lee port to imxrt series - */ - -#include -#include -#ifdef BSP_USING_PULSE_ENCODER - -#include "fsl_common.h" -#include "fsl_enc.h" - -#define LOG_TAG "drv.pulse_encoder" -#include - -#if !defined(BSP_USING_PULSE_ENCODER1) && !defined(BSP_USING_PULSE_ENCODER2) && !defined(BSP_USING_PULSE_ENCODER3) \ - && !defined(BSP_USING_PULSE_ENCODER4) - #error "Please define at least one BSP_USING_PULSE_ENCODERx" - /* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */ -#elif (defined(BSP_USING_PULSE_ENCODER2) || defined(BSP_USING_PULSE_ENCODER3) || defined(BSP_USING_PULSE_ENCODER4)) || defined(SOC_IMXRT1015_SERIES) - #error "IMXRT1015 had only one quadrature decoder module" -#elif (defined(BSP_USING_PULSE_ENCODER3) || defined(BSP_USING_PULSE_ENCODER4)) || defined(SOC_IMXRT1020_SERIES) - #error "IMXRT1020 had only two quadrature decoder module" -#endif - -enum -{ -#ifdef BSP_USING_PULSE_ENCODER1 - PULSE_ENCODER1_INDEX, -#endif -#ifdef BSP_USING_PULSE_ENCODER2 - PULSE_ENCODER2_INDEX, -#endif -#ifdef BSP_USING_PULSE_ENCODER3 - PULSE_ENCODER3_INDEX, -#endif -#ifdef BSP_USING_PULSE_ENCODER4 - PULSE_ENCODER4_INDEX, -#endif -}; - -struct imxrt_pulse_encoder_device -{ - struct rt_pulse_encoder_device pulse_encoder; - ENC_Type *base; - char *name; -}; -typedef struct imxrt_pulse_encoder_device imxrt_pulse_enccoder_device_t; - -static imxrt_pulse_enccoder_device_t imxrt_pulse_encoder_obj[] = -{ -#ifdef BSP_USING_PULSE_ENCODER1 - { - .base = ENC1, - .name = "pulse1" - }, -#endif -#ifdef BSP_USING_PULSE_ENCODER2 - { - .base = ENC2, - .name = "pulse2" - }, -#endif -#ifdef BSP_USING_PULSE_ENCODER3 - { - .base = ENC3, - .name = "pulse3" - }, -#endif -#ifdef BSP_USING_PULSE_ENCODER4 - { - .base = ENC4, - .name = "pulse4" - }, -#endif -}; - - - -rt_err_t pulse_encoder_init(struct rt_pulse_encoder_device *pulse_encoder) -{ - ENC_Type *base = ((imxrt_pulse_enccoder_device_t *)(pulse_encoder->parent.user_data))->base; - enc_config_t enc_config; - ENC_GetDefaultConfig(&enc_config); - ENC_Init(base, &enc_config); - ENC_DoSoftwareLoadInitialPositionValue(base); /* Update the position counter with initial value. */ - return RT_EOK; -} - -rt_err_t pulse_encoder_clear_count(struct rt_pulse_encoder_device *pulse_encoder) -{ - ENC_SetInitialPositionValue(((imxrt_pulse_enccoder_device_t *)(pulse_encoder->parent.user_data))->base, 0); - return RT_EOK; -} - -rt_int32_t pulse_encoder_get_count(struct rt_pulse_encoder_device *pulse_encoder) -{ - return (rt_int32_t)ENC_GetPositionValue(((imxrt_pulse_enccoder_device_t *)(pulse_encoder->parent.user_data))->base); -} - -rt_err_t pulse_encoder_control(struct rt_pulse_encoder_device *pulse_encoder, rt_uint32_t cmd, void *args) -{ - rt_err_t result; - - result = RT_EOK; - - switch (cmd) - { - case PULSE_ENCODER_CMD_ENABLE: - result = pulse_encoder->ops->init(pulse_encoder); - break; - case PULSE_ENCODER_CMD_DISABLE: - ENC_Deinit(((imxrt_pulse_enccoder_device_t *)(pulse_encoder->parent.user_data))->base); - break; - default: - result = -RT_ENOSYS; - break; - } - - return result; -} - -static const struct rt_pulse_encoder_ops _ops = -{ - .init = pulse_encoder_init, - .get_count = pulse_encoder_get_count, - .clear_count = pulse_encoder_clear_count, - .control = pulse_encoder_control, -}; - -int rt_hw_pulse_encoder_init(void) -{ - int i; - int result; - - result = RT_EOK; - for (i = 0; i < sizeof(imxrt_pulse_encoder_obj) / sizeof(imxrt_pulse_encoder_obj[0]); i++) - { - imxrt_pulse_encoder_obj[i].pulse_encoder.type = AB_PHASE_PULSE_ENCODER; - imxrt_pulse_encoder_obj[i].pulse_encoder.ops = &_ops; - imxrt_pulse_encoder_obj[i].pulse_encoder.parent.user_data = &(imxrt_pulse_encoder_obj[i]); - - if (rt_device_pulse_encoder_register(&imxrt_pulse_encoder_obj[i].pulse_encoder, imxrt_pulse_encoder_obj[i].name, &imxrt_pulse_encoder_obj[i]) != RT_EOK) - { - LOG_E("%s register failed", imxrt_pulse_encoder_obj[i].name); - result = -RT_ERROR; - } - } - - return result; -} -INIT_BOARD_EXPORT(rt_hw_pulse_encoder_init); - -#endif diff --git a/bsp/imxrt/libraries/drivers/drv_usbh.c b/bsp/imxrt/libraries/drivers/drv_usbh.c deleted file mode 100644 index a7e0ad6062..0000000000 --- a/bsp/imxrt/libraries/drivers/drv_usbh.c +++ /dev/null @@ -1,730 +0,0 @@ -/* - * 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 - -#if defined(BSP_USB0_HOST) || defined(BSP_USB1_HOST) -#include "drv_usbh.h" -#include -#include -#include -#include -#include -#include -#include - - -/* 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 deleted file mode 100644 index 9cd4ee0e7d..0000000000 --- a/bsp/imxrt/libraries/drivers/drv_usbh.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 - -#define OTG_PORT 1 - -int imxrt_usbh_register(void); - -#endif - -/************* 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 6d9167ceac..53be402cd3 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host.h +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host.h @@ -1,9 +1,31 @@ /* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016 - 2019 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ #ifndef _USB_HOST_H_ @@ -46,16 +68,6 @@ 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 */ @@ -91,60 +103,7 @@ 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. * @@ -284,8 +243,8 @@ typedef struct _usb_host_pipe_init /*! @brief Cancel transfer parameter structure */ typedef struct _usb_host_cancel_param { - usb_host_pipe_handle pipeHandle; /*!< Canceling pipe handle*/ - usb_host_transfer_t *transfer; /*!< Canceling transfer*/ + usb_host_pipe_handle pipeHandle; /*!< Cancelling pipe handle*/ + usb_host_transfer_t *transfer; /*!< Cancelling transfer*/ } usb_host_cancel_param_t; /******************************************************************************* @@ -383,7 +342,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. * @@ -394,8 +353,7 @@ 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. * @@ -406,8 +364,7 @@ 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. * @@ -418,8 +375,7 @@ 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. * @@ -430,8 +386,7 @@ 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. * @@ -440,8 +395,7 @@ 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. * @@ -450,8 +404,7 @@ 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. * @@ -460,8 +413,7 @@ 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. * @@ -470,7 +422,7 @@ extern void USB_HostOhciIsrFunction(void *hostHandle); * @param[in] hostHandle The host handle. */ extern void USB_HostIp3516HsIsrFunction(void *hostHandle); -#endif + /*! @}*/ /*! @@ -614,7 +566,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. See the usb_spec.h. + * @param[in] usbRequest A USB standard request code. Se 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. @@ -742,10 +694,10 @@ extern usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle, /*! * @brief Update the lpm param. * - * The function is used to configure the lpm token. + * The function is used to configuure the lpm token. * * @param[in] hostHandle The host handle. - * @param[in] lpmParam HIRD value and whether enable remotewakeup. + * @param[in] lpmParam HIRD vaule and whether enable remotewakeup. * */ extern usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam); @@ -763,19 +715,6 @@ 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 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 2bbc89233a..42b16e071e 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.c @@ -1,28 +1,46 @@ /* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016,2019 NXP + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ -#include +#include #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 ******************************************************************************/ @@ -52,7 +70,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, uint32_t dataLength); +static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance); /*! * @brief notify the application event, the callback is registered when initializing host. @@ -62,10 +80,7 @@ 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_handle hostHandle, - usb_host_device_instance_t *deviceInstance, - uint32_t eventCode, - uint32_t eventParameter); +static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInstance, uint32_t eventCode); /*! * @brief allocate one address. @@ -125,57 +140,68 @@ 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 */ { - kStatus_DEV_Notinit, - kStatus_DEV_Notinit, - NULL, + 0, 0, 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, }, }; @@ -185,66 +211,69 @@ 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) { - /* 0 - retry current transfer, 1 - transfer success process, - * 2 - retry whole process, 3 - fail process - */ - uint8_t nextStep = 0U; + uint8_t nextStep = 0; usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)param; - usb_status_t failReason = kStatus_USB_Success; - uint32_t dataLength; - dataLength = transfer->transferSofar; - (void)USB_HostFreeTransfer(deviceInstance->hostHandle, transfer); /* free transfer */ + USB_HostFreeTransfer(deviceInstance->hostHandle, transfer); /* free transfer */ if (status == kStatus_USB_Success) { - nextStep = 1U; + nextStep = 1; } else if (status == kStatus_USB_TransferStall) { #if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST)) - (void)usb_echo("no response from device\r\n"); -#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */ - if (deviceInstance->stallRetries > 0U) /* retry same transfer when stall */ + usb_echo("no response from device\r\n"); +#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */ + if (deviceInstance->stallRetries > 0) /* retry same transfer when stall */ { - nextStep = 0U; deviceInstance->stallRetries--; } - else + else /* process next state when all retries stall */ { - failReason = kStatus_USB_TransferFailed; - nextStep = 2U; + nextStep = 1; } } else if (status == kStatus_USB_TransferCancel) { - failReason = kStatus_USB_TransferCancel; - nextStep = 3U; + return; } else { - failReason = kStatus_USB_TransferFailed; - nextStep = 2U; - } - - if (nextStep == 1U) - { - deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES; - if (s_EnumEntries[deviceInstance->state - 1U].process == NULL) + if (deviceInstance->enumRetries > 0) /* next whole retry */ { - deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].successState; /* next state */ + deviceInstance->enumRetries--; + deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES; + deviceInstance->configurationValue = 0; + deviceInstance->state = kStatus_DEV_GetDes8; } else { - status = s_EnumEntries[deviceInstance->state - 1U].process( - deviceInstance, dataLength); /* process the previous state result */ +#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST)) + usb_echo("Device No Response\r\n"); +#endif + return; + } + } + + if (nextStep == 1) + { + deviceInstance->stallRetries = USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES; + if (s_EnumEntries[deviceInstance->state - 1].process == NULL) + { + deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].successState; /* next state */ + } + else + { + status = s_EnumEntries[deviceInstance->state - 1].process( + deviceInstance); /* process the previous state result */ if (status == kStatus_USB_Success) /* process success */ { - deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].successState; + deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].successState; } else if (status == kStatus_USB_Retry) /* need retry */ { - deviceInstance->state = (uint8_t)s_EnumEntries[deviceInstance->state - 1U].retryState; + deviceInstance->state = s_EnumEntries[deviceInstance->state - 1].retryState; } else if (status == kStatus_USB_NotSupported) /* device don't suport by the application */ { @@ -252,48 +281,30 @@ static void USB_HostEnumerationTransferCallback(void *param, usb_host_transfer_t } else /* process error, next retry */ { - /* kStatus_USB_Error or kStatus_USB_AllocFail */ - failReason = status; - nextStep = 2U; + 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; /* unrecoverable fail */ + } } } } - if (nextStep == 2U) + if (USB_HostProcessState(deviceInstance) != kStatus_USB_Success) /* process the new state */ { - 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"); -#endif - nextStep = 3U; - } - } - - /* 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 - failReason = kStatus_USB_Error; - nextStep = 3U; - } - } - - if (nextStep == 3U) - { - (void)USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, (uint32_t)kUSB_HostEventEnumerationFail, - (uint32_t)failReason); + return; } } @@ -302,11 +313,9 @@ 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 */ - state = (usb_host_device_enumeration_status_t)deviceInstance->state; - if (state != kStatus_DEV_EnumDone) + if (deviceInstance->state != kStatus_DEV_EnumDone) { if (USB_HostMallocTransfer(deviceInstance->hostHandle, &transfer) != kStatus_USB_Success) { @@ -315,29 +324,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 = 0x00U; - transfer->setupPacket->wIndex = 0U; - transfer->setupPacket->wLength = 0U; - transfer->setupPacket->wValue = 0U; + transfer->setupPacket->bmRequestType = 0x00; + transfer->setupPacket->wIndex = 0; + transfer->setupPacket->wLength = 0; + transfer->setupPacket->wValue = 0; } - switch (state) + switch (deviceInstance->state) { case kStatus_DEV_GetDes8: case kStatus_DEV_GetDes: /* get descriptor state */ getDescriptorParam.descriptorLength = sizeof(usb_descriptor_device_t); - if (deviceInstance->state == (uint8_t)kStatus_DEV_GetDes8) + if (deviceInstance->state == kStatus_DEV_GetDes8) { - getDescriptorParam.descriptorLength = 8U; + getDescriptorParam.descriptorLength = 8; } getDescriptorParam.descriptorBuffer = (uint8_t *)deviceInstance->deviceDescriptor; - getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE; - getDescriptorParam.descriptorIndex = 0U; - getDescriptorParam.languageId = 0U; + getDescriptorParam.descriptorType = USB_DESCRIPTOR_TYPE_DEVICE; + getDescriptorParam.descriptorIndex = 0; + getDescriptorParam.languageId = 0; transfer->setupPacket->bmRequestType |= USB_REQUEST_TYPE_DIR_IN; transfer->setupPacket->bRequest = USB_REQUEST_STANDARD_GET_DESCRIPTOR; @@ -350,10 +359,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; @@ -362,10 +371,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; @@ -376,71 +385,52 @@ 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 */ - /* notify device enumeration done */ - status = USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, - (uint32_t)kUSB_HostEventEnumerationDone, (uint32_t)kStatus_USB_Success); + status = USB_HostNotifyDevice(deviceInstance, + kUSB_HostEventEnumerationDone); /* notify device enumeration done */ if (status == kStatus_USB_Success) { - deviceInstance->state = (uint8_t)kStatus_DEV_AppUsed; + deviceInstance->state = kStatus_DEV_AppUsed; } break; default: - /*no action*/ break; } return status; } -static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance, uint32_t dataLength) +static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceInstance) { 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; - state = (usb_host_device_enumeration_status_t)deviceInstance->state; - switch (state) + switch (deviceInstance->state) { case kStatus_DEV_GetDes8: /* process get 8 bytes descriptor result */ - if (dataLength != 8u) - { - return kStatus_USB_Error; - } pipe->maxPacketSize = deviceInstance->deviceDescriptor->bMaxPacketSize0; - /* the callbackFn is initialized in USB_HostGetControllerInterface */ - (void)hostInstance->controllerTable->controllerIoctl( + hostInstance->controllerTable->controllerIoctl( hostInstance->controllerHandle, kUSB_HostUpdateControlPacketSize, deviceInstance->controlPipe); break; case kStatus_DEV_SetAddress: /* process set address result */ deviceInstance->setAddress = deviceInstance->allocatedAddress; - /* the callbackFn is initialized in USB_HostGetControllerInterface */ - (void)hostInstance->controllerTable->controllerIoctl( + hostInstance->controllerTable->controllerIoctl( hostInstance->controllerHandle, kUSB_HostUpdateControlEndpointAddress, deviceInstance->controlPipe); break; - case kStatus_DEV_GetDes: /* process get full device descriptor result */ - if (dataLength != sizeof(usb_descriptor_device_t)) - { - return kStatus_USB_Error; - } + case kStatus_DEV_GetDes: /* process set address result */ + /* NULL */ break; case kStatus_DEV_GetCfg9: /* process get 9 bytes configuration result */ - if (dataLength != 9u) - { - return kStatus_USB_Error; - } - temp = (void *)&deviceInstance->enumBuffer[0]; - configureDesc = (usb_descriptor_configuration_t *)temp; + configureDesc = (usb_descriptor_configuration_t *)&deviceInstance->enumBuffer[0]; deviceInstance->configurationLen = USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(configureDesc->wTotalLength); if (deviceInstance->configurationDesc != NULL) @@ -448,25 +438,19 @@ 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 - OSA_MemoryFree(deviceInstance->configurationDesc); + USB_OsaMemoryFree(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 & 0x03U) != 0U) + if ((deviceInstance->configurationLen & 0x03) != 0) { #if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U)) deviceInstance->configurationDesc = - (uint8_t *)SDK_Malloc((deviceInstance->configurationLen & 0xFFFCu) + 4, USB_CACHE_LINESIZE); + (uint8_t *)SDK_Malloc((deviceInstance->configurationLen & 0xFFFFFFFCu) + 4, USB_CACHE_LINESIZE); #else deviceInstance->configurationDesc = - (uint8_t *)OSA_MemoryAllocate((((uint32_t)deviceInstance->configurationLen) & 0xFFFCU) + 4UL); + (uint8_t *)USB_OsaMemoryAllocate((deviceInstance->configurationLen & 0xFFFFFFFCu) + 4); #endif } else @@ -475,22 +459,18 @@ 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 *)OSA_MemoryAllocate(deviceInstance->configurationLen); + deviceInstance->configurationDesc = (uint8_t *)USB_OsaMemoryAllocate(deviceInstance->configurationLen); #endif } if (deviceInstance->configurationDesc == NULL) { - return kStatus_USB_AllocFail; + return kStatus_USB_Error; } break; - 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) + case kStatus_DEV_GetCfg: /* process get cofiguration result */ + if (((usb_descriptor_configuration_t *)deviceInstance->configurationDesc)->bMaxPower > + USB_HOST_CONFIG_MAX_POWER) { return kStatus_USB_Error; } @@ -501,8 +481,7 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn return kStatus_USB_Error; } - status = USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, (uint32_t)kUSB_HostEventAttach, - (uint32_t)kStatus_USB_Success); + status = USB_HostNotifyDevice(deviceInstance, kUSB_HostEventAttach); if (status != kStatus_USB_Success) { @@ -513,9 +492,8 @@ static usb_status_t USB_HostProcessCallback(usb_host_device_instance_t *deviceIn } else { - /* notify application device is not supported */ - (void)USB_HostNotifyDevice(deviceInstance->hostHandle, deviceInstance, - (uint32_t)kUSB_HostEventNotSupported, (uint32_t)kStatus_USB_Success); + USB_HostNotifyDevice(deviceInstance, + kUSB_HostEventNotSupported); /* notify application device is not supported */ return kStatus_USB_NotSupported; } } @@ -526,17 +504,13 @@ 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_handle hostHandle, - usb_host_device_instance_t *deviceInstance, - uint32_t eventCode, - uint32_t eventParameter) +static usb_status_t USB_HostNotifyDevice(usb_host_device_instance_t *deviceInstance, uint32_t eventCode) { usb_host_instance_t *hostInstance; usb_status_t status1 = kStatus_USB_Error; @@ -547,37 +521,34 @@ static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle, 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 = 0U; - haveNoHub = 0U; - for (interfaceIndex = 0U; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex) + haveHub = 0; + haveNoHub = 0; + for (interfaceIndex = 0; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex) { if (((usb_descriptor_interface_t *)deviceInstance->configuration.interfaceList[interfaceIndex].interfaceDesc) ->bInterfaceClass == USB_HOST_HUB_CLASS_CODE) { - haveHub = 1U; + haveHub = 1; } else { - haveNoHub = 1U; + haveNoHub = 1; } } - if ((hostInstance->deviceCallback != NULL) && - ((haveNoHub == 1U) || (deviceInstance->configuration.interfaceCount == 0U))) + if ((haveNoHub == 1) && (hostInstance->deviceCallback != NULL)) { - /* call host callback function, function is initialized in USB_HostInit */ - status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, eventCode); + status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, + eventCode); /* notify application event */ } - if (0U != haveHub) + if (haveHub) { status2 = USB_HostHubDeviceEvent(hostInstance, deviceInstance, &deviceInstance->configuration, eventCode); /* notify hub event */ @@ -587,7 +558,7 @@ static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle, { return kStatus_USB_Success; } - else if (eventCode == (uint32_t)kUSB_HostEventAttach) /* attach event */ + else if (eventCode == kUSB_HostEventAttach) /* attach event */ { status1 = kStatus_USB_NotSupported; } @@ -598,8 +569,8 @@ static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle, #else if (hostInstance->deviceCallback != NULL) { - /* call host callback function, function is initialized in USB_HostInit */ - status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, eventCode); + status1 = hostInstance->deviceCallback(deviceInstance, &deviceInstance->configuration, + eventCode); /* call host callback function */ } #endif return status1; @@ -607,24 +578,24 @@ static usb_status_t USB_HostNotifyDevice(usb_host_handle hostHandle, static uint8_t USB_HostAllocateDeviceAddress(usb_host_instance_t *hostInstance) { - uint8_t address = 0U; + uint8_t address = 0; uint8_t addressIndex; uint8_t addressBitIndex; - for (addressIndex = 0U; addressIndex < 8U; ++addressIndex) /* find the idle address position byte */ + for (addressIndex = 0; addressIndex < 8; ++addressIndex) /* find the idle address postion byte */ { - if (hostInstance->addressBitMap[addressIndex] != 0xFFU) + if (hostInstance->addressBitMap[addressIndex] != 0xFF) { break; } } - if (addressIndex < 8U) + if (addressIndex < 8) { - for (addressBitIndex = 0U; addressBitIndex < 8U; ++addressBitIndex) /* find the idle address position bit */ + for (addressBitIndex = 0; addressBitIndex < 8; ++addressBitIndex) /* find the idle address position bit */ { - if (0U == (hostInstance->addressBitMap[addressIndex] & (0x01U << addressBitIndex))) + if (!(hostInstance->addressBitMap[addressIndex] & (0x01u << addressBitIndex))) { - hostInstance->addressBitMap[addressIndex] |= (0x01U << addressBitIndex); /* set the allocated bit */ - address = addressIndex * 8U + addressBitIndex + 1U; /* the address minimum is 1 */ + hostInstance->addressBitMap[addressIndex] |= (0x01u << addressBitIndex); /* set the allocated bit */ + address = addressIndex * 8 + addressBitIndex + 1; /* the address minimum is 1 */ break; } } @@ -634,10 +605,10 @@ static uint8_t USB_HostAllocateDeviceAddress(usb_host_instance_t *hostInstance) static void USB_HostReleaseDeviceAddress(usb_host_instance_t *hostInstance, uint8_t address) { - (void)USB_HostLock(); - hostInstance->addressBitMap[((uint32_t)address - 1U) >> 3U] &= - (~(0x01U << (((uint32_t)address - 1U) & 0x07U))); /* reset the allocated bit */ - (void)USB_HostUnlock(); + USB_HostLock(); + hostInstance->addressBitMap[(uint32_t)(address - 1) >> 3] &= + (~(0x01u << (((uint32_t)address - 1) & 0x07U))); /* reset the allocated bit */ + USB_HostUnlock(); } static usb_status_t USB_HostRemoveDeviceInstance(usb_host_handle hostHandle, usb_device_handle deviceHandle) @@ -669,7 +640,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; } @@ -689,13 +660,13 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb } #endif /* release device's address */ - if (deviceInstance->setAddress != 0U) + if (deviceInstance->setAddress != 0) { USB_HostReleaseDeviceAddress(hostInstance, deviceInstance->setAddress); } else { - if (deviceInstance->allocatedAddress != 0U) + if (deviceInstance->allocatedAddress != 0) { USB_HostReleaseDeviceAddress(hostInstance, deviceInstance->allocatedAddress); } @@ -704,7 +675,7 @@ static void USB_HostReleaseDeviceResource(usb_host_instance_t *hostInstance, usb /* close control pipe */ if (deviceInstance->controlPipe != NULL) { - (void)USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL); + USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL); if (USB_HostClosePipe(hostInstance, deviceInstance->controlPipe) != kStatus_USB_Success) { #ifdef HOST_ECHO @@ -720,7 +691,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 - OSA_MemoryFree(deviceInstance->configurationDesc); + USB_OsaMemoryFree(deviceInstance->configurationDesc); #endif } @@ -730,20 +701,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 - OSA_MemoryFree(deviceInstance->deviceDescriptor); + USB_OsaMemoryFree(deviceInstance->deviceDescriptor); #endif /* free device instance buffer */ - OSA_MemoryFree(deviceInstance); + USB_OsaMemoryFree(deviceInstance); #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB)) /* enable controller attach if root hub */ - if (level == 1U) + if (level == 1) { - (void)USB_HostControlBus(hostInstance, (uint8_t)kUSB_HostBusEnableAttach); + USB_HostControlBus(hostInstance, kUSB_HostBusEnableAttach); } #else /* enable controller attach */ - USB_HostControlBus(hostInstance, (uint8_t)kUSB_HostBusEnableAttach); + USB_HostControlBus(hostInstance, kUSB_HostBusEnableAttach); #endif } @@ -755,39 +726,35 @@ 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; } - temp = (void *)&deviceInstance->configuration; - buffer = (uint8_t *)temp; + buffer = (uint8_t *)&deviceInstance->configuration; /* clear the previous parse result, note: end_pos means buffer index here*/ - for (endPos = 0U; endPos < sizeof(usb_host_configuration_t); endPos++) + for (endPos = 0; endPos < sizeof(usb_host_configuration_t); endPos++) { - buffer[endPos] = 0U; + buffer[endPos] = 0; } - for (endPos = 0U; endPos < USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE; ++endPos) + for (endPos = 0; endPos < USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE; ++endPos) { - deviceInstance->interfaceStatus[endPos] = 0U; + deviceInstance->interfaceStatus[endPos] = 0; } /* parse configuration descriptor */ - temp = (void *)deviceInstance->configurationDesc; - unionDes = (usb_descriptor_union_t *)temp; - endPos = (uint32_t)(deviceInstance->configurationDesc + deviceInstance->configurationLen); + unionDes = (usb_descriptor_union_t *)deviceInstance->configurationDesc; + endPos = (uint32_t)(deviceInstance->configurationDesc + deviceInstance->configurationLen); if ((unionDes->common.bLength == USB_DESCRIPTOR_LENGTH_CONFIGURE) && (unionDes->common.bDescriptorType == USB_DESCRIPTOR_TYPE_CONFIGURE)) { /* configuration descriptor */ - temp = (void *)unionDes; - deviceInstance->configuration.configurationDesc = (usb_descriptor_configuration_t *)temp; + deviceInstance->configuration.configurationDesc = (usb_descriptor_configuration_t *)unionDes; 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) { @@ -797,8 +764,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle { deviceInstance->configuration.configurationExtension = (uint8_t *)unionDes; } - if ((unionDes->common.bDescriptorType == 0x00U) || - (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */ + if ((unionDes->common.bDescriptorType == 0x00) || + (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -812,17 +779,17 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle } /* interface descriptor */ - deviceInstance->configuration.interfaceCount = 0U; + deviceInstance->configuration.interfaceCount = 0; while ((uint32_t)unionDes < endPos) { if (unionDes->common.bDescriptorType == USB_DESCRIPTOR_TYPE_INTERFACE) { - if (unionDes->interface.bAlternateSetting == 0x00U) + if (unionDes->interface.bAlternateSetting == 0x00) { if (deviceInstance->configuration.interfaceCount >= USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE) { -#if (((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST)) || defined(HOST_ECHO)) - (void)usb_echo( +#ifdef HOST_ECHO + 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 @@ -831,13 +798,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 == 0x00U) /* the descriptor data is wrong */ + interfaceParse->interfaceExtension = NULL; + interfaceParse->interfaceIndex = unionDes->interface.bInterfaceNumber; + if (unionDes->common.bLength == 0x00) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -851,8 +818,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle { interfaceParse->interfaceExtension = (uint8_t *)unionDes; } - if ((unionDes->common.bDescriptorType == 0x00U) || - (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */ + if ((unionDes->common.bDescriptorType == 0x00) || + (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -866,7 +833,7 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle } /* endpoint descriptor */ - if (interfaceParse->interfaceDesc->bNumEndpoints != 0U) + if (interfaceParse->interfaceDesc->bNumEndpoints != 0) { if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) || (interfaceParse->interfaceDesc->bNumEndpoints > USB_HOST_CONFIG_INTERFACE_MAX_EP)) @@ -887,13 +854,11 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle #endif return kStatus_USB_Error; } - 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 */ + 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 */ { return kStatus_USB_Error; } @@ -907,8 +872,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle { epParse->epExtension = (uint8_t *)unionDes; } - if ((unionDes->common.bDescriptorType == 0x00U) || - (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */ + if ((unionDes->common.bDescriptorType == 0x00) || + (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -935,7 +900,7 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle { interfaceParse->interfaceExtension = (uint8_t *)unionDes; } - if (unionDes->common.bLength == 0x00U) /* the descriptor data is wrong */ + if (unionDes->common.bLength == 0x00) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -945,8 +910,8 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle { if (unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_INTERFACE) { - if ((unionDes->common.bDescriptorType == 0x00U) || - (unionDes->common.bLength == 0x00U)) /* the descriptor data is wrong */ + if ((unionDes->common.bDescriptorType == 0x00) || + (unionDes->common.bLength == 0x00)) /* the descriptor data is wrong */ { return kStatus_USB_Error; } @@ -967,9 +932,9 @@ static usb_status_t USB_HostParseDeviceConfigurationDescriptor(usb_device_handle } } - for (endPos = 0U; endPos < deviceInstance->configuration.interfaceCount; ++endPos) + for (endPos = 0; endPos < deviceInstance->configuration.interfaceCount; ++endPos) { - deviceInstance->interfaceStatus[endPos] = (uint8_t)kStatus_interface_Attached; + deviceInstance->interfaceStatus[endPos] = kStatus_interface_Attached; } return kStatus_USB_Success; @@ -1023,29 +988,28 @@ usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle, #endif /* Allocate new device instance */ - newInstance = (usb_host_device_instance_t *)OSA_MemoryAllocate(sizeof(usb_host_device_instance_t)); + newInstance = (usb_host_device_instance_t *)USB_OsaMemoryAllocate(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 = (uint8_t)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 = 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 *)OSA_MemoryAllocate(sizeof(usb_descriptor_device_t) + 9U); + newInstance->deviceDescriptor = + (usb_descriptor_device_t *)USB_OsaMemoryAllocate(sizeof(usb_descriptor_device_t) + 9); #endif if (newInstance->deviceDescriptor == NULL) { @@ -1055,66 +1019,62 @@ 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 - OSA_MemoryFree(newInstance->deviceDescriptor); + USB_OsaMemoryFree(newInstance->deviceDescriptor); #endif - OSA_MemoryFree(newInstance); - (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail, - (uint32_t)kStatus_USB_AllocFail); + USB_OsaMemoryFree(newInstance); 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 > 1U)) + if ((speed != USB_SPEED_HIGH) && (level > 1)) { - newInstance->hsHubNumber = (uint8_t)USB_HostHubGetHsHubNumber(hostHandle, hubNumber); - newInstance->hsHubPort = (uint8_t)USB_HostHubGetHsHubPort(hostHandle, hubNumber, portNumber); + newInstance->hsHubNumber = USB_HostHubGetHsHubNumber(hostHandle, hubNumber); + newInstance->hsHubPort = USB_HostHubGetHsHubPort(hostHandle, hubNumber, portNumber); } else { newInstance->hsHubNumber = hubNumber; - newInstance->hsHubPort = portNumber; + newInstance->hsHubPort = portNumber; } #endif /* USB_HOST_CONFIG_HUB */ - (void)USB_HostLock(); + USB_HostLock(); /* allocate address && insert to the dev list */ address = USB_HostAllocateDeviceAddress(hostInstance); - if (address == 0U) + if (address == 0) { #ifdef HOST_ECHO usb_echo("allocate address fail\r\n"); #endif - (void)USB_HostUnlock(); + USB_HostUnlock(); #if ((defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE)) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U)) SDK_Free(newInstance->deviceDescriptor); #else - OSA_MemoryFree(newInstance->deviceDescriptor); + USB_OsaMemoryFree(newInstance->deviceDescriptor); #endif - OSA_MemoryFree(newInstance); - (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail, - (uint32_t)kStatus_USB_Error); + USB_OsaMemoryFree(newInstance); 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 = (uint8_t)kStatus_DEV_Initial; - (void)USB_HostUnlock(); + newInstance->state = kStatus_DEV_Initial; + 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 */ @@ -1122,22 +1082,15 @@ 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 - OSA_MemoryFree(newInstance->deviceDescriptor); + USB_OsaMemoryFree(newInstance->deviceDescriptor); #endif - OSA_MemoryFree(newInstance); - (void)USB_HostNotifyDevice(hostInstance, NULL, (uint32_t)kUSB_HostEventEnumerationFail, - (uint32_t)kStatus_USB_Error); + USB_OsaMemoryFree(newInstance); return kStatus_USB_Error; } /* start enumeration */ - 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); - } + newInstance->state = kStatus_DEV_GetDes8; + USB_HostProcessState(newInstance); /* process enumeration state machine */ *deviceHandle = newInstance; return kStatus_USB_Success; @@ -1153,7 +1106,7 @@ usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber, return kStatus_USB_InvalidHandle; } - (void)USB_HostLock(); + 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; @@ -1168,7 +1121,7 @@ usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber, #else deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList; #endif - (void)USB_HostUnlock(); + USB_HostUnlock(); if (deviceInstance != NULL) { return USB_HostDetachDeviceInternal(hostHandle, deviceInstance); /* device instance detach */ @@ -1179,33 +1132,31 @@ 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 = (uint8_t)kStatus_device_Detached; /* mark the device is detached from host */ + deviceInstance->deviceAttachState = kStatus_device_Detached; /* mark the device is detached from host */ - if (deviceInstance->state >= (uint8_t)kStatus_DEV_Initial) /* device instance is valid */ + if (deviceInstance->state >= kStatus_DEV_Initial) /* device instance is valid */ { /* detach internally */ - if (deviceInstance->state < (uint8_t)kStatus_DEV_AppUsed) /* enumeration is not done */ + if (deviceInstance->state < kStatus_DEV_AppUsed) /* enumeration is not done */ { if (deviceInstance->controlPipe != NULL) { - (void)USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL); + USB_HostCancelTransfer(hostInstance, deviceInstance->controlPipe, NULL); } /* remove device instance from host */ - (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); + USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); USB_HostReleaseDeviceResource(hostInstance, deviceInstance); } - else /* enumeration has be done and notified application */ + else /* enumeration has be done and notifed application */ { - /* notify application device detach */ - (void)USB_HostNotifyDevice(hostInstance, deviceInstance, (uint32_t)kUSB_HostEventDetach, - (uint32_t)kStatus_USB_Success); + USB_HostNotifyDevice(deviceInstance, kUSB_HostEventDetach); /* notify application device detach */ } } @@ -1214,7 +1165,7 @@ usb_status_t USB_HostDetachDeviceInternal(usb_host_handle hostHandle, usb_device uint8_t USB_HostGetDeviceAttachState(usb_device_handle deviceHandle) { - return (NULL != deviceHandle) ? ((usb_host_device_instance_t *)deviceHandle)->deviceAttachState : 0x0U; + return deviceHandle ? ((usb_host_device_instance_t *)deviceHandle)->deviceAttachState : 0x0; } usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle) @@ -1232,7 +1183,7 @@ usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handl searchDev = searchDev->next; } - if (NULL != searchDev) + if (searchDev) { return kStatus_USB_Success; } @@ -1241,14 +1192,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); @@ -1258,7 +1209,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; @@ -1268,11 +1219,11 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos } hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle; - (void)USB_HostLock(); + USB_HostLock(); /* check host_instance valid? */ for (; index < USB_HOST_CONFIG_MAX_HOST; ++index) { - if ((g_UsbHostInstance[index].occupied == 1U) && + if ((g_UsbHostInstance[index].occupied == 1) && ((usb_host_instance_t *)(&g_UsbHostInstance[index]) == (hostInstance))) { break; @@ -1280,14 +1231,14 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos } if (index >= USB_HOST_CONFIG_MAX_HOST) { - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Error; } /* check deviceHandle valid? */ if (USB_HostValidateDevice(hostInstance, deviceHandle) != kStatus_USB_Success) { - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Error; } @@ -1296,11 +1247,11 @@ usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle, usb_hos { if (&deviceInstance->configuration.interfaceList[interfaceIndex] == interfaceHandle) { - deviceInstance->interfaceStatus[interfaceIndex] = (uint8_t)kStatus_interface_Opened; + deviceInstance->interfaceStatus[interfaceIndex] = kStatus_interface_Opened; break; } } - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Success; } @@ -1308,10 +1259,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) { @@ -1319,11 +1270,11 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho } hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle; - (void)USB_HostLock(); + USB_HostLock(); /* check host_instance valid? */ for (; index < USB_HOST_CONFIG_MAX_HOST; ++index) { - if ((g_UsbHostInstance[index].occupied == 1U) && + if ((g_UsbHostInstance[index].occupied == 1) && ((usb_host_instance_t *)(&g_UsbHostInstance[index]) == (hostInstance))) { break; @@ -1331,14 +1282,14 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho } if (index >= USB_HOST_CONFIG_MAX_HOST) { - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Error; } /* check deviceHandle valid? */ if (USB_HostValidateDevice(hostInstance, deviceHandle) != kStatus_USB_Success) { - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Error; } @@ -1349,32 +1300,32 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho { if (&deviceInstance->configuration.interfaceList[interfaceIndex] == interfaceHandle) { - deviceInstance->interfaceStatus[interfaceIndex] = (uint8_t)kStatus_interface_Detached; + deviceInstance->interfaceStatus[interfaceIndex] = kStatus_interface_Detached; break; } } } - if (deviceInstance->deviceAttachState == (uint8_t)kStatus_device_Detached) /* device is removed from host */ + if (deviceInstance->deviceAttachState == 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] == (uint8_t)kStatus_interface_Opened) + if (deviceInstance->interfaceStatus[interfaceIndex] == kStatus_interface_Opened) { - removeLabel = 0U; + removeLabel = 0; break; } } - if (removeLabel == 1U) + if (removeLabel == 1) { /* remove device instance from host */ - (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); + USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); } - (void)USB_HostUnlock(); + USB_HostUnlock(); - if (removeLabel == 1U) + if (removeLabel == 1) { USB_HostReleaseDeviceResource((usb_host_instance_t *)deviceInstance->hostHandle, deviceInstance); /* release device resource */ @@ -1382,7 +1333,7 @@ usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle, usb_ho } else { - (void)USB_HostUnlock(); + USB_HostUnlock(); } return kStatus_USB_Success; @@ -1390,9 +1341,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; @@ -1411,26 +1362,25 @@ 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 = (uint8_t)kStatus_device_Detached; - if (deviceInstance->state >= (uint8_t)kStatus_DEV_Initial) /* device is valid */ + deviceInstance->deviceAttachState = kStatus_device_Detached; + if (deviceInstance->state >= kStatus_DEV_Initial) /* device is valid */ { - if (deviceInstance->state < - (uint8_t)kStatus_DEV_AppUsed) /* enumeration is not done or application don't use */ + if (deviceInstance->state < kStatus_DEV_AppUsed) /* enumeraion is not done or application don't use */ { /* detach internally */ - (void)USB_HostDetachDeviceInternal(hostHandle, deviceHandle); + USB_HostDetachDeviceInternal(hostHandle, deviceHandle); } else /* application use the device */ { - for (interfaceIndex = 0U; interfaceIndex < deviceInstance->configuration.interfaceCount; + for (interfaceIndex = 0; interfaceIndex < deviceInstance->configuration.interfaceCount; ++interfaceIndex) { - if (deviceInstance->interfaceStatus[interfaceIndex] == (uint8_t)kStatus_interface_Opened) + if (deviceInstance->interfaceStatus[interfaceIndex] == kStatus_interface_Opened) { #ifdef HOST_ECHO usb_echo("error: there is class instance that is not deinited\r\n"); @@ -1439,20 +1389,20 @@ usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle } } /* remove device instance from host */ - (void)USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); + USB_HostRemoveDeviceInstance(hostInstance, deviceInstance); USB_HostReleaseDeviceResource(hostInstance, deviceInstance); /* release resource */ } } #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB)) - if (level == 1U) + if (level == 1) { - (void)USB_HostControlBus(hostHandle, (uint8_t)kUSB_HostBusReset); /* reset controller port */ - (void)USB_HostControlBus(hostHandle, (uint8_t)kUSB_HostBusRestart); /* restart controller port */ + USB_HostControlBus(hostHandle, kUSB_HostBusReset); /* reset controller port */ + USB_HostControlBus(hostHandle, kUSB_HostBusRestart); /* restart controller port */ } else { - (void)USB_HostHubRemovePort(hostHandle, devHubNo, devPortNo); /* reset hub port */ + USB_HostHubRemovePort(hostHandle, devHubNo, devPortNo); /* reset hub port */ } #else USB_HostControlBus(hostHandle, kUSB_HostBusReset); /* reset controller port */ 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 84d5497c9f..422e876a12 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_devices.h @@ -1,9 +1,31 @@ /* * Copyright (c) 2015, Freescale Semiconductor, Inc. * Copyright 2016 NXP - * All rights reserved. * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ #ifndef _USB_HOST_DEV_MNG_H_ @@ -57,11 +79,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 configurationValue; /*!< Configuration index */ + uint8_t *enumBuffer; /*!< Buffer for enumeration */ uint8_t state; /*!< Device state for enumeration */ uint8_t enumRetries; /*!< Re-enumeration when error in control transfer */ uint8_t stallRetries; /*!< Re-transfer when stall */ @@ -82,10 +104,11 @@ typedef struct _usb_host_device_instance typedef struct _usb_host_enum_process_entry { - 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); + 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_enum_process_entry_t; /******************************************************************************* 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 58059e033d..8a31514b3a 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.c @@ -1,22 +1,41 @@ /* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016,2019 - 2020 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ -#include +#include #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 +#include "usb_phy.h" #if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST)) #include "usb_host.h" #endif @@ -31,16 +50,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) @@ -83,7 +102,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, - uint16_t frameBandwidths[8]); + uint8_t frameBandwidths[8]); /*! * @brief compute current allocated HS bandwidth when ehci work as hi-speed host. @@ -94,7 +113,7 @@ static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t * */ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t *ehciInstance, uint16_t frameIndex, - uint16_t frameBandwidths[8]); + uint8_t frameBandwidths[8]); /*! * @brief allocate HS bandwidth when host work as high-speed host. @@ -156,6 +175,13 @@ 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. * @@ -163,6 +189,13 @@ static void USB_HostEhciDelay(USBHS_Type *ehciIpBase, uint32_t ms); */ 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. * @@ -482,6 +515,16 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc usb_host_ehci_pipe_t *ehciPipePointer, 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. * @@ -489,7 +532,20 @@ static usb_status_t USB_HostEhciCancelPipe(usb_host_ehci_instance_t *ehciInstanc */ 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)) /*! @@ -530,60 +586,71 @@ 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]; -static uint8_t usbHostEhciFramListStatus[1] = {0}; +#define USB_HOST_EHCI_FRAME_LIST_ARRAY \ + { \ + &s_UsbHostEhciFrameList1[0] \ + } USB_RAM_ADDRESS_ALIGNMENT(64) USB_CONTROLLER_DATA static usb_host_ehci_data_t s_UsbHostEhciData1; -#elif (USB_HOST_CONFIG_EHCI == 2U) +#define USB_HOST_EHCI_DATA_ARRAY \ + { \ + &s_UsbHostEhciData1 \ + } +#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]; -static uint8_t usbHostEhciFramListStatus[2] = {0, 0}; +#define USB_HOST_EHCI_FRAME_LIST_ARRAY \ + { \ + &s_UsbHostEhciFrameList1[0], &s_UsbHostEhciFrameList2[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_SlotMaxBandwidthHs[8] = {100, 100, 100, 100, 100, 100, 100, 100}; +static uint8_t s_SlotMaxBandwidth[8] = {125, 125, 125, 125, 125, 125, 50, 0}; /******************************************************************************* * 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)) -static void *USB_EhciNCGetBase(uint8_t controllerId) +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 < (uint8_t)kUSB_ControllerEhci0) + if (controllerId < kUSB_ControllerEhci0) { return NULL; } - controllerId = controllerId - (uint8_t)kUSB_ControllerEhci0; + controllerId = controllerId - kUSB_ControllerEhci0; for (instance = 0; instance < (sizeof(usbnc_base_temp) / sizeof(usbnc_base_temp[0])); instance++) { - if (usbnc_base_temp[instance] != 0U) + if (usbnc_base_temp[instance]) { usbnc_base[newinstance++] = usbnc_base_temp[instance]; } @@ -593,7 +660,7 @@ static void *USB_EhciNCGetBase(uint8_t controllerId) return NULL; } - usbNCBase = (void *)(uint8_t *)usbnc_base[controllerId]; + usbNCBase = (void *)usbnc_base[controllerId]; #endif return usbNCBase; } @@ -662,19 +729,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); } @@ -707,8 +774,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); } @@ -728,7 +795,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) @@ -749,7 +816,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) @@ -781,24 +848,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(); @@ -821,11 +888,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); @@ -840,8 +907,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); @@ -850,8 +917,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); @@ -867,7 +934,7 @@ static void USB_HostEhciTestSingleStepGetDeviceDescData(usb_host_ehci_instance_t return; } -static void USB_HostEhciTestModeInit(usb_device_handle deviceHandle) +void USB_HostEhciTestModeInit(usb_device_handle deviceHandle) { uint32_t productId; usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle; @@ -908,7 +975,6 @@ static void USB_HostEhciTestModeInit(usb_device_handle deviceHandle) USB_HostEhciTestSingleStepGetDeviceDescData(ehciInstance, deviceHandle); break; default: - /*no action */ break; } @@ -948,62 +1014,60 @@ 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 = (3167U + ((1000U * dataLength) * 7U * 8U / 6U)) / 1000U; + uint32_t result = (3167 + ((1000 * dataLength) * 7U * 8U / 6U)) / 1000; if (pipeType == USB_ENDPOINT_ISOCHRONOUS) /* iso */ { if (speed == USB_SPEED_HIGH) { - result = 38U * 8U * 2083U + 2083U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 38 * 8 * 2083 + 2083 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } else if (speed == USB_SPEED_FULL) { if (direction == USB_IN) { - result = 7268000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 7268000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } else { - result = 6265000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 6265000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } } else { - /*no action*/ } } else /* interrupt */ { if (speed == USB_SPEED_HIGH) { - result = 55U * 8U * 2083U + 2083U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 55 * 8 * 2083 + 2083 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } else if (speed == USB_SPEED_FULL) { - result = 9107000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 9107000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } else if (speed == USB_SPEED_LOW) { if (direction == USB_IN) { - result = 64060000U + 2000U * USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP + 676670U * result + + result = 64060000 + 2000 * USB_HOST_EHCI_BANDWIDTH_HUB_LS_SETUP + 676670 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } else { - result = 6265000U + 83540U * result + USB_HOST_EHCI_BANDWIDTH_DELAY; + result = 6265000 + 83540 * result + USB_HOST_EHCI_BANDWIDTH_DELAY; } } else { - /*no action*/ } } - result /= 1000000U; - if (result == 0U) + result /= 1000000; + if (result == 0) { - result = 1U; + result = 1; } return result; @@ -1014,7 +1078,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; @@ -1027,28 +1091,26 @@ 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) && - (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) & - ((uint32_t)ehciPipePointer->pipeCommon.interval - 1U)))) + (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) & + (uint32_t)(ehciPipePointer->pipeCommon.interval - 1)))) { *frameBandwidth += ehciPipePointer->dataTime; } } - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } } static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t *ehciInstance, uint32_t hubNumber, uint16_t frameIndex, - uint16_t frameBandwidths[8]) + uint8_t frameBandwidths[8]) { usb_host_ehci_pipe_t *ehciPipePointer; uint8_t index; uint32_t deviceInfo; - void *temp; - for (index = 0; index < 8U; ++index) + for (index = 0; index < 8; ++index) { frameBandwidths[index] = 0; } @@ -1062,50 +1124,47 @@ 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 */ - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceHSHubNumber, &deviceInfo); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, + kUSB_HostGetDeviceHSHubNumber, &deviceInfo); if (deviceInfo != hubNumber) { - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; continue; } - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &deviceInfo); if (deviceInfo == USB_SPEED_HIGH) { - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; continue; } /* does pipe allocate bandwidth in frameIndex frame? note: interval is power of 2. */ if ((frameIndex >= ehciPipePointer->startFrame) && - (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) & - ((uint32_t)ehciPipePointer->pipeCommon.interval - 1U)))) + (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) & + (uint32_t)(ehciPipePointer->pipeCommon.interval - 1)))) { if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_ISOCHRONOUS) /* iso bandwidth is allocated once */ { - frameBandwidths[ehciPipePointer->startUframe + 1U] += ehciPipePointer->dataTime; + frameBandwidths[ehciPipePointer->startUframe + 1] += ehciPipePointer->dataTime; } else /* iso bandwidth is allocated three times */ { - frameBandwidths[ehciPipePointer->startUframe + 1U] += ehciPipePointer->dataTime; - frameBandwidths[ehciPipePointer->startUframe + 2U] += ehciPipePointer->dataTime; - frameBandwidths[ehciPipePointer->startUframe + 3U] += ehciPipePointer->dataTime; + frameBandwidths[ehciPipePointer->startUframe + 1] += ehciPipePointer->dataTime; + frameBandwidths[ehciPipePointer->startUframe + 2] += ehciPipePointer->dataTime; + frameBandwidths[ehciPipePointer->startUframe + 3] += ehciPipePointer->dataTime; } } } - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } - for (index = 0; index < 7U; ++index) /* */ + for (index = 0; index < 7; ++index) /* */ { if (frameBandwidths[index] > s_SlotMaxBandwidth[index]) { - frameBandwidths[index + 1U] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]); + frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]); frameBandwidths[index] = s_SlotMaxBandwidth[index]; } } @@ -1113,14 +1172,14 @@ static void USB_HostBandwidthHsHostComputeCurrentFsls(usb_host_ehci_instance_t * static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t *ehciInstance, uint16_t frameIndex, - uint16_t frameBandwidths[8]) + uint8_t frameBandwidths[8]) { usb_host_ehci_pipe_t *ehciPipePointer; - uint16_t index; + uint8_t index; uint32_t deviceInfo; uint16_t frameInterval; - void *temp; - for (index = 0; index < 8U; ++index) + + for (index = 0; index < 8; ++index) { frameBandwidths[index] = 0; } @@ -1133,26 +1192,26 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_INTERRUPT)) { frameInterval = ehciPipePointer->pipeCommon.interval; - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &deviceInfo); if (deviceInfo == USB_SPEED_HIGH) /* high-speed data bandwidth */ { /* frameInterval means micro-frame here */ if (frameIndex >= ehciPipePointer->startFrame) { - if ((frameInterval > 8U) && - (frameIndex * 8U - ehciPipePointer->startFrame * 8U >= ehciPipePointer->startUframe)) + if ((frameInterval > 8) && + (frameIndex * 8 - ehciPipePointer->startFrame * 8 >= ehciPipePointer->startUframe)) { - if (0U == ((((uint32_t)frameIndex) * 8U - ehciPipePointer->startFrame * 8U - - ehciPipePointer->startUframe) & - ((uint32_t)frameInterval - 1U))) + if (!((uint32_t)(frameIndex * 8 - ehciPipePointer->startFrame * 8 - + ehciPipePointer->startUframe) & + (uint32_t)(frameInterval - 1))) { frameBandwidths[ehciPipePointer->startUframe] += ehciPipePointer->dataTime; } } else { - for (index = ehciPipePointer->startUframe; index < 8U; index += frameInterval) + for (index = ehciPipePointer->startUframe; index < 8; index += frameInterval) { frameBandwidths[index] += ehciPipePointer->dataTime; } @@ -1162,18 +1221,17 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t else /* full-speed split bandwidth */ { if ((frameIndex >= ehciPipePointer->startFrame) && - (0U == ((uint32_t)((uint32_t)frameIndex - ehciPipePointer->startFrame) & - (uint32_t)((uint32_t)frameInterval - 1U)))) + (!((uint32_t)(frameIndex - ehciPipePointer->startFrame) & (uint32_t)(frameInterval - 1)))) { - for (index = 0; index < 8U; ++index) + for (index = 0; index < 8; ++index) { - if (0U != ((uint32_t)(ehciPipePointer->uframeSmask) & - (uint32_t)(0x01UL << index))) /* start-split micro-frames */ + if ((uint32_t)(ehciPipePointer->uframeSmask) & + (uint32_t)(0x01 << index)) /* start-split micro-frames */ { frameBandwidths[index] += ehciPipePointer->startSplitTime; } - if (0U != ((uint32_t)(ehciPipePointer->uframeCmask) & - (uint32_t)(0x01UL << index))) /* complete-split micro-frames */ + if ((uint32_t)(ehciPipePointer->uframeCmask) & + (uint32_t)(0x01 << index)) /* complete-split micro-frames */ { frameBandwidths[index] += ehciPipePointer->completeSplitTime; } @@ -1181,20 +1239,17 @@ static void USB_HostBandwidthHsHostComputeCurrentHsAll(usb_host_ehci_instance_t } } } - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } -#if 0 for (index = 0; index < 7; ++index) /* */ { - if (frameBandwidths[index] > s_SlotMaxBandwidthHs[index]) + if (frameBandwidths[index] > s_SlotMaxBandwidth[index]) { - frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidthHs[index]); - frameBandwidths[index] = s_SlotMaxBandwidthHs[index]; + frameBandwidths[index + 1] += (frameBandwidths[index] - s_SlotMaxBandwidth[index]); + frameBandwidths[index] = s_SlotMaxBandwidth[index]; } } -#endif } /*! @@ -1215,19 +1270,15 @@ static usb_status_t USB_HostBandwidthHsHostAllocateHsCommon(usb_host_ehci_instan uint16_t uframeIntervalIndex; uint16_t uframeIndex; uint16_t frameIndex; - uint16_t frameTimes[8]; + uint8_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 * 8U); + for (uframeIndex = uframeIntervalIndex; uframeIndex < (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8); uframeIndex += uframeInterval) { if (frameIndex != (uframeIndex >> 3)) @@ -1237,13 +1288,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 & 0x0007U] + timeData > - s_SlotMaxBandwidthHs[(uframeIndex & 0x0007U)]) /* micro-frame has enough idle bandwidth? */ + if (frameTimes[uframeIndex & 0x0007] + timeData > + s_SlotMaxBandwidth[(uframeIndex & 0x0007)]) /* micro-frame has enough idle bandwidth? */ { break; /* fail */ } } - if (uframeIndex >= (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8U)) /* success? */ + if (uframeIndex >= (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE * 8)) /* success? */ { break; } @@ -1267,97 +1318,91 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t usb_host_ehci_pipe_t *ehciPipePointer) { usb_status_t status; - uint32_t deviceInfo = 0; - uint32_t hubNumber = 0; + uint32_t deviceInfo; + uint32_t hubNumber; 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; - uint16_t frameTimes[8]; + uint8_t frameTimes[8]; uint8_t allocateOk = 1; - uint16_t index; + uint8_t index; - for (uint8_t i = 0; i < 8U; ++i) - { - frameTimes[i] = 0U; - } - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &deviceInfo); timeData = USB_HostBandwidthComputeTime( - (uint8_t)deviceInfo, USB_ENDPOINT_ISOCHRONOUS, ehciPipePointer->pipeCommon.direction, - (((uint32_t)ehciPipePointer->pipeCommon.maxPacketSize) * ehciPipePointer->pipeCommon.numberPerUframe)); + deviceInfo, USB_ENDPOINT_ISOCHRONOUS, ehciPipePointer->pipeCommon.direction, + ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe); /* pipe is high-speed */ if (deviceInfo == USB_SPEED_HIGH) { uframeIntervalIndex = 0; - status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, - (uint16_t)timeData, &uframeIntervalIndex); + status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, timeData, + &uframeIntervalIndex); if (status == kStatus_USB_Success) { - ehciPipePointer->startFrame = (uframeIntervalIndex / 8U); - ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U); - ehciPipePointer->dataTime = (uint16_t)timeData; + ehciPipePointer->startFrame = (uframeIntervalIndex / 8); + ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007); + ehciPipePointer->dataTime = timeData; return kStatus_USB_Success; } } else /* pipe is full-speed or low-speed */ { - (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); + 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); frameInterval = ehciPipePointer->pipeCommon.interval; /* compute start-split and complete-split bandwidth */ if (ehciPipePointer->pipeCommon.direction == USB_OUT) { - timeStartSplit = (uint16_t)USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_OUT, - ehciPipePointer->pipeCommon.maxPacketSize); + timeStartSplit = USB_HostBandwidthComputeTime(USB_SPEED_HIGH, USB_ENDPOINT_ISOCHRONOUS, USB_OUT, + ehciPipePointer->pipeCommon.maxPacketSize); timeCompleteSplit = 0; } else { - 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); + 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); } /* note: bandwidth must put in one frame */ - for (uframeIntervalIndex = 0U; uframeIntervalIndex <= 5U; ++uframeIntervalIndex) /* uframe interval */ + for (uframeIntervalIndex = 0; uframeIntervalIndex <= 5; ++uframeIntervalIndex) /* uframe interval */ { - for (frameIntervalIndex = 0U; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */ + for (frameIntervalIndex = 0; 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 = (uint8_t)((ehciPipePointer->pipeCommon.maxPacketSize + 187U) / - 188U); /* ss number for iso out; cs number for iso in */ + SsCsNumber = (ehciPipePointer->pipeCommon.maxPacketSize + 187) / + 188; /* ss number for iso out; cs number for iso in */ if (ehciPipePointer->pipeCommon.direction == USB_OUT) /* ISO OUT */ { - if (uframeIntervalIndex + SsCsNumber > 8U) + if (uframeIntervalIndex + SsCsNumber > 8) { - allocateOk = 0U; + allocateOk = 0; } } else { - if (uframeIntervalIndex + 2U + SsCsNumber > - 8U) /* ISO IN: there are two micro-frame interval between start-split and complete-split */ + if (uframeIntervalIndex + 2 + SsCsNumber > + 8) /* ISO IN: there are two micro-frame interval between start-split and complete-split */ { - allocateOk = 0U; + allocateOk = 0; } } - if (0U != allocateOk) + if (allocateOk) { /* allocate start-split and complete-split bandwidth */ USB_HostBandwidthHsHostComputeCurrentHsAll(ehciInstance, frameIndex, frameTimes); @@ -1366,9 +1411,9 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t index = uframeIntervalIndex; for (; index < (uframeIntervalIndex + SsCsNumber); ++index) { - if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidthHs[index]) + if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidth[index]) { - allocateOk = 0U; + allocateOk = 0; break; } } @@ -1376,20 +1421,20 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t else /* ISO IN */ { index = uframeIntervalIndex; - if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidthHs[index]) + if (frameTimes[index] + timeStartSplit > s_SlotMaxBandwidth[index]) { - allocateOk = 0U; + allocateOk = 0; } - if (0U != allocateOk) + if (allocateOk) { index = uframeIntervalIndex + - 2U; /* there are two micro-frames interval between start-split and complete-split */ - for (; index < (uframeIntervalIndex + 2U + SsCsNumber); ++index) + 2; /* there are two micro-frames interval between start-split and complete-split */ + for (; index < (uframeIntervalIndex + 2 + SsCsNumber); ++index) { - if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidthHs[index]) + if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidth[index]) { - allocateOk = 0U; + allocateOk = 0; break; } } @@ -1398,18 +1443,18 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t } /* allocate data bandwidth */ - if (0U != allocateOk) + if (allocateOk) { USB_HostBandwidthHsHostComputeCurrentFsls(ehciInstance, hubNumber, frameIndex, frameTimes); - index = uframeIntervalIndex + 1U; /* timeData bandwidth start position */ + index = uframeIntervalIndex + 1; /* timeData bandwidth start position */ /* iso must occupy all the uframe bandwidth */ { deviceInfo = timeData; /* note: deviceInfo variable means bandwidth here */ - while ((index < 8U) && (deviceInfo > s_SlotMaxBandwidth[index])) + while ((index < 8) && (deviceInfo > s_SlotMaxBandwidth[index])) { - if (frameTimes[index] > 0U) + if (frameTimes[index] > 0) { - allocateOk = 0U; + allocateOk = 0; break; } else @@ -1420,16 +1465,16 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t } } } - if (0U != allocateOk) + if (allocateOk) { /* data bandwidth can be put in the frame? */ - index = uframeIntervalIndex + 1U; /* timeData bandwidth start position */ - frameTimes[index] += (uint16_t)timeData; - for (; index < 7U; ++index) + index = uframeIntervalIndex + 1; /* timeData bandwidth start position */ + frameTimes[index] += timeData; + for (; index < 7; ++index) { if (frameTimes[index] > s_SlotMaxBandwidth[index]) { - frameTimes[index + 1U] += (frameTimes[index] - s_SlotMaxBandwidth[index]); + frameTimes[index + 1] += (frameTimes[index] - s_SlotMaxBandwidth[index]); frameTimes[index] = s_SlotMaxBandwidth[index]; } else @@ -1443,45 +1488,45 @@ static usb_status_t USB_HostBandwidthHsHostAllocateIso(usb_host_ehci_instance_t } } - if (0U != allocateOk) + if (allocateOk) { break; } } - if (0U != allocateOk) + if (allocateOk) { break; } } - if (0U != allocateOk) + if (allocateOk) { break; } } - if (0U != allocateOk) + if (allocateOk) { - ehciPipePointer->startFrame = frameIntervalIndex; - ehciPipePointer->startUframe = (uint8_t)uframeIntervalIndex; - ehciPipePointer->dataTime = (uint16_t)timeData; - ehciPipePointer->startSplitTime = timeStartSplit; + ehciPipePointer->startFrame = frameIntervalIndex; + ehciPipePointer->startUframe = uframeIntervalIndex; + ehciPipePointer->dataTime = timeData; + ehciPipePointer->startSplitTime = timeStartSplit; ehciPipePointer->completeSplitTime = timeCompleteSplit; if (ehciPipePointer->pipeCommon.direction == USB_OUT) { index = uframeIntervalIndex; for (; index < (uframeIntervalIndex + SsCsNumber); ++index) { - ehciPipePointer->uframeSmask = ehciPipePointer->uframeSmask | (uint8_t)(0x01UL << index); + ehciPipePointer->uframeSmask = (uint32_t)ehciPipePointer->uframeSmask | (uint32_t)(0x01 << index); } } else { - index = uframeIntervalIndex; - ehciPipePointer->uframeSmask = ehciPipePointer->uframeSmask | (uint8_t)(0x01UL << index); - index = uframeIntervalIndex + 2U; - for (; index < (uframeIntervalIndex + 2U + SsCsNumber); ++index) + index = uframeIntervalIndex; + ehciPipePointer->uframeSmask = (uint32_t)ehciPipePointer->uframeSmask | (uint32_t)(0x01 << index); + index = uframeIntervalIndex + 2; + for (; index < (uframeIntervalIndex + 2 + SsCsNumber); ++index) { - ehciPipePointer->uframeCmask = ehciPipePointer->uframeCmask | (uint8_t)(0x01UL << index); + ehciPipePointer->uframeCmask = (uint32_t)ehciPipePointer->uframeCmask | (uint32_t)(0x01 << index); } } @@ -1498,100 +1543,92 @@ static usb_status_t USB_HostBandwidthHsHostAllocateInterrupt(usb_host_ehci_insta usb_host_ehci_pipe_t *ehciPipePointer) { usb_status_t status; - uint32_t deviceInfo = 0; - uint32_t hubNumber = 0; + uint32_t deviceInfo; + uint32_t hubNumber; 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; - uint16_t frameTimes[8]; + uint8_t frameTimes[8]; uint8_t allocateOk = 1; uint8_t index; - for (uint8_t i = 0; i < 8U; ++i) - { - frameTimes[i] = 0U; - } - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &deviceInfo); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &deviceInfo); timeData = USB_HostBandwidthComputeTime( - (uint8_t)deviceInfo, USB_ENDPOINT_INTERRUPT, ehciPipePointer->pipeCommon.direction, - (uint32_t)ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe); + deviceInfo, USB_ENDPOINT_INTERRUPT, ehciPipePointer->pipeCommon.direction, + ehciPipePointer->pipeCommon.maxPacketSize * ehciPipePointer->pipeCommon.numberPerUframe); /* pipe is high-speed */ if (deviceInfo == USB_SPEED_HIGH) { uframeIntervalIndex = 0; - status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, - (uint16_t)timeData, &uframeIntervalIndex); + status = USB_HostBandwidthHsHostAllocateHsCommon(ehciInstance, ehciPipePointer->uframeInterval, timeData, + &uframeIntervalIndex); if (status == kStatus_USB_Success) { - ehciPipePointer->startFrame = (uframeIntervalIndex / 8U); - ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U); + ehciPipePointer->startFrame = (uframeIntervalIndex / 8); + ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007); /* for HS interrupt start transaction position */ - if (ehciPipePointer->uframeInterval >= 8U) + if (ehciPipePointer->uframeInterval >= 8) { - ehciPipePointer->uframeSmask = (0x01U << ehciPipePointer->startUframe); + ehciPipePointer->uframeSmask = (0x01 << ehciPipePointer->startUframe); } else { - ehciPipePointer->uframeSmask = 0x00U; - for (index = ehciPipePointer->startUframe; index < 8U; - index += (uint8_t)ehciPipePointer->uframeInterval) + ehciPipePointer->uframeSmask = 0x00u; + for (index = ehciPipePointer->startUframe; index < 8; index += ehciPipePointer->uframeInterval) { ehciPipePointer->uframeSmask |= (0x01U << index); } } - ehciPipePointer->dataTime = (uint16_t)timeData; + ehciPipePointer->dataTime = timeData; return kStatus_USB_Success; } } else /* pipe is full-speed or low-speed */ { - (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); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetHubThinkTime, + &deviceInfo); + timeData += (deviceInfo * 7 / (6 * 12)); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubNumber, + &hubNumber); frameInterval = ehciPipePointer->pipeCommon.interval; - SsCsNumber = 3U; /* complete split number */ + SsCsNumber = 3; /* complete split number */ /* compute start-split and complete-split bandwidth */ if (ehciPipePointer->pipeCommon.direction == USB_OUT) { - 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); + 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); } else { - 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); + 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); } /* note: bandwidth must put in one frame */ - for (uframeIntervalIndex = 0U; uframeIntervalIndex <= 4U; ++uframeIntervalIndex) /* uframe interval */ + for (uframeIntervalIndex = 0; uframeIntervalIndex <= 4; ++uframeIntervalIndex) /* uframe interval */ { - for (frameIntervalIndex = 0U; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */ + for (frameIntervalIndex = 0; frameIntervalIndex < frameInterval; ++frameIntervalIndex) /* frame interval */ { - allocateOk = 1U; + allocateOk = 1; 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 = (uint8_t)(uframeIntervalIndex + 1U); - for (; index <= (uframeIntervalIndex + 3U); ++index) /* data bandwidth number is 3. + index = uframeIntervalIndex + 1; + for (; index <= (uframeIntervalIndex + 3); ++index) /* data bandwidth number is 3. uframeIntervalIndex don't exceed 4, so index cannot exceed 7 */ { @@ -1602,61 +1639,60 @@ static usb_status_t USB_HostBandwidthHsHostAllocateInterrupt(usb_host_ehci_insta } } - if (0U != allocateOk) + if (allocateOk) { USB_HostBandwidthHsHostComputeCurrentHsAll(ehciInstance, frameIndex, frameTimes); /* allocate start_split bandwidth */ - if (frameTimes[uframeIntervalIndex] + timeStartSplit > - s_SlotMaxBandwidthHs[uframeIntervalIndex]) + if (frameTimes[uframeIntervalIndex] + timeStartSplit > s_SlotMaxBandwidth[uframeIntervalIndex]) { - allocateOk = 0U; + allocateOk = 0; } - if (0U != allocateOk) + if (allocateOk) { /* allocate complete_split bandwidth */ - index = (uint8_t)uframeIntervalIndex + 2U; + index = uframeIntervalIndex + 2; /* complete-split number is normal 3. When uframeIntervalIndex is 4, complete-split number * is 2. */ - for (; (index <= (uframeIntervalIndex + 1U + SsCsNumber)) && (index < 8U); ++index) + for (; (index <= (uframeIntervalIndex + 1 + SsCsNumber)) && (index < 8); ++index) { - if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidthHs[index]) + if (frameTimes[index] + timeCompleteSplit > s_SlotMaxBandwidth[index]) { - allocateOk = 0U; + allocateOk = 0; break; } } } } - if (0U == allocateOk) + if (!allocateOk) { break; /* allocate fail */ } } - if (0U != allocateOk) + if (allocateOk) { break; } } - if (0U != allocateOk) + if (allocateOk) { break; } } - if (0U != allocateOk) + if (allocateOk) { - 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->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->uframeCmask = ehciPipePointer->uframeCmask | (0x01U << index); + ehciPipePointer->uframeCmask = (uint32_t)ehciPipePointer->uframeCmask | (uint32_t)(0x01 << index); } - ehciPipePointer->dataTime = (uint16_t)timeData; - ehciPipePointer->startSplitTime = timeStartSplit; + ehciPipePointer->dataTime = timeData; + ehciPipePointer->startSplitTime = timeStartSplit; ehciPipePointer->completeSplitTime = timeCompleteSplit; return kStatus_USB_Success; @@ -1670,18 +1706,17 @@ 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; - (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, + 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, ehciPipePointer->pipeCommon.direction, ehciPipePointer->pipeCommon.maxPacketSize); @@ -1705,11 +1740,11 @@ static usb_status_t USB_HostBandwidthFslsHostAllocate(usb_host_ehci_instance_t * } if (uframeIntervalIndex < ehciPipePointer->uframeInterval) { - ehciPipePointer->startFrame = (uframeIntervalIndex >> 3); - ehciPipePointer->startUframe = (uint8_t)(uframeIntervalIndex & 0x0007U); + ehciPipePointer->startFrame = (uframeIntervalIndex >> 3); + ehciPipePointer->startUframe = (uframeIntervalIndex & 0x0007); ehciPipePointer->uframeSmask = 0; /* useless */ ehciPipePointer->uframeCmask = 0; - ehciPipePointer->dataTime = (uint16_t)FslsTime; + ehciPipePointer->dataTime = FslsTime; return kStatus_USB_Success; } @@ -1719,46 +1754,46 @@ static usb_status_t USB_HostBandwidthFslsHostAllocate(usb_host_ehci_instance_t * static uint8_t USB_HostEhciGet2PowerValue(uint8_t value) { - if ((value == 0U) || (value == 1U)) + if ((value == 0) || (value == 1)) { return value; } - if (0U != (value & 0xf0U)) + if (value & 0xf0) { - if (0U != (value & 0x80U)) + if (value & 0x80) { - return 128U; + return 128; } - else if (0U != (value & 0x40U)) + else if (value & 0x40) { - return 64U; + return 64; } - else if (0U != (value & 0x20U)) + else if (value & 0x20) { - return 32U; + return 32; } else { - return 16U; + return 16; } } else { - if (0U != (value & 0x08U)) + if (value & 0x08) { - return 8U; + return 8; } - else if (0U != (value & 0x04U)) + else if (value & 0x04) { - return 4U; + return 4; } - else if (0U != (value & 0x02U)) + else if (value & 0x02) { - return 2U; + return 2; } else { - return 1U; + return 1; } } } @@ -1766,9 +1801,8 @@ 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 (0U != length) + while (length--) { - length--; *buffer = 0; buffer++; } @@ -1777,24 +1811,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) */ - uint32_t sofStart; - uint32_t SofEnd; + int32_t sofStart; + int32_t SofEnd; uint32_t distance; - sofStart = (ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); + sofStart = (int32_t)(ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); do { - 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 */ + 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 */ } -void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance) +static void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance) { uint32_t stateSync; - if (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) + if (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) { /* the status must be same when change USBCMD->ASE */ do @@ -1805,7 +1839,7 @@ void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance) ehciInstance->ehciIpBase->ASYNCLISTADDR = (uint32_t)(ehciInstance->shedFirstQh); ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_ASE_MASK; - while (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) + while (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) { } } @@ -1823,16 +1857,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 (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) + while (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK) { } } -void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance) +static void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance) { uint32_t stateSync; - if (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)) + if (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)) { /* the status must be same when change USBCMD->PSE */ do @@ -1841,11 +1875,11 @@ 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 (0U == (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_PSE_MASK)) + if (!(ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_PSE_MASK)) { ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_PSE_MASK; /* start periodic schedule */ } - while (0U == (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)) + while (!(ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)) { } } @@ -1864,7 +1898,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 (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK)) + while (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_PS_MASK) { } } @@ -1874,7 +1908,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; @@ -1887,23 +1921,19 @@ 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 == 0U) + if (transfer->transferLength == 0) { - qtdNumber = 2U; + qtdNumber = 2; } else { - qtdNumber = 3U; + qtdNumber = 3; } } else { - qtdNumber = (((transfer->transferLength) & 0xFFFFC000U) >> 14U) + - (0U != ((transfer->transferLength) & 0x00003FFFU) ? 1U : 0U); - if (0U == qtdNumber) - { - qtdNumber = 1U; - } + qtdNumber = + (((transfer->transferLength) & 0xFFFFC000U) >> 14) + (((transfer->transferLength) & 0x00003FFF) ? 1 : 0); } vltQhPointer = (volatile usb_host_ehci_qh_t *)ehciPipePointer->ehciQh; @@ -1911,21 +1941,20 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst USB_HostEhciLock(); if (qtdNumber <= ehciInstance->ehciQtdNumber) { - ehciInstance->ehciQtdNumber -= (uint8_t)qtdNumber; + ehciInstance->ehciQtdNumber -= 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; - --qtdNumber; - } while (0U != qtdNumber); - if (ehciInstance->ehciQtdNumber == 0U) + } while (--qtdNumber); + if (ehciInstance->ehciQtdNumber == 0) { ehciInstance->ehciQtdTail = NULL; } @@ -1941,34 +1970,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[1] = 0U; + qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0; qtdPointer->transferResults[0] = - ((0x00000000UL << EHCI_HOST_QTD_DT_SHIFT) | (8UL << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) | + ((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 < 4U; ++index) + for (index = 0; index < 4; ++index) { - qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U); + qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 0xFFFFF000U); } /* data transaction qtd */ dataLength = transfer->transferLength; - if (dataLength != 0U) + if (dataLength != 0) { 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[1] = 0U; + qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0; if (transfer->direction == USB_OUT) { qtdPointer->transferResults[0] = - ((0x00000001UL << EHCI_HOST_QTD_DT_SHIFT) | (dataLength << EHCI_HOST_QTD_TOTAL_BYTES_SHIFT) | + ((0x00000001U << 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 @@ -1978,24 +2007,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 < 4U; ++index) + for (index = 0; index < 4; ++index) { - qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U); + qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 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[1] = 0; - if ((dataLength == 0U) || (transfer->direction == USB_OUT)) + qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0; + if ((dataLength == 0) || (transfer->direction == USB_OUT)) { qtdPointer->transferResults[0] = - ((0x00000001UL << EHCI_HOST_QTD_DT_SHIFT) | (EHCI_HOST_PID_IN << EHCI_HOST_QTD_PID_CODE_SHIFT) | + ((0x00000001U << 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 @@ -2008,11 +2037,12 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst } else { + dataLength = transfer->transferLength; dataAddress = (uint32_t)transfer->transferBuffer; - qtdPointer = BaseQtdPointer; - while (1U == 1U) + qtdPointer = BaseQtdPointer; + while (1) { - endAddress = dataAddress + (16U * 1024U); + endAddress = dataAddress + (16 * 1024); if (endAddress > (uint32_t)(transfer->transferBuffer + transfer->transferLength)) { endAddress = (uint32_t)(transfer->transferBuffer + transfer->transferLength); @@ -2020,7 +2050,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[1] = 0U; + qtdPointer->transferResults[0] = qtdPointer->transferResults[1] = 0; if (transfer->direction == USB_OUT) { qtdPointer->transferResults[0] = @@ -2039,13 +2069,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 < 4U; ++index) + for (index = 0; index < 4; ++index) { - qtdPointer->bufferPointers[index] = ((dataAddress + ((uint32_t)index + 1U) * 4U * 1024U) & 0xFFFFF000U); + qtdPointer->bufferPointers[index] = ((dataAddress + (index + 1) * 4 * 1024) & 0xFFFFF000U); } dataAddress = endAddress; /* for next qtd */ - if (qtdPointer->nextQtdPointer == 0U) + if (qtdPointer->nextQtdPointer == 0) { break; } @@ -2063,25 +2093,24 @@ static usb_status_t USB_HostEhciQhQtdListInit(usb_host_ehci_instance_t *ehciInst transfer->next = NULL; if (vltQhPointer->ehciTransferHead == NULL) { - transfer->next = NULL; - vltQhPointer->ehciTransferTail = transfer; - vltQhPointer->ehciTransferHead = transfer; + 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 */ - while ((0U != dataAddress) && (0U == (dataAddress & EHCI_HOST_T_INVALID_VALUE))) + 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)BaseQtdPointer; USB_HostEhciUnlock(); @@ -2097,7 +2126,7 @@ static uint32_t USB_HostEhciQtdListRelease(usb_host_ehci_instance_t *ehciInstanc uint32_t length = 0; usb_host_ehci_qtd_t *qtdPointer; - ehciQtdEnd->nextQtdPointer = 0U; + ehciQtdEnd->nextQtdPointer = 0; /* compute remaining length */ qtdPointer = ehciQtdStart; @@ -2112,7 +2141,7 @@ static uint32_t USB_HostEhciQtdListRelease(usb_host_ehci_instance_t *ehciInstanc /* put releasing qtd to idle qtd list */ USB_HostEhciLock(); - if (ehciInstance->ehciQtdNumber == 0U) + if (ehciInstance->ehciQtdNumber == 0) { ehciInstance->ehciQtdHead = ehciQtdStart; ehciInstance->ehciQtdTail = ehciQtdEnd; @@ -2120,7 +2149,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) @@ -2140,41 +2169,37 @@ 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; - uint32_t currentQtdPointer; - uint8_t needStop = 0U; + uint8_t needStop = 0; 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 */ - /*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))) + if ((!((uint32_t)vltQhPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE)) || + (!((uint32_t)vltQhPointer->currentQtdPointer & EHCI_HOST_T_INVALID_VALUE))) { /* need stop async schedule */ - if ((0U == (vltQhPointer->horizontalLinkPointer & EHCI_HOST_T_INVALID_VALUE)) && + if ((!(vltQhPointer->horizontalLinkPointer & EHCI_HOST_T_INVALID_VALUE)) && (ehciPipePointer->pipeCommon.pipeType != USB_ENDPOINT_INTERRUPT)) { - needStop = 1U; + needStop = 1; } - if (0U != needStop) + if (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 (0U != needStop) + if (needStop) { USB_HostEhciStartAsync(ehciInstance); } } /* remove transfer from the QH transfer list */ - transfer = vltQhPointer->ehciTransferHead; - vltQhPointer->ehciTransferTail = NULL; - vltQhPointer->ehciTransferHead = NULL; + transfer = vltQhPointer->ehciTransferHead; + vltQhPointer->ehciTransferHead = vltQhPointer->ehciTransferTail = NULL; USB_HostEhciUnlock(); /* release qtd and transfer callback*/ @@ -2185,9 +2210,8 @@ 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) ? - 0U : + 0 : (transfer->transferLength - transfer->transferSofar); - /* callback function is different from the current condition */ transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel); transfer = nextTransfer; } @@ -2209,14 +2233,13 @@ 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 ((0U != (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)) || - (0U == (qtdPointerEntry & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))) + if ((qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE) || (!(qtdPointerEntry & EHCI_HOST_QTD_STATUS_ACTIVE_MASK))) { qhNextQtdValue = (uint32_t)vltQhPointer->nextQtdPointer; } - if (0U == (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE)) /* there is pending qtd in the qh */ + if (!(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) @@ -2232,11 +2255,11 @@ static usb_status_t USB_HostEhciTransferQtdListDeinit(usb_host_ehci_instance_t * /* remove qtd from qh one by one */ qtdPointerEntry = transfer->union1.unitHead; - while (1U == 1U) + while (1) { /* search qh's qtd list for qtdPointerEntry */ searchQtdEntryPointer = &qhNextQtdValue; - while (0U == ((*searchQtdEntryPointer) & EHCI_HOST_T_INVALID_VALUE)) + while (!((*searchQtdEntryPointer) & EHCI_HOST_T_INVALID_VALUE)) { if ((*searchQtdEntryPointer) == qtdPointerEntry) { @@ -2283,15 +2306,13 @@ 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) ? - 0U : - (transfer->transferLength - transfer->transferSofar); - /* callback function is different from the current condition */ + transfer->transferSofar = + (transfer->transferLength < transfer->transferSofar) ? 0 : (transfer->transferLength - transfer->transferSofar); 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 != 0U) && (0U == (qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE))) + if ((qhNextQtdValue != 0) && (!(qhNextQtdValue & EHCI_HOST_T_INVALID_VALUE))) { vltQhPointer->nextQtdPointer = qhNextQtdValue; } @@ -2302,14 +2323,9 @@ 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 = 0; - uint32_t speed = 0; - uint32_t portNumber = 0; - uint32_t hubNumber = 0; - ; - uint32_t controlBits1 = 0U; - uint32_t controlBits2 = 0U; - + uint32_t address, speed, portNumber, hubNumber; + uint32_t controlBits1 = 0; + uint32_t controlBits2 = 0; /* get qh */ USB_HostEhciLock(); if (ehciInstance->ehciQhList != NULL) @@ -2329,27 +2345,26 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u ehciPipePointer->ehciQh = (void *)qhPointer; /* initialize qh */ - 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; + 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; qhPointer->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE; - 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); + qhPointer->ehciPipePointer = ehciPipePointer; + qhPointer->timeOutLabel = 0; + qhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, 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 |= ((0UL << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK); + controlBits1 |= ((0U << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK); } else { - if (ehciPipePointer->pipeCommon.nakCount >= 16U) + if (ehciPipePointer->pipeCommon.nakCount >= 16) { - controlBits1 |= ((15UL << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK); + controlBits1 |= ((15U << EHCI_HOST_QH_RL_SHIFT) & EHCI_HOST_QH_RL_MASK); } else { @@ -2361,15 +2376,15 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u { if (speed != USB_SPEED_HIGH) { - controlBits1 |= (1UL << EHCI_HOST_QH_C_SHIFT); + controlBits1 |= (1 << EHCI_HOST_QH_C_SHIFT); } - controlBits1 |= (1UL << EHCI_HOST_QH_DTC_SHIFT); + controlBits1 |= (1 << 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); - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceAddress, &address); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress, + &address); controlBits1 |= (address << EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT); qhPointer->staticEndpointStates[0] = controlBits1; if (speed == USB_SPEED_HIGH) @@ -2378,22 +2393,22 @@ static usb_status_t USB_HostEhciQhInit(usb_host_ehci_instance_t *ehciInstance, u } else { - controlBits2 |= (0x00000001UL << EHCI_HOST_QH_MULT_SHIFT); + controlBits2 |= (0x00000001U << EHCI_HOST_QH_MULT_SHIFT); } /*initialize staticEndpointStates[1] */ if (speed != USB_SPEED_HIGH) { - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceHSHubNumber, &hubNumber); - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceHSHubPort, &portNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubNumber, + &hubNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHSHubPort, + &portNumber); } else { - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceHubNumber, &hubNumber); - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDevicePortNumber, &portNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHubNumber, + &hubNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDevicePortNumber, + &portNumber); } controlBits2 |= (portNumber << EHCI_HOST_QH_PORT_NUMBER_SHIFT); controlBits2 |= (hubNumber << EHCI_HOST_QH_HUB_ADDR_SHIFT); @@ -2410,12 +2425,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 */ - (void)USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer); + 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; @@ -2428,19 +2443,17 @@ 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 */ - temp = (void *)ehciInstance->ehciFrameList; - frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)temp)[framePos]); - while (NULL != frameEntryPointer) + frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)ehciInstance->ehciFrameList)[framePos]); + while (frameEntryPointer) { frameEntryValue = *frameEntryPointer; - if (0U != (frameEntryValue & EHCI_HOST_T_INVALID_VALUE)) + if (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; } @@ -2454,7 +2467,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 @@ -2470,15 +2483,14 @@ 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 */ - temp = (void *)ehciInstance->ehciFrameList; - frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)temp)[framePos]); - while (NULL != frameEntryPointer) + /* search for the qh/itd/sitd entry */ + frameEntryPointer = (volatile uint32_t *)(&((uint32_t *)ehciInstance->ehciFrameList)[framePos]); + + while (frameEntryPointer) { frameEntryValue = *frameEntryPointer; - if (0U != (frameEntryValue & EHCI_HOST_T_INVALID_VALUE)) + if (frameEntryValue & EHCI_HOST_T_INVALID_VALUE) { return; } @@ -2505,71 +2517,53 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance, usb_host_ehci_sitd_t *sitdPointer; uint32_t distance; uint32_t frameInterval; - uint32_t shouldLinkFrame; - uint32_t currentFrame; - void *temp; + int32_t shouldLinkFrame; + int32_t currentFrame; - frameInterval = ((uint32_t)ehciPipePointer->uframeInterval >> 3U); + frameInterval = (ehciPipePointer->uframeInterval >> 3); - if (isoPointer->lastLinkFrame == 0xFFFFU) /* first link */ + if (isoPointer->lastLinkFrame == 0xFFFF) /* first link */ { - currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & USB_HOST_EHCI_MAX_MICRFRAME_VALUE) >> 3U); + currentFrame = ((ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE) >> 3); currentFrame = ((uint32_t)(currentFrame + USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER) & - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U)); /* add USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER */ + (EHCI_MAX_UFRAME_VALUE >> 3)); /* add USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER */ /* frame should align with interval */ - if (currentFrame <= ehciPipePointer->startFrame) - { - currentFrame = ehciPipePointer->startFrame; - } - else - { - currentFrame -= ehciPipePointer->startFrame; - currentFrame = ((currentFrame + frameInterval - 1U) & (~(frameInterval - 1U))); - currentFrame += ehciPipePointer->startFrame; - } + currentFrame -= ehciPipePointer->startFrame; + currentFrame = + ((uint32_t)(currentFrame + frameInterval - 1) & (~(frameInterval - 1))); /* frameInterval is power of 2 */ + currentFrame += ehciPipePointer->startFrame; } else { shouldLinkFrame = isoPointer->lastLinkFrame + frameInterval; /* continuous next should link frame */ - if (shouldLinkFrame > USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U) + if (shouldLinkFrame > (int32_t)(EHCI_MAX_UFRAME_VALUE >> 3)) { - shouldLinkFrame = shouldLinkFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3U) + 1U); + shouldLinkFrame = shouldLinkFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1); } - 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 */ + 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 */ /* 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 * USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER)) && - (distance > 0U)) + if ((distance <= (USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER + frameInterval * 2)) && (distance > 0)) { currentFrame = shouldLinkFrame; } else /* re-link */ { currentFrame = - ((currentFrame + USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER) & (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3)); - - /*if (currentFrame > (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3)) + ((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 = currentFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3) + 1U); - }*/ + currentFrame = currentFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1); + } /* frame should align with interval */ - if (currentFrame <= ehciPipePointer->startFrame) - { - currentFrame = ehciPipePointer->startFrame; - } - else - { - currentFrame -= ehciPipePointer->startFrame; - currentFrame = ((currentFrame + frameInterval - 1U) & (~(frameInterval - 1U))); - currentFrame += ehciPipePointer->startFrame; - } + currentFrame -= ehciPipePointer->startFrame; + currentFrame = ((uint32_t)(currentFrame + frameInterval - 1) & (~(frameInterval - 1))); + currentFrame += ehciPipePointer->startFrame; } } - if (currentFrame >= USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) /* frame turn around */ + if (currentFrame >= (int32_t)USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) /* frame turn around */ { shouldLinkFrame = (currentFrame - USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE); /* shouldLinkFrame means inserted frame position */ @@ -2580,14 +2574,14 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance, } sitdPointer = (usb_host_ehci_sitd_t *)startEntryPointer; - while (NULL != sitdPointer) + while (sitdPointer) { - sitdPointer->frameEntryIndex = (uint16_t)shouldLinkFrame; + sitdPointer->frameEntryIndex = shouldLinkFrame; /* add to frame list head */ - 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 */ + 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 */ { break; } @@ -2595,17 +2589,17 @@ static void USB_HostEhciLinkSitd(usb_host_ehci_instance_t *ehciInstance, shouldLinkFrame += frameInterval; currentFrame += frameInterval; - if (shouldLinkFrame >= USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) + if (shouldLinkFrame >= (int32_t)USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE) { shouldLinkFrame = (shouldLinkFrame - USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE); } } - if (currentFrame > (USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3)) + if (currentFrame > (int32_t)(EHCI_MAX_UFRAME_VALUE >> 3)) { - currentFrame = currentFrame - ((USB_HOST_EHCI_MAX_MICRFRAME_VALUE >> 3) + 1U); + currentFrame = currentFrame - ((EHCI_MAX_UFRAME_VALUE >> 3) + 1); } - isoPointer->lastLinkFrame = (uint16_t)currentFrame; /* save the last link frame value */ + isoPointer->lastLinkFrame = currentFrame; /* save the last link frame value */ } static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInstance, @@ -2618,35 +2612,33 @@ 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 = 0U; - uint32_t portNumber = 0U; - uint32_t address = 0U; + uint32_t hubNumber; + uint32_t portNumber; + uint32_t address; uint32_t tmp; - uint32_t *temp; - uint32_t index; - int32_t tempIndex; - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceAddress, &address); + uint8_t index; - sitdNumber = ((transfer->transferLength - 1U + (ehciPipePointer->pipeCommon.maxPacketSize)) / + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress, + &address); + + sitdNumber = ((transfer->transferLength - 1 + (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 = 1U; index < sitdNumber; ++index) + for (index = 1; index < sitdNumber; ++index) { - /*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 = + (((usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer) - ehciInstance->ehciSitdIndexBase); + sitdPointer = (usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer; } sitdPointer->nextSitdIndex = 0xFF; - ehciInstance->ehciSitdList = (usb_host_ehci_sitd_t *)(sitdPointer->nextLinkPointer & 0xFFFFFFFEU); - ehciInstance->ehciSitdNumber -= (uint8_t)sitdNumber; + ehciInstance->ehciSitdList = (usb_host_ehci_sitd_t *)sitdPointer->nextLinkPointer; + ehciInstance->ehciSitdNumber -= sitdNumber; } else { @@ -2656,16 +2648,15 @@ static usb_status_t USB_HostEhciSitdArrayInit(usb_host_ehci_instance_t *ehciInst /* USB_HostEhciUnlock(); */ transfer->union2.unitTail = (uint32_t)sitdPointer; /* initialize sitd array */ - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceHubNumber, &hubNumber); - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDevicePortNumber, &portNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceHubNumber, + &hubNumber); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDevicePortNumber, + &portNumber); sitdPointer = (usb_host_ehci_sitd_t *)transfer->union1.unitHead; - dataLength = transfer->transferLength; - while (0U != sitdNumber) + dataLength = transfer->transferLength; + while (sitdNumber--) { - sitdNumber--; - USB_HostEhciZeroMem((void *)sitdPointer, 7); + USB_HostEhciZeroMem((uint32_t *)sitdPointer, 7); sitdLength = dataLength; if (sitdLength > ehciPipePointer->pipeCommon.maxPacketSize) { @@ -2674,7 +2665,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 + 4U * 1024U) & 0xFFFFF000U); + sitdPointer->transferResults[2] = ((dataBufferValue + 4 * 1024) & 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) | @@ -2688,14 +2679,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 + 187U) / 188U; - if (tmp > 1U) + tmp = (sitdLength + 187) / 188; + if (tmp > 1) { - sitdPointer->transferResults[2] |= (0x01U << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */ + sitdPointer->transferResults[2] |= (0x01 << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */ } else { - sitdPointer->transferResults[2] |= (0x00U << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */ + sitdPointer->transferResults[2] |= (0x00 << EHCI_HOST_SITD_TP_SHIFT); /* for iso split */ } sitdPointer->transferResults[2] |= (tmp << EHCI_HOST_SITD_TCOUNT_SHIFT); /* for iso split */ } @@ -2705,29 +2696,26 @@ 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] |= (1UL << EHCI_HOST_SITD_IOC_SHIFT); /* last set IOC */ + sitdPointer->transferResults[0] |= (1U << 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->ehciTransferTail = transfer; - isoPointer->ehciTransferHead = transfer; + transfer->next = NULL; + isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = 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)*/ - /*misra 11.6*/ - temp = (uint32_t *)(transfer->union1.unitHead); - USB_HostEhciLinkSitd(ehciInstance, ehciPipePointer, (void *)temp); + USB_HostEhciLinkSitd(ehciInstance, ehciPipePointer, (void *)transfer->union1.unitHead); return kStatus_USB_Success; } @@ -2737,9 +2725,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 (1U == 1U) + while (1) { /* record the transfer's result length */ leftLength += @@ -2749,9 +2737,8 @@ static uint32_t USB_HostEhciSitdArrayRelease(usb_host_ehci_instance_t *ehciInsta /* release itd */ /* USB_HostEhciLock(); */ - /*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; + sitdPointer->nextLinkPointer = (uint32_t)ehciInstance->ehciSitdList; + ehciInstance->ehciSitdList = sitdPointer; ehciInstance->ehciSitdNumber++; /* USB_HostEhciUnlock(); */ @@ -2775,9 +2762,8 @@ 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->ehciTransferTail = NULL; - isoPointer->ehciTransferHead = NULL; + transfer = isoPointer->ehciTransferHead; + isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = NULL; USB_HostEhciUnlock(); while (transfer != NULL) @@ -2788,7 +2774,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); - /* callback function is different from the current condition */ + /* transfer callback */ transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferCancel); /* next transfer */ transfer = nextTransfer; @@ -2804,66 +2790,50 @@ static uint32_t USB_HostEhciGetItdLinkFrame(usb_host_ehci_instance_t *ehciInstan uint16_t startUframe, uint16_t uframeInterval) { - uint32_t shouldLinkUframe; - uint32_t currentUframe; - uint32_t distance; + int32_t shouldLinkUframe; + int32_t currentUframe; + int32_t distance; - if (lastLinkUframe != 0xFFFFU) + if (lastLinkUframe != 0xFFFF) { shouldLinkUframe = lastLinkUframe + uframeInterval; - if (shouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE) + if (shouldLinkUframe > (int32_t)EHCI_MAX_UFRAME_VALUE) { - shouldLinkUframe = shouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U); + shouldLinkUframe = shouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1); } - 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 */ + currentUframe = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); + distance = ((shouldLinkUframe - currentUframe + EHCI_MAX_UFRAME_VALUE + 1) & + EHCI_MAX_UFRAME_VALUE); /* get the distance */ /* shouldLinkUframe has add uframeInterval, think about the align with interval, so here add (uframeInterval * * 2) */ - if ((distance <= ((uint32_t)USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER + - ((uint32_t)uframeInterval * USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER))) && - (distance > 2U)) + if ((distance <= (int32_t)(USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER + (uframeInterval * 2))) && (distance > 2)) { currentUframe = shouldLinkUframe; } else /* re-link */ { currentUframe = - ((currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & USB_HOST_EHCI_MAX_MICRFRAME_VALUE); - /*if (currentUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE) + ((uint32_t)(currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & EHCI_MAX_UFRAME_VALUE); + if (currentUframe > (int32_t)EHCI_MAX_UFRAME_VALUE) { - currentUframe = currentUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U); - }*/ + currentUframe = currentUframe - (EHCI_MAX_UFRAME_VALUE + 1); + } /* uframe should align with interval */ - if (currentUframe <= startUframe) - { - currentUframe = startUframe; - } - else - { - currentUframe -= startUframe; - currentUframe = ((uint32_t)(currentUframe + uframeInterval) & - (~((uint32_t)uframeInterval - 1U))); /* uframeInterval is power of 2 */ - currentUframe += startUframe; - } + currentUframe -= startUframe; + currentUframe = ((uint32_t)(currentUframe + uframeInterval - 1) & + (~((uint32_t)uframeInterval - 1))); /* uframeInterval is power of 2 */ + currentUframe += startUframe; } } else { - 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); + currentUframe = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); + currentUframe = ((uint32_t)(currentUframe + USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER) & EHCI_MAX_UFRAME_VALUE); /* uframe should align with interval */ - if (currentUframe <= startUframe) - { - currentUframe = startUframe; - } - else - { - currentUframe -= startUframe; - currentUframe = - ((currentUframe + uframeInterval) & (~(uframeInterval - 1U))); /* uframeInterval is power of 2 */ - currentUframe += startUframe; - } + currentUframe -= startUframe; + currentUframe = ((uint32_t)(currentUframe + uframeInterval - 1) & + (~((uint32_t)uframeInterval - 1))); /* uframeInterval is power of 2 */ + currentUframe += startUframe; } return currentUframe; @@ -2875,29 +2845,27 @@ 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 = 0U; + uint32_t address; uint32_t lastShouldLinkUframe; uint32_t linkUframe; - uint32_t minDataPerItd = - (uint32_t)ehciPipePointer->pipeCommon.numberPerUframe * ehciPipePointer->pipeCommon.maxPacketSize; + uint32_t minDataPerItd = ehciPipePointer->pipeCommon.numberPerUframe * ehciPipePointer->pipeCommon.maxPacketSize; uint8_t maxItdNumber; - uint16_t index = 0; + uint8_t index = 0; isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh; - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceAddress, &address); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceAddress, + &address); /* max needed itd number, the actual needed number may be less because micro-frame interval may be less than 8 */ - maxItdNumber = (uint8_t)((transfer->transferLength - 1U + minDataPerItd) / minDataPerItd); - if (ehciPipePointer->uframeInterval < 8U) + maxItdNumber = ((transfer->transferLength - 1 + minDataPerItd) / minDataPerItd); + if (ehciPipePointer->uframeInterval < 8) { - maxItdNumber = (uint8_t)((maxItdNumber * ehciPipePointer->uframeInterval + 7U) / 8U) + 1U; + maxItdNumber = ((maxItdNumber * ehciPipePointer->uframeInterval + 7) / 8) + 1; } if (maxItdNumber > ehciInstance->ehciItdNumber) { @@ -2909,46 +2877,43 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta /* USB_HostEhciLock(); */ if (isoPointer->ehciTransferHead == NULL) { - isoPointer->ehciTransferTail = transfer; - isoPointer->ehciTransferHead = transfer; + isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = transfer; } else { isoPointer->ehciTransferTail->next = transfer; - isoPointer->ehciTransferTail = transfer; + isoPointer->ehciTransferTail = transfer; } /* USB_HostEhciUnlock(); */ - dataLength = transfer->transferLength; - transfer->union1.unitHead = 0U; + dataLength = transfer->transferLength; + transfer->union1.unitHead = (uint32_t)NULL; /* get the link micro-frame */ lastShouldLinkUframe = USB_HostEhciGetItdLinkFrame( ehciInstance, isoPointer->lastLinkFrame, (uint16_t)((ehciPipePointer->startFrame << 3) + ehciPipePointer->startUframe), ehciPipePointer->uframeInterval); - if (lastShouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE) + if (lastShouldLinkUframe > EHCI_MAX_UFRAME_VALUE) { - linkUframe = lastShouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U); + linkUframe = lastShouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1); } else { linkUframe = lastShouldLinkUframe; } - itdHead = ehciInstance->ehciItdList; - while (0U != dataLength) + while (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 == 0U) /* first itd */ + if (transfer->union1.unitHead == (uint32_t)NULL) /* first itd */ { transfer->union1.unitHead = (uint32_t)tmpItdPointer; } @@ -2959,11 +2924,11 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta itdPointer = tmpItdPointer; /* itd has been set to all zero when releasing */ - itdBufferValue = (uint32_t)(transfer->transferBuffer + (transfer->transferLength - dataLength)); - itdBufferBaseValue = itdBufferValue; - for (index = 0; index < 7U; ++index) + itdBufferBaseValue = itdBufferValue = + (uint32_t)(transfer->transferBuffer + (transfer->transferLength - dataLength)); + for (index = 0; index < 7; ++index) { - itdPointer->bufferPointers[index] = ((itdBufferBaseValue + ((uint32_t)index * 4U * 1024U)) & 0xFFFFF000U); + itdPointer->bufferPointers[index] = ((itdBufferBaseValue + (index * 4 * 1024)) & 0xFFFFF000U); } /* initialize iTD common fields */ itdPointer->bufferPointers[0] |= @@ -2974,7 +2939,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 = (uint8_t)(linkUframe & 0x0007U); index < 8U; index += ehciPipePointer->uframeInterval) + for (index = (linkUframe & 0x0007); index < 8; index += ehciPipePointer->uframeInterval) { transactionLength = ((dataLength > minDataPerItd) ? minDataPerItd : dataLength); /* initialize the uframeIndex's transaction descriptor in itd */ @@ -2986,7 +2951,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 <= 0U) + if (dataLength <= 0) { break; } @@ -2994,25 +2959,17 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta } transfer->union2.unitTail = (uint32_t)itdPointer; - itdPointer->transactions[index] |= (1UL << EHCI_HOST_ITD_IOC_SHIFT); /* last set IOC */ + itdPointer->transactions[index] |= (1 << EHCI_HOST_ITD_IOC_SHIFT); /* last set IOC */ - itdPointer = itdHead; /* link itd to frame list (note: initialize frameEntryIndex)*/ - while (NULL != itdPointer) + while (itdPointer) { - 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; + 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; if (itdPointer == NULL) { break; @@ -3026,11 +2983,11 @@ static usb_status_t USB_HostEhciItdArrayInit(usb_host_ehci_instance_t *ehciInsta } } - if (lastShouldLinkUframe > USB_HOST_EHCI_MAX_MICRFRAME_VALUE) + if (lastShouldLinkUframe > EHCI_MAX_UFRAME_VALUE) { - lastShouldLinkUframe = lastShouldLinkUframe - (USB_HOST_EHCI_MAX_MICRFRAME_VALUE + 1U); + lastShouldLinkUframe = lastShouldLinkUframe - (EHCI_MAX_UFRAME_VALUE + 1); } - isoPointer->lastLinkFrame = (uint16_t)lastShouldLinkUframe; + isoPointer->lastLinkFrame = lastShouldLinkUframe; return kStatus_USB_Success; } @@ -3044,24 +3001,23 @@ static uint32_t USB_HostEhciItdArrayRelease(usb_host_ehci_instance_t *ehciInstan uint32_t doneLength = 0; /* remove itd from frame list */ - while (1U == 1U) + while (1) { /* record the transfer's result length */ - for (index = 0U; index < 8U; ++index) + for (index = 0; index < 8; ++index) { doneLength += ((itdPointer->transactions[index] & EHCI_HOST_ITD_TRANSACTION_LEN_MASK) >> EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT); } USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)itdPointer, - (uint16_t)itdPointer->frameEntryIndex); /* remove from the inserted frame list */ + itdPointer->frameEntryIndex); /* remove from the inserted frame list */ /* release itd */ /* USB_HostEhciLock(); */ - /*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; + USB_HostEhciZeroMem((uint32_t *)itdPointer, sizeof(usb_host_ehci_itd_t) >> 2); + itdPointer->nextLinkPointer = (uint32_t)ehciInstance->ehciItdList; + ehciInstance->ehciItdList = itdPointer; ehciInstance->ehciItdNumber++; /* USB_HostEhciUnlock(); */ @@ -3085,15 +3041,14 @@ 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->ehciTransferTail = NULL; - isoPointer->ehciTransferHead = NULL; + transfer = isoPointer->ehciTransferHead; + isoPointer->ehciTransferHead = isoPointer->ehciTransferTail = 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); @@ -3104,7 +3059,6 @@ 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 */ @@ -3128,7 +3082,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; @@ -3139,11 +3093,10 @@ 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)temp) /* the removing qh is the first qh in the async list */ + (uint32_t)ehciPipePointer->ehciQh) /* the removing qh is the first qh in the async list */ { USB_HostEhciStopAsync(ehciInstance); ehciInstance->shedFirstQh->horizontalLinkPointer = @@ -3157,8 +3110,8 @@ static usb_status_t USB_HostEhciCloseControlBulk(usb_host_ehci_instance_t *ehciI while (vltPrevQhPointer != NULL) { horizontalLinkValue = vltPrevQhPointer->horizontalLinkPointer; - if ((0U != (horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE)) || - ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)temp) || + if ((horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE) || + ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciPipePointer->ehciQh) || ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciInstance->shedFirstQh)) { break; @@ -3168,10 +3121,8 @@ static usb_status_t USB_HostEhciCloseControlBulk(usb_host_ehci_instance_t *ehciI } /* remove the qh from async list */ - /*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)) + if ((vltPrevQhPointer != NULL) && (!(horizontalLinkValue & EHCI_HOST_T_INVALID_VALUE)) && + ((horizontalLinkValue & EHCI_HOST_POINTER_ADDRESS_MASK) == (uint32_t)ehciPipePointer->ehciQh)) { USB_HostEhciStopAsync(ehciInstance); vltPrevQhPointer->horizontalLinkPointer = @@ -3189,7 +3140,6 @@ 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) @@ -3213,10 +3163,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 += (((uint32_t)ehciPipePointer->uframeInterval + 7U) / 8U)) + frameIndex += (ehciPipePointer->uframeInterval / 8)) { - temp = (uint32_t *)ehciPipePointer->ehciQh; - USB_HostEhciAddQhToFrame(ehciInstance, (uint32_t)temp, (uint16_t)frameIndex, ehciPipePointer->uframeInterval); + USB_HostEhciAddQhToFrame(ehciInstance, (uint32_t)ehciPipePointer->ehciQh, frameIndex, + ehciPipePointer->uframeInterval); } return kStatus_USB_Success; @@ -3226,13 +3176,12 @@ 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 += (((uint32_t)ehciPipePointer->uframeInterval + 7U) / 8U)) + frameIndex += (ehciPipePointer->uframeInterval / 8)) { - temp = (uint32_t *)ehciPipePointer->ehciQh; - USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)temp, (uint16_t)frameIndex); + USB_HostEhciRemoveFromFrame(ehciInstance, (uint32_t)ehciPipePointer->ehciQh, frameIndex); } ((usb_host_ehci_qh_t *)ehciPipePointer->ehciQh)->horizontalLinkPointer |= EHCI_HOST_T_INVALID_VALUE; /* invalid next qh link */ @@ -3270,11 +3219,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; } @@ -3282,32 +3231,31 @@ 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 = 0U; + uint32_t speed; isoPointer = (usb_host_ehci_iso_t *)ehciPipePointer->ehciQh; if (isoPointer->ehciTransferHead != NULL) { - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &speed); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &speed); if (speed == USB_SPEED_HIGH) { #if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) - (void)USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd list and free them */ + 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)) - (void)USB_HostEhciSitdArrayDeinit(ehciInstance, - ehciPipePointer); /* de-initialize sitd list and free them */ + 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; @@ -3319,17 +3267,17 @@ static usb_status_t USB_HostEhciResetIP(usb_host_ehci_instance_t *ehciInstance) { /* reset controller */ ehciInstance->ehciIpBase->USBCMD = USBHS_USBCMD_RST_MASK; - while (0U != (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_RST_MASK)) + while (ehciInstance->ehciIpBase->USBCMD & USBHS_USBCMD_RST_MASK) { } /* set host mode */ #if (ENDIANNESS == USB_LITTLE_ENDIAN) - ehciInstance->ehciIpBase->USBMODE |= 0x03U; + ehciInstance->ehciIpBase->USBMODE |= 0x03; #else - ehciInstance->ehciIpBase->USBMODE |= (0x03U | (0x01U << USBHS_USBMODE_ES_SHIFT)); + ehciInstance->ehciIpBase->USBMODE |= (0x03 | (0x01 << USBHS_USBMODE_ES_SHIFT)); #endif /* check frame list size */ - if (0U == (ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK)) + if (!(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; @@ -3345,7 +3293,7 @@ static usb_status_t USB_HostEhciStartIP(usb_host_ehci_instance_t *ehciInstance) { uint32_t tmp = 0; - if (0U != (ehciInstance->ehciIpBase->HCSPARAMS & USBHS_HCSPARAMS_PPC_MASK)) /* Ports have power port switches */ + if (ehciInstance->ehciIpBase->HCSPARAMS & USBHS_HCSPARAMS_PPC_MASK) /* Ports have power port switches */ { /* only has one port */ tmp = ehciInstance->ehciIpBase->PORTSC1; @@ -3354,41 +3302,41 @@ static usb_status_t USB_HostEhciStartIP(usb_host_ehci_instance_t *ehciInstance) } /* set frame list size */ - if (0U != (ehciInstance->ehciIpBase->HCCPARAMS & USBHS_HCCPARAMS_PFL_MASK)) + if (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 |= (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); + 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); #endif #else #if (USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE == 1024) - 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); + 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); #endif #endif } /* start the controller */ - ehciInstance->ehciIpBase->USBCMD |= USBHS_USBCMD_RS_MASK; + ehciInstance->ehciIpBase->USBCMD = USBHS_USBCMD_RS_MASK; /* set timer0 */ - ehciInstance->ehciIpBase->GPTIMER0LD = (100U * 1000U - 1U); /* 100ms */ + ehciInstance->ehciIpBase->GPTIMER0LD = (300 * 1000 - 1); /* 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 |= (0x1000037U); + ehciInstance->ehciIpBase->USBINTR |= (0x1000037); return kStatus_USB_Success; } @@ -3401,7 +3349,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 = 0U; + uint32_t speed; #endif uint8_t cancelPipe = 0; @@ -3420,24 +3368,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 = 1U; + cancelPipe = 1; } else { - cancelPipe = 0U; + cancelPipe = 0; } } else { - cancelPipe = 1U; + cancelPipe = 1; } - if (cancelPipe == 1U) /* cancel all pipe */ + if (cancelPipe == 1) /* cancel all pipe */ { - (void)USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer); /* release all the qtd */ + USB_HostEhciQhQtdListDeinit(ehciInstance, ehciPipePointer); /* release all the qtd */ } else /* cancel one transfer */ { - (void)USB_HostEhciTransferQtdListDeinit(ehciInstance, ehciPipePointer, transfer); + USB_HostEhciTransferQtdListDeinit(ehciInstance, ehciPipePointer, transfer); } break; @@ -3450,55 +3398,54 @@ 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 */ - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &speed); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &speed); if (speed == USB_SPEED_HIGH) { #if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) - (void)USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd */ + USB_HostEhciItdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize itd */ #endif } else { #if ((defined USB_HOST_CONFIG_EHCI_MAX_SITD) && (USB_HOST_CONFIG_EHCI_MAX_SITD)) - (void)USB_HostEhciSitdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize sitd */ + USB_HostEhciSitdArrayDeinit(ehciInstance, ehciPipePointer); /* de-initialize sitd */ #endif } break; #endif default: - /*no action*/ break; } return kStatus_USB_Success; } -usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl) +static usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl) { usb_status_t status = kStatus_USB_Success; uint32_t portScRegister; - usb_host_bus_control_t controlCode = (usb_host_bus_control_t)busControl; - switch (controlCode) + + switch (busControl) { case kUSB_HostBusReset: /* reset port */ portScRegister = ehciInstance->ehciIpBase->PORTSC1; portScRegister &= (~EHCI_PORTSC1_W1_BITS); ehciInstance->ehciIpBase->PORTSC1 = (portScRegister | USBHS_PORTSC1_PR_MASK); - while (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK)) + while (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK) { } break; case kUSB_HostBusRestart: - ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached; + ehciInstance->deviceAttached = kEHCIDeviceDetached; ehciInstance->ehciIpBase->USBINTR |= (USBHS_USBINTR_PCE_MASK); /* enable ehci port change interrupt */ break; case kUSB_HostBusEnableAttach: /* enable device attach */ - if (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceDetached) + if (ehciInstance->deviceAttached == kEHCIDeviceDetached) { ehciInstance->ehciIpBase->USBINTR |= (USBHS_USBINTR_PCE_MASK); /* enable ehci port change interrupt */ } @@ -3509,7 +3456,7 @@ usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint break; #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) case kUSB_HostBusSuspend: - if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + if (ehciInstance->ehciIpBase->PORTSC1 && USBHS_PORTSC1_CCS_MASK) { /* set timer1 */ ehciInstance->ehciIpBase->GPTIMER1LD = (1 * 1000); /* 1ms */ @@ -3518,9 +3465,9 @@ usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint USB_HostEhciStopAsync(ehciInstance); USB_HostEhciStopPeriodic(ehciInstance); - while (0U != (ehciInstance->ehciIpBase->USBSTS & (USBHS_USBSTS_PS_MASK | USBHS_USBSTS_AS_MASK))) + while (ehciInstance->ehciIpBase->USBSTS & (USBHS_USBSTS_PS_MASK | USBHS_USBSTS_AS_MASK)) { - __NOP(); + __ASM("nop"); } ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_WKCN_MASK; ehciInstance->ehciIpBase->PORTSC1 |= USBHS_PORTSC1_WKDS_MASK; @@ -3538,7 +3485,7 @@ usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint case kUSB_HostBusResume: ehciInstance->ehciIpBase->PORTSC1 &= ~(USBHS_PORTSC1_SUSP_MASK); /* Clear Suspend bit */ ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_PHCD_MASK; - if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceDetached) + if (ehciInstance->deviceAttached != kEHCIDeviceDetached) { ehciInstance->busSuspendStatus = kBus_EhciStartResume; #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U)) @@ -3585,9 +3532,6 @@ 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) @@ -3598,45 +3542,43 @@ 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; - 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 */ + 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 */ { - qtdStatus = (transferResults & EHCI_HOST_QTD_STATUS_ERROR_MASK); + qtdStatus = (vltQtdPointer->transferResults[0] & 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) ? - 0U : + 0 : (transfer->transferLength - transfer->transferSofar); vltQhPointer->ehciTransferHead = transfer->next; - vltQhPointer->timeOutLabel = 0U; - vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; - if (0U != qtdStatus) /* has errors */ + vltQhPointer->timeOutLabel = 0; + vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; + if (qtdStatus) /* has errors */ { - if (0U == (transferOverlayResults & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) + if (!(vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) { vltQhPointer->transferOverlayResults[0] &= (~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */ } - if (0U != (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK)) + if (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->callbackFn(transfer->callbackParam, transfer, + kStatus_USB_TransferStall); /* transfer stall */ } } else @@ -3660,8 +3602,8 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance) { break; } - temp = (void *)ehciClearPipePointer->pipeCommon.next; - ehciClearPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciClearPipePointer = + (usb_host_ehci_pipe_t *)ehciClearPipePointer->pipeCommon.next; } if ((ehciClearPipePointer != NULL) && @@ -3672,19 +3614,18 @@ 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 ((0U == (transferOverlayResults & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) && - (0U != (transferOverlayResults & - EHCI_HOST_QH_STATUS_ERROR_MASK))) /* there is error and transfer is done */ + 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 */ { - 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 ((0U != ((uint32_t)vltQtdPointer & EHCI_HOST_T_INVALID_VALUE)) || + if (((uint32_t)vltQtdPointer & EHCI_HOST_T_INVALID_VALUE) || (vltQtdPointer == NULL)) /* the error status is unreasonable */ { vltQhPointer->transferOverlayResults[0] &= @@ -3693,13 +3634,13 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance) else { /* remove qtd from qh */ - while ((vltQtdPointer != NULL) && - (0U == (transferResults & EHCI_HOST_QTD_IOC_MASK))) /* find the IOC qtd */ + while ((vltQtdPointer != NULL) && (!(vltQtdPointer->transferResults[0] & + 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 */ @@ -3712,20 +3653,18 @@ 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) ? - 0U : + 0 : (transfer->transferLength - transfer->transferSofar); vltQhPointer->ehciTransferHead = transfer->next; - vltQhPointer->timeOutLabel = 0U; - vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; - if (0U != (qtdStatus & EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK)) + vltQhPointer->timeOutLabel = 0; + vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; + if (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 */ } @@ -3741,42 +3680,41 @@ 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; - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &speed); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, + 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 < 8U; ++index) + for (index = 0; index < 8; ++index) { - if (0U != (vltItdPointer->transactions[index] & EHCI_HOST_ITD_STATUS_ACTIVE_MASK)) + if (vltItdPointer->transactions[index] & EHCI_HOST_ITD_STATUS_ACTIVE_MASK) { break; } } - if (index == 8U) /* transfer is done */ + if (index == 8) /* 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 = 1U; /* break */ + qtdStatus = 1; /* break */ } #endif } @@ -3785,27 +3723,26 @@ 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 (0U == (vltSitdPointer->transferResults[0] & - EHCI_HOST_SITD_STATUS_ACTIVE_MASK)) /* transfer is done */ + if (!(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 = transfer->transferLength - 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 = 1U; /* break */ + qtdStatus = 1; /* break */ } #endif } - if (qtdStatus == 1U) + if (qtdStatus == 1) { break; } @@ -3815,40 +3752,38 @@ void USB_HostEhciTransactionDone(usb_host_ehci_instance_t *ehciInstance) #endif default: - /*no action*/ break; } - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } } -void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance) +static void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance) { /* note: only has one port */ uint32_t portScRegister = ehciInstance->ehciIpBase->PORTSC1; - uint32_t sofStart = 0; - uint32_t sofCount = 0; + int32_t sofStart = 0; + int32_t sofCount = 0; uint32_t index; - if (0U != (portScRegister & USBHS_PORTSC1_CSC_MASK)) /* connection status change */ + if (portScRegister & USBHS_PORTSC1_CSC_MASK) /* connection status change */ { - sofStart = (ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); + sofStart = (int32_t)(ehciInstance->ehciIpBase->FRINDEX & EHCI_MAX_UFRAME_VALUE); /* process CSC bit */ - while (1U == 1U) + while (1) { portScRegister = ehciInstance->ehciIpBase->PORTSC1; - if (0U != (portScRegister & USBHS_PORTSC1_CSC_MASK)) + if (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 = (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 */ + 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 */ { break; } @@ -3857,10 +3792,10 @@ void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance) /* process CCS bit */ portScRegister = ehciInstance->ehciIpBase->PORTSC1; - if (0U != (portScRegister & USBHS_PORTSC1_CCS_MASK)) /* process attach */ + if (portScRegister & USBHS_PORTSC1_CCS_MASK) /* process attach */ { - if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDevicePhyAttached) || - (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached)) + if ((ehciInstance->deviceAttached == kEHCIDevicePhyAttached) || + (ehciInstance->deviceAttached == kEHCIDeviceAttached)) { return; } @@ -3871,25 +3806,25 @@ 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 (0U == (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + if (!(ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) { break; } } if (index < USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY) /* CCS is cleared */ { - ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceDetached; + ehciInstance->deviceAttached = kEHCIDeviceDetached; return; } /* reset port */ portScRegister = ehciInstance->ehciIpBase->PORTSC1; portScRegister &= (~EHCI_PORTSC1_W1_BITS); ehciInstance->ehciIpBase->PORTSC1 = (portScRegister | USBHS_PORTSC1_PR_MASK); - while (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK)) + while (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PR_MASK) { } ehciInstance->firstDeviceSpeed = - (uint8_t)((ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PSPD_MASK) >> USBHS_PORTSC1_PSPD_SHIFT); + ((ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_PSPD_MASK) >> USBHS_PORTSC1_PSPD_SHIFT); /* enable ehci phy disconnection */ if (ehciInstance->firstDeviceSpeed == USB_SPEED_HIGH) { @@ -3899,16 +3834,16 @@ void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance) /* wait for reset */ USB_HostEhciDelay(ehciInstance->ehciIpBase, USB_HOST_EHCI_PORT_RESET_DELAY); /* process attach */ - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_ATTACH); + USB_OsaEventSet(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 = (uint8_t)kEHCIDevicePhyAttached; + ehciInstance->deviceAttached = kEHCIDevicePhyAttached; } else { - if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDevicePhyAttached) || - (ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached)) + if ((ehciInstance->deviceAttached == kEHCIDevicePhyAttached) || + (ehciInstance->deviceAttached == kEHCIDeviceAttached)) { #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) ehciInstance->busSuspendStatus = kBus_EhciIdle; @@ -3919,20 +3854,19 @@ void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance) /* disable async and periodic */ USB_HostEhciStopAsync(ehciInstance); USB_HostEhciStopPeriodic(ehciInstance); - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_DETACH); + USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_DEVICE_DETACH); } } } -void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance) +static void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance) { volatile usb_host_ehci_qh_t *vltQhPointer; - usb_host_ehci_qtd_t *vltQtdPointer; + volatile 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) @@ -3942,13 +3876,13 @@ 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 = 0U; - if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceAttached) + timeoutLabel = 0; + if (ehciInstance->deviceAttached != kEHCIDeviceAttached) { - vltQtdPointer = (usb_host_ehci_qtd_t *)transfer->union2.unitTail; + vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail; vltQhPointer->nextQtdPointer = EHCI_HOST_T_INVALID_VALUE; /* invalid next qtd */ vltQhPointer->transferOverlayResults[0] &= @@ -3957,15 +3891,15 @@ void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance) } else { - if (0U != (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK)) + if (vltQhPointer->transferOverlayResults[0] & EHCI_HOST_QTD_STATUS_ACTIVE_MASK) { - vltQtdPointer = (usb_host_ehci_qtd_t *)vltQhPointer->currentQtdPointer; + vltQtdPointer = (volatile usb_host_ehci_qtd_t *)vltQhPointer->currentQtdPointer; totalBytesAddress = &(vltQhPointer->transferOverlayResults[0]); } else { - vltQtdPointer = (usb_host_ehci_qtd_t *)transfer->union2.unitTail; - totalBytesAddress = &(vltQtdPointer->transferResults[0]); + vltQtdPointer = (volatile usb_host_ehci_qtd_t *)transfer->union2.unitTail; + totalBytesAddress = ((uint32_t *)vltQtdPointer + 2); } backValue = @@ -3974,7 +3908,7 @@ 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 = (uint16_t)backValue; + vltQhPointer->timeOutLabel = backValue; } else { @@ -3982,7 +3916,7 @@ void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance) * USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE */ (vltQhPointer->timeOutValue)--; - if (vltQhPointer->timeOutValue == 0U) + if (vltQhPointer->timeOutValue == 0) { /* stop the qh schedule */ USB_HostEhciStopAsync(ehciInstance); @@ -3997,24 +3931,22 @@ void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance) vltQhPointer->transferOverlayResults[0] &= (~EHCI_HOST_QTD_STATUS_MASK); /* clear error status */ USB_HostEhciStartAsync(ehciInstance); - timeoutLabel = 1U; + timeoutLabel = 1; } } } } - if (timeoutLabel == 1U) + if (timeoutLabel == 1) { /* remove qtd from qh */ - temp = (void *)vltQhPointer->ehciTransferTail; while ((vltQtdPointer != NULL) && - (0U == (vltQtdPointer->transferResults[0] & EHCI_HOST_QTD_IOC_MASK)) && - (vltQtdPointer != (usb_host_ehci_qtd_t *)temp)) + (!(vltQtdPointer->transferResults[0] & EHCI_HOST_QTD_IOC_MASK)) && + (vltQtdPointer != (usb_host_ehci_qtd_t *)vltQhPointer->ehciTransferTail)) { - vltQtdPointer = (usb_host_ehci_qtd_t *)vltQtdPointer->nextQtdPointer; + vltQtdPointer = (volatile usb_host_ehci_qtd_t *)vltQtdPointer->nextQtdPointer; } - if ((vltQtdPointer != NULL) && - (0U == (vltQtdPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE))) + if ((vltQtdPointer != NULL) && (!(vltQtdPointer->nextQtdPointer & EHCI_HOST_T_INVALID_VALUE))) { vltQhPointer->nextQtdPointer = vltQtdPointer->nextQtdPointer; /* start qh if there are other qtd that don't belong to @@ -4024,41 +3956,38 @@ 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) ? - 0U : + 0 : (transfer->transferLength - transfer->transferSofar); vltQhPointer->ehciTransferHead = transfer->next; - vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; - /* callback function is different from the current condition */ + vltQhPointer->timeOutValue = USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE; transfer->callbackFn(transfer->callbackParam, transfer, kStatus_USB_TransferFailed); } } break; default: - /*no action*/ break; } - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciPipePointer = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } } #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 != (uint8_t)kEHCIDeviceDetached) + if (ehciInstance->deviceAttached != kEHCIDeviceDetached) { if (kBus_EhciStartSuspend == ehciInstance->busSuspendStatus) { usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle; - if (0U == ehciInstance->matchTick) + if (0 == ehciInstance->matchTick) { ehciInstance->matchTick = hostPointer->hwTick; } else { - if ((hostPointer->hwTick - ehciInstance->matchTick) >= 5U) + if ((hostPointer->hwTick - ehciInstance->matchTick) >= 5) { ehciInstance->ehciIpBase->USBCMD &= ~USBHS_USBCMD_RS_MASK; ehciInstance->ehciIpBase->USBSTS |= USBHS_USBSTS_SRI_MASK; @@ -4075,9 +4004,9 @@ static void USB_HostEhciTimer1(usb_host_ehci_instance_t *ehciInstance) ehciInstance->registerPhyBase->PWD = 0xFFFFFFFFU; - while (0U != (ehciInstance->registerPhyBase->CTRL & (USBPHY_CTRL_UTMI_SUSPENDM_MASK))) + while (ehciInstance->registerPhyBase->CTRL & (USBPHY_CTRL_UTMI_SUSPENDM_MASK)) { - __NOP(); + __ASM("nop"); } #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U)) @@ -4089,8 +4018,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; - (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, - kUSB_HostEventSuspended); /* call host callback function */ + hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, + kUSB_HostEventSuspended); /* call host callback function */ ehciInstance->busSuspendStatus = kBus_EhciSuspended; } } @@ -4098,17 +4027,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 (0U == (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK)) + if (!(ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK)) { ehciInstance->ehciIpBase->PORTSC1 &= ~USBHS_PORTSC1_WKDS_MASK; - if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK) { USB_HostEhciStartAsync(ehciInstance); USB_HostEhciStartPeriodic(ehciInstance); } - (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, - kUSB_HostEventResumed); /* call host callback function */ - hostPointer->suspendedDevice = NULL; + 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); } @@ -4130,31 +4059,30 @@ usb_status_t USB_HostEhciCreate(uint8_t controllerId, usb_host_controller_handle *controllerHandle) { uint32_t index = 0; - osa_status_t osaStatus; + usb_osa_status_t osaStatus; usb_host_ehci_instance_t *ehciInstance; uint32_t usbhsBaseAddrs[] = USBHS_BASE_ADDRS; - usb_host_ehci_data_t *usbHostEhciData[USB_HOST_CONFIG_EHCI]; + usb_host_ehci_data_t *usbHostEhciData[] = USB_HOST_EHCI_DATA_ARRAY; + uint8_t *usbHostEhciFrameList[] = USB_HOST_EHCI_FRAME_LIST_ARRAY; uint32_t *framePointer; - void *temp; - uint8_t instanceIndex = 0U; - if ((controllerId - (uint8_t)kUSB_ControllerEhci0) >= (sizeof(usbhsBaseAddrs) / sizeof(usbhsBaseAddrs[0]))) + if ((uint32_t)(controllerId - kUSB_ControllerEhci0) >= (sizeof(usbhsBaseAddrs) / sizeof(usbhsBaseAddrs[0]))) { return kStatus_USB_ControllerNotFound; } *controllerHandle = NULL; - ehciInstance = (usb_host_ehci_instance_t *)OSA_MemoryAllocate( + ehciInstance = (usb_host_ehci_instance_t *)USB_OsaMemoryAllocate( 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 = (uint8_t)kEHCIDeviceDetached; - ehciInstance->ehciIpBase = (USBHS_Type *) - usbhsBaseAddrs[controllerId - (uint8_t)kUSB_ControllerEhci0]; /* operate ehci ip through the base address */ + ehciInstance->controllerId = controllerId; + ehciInstance->hostHandle = upperLayerHandle; + ehciInstance->deviceAttached = kEHCIDeviceDetached; + ehciInstance->ehciIpBase = (USBHS_Type *) + usbhsBaseAddrs[controllerId - 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; @@ -4169,150 +4097,95 @@ usb_status_t USB_HostEhciCreate(uint8_t controllerId, #endif - if ((USB_HostEhciResetIP(ehciInstance) != kStatus_USB_Success) || - ((ehciInstance->controllerId < (uint8_t)kUSB_ControllerEhci0))) /* reset ehci ip */ + if (USB_HostEhciResetIP(ehciInstance) != kStatus_USB_Success) /* reset ehci ip */ { - OSA_MemoryFree(ehciInstance); + USB_OsaMemoryFree(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 - { - /*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 - - temp = (void *)usbHostEhciData[instanceIndex]; - ehciInstance->ehciUnitBase = (uint32_t *)(temp); + /* initialize ehci units */ + ehciInstance->ehciUnitBase = (uint32_t *)(usbHostEhciData[ehciInstance->controllerId - kUSB_ControllerEhci0]); /* 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)); -#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 = + ehciInstance->ehciSitdList = ehciInstance->ehciSitdIndexBase = (usb_host_ehci_sitd_t *)((uint32_t)ehciInstance->ehciItdList + (sizeof(usb_host_ehci_itd_t) * USB_HOST_CONFIG_EHCI_MAX_ITD)); - ehciInstance->ehciSitdList = ehciInstance->ehciSitdIndexBase; - ehciInstance->ehciIsoList = (usb_host_ehci_iso_t *)((uint32_t)ehciInstance->ehciSitdList + + 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 = 1U; index < USB_HOST_CONFIG_EHCI_MAX_QH; ++index) + for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_QH; ++index) { - ehciInstance->ehciQhList[index - 1U].horizontalLinkPointer = (uint32_t)(&ehciInstance->ehciQhList[index]); + ehciInstance->ehciQhList[index - 1].horizontalLinkPointer = (uint32_t)(&ehciInstance->ehciQhList[index]); } - ehciInstance->ehciQhList[USB_HOST_CONFIG_EHCI_MAX_QH - 1U].horizontalLinkPointer = 0U; + ehciInstance->ehciQhList[USB_HOST_CONFIG_EHCI_MAX_QH - 1].horizontalLinkPointer = (uint32_t)NULL; for (index = 1; index < USB_HOST_CONFIG_EHCI_MAX_QTD; ++index) { - ehciInstance->ehciQtdHead[index - 1U].nextQtdPointer = (uint32_t)(&ehciInstance->ehciQtdHead[index]); + ehciInstance->ehciQtdHead[index - 1].nextQtdPointer = (uint32_t)(&ehciInstance->ehciQtdHead[index]); } - 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]; + 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]; #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 - 1U].nextItdPointer = - (usb_host_ehci_itd_t *)(&ehciInstance->ehciItdList[index]); + ehciInstance->ehciItdList[index - 1].nextLinkPointer = (uint32_t)(&ehciInstance->ehciItdList[index]); } - ehciInstance->ehciItdNumber = USB_HOST_CONFIG_EHCI_MAX_ITD; - ehciInstance->ehciItdList[USB_HOST_CONFIG_EHCI_MAX_ITD - 1U].nextItdPointer = NULL; + ehciInstance->ehciItdNumber = USB_HOST_CONFIG_EHCI_MAX_ITD; + ehciInstance->ehciItdList[USB_HOST_CONFIG_EHCI_MAX_ITD - 1].nextLinkPointer = (uint32_t)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 - 1U].nextLinkPointer = (uint32_t)(&ehciInstance->ehciSitdList[index]); + ehciInstance->ehciSitdList[index - 1].nextLinkPointer = (uint32_t)(&ehciInstance->ehciSitdList[index]); } - ehciInstance->ehciSitdNumber = USB_HOST_CONFIG_EHCI_MAX_SITD; - ehciInstance->ehciSitdList[USB_HOST_CONFIG_EHCI_MAX_SITD - 1U].nextLinkPointer = 0U; + ehciInstance->ehciSitdNumber = USB_HOST_CONFIG_EHCI_MAX_SITD; + ehciInstance->ehciSitdList[USB_HOST_CONFIG_EHCI_MAX_SITD - 1].nextLinkPointer = (uint32_t)NULL; #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 - 1U].next = &ehciInstance->ehciIsoList[index]; + ehciInstance->ehciIsoList[index - 1].next = &ehciInstance->ehciIsoList[index]; } - ehciInstance->ehciIsoList[USB_HOST_EHCI_ISO_NUMBER - 1U].next = NULL; + ehciInstance->ehciIsoList[USB_HOST_EHCI_ISO_NUMBER - 1].next = NULL; #endif /* initialize pipes */ ehciInstance->ehciPipeList = ehciInstance->ehciPipeIndexBase; for (index = 1; index < USB_HOST_CONFIG_MAX_PIPES; ++index) { - temp = (void *)&ehciInstance->ehciPipeList[index]; - ehciInstance->ehciPipeList[index - 1U].pipeCommon.next = (usb_host_pipe_t *)temp; + ehciInstance->ehciPipeList[index - 1].pipeCommon.next = (usb_host_pipe_t *)&ehciInstance->ehciPipeList[index]; } /* initialize mutext */ - ehciInstance->ehciMutex = (osa_mutex_handle_t)(&ehciInstance->mutexBuffer[0]); - osaStatus = OSA_MutexCreate(ehciInstance->ehciMutex); - if (osaStatus != KOSA_StatusSuccess) + osaStatus = USB_OsaMutexCreate(&ehciInstance->ehciMutex); + if (osaStatus != kStatus_USB_OSA_Success) { #ifdef HOST_ECHO usb_echo("ehci mutex init fail\r\n"); #endif - OSA_MemoryFree(ehciInstance); + USB_OsaMemoryFree(ehciInstance); return kStatus_USB_Error; } /* initialize task event */ - ehciInstance->taskEventHandle = (osa_event_handle_t)&ehciInstance->taskEventHandleBuffer[0]; - osaStatus = OSA_EventCreate(ehciInstance->taskEventHandle, 1); - if (osaStatus != KOSA_StatusSuccess) + osaStatus = USB_OsaEventCreate(&ehciInstance->taskEventHandle, 1); + if (osaStatus != kStatus_USB_OSA_Success) { #ifdef HOST_ECHO usb_echo("ehci event init fail\r\n"); #endif - (void)OSA_MutexDestroy(ehciInstance->ehciMutex); - OSA_MemoryFree(ehciInstance); + USB_OsaMutexDestroy(ehciInstance->ehciMutex); + USB_OsaMemoryFree(ehciInstance); return kStatus_USB_Error; } @@ -4320,23 +4193,22 @@ 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] |= (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->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->alternateNextQtdPointer = EHCI_HOST_T_INVALID_VALUE; ehciInstance->shedFirstQh->horizontalLinkPointer = (uint32_t)((uint32_t)(ehciInstance->shedFirstQh) | EHCI_HOST_POINTER_TYPE_QH); /* initialize periodic list */ - temp = (void *)ehciInstance->ehciFrameList; - framePointer = (uint32_t *)temp; + framePointer = (uint32_t *)ehciInstance->ehciFrameList; for (index = 0; index < USB_HOST_CONFIG_EHCI_FRAME_LIST_SIZE; ++index) { framePointer[index] = EHCI_HOST_T_INVALID_VALUE; } - (void)USB_HostEhciStartIP(ehciInstance); /* start ehci ip */ + USB_HostEhciStartIP(ehciInstance); /* start ehci ip */ *controllerHandle = ehciInstance; @@ -4351,29 +4223,10 @@ usb_status_t USB_HostEhciDestory(usb_host_controller_handle controllerHandle) ehciInstance->ehciIpBase->USBINTR = 0; /* stop the controller */ ehciInstance->ehciIpBase->USBCMD = 0; -/* 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); + /* free memory */ + USB_OsaMutexDestroy(ehciInstance->ehciMutex); + USB_OsaEventDestroy(ehciInstance->taskEventHandle); + USB_OsaMemoryFree(ehciInstance); return kStatus_USB_Success; } @@ -4384,17 +4237,15 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle, { usb_host_ehci_pipe_t *ehciPipePointer = NULL; usb_status_t status; - uint32_t speed = 0; + uint32_t speed; 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; - temp = (void *)ehciPipePointer->pipeCommon.next; - ehciInstance->ehciPipeList = (usb_host_ehci_pipe_t *)temp; + ehciPipePointer = ehciInstance->ehciPipeList; + ehciInstance->ehciPipeList = (usb_host_ehci_pipe_t *)ehciPipePointer->pipeCommon.next; } USB_HostEhciUnlock(); if (ehciPipePointer == NULL) @@ -4406,54 +4257,44 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle, } /* initialize pipe informations */ - USB_HostEhciZeroMem((void *)ehciPipePointer, sizeof(usb_host_ehci_pipe_t) / 4U); - ehciPipePointer->pipeCommon.deviceHandle = pipeInit->devInstance; + USB_HostEhciZeroMem((uint32_t *)ehciPipePointer, sizeof(usb_host_ehci_pipe_t) / 4); + 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 + 1U; - if (ehciPipePointer->pipeCommon.numberPerUframe > 3U) + 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.numberPerUframe = 3U; + ehciPipePointer->pipeCommon.numberPerUframe = 1; } - 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.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) { - if (ehciPipePointer->pipeCommon.pipeType == USB_ENDPOINT_ISOCHRONOUS) + 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) { ehciPipePointer->pipeCommon.interval = - (uint16_t)(1UL << (ehciPipePointer->pipeCommon.interval - 1U)); /* iso interval is the power of 2 */ + (1 << (ehciPipePointer->pipeCommon.interval - 1)); /* HS interrupt interval is the power of 2 */ } else { - 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; + ehciPipePointer->pipeCommon.interval = USB_HostEhciGet2PowerValue( + ehciPipePointer->pipeCommon + .interval); /* FS/LS interrupt interval should be the power of 2, it is used for ehci bandwidth */ } } + else + { + } /* save the micro-frame interval, it is convenient for the interval process */ if (speed == USB_SPEED_HIGH) @@ -4462,7 +4303,7 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle, } else { - ehciPipePointer->uframeInterval = 8U * ehciPipePointer->pipeCommon.interval; + ehciPipePointer->uframeInterval = 8 * ehciPipePointer->pipeCommon.interval; } /* open pipe */ @@ -4493,17 +4334,15 @@ usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle, { /* release pipe */ USB_HostEhciLock(); - temp = (void *)ehciInstance->ehciPipeList; - ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp; - ehciInstance->ehciPipeList = ehciPipePointer; + ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciPipeList; + ehciInstance->ehciPipeList = ehciPipePointer; USB_HostEhciUnlock(); return status; } /* add pipe to run pipe list */ USB_HostEhciLock(); - temp = (void *)ehciInstance->ehciRunningPipeList; - ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp; + ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciRunningPipeList; ehciInstance->ehciRunningPipeList = ehciPipePointer; USB_HostEhciUnlock(); @@ -4514,50 +4353,43 @@ 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; - void *temp; - void *tempCurrent; + usb_host_ehci_pipe_t *ehciPipePointer = (usb_host_ehci_pipe_t *)pipeHandle; + usb_host_pipe_t *prevPointer = NULL; switch (ehciPipePointer->pipeCommon.pipeType) { case USB_ENDPOINT_BULK: case USB_ENDPOINT_CONTROL: - (void)USB_HostEhciCloseControlBulk(ehciInstance, ehciPipePointer); + USB_HostEhciCloseControlBulk(ehciInstance, ehciPipePointer); break; case USB_ENDPOINT_INTERRUPT: - (void)USB_HostEhciCloseInterrupt(ehciInstance, ehciPipePointer); + 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: - (void)USB_HostEhciCloseIso(ehciInstance, ehciPipePointer); + USB_HostEhciCloseIso(ehciInstance, ehciPipePointer); break; #endif default: - /*no action*/ break; } /* delete pipe from run pipe list */ USB_HostEhciLock(); - temp = (void *)ehciInstance->ehciRunningPipeList; - prevPointer = (usb_host_pipe_t *)temp; - tempCurrent = (void *)ehciPipePointer; - if (prevPointer == (usb_host_pipe_t *)tempCurrent) + prevPointer = (usb_host_pipe_t *)ehciInstance->ehciRunningPipeList; + if (prevPointer == (usb_host_pipe_t *)ehciPipePointer) { - temp = (void *)prevPointer->next; - ehciInstance->ehciRunningPipeList = (usb_host_ehci_pipe_t *)(temp); + ehciInstance->ehciRunningPipeList = (usb_host_ehci_pipe_t *)(prevPointer->next); } else { while (prevPointer != NULL) { - temp = (void *)ehciPipePointer; - if (prevPointer->next == (usb_host_pipe_t *)temp) + if (prevPointer->next == (usb_host_pipe_t *)ehciPipePointer) { prevPointer->next = ehciPipePointer->pipeCommon.next; break; @@ -4572,9 +4404,8 @@ usb_status_t USB_HostEhciClosePipe(usb_host_controller_handle controllerHandle, /* release pipe */ USB_HostEhciLock(); - temp = (void *)ehciInstance->ehciPipeList; - ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)temp; - ehciInstance->ehciPipeList = ehciPipePointer; + ehciPipePointer->pipeCommon.next = (usb_host_pipe_t *)ehciInstance->ehciPipeList; + ehciInstance->ehciPipeList = ehciPipePointer; USB_HostEhciUnlock(); return kStatus_USB_Success; @@ -4585,11 +4416,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 = 0U; + uint32_t speed; #endif switch (ehciPipePointer->pipeCommon.pipeType) @@ -4604,8 +4435,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: - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceSpeed, &speed); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, kUSB_HostGetDeviceSpeed, + &speed); if (speed == USB_SPEED_HIGH) { #if ((defined USB_HOST_CONFIG_EHCI_MAX_ITD) && (USB_HOST_CONFIG_EHCI_MAX_ITD)) @@ -4624,7 +4455,6 @@ usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerHandle, #endif default: - /*no action*/ break; } return status; @@ -4639,22 +4469,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 = 0; - usb_host_controller_control_t controlCode = (usb_host_controller_control_t)ioctlEvent; + uint32_t deviceAddress; + if (controllerHandle == NULL) { return kStatus_USB_InvalidHandle; } - switch (controlCode) + switch (ioctlEvent) { 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; @@ -4668,19 +4498,18 @@ 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 */ - (void)USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, - (uint32_t)kUSB_HostGetDeviceAddress, &deviceAddress); + USB_HostHelperGetPeripheralInformation(ehciPipePointer->pipeCommon.deviceHandle, 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 (0U != (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK)) + if (ehciInstance->ehciIpBase->USBSTS & USBHS_USBSTS_AS_MASK) { USB_HostEhciStopAsync(ehciInstance); /* update max packet size */ @@ -4698,13 +4527,8 @@ 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; @@ -4722,44 +4546,44 @@ void USB_HostEhciTaskFunction(void *hostHandle) } ehciInstance = (usb_host_ehci_instance_t *)((usb_host_instance_t *)hostHandle)->controllerHandle; - if (OSA_EventWait(ehciInstance->taskEventHandle, 0xFF, 0, USB_OSA_WAIT_TIMEOUT, &bitSet) == - KOSA_StatusSuccess) /* wait all event */ + if (USB_OsaEventWait(ehciInstance->taskEventHandle, 0xFF, 0, 0, &bitSet) == + kStatus_USB_OSA_Success) /* wait all event */ { - if (0U != (bitSet & EHCI_TASK_EVENT_PORT_CHANGE)) /* port change */ + if (bitSet & EHCI_TASK_EVENT_PORT_CHANGE) /* port change */ { USB_HostEhciPortChange(ehciInstance); } - if (0U != (bitSet & EHCI_TASK_EVENT_TIMER0)) /* timer0 */ + if (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 (0U != (bitSet & EHCI_TASK_EVENT_TIMER1)) /* timer1 */ + if (bitSet & EHCI_TASK_EVENT_TIMER1) /* timer1 */ { USB_HostEhciTimer1(ehciInstance); } #endif - if ((ehciInstance->deviceAttached == (uint8_t)kEHCIDeviceAttached)) + if (ehciInstance->deviceAttached == kEHCIDeviceAttached) { - if (0U != (bitSet & EHCI_TASK_EVENT_TRANSACTION_DONE)) /* transaction done */ + if (bitSet & EHCI_TASK_EVENT_TRANSACTION_DONE) /* transaction done */ { USB_HostEhciTransactionDone(ehciInstance); } - if (0U != (bitSet & EHCI_TASK_EVENT_DEVICE_DETACH)) /* device detach */ + if (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 = (uint8_t)kEHCIDeviceDetached; - (void)USB_HostDetachDevice(ehciInstance->hostHandle, 0, 0); + ehciInstance->deviceAttached = kEHCIDeviceDetached; + USB_HostDetachDevice(ehciInstance->hostHandle, 0, 0); } } - else if (ehciInstance->deviceAttached != (uint8_t)kEHCIDeviceAttached) + else if (ehciInstance->deviceAttached != kEHCIDeviceAttached) { - if (0U != (bitSet & EHCI_TASK_EVENT_DEVICE_ATTACH)) /* device is attached */ + if (bitSet & EHCI_TASK_EVENT_DEVICE_ATTACH) /* device is attached */ { USB_HostEhciStartAsync(ehciInstance); USB_HostEhciStartPeriodic(ehciInstance); @@ -4767,13 +4591,12 @@ void USB_HostEhciTaskFunction(void *hostHandle) if (USB_HostAttachDevice(ehciInstance->hostHandle, ehciInstance->firstDeviceSpeed, 0, 0, 1, &deviceHandle) == kStatus_USB_Success) { - ehciInstance->deviceAttached = (uint8_t)kEHCIDeviceAttached; + ehciInstance->deviceAttached = kEHCIDeviceAttached; } } } else { - /*no action*/ } } } @@ -4793,18 +4616,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 (0U != (ehciInstance->registerNcBase->USB_OTGn_CTRL & USBNC_USB_OTGn_CTRL_WIE_MASK)) + if (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; - (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)) + 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)) { } -#endif - if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + + if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK) { USB_HostEhciStartAsync(ehciInstance); USB_HostEhciStartPeriodic(ehciInstance); @@ -4817,27 +4640,25 @@ void USB_HostEhciIsrFunction(void *hostHandle) } else { - /*no action*/ } } else { - /*no action*/ } #else - if (0U != (ehciInstance->ehciIpBase->USBGENCTRL & USBHS_USBGENCTRL_WU_IE_MASK)) + if (ehciInstance->ehciIpBase->USBGENCTRL & USBHS_USBGENCTRL_WU_IE_MASK) { usb_host_instance_t *hostPointer = (usb_host_instance_t *)ehciInstance->hostHandle; - (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, - kUSB_HostEventDetectResume); /* call host callback function */ + hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, + kUSB_HostEventDetectResume); /* call host callback function */ - while (0U == (USBPHY->PLL_SIC & USBPHY_PLL_SIC_PLL_LOCK_MASK)) + while (!(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 (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK) { USB_HostEhciStartAsync(ehciInstance); USB_HostEhciStartPeriodic(ehciInstance); @@ -4850,12 +4671,10 @@ void USB_HostEhciIsrFunction(void *hostHandle) } else { - /*no action*/ } } else { - /*no action*/ } #endif /* FSL_FEATURE_SOC_USBNC_COUNT */ @@ -4863,61 +4682,60 @@ void USB_HostEhciIsrFunction(void *hostHandle) interruptStatus = ehciInstance->ehciIpBase->USBSTS; interruptStatus &= ehciInstance->ehciIpBase->USBINTR; - while (0U != interruptStatus) /* there are usb interrupts */ + while (interruptStatus) /* there are usb interrupts */ { ehciInstance->ehciIpBase->USBSTS = interruptStatus; /* clear interrupt */ - if (0U != (interruptStatus & USBHS_USBSTS_SRI_MASK)) /* SOF interrupt */ + if (interruptStatus & USBHS_USBSTS_SRI_MASK) /* SOF interrupt */ { } - if (0U != (interruptStatus & USBHS_USBSTS_SEI_MASK)) /* system error interrupt */ + if (interruptStatus & USBHS_USBSTS_SEI_MASK) /* system error interrupt */ { } - if ((0U != (interruptStatus & USBHS_USBSTS_UI_MASK)) || - (0U != (interruptStatus & USBHS_USBSTS_UEI_MASK))) /* USB interrupt or USB error interrupt */ + if ((interruptStatus & USBHS_USBSTS_UI_MASK) || + (interruptStatus & USBHS_USBSTS_UEI_MASK)) /* USB interrupt or USB error interrupt */ { - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TRANSACTION_DONE); + USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TRANSACTION_DONE); } - if (0U != (interruptStatus & USBHS_USBSTS_PCI_MASK)) /* port change detect interrupt */ + if (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 (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK)) + if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_FPR_MASK) { if (kBus_EhciStartSuspend == ehciInstance->busSuspendStatus) { - if (0U != (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK)) + if (ehciInstance->ehciIpBase->PORTSC1 & USBHS_PORTSC1_CCS_MASK) { USB_HostEhciStartAsync(ehciInstance); USB_HostEhciStartPeriodic(ehciInstance); } - (void)hostPointer->deviceCallback(hostPointer->suspendedDevice, NULL, - kUSB_HostEventNotSuspended); /* call host callback function */ - hostPointer->suspendedDevice = NULL; + 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 - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_PORT_CHANGE); + USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_PORT_CHANGE); } - if (0U != (interruptStatus & USBHS_USBSTS_TI0_MASK)) /* timer 0 interrupt */ + if (interruptStatus & USBHS_USBSTS_TI0_MASK) /* timer 0 interrupt */ { - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER0); + USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER0); } #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) - if (0U != (interruptStatus & USBHS_USBSTS_TI1_MASK)) /* timer 1 interrupt */ + if (interruptStatus & USBHS_USBSTS_TI1_MASK) /* timer 1 interrupt */ { - (void)OSA_EventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER1); + USB_OsaEventSet(ehciInstance->taskEventHandle, EHCI_TASK_EVENT_TIMER1); } #endif 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 5aea41c147..162d6576cd 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_ehci.h @@ -1,9 +1,31 @@ /* * Copyright (c) 2015, Freescale Semiconductor, Inc. - * Copyright 2016,2019 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ #ifndef _USB_HOST_CONTROLLER_EHCI_H_ @@ -17,95 +39,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 (0UL) -#define EHCI_HOST_PID_IN (1UL) -#define EHCI_HOST_PID_SETUP (2UL) +#define EHCI_HOST_PID_OUT (0U) +#define EHCI_HOST_PID_IN (1U) +#define EHCI_HOST_PID_SETUP (2U) -#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 (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_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_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() (void)OSA_MutexLock(ehciInstance->ehciMutex, USB_OSA_WAIT_TIMEOUT) -#define USB_HostEhciUnlock() (void)OSA_MutexUnlock(ehciInstance->ehciMutex) +#define USB_HostEhciLock() USB_OsaMutexLock(ehciInstance->ehciMutex) +#define USB_HostEhciUnlock() USB_OsaMutexUnlock(ehciInstance->ehciMutex) /******************************************************************************* * KHCI driver public structures, enumerations, macros, functions @@ -122,8 +144,6 @@ #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 @@ -151,7 +171,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 (50U) +#define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (20U) #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) typedef enum _bus_ehci_suspend_request_state @@ -303,10 +323,8 @@ 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*/ - 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*/ + usb_osa_mutex_handle ehciMutex; /*!< EHCI mutex*/ + usb_osa_event_handle taskEventHandle; /*!< EHCI task event*/ #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 */ @@ -337,10 +355,6 @@ 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*/ @@ -474,45 +488,6 @@ 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 diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c deleted file mode 100644 index b45612289d..0000000000 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#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; -} diff --git a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h b/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h deleted file mode 100644 index 53f618fdc3..0000000000 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_framework.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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_ */ 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 1409868b7b..927bf8bd9c 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.c @@ -1,12 +1,34 @@ /* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016 - 2019 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ -#include +#include #include "fsl_common.h" #include "usb_host.h" #include "usb_host_hci.h" @@ -20,24 +42,16 @@ * 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)) -#include "usb_host_hub.h" -#include "usb_host_hub_app.h" +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); #endif /*! @@ -63,6 +77,15 @@ 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 ******************************************************************************/ @@ -71,7 +94,8 @@ 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, }; @@ -79,7 +103,8 @@ 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, }; @@ -87,7 +112,8 @@ 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, }; @@ -95,67 +121,65 @@ 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; - (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); + 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); - if ((productId != 0x0200U) && (productId != 0x0101U) && (productId != 0x0102U) && (productId != 0x0103U) && - (productId != 0x0104U) && (productId != 0x0105U) && (productId != 0x0106U) && (productId != 0x0107U) && - (productId != 0x0108U)) + if ((productId != 0x0200U) && (productId != 0x0101) && (productId != 0x0102) && (productId != 0x0103) && + (productId != 0x0104) && (productId != 0x0105) && (productId != 0x0106) && (productId != 0x0107) && + (productId != 0x0108)) { - (void)usb_echo("Unsupported Device\r\n"); + usb_echo("Unsupported Device\r\n"); } if (productId == 0x0200U) { - (void)usb_echo("PET test device attached\r\n"); + usb_echo("PET test device attached\r\n"); } else { #if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) if (hostInstance->controllerTable == &s_EhciInterface) { - (void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit, - (void *)deviceHandle); + USB_HostEhciTestModeInit(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) { - (void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit, - (void *)deviceHandle); + USB_HostIp3516HsTestModeInit(deviceHandle); } #endif } @@ -166,14 +190,13 @@ 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; - void *temp; - OSA_SR_ALLOC(); - OSA_ENTER_CRITICAL(); + USB_OSA_SR_ALLOC(); + USB_OSA_ENTER_CRITICAL(); for (; i < USB_HOST_CONFIG_MAX_HOST; i++) { - if (g_UsbHostInstance[i].occupied != 1U) + if (g_UsbHostInstance[i].occupied != 1) { uint8_t *buffer = (uint8_t *)&g_UsbHostInstance[i]; for (uint32_t j = 0U; j < sizeof(usb_host_instance_t); j++) @@ -181,53 +204,53 @@ static usb_host_instance_t *USB_HostGetInstance(void) buffer[j] = 0x00U; } g_UsbHostInstance[i].occupied = 1; - OSA_EXIT_CRITICAL(); + USB_OSA_EXIT_CRITICAL(); for (index = 0; index < USB_HOST_CONFIG_MAX_TRANSFERS; ++index) { - temp = (void *)&(s_Setupbuffer[i][index][0]); - g_UsbHostInstance[i].transferList[index].setupPacket = (usb_setup_struct_t *)temp; + g_UsbHostInstance[i].transferList[index].setupPacket = + (usb_setup_struct_t *)&(s_Setupbuffer[i][index][0]); } return &g_UsbHostInstance[i]; } } - OSA_EXIT_CRITICAL(); + USB_OSA_EXIT_CRITICAL(); return NULL; } static void USB_HostReleaseInstance(usb_host_instance_t *hostInstance) { - OSA_SR_ALLOC(); - OSA_ENTER_CRITICAL(); + USB_OSA_SR_ALLOC(); + USB_OSA_ENTER_CRITICAL(); hostInstance->occupied = 0; - OSA_EXIT_CRITICAL(); + USB_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 == (uint8_t)kUSB_ControllerKhci0) + if (controllerId == kUSB_ControllerKhci0) { *controllerTable = &s_KhciInterface; } #endif /* USB_HOST_CONFIG_KHCI */ #if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) - if ((controllerId == (uint8_t)kUSB_ControllerEhci0) || (controllerId == (uint8_t)kUSB_ControllerEhci1)) + if ((controllerId == kUSB_ControllerEhci0) || (controllerId == kUSB_ControllerEhci1)) { *controllerTable = &s_EhciInterface; } #endif /* USB_HOST_CONFIG_EHCI */ #if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U)) - if (controllerId == (uint8_t)kUSB_ControllerOhci0) + if (controllerId == kUSB_ControllerOhci0) { *controllerTable = &s_OhciInterface; } #endif /* USB_HOST_CONFIG_OHCI */ #if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U)) - if (controllerId == (uint8_t)kUSB_ControllerIp3516Hs0) + if (controllerId == kUSB_ControllerIp3516Hs0) { *controllerTable = &s_Ip3516HsInterface; } @@ -236,10 +259,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) @@ -268,11 +291,10 @@ 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; - hostInstance->hostMutex = (osa_mutex_handle_t)(&hostInstance->mutexBuffer[0]); - if (KOSA_StatusSuccess != OSA_MutexCreate(hostInstance->hostMutex)) + hostInstance->deviceList = NULL; + if (kStatus_USB_OSA_Success != USB_OsaMutexCreate(&hostInstance->hostMutex)) { USB_HostReleaseInstance(hostInstance); #ifdef HOST_ECHO @@ -284,19 +306,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, the callbackFn is initialized in USB_HostGetControllerInterface */ + /* controller create */ status = hostInstance->controllerTable->controllerCreate(controllerId, hostInstance, &(hostInstance->controllerHandle)); if ((status != kStatus_USB_Success) || (hostInstance->controllerHandle == NULL)) { - (void)OSA_MutexDestroy(hostInstance->hostMutex); + USB_OsaMutexDestroy(hostInstance->hostMutex); USB_HostReleaseInstance(hostInstance); #ifdef HOST_ECHO usb_echo("host init: controller init fail\r\n"); @@ -310,8 +332,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) @@ -324,23 +346,23 @@ usb_status_t USB_HostDeinit(usb_host_handle hostHandle) while (deviceInstance != NULL) { deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList; - (void)USB_HostDetachDeviceInternal(hostHandle, deviceInstance); + USB_HostDetachDeviceInternal(hostHandle, deviceInstance); } - /* controller instance destroy, the callbackFn is initialized in USB_HostGetControllerInterface */ - status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle); + /* controller instance destory */ + status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle); hostInstance->controllerHandle = NULL; if (status != kStatus_USB_Success) { #ifdef HOST_ECHO - usb_echo("host controller destroy fail\r\n"); + usb_echo("host controller destory fail\r\n"); #endif } /* resource release */ - if (NULL != hostInstance->hostMutex) + if (hostInstance->hostMutex) { - (void)OSA_MutexDestroy(hostInstance->hostMutex); + USB_OsaMutexDestroy(hostInstance->hostMutex); hostInstance->hostMutex = NULL; } USB_HostReleaseInstance(hostInstance); @@ -352,7 +374,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)) @@ -360,7 +382,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle, return kStatus_USB_InvalidHandle; } - /* call controller open pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */ + /* call controller open pipe interface */ status = hostInstance->controllerTable->controllerOpenPipe(hostInstance->controllerHandle, pipeHandle, pipeInit); return status; @@ -368,7 +390,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)) @@ -376,7 +398,7 @@ usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle return kStatus_USB_InvalidHandle; } - /* call controller close pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */ + /* call controller close pipe interface */ status = hostInstance->controllerTable->controllerClosePipe(hostInstance->controllerHandle, pipeHandle); return status; @@ -384,7 +406,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)) @@ -394,9 +416,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; - (void)USB_HostLock(); /* This api can be called by host task and app task */ + 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 @@ -413,10 +435,9 @@ 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); - (void)USB_HostUnlock(); + USB_HostUnlock(); return status; } @@ -424,7 +445,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)) @@ -434,8 +455,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; @@ -445,7 +466,7 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle, transfer->direction = USB_OUT; } - (void)USB_HostLock(); /* This API can be called by host task and application task */ + 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 @@ -463,16 +484,15 @@ 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); - (void)USB_HostUnlock(); + 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)) @@ -482,9 +502,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; - (void)USB_HostLock(); /* This API can be called by host task and application task */ + 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 @@ -501,10 +521,9 @@ 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); - (void)USB_HostUnlock(); + USB_HostUnlock(); return status; } @@ -512,7 +531,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; @@ -523,10 +542,9 @@ 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(); */ @@ -544,18 +562,18 @@ usb_status_t USB_HostMallocTransfer(usb_host_handle hostHandle, usb_host_transfe } /* get one from the transfer_head */ - (void)USB_HostLock(); + USB_HostLock(); if (hostInstance->transferHead != NULL) { - *transfer = hostInstance->transferHead; + *transfer = hostInstance->transferHead; hostInstance->transferHead = hostInstance->transferHead->next; - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Success; } else { *transfer = NULL; - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Error; } } @@ -574,10 +592,10 @@ usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_transfer_ } /* release one to the transfer_head */ - (void)USB_HostLock(); - transfer->next = hostInstance->transferHead; + USB_HostLock(); + transfer->next = hostInstance->transferHead; hostInstance->transferHead = transfer; - (void)USB_HostUnlock(); + USB_HostUnlock(); return kStatus_USB_Success; } @@ -586,28 +604,23 @@ 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; } - devInfo = (usb_host_dev_info_t)infoCode; - switch (devInfo) + + switch (infoCode) { case kUSB_HostGetDeviceAddress: /* device address */ - *infoValue = (uint32_t)deviceInstance->setAddress; break; case kUSB_HostGetDeviceControlPipe: /* device control pipe */ - temp = (uint32_t *)deviceInstance->controlPipe; - *infoValue = (uint32_t)temp; + *infoValue = (uint32_t)deviceInstance->controlPipe; break; case kUSB_HostGetHostHandle: /* device host handle */ - temp = (uint32_t *)deviceInstance->hostHandle; - *infoValue = (uint32_t)temp; + *infoValue = (uint32_t)deviceInstance->hostHandle; break; #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB)) @@ -672,8 +685,7 @@ usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHand break; default: - /*no action*/ - break; + return kStatus_USB_Error; } return kStatus_USB_Success; @@ -686,27 +698,26 @@ 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 == 0U) + if (alternateSetting == 0) { return kStatus_USB_InvalidParameter; } /* parse configuration descriptor */ - temp = (void *)((usb_host_interface_t *)interfaceHandle)->interfaceDesc; - ; - unionDes = (usb_descriptor_union_t *)temp; /* interface extend descriptor start */ + unionDes = (usb_descriptor_union_t *)((usb_host_interface_t *)interfaceHandle) + ->interfaceDesc; /* 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 descriptor */ + /* search for the alternate setting interface descritpor */ while ((uint32_t)unionDes < endPosition) { if (unionDes->interface.bDescriptorType == USB_DESCRIPTOR_TYPE_INTERFACE) @@ -731,12 +742,12 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter } /* initialize interface handle structure instance */ - interface->interfaceDesc = &unionDes->interface; - interface->alternateSettingNumber = 0U; - interface->epCount = 0U; - interface->interfaceExtension = NULL; - interface->interfaceExtensionLength = 0U; - interface->interfaceIndex = unionDes->interface.bInterfaceNumber; + interface->interfaceDesc = &unionDes->interface; + interface->alternateSettingNumber = 0; + interface->epCount = 0; + interface->interfaceExtension = NULL; + interface->interfaceExtensionLength = 0; + interface->interfaceIndex = unionDes->interface.bInterfaceNumber; /* search for endpoint descriptor start position */ unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength); @@ -759,7 +770,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter } /* parse endpoint descriptor */ - if (interface->interfaceDesc->bNumEndpoints != 0U) + if (interface->interfaceDesc->bNumEndpoints != 0) { if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) || (interface->interfaceDesc->bNumEndpoints > USB_HOST_CONFIG_INTERFACE_MAX_EP)) @@ -779,12 +790,11 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter #endif return kStatus_USB_Error; } - epParse = (usb_host_ep_t *)&interface->epList[interface->epCount]; - temp = (void *)unionDes; - epParse->epDesc = (usb_descriptor_endpoint_t *)temp; + epParse = (usb_host_ep_t *)&interface->epList[interface->epCount]; + epParse->epDesc = (usb_descriptor_endpoint_t *)unionDes; 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) && @@ -810,7 +820,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter void USB_HostGetVersion(uint32_t *version) { - if (NULL != version) + if (version) { *version = (uint32_t)USB_MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX); @@ -818,12 +828,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 suspend request */ +/* Send BUS or specific device suepend 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) @@ -839,7 +849,6 @@ 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 @@ -848,12 +857,11 @@ 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 (0U == deviceInstance->hubNumber) + if (0 == deviceInstance->hubNumber) { #endif if (hostInstance->deviceList == deviceHandle) { - /* the callbackFn is initialized in USB_HostGetControllerInterface */ status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type); } @@ -880,7 +888,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) @@ -897,7 +905,6 @@ 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); } @@ -905,12 +912,11 @@ 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 (0U == deviceInstance->hubNumber) + if (0 == deviceInstance->hubNumber) { #endif if (hostInstance->deviceList == deviceHandle) { - /* the callbackFn is initialized in USB_HostGetControllerInterface */ status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type); } @@ -929,13 +935,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 suspend request */ +/* Send BUS or specific device suepend 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) @@ -949,9 +955,8 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle, if (1U == sleepType) { /*#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))*/ - /*To do, incomplete hub L1 suspend device*/ + /*To do, implete hub L1 suspend device*/ /*#else*/ - /* the callbackFn is initialized in USB_HostGetControllerInterface */ status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type); /*#endif*/ @@ -963,7 +968,6 @@ 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); } @@ -974,7 +978,7 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle, } return status; } -/* Send BUS or specific device suspend request */ +/* Send BUS or specific device suepend request */ usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam) { usb_host_instance_t *hostInstance; @@ -985,7 +989,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); @@ -999,7 +1003,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) @@ -1010,19 +1014,17 @@ 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); } @@ -1048,18 +1050,3 @@ 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 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 c1450dde38..26b6d4a9c5 100644 --- a/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h +++ b/bsp/imxrt/libraries/drivers/usb/host/usb_host_hci.h @@ -1,9 +1,31 @@ /* * Copyright (c) 2015, Freescale Semiconductor, Inc. - * Copyright 2016 - 2019 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ #ifndef _USB_HOST_HCI_H_ @@ -14,9 +36,9 @@ ******************************************************************************/ /*! @brief USB host lock */ -#define USB_HostLock() OSA_MutexLock(hostInstance->hostMutex, USB_OSA_WAIT_TIMEOUT) +#define USB_HostLock() USB_OsaMutexLock(hostInstance->hostMutex) /*! @brief USB host unlock */ -#define USB_HostUnlock() OSA_MutexUnlock(hostInstance->hostMutex) +#define USB_HostUnlock() USB_OsaMutexUnlock(hostInstance->hostMutex) /*! * @addtogroup usb_host_controller_driver @@ -34,10 +56,6 @@ 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 */ @@ -79,9 +97,7 @@ 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 + /*! @}*/ /*! @@ -94,8 +110,7 @@ typedef struct _usb_host_instance { void *controllerHandle; /*!< The low level controller handle*/ host_callback_t deviceCallback; /*!< Device attach/detach callback*/ - osa_mutex_handle_t hostMutex; /*!< Host layer mutex*/ - uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< Host layer mutex*/ + usb_osa_mutex_handle hostMutex; /*!< 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*/ @@ -111,7 +126,6 @@ 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_ */ diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb.h b/bsp/imxrt/libraries/drivers/usb/include/usb.h index a219f10cec..256896b472 100644 --- a/bsp/imxrt/libraries/drivers/usb/include/usb.h +++ b/bsp/imxrt/libraries/drivers/usb/include/usb.h @@ -34,7 +34,6 @@ #include #include #include -#include #include "usb_misc.h" #include "usb_spec.h" diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h b/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h deleted file mode 100644 index 8990136352..0000000000 --- a/bsp/imxrt/libraries/drivers/usb/include/usb_host_config.h +++ /dev/null @@ -1,247 +0,0 @@ -/* - * 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_ */ diff --git a/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h b/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h index df12d6cd1d..4e65cfa94b 100644 --- a/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h +++ b/bsp/imxrt/libraries/drivers/usb/include/usb_misc.h @@ -1,34 +1,46 @@ /* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. - * Copyright 2016, 2019 NXP - * All rights reserved. + * Copyright 2016 NXP * - * SPDX-License-Identifier: BSD-3-Clause + * 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. */ #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" { @@ -40,14 +52,10 @@ 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 rt_kprintf -#endif -#else -#define usb_echo +#define usb_echo DbgConsole_Printf #endif #if defined(__ICCARM__) @@ -70,7 +78,7 @@ extern int DbgConsole_Printf(const char *fmt_s, ...); #define STRUCT_UNPACKED __attribute__((__packed__)) #endif -#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION)) +#elif defined(__CC_ARM) #ifndef STRUCT_PACKED #define STRUCT_PACKED _Pragma("pack(1U)") @@ -104,7 +112,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); \ @@ -112,13 +120,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); \ @@ -126,7 +134,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); \ } @@ -142,66 +150,65 @@ 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] = (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_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_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_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_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_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_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_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_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \ - { \ - m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \ - m[0] = (((uint16_t)(n)) & 0xFFU); \ +#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \ + { \ + m[1] = ((n >> 8U) & 0xFFU); \ + m[0] = (n & 0xFFU); \ } -#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U))) +#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U))) -#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_TO_BIG_ENDIAN_ADDRESS(n, m) \ + { \ + m[0] = ((n >> 8U) & 0xFFU); \ + m[1] = (n & 0xFFU); \ } -#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U))) +#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U))) -#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_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_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_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_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_TO_LITTLE_ENDIAN_DATA(n, m) \ + { \ + *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \ + *((uint8_t *)&(m)) = ((n)&0xFFU); \ } -#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \ - ((uint16_t)((uint16_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n))))) +#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n)))))) #else @@ -215,76 +222,75 @@ 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] = (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_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_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_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_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_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_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_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_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \ - { \ - m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \ - m[0] = (((uint16_t)(n)) & 0xFFU); \ +#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \ + { \ + m[1] = ((n >> 8U) & 0xFFU); \ + m[0] = (n & 0xFFU); \ } -#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U))) +#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U))) -#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_TO_BIG_ENDIAN_ADDRESS(n, m) \ + { \ + m[0] = ((n >> 8U) & 0xFFU); \ + m[1] = (n & 0xFFU); \ } -#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U))) +#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U))) -#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_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_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_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_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_TO_LITTLE_ENDIAN_DATA(n, m) \ + { \ + *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \ + *((uint8_t *)&(m)) = ((n)&0xFFU); \ } -#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \ - ((uint16_t)(((uint16_t)(*(((uint8_t *)&(n)) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n)))))) +#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((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 - * 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 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 * 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 macro can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT. + * the marco 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. @@ -307,63 +313,40 @@ _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_DMA_INIT_DATA(sec) USB_LINK_SECTION_PART(location = #sec) +#define USB_LINK_SECTION_SUB(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 -#define USB_LINK_USB_BDT_BSS +#define USB_LINK_USB_GLOBAL_BSS _Pragma("location = \".bss.m_usb_global\"") +#define USB_LINK_USB_BDT_BSS _Pragma("location = \".bss.m_usb_bdt\"") _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) || (defined(__ARMCC_VERSION)) +#elif defined(__CC_ARM) #define USB_WEAK_VAR __attribute__((weak)) -#define USB_WEAK_FUN __attribute__((weak)) +#define USB_WEAK_FUN __weak #define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n))) -#define USB_LINK_DMA_INIT_DATA(sec) __attribute__((section(#sec))) -#if defined(__CC_ARM) +#define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec))) #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)) -#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_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)) #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_DMA_INIT_DATA(sec) __attribute__((section(#sec))) +#define USB_LINK_SECTION_SUB(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 -#define USB_LINK_USB_BDT_BSS +#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_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 @@ -373,32 +356,28 @@ _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 4U +#define USB_CACHE_LINESIZE 4 #endif #else -#define USB_CACHE_LINESIZE 4U +#define USB_CACHE_LINESIZE 4 #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 64U +#define USB_DATA_ALIGN 64 #else -#define USB_DATA_ALIGN 4U +#define USB_DATA_ALIGN 4 #endif -#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 MAX(USB_CACHE_LINESIZE, USB_DATA_ALIGN) -#define USB_DATA_ALIGN_SIZE_MULTIPLE(n) (((n) + USB_DATA_ALIGN_SIZE - 1U) & (~(USB_DATA_ALIGN_SIZE - 1U))) +#define USB_DATA_ALIGN_SIZE_MULTIPLE(n) ((n + USB_DATA_ALIGN_SIZE - 1) & (~(USB_DATA_ALIGN_SIZE - 1))) #if defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL) @@ -408,19 +387,13 @@ _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_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_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data) #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) @@ -430,13 +403,7 @@ _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_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_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data) #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA #else #define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS @@ -444,7 +411,6 @@ _Pragma("diag_suppress=Pm120") #define USB_DMA_DATA_INIT_SUB #define USB_CONTROLLER_DATA #endif -#endif #else @@ -454,17 +420,9 @@ _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_DMA_INIT_DATA(m_usb_dma_init_data) +#define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(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 @@ -475,8 +433,6 @@ _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 diff --git a/bsp/nuvoton/libraries/m480/rtt_port/drv_usbhost.c b/bsp/nuvoton/libraries/m480/rtt_port/drv_usbhost.c index 92375cda19..be19dac9e5 100644 --- a/bsp/nuvoton/libraries/m480/rtt_port/drv_usbhost.c +++ b/bsp/nuvoton/libraries/m480/rtt_port/drv_usbhost.c @@ -844,7 +844,7 @@ int nu_usbh_register(void) RT_ASSERT(res == RT_EOK); /*initialize the usb host function */ - res = rt_usb_host_init("usbh"); + res = rt_usb_host_init(); RT_ASSERT(res == RT_EOK); #if defined(RT_USING_PM) diff --git a/bsp/rx/applications/application.c b/bsp/rx/applications/application.c index 9ea0023015..4a6e250429 100644 --- a/bsp/rx/applications/application.c +++ b/bsp/rx/applications/application.c @@ -130,7 +130,7 @@ void rt_init_thread_entry(void* parameter) #endif #ifdef RT_USING_USB_HOST - rt_usb_host_init("usbh"); + rt_usb_host_init(); #endif #ifdef RT_USING_FINSH diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usbh.c b/bsp/stm32/libraries/HAL_Drivers/drv_usbh.c index 47b24fb950..680a93e722 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usbh.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usbh.c @@ -241,7 +241,7 @@ int stm_usbh_register(void) return -RT_ERROR; } - rt_usb_host_init("usbh"); + rt_usb_host_init(); return RT_EOK; } diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index b0caabc73c..006497519f 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -642,14 +642,6 @@ menu "Using USB" string "Udisk mount dir" default "/" endif - config RT_USBH_HID - bool "Enable HID Drivers" - default n - if RT_USBH_HID - config RT_USBH_HID_MOUSE - bool "Enable HID mouse protocol" - default n - endif endif config RT_USING_USB_DEVICE bool "Using USB device" diff --git a/components/drivers/include/drivers/usb_host.h b/components/drivers/include/drivers/usb_host.h index bd73c7d1d7..2a68f4edb5 100644 --- a/components/drivers/include/drivers/usb_host.h +++ b/components/drivers/include/drivers/usb_host.h @@ -136,8 +136,7 @@ struct uhcd struct rt_device parent; uhcd_ops_t ops; rt_uint8_t num_ports; - uhub_t roothub; - struct rt_messagequeue *usb_mq; + uhub_t roothub; }; typedef struct uhcd* uhcd_t; @@ -164,7 +163,7 @@ struct uhost_msg typedef struct uhost_msg* uhost_msg_t; /* usb host system interface */ -rt_err_t rt_usb_host_init(const char *name); +rt_err_t rt_usb_host_init(void); void rt_usbh_hub_init(struct uhcd *hcd); /* usb host core interface */ @@ -204,7 +203,7 @@ rt_err_t rt_usbh_hub_clear_port_feature(uhub_t uhub, rt_uint16_t port, rt_err_t rt_usbh_hub_set_port_feature(uhub_t uhub, rt_uint16_t port, rt_uint16_t feature); rt_err_t rt_usbh_hub_reset_port(uhub_t uhub, rt_uint16_t port); -rt_err_t rt_usbh_event_signal(uhcd_t uhcd, struct uhost_msg* msg); +rt_err_t rt_usbh_event_signal(struct uhost_msg* msg); void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool_t isHS); diff --git a/components/drivers/pm/debug.log b/components/drivers/pm/debug.log deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/components/drivers/usb/usbhost/class/hid.c b/components/drivers/usb/usbhost/class/hid.c index 1abc82184f..e16096877f 100644 --- a/components/drivers/usb/usbhost/class/hid.c +++ b/components/drivers/usb/usbhost/class/hid.c @@ -26,7 +26,7 @@ static rt_list_t _protocal_list; * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id) +rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id) { struct urequest setup; struct uinstance* device; @@ -40,15 +40,14 @@ rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id) setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.bRequest = USB_REQ_SET_IDLE; - setup.wIndex = 0; - setup.wLength = 0; - setup.wValue = (duration << 8 )| report_id; + setup.request = USB_REQ_SET_IDLE; + setup.index = 0; + setup.length = 0; + setup.value = (duration << 8 )| report_id; - if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) - return RT_EOK; - else - return -RT_FALSE; + if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0, + timeout) == 0) return RT_EOK; + else return -RT_FALSE; } /** @@ -60,7 +59,7 @@ rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, +rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; @@ -75,24 +74,14 @@ rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.bRequest = USB_REQ_GET_REPORT; - setup.wIndex = intf->intf_desc->bInterfaceNumber; - setup.wLength = size; - setup.wValue = (type << 8 ) + id; + setup.request = USB_REQ_GET_REPORT; + setup.index = intf->intf_desc->bInterfaceNumber; + setup.length = size; + setup.value = (type << 8 ) + id; - if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) - { - if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size) - { - if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0) - { - return RT_EOK; - } - } - } - else - return -RT_FALSE; - return -RT_FALSE; + if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, + timeout) == size) return RT_EOK; + else return -RT_FALSE; } /** @@ -104,7 +93,7 @@ rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size) +rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; struct uinstance* device; @@ -118,15 +107,14 @@ rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.bRequest = USB_REQ_SET_REPORT; - setup.wIndex = intf->intf_desc->bInterfaceNumber; - setup.wLength = size; - setup.wValue = 0x02 << 8; + setup.request = USB_REQ_SET_REPORT; + setup.index = intf->intf_desc->bInterfaceNumber; + setup.length = size; + setup.value = 0x02 << 8; - if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) - return RT_EOK; - else - return -RT_FALSE; + if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, + timeout) == size) return RT_EOK; + else return -RT_FALSE; } /** @@ -137,7 +125,7 @@ rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol) +rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol) { struct urequest setup; struct uinstance* device; @@ -151,15 +139,14 @@ rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol) setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.bRequest = USB_REQ_SET_PROTOCOL; - setup.wIndex = 0; - setup.wLength = 0; - setup.wValue = protocol; + setup.request = USB_REQ_SET_PROTOCOL; + setup.index = 0; + setup.length = 0; + setup.value = protocol; - if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) - return RT_EOK; - else - return -RT_FALSE; + if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0, + timeout) == 0) return RT_EOK; + else return -RT_FALSE; } /** @@ -172,7 +159,7 @@ rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, +rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; @@ -187,24 +174,14 @@ rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_STANDARD| USB_REQ_TYPE_INTERFACE; - setup.bRequest = USB_REQ_GET_DESCRIPTOR; - setup.wIndex = 0; - setup.wLength = size; - setup.wValue = USB_DESC_TYPE_REPORT << 8; + setup.request = USB_REQ_GET_DESCRIPTOR; + setup.index = 0; + setup.length = size; + setup.value = USB_DESC_TYPE_REPORT << 8; - if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) - { - if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size) - { - if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0) - { - return RT_EOK; - } - } - } - else - return -RT_FALSE; - return -RT_FALSE; + if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, + timeout) == size) return RT_EOK; + else return -RT_FALSE; } /** @@ -243,16 +220,16 @@ static void rt_usbh_hid_callback(void* context) RT_ASSERT(context != RT_NULL); pipe = (upipe_t)context; - hid = (struct uhid*)((struct uhintf*)pipe->inst)->user_data; + hid = (struct uhid*)pipe->intf->user_data; /* invoke protocal callback function */ hid->protocal->callback((void*)hid); /* parameter check */ - RT_ASSERT(((struct uhintf*)pipe->inst)->device->hcd != RT_NULL); + RT_ASSERT(pipe->intf->device->hcd != RT_NULL); - rt_usb_hcd_pipe_xfer(((struct uhintf*)pipe->inst)->device->hcd, pipe, - hid->buffer, pipe->ep.wMaxPacketSize, timeout); + rt_usb_hcd_int_xfer(pipe->intf->device->hcd, pipe, hid->buffer, + pipe->ep.wMaxPacketSize, timeout); } /** @@ -291,7 +268,9 @@ static rt_err_t rt_usbh_hid_enable(void* arg) int i = 0, pro_id; uprotocal_t protocal; struct uhid* hid; - struct uhintf* intf = (struct uhintf*)arg; + struct uintf* intf = (struct uintf*)arg; + int timeout = USB_TIMEOUT_BASIC; + upipe_t pipe; /* parameter check */ if(intf == RT_NULL) @@ -340,13 +319,19 @@ static rt_err_t rt_usbh_hid_enable(void* arg) if(!(ep_desc->bEndpointAddress & USB_DIR_IN)) continue; ret = rt_usb_hcd_alloc_pipe(intf->device->hcd, &hid->pipe_in, - intf, ep_desc); + intf, ep_desc, rt_usbh_hid_callback); if(ret != RT_EOK) return ret; } /* initialize hid protocal */ - hid->protocal->init((void*)intf); + hid->protocal->init((void*)intf); + pipe = hid->pipe_in; + /* parameter check */ + RT_ASSERT(pipe->intf->device->hcd != RT_NULL); + + rt_usb_hcd_int_xfer(pipe->intf->device->hcd, hid->pipe_in, + hid->buffer, hid->pipe_in->ep.wMaxPacketSize, timeout); return RT_EOK; } @@ -361,7 +346,7 @@ static rt_err_t rt_usbh_hid_enable(void* arg) static rt_err_t rt_usbh_hid_disable(void* arg) { struct uhid* hid; - struct uhintf* intf = (struct uhintf*)arg; + struct uintf* intf = (struct uintf*)arg; RT_ASSERT(intf != RT_NULL); @@ -379,6 +364,9 @@ static rt_err_t rt_usbh_hid_disable(void* arg) /* free the hid instance */ rt_free(hid); } + + /* free the instance */ + rt_free(intf); return RT_EOK; } diff --git a/components/drivers/usb/usbhost/class/hid.h b/components/drivers/usb/usbhost/class/hid.h index 04c67aa42b..8e446c8cea 100644 --- a/components/drivers/usb/usbhost/class/hid.h +++ b/components/drivers/usb/usbhost/class/hid.h @@ -31,11 +31,11 @@ typedef struct uhid uhid_t; #define USB_HID_KEYBOARD 1 #define USB_HID_MOUSE 2 -rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id); -rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size); -rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size); -rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol); -rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id); +rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol); +rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size); rt_err_t rt_usbh_hid_protocal_register(uprotocal_t protocal); #endif diff --git a/components/drivers/usb/usbhost/class/umouse.c b/components/drivers/usb/usbhost/class/umouse.c index 7f50c0451f..e769475a98 100644 --- a/components/drivers/usb/usbhost/class/umouse.c +++ b/components/drivers/usb/usbhost/class/umouse.c @@ -126,36 +126,15 @@ static rt_err_t rt_usbh_hid_mouse_callback(void* arg) return RT_EOK; } -rt_thread_t mouse_thread; -void mouse_task(void* param) -{ - struct uhintf* intf = (struct uhintf*)param; - while (1) - { - if (rt_usb_hcd_pipe_xfer(intf->device->hcd, ((struct uhid*)intf->user_data)->pipe_in, - ((struct uhid*)intf->user_data)->buffer, ((struct uhid*)intf->user_data)->pipe_in->ep.wMaxPacketSize, - USB_TIMEOUT_BASIC) == 0) - { - break; - } - - rt_usbh_hid_mouse_callback(intf->user_data); - } -} - - static rt_err_t rt_usbh_hid_mouse_init(void* arg) { - struct uhintf* intf = (struct uhintf*)arg; + struct uintf* intf = (struct uintf*)arg; RT_ASSERT(intf != RT_NULL); rt_usbh_hid_set_protocal(intf, 0); - rt_usbh_hid_set_idle(intf, 0, 0); - - mouse_thread = rt_thread_create("mouse0", mouse_task, intf, 500, 8, 100); - rt_thread_startup(mouse_thread); + rt_usbh_hid_set_idle(intf, 10, 0); RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb mouse\n")); #ifdef RT_USING_RTGUI diff --git a/components/drivers/usb/usbhost/core/driver.c b/components/drivers/usb/usbhost/core/driver.c index 871a7b578a..37327108c1 100644 --- a/components/drivers/usb/usbhost/core/driver.c +++ b/components/drivers/usb/usbhost/core/driver.c @@ -13,7 +13,6 @@ #include static rt_list_t _driver_list; -static rt_bool_t _driver_list_created = RT_FALSE; /** * This function will initilize the usb class driver related data structure, @@ -23,11 +22,8 @@ static rt_bool_t _driver_list_created = RT_FALSE; */ rt_err_t rt_usbh_class_driver_init(void) { - if (_driver_list_created == RT_FALSE) - { - rt_list_init(&_driver_list); - _driver_list_created = RT_TRUE; - } + rt_list_init(&_driver_list); + return RT_EOK; } @@ -43,11 +39,8 @@ rt_err_t rt_usbh_class_driver_register(ucd_t drv) { if (drv == RT_NULL) return -RT_ERROR; - if (rt_usbh_class_driver_find(drv->class_code, drv->subclass_code) == RT_NULL) - { - /* insert class driver into driver list */ - rt_list_insert_after(&_driver_list, &(drv->list)); - } + /* insert class driver into driver list */ + rt_list_insert_after(&_driver_list, &(drv->list)); return RT_EOK; } diff --git a/components/drivers/usb/usbhost/core/hub.c b/components/drivers/usb/usbhost/core/hub.c index c0e025ba7e..eefa571472 100644 --- a/components/drivers/usb/usbhost/core/hub.c +++ b/components/drivers/usb/usbhost/core/hub.c @@ -13,9 +13,9 @@ #define USB_THREAD_STACK_SIZE 4096 -// static struct rt_messagequeue *usb_mq; +static struct rt_messagequeue *usb_mq; static struct uclass_driver hub_driver; -// static struct uhub root_hub; +static struct uhub root_hub; static rt_err_t root_hub_ctrl(struct uhcd *hcd, rt_uint16_t port, rt_uint8_t cmd, void *args) { @@ -92,7 +92,7 @@ void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool { hcd->roothub->port_status[port - 1] |= PORT_LSDA; } - rt_usbh_event_signal(hcd, &msg); + rt_usbh_event_signal(&msg); } void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port) @@ -102,7 +102,7 @@ void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port) msg.content.hub = hcd->roothub; hcd->roothub->port_status[port - 1] |= PORT_CCSC; hcd->roothub->port_status[port - 1] &= ~PORT_CCS; - rt_usbh_event_signal(hcd, &msg); + rt_usbh_event_signal(&msg); } /** @@ -647,13 +647,12 @@ ucd_t rt_usbh_class_driver_hub(void) */ static void rt_usbh_hub_thread_entry(void* parameter) { - uhcd_t hcd = (uhcd_t)parameter; while(1) { struct uhost_msg msg; /* receive message */ - if(rt_mq_recv(hcd->usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER) + if(rt_mq_recv(usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER) != RT_EOK ) continue; //RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type)); @@ -680,12 +679,12 @@ static void rt_usbh_hub_thread_entry(void* parameter) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_event_signal(uhcd_t hcd, struct uhost_msg* msg) +rt_err_t rt_usbh_event_signal(struct uhost_msg* msg) { RT_ASSERT(msg != RT_NULL); /* send message to usb message queue */ - rt_mq_send(hcd->usb_mq, (void*)msg, sizeof(struct uhost_msg)); + rt_mq_send(usb_mq, (void*)msg, sizeof(struct uhost_msg)); return RT_EOK; } @@ -699,17 +698,16 @@ rt_err_t rt_usbh_event_signal(uhcd_t hcd, struct uhost_msg* msg) void rt_usbh_hub_init(uhcd_t hcd) { rt_thread_t thread; - /* create root hub for hcd */ - hcd->roothub = rt_malloc(sizeof(struct uhub)); - rt_memset(hcd->roothub, 0, sizeof(struct uhub)); - hcd->roothub->is_roothub = RT_TRUE; - hcd->roothub->hcd = hcd; - hcd->roothub->num_ports = hcd->num_ports; + /* link root hub to hcd */ + root_hub.is_roothub = RT_TRUE; + hcd->roothub = &root_hub; + root_hub.hcd = hcd; + root_hub.num_ports = hcd->num_ports; /* create usb message queue */ - hcd->usb_mq = rt_mq_create(hcd->parent.parent.name, 32, 16, RT_IPC_FLAG_FIFO); + usb_mq = rt_mq_create("usbh", 32, 16, RT_IPC_FLAG_FIFO); /* create usb hub thread */ - thread = rt_thread_create(hcd->parent.parent.name, rt_usbh_hub_thread_entry, hcd, + thread = rt_thread_create("usbh", rt_usbh_hub_thread_entry, RT_NULL, USB_THREAD_STACK_SIZE, 8, 20); if(thread != RT_NULL) { diff --git a/components/drivers/usb/usbhost/core/usbhost.c b/components/drivers/usb/usbhost/core/usbhost.c index b9e6a7a4b1..f0294238c4 100644 --- a/components/drivers/usb/usbhost/core/usbhost.c +++ b/components/drivers/usb/usbhost/core/usbhost.c @@ -22,15 +22,15 @@ * * @return none. */ -rt_err_t rt_usb_host_init(const char *name) +rt_err_t rt_usb_host_init(void) { ucd_t drv; rt_device_t uhc; - uhc = rt_device_find(name); + uhc = rt_device_find(USB_HOST_CONTROLLER_NAME); if(uhc == RT_NULL) { - rt_kprintf("can't find usb host controller %s\n", name); + rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME); return -RT_ERROR; } @@ -44,16 +44,6 @@ rt_err_t rt_usb_host_init(const char *name) /* register mass storage class driver */ drv = rt_usbh_class_driver_storage(); rt_usbh_class_driver_register(drv); -#endif -#ifdef RT_USBH_HID - /* register mass storage class driver */ - drv = rt_usbh_class_driver_hid(); - rt_usbh_class_driver_register(drv); -#ifdef RT_USBH_HID_MOUSE - uprotocal_t protocal; - protocal = rt_usbh_hid_protocal_mouse(); - rt_usbh_hid_protocal_register(protocal); -#endif #endif /* register hub class driver */