timerint.c

来自「用c语言开发的操作系统内核」· C语言 代码 · 共 126 行

C
126
字号
/************************************************************************
*
*  Module name         : TIMERINT.C
*
*  Module description  :
*     Timer interrupt handler.
*
*  Project             : RTMK
*
*  Target platform     : DOS
*
*  Compiler & Library  : BC++ 3.1
*
*  Author              : Richard Shen
*
*  Creation date       : 30 August, 1995
*
************************************************************************/
#ifdef __DOS__

#include <dos.h>
#include <types.h>
#include <timerint.h>
#include "rtmkloc.h"

/************************************************************************
*                 F U N T I O N    P R O T O T Y P E S                  *
************************************************************************/
static void interrupt   TimerIntHandler(__CPPARGS);

/************************************************************************
*                    S T A T I C    V A R I A B L E S                   *
************************************************************************/
static void interrupt   (*OriginalInt1C)(__CPPARGS) = NULL;
static void             (*ApplTimerFunc)(void)      = NULL;

/************************************************************************
*  Function name   : SetTimerInt
*  Description     : Install timer interrupt handler (int 1cH)
*                  :
*  Parameters      : -
*  Returns         : -
*  Author          : Richard Shen
* -----------------------------------------------------------------------
*  Date     By      Description
* -----------------------------------------------------------------------
*  30Aug95  RCS     Created.
************************************************************************/
void SetTimerInt(void)
{
   disable();
   OriginalInt1C = getvect(0x1c);
   ApplTimerFunc = NULL;
   setvect(0x1c, TimerIntHandler);
   enable();
} /* SetTimerInt() */

/************************************************************************
*  Function name   : RestoreTimerInt
*  Description     : Restore timer interrupt handler (int 1cH)
*                  :
*  Parameters      : -
*  Returns         : -
*  Author          : Richard Shen
* -----------------------------------------------------------------------
*  Date     By      Description
* -----------------------------------------------------------------------
*  30Aug95  RCS     Created.
************************************************************************/
void RestoreTimerInt(void)
{
   disable();
   if (OriginalInt1C)
   {
      setvect(0x1c, OriginalInt1C);
      ApplTimerFunc = NULL;
   } /* end of if */

   enable();
} /* RestoreTimerInt() */

/************************************************************************
*  Function name   : TimerIntHandler
*  Description     : Timer interrupt handler
*                  :
*  Parameters      : -
*  Returns         : -
*  Author          : Richard Shen
* -----------------------------------------------------------------------
*  Date     By      Description
* -----------------------------------------------------------------------
*  30Aug95  RCS     Created.
************************************************************************/
static void interrupt TimerIntHandler(__CPPARGS)
{
   disable();
   servingInt++;
   if (ApplTimerFunc != NULL)
      ApplTimerFunc();

   servingInt--;
   outport(0x20, 0x20);                /* Inform PIC end of interrupt */
   enable();
} /* TimerIntHandler() */

/************************************************************************
*  Function name   : SetApplTimerHandler
*  Description     : Set up application timer service routine
*                  :
*  Parameters      : applHandler - Application service routine
*  Returns         : -
*  Author          : Richard Shen
* -----------------------------------------------------------------------
*  Date     By      Description
* -----------------------------------------------------------------------
*  30Aug95  RCS     Created.
************************************************************************/
void SetApplTimerHandler(void (*applHandler)(void))
{
   disable();
   ApplTimerFunc = applHandler;
   enable();
} /* SetApplTimerHandler() */

#endif /* __DOS__ */

⌨️ 快捷键说明

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