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

📄 time.c

📁 小型操作系统,以VC为开发环境,需要boachs调试
💻 C
字号:
/***************************************************************************
**     File name   : time.c
**     Author      : x.cheng
**     Create date :
**
**	   Comment:
**        timer driver
**
**     Revisions:
**     $Log: time.c,v $
**     Revision 1.3  2005/08/04 08:43:28  x.cheng
**     new method for interrupt ISR install
**
**     Revision 1.2  2005/07/27 07:06:25  x.cheng
**     move global ticker variable to this file..
**     ulTimeGetTicker() function added
**
**     Revision 1.1.1.1  2005/07/27 06:53:15  x.cheng
**     add into repositories
**
**
***************************************************************************/
#include "const.h"
#include "type.h"
#include "stdarg.h"
#include "stdlib.h"

#include "..\..\Inc\i386\io.h"
#include "..\..\Inc\i386\system.h"
#include "..\..\Inc\i386\x86.h"
#include "..\..\Inc\i386\interrupt.h"
#include "..\..\Inc\i386\exception.h"


#include "..\..\Inc\time.h"
#include "..\..\inc\mts.h"

#include "..\inc\def_time.h"

/**********global variable****************/
volatile unsigned long g_ulTickers = 0;

/******ISR defined in hwISR2.asm***********/
void vTimeISR(void);

unsigned long ulSecondFrom1970010100(ts_TIME *pstTime);
/************************************************************
*************************************************************
**      Function Name:			vDoTimeIRQ
**      Author:                 x.cheng
**
**      Comment:
**			每次时钟中断会调用这个函数
**
**      List of parameters:
**			no
**
**      Return value:   
**          no
**
**      Revisions:
**
*************************************************************
*************************************************************/
extern unsigned long gulStartUpTime;
void vDoTimeIRQ(ts_IrqContext* pstContext) 
{

	g_ulTickers ++;
/*
	if ( !(gulTickers % 100) ){
		//kprintf("From 1970-01-01 00:00:00, This is %d seconds\n", (gulStartUpTime+gulTickers));
		//kprintf("From start up, This is %d seconds\n", gulTickers/100);
	}
*/
	if ( !(g_ulTickers % 50) ){
		vMtsSchedule();
	} 
	vDbgDummy();
}

/////////////////////////////////////////////////////
//Get cmos time
/////////////////////////////////////////////////////
void vCMOSGetTime(ts_TIME *pstCurTime)
{
	do { /*用于控制时间误差在1秒之内*/
		pstCurTime->iSec		= CMOS_Read(RTC_SECOND);
		pstCurTime->iMin		= CMOS_Read(RTC_MINUTE);
		pstCurTime->iHour		= CMOS_Read(RTC_HOUR);
		pstCurTime->iDay		= CMOS_Read(RTC_DAY);
		pstCurTime->iMon		= CMOS_Read(RTC_MONTH);	/*1-12*/
		pstCurTime->iYear		= CMOS_Read(RTC_YEAR);
	}while (pstCurTime->iSec != CMOS_Read(RTC_SECOND));

	Bcd_To_Bin(pstCurTime->iSec);
	Bcd_To_Bin(pstCurTime->iMin);
	Bcd_To_Bin(pstCurTime->iHour);
	Bcd_To_Bin(pstCurTime->iDay);
	Bcd_To_Bin(pstCurTime->iMon);
	Bcd_To_Bin(pstCurTime->iYear);
}
/************************************************************
*************************************************************
**      Function Name:			ulTimeInit
**      Author:                 x.cheng
**
**      Comment:
**		 时钟每秒中断100次,即每10ms中断一次
**			设置时钟中断,计算自1970。1。1零点到现在的秒数
**
**      List of parameters:
**			no
**
**      Return value:   
**          unsigned long - 秒数
**
**      Revisions:
**
*************************************************************
*************************************************************/
unsigned long ulTimeInit(void)
{
	ts_TIME stCurTime;

	vCMOSGetTime(&stCurTime);
//	kprintf("\nNow it's 20%02d-%02d-%02d %02d:%02d:%02d\n", stCurTime.iYear, stCurTime.iMon, stCurTime.iDay,
//											 stCurTime.iHour, stCurTime.iMin, stCurTime.iSec);
  
	/*初始化8253/54的计数器0, 该计数器产生irq0(时钟中断)*/
	vOutPortDelay(CTRL_REG_8253, MODE_CW_COUTER0);
	vOutPortDelay(REG0_8253, COUNTER0_PER_IRQ&0xff); /* LSB */
	vOutPortDelay(REG0_8253, COUNTER0_PER_IRQ>>8); /* MSB */
	
	//install timer interrupt handler
	IsrInstallHandler(HWM_TIMER_IRQ0, &vDoTimeIRQ);

	return ulSecondFrom1970010100(&stCurTime);
}

/************************************************************
*************************************************************
**      Function Name:			ulTimeGetTicker
**      Author:                 x.cheng
**
**      Comment:
**
**      List of parameters:
**			no
**
**      Return value:   
**          unsigned long - tickers
**
**      Revisions:
**
*************************************************************
*************************************************************/
unsigned long ulTimeGetTicker(void)
{
	return g_ulTickers;
}

⌨️ 快捷键说明

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