First cleanup pass to USB VCOM sources

replace/52fc03e60ed00ba75558034e14a823e2c94c42d3
Silvano Seva 2020-12-21 21:55:37 +01:00
rodzic 626d710151
commit 4d4a561345
3 zmienionych plików z 4 dodań i 505 usunięć

Wyświetl plik

@ -92,448 +92,14 @@ USB_GLOBAL static usb_osa_msgq_struct_t s_UsbBmMsgqStruct[USB_OSA_BM_MSGQ_COUNT]
* Code
******************************************************************************/
void *USB_OsaMemoryAllocate(uint32_t length)
{
void *p = (void *)malloc(length);
uint8_t *temp = (uint8_t *)p;
if (p)
{
for (uint32_t count = 0U; count < length; count++)
{
temp[count] = 0U;
}
}
return p;
}
void USB_OsaMemoryFree(void *p)
{
free(p);
}
void USB_OsaEnterCritical(uint32_t *sr)
{
*sr = DisableGlobalIRQ();
*sr = __get_PRIMASK();
__disable_irq();
__ASM("CPSID I");
}
void USB_OsaExitCritical(uint32_t sr)
{
EnableGlobalIRQ(sr);
}
usb_osa_status_t USB_OsaEventCreate(usb_osa_event_handle *handle, uint32_t flag)
{
usb_osa_event_struct_t *event = NULL;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
for (uint32_t i = 0; i < USB_OSA_BM_EVENT_COUNT; i++)
{
if (0 == s_UsbBmEventStruct[i].isUsed)
{
event = &s_UsbBmEventStruct[i];
break;
}
}
if (NULL == event)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Error;
}
event->value = 0U;
event->flag = flag;
event->isUsed = 1;
*handle = event;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaEventDestroy(usb_osa_event_handle handle)
{
usb_osa_event_struct_t *event = (usb_osa_event_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
event->isUsed = 0;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaEventSet(usb_osa_event_handle handle, uint32_t bitMask)
{
usb_osa_event_struct_t *event = (usb_osa_event_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
event->value |= bitMask;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaEventWait(
usb_osa_event_handle handle, uint32_t bitMask, uint32_t flag, uint32_t timeout, uint32_t *bitSet)
{
usb_osa_event_struct_t *event = (usb_osa_event_struct_t *)handle;
uint32_t bits;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
bits = event->value & bitMask;
if (flag)
{
if (bits != bitMask)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_TimeOut;
}
}
else
{
if (!bits)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_TimeOut;
}
}
if (bitSet)
{
*bitSet = bits;
}
if (event->flag)
{
event->value &= ~bits;
}
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaEventCheck(usb_osa_event_handle handle, uint32_t bitMask, uint32_t *bitSet)
{
usb_osa_event_struct_t *event = (usb_osa_event_struct_t *)handle;
uint32_t bits;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
bits = event->value & bitMask;
if (!bits)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Error;
}
if (bitSet)
{
*bitSet = bits;
}
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaEventClear(usb_osa_event_handle handle, uint32_t bitMask)
{
usb_osa_event_struct_t *event = (usb_osa_event_struct_t *)handle;
uint32_t bits;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
bits = event->value & bitMask;
event->value &= ~bits;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaSemCreate(usb_osa_sem_handle *handle, uint32_t count)
{
usb_osa_sem_struct_t *sem = NULL;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
for (uint32_t i = 0; i < USB_OSA_BM_SEM_COUNT; i++)
{
if (0 == s_UsbBmSemStruct[i].isUsed)
{
sem = &s_UsbBmSemStruct[i];
break;
}
}
if (NULL == sem)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Error;
}
sem->value = count;
sem->isUsed = 1;
*handle = sem;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaSemDestroy(usb_osa_sem_handle handle)
{
usb_osa_sem_struct_t *sem = (usb_osa_sem_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (handle)
{
USB_OSA_ENTER_CRITICAL();
sem->isUsed = 0;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
return kStatus_USB_OSA_Error;
}
usb_osa_status_t USB_OsaSemPost(usb_osa_sem_handle handle)
{
usb_osa_sem_struct_t *sem = (usb_osa_sem_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
sem->value++;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaSemWait(usb_osa_sem_handle handle, uint32_t timeout)
{
usb_osa_sem_struct_t *sem = (usb_osa_sem_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
if (sem->value)
{
sem->value--;
}
else
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_TimeOut;
}
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMutexCreate(usb_osa_mutex_handle *handle)
{
if (!handle)
{
return kStatus_USB_OSA_Error;
}
*handle = (usb_osa_mutex_handle)0xFFFF0000U;
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMutexDestroy(usb_osa_mutex_handle handle)
{
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMutexLock(usb_osa_mutex_handle handle)
{
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMutexUnlock(usb_osa_mutex_handle handle)
{
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMsgqCreate(usb_osa_msgq_handle *handle, uint32_t count, uint32_t size)
{
usb_osa_msgq_struct_t *msgq = NULL;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
for (uint32_t i = 0; i < USB_OSA_BM_MSGQ_COUNT; i++)
{
if (0 == s_UsbBmMsgqStruct[i].isUsed)
{
msgq = &s_UsbBmMsgqStruct[i];
break;
}
}
if ((NULL == msgq) || (count > USB_OSA_BM_MSG_COUNT) || (size > USB_OSA_BM_MSG_SIZE))
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Error;
}
msgq->count = count;
msgq->msgSize = size;
msgq->msgCount = 0U;
msgq->index = 0U;
msgq->current = 0U;
msgq->isUsed = 1;
*handle = msgq;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMsgqDestroy(usb_osa_msgq_handle handle)
{
usb_osa_msgq_struct_t *msgq = (usb_osa_msgq_struct_t *)handle;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
msgq->isUsed = 0;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMsgqSend(usb_osa_msgq_handle handle, void *msg)
{
usb_osa_msgq_struct_t *msgq = (usb_osa_msgq_struct_t *)handle;
usb_osa_msg_struct_t *msgEntity;
uint32_t *p;
uint32_t *q;
uint32_t count;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
if (msgq->msgCount >= msgq->count)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Error;
}
msgEntity = &msgq->msgs[msgq->index];
p = (uint32_t *)&msgEntity->msg[0];
q = (uint32_t *)msg;
for (count = 0U; count < msgq->msgSize; count++)
{
p[count] = q[count];
}
if (0U == msgq->msgCount)
{
msgq->current = msgq->index;
}
msgq->msgCount++;
msgq->index++;
msgq->index = msgq->index % msgq->count;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMsgqRecv(usb_osa_msgq_handle handle, void *msg, uint32_t timeout)
{
usb_osa_msgq_struct_t *msgq = (usb_osa_msgq_struct_t *)handle;
usb_osa_msg_struct_t *msgEntity;
uint32_t *p;
uint32_t *q;
uint32_t count;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
if (msgq->msgCount < 1U)
{
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_TimeOut;
}
msgEntity = &msgq->msgs[msgq->current];
q = (uint32_t *)&msgEntity->msg[0];
p = (uint32_t *)msg;
for (count = 0U; count < msgq->msgSize; count++)
{
p[count] = q[count];
}
msgq->msgCount--;
msgq->current++;
msgq->current = msgq->current % msgq->count;
USB_OSA_EXIT_CRITICAL();
return kStatus_USB_OSA_Success;
}
usb_osa_status_t USB_OsaMsgqCheck(usb_osa_msgq_handle handle, void *msg)
{
usb_osa_msgq_struct_t *msgq = (usb_osa_msgq_struct_t *)handle;
uint32_t msgCount;
USB_OSA_SR_ALLOC();
if (!handle)
{
return kStatus_USB_OSA_Error;
}
USB_OSA_ENTER_CRITICAL();
msgCount = msgq->msgCount;
USB_OSA_EXIT_CRITICAL();
if (msgCount)
{
if (kStatus_USB_OSA_Success == USB_OsaMsgqRecv(msgq, msg, 0U))
{
return kStatus_USB_OSA_Success;
}
}
return kStatus_USB_OSA_Error;
__set_PRIMASK(sr);
}

Wyświetl plik

@ -44,27 +44,8 @@
#include "usb_device_descriptor.h"
#include "virtual_com.h"
#if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
#include "fsl_sysmpu.h"
#endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
#include "usb_phy.h"
#endif
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
#include "fsl_smc.h"
#endif
#include "fsl_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* USB clock source and frequency*/
#define USB_FS_CLK_SRC kCLOCK_UsbSrcIrc48M
#define USB_FS_CLK_FREQ 48000000U
/*******************************************************************************
* Variables
******************************************************************************/
@ -98,12 +79,7 @@ USB_DATA_ALIGNMENT static uint8_t s_currSendBuf[DATA_BUFF_SIZE];
volatile static uint32_t s_recvSize = 0;
volatile static uint32_t s_sendSize = 0;
static uint32_t s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
volatile static uint8_t s_waitForDataReceive = 0;
volatile static uint8_t s_comOpen = 0;
#endif
/*******************************************************************************
* Prototypes
******************************************************************************/
@ -163,12 +139,6 @@ usb_status_t USB_DeviceCdcAcmBulkIn(usb_device_handle handle,
/* User: add your own code for send complete event */
/* Schedule buffer for next receive event */
USB_DeviceRecvRequest(handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
s_waitForDataReceive = 1;
USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
#endif
}
}
else
@ -198,22 +168,10 @@ usb_status_t USB_DeviceCdcAcmBulkOut(usb_device_handle handle,
{
s_recvSize = message->length;
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
s_waitForDataReceive = 0;
USB0->INTEN |= USB_INTEN_SOFTOKEN_MASK;
#endif
if (!s_recvSize)
{
/* Schedule buffer for next receive event */
USB_DeviceRecvRequest(handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
s_waitForDataReceive = 1;
USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
#endif
}
}
return error;
@ -421,14 +379,6 @@ usb_status_t USB_DeviceProcessClassRequest(usb_device_handle handle,
if (1 == s_cdcVcom.attach)
{
s_cdcVcom.startTransactions = 1;
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
s_waitForDataReceive = 1;
USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
s_comOpen = 1;
usb_echo("USB_APP_CDC_DTE_ACTIVATED\r\n");
#endif
}
}
else

Wyświetl plik

@ -36,27 +36,10 @@
/*******************************************************************************
* Definitions
******************************************************************************/
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
#define CONTROLLER_ID kUSB_ControllerEhci0
#define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
#endif
#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
#define CONTROLLER_ID kUSB_ControllerKhci0
#define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
#endif
#if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
#define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
#define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
#endif
#if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
#define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
#define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
#endif
#define USB_DEVICE_INTERRUPT_PRIORITY (3U)
/* Currently configured line coding */