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

📄 eb63_consume.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           : eb63_consume.c
//* Object              : AT91M63200 - Consumption measurement
//* Exported resources  : main
//* Imported resources  : ExecuteTest
//*
//* 1.0 99/01/08 JLV  : Creation
//* 2.0 00/03/04 JCZ  : Clean up
//*-----------------------------------------------------------------------------


/*----- Files to be included Definition -----*/

#include <stdio.h>
#include <stdlib.h>
#include "parts\m63200\lib_m63200.h"
#include "targets\eb63\eb63.h"

/*----- Types and Constants Definition -----*/

#define COMPO_ID            "AT91M63200"
#define TARGET_ID           "EB63"


/*----- Imported Resources Definition -----*/
extern void ExecuteArmTest (void);
extern void ExecuteThumbTest (void);
extern void ExecuteTest (u_int *address, u_int arm);



//*-----------------------------------------------------------------------------
//* Function Name       : PCA_choice
//* Object              : Peripheral clocks activated or not choice
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : none
//*-----------------------------------------------------------------------------
void PCA_choice ( void )
//* Begin
{
    int     choice ;

    printf ( "\n  1 - All peripheral clocks activated\n" ) ;
    printf ( "  2 - All peripheral clocks deactivated (without PIOB)\n" ) ;	
    printf ( "  3 - PIOA clock activated\n" ) ;
    printf ( "  4 - Timer Counter Block 0 clock activated\n" ) ;
    printf ( "  5 - Timer Counter Channel 0 clock activated\n" ) ;
    printf ( "  6 - USART 0 clock activated\n" ) ;
    printf ( "  7 - SPI clock activated\n" ) ;
    printf ( "\n   Enter your choice : " ) ;
    scanf ("%d", &choice ) ;
    
	switch ( choice )
    {
        case 1 :

            at91_clock_set_mode ( PS_ALL_PERIPH_ACTIVE ) ;

            break ;

        case 2 :

            at91_clock_close ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_close ( SPI_ID ) ;
            at91_clock_close ( TC0_ID ) ;
            at91_clock_close ( TC1_ID ) ;
            at91_clock_close ( TC2_ID ) ;
            at91_clock_close ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_close ( PIOA_ID ) ;


            break ;


        case 3 :

            at91_clock_close ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_close ( SPI_ID ) ;
            at91_clock_close ( TC0_ID ) ;
            at91_clock_close ( TC1_ID ) ;
            at91_clock_close ( TC2_ID ) ;
            at91_clock_close ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_open  ( PIOA_ID ) ;

            break ;

        case 4 :

            at91_clock_close ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_close ( SPI_ID ) ;
            at91_clock_open  ( TC0_ID ) ;
            at91_clock_open  ( TC1_ID ) ;
            at91_clock_open  ( TC2_ID ) ;
            at91_clock_open  ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_close ( PIOA_ID ) ;

            break ;

        case 5 :

            at91_clock_close ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_close ( SPI_ID ) ;
            at91_clock_open  ( TC0_ID ) ;
            at91_clock_close ( TC1_ID ) ;
            at91_clock_close ( TC2_ID ) ;
            at91_clock_close ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_close ( PIOA_ID ) ;

            break ;

        case 6 :

            at91_clock_open  ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_close ( SPI_ID ) ;
            at91_clock_close ( TC0_ID ) ;
            at91_clock_close ( TC1_ID ) ;
            at91_clock_close ( TC2_ID ) ;
            at91_clock_close ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_close ( PIOA_ID ) ;

            break ;

        case 7 :

            at91_clock_close ( US0_ID ) ;
            at91_clock_close ( US1_ID ) ;
            at91_clock_close ( US2_ID ) ;
            at91_clock_open  ( SPI_ID ) ;
            at91_clock_close ( TC0_ID ) ;
            at91_clock_close ( TC1_ID ) ;
            at91_clock_close ( TC2_ID ) ;
            at91_clock_close ( TC3_ID ) ;
            at91_clock_close ( TC4_ID ) ;
            at91_clock_close ( TC5_ID ) ;
            at91_clock_close ( PIOA_ID ) ;

            break ;

        default :

            break ;
    }
}

//*-----------------------------------------------------------------------------
//* Function Name       : at91_pio_irq_handler
//* Object              : PIO Interrupt handler
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : None
//*-----------------------------------------------------------------------------
__irq void at91_pio_irq_handler ( void )
//* Begin
{
    u_int data ;
	int i ;
	
	StructAIC *aic_pt = AIC_BASE ;
	StructPIO *piob_pt = PIOB_BASE ;

    data = piob_pt->PIO_ISR ;
	data = piob_pt->PIO_ISR ;
	for ( i = 0; i<8; i++)
	aic_pt->AIC_EOICR = 0xFFFFFFFF ;
}


//*-----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : AT91M63200 Consume Test
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : None
//*-----------------------------------------------------------------------------
int main( void )
//* Begin
{
    int		nws = 0 ;
    int		resp = 0 ;
	
    StructEBI   *ebi_pt = EBI_BASE ;
	
    at91_clock_open ( PIOA_ID ) ;
    at91_clock_open ( PIOB_ID ) ;


    //* -- Set up PIOB
	at91_pio_open ( &PIOB_DESC, SW1_MASK, PIO_INPUT ) ;

    //* Set up MPI interface
    ebi_pt->EBI_CSR[2] = 0x03003021 ;


    //* Enable the PIO interrupt in interrupt controller
    at91_irq_open ( PIOB_ID, 0, AIC_SRCTYPE_INT_LEVEL_SENSITIVE, at91_pio_irq_handler ) ;

    //* Enable the PIO interrupt on PB4/SW2
    at91_pio_open ( &PIOB_DESC, SW2_MASK, ( PIO_INPUT | PIO_INPUT_IRQ_ON ) ) ;
	
    
	//* Repeat for ever
    for (;;)
    {
        //* Display Utility Header
        printf ( "\n**** %s Consumption Measurement Utility on %s board ****\n", COMPO_ID, TARGET_ID ) ;

        //* Choice menu
        printf ( "\n  1 - Idle mode\n" ) ;
        printf ( "  2 - Internal memory working mode in ARM code\n" ) ;
        printf ( "  3 - Internal memory working mode in Thumb code\n" ) ;
        printf ( "  4 - External memory working mode in ARM code\n" ) ;
        printf ( "  5 - External memory working mode in Thumb code\n" ) ;

        printf ( "\n   Enter your choice : " ) ;
		scanf ("%d", &resp ) ;

        switch ( resp )
        {
            case 1 :

				printf ( "\n\n\n*** Idle mode ***\n" ) ;
				PCA_choice ( ) ;
				printf ( "\n\n*** To return to the main menu, press the SW2 push button  ***\n" ) ;
                at91_clock_set_mode ( PS_MODE_IDLE ) ;
				break ;

            case 2 :

                printf ( "\n\n\n*** Internal memory working mode in ARM code ***\n" ) ;
                PCA_choice ( ) ;
				printf ( "\n\n*** To return to the main menu, press the SW1 push button ***\n" ) ;                
				ExecuteTest ( (u_int *)0x100, 0 ) ;

                break ;

            case 3 :

                printf ( "\n\n\n*** Internal memory working mode in Thumb code ***\n" ) ;
                PCA_choice ( ) ;
				printf ( "\n\n*** To return to the main menu, press the SW1 push button  ***\n" ) ;				
                ExecuteTest ( (u_int *)0x100, 1 ) ;

                break ;

            case 4 :

                do
                {
                    printf ( "\n\n   Enter the wait states number [0..8] : " ) ;
                    scanf ( "%d", &nws ) ;
                }
                while ( ( nws < 0 ) || ( nws > 8 ) ) ;

                if ( nws == 0 )
                {
                    ebi_pt->EBI_MCR |= EBI_DRP_EARLY ;
                    ebi_pt->EBI_CSR[1] &= ~EBI_WSE ;
                }
                else
                {
                    ebi_pt->EBI_CSR[1] &= ~EBI_NWS ;
                    ebi_pt->EBI_CSR[1] |= ( EBI_WSE | (( nws - 1 ) << 2 ) ) ;
                }

                printf ( "\n\n\n*** External memory %d wait states working mode in ARM code ***\n", nws ) ;
                PCA_choice ( ) ;
				printf ( "\n\n*** To return to the main menu, press the SW1 push button  ***\n" ) ;				
                ExecuteTest ( (u_int *)0x2020000, 0 ) ;
                if ( nws == 0 )
                {
                    ebi_pt->EBI_CSR[1] |= EBI_WSE ;
                    ebi_pt->EBI_MCR &= ~EBI_DRP_EARLY ;
                }

                break ;

            case 5 :

                do
                {
                    printf ( "\n\n   Enter the wait states number [0..8] : " ) ;
                    scanf ( "%d", &nws ) ;
                }
                while ( ( nws < 0 ) || ( nws > 8 ) ) ;

                if ( nws == 0 )
                {
                    ebi_pt->EBI_MCR |= EBI_DRP_EARLY ;
                    ebi_pt->EBI_CSR[1] &= ~EBI_WSE ;
                }
                else
                {
                    ebi_pt->EBI_CSR[1] &= ~nws ;
                    ebi_pt->EBI_CSR[1] |= ( EBI_WSE | (( nws - 1 ) << 2 ) ) ;
                }

                printf ( "\n\n\n*** External memory %d wait states working mode in Thumb code ***\n", nws ) ;
                PCA_choice ( ) ;
				printf ( "\n\n*** To return to the main menu, press the SW1 push button  ***\n" ) ;				
                ExecuteTest ( (u_int *)0x2020000, 1 ) ;
                if ( nws == 0 )
                {
                    ebi_pt->EBI_CSR[1] |= EBI_WSE ;
                    ebi_pt->EBI_MCR &= ~EBI_DRP_EARLY ;
                }

                break ;

            default :

                break ;
        }

    }
    return(0);
}

⌨️ 快捷键说明

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