📄 sys.c
字号:
/************************************************************************
*
* sys.c
*
* System functions
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved.
*
* Unpublished rights reserved under the Copyright Laws of the United States of
* America.
*
* This document contains information that is proprietary to MIPS Technologies,
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information
* (in whole or in part) which is not expressly permitted in writing by MIPS
* Technologies or a contractually-authorized third party is strictly
* prohibited. At a minimum, this information is protected under unfair
* competition laws and the expression of the information contained herein is
* protected under federal copyright laws. Violations thereof may result in
* criminal penalties and fines.
* MIPS Technologies or any contractually-authorized third party reserves the
* right to change the information contained in this document to improve
* function, design or otherwise. MIPS Technologies does not assume any
* liability arising out of the application or use of this information. Any
* license under patent rights or any other intellectual property rights owned
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies
* or any contractually-authorized third party in a separate license agreement
* between the parties.
* The information contained in this document constitutes one or more of the
* following: commercial computer software, commercial computer software
* documentation or other commercial items. If the user of this information, or
* any related documentation of any kind, including related technical data or
* manuals, is an agency, department, or other entity of the United States
* government ("Government"), the use, duplication, reproduction, release,
* modification, disclosure, or transfer of this information, or any related
* documentation of any kind, is restricted in accordance with Federal
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of
* this information by the Government is further restricted in accordance with
* the terms of the license agreement(s) and/or applicable contract terms and
* conditions covering this information from MIPS Technologies or any
* contractually-authorized third party.
*
************************************************************************/
/************************************************************************
* Include files
************************************************************************/
#include <sysdefs.h>
#include <io_api.h>
#include <syscon_api.h>
#include <net_api.h>
#include <serial_api.h>
#include <syserror.h>
#include <shell_api.h>
#include <sys_api.h>
#include <product.h>
#include <stdio.h>
#include <mips.h>
/************************************************************************
* Definitions
************************************************************************/
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
static char msg[30];
/************************************************************************
* Static function prototypes
************************************************************************/
static bool
determine_dev(
UINT32 port,
UINT32 *major,
UINT32 *minor );
static UINT32
sys_validate_ram_range(
UINT32 start, /* Start address (physical) */
UINT32 last ); /* Last address (physical) */
/************************************************************************
* Implementation : Public functions
************************************************************************/
/************************************************************************
* sys_putchar
************************************************************************/
void
sys_putchar(
UINT32 port,
char ch )
{
UINT32 major, minor;
/* LF -> CR+LF due to some terminal programs */
if( ch == LF )
sys_putchar( port, CR );
if( determine_dev( port, &major, &minor ) )
{
IO_write( major, minor, (UINT8 *)(&ch) );
}
}
/************************************************************************
* sys_puts
************************************************************************/
void
sys_puts(
UINT32 port,
char *s )
{
while( *s != '\0' )
{
sys_putchar( port, *(s++) );
}
}
/************************************************************************
* sys_getchar
************************************************************************/
bool /* TRUE -> OK, FALSE -> FAILED */
sys_getchar(
UINT32 port,
char *ch )
{
UINT32 major, minor;
INT32 rc;
if( port == PORT_NET )
{
*ch = net_getchar();
return TRUE;
}
if( determine_dev( port, &major, &minor ) )
{
/* Poll whatever needs to be polled (platform specific) */
sys_poll();
rc = IO_read( major, minor, (UINT8 *)(ch) );
if ( (rc == OK) || (rc == ERROR_SERIAL_COMM_BREAK) )
{
return TRUE;
}
if ( rc == ERROR_SERIAL_COMM_ERROR )
{
*ch = UART_ERROR;
return TRUE;
}
return FALSE;
}
else
return FALSE;
}
/************************************************************************
* sys_getchar_ctrlc
************************************************************************/
bool /* TRUE -> CTRL-C received */
sys_getchar_ctrlc(
UINT32 port )
{
UINT32 major, minor;
t_SERIAL_ctrl_descriptor descr;
descr.sc_command = SERIAL_CTRL_POLL_BREAK;
if( determine_dev( port, &major, &minor ) )
{
return
(IO_ctrl( major, minor, (void *)&descr ) ==
ERROR_SERIAL_COMM_BREAK) ?
TRUE :
FALSE;
}
else
return FALSE;
}
/************************************************************************
*
* sys_disp
* Description :
* -------------
*
* Display value in ASCII display
*
* Return values :
* ---------------
*
* None
*
************************************************************************/
void sys_disp(
UINT32 val )
{
SYSCON_write( SYSCON_BOARD_ASCIIWORD_ID,
(void *)&val, sizeof(UINT32) );
}
/************************************************************************
*
* sys_disp_ch
* Description :
* -------------
*
* Display character in ASCII display
*
* Return values :
* ---------------
*
* None
*
************************************************************************/
void sys_disp_ch(
UINT8 pos,
char ch )
{
t_sys_alphanumeric data;
data.posid = pos;
data.string = (UINT8 *)&ch;
SYSCON_write( SYSCON_BOARD_ASCIICHAR_ID,
(void *)&data, sizeof(t_sys_alphanumeric) );
}
/************************************************************************
*
* sys_disp_str
* Description :
* -------------
*
* Display string in ASCII display
*
* Return values :
* ---------------
*
* None
*
************************************************************************/
void sys_disp_str(
char *s )
{
t_sys_alphanumeric data;
data.posid = 0;
data.string = (UINT8 *)s;
SYSCON_write( SYSCON_BOARD_ASCIISTRING_ID,\
(void *)&data, sizeof(t_sys_alphanumeric) );
}
/************************************************************************
*
* sys_wait_ms
* Description :
* -------------
*
* Wait for the specified interval
*
* Return values :
* ---------------
*
* None
*
************************************************************************/
void
sys_wait_ms(
UINT32 ms ) /* Interval in milliseconds */
{
UINT32 cycles;
UINT32 data = 0;
UINT32 cycle_per_count;
SYSCON_read(
SYSCON_CPU_CYCLE_PER_COUNT_ID,
&cycle_per_count,
sizeof(UINT32) );
cycles = (sys_cpufreq_hz / 1000) * ms / cycle_per_count;
/* Set counter to 0 */
SYSCON_write( SYSCON_CPU_CP0_COUNT_ID,
(void *)(&data),
sizeof(UINT32) );
do
{
SYSCON_read( SYSCON_CPU_CP0_COUNT_ID,
(void *)(&data),
sizeof(UINT32) );
}
while( data < cycles );
}
/************************************************************************
*
* sys_reg_addr
* Description :
* -------------
*
* Calc address from base address, register spacing and register offset.
* Also, in case of device with different endianness than CPU, adjust
* for endianness (only supported for 1 byte spacings).
*
* In case the following is true, the 2 lsb of the address need
* to be inverted :
*
* 1) Endianness of target and CPU are not the same
* 3) spacing is 1 byte
*
* Return values :
* ---------------
*
* address (void pointer)
*
************************************************************************/
void *
sys_reg_addr(
bool target_bigend, /* TRUE -> target is big endian.
FALSE -> target is little endian. */
UINT8 spacing, /* spacing of regs in bytes */
void *base, /* Base address */
UINT32 offset ) /* Offset scaled down by spacing */
{
UINT32 addr = (UINT32)base + offset * spacing;
if( spacing == sizeof(UINT8) )
{
addr = target_bigend ?
SWAP_BYTEADDR_EB( addr ) :
SWAP_BYTEADDR_EL( addr );
}
return (void *)addr;
}
/************************************************************************
*
* sys_validate_range
* Description :
* -------------
*
* Validate address range (alignment, TLB if mapped address, RAM range).
*
* Return values :
* ---------------
*
* OK : No error
* SHELL_ERROR_ALIGN : Alignment error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -