📄 debug.c
字号:
//
// Copyright (c) 2002 Palmmicro Communications Inc. All rights reserved.
//
// --------------------------------------------------------------------
/*++
Module Name:
debug.c
Abstract:
This file implements the facilities for debugging.
Notes:
--*/
#include "def.h"
#include "at4x0f.h"
#include "cspregs.h"
#include <stdio.h>
#include <stdarg.h>
#include "debug.h"
#include "sysclock.h"
extern SYSTEMCLOCKINFO g_SysClock;
#define IO_CLK (g_SysClock.dwIoClock)
#define RESET_SR_USP7_RST (1 << 25) // USP7 software reset
#ifdef DEBUG_UART_PORT
#ifdef DEBUG_UART_PORT_6
void _uart_init(int baudrate)
{
int stop_bit_num = 1;
int data_bit_num = 3;
int sample_div = 16;
int i,uart_baud_rate;
// enable usp7 pin
//ENABLE_USP0_DATA_PAD();// release pin to USP0 txd and rxd
//ENABLE_USP0_CTRL_PAD();// release pin to USP0 flow control
ENABLE_USP2_PAD();
// for safety reason, reset the uart block
PWR_CLOCK_ENABLE(PWRCLK_SP0_EN);
RESET_DECLARE(RESET_SR_USP6_RST);
for(i=0; i<10; i++);
RESET_CLEAR(RESET_SR_USP6_RST);
for(i=0; i<10; i++);
RSC_PIN_MUX |= 0x40;
uart_baud_rate = (IO_CLK * 2/sample_div/baudrate + 1) / 2 - 1;
UART6_DIVISOR = uart_baud_rate |((sample_div-1)<<16);
//UART_IO_DIV=uart_baud_rate;
UART6_LINE_CTRL = data_bit_num|(stop_bit_num<<2);
UART6_TX_DMA_IO_CTRL = UART6_TX_IO_MODE;
UART6_RX_DMA_IO_CTRL = UART6_RX_IO_MODE;
UART6_TX_DMA_IO_LEN = 0;
UART6_RX_DMA_IO_LEN = 0;
UART6_TXFIFO_CTRL = 0x08 ;
UART6_RXFIFO_CTRL = 0x18 ;
UART6_TXFIFO_LEVEL_CHK = 0x06 | (0x04 << 10) | (0x02 << 20);
UART6_RXFIFO_LEVEL_CHK = 0x02 | (0x04 << 10) | (0x06 << 20);
UART6_TXRX_ENA_REG = UART6_RX_EN | UART6_TX_EN;
// Fifo Reset
UART6_TXFIFO_OP = UART6_TXFIFO_RESET;
UART6_RXFIFO_OP = UART6_RXFIFO_RESET;
// Fifo Start
UART6_TXFIFO_OP = UART6_TXFIFO_START;
UART6_RXFIFO_OP = UART6_RXFIFO_START;
// clear all pending uart interrupts
UART6_INT_STATUS = UART_INT_MASK_ALL;
}
#else
#ifdef DEBUG_UART_PORT_7
void _uart_init(int baudrate)
{
int stop_bit_num = 1;
int data_bit_num = 3;
int sample_div = 16;
int i,uart_baud_rate;
// enable usp7 pin
//ENABLE_USP0_DATA_PAD();// release pin to USP0 txd and rxd
//ENABLE_USP0_CTRL_PAD();// release pin to USP0 flow control
ENABLE_USP3_PAD();
// for safety reason, reset the uart block
PWR_CLOCK_ENABLE(PWRCLK_SP0_EN);
RESET_DECLARE(RESET_SR_USP7_RST);
for(i=0; i<10; i++);
RESET_CLEAR(RESET_SR_USP7_RST);
for(i=0; i<10; i++);
RSC_PIN_MUX |= 0x80;
uart_baud_rate = (IO_CLK * 2/sample_div/baudrate + 1) / 2 - 1;
UART7_DIVISOR = uart_baud_rate |((sample_div-1)<<16);
//UART_IO_DIV=uart_baud_rate;
UART7_LINE_CTRL = data_bit_num|(stop_bit_num<<2);
UART7_TX_DMA_IO_CTRL = UART7_TX_IO_MODE;
UART7_RX_DMA_IO_CTRL = UART7_RX_IO_MODE;
UART7_TX_DMA_IO_LEN = 0;
UART7_RX_DMA_IO_LEN = 0;
UART7_TXFIFO_CTRL = 0x08 ;
UART7_RXFIFO_CTRL = 0x18 ;
UART7_TXFIFO_LEVEL_CHK = 0x06 | (0x04 << 10) | (0x02 << 20);
UART7_RXFIFO_LEVEL_CHK = 0x02 | (0x04 << 10) | (0x06 << 20);
UART7_TXRX_ENA_REG = UART7_RX_EN | UART7_TX_EN;
// Fifo Reset
UART7_TXFIFO_OP = UART7_TXFIFO_RESET;
UART7_RXFIFO_OP = UART7_RXFIFO_RESET;
// Fifo Start
UART7_TXFIFO_OP = UART7_TXFIFO_START;
UART7_RXFIFO_OP = UART7_RXFIFO_START;
// clear all pending uart interrupts
UART7_INT_STATUS = UART_INT_MASK_ALL;
}
#else
void _uart_init(int baudrate)
{
int i,uart_baud_rate;
// for safety reason, reset the uart block
PWR_CLOCK_ENABLE(PWRCLK_SP0_EN);
RESET_DECLARE(RESET_SR_SP0_RST);
for(i=0; i<10; i++);
RESET_CLEAR(RESET_SR_SP0_RST);
for(i=0; i<10; i++);
ENABLE_USP0_DATA_PAD();// release pin to USP0 txd and rxd
ENABLE_USP0_CTRL_PAD();// release pin to USP0 flow control
uart_baud_rate = (IO_CLK * 2/16/baudrate + 1) / 2 - 1;
UART_DIVISOR = uart_baud_rate |((16-1)<<16);
UART_IO_DIV=uart_baud_rate;
UART_LINE_CTRL = 3;
UART_TX_DMA_IO_CTRL = UART_TX_IO_MODE;
UART_RX_DMA_IO_CTRL = UART_RX_IO_MODE;
UART_TX_DMA_IO_LEN = 0;
UART_RX_DMA_IO_LEN = 0;
UART_TXFIFO_CTRL = 0x08 ;
UART_RXFIFO_CTRL = 0x18 ;
UART_TXFIFO_LEVEL_CHK = 0x06 | (0x04 << 10) | (0x02 << 20);
UART_RXFIFO_LEVEL_CHK = 0x02 | (0x04 << 10) | (0x06 << 20);
UART_TXRX_ENA_REG = UART_RX_EN | UART_TX_EN;
// Fifo Reset
UART_TXFIFO_OP = UART_TXFIFO_RESET;
UART_RXFIFO_OP = UART_RXFIFO_RESET;
// Fifo Start
UART_TXFIFO_OP = UART_TXFIFO_START;
UART_RXFIFO_OP = UART_RXFIFO_START;
// clear all pending uart interrupts
UART_INT_STATUS = UART_INT_MASK_ALL;
}
#endif
#endif
#else // DEBUG_UART_PORT
void _usp5_init(int baudrate, int stop_bit_num, int irda_en, int irda_width,int irda_idle_level, int sample_div)
{
int tx_data_len, tx_sync_len, tx_frm_len, tx_shifter_len;
int rx_data_len, rx_frm_len, rx_shifter_len;
int rxfifo_threshold, txfifo_threshold;
int i, usp_baud_rate;
// IO_CLOCK_75M();// 75MHz ioclk
/* PWR_PLL1_CONFIG=0x2319; //pll1 output 100MHz clock
for(io_i=1;io_i<=30;io_i++); \
PWR_CLK_RATIO=0x40; // the ratio of both cpu and sys clock are 1 and that of ioclk is 1/2
for(io_i=1;io_i<=30;io_i++); \
PWR_CLK_SWITCH=0x2; //select the PLL1
*/
// for safety reason, reset the uart block
// PWR_CLOCK_ENABLE(PWRCLK_SP5_EN);
RESET_DECLARE(RESET_SR_SP5_RST);
for(i=0; i<10; i++);
RESET_CLEAR(RESET_SR_SP5_RST);
for(i=0; i<10; i++);
// IO_CLOCK_75M();// 75MHz ioclk
// RSC_PIN_MUX=0;
ENABLE_USP5_PAD();
PWR_PIN_RELEASE=1;
uart_baud_rate = (IO_CLK * 2/sample_div/baudrate + 1) / 2 - 1;
// Set to RS232 asynchronous mode
USP5_MODE1 = irda_idle_level|USP_LITTLE_ENDIAN|irda_en|(i<<22);
// clear all pending uart interrupts
USP5_INT_STATUS = USP_INT_MASK_ALL;
USP5_MODE2 = 1 | // RX_DATA_DELAY_LENGTH
(1 << 8)| // TX_DATA_DELAY_LENGTH
(usp_baud_rate << 21) |
irda_width;
USP5_RX_TIMEOUT_PAR=USP5_RX_TIMEOUT_PAR&0xffff|((sample_div-1)<<16);
USP5_TX_DMA_IO_CTRL = USP_TX_IO_MODE;
USP5_RX_DMA_IO_CTRL = USP_RX_IO_MODE;
USP5_TX_DMA_IO_LEN = 0;
USP5_RX_DMA_IO_LEN = 0;
tx_data_len = 0x07; // 8 bit data
tx_sync_len = 0x08; // add 1 start data
tx_frm_len = 0x08+stop_bit_num; // add stop_bit_num stop bit
tx_shifter_len = 0x07;
USP5_TX_FRAME_CTRL = tx_data_len |
(tx_sync_len << 8) |
(tx_frm_len << 16) |
(tx_shifter_len << 24);
rx_data_len = 0x07; // 8 bit data
rx_frm_len = 0x08+stop_bit_num; // add stop_bit_num stop bit
rx_shifter_len = 0x07;
USP5_RX_FRAME_CTRL = rx_data_len |
(rx_frm_len << 8) |
(rx_shifter_len << 16);
txfifo_threshold=0x08;
rxfifo_threshold=0x18;
USP5_TXFIFO_CTRL = (txfifo_threshold << 2);
USP5_RXFIFO_CTRL = (rxfifo_threshold << 2);
USP5_TXFIFO_LEVEL_CHK = 0x06 | (0x04 << 10) | (0x02 << 20);
USP5_RXFIFO_LEVEL_CHK = 0x02 | (0x04 << 10) | (0x06 << 20);
// Enable TX and RX
USP5_MODE1 |= USP_ENABLE;
USP5_TX_RX_ENABLE = USP_RX_EN | USP_TX_EN;
// Fifo Reset
USP5_TXFIFO_OP = USP_TXFIFO_RESET;
USP5_RXFIFO_OP = USP_RXFIFO_RESET;
// Fifo Start
USP5_TXFIFO_OP = USP_TXFIFO_START;
USP5_RXFIFO_OP = USP_RXFIFO_START;
}
#endif // DEBUG_UART_PORT
void _dbgputchar (char ch)
{
#ifdef DEBUG_UART_PORT
#ifdef DEBUG_UART_PORT_6
while (UART6_TXFIFO_STATUS & UART6_TXFIFO_FULL) {}
UART6_TXFIFO_DATA = ch;
#else
#ifdef DEBUG_UART_PORT_7
while (UART7_TXFIFO_STATUS & UART7_TXFIFO_FULL) {}
UART7_TXFIFO_DATA = ch;
#else
while (UART_TXFIFO_STATUS & UART_TXFIFO_FULL) {}
UART_TXFIFO_DATA = ch;
#endif
#endif
#else // DEBUG_UART_PORT
while (USP5_TXFIFO_STATUS & USP_TXFIFO_FULL) {}
USP5_TXFIFO_DATA = ch;
#endif // DEBUG_UART_PORT
}
void _dbgputstring (const char *str)
{
while (*str) {
_dbgputchar (*str++);
}
}
void _dbgputhex (unsigned num)
{
static const char HexCharTable [] = "0123456789ABCDEF";
int i;
_dbgputchar ('0');
_dbgputchar ('x');
for (i = 28; i >= 0; i -= 4) {
_dbgputchar (HexCharTable [(num >> i) & 0x0f]);
}
}
char _dbggetchar (void)
{
#ifdef DEBUG_UART_PORT
#ifdef DEBUG_UART_PORT_6
if (UART6_RXFIFO_STATUS & UART6_RXFIFO_EMPTY)
return OEM_DEBUG_READ_NODATA;
return (char) UART6_RXFIFO_DATA;
#else
#ifdef DEBUG_UART_PORT_7
if(UART7_RXFIFO_STATUS & UART7_RXFIFO_EMPTY)
return OEM_DEBUG_READ_NODATA;
return (char) UART7_RXFIFO_DATA;
#else
if (UART_RXFIFO_STATUS & UART_RXFIFO_EMPTY)
return OEM_DEBUG_READ_NODATA;
else
return (char) UART_RXFIFO_DATA;
#endif
#endif
#else // DEBUG_UART_PORT
if (USP5_RXFIFO_STATUS & USP_RXFIFO_EMPTY)
return OEM_DEBUG_READ_NODATA;
else
return (char) USP5_RXFIFO_DATA;
#endif // DEBUG_UART_PORT
}
#if defined (DEBUG_NBOOT)
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]);
}
}
const char LedCharTable[] = { LED_SHOW_0, LED_SHOW_1, LED_SHOW_2, LED_SHOW_3,
LED_SHOW_4, LED_SHOW_5, LED_SHOW_6, LED_SHOW_7,
LED_SHOW_8, LED_SHOW_9, LED_SHOW_A, LED_SHOW_B,
LED_SHOW_C, LED_SHOW_D, LED_SHOW_E, LED_SHOW_F,
0xff /* nothing */
};
/*
if the value cDisp is passed in as an ascii character,
we can display 0-9, A-F.
if the value cDisp is a value less than or equal to 16,
we just take it as a hex value and display the hex char
*/
void _leddispchar(int iLED, unsigned char cDispChar)
{
unsigned char disp;
if (cDispChar <= 16) {
disp = LedCharTable[cDispChar];
} else if (cDispChar>='0' && cDispChar<='9') {
disp = LedCharTable[cDispChar - '0'];
} else if (cDispChar>='a' && cDispChar<='f') {
disp = LedCharTable[cDispChar - 'a' + 10];
} else if (cDispChar>='A' && cDispChar<='F') {
disp = LedCharTable[cDispChar - 'A' + 10];
} else {
disp = LedCharTable[16];
}
if (iLED == 0) {
TLCD_LED1 = disp;
} else {
TLCD_LED2 = disp;
}
}
#endif // defined (DEBUG_NBOOT)
/* end of debug.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -