?? ti752.c
字號:
//--------------------------------------------------------------------------
// IP Stack
//--------------------------------------------------------------------------
// ti750.c - TI TLC16C750 Serial Port Driver with HDLC
//
// Author: Michael Denio
// Copyright 2001, 2003 by Texas Instruments, Inc.
//-------------------------------------------------------------------------
#include <std.h>
#include <sys.h>
#include <sem.h>
#include <hwi.h>
#include <c62.h>
#include <stkmain.h>
#include "llserial.h"
#include "ti752.h"
//
// We use the following direct access to registers
//
extern cregister volatile uint ICR;
//
// Declare our local functions
//
static void spInitialize( SDINFO *pi );
static void spStart( SDINFO *pi );
static void spStop( SDINFO *pi );
static void spIsr(SDINFO *pi);
static uint spWriteFifo( SDINFO *pi );
// Basic HDLC equates
#define HDLC_FLAGCHAR 0x7E // Character to indicate frame boundary
#define HDLC_MINCHAR 0x20 // Minimum non-escaped char
#define HDLC_ESCCHAR 0x7D // Character to indicate escape
#define HDLC_XORCHAR 0x20 // Escape XOR modifier
// FCS lookup table as calculated by the table generator.
#define PPPINITFCS16 0xffff // Initial FCS value
#define PPPGOODFCS16 0xf0b8 // Good final FCS value
static const UINT16 fcstab[16] = {
0x0000, 0x1081, 0x2102, 0x3183, 0x4204, 0x5285, 0x6306, 0x7387,
0x8408, 0x9489, 0xA50A, 0xB58B, 0xC60C, 0xD68D, 0xE70E, 0xF78F
};
uint SerRxGood=0,SerRxBadCRC=0;
//--------------------------------------------------------------------
// HwSerInit()
//
// Initialize serial environment and return instance count
//--------------------------------------------------------------------
uint HwSerInit()
{
// EMIF control
if( HW_CE_REG )
*HW_CE_REG = HW_CE_VALUE;
#ifdef EVMDM642
EVMDM642_OSD_init();
#endif
return(2);
}
//--------------------------------------------------------------------
// HwSerShutdown()
//
// Shutdown Device Environment
//--------------------------------------------------------------------
void HwSerShutdown()
{
}
//--------------------------------------------------------------------
// HwSerOpen()
//
// Open Device Instance
//--------------------------------------------------------------------
uint HwSerOpen( SDINFO *pi )
{
uint device;
// Setup the base address
#ifdef EVMDM642
if( !pi->PhysIdx )
{
pi->HwBaseAddr = ACE_PORT_BASE1;
device = UARTA_IRQ;
}
else
{
pi->HwBaseAddr = ACE_PORT_BASE2;
device = UARTB_IRQ;
}
#endif
// Attempt to reset the entire part
spInitialize( pi );
// Hook the interrupt
#ifdef EVMDM642
EVMDM642_OSD_intHook( device, (EVMDM642_OSD_IntHandler)spIsr, pi );
#endif
// Start
spStart( pi );
return(1);
}
//--------------------------------------------------------------------
// HwSerClose()
//
// Close Device Instance
//--------------------------------------------------------------------
void HwSerClose( SDINFO *pi )
{
// Normally we'd shut off the part, but here we'll only
// stop it. This is because it can't handle a soft reset.
spStop( pi );
}
//--------------------------------------------------------------------
// HwSerSetConfig()
//
// Update hardware configuration
//--------------------------------------------------------------------
void HwSerSetConfig( SDINFO *pi )
{
// Stop the part in preparation to re-initialize
spStop( pi );
// Attempt to reset the entire part
spInitialize( pi );
// Start
spStart( pi );
}
//--------------------------------------------------------------------
// HwSerTxNext()
//
// Transmit Next Buffer on Tx Queue
//--------------------------------------------------------------------
void HwSerTxNext( SDINFO *pi )
{
// Disable serial interrupts
SREG(pi,UART_IER) = 0;
if( !pi->TxFree )
{
SREG(pi,UART_IER) = TL16C752_IER_RX_AVAIL | TL16C752_IER_TX_READY;
return;
}
pi->TxFree = 0;
if( spWriteFifo( pi ) )
SREG(pi,UART_IER) = TL16C752_IER_RX_AVAIL | TL16C752_IER_TX_READY;
else
SREG(pi,UART_IER) = TL16C752_IER_RX_AVAIL;
}
//--------------------------------------------------------------------
// HwSerPoll()
//
// Poll routine
//--------------------------------------------------------------------
void _HwSerPoll( SDINFO *pi,uint fTimerTick )
{
(void)pi;
(void)fTimerTick;
}
//--------------------------------------------------------------------
// spInitialize()
//
// Reset serial port and setup for operation
//--------------------------------------------------------------------
static void spInitialize( SDINFO *pi )
{
uint baudsetting;
// Disable serial interrupts
SREG(pi,UART_IER) = 0;
// Calculate Baud setting based on BAUDRATENUM constant
baudsetting = BAUDRATENUM / pi->Baud;
// Set mode to baud latch enable and enable EFR
SREG(pi,UART_LCR) = TL16C752_LCR_DLABEFR;
// Set baud rate
SREG(pi,UART_BRDL) = (UINT8)baudsetting;
SREG(pi,UART_BRDH) = (UINT8)(baudsetting>>8);
// Setup TX fifo trigger to 8 and RX fifo to 32
SREG(pi,UART_EFR) = TL16C752_EFR_ENHANCE;
SREG(pi,UART_TLR) = 0x82; // 8*4=32 RX, 2*4=8 TX
// Setup RX flow control in case its needed
// Halt at 60, restore at 32
SREG(pi,UART_TCR) = 0x8F; // 8*4=32 Restore, 15*4=8 Halt
// Enable FIFO, reset RX and TX
SREG(pi,UART_FCR) = TL16C752_FCR_FIFO_ON |
TL16C752_FCR_RX_RESET | TL16C752_FCR_TX_RESET;
// Set or disable flow control
if( pi->FlowCtrl == HAL_SERIAL_FLOWCTRL_HARDWARE )
{
SREG(pi,UART_EFR) = TL16C752_EFR_ENHANCE |
TL16C752_EFR_RTSFLOW |
TL16C752_EFR_CTSFLOW;
SREG(pi,UART_MCR) = TL16C752_MCR_IRQEN |
TL16C752_MCR_DTR;
}
else
SREG(pi,UART_MCR) = TL16C752_MCR_IRQEN |
TL16C752_MCR_RTS |
TL16C752_MCR_DTR;
// Set mode (without latch enable)
if( pi->Mode == HAL_SERIAL_MODE_7E1 )
SREG(pi,UART_LCR) = 0x1a; // 7E1
else
SREG(pi,UART_LCR) = 0x03; // 8N1
// Tansmitter is not free until we start
pi->TxFree = 0;
}
//--------------------------------------------------------------------
// spStart()
//
// Start serial port Rx and Tx state machines
//--------------------------------------------------------------------
static void spStart( SDINFO *pi )
{
// Enable RX and TX buffer interrupts
SREG(pi,UART_IER) = TL16C752_IER_RX_AVAIL;
pi->TxFree = 1;
}
//--------------------------------------------------------------------
// spStop()
//
// Stop serial port, abort current Rx and Tx
//--------------------------------------------------------------------
static void spStop( SDINFO *pi )
{
// Disable serial interrupts
SREG(pi,UART_IER) = 0;
// Clear any pending interrupt
ICR = HW_IFLAG;
// Clear any waiting charmode data
pi->CharReadIdx = pi->CharWriteIdx = pi->CharCount = 0;
// Zap pending RX
if( pi->hRxPend )
{
PBM_free( pi->hRxPend );
pi->hRxPend = 0;
}
// Zap pending TX
if( pi->hTxPend )
{
PBM_free( pi->hTxPend );
pi->hTxPend = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -