⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stty.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

/************************************************************************
 *
 *  stty.c
 *
 *  Shell stty command
 *
 *  stty [-tty0|-tty1] [-b|-u| [-p][<baudrate>][n|o|e][7|8][1|2] ]
 *
 *
 * ######################################################################
 *
 * 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 <shell_api.h>
#include "shell.h"
#include <syscon_api.h>
#include <env_api.h>
#include <string.h>
#include <stdio.h>
#include <serial_api.h>
#include <io_api.h>
#include <sys_api.h>

/************************************************************************
 *  Definitions
 ************************************************************************/

/************************************************************************
 *  Static function prototypes
 ************************************************************************/

static MON_FUNC(stty);

static MON_FUNC(stty_sdb);

static UINT32 
get_options(
    UINT32 argc,
    char   **argv,
    UINT8  *action,
#define ACTION_READ	0x01
#define ACTION_LIST	0x02
#define ACTION_UPDATE	0x04
#define ACTION_STORE	0x08
    UINT8  *port,
    UINT8  *baudrate,
    UINT8  *parity,
    UINT8  *databits,
    UINT8  *stopbits,
    bool   sdb );

static UINT32
do_stty(
    UINT8 action,
    UINT8 port,
    UINT8 baudrate,
    UINT8 parity,
    UINT8 databits,
    UINT8 stopbits );

static void
re_init_port(
    UINT32 port );

/************************************************************************
 *  Public variables
 ************************************************************************/

/************************************************************************
 *  Static variables
 ************************************************************************/

/* OPTIONS */
static t_cmd_option options[] =
{ 
  { "u",     "Force environment settings for port to take effect" },
  { "p",     "Transfer current settings for port to environment" },
  { "b",     "List supported baud rates for the specified port" },
  { "tty0",  "Setup port 0 - default" },
  { "tty1",  "Setup port 1" }
};
#define OPTION_COUNT	(sizeof(options)/sizeof(t_cmd_option))


/* Command definition for help */
static t_cmd cmd_def =
{
    "stty",
     stty,
    "stty [-tty0|-tty1] [-b|-u| [-p] [<baudrate>] [n|o|e] [7|8] [1|2] ]",

    "Setup or view serial port setup. Default port is "
#if (DEFAULT_PORT == PORT_TTY0)
    "tty0"
#else
    "tty1"
#endif
    ".\n"
    "-b,-u,-p apply to the default port if no port is specified.\n"
    "\n"
    "The possible baudrates are generally 75-460800, but not all baudrates\n"
    "are supported by all platforms. Use 'stty -ttyx -b' to get a list of\n"
    "the supported baudrates for a specific port.\n"
    "Available parity settings are n (none), o (odd), e (even).\n"
    "Available databits are 7 and 8.\n"
    "Available stopbits are 1 and 2.\n"
    "\n"
    "When changing the parameters for a tty which is being used (e.g. the\n"
    "console), some strange characters may appear as a result.\n"
    "\n"
    "Also note that stty does not by default modify the semi-permanent tty\n"
    "setting recorded in the environment variables. Use the '-p' option if\n"
    "you want to set the environment variable for the specific tty as well.",

    options,
    OPTION_COUNT,
    FALSE
};

static t_cmd cmd_def_sdb_lower =
{
    "b",
     stty_sdb,
    "b <baudrate>             (Microsoft SDB command)",
    "Setup baudrate of port "
#if (DEFAULT_PORT == PORT_TTY0)
    "tty0."
#else
    "tty1."
#endif
    " This command is equivalent to\n"
    "'stty -tty0 <baudrate>'. See 'help stty' for more information on\n"
    "available baudrates.",

    NULL,
    0,
    TRUE
};


/************************************************************************
 *  Implementation : Static functions
 ************************************************************************/


/************************************************************************
 *                          stty
 ************************************************************************/
static MON_FUNC(stty)
{
    /* Options */
    UINT8   action, port, baudrate, parity, databits, stopbits;
    UINT32  rc;

    rc = get_options( argc, argv,
		      &action,
		      &port,
		      &baudrate,
		      &parity,
		      &databits,
		      &stopbits,
		      FALSE );

    if( rc != OK )
        return rc;
    else
    {
        return do_stty( action, port, baudrate, parity, databits, stopbits );
    }
}


/************************************************************************
 *                          stty_sdb
 ************************************************************************/
static MON_FUNC(stty_sdb)
{
    /* Options */
    UINT8  action, port, baudrate, parity, databits, stopbits;
    UINT32 rc;

    rc = get_options( argc, argv,
		      &action,
		      &port,
		      &baudrate,
		      &parity,
		      &databits,
		      &stopbits,
		      TRUE );

    if( rc != OK )
        return rc;
    else
    {
        return do_stty( action, port, baudrate, parity, databits, stopbits ); 
    }
}


/************************************************************************
 *                          do_stty
 ************************************************************************/
static UINT32
do_stty(
    UINT8 action,
    UINT8 port,
    UINT8 baudrate,
    UINT8 parity,
    UINT8 databits,
    UINT8 stopbits )
{
    char    msg[200];
    char    *s;
    UINT32  rc;
    UINT8   flowctrl;
    char    *mode;

    if( action & ACTION_LIST )
    {
	if( SHELL_PUTS( "\nAvailable baudrates are :\n\n" )) return OK;
	    
	for( baudrate = SERIAL_BAUDRATE_NOT_DEFINED + 1;
	     baudrate < SERIAL_BAUDRATE_MAX;
	     baudrate++ )
        {
            /*  Validate baudrate for specific port.
             *  If the following write operation fails, the baudrate is
	     *  not supported.
	     */
	    if( SYSCON_write( (port == PORT_TTY0) ?
		                  SYSCON_COM_TTY0_BAUDRATE_VERIFY_ID :
			          SYSCON_COM_TTY1_BAUDRATE_VERIFY_ID,
		              (void *)&baudrate, sizeof(UINT8) ) == OK )
	    {
	        env_baudrate_num2s( baudrate , &s );

		if( SHELL_PUTS( s )) return OK;
		if( SHELL_PUTC( '\n' )) return OK;
	    }
        }

	SHELL_PUTC( '\n' );
	
	return OK;
    }

    /* Handle flowctrl differently since it can't be configured */

    SYSCON_read( (port == PORT_TTY0) ?
		     SYSCON_COM_TTY0_FLOWCTRL_ID :
		     SYSCON_COM_TTY1_FLOWCTRL_ID,
		 (void *)&flowctrl, sizeof(UINT8) );

    /**************************************************************
    ** Settings have been read from "CURRENT" or from command line
    */


    s = (port == PORT_TTY0) ? ENV_MODETTY0 : ENV_MODETTY1;

    if( action & ACTION_UPDATE )
    {
        /**********************************************
        ** Replace settings with those from environment
        */

        if( !env_get( s, &mode, NULL, 0 ) )
	    return SHELL_ERROR_FAILED;  /* TBD : error code */
	
	env_modetty_string2parts( mode,
                                  &baudrate,
				  &parity,
				  &databits,
				  &stopbits,
				  &flowctrl );
    }

    if( action & ACTION_STORE )
    {	
        /********************************
	** Store settings in environment
        */

        /* put together and store new mode */
        env_modetty_parts2string( &mode,
				  baudrate,
				  parity,
				  databits,
				  stopbits,
				  flowctrl );

        rc = env_set( s, mode, ENV_ATTR_RW, NULL, NULL );
	
	if( rc != OK )
	    return rc;
    }
    
    /*****************
    ** show settings
    */
 
    if( action & ACTION_STORE )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -