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

📄 env_tty.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ * *  env_tty.c * *  TTY specific parts of ENV module * * ###################################################################### * * mips_start_of_legal_notice *  * Copyright (c) 2004 MIPS Technologies, Inc. All rights reserved. * * * Unpublished rights (if any) reserved under the copyright laws of the * United States of America and other countries. * * This code is proprietary to MIPS Technologies, Inc. ("MIPS * Technologies"). Any copying, reproducing, modifying or use of this code * (in whole or in part) that is not expressly permitted in writing by MIPS * Technologies or an authorized third party is strictly prohibited. At a * minimum, this code is protected under unfair competition and copyright * laws. Violations thereof may result in criminal penalties and fines. * * MIPS Technologies reserves the right to change this code to improve * function, design or otherwise. MIPS Technologies does not assume any * liability arising out of the application or use of this code, or of any * error or omission in such code. Any warranties, whether express, * statutory, implied or otherwise, including but not limited to the implied * warranties of merchantability or fitness for a particular purpose, are * excluded. Except as expressly provided in any written license agreement * from MIPS Technologies or an authorized third party, the furnishing of * this code does not give recipient any license to any intellectual * property rights, including any patent rights, that cover this code. * * This code shall not be exported, reexported, transferred, or released, * directly or indirectly, in violation of the law of any country or * international law, regulation, treaty, Executive Order, statute, * amendments or supplements thereto. Should a conflict arise regarding the * export, reexport, transfer, or release of this code, the laws of the * United States of America shall be the governing law. * * This code constitutes one or more of the following: commercial computer * software, commercial computer software documentation or other commercial * items. If the user of this code, 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 code, 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 code 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 code from MIPS Technologies or an authorized * third party. * * * *  * mips_end_of_legal_notice *  * ************************************************************************//************************************************************************ *  Include files ************************************************************************/#include <sysdefs.h>#include <sys_api.h>#include <syscon_api.h>#include <serial_api.h>#include <env_api.h>#include <string.h>/************************************************************************ *  Definitions ************************************************************************/typedef struct{    UINT8 number;    char  *s;}t_num_string_pair;/************************************************************************ *  Public variables ************************************************************************//************************************************************************ *  Static variables ************************************************************************//* Default values of environment variables */static char   *default_modetty      = DEFAULT_SERIAL_ENV;static char   *default_bootserport  = DEFAULT_BOOTPORT_ENV;/*  Mappings between enumerated values and strings describing serial *  port parameters. */static t_num_string_pair baudrate_num2s_array[] ={    { SERIAL_BAUDRATE_075_BPS,    "75"      },    { SERIAL_BAUDRATE_110_BPS,	  "110"	    },     { SERIAL_BAUDRATE_150_BPS,	  "150"	    },    { SERIAL_BAUDRATE_300_BPS,	  "300"	    },    { SERIAL_BAUDRATE_600_BPS,	  "600"	    },    { SERIAL_BAUDRATE_1200_BPS,	  "1200"    },    { SERIAL_BAUDRATE_1800_BPS,	  "1800"    },    { SERIAL_BAUDRATE_2400_BPS,	  "2400"    },    { SERIAL_BAUDRATE_4800_BPS,	  "4800"    },    { SERIAL_BAUDRATE_7200_BPS,	  "7200"    },    { SERIAL_BAUDRATE_9600_BPS,	  "9600"    },    { SERIAL_BAUDRATE_14400_BPS,  "14400"   },    { SERIAL_BAUDRATE_19200_BPS,  "19200"   },    { SERIAL_BAUDRATE_38400_BPS,  "38400"   },    { SERIAL_BAUDRATE_57600_BPS,  "57600"   },         { SERIAL_BAUDRATE_115200_BPS, "115200"  },    { SERIAL_BAUDRATE_230400_BPS, "230400"  },    { SERIAL_BAUDRATE_460800_BPS, "460800"  }#if 0    /* Not supported */    { SERIAL_BAUDRATE_921600_BPS, "921600"  }#endif    };#define BAUDRATE_NUM2S_COUNT \	    (sizeof(baudrate_num2s_array) / sizeof(t_num_string_pair))static t_num_string_pair databits_num2s_array[] ={    { SERIAL_DATABITS_7, "7" },    { SERIAL_DATABITS_8, "8" }};#define DATABITS_NUM2S_COUNT \	    (sizeof(databits_num2s_array) / sizeof(t_num_string_pair))static t_num_string_pair parity_num2s_array[] ={    { SERIAL_PARITY_NONE, "n" },    { SERIAL_PARITY_ODD,  "o" },    { SERIAL_PARITY_EVEN, "e" }};#define PARITY_NUM2S_COUNT \	    (sizeof(parity_num2s_array) / sizeof(t_num_string_pair))static t_num_string_pair flowctrl_num2s_array[] ={    { SERIAL_FLOWCTRL_HARDWARE, "hw"      },    { SERIAL_FLOWCTRL_NONE,	"none"    }#if 0    /* Not supported yet */    { SERIAL_FLOWCTRL_XON_XOFF, "xonxoff" }#endif};#define FLOWCTRL_NUM2S_COUNT \	    (sizeof(flowctrl_num2s_array) / sizeof(t_num_string_pair))static t_num_string_pair stopbits_num2s_array[] ={    { SERIAL_STOPBITS_10, "1"   },    { SERIAL_STOPBITS_20, "2"   }#if 0    /* Not supported */    { SERIAL_STOPBITS_15, "1.5" }#endif};#define STOPBITS_NUM2S_COUNT \	    (sizeof(stopbits_num2s_array) / sizeof(t_num_string_pair))/************************************************************************ *  Static function prototypes ************************************************************************/static boolsearch_s2num(    char               *raw,    void               *decoded,    UINT32             size,    t_num_string_pair *pairs,    UINT32             count );static boolsearch_num2s(     UINT8	       param,    char	       **s,    t_num_string_pair  *pairs,    UINT32             count );static bool modetty_s2num(    bool   verify_baud,    UINT32 verify_id,    char   *raw,    void   *decoded,    UINT32 size );static bool modetty_s2num0(    char   *raw,    void   *decoded,    UINT32 size );static bool modetty_s2num1(    char   *raw,    void   *decoded,    UINT32 size );static voidregister_initial( void );/************************************************************************ *  Implementation : Static functions ************************************************************************//************************************************************************ * *                          search_s2num *  Description : *  ------------- * *  Search for string and return corresponding enumerated value (if *  buffer is not NULL and size matches). * *  Return values : *  --------------- * *  TRUE if string is found, else FALSE * ************************************************************************/static boolsearch_s2num(    char               *raw, 	 /* The string				*/    void               *decoded, /* Decoded data			*/    UINT32             size,	 /* Size of decoded data		*/    t_num_string_pair *pairs,	 /* Array holding the str/number pairs  */    UINT32             count )   /* Array size				*/{    UINT32 i;    if( !raw ) return FALSE;    for( i=0;         (i < count) &&	 (strcmp( raw, pairs[i].s ) != 0);	 i++ );    if( i == count ) return FALSE;    if( decoded )    {        if( size != sizeof(UINT8) ) return FALSE;	*(UINT8 *)decoded = pairs[i].number;    }    return TRUE;}/************************************************************************ * *                          search_num2s *  Description : *  ------------- * *  Search for enumerated value and return corresponding string. * *  Return values : *  --------------- * *  TRUE if value is found, else FALSE * ************************************************************************/static boolsearch_num2s(     UINT8	       param,	 /* Numeric value of parameter		*/    char	       **s,	 /* env. string representing data	*/    t_num_string_pair  *pairs,	 /* Array holding the str/number pairs  */    UINT32             count )   /* Array size				*/{    UINT32 i;    if( !s ) return FALSE;    for( i=0;         (i < count) &&	 (param != pairs[i].number);	 i++ );    if( i == count ) return FALSE;    *s = pairs[i].s;    return TRUE;}/************************************************************************ * *                          modetty_s2num/ *			    modetty_s2num0/ *			    modetty_s2num1/			     *  Description : *  ------------- * *  Convert string describing serial port configuration (environment  *  variable format) to UINT32 containing the coded values (if buffer *  for this is available and format is correct) * *  modetty_s2num0/1 are the functions registered for TTY0 and TTY1. *  They call upon the common function modetty_s2num in order to *  perform the operation. Only difference is the SYSCON object used *  to verify the baudrate * *  Return values : *  --------------- * *  TRUE if conversion is possible, else FALSE * ************************************************************************/static bool modetty_s2num0(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size )		/* Size of decoded data			*/{    return modetty_s2num( TRUE,			  SYSCON_COM_TTY0_BAUDRATE_VERIFY_ID, 			  raw, 			  decoded, 			  size );}static bool modetty_s2num1(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size )		/* Size of decoded data			*/{    return modetty_s2num( TRUE,			  SYSCON_COM_TTY1_BAUDRATE_VERIFY_ID, 			  raw, 			  decoded, 			  size );}static bool modetty_s2num(     bool   verify_baud,		/* TRUE -> Verify baudrate		*/    UINT32 verify_id,		/* SYSCON ID used to verify baudrate	*/    char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size )		/* Size of decoded data			*/{#define NUMTOKENS 5    char  *myarg[NUMTOKENS];    char  myraw[24];   /* "921600,n,8,1,xonxoff" (max) */    char  c;    int   n;    char  *p;    UINT8 baudrate, parity, databits, stopbits, flowctrl;    /* Check that we have the string */    if( !raw )        return FALSE;    /* Check size of variable for decoded data */    if( decoded && (size != sizeof(UINT32)) )        return FALSE;    if( strlen(raw) > sizeof(myraw)-1 )        return FALSE;    /* make a local copy of string data */    strcpy(myraw, raw);    /* Get exactly NUMTOKENS ','-separated tokens from the ascii input */    myarg[0] = myraw;                           /* first token is easy */    for (n=0, p = myraw; (c= *p); p++)    {        if (c == ',')        {            if (n == NUMTOKENS-1) return FALSE; /* too many tokens */            *p = '\0';                          /* token end   */            myarg[++n] = p+1;                   /* next token */        }    }    if (n != NUMTOKENS-1) return FALSE;         /* too few tokens */    /*  Check validity of the 5 tokens and extract environment value     *  for each.     */    if( !env_baudrate_s2num( myarg[0], &baudrate, sizeof(UINT8)) )        return FALSE;    /*  Port specific check.     *  If the following write operation fails, the baudrate is     *  not supported.     */    if( verify_baud &&        (SYSCON_write( verify_id, &baudrate, sizeof(UINT8) ) != OK) )    {        return FALSE;    }    if( !env_parity_s2num(   myarg[1], &parity, sizeof(UINT8)) )        return FALSE;    if( !env_databits_s2num( myarg[2], &databits, sizeof(UINT8)) )        return FALSE;    if( !env_stopbits_s2num( myarg[3], &stopbits, sizeof(UINT8)) )        return FALSE;    if( !env_flowctrl_s2num( myarg[4], &flowctrl, sizeof(UINT8)) )        return FALSE;    if (decoded)    {        /* Construct environment value (byte) */        *(UINT32 *)decoded = 	     baudrate                |             (parity<<8)             |             (databits<<16)          |             ((stopbits & 0x0f)<<24) |             ((flowctrl & 0x0f)<<28);    }    return TRUE;#undef NUMTOKENS}/************************************************************************ * *                          register_initial *  Description : *  ------------- * *  Determine initial serial port settings and register these with SYSCON * *  Return values : *  --------------- * *  None * ************************************************************************/static voidregister_initial( void )

⌨️ 快捷键说明

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