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

📄 main.c

📁 针对华清远见的FS9200(其内核为at91rm9200)的一个emacs程序
💻 C
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : main.c
//* Object              : main application written in C
//* Creation            : Hi   11/18/2002
//*
//*----------------------------------------------------------------------------
#include "AT91RM9200.h"
#include "lib_AT91RM9200.h"
#include "config.h"
#include "utils.h"
#include "console.h"
#include "Emac.h"
//#include <stdio.h>
//#include <string.h>


//* Interrupt Handlers
extern void AT91F_ST_ASM_HANDLER(void);
//* functions in Emac.c
extern int AT91F_EmacEntry(void);
extern int AT91F_ProcessEmacPacket(AT91PS_IPheader pHeader);

//* Message buffer
char MsgBuffer[256];

//* system timer counter
unsigned int StTick = 0;


//*----------------------------------------------------------------------------
//* \fn    AT91F_GetTickCount
//* \brief This function returns the value of the system timer
//* This function is for demonstration purpose only
//*----------------------------------------------------------------------------
unsigned int AT91F_GetTickCount(void)
{
	return(StTick);
}


//*----------------------------------------------------------------------------
//* \fn    AT91F_ST_HANDLER
//* \brief This function is invoked by main
//* This function is for demonstration purpose only
//*----------------------------------------------------------------------------
void AT91F_ST_HANDLER(void)
{
	volatile int StStatus;
	// Read the system timer status register
	StStatus = *(AT91C_ST_SR);
	StTick++;
//	if(!(StTick&0xff))
//		putch('I');
}


//*----------------------------------------------------------------------------
//* \fn    AT91F_DisplayIpPacket
//* \brief This function is invoked by main
//* This function is for demonstration purpose only
//*----------------------------------------------------------------------------
void AT91F_DisplayIpPacket(AT91PS_IPheader pIpHeader)
{
char address[6];

	puts("\n-I- ================ IP HEADER ======================\n");
	printf("\n IP Version        = v.%d", pIpHeader->ip_hl_v & 0x0F);
	printf("\n Header Length     = %d",(pIpHeader->ip_hl_v & 0xF0) >> 2);
	printf("\n Type of service   = 0x%x",pIpHeader->ip_tos);
	printf("\n Total IP Length   = %d",(pIpHeader->ip_len) >> 8);
	printf("\n ID                = 0x%X",(pIpHeader->ip_id));
	printf("\n Header Checksum   = 0x%X",(pIpHeader->ip_sum));

	switch(pIpHeader->ip_p) {
		case PROT_IP:
			printf("\n Protocol          = %s","IP");
			break;
	
		case PROT_ICMP:
			printf("\n Protocol          = %s","ICMP");
			break;
		default:
			printf("\n Protocol          = 0x%X",pIpHeader->ip_p);
			break;
	}

	memcpy((char *)address, (char *)(pIpHeader->ip_src), 4);
	address[4] = 0;

	printf("\n IP Src Address    = %d:%d:%d:%d", 
		                                         pIpHeader->ip_src[0], 
	                                             pIpHeader->ip_src[1],
	                                             pIpHeader->ip_src[2],
	                                             pIpHeader->ip_src[3]
	);

	memcpy((char *)address, (char *)pIpHeader->ip_dst, 4);
	address[4] = 0;

	printf("\n IP Dest Address   = %d:%d:%d:%d",
		                                         pIpHeader->ip_dst[0], 
	                                             pIpHeader->ip_dst[1],
	                                             pIpHeader->ip_dst[2],
	                                             pIpHeader->ip_dst[3]
	);

}

void __irq irq_handler(void)	//added by hzh
{	
	void (*svr)(void);
	AT91PS_AIC ptr = AT91C_BASE_AIC;
	U32 i;
//	U8 irq_idx;

//取得中断入口地址可用AIC_IVR或用AIC_ISR作索引得到AIC_SVR数组中的地址
	i = ptr->AIC_IVR;		//read AIC_IVR
//	irq_idx = ptr->AIC_ISR&0x1f;
//边沿触发中断必须以此清中断
//	AT91F_AIC_ClearIt(AT91C_BASE_AIC, irq_idx);	

// Write in the IVR to support Protect Mode
// No effect in Normal Mode
// De-assert the NIRQ and clear the source in Protect Mode	
	ptr->AIC_IVR = (AT91_REG)ptr;
	
//	putch("I");
//	printf("%x,%x,%x\n", irq_idx, ptr->AIC_IPR, ptr->AIC_CISR);

	svr = (void (*)(void))i;//ptr->AIC_SVR[irq_idx];
	(*svr)();
	AT91F_AIC_AcknowledgeIt(ptr);	//退出中断前必须应答
}

//*----------------------------------------------------------------------------
//* \fn    main
//* \brief 
//* 
//*----------------------------------------------------------------------------
int main()
{
	AT91S_IPheader IpHeader;
	int status;

	//将IRQ入口地址(0x18)的指令改为 ldr, pc, [pc, #-&F20](本程序所用的中断处理方式)
	AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, AT91C_AIC_BRANCH_OPCODE);

	puts("\n-I- ======================================\n");
	puts("-I- AT91RM9200 EMAC Test\n\r");
	puts("-I- --------------------------------------\n");

	//* System Timer initialization
	AT91F_ST_SetPeriodInterval(AT91C_BASE_ST, AT91C_ST_PITS);
	AT91F_ST_EnableIt(AT91C_BASE_ST, AT91C_ST_PITS);
	AT91F_AIC_ConfigureIt (
							AT91C_BASE_AIC,                        // AIC base address
							AT91C_ID_SYS,                          // System peripheral ID
							AT91C_AIC_PRIOR_HIGHEST,               // Max priority
							AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE,   // Level sensitive
							AT91F_ST_ASM_HANDLER );						
	//* Enable ST interrupt
	AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);

	//* Initialize AT91RM9200 EMAC
/*	status = AT91F_EmacEntry();
	if (status)
	{
		printf("Error EMAC init: 0x%x", status);
		while(1);
	}*/
//	printf("...y = %d, Y = %d, n = %d, N = %d\n", 'y', 'Y', 'n', 'N');
	puts("wait for link...\n");	//modified by hzh
	do {
		status = AT91F_EmacEntry();
	}while(status);

	while(1)
		if (AT91F_ProcessEmacPacket(&IpHeader) == AT91C_IPPACKET)
			AT91F_DisplayIpPacket(&IpHeader);
}

⌨️ 快捷键说明

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