memprint.c

来自「au1500开发的应用程序」· C语言 代码 · 共 78 行

C
78
字号
/* memPrint.h - memory print routine */

/* Copyright 2002-2005 Founder Communications, Inc. */

/*
modification history
--------------------
01a,21apr05,fhchen  written
*/

/*
DESCRIPTION

This file contain routines to print characters to on board mem, region
is from MEM_PRINT_LOW_ADRS to MEM_PRINT_HIGH_ADRS.

These routines are not reentrancy, used only in early startup procedure
when tty is not available.

*/

/* includes */

#include <stdarg.h>
#include <stdio.h>
#include "memPrint.h"

/*******************************************************************************
*
* memPrint - print characters to ram
*
* This routine prints string into certain RAM region.  When the top of this
* region is arrived, it roll back to the beginning. Strings longer than
* MEM_PRINT_MAX_LEN characters are truncated.
*
* RETURNS: NA
*/

void memPrintStr
(
    char *string                             /* message to print */
    )
    {
    int count = 0;
    static char *current = (char *)MEM_PRINT_LOW_ADRS;

    while((*string != '\0') && (count < MEM_PRINT_MAX_LEN))
        {
        *current++ = *string++;
        count++;

        if((unsigned int)current >= MEM_PRINT_HIGH_ADRS)
            current = (char *)MEM_PRINT_LOW_ADRS;
        }
    }

/*******************************************************************************
*
* memPrintf - format and print message to ram
*
* This routine wrap up memPrint and provide printf-like format function.
*
* RETURNS: NA
*/

void memPrintf(char *fmt, ...)
    {
    va_list ap;
    char string[MEM_PRINT_MAX_LEN];

    /* format the input and print it to RAM */

    va_start(ap, fmt);
    vsprintf(string, fmt, ap);
    memPrintStr(string);
    va_end(ap);
    }

⌨️ 快捷键说明

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