[an error occurred while processing this directive] [an error occurred while processing this directive]
Ответ: (+)
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)
[an error occurred while processing this directive] [an error occurred while processing this directive]

Отправлено Музыкант 13 мая 2002 г. 16:06
В ответ на: Подскажите, как PEB22320N кодирует передачу? из родного пдфника я так и не понял... отправлено Очень интересно 25 января 2002 г. 06:51

/*
HDLC.C Release 1.0

COPYRIGHT, RIGHTS OF USE AND DISCLAIMER

Copyright Mitel Corporation, 1999. All rights reserved.
Mitel Corporation grants you a non-exclusive license to use
this software. Mitel Corporation owns and shall retain all
copyrights and other intellectual property rights in this
software. Any permitted copies of this software shall include
this notice.

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES
OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OR CONDITIONS
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
NON-INFRINGEMENT. YOU ASSUME THE ENTIRE RISK AS TO THE RESULTS
AND PERFORMANCE OF THIS SOFTWARE. IN NO EVENT SHALL MITEL
CORPORATION BE LIABLE FOR ANY CLAIM OR DAMAGES OF ANY KIND FOR
ERRORS THAT MAY APPEAR IN THIS SOFTWARE, OR ARISING IN ANY WAY
OUT OF THE APPLICATION OR USE OF THIS SOFTWARE OR FOR ANY
INFRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS
WHICH MAY RESULT FROM SUCH APPLICATION OR USE, EVEN IF IT HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR CLAIM, OR
THEY ARE FORESEEABLE.

*/

#include "mtapi.h"
#include "mt9075.h"

void HdlcReset ( CHAR );
void HdlcSelect ( CHAR );
void HdlcSetRxThreshold ( CHAR, CHAR );
void HdlcSetTxThreshold ( CHAR, CHAR );
void HdlcStartRx ( CHAR, CHAR, CHAR, CHAR, CHAR, CHAR, CHAR, CHAR, CHAR, CHAR );
void HdlcStartTx ( CHAR, CHAR, CHAR, HdlcInfo * , HdlcTmp * );
void HdlcTxStop ( CHAR );
void HdlcRxStop ( CHAR );
void HdlcRxFifo ( CHAR, HdlcInfo *, HdlcTmp * );
void HdlcRxFifoRxff ( CHAR, HdlcInfo *, HdlcTmp * );
void HdlcTxFifoFill ( CHAR, HdlcInfo * , HdlcTmp * );
void HdlcTxFifoTxfl ( CHAR, HdlcInfo *, HdlcTmp * );
void HdlcRxFrameAbort ( CHAR, HdlcInfo *, HdlcTmp * );
void HdlcRxOvfl ( CHAR, HdlcInfo *, HdlcTmp * );
void HdlcIntstatTeop ( CHAR, HdlcInfo *, HdlcTmp * );

/*
******************************************************************************
* Function: HdlcReset
*
* Description: Reset Hdlc inside the chip
*
* Parameters:
* intdev -IN internal device number
*
* Returns: none
*
* Notes:
******************************************************************************
*/
void HdlcReset ( CHAR intdev )
{
MtPutBitfield ( HRST_BIT, intdev, 0, 1 );
MtPutBitfield ( HRST_BIT, intdev, 0, 0 );
MtPutBitfield ( HRST_BIT, intdev, 0, 1 );
MtPutBitfield ( HRST_BIT, intdev, 0, 0 );
}


/*
******************************************************************************
* Function: HdlcSelect
*
* Description: Select Hdlc
*
* Parameters:
* intdev -IN internal device number
*
*
* Returns: none
*
* Notes:
******************************************************************************
*/
void HdlcSelect ( CHAR intdev )
{
if ( intdev )
{
MtPutBitfield ( TXCCS_BIT, 2, 0, 1);
MtPutBitfield ( CCS64K_BIT, 2, 0, 0);
MtPutBitfield ( HDLC1_BIT, 2, 0, 1);
}
else
{
MtPutBitfield ( SA48_BIT, 2, 0, 0X1F);
MtPutBitfield ( HDLC0_BIT, 2, 0, 1);
}
}

/*
******************************************************************************
* Function: HdlcSetRxThreshold
*
* Description: Select the RXFF interrupt threshold level
*
* Parameters:
* level - IN select threshold level
* intdev - IN internal device number
*
*
* Returns: none
*
* Notes:
******************************************************************************
*/
void HdlcSetRxThreshold ( CHAR intdev, CHAR level )
{
MtPutBitfield ( RFFS20_BIT, intdev, 0, level );
}

/*
******************************************************************************
* Function: HdlcSetRTxThreshold
*
* Description: selects the TXFF interrupt threshold level
*
* Parameters:
* level - IN select threshold level
* intdev - IN internal device number
*
*
* Returns: none
*
* Notes:
******************************************************************************
*/
void HdlcSetTxThreshold ( CHAR intdev, CHAR level )
{
MtPutBitfield ( TFLS20_BIT, intdev, 0, level );
}


/*
******************************************************************************
* Function: HdlcStartRx
*
* Description: Prepare Hdlc to receive data
*
* Parameters:
* intdev -IN internal device number
* threshold -IN interrupt threshold level
* rxfifo -IN rx fifo level
* adrec -IN address recognition
* seven -IN seven bit
* adr61 -IN address 6 to 1
* adr10 -IN seventh bit address
* a1en -IN eneble address 1
* adr60 -IN address 6 to 0
* a2en -IN enebla address 2
*
*
* Returns: none
*
* Notes:
******************************************************************************
*/
void HdlcStartRx ( CHAR intdev, CHAR threshold, CHAR rxfifo, CHAR adrec,
CHAR seven, CHAR adr61, CHAR adr10, CHAR a1en, CHAR adr60 ,
CHAR a2en )
{

UCHAR reg;

//HdlcReset (Hdlc);
HdlcSelect ( intdev);
MtPutBitfield ( RXFRST_BIT, intdev, 0, 1);
HdlcSetRxThreshold ( intdev, threshold);
MtPutBitfield ( RFD20_BIT, intdev, 0, rxfifo);

/*address recognition*/
if ( adrec==0 )
{
if ( a1en==0 )
{
if ( seven==0 )
{
MtPutBitfield (SEVEN_BIT, intdev, 0, seven);
MtPutBitfield ( ADR161_BIT, intdev, 0, adr10);
}
MtPutBitfield ( ADR10_BIT, intdev, 0, adr61);
MtPutBitfield ( A1EN_BIT, intdev, 0, a1en);
}
else
{
MtPutBitfield ( A1EN_BIT, intdev, 0, a1en);
}
if ( a2en==0 )
{
MtPutBitfield ( ADR260_BIT, intdev, 0, adr60);
MtPutBitfield ( A2EN_BIT, intdev, 0, a2en);
}
else
{
MtPutBitfield ( A2EN_BIT, intdev, 0, a2en);
}
MtPutBitfield ( ADREC_BIT, intdev, 0, adrec);
}
else
{
MtPutBitfield ( ADREC_BIT, intdev, 0, adrec);
}
MtPutBitfield ( INTSEL_BIT, intdev, 0, 0);

/*unmask interrupts*/
MtGetRegister( HDLC_IMASK_REG , intdev, 0, ® );
reg|=0xD7;
MtPutRegister( HDLC_IMASK_REG , intdev, 0, reg);
MtPutBitfield ( RXEN_BIT, intdev, 0, 1);
}

/*
**************************************************************************
* Function: HdlcStartTx
*
* Description: Prepare Hdlc to transmit data
*
* Parameters:
* intdev - IN internal device number
* threshold - IN interrupt threshold level
* txfifo - IN TX fifo level
* StatPtr - pointers structure
* TmpPtr - pointers structure
*
* Returns: none
*
* Notes:
**************************************************************************
*/
void HdlcStartTx ( CHAR intdev, CHAR threshold, CHAR txfifo, HdlcInfo *StatPtr,
HdlcTmp *TmpPtr )
{

UCHAR reg;
// HdlcReset ( intdev);

HdlcSelect ( intdev);
MtPutBitfield ( TXFRST_BIT, intdev, 0, 1);
HdlcSetTxThreshold ( intdev, threshold);
MtPutBitfield ( TFD20_BIT, intdev, 0, txfifo);
MtPutBitfield ( INTSEL_BIT, intdev, 0, 1);
MtPutBitfield ( MIDLE_BIT, intdev, 0, 1);
HdlcTxFifoFill ( intdev, StatPtr , TmpPtr);

/*unmask interrupts*/
MtGetRegister( HDLC_IMASK_REG , intdev, 0, ®);
reg|=0x2C;
MtPutRegister( HDLC_IMASK_REG , intdev, 0, reg);
MtPutBitfield ( TXEN_BIT, intdev, 0, 1);
}
/*
******************************************************************************
* Function: HdlcTxStop
*
* Description: Stop transmiting data
*
* Parameters:
* intdev - IN internal device number
*
*
* Returns: none
*
* Notes: disable transmiter
*****************************************************************************
*/

