Check out and contribute to CodePedia, the wiki for developers.
*/
*/

View \TIMER.CPP

C++ sources for serial communication

Submitted By: WEBMASTER
Rating: starstar (Rate It)


// Copyright ***********************************************************
//
//      The information in this file is copyright 1991 by David Orme.
//
//            Anyone may use this information for any purpose as long as he takes
//            responsability for any and all libility incurred from its use
//            or misuse and acknowledges its use in the user documentation.  This
//            information is provided AS IS with no warrenty of any kind, either
//            expressed or implied.
//
// End *****************************************************************


// Contents ************************************************************
//
//            Timer::Timer()
//            Timer::~Timer()
//            Timer::NewTimer()
//
// Description
//
//            The Timer class implements a hardware-based background timer.
//            Note that all instances of this class reference the _same_ timer
//            ISR.
//
// End *****************************************************************


// Interface Dependencies ----------------------------------------------

#ifndef __TIMER_H
#include "timer.h"
#endif


// Implementation Dependencies -----------------------------------------

#ifndef __DOS_H
#include <dos.h>
#define __DOS_H
#endif


// Global Variables ----------------------------------------------------

volatile unsigned long Timer::ticker = 0l;
void interrupt (far * Timer::oldtimer)(...) = 0;


// Constructor //

Timer::Timer()

// Summary -------------------------------------------------------------
//
//            Initialize the new timer interrupt handler
//
// End -----------------------------------------------------------------

{
        ticker = 0l;
        oldtimer = getvect(TIMER);
        setvect(TIMER, Timer::NewTimer);
}



// Destructor //

Timer::~Timer()

// Summary --------------------------------------------------------------
//
//            Restore the old timer interrupt in the chain
//
// End ------------------------------------------------------------------

{
        setvect(TIMER, oldtimer);
}



// ISR //

void interrupt far Timer::NewTimer(...)

// Summary --------------------------------------------------------------
//
//            After chaining to the old interrupt handler, decrement our
//            counter if it is greater than 0.
//
// End ------------------------------------------------------------------

{
    (*oldtimer)();
    if (ticker > 0l)
        --ticker;
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings