📄 hdlc100init.c
字号:
/****************************************************************//* */ /* MODULE: BDTest/hdlc100init.c *//* DATE: 98/12/01 *//* PURPOSE: hdlc(high level data link control) header *//* *//*--------------------------------------------------------------*//* Copyright (C) 1998 Samsung Electronics. *//* *//* programmed by jwCHOI & suCHOI *//****************************************************************//* *//* Modified by *//* Dmitriy Cherkashin *//* dch@ucrouter.ru *//* 2002,2003 *//* */#include "ks32c50.h"#include "evm50100.h"//#define HDLC_TX_ISR_DEBUG // uncomment to debug Tx ISR//#define HDLC_RX_ISR_DEBUG // uncomment to debug Rx ISR//#define USER_AREA#define HDLC_1500#define HDLCPORTNUM 2 // HDLC ports count #define NonCache 0x4000000 // non cache bit#define HDLC_MAX_TX_DES 64 // Tx Buffer Descriptors count#define HDLC_MAX_RX_DES 512 // Rx Buffer Descriptors count#ifdef HDLC_1500#define HDLC_RX_BUF_LENGTH 1504 // Rx buffer length (bytes)#define HDLC_TX_BUF_LENGTH 1504 // Tx buffer length (bytes)#else#define HDLC_RX_BUF_LENGTH 64 // Rx buffer length (bytes)#define HDLC_TX_BUF_LENGTH 128 // Tx buffer length (bytes)#endif // Tx alloc buffer size (words)#define HDLC_TX_ALLOC_BUF_SIZE (HDLC_MAX_TX_DES*HDLC_TX_BUF_LENGTH/sizeof(U32))// Rx alloc buffer size (words)#define HDLC_RX_ALLOC_BUF_SIZE (HDLC_MAX_RX_DES*HDLC_RX_BUF_LENGTH/sizeof(U32))#ifdef USER_AREA// sizeof buffer to copy Rx Packets (words)#define HDLC_USER_AREA_SIZE (HDLC_MAX_RX_DES * HDLC_RX_BUF_LENGTH) #endif // USER_AREA// 1500 Content HMFLR (Maximum Frame Lengt for DMA Mode) with CRC int HDLC_MAX_FRAME_LENGTH = 1504; //////////////////////////////////////////////////////////////////////////////// // Tx/Rx Buffer descriptor structure (With Previous Descriptor) //////////////////////////////////////////////////////////////////////////////////////////////// typedef struct HDLCBD { U32 BufferDataPtr; // Data buffer pointer (+ownership bit) U32 Reserved; U32 StatusLength; struct HDLCBD * Next; struct HDLCBD * Prev;} sHDLCBD;// HDLC Buffer Descriptors /////////////////////////////////////////////////////sHDLCBD sHDLCTxBD[HDLCPORTNUM][HDLC_MAX_TX_DES]; // Tx Buffer descriptorssHDLCBD sHDLCRxBD[HDLCPORTNUM][HDLC_MAX_RX_DES]; // Tx Buffer Descriptors// alloc buffers ///////////////////////////////////////////////////////////////U32 HDLCTxAllocBuf[HDLCPORTNUM][HDLC_TX_ALLOC_BUF_SIZE]; // Tx Data buffersU32 HDLCRxAllocBuf[HDLCPORTNUM][HDLC_RX_ALLOC_BUF_SIZE]; // Rx Data buffersvolatile U32 gHDLCTxStart[HDLCPORTNUM]; // Tx start BD pointer (moved by Tx ISR) volatile U32 gHDLCTxEnd[HDLCPORTNUM]; // Tx end BD pointer (moved by Send)volatile U32 gHDLCTxCount[HDLCPORTNUM] // Used Tx BD count = {0, 0};// volatile U32 gHDLCRxStart[HDLCPORTNUM]; // volatile U32 gHDLCRxEnd[HDLCPORTNUM]; // Rx end BD pointer (moved by Rx ISR)#ifndef USER_AREAvolatile U32 gHDLCRxCount[HDLCPORTNUM] // Used Rx BD count = {0, 0};#endif // not def USER_AREAint gHDLCCPUmode = 0; // 0 = DMA modevolatile U32 gHDLCRxDone = 0; // used in CPU Mode ISR#ifdef USER_AREA// Rx Queue ////////////////////////////////////////////////////////////////////U32 HDLCRxUserArea [HDLCPORTNUM][HDLC_USER_AREA_SIZE];volatile U32 *HDLCRxUserRead [HDLCPORTNUM]={HDLCRxUserArea[0],HDLCRxUserArea[1]};volatile U32 *HDLCRxUserWrite[HDLCPORTNUM]={HDLCRxUserArea[0],HDLCRxUserArea[1]};volatile U32 *HDLCRxUserFirst[HDLCPORTNUM]={(U32 *) (-1), (U32 *) (-1) };volatile int HDLCRxUserCount[HDLCPORTNUM]={ 0, 0 };#endif // USER_AREA// HDLC Statistics ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // HDLC Tx Status Structure ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// typedef struct HdlcTxStatus {#ifdef HDLC_TX_ISR_DEBUG U32 TxISR; // #endif // HDLC_TX_ISR_DEBUG U32 TxFC; // Tx Frame Complete (TxFC) U32 TxFA; // Tx FIFO Avail U32 TxSCTS; // Tx CTS Store (TxSCTS) U32 TxU; // Tx Underrun (TxU) U32 TxLBDNC; // last BD Not completed U32 DMATxABT; // Tx DMA Abort (DTxABT) U32 DMATxFD; // Tx DMA Frame Done (DTxFD) U32 DMATxNL; // Tx DMA Null List (DTxNL) U32 DMATxNO; // Tx DMA Not Owner (DTxNO)} HDLCTXSTATUS;//////////////////////////////////////////////////////////////////////////////// // HDLC Rx Status Structure ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// typedef struct HdlcRxStatus {#ifdef HDLC_RX_ISR_DEBUG U32 RxISR;#endif // HDLC_RX_ISR_DEBUG U32 RxFA; // Rx FIFO Avail (RxFA) U32 RxFD; // Rx Flag Detect (RxFD) U32 RxSDCD; // Rx DCD store (RxSDCD) U32 RxFV; // Rx Frame Valid (RxFV) U32 RxIDLE; // Rx Idle U32 RxABT; // Rx Abort U32 RxCRCE; // Rx CRC Error U32 RxNO; // Rx Non Octet (RxNO) U32 RxOV; // Rx Overrun (RxOV) U32 RxMOV; // Rx memory overflow (RxMOV) U32 RxIERR; // Rx Inter Error (RxIERR) U32 DRxFD; // Rx DMA FD (DRxFD) U32 DRxNL; // Rx DMA NL (DRxNL) U32 DRxNO; // Rx DMA NO (DRxNO)} HDLCRXSTATUS; //////////////////////////////////////////////////////////////////////////////// // HDLC DPLL Status Structure ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// typedef struct HdlcDPLLStatus { U32 DPLLOM; U32 DPLLTM;} HDLCDPLLSTATUS;// HDLCTXSTATUS HDLCTxStatus[HDLCPORTNUM]; // Tx StatisticsHDLCRXSTATUS HDLCRxStatus[HDLCPORTNUM]; // Rx StatisticsHDLCDPLLSTATUS HDLCDPLLStatus[HDLCPORTNUM]; // DPLL Statistics////////////////////////////////////////////////////////////////////////////////// HMODEA & HMODEB /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////U32 gHMODE = // HMODEA & HMODEB content // HMODE_MFinFIFO | // 1 = Multiple frame in FIFO HMODE_RxLittle | // Rx Little Endian HMODE_TxLittle | // Tx Little Endian// Transmit Preamble Length ////////////////////////////////////////////////////// HMODE_TxPL1 // 000 = 1 byte// HMODE_TxPL2 // 001 = 2 bytes // HMODE_TxPL3 // HMODE_TxPL4 // HMODE_TxPL5 // HMODE_TxPL6 // HMODE_TxPL7 // HMODE_TxPL8 // 111 = 8 bytes // Data Format ///////////////////////////////////////////////////////////////// HMODE_DF_NRZ | // HMODE_DF_NRZI // 001 = NRZI (zero complement)// HMODE_DF_FM0 // 010 = FM0// HMODE_DF_FM1 // 011 = FM1// HMODE_DF_Manchester // 100 = Manchester// DPLL Source /////////////////////////////////////////////////////////////////// HMODE_DPLLCLK_TXC // 000 = TXC// HMODE_DPLLCLK_RXC // 001 = RXC// HMODE_DPLLCLK_MCLK // 010 = MCLK// HMODE_DPLLCLK_BRGOUT1 // 011 = BRGOUT1// HMODE_DPLLCLK_BRGOUT2 // 100 = BRGOUT2// BRG Source //////////////////////////////////////////////////////////////////// HMODE_BRGCLK_RXC // 0 = RXC HMODE_BRGCLK_MCLK2 | // 1 = MCLK2// TxCLK ///////////////////////////////////////////////////////////////////////// HMODE_TxCLK_TXC // 000 = TXC// HMODE_TxCLK_RXC // 001 = RXC// HMODE_TxCLK_DPLLOUTT // 010 = DPLLOUTT// MODE_TxCLK_BRGOUT1 // 011 = BRGOUT1 HMODE_TxCLK_BRGOUT2 | // 100 = BRGOUT2// HMODE_RxCLK_TXC // 000 = TXC // HMODE_RxCLK_RXC // 001 = RXC// HMODE_RxCLK_DPLLOUTR // 010 = DPLLOUTR// HMODE_RxCLK_BRGOUT1 // 011 = BRGOUT1 HMODE_RxCLK_BRGOUT2; // 100 = BRGOUT2 // TxC Output Source ///////////////////////////////////////////////////////////// HMODE_TXCOPS_TxCLK // 000 = TxCLK// HMODE_TXCOPS_RxCLK // 001 = RxCLK // HMODE_TXCOPS_BRGOUT1 // 010 = BRGOUT1// HMODE_TXCOPS_BRGOUT2 // 011 = BRGOUT2// HMODE_TXCOPS_DPLLOUTT // 100 = DPLLOUTT// HMODE_TXCOPS_DPLLOUTR // DPLLOUTR////////////////////////////////////////////////////////////////////////////////// HCONA & HCONB ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////volatile U32 gHCON = // HCONA & HCONB content // HCON_TxRS // [0] Tx reset (TxRS)// HCON_RxRS // [1] Rx reset (RxRS)// HCON_DTxRS // [2] DMA Tx reset (DTxRS)// HCON_DRxRS // [3] DMA Rx reset (DRxRS)// HCON_TxEN // [4] Tx enable (TxEN)// HCON_RxEN // [5] Rx enable (RxEN)// HCON_DTxEN // [6] DMA Tx enable (DTxEN)// HCON_DRxEN // [7] DMA Rx enable (DRxEN)// HCON_DPLLEN // [8] DPLL enable (DPLLEN) HCON_BRGEN | // [9] BRG enable (BRGEN) HCON_Tx1WD | // 1-word mode selected// HCON_Tx4WD | // 4-word mode selected HCON_Rx1WD | // 1-word mode selected// HCON_Rx4WD | // 1 = 4-word mode selected// Rx Allignment /////////////////////////////////////////////////////////////// HCON_RxWA0 | // 00 = No Invalid bytes// HCON_RxWA1 // 01 = 1 invalid byte// HCON_RxWA2 // 10 = 2 invalid bytes// HCON_RxWA3 // 11 = 3 invalid bytesHCON_DTxSTSK | // [14] DMA Tx stop or skip (DTxSTSK)HCON_DRxSTSK | // [15] DMA Rx stop or skip (DRxSTSK)// HCON_DRxMADEC // [16] DMA Rx memory address decrement (DRxMADEC) HCON_TxFLAG | // [17] Tx flag idle (TxFLAG)// HCON_TxSFLAG // [18] Tx single flag (TxSFLAG)// HCON_TxLOOP // [19] Tx loop-back mode (TxLOOP)// HCON_RxECHO // [20] Rx echo mode (RxECHO)// HCON_TxABTEXT // [21] Tx abort extension (TxABTEXT)// HCON_TxABT // [22] Tx abort (TxABT)// HCON_TxPRMB // [23] Tx preamble (TxPRMB)HCON_TxDTR ; // [24] Tx data terminal ready (TxDTR)// HCON_RxDISCON // [25] Rx frame discontinue (RxDISCON)// HCON_TxNOCRC // [26] Tx no CRC (TxNOCRC)// HCON_RxNoCRC // [27] Rx no CRC (RxNOCRC)// HCON_AutoEN; // [28] Auto enable (AutoEN)////////////////////////////////////////////////////////////////////////////////// HINTENA HDLC Channel A Interrupt Enable /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////volatile U32 gHINTENA = // HINTEN_TxFCIE // [4] Tx frame complete interrupt enable// HINTEN_TxFAIE // [5] Tx FIFO available to write interrupt enable HINTEN_TxSCTSIE | // [7] CTS transition has occurred interrupt enable HINTEN_TxUIE | // [8] Tx underrun has occurred interrupt enable// HINTEN_RxFAIE // [9] Rx FIFO available to read interrupt enable HINTEN_RxFDIE | // [11]Rx flag detected interrupt enable HINTEN_RxSDCDIE | // [13]DCD transition interrupt enable// HINTEN_RxFVIE // [14]Rx frame valid interrupt enable HINTEN_RxIDLEIE | // [15]Idle detected interrupt enable HINTEN_RxABTIE | // [16]Abort detected interrupt enable// HINTEN_RxCRCEIE // [17]CRC error frame interrupt enable// HINTEN_RxNOIE // [18]Non-octet aligned frame interrupt enable// HINTEN_RxOVIE // [19]Rx overrun interrupt enable HINTEN_RxMOVIE | // [20]Rx memory overflow interrupt enable HINTEN_DTxABTIE | // [22]DMA Tx abort interrupt enable HINTEN_RxIERRIE | // [23]Rx internal error interrupt enable HINTEN_DRxFDIE | // [24]DMA Rx frame done interrupt enable HINTEN_DRxNLIE | // [25]DMA Rx null list interrupt enable HINTEN_DRxNOIE | // [26]DMA Rx not owner interrupt enable HINTEN_DTxFDIE | // [27]DMA Tx frame done every transmitted frame interrupt enable HINTEN_DTxNLIE | // [28]DMA Tx null list interrupt enable HINTEN_DTxNOIE ; // [29]DMA Tx not owner interrupt enable// HINTEN_DPLLOMIE // [30]DPLL one clock missing interrupt enable// HINTEN_DPLLTMIE; // [31]DPLL two clocks missing interrupt enable////////////////////////////////////////////////////////////////////////////////// HINTENB HDLC Channel B Interrupt Enable /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////volatile U32 gHINTENB = // HINTEN_TxFCIE // [4] Tx frame complete interrupt enable// HINTEN_TxFAIE // [5] Tx FIFO available to write interrupt enable HINTEN_TxSCTSIE | // [7] CTS transition has occurred interrupt enable HINTEN_TxUIE | // [8] Tx underrun has occurred interrupt enable// HINTEN_RxFAIE // [9] Rx FIFO available to read interrupt enable HINTEN_RxFDIE | // [11]Rx flag detected interrupt enable HINTEN_RxSDCDIE | // [13]DCD transition interrupt enable// HINTEN_RxFVIE // [14]Rx frame valid interrupt enable HINTEN_RxIDLEIE | // [15]Idle detected interrupt enable HINTEN_RxABTIE | // [16]Abort detected interrupt enable// HINTEN_RxCRCEIE // [17]CRC error frame interrupt enable// HINTEN_RxNOIE // [18]Non-octet aligned frame interrupt enable// HINTEN_RxOVIE // [19]Rx overrun interrupt enable HINTEN_RxMOVIE | // [20]Rx memory overflow interrupt enable HINTEN_DTxABTIE | // [22]DMA Tx abort interrupt enable HINTEN_RxIERRIE | // [23]Rx internal error interrupt enable HINTEN_DRxFDIE | // [24]DMA Rx frame done interrupt enable HINTEN_DRxNLIE | // [25]DMA Rx null list interrupt enable HINTEN_DRxNOIE | // [26]DMA Rx not owner interrupt enable HINTEN_DTxFDIE | // [27]DMA Tx frame done every transmitted frame interrupt enable HINTEN_DTxNLIE | // [28]DMA Tx null list interrupt enable HINTEN_DTxNOIE ; // [29]DMA Tx not owner interrupt enable// HINTEN_DPLLOMIE; // [30]DPLL one clock missing interrupt enable// HINTEN_DPLLTMIE; // [31]DPLL two clocks missing interrupt enable////////////////////////////////////////////////////////////////////////////////// View HDLC Global variables //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return index in array BD, -1 = invalid pointer //////////////////////////////static int HdlcVarIdx(U32 ptr, sHDLCBD * base){ int index; index = (ptr & ~NonCache) - (((U32)(base)) & ~NonCache);//Print("\nptr %x base %x index %d", ptr, (U32) base, index); if( (index % sizeof(sHDLCBD)) == 0 ) { return(index / sizeof(sHDLCBD)); } else { return(-1); } }void HdlcVarView(void){ int txstart[2]; // tx BD start index int txend[2]; // tx BD end index int txptr[2]; // tx BD pointer index int rxstart[2]; // rx BD start index int rxend[2]; // rx BD end index int rxptr[2]; // rx BD pointer index int cn; for(cn = 0; cn < 2; ++cn) { txstart[cn] = HdlcVarIdx(gHDLCTxStart[cn], & sHDLCTxBD[cn][0]); txend [cn] = HdlcVarIdx(gHDLCTxEnd [cn], & sHDLCTxBD[cn][0]); txptr [cn] = HdlcVarIdx(HDMATXPTR (cn), & sHDLCTxBD[cn][0]); rxstart[cn] = HdlcVarIdx(gHDLCRxStart[cn], & sHDLCRxBD[cn][0]); rxend [cn] = HdlcVarIdx(gHDLCRxEnd [cn], & sHDLCRxBD[cn][0]); rxptr [cn] = HdlcVarIdx(HDMARXPTR (cn), & sHDLCRxBD[cn][0]); }#define PrintVarS(fmt,val0, val1 ) \ Print(fmt "0x%08x %4s 0x%08x %4s", val0, "", val1, "")#define PrintVarD(fmt,val0,val1, idx) \ Print(fmt "0x%08x %4d 0x%08x %4d",val0,idx[0],val1,idx[1]) while(1) { sHDLCBD * bd; int num; U8 dir; U8 it; PrintVarS("\n[T] HDLCTxBD........",sHDLCTxBD [0],sHDLCTxBD [1]); PrintVarS("\n HDLCTxBD Max Cnt",HDLC_MAX_TX_DES ,HDLC_MAX_TX_DES ); PrintVarS("\n HDLCTxAllocBuf..",HDLCTxAllocBuf [0],HDLCTxAllocBuf [1]); PrintVarD("\n HDLCTxStart.....",gHDLCTxStart [0],gHDLCTxStart [1], txstart); PrintVarD("\n HDLCTxEnd.......",gHDLCTxEnd [0],gHDLCTxEnd [1], txend); PrintVarS("\n HDLCTxCount.....",gHDLCTxCount [0],gHDLCTxCount [1]); PrintVarD("\n HDMATXPTR.......",HDMATXPTRA ,HDMATXPTRB , txptr); PrintVarS("\n[R] HDLCRxBD.......,",sHDLCRxBD [0],sHDLCRxBD [1]); PrintVarS("\n HDLCRxBD Max Cnt",HDLC_MAX_RX_DES ,HDLC_MAX_RX_DES );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -