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

📄 entry.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 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 AT91EB63 test                            */
/*                                                                             */
/* 1.0 04/09/98 JLV    : Creation                                              */
/* 2.1 29/01/02 PFi    : Clean up and new function added                       */
/*                     : USART , Serial EEPROM and SPI DataFlash test          */
/*                     : Boot Version 2.10                                     */
/*-----------------------------------------------------------------------------*/

#include "parts/m63200/lib_m63200.h"
#include "drivers/capture/capture.h"
#include "drivers/wait/wait.h"
#include "targets/eb63/eb63.h"


extern void BootFts ( void ) ;
extern int BootLoad ( void ) ;
extern void wake_up_handler (void) ;

/* Global Variable */
WaitDesc wait_desc = { &TC0_DESC, 0, 0, WAIT_DELAY, wake_up_handler } ;

typedef void    (type_pt_angel(u_int clock)) ;

/*-------------------------------------------------------------------------------*/
/* Function Name       : mcki_detect                                             */
/* Object              : Master Clock Frequency Detection                        */
/* Input Parameters    : None                                                    */
/* Output Parameters   : The Frequency in kHz                                    */
/* Functions called    : at91_capture_open, at91_capture_open, at91_capture_read */
/*-------------------------------------------------------------------------------*/
u_int mcki_detect ( void )
/* Begin */
{
    int period ;

    at91_capture_open ( &TC0_DESC, MODE_TIOA_PERIOD ) ;
    while ( at91_capture_get_status ( &TC0_DESC ) != TRUE ) ;
    period = at91_capture_read ( &TC0_DESC ) ;
    at91_capture_close ( &TC0_DESC ) ;

    if ( period > 15 )
        return ( MCKKHz ) ;
    if ( period > 7 )
        return ( MCKKHz >> 1 ) ;
    if ( period > 3 )
        return ( MCKKHz >> 2 ) ;
    if ( period > 1 )
        return ( MCKKHz >> 3 ) ;

    return ( MCKKHz >> 4 ) ;
}
/* End */

/*-------------------------------------------------------------------------------*/
/* 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 *)(0x1004000) ;

    //* -- Set up PIO
    at91_pio_open ( &PIOA_DESC, SW4_MASK, PIO_INPUT ) ;
    at91_pio_open ( &PIOB_DESC, (SW1_MASK|SW2_MASK|SW3_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 = mcki_detect () ;
    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 ( &PIOB_DESC ) & SW2_MASK) == 0 )
        {
            /* Light on all the leds */
            at91_pio_write ( &PIOB_DESC, LED_MASK, LED_ON  ) ;

            /* Expect S2 un-pressed */
            while (( at91_pio_read ( &PIOB_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 () ;
        }

        /* Light on the led 1 */
        at91_pio_write (&PIOB_DESC, LED1, LED_ON ) ;

        /* Enable USART0 Clock */
        at91_clock_open ( USART0_DESC.periph_id ) ;

        /* Branch Angel in Flash */
        pt_angel ( wait_desc.mcki_khz ) ;



}/* End */

/*-------------------------------------------------------------------------------*/
/* Function Name           : main                                                */
/* Object                  : Entry point of boot                                 */
/* Input Parameters        : None                                                */
/* Output Parameters       : None                                                */
/* Functions called        : BooFts, BootLoad                                    */
/*-------------------------------------------------------------------------------*/
int main ( void )
/* Begin */
{
 void (*next)(void);
   next =  (void (*)(void)) main_boot();
   (*next)();

}

⌨️ 快捷键说明

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