📄 transport.c
字号:
#include "def.h"
#include "debug.h"
#include "vendormsg.h"
#include "usb.h"
#include "at4x0f.h"
extern int g_iDevStatus;
#define DBG_INPUT_BUF_SIZE 64
char g_dbgMsg[DBG_INPUT_BUF_SIZE];
static int _iOffset;
void DbgPutChar(char ch)
{
char c[2];
c[0] = ch;
c[1] = 0;
if(g_iDevStatus < ATLAS_DEV_STATUS_IN_USB_SESSION_NBOOT)
_dbgputchar((char)(ch));
else
USB_OutputString(c);
}
void DbgPutString(const char *str)
{
if(g_iDevStatus < ATLAS_DEV_STATUS_IN_USB_SESSION_NBOOT)
_dbgputstring(str);
else
USB_OutputString(str);
}
void DbgPutHex(unsigned hex)
{
static const char HexCharTable [] = "0123456789ABCDEF";
char out[12];
int i,j;
out[0] = '0';
out[1] = 'x';
j = 2;
for (i = 28; i >= 0; i -= 4) {
out[j++] = (HexCharTable [(hex >> i) & 0x0f]);
}
out[10] = 0;
if(g_iDevStatus < ATLAS_DEV_STATUS_IN_USB_SESSION_NBOOT)
_dbgputstring(out);
else
USB_OutputString(out);
}
void DbgPutDec(unsigned num)
{
char decnum[12];
int i = sizeof decnum / sizeof decnum[0] - 1;
if (num < 10) {
DbgPutChar (num + '0');
}
else {
decnum [i] = '\0';
while (num) {
--i;
decnum [i] = '0' + (num % 10);
num /= 10;
}
DbgPutString (&decnum [i]);
}
}
char * DbgGetString(void)
{
char c;
if(g_iDevStatus < ATLAS_DEV_STATUS_IN_USB_SESSION_NBOOT)
{
c = _dbggetchar();
if(c == OEM_DEBUG_READ_NODATA)
return NULL;
if(c == 0x0a || c == 0x0d)
{
g_dbgMsg[_iOffset] = 0;
_iOffset = 0;
return g_dbgMsg;
}
else
{
if(_iOffset < DBG_INPUT_BUF_SIZE - 1)
{
if(c == 0x08)
{
if(_iOffset)
_iOffset --;
}
else
{
g_dbgMsg[_iOffset++] = c;
_dbgputchar(c);
}
}
}
}
else
{
return USB_GetInstruction();
}
return NULL;
}
void DbgFlush(void)
{
int i;
#ifdef DEBUG_UART_PORT
#ifdef DEBUG_UART_PORT_6
while (!(UART6_TXFIFO_STATUS & UART6_TXFIFO_EMPTY)) {}
#elif defined DEBUG_UART_PORT_7
while (!(UART7_TXFIFO_STATUS & UART7_TXFIFO_EMPTY)) {}
#else // default we'll use UART 0 as debug port
while (!(UART_TXFIFO_STATUS & UART_TXFIFO_EMPTY)) {}
#endif
#else // DEBUG_UART_PORT
while (!(USP5_TXFIFO_STATUS & USP_TXFIFO_EMPTY)) {}
#endif // DEBUG_UART_PORT
for (i = 0; i < 0x5000; ++i) {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -