📄 usb_connection.c
字号:
/*
** ============================================================================
**
** FILE
** USB_connection.c
**
** DESCRIPTION
** realizes the UART command interpreter
**
** CREATED
** Silicon Laboratories Hungary Ltd
**
** COPYRIGHT
** Copyright 2008 Silicon Laboratories, Inc.
** http://www.silabs.com
**
** ============================================================================
*/
#ifndef USB_CONNECTION_C
#define USB_CONNECTION_C
#include "S8051.h"
#include "uart.h"
/*------------------------------------------------------------------------*/
/* GLOBAL variables */
/*------------------------------------------------------------------------*/
extern idata uint8 UartEcho;
extern code uint8 FirmwareVersion[5];
extern code uint8 HardwareVersion[5];
/*------------------------------------------------------------------------*/
/* FUNCTION prototypes */
/*------------------------------------------------------------------------*/
void _PrintDataH(uint8 d, uint8 chr);
void _PrintSpiIn(void);
uint8 _GetRegisterContent(uint8 * d, uint16 * command);
uint8 _AsciiTiInt(uint8 d);
uint8 _AsciiToBCD(uint8 d);
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: uint8 USBConnectionSupport(uint8 * uart_buffer)
+
+ DESCRIPTION: command interpreter
+
+ INPUT: uart_buffer - pointer to the buffer contains the received command
+
+ RETURN: TRUE - command is valid
+ FALSE - other case
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 USBConnectionSupport(uint8 * uart_buffer)
{
uint8 temp8;
uint16 temp16;
UU16 temp,ReceivedWord;
/*PRINT VERSION INFORMATION*/
if( uart_buffer[0] == 'i' || uart_buffer[0] == 'I' )
{
printf("\n\rSoftware Development Board FW V%s, HW V%s\n\rSilicon Labs., 2008",FirmwareVersion,HardwareVersion);
printf("\n\rwww.silabs.com");
return TRUE;
}
/*SET ECHO*/
if( uart_buffer[0] == 'e' || uart_buffer[0] == 'E' ) //================================
{ // echo_mode | 0 | 1 | 2 | 3 | 4 |
temp8 = uart_buffer[1] - '0'; //--------------------------------
if( (temp8 < 5) && (uart_buffer[2] == 0) ) // Echo | | X | | | |
{ // "SPI in:" | | X | | | |
UartEcho = temp8; // data read | | X | X | X | |
return TRUE; // ">" | X | X | X | X | X |
} //================================
}
/*SEND TWO BYTES OF SPI COMMAND*/
if( (memcmp(&uart_buffer[0], "s2", 2) == 0) || (memcmp(&uart_buffer[0], "S2", 2) == 0) )
{//set register
temp8 = _GetRegisterContent(&uart_buffer[2], &temp16);
if( temp8 == TRUE )
{
temp.U16 = temp16;
ReceivedWord = SpiRfReadWriteWord(temp);
_PrintSpiIn();
_PrintDataH(ReceivedWord.U8[MSB], 0);
_PrintDataH(ReceivedWord.U8[LSB], 'h');
return TRUE;
}
}
/*HELP*/
if( (memcmp(&uart_buffer[0], "?", 1) == 0) )
{
PrintHelp();
return TRUE;
}
return FALSE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void PrintHelp(void)
+
+ DESCRIPTION: prints out the available functions of the demo board
+
+ RETURN:
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void PrintHelp(void)
{
printf("\r\n----------------------------------HELP----------------------------------\r\n");
printf("CONTROL FROM WDS\r\n - 'S2xxxx': send two bytes of SPI command\r\n");
printf(" - 'Ex': set echo mode\r\n");
printf(" - 'I': get board information\r\n\r\n");
printf("-------------------------------------------------------------------------\r\n");
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void _PrintSpiIn(void)
+
+ DESCRIPTION: prints out SPI IN: according the echo tpye
+
+ RETURN:
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void _PrintSpiIn(void)
{
switch(UartEcho)
{
case 1:
printf("\n\rSPI IN: ");
break;
default:
break;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void _PrintDataH(uint8 d, uint8 chr)
+
+ DESCRIPTION: prints out data
+
+ RETURN:
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void _PrintDataH(uint8 d, uint8 chr)
{
switch(UartEcho)
{
case 1:
case 2:
case 3:
printf("%02bx",d);
if( chr )
{
putchar(chr);
}
break;
default:
break;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: uint8 _GetRegisterContent(uint8 * d, uint16 * command)
+
+ DESCRIPTION: get the register value
+
+ RETURN: d - value of the register
+
+ INPUT: command - register address
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 _GetRegisterContent(uint8 * d, uint16 * command)
{
uint8 temp8, shift, i;
uint16 temp16;
temp16 = 0;
shift = 16;
for(i=0;i<5;i++)
{
if( *d != 0 )
{
temp8 = _AsciiToBCD(*d++);
if( temp8 != 0xFF )
{
shift -= 4;
temp16 += ((uint16)temp8 << shift);
}
else
{
return FALSE;
}
}
else
{//no more data
*command = temp16 >> shift;
return TRUE;
}
}
//there were no ENTER
return FALSE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: uint8 _AsciiToBCD(uint8 d)
+
+ DESCRIPTION:
+
+ RETURN:
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 _AsciiToBCD(uint8 d)
{
uint8 temp8;
temp8 = _AsciiTiInt(d);
if( temp8 != 0xFF )
return temp8;
if( d > 64 && d < 71)
return ( d - 55 );
if( d > 96 && d < 103)
return ( d - 87 );
//not valid character
return 0xFF;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: uint8 _AsciiTiInt(uint8 d)
+
+ DESCRIPTION: prints out data
+
+ RETURN:
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 _AsciiTiInt(uint8 d)
{
uint8 temp8;
temp8 = d - 0x30;
if( temp8 < 10 )
return temp8;
else
return 0xFF;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -