📄 eb55_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 : eb55_consume.c
//* Object : AT91M55800 - Consumption measurement
//* Exported resources : main
//* Imported resources : ExecuteTest
//*
//* 1.0 28/07/00 PF : Creation
//* 2.0 11/07/01 PF : Adding Clock Switching Functions
//*-----------------------------------------------------------------------------
/*----- Files to be included Definition -----*/
#include <stdio.h>
#include <stdlib.h>
#include "parts\m55800\lib_m55800.h"
#include "targets\eb55\eb55.h"
#include "clock_switching_driver.h"
/*----- Types and Constants Definition -----*/
#define CHIP_ID "AT91M55800"
#define TARGET_ID "EB55"
#define ARM_MODE 0
#define THUMB_MODE 1
#define MOSC_CONFIG ( APMC_MOSC_EN | (34<<B_OSCOUNT)|(0x1<<B_PLLCOUNT) )
#define PLL 0x2 //* low frequency oscillator output => MCK
#define MAIN_OSC 0x1 //* main oscillator output => MCK
#define SLOW_OSC 0x0 //* PLL output =MCK
#define MUL_x3 0x3
#define MUL_x2 0x2
#define NO_MUL 0x1
/* Global Variables */
/*----- 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 : freq_choice
//* Object : Choice of the AT91M55800
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : none
//*-----------------------------------------------------------------------------
void freq_choice ( void )
//* Begin
{
u_int freq ;
//* Frequency choice
printf ( "\n Select the desired Frequency :\n" ) ;
printf ( "\n 1 - 48MHz (with PLL)\n" ) ;
printf ( " 2 - 32MHz (with PLL)\n\n" ) ;
printf ( " 3 - 16MHz (Main oscillator)\n" ) ;
printf ( " 4 - 8MHz (Main oscillator/2)\n" ) ;
printf ( " 5 - 4MHz (Main oscillator/4)\n\n" ) ;
printf ( " 6 - 250KHz (Main oscillator/32)\n" ) ;
printf ( " 7 - 32KHz (Low frequency oscillator)\n" ) ;
printf ( "\n Enter your choice : " ) ;
scanf ("%d", &freq ) ;
switch ( freq )
{
case 1 : //* 48MHz (with PLL)
mck_clock_speed (PLL, MUL_x3, APMC_PRES_NONE ) ;
break ;
case 2 : //* 32MHz (with PLL)
mck_clock_speed (PLL, MUL_x2, APMC_PRES_NONE) ;
break ;
case 3 : //* 16MHz (Main oscillator)
mck_clock_speed (MAIN_OSC, NO_MUL, APMC_PRES_NONE ) ;
break ;
case 4 : //* 8MHz (Main oscillator/2)
mck_clock_speed (MAIN_OSC, NO_MUL, APMC_PRES_DIV2 ) ;
break ;
case 5 : //* 4MHz (Main oscillator/4)
mck_clock_speed (MAIN_OSC, NO_MUL, APMC_PRES_DIV4 ) ;
break ;
case 6 : //* 250KHz (Main oscillator/32)
mck_clock_speed (MAIN_OSC, NO_MUL, APMC_PRES_DIV32 ) ;
break ;
case 7 : //* 32KHz (Low frequency oscillator)
mck_clock_speed (SLOW_OSC, NO_MUL, APMC_PRES_NONE ) ;
break ;
default :
break ;
}
}
//*-----------------------------------------------------------------------------
//* 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 \n" ) ;
printf ( " 3 - USART 0 clock activated\n" ) ;
printf ( " 4 - USART 0, 1 and 2 clock activated\n" ) ;
printf ( " 5 - SPI clock activated\n" ) ;
printf ( " 6 - Timer Counter Channel 0 clock activated\n" ) ;
printf ( " 7 - Timer Counter 0, 1 and 3 clock activated\n" ) ;
printf ( " 8 - PIOA clock activated\n" ) ;
printf ( " 9 - PIOA and PIOB clock activated\n" ) ;
printf ( " 10 - ADC0 clock activated\n" ) ;
printf ( " 11 - ADC0 and ADC1 clock activated\n" ) ;
printf ( " 12 - DAC0 clock activated\n" ) ;
printf ( " 13 - DAC0, DAC1 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_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
break ;
case 3 : //* USART 0 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( US0_ID ) ;
break ;
case 4 : //* USART 0, 1 and 2 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( US0_ID ) ;
at91_clock_open ( US1_ID ) ;
at91_clock_open ( US2_ID ) ;
break ;
case 5 : //* SPI clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( SPI_ID ) ;
break ;
case 6 : //* Timer Counter Channel 0 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( TC0_ID ) ;
break ;
case 7 : //* Timer Counter 0, 1 and 3 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( TC0_ID ) ;
at91_clock_open ( TC1_ID ) ;
at91_clock_open ( TC2_ID ) ;
break ;
case 8 : //* PIOA clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( PIOA_ID ) ;
break ;
case 9 : //* PIOA and PIOB clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( PIOA_ID ) ;
at91_clock_open ( PIOB_ID ) ;
break ;
case 10 : //* ADC0 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( AD0_ID ) ;
break ;
case 11 : //* ADC0 and ADC1 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( AD0_ID ) ;
at91_clock_open ( AD1_ID ) ;
break ;
case 12 : //* DAC0 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( DAC0_ID ) ;
break ;
case 13 : //* DAC0, DAC1 clock activated
at91_clock_set_mode ( PS_ALL_PERIPH_INACTIVE ) ;
at91_clock_open ( DAC0_ID ) ;
at91_clock_open ( DAC1_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
{
at91_clock_open ( PIOA_ID ) ;
*(u_int*)0xFFE00130 = 0 ;
}
//*-----------------------------------------------------------------------------
//* Function Name : main
//* Object : AT91M55800 Consume Test
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : None
//*-----------------------------------------------------------------------------
int main( void )
//* Begin
{
int nws = 0 ;
int resp = 0 ;
StructPIO *pioa_pt = PIOA_BASE ;
StructPIO *piob_pt = PIOB_BASE ;
StructEBI *ebi_pt = EBI_BASE ;
at91_clock_open ( PIOA_ID ) ;
at91_clock_open ( PIOB_ID ) ;
pioa_pt -> PIO_ODR = 0xFFFFFFFF ;
pioa_pt -> PIO_OER = 0xFFF6FDFF ;
piob_pt -> PIO_ODR = 0xFFFFFFFF ;
piob_pt -> PIO_OER = 0xFFE5FFFF ;
//* Enable the IRQ0 in interrupt controller
at91_extirq_open (&IRQ0_DESC , 7 , AIC_SRCTYPE_EXT_POSITIVE_EDGE , ext_irq_asm_handler ) ;
//* Repeat for ever
for (;;)
{
//* Display Utility Header
printf ( "\n**** %s Consumption Measurement Utility on %s board ****\n", CHIP_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 : //* Idle mode
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" ) ;
freq_choice () ;
at91_clock_set_mode ( PS_MODE_IDLE ) ;
break ;
case 2 : //* Internal memory working mode in ARM code
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 SW2/IRQ0 push button ***\n" ) ;
freq_choice () ;
ExecuteTest ( (u_int *)0x100, ARM_MODE ) ;
break ;
case 3 : //* Internal memory working mode in Thumb code
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 SW2/IRQ0 push button ***\n" ) ;
freq_choice () ;
ExecuteTest ( (u_int *)0x100, THUMB_MODE ) ;
break ;
case 4 : //* External memory working mode in ARM code
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 SW2/IRQ0 push button ***\n" ) ;
freq_choice () ;
ExecuteTest ( (u_int *)0x2020000, ARM_MODE ) ;
if ( nws == 0 )
{
ebi_pt->EBI_CSR[1] |= EBI_WSE ;
ebi_pt->EBI_MCR &= ~EBI_DRP_EARLY ;
}
break ;
case 5 : //* External memory working mode in Thumb code
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 SW2/IRQ0 push button ***\n" ) ;
freq_choice () ;
ExecuteTest ( (u_int *)0x2020000, THUMB_MODE ) ;
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 + -