?? ti750.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 <csl.h>
#include <csl_cache.h>
#include "llserial.h"
#include "ti750.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();
static uint spWriteFifo( SDINFO *pi );
// Local instance information pointer for our single device instance
static SDINFO *pSDI = 0;
// 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()
{
//
// Note: This code supports only a single instance of the device
// Otherwise, we would do device detection here.
//
return(1);
}
//--------------------------------------------------------------------
// HwSerShutdown()
//
// Shutdown Device Environment
//--------------------------------------------------------------------
void HwSerShutdown()
{
}
//--------------------------------------------------------------------
// HwSerOpen()
//
// Open Device Instance
//--------------------------------------------------------------------
uint HwSerOpen( SDINFO *pi )
{
HWI_Attrs hwiattr;
// We only have one device, so store off the SDINFO pointer as
// global to this module. Otherwise; we'd pick an unclaimed device
// and associate it with the SDINFO.
// IF pSDI is aleady set, this is a restart. Since the part
// can't handle a soft reset, we don't dare reinitialize
if( !pSDI )
{
pSDI = pi;
// Configure the interrupt
// Hook serial port interrupt
hwiattr.intrMask = HW_IFLAG;
hwiattr.ccMask = 1;
hwiattr.arg = 0;
HWI_dispatchPlug( 6, (Fxn)spIsr, -1, &hwiattr );
CACHE_invalidate( CACHE_L1PALL, 0, 0 );
// Enable interrupt
C62_enableIER( HW_IFLAG );
}
else
{
// Stop the part in preparation to re-initialize
spStop( pSDI );
// Use the new SDINFO
pSDI = pi;
}
// Attempt to reset the entire part
spInitialize( pi );
// 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(UART_IER) = 0;
if( !pi->TxFree )
{
SREG(UART_IER) = TL16C750_IER_RX_AVAIL | TL16C750_IER_TX_READY;
return;
}
pi->TxFree = 0;
if( spWriteFifo( pi ) )
SREG(UART_IER) = TL16C750_IER_RX_AVAIL | TL16C750_IER_TX_READY;
else
SREG(UART_IER) = TL16C750_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;
// EMIF control
if( HW_CE_REG )
*HW_CE_REG = HW_CE_VALUE;
// Disable serial interrupts
SREG(UART_IER) = 0;
// Calculate Baud setting based on 3.6864 MHz crystal
baudsetting = 230400 / pi->Baud;
// Set baud latch enable
SREG(UART_LCR) = TL16C750_LCR_DLAB;
// Set baud rate
SREG(UART_BRDL) = (UINT8)baudsetting;
SREG(UART_BRDH) = (UINT8)(baudsetting>>8);
// Enable FIFO, reset RX and TX
// Set 64 byte FIFO, with a 32 byte trigger
// (64 bit FIFO mode can only be set with latch enable on)
SREG(UART_FCR) = TL16C750_FCR_FIFO_ON |
TL16C750_FCR_RX_RESET | TL16C750_FCR_TX_RESET |
TL16C750_FCR_BIG_FIFO | TL16C750_FCR_TRIG_2;
// Set mode (without latch enable)
if( pi->Mode == HAL_SERIAL_MODE_7E1 )
SREG(UART_LCR) = 0x1a; // 7E1
else
SREG(UART_LCR) = 0x03; // 8N1
// Set or disable flow control
if( pi->FlowCtrl == HAL_SERIAL_FLOWCTRL_HARDWARE )
SREG(UART_MCR) = TL16C750_MCR_AFE | TL16C750_MCR_RTS |
TL16C750_MCR_OUT1;
else
SREG(UART_MCR) = TL16C750_MCR_RTS | TL16C750_MCR_DTR |
TL16C750_MCR_OUT1;
// 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(UART_IER) = TL16C750_IER_RX_AVAIL;
pi->TxFree = 1;
}
//--------------------------------------------------------------------
// spStop()
//
// Stop serial port, abort current Rx and Tx
//--------------------------------------------------------------------
static void spStop( SDINFO *pi )
{
// Disable serial interrupts
SREG(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 );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -