profile.c

来自「USB-TEST是USB通信的例子」· C语言 代码 · 共 81 行

C
81
字号
/*********************************************************************************************
* File:		main.c
* Author:	embest
* Desc:		c main entry
* History:	
*			J.Y.Guo, Programming start, March 12, 2005
*********************************************************************************************/

/*------------------------------------------------------------------------------------------*/
/*                                     include files	                                    */
/*------------------------------------------------------------------------------------------*/
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

#include "2410lib.h"

/*------------------------------------------------------------------------------------------*/
/*                                     global variables                                     */
/*------------------------------------------------------------------------------------------*/
static int f_nCount;

/*------------------------------------------------------------------------------------------*/
/*                                     function declare                                     */
/*------------------------------------------------------------------------------------------*/
void wdt_int(void) __attribute__ ((interrupt ("IRQ")));

/*********************************************************************************************
* name:		timer_initex
* func:		timer operation
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void timer_initex(void)
{
	f_nCount = 0;	
	pISR_WDT = (UINT32T)wdt_int;
	ClearPending(BIT_WDT);
	rINTMSK &= ~(BIT_WDT);
}

void timer_startex(void)
{
	int divider = 0;
	rWTCON = ((PCLK/1000000-1)<<8)|(0<<3)|(1<<2);	// 16us
	rWTDAT = 0xffff;
	rWTCNT = 0xffff;   

	// 1/16/(65+1),interrupt enable,reset disable,watchdog enable
	rWTCON = ((PCLK/1000000-1)<<8)|(0<<3)|(1<<2)|(0<<0)|(1<<5);   
}

float timer_stopex(void)
{
	int count;
	rWTCON = ((PCLK/1000000-1)<<8);
	rINTMSK |= BIT_WDT;
	count = (0xffff-rWTCNT)+(f_nCount*0xffff);
	return ((float)count*(16e-6));
}

/*********************************************************************************************
* name:		wdt_int
* func:		watch dog interrupt handler
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void wdt_int(void)
{
	ClearPending(BIT_WDT);
	f_nCount++;   	
}



⌨️ 快捷键说明

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