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

📄 main.c

📁 at91rm9200 mac control源码
💻 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>
//#include "main.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;
unsigned int tc = 0;
unsigned int test = 0;
unsigned int count = 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

	CheckSound( );
	
	StStatus = *(AT91C_ST_SR);
	StTick++;	
	tc++;
	test++;
	if(tc==20)  CpuLED_Off(); 
	if(tc==40) { CpuLED_On(); ;tc=0;}
//		putch('I');
	//AT91C_BASE_PMC->PMC_SCER=0xF00;
}


//*----------------------------------------------------------------------------
//* \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;
	
	puts("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);	//退出中断前必须应答
}


static void InitPio(void)
{	
	// VSYNC,HREF,PCLK INPUT,FD0~FD7 INPUT
	 
	AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, ((unsigned int) 1 << AT91C_ID_PIOB));
	AT91F_PIO_CfgInput(AT91C_BASE_PIOC, AT91C_PIO_PC12|AT91C_PIO_PC13|AT91C_PIO_PC14);
	AT91F_PIO_CfgInput(AT91C_BASE_PIOB, AT91C_PIO_PB0|AT91C_PIO_PB1|AT91C_PIO_PB2|AT91C_PIO_PB3|AT91C_PIO_PB4|AT91C_PIO_PB5|AT91C_PIO_PB6|AT91C_PIO_PB7);
	AT91F_PIO_CfgInput(AT91C_BASE_PIOB, AT91C_PIO_PB10|AT91C_PIO_PB23|AT91C_PIO_PB24|AT91C_PIO_PB27);
	AT91F_PIO_CfgPullup(AT91C_BASE_PIOC,0xFFFFFFFF);
	AT91F_PIO_CfgPullup(AT91C_BASE_PIOB,0xFFFFFFFF);
	// SDA,SCL  OUTPUT
	AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, ((unsigned int) 1 << AT91C_ID_PIOA));
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA25|AT91C_PIO_PA26);	
	//led	
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, AT91C_PIO_PB11|AT91C_PIO_PB25|AT91C_PIO_PB26);
	AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, AT91C_PIO_PB11|AT91C_PIO_PB25|AT91C_PIO_PB26);
	//key
//	AT91F_PIO_CfgInput(AT91C_BASE_PIOB, AT91C_PIO_PB6|AT91C_PIO_PB7|AT91C_PIO_PB8|AT91C_PIO_PB9);
	//buzzer
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
//	AT91F_PIO_SetOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);	
//	delay(20);		
	AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
	//PCK1 ( cmos CLOCK)  enable
	AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA, 0, 0x10);
	AT91C_BASE_PMC->PMC_PCKR[1]=0xE;
	AT91C_BASE_PMC->PMC_SCER=0xF00;
	//  IIS  bus config
	//AT91F_PIO_CfgInput(AT91C_BASE_PIOB, AT91C_PIO_PB27);
	
	}	
//*----------------------------------------------------------------------------
//* \fn    main
//* \brief 
//* 
//*----------------------------------------------------------------------------
int main()
{
	AT91S_IPheader IpHeader;
	int status;
	int *temp;
	
	//MMU_Init();
	//将IRQ入口地址(0x18)的指令改为 ldr, pc, [pc, #-&F20](本程序所用的中断处理方式)
	AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, AT91C_AIC_BRANCH_OPCODE);

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

	//* System Timer initialization
//	AT91F_ST_SetPeriodInterval(AT91C_BASE_ST, AT91C_ST_PITS);
	AT91F_ST_SetPeriodInterval(AT91C_BASE_ST, 25);
	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);
	
	initrs232();
	//InitializeCMOS();
	InitializeMBF();
	
//	while(1) InitializeMBF();
	puts("wait Int end.kk..\n");	//modified by hzh
	
	 
	/********************   Test FOC568  by kim *******************/ 
	while(0)
	{	
	  if (test<80)  AT91F_PIO_SetOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
	  if (test>80)	AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
	  if (test>1200) {
	  				test=0;
	  				count++;
	  				printf("count=%d\n", count);
	  				}
	  }
	 Sound_OK();
	 CpuLED_Off(); 
	 readIIC();
	//detectFinger();
	 while(1)	RS232BCommandProc();
	 
	do {
		status = AT91F_EmacEntry();
	}while(status);

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

⌨️ 快捷键说明

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