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

📄 dm_serialinout.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:       DM_SerialInOut.c       
**
**  PURPOSE:       This file contains that will allow to run an automated test 
**                 for the manufacturing diagnostics.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "systypes.h"
#include "xsuart.h"
#include "xsffuart.h"
#include "xsbtuart.h"
#include "xsstuart.h"
//#include "uarts.h"
#include "DM_SerialInOut.h"
#include "timedelays.h"
#include "DM_Test.h"
#include "commandlist.h"
#include "boardControl.h"

// Constants used by serial I/O
#define WRITE_BUFFER_SIZE   256
#define CMD_STRING_SIZE     64
#define CR                  '\r'
#define PARAM_SEPRT         ','
#define SERIAL_TIMEOUT      100

static UartContextT * SystemUartP;

/*----------------------------------------------------------------------
 * Default configuration record for the serial port
 */
static UartCfgT SystemUartCfg = {
    FCR_TRFIFOE,                 // Enable FIFOs
    IER_UUE,                     // Disable DMA, no NRZ, disable IRQ, and enable UART unit
    LCR_DLAB1 | LCR_WLS8,        // One stop bit, no parity, 8 bits
    0,                           // No IRDA
    UartLoopbackOff,             // Disable loopback
    115200,                      // baud rate 115200
};

/*----------------------------------------------------------------------
 * Open the serial device.
 */
static
UINT openSerial(UartContextT * ctxP)
{
    UINT failed = FALSE;

    // Get the configuration structure.
    ctxP->uartCfgP = &SystemUartCfg;

    // Open the serial device
    if (ctxP == NULL)
    {
        printf(" Error! System UART open failed\r\n");
        failed = TRUE;
    }
    else
    {
        if (ctxP->type == (SystemUart|STUartType))
        {
            // Set Sir polarity to negative and enable Rx
            ctxP->uartCfgP->maskIRDA |= ISR_RCVEIR|ISR_RXPL;
        }
        else if (ctxP->type == (SystemUart|BTUartType))
        {
            // Enable RS232 tranceiver for BTUART
            ModifyMiscWr1Register(1, nBt_OFF);
        }
        
        // A virtual switch is read to change UART speed. NO Physical switch any more
          if ((POSTRunState() & VS_UART_SPEED_9600) == VS_UART_SPEED_9600)
          ctxP->uartCfgP->rate = 9600;

        // Initialize the system UART
        if (ctxP->setupUartFnP(ctxP))
          failed = TRUE;
    }

    return failed;
}

/*
*******************************************************************************
*
* FUNCTION:         InitSystemUart
*   
* DESCRIPTION:      This function reads board control register, and analizes 
*                   the settings of HEX switches. It performs software init and 
*                   opens the system uart. It sets the uart type variable in 
*                   context structure to indicate the system device.
*
* INPUT PARAMETERS: none.
*
* RETURNS:          UINT status = 0, if no errors.                 
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
* CALLS:
*
* CALLED BY:        
*
* PROTOTYPE:        UINT InitSystemUart (void)
*
*******************************************************************************
*/

UINT InitSystemUart (UartType_T uartType)
{
    UINT status = FALSE;
    UartContextT * ctxP;

    if (uartType == FFUartType)
    {
        // Initialize FFUART Context Structure.
        ctxP = &FFUart;
        ctxP->type = SystemUart | FFUartType;
    }
    else if (uartType == BTUartType)
    {
        // Initialize BTUART Context Structure.
        ctxP = &BTUart;
        ctxP->type = SystemUart | BTUartType;
    }
    else if (uartType == STUartType)
    {
        // Initialize STUART Context Structure.
        ctxP = &STUart;
        ctxP->type = SystemUart | STUartType;
    }

    // Open the System UART
    status = openSerial(ctxP);
    SystemUartP = ctxP;

    return status;
}

/*
*******************************************************************************
*
* FUNCTION:         GetPointerToSystemUart
*   
* DESCRIPTION:      This function returns a pointer to the system uart's context 
*                   structure
*
* INPUT PARAMETERS: none.
*
* RETURNS:          UartContextT * is a pointer to the Uart's context structure or NULL
*                   pointer if uart has not been initialized.                 
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
* CALLS:            InitSystemUart()
*
* CALLED BY:        Uart tests
*
* PROTOTYPE:        UartContextT * GetPointerToSystemUart (void)
*
*******************************************************************************
*/

UartContextT * GetPointerToSystemUart (void)
{
    return SystemUartP;
}

/*
*******************************************************************************
*
* FUNCTION:         GetInputString
*
* DESCRIPTION:      This function is used to get the input string from the serial
*                   port and place it to the specified buffer.
*
* INPUT PARAMETERS: ctxP is a pointer to the serial device
*                   buffP is a pointer to the buffer, where the input string would
*                         be stored.
*
* RETURNS:          a pointer to the command string.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      The input string has a following format:
*                         :DEVICENAME.COMMAND,YY,ZZ,...<CR>
*                   where:
*                         : is optional, for historic reasons.
*                         DEVICENAME.COMMAND is a command string,
*                         YY,ZZ,... are the optional parameters separated by commas
*                         <CR> is a carriage return character.
*
*******************************************************************************
*/
static
char * GetInputString (UartContextT * ctxP, char * buffP)
{
    char *b;
    
    b = buffP;
again:
    printf ("\r\n>");
    do {
        if (ctxP->readUartFnP(ctxP, b, 1)) {
            if (*b == CR) {
                if (b == buffP) goto again; // Don't allow empty commands.
                while (*(b-1) == ' ') b--;  // Eat trailing spaces.
                *b = 0x00;                  // Nul terminate.
                if (*buffP != ':') {        // ':' signals half duplex
                    printf("\r\n");
                    return (buffP);
                } else return (buffP + 1);  // Eat leading colon.
            } else if (*b == '\b') {        // Handle backspace
                if (b != buffP) {           // Don't backspace too far!
                    b--;
                    printf("\b \b");
                }
            } else if (
                *b > 0x1f &&                // Don't allow unhandled control characters.
                *b < 0x7f &&                // Don't allow high ASCII or 'del' character.
                 b != buffP+CMD_STRING_SIZE-1 &&  // Don't overfill the buffer.
                (b != buffP || *b != ' ')   // Don't allow leading spaces.
            ) {
                if (*buffP != ':')          // Leading colon signals half duplex.
                    printf("%c", *b);
                b++;
            }
        }
    } while (1);                            // Wait for a carriage return.
}

/*
*******************************************************************************
*
* FUNCTION:          ConvertToUpper
*
* DESCRIPTION:       This function replaces all the lower case charachters in the
*                    string to the upper case.
*
* INPUT PARAMETERS:  stringP is a pointer to the null-terminated string.
*
* RETURNS:           none.
*
* GLOBAL EFFECTS:    none.
*
* ASSUMPTIONS:       none.
*
*******************************************************************************
*/
static
void ConvertToUpper (char * stringP)
{
    int i,j;
    char c;

    j = strlen(stringP);
    for (i = 0; i < j; ++i,++stringP)
    {
        c = *stringP;
        if ((!ispunct(c)) && (!(isdigit(c))))
          c = toupper(c);
        *stringP = c;
    }
}


/*
*******************************************************************************
*
* FUNCTION:         FindCmd
*
* DESCRIPTION:      This function is used to find a command structure in the
*                   command list array. It converts all the charachters in the
*                   input string to the upper case. It looks for the function
*                   name of the command entry structure that matches the name
*                   of the input string.
*
* INPUT PARAMETERS: cmdListP   is a pointer to the command list array.
*                   cmdStringP is a pointer to the command string.
*
* RETURNS:          a pointer  to command list entry structure in the command
*                              list array.
*                   NULL       if no match is found.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/
static
DM_CommandListEntry_T * FindCmd (DM_CommandListEntry_T * command, char * cmdStringP)
{
    int i;

    for (i=0; command[i].name; i++)
    {
        if (strcmp(command[i].name, cmdStringP) == 0)
        {
            return &command[i];
        }
    }

    return NULL;
}

/*
*******************************************************************************
*
* FUNCTION:         ExecuteCmd
*
* DESCRIPTION:      This function calls the function from the command list entry
*                   structure.
*
* INPUT PARAMETERS: cmdListEntryP is a pointer to command list entry structure.
*                   paramString   is a pointer to the parameter string that
*                                 would be passed to the function in the command
*                                 list entry structure.
*
* RETURNS:          none.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
void ExecuteCmd (DM_CommandListEntry_T * cmdListEntryP, char * paramStringP)
{
    cmdListEntryP->func(cmdListEntryP->arg, paramStringP);
}

/*
*******************************************************************************
*
* FUNCTION:         AccessCmdList
*
* DESCRIPTION:      This function is used to process an input string, split the

⌨️ 快捷键说明

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