void HdlcTxStop ( CHAR intdev )
{
MtPutBitfield ( TXEN_BIT, intdev, 0, 0 ); //disable tx
MtPutBitfield ( TXFRST_BIT, intdev, 0, 1 );//reset tx fifo
MtPutBitfield ( TXFRST_BIT, intdev, 0, 1 );
}

/*
******************************************************************************
* Function: HdlcRxStop
*
* Description: Stop receiveng data
*
* Parameters:
* intdev - IN Internal Device Number
*
*
* Returns: none
*
* Notes: Disable receiver and resets rxfifo
******************************************************************************
*/
void HdlcRxStop ( CHAR intdev )
{
MtPutBitfield ( RXEN_BIT, intdev, 0, 0 );
MtPutBitfield ( RXFRST_BIT, intdev, 0, 1 );
MtPutBitfield ( RXFRST_BIT, intdev, 0, 1 );
}

/*******************************************/
/* FIFO SERVICE FUNCTIONS */
/*******************************************/
/*
******************************************************************************
* Function: HdlcRxFifo
*
* Description: Empties the rx fifo for the specified hdlc controller
*
* Parameters:
* intdev -IN internal device number
* Statptr -pointers structure
* TmpPtr -pointers structure
*
* Returns: none
*
*
* Notes : Called from HdlcIsr() only.
******************************************************************************
*/
void HdlcRxFifo ( CHAR intdev, HdlcInfo *StatPtr, HdlcTmp *TmpPtr )
{

UCHAR rxfifostatus;
INT j;

j = 0;
// Read the HDLC status register to check the byte status and
// FIFO status bits before reading the byte itself
MtGetBitfield ( RQ98_BIT, intdev, 0, &rxfifostatus );
// Clean out the entire RX FIFO
while ( ( rxfifostatus & RXSTAT_MASK ) != RXFIFO_EMPTY )
{
// Read a byte from the Rx FIFO
MtGetRegister ( HDLC_RX_TX_FIFO_REG , intdev, 0,
TmpPtr->CurRxBytePtr );

// Check the status of this byte
switch ( rxfifostatus )
{
case RXFIFO_PACKET_BYTE:
TmpPtr->CurRxBytePtr++;
StatPtr->FrameBytesReceived++;
StatPtr->TotalBytesReceived++;
break;

case RXFIFO_FIRST_BYTE:
StatPtr->FrameBytesReceived = 1;
TmpPtr->CurRxBytePtr++;
StatPtr->TotalBytesReceived++;
break;

case RXFIFO_LAST_GOOD:

//The byte read is the last of the packet
//Inc frame count for the frame we received
StatPtr->FramesReceived++;
TmpPtr->CurRxBytePtr =
StatPtr->GlobalrxBufferbasePtr;
StatPtr->FramesRxGoodFCS++;
StatPtr->FrameBytesReceived++;
StatPtr->TotalBytesReceived++;
StatPtr->FrameBytesReceived = 0;
break;
case RXFIFO_LAST_BAD:

//The byte just read is the last of the packet
//Inc the frame count for the frame we receive
StatPtr->FramesReceived++;
TmpPtr->CurRxBytePtr =
StatPtr->GlobalrxBufferbasePtr;
StatPtr->FramesRxBadFCS++;
StatPtr->FrameBytesReceived++;
StatPtr->TotalBytesReceived++;
StatPtr->FrameBytesReceived = 0;
break;

}

// Check to see if the global receive buffer has been filled.
// If so, then the current receive byte pointer is reset to
// the base of the global receive buffer.
if ( StatPtr->FrameBytesReceived>StatPtr->GlobalrxBufSize )
{
TmpPtr->CurRxBytePtr = StatPtr->GlobalrxBufferbasePtr;
}

// Read the HDLC status register to check the byte status and
// FIFO status bits before reading the byte itself.
MtGetRegister ( HDLC_STATUS_REG , intdev, 0, &rxfifostatus );

j++;
}
StatPtr->EopdBytes = j;
}

/*
******************************************************************************
* Function: HdlcRxFifoRxff
*
* Description: Pulls 64 bytes from the fifo
*
* Parameters:
* intdev -IN internal device number
* Statptr -pointers structure
* TmpPtr -pointers structure
*
* Returns: none
*
*
*
* Notes:
******************************************************************************
*/
void HdlcRxFifoRxff ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{

CHAR i;
UCHAR rxfifostatus;

MtGetRegister ( HDLC_STATUS_REG , intdev, 0, &rxfifostatus );

//******************************************************************
// Make sure that there are 64 bytes to be pulled before pulling 64.
// Not checking this can lead to pulling garbage bytes from the RX
// FIFO. Ignoring this interrupt if a mismatch occurs worked in
// testing.
//******************************************************************
if ( ( rxfifostatus&RXSTAT_MASK ) == RXFIFO_ABOVE_THRESHOLD )
{
// Go get ( threshold ) bytes only.
// ( There may be more than that there, but only get to
// allow the transmitter time to run as well, if necessary )
for ( i = 0;iRxThreshold;i++ )
{
// Read a byte from the Rx FIFO
MtGetRegister ( HDLC_RX_TX_FIFO_REG , intdev,
0, TmpPtr->CurRxBytePtr );

// Inc ptr for byte just transferred from rx
TmpPtr->CurRxBytePtr++;
StatPtr->FrameBytesReceived++;

// Check to see if the global receive buffer has
// been filled.If so, then the current receive
// byte pointer is reset to
// the base of the global receive buffer
if ( StatPtr->FrameBytesReceived>StatPtr->GlobalrxBufSize )
{
TmpPtr->CurRxBytePtr = StatPtr->GlobalrxBufferbasePtr;
}
}
StatPtr->TotalBytesReceived += TmpPtr->RxThreshold;
}
else
{
// Note the mismatch between the occurence of the
// interrupt and the value of the status register
StatPtr->Mismach++;
}
}


/*
******************************************************************************
* Function: HdlcTxFifoFill
*
* Description: Fill the TX FIFO with 128 bytes at the start of a frame
*
* Parameters:
* intdev -IN internal device number
* StatPtr -pointers structure
* TmpPtr -pointers structure
*
*
*
* Returns: none
*
*
*
* Notes:
******************************************************************************
*/
void HdlcTxFifoFill ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{

UCHAR hdlcreg;
// Fill the tx FIFO until full or end of frame

// If there is something left to send...
if ( ( TmpPtr->EndDataPtr-TmpPtr->CurTxBytePtr ) > 0 )
{
MtGetRegister ( HDLC_STATUS_REG , intdev, 0, &hdlcreg );

while ( ( hdlcreg & TXSTAT_MASK ) != TXFIFO_FULL )
{
if ( ( TmpPtr->CurTxBytePtr+1 ) == TmpPtr->EndDataPtr )
{
MtPutBitfield ( EOP_BIT, intdev, 0, 1 );
MtPutRegister ( HDLC_RX_TX_FIFO_REG , intdev,
0, *TmpPtr->CurTxBytePtr );
TmpPtr->CurTxBytePtr++;
StatPtr->BytesTransmitted++;
StatPtr->SentFrameCount++;
break;
}
else
{
MtPutRegister ( HDLC_RX_TX_FIFO_REG , intdev,
0, *TmpPtr->CurTxBytePtr );
TmpPtr->CurTxBytePtr++;//Inc ptr to next byte
StatPtr->BytesTransmitted++;
}
MtGetRegister ( HDLC_STATUS_REG , intdev, 0, &hdlcreg );
}
}
}

/*
******************************************************************************
* Function: HdlcTxFifoTxfl
*
* Description: Puts 64 bytes into the FIFO.
*
* Parameters:
* intdev -IN internal device number
* StatPtr -pointers structure
* TmpPtr -pointers structure
*
*
* Returns: none
*
*
*
* Notes:
******************************************************************************
*/
void HdlcTxFifoTxfl ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{


UCHAR hdlcreg;
INT bytesremaining;
INT bytestoputin;
CHAR i;

bytesremaining=TmpPtr->EndDataPtr-TmpPtr->CurTxBytePtr;

// If there is something left to send...
if ( bytesremaining>0 )
{
MtGetRegister ( HDLC_STATUS_REG , intdev, 0, &hdlcreg );
if ( ( hdlcreg&TXSTAT_MASK ) == TXFIFO_BELOW_THRESHOLD )
{
if ( bytesremaining <= ( 128-TmpPtr->TxThreshold ) )
{

bytestoputin=bytesremaining-1;

// Put in all but the last byte
for ( i=0;i {
MtPutRegister ( HDLC_RX_TX_FIFO_REG,
intdev, 0, *TmpPtr->CurTxBytePtr );
TmpPtr->CurTxBytePtr++;
StatPtr->BytesTransmitted++;
}


// Now deal with the last byte
MtPutBitfield ( EOP_BIT, intdev, 0, 1 );
MtPutRegister ( HDLC_RX_TX_FIFO_REG , intdev,
0, *TmpPtr->CurTxBytePtr );
TmpPtr->CurTxBytePtr++;
StatPtr->SentFrameCount++;
StatPtr->BytesTransmitted++;
}
else
{
// Put in ( 128-threshold ) bytes and go
bytestoputin=128-TmpPtr->TxThreshold;

for ( i=0;i {
MtPutRegister ( HDLC_RX_TX_FIFO_REG ,
intdev, 0, *TmpPtr->CurTxBytePtr );
TmpPtr->CurTxBytePtr++;
StatPtr->BytesTransmitted++;
}
}
}
else
{
// Note the mismatch between the occurence of the
// interrupt and the value of the status register
StatPtr->Mismach++;
}
}
}


/*
******************************************************************************
* Function HdlcRxFrameAbort
*
* Description Upon frame abort, drain the RX FIFO and set up for a new frame
*
* Parameters:
* intdev -IN internal device number
* StatPtr -pointers structure
* TmpPtr -pointers structure
*
*
*
* Returns None
*
*
*
* Notes
******************************************************************************
*/
void HdlcRxFrameAbort ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{
TmpPtr->CurRxBytePtr = StatPtr->GlobalrxBufferbasePtr;
HdlcRxFifo ( intdev, StatPtr, TmpPtr );
TmpPtr->CurRxBytePtr = StatPtr->GlobalrxBufferbasePtr;
}


/*
******************************************************************************
* Function: HdlcRxOvfl
*
* Description: Upon Receiver Overflow,reset the RX FIFO and set up to receive
* a new packet
*
*
* Parameters:
* intdev -IN internal device number
* StatPtr -pointers structure
* TmpPtr -pointers structure
*
*
* Returns: none
*
*
* Notes:
******************************************************************************
*/
void HdlcRxOvfl ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{
// Reset the Rx FIFO, otherwise it will not be cleared,
// and an Rx overflow will occur again ( Table 85 ) .
MtPutBitfield ( RXFRST_BIT, intdev, 0, 1 );
TmpPtr->CurRxBytePtr = StatPtr->GlobalrxBufferbasePtr;
}

/*
******************************************************************************
* Function: HdlcIntstatTeop
*
* Description: After transmitting the last byte of a frame,
* this interrupt
*
* Parameters:
* intdev -IN internal device number
* StatPtr -pointers structure
* TmpPtr -pointers structure
*
*
* Returns: none
*
*
* Notes: If repetitions of 0 was specified, it means send forever.
******************************************************************************
*/
void HdlcIntstatTeop ( CHAR intdev, HdlcInfo *StatPtr , HdlcTmp *TmpPtr )
{
// Reset CurTxBytePtr to the beginning of the frame for
// the next one to be sent.
TmpPtr->CurTxBytePtr = StatPtr->GlobaltxBufferbasePtr;

// Check to see if there are more frames to go
if ( ( StatPtr->ReqSendCount == 0 ) ||
( StatPtr->SentFrameCount < StatPtr->ReqSendCount ) )
{
HdlcTxFifoFill ( intdev, StatPtr, TmpPtr );
}
else
{
if ( StatPtr->SentFrameCount == StatPtr->ReqSendCount )
{
HdlcTxStop ( intdev ); // All done - shut off transmitter
}
}


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru