📄 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 : JPP 13/Jan/2003
//*
//*----------------------------------------------------------------------------
//* Include Standard LIB files
#include "eb55.h"
#include "clock_switching.h"
#define INTERNAL_DATA_BASE (0x200)
#define INTERNAL_PGM_BASE (INTERNAL_DATA_BASE+4)
//* --------------------------- Global data definition -------------------------
volatile unsigned int emi_test; //* test definition
unsigned int mck; //* Actual Master Clock
unsigned int *ptEmiFlag; //* Pointer on data for stop loop
extern unsigned int emi_flag;
//* ---------------------- External Function Prototype ------------------------
extern void asm_int(unsigned int *ptEmiFlag); //* Internal Loop
extern void asm_ext (unsigned int *ptEmiFlag); //* External Loop
extern void Usart_init ( void ); //* Usat initialisation
extern unsigned int __ghs_eofn_asm_int[]; //* size of program Internal Loop
//*----------------------------------------------------------------------------
//* Function Name : SetPgmInternal
//* Object : Copy the code extrenal area in internal memory
//* And set the global address
//* Input Parameters : none
//* Output Parameters : Internal address function
//*----------------------------------------------------------------------------
unsigned int * SetPgmInternal( void )
//* Begin
{
unsigned int * External;
unsigned int * InternalRam;
unsigned int i,j;
// Set Internal Memory code
ptEmiFlag = (unsigned int *)INTERNAL_DATA_BASE;
// Set Internal Memory code
InternalRam = (unsigned int *) INTERNAL_PGM_BASE;
External =(unsigned int *) &asm_int;
// Size of function
j= __ghs_eofn_asm_int -External;
// Copy from external to internal
for (i=0;i <j; i++ )
{
*InternalRam++=*External++;
}
return (unsigned int *) INTERNAL_PGM_BASE;
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main interrupt function
//* Input Parameters : none
//* Output Parameters : TRUE
//*----------------------------------------------------------------------------
void main( void )
//* Begin
{
void (*asmInternal)(unsigned int *ptEmiFlag); // Function declaration
// Set Internal Memory code
asmInternal = (void (*)(unsigned int *)) SetPgmInternal();
// get the mck
mck =MCK;
// Set the PIO
// First, enable the clock of the PIOB and set the LEDs in output
AT91F_APMC_EnablePeriphClock ( AT91C_BASE_APMC, 1<<AT91C_ID_PIOB ) ;
AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK ) ;
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED_MASK) ;
AT91F_APMC_DisablePeriphClock( AT91C_BASE_APMC, 1<<AT91C_ID_PIOB ) ;
//* Use divided by 4 = 16/4 = > 4Mhzs
set_Prescaler(APMC_PRES_DIV4);
mck_clock_speed (TO_PLL_OUTPUT, 32 /(EXTARNAL_CLOCK_Mhz/PRESCALER_VAL) ) ;
//* Usart Initialisation
Usart_init();
//* Start the target application
emi_test= 1;
//* Background measurement
while( 1==1) {
*ptEmiFlag=0;
if (emi_test == 0) { // works in external
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED_MASK ) ;
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED1) ;
asm_ext(ptEmiFlag);
}
if (emi_test == 1){ // works in internal by SetPgmInternal
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED_MASK ) ;
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED2) ;
(*asmInternal)(ptEmiFlag);
}
}
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -