📄 txrxtst.c
字号:
/*
Copyright (c) 2002-2005 Vitesse Semiconductor Corporation "Vitesse".
All Rights Reserved. Unpublished rights reserved under the copyright laws
of the United States of America, other countries and international treaties.
The software is provided without a fee. Permission to use, copy, store and
modify, the software and its source code is granted. Permission to integrate
into other products, disclose, transmit and distribute the software in an
absolute machine readable format (e.g. HEX file) is also granted.
The source code of the software may not be disclosed, transmitted or
distributed without the written permission of Vitesse. The software and its
source code may only be used in products utilizing a Vitesse VSC73xx product.
This copyright notice must appear in any copy, modification, disclosure,
transmission or distribution of the software. Vitesse retains all ownership,
copyright, trade secret and proprietary rights in the software.
THIS SOFTWARE HAS BEEN PROVIDED "AS IS," WITHOUT EXPRESS OR IMPLIED WARRANTY
INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR USE AND NON-INFRINGEMENT.
*/
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "h2reg.h"
#include "hwconf.h"
#include "hwport.h"
#include "txt.h"
#include "h2io.h"
#include "h2.h"
#include "h2txrx.h"
#include "phyconf.h"
#include "phydrv.h"
#include "phymap.h"
#include "timer.h"
#include "main.h"
#include "print.h"
#if LOOPBACK_TEST
/* ************************************************************************ **
*
*
* Defines
*
*
*
* ************************************************************************ */
#define PACKET_LENGTH 128
#define pac_len_t uchar
//#define pac_len_t ushort
/* ************************************************************************ **
*
*
* Typedefs and enums
*
*
*
* ************************************************************************ */
/* ************************************************************************ **
*
*
* Prototypes for local functions
*
*
*
* ************************************************************************ */
static uchar test_tx_rx (uchar rx_port_no, uchar tx_port_no);
static void send_packet (uchar port_no);
static uchar get_and_check_packet (uchar rx_port_no, uchar tx_port_no);
static void init_port (uchar port_no, uchar mode);
static void init_phys_forced (uchar port_no_1, uchar port_no_2, uchar mode);
/* ************************************************************************ **
*
*
* Local data
*
*
*
* ************************************************************************ */
#ifdef LOOP_CHAIN
static void set_src_mask (uchar port_no, uchar bit_no)
{
h2_write(ANALYZER, 0, ANA_SRCMASKS + port_no, PORT_BIT_MASK(bit_no));
}
/* ************************************************************************ */
void test_loop_chain (uchar type)
/* ------------------------------------------------------------------------ --
* Purpose :
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar port_no;
uchar bit_no;
/* Disable learning */
h2_write(ANALYZER, 0, 13, 0);
if (type == 0) {
/*
** Set all port to run 1G full duplex.
** Set up src masks to support test chain:
** port source mask
** 0 0000000000000010
** 1 0000000000000001
** 2 0000000000001000
** 3 0000000000000100
** .
** .
** .
** 14 1000000000000000
** 15 0100000000000000
*/
port_no = MIN_PORT;
while (port_no < MAX_PORT) {
init_port(port_no, LINK_MODE_SPEED_1000);
if (port_no & 0x01) {
bit_no = port_no - 1;
}
else {
bit_no = port_no + 1;
}
set_src_mask(port_no, bit_no);
port_no++;
}
}
else {
/*
** Set all port to run 1G full duplex.
** Set up src masks to support test chain with loopback on all PHYs except port 1 and 16:
** port source mask
** 0 0000000000000010
** 1 0000000000000100
** 2 0000000000001000
** 3 0000000000010000
** .
** .
** .
** 14 1000000000000000
** 15 0000000000000000
*/
port_no = MIN_PORT;
while (port_no < MAX_PORT) {
init_port(port_no, LINK_MODE_SPEED_1000);
if ((port_no != MIN_PORT) && (port_no != (MAX_PORT - 1))) {
phy_set_forced_speed(port_no, LINK_MODE_SPEED_1000 | LINK_MODE_FDX_MASK | LINK_MODE_INT_LOOPBACK);
}
set_src_mask(port_no, (port_no + 1) % MAX_PORT);
port_no++;
}
}
/* enable receive on all ports */
h2_write(ANALYZER, 0, ANA_RECVMASK, ALL_PORTS);
/* Loop until user presses a key */
while (TRUE) {
if (cmd_ready()) {
return;
}
}
}
#endif
/* ************************************************************************ */
void perform_tx_rx_test (uchar port_no, uchar speed, uchar external_loopback)
/* ------------------------------------------------------------------------ --
* Purpose : Perform internal or pair-wise external loopback on ports/PHYs. Dump
* results to RS-232.
* Remarks : If port_no is in range 0-15, do loopback on this port and, in case
* of external loopback, on its counterpart as well. Otherwise do
* loopback on all ports.
* If speed is in range 0-3, loopback is performed at one speed only
* (0 = 10 Mbit/s, 1 = 100 Mbit/s, 2 = 1000 Mbit/s, 3 = TBI). Otherwise
* run test at all speeds.
* external_loopback selects between internal (0) and external (1)
* loopback.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar port_no_stop;
uchar mode;
uchar mode_mask;
uchar result [2];
uchar result_tmp;
uchar j;
uchar loop_count_1;
uchar loop_count_2;
uchar port_no_1;
uchar port_no_2;
#define NO_OF_MODES 3
#define MODE_MASK_ALL 0x07 /* 10, 100 and 1000 */
/*
** Display headers.
*/
if (external_loopback) {
print_str(txt_09); /* "External " */
}
else {
print_str(txt_08); /* "Internal " */
}
print_str(txt_11); /* header with speed-columns */
/*
** Determine ports to run test on
*/
if (port_no >= MAX_PORT) {
port_no = MIN_PORT;
port_no_stop = MAX_PORT - 1;
}
else {
if (external_loopback) {
port_no = port_no & ~0x01;
port_no_stop = port_no + 1;
}
else {
port_no_stop = port_no;
}
}
/*
** Determine speeds to run test at
*/
if (speed == 0xff) {
mode_mask = MODE_MASK_ALL;
}
else {
mode_mask = 1 << speed;
}
h2_write(ANALYZER, 0, 13, 0); /* Disable learning */
h2_write(ANALYZER, 0, 14, 0);
h2_write(ANALYZER, 0, 15, 0);
/*
** Run through ports (2 ports at each run if external loopback)
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -