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

📄 dm_serialinout.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
*                   input string into command and parameter strings, find a command
*                   structure in the command list array and execute the command.
*
* INPUT PARAMETERS: cmdListP   is a pointer to the command list array.
*                   cmdStringP is a pointer to the input string.
*
* RETURNS:          none.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/
static
void AccessCmdList (DM_CommandListEntry_T * cmdListP, char * inputStringP)
{
    DM_CommandListEntry_T * cmdListEntryP;
    char * cmdStringP, * paramStringP, * temp_pntr;

    if ((temp_pntr=strchr(inputStringP, PARAM_SEPRT)) == NULL)
    {
        paramStringP = NULL;
    }
    else
    {
        *temp_pntr = '\0';
        paramStringP = ++temp_pntr;
    }
    cmdStringP = inputStringP;

    if ((cmdListEntryP=FindCmd(cmdListP, cmdStringP)) == NULL)
    {
        printf("Command is not found\r\n");
    }
    else
    {
        ExecuteCmd (cmdListEntryP, paramStringP);
    }
}

/*
*******************************************************************************
*
* FUNCTION:         DispatchCmd
*
* DESCRIPTION:      This function is used to get an input string, find a command
*                   structure in the command list array and execute the command.
*
* INPUT PARAMETERS: cmdListP is a pointer to command list array
*                   buffP    is a pointer to the buffer where the input string,
*                            taken from the serial port, is placed.
*
* RETURNS:          none.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/
static
void DispatchCmd (DM_CommandListEntry_T * cmdListP)
{
    UartContextT * ctxP = GetPointerToSystemUart();
    char * inputStringP;
    char buff[CMD_STRING_SIZE];

    inputStringP = GetInputString (ctxP, buff);
    ConvertToUpper(inputStringP);
    AccessCmdList (cmdListP, inputStringP);
}

/*
*******************************************************************************
*
* FUNCTION:         DM_SerialInOut
*
* DESCRIPTION:      This function will allow to run an automated test for the
*                   manufacturing diagnostics.
*                   Any commands from the Diagnostic Manager command lists can be
*                   executed by sending the specific string to the platform.
*                   The '>' prompt will be sent to the terminal and
*                   DM expects the control string to be returned.
*
* INPUT PARAMETERS: none
*
* RETURNS:          none
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      Terminal is attached to the serial port and the test script
*                   is running on the host platform.
*
*******************************************************************************
*/
/*
void DM_SerialInOut(void)
{
    DM_CommandListEntry_T * cmdListP;

    // Select the platform specific command list
    cmdListP = GetPlatformCommandList();

    while(1)
    {
        // Process a command string.
        DispatchCmd (cmdListP);
    }
}
*/
/*
*******************************************************************************
*
* FUNCTION:         DM_TranslateMenuToCmd
*
* DESCRIPTION:      This function is used by the menu system. It is passed the
*                   string from menu entry structure. It splits the string into
*                   the command and parameter strings, finds a command in the
*                   command list array structure and executes the command.
*
* INPUT PARAMETERS: arg          is a pointer to the command list.
*                   inputStringP is a pointer to the the command string from menu
*                                entry structure.
*
* RETURNS:          none.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      A format of the command string in the menu structure is identical
*                   to the input string, receved from the serial port to access the
*                   command list.
*                   The input string has a following format:
*                         :DEVICENAME.COMMAND,YY,ZZCR
*                   where:
*                         DEVICENAME.COMMAND is a command string,
*                         YY and ZZ ... are the parameters, separated by ','.
*                         CR is a carriage return character.
*
*******************************************************************************
*/

void DM_TranslateMenuToCmd(void* arg, char * inputStringP)
{
    DM_CommandListEntry_T * cmdListP = (DM_CommandListEntry_T *) arg;
    char buff[CMD_STRING_SIZE], * buffP;

    buffP = buff;
    strcpy(buffP, inputStringP);
    buff[CMD_STRING_SIZE - 1] = '\0';

    AccessCmdList(cmdListP, buffP);
}

// Skips to the first comma (parameter separator).
// Then points to next alphanumeric or null character, whichever comes first.
// Ignores, for instance, all punctuation marks - including subsequent commas
//  that are not preceded  by alphanumeric characters.
// So "empty" parameters are not supported.

PCHAR SysCmdPaFindNextParam  (PCHAR srcStringP)
{
    // First, skip the current parameter
    while (*srcStringP &&  (',' != *srcStringP))
    {
        srcStringP++;
    }

    // Then, find the next parameter if it exists
    if  (',' == *srcStringP)
    {
        srcStringP++;
    }
    while (*srcStringP &&  (!isalnum(*srcStringP)))
    {
        srcStringP++;
    }
    return(srcStringP);

} // SysCmdPaNextParam()

/*
*******************************************************************************
*
* FUNCTION:         GetUserResponse
*
* DESCRIPTION:      This function will allow to run an interructive tests for the
*                   manufacturing diagnostics.
*
* INPUT PARAMETERS: 
*   UserResponceT   param - if YES it sends  "User! Press Y to continue >>" message
*                           if YES/NO it sends "User! Enter Y or N >>"
*
* RETURNS:          BOOL - TRUE for 'Y', FALSE for 'N' or anything else 
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      Terminal is attached to the serial port and the user enters
*                   Y/N keys
*
*******************************************************************************
*/
/*
char WaitUserKey(void);	//hzh
BOOL GetUserResponse(UserResponseT param)
{                    
    CHAR key;
    BOOL status;
    //UartContextT * ctxP = GetPointerToSystemUart();
    //volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP;

    //ctxP->clearRxUartFnP(ctxP);
    if (param == YES)
    {
        printf (" User! Press Y to continue >>");
        while (1)
        {
            //while (ctxP->readUartFnP(ctxP, (PCHAR)&key, 1) == 0);
            // Toggle RTS signal
            //uartP->MCR ^= MCR_RTS;
            key = WaitUserKey();	//hzh

            // Translate the key
            key &= 0xff;
            if ((key == 'Y')||(key == 'y')||(key == '1'))	//hzh
            {
                status = TRUE;
                break;
            }
        }
    }
    else if (param == YESNO)
    {
        printf (" User! Enter Y or N >>");
        while (1)
        {
            //while (ctxP->readUartFnP(ctxP, (PCHAR)&key, 1) == 0);
            key = WaitUserKey();	//hzh
            // Translate the key
            key &= 0xff;
            if ((key == 'Y')||(key == 'y')||(key == '1'))	//hzh
            {
                status = TRUE;
                break;
            }
            else if ((key == 'N')||(key == 'n')||(key == '0'))	//hzh
            {
                status = FALSE;
                break;
            }
        }
    }

    printf("\r\n");
    return status;
}
*/
/*
*******************************************************************************
*
* FUNCTION:         GetUserResponseAction
*
* DESCRIPTION:      This function will allow to run an interructive tests for the
*                   manufacturing diagnostics.
*
* INPUT PARAMETERS: 
*   UserResponceT   param - if YES it sends  "User! Press Y to continue >>" message
*                           if YES/NO it sends "User! Enter Y or N >>"
*   UserFunctionFnP function - function that will be called why we are waiting for the
*                              user responce.
*
* RETURNS:          BOOL - TRUE for 'Y', FALSE for 'N' or anything else 
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      Terminal is attached to the serial port and the user enters
*                   Y/N keys
*
*******************************************************************************
*/
BOOL GetUserResponseCallAction(UserResponseT param, UserFunctionFnPT function)
{                    
    CHAR key;
    BOOL status;
    UartContextT * ctxP = GetPointerToSystemUart();
    volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP;

    ctxP->clearRxUartFnP(ctxP);
    if (param == YES)
    {
        printf (" User! Press Y to continue >>");
        while (1)
        {
            while (ctxP->readUartFnP(ctxP, (PCHAR)&key, 1) == 0)
            {
                // Toggle RTS signal
                uartP->MCR ^= MCR_RTS;

                // Call user supplied function
                if (function != NULL)
                  function();
            }

            // Translate the key
            key &= 0xff;
            if ((key == 'Y')||(key == 'y'))
            {
                status = TRUE;
                break;
            }
        }
    }
    else if (param == YESNO)
    {
        printf (" User! Enter Y or N >>");
        while (1)
        {
            while (ctxP->readUartFnP(ctxP, (PCHAR)&key, 1) == 0);
            // Translate the key
            key &= 0xff;
            if ((key == 'Y')||(key == 'y'))
            {
                status = TRUE;
                break;
            }
            else if ((key == 'N')||(key == 'n'))
            {
                status = FALSE;
                break;
            }
        }
    }

    printf("\r\n");
    return status;
}


/*
*******************************************************************************
*
* FUNCTION:         UartKeepAlive
*
* DESCRIPTION:      This function is used to prevent RS232 transiver from getting
*                   into the AutoShutdown mode if there is no activity via the serial
*                   port.
*
* INPUT PARAMETERS: None
*
* RETURNS:          None 
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      This function should be used every time when software might be wating
*                   for more than 30 sec. for an event to happened
*
*******************************************************************************
*/

VOID UartKeepAlive(VOID)
{
    UartContextT * ctxP = GetPointerToSystemUart();
    volatile UartRegsT * uartP = (UartRegsT *)ctxP->regsP;

    // Toggle RTS signal
    uartP->MCR ^= MCR_RTS;
}

⌨️ 快捷键说明

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