📄 main.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 "common.h"
#include "hwconf.h"
#include "h2io.h"
#include "h2reg.h"
#include "main.h"
#include "timer.h"
#include "uartdrv.h"
#include "phytsk.h"
#include "h2.h"
#include "h2flowc.h"
#include "print.h"
#include "misc2.h"
#include "clihnd.h"
#include "h2mactab.h"
#include "hwport.h"
#include "eep.h"
#include "taskdef.h"
/* ************************************************************************ **
*
*
* Public data
*
*
*
* ************************************************************************ */
/* ************************************************************************ **
*
*
* Defines
*
*
*
* ************************************************************************ */
/* Define period for performing ageing, granularity is 1 second */
#define AGEING_TIMEOUT 150
/* ************************************************************************ **
*
*
* Typedefs and enums
*
*
*
* ************************************************************************ */
/* ************************************************************************ **
*
*
* Prototypes for local functions
*
*
*
* ************************************************************************ */
static void error_check (void);
static void handle_ageing (void);
static uchar checksum_ok (void);
/* ************************************************************************ **
*
*
* Local data
*
*
*
* ************************************************************************ */
static bool h2_fatal_error = FALSE;
static uchar ageing_timer = 0;
/* ************************************************************************ */
void main (void)
/* ------------------------------------------------------------------------ --
* Purpose : Control initialization sequence and control round-robin loop.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
/* Determine hardware version */
get_hw_version();
/*
** Initialize LED outputs.
*/
ALIVE_LED_ON; /* Turn on alive LED (if any) until power up done */
/* Increase speed */
h2_write_masked(SYSTEM, 0, SYS_ICPU_CTRL, (ulong) CLK_DIV << 8, CLK_DIV_MASK);
/*
** If checksum of flash PROM is wrong, hang with error indication on
** internal LEDs
*/
if (!checksum_ok()) {
while (TRUE) {
/* do nothing */
}
}
/* Set up timer 0 for system tick */
timer_1_init();
/* Initialize drivers */
#ifndef NO_DEBUG_IF
uart_init();
#endif
/* Enable global interrupt */
EA = 1;
/* Wait 20 msec before accessing chip and PHYs */
delay_1(20);
#ifdef DISABLE_FRAME_AGING
h2_disable_frame_aging();
#endif
h2_post_reset();
gpio_init();
/* Turn on red front LED until power up done */
#if FRONT_LED_PRESENT
front_led(FRONT_LED_RED);
#endif
/*
** Do some health check of chip
*/
if ((h2_check() != 0) || h2_fatal_error) {
hang();
}
/*
** Initialize and check PHYs
*/
phy_hw_init();
phy_init();
if (phy_check_all() != 0) {
hang();
}
/* Turn on red front LED until power up done */
#if FRONT_LED_PRESENT
front_led(FRONT_LED_RED);
#endif
/*
** Initialize chip and software
*/
h2_init_ports();
phy_tsk_init();
/* Turn on green front LED when power up done */
#if FRONT_LED_PRESENT
front_led(FRONT_LED_GREEN);
#endif
#if (WATCHDOG_PRESENT && WATCHDOG_ENABLE)
enable_watchdog();
#endif
#if TRANSIT_VERIPHY
phy_veriphy_all();
#endif
/* ************************************************************************ **
*
*
* Loop forever
*
*
*
* ************************************************************************ */
while (TRUE) {
/* For profiling/debug purposes */
MAIN_LOOP_ENTER();
/*
** In case of fatal error, reboot
*/
if (h2_fatal_error) {
h2_fatal_error = FALSE;
reboot();
}
/* Handle any commands received on RS232 interface */
#ifndef NO_DEBUG_IF
TASK(TASK_ID_CLI, cli_tsk());
#endif
/*
** Do 10 msec jobs
*/
if (ms_10_timeout_flag) {
ms_10_timeout_flag = 0;
TASK(TASK_ID_PHY_TIMER, phy_timer_10());
TASK(TASK_ID_PHY, phy_tsk());
#if (WATCHDOG_PRESENT && WATCHDOG_ENABLE)
TASK(TASK_ID_WATCHDOG, kick_watchdog());
#endif
}
/*
** Do 1 sec jobs
*/
if (sec_1_timeout_flag) {
sec_1_timeout_flag = 0;
TASK(TASK_ID_AGEING, handle_ageing());
/*
** Check H2 and PHYs
*/
TASK(TASK_ID_ERROR_CHECK, error_check());
/* toggle any alive LED */
ALIVE_LED_TOGGLE;
}
/* For profiling/debug purposes */
MAIN_LOOP_EXIT();
}
}
/* ************************************************************************ */
void reboot (void)
/* ------------------------------------------------------------------------ --
* Purpose : Reboot by forcing watchdog reset or utilizing any other
* reset feature.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
RA_DA3 = 0;
RA_DA2 = 0;
RA_DA1 = 0;
RA_DA0 = 1;
RA_BLK = SYSTEM;
RA_AD_WR = SYS_GLORESET;
RA_DONE = 1;
while (TRUE) {
/* await reset */
}
}
/* ************************************************************************ */
void hang (void)
/* ------------------------------------------------------------------------ --
* Purpose : Hang forever with front LED blinking red.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar status;
status = 1;
while (TRUE) {
#if FRONT_LED_PRESENT
/* Toggle red LED */
if (status) {
front_led(FRONT_LED_RED);
}
else {
front_led(FRONT_LED_OFF);
}
delay(MSEC_400);
status ^= 1;
#endif
}
}
/* ************************************************************************ */
void set_fatal_error (uchar error_id)
/* ------------------------------------------------------------------------ --
* Purpose : Indicate error and initiate error recovery.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
error_id = error_id; /* keep compiler happy */
h2_fatal_error = TRUE;
}
/* ************************************************************************ */
static void handle_ageing (void)
/* ------------------------------------------------------------------------ --
* Purpose : Handles ageing. To be called every 1 second.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
#define age_time AGEING_TIMEOUT
if (age_time != 0) {
if (++ageing_timer >= age_time) {
ageing_timer = 0;
h2_mactab_age();
}
}
}
/* ************************************************************************ */
static void error_check (void)
/* ------------------------------------------------------------------------ --
* Purpose :
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
if (h2_check() != 0) {
set_fatal_error(H2_GENERAL_FAILURE);
}
if (phy_check_all() != 0) {
set_fatal_error(PHY_GENERAL_FAILURE);
}
}
/* ************************************************************************ */
static uchar checksum_ok (void)
/* ------------------------------------------------------------------------ --
* Purpose : Calculate and verify checksum of program flash.
* Remarks : Returns TRUE if checksum is ok, otherwise FALSE.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
return eep_checksum_ok();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -