📄 eb40a_consume.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 : eb40a_consume.c
//* Object : AT91R40008 Consumption measurement
//* Exported resources : main
//* Imported resources : ExecuteTest
//*
//* 1.0 06/08/01 PF : Creation
//*
//*-----------------------------------------------------------------------------
/*----- Files to be included Definition -----*/
#include <stdio.h>
#include <stdlib.h>
#include "parts/r40008/lib_r40008.h"
#include "targets/eb40a/eb40a.h"
#define CHIP_ID "AT91R40008"
#define TARGET_ID "EB40A"
/*----- Types and Constants Definition -----*/
#define PIO_PIN_AS_OUTPUT 0x00BF6DF8 //(P0|P7|P8|P10|P11|P13|P14|P20|P21)
#define PIO_PIN_AS_INPUT 0x01409206 //(P1|P2|P9|P12|P15|P22)
#define ARM_MODE 0x0
#define THUMB_MODE 0x1
/*----- Imported Resources Definition -----*/
extern void ExecuteArmTest (void);
extern void ExecuteThumbTest (void);
extern void ExecuteTest (u_int *address, u_int arm);
//* Assembler Interrupt
extern void ext_irq_asm_handler ( void ) ;
//*-----------------------------------------------------------------------------
//* Function Name : PCA_choice
//* Object : Peripheral clocks activated or not choice
//* Input Parameters : string (menu content), integer pointer
//* Output Parameters : none
//* Functions called : none
//*-----------------------------------------------------------------------------
void PCA_choice ( void )
//* Begin
{
int choice ;
printf ( "\n\n 1 - All peripheral clocks activated\n" ) ;
printf ( " 2 - All peripheral clocks deactivated \n" ) ;
printf ( " 3 - TIMER COUNTER 0 clock activated \n" ) ;
printf ( " 4 - USART 0 clock activated \n" ) ;
printf ( " 5 - PIO clock activated \n" ) ;
printf ( "\n Enter your choice : By default all peripheral clocks are stopped : " ) ;
scanf ("%d", &choice ) ;
switch ( choice )
{
case 1 :
at91_clock_set_mode ( PS_ALL_PERIPH_ACTIVE ) ;
break ;
case 2 :
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
break ;
case 3 :
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( TC0_ID ) ;
break ;
case 4 :
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( US0_ID ) ;
break ;
case 5 :
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( PIO_ID ) ;
break ;
default :
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
break ;
}
}
//*-----------------------------------------------------------------------------
//* Function Name : ext_irq_c_handler
//* Object : External Interrupt C handler
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : None
//*-----------------------------------------------------------------------------
void ext_irq_c_handler ( void )
//* Begin
{
int i ;
StructAIC *aic_pt = AIC_BASE ;
for ( i = 0; i<8; i++)
aic_pt->AIC_EOICR = 0xFFFFFFFF ;
at91_clock_open ( PIO_ID ) ;
}
//*-----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main
//* Input Parameters : none
//* Output Parameters : none
//*-----------------------------------------------------------------------------
int main(void)
//* Begin
{
int resp = 0;
u_int *addr_test = 0x0 ;
//* -- Set up PIOs
at91_clock_open ( PIO_ID ) ;
// Set the unconnected and the following PIO pin as OUTPUT to avoid oscillation
at91_pio_open ( &PIO_DESC, LED_MASK, PIO_OUTPUT ) ;
at91_pio_write ( &PIO_DESC, LED_MASK, PIO_SET_OUT ) ;
at91_pio_open ( &PIO_DESC, SW_MASK, PIO_INPUT | PIO_INPUT_IRQ_OFF ) ;
//* Enable the IRQ0 in interrupt controller
at91_extirq_open (&IRQ0_DESC , 7 , AIC_SRCTYPE_EXT_POSITIVE_EDGE , ext_irq_asm_handler ) ;
for (;;)
{
//* Display Utility Header
printf ( "\n**** %s Consumption Measurement Utility on %s board ****\n", CHIP_ID, TARGET_ID ) ;
printf ( "\n**** Board running at 66MHz ****\n") ;
//* 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 ( "\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/IRQ0 push button ***\n" ) ;
at91_clock_set_mode ( PS_MODE_IDLE ) ;
break ;
case 2 :
addr_test = (u_int*)0x10000 ;
printf ( "\n\n\n**** Internal EXTENDED SRAM memory working mode in ARM code ****\n" ) ;
PCA_choice ( ) ;
printf ( "\n\n*** To return to the main menu, press the SW2/IRQ0 push button ***\n" ) ;
ExecuteTest ( addr_test, ARM_MODE ) ;
break ;
case 3 :
addr_test = (u_int*)0x10000 ;
printf ( "\n\n\n**** Internal EXTENDED SRAM memory working mode in THUMB code ****\n" ) ;
PCA_choice ( ) ;
printf ( "\n\n*** To return to the main menu, press the SW2/IRQ0 push button ***\n" ) ;
ExecuteTest ( addr_test, THUMB_MODE ) ;
break ;
default :
break ;
}
} //* End for
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -