📄 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 AT91EB55 test
//*
//* 1.0 17/07/00 PF : Creation
//* 2.0 29/01/02 PFi : Clean up.
//* : Boot Version 2.20
//*--------------------------------------------------------------------------------------
#include "parts/m55800/lib_m55800.h"
#include "drivers/capture/capture.h"
#include "drivers/time_rtc/time_rtc.h"
#include "drivers/wait/wait.h"
#include "targets/eb55/eb55.h"
#include "rtc_utility.h"
extern void BootFts ( void ) ;
extern u_int BootLoad ( void ) ;
extern void wake_up_handler ( void ) ;
extern int fmu ( void ) ;
TimeDescRtc rtc;
/* 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 ;
int temp_var = 0 ;
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 = 32000 ;
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 ( US0_ID | US1_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, Board enters in 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 S4 un-pressed
while (( at91_pio_read (&PIOB_DESC ) & SW4_MASK) == 0 ) ;
//* Light off all the leds unless led 4
at91_pio_write ( &PIOB_DESC, (LED_MASK&~LED4), LED_OFF ) ;
while (( at91_pio_read (&PIOB_DESC ) & SW4_MASK) == SW4_MASK ) ;
//* INIT RTC VALUES
rtc.rtc_desc=&RTC_DESC;
at91_time_rtc_open(&rtc);
//* REAL TIME CONTROLLER READING
at91_time_rtc_read(&rtc);
//* ADD THE WAITING DELAY TIME FOR THE ALARM SETTING
temp_var = elapsed_time () + WAITING_TIME;
//* SET THE ALARM EVENT IN THE RTC REGISTERS
set_alarm (temp_var);
/* Set the Alarm Event Mode for the time */
rtc.mode_al_time = ((rtc.alarm_int.ampm <<22) | RTC_HOUR_ALRM_EN | RTC_MINUTE_ALRM_EN | RTC_SECOND_ALRM_EN);
/* Set the Alarm Event Mode for the calandar */
rtc.mode_al_cal = (RTC_MONTH_ALRM_EN | RTC_DATE_ALRM_EN) ;
/* Write the alarm Date and Clock in AT91 RTC registers */
at91_time_rtc_set_time_alarm (&rtc);
at91_time_rtc_set_cal_alarm (&rtc);
//* POWER SUPPLY SHUTDOWN
/* Configure the Wake-up and shutdown mode */
at91_power_mode (APMC_PMR_MODE); /* apmc_pmr register */
/* Start the software shutdown */
at91_trig_cmd (POWER_SHUTDOWN);
} //* 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 + -