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

📄 cstartup_epa.c

📁 包括EPA协议栈
💻 C
字号:
//- File name	: CStartup.c
//- Author		: Sunpan
//- Date		: 2006-3
//- Function	: Define execution functions
//-				: Init EBI, AIC... & copy vectors
//-				: & copy necessary data from flash/ram to ram
//- Remark		: For ADS 1.2 and AXD
//- Attention	:
//- Modify		:
//-


#include "at91r40008.h"
#include "eb40a.h"
#include "lib_AT91R40008.H"

//------------------------------------------------------------------------------
//- Part1. Vectoring Execution functions
//------------------------------------------------------------------------------

void SoftReset(void)
{
}
void UndefHandler(void)
{
}
void SWIHandler(void)
{
}
void PrefetchAbortHandler(void)
{
}
void DataAbortHandler(void)
{
}
void AT91F_Default_FIQ_handler(void)
{
}
void AT91F_Default_IRQ_handler(void)
{
}
void AT91F_Spurious_handler(void)
{
}

//------------------------------------------------------------------------------
//- Part2. Init EBI, AIC...
//------------------------------------------------------------------------------

//- Set up EBI value
//- After reset, All EBI register are setted at the default value.
//- The new value will be effective only after the remap command.

void AT91F_Init_EBI(void)
{
	AT91PS_EBI pEbi;

	pEbi = AT91C_BASE_EBI;

	pEbi->EBI_CSR[0] = EBI_CSR_0;
	pEbi->EBI_CSR[1] = EBI_CSR_1;
	pEbi->EBI_CSR[2] = EBI_CSR_2;
	pEbi->EBI_CSR[3] = EBI_CSR_3;
	pEbi->EBI_CSR[4] = EBI_CSR_4;
	pEbi->EBI_CSR[5] = EBI_CSR_5;
	pEbi->EBI_CSR[6] = EBI_CSR_6;
	pEbi->EBI_CSR[7] = EBI_CSR_7;
	// 6 memory regions, standard read
	pEbi->EBI_MCR =	6;
}

//- Set up EBI value
//- Normally, the code is executed only if a reset has been actually performed.
//- So, the AIC initialization resumes at setting up the default vectors.
void AT91F_Init_AIC(void)
{
	int i;
	AT91PS_AIC pAic;

	// Load System pAic Base address
	pAic = AT91C_BASE_AIC;
	// Mask All interrupt
	pAic->AIC_IDCR = 0xFFFFFFFF;
	// Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ
	for (i = 0; i < 8; i ++){
		AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
	}
	// Set up the default interrupts handler vectors
	pAic->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler;
	for (i = 1;i < 31; i ++){
		pAic->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler;
	}
	pAic->AIC_SPU = (int) AT91F_Spurious_handler;
}

//------------------------------------------------------------------------------
//- Part3. Copy necessary data from flash/ram to ram
//------------------------------------------------------------------------------

void AT91F_CopyCode2Ram(void)
{
	int i;
	unsigned int * p_ram = (unsigned int *)0x00300000;		// START_RAM_BASE
	//unsigned int * p_ram = (unsigned int *)0x00000000;		// START_RAM_BASE
	unsigned int * p_flash = (unsigned int *)0x00000000;	// START_FLASH_BASE;

	// Copy all the program to ram, MAX LENGTH == RAM_SIZE
	for(i = 0; i < RAM_SIZE / 4; i++){			// /4 byte->word
		*(p_ram ++) = *(p_flash ++);
	}
}

//------------------------------------------------------------------------------
//- Part4. Copy vector from flash/ram to ram
//------------------------------------------------------------------------------

AT91_REG * AT91F_CopyVector2Ram(unsigned int * Vector, unsigned int * InternalRam)
{
	int i;
	AT91PS_EBI pEbi;

	pEbi = AT91C_BASE_EBI;
	// Copy the ARM exception vectors and indirect table (again:-))
	for(i = 0; i < (8+5); i++ ){
	   *(InternalRam ++) = *(Vector ++);
	}

	return (&pEbi->EBI_RCR); 
}

void config_led(void)
{
	// First, enable the clock of the PIOB
    AT91F_PS_EnablePeriphClock (AT91C_BASE_PS, 1<<AT91C_ID_PIO) ;

    // define led at PIO output
    AT91F_PIO_CfgOutput (AT91C_BASE_PIO, LED_MASK);

    // Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
    AT91F_PIO_SetOutput(AT91C_BASE_PIO, LED_MASK);
}

void led_on(void)
{
	int i;
	/* set LED */
	AT91F_PIO_ClearOutput (AT91C_BASE_PIO, LED1);

	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
}

void led_off(void)
{
	int i;
	/* clear LED */
	AT91F_PIO_SetOutput (AT91C_BASE_PIO, LED1) ;

	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
	for(i = 0x5000; i>0; i--){;}
}

⌨️ 快捷键说明

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