TMC32_QJB/VSP/VSP_main.c
2026-04-30 16:23:12 +08:00

72 lines
1.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************************
* Copyright (c) 2016, Beijing Tongfang Microelectroics Co., Ltd.
* All rights reserved.
* Module: VSP Data processing
* Author: Yang Song
* Version: V1.0
* History:
* 2016-09-22 Original version
********************************************************************************/
#include "global.h"
/***************************************************************************
* Function: usbVspSendChars
* Description: 数据发送
* Input: buf 待发送数据地址
* Input: len 待发送数据长度
* Output: NULL
* Return: NULL
* Other: NULL
**************************************************************************/
void usbVspSendChars(u8 *buf, u32 len)
{
u32 offset=0;
u32 dly;
if (len > 200*1024)
{
dly = 0;
}
else
{
dly = 1;
}
while(len >= VSPTXLEN){
memcpy(g_abUsbEp2Buf, buf+offset, VSPTXLEN);
usbEpnTxAll(2,g_abUsbEp2Buf,VSPTXLEN);
TimerDelay(TIM2, dly);
offset += VSPTXLEN;
len -= VSPTXLEN;
}
memcpy(g_abUsbEp2Buf, buf+offset, len);
usbEpnTxAll(2,g_abUsbEp2Buf,len);
}
/***************************************************************************
* Function: usbVspRecvChars
* Description: 数据接收
* Input: 把收到的数据拷贝到buf
* Input: bufSize buf的大小防止越界
* Output: 收到的数据长度
* Return: NULL
* Other: NULL
**************************************************************************/
u32 usbVspRecvChars(u8 *buf, u32 bufSize)
{
u32 rcvlen = 0;
if (USBEP1STS & Bit19_En)
{
rcvlen = (USBEP1STS >> 8) & 0x000003FF;
rcvlen = rcvlen > bufSize ? bufSize:rcvlen;
memcpy(buf, g_abUsbEp1Buf, rcvlen);
USBEP1CON |= Bit9_En; // clear buf 控制端点是bit10 其他端点是bit9
}
return rcvlen;
}