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

📄 cpuat91rm9200.c

📁 This zip describes a benchmark software provided by IXXAT. It shows how to use the DBGU and timer pe
💻 C
字号:
/*************************************************************************
**    IXXAT Automation GmbH
**************************************************************************
**
**       File: CPUxxx.c
**    Summary: CPU specific part of the benchmark program. Must be adapted
**             to the target system.
**    Version: 1.0
**       Date: 22.01.2003
**     Author: J. Stolberg
**
**************************************************************************
**************************************************************************
**
**  Functions: InitCPU
**             InitRS232
**             StartTimer
**             GetTimer
**   Compiler: -
**    Remarks: -
**
**    History:
**
**************************************************************************
**    all rights reserved
*************************************************************************/

/*************************************************************************
**    compiler directives
*************************************************************************/

void TimerISR(void);
/*************************************************************************
**    include-files
*************************************************************************/
#include "AT91RM9200.h"
#include "lib_AT91RM9200.h"

#include "target.h"


#define SOFT_INTERRUPT_LEVEL		1
#define TIMER_INTERRUPT_LEVEL		2
#define MiliSeconde	30000		// 60 MHz at MCK/2 => 30000 for 1ms

// Use the Library Handler defined in file periph/pio/pio_irq/irq_pio.s
extern void sw_asm_irq_handler(void);
extern void timer0_asm_irq_handler(void);
/*************************************************************************
**    global variables
*************************************************************************/
volatile UINT32 ISRCounter = 0;

/*************************************************************************
**    static constants, types, macros, variables
*************************************************************************/

volatile UINT32 TimerTicks = 0;

/*************************************************************************
**    static function-prototypes
*************************************************************************/
//*----------------------------------------------------------------------------
//* Function Name       : timer_init
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
void timer_init ( void )
//* Begin
{
    //init the timer interrupt counter
    int dummy;
    	// First, enable the clock of the TIMER
    	AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_TC0 ) ;

	//* Disable the clock and the interrupts
	AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS ;
	AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF ;

        //* Clear status bit 
        dummy = AT91C_BASE_TC0->TC_SR;
        //* Supress warning variable "dummy" was set but never used
        dummy = dummy;
	//* Set the Mode of the Timer Counter
	AT91C_BASE_TC0->TC_CMR = AT91C_TC_WAVE |AT91C_TC_CPCTRG ;


    	//* open Timer 0 interrupt
	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_TC0, TIMER_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, timer0_asm_irq_handler); 

	AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;  //  IRQ enable CPC
	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC0);
	
  TimerTicks = 0;
}

/*************************************************************************
**    global functions
*************************************************************************/

/*************************************************************************
**
** Function   : InitCPU
** Description: Initialize CPU and hardware:
**              - enable MeasureISR for interrupt performance measuring
**                (priority must be lower than the priority of the TimerISR)
**              - enable global interrupt
** Parameters : -
** Returnvalue: -
**
*************************************************************************/
void InitCPU(void)
{
    	//* Open the software interrupt on the AIC
	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_SYS, SOFT_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_EXT_POSITIVE_EDGE,  sw_asm_irq_handler); 
	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_SYS);
	timer_init();

  ISRCounter=0;
}

/*************************************************************************
**
** Function   : InitRS232
** Description: Initialize The RS232 interface/stdout for outputs
**              via printf. Baudrate and bit protcol is irrelevant.
** Parameters : -
** Returnvalue: -
**
*************************************************************************/
void InitRS232(void)
{
 // Already initialized in the Cstartup function
 
}

/*************************************************************************
**
** Function   : StartTimer
** Description: Start a on-board timer with a resulution of 1 msec,
**              so that the 'TimerISR' is called every msec.
** Parameters : -
** Returnvalue: -
**
*************************************************************************/
void StartTimer(void)
{
	//* Enable the clock
	AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN ;
	//* Start timer0
	AT91C_BASE_TC0->TC_RA = 0;
	AT91C_BASE_TC0->TC_RB = AT91C_BASE_TC0->TC_RC = MiliSeconde;
	AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG ;

}

//*----------------------------------------------------------------------------
//* \fn    printfHeader
//* \brief This function print the IXXAT Header
//*----------------------------------------------------------------------------
void   printfHeader(void)
{
    AT91F_DBGU_Printk("IXXAT benchmark V2.0\r");
}
//*----------------------------------------------------------------------------
//* \fn    print
//* \brief This function print a message and a parameter if TRACE Flasg is enable
//*----------------------------------------------------------------------------
void print(char * message1,UINT32 arg)
{
#ifdef TRACE
    char test[50];
    sprintf(test,message1,arg);
    AT91F_DBGU_Printk(test);
    AT91F_DBGU_Printk("\r");
#endif    
}
//*----------------------------------------------------------------------------
//* \fn    printfBM
//* \brief This function print a bench message with parameter in float
//*----------------------------------------------------------------------------
void   printfBM(char * message1, UINT32 val1, UINT32 val)
{
    char test[50];
    float res;
    res = (float)val1*1000.0 / (float)val;;
    sprintf(test,message1,res);
    AT91F_DBGU_Printk(test);
    AT91F_DBGU_Printk("\r");

}
//*----------------------------------------------------------------------------
//* \fn    printfbenchmark
//* \brief This function print a bench Result with 2 parameters in float
//*----------------------------------------------------------------------------
void   printfbenchmark( UINT32 val1, UINT32 val)
{
    char test[50];
    float res;    
    res = (float)val1* 2458.0 / (float)val;;
    sprintf(test,"\n\n benchmark value: %8.1f",res);
    AT91F_DBGU_Printk(test);
    AT91F_DBGU_Printk("\r");
}

⌨️ 快捷键说明

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