📄 vcomuser.c
字号:
case USB_EVT_OUT:
DeviceData2UART( 1 );
break;
}
event;
}
/*
* USB Endpoint 6 Event Callback
* Parameter: event
*/
void USB_EndPoint6 (DWORD event) {
event;
}
/*
* USB Endpoint 7 Event Callback
* Parameter: event
*/
void USB_EndPoint7 (DWORD event) {
event;
}
/*
* USB Endpoint 8 Event Callback
* Parameter: event
*/
void USB_EndPoint8 (DWORD event) {
event;
}
/*
* USB Endpoint 9 Event Callback
* Parameter: event
*/
void USB_EndPoint9 (DWORD event) {
event;
}
/*
* USB Endpoint 10 Event Callback
* Parameter: event
*/
void USB_EndPoint10 (DWORD event) {
event;
}
/*
* USB Endpoint 11 Event Callback
* Parameter: event
*/
void USB_EndPoint11 (DWORD event) {
event;
}
/*
* USB Endpoint 12 Event Callback
* Parameter: event
*/
void USB_EndPoint12 (DWORD event) {
event;
}
/*
* USB Endpoint 13 Event Callback
* Parameter: event
*/
void USB_EndPoint13 (DWORD event) {
event;
}
/*
* USB Endpoint 14 Event Callback
* Parameter: event
*/
void USB_EndPoint14 (DWORD event) {
event;
}
/*
* USB Endpoint 15 Event Callback
* Parameter: event
*/
void USB_EndPoint15 (DWORD event) {
event;
}
/* UART setup and simple putc() and getc() routine */
/* Default setting of CCLK is 60Mhz, VPBCLK is 1/4 = 15Mhz */
void init_serial (void) { /* Initialize Serial Interface */
#if NO_UART_CABLE
#else
PINSEL0 = 0x00050005; /* Enable RxD1 and TxD1, RxD0 and TxD0 */
#endif
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
U0FCR = 0x07; /* Enable and reset TX and RX FIFO. */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
U1FCR = 0x07; /* Enable and reset TX and RX FIFO. */
}
int putchar(BYTE portNum, int ch) { /* Write character to Serial Port */
if ( portNum == 0 ) {
if (ch == '\n') {
while (!(U0LSR & 0x20));
U0THR = CR; /* output CR */
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
else {
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
}
int getchar ( BYTE portNum ) { /* Read character from Serial Port */
if ( portNum == 0 ) {
while (!(U0LSR & 0x01));
return (U0RBR);
}
else {
while (!(U1LSR & 0x01));
return (U1RBR);
}
}
/* Setup SIO configuration based on the channel number */
void SetSIOBaudrate( BYTE channelNum, BYTE Data )
{
/* Data = 0x1 Baudrate = 115,200
Data = 0x2 Baudrate = 57,600
Data = 0x3 Baudrate = 38,400
Data = 0x6 Baudrate = 19,200
Data = 0x0C Baudrate = 9,600 */
/* PCLK is set the same as CCLK at 60Mhz */
if ( channelNum == 0 ) {
U0FCR = 0x07; /* Enable and reset TX and RX FIFO. */
U0LCR |= 0x80;
if ( Data == 0x01 ) {
U0DLL = 0x20;
U0DLM = 0x00;
}
else if ( Data == 0x02 ) {
U0DLL = 0x41;
U0DLM = 0x00;
}
else if ( Data == 0x03 ) {
U0DLL = 0x61;
U0DLM = 0x00;
}
else if ( Data == 0x06 ) {
U0DLL = 0xC3;
U0DLM = 0x00;
}
else if ( Data == 0x0C ) {
U0DLL = 0x86;
U0DLM = 0x01;
}
U0LCR &= ~0x80;
}
else if ( channelNum == 1 ) {
U1FCR = 0x07; /* Enable and reset TX and RX FIFO. */
U1LCR |= 0x80;
if ( Data == 0x01 ) {
U1DLL = 0x20;
U1DLM = 0x00;
}
else if ( Data == 0x02 ) {
U1DLL = 0x41;
U1DLM = 0x00;
}
else if ( Data == 0x03 ) {
U1DLL = 0x61;
U1DLM = 0x00;
}
else if ( Data == 0x06 ) {
U1DLL = 0xC3;
U1DLM = 0x00;
}
else if ( Data == 0x0C ) {
U1DLL = 0x86;
U1DLM = 0x01;
}
U1LCR &= ~0x80;
}
}
void SetSIOStopBit( BYTE channelNum, BYTE ConfigValue )
{
BYTE lcr;
/* 0 is 1 stop bit, 1 is 2 stop bits, bit2 on LCR is stop bit setting */
if ( channelNum == 0 ) {
lcr = U0LCR & 0xFB;
U0LCR = lcr | (ConfigValue << 2);
}
else if ( channelNum == 1 ) {
lcr = U1LCR & 0xFB;
U1LCR = lcr | (ConfigValue << 2);
}
}
void SetSIODataBit( BYTE channelNum, BYTE ConfigValue )
{
BYTE lcr;
if ( channelNum == 0 ) {
lcr = U0LCR & 0xFC;
U0LCR = lcr | ConfigValue;
}
else if ( channelNum == 1 ) {
lcr = U1LCR & 0xFC;
U1LCR = lcr | ConfigValue;
}
}
void SetSIOParity( BYTE channelNum, BYTE ConfigValue )
{
BYTE lcr;
if ( channelNum == 0 ) {
lcr = U0LCR & 0xCF;
U0LCR = lcr | (ConfigValue << 4);
}
else if ( channelNum == 1 ) {
lcr = U1LCR & 0xCF;
U1LCR = lcr | (ConfigValue << 4);
}
}
void SetSIOFlowControl( BYTE channelNum, BYTE ConfigValue )
{
/* NO flow control setting is neceaasry, unlike the UART on x51 */
if ( channelNum == 0 ) {
ConfigValue = ConfigValue;
}
else if ( channelNum == 1 ) {
ConfigValue = ConfigValue;
}
}
void SetSIODTR( BYTE channelNum, BYTE ConfigValue )
{
BYTE mcr;
/* only apply to channel 1 */
if ( channelNum == 1 ) {
mcr = U1MCR & 0xFE;
U1MCR = mcr | ConfigValue;
}
}
void SetSIORTS( BYTE channelNum, BYTE ConfigValue )
{
BYTE mcr;
/* only apply to channel 1 */
if ( channelNum == 1 ) {
mcr = U1MCR & 0xFD;
U1MCR = mcr | (ConfigValue << 1);
}
}
void GetSIOModemStatus( BYTE channelNum )
{
channelNum = channelNum;
}
/*
* VCOM Get SIO Setup Request Callback
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL VCOM_GetSIOSetup (void) {
/* Get SIO setup from the device, not supported */
return (TRUE);
}
/*
* VCOM Set SIO Setup Request Callback
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL VCOM_SetSIOSetup( BYTE Cmd, BYTE Data ) {
BYTE ChannelNum;
/* Set SIO configuration, baudrate, data bits, stop bits, parity, flow control,
based on the info. from the host */
if ( !(Cmd & 0x20) )
ChannelNum = 0;
else
ChannelNum = 1;
Cmd &= ~0x20; /* clear bit 5, use all cmd for channel 0 */
switch ( Cmd ) {
case BAUDRATE_SETUP:
SetSIOBaudrate( ChannelNum, Data );
break;
case STOPBIT_SETUP:
SetSIOStopBit( ChannelNum, Data );
break;
case DATABIT_SETUP:
SetSIODataBit( ChannelNum, Data );
break;
case PARITY_SETUP:
SetSIOParity( ChannelNum, Data );
break;
case FLOWCTRL_SETUP:
SetSIOFlowControl( ChannelNum, Data );
break;
case DTR_SETUP:
SetSIODTR( ChannelNum, Data );
break;
case RTS_SETUP:
SetSIORTS( ChannelNum, Data );
break;
case HARDCODE_SETUP:
break;
case MODEM_SETUP:
GetSIOModemStatus( ChannelNum );
break;
default:
// EP0Buf[] = ...;
// break;
return (FALSE);
}
return (TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -