📄 mips.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 : mips.c
//* Object : Mips calculation
//* Creation : JPP 13/Jan/2003
//*
//*----------------------------------------------------------------------------
// Include Standard LIB files
#include "eb55.h"
//* ------------------- Internal function prototype -------------------------
void Init_Mips_Timer (void);
void Start_Mips_Timer (void);
unsigned int Mips_Result_loop(void);
unsigned int Mips_Result_all(void) ;
//* --------------------------- Constant definition ---------------------------
#define NB_LOSE_CYCLE 3 /* 1 for break pipe and 2 for "LDR"*/
#define NB_ASM_INSTRUCTION (40 + NB_LOSE_CYCLE)
/* Clock Selection */
/*-----------------*/
#define TC_CLKS 0x7
#define TC_CLKS_MCK2 0x0
#define TC_CLKS_MCK8 0x1
#define TC_CLKS_MCK32 0x2
#define TC_CLKS_MCK128 0x3
#define TC_CLKS_MCK1024 0x4
#define TIMER_INTERRUPT_LEVEL 7
//* --------------------------- Structure definition --------------------------
typedef struct _AT91S_MIPS_TIMER {
unsigned int Id ;
unsigned short Peroid;
unsigned char Div;
} AT91S_MIPS_TIMER, *AT91PS_MIPS_TIMER;
//* ------------------------------ Global variable ----------------------------
const AT91PS_TC MipsTimerBase =AT91C_BASE_TC1;
const AT91S_MIPS_TIMER MipsTimer = { AT91C_ID_TC1,((MCK)/1024),TC_CLKS_MCK1024};
volatile unsigned int cmpt_loop[2];
//* ----------------------- External Function Prototype -----------------------
extern void timer_mpis_irq_handler(void);
//*----------------------------------------------------------------------------
//* Function Name : Init_Mips_Timer
//* Object : Init Timer management
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Init_Mips_Timer (void)
{
int dummy;
//* Init timer interrupt
AT91F_APMC_EnablePeriphClock(AT91C_BASE_APMC,1 << MipsTimer.Id);
//* Disable the clock and the interrupts
MipsTimerBase->TC_CCR = AT91C_TC_CLKDIS ;
MipsTimerBase->TC_IDR = 0xFFFFFFFF ;
dummy = MipsTimerBase->TC_SR ;
//* Set the Mode of the Timer Counter
MipsTimerBase->TC_CMR = AT91C_TC_WAVE |AT91C_TC_CPCTRG | MipsTimer.Div ;
//* open Timer 0 interrupt
AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, MipsTimer.Id, TIMER_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, timer_mpis_irq_handler);
MipsTimerBase->TC_IER = AT91C_TC_CPCS; //* Enable the RC Compare interrupt
AT91F_AIC_EnableIt (AT91C_BASE_AIC, MipsTimer.Id);
}
//*----------------------------------------------------------------------------
//* Function Name : Start_Mips_Timer
//* Object : Start Timer
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Start_Mips_Timer (void)
{
cmpt_loop[0]=0;
//* Enable the clock and Start timer
MipsTimerBase->TC_CCR = AT91C_TC_CLKEN ;
MipsTimerBase->TC_RA = 0;
MipsTimerBase->TC_RB = MipsTimerBase->TC_RC = MipsTimer.Peroid;
MipsTimerBase->TC_CCR = AT91C_TC_SWTRG ;
}
//*----------------------------------------------------------------------------
//* Function Name : Mips_Result_loop
//* Object : Return the number of loop can be executed under the time
//* Input Parameters : none
//* Output Parameters : the counter value
//*----------------------------------------------------------------------------
unsigned int Mips_Result_loop(void)
{
return (cmpt_loop[1]);
}
//*----------------------------------------------------------------------------
//* Function Name : Mips_Result_all
//* Object : Return the number of loop can be executed under the time
//* Input Parameters : none
//* Output Parameters : miliMPIS
//*----------------------------------------------------------------------------
unsigned int Mips_Result_all(void)
{
return ((cmpt_loop[1]*NB_ASM_INSTRUCTION) / 1000);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -