新增4轮4转-补丁代码

This commit is contained in:
2026-01-09 16:48:24 +08:00
parent 43d95adee5
commit 0442bff0c6
10522 changed files with 4465174 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* This file is provided as an example on how to use Micrium products.
*
* Please feel free to use any application code labeled as 'EXAMPLE CODE' in
* your application products. Example code may be used as is, in whole or in
* part, or may be used as a reference only. This file can be modified as
* required to meet the end-product requirements.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO DEVICE CONFIGURATION FILE
*
* Filename : usbd_audio_drv_uda1380_codec.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This USB device configuration header file is protected from multiple pre-processor
* inclusion through use of the USB device configuration module present pre-processor
* macro definition.
*********************************************************************************************************
*/
#ifndef USBD_AUDIO_DRV_TEMPLATE_MODULE_PRESENT /* See Note #1. */
#define USBD_AUDIO_DRV_TEMPLATE_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../usbd_audio_processing.h"
/*
*********************************************************************************************************
* USB AUDIO FUNCTION TOPOLOGY 1 CONFIGURATION
*********************************************************************************************************
*/
extern const USBD_AUDIO_DRV_COMMON_API USBD_Audio_DrvCommonAPI_UDA1380_Codec;
extern const USBD_AUDIO_DRV_AC_FU_API USBD_Audio_DrvFU_API_UDA1380_Codec;
extern const USBD_AUDIO_DRV_AS_API USBD_Audio_DrvAS_API_UDA1380_Codec;
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,68 @@
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* This file is provided as an example on how to use Micrium products.
*
* Please feel free to use any application code labeled as 'EXAMPLE CODE' in
* your application products. Example code may be used as is, in whole or in
* part, or may be used as a reference only. This file can be modified as
* required to meet the end-product requirements.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO CODEC DRIVER TEMPLATE
*
* Filename : usbd_audio_drv_template.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This USB device configuration header file is protected from multiple pre-processor
* inclusion through use of the USB device configuration module present pre-processor
* macro definition.
*********************************************************************************************************
*/
#ifndef USBD_AUDIO_DRV_TEMPLATE_MODULE_PRESENT /* See Note #1. */
#define USBD_AUDIO_DRV_TEMPLATE_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../usbd_audio_processing.h"
/*
*********************************************************************************************************
* USB AUDIO FUNCTION TOPOLOGY 1 CONFIGURATION
*********************************************************************************************************
*/
extern const USBD_AUDIO_DRV_COMMON_API USBD_Audio_DrvCommonAPI_Template;
extern const USBD_AUDIO_DRV_AC_OT_API USBD_Audio_DrvOT_API_Template;
extern const USBD_AUDIO_DRV_AC_FU_API USBD_Audio_DrvFU_API_Template;
extern const USBD_AUDIO_DRV_AC_MU_API USBD_Audio_DrvMU_API_Template;
extern const USBD_AUDIO_DRV_AC_SU_API USBD_Audio_DrvSU_API_Template;
extern const USBD_AUDIO_DRV_AS_API USBD_Audio_DrvAS_API_Template;
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,651 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO DEVICE OPERATING SYSTEM LAYER
* FreeRTOS
*
* Filename : usbd_audio_os.c
* Version : V1.01.01
*********************************************************************************************************
*/
#include "../../usbd_audio_internal.h"
#include "../../usbd_audio_os.h"
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <semphr.h>
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE
#define USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE (1024u)
#endif
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO
#define USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO (configMAX_PRIORITIES - 6)
#endif
#endif
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE
#define USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE (1024u)
#endif
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO
#define USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO (configMAX_PRIORITIES - 6)
#endif
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static QueueHandle_t USBD_Audio_OS_RecordMsgQPtr; /* Ptr to record msg Q. */
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static QueueHandle_t USBD_Audio_OS_PlaybackMsgQPtr; /* Ptr to playback msg Q. */
#endif
static SemaphoreHandle_t USBD_Audio_OS_AS_IF_MutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_EP];
static SemaphoreHandle_t USBD_Audio_OS_RingBufQMutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_SETTINGS];
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask(void *p_arg);
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_Init()
*
* Description : Initialize the audio class OS layer.
*
* Argument(s) : msg_qty Maximum quantity of messages for playback and record tasks' queues.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE OS layer initialization successful.
* USBD_ERR_OS_INIT_FAIL OS layer initialization failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_Init (CPU_INT16U msg_qty,
USBD_ERR *p_err)
{
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
BaseType_t ret;
#else
(void)msg_qty;
#endif
/* ---------------- CREATE REQUIRED QS ---------------- */
/* Create msg Q handle. */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
USBD_Audio_OS_RecordMsgQPtr = xQueueCreate(msg_qty, sizeof(void *));
if (!USBD_Audio_OS_RecordMsgQPtr) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
#endif
/* Create playback msg Q handle. */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
USBD_Audio_OS_PlaybackMsgQPtr = xQueueCreate(msg_qty, sizeof(void *));
if (!USBD_Audio_OS_PlaybackMsgQPtr) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
#endif
/* -------------------- RECORD TASK ------------------- */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
ret = xTaskCreate( USBD_Audio_OS_RecordTask,
"USBD Audio Record Task",
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE,
NULL,
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
NULL);
if (ret != pdPASS) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#endif
/* ------------------- PLAYBACK TASK ------------------ */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
ret = xTaskCreate( USBD_Audio_OS_PlaybackTask,
"USBD Audio Playback Task",
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE,
NULL,
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
NULL);
if (ret != pdPASS) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#endif
*p_err = USBD_ERR_NONE;
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockCreate()
*
* Description : Create an OS resource to use as an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockCreate (CPU_INT08U as_if_nbr,
USBD_ERR *p_err)
{
USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr] = xSemaphoreCreateMutex();
if (!USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
} else {
*p_err = USBD_ERR_NONE;
}
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockAcquire()
*
* Description : Wait for an AudioStreaming interface to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockAcquire (CPU_INT08U as_if_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
BaseType_t ret;
TickType_t xTicksToWait;
xTicksToWait = timeout_ms ? timeout_ms : portMAX_DELAY;
ret = xSemaphoreTake(USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr], xTicksToWait);
if (ret == pdTRUE) {
*p_err = USBD_ERR_NONE;
} else {
*p_err = USBD_ERR_OS_TIMEOUT;
}
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockRelease()
*
* Description : Release an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockRelease (CPU_INT08U as_if_nbr)
{
xSemaphoreGive(USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr]);
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockCreate()
*
* Description : Create an OS resource to use as a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockCreate (CPU_INT08U as_if_settings_ix,
USBD_ERR *p_err)
{
USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix] = xSemaphoreCreateMutex();
if (!USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
} else {
*p_err = USBD_ERR_NONE;
}
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockAcquire()
*
* Description : Wait for a stream ring buffer queue to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockAcquire (CPU_INT08U as_if_settings_ix,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
BaseType_t ret;
TickType_t xTicksToWait;
xTicksToWait = timeout_ms ? timeout_ms : portMAX_DELAY;
ret = xSemaphoreTake(USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix], xTicksToWait);
if (ret == pdTRUE) {
*p_err = USBD_ERR_NONE;
} else {
*p_err = USBD_ERR_OS_TIMEOUT;
}
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockRelease()
*
* Description : Release a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockRelease (CPU_INT08U as_if_settings_ix)
{
xSemaphoreGive(USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix]);
return;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPost()
*
* Description : Post a request into the record task's queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the Record buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_OS_RecordReqPost (void *p_msg,
USBD_ERR *p_err)
{
BaseType_t ret;
BaseType_t woken;
void *msg_buf;
msg_buf = p_msg;
if (arch_in_irq_mode()) {
woken = pdFALSE;
ret = xQueueSendFromISR(USBD_Audio_OS_RecordMsgQPtr, &msg_buf, &woken);
if (woken) {
portYIELD_FROM_ISR(woken);
}
} else {
ret = xQueueSend(USBD_Audio_OS_RecordMsgQPtr, &msg_buf, portMAX_DELAY);
}
*p_err = (ret == pdTRUE) ? USBD_ERR_NONE : USBD_ERR_OS_FAIL;
return;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPend()
*
* Description : Pend on a request from the record task's queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the record buffer queue.
*
* Return(s) : Pointer to record request, if NO error(s).
*
* Null pointer, otherwise
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void *USBD_Audio_OS_RecordReqPend (USBD_ERR *p_err)
{
BaseType_t ret;
void *p_msg = NULL;
ret = xQueueReceive(USBD_Audio_OS_RecordMsgQPtr, &p_msg, portMAX_DELAY);
*p_err = (ret == pdTRUE) ? USBD_ERR_NONE : USBD_ERR_OS_TIMEOUT;
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPost()
*
* Description : Post a request to the playback's task queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the playback buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_OS_PlaybackReqPost (void *p_msg,
USBD_ERR *p_err)
{
BaseType_t ret;
BaseType_t woken;
void *msg_buf;
msg_buf = p_msg;
if (arch_in_irq_mode()) {
woken = pdFALSE;
ret = xQueueSendFromISR(USBD_Audio_OS_PlaybackMsgQPtr, &msg_buf, &woken);
if (woken) {
portYIELD_FROM_ISR(woken);
}
} else {
ret = xQueueSend(USBD_Audio_OS_PlaybackMsgQPtr, &msg_buf, portMAX_DELAY);
}
*p_err = (ret == pdTRUE) ? USBD_ERR_NONE : USBD_ERR_OS_FAIL;
return;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPend()
*
* Description : Pend on a request from the playback's task queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the playback buffer queue.
*
* Return(s) : Pointer to playback request, if NO error(s).
*
* Null pointer, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void *USBD_Audio_OS_PlaybackReqPend (USBD_ERR *p_err)
{
BaseType_t ret;
void *p_msg = NULL;
ret = xQueueReceive(USBD_Audio_OS_PlaybackMsgQPtr, &p_msg, portMAX_DELAY);
*p_err = (ret == pdTRUE) ? USBD_ERR_NONE : USBD_ERR_OS_TIMEOUT;
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_DlyMs()
*
* Description : Delay a task for a certain time.
*
* Argument(s) : ms Delay in milliseconds.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_DlyMs (CPU_INT32U ms)
{
vTaskDelay(ms);
return;
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordTask()
*
* Description : OS-dependent shell task to process record data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_RecordTaskHandler();
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackTask()
*
* Description : OS-dependent shell task to process playback data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_PlaybackTaskHandler();
}
#endif

View File

@@ -0,0 +1,500 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO DEVICE OPERATING SYSTEM LAYER
* Template
*
* Filename : usbd_audio_os.c
* Version : V4.06.01
*********************************************************************************************************
*/
#include "../../usbd_audio_internal.h"
#include "../../usbd_audio_os.h"
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask(void *p_arg);
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_Init()
*
* Description : Initialize the audio class OS layer.
*
* Argument(s) : msg_qty Maximum quantity of messages for playback and record tasks' queues.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE OS layer initialization successful.
* USBD_ERR_OS_INIT_FAIL OS layer initialization failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_Init (CPU_INT16U msg_qty,
USBD_ERR *p_err)
{
(void)msg_qty;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockCreate()
*
* Description : Create an OS resource to use as an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockCreate (CPU_INT08U as_if_nbr,
USBD_ERR *p_err)
{
(void)as_if_nbr;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockAcquire()
*
* Description : Wait for an AudioStreaming interface to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockAcquire (CPU_INT08U as_if_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
(void)as_if_nbr;
(void)timeout_ms;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockRelease()
*
* Description : Release an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockRelease (CPU_INT08U as_if_nbr)
{
(void)as_if_nbr;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockCreate()
*
* Description : Create an OS resource to use as a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockCreate (CPU_INT08U as_if_settings_ix,
USBD_ERR *p_err)
{
(void)as_if_settings_ix;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockAcquire()
*
* Description : Wait for a stream ring buffer queue to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockAcquire (CPU_INT08U as_if_settings_ix,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
(void)as_if_settings_ix;
(void)timeout_ms;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockRelease()
*
* Description : Release a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockRelease (CPU_INT08U as_if_settings_ix)
{
(void)as_if_settings_ix;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPost()
*
* Description : Post a request into the record task's queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the Record buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_OS_RecordReqPost (void *p_msg,
USBD_ERR *p_err)
{
(void)p_msg;
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPend()
*
* Description : Pend on a request from the record task's queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the record buffer queue.
*
* Return(s) : Pointer to record request, if NO error(s).
*
* Null pointer, otherwise
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void *USBD_Audio_OS_RecordReqPend (USBD_ERR *p_err)
{
*p_err = USBD_ERR_NONE;
return ((void *)0);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPost()
*
* Description : Post a request to the playback's task queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the playback buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_OS_PlaybackReqPost (void *p_msg,
USBD_ERR *p_err)
{
(void)p_msg;
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPend()
*
* Description : Pend on a request from the playback's task queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the playback buffer queue.
*
* Return(s) : Pointer to playback request, if NO error(s).
*
* Null pointer, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void *USBD_Audio_OS_PlaybackReqPend (USBD_ERR *p_err)
{
*p_err = USBD_ERR_NONE;
return ((void *)0);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_DlyMs()
*
* Description : Delay a task for a certain time.
*
* Argument(s) : ms Delay in milliseconds.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_DlyMs (CPU_INT32U ms)
{
(void)ms;
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordTask()
*
* Description : OS-dependent shell task to process record data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_RecordTaskHandler();
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackTask()
*
* Description : OS-dependent shell task to process playback data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_PlaybackTaskHandler();
}
#endif

View File

@@ -0,0 +1,843 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO DEVICE OPERATING SYSTEM LAYER
* Micrium uC/OS-II
*
* Filename : usbd_audio_os.c
* Version : V4.06.01
*********************************************************************************************************
*/
#include <app_cfg.h>
#include "../../usbd_audio_internal.h"
#include "../../usbd_audio_os.h"
#include <Source/ucos_ii.h>
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE
#error "USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO
#error "USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#endif
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE
#error "USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO
#error "USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static OS_STK USBD_Audio_OS_RecordTaskStk[USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE];
static OS_EVENT *USBD_Audio_OS_RecordMsgQPtr; /* Ptr to record msg Q. */
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static OS_STK USBD_Audio_OS_PlaybackTaskStk[USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE];
static OS_EVENT *USBD_Audio_OS_PlaybackMsgQPtr; /* Ptr to playback msg Q. */
#endif
static OS_EVENT *USBD_Audio_OS_AS_IF_MutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_EP];
static OS_EVENT *USBD_Audio_OS_RingBufQMutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_SETTINGS];
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask(void *p_arg);
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_Init()
*
* Description : Initialize the audio class OS layer.
*
* Argument(s) : msg_qty Maximum quantity of messages for playback and record tasks' queues.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE OS layer initialization successful.
* USBD_ERR_OS_INIT_FAIL OS layer initialization failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_Init (CPU_INT16U msg_qty,
USBD_ERR *p_err)
{
INT8U os_err;
void *p_record_msg_q_storage;
void *p_playback_msg_q_storage;
LIB_ERR err_lib;
/* ---------------- CREATE REQUIRED QS ---------------- */
/* Alloc storage space for record msg Q. */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
p_record_msg_q_storage = Mem_HeapAlloc( (msg_qty * sizeof(void *)),
sizeof(CPU_ALIGN),
(CPU_SIZE_T *)0,
&err_lib);
if (err_lib != LIB_MEM_ERR_NONE) {
*p_err = USBD_ERR_ALLOC;
return;
}
#endif
/* Alloc storage space for playback msg Q. */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
p_playback_msg_q_storage = Mem_HeapAlloc( (msg_qty * sizeof(void *)),
sizeof(CPU_ALIGN),
(CPU_SIZE_T *)0,
&err_lib);
if (err_lib != LIB_MEM_ERR_NONE) {
*p_err = USBD_ERR_ALLOC;
return;
}
#endif
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
USBD_Audio_OS_RecordMsgQPtr = OSQCreate(p_record_msg_q_storage,
msg_qty);
if (USBD_Audio_OS_RecordMsgQPtr == (OS_EVENT *)0) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
USBD_Audio_OS_PlaybackMsgQPtr = OSQCreate(p_playback_msg_q_storage,
msg_qty);
if (USBD_Audio_OS_PlaybackMsgQPtr == (OS_EVENT *)0) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
#endif
/* ------------------- RECORD TASK -------------------- */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
#if (OS_TASK_CREATE_EXT_EN == 1u)
#if (OS_STK_GROWTH == 1u)
os_err = OSTaskCreateExt(USBD_Audio_OS_RecordTask,
DEF_NULL,
&USBD_Audio_OS_RecordTaskStk[USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
&USBD_Audio_OS_RecordTaskStk[0u],
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE,
DEF_NULL,
OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK);
#else
os_err = OSTaskCreateExt(USBD_Audio_OS_RecordTask,
DEF_NULL,
&USBD_Audio_OS_RecordTaskStk[0u],
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
&USBD_Audio_OS_RecordTaskStk[USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE,
DEF_NULL,
OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK);
#endif
#else
#if (OS_STK_GROWTH == 1u)
os_err = OSTaskCreate(USBD_Audio_OS_RecordTask,
DEF_NULL,
&USBD_Audio_OS_RecordTaskStk[USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO);
#else
os_err = OSTaskCreate(USBD_Audio_OS_RecordTask,
DEF_NULL,
&USBD_Audio_OS_RecordTaskStk[0u],
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO);
#endif
#endif
if (os_err != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#if (OS_TASK_STAT_EN > 0)
OSTaskNameSet(USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO, (INT8U *)"USBD Audio Record Task", &os_err);
#endif
#endif
/* ------------------ PLAYBACK TASK ------------------- */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
#if (OS_TASK_CREATE_EXT_EN == 1u)
#if (OS_STK_GROWTH == 1u)
os_err = OSTaskCreateExt(USBD_Audio_OS_PlaybackTask,
DEF_NULL,
&USBD_Audio_OS_PlaybackTaskStk[USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
&USBD_Audio_OS_PlaybackTaskStk[0u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE,
DEF_NULL,
OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK);
#else
os_err = OSTaskCreateExt(USBD_Audio_OS_PlaybackTask,
DEF_NULL,
&USBD_Audio_OS_PlaybackTaskStk[0u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
&USBD_Audio_OS_PlaybackTaskStk[USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE,
DEF_NULL,
(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#endif
#else
#if (OS_STK_GROWTH == 1u)
os_err = OSTaskCreate(USBD_Audio_OS_PlaybackTask,
DEF_NULL,
&USBD_Audio_OS_PlaybackTaskStk[USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE - 1u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO);
#else
os_err = OSTaskCreate(USBD_Audio_OS_PlaybackTask,
DEF_NULL,
&USBD_Audio_OS_PlaybackTaskStk[0u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO);
#endif
#endif
if (os_err != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#if (OS_TASK_STAT_EN > 0)
OSTaskNameSet(USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO, (INT8U *)"USBD Audio Playback Task", &os_err);
#endif
#endif
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockCreate()
*
* Description : Create an OS resource to use as an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockCreate (CPU_INT08U as_if_nbr,
USBD_ERR *p_err)
{
OS_EVENT *p_event;
p_event = OSSemCreate(1u);
if (p_event == (OS_EVENT *)0) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr] = p_event;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockAcquire()
*
* Description : Wait for an AudioStreaming interface to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockAcquire (CPU_INT08U as_if_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
OS_EVENT *p_event;
INT8U err_os;
INT32U timeout_ticks;
p_event = USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr];
timeout_ticks = ((((INT32U)timeout_ms * OS_TICKS_PER_SEC) + 1000u - 1u) / 1000u);
OSSemPend(p_event,
timeout_ticks,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEND_ISR:
case OS_ERR_PEVENT_NULL:
case OS_ERR_PEND_LOCKED:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockRelease()
*
* Description : Release an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockRelease (CPU_INT08U as_if_nbr)
{
OS_EVENT *p_event;
p_event = USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr];
(void)OSSemPost(p_event);
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockCreate()
*
* Description : Create an OS resource to use as a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockCreate (CPU_INT08U as_if_settings_ix,
USBD_ERR *p_err)
{
OS_EVENT *p_event;
p_event = OSSemCreate(1u);
if (p_event == (OS_EVENT *)0) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix] = p_event;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockAcquire()
*
* Description : Wait for a stream ring buffer queue to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockAcquire (CPU_INT08U as_if_settings_ix,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
OS_EVENT *p_event;
INT8U err_os;
INT32U timeout_ticks;
p_event = USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix];
timeout_ticks = ((((INT32U)timeout_ms * OS_TICKS_PER_SEC) + 1000u - 1u) / 1000u);
OSSemPend(p_event,
timeout_ticks,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEND_ISR:
case OS_ERR_PEVENT_NULL:
case OS_ERR_PEND_LOCKED:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockRelease()
*
* Description : Release a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockRelease (CPU_INT08U as_if_settings_ix)
{
OS_EVENT *p_event;
p_event = USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix];
(void)OSSemPost(p_event);
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPost()
*
* Description : Post a request into the record task's queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the Record buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_OS_RecordReqPost (void *p_msg,
USBD_ERR *p_err)
{
INT8U os_err;
os_err = OSQPost(USBD_Audio_OS_RecordMsgQPtr, p_msg);
if (os_err != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPend()
*
* Description : Pend on a request from the record task's queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the record buffer queue.
*
* Return(s) : Pointer to record request, if NO error(s).
*
* Null pointer, otherwise
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void *USBD_Audio_OS_RecordReqPend (USBD_ERR *p_err)
{
void *p_msg;
INT8U os_err;
p_msg = OSQPend(USBD_Audio_OS_RecordMsgQPtr,
0u,
&os_err);
switch (os_err) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEVENT_NULL:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_LOCKED:
*p_err = USBD_ERR_OS_FAIL;
break;
}
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPost()
*
* Description : Post a request to the playback's task queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the playback buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_OS_PlaybackReqPost (void *p_msg,
USBD_ERR *p_err)
{
INT8U os_err;
os_err = OSQPost(USBD_Audio_OS_PlaybackMsgQPtr, p_msg);
if (os_err != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPend()
*
* Description : Pend on a request from the playback's task queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the playback buffer queue.
*
* Return(s) : Pointer to playback request, if NO error(s).
*
* Null pointer, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void *USBD_Audio_OS_PlaybackReqPend (USBD_ERR *p_err)
{
void *p_msg;
INT8U os_err;
p_msg = OSQPend(USBD_Audio_OS_PlaybackMsgQPtr,
0u,
&os_err);
switch (os_err) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEVENT_NULL:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_LOCKED:
*p_err = USBD_ERR_OS_FAIL;
break;
}
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_DlyMs()
*
* Description : Delay a task for a certain time.
*
* Argument(s) : ms Delay in milliseconds.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_DlyMs (CPU_INT32U ms)
{
(void)OSTimeDlyHMSM(0u, 0u, 0u, ms);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordTask()
*
* Description : OS-dependent shell task to process record data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_RecordTaskHandler();
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackTask()
*
* Description : OS-dependent shell task to process playback data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_PlaybackTaskHandler();
}
#endif

View File

@@ -0,0 +1,794 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB AUDIO DEVICE OPERATING SYSTEM LAYER
* Micrium uC/OS-III
*
* Filename : usbd_audio_os.c
* Version : V4.06.01
*********************************************************************************************************
*/
#include <app_cfg.h>
#include "../../usbd_audio_internal.h"
#include "../../usbd_audio_os.h"
#include <Source/os.h>
#include <os_cfg_app.h>
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE
#error "USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO
#error "USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#endif
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE
#error "USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO
#error "USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO not #define'd in 'app_cfg.h' [MUST be > 0]"
#endif
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static OS_TCB USBD_Audio_OS_RecordTaskTCB;
static CPU_STK USBD_Audio_OS_RecordTaskStk[USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE];
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static OS_TCB USBD_Audio_OS_PlaybackTaskTCB;
static CPU_STK USBD_Audio_OS_PlaybackTaskStk[USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE];
#endif
static OS_MUTEX USBD_Audio_OS_AS_IF_MutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_EP];
static OS_MUTEX USBD_Audio_OS_RingBufQMutexTbl[USBD_AUDIO_MAX_NBR_AS_IF_SETTINGS];
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask(void *p_arg);
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_Init()
*
* Description : Initialize the audio class OS layer.
*
* Argument(s) : msg_qty Maximum quantity of messages for playback and record tasks' queues.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE OS layer initialization successful.
* USBD_ERR_OS_INIT_FAIL OS layer initialization failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_Init (CPU_INT16U msg_qty,
USBD_ERR *p_err)
{
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
OS_ERR err_os;
#else
(void)msg_qty;
#endif
/* -------------------- RECORD TASK ------------------- */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
OSTaskCreate(&USBD_Audio_OS_RecordTaskTCB,
"USBD Audio Record Task",
USBD_Audio_OS_RecordTask,
DEF_NULL,
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO,
&USBD_Audio_OS_RecordTaskStk[0u],
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE / 10u,
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE,
msg_qty, /* Record buf queue. */
0u,
DEF_NULL,
OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR,
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#endif
/* ------------------- PLAYBACK TASK ------------------ */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
OSTaskCreate(&USBD_Audio_OS_PlaybackTaskTCB,
"USBD Audio Playback Task",
USBD_Audio_OS_PlaybackTask,
DEF_NULL,
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO,
&USBD_Audio_OS_PlaybackTaskStk[0u],
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE / 10u,
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE,
msg_qty, /* Playback req queue. */
0u,
DEF_NULL,
OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR,
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
#endif
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockCreate()
*
* Description : Create an OS resource to use as an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockCreate (CPU_INT08U as_if_nbr,
USBD_ERR *p_err)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
p_mutex = &USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr];
OSMutexCreate(p_mutex,
"USBD AS IF Mutex",
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockAcquire()
*
* Description : Wait for an AudioStreaming interface to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockAcquire (CPU_INT08U as_if_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
OS_TICK timeout_ticks;
p_mutex = &USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr];
timeout_ticks = ((((OS_TICK)timeout_ms * OSCfg_TickRate_Hz) + 1000u - 1u) / 1000u);
(void)OSMutexPend(p_mutex,
timeout_ticks,
OS_OPT_PEND_BLOCKING,
DEF_NULL,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_MUTEX_OWNER:
case OS_ERR_OBJ_DEL:
case OS_ERR_OBJ_PTR_NULL:
case OS_ERR_OBJ_TYPE:
case OS_ERR_OPT_INVALID:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_WOULD_BLOCK:
case OS_ERR_SCHED_LOCKED:
case OS_ERR_STATE_INVALID:
case OS_ERR_STATUS_INVALID:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_AS_IF_LockRelease()
*
* Description : Release an AudioStreaming interface lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_AS_IF_LockRelease (CPU_INT08U as_if_nbr)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
p_mutex = &USBD_Audio_OS_AS_IF_MutexTbl[as_if_nbr];
OSMutexPost(p_mutex,
OS_OPT_POST_NONE,
&err_os);
(void)err_os;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockCreate()
*
* Description : Create an OS resource to use as a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully created.
* USBD_ERR_OS_SIGNAL_CREATE OS lock NOT successfully created.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockCreate (CPU_INT08U as_if_settings_ix,
USBD_ERR *p_err)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
p_mutex = &USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix];
OSMutexCreate(p_mutex,
"USBD Ring Buf Q Mutex",
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockAcquire()
*
* Description : Wait for a stream ring buffer queue to become available and acquire its lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* timeout_ms Lock wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS lock successfully acquired.
* USBD_ERR_OS_TIMEOUT OS lock NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS lock aborted.
* USBD_ERR_OS_FAIL OS lock not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockAcquire (CPU_INT08U as_if_settings_ix,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
OS_TICK timeout_ticks;
p_mutex = &USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix];
timeout_ticks = ((((OS_TICK)timeout_ms * OSCfg_TickRate_Hz) + 1000u - 1u) / 1000u);
(void)OSMutexPend(p_mutex,
timeout_ticks,
OS_OPT_PEND_BLOCKING,
DEF_NULL,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_MUTEX_OWNER:
case OS_ERR_OBJ_DEL:
case OS_ERR_OBJ_PTR_NULL:
case OS_ERR_OBJ_TYPE:
case OS_ERR_OPT_INVALID:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_WOULD_BLOCK:
case OS_ERR_SCHED_LOCKED:
case OS_ERR_STATE_INVALID:
case OS_ERR_STATUS_INVALID:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RingBufQLockRelease()
*
* Description : Release a stream ring buffer queue lock.
*
* Argument(s) : as_if_nbr AudioStreaming interface settings index.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_Audio_OS_RingBufQLockRelease (CPU_INT08U as_if_settings_ix)
{
OS_MUTEX *p_mutex;
OS_ERR err_os;
p_mutex = &USBD_Audio_OS_RingBufQMutexTbl[as_if_settings_ix];
OSMutexPost(p_mutex,
OS_OPT_POST_NONE,
&err_os);
(void)err_os;
}
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPost()
*
* Description : Post a request into the record task's queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the Record buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_OS_RecordReqPost (void *p_msg,
USBD_ERR *p_err)
{
OS_ERR err_os;
OSTaskQPost ( &USBD_Audio_OS_RecordTaskTCB,
p_msg,
(OS_MSG_SIZE)0u,
OS_OPT_POST_FIFO,
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordReqPend()
*
* Description : Pend on a request from the record task's queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the record buffer queue.
*
* Return(s) : Pointer to record request, if NO error(s).
*
* Null pointer, otherwise
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void *USBD_Audio_OS_RecordReqPend (USBD_ERR *p_err)
{
void *p_msg;
OS_ERR err_os;
OS_MSG_SIZE len;
p_msg = OSTaskQPend((OS_TICK )0,
OS_OPT_PEND_BLOCKING,
&len,
DEF_NULL,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_WOULD_BLOCK:
case OS_ERR_Q_EMPTY:
case OS_ERR_SCHED_LOCKED:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPost()
*
* Description : Post a request to the playback's task queue.
*
* Argument(s) : p_msg Pointer to message.
*
* p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Placing buffer in queue successful.
* USBD_ERR_OS_FAIL Failed to place item into the playback buffer queue.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_OS_PlaybackReqPost (void *p_msg,
USBD_ERR *p_err)
{
OS_ERR err_os;
OSTaskQPost( &USBD_Audio_OS_PlaybackTaskTCB,
p_msg,
(OS_MSG_SIZE)0u,
OS_OPT_POST_FIFO,
&err_os);
if (err_os != OS_ERR_NONE) {
*p_err = USBD_ERR_OS_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackReqPend()
*
* Description : Pend on a request from the playback's task queue.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function:
*
* USBD_ERR_NONE Getting buffer in queue successful.
* USBD_ERR_OS_TIMEOUT Timeout has elapsed.
* USBD_ERR_OS_ABORT Getting buffer in queue aborted.
* USBD_ERR_OS_FAIL Failed to get item from the playback buffer queue.
*
* Return(s) : Pointer to playback request, if NO error(s).
*
* Null pointer, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void *USBD_Audio_OS_PlaybackReqPend (USBD_ERR *p_err)
{
void *p_msg;
OS_ERR err_os;
OS_MSG_SIZE len;
p_msg = OSTaskQPend((OS_TICK )0,
OS_OPT_PEND_BLOCKING,
&len,
DEF_NULL,
&err_os);
switch (err_os) {
case OS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case OS_ERR_TIMEOUT:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
case OS_ERR_PEND_ABORT:
*p_err = USBD_ERR_OS_ABORT;
break;
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_WOULD_BLOCK:
case OS_ERR_Q_EMPTY:
case OS_ERR_SCHED_LOCKED:
default:
*p_err = USBD_ERR_OS_FAIL;
break;
}
return (p_msg);
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_DlyMs()
*
* Description : Delay a task for a certain time.
*
* Argument(s) : ms Delay in milliseconds.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_Audio_OS_DlyMs (CPU_INT32U ms)
{
OS_ERR err_os;
OSTimeDlyHMSM(0u, 0u, 0u, ms,
OS_OPT_TIME_HMSM_NON_STRICT,
&err_os);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_Audio_OS_RecordTask()
*
* Description : OS-dependent shell task to process record data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
static void USBD_Audio_OS_RecordTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_RecordTaskHandler();
}
#endif
/*
*********************************************************************************************************
* USBD_Audio_OS_PlaybackTask()
*
* Description : OS-dependent shell task to process playback data streams.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
static void USBD_Audio_OS_PlaybackTask (void *p_arg)
{
(void)p_arg;
USBD_Audio_PlaybackTaskHandler();
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,601 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE AUDIO CLASS
*
* Filename : usbd_audio_internal.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*********************************************************************************************************
*/
#ifndef USBD_AUDIO_INTERNAL_MODULE_PRESENT
#define USBD_AUDIO_INTERNAL_MODULE_PRESENT
/*
*********************************************************************************************************
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*********************************************************************************************************
*/
#include "usbd_audio.h"
#include <lib_math.h>
/*
*********************************************************************************************************
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* RING BUF Q
*********************************************************************************************************
*/
#define USBD_AUDIO_AS_IF_RING_BUF_Q_INVALID_IX 0xFFFF
/*
*********************************************************************************************************
* AUDIO CLASS SYNCH EP
*
* Note(s): (1) The information carried over the synch path consists of a 3-byte data packet.
* See 'USB Device Class Definition for Audio Data Formats, Release 1.0, March 18, 1998',
* section 3.7.2.2 for more details about Isochronous Synch Endpoint.
*
* (2) Tests on Windows showed that the transfer length should be the same, no matter the speed
* of the device.
*********************************************************************************************************
*/
/* See Note #1. */
#define USBD_AUDIO_FS_SYNCH_EP_XFER_LEN 3u /* Full-speed synch xfer len. */
#define USBD_AUDIO_HS_SYNCH_EP_XFER_LEN 3u /* High-speed synch xfer len. See Note #2. */
#define USBD_AUDIO_PLAYBACK_SYNCH_BUF_NBR 1u /* Nbr of synch buf per AudioStreaming IF. */
/*
*********************************************************************************************************
* AUDIO STREAMING IF
*
* Note(s): (1) The audio class uses 2 internal important types of structure for its functioning:
* AudioStreaming Interface (AS IF) and AudioStreaming Interface Settings (AS IF Settings).
*
* The following figure shows the device/configuration/interface/endpoint topology and how
* the AudioStreaming Interface and AudioStreaming Interface Settings fit in this topology.
* Let's consider the following high-speed capable device topology:
*
* Device HS
* Configuration HS
* +--------------------------------------+
* | |
* | AudioControl Interface |
* | AudioStreaming Interface | -> AS IF #1 -> AS IF Settings #1
* | Isochronous OUT EP |
* | AudioStreaming Interface | -> AS IF #2 -> AS IF Settings #2
* | Isochronous IN EP |
* | |
* +---- AUDIO INTERFACE COLLECTION 0 ----+ = class instance #0
* Configuration FS
* +--------------------------------------+
* | |
* | AudioControl Interface |
* | AudioStreaming Interface | -> AS IF #3 -> AS IF Settings #1
* | Isochronous OUT EP |
* | AudioStreaming Interface | -> AS IF #4 -> AS IF Settings #2
* | Isochronous IN EP |
* | |
* +---- AUDIO INTERFACE COLLECTION 0 ----+ = class instance #0
*
* 2 configurations are needed, one high-speed and the other full-speed. Each configuration
* contains the same playback and record AudioStreaming interfaces. To handle this topology,
* the audio class will use 4 different AS IF structures and 2 different AS IF Settings
* structures.
* The AS IF structure is associated to the ischronous endpoint. Since an endpoint can have
* different characteristics depending of the speed, each time an AudioStreaming interface
* is added to a configuration, a new AS IF structure is allocated.
* Since the AS IF Settings contains information that is more stream-specific and the same
* stream can be added to different configurations, thus the same AS IF Settings structure
* can also be added to different configurations.
*********************************************************************************************************
*/
/* Max nbr of comm struct. */
#define USBD_AUDIO_MAX_NBR_COMM (USBD_AUDIO_CFG_MAX_NBR_AIC * \
USBD_AUDIO_CFG_MAX_NBR_CFG)
/* Max nbr of alt setting struct. */
#define USBD_AUDIO_MAX_NBR_IF_ALT (USBD_AUDIO_CFG_MAX_NBR_AIC * \
USBD_AUDIO_CFG_MAX_NBR_CFG * \
USBD_AUDIO_CFG_MAX_NBR_IF_ALT)
/* Max nbr of AudioStreaming IF EP. */
#define USBD_AUDIO_MAX_NBR_AS_IF_EP ( USBD_AUDIO_CFG_MAX_NBR_AIC * \
USBD_AUDIO_CFG_MAX_NBR_CFG * \
(USBD_AUDIO_CFG_MAX_NBR_AS_IF_PLAYBACK + USBD_AUDIO_CFG_MAX_NBR_AS_IF_RECORD))
/* Maximum Number of AudioStreaming IF Settings. */
#define USBD_AUDIO_MAX_NBR_AS_IF_SETTINGS ( USBD_AUDIO_CFG_MAX_NBR_AIC * \
(USBD_AUDIO_CFG_MAX_NBR_AS_IF_PLAYBACK + USBD_AUDIO_CFG_MAX_NBR_AS_IF_RECORD))
/*
*********************************************************************************************************
* SYNCH ENDPOINT
*
* Note(s): (1) Synch endpoint was known as feedback endpoint in the audio 1.0 specification. Synch
* endpoint is the official name now.
*
* (2) Tests on Windows showed that the bit shift amount should be the same, no matter the speed
* of the device.
*
* (3) The maximum adjustment allows to add (underrun) or remove (overrun) 1 sample.
* The medium adjustment allows to add (underrun) or remove (overrun) 1/2 sample.
* The min adjustment allows to add (underrun) or remove (overrun) 1/2048 sample.
*********************************************************************************************************
*/
#define USBD_AUDIO_STREAM_CORR_BOUNDARY_INTERVAL 6u
#define USBD_AUDIO_PLAYBACK_FS_BIT_SHIFT 14u /* Full-speed synch bit shift amount. */
#define USBD_AUDIO_PLAYBACK_HS_BIT_SHIFT 14u /* High-speed synch bit shift amount. See Note #2. */
/* Min, med and max cst for feedback value (see Note #3)*/
#define USBD_AUDIO_PLAYBACK_SYNCH_MIN_ADJ(bit_shift) (1u << (bit_shift - 11u))
#define USBD_AUDIO_PLAYBACK_SYNCH_MED_ADJ(bit_shift) (1u << (bit_shift - 1u))
#define USBD_AUDIO_PLAYBACK_SYNCH_MAX_ADJ(bit_shift) (1u << bit_shift)
/*
*********************************************************************************************************
* AS IF HANDLE
*********************************************************************************************************
*/
#define USBD_AUDIO_AS_IF_HANDLE_CREATE(as_if, ix) DEF_BIT_FIELD_WR((as_if)->Handle, \
((ix) & 0x00FFu) , \
0x00FFu)
#define USBD_AUDIO_AS_IF_HANDLE_VALIDATE(as_if, as_handle) (((as_handle) == (as_if)->Handle) ? DEF_OK : DEF_FAIL)
#define USBD_AUDIO_AS_IF_HANDLE_INVALIDATE(as_if) ((as_if)->Handle = ((as_if)->Handle + 0x0100u))
#define USBD_AUDIO_AS_IF_HANDLE_IX_GET(as_handle) ((CPU_INT08U)(as_handle & 0x00FFu))
/*
*********************************************************************************************************
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
typedef enum usbd_audio_state { /* Audio class states. */
USBD_AUDIO_STATE_NONE = 0u,
USBD_AUDIO_STATE_INIT,
USBD_AUDIO_STATE_CFG
} USBD_AUDIO_STATE;
typedef enum usbd_audio_stream_dir { /* Audio stream dir. */
USBD_AUDIO_STREAM_NONE = 0u,
USBD_AUDIO_STREAM_IN,
USBD_AUDIO_STREAM_OUT
} USBD_AUDIO_STREAM_DIR;
typedef enum usbd_audio_entity_type { /* Audio entity type. */
USBD_AUDIO_ENTITY_UNKNOWN = 0u,
USBD_AUDIO_ENTITY_IT,
USBD_AUDIO_ENTITY_OT,
USBD_AUDIO_ENTITY_FU,
USBD_AUDIO_ENTITY_MU,
USBD_AUDIO_ENTITY_SU
} USBD_AUDIO_ENTITY_TYPE;
/*
*********************************************************************************************************
* FORWARD DECLARATIONS
*********************************************************************************************************
*/
typedef struct usbd_audio_ctrl USBD_AUDIO_CTRL;
typedef struct usbd_audio_comm USBD_AUDIO_COMM;
typedef struct usbd_audio_entity USBD_AUDIO_ENTITY;
typedef struct usbd_audio_it USBD_AUDIO_IT;
typedef struct usbd_audio_ot USBD_AUDIO_OT;
typedef struct usbd_audio_fu USBD_AUDIO_FU;
typedef struct usbd_audio_mu USBD_AUDIO_MU;
typedef struct usbd_audio_su USBD_AUDIO_SU;
typedef struct usbd_audio_as_if USBD_AUDIO_AS_IF;
typedef struct usbd_audio_buf_desc USBD_AUDIO_BUF_DESC;
/*
*********************************************************************************************************
* AUDIO CLASS CTRL INFO
*********************************************************************************************************
*/
struct usbd_audio_ctrl {
CPU_INT08U DevNbr; /* Dev nbr. */
CPU_INT08U ClassNbr; /* Class nbr. */
USBD_AUDIO_STATE State; /* Audio class state. */
USBD_AUDIO_COMM *CommPtr; /* Comm info ptr. */
USBD_AUDIO_COMM *CommHeadPtr; /* Comm list head ptr. */
USBD_AUDIO_COMM *CommTailPtr; /* Comm list tail ptr. */
CPU_INT08U CommCnt; /* Nbr of Comm Struct for this class instance. */
CPU_INT08U *ReqBufPtr; /* Pointer to class req buf. */
USBD_AUDIO_DRV DrvInfo; /* Audio driver info. */
USBD_AUDIO_EVENT_FNCTS *EventFnctPtr; /* Pointer to the audio event callbacks. */
CPU_INT08U EntityID_Nxt; /* Index used for entity ID assignment. */
CPU_INT08U EntityCnt; /* Nbr of Terminals and Units. */
USBD_AUDIO_ENTITY **EntityID_TblPtr; /* Table used for ID management. */
};
/*
*********************************************************************************************************
* AUDIO CLASS COMM INFO
*********************************************************************************************************
*/
struct usbd_audio_comm {
USBD_AUDIO_CTRL *CtrlPtr; /* Pointer to ctrl info. */
CPU_INT08U CfgNbr; /* Cfg number. */
CPU_INT08U AS_IF_Cnt; /* Nbr of AudioStreaming IFs. */
USBD_AUDIO_AS_IF *AS_IF_HeadPtr; /* AudioStreaming IFs list head ptr. */
USBD_AUDIO_AS_IF *AS_IF_TailPtr; /* AudioStreaming IFs list tail ptr. */
USBD_AUDIO_COMM *NextPtr; /* Pointer to the next Comm Info structure. */
};
/*
*********************************************************************************************************
* UNIT AND TERMINAL INFO STRUCT
*********************************************************************************************************
*/
struct usbd_audio_entity { /* Overlay struct used mainly for ID management. */
USBD_AUDIO_ENTITY_TYPE EntityType; /* Terminal or unit type. */
};
struct usbd_audio_it {
USBD_AUDIO_ENTITY_TYPE EntityType; /* Terminal type. */
CPU_INT08U ID; /* Unique ID identifying Terminal within audio fnct. */
CPU_INT08U AssociatedOT_ID; /* Output Terminal ID associated to this Input Terminal.*/
USBD_AUDIO_IT_CFG *IT_CfgPtr; /* Ptr to the Input Terminal cfg. */
};
struct usbd_audio_ot {
USBD_AUDIO_ENTITY_TYPE EntityType; /* Terminal type. */
CPU_INT08U ID; /* Unique ID identifying Terminal within audio fnct. */
CPU_INT08U AssociatedIT_ID; /* Input Terminal ID associated to this Output Terminal.*/
CPU_INT08U SourceID; /* Unit or Terminal ID to which Terminal is connected. */
USBD_AUDIO_OT_CFG *OT_CfgPtr; /* Ptr to the Output Terminal cfg. */
const USBD_AUDIO_DRV_AC_OT_API *OT_API_Ptr; /* Ptr to Audio Drv OT API. */
USBD_AUDIO_DRV *DrvInfoPtr; /* Ptr to audio drv info. */
};
struct usbd_audio_fu {
USBD_AUDIO_ENTITY_TYPE EntityType; /* Unit type. */
CPU_INT08U ID; /* Unique ID identifying Unit within audio fnct. */
CPU_INT08U SourceID; /* Unit or Terminal ID to which Unit is connected to. */
USBD_AUDIO_FU_CFG *FU_CfgPtr; /* Ptr to the Feature Unit cfg. */
const USBD_AUDIO_DRV_AC_FU_API *FU_API_Ptr; /* Ptr to Audio Drv FU API. */
USBD_AUDIO_DRV *DrvInfoPtr; /* Ptr to audio drv info. */
};
struct usbd_audio_mu {
USBD_AUDIO_ENTITY_TYPE EntityType; /* Unit type. */
CPU_INT08U ID; /* Unique ID identifying Unit within audio fnct. */
CPU_INT08U *SourceID_TblPtr; /* Tbl of Unit or Terminal ID to which Unit is connected*/
CPU_INT32U ControlsSize; /* bmControls tbl size. */
CPU_INT08U *ControlsTblPtr; /* Bitmap tbl indicating which mixing Ctrls are ... */
/* ...programmable. */
USBD_AUDIO_MU_CFG *MU_CfgPtr; /* Ptr to the Mixer Unit cfg. */
const USBD_AUDIO_DRV_AC_MU_API *MU_API_Ptr; /* Ptr to Audio Drv MU API. */
USBD_AUDIO_DRV *DrvInfoPtr; /* Ptr to audio drv info. */
};
struct usbd_audio_su {
USBD_AUDIO_ENTITY_TYPE EntityType; /* Unit type. */
CPU_INT08U ID; /* Unique ID identifying Unit within audio fnct. */
CPU_INT08U *SourceID_TblPtr; /* Tbl of Unit or Terminal ID to which Unit is connected*/
USBD_AUDIO_SU_CFG *SU_CfgPtr; /* Ptr to the Selector Unit cfg. */
const USBD_AUDIO_DRV_AC_SU_API *SU_API_Ptr; /* Ptr to Audio Drv SU API. */
USBD_AUDIO_DRV *DrvInfoPtr; /* Ptr to audio drv info. */
};
/*
*********************************************************************************************************
* AUDIO STREAMING IF
*
* Note(s) : (1) Each AudioStreaming interface has a ring buffer queue managed by four indexes. It allows
* to manage a producer/consumer communication model between the USB and codec sides:
*
* Producer -> Consumer
* USB -> Codec (Playback)
* Codec -> USB (Record)
*
* The meaning of indexes is the following depending of playback or record stream:
*
* PLAYBACK
* ProducerStartIx Core or Playback task submits a USB transfer
* ProducerEndIx Core task calls USBD_Audio_PlaybackIsocCmpl() to finish a USB transfer
* ConsumerStartIx Playback task submits an audio buffer to the codec driver
* ConsumerEndIx Codec driver has finished an audio transfer
*
* RECORD
* ProducerStartIx Codec driver starts an audio transfer
* ProducerEndIx Codec driver has finished an audio transfer
* ConsumerStartIx Core or Record task submits a USB transfer
* ConsumerEndIx Core task calls USBD_Audio_RecordIsocCmpl() to finish a USB transfer
*
* (2) The structure USBD_AUDIO_AS_IF_SETTINGS contains stream characteristics that will
* be the same across different device configurations.
*
* (3) For certain sampling frequencies (i.e. 11.025, 22.050 and 44.1 KHz), a data rate
* adjustment is necessary because the number of audio samples per ms is not an
* integer number. Partial audio samples are not possible. For those sampling
* frequencies, the table below gives the required adjustment:
*
* Samples per frm/ms | Typical Packet Size | Adjustment
* 11.025 | 11 samples | 12 samples every 40 packets (i.e. ms)
* 22.050 | 22 samples | 23 samples every 20 packets (i.e. ms)
* 44.1 | 44 samples | 45 samples every 10 packets (i.e. ms)
*********************************************************************************************************
*/
/* AudioStreaming IF ring buf queue (see Note #1). */
typedef struct usbd_audio_as_if_ring_buf_q {
USBD_AUDIO_BUF_DESC *BufDescTblPtr;
CPU_INT16U ProducerStartIx;
CPU_INT16U ProducerEndIx;
CPU_INT16U ConsumerStartIx;
CPU_INT16U ConsumerEndIx;
} USBD_AUDIO_AS_IF_RING_BUF_Q;
/* AudioStreaming alt settings (see Note #2). */
typedef struct usbd_audio_as_if_alt {
USBD_AUDIO_AS_ALT_CFG *AS_CfgPtr; /* Pointer to the Audiostreaming cfg. */
CPU_INT08U DataIsocAddr; /* Data isoc EP addr. */
CPU_INT08U SynchIsocAddr; /* Synchronization isoc EP addr. */
CPU_INT16U MaxPktLen; /* Max pkt len in byte. */
} USBD_AUDIO_AS_IF_ALT;
/* Audio playback synch struct. */
typedef struct usbd_audio_playback_synch {
CPU_INT16U SynchFrameNbr; /* Frame nbr used to track bRefresh period synch EP. */
/* Nbr of buff diff at which light feedback is applied. */
CPU_INT08S SynchBoundaryLightPos;
CPU_INT08S SynchBoundaryLightNeg;
CPU_INT32U FeedbackNominalVal; /* Nominal feedback val (already bit-shifted). */
CPU_INT32U FeedbackCurVal; /* Current feedback val (already bit-shifted). */
CPU_BOOLEAN FeedbackValUpdate; /* Flag indicating if a new feedback val must be sent. */
CPU_INT08S PrevBufDiff; /* Prev diff between nbr of rx'd and consumed bufs. */
CPU_INT16U PrevFrameNbr; /* Prev frame nbr during which a situation occurred. */
CPU_INT32U *SynchBufPtr; /* Ptr to single synch buf. */
CPU_BOOLEAN SynchBufFree; /* Flag indicating if synch buf free. */
} USBD_AUDIO_PLAYBACK_SYNCH;
typedef struct usbd_audio_as_if_settings { /* See Note #1. */
const USBD_AUDIO_DRV_AS_API *AS_API_Ptr; /* Ptr to Audio Drv AS API. */
USBD_AUDIO_DRV *DrvInfoPtr; /* Ptr to audio drv info. */
CPU_INT08U Ix; /* AS IF Settings ix. */
CPU_INT08U TerminalID; /* Terminal ID associated to this AS IF. */
CPU_INT16U BufTotalNbr; /* Nbr of buf allocated for this stream. */
CPU_INT16U BufTotalLen; /* Total len of a buf. */
CPU_INT08U *BufMemPtr; /* Ptr to mem region containing buf. */
USBD_AUDIO_STREAM_DIR StreamDir; /* Stream dir: IN or OUT. */
CPU_BOOLEAN StreamStarted; /* Flag indicating stream start. */
CPU_INT16U StreamPreBufMax; /* Max buf to acculumate for pre-buffering stream. */
CPU_BOOLEAN StreamPrimingDone; /* Flag indicating stream priming done. */
USBD_AUDIO_AS_IF_RING_BUF_Q StreamRingBufQ; /* Ring Buf Q. */
/* PLAYBACK STATE: */
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) && \
(USBD_AUDIO_CFG_PLAYBACK_FEEDBACK_EN == DEF_ENABLED)
USBD_AUDIO_PLAYBACK_SYNCH PlaybackSynch; /* Struct containing synch infos. */
#endif
/* RECORD STATE: */
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
CPU_INT16U RecordBufLen; /* Buf len used during stream comm. */
CPU_INT16U RecordRateAdjMs; /* Data rate adjustment in milliseconds (see Note #2). */
CPU_INT32U RecordRateAdjXferCtr;/* Ctr tracking data rate adjustment. */
CPU_INT16S RecordIsocTxOngoingCnt; /* Nbr of isoc IN xfer in progress. */
#endif
/* BUILT-IN STREAM CORR: */
#if (USBD_AUDIO_CFG_PLAYBACK_CORR_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_CORR_EN == DEF_ENABLED)
CPU_INT16U CorrPeriod; /* Period at which corr must be monitored. */
CPU_INT16U CorrFrameNbr; /* Last frame used to track corr period. */
USBD_AUDIO_PLAYBACK_CORR_FNCT CorrCallbackPtr; /* Ptr to app callback for playback corr. */
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_FEEDBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_PLAYBACK_CORR_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_CORR_EN == DEF_ENABLED)
/* Nbr of buff diff at which heavy correction is applied.*/
CPU_INT08S CorrBoundaryHeavyPos;
CPU_INT08S CorrBoundaryHeavyNeg;
#endif
#if (USBD_AUDIO_CFG_STAT_EN == DEF_ENABLED)
USBD_AUDIO_STAT *StatPtr; /* Statistics for given AS IF. */
#endif
} USBD_AUDIO_AS_IF_SETTINGS;
struct usbd_audio_as_if {
USBD_AUDIO_AS_HANDLE Handle; /* AudioStreaming IF handle. */
USBD_AUDIO_COMM *CommPtr; /* Ptr to comm struct. */
CPU_INT08U DevNbr; /* Dev nbr. */
CPU_INT08U ClassNbr; /* Class nbr. */
CPU_INT08U AS_IF_Nbr; /* AudioStreaming IF nbr attributed by the core. */
USBD_AUDIO_AS_IF_SETTINGS *AS_IF_SettingsPtr; /* Ptr to AS settings. */
/* ALTERNATE SETTINGS: */
USBD_AUDIO_AS_IF_ALT *AS_IF_AltCurPtr; /* Alt setting cur ptr. */
USBD_AUDIO_AS_IF *NextPtr; /* Ptr to nxt AudioStreaming IF struct. */
};
/* Buf desc used during streaming. */
struct usbd_audio_buf_desc {
void *BufPtr;
CPU_INT16U BufLen;
};
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*********************************************************************************************************
*/
#define USBD_AUDIO_BIT_SET_CNT(nbr_bit_set, var_to_test) do { \
CPU_INT32U __bitmap; \
\
__bitmap = (var_to_test); \
for ((nbr_bit_set) = 0u; (nbr_bit_set) < __bitmap; (nbr_bit_set)++) { \
__bitmap &= (__bitmap - 1u); \
} \
} while (0);
/*
*********************************************************************************************************
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/* Implemented in usbd_audio_processing.c. */
void USBD_Audio_ProcessingInit ( CPU_INT16U msg_qty,
USBD_ERR *p_err);
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
USBD_AUDIO_AS_IF *USBD_Audio_AS_IF_Alloc ( USBD_ERR *p_err);
#endif
void USBD_Audio_AC_TerminalCtrl ( CPU_INT08U terminal_id,
USBD_AUDIO_ENTITY_TYPE recipient,
const void *p_recipient_info,
CPU_INT08U b_req,
CPU_INT16U w_val,
CPU_INT08U *p_buf,
CPU_INT16U req_len,
USBD_ERR *p_err);
void USBD_Audio_AC_UnitCtrl ( CPU_INT08U unit_id,
USBD_AUDIO_ENTITY_TYPE recipient,
const void *p_recipient_info,
CPU_INT08U b_req,
CPU_INT16U w_val,
CPU_INT08U *p_buf,
CPU_INT16U req_len,
USBD_ERR *p_err);
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_AS_EP_CtrlProcess ( USBD_AUDIO_AS_IF *p_as_if,
const USBD_AUDIO_AS_ALT_CFG *p_as_cfg,
CPU_INT16U ep_addr,
CPU_INT08U b_req,
CPU_INT16U w_val,
CPU_INT08U *p_buf,
CPU_INT16U req_len,
USBD_ERR *p_err);
#endif
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_RecordTaskHandler (void);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_PlaybackTaskHandler(void);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED) || \
(USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_AS_IF_Start ( USBD_AUDIO_AS_IF *p_as_if,
USBD_ERR *p_err);
void USBD_Audio_AS_IF_Stop ( USBD_AUDIO_AS_IF *p_as_if,
USBD_ERR *p_err);
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,157 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE AUDIO CLASS
*
* Filename : usbd_audio_os.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*********************************************************************************************************
*/
#ifndef USBD_AUDIO_OS_MODULE_PRESENT
#define USBD_AUDIO_OS_MODULE_PRESENT
/*
*********************************************************************************************************
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
void USBD_Audio_OS_Init (CPU_INT16U msg_qty,
USBD_ERR *p_err);
void USBD_Audio_OS_AS_IF_LockCreate (CPU_INT08U as_if_nbr,
USBD_ERR *p_err);
void USBD_Audio_OS_AS_IF_LockAcquire (CPU_INT08U as_if_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err);
void USBD_Audio_OS_AS_IF_LockRelease (CPU_INT08U as_if_nbr);
void USBD_Audio_OS_RingBufQLockCreate (CPU_INT08U as_if_settings_ix,
USBD_ERR *p_err);
void USBD_Audio_OS_RingBufQLockAcquire(CPU_INT08U as_if_settings_ix,
CPU_INT16U timeout_ms,
USBD_ERR *p_err);
void USBD_Audio_OS_RingBufQLockRelease(CPU_INT08U as_if_settings_ix);
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void USBD_Audio_OS_RecordReqPost (void *p_msg,
USBD_ERR *p_err);
void *USBD_Audio_OS_RecordReqPend (USBD_ERR *p_err);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_OS_PlaybackReqPost (void *p_msg,
USBD_ERR *p_err);
void *USBD_Audio_OS_PlaybackReqPend (USBD_ERR *p_err);
#endif
void USBD_Audio_OS_DlyMs (CPU_INT32U ms);
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,231 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE AUDIO CLASS
*
* Filename : usbd_audio_processing.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*********************************************************************************************************
*/
#ifndef USBD_AUDIO_PROCESSING_MODULE_PRESENT
#define USBD_AUDIO_PROCESSING_MODULE_PRESENT
/*
*********************************************************************************************************
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
#include "usbd_audio.h"
/*
*********************************************************************************************************
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*********************************************************************************************************
*/
#ifdef USBD_AUDIO_PROCESSING_MODULE
#define USBD_AUDIO_PROCESSING_EXT
#else
#define USBD_AUDIO_PROCESSING_EXT extern
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_RECORD_EN == DEF_ENABLED)
void *USBD_Audio_RecordBufGet (USBD_AUDIO_AS_HANDLE as_handle,
CPU_INT16U *p_buf_len);
void USBD_Audio_RecordRxCmpl (USBD_AUDIO_AS_HANDLE as_handle);
void USBD_Audio_RecordBufFree (USBD_AUDIO_AS_HANDLE as_handle,
void *p_buf);
#endif
#if (USBD_AUDIO_CFG_PLAYBACK_EN == DEF_ENABLED)
void USBD_Audio_PlaybackTxCmpl (USBD_AUDIO_AS_HANDLE as_handle);
void USBD_Audio_PlaybackBufFree(USBD_AUDIO_AS_HANDLE as_handle,
void *p_buf);
#endif
#if (USBD_AUDIO_CFG_STAT_EN == DEF_ENABLED)
USBD_AUDIO_STAT *USBD_Audio_StatGet (USBD_AUDIO_AS_HANDLE as_handle);
#endif
/*
*********************************************************************************************************
* AUDIO STATISTICS MACRO'S
*********************************************************************************************************
*/
#if (USBD_AUDIO_CFG_STAT_EN == DEF_ENABLED)
#define USBD_AUDIO_STAT_INC(ctr) { \
(ctr)++; \
}
#define USBD_AUDIO_STAT_PROT_INC(ctr) { \
CPU_CRITICAL_ENTER(); \
(ctr)++; \
CPU_CRITICAL_EXIT(); \
}
#define USBD_AUDIO_DRV_STAT_INC(as_handle, ctr) { \
USBD_AUDIO_STAT *__p_audio_stat; \
\
__p_audio_stat = USBD_Audio_StatGet((as_handle)); \
__p_audio_stat->ctr++; \
}
#define USBD_AUDIO_STAT_DEC(ctr) { \
(ctr)--; \
}
#define USBD_AUDIO_STAT_PROT_DEC(ctr) { \
CPU_CRITICAL_ENTER(); \
(ctr)--; \
CPU_CRITICAL_EXIT(); \
}
#define USBD_AUDIO_STAT_MAX(ctr, max) { \
if ((ctr) > (max)) { \
(max) = (ctr); \
} \
}
#define USBD_AUDIO_STAT_PROT_MAX(ctr, max) { \
CPU_CRITICAL_ENTER(); \
if ((ctr) > (max)) { \
(max) = (ctr); \
} \
CPU_CRITICAL_EXIT(); \
}
#define USBD_AUDIO_STAT_MIN(ctr, min) { \
if ((ctr) < (min)) { \
(min) = (ctr); \
} \
}
#define USBD_AUDIO_STAT_PROT_MIN(ctr, min) { \
CPU_CRITICAL_ENTER(); \
if ((ctr) < (min)) { \
(min) = (ctr); \
} \
CPU_CRITICAL_EXIT(); \
}
#define USBD_AUDIO_STAT_ADD(ctr, add) { \
(ctr) += (add); \
}
#define USBD_AUDIO_STAT_RESET(ctr) { \
(ctr) = 0u; \
}
#else
#define USBD_AUDIO_STAT_INC(ctr)
#define USBD_AUDIO_STAT_PROT_INC(ctr)
#define USBD_AUDIO_DRV_STAT_INC(as_handle, ctr)
#define USBD_AUDIO_STAT_DEC(ctr)
#define USBD_AUDIO_STAT_PROT_DEC(ctr)
#define USBD_AUDIO_STAT_MAX(ctr, max)
#define USBD_AUDIO_STAT_PROT_MAX(ctr, max)
#define USBD_AUDIO_STAT_ADD(ctr, add)
#define USBD_AUDIO_STAT_RESET(ctr)
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,228 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB COMMUNICATIONS DEVICE CLASS (CDC)
* ETHERNET EMULATION MODEL (EEM)
*
* Filename : usbd_cdc_eem.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_CDC_EEM_MODULE_PRESENT
#define USBD_CDC_EEM_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_CDC_EEM_MODULE
#define USBD_CDC_EEM_EXT
#else
#define USBD_CDC_EEM_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define USBD_CDC_EEM_HDR_LEN 2u /* CDC EEM data header length. */
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CDC EEM CLASS INSTANCE CONFIGURATION STRUCTURE
*********************************************************************************************************
*/
typedef struct usbd_cdc_eem_cfg {
CPU_INT08U RxBufQSize; /* Size of rx buffer Q. */
CPU_INT08U TxBufQSize; /* Size of tx buffer Q. */
} USBD_CDC_EEM_CFG;
/*
*********************************************************************************************************
* CDC EEM DRIVER
*********************************************************************************************************
*/
typedef const struct usbd_cdc_eem_drv {
/* Retrieve a Rx buffer. */
CPU_INT08U *(*RxBufGet) (CPU_INT08U class_nbr,
void *p_arg,
CPU_INT16U *p_buf_len);
/* Signal that a rx buffer is ready. */
void (*RxBufRdy) (CPU_INT08U class_nbr,
void *p_arg);
/* Free a tx buffer. */
void (*TxBufFree) (CPU_INT08U class_nbr,
void *p_arg,
CPU_INT08U *p_buf,
CPU_INT16U buf_len);
} USBD_CDC_EEM_DRV;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_CDC_EEM_Init ( USBD_ERR *p_err);
CPU_INT08U USBD_CDC_EEM_Add ( USBD_ERR *p_err);
void USBD_CDC_EEM_CfgAdd ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
const CPU_CHAR *p_if_name,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_CDC_EEM_IsConn ( CPU_INT08U class_nbr);
void USBD_CDC_EEM_InstanceInit ( CPU_INT08U class_nbr,
USBD_CDC_EEM_CFG *p_cfg,
USBD_CDC_EEM_DRV *p_cdc_eem_drv,
void *p_arg,
USBD_ERR *p_err);
void USBD_CDC_EEM_Start ( CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_CDC_EEM_Stop ( CPU_INT08U class_nbr,
USBD_ERR *p_err);
CPU_INT08U USBD_CDC_EEM_DevNbrGet ( CPU_INT08U class_nbr,
USBD_ERR *p_err);
CPU_INT08U *USBD_CDC_EEM_RxDataPktGet ( CPU_INT08U class_nbr,
CPU_INT16U *p_rx_len,
CPU_BOOLEAN *p_crc_computed,
USBD_ERR *p_err);
void USBD_CDC_EEM_TxDataPktSubmit( CPU_INT08U class_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
CPU_BOOLEAN crc_computed,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_CDC_EEM_CFG_MAX_NBR_DEV
#error "USBD_CDC_EEM_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 1] "
#endif
#if (USBD_CDC_EEM_CFG_MAX_NBR_DEV < 1u)
#error "USBD_CDC_EEM_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 1] "
#endif
#ifndef USBD_CDC_EEM_CFG_MAX_NBR_CFG
#error "USBD_CDC_EEM_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 1] "
#endif
#if (USBD_CDC_EEM_CFG_MAX_NBR_CFG < 1u)
#error "USBD_CDC_EEM_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 1] "
#endif
#ifdef USBD_CDC_EEM_CFG_RX_BUF_QTY_PER_DEV
#if ((USBD_CDC_EEM_CFG_RX_BUF_QTY_PER_DEV - 1u) > USBD_CFG_MAX_NBR_URB_EXTRA)
#error "USBD_CDC_EEM_CFG_RX_BUF_QTY_PER_DEV illegally #define'd in 'usbd_cfg.h'"
#error " [MUST be <= USBD_CFG_MAX_NBR_URB_EXTRA + 1] "
#endif
#endif
#ifndef USBD_CDC_EEM_CFG_ECHO_BUF_LEN
#error "USBD_CDC_EEM_CFG_ECHO_BUF_LEN not #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 2u] "
#endif
#if (USBD_CDC_EEM_CFG_ECHO_BUF_LEN < 2u)
#error "USBD_CDC_EEM_CFG_ECHO_BUF_LEN illegally #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 2] "
#endif
#ifndef USBD_CDC_EEM_CFG_RX_BUF_LEN
#error "USBD_CDC_EEM_CFG_RX_BUF_LEN not #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 2u] "
#endif
#if (USBD_CDC_EEM_CFG_RX_BUF_LEN < 2u)
#error "USBD_CDC_EEM_CFG_RX_BUF_LEN illegally #define'd in 'usbd_cfg.h'"
#error " [MUST be >= 2] "
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,288 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NOTICE
*
* Semidrive modified this file to adapt it for ssdk platform.
* The modifications are only intended for use with Semidrive chips.
* Copyright of all the modifications belongs to Semidrive Semiconductor.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB COMMUNICATIONS DEVICE CLASS (CDC)
* ABSTRACT CONTROL MODEL (ACM)
* SERIAL EMULATION
*
* Filename : usbd_acm_serial.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_ACM_SERIAL_MODULE_PRESENT
#define USBD_ACM_SERIAL_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../usbd_cdc.h"
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define USBD_ACM_SERIAL_NBR_NONE DEF_INT_08U_MAX_VAL
/*
*********************************************************************************************************
* PORT SETTINGS DEFINES
*********************************************************************************************************
*/
#define USBD_ACM_SERIAL_PARITY_NONE 0u
#define USBD_ACM_SERIAL_PARITY_ODD 1u
#define USBD_ACM_SERIAL_PARITY_EVEN 2u
#define USBD_ACM_SERIAL_PARITY_MARK 3u
#define USBD_ACM_SERIAL_PARITY_SPACE 4u
#define USBD_ACM_SERIAL_STOP_BIT_1 0u
#define USBD_ACM_SERIAL_STOP_BIT_1_5 1u
#define USBD_ACM_SERIAL_STOP_BIT_2 2u
/*
*********************************************************************************************************
* LINE EVENTS FLAGS DEFINES
*********************************************************************************************************
*/
#define USBD_ACM_SERIAL_CTRL_BREAK DEF_BIT_00
#define USBD_ACM_SERIAL_CTRL_RTS DEF_BIT_01
#define USBD_ACM_SERIAL_CTRL_DTR DEF_BIT_02
#define USBD_ACM_SERIAL_STATE_DCD DEF_BIT_00
#define USBD_ACM_SERIAL_STATE_DSR DEF_BIT_01
#define USBD_ACM_SERIAL_STATE_BREAK DEF_BIT_02
#define USBD_ACM_SERIAL_STATE_RING DEF_BIT_03
#define USBD_ACM_SERIAL_STATE_FRAMING DEF_BIT_04
#define USBD_ACM_SERIAL_STATE_PARITY DEF_BIT_05
#define USBD_ACM_SERIAL_STATE_OVERUN DEF_BIT_06
/*
*********************************************************************************************************
* CALL MANAGEMENT CAPABILITIES
*
* Note(s) : (1) See 'USB, Communications Class, Subclass Specification for PSTN Devices, Revision 1.2,
* February 9 2007', section '5.3.1 Call Management Functional Descriptor' for more details
* about the Call Management capabilities.
*********************************************************************************************************
*/
#define USBD_ACM_SERIAL_CALL_MGMT_DEV DEF_BIT_00
#define USBD_ACM_SERIAL_CALL_MGMT_DATA_CCI_DCI DEF_BIT_01
#define USBD_ACM_SERIAL_CALL_MGMT_DATA_OVER_DCI (DEF_BIT_01 | DEF_BIT_00)
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LINE CODING DATA TYPE
*********************************************************************************************************
*/
typedef struct usbd_acm_serial_line_coding {
CPU_INT32U BaudRate;
CPU_INT08U Parity;
CPU_INT08U StopBits;
CPU_INT08U DataBits;
} USBD_ACM_SERIAL_LINE_CODING;
/*
*********************************************************************************************************
* LINE CTRL CHANGE CALLBACK DATA TYPE
*********************************************************************************************************
*/
typedef void (*USBD_ACM_SERIAL_LINE_CTRL_CHNGD) (CPU_INT08U subclass_nbr,
CPU_INT08U event,
CPU_INT08U event_chngd,
void *p_arg);
/*
*********************************************************************************************************
* LINE CODING CHANGE CALLBACK DATA TYPE
*********************************************************************************************************
*/
typedef CPU_BOOLEAN (*USBD_ACM_SERIAL_LINE_CODING_CHNGD) (CPU_INT08U subclass_nbr,
USBD_ACM_SERIAL_LINE_CODING *p_line_coding,
void *p_arg);
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_ACM_SerialInit (USBD_ERR *p_err);
CPU_INT08U USBD_ACM_SerialAdd (CPU_INT16U line_state_interval,
CPU_INT16U call_mgmt_capabilities,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_ACM_SerialCfgAdd (CPU_INT08U subclass_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_ACM_SerialIsConn (CPU_INT08U subclass_nbr);
CPU_INT32U USBD_ACM_SerialRx (CPU_INT08U subclass_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
CPU_INT32U USBD_ACM_SerialTx (CPU_INT08U subclass_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
#if 1
void USBD_ACM_SerialRxAsync (CPU_INT08U subclass_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
USBD_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
void USBD_ACM_SerialTxAsync (CPU_INT08U subclass_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
USBD_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
#endif
CPU_INT08U USBD_ACM_SerialLineCtrlGet (CPU_INT08U subclass_nbr,
USBD_ERR *p_err);
void USBD_ACM_SerialLineCtrlReg (CPU_INT08U subclass_nbr,
USBD_ACM_SERIAL_LINE_CTRL_CHNGD line_ctrl_chngd,
void *p_arg,
USBD_ERR *p_err);
void USBD_ACM_SerialLineCodingGet(CPU_INT08U subclass_nbr,
USBD_ACM_SERIAL_LINE_CODING *p_line_coding,
USBD_ERR *p_err);
void USBD_ACM_SerialLineCodingSet(CPU_INT08U subclass_nbr,
USBD_ACM_SERIAL_LINE_CODING *p_line_coding,
USBD_ERR *p_err);
void USBD_ACM_SerialLineCodingReg(CPU_INT08U subclass_nbr,
USBD_ACM_SERIAL_LINE_CODING_CHNGD line_coding_chngd,
void *p_arg,
USBD_ERR *p_err);
void USBD_ACM_SerialLineStateSet (CPU_INT08U subclass_nbr,
CPU_INT08U events,
USBD_ERR *p_err);
void USBD_ACM_SerialLineStateClr (CPU_INT08U subclass_nbr,
CPU_INT08U events,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
* DEFINED IN OS'S usbd_acm_serial_os.c
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_ACM_SERIAL_CFG_MAX_NBR_DEV
#error "USBD_ACM_SERIAL_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif (USBD_ACM_SERIAL_CFG_MAX_NBR_DEV < 1u)
#error "USBD_ACM_SERIAL_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h'[MUST be >= 1]"
#elif (USBD_ACM_SERIAL_CFG_MAX_NBR_DEV > USBD_CDC_CFG_MAX_NBR_DEV)
#error "USBD_ACM_SERIAL_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be <= USBD_CDC_CFG_MAX_NBR_DEV]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,216 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB COMMUNICATIONS DEVICE CLASS (CDC)
* NETWORK CONTROL MODEL (NCM)
* USB Ethernet
*
* Filename : usbd_ncm.h
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_NCM_MODULE_PRESENT
#define USBD_NCM_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../usbd_cdc.h"
#include <netdev.h>
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define USBD_NCM_NBR_NONE DEF_INT_08U_MAX_VAL
/*
* IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
* and FCS/CRC (frame check sequence).
*/
#define ETH_ALEN 6 /* Octets in one ethernet addr */
#define ETH_TLEN 2 /* Octets in ethernet type field */
#define ETH_HLEN 14 /* Total octets in header. */
#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
#define ETH_DATA_LEN 1500u /* Max. octets in payload */
#define ETH_FRAME_LEN 1514u /* Max. octets in frame sans FCS */
#define ETH_FCS_LEN 4 /* Octets in the FCS */
/* CDC NCM subclass 5.2.1 NCM Functional Descriptor, bmNetworkCapabilities */
#define USB_CDC_NCM_NCAP_ETH_FILTER (1 << 0)
#define USB_CDC_NCM_NCAP_NET_ADDRESS (1 << 1)
#define USB_CDC_NCM_NCAP_ENCAP_COMMAND (1 << 2)
#define USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE (1 << 3)
#define USB_CDC_NCM_NCAP_CRC_MODE (1 << 4)
#define USB_CDC_NCM_NCAP_NTB_INPUT_SIZE (1 << 5)
/* CDC NCM subclass Table 6-3: NTB Parameter Structure */
#define USB_CDC_NCM_NTB16_SUPPORTED (1 << 0)
#define USB_CDC_NCM_NTB32_SUPPORTED (1 << 1)
/* CDC NCM subclass 6.2.7 SetNtbInputSize */
#define USB_CDC_NCM_NTB_MIN_IN_SIZE 2048
#define USB_CDC_NCM_NTB_MIN_OUT_SIZE 2048
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
struct usb_cdc_ether_desc {
CPU_INT08U bLength;
CPU_INT08U bDescriptorType;
CPU_INT08U bDescriptorSubType;
CPU_INT08U iMACAddress;
CPU_INT32U bmEthernetStatistics;
CPU_INT16U wMaxSegmentSize;
CPU_INT16U wNumberMCFilters;
CPU_INT08U bNumberPowerFilters;
} __attribute__ ((packed));
/* "NCM Control Model Functional Descriptor" */
struct usb_cdc_ncm_desc {
CPU_INT08U bLength;
CPU_INT08U bDescriptorType;
CPU_INT08U bDescriptorSubType;
CPU_INT16U bcdNcmVersion;
CPU_INT08U bmNetworkCapabilities;
} __attribute__ ((packed));
/*
* Class Specific structures and constants
*
* CDC NCM NTB parameters structure, CDC NCM subclass 6.2.1
*
*/
struct usb_cdc_ncm_ntb_parameters {
CPU_INT16U wLength;
CPU_INT16U bmNtbFormatsSupported;
CPU_INT32U dwNtbInMaxSize;
CPU_INT16U wNdpInDivisor;
CPU_INT16U wNdpInPayloadRemainder;
CPU_INT16U wNdpInAlignment;
CPU_INT16U wPadding1;
CPU_INT32U dwNtbOutMaxSize;
CPU_INT16U wNdpOutDivisor;
CPU_INT16U wNdpOutPayloadRemainder;
CPU_INT16U wNdpOutAlignment;
CPU_INT16U wNtbOutMaxDatagrams;
} __attribute__ ((packed));
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_NCM_Init (USBD_ERR *p_err);
CPU_INT08U USBD_NCM_Add (USBD_ERR *p_err);
CPU_BOOLEAN USBD_NCM_CfgAdd (CPU_INT08U subclass_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_NCM_Bind (CPU_INT08U subclass_nbr,
struct net_driver_s *nd,
CPU_INT08U *mac_addr);
void USBD_NCM_TxDatagramSubmit(CPU_INT08U subclass_nbr,
struct pbuf *p,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_CDC_NCM_CFG_MAX_NBR_DEV
#error "USBD_CDC_NCM_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif (USBD_CDC_NCM_CFG_MAX_NBR_DEV < 1u)
#error "USBD_CDC_NCM_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h'[MUST be >= 1]"
#elif (USBD_CDC_NCM_CFG_MAX_NBR_DEV > USBD_CDC_CFG_MAX_NBR_DEV)
#error "USBD_CDC_NCM_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be <= USBD_CDC_CFG_MAX_NBR_DEV]"
#endif
#ifndef USBD_CDC_NCM_CFG_TX_DPE_LEN
#error "USBD_CDC_NCM_CFG_TX_DPE_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif (USBD_CDC_NCM_CFG_TX_DPE_LEN < 1u)
#error "USBD_CDC_NCM_CFG_TX_DPE_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 1]"
#endif
#ifndef USBD_CDC_NCM_CFG_TX_BUF_LEN
#error "USBD_CDC_NCM_CFG_TX_BUF_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 2]"
#elif (USBD_CDC_NCM_CFG_TX_BUF_LEN < 2u) || (USBD_CDC_NCM_CFG_TX_BUF_LEN > 64u)
#error "USBD_CDC_NCM_CFG_TX_BUF_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 2 and <=64]"
#endif
#ifndef USBD_CDC_NCM_CFG_RX_BUF_LEN
#error "USBD_CDC_NCM_CFG_RX_BUF_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 2]"
#elif (USBD_CDC_NCM_CFG_RX_BUF_LEN < 2u) || (USBD_CDC_NCM_CFG_RX_BUF_LEN > 64u)
#error "USBD_CDC_NCM_CFG_RX_BUF_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 2 and <=64]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,458 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NOTICE
*
* Semidrive modified this file to adapt it for ssdk platform.
* The modifications are only intended for use with Semidrive chips.
* Copyright of all the modifications belongs to Semidrive Semiconductor.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB COMMUNICATIONS DEVICE CLASS (CDC)
*
* Filename : usbd_cdc.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_CDC_MODULE_PRESENT
#define USBD_CDC_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CDC INVALID INSTANCE NUMBERS DEFINES
*********************************************************************************************************
*/
#define USBD_CDC_NBR_NONE DEF_INT_08U_MAX_VAL
#define USBD_CDC_DATA_IF_NBR_NONE DEF_INT_08U_MAX_VAL
/*
*********************************************************************************************************
* COMMUNICATIONS CLASS SUBCLASS CODES DEFINES
*
* Note(s) : (1) Communication class subclass codes are defined in table 4 from the CDC specification
* revision 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_SUBCLASS_RSVD 0x00u /* Reserved. */
#define USBD_CDC_SUBCLASS_DLCM 0x01u /* Direct line control model. */
#define USBD_CDC_SUBCLASS_ACM 0x02u /* Abstract control model. */
#define USBD_CDC_SUBCLASS_TCM 0x03u /* Telephone control model. */
#define USBD_CDC_SUBCLASS_MCCM 0x04u /* Multi-channel control model. */
#define USBD_CDC_SUBCLASS_CAPICM 0x05u /* CAPI control model. */
#define USBD_CDC_SUBCLASS_ENCM 0x06u /* Ethernet networking control model. */
#define USBD_CDC_SUBCLASS_ATM 0x07u /* ATM networking control model. */
#define USBD_CDC_SUBCLASS_WHCM 0x08u /* Wireless handset control model. */
#define USBD_CDC_SUBCLASS_DEV_MGMT 0x09u /* Device management. */
#define USBD_CDC_SUBCLASS_MDLM 0x0Au /* Mobile direct line model. */
#define USBD_CDC_SUBCLASS_OBEX 0x0Bu /* OBEX. */
#define USBD_CDC_SUBCLASS_EEM 0x0Cu /* Ethernet emulation model. */
#define USBD_CDC_SUBCLASS_NCM 0x0Du /* Network control model. */
#define USBD_CDC_SUBCLASS_VENDOR 0xFEu /* Vendor specific. */
/*
*********************************************************************************************************
* COMMUNICATION CLASS PROTOCOL CODES DEFINES
*
* Note(s) : (1) Communication class protocol codes are defined in table 5 from the CDC specification
* revision 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_COMM_PROTOCOL_NONE 0x00u /* No class specific protocol required. */
#define USBD_CDC_COMM_PROTOCOL_AT_V250 0x01u /* AT Commands: V.250 etc. */
#define USBD_CDC_COMM_PROTOCOL_AT_PCCA_101 0x02u /* AT Commands defined by PCCA-101. */
#define USBD_CDC_COMM_PROTOCOL_AT_PCCA_101_ANNEX 0x03u /* AT Commands defined by PCCA-101 & Annex O. */
#define USBD_CDC_COMM_PROTOCOL_AT_GSM_7_07 0x04u /* AT Commands defined by GSM 07.07 */
#define USBD_CDC_COMM_PROTOCOL_AT_3GPP_27_07 0x05u /* AT Commands defined by 3GPP 27.007 */
#define USBD_CDC_COMM_PROTOCOL_AT_TIA_CDMA 0x06u /* AT Commands defined by TIA for CDMA */
#define USBD_CDC_COMM_PROTOCOL_EEM 0x07u /* Ethernet Emulation Model. */
#define USBD_CDC_COMM_PROTOCOL_EXT 0xFEu /* External Protocol: Commands defined by command ... */
/* ... set functional descriptor. */
#define USBD_CDC_COMM_PROTOCOL_VENDOR 0xFFu /* Vendor-specific. */
/*
*********************************************************************************************************
* DATA INTERFACE CLASS PROTOCOL CODES DEFINES
*
* Note(s) : (1) Data interface class protocol codes are defined in table 7 from the CDC specification
* revision 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_DATA_PROTOCOL_NONE 0x00u /* No class specific protocol required. */
#define USBD_CDC_DATA_PROTOCOL_NTB 0x01u /* Network transfer block. */
#define USBD_CDC_DATA_PROTOCOL_PHY 0x30u /* Physical interface protocol for ISDN BRI. */
#define USBD_CDC_DATA_PROTOCOL_HDLC 0x31u /* Physical interface protocol for ISDN BRI. */
#define USBD_CDC_DATA_PROTOCOL_TRANS 0x32u /* Transparent. */
#define USBD_CDC_DATA_PROTOCOL_Q921M 0x50u /* Management protocol for Q.921 data link protocol. */
#define USBD_CDC_DATA_PROTOCOL_Q921 0x51u /* Data link protocol for Q.931. */
#define USBD_CDC_DATA_PROTOCOL_Q921TM 0x52u /* TEI-multiplexor for Q.921 data link protocol. */
#define USBD_CDC_DATA_PROTOCOL_COMPRES 0x90u /* Data compression procedures. */
#define USBD_CDC_DATA_PROTOCOL_Q9131 0x91u /* Q.931/Euro- ISDN Euro-ISDN protocol control. */
#define USBD_CDC_DATA_PROTOCOL_V24 0x92u /* V.24 rate adaptation to ISDN. */
#define USBD_CDC_DATA_PROTOCOL_CAPI 0x93u /* CAPI commands. */
#define USBD_CDC_DATA_PROTOCOL_HOST 0xFDu /* Host based drivers. */
#define USBD_CDC_DATA_PROTOCOL_CDC 0xFEu /* The protocol(s) are described using a protocol ... */
/* ... unit functional descriptors on communications... */
/* ... class. */
#define USBD_CDC_DATA_PROTOCOL_VENDOR 0xFFu /* Vendor-specific. */
/*
*********************************************************************************************************
* MANAGEMENT ELEMENTS REQUESTS DEFINES
*
* Note(s) : (1) Management elements requests are defined in table 19 from the CDC specification
* revision 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_REQ_SEND_ENCAP_COMM 0x00u
#define USBD_CDC_REQ_GET_ENCAP_RESP 0x01u
#define USBD_CDC_REQ_SET_COMM_FEATURE 0x02u
#define USBD_CDC_REQ_GET_COMM_FEATURE 0x03u
#define USBD_CDC_REQ_CLR_COMM_FEATURE 0x04u
#define USBD_CDC_REQ_SET_AUX_LINE_STATE 0x10u
#define USBD_CDC_REQ_SET_HOOK_STATE 0x11u
#define USBD_CDC_REQ_PULSE_SETUP 0x12u
#define USBD_CDC_REQ_SEND_PULSE 0x13u
#define USBD_CDC_REQ_SET_PULSE_TIME 0x14u
#define USBD_CDC_REQ_RING_AUX_JACK 0x15u
#define USBD_CDC_REQ_SET_LINE_CODING 0x20u
#define USBD_CDC_REQ_GET_LINE_CODING 0x21u
#define USBD_CDC_REQ_SET_CTRL_LINE_STATE 0x22u
#define USBD_CDC_REQ_SEND_BREAK 0x23u
#define USBD_CDC_REQ_SET_RINGER_PAARMS 0x30u
#define USBD_CDC_REQ_GET_RINGER_PARAMS 0x31u
#define USBD_CDC_REQ_SET_OPERATION_PARAMS 0x32u
#define USBD_CDC_REQ_GET_OPERATION_PARAMS 0x33u
#define USBD_CDC_REQ_SET_LINE_PARAMS 0x34u
#define USBD_CDC_REQ_GET_LINE_PARAMS 0x35u
#define USBD_CDC_REQ_DIAL_DIGITS 0x36u
#define USBD_CDC_REQ_SET_UNIT_PARAM 0x37u
#define USBD_CDC_REQ_GET_UNIT_PARAM 0x38u
#define USBD_CDC_REQ_CLR_UNUT_PARAM 0x39u
#define USBD_CDC_REQ_GET_PROFILE 0x3Au
#define USBD_CDC_REQ_SET_ETHER_MULTI_FILTER 0x40u
#define USBD_CDC_REQ_SET_ETHER_PWR_MGT_FILTER 0x41u
#define USBD_CDC_REQ_GET_ETHER_PWR_MGT_FILTER 0x42u
#define USBD_CDC_REQ_SET_ETHER_PKT_FILTER 0x43u
#define USBD_CDC_REQ_GET_ETHER_STAT 0x44u
#define USBD_CDC_REQ_SET_ATM_DATA_FMT 0x50u
#define USBD_CDC_REQ_GET_ATM_DATA_FMT 0x51u
#define USBD_CDC_REQ_GET_ATM_DEV_STAT 0x52u
#define USBD_CDC_REQ_SET_ATM_DFLT_VC 0x53u
#define USBD_CDC_REQ_GET_ATM_VC_STAT 0x54u
#define USBD_CDC_REQ_GET_NTB_PARAM 0x80u
#define USBD_CDC_REQ_GET_NET_ADDR 0x81u
#define USBD_CDC_REQ_SET_NET_ADDR 0x82u
#define USBD_CDC_REQ_GET_NTB_FMT 0x83u
#define USBD_CDC_REQ_SET_NTB_FMT 0x84u
#define USBD_CDC_REQ_GET_NTB_INPUT_SIZE 0x85u
#define USBD_CDC_REQ_SET_NTB_INPUT_SIZE 0x86u
#define USBD_CDC_REQ_GET_MAX_DATAGRAM_SIZE 0x87u
#define USBD_CDC_REQ_SET_MAX_DATAGRAM_SIZE 0x88u
#define USBD_CDC_REQ_GET_CRC_MODE 0x89u
#define USBD_CDC_REQ_SET_CRC_MODE 0x8Au
/*
*********************************************************************************************************
* CDC FUNCTIONAL DESCRIPTOR TYPE DEFINES
*
* Note(s) : (1) Functional descriptors types are defined in table 12 from the CDC specification revision
* 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_DESC_TYPE_CS_IF 0x24u
#define USBD_CDC_DESC_TYPE_CS_EP 0x25u
/*
*********************************************************************************************************
* CDC FUNCTIONAL DESCRIPTOR SUBTYPE DEFINES
*
* Note(s) : (1) Functional descriptors subtypes are defined in table 13 from the CDC specification
* revision 1.2.
*********************************************************************************************************
*/
#define USBD_CDC_DESC_SUBTYPE_HEADER 0x00u /* Header functional descriptor, which marks the ... */
/* ... beginning of the concatenated set of ... */
/* ... functional descriptors for the interface. */
#define USBD_CDC_DESC_SUBTYPE_CALL_MGMT 0x01u /* Call management functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_ACM 0x02u /* Abstract control management functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_DLM 0x03u /* Direct line management functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_TEL_RINGER 0x04u /* Telephone Ringer functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_TEL_CALL_LINE 0x05u /* Telephone call and line state reporting ... */
/* ... capabilities functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_UNION 0x06u /* Union functional descriptor. */
#define USBD_CDC_DESC_SUBTYPE_COUNTRY_SEL 0x07u /* Country selection functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_TEL_OPERA 0x08u /* Telephone operational modes functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_USB_TERM 0x09u /* USB terminal functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_NET_CH_TERM 0x0Au /* Network channel terminal descriptor. */
#define USBD_CDC_DESC_SUBTYPE_PROTOCOL_UNIT 0x0Bu /* Protocol unit functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_EXT_UNIT 0x0Cu /* Extension unit functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_MULTI_CH_MGMT 0x0Du /* Multi-Channel management functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_CAPI_CTRL 0x0Eu /* CAPI control management functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_ETHER_NET 0x0Fu /* Ethernet networking functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_ATM_NET 0x10u /* ATM networking functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_WIRELESS_CTRL 0x11u /* Wireless handset control model functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_MOBILE DLM 0x12u /* Mobile Direct Line Model functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_DETAIL 0x13u /* MDLM Detail functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_DEV_MGMT 0x14u /* Device management model functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_OBEX 0x15u /* OBEX functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_CMD_SET 0x16u /* Command set functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_CMD_SET_DETAIL 0x17u /* Command set detail functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_TCM 0x18u /* Telephone control model functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_OBEX_SERV 0x19u /* OBEX service identifier functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_NCM 0x1Au /* NCM functional descriptor.*/
#define USBD_CDC_DESC_SUBTYPE_VENDOR 0xFEu /* Vendor specific. */
/*
*********************************************************************************************************
* CDC NOTIFIACTION DEFINES
*
* Note(s) : (1) Refer to Table 20: Class-Specific Notification Codes in 6.3 Management Element
* Notifications, CDC spec.
*********************************************************************************************************
*/
#define USBD_CDC_NOTIFICATION_HEADER 8u
#define USBD_CDC_NTF_SPEED_DATA_LEN 8u
#define USBD_CDC_NTF_NETWORK_CONNECTION 0x00u
#define USBD_CDC_NTF_RESPONSE_AVAILABLE 0x01u
#define USBD_CDC_NTF_SERIAL_STATE 0x20u
#define USBD_CDC_NTF_SPEED_CHANGE 0x2Au
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CDC SUBCLASS DRIVER
*********************************************************************************************************
*/
typedef const struct usbd_cdc_subclass_drv {
/* Callback to handle management requests. */
CPU_BOOLEAN (*MngmtReq) ( CPU_INT08U dev_nbr,
const USBD_SETUP_REQ *p_setup_req,
void *p_subclass_arg);
/* Callback to handle notification completion. */
void (*NotifyCmpl) ( CPU_INT08U dev_nbr,
void *p_subclass_arg);
/* Callback to build functional desc. */
void (*FnctDesc) ( CPU_INT08U dev_nbr,
void *p_subclass_arg,
CPU_INT08U first_dci_if_nbr);
/* Callback to get the size of the functional desc. */
CPU_INT16U (*FnctDescSizeGet)( CPU_INT08U dev_nbr,
void *p_subclass_arg);
/* Callback to handle alternate setting event. */
void (*DataAltSet) ( CPU_INT08U dev_nbr,
void *p_subclass_arg,
CPU_INT08U if_alt_nbr);
#if (USBD_CFG_MS_OS_DESC_EN == DEF_ENABLED)
/* Callback to get subclass MS ext properties. */
CPU_INT08U (*FnctMSExtPropertyTbl)( CPU_INT08U dev_nbr,
void *p_subclass_arg,
USBD_MS_OS_EXT_PROPERTY **pp_ext_property_tbl);
#endif
} USBD_CDC_SUBCLASS_DRV;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_CDC_Init (USBD_ERR *p_err);
CPU_INT08U USBD_CDC_Add (CPU_INT08U subclass,
USBD_CDC_SUBCLASS_DRV *p_subclass_drv,
void *p_subclass_arg,
CPU_INT08U protocol,
CPU_BOOLEAN notify_en,
CPU_INT16U notify_interval,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_CDC_CfgAdd (CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
const CPU_CHAR *comm_name,
const CPU_CHAR *data_name,
const CPU_CHAR *grp_name,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_CDC_IsConn (CPU_INT08U class_nbr);
/* ---------- DATA INTERFACE CLASS FUNCTIONS ---------- */
CPU_INT08U USBD_CDC_DataIF_Add(CPU_INT08U class_nbr,
CPU_BOOLEAN isoc_en,
CPU_INT08U protocol,
USBD_ERR *p_err);
CPU_INT32U USBD_CDC_DataRx (CPU_INT08U class_nbr,
CPU_INT08U data_if_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
CPU_INT32U USBD_CDC_DataTx (CPU_INT08U class_nbr,
CPU_INT08U data_if_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_CDC_DataRxAsync (CPU_INT08U class_nbr,
CPU_INT08U data_if_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
USBD_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
void USBD_CDC_DataTxAsync (CPU_INT08U class_nbr,
CPU_INT08U data_if_nbr,
CPU_INT08U *p_buf,
CPU_INT32U buf_len,
USBD_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
/* ------------- NOTIFICATION FUNCTIONS -------------- */
CPU_BOOLEAN USBD_CDC_Notify (CPU_INT08U class_nbr,
CPU_INT08U notification,
CPU_INT16U value,
CPU_INT08U *p_buf,
CPU_INT16U data_len,
USBD_ERR *p_err);
#if 0
void USBD_CDC_GrpCreate (CPU_INT08 class_nbr,
USBD_ERR *p_err);
void USBD_CDC_GrpAdd (CPU_INT08U class_nbr,
CPU_INT08U nbr_slave,
USBD_ERR *p_err);
#endif
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_CDC_CFG_MAX_NBR_DEV
#error "USBD_CDC_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif ((USBD_CDC_CFG_MAX_NBR_DEV < 1u ) || \
(USBD_CDC_CFG_MAX_NBR_DEV >= USBD_IF_NBR_NONE))
#error "USBD_CDC_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_CDC_CFG_MAX_NBR_CFG
#error "USBD_CDC_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif ((USBD_CDC_CFG_MAX_NBR_CFG < 1u ) || \
(USBD_CDC_CFG_MAX_NBR_CFG >= USBD_CFG_NBR_NONE))
#error "USBD_CDC_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_CDC_CFG_MAX_NBR_DATA_IF
#error "USBD_CDC_CFG_MAX_NBR_DATA_IF not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#elif ((USBD_CDC_CFG_MAX_NBR_DATA_IF < 1u ) || \
(USBD_CDC_CFG_MAX_NBR_DATA_IF >= USBD_IF_NBR_NONE))
#error "USBD_CDC_CFG_MAX_NBR_DATA_IF illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
/*
**********************************************************************************************************
* MODULE END
**********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,245 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE OPERATING SYSTEM LAYER
* For CMSIS OS2
*
* Filename : usbd_fb_os.c
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../usbd_fb.h"
#include "../../usbd_fb_os.h"
#include <FreeRTOS.h>
#include <udelay/udelay.h>
#include "task.h"
#include "event_groups.h"
#include "semphr.h"
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static SemaphoreHandle_t USBD_FB_OS_EnumSignal;
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
#define fbd_os_err(...) ssdk_printf(SSDK_CRIT, __VA_ARGS__)
#define IS_IRQ_MASKED arch_irq_is_masked
#define IS_IRQ_MODE arch_in_irq_mode
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void USBD_FB_OS_Task (void *p_arg);
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_FB_OS_Init()
*
* Description : Initialize FastBoot OS interface.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS initialization successful.
* USBD_ERR_OS_FAIL OS objects NOT successfully initialized.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_FB_OS_Init (USBD_ERR *p_err)
{
TaskHandle_t thread;
USBD_FB_OS_EnumSignal = xSemaphoreCreateCounting(10000u, 0);
if (!USBD_FB_OS_EnumSignal) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
if (xTaskCreate(USBD_FB_OS_Task, "USBD FB Tsk", 1024u, NULL, (configMAX_PRIORITIES - 6), &thread) != pdPASS) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_FB_OS_Task()
*
* Description : OS-dependent shell task to process FastBoot task
*
* Argument(s) : p_arg Pointer to task initialization argument (required by CMSIS OS2).
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
static void USBD_FB_OS_Task (void *p_arg)
{
CPU_INT08U class_nbr;
class_nbr = (CPU_INT08U)(CPU_ADDR)p_arg;
USBD_FB_TaskHandler(class_nbr);
}
/*
*********************************************************************************************************
* USBD_FB_OS_EnumSignalPost()
*
* Description : Post a semaphore for FastBoot enumeration process.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully posted.
* USBD_ERR_OS_FAIL OS signal NOT successfully posted.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_FB_OS_EnumSignalPost (USBD_ERR *p_err)
{
if (xSemaphoreGive(USBD_FB_OS_EnumSignal) != pdPASS) {
fbd_os_err("Err @%d, %s\n", __LINE__, __func__);
*p_err = USBD_ERR_OS_FAIL;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_FB_OS_EnumSignalPend()
*
* Description : Wait on a semaphore to become available for FastBoot enumeration process.
*
* Argument(s) : timeout Timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
* USBD_ERR_NONE The call was successful and your task owns the resource
* or, the event you are waiting for occurred.
* USBD_ERR_OS_TIMEOUT The semaphore was not received within the specified timeout.
* USBD_ERR_OS_FAIL otherwise.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_FB_OS_EnumSignalPend (CPU_INT32U timeout,
USBD_ERR *p_err)
{
BaseType_t ret;
uint32_t tmo;
tmo = timeout ? timeout : portMAX_DELAY;
ret = xSemaphoreTake(USBD_FB_OS_EnumSignal, tmo);
switch (ret) {
case pdPASS:
*p_err = USBD_ERR_NONE;
break;
case pdFAIL:
default:
if (tmo > 0) {
*p_err = USBD_ERR_OS_TIMEOUT;
} else {
*p_err = USBD_ERR_OS_FAIL;
fbd_os_err("Err @%d, %s\n", __LINE__, __func__);
}
break;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,191 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE FASTBOOT CLASS
*
* Filename : usbd_fb.h
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_FB_MODULE_PRESENT
#define USBD_FB_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define MAX_RSP_SIZE 64u
/*
**********************************************************************************************************
* DATA TYPES
**********************************************************************************************************
*/
typedef void (*USBD_FB_CMD_HDL)(unsigned char *fb_cls, const char *arg, void *data, unsigned int sz);
typedef struct usbd_fb_cmd {
const char *cmd;
USBD_FB_CMD_HDL handler;
} USBD_FB_CMD;
typedef struct usbd_fb_var {
const char *name;
const char *value;
} USBD_FB_VAR;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_FB_Init ( USBD_ERR *p_err);
CPU_INT08U USBD_FB_Add ( USBD_ERR *p_err);
CPU_BOOLEAN USBD_FB_CfgAdd ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_FB_SetDL ( CPU_INT08U class_nbr,
void *download_addr,
CPU_INT32U download_max,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_FB_SetCmdTbl ( CPU_INT08U class_nbr,
const USBD_FB_CMD *cmd_tbl,
CPU_INT16U cmd_len,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_FB_SetVarTbl ( CPU_INT08U class_nbr,
const USBD_FB_VAR *var_tbl,
CPU_INT16U var_len,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_FB_IsConn ( CPU_INT08U class_nbr);
#if CONFIG_OS
void USBD_FB_TaskHandler( CPU_INT08U class_nbr);
#else
void USBD_FB_TaskLoop ( CPU_INT08U class_nbr);
#endif
void USBD_FB_Ack ( unsigned char *fb_cls,
const char *code,
const char *reason);
void USBD_FB_Info ( unsigned char *fb_cls,
const char *reason);
void USBD_FB_Fail ( unsigned char *fb_cls,
const char *reason);
void USBD_FB_Okay ( unsigned char *fb_cls,
const char *info);
void USBD_FB_CmdGetVar ( unsigned char *fb_cls,
const char *arg,
void *data,
unsigned sz);
void USBD_FB_CmdFlash ( unsigned char *fb_cls,
const char *arg,
void *data,
unsigned sz);
void USBD_FB_CmdDownload ( unsigned char *fb_cls,
const char *arg,
void *data,
unsigned sz);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_FB_CFG_MAX_NBR_DEV
#error "USBD_FB_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_FB_CFG_MAX_NBR_DEV < 1u)
#error "USBD_FB_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_FB_CFG_MAX_NBR_CFG
#error "USBD_FB_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_FB_CFG_MAX_NBR_CFG < 1u)
#error "USBD_FB_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,103 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB FB CLASS OPERATING SYSTEM LAYER
*
* Filename : usbd_fb_os.h
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_FB_OS_MODULE_PRESENT
#define USBD_FB_OS_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_FB_OS_Init (USBD_ERR *p_err);
void USBD_FB_OS_EnumSignalPost(USBD_ERR *p_err);
void USBD_FB_OS_EnumSignalPend(CPU_INT32U timeout,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,679 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB HID CLASS OPERATING SYSTEM LAYER
* For CMSIS OS2
*
* Filename : usbd_hid_os.c
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../../../Source/usbd_core.h"
#include "../../usbd_hid_report.h"
#include "../../usbd_hid_os.h"
#include <cmsis_os2.h>
#include <driver/irq.h>
#include <debug.h>
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define HID_DATA_EVENT_POST (1u<<0)
#define HID_DATA_EVENT_ABORT (1u<<1)
#define HID_DATA_EVENT_ALL (HID_DATA_EVENT_POST | HID_DATA_EVENT_ABORT)
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ---------------- USB HID SEM OBJECTS --------------- */
static osEventFlagsId_t USBD_HID_OS_InputDataSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static volatile CPU_INT32U USBD_HID_OS_InDataSemCnt_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static osSemaphoreId_t USBD_HID_OS_InputLockSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static osSemaphoreId_t USBD_HID_OS_TxSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static osSemaphoreId_t USBD_HID_OS_OutputLockSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static osEventFlagsId_t USBD_HID_OS_OutputDataSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static volatile CPU_INT32U USBD_HID_OS_OutDataSemCnt_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
static osThreadId_t USBD_HID_OS_TmrTaskID;
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
#define hidd_os_err(...) ssdk_printf(SSDK_CRIT, __VA_ARGS__)
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void USBD_HID_OS_TmrTask(void *p_arg);
/*
*********************************************************************************************************
* USBD_HID_OS_Init()
*
* Description : Initialize HID OS interface.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE HID OS initialization successful.
* USBD_ERR_OS_SIGNAL_CREATE HID OS objects NOT successfully initialized.
* USBD_ERR_OS_INIT_FAIL HID OS task NOT successfully initialized.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_Init (USBD_ERR *p_err)
{
CPU_INT08U class_nbr;
osThreadId_t thread;
osThreadAttr_t attr = {
.name = "USBD HID Tmr Tsk",
.stack_size = 4096,
.priority = osPriorityAboveNormal3,
};
for (class_nbr = 0; class_nbr < USBD_HID_CFG_MAX_NBR_DEV; class_nbr++) {
USBD_HID_OS_TxSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
if (!USBD_HID_OS_TxSem_Tbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_HID_OS_OutputLockSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
if (!USBD_HID_OS_OutputLockSem_Tbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_HID_OS_OutputDataSem_Tbl[class_nbr] = osEventFlagsNew(NULL);
if (!USBD_HID_OS_OutputDataSem_Tbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr] = 0;
USBD_HID_OS_InputLockSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
if (!USBD_HID_OS_InputLockSem_Tbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_HID_OS_InputDataSem_Tbl[class_nbr] = osEventFlagsNew(NULL);
if (!USBD_HID_OS_InputDataSem_Tbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr] = 0;
}
thread = osThreadNew(USBD_HID_OS_TmrTask, NULL, &attr);
if (!thread) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
USBD_HID_OS_TmrTaskID = thread;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_HID_OS_TmrTask()
*
* Description : OS-dependent shell task to process periodic HID input reports.
*
* Argument(s) : p_arg Pointer to task initialization argument (required by CMSIS OS2).
*
* Return(s) : none.
*
* Note(s) : (1) Assumes OSCfg_TickRate_Hz frequency is greater than or equal to 250 Hz. Otherwise,
* timer task scheduling rate will NOT be correct.
*
* (2) Timer task MUST delay without failure.
*
* (a) Failure to delay timer task will prevent some HID report task(s)/operation(s) from
* functioning correctly. Thus, timer task is assumed to be successfully delayed
* since NO error handling could be performed to counteract failure.
*********************************************************************************************************
*/
static void USBD_HID_OS_TmrTask (void *p_arg)
{
while (DEF_ON) {
osDelay(4);
USBD_HID_Report_TmrTaskHandler();
}
}
/*
*********************************************************************************************************
* USBD_HID_OS_InputLock()
*
* Description : Lock class input report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE Class input report successfully locked.
* USBD_ERR_OS_ABORT Class input report aborted.
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_InputLock (CPU_INT08U class_nbr,
USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreAcquire(USBD_HID_OS_InputLockSem_Tbl[class_nbr], osWaitForever);
switch (ret) {
case osOK:
*p_err = USBD_ERR_NONE;
break;
default:
*p_err = USBD_ERR_OS_FAIL;
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
break;
}
}
/*
*********************************************************************************************************
* USBD_HID_OS_InputUnlock()
*
* Description : Unlock class input report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_InputUnlock (CPU_INT08U class_nbr)
{
osStatus_t ret;
ret = osSemaphoreRelease(USBD_HID_OS_InputLockSem_Tbl[class_nbr]);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_OutputDataPendAbort()
*
* Description : Abort class output report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_OutputDataPendAbort (CPU_INT08U class_nbr)
{
int32_t ret;
ret = osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ABORT);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_OutputDataPend()
*
* Description : Wait for output report data transfer to complete.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* timeout_ms Signal wait timeout, in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE Class output successfully locked.
* USBD_ERR_OS_ABORT Class output aborted.
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_OutputDataPend (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
int32_t ret;
uint32_t tmo;
uint32_t tk_start, tk_current;
CPU_INT32U cnt;
CPU_SR_ALLOC();
tk_start = osKernelGetTickCount();
tk_current = tk_start;
do {
tmo = timeout_ms ? (tk_start + timeout_ms - tk_current): osWaitForever;
ret = osEventFlagsWait(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ALL, 0, tmo);
if (ret < 0) {
switch (ret) {
case osErrorTimeout:
*p_err = USBD_ERR_OS_TIMEOUT;
return;
default:
*p_err = USBD_ERR_OS_FAIL;
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
return;
}
} else if (ret & HID_DATA_EVENT_ABORT) {
*p_err = USBD_ERR_OS_ABORT;
return;
}
CPU_CRITICAL_ENTER();
cnt = USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr];
if (cnt)
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr] = cnt - 1;
CPU_CRITICAL_EXIT();
if (cnt > 1) {
osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
}
if (cnt) {
*p_err = USBD_ERR_NONE;
return;
}
tk_current = osKernelGetTickCount();
} while (!timeout_ms || (tk_current - tk_start <= timeout_ms));
*p_err = USBD_ERR_OS_TIMEOUT;
return;
}
/*
*********************************************************************************************************
* USBD_HID_OS_OutputDataPost()
*
* Description : Signal that output report data is available.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_OutputDataPost (CPU_INT08U class_nbr)
{
int32_t ret;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr]++;
CPU_CRITICAL_EXIT();
ret = osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_OutputLock()
*
* Description : Lock class output report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE Class output successfully locked.
* USBD_ERR_OS_ABORT Class output aborted.
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_OutputLock (CPU_INT08U class_nbr,
USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreAcquire(USBD_HID_OS_OutputLockSem_Tbl[class_nbr], osWaitForever);
switch (ret) {
case osOK:
*p_err = USBD_ERR_NONE;
break;
default:
*p_err = USBD_ERR_OS_FAIL;
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
break;
}
}
/*
*********************************************************************************************************
* USBD_HID_OS_OutputUnlock()
*
* Description : Unlock class output report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_OutputUnlock (CPU_INT08U class_nbr)
{
osStatus_t ret;
ret = osSemaphoreRelease(USBD_HID_OS_OutputLockSem_Tbl[class_nbr]);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_TxLock()
*
* Description : Lock class transmit.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE Class feature report successfully locked.
* USBD_ERR_OS_ABORT Class feature report aborted.
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_TxLock (CPU_INT08U class_nbr,
USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreAcquire(USBD_HID_OS_TxSem_Tbl[class_nbr], osWaitForever);
switch (ret) {
case osOK:
*p_err = USBD_ERR_NONE;
break;
default:
*p_err = USBD_ERR_OS_FAIL;
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
break;
}
}
/*
*********************************************************************************************************
* USBD_HID_OS_TxUnlock()
*
* Description : Unlock class transmit.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_TxUnlock (CPU_INT08U class_nbr)
{
osStatus_t ret;
ret = osSemaphoreRelease(USBD_HID_OS_TxSem_Tbl[class_nbr]);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_InputDataPend()
*
* Description : Wait for input report data transfer to complete.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* timeout_ms Signal wait timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully acquired.
* USBD_ERR_OS_TIMEOUT OS signal NOT successfully acquired in the time
* specified by 'timeout_ms'.
* USBD_ERR_OS_ABORT OS signal aborted.
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_InputDataPend (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
int32_t ret;
uint32_t tmo;
uint32_t tk_start, tk_current;
CPU_INT32U cnt;
CPU_SR_ALLOC();
tk_start = osKernelGetTickCount();
tk_current = tk_start;
do {
tmo = timeout_ms ? (tk_start + timeout_ms - tk_current): osWaitForever;
ret = osEventFlagsWait(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ALL, 0, tmo);
if (ret < 0) {
switch (ret) {
case osErrorTimeout:
*p_err = USBD_ERR_OS_TIMEOUT;
return;
default:
*p_err = USBD_ERR_OS_FAIL;
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
return;
}
} else if (ret & HID_DATA_EVENT_ABORT) {
*p_err = USBD_ERR_OS_ABORT;
return;
}
CPU_CRITICAL_ENTER();
cnt = USBD_HID_OS_InDataSemCnt_Tbl[class_nbr];
if (cnt)
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr] = cnt - 1;
CPU_CRITICAL_EXIT();
if (cnt > 1) {
osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
}
if (cnt) {
*p_err = USBD_ERR_NONE;
return;
}
tk_current = osKernelGetTickCount();
} while (!timeout_ms || (tk_current - tk_start <= timeout_ms));
*p_err = USBD_ERR_OS_TIMEOUT;
return;
}
/*
*********************************************************************************************************
* USBD_HID_OS_InputDataPendAbort()
*
* Description : Abort any operation on input report.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_InputDataPendAbort (CPU_INT08U class_nbr)
{
int32_t ret;
ret = osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ABORT);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}
/*
*********************************************************************************************************
* USBD_HID_OS_InputDataPost()
*
* Description : Signal that input report data transfer has completed.
*
* Argument(s) : class_nbr Class instance number.
* --------- Argument validated by the caller(s).
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_HID_OS_InputDataPost (CPU_INT08U class_nbr)
{
int32_t ret;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr]++;
CPU_CRITICAL_EXIT();
ret = osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
if (ret < 0)
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,265 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE HID CLASS
*
* Filename : usbd_hid.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_HID_MODULE_PRESENT
#define USBD_HID_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
#include "usbd_hid_report.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_HID_MODULE
#define USBD_HID_EXT
#else
#define USBD_HID_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices (HID), 6/27/01, Version 1.11',
* section 6.2.1 for more details about HID descriptor country code.
*
* (a) The country code identifies which country the hardware is localized for. Most
* hardware is not localized and thus this value would be zero (0). However, keyboards
* may use the field to indicate the language of the key caps.
*********************************************************************************************************
*/
/* ------------ COUNTRY CODES (see Note #1) ----------- */
typedef enum usbd_hid_country_code {
USBD_HID_COUNTRY_CODE_NOT_SUPPORTED = 0u, /* See Note #1a. */
USBD_HID_COUNTRY_CODE_ARABIC = 1u,
USBD_HID_COUNTRY_CODE_BELGIAN = 2u,
USBD_HID_COUNTRY_CODE_CANADIAN_BILINGUAL = 3u,
USBD_HID_COUNTRY_CODE_CANADIAN_FRENCH = 4u,
USBD_HID_COUNTRY_CODE_CZECH_REPUBLIC = 5u,
USBD_HID_COUNTRY_CODE_DANISH = 6u,
USBD_HID_COUNTRY_CODE_FINNISH = 7u,
USBD_HID_COUNTRY_CODE_FRENCH = 8u,
USBD_HID_COUNTRY_CODE_GERMAN = 9u,
USBD_HID_COUNTRY_CODE_GREEK = 10u,
USBD_HID_COUNTRY_CODE_HEBREW = 11u,
USBD_HID_COUNTRY_CODE_HUNGARY = 12u,
USBD_HID_COUNTRY_CODE_INTERNATIONAL = 13u,
USBD_HID_COUNTRY_CODE_ITALIAN = 14u,
USBD_HID_COUNTRY_CODE_JAPAN_KATAKANA = 15u,
USBD_HID_COUNTRY_CODE_KOREAN = 16u,
USBD_HID_COUNTRY_CODE_LATIN_AMERICAN = 17u,
USBD_HID_COUNTRY_CODE_NETHERLANDS_DUTCH = 18u,
USBD_HID_COUNTRY_CODE_NORWEGIAN = 19u,
USBD_HID_COUNTRY_CODE_PERSIAN_FARSI = 20u,
USBD_HID_COUNTRY_CODE_POLAND = 21u,
USBD_HID_COUNTRY_CODE_PORTUGUESE = 22u,
USBD_HID_COUNTRY_CODE_RUSSIA = 23u,
USBD_HID_COUNTRY_CODE_SLOVAKIA = 24u,
USBD_HID_COUNTRY_CODE_SPANISH = 25u,
USBD_HID_COUNTRY_CODE_SWEDISH = 26u,
USBD_HID_COUNTRY_CODE_SWISS_FRENCH = 27u,
USBD_HID_COUNTRY_CODE_SWISS_GERMAN = 28u,
USBD_HID_COUNTRY_CODE_SWITZERLAND = 29u,
USBD_HID_COUNTRY_CODE_TAIWAN = 30u,
USBD_HID_COUNTRY_CODE_TURKISH_Q = 31u,
USBD_HID_COUNTRY_CODE_UK = 32u,
USBD_HID_COUNTRY_CODE_US = 33u,
USBD_HID_COUNTRY_CODE_YUGOSLAVIA = 34u,
USBD_HID_COUNTRY_CODE_TURKISH_F = 35u
} USBD_HID_COUNTRY_CODE;
/*
*********************************************************************************************************
* HUMAN INTERFACE DEVICE CLASS SUBCLASS CODES DEFINES
*
* Note(s) : (1) Human interface device class subclass codes are defined in section 4.2 of HID
* specification revision 1.11.
*********************************************************************************************************
*/
#define USBD_HID_SUBCLASS_NONE 0x00u /* No subclass. */
#define USBD_HID_SUBCLASS_BOOT 0x01u /* Boot interface. */
/*
*********************************************************************************************************
* HUMAN INTERFACE DEVICE CLASS PROTOCOL CODES DEFINES
*
* Note(s) : (1) Human interface device class protocol codes are defined in section 4.3 of HID
* specification revision 1.11.
*********************************************************************************************************
*/
#define USBD_HID_PROTOCOL_NONE 0x00u /* No class specific protocol. */
#define USBD_HID_PROTOCOL_KBD 0x01u /* Keyboard protocol. */
#define USBD_HID_PROTOCOL_MOUSE 0x02u /* Mouse protocol. */
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/* Async comm callback. */
typedef void (*USBD_HID_ASYNC_FNCT)(CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT32U xfer_len,
void *p_callback_arg,
USBD_ERR err);
/* HID desc and req callbacks. */
typedef const struct usbd_hid_callback {
CPU_BOOLEAN (*FeatureReportGet)(CPU_INT08U class_nbr,
CPU_INT08U report_id,
CPU_INT08U *p_report_buf,
CPU_INT16U report_len);
CPU_BOOLEAN (*FeatureReportSet)(CPU_INT08U class_nbr,
CPU_INT08U report_id,
CPU_INT08U *p_report_buf,
CPU_INT16U report_len);
CPU_INT08U (*ProtocolGet) (CPU_INT08U class_nbr,
USBD_ERR *p_err);
void (*ProtocolSet) (CPU_INT08U class_nbr,
CPU_INT08U protocol,
USBD_ERR *p_err);
void (*ReportSet) (CPU_INT08U class_nbr,
CPU_INT08U report_id,
CPU_INT08U *p_report_buf,
CPU_INT16U report_len);
} USBD_HID_CALLBACK;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/* HID class initialization. */
void USBD_HID_Init (USBD_ERR *p_err);
/* Add new instance of the HID class. */
CPU_INT08U USBD_HID_Add (CPU_INT08U subclass,
CPU_INT08U protocol,
USBD_HID_COUNTRY_CODE country_code,
CPU_INT08U *p_report_desc,
CPU_INT16U report_desc_len,
CPU_INT08U *p_phy_desc,
CPU_INT16U phy_desc_len,
CPU_INT16U interval_in,
CPU_INT16U interval_out,
CPU_BOOLEAN ctrl_rd_en,
USBD_HID_CALLBACK *p_hid_callback,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_HID_CfgAdd (CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_HID_IsConn (CPU_INT08U class_nbr);
CPU_INT32U USBD_HID_Wr (CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_HID_WrAsync(CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_HID_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
CPU_INT32U USBD_HID_Rd (CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_HID_RdAsync(CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_HID_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,137 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB HID CLASS OPERATING SYSTEM LAYER
*
* Filename : usbd_hid_os.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_HID_OS_MODULE_PRESENT
#define USBD_HID_OS_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_HID_OS_Init (USBD_ERR *p_err);
void USBD_HID_OS_InputLock (CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_HID_OS_InputUnlock (CPU_INT08U class_nbr);
void USBD_HID_OS_InputDataPend (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err);
void USBD_HID_OS_InputDataPendAbort (CPU_INT08U class_nbr);
void USBD_HID_OS_InputDataPost (CPU_INT08U class_nbr);
void USBD_HID_OS_OutputLock (CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_HID_OS_OutputUnlock (CPU_INT08U class_nbr);
void USBD_HID_OS_OutputDataPendAbort(CPU_INT08U class_nbr);
void USBD_HID_OS_OutputDataPend (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err);
void USBD_HID_OS_OutputDataPost (CPU_INT08U class_nbr);
void USBD_HID_OS_TxLock (CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_HID_OS_TxUnlock (CPU_INT08U class_nbr);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,391 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE HID REPORT
*
* Filename : usbd_hid_report.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_HID_REPORT_MODULE_PRESENT
#define USBD_HID_REPORT_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_HID_REPORT_MODULE
#define USBD_HID_REPORT_EXT
#else
#define USBD_HID_REPORT_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices (HID), 6/27/01, Version 1.11'
* for more details about :
*
* (a) SHORT ITEM TYPES (Section 6.2.2.2)
*
* (e) MAIN ITEMS (Section 6.2.2.4)
*
* (f) INPUT/OUTPUT/FEATURE ITEMS (Section 6.2.2.5)
*
* (g) COLLECTION ITEMS (Section 6.2.2.6)
*
* (h) GLOBAL ITEMS (Section 6.2.2.7)
*
* (i) LOCAL ITEMS (Section 6.2.2.7)
*********************************************************************************************************
*/
/* ------------------ HID REPORT DESC ----------------- */
#define USBD_HID_ITEM_LONG 0xFE
/* Short item types (see Note #1a). */
#define USBD_HID_ITEM_TYPE_MAIN 0x00
#define USBD_HID_ITEM_TYPE_GLOBAL 0x04
#define USBD_HID_ITEM_TYPE_LOCAL 0x08
#define USBD_HID_ITEM_TYPE_RESERVED 0x0C
/* Main item (see Note #1e). */
#define USBD_HID_MAIN_INPUT 0x80
#define USBD_HID_MAIN_OUTPUT 0x90
#define USBD_HID_MAIN_COLLECTION 0xA0
#define USBD_HID_MAIN_FEATURE 0xB0
#define USBD_HID_MAIN_ENDCOLLECTION 0xC0
/* Input/output/feature item (see Note #1f). */
#define USBD_HID_MAIN_CONSTANT 0x01
#define USBD_HID_MAIN_DATA 0x00
#define USBD_HID_MAIN_VARIABLE 0x02
#define USBD_HID_MAIN_ARRAY 0x00
#define USBD_HID_MAIN_RELATIVE 0x04
#define USBD_HID_MAIN_ABSOLUTE 0x00
#define USBD_HID_MAIN_WRAP 0x08
#define USBD_HID_MAIN_NOWRAP 0x00
#define USBD_HID_MAIN_NONLINEAR 0x10
#define USBD_HID_MAIN_LINEAR 0x00
#define USBD_HID_MAIN_NOPREFERRED 0x20
#define USBD_HID_MAIN_PREFERREDSTATE 0x00
#define USBD_HID_MAIN_NULLSTATE 0x40
#define USBD_HID_MAIN_NONULLPOSITION 0x00
#define USBD_HID_MAIN_VOLATILE 0x80
#define USBD_HID_MAIN_NONVOLATILE 0x00
#define USBD_HID_MAIN_BUFFEREDBYTES 0x0100
#define USBD_HID_MAIN_BITFIELD 0x0000
/* Collection item (see Note #1g). */
#define USBD_HID_COLLECTION_PHYSICAL 0x00
#define USBD_HID_COLLECTION_APPLICATION 0x01
#define USBD_HID_COLLECTION_LOGICAL 0x02
#define USBD_HID_COLLECTION_REPORT 0x03
#define USBD_HID_COLLECTION_NAMEDARRAY 0x04
#define USBD_HID_COLLECTION_USAGESWITCH 0x05
#define USBD_HID_COLLECTION_USAGEMODIFIER 0x06
/* Global item (see Note #1h). */
#define USBD_HID_GLOBAL_USAGE_PAGE 0x04
#define USBD_HID_GLOBAL_LOG_MIN 0x14
#define USBD_HID_GLOBAL_LOG_MAX 0x24
#define USBD_HID_GLOBAL_PHY_MIN 0x34
#define USBD_HID_GLOBAL_PHY_MAX 0x44
#define USBD_HID_GLOBAL_UNIT_EXPONENT 0x54
#define USBD_HID_GLOBAL_UNIT 0x64
#define USBD_HID_GLOBAL_REPORT_SIZE 0x74
#define USBD_HID_GLOBAL_REPORT_ID 0x84
#define USBD_HID_GLOBAL_REPORT_COUNT 0x94
#define USBD_HID_GLOBAL_PUSH 0xA4
#define USBD_HID_GLOBAL_POP 0xB4
/* Local item (see Note #1i). */
#define USBD_HID_LOCAL_USAGE 0x08
#define USBD_HID_LOCAL_USAGE_MIN 0x18
#define USBD_HID_LOCAL_USAGE_MAX 0x28
#define USBD_HID_LOCAL_DESIGNATOR_INDEX 0x38
#define USBD_HID_LOCAL_DESIGNATOR_MIN 0x48
#define USBD_HID_LOCAL_DESIGNATOR_MAX 0x58
#define USBD_HID_LOCAL_STRING_INDEX 0x78
#define USBD_HID_LOCAL_STRING_MIN 0x88
#define USBD_HID_LOCAL_STRING_MAX 0x98
#define USBD_HID_LOCAL_DELIMITER 0xA8
/*
*********************************************************************************************************
* HID PHYSICAL DESCRIPTOR DEFINES
*
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices Version 1.11', Section 6.2.3.
*********************************************************************************************************
*/
/* ---------- HID PHYSICAL DESC (see Note #1) --------- */
/* Bias values. */
#define USBD_HID_BIAS_NOT_APPLICABLE 0
#define USBD_HID_BIAS_RIGHT_HAND 1
#define USBD_HID_BIAS_LEFT_HAND 2
#define USBD_HID_BIAS_BOTH_HANDS 3
#define USBD_HID_BIAS_EITHER_HAND 4
/* Designator values. */
#define USBD_HID_DESIGNATOR_NONE 0x00
#define USBD_HID_DESIGNATOR_HAND 0x01
#define USBD_HID_DESIGNATOR_EYEBALL 0x02
#define USBD_HID_DESIGNATOR_EYEBROW 0x03
#define USBD_HID_DESIGNATOR_EYELID 0x04
#define USBD_HID_DESIGNATOR_EAR 0x05
#define USBD_HID_DESIGNATOR_NOSE 0x06
#define USBD_HID_DESIGNATOR_MOUTH 0x07
#define USBD_HID_DESIGNATOR_UPPER_LIP 0x08
#define USBD_HID_DESIGNATOR_LOWER_LIP 0x09
#define USBD_HID_DESIGNATOR_JAW 0x0A
#define USBD_HID_DESIGNATOR_NECK 0x0B
#define USBD_HID_DESIGNATOR_UPPER_ARM 0x0C
#define USBD_HID_DESIGNATOR_ELBOW 0x0D
#define USBD_HID_DESIGNATOR_FOREARM 0x0E
#define USBD_HID_DESIGNATOR_WRIST 0x0F
#define USBD_HID_DESIGNATOR_PALM 0x10
#define USBD_HID_DESIGNATOR_THUMB 0x11
#define USBD_HID_DESIGNATOR_INDEX_FINGER 0x12
#define USBD_HID_DESIGNATOR_MIDDLE_FINGER 0x13
#define USBD_HID_DESIGNATOR_RING_FINGER 0x14
#define USBD_HID_DESIGNATOR_LITTLE_FINGER 0x15
#define USBD_HID_DESIGNATOR_HEAD 0x16
#define USBD_HID_DESIGNATOR_SHOULDER 0x17
#define USBD_HID_DESIGNATOR_HIP 0x18
#define USBD_HID_DESIGNATOR_WAIST 0x19
#define USBD_HID_DESIGNATOR_THIGH 0x1A
#define USBD_HID_DESIGNATOR_KNEE 0x1B
#define USBD_HID_DESIGNATOR_CALF 0x1C
#define USBD_HID_DESIGNATOR_ANKLE 0x1D
#define USBD_HID_DESIGNATOR_FOOT 0x1E
#define USBD_HID_DESIGNATOR_HEEL 0x1F
#define USBD_HID_DESIGNATOR_BALL_OF_FOOT 0x20
#define USBD_HID_DESIGNATOR_BIG_TOE 0x21
#define USBD_HID_DESIGNATOR_SECOND_TOE 0x22
#define USBD_HID_DESIGNATOR_THIRD_TOE 0x23
#define USBD_HID_DESIGNATOR_FOURTH_TOE 0x24
#define USBD_HID_DESIGNATOR_LITTLE_TOE 0x25
#define USBD_HID_DESIGNATOR_BROW 0x26
#define USBD_HID_DESIGNATOR_CHEEK 0x27
/* Qualifier values. */
#define USBD_HID_QUALIFIER_NOT_APPLICABLE 0
#define USBD_HID_QUALIFIER_RIGHT 1
#define USBD_HID_QUALIFIER_LEFT 2
#define USBD_HID_QUALIFIER_BOTH 3
#define USBD_HID_QUALIFIER_EITHER 4
#define USBD_HID_QUALIFIER_CENTER 5
/*
*********************************************************************************************************
* HID USAGE PAGES
*
* Note(s) : (1) See 'Universal Serial Bus HID Usage Tables', Version 1.12, Section 3 for more details
* about Usage Pages.
*
* (2) See 'Universal Serial Bus HID Usage Tables', Version 1.12, Section 4 for more details
* about Generic Desktop Page usages and controls.
*********************************************************************************************************
*/
/* ------------- USAGE PAGES (see Note #1) ------------ */
#define USBD_HID_USAGE_PAGE_UNDEFINED 0x00
#define USBD_HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS 0x01
#define USBD_HID_USAGE_PAGE_SIMULATION_CONTROLS 0x02
#define USBD_HID_USAGE_PAGE_VR_CONTROLS 0x03
#define USBD_HID_USAGE_PAGE_SPORT_CONTROLS 0x04
#define USBD_HID_USAGE_PAGE_GAME_CONTROLS 0x05
#define USBD_HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS 0x06
#define USBD_HID_USAGE_PAGE_KEYBOARD 0x07
#define USBD_HID_USAGE_PAGE_LEDS 0x08
#define USBD_HID_USAGE_PAGE_BUTTON 0x09
#define USBD_HID_USAGE_PAGE_ORDINAL 0x0A
#define USBD_HID_USAGE_PAGE_TELEPHONY 0x0B
#define USBD_HID_USAGE_PAGE_CONSUMER 0x0C
#define USBD_HID_USAGE_PAGE_DIGITIZER 0x0D
#define USBD_HID_USAGE_PAGE_PID_PAGE 0x0F
#define USBD_HID_USAGE_PAGE_UNICODE 0x10
#define USBD_HID_USAGE_PAGE_ALPHANUMERIC_DISPLAY 0x14
#define USBD_HID_USAGE_PAGE_MEDICAL_INSTRUMENTS 0x40
#define USBD_HID_USAGE_PAGE_MONITOR_0 0x80
#define USBD_HID_USAGE_PAGE_MONITOR_1 0x81
#define USBD_HID_USAGE_PAGE_MONITOR_2 0x82
#define USBD_HID_USAGE_PAGE_MONITOR_3 0x83
#define USBD_HID_USAGE_PAGE_POWER_0 0x84
#define USBD_HID_USAGE_PAGE_POWER_1 0x85
#define USBD_HID_USAGE_PAGE_POWER_2 0x86
#define USBD_HID_USAGE_PAGE_POWER_3 0x87
#define USBD_HID_USAGE_PAGE_BAR_CODE_SCANNER_PAGE 0x8C
#define USBD_HID_USAGE_PAGE_SCALE_PAGE 0x8D
#define USBD_HID_USAGE_PAGE_MSR_DEVICES 0x8E
#define USBD_HID_USAGE_PAGE_POINT_OF_SALE_PAGES 0x8F
#define USBD_HID_USAGE_PAGE_CAMERA_CONTROL_PAGE 0x90
#define USBD_HID_USAGE_PAGE_ARCADE_PAGE 0x91
/* -------- GENERIC DESKTOP PAGE USAGES & CTRL -------- */
/* See Note #2. */
#define USBD_HID_CP_POINTER 0x01
#define USBD_HID_CA_MOUSE 0x02
#define USBD_HID_CA_JOYSTICK 0x04
#define USBD_HID_CA_GAME_PAD 0x05
#define USBD_HID_CA_KEYBOARD 0x06
#define USBD_HID_CA_KEYPAD 0x07
#define USBD_HID_CA_MULTI_AXIS_CONTROLLER 0x08
#define USBD_HID_DV_X 0x30
#define USBD_HID_DV_Y 0x31
#define USBD_HID_DV_Z 0x32
#define USBD_HID_DV_WHEEL 0x38
#define USBD_HID_CA_SYSTEM_CONTROL 0x80
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef enum usbd_hid_report_type {
USBD_HID_REPORT_TYPE_NONE = 0,
USBD_HID_REPORT_TYPE_INPUT,
USBD_HID_REPORT_TYPE_OUTPUT,
USBD_HID_REPORT_TYPE_FEATURE
} USBD_HID_REPORT_TYPE;
typedef struct usbd_hid_report_id USBD_HID_REPORT_ID;
struct usbd_hid_report_id {
CPU_INT08U ID;
CPU_INT16U Size;
CPU_INT08U *DataPtr;
USBD_HID_REPORT_ID *NextPtr;
CPU_INT08U ClassNbr;
CPU_INT08U IdleCnt;
CPU_INT08U IdleRate;
CPU_BOOLEAN Update;
USBD_HID_REPORT_ID *TmrNextPtr;
};
typedef struct usbd_hid_report {
CPU_BOOLEAN HasReports;
CPU_INT16U MaxInputReportSize;
CPU_INT16U MaxFeatureReportSize;
CPU_INT08U *MaxFeatureReportPtr;
CPU_INT16U MaxOutputReportSize;
CPU_INT08U *MaxOutputReportPtr;
USBD_HID_REPORT_ID *Reports[3]; /* Index 0: Input Reports; 1: Output; 2: Feature. */
} USBD_HID_REPORT;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_HID_Report_Init ( USBD_ERR *p_err);
void USBD_HID_Report_Parse ( CPU_INT08U class_nbr,
const CPU_INT08U *p_report_data,
CPU_INT16U report_data_len,
USBD_HID_REPORT *p_report,
USBD_ERR *p_err);
CPU_INT16U USBD_HID_ReportID_InfoGet (const USBD_HID_REPORT *p_report,
USBD_HID_REPORT_TYPE report_type,
CPU_INT08U report_id,
CPU_INT08U **p_buf,
CPU_BOOLEAN *p_is_largest,
USBD_ERR *p_err);
CPU_INT08U USBD_HID_ReportID_IdleGet (const USBD_HID_REPORT *p_report,
CPU_INT08U report_id,
USBD_ERR *p_err);
void USBD_HID_ReportID_IdleSet (const USBD_HID_REPORT *p_report,
CPU_INT08U report_id,
CPU_INT08U idle_rate,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_HID_ReportID_IsLargestIn (const USBD_HID_REPORT *p_report,
CPU_INT08U report_id,
USBD_ERR *p_err);
void USBD_HID_Report_RemoveAllIdle (const USBD_HID_REPORT *p_report);
void USBD_HID_Report_TmrTaskHandler(void);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_HID_CFG_MAX_NBR_REPORT_ID
#error "USBD_HID_CFG_MAX_NBR_REPORT_ID not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_HID_CFG_MAX_NBR_REPORT_ID < 1u)
#error "USBD_HID_CFG_MAX_NBR_REPORT_ID illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP
#error "USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP not #define'd in 'usbd_cfg.h' [MUST be >= 0]"
#endif
#if (USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP < 0)
#error "USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP illegally #define'd in 'usbd_cfg.h' [MUST be >= 0]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,382 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright (c) 2021 Semidrive Semiconductor
*
* All rights reserved.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE OPERATING SYSTEM LAYER
* For CMSIS OS2
*
* Filename : usbd_msc_os.c
* Version : V1.00.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../usbd_msc.h"
#include "../../usbd_msc_os.h"
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
#include "../../Storage/uC-FS/V4/usbd_storage.h"
#endif
#include <cmsis_os2.h>
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
#error "USBD_MSC_CFG_FS_REFRESH_TASK_EN is not supported yet."
#endif
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static osSemaphoreId_t USBD_MSC_OS_TASK_SemTbl[USBD_MSC_CFG_MAX_NBR_DEV];
static osSemaphoreId_t USBD_MSC_OS_EnumSignal;
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
#define mscd_os_err(...) ssdk_printf(SSDK_CRIT, __VA_ARGS__)
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void USBD_MSC_OS_Task (void *p_arg);
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_MSC_OS_Init()
*
* Description : Initialize MSC OS interface.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS initialization successful.
* USBD_ERR_OS_FAIL OS objects NOT successfully initialized.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_Init (USBD_ERR *p_err)
{
CPU_INT08U class_nbr;
osThreadId_t thread;
osThreadAttr_t attr = {
.name = "USBD MSC Tsk",
.stack_size = 4096,
.priority = osPriorityAboveNormal3,
};
/* Create sem for signal used for MSC comm. */
for (class_nbr = 0u; class_nbr < USBD_MSC_CFG_MAX_NBR_DEV; class_nbr++) {
USBD_MSC_OS_TASK_SemTbl[class_nbr] = osSemaphoreNew(10000u, 0, NULL);
if (!USBD_MSC_OS_TASK_SemTbl[class_nbr]) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
}
/* Create sem for signal used for MSC enum. */
USBD_MSC_OS_EnumSignal = osSemaphoreNew(10000u, 0, NULL);
if (!USBD_MSC_OS_EnumSignal) {
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
return;
}
thread = osThreadNew(USBD_MSC_OS_Task, NULL, &attr);
if (!thread) {
*p_err = USBD_ERR_OS_INIT_FAIL;
return;
}
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_MSC_OS_Task()
*
* Description : OS-dependent shell task to process MSC task
*
* Argument(s) : p_arg Pointer to task initialization argument (required by CMSIS OS2).
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
static void USBD_MSC_OS_Task (void *p_arg)
{
CPU_INT08U class_nbr;
class_nbr = (CPU_INT08U)(CPU_ADDR)p_arg;
USBD_MSC_TaskHandler(class_nbr);
}
/*
*********************************************************************************************************
* USBD_MSC_OS_CommSignalPost()
*
* Description : Post a semaphore used for MSC communication.
*
* Argument(s) : class_nbr MSC instance class number
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully posted.
* USBD_ERR_OS_FAIL OS signal NOT successfully posted.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_CommSignalPost (CPU_INT08U class_nbr,
USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreRelease(USBD_MSC_OS_TASK_SemTbl[class_nbr]);
if (ret < 0) {
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
*p_err = USBD_ERR_OS_FAIL;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_MSC_OS_CommSignalPend()
*
* Description : Wait on a semaphore to become available for MSC communication.
*
* Argument(s) : class_nbr MSC instance class number
*
* timeout Timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
* USBD_ERR_NONE The call was successful and your task owns the resource
* or, the event you are waiting for occurred.
* USBD_ERR_OS_TIMEOUT The semaphore was not received within the specified timeout.
* USBD_ERR_OS_FAIL otherwise.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_CommSignalPend (CPU_INT08U class_nbr,
CPU_INT32U timeout,
USBD_ERR *p_err)
{
osStatus_t ret;
uint32_t tmo;
tmo = timeout ? timeout : osWaitForever;
ret = osSemaphoreAcquire(USBD_MSC_OS_TASK_SemTbl[class_nbr], tmo);
switch (ret) {
case osOK:
*p_err = USBD_ERR_NONE;
break;
case osErrorTimeout:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
default:
*p_err = USBD_ERR_OS_FAIL;
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
break;
}
}
/*
*********************************************************************************************************
* USBD_MSC_OS_CommSignalDel()
*
* Description : Delete a semaphore if no tasks are waiting on it for MSC communication.
*
* Argument(s) : class_nbr MSC instance class number
*
* p_err Pointer to variable that will receive the return error code from this function :
* USBD_ERR_NONE The call was successful and the semaphore was destroyed
* USBD_ERR_OS_FAIL otherwise.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_CommSignalDel (CPU_INT08U class_nbr,
USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreDelete(USBD_MSC_OS_TASK_SemTbl[class_nbr]);
if (ret < 0) {
*p_err = USBD_ERR_OS_FAIL;
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_MSC_OS_EnumSignalPost()
*
* Description : Post a semaphore for MSC enumeration process.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully posted.
* USBD_ERR_OS_FAIL OS signal NOT successfully posted.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_EnumSignalPost (USBD_ERR *p_err)
{
osStatus_t ret;
ret = osSemaphoreRelease(USBD_MSC_OS_EnumSignal);
if (ret < 0) {
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
*p_err = USBD_ERR_OS_FAIL;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_MSC_OS_EnumSignalPend()
*
* Description : Wait on a semaphore to become available for MSC enumeration process.
*
* Argument(s) : timeout Timeout in milliseconds.
*
* p_err Pointer to variable that will receive the return error code from this function :
* USBD_ERR_NONE The call was successful and your task owns the resource
* or, the event you are waiting for occurred.
* USBD_ERR_OS_TIMEOUT The semaphore was not received within the specified timeout.
* USBD_ERR_OS_FAIL otherwise.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_MSC_OS_EnumSignalPend (CPU_INT32U timeout,
USBD_ERR *p_err)
{
osStatus_t ret;
uint32_t tmo;
tmo = timeout ? timeout : osWaitForever;
ret = osSemaphoreAcquire(USBD_MSC_OS_EnumSignal, tmo);
switch (ret) {
case osOK:
*p_err = USBD_ERR_NONE;
break;
case osErrorTimeout:
*p_err = USBD_ERR_OS_TIMEOUT;
break;
default:
*p_err = USBD_ERR_OS_FAIL;
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
break;
}
}

View File

@@ -0,0 +1,443 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NOTICE
*
* Semidrive modified this file to adapt it for ssdk platform.
* The modifications are only intended for use with Semidrive chips.
* Copyright of all the modifications belongs to Semidrive Semiconductor.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* RAMDISK
*
* Filename : usbd_storage.c
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define MICRIUM_SOURCE
#include "usbd_storage.h"
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define USBD_RAMDISK_SIZE (USBD_RAMDISK_CFG_BLK_SIZE * \
USBD_RAMDISK_CFG_NBR_BLKS)
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
#if (USBD_RAMDISK_CFG_BASE_ADDR == 0)
static CPU_INT08U *USBD_RAMDISK_DataArea[USBD_RAMDISK_CFG_NBR_UNITS];
#else
static CPU_INT08U *USBD_RAMDISK_DataArea[USBD_RAMDISK_CFG_NBR_UNITS];
#endif
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_StorageInit()
*
* Description : Initialize internal tables used by the storage layer.
*
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Storage successfully initialized.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err)
{
LIB_ERR err_lib;
USBD_RAMDISK_DataArea[0] = (CPU_INT08U *)Mem_HeapAlloc( USBD_RAMDISK_CFG_NBR_UNITS * USBD_RAMDISK_SIZE,
USBD_RAMDISK_CFG_BLK_SIZE,
(CPU_SIZE_T *)DEF_NULL,
&err_lib);
if (err_lib != LIB_MEM_ERR_NONE) {
*p_err = USBD_ERR_ALLOC;
return;
}
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageAdd()
*
* Description : Initialize storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Storage successfully initialized.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Initiliazing RAM area failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
CPU_INT32U ix;
CPU_INT08U lun_nbr;
lun_nbr = p_storage_lun->LunNbr;
/* Fill the RAM area with zeros. */
#if (USBD_RAMDISK_CFG_BASE_ADDR != 0)
USBD_RAMDISK_DataArea[lun_nbr] = (CPU_INT08U *)USBD_RAMDISK_CFG_BASE_ADDR + lun_nbr * USBD_RAMDISK_SIZE;
#endif
Mem_Clr((void *)&USBD_RAMDISK_DataArea[lun_nbr][0],
USBD_RAMDISK_SIZE);
for (ix = 0; ix < USBD_RAMDISK_SIZE; ix++) { /* Chk if RAM area is cleared. */
if (USBD_RAMDISK_DataArea[lun_nbr][ix] != 0) {
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
return;
}
}
p_storage_lun->MediumPresent = DEF_TRUE; /* RAMDisk medium is initially always present. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageCapacityGet()
*
* Description : Get storage medium's capacity.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
*
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium capacity successfully gotten.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err)
{
(void)p_storage_lun;
*p_nbr_blks = USBD_RAMDISK_CFG_NBR_BLKS;
*p_blk_size = USBD_RAMDISK_CFG_BLK_SIZE;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageRd()
*
* Description : Read data from the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting read block.
*
* nbr_blks Number of logical blocks to read.
*
* p_data_buf Pointer to buffer in which data will be stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully read.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
* operations.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
CPU_INT08U lun;
CPU_INT64U mem_area_size;
CPU_INT32U mem_size_copy;
lun = (*p_storage_lun).LunNbr;
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
return;
}
mem_area_size = ((blk_addr + nbr_blks) * USBD_RAMDISK_CFG_BLK_SIZE);
if (mem_area_size > USBD_RAMDISK_SIZE) {
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
return;
}
mem_size_copy = nbr_blks * USBD_RAMDISK_CFG_BLK_SIZE;
Mem_Copy((void *) p_data_buf,
(void *)&USBD_RAMDISK_DataArea[lun][blk_addr * USBD_RAMDISK_CFG_BLK_SIZE],
mem_size_copy);
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageWr()
*
* Description : Write data to the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting write block.
*
* nbr_blks Number of logical blocks to write.
*
* p-data_buf Pointer to buffer in which data is stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully written.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
* operations.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
CPU_INT08U lun;
CPU_INT64U mem_area_size;
CPU_INT32U mem_size_copy;
lun = (*p_storage_lun).LunNbr;
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
return;
}
mem_area_size = ((blk_addr + nbr_blks) * USBD_RAMDISK_CFG_BLK_SIZE);
if (mem_area_size > USBD_RAMDISK_SIZE) {
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
return;
}
mem_size_copy = nbr_blks * USBD_RAMDISK_CFG_BLK_SIZE;
Mem_Copy((void *)&USBD_RAMDISK_DataArea[lun][blk_addr * USBD_RAMDISK_CFG_BLK_SIZE],
(void *) p_data_buf,
mem_size_copy);
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageStatusGet()
*
* Description : Get storage medium's status.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium present.
* USB_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
CPU_INT08U lun;
lun = p_storage_lun->LunNbr;
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
return;
}
if (p_storage_lun->MediumPresent == DEF_FALSE) {
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_StorageLock()
*
* Description : Lock storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* timeout_ms Timeout in milliseconds.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully locked.
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
* USBD_ERR_SCSI_LOCK Medium lock failed.
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err)
{
(void)timeout_ms;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageUnlock()
*
* Description : Unlock storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully unlocked.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
*p_err = USBD_ERR_NONE;
}

View File

@@ -0,0 +1,160 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* RAMDISK
*
* Filename : usbd_storage.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBF_STORAGE_H
#define USBF_STORAGE_H
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../../../Source/usbd_core.h"
#include "../../usbd_scsi.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err);
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
void USBD_StorageCapacityGet(USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err);
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err);
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_RAMDISK_CFG_BLK_SIZE
#error "USBD_RAMDISK_CFG_BLK_SIZE not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
#elif (USBD_RAMDISK_CFG_BLK_SIZE < 1u)
#error "USBD_RAMDISK_CFG_BLK_SIZE illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_RAMDISK_CFG_NBR_BLKS
#error "USBD_RAMDISK_CFG_NBR_BLKS not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
#elif (USBD_RAMDISK_CFG_NBR_BLKS < 1u)
#error "USBD_RAMDISK_CFG_NBR_BLKS illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_RAMDISK_CFG_NBR_UNITS
#error "USBD_RAMDISK_CFG_NBR_UNITS not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
#elif (USBD_RAMDISK_CFG_NBR_UNITS < 1u)
#error "USBD_RAMDISK_CFG_NBR_UNITS illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
#endif
#ifndef USBD_RAMDISK_CFG_BASE_ADDR
#error "USBD_RAMDISK_CFG_BASE_ADDR not #defined'd in 'usbd_cfg.h' [MUST be >= 0]"
#elif (USBD_RAMDISK_CFG_BASE_ADDR < 0u)
#error "USBD_RAMDISK_CFG_BASE_ADDR illegally #define'd in 'usbd_cfg.h' [MUST be >= 0]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,333 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* TEMPLATE
*
* Filename : usbd_storage.c
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define MICRIUM_SOURCE
#include "usbd_storage.h"
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_StorageInit()
*
* Description : Initialize the storage medium.
*
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Storage successfully initialized.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Initiliazing RAM area failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err)
{
/* $$$$ Insert code to initialize the storage medium. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageCapacityGet()
*
* Description : Get the capacity of the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
*
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium capacity successfully gotten.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err)
{
/* $$$$ Insert code to return the capacity of the storage medium in terms of number of blocks and default size of a block. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageRd()
*
* Description : Read the data from the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting read block.
*
* nbr_blks Number of logical blocks to read.
*
* p_data_buf Pointer to buffer in which data will be stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully read.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
* operations.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
/* $$$$ Insert code to read data from the storage medium. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageWr()
*
* Description : Write the data to the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting write block.
*
* nbr_blks Number of logical blocks to write.
*
* p-data_buf Pointer to buffer in which data is stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully written.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
* operations.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
/* $$$$ Insert code to write data to the storage medium. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageStatusGet()
*
* Description : Get the status of the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium present.
* USB_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
/* $$$$ Insert code to determine the presence or absence of the storage medium. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageLock()
*
* Description : Lock the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* timeout_ms Timeout in milliseconds.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully locked.
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
* USBD_ERR_SCSI_LOCK Medium lock failed.
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err)
{
/* $$$$ Insert code to lock access to the storage medium. This is useful to avoid an embedded file system accessing the same storage medium as the USB host. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageUnlock()
*
* Description : Unlock the storage medium.
*
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully unlocked.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
/* $$$$ Insert code to unlock access to the storage medium. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* END
*********************************************************************************************************
*/

View File

@@ -0,0 +1,141 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* TEMPLATE
*
* Filename : usbf_storage.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBF_STORAGE_H
#define USBF_STORAGE_H
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../../../Source/usbd_core.h"
#include "../../usbd_scsi.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEVICE TYPES
*********************************************************************************************************
*/
#define USBD_DISK_DIRECT_ACCESS_DEVICE 0x00
#define USBD_DISK_SEQUENTIAL_ACCESS_DEVICE 0x01
#define USBD_DISK_PRINTER_DEVICE 0x02
/*
*********************************************************************************************************
* DIRECT ACCESS MEDIUM TYPE
*********************************************************************************************************
*/
#define USBD_DISK_MEMORY_MEDIA 0x00
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err);
void USBD_StorageCapacityGet(USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err);
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err);
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,571 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* uC/FS V4
*
* Filename : usbd_storage.c
* Version : V4.06.01
*********************************************************************************************************
*/
/*
**********************************************************************************************************
* INCLUDE FILES
**********************************************************************************************************
*/
#define MICRIUM_SOURCE
#include "usbd_storage.h"
#include "../../../usbd_msc_os.h"
#include <Source/fs.h>
#include <Source/fs_dev.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
/* Tbl of dev to be polled. */
static USBD_STORAGE_LUN *USBD_FS_StorageDevPollList[USBD_MSC_CFG_MAX_LUN];
#endif
/* Cached luns state. */
static CPU_BOOLEAN USBD_FS_LunStatePresent[USBD_MSC_CFG_MAX_LUN];
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
#if (USBD_MSC_CFG_MICRIUM_FS == DEF_DISABLED)
#error "USBD_MSC_CFG_MICRIUM_FS illegally #defined in 'usbd_cfg.h' [MUST be DEF_ENABLED] "
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_StorageInit()
*
* Description : Initialize internal tables used by the storage layer.
*
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Storage successfully initialized.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err)
{
CPU_INT08U ix;
for (ix = 0; ix < USBD_MSC_CFG_MAX_LUN; ix++) {
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
USBD_FS_StorageDevPollList[ix] = (USBD_STORAGE_LUN *)0u;
#endif
USBD_FS_LunStatePresent[ix] = DEF_FALSE;
}
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageAdd()
*
* Description : Initialize storage medium.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Storage successfully initialized.
* USBD_ERR_SCSI_LU_NOTRDY Querying storage information failed.
*
* Return(s) : None.
*
* Note(s) : (1) Querying a device returns information such as size, sector size, removable or not.
* For fixed media (e.g. RAM, Flash NAND), all the information are always obtained.
* For removable media (e.g. SD card), only some information can be obtained if the
* media is not present. In this case, even if the device information structure contains
* valid information, an error code may be returned and the execution continues normally.
* The function USBD_StorageInit() should return immediately only when a fatal error
* occurs.
*********************************************************************************************************
*/
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
FS_ERR err_fs;
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
FS_DEV_INFO dev_info;
#endif
FSDev_Refresh(p_storage_lun->VolStrPtr, /* Obtain disk status. */
&err_fs);
if (err_fs == FS_ERR_NONE){ /* Initialize media present status. */
p_storage_lun->MediumPresent = DEF_TRUE;
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_TRUE;
} else {
p_storage_lun->MediumPresent = DEF_FALSE;
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
}
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
FSDev_Query(p_storage_lun->VolStrPtr,
&dev_info,
&err_fs);
switch (err_fs) {
/* See Note #1. */
case FS_ERR_NONE:
case FS_ERR_DEV_NOT_PRESENT:
case FS_ERR_DEV_IO:
break;
default:
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
return;
}
if(dev_info.Fixed == DEF_NO) { /* Removable media. */
USBD_FS_StorageDevPollList[p_storage_lun->LunNbr] = p_storage_lun;
}
#endif
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageCapacityGet()
*
* Description : Get storage medium's capacity.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
*
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium capacity successfully gotten.
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
*
* Return(s) : None.
*
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
* command.
*********************************************************************************************************
*/
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err)
{
FS_ERR err_fs;
FS_DEV_INFO dev_info;
CPU_SR_ALLOC();
FSDev_Query(p_storage_lun->VolStrPtr,
&dev_info,
&err_fs);
if (err_fs != FS_ERR_NONE) {
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
/* See Note #1. */
CPU_CRITICAL_ENTER();
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
CPU_CRITICAL_EXIT();
return;
}
*p_nbr_blks = dev_info.Size;
*p_blk_size = dev_info.SecSize;
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_StorageRd()
*
* Description : Read data from the storage medium.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting read block.
*
* nbr_blks Number of logical blocks to read.
*
* p_data_buf Pointer to buffer in which data will be stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully read.
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
*
* Return(s) : None.
*
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
* command.
*********************************************************************************************************
*/
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
FS_ERR err_fs;
CPU_SR_ALLOC();
FSDev_Rd(p_storage_lun->VolStrPtr,
p_data_buf,
blk_addr,
nbr_blks,
&err_fs);
if (err_fs != FS_ERR_NONE) {
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
/* See Note #1. */
CPU_CRITICAL_ENTER();
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
CPU_CRITICAL_EXIT();
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_StorageWr()
*
* Description : Write data to the storage medium.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* blk_addr Logical Block Address (LBA) of starting write block.
*
* nbr_blks Number of logical blocks to write.
*
* p-data_buf Pointer to buffer in which data is stored.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully written.
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
*
* Return(s) : None.
*
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
* command.
*********************************************************************************************************
*/
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err)
{
FS_ERR err_fs;
CPU_SR_ALLOC();
FSDev_Wr(p_storage_lun->VolStrPtr,
p_data_buf,
blk_addr,
nbr_blks,
&err_fs);
if (err_fs != FS_ERR_NONE) {
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
/* See Note #1. */
CPU_CRITICAL_ENTER();
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
CPU_CRITICAL_EXIT();
} else {
*p_err = USBD_ERR_NONE;
}
}
/*
*********************************************************************************************************
* USBD_StorageStatusGet()
*
* Description : Get storage medium's status.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium present.
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
* USBD_ERR_SCSI_MEDIUM_NOT_RDY_TO_RDY Medium state from not ready to ready.
* USBD_ERR_SCSI_MEDIUM_RDY_TO_NOT_RDY Medium state from ready to not ready.
*
* Return(s) : None.
*
* Note(s) : (1) Sometimes a removable device may fail since device may be removed, powered off or
* suddenly unresponsive. The associated device states for the latter are: FS_DEV_STATE_CLOSED,
* FS_DEV_STATE_CLOSING and FS_DEV_STATE_STARTING. The device will need to be refreshed
* or closed and re-opened.
*
* (2) If the return error is neither FS_ERR_NONE nor FS_ERR_DEV_INVALID_LOW_FMT, then no
* functioning device is present. The device must be refreshed at a later time.
*********************************************************************************************************
*/
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
FS_STATE state;
state = USBD_FS_LunStatePresent[p_storage_lun->LunNbr];
if (p_storage_lun->MediumPresent == DEF_FALSE) {
if (state == DEF_TRUE){ /* Media is inserted. */
*p_err = USBD_ERR_SCSI_MEDIUM_NOT_RDY_TO_RDY;
p_storage_lun->MediumPresent = DEF_TRUE;
} else {
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
}
} else {
if (state == DEF_FALSE){ /* Media is removed. */
*p_err = USBD_ERR_SCSI_MEDIUM_RDY_TO_NOT_RDY;
p_storage_lun->MediumPresent = DEF_FALSE;
} else {
*p_err = USBD_ERR_NONE;
}
}
}
/*
*********************************************************************************************************
* USBD_StorageLock()
*
* Description : Lock storage medium.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* timeout_ms Timeout in milliseconds.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully locked.
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
* USBD_ERR_SCSI_LOCK Medium lock failed.
*
* Return(s) : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err)
{
FS_ERR err_fs;
FSDev_AccessLock(p_storage_lun->VolStrPtr,
timeout_ms,
&err_fs);
switch (err_fs) {
case FS_ERR_NONE:
*p_err = USBD_ERR_NONE;
break;
case FS_ERR_OS_LOCK_TIMEOUT:
*p_err = USBD_ERR_SCSI_LOCK_TIMEOUT;
break;
default:
*p_err = USBD_ERR_SCSI_LOCK;
break;
}
}
/*
*********************************************************************************************************
* USBD_StorageUnlock()
*
* Description : Unlock storage medium.
*
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
*
* p_err Pointer to variable that will receive error code from this function.
*
* USBD_ERR_NONE Medium successfully unlocked.
* USBD_ERR_SCSI_UNLOCK Medium unlock failed.
*
* Return(s) : None.
*
* Note(s) : (1) If an embedded file system application manipulates files on a medium shared with
* uC/USB-Device, a lock mechanism is used to ensure an exclusive access to the mediunm.
* uC/USB-Device can try to obtain the lock on the medium between each file system
* operation. In that case, the file system operations sequence can be interrupted at
* any time by uC/USB-Device. When uC/USB-Device releases the lock, files which were
* manipulated by uC/FS are invalidated because the computer host may have altered them.
*********************************************************************************************************
*/
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err)
{
FS_ERR err_fs;
FSDev_Invalidate(p_storage_lun->VolStrPtr, &err_fs); /* Invalidate files opened on logical unit (see Note #1)*/
if (err_fs != FS_ERR_NONE) {
*p_err = USBD_ERR_SCSI_UNLOCK;
return;
}
FSDev_AccessUnlock(p_storage_lun->VolStrPtr, &err_fs);
if (err_fs != FS_ERR_NONE) {
*p_err = USBD_ERR_SCSI_UNLOCK;
return;
}
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_StorageRefreshTaskHandler()
*
* Description : Device medium status refresh.
*
* Argument(s) : p_arg Pointer to task initialization argument.
*
* Return(s) : None.
*
* Note(s) : (1) This function must be called by the MSC OS layer periodically. The period is
* configurable through the constant USBD_MSC_CFG_DEV_POLL_DLY_mS defined in usbd_cfg.h.
*
* (2) Polling list is used by removable media such as SD card whose insertion and removal
* detection do NOT trigger an interrupt for the CPU. Hence, periodically, the presence
* state (i.e. present or not) of each logical unit added to the polling list is
* verified.
*********************************************************************************************************
*/
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
void USBD_StorageRefreshTaskHandler (void *p_arg)
{
FS_ERR err_fs;
CPU_INT32U i;
(void)p_arg;
/* ------ POLLING LIST PROCESSING (see Note #1) ------- */
for (i = 0u; i < USBD_MSC_CFG_MAX_LUN; i++) {
if (USBD_FS_StorageDevPollList[i] != (USBD_STORAGE_LUN *)0u) {
/* Get status of removable media. */
FSDev_Refresh(USBD_FS_StorageDevPollList[i]->VolStrPtr, &err_fs);
if(err_fs == FS_ERR_NONE) {
USBD_FS_LunStatePresent[i] = DEF_TRUE;
} else {
USBD_FS_LunStatePresent[i] = DEF_FALSE;
}
}
}
}
#endif

View File

@@ -0,0 +1,150 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS STORAGE DRIVER
*
* uC/FS V4
*
* Filename : usbd_storage.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
**********************************************************************************************************
* MODULE
**********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../../../../Source/usbd_core.h"
#include "../../../usbd_scsi.h"
#include <fs_cfg.h>
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef STORAGE_MODULE
#define STORAGE_EXT
#else
#define STORAGE_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_StorageInit (USBD_ERR *p_err);
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U *p_nbr_blks,
CPU_INT32U *p_blk_size,
USBD_ERR *p_err);
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT64U blk_addr,
CPU_INT32U nbr_blks,
CPU_INT08U *p_data_buf,
USBD_ERR *p_err);
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
CPU_INT32U timeout_ms,
USBD_ERR *p_err);
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
USBD_ERR *p_err);
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
void USBD_StorageRefreshTaskHandler(void *p_arg);
#endif
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_MSC_CFG_FS_REFRESH_TASK_EN
#error "USBD_MSC_CFG_FS_REFRESH_TASK_EN not #defined'd in 'usbd_cfg.h' [MUST be DEF_ENABLED or DEF_DISABLED]"
#endif
/*
**********************************************************************************************************
* MODULE END
**********************************************************************************************************
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,177 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC CLASS
*
* Filename : usbd_msc.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_MSC_MODULE_PRESENT
#define USBD_MSC_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_MSC_MODULE
#define USBD_MSC_EXT
#else
#define USBD_MSC_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*
* Note(s) : (1) The T10 VENDOR IDENTIFICATION field contains 8 bytes of left-aligned ASCII data
* identifying the vendor of the product. The T10 vendor identification shall be one
* assigned by INCITS.
* The PRODUCT IDENTIFICATION field contains 16 bytes of left-aligned ASCII data
* defined by the vendor.
* See 'SCSI Primary Commands - 3 (SPC-3)', section 6.4.2 for more details about
* Standard INQUIRY data format.
*********************************************************************************************************
*/
/* ---- STANDARD INQUIRY DATA FORMAT (see Note #1) ---- */
#define USBD_MSC_DEV_MAX_VEND_ID_LEN 8u
#define USBD_MSC_DEV_MAX_PROD_ID_LEN 16u
/*
**********************************************************************************************************
* DATA TYPES
**********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_MSC_Init ( USBD_ERR *p_err);
CPU_INT08U USBD_MSC_Add ( USBD_ERR *p_err);
CPU_BOOLEAN USBD_MSC_CfgAdd ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
void USBD_MSC_LunAdd (const CPU_CHAR *p_store_name,
CPU_INT08U class_nbr,
CPU_CHAR *p_vend_id,
CPU_CHAR *p_prod_id,
CPU_INT32U prod_rev_level,
CPU_BOOLEAN rd_only,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_MSC_IsConn ( CPU_INT08U class_nbr);
void USBD_MSC_TaskHandler( CPU_INT08U class_nbr);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_MSC_CFG_MAX_NBR_DEV
#error "USBD_MSC_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_MSC_CFG_MAX_NBR_DEV < 1u)
#error "USBD_MSC_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_MSC_CFG_MAX_NBR_CFG
#error "USBD_MSC_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_MSC_CFG_MAX_NBR_CFG < 1u)
#error "USBD_MSC_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_MSC_CFG_MAX_LUN
#error "USBD_MSC_CFG_MAX_LUN not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_MSC_CFG_MAX_LUN < 1u)
#error "USBD_MSC_CFG_MAX_LUN illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_MSC_CFG_DATA_LEN
#error "USBD_MSC_CFG_DATA_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_MSC_CFG_DATA_LEN < 1u)
#error "USBD_MSC_CFG_DATA_LEN illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_MSC_CFG_MICRIUM_FS
#error "USBD_MSC_CFG_MICRIUM_FS not #define'd in 'usbd_cfg.h' [MUST be DEF_ENABLED or DEF_DISABLED]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,117 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB MSC CLASS OPERATING SYSTEM LAYER
*
* Filename : usbd_msc_os.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_MSC_OS_MODULE_PRESENT
#define USBD_MSC_OS_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_MSC_OS_Init (USBD_ERR *p_err);
void USBD_MSC_OS_CommSignalPost(CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_MSC_OS_CommSignalPend(CPU_INT08U class_nbr,
CPU_INT32U timeout,
USBD_ERR *p_err);
void USBD_MSC_OS_CommSignalDel (CPU_INT08U class_nbr,
USBD_ERR *p_err);
void USBD_MSC_OS_EnumSignalPost(USBD_ERR *p_err);
void USBD_MSC_OS_EnumSignalPend(CPU_INT32U timeout,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,182 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE MSC SCSI
*
* Filename : usbd_scsi.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
**********************************************************************************************************
* MODULE
**********************************************************************************************************
*/
#ifndef USBD_SCSI_H
#define USBD_SCSI_H
/*
**********************************************************************************************************
* INCLUDE FILES
**********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
#include "usbd_msc.h"
/*
**********************************************************************************************************
* EXTERNS
**********************************************************************************************************
*/
#ifdef USBD_SCSI_MODULE
#define USBD_SCSI_EXT
#else
#define USBD_SCSI_EXT extern
#endif
/*
**********************************************************************************************************
* DEFINES
**********************************************************************************************************
*/
/*
**********************************************************************************************************
* DATA TYPES
**********************************************************************************************************
*/
/*
**********************************************************************************************************
* STORAGE UNIT CONTROL
**********************************************************************************************************
*/
typedef struct usbd_storage_lun {
CPU_INT08U LunNbr; /* Logical Unit Number. */
CPU_CHAR *VolStrPtr; /* String uniquely identifying a logical unit. */
CPU_BOOLEAN MediumPresent; /* Flag indicating presence of logical unit. */
CPU_BOOLEAN LockFlag; /* Flag indicating logical unit locked or not. */
CPU_BOOLEAN EjectFlag; /* Flag indicating logical unit ejected by host or not. */
} USBD_STORAGE_LUN;
/*
**********************************************************************************************************
* LOGICAL UNIT CHARACTERISTICS
**********************************************************************************************************
*/
typedef struct usbd_lun_info {
CPU_INT08U VendorId[USBD_MSC_DEV_MAX_VEND_ID_LEN]; /* Dev vendor info. */
CPU_INT08U ProdId[USBD_MSC_DEV_MAX_PROD_ID_LEN]; /* Dev prod ID. */
CPU_INT32U ProdRevisionLevel; /* Revision level of product. */
CPU_BOOLEAN ReadOnly; /* Wr protected or not. */
} USBD_LUN_INFO;
/*
**********************************************************************************************************
* LOGICAL UNIT CONTROL
**********************************************************************************************************
*/
typedef struct usbd_msc_lun_ctrl {
CPU_INT08U LunNbr; /* LUN given by MSC IF. */
USBD_LUN_INFO LunInfo; /* Logical unit info. */
CPU_INT64U NbrBlocks; /* Nbr of blks supported by logical unit. */
CPU_INT32U BlockSize; /* Blk size supported by logical unit. */
void *LunArgPtr; /* Ptr to the LUN specific argument. */
} USBD_MSC_LUN_CTRL;
/*
**********************************************************************************************************
* GLOBAL VARIABLES
**********************************************************************************************************
*/
/*
**********************************************************************************************************
* MACRO'S
**********************************************************************************************************
*/
/*
**********************************************************************************************************
* FUNCTION PROTOTYPES
**********************************************************************************************************
*/
void USBD_SCSI_Init ( USBD_ERR *p_err);
void USBD_SCSI_LunAdd ( CPU_INT08U lun_nbr,
CPU_CHAR *p_vol_str,
USBD_ERR *p_err);
void USBD_SCSI_CmdProcess( USBD_MSC_LUN_CTRL *p_lun,
const CPU_INT08U *p_cbwcb,
CPU_INT32U *p_resp_len,
CPU_INT08U *p_data_dir,
USBD_ERR *p_err);
void USBD_SCSI_DataRd (const USBD_MSC_LUN_CTRL *p_lun,
CPU_INT08U scsi_cmd,
CPU_INT08U *p_data_buf,
CPU_INT32U data_len,
CPU_INT32U *p_ret_len,
USBD_ERR *p_err);
void USBD_SCSI_DataWr (const USBD_MSC_LUN_CTRL *p_lun,
CPU_INT08U scsi_cmd,
void *p_data_buf,
CPU_INT32U data_len,
USBD_ERR *p_err);
void USBD_SCSI_Reset ( void);
void USBD_SCSI_Conn (const USBD_MSC_LUN_CTRL *p_lun);
void USBD_SCSI_Unlock (const USBD_MSC_LUN_CTRL *p_lun,
USBD_ERR *p_err);
/*
**********************************************************************************************************
* CONFIGURATION ERRORS
**********************************************************************************************************
*/
/*
**********************************************************************************************************
* MODULE END
**********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,315 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB PHDC CLASS OPERATING SYSTEM LAYER
* Micrium Template
*
* Filename : usbd_phdc_os.c
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../usbd_phdc.h"
#include "../../usbd_phdc_os.h"
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void USBD_PHDC_OS_WrBulkSchedTask(void *p_arg);
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* USBD_PHDC_OS_Init()
*
* Description : Initialize PHDC OS interface.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS initialization successful.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_Init (USBD_ERR *p_err)
{
/* $$$$ Initialize all internal variables and tasks used by OS layer. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_RdLock()
*
* Description : Lock PHDC read pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* timeout_ms Timeout, in ms.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully acquired.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_RdLock (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
/* $$$$ Lock read pipe. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_RdUnlock()
*
* Description : Unlock PHDC read pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_RdUnlock (CPU_INT08U class_nbr)
{
/* $$$$ Unlock read pipe. */
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_WrIntrLock()
*
* Description : Lock PHDC write interrupt pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* timeout_ms Timeout, in ms.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully acquired.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_WrIntrLock (CPU_INT08U class_nbr,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
/* $$$$ Lock interrupt write pipe. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_WrIntrUnlock()
*
* Description : Unlock PHDC write interrupt pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_WrIntrUnlock (CPU_INT08U class_nbr)
{
/* $$$$ Unlock interrupt write pipe. */
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_WrBulkLock()
*
* Description : Lock PHDC write bulk pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* prio Priority of the transfer, based on its QoS.
*
* timeout_ms Timeout, in ms.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* USBD_ERR_NONE OS signal successfully acquired.
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_WrBulkLock (CPU_INT08U class_nbr,
CPU_INT08U prio,
CPU_INT16U timeout_ms,
USBD_ERR *p_err)
{
/* $$$$ Lock bulk write pipe. */
*p_err = USBD_ERR_NONE;
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_WrBulkUnlock()
*
* Description : Unlock PHDC write bulk pipe.
*
* Argument(s) : class_nbr PHDC instance number;
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_WrBulkUnlock (CPU_INT08U class_nbr)
{
/* $$$$ Unlock bulk wirte pipe. */
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_Reset()
*
* Description : Reset PHDC OS layer for given instance.
*
* Argument(s) : class_nbr PHDC instance number;
*
* Return(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void USBD_PHDC_OS_Reset (CPU_INT08U class_nbr)
{
/* $$$$ Reset OS layer. */
}
/*
*********************************************************************************************************
* USBD_PHDC_OS_WrBulkSchedTask()
*
* Description : OS-dependent shell task to schedule bulk transfers in function of their priority.
*
* Argument(s) : p_arg Pointer to task initialization argument (required by uC/OS-III).
*
* Return(s) : none.
*
* Note(s) : (1) Only one task handle all class instances bulk write scheduling.
*********************************************************************************************************
*/
static void USBD_PHDC_OS_WrBulkSchedTask (void *p_arg)
{
/* $$$$ If QoS prioritization is used, implement this task to act as a scheduler. */
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,230 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE PHDC CLASS
*
* Filename : usbd_phdc.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_PHDC_CLASS_MODULE_PRESENT
#define USBD_PHDC_CLASS_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_PHDC_MODULE
#define USBD_PHDC_EXT
#else
#define USBD_PHDC_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define USBD_PHDC_NBR_NONE DEF_INT_08U_MAX_VAL
/*
*********************************************************************************************************
* LATENCY / RELIABILITY BITMAPS
*********************************************************************************************************
*/
#define USBD_PHDC_LATENCY_VERYHIGH_RELY_BEST DEF_BIT_05
#define USBD_PHDC_LATENCY_HIGH_RELY_BEST DEF_BIT_04
#define USBD_PHDC_LATENCY_MEDIUM_RELY_BEST DEF_BIT_03
#define USBD_PHDC_LATENCY_MEDIUM_RELY_BETTER DEF_BIT_02
#define USBD_PHDC_LATENCY_MEDIUM_RELY_GOOD DEF_BIT_01
#define USBD_PHDC_LATENCY_LOW_RELY_GOOD DEF_BIT_00
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef CPU_INT08U LATENCY_RELY_FLAGS;
/*
*********************************************************************************************************
* ASYNCHRONOUS CALLBACK FUNCTION DATA TYPE
*********************************************************************************************************
*/
typedef void (*USBD_PHDC_PREAMBLE_EN_NOTIFY)(CPU_INT08U class_nbr,
CPU_BOOLEAN preamble_en);
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* APPLICATION FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_PHDC_Init ( USBD_ERR *p_err);
CPU_INT08U USBD_PHDC_Add ( CPU_BOOLEAN data_fmt_11073,
CPU_BOOLEAN preamble_capable,
USBD_PHDC_PREAMBLE_EN_NOTIFY preamble_en_notify,
CPU_INT16U low_latency_interval,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_PHDC_CfgAdd ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_PHDC_IsConn ( CPU_INT08U class_nbr);
void USBD_PHDC_RdCfg ( CPU_INT08U class_nbr,
LATENCY_RELY_FLAGS latency_rely,
const CPU_INT08U *p_data_opaque,
CPU_INT08U data_opaque_len,
USBD_ERR *p_err);
void USBD_PHDC_WrCfg ( CPU_INT08U class_nbr,
LATENCY_RELY_FLAGS latency_rely,
const CPU_INT08U *p_data_opaque,
CPU_INT08U data_opaque_len,
USBD_ERR *p_err);
void USBD_PHDC_11073_ExtCfg( CPU_INT08U class_nbr,
CPU_INT16U *p_dev_specialization,
CPU_INT08U nbr_dev_specialization,
USBD_ERR *p_err);
CPU_INT08U USBD_PHDC_PreambleRd ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT08U buf_len,
CPU_INT08U *p_nbr_xfer,
CPU_INT16U timeout,
USBD_ERR *p_err);
CPU_INT16U USBD_PHDC_Rd ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT16U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_PreambleWr ( CPU_INT08U class_nbr,
void *p_data_opaque,
CPU_INT08U data_opaque_len,
LATENCY_RELY_FLAGS latency_rely,
CPU_INT08U nbr_xfers,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_Wr ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT16U buf_len,
LATENCY_RELY_FLAGS latency_rely,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_Reset ( CPU_INT08U class_nbr);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_PHDC_CFG_MAX_NBR_DEV
#error "USBD_PHDC_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_PHDC_CFG_MAX_NBR_DEV < 1u)
#error "USBD_PHDC_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_PHDC_CFG_MAX_NBR_CFG
#error "USBD_PHDC_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_PHDC_CFG_MAX_NBR_CFG < 1u)
#error "USBD_PHDC_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN
#error "USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 0]"
#endif
#if (USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN < 0u)
#error "USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN illegally #define'd in 'usbd_cfg.h' [MUST be >= 0]"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

View File

@@ -0,0 +1,130 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB PHDC CLASS OPERATING SYSTEM LAYER
*
* Filename : usbd_phdc_os.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_PHDC_OS_MODULE_PRESENT
#define USBD_PHDC_OS_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
#include <Source/os.h>
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_PHDC_OS_Init ( USBD_ERR *p_err);
void USBD_PHDC_OS_RdLock (CPU_INT08U class_nbr,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_OS_RdUnlock (CPU_INT08U class_nbr);
void USBD_PHDC_OS_WrBulkLock (CPU_INT08U class_nbr,
CPU_INT08U prio,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_OS_WrBulkUnlock(CPU_INT08U class_nbr);
void USBD_PHDC_OS_WrIntrLock (CPU_INT08U class_nbr,
CPU_INT16U timeout,
USBD_ERR *p_err);
void USBD_PHDC_OS_WrIntrUnlock(CPU_INT08U class_nbr);
void USBD_PHDC_OS_Reset (CPU_INT08U class_nbr);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#if (OS_VERSION >= 30000)
#error "USB-Device PHDC class is not supported by uC/OS-III"
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,225 @@
/*
*********************************************************************************************************
* uC/USB-Device
* The Embedded USB Device Stack
*
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* USB DEVICE VENDOR CLASS
*
* Filename : usbd_vendor.h
* Version : V4.06.01
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef USBD_VENDOR_MODULE_PRESENT
#define USBD_VENDOR_MODULE_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "../../Source/usbd_core.h"
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef USBD_VENDOR_MODULE
#define USBD_VENDOR_EXT
#else
#define USBD_VENDOR_EXT extern
#endif
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/* App callback used for vendor-specific req. */
typedef CPU_BOOLEAN (*USBD_VENDOR_REQ_FNCT) ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
const USBD_SETUP_REQ *p_setup_req);
/* App callback used for async comm. */
typedef void (*USBD_VENDOR_ASYNC_FNCT)( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT32U xfer_len,
void *p_callback_arg,
USBD_ERR err);
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void USBD_Vendor_Init ( USBD_ERR *p_err);
CPU_INT08U USBD_Vendor_Add ( CPU_BOOLEAN intr_en,
CPU_INT16U interval,
USBD_VENDOR_REQ_FNCT req_callback,
USBD_ERR *p_err);
void USBD_Vendor_CfgAdd ( CPU_INT08U class_nbr,
CPU_INT08U dev_nbr,
CPU_INT08U cfg_nbr,
USBD_ERR *p_err);
CPU_BOOLEAN USBD_Vendor_IsConn ( CPU_INT08U class_nbr);
#if (USBD_CFG_MS_OS_DESC_EN == DEF_ENABLED)
void USBD_Vendor_MS_ExtPropertyAdd( CPU_INT08U class_nbr,
CPU_INT08U property_type,
const CPU_INT08U *p_property_name,
CPU_INT16U property_name_len,
const CPU_INT08U *p_property,
CPU_INT32U property_len,
USBD_ERR *p_err);
#endif
CPU_INT32U USBD_Vendor_Rd ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
CPU_INT32U USBD_Vendor_Wr ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
CPU_BOOLEAN end,
USBD_ERR *p_err);
void USBD_Vendor_RdAsync ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_VENDOR_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
void USBD_Vendor_WrAsync ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_VENDOR_ASYNC_FNCT async_fnct,
void *p_async_arg,
CPU_BOOLEAN end,
USBD_ERR *p_err);
CPU_INT32U USBD_Vendor_IntrRd ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
USBD_ERR *p_err);
CPU_INT32U USBD_Vendor_IntrWr ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
CPU_INT16U timeout,
CPU_BOOLEAN end,
USBD_ERR *p_err);
void USBD_Vendor_IntrRdAsync ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_VENDOR_ASYNC_FNCT async_fnct,
void *p_async_arg,
USBD_ERR *p_err);
void USBD_Vendor_IntrWrAsync ( CPU_INT08U class_nbr,
void *p_buf,
CPU_INT32U buf_len,
USBD_VENDOR_ASYNC_FNCT async_fnct,
void *p_async_arg,
CPU_BOOLEAN end,
USBD_ERR *p_err);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef USBD_VENDOR_CFG_MAX_NBR_DEV
#error "USBD_VENDOR_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_VENDOR_CFG_MAX_NBR_DEV < 1u)
#error "USBD_VENDOR_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#ifndef USBD_VENDOR_CFG_MAX_NBR_CFG
#error "USBD_VENDOR_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_VENDOR_CFG_MAX_NBR_CFG < 1u)
#error "USBD_VENDOR_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_CFG_MS_OS_DESC_EN == DEF_ENABLED)
#ifndef USBD_VENDOR_CFG_MAX_NBR_MS_EXT_PROPERTY
#error "USBD_VENDOR_CFG_MAX_NBR_MS_EXT_PROPERTY not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#if (USBD_VENDOR_CFG_MAX_NBR_MS_EXT_PROPERTY < 1u)
#error "USBD_VENDOR_CFG_MAX_NBR_MS_EXT_PROPERTY illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
#endif
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif