📄 entry.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 : entry.c
//* Object : Main loop of AT91EB42 test
//*
//* 1.0 17/07/00 PF : Creation
//* 2.0 29/01/02 PFi : Clean up.
//* : Boot Version 1.02
//*-----------------------------------------------------------------------------
#include "parts/m42800/lib_m42800.h"
#include "drivers/capture/capture.h"
#include "drivers/wait/wait.h"
#include "targets/eb42/eb42.h"
#include "clock_switching_driver.h"
extern void BootFts ( void ) ;
extern u_int BootLoad ( void ) ;
extern void wake_up_handler ( void ) ;
extern int fmu ( void ) ;
extern void mck_clock_speed (short target_source, u_int frequency_multiplier, u_int prescaler) ;
#define PLL 0x2 //* low frequency oscillator output => MCK
#define SLOW_OSC 0x0 //* PLL output =MCK
#define MUL_x3 0x3
#define MUL_x2 0x2
#define NO_MUL 0x1
/* Global Variable */
WaitDesc wait_desc = { &TC0_DESC, 0, 0, WAIT_DELAY, wake_up_handler } ;
typedef void (type_pt_angel(u_int clock)) ;
//*-------------------------------------------------------------------------------
//* Function Name : BootEntry
//* Object : Entry point of boot
//* Input Parameters : None
//* Output Parameters : None
//* Functions called : at91_pio_open, at91_pio_write
//*-------------------------------------------------------------------------------
void * main_boot ( void )
//* Begin
{
u_int i ;
type_pt_angel *pt_angel ;
pt_angel = (type_pt_angel *)(0x1006000) ;
//* -- Set up PIO
at91_pio_open ( &PIOA_DESC, SW2_MASK, PIO_INPUT ) ;
at91_pio_open ( &PIOB_DESC, (SW1_MASK|SW3_MASK|SW4_MASK), PIO_INPUT ) ;
at91_pio_open ( &PIOB_DESC, LED_MASK, PIO_OUTPUT ) ;
at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF ) ;
//* Detect Master Clock
wait_desc.mcki_khz = 32768 ;
wait_desc.period = 50000 ;
//* Once a Shot on each led
for ( i=LED1 ; i <= LED8 ; i<<=1 )
{
at91_pio_write (&PIOB_DESC, i, LED_ON ) ;
at91_wait_open ( &wait_desc ) ;
at91_pio_write (&PIOB_DESC, i, LED_OFF ) ;
}
//* Light off all leds
at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF ) ;
//* If SW1 button pressed, Functional Test Software
if (( at91_pio_read( &PIOB_DESC ) & SW1_MASK ) == 0 )
{
//* Light on all the leds
at91_pio_write ( &PIOB_DESC, LED_MASK, LED_ON ) ;
//* Expect S1 un-pressed
while (( at91_pio_read (&PIOB_DESC ) & SW1_MASK) == 0 ) ;
//* Light off all the leds unless led 1
at91_pio_write ( &PIOB_DESC, (LED_MASK&~LED1), LED_OFF ) ;
BootFts() ;
} //* EndIf
//* If SW2 button pressed, Load in SRAM
if (( at91_pio_read ( &PIOA_DESC ) & SW2_MASK) == 0 )
{
//* Enable USART 1 & PIOB Clock
at91_clock_open (US1_ID | US0_ID) ;
at91_clock_open (PIOB_ID) ;
//* Light on all the leds
at91_pio_write ( &PIOB_DESC, LED_MASK, LED_ON ) ;
//* Expect S2 un-pressed
while (( at91_pio_read ( &PIOA_DESC ) & SW2_MASK) == 0 ) ;
//* Light off all the leds unless led 2
at91_pio_write ( &PIOB_DESC, (LED_MASK&~LED2), LED_OFF ) ;
return (void *)BootLoad () ;
//* disable USART 1
at91_clock_close (US1_ID ) ;
at91_pio_write ( &PIOB_DESC, LED2, LED_OFF ) ;
}//* EndIf
//* ----------------------------------------------
//* If SW3 button pressed, Load the Flash_uploader
//* ----------------------------------------------
if (( at91_pio_read( &PIOB_DESC ) & SW3_MASK ) == 0 )
{
//* Light on all the leds
at91_pio_write ( &PIOB_DESC, LED_MASK, LED_ON ) ;
//* Expect S3 un-pressed
while (( at91_pio_read (&PIOB_DESC ) & SW3_MASK) == 0 ) ;
//* Light off all the leds unless led 3
at91_pio_write ( &PIOB_DESC, (LED_MASK&~LED3), LED_OFF ) ;
fmu();
} //* EndIf
//* -------------------------------------
//* If SW4 button pressed, ShutDown Mode
//* -------------------------------------
if (( at91_pio_read( &PIOB_DESC ) & SW4_MASK ) == 0 )
{
//* Light on all the leds
at91_pio_write ( &PIOB_DESC, LED_MASK, LED_ON ) ;
//* Expect S3 un-pressed
while (( at91_pio_read (&PIOB_DESC ) & SW4_MASK) == 0 ) ;
// Turn off all peripheral clocks except PIOB and TC0
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( PIOB_ID ) ;
at91_clock_open ( TC0_ID ) ;
//* Light off all the leds unless led 3
at91_pio_write ( &PIOB_DESC, (LED_MASK&~LED4), LED_OFF ) ;
//* Switch the Master Clock to 32,768KHz (Slow Clock)
mck_clock_speed ( SLOW_OSC, NO_MUL, PMC_PRES_NONE ) ;
for (;;)
{
at91_pio_write ( &PIOB_DESC, (LED4), LED_OFF ) ;
wait_desc.period = 5000 ;
at91_wait_open ( &wait_desc ) ;
at91_wait_open ( &wait_desc ) ;
at91_pio_write ( &PIOB_DESC, (LED4), LED_ON ) ;
at91_pio_write ( &PIOB_DESC, (LED4), LED_ON ) ;
if (( at91_pio_read( &PIOB_DESC ) & SW4_MASK ) == 0 )
{
//* Switch the Master Clock to 32,768MHz
mck_clock_speed ( PLL, 1000, PMC_PRES_NONE) ;
//* Re-enable USART0 Clock
at91_clock_open ( US0_ID ) ;
//* Branch Angel in Flash
pt_angel ( wait_desc.mcki_khz ) ;
}
}
} //* EndIf
//* Light on the led 1
at91_pio_write (&PIOB_DESC, LED1, LED_ON ) ;
//* Enable USART0 Clock
at91_clock_open ( US0_ID ) ;
//* Branch Angel in Flash
pt_angel ( wait_desc.mcki_khz ) ;
//* End
}
/*-------------------------------------------------------------------------------*/
/* Function Name : BootEntry */
/* Object : Entry point of boot */
/* Input Parameters : None */
/* Output Parameters : None */
/* Functions called : at91_pio_open, at91_pio_write */
/*-------------------------------------------------------------------------------*/
int main ( void )
/* Begin */
{
void (*next)(void);
next = (void (*)(void)) main_boot();
(*next)();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -