📄 main.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 "Emac.h"
#include <stdio.h>
#include <string.h>
//* Interrupt Handlers
extern void AT91F_ST_ASM_HANDLER(void);
//* function in init.c
extern void AT91F_DBGU_Printk(char *buffer);
//* 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++;
}
//*----------------------------------------------------------------------------
//* \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];
AT91F_DBGU_Printk("\n\n\r-I- ================ IP HEADER ======================\n\r");
sprintf(MsgBuffer, "\n\r IP Version = v.%d",pIpHeader->ip_hl_v & 0x0F);
AT91F_DBGU_Printk(MsgBuffer);
sprintf(MsgBuffer, "\n\r Header Length = %d",(pIpHeader->ip_hl_v & 0xF0) >> 2);
AT91F_DBGU_Printk(MsgBuffer);
sprintf(MsgBuffer, "\n\r Type of service = 0x%x",pIpHeader->ip_tos);
AT91F_DBGU_Printk(MsgBuffer);
sprintf(MsgBuffer, "\n\r Total IP Length = %d",(pIpHeader->ip_len) >> 8);
AT91F_DBGU_Printk(MsgBuffer);
sprintf(MsgBuffer, "\n\r ID = 0x%X",(pIpHeader->ip_id));
AT91F_DBGU_Printk(MsgBuffer);
sprintf(MsgBuffer, "\n\r Header Checksum = 0x%X",(pIpHeader->ip_sum));
AT91F_DBGU_Printk(MsgBuffer);
switch(pIpHeader->ip_p) {
case PROT_IP:
sprintf(MsgBuffer, "\n\r Protocol = %s","IP");
break;
case PROT_ICMP:
sprintf(MsgBuffer, "\n\r Protocol = %s","ICMP");
break;
default:
sprintf(MsgBuffer, "\n\r Protocol = 0x%X",pIpHeader->ip_p);
break;
}
AT91F_DBGU_Printk(MsgBuffer);
strncpy((char *)address, (const char *)(pIpHeader->ip_src), 4);
address[4] = 0;
sprintf(MsgBuffer, "\n\r IP Src Address = %d:%d:%d:%d",
pIpHeader->ip_src[0],
pIpHeader->ip_src[1],
pIpHeader->ip_src[2],
pIpHeader->ip_src[3]
);
AT91F_DBGU_Printk(MsgBuffer);
strncpy((char *)address, (const char *)pIpHeader->ip_dst, 4);
address[4] = 0;
sprintf(MsgBuffer, "\n\r IP Dest Address = %d:%d:%d:%d",
pIpHeader->ip_dst[0],
pIpHeader->ip_dst[1],
pIpHeader->ip_dst[2],
pIpHeader->ip_dst[3]
);
AT91F_DBGU_Printk(MsgBuffer);
}
//*----------------------------------------------------------------------------
//* \fn main
//* \brief
//*
//*----------------------------------------------------------------------------
int main()
{
AT91S_IPheader IpHeader;
int status;
AT91F_DBGU_Printk("\n\n\r-I- ======================================\n\r");
AT91F_DBGU_Printk("-I- AT91RM9200 EMAC Test\n\r");
AT91F_DBGU_Printk("-I- --------------------------------------\n\r");
//* 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)
{
sprintf(MsgBuffer, "Error EMAC init: 0x%x", status);
AT91F_DBGU_Printk(MsgBuffer);
while(1);
}
while(1)
if (AT91F_ProcessEmacPacket(&IpHeader) == AT91C_IPPACKET)
AT91F_DisplayIpPacket(&IpHeader);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -