⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsffuart.c

📁 uart实验源码!希望你可以给你们带来帮助!谢谢可以跟大家分享!
💻 C
📖 第 1 页 / 共 2 页
字号:
*/ 

static 
INT readFFUart(UartContextT * ctxP, CHAR * rxbufP, INT len) 
{ 
volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP; 
INT retry = RETRY; 
INT i; 

for (i=0; i < len; i++) 
{ 
// Wait for data to be available 
//while (((uartP->LSR &amt; LSR_DR) == 0) &amt;&amt; (--retry > 0)) 
// DM_WaitMs(1); 
while (((uartP->LSR &amt; LSR_DR) == 0)); //hzh 

// Read data 
if (retry > 0) 
*rxbufP++ = uartP->UDATA; 
else 
break; 
} 
return i; 
} 

static //add by hzh 
INT FFUartRxRdy(UartContextT * ctxP) 
{ 
volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP; 

return (uartP->LSR &amt; LSR_DR); 
} 

/* 
******************************************************************************* 
* 
* FUNCTION: clearRxFFUart 
* 
* DESCRIPTION: This function is used to clear receive FIFO of the UART 
* 
* INPUT PARAMETERS: ctxP is a pointer to UART context structure 
* 
* RETURNS: INT total number of bytes read 
* 
* GLOBAL EFFECTS: none. 
* 
* ASSUMPTIONS: none. 
* 
******************************************************************************* 
*/ 

static 
INT clearRxFFUart(UartContextT * ctxP) 
{ 
volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP; 
UINT data; 
INT total = 0; 

// Clear the Rx FIFO 
uartP->FCR = ctxP->uartCfgP->maskFIFO | FCR_RESETRF; 

// Read data from FIFO until none is left 
while ((uartP->LSR &amt; LSR_DR) != 0) 
{ 
data = uartP->UDATA; 
total++; 
} 

return total; 
} 

/* 
******************************************************************************* 
* 
* FUNCTION: XsFFUartHWShutdown 
* 
* DESCRIPTION: This function is used to shutdown the UART 
* Tx and Rx FIFOs are cleared and and a clock is stopped. 
* 
* INPUT PARAMETERS: ctxP is a pointer to the UART's context structure 
* 
* RETURNS: INT a contence of the Interrupt Enable Register (IER) 
* 
* GLOBAL EFFECTS: none. 
* 
* ASSUMPTIONS: none. 
* 
******************************************************************************* 
*/ 

static 
INT XsFFUartHWShutdown (UartContextT * ctxP) 
{ 
volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP; 

// Disable the UART 
uartP->IER &amt;= ~IER_UUE; 

// Clear MCR register 
uartP->MCR = 0; 

// Clear the peripheral clock bit for the UART 
xsCMDisableClock (CK_FFUART); 

return uartP->IER; 
} 

