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

📄 main.c

📁 基于Freescale的MX21处理器的bootloader程序
💻 C
字号:
/*-------------------------------------------------------------------
FILE NAME:
	main.c
DESCRIPTION:
	this file includes test functions for audio codec. 
AUTHOR:
	WYF
VERSION:
	2005.1122.00
COMPANY:
	APLUS COMUNICATION TECHNOLOGY CO,.LTD
HISTORY:
	2005.1122 Creat this file
	...
--------------------------------------------------------------------*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <locale.h>
#include "nucleus.h"
#include "ADSmx21_defs.h"
#include "drv_defs.h"
#include "drv_extr.h"
#include "console.h"
#include "main.h"
#include "net.h"

/*-----------define variables---------------------------------------*/
#define STACKSIZE 0x10000

NU_TASK TSK_1;
static char stack[2][STACKSIZE];
NU_TIMER cpu_timer;

TPARAM bootparam = {
20,"192.168.0.77","255.255.255.0","01-3e-54-aa-c4-10"
};
	
char  logo_string[] = \
//" ===================================================\n" 
"             ___            __                      \n" 
"            /   |   ____   / /__  __ _____          \n" 
"           / /| |  / __ \\ / // / / // ___/         \n" 
"          / ___ | / /_/ // // /_/ /(__  )           \n" 
"         /_/  |_|/ .___//_/ \\__,_//____/    :-)    \n"
"                /_/                                 \n" 
//"----------------------------------------------------\n"
//" ===================================================\n"
;
char  version_string[] = "Freescale MC9328MX21 - 266 MHz ";

unsigned int cpu_idle,cpuratio, cache;
int testflag;

/*-----------declare functions---------------------------------------*/
void test_TSK(UNSIGNED arc, void *arv);
int do_boot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);

void kpp_cb(int updown, int key)
{
	if (updown == 0){
		printf("key = 0x%04x is pressed.\n", key);
	}
	else if (updown == 1){
		printf("key = 0x%04x is releaseed.\n", key);
	}
}

void console_cb(int arg)
{
	;
}

void cpu_TIMER(UNSIGNED id)
{
	static unsigned int ratio=0;
	static unsigned int cnt=0;

	ratio += STC_Get_Record();
	cnt++;
	if (cnt == 128){
		ratio >>= 7;
		if (ratio >= cpu_idle) ratio = 0;
		else ratio = cpu_idle - ratio;
		cpuratio = ratio*100/cpu_idle;
		ratio = 0;
		cnt = 0;
	}
}

/*-------------------------------------------------------------------
FUNC NAME:
	Application_Initialize
DESCRIPTION:
	... 
ARGUMENTS:
	...
RETURN:
	...
--------------------------------------------------------------------*/
void Application_Initialize(void *first_available_memory)
{
	STATUS s;
	
	s = NU_Create_Task(&TSK_1, "test1", test_TSK, 0, NU_NULL, stack[0], STACKSIZE, 20, 2, NU_PREEMPT, NU_START);
	assert(s == NU_SUCCESS);

	memset(&cpu_timer,0,sizeof(NU_TIMER)); 
	s = NU_Create_Timer(&cpu_timer, "cpu", cpu_TIMER, 1, 5, 2, NU_DISABLE_TIMER);
	assert(s == NU_SUCCESS);

}

/*-------------------------------------------------------------------
FUNC NAME:
	test_TSK
DESCRIPTION:
	... 
ARGUMENTS:
	...
RETURN:
	...
--------------------------------------------------------------------*/
void test_TSK(UNSIGNED arc, void *arv)
{
	STATUS s;
	int i;

	setlocale( LC_ALL, "C" );

	drivers_init();
	NU_Sleep(10);
	cpu_idle = STC_Get_Record();
	if (cpu_idle > 0x1000){cache = 1;MAPIO|=0x4000;}
	else {cache = 0;MAPIO&=(~0x4000);}

	s = NU_Control_Timer(&cpu_timer, NU_ENABLE_TIMER);
	assert(s == NU_SUCCESS);

	console_init(console_cb);
	printf("%s\n", logo_string);
	printf("CPU: %s\n", version_string);
	printf("Flash: base - 0x%08x  length - 0x%08x\n", FLASH_BASE, FLASH_LENGTH);
	printf("Sdram: base - 0x%08x  length - 0x%08x\n", SDRAM_NOCACHE_BASE, SDRAM_SIZE);
	{
		char mac[6];
		int rev; 

		NetConvEther(mac, bootparam.macaddr);
		rev = eth_init(mac);
		if (rev != 0){
			printf( "CS8900:id - %04x  rev - %04x\n", 0x630e, rev);
			printf( "Physical Address: ");
			for (i = 0; i < 6; i++){
				printf("%02x", mac[i]);
				if (i != 5)
					mputs("-");
			}
			mputs("\n");
			NetOurIP = NetConvIP(bootparam.ipaddr);
			printf( "IP Address: ");
			print_IPaddr(NetOurIP);
			mputs( "\n");
			NetCopyEther(NetOurEther, mac);
		}
		else{
			printf( "Ethernet chip not found?!\n" );
		}

	}	
	tftp_stopserv();
	
	i = bootparam.bootdelay;
	printf("Boot system after %d seconds, press 'a' to quit",i);
	i *= 5;
	do{
		NU_Sleep(100);
		if (--i%5==0){
			clear_line();
			printf("Boot system after %d seconds, press 'a' to quit",i/5);
		}
	}while((active==0)&&(i>0));

	if (!active){	
		do_boot(NULL, 0, 0, NULL);
		while(1){NU_Sleep(500);};
	}
	clear_line();
//	mputs("\n");
	mputs(PROMPT);

	i = 0;
	while(1){
		eth_rx();
		NU_Sleep(1);
		if (++i == 125){
			MAPIO ^= 0x8000;
			i = 0;
		}
	}	
}


⌨️ 快捷键说明

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