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

📄 burn.c

📁 自动联想命令行处理代码
💻 C
字号:
#if !BASIC_BIOS

#include <stdio.h>
#include "cli.h"
#include "uart.h"
#include "bios.h"
#include "39vf160.h"

extern void BurnFlash( unsigned short *dst, unsigned short *src, unsigned long size );
extern void CLI_BurnBasicBios( void );
extern void CLI_BurnExtendBios( void );

#if 0
static CommandNode CLI_NAME_NURN =
{
    "burn",                 // node command hint pointer
    "保存数据类",           // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_BIOS =
{
    "bios",                 // node command hint pointer
    "BIOS",                 // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_BASIC =
{
    "basic",                // node command hint pointer
    "基本BIOS",             // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    CLI_BURNBASICBIOS       // node command value
};

static CommandNode CLI_NAME_EXTEND =
{
    "extend",               // node command hint pointer
    "扩展BIOS",             // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    CLI_BURNEXTENDBIOS      // node command value
};

static CommandNode CLI_NAME_FROM =
{
    "from",                 // node command hint pointer
    "源地址",               // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_FROM1 =
{
    "from",                 // node command hint pointer
    "源地址",               // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_PROGRAM =
{
    "program",              // node command hint pointer
    "用户程序",             // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    CLI_BURNPROGRAM         // node command value
};

static CommandNode CLI_NAME_SIZE =
{
    "size",                 // node command hint pointer
    "程序大小",             // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    NULL                    // node command value
};

CommandNode *CLI_BurnBasicBios4[] =
{
	&CLI_NAME_NURN,
	&CLI_NAME_BIOS,
	&CLI_NAME_BASIC,
	&CLI_NAME_FROM
};

CommandNode *CLI_BurnExtendBios4[] =
{
	&CLI_NAME_NURN,
	&CLI_NAME_BIOS,
	&CLI_NAME_EXTEND,
	&CLI_NAME_FROM
};

CommandNode *CLI_BurnProgram4[] =
{
	&CLI_NAME_NURN,
	&CLI_NAME_PROGRAM,
	&CLI_NAME_FROM1,
	&CLI_NAME_SIZE
};

void CLI_BurnProc( unsigned char key )
{
    switch( key )
    {
		case CLI_BURNBASICBIOS:
			CLI_BurnBasicBios();
			break;
			
		case CLI_BURNEXTENDBIOS:
			CLI_BurnExtendBios();
			break;
			
		case CLI_BURNPROGRAM:
			break;
    }
}

void CLI_BurnBasicBios( void )
{
    char *str;
    unsigned long addr;

    str = CLI_GetCommandKey( 0 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &addr ))
        {
            BurnFlash( (unsigned short*)FLASH_BASIC_BIOS_ADDR, (unsigned short*)addr, FLASH_BASIC_BIOS_SIZE );
        }
    }
}

void CLI_BurnExtendBios( void )
{
    char *str;
    unsigned long addr;

    str = CLI_GetCommandKey( 0 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &addr ))
        {
            BurnFlash( (unsigned short*)FLASH_EXTEND_BIOS_ADDR, (unsigned short*)addr, FLASH_EXTEND_BIOS_SIZE );
        }
    }
}

void CLI_BurnProgram( void )
{
    char *str;
    unsigned long addr, size;

    str = CLI_GetCommandKey( 0 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &addr ))
        {
        }
        else
        {
            return;
        }
    }

    str = CLI_GetCommandKey( 1 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &size ))
        {
            BurnFlash( (unsigned short*)FLASH_PROGRAM_START_ADDR, (unsigned short*)addr, size );
        }
    }
}
#endif

void BurnFlash( unsigned short *dst, unsigned short *src, unsigned long size )
{
    unsigned long i, k;
    unsigned long tmp = (unsigned long)dst;

	UART_Printf("\r\nBurning from SDRAM 0X%08X to FALSH 0X%08X", src, dst );
	UART_Printf("\r\n0X      " );
	for( i = 0; i < (size + SECTOR_BYTE_SIZE - 1)/ SECTOR_BYTE_SIZE; i++ )
	{
	    Erase_One_Sector( dst );
	    for( k = 0; k < SECTOR_WORD_SIZE; k++ )
	    {
			Program_One_Word( dst, *src );
			dst++;
			src++;
	    }

	    UART_Printf("\b\b\b\b\b\b%06X", (unsigned long)dst - tmp );
	}
}

#endif

⌨️ 快捷键说明

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