/* 
******************************************************************************* 
* 
* FUNCTION: InterruptHandlerDmaTxFFUart 
* 
* DESCRIPTION: Interrupt handler for DMA Tx transfer. 
* This is callback function, called by the DMA service. 
* 
* INPUT PARAMETERS: PVOID param - pointer to the Uart's context structure 
* UINT32 triggeringDcsr - contains the interrupts status 
* 
* RETURNS: None 
* 
* GLOBAL EFFECTS: None 
* 
* ASSUMPTIONS: The DMA service clears the interrupts 
* 
* CALLS: 
* 
* CALLED BY: DMA interrupt service 
* 
* PROTOTYPE: VOID InterruptHandlerDmaTxFFUart (PVOID param, UINT32 triggeringDcsr); 
* 
******************************************************************************* 
*/ 
/* 
VOID InterruptHandlerDmaTxFFUart (PVOID param, UINT32 triggeringDcsr) 
{ 
UartContextT * ctxP = (UartContextT *)param; 

// Check for the bus error 
if (triggeringDcsr &amt; DCSR_BUSERRINTR) 
{ 
DM_CwDbgPrintf(DM_CW_UART_0, "Bus Error Interrupt \n"); 
// Increment bus errorcounter 
ctxP->dmaTxIntStatusP->busErrorIntCount++; 
} 

// Check for completion of the current transmition 
if (triggeringDcsr &amt; DCSR_ENDINTR) 
{ 
// Increment end interrupt counter 
ctxP->dmaTxIntStatusP->endIntCount++; 
if (ctxP->dmaTxIntStatusP->endIntCount >= ctxP->dmaTxCfgP->descNum) 
{ 
DM_CwDbgPrintf(DM_CW_UART_0, "End of the Tx transfer"); 
ctxP->xferTxComplete = TRUE; 
} 
} 

if (triggeringDcsr &amt; DCSR_STARTINTR) 
{ 
// Increment start interrupt counter 
ctxP->dmaTxIntStatusP->startIntCount++; 
} 

if (triggeringDcsr &amt; DCSR_STOPINTR) 
{ 
// Increment stop interrupt counter 
ctxP->dmaTxIntStatusP->stopIntCount++; 
DM_CwDbgPrintf(DM_CW_UART_0, "End of the Tx transfer"); 
ctxP->xferTxComplete = TRUE; 
} 
} 
*/ 
/* 
******************************************************************************* 
* 
* FUNCTION: InterruptHandlerDmaRxFFUart 
* 
* DESCRIPTION: Interrupt handler for DMA Rx transfer. 
* This is callback function, called by the DMA service. 
* 
* INPUT PARAMETERS: PVOID param - pointer to the Uart's context structure 
* UINT32 triggeringDcsr - contains the interrupts status 
* 
* RETURNS: None 
* 
* GLOBAL EFFECTS: None 
* 
* ASSUMPTIONS: The DMA service clears the interrupts 
* 
* CALLS: 
* 
* CALLED BY: DMA interrupt service 
* 
* PROTOTYPE: VOID InterruptHandlerDmaRxFFUart (PVOID param, UINT32 triggeringDcsr); 
* 
******************************************************************************* 
*/ 
/* 
VOID InterruptHandlerDmaRxFFUart (PVOID param, UINT32 triggeringDcsr) 
{ 
UartContextT * ctxP = (UartContextT *)param; 

// Check for the bus error 
if (triggeringDcsr &amt; DCSR_BUSERRINTR) 
{ 
DM_CwDbgPrintf(DM_CW_UART_0, "Bus Error Interrupt \n"); 
// Increment bus errorcounter 
ctxP->dmaRxIntStatusP->busErrorIntCount++; 
} 

// Check for completion of the current transmition 
if (triggeringDcsr &amt; DCSR_ENDINTR) 
{ 
// Increment end interrupt counter 
ctxP->dmaRxIntStatusP->endIntCount++; 
if (ctxP->dmaRxIntStatusP->endIntCount >= ctxP->dmaRxCfgP->descNum) 
{ 
DM_CwDbgPrintf(DM_CW_UART_0, "End of the Rx transfer"); 
ctxP->xferRxComplete = TRUE; 
} 
} 

if (triggeringDcsr &amt; DCSR_STARTINTR) 
{ 
// Increment start interrupt counter 
ctxP->dmaRxIntStatusP->startIntCount++; 
} 

if (triggeringDcsr &amt; DCSR_STOPINTR) 
{ 
// Increment stop interrupt counter 
ctxP->dmaRxIntStatusP->stopIntCount++; 
DM_CwDbgPrintf(DM_CW_UART_0, "End of the Rx transfer"); 
ctxP->xferRxComplete = TRUE; 
} 
} 
*/ 
/* 
******************************************************************************* 
* 
* FUNCTION: XsFFUartSWInit 
* 
* DESCRIPTION: This function is used to initialize FFUART's context structure. 
* No hardware setup is done at this point. 
* 
* INPUT PARAMETERS: none. 
* 
* RETURNS: none. 
* 
* GLOBAL EFFECTS: none. 
* 
* ASSUMPTIONS: none. 
* 
******************************************************************************* 
*/ 

void XsFFUartSWInit (void) 
{ 
// Initialize the UART 
UartContextT * ctxP = &amt;FFUart; 

// Initialize the UART's register base 
UartRegsT * regsP = (UartRegsT *)FFUARTREG_BASE; 
ctxP->regsP = regsP; 

// Initialize the UART's setup configuration 
ctxP->uartCfgP = &amt;defaultFFUartCfg; 

// Initialize the UART's Dma configuration 
ctxP->dmaTxCfgP = &amt;defaultDmaTxCfg; 
ctxP->dmaRxCfgP = &amt;defaultDmaRxCfg; 

// Initialize the UART's pointer to the Dma Status structure 
ctxP->dmaTxIntStatusP = &amt;defaultDmaTxStatus; 
ctxP->dmaRxIntStatusP = &amt;defaultDmaRxStatus; 

// Set the context structures functions pointers 
ctxP->setupUartFnP = (UartSetupT)XsFFUartHWSetup; 
ctxP->loopbackUartFnP = (UartLoopbackT)loopbackFFUart; 
ctxP->writeUartFnP = (UartWriteT)writeFFUart; 
ctxP->readUartFnP = (UartReadT)readFFUart; 
ctxP->RxRdyUartFnP = (UartRxRdyT)FFUartRxRdy; //add by hzh 
ctxP->clearRxUartFnP = (UartClearRxT)clearRxFFUart; 
ctxP->shutdownUartFnP = (UartCleanupT)XsFFUartHWShutdown; 
//ctxP->intHandlerDmaTxFnP = (UartDmaIntHandlerT)InterruptHandlerDmaTxFFUart; 
// ctxP->intHandlerDmaRxFnP = (UartDmaIntHandlerT)InterruptHandlerDmaRxFFUart; 

// Load Uart ID 
ctxP->type = FFUartType; 

ctxP->loggedError = 0; 
ctxP->dmaRxChannel = 0; 
ctxP->dmaTxChannel = 0; 
ctxP->xferTxComplete = 0; 
ctxP->xferRxComplete = 0; 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -