📄 dpx_test.c
字号:
/******************************************************************************/
/** COPYRIGHT (C) 1999 PMC-SIERRA, INC. ALL RIGHTS RESERVED. **/
/**--------------------------------------------------------------------------**/
/** This software embodies materials and concepts which are proprietary and **/
/** confidential to PMC-Sierra, Inc. **/
/** PMC-Sierra distributes this software to its customers pursuant to the **/
/** terms and conditions of the Device Driver Software License Agreement **/
/** contained in the text file software.lic that is distributed along with **/
/** the device driver software. This software can only be utilized if all **/
/** terms and conditions of the Device Driver Software License Agreement are **/
/** accepted. If there are any questions, concerns, or if the Device Driver **/
/** Software License Agreement text file, software.lic, is missing please **/
/** contact PMC-Sierra for assistance. **/
/**--------------------------------------------------------------------------**/
/** **/
/******************************************************************************/
/*******************************************************************************
** MODULE : Duplex device drivers
**
** FILE : Dpx_sar.c
**
** DESCRIPTION: This file contains some utility function for Tx data out via
** Microprocessor port.
**
**
** NOTES : This is an example file which can be used for testing in the
** VxWorks and PV platform. It does NOT intend for use in real
** production code.
**
*******************************************************************************/
/*
** MODIFICATION HISTORY:
**
** $Log: dpx_test.c.rca $
**
** Revision: 1.1 Wed Aug 16 16:22:18 2000 bhalwani
** Beta-1.0
**
**
** 5 05/05/00 Bhalwani Vortex chipset driver beta-1.0
** 4 05/05/00 Bhalwani Vortex chipset driver Alpha-1.30
** 3 05/05/00 chenkemi fixed byte order in vpi/vci and trail length
** calculation
** 2 02/15/00 chenkemi alpha-001
** 1 07/21/99 chenkemi Initial Version
*/
/** include files **/
#include "dpx_test.h"
/** private data **/
/*******************************************************************************
**
** dpx_TxAAL0Msg
** ___________________________________________________________________________
**
** DESCRIPTION: Transmits a AAL0 cell message on an active HSS link of a DUPLEX
** device. No CRC-32 protection is provided for AAL0 message.
**
**
** SIDE EFFECTS: It is recommended that cell reception be given higher priority
** than cell transmission to prevent extract FIFO overflow. In
** other words, all cells of a received message should be
** extracted before switching context.
**
** INPUTS:
** usrCtxt - user's context for the device.
** pMsg - pointer to the message buffer to be sent
**
**
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (invalid callback type)
** DPX_ERR_CELL_TX_FAILURE (cell transmission failed)
*******************************************************************************/
INT4 dpx_TxAAL0Msg (DUPLEX duplex, UINT1 *pMsg, UINT1 vpi, UINT2 vci)
{
sDPX_CELL_HDR sCellHdr;
sDPX_CELL_CTRL sCtrl;
INT4 ErrorCode;
UINT1 Pti = 0; /* 3 PTI bits in the header. 1 = last cell, otherwise 0 */
UINT1 Clp = 0; /* 1 CLPI bit in the header. */
UINT1 Hec = 0; /* 1 HEC byte in the cell */
/* Stuff the cell header */
sCellHdr.u1Hdr[0] = (vpi >> 4) & 0xFF;
sCellHdr.u1Hdr[1] = ((vpi & 0x0F) << 4) | ((vci >> 12) & 0x0F);
sCellHdr.u1Hdr[2] = (vci >> 4) & 0xFF;
sCellHdr.u1Hdr[3] = ((vci & 0x0F) << 4) | ((Pti & 0x07) << 1)
| (Clp & 0x01) ;
sCellHdr.u1Hdr[4] = Hec;
sCellHdr.u1UDF = 0;
/* Initialize the Cell Type Control buffer */
sCtrl.u1CellType = DPX_CELL_TYPE_FIRST_CELL | DPX_CELL_TYPE_LAST_CELL;
sCtrl.u4Crc32Prev = 0;
sCtrl.u4Crc32 = 0;
/* Send out the complete cell */
/* transmit the cell */
ErrorCode = duplexInsertCell(duplex, &sCellHdr, pMsg, &sCtrl);
if(ErrorCode != DPX_SUCCESS)
return(ErrorCode);
/* done here for sending the AAL0 message */
return(DPX_SUCCESS);
}
/*******************************************************************************
**
** dpx_TxAAL5Msg
** ___________________________________________________________________________
**
** DESCRIPTION: Transmits a AAL5 PDU message on an active HSS link of a DUPLEX
** device.
** If the message length is greater than the length of a cell's
** payload, then the message is segmented into 48 byte cells
** before calling the "duplexInsertCell()"
** For the last cell of the message (indicated by the user), the
** CRC is inserted into the last 4 bytes of the cell's payload.
**
**
** SIDE EFFECTS: It is recommended that cell reception be given higher priority
** than cell transmission to prevent extract FIFO overflow. In
** other words, all cells of a received message should be
** extracted before switching context.
**
** INPUTS:
** usrCtxt - user's context for the device.
** pMsg - pointer to the message buffer to be sent
** length - message length
** vpi - message's VPI
** vci - massage's VCI
**
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (invalid callback type)
** DPX_ERR_CELL_TX_FAILURE (cell transmission failed)
*******************************************************************************/
INT4 dpx_TxAAL5Msg (DUPLEX duplex, UINT1 *pMsg, INT4 length, UINT1 vpi,
UINT2 vci)
{
sDPX_CELL_HDR sCellHdr;
UINT1 * pu1CellPyld;
sDPX_CELL_CTRL sCtrl;
INT4 ErrorCode, i;
INT4 nCells; /* number of cells */
INT4 nBytesOfLastCell; /* number of bytes for the last cell payload */
INT4 nPadding; /* number of bytes for Padding */
UINT1 Pti = 0; /* 3 PTI bits in the header. 1 = last cell, otherwise 0 */
UINT1 Clp = 0; /* 1 CLPI bit in the header. */
UINT1 Hec = 0; /* 1 HEC byte in the cell */
UINT1 LastCellPyld[DPX_CELL_PAYLOAD_SIZE];
/* check the message length, add 8 bytes for the AAL5 CPCS trail */
nCells = (length / DPX_CELL_PAYLOAD_SIZE);
nBytesOfLastCell = length % DPX_CELL_PAYLOAD_SIZE;
/* Stuff the cell header */
sCellHdr.u1Hdr[0] = (vpi >> 4) & 0xFF;
sCellHdr.u1Hdr[1] = ((vpi & 0x0F) << 4) | ((vci >> 12) & 0x0F);
sCellHdr.u1Hdr[2] = (vci >> 4) & 0xFF;
sCellHdr.u1Hdr[3] = ((vci & 0x0F) << 4) | ((Pti & 0x07) << 1)
| (Clp & 0x01) ;
sCellHdr.u1Hdr[4] = Hec;
sCellHdr.u1UDF = 0;
/* Initialize the Cell Type Control buffer */
sCtrl.u1CellType = DPX_CELL_TYPE_FIRST_CELL | DPX_CELL_TYPE_CRC;
sCtrl.u4Crc32Prev = 0;
sCtrl.u4Crc32 = 0;
/* Send out the complete cells, except last cell */
for ( i = 0; i < nCells ; i++ )
{
pu1CellPyld = pMsg + i * DPX_CELL_PAYLOAD_SIZE;
/* transmit the cell */
ErrorCode = duplexInsertCell(duplex, &sCellHdr, pu1CellPyld, &sCtrl);
if(ErrorCode != DPX_SUCCESS)
return(ErrorCode);
/* set the cell type: not the first cell from now on */
sCtrl.u1CellType &= ~(DPX_CELL_TYPE_FIRST_CELL);
/* store the CRC-32 value in the u4Crc32Prev */
sCtrl.u4Crc32Prev = sCtrl.u4Crc32;
}
/******************************************************
** Now considering Last cell(s) of AAL5 message **
******************************************************/
/* initialize the lastCell buffer */
sysDuplexMemset(LastCellPyld, 0x00, DPX_CELL_PAYLOAD_SIZE);
if(nBytesOfLastCell < 41)
{
/* Last Cell contains data + padding + trailer */
if (nBytesOfLastCell != 0)
{
pu1CellPyld = pMsg + nCells * DPX_CELL_PAYLOAD_SIZE;
sysDuplexMemCopy(LastCellPyld, pu1CellPyld, nBytesOfLastCell);
}
/* else: Last Cell contains only padding + trailer */
LastCellPyld[40] = 0x00; /* UU field in the AAL5 CPCS trailer */
LastCellPyld[41] = 0x00; /* CPI field in the AAL5 CPCS trailer */
LastCellPyld[42] = (length & 0xFF00) >> 8; /* Length field (MSB) */
LastCellPyld[43] = length & 0x00FF; /* Length field (LSB) */
/* set the PTI bit to indicate the last cell */
sCellHdr.u1Hdr[3] |= ATM_CELL_HEADER_PTI_BIT;
/* set the last cell type */
sCtrl.u1CellType |= (DPX_CELL_TYPE_LAST_CELL);
ErrorCode = duplexInsertCell(duplex, &sCellHdr, LastCellPyld, &sCtrl);
if(ErrorCode != DPX_SUCCESS)
return(ErrorCode);
/* store the CRC-32 value in the u4Crc32Prev */
sCtrl.u4Crc32Prev = sCtrl.u4Crc32;
}
else
{
/* In this special case, (nBytesOfLastCell + 8), i.e. (data + trailer)
will overfill one cell payload. Therefore one additonal cell is
needed to accomodate the trail bytes */
/**** The first of the last two cells *****/
/* stuff the data */
pu1CellPyld = pMsg + nCells * DPX_CELL_PAYLOAD_SIZE;
sysDuplexMemCopy(LastCellPyld, pu1CellPyld, nBytesOfLastCell);
/* padding the remainder of the cell payload */
nPadding = DPX_CELL_PAYLOAD_SIZE - nBytesOfLastCell;
sysDuplexMemset(&LastCellPyld[nBytesOfLastCell], 0x00, nPadding);
ErrorCode = duplexInsertCell(duplex, &sCellHdr, LastCellPyld, &sCtrl);
if(ErrorCode != DPX_SUCCESS)
return(ErrorCode);
/* store the CRC-32 value in the u4Crc32Prev */
sCtrl.u4Crc32Prev = sCtrl.u4Crc32;
/*** The second of the last two cells ****/
/* initialize the lastCell buffer */
sysDuplexMemset(LastCellPyld, 0x00, DPX_CELL_PAYLOAD_SIZE);
LastCellPyld[40] = 0x00; /* UU field in the AAL5 CPCS trailer */
LastCellPyld[41] = 0x00; /* CPI field in the AAL5 CPCS trailer */
LastCellPyld[42] = (length & 0xFF00) >> 8; /* Length field (MSB) */
LastCellPyld[43] = length & 0x00FF; /* Length field (LSB) */
/* set the PTI bit to indicate the last cell */
sCellHdr.u1Hdr[3] |= ATM_CELL_HEADER_PTI_BIT;
/* set the last cell type */
sCtrl.u1CellType |= (DPX_CELL_TYPE_LAST_CELL);
sCtrl.u1CellType &= ~(DPX_CELL_TYPE_FIRST_CELL); /* not first cell */
ErrorCode = duplexInsertCell(duplex, &sCellHdr, LastCellPyld, &sCtrl);
if(ErrorCode != DPX_SUCCESS)
return(ErrorCode);
/* store the CRC-32 value in the u4Crc32Prev */
sCtrl.u4Crc32Prev = sCtrl.u4Crc32;
}
/* done here for sending the AAL5 message */
return(DPX_SUCCESS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -