/*
    TM8254Timer.c, Copyright  (c) by Lukas Ruf, lr@lpr.ch,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
	
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Threads/ia32/TMClock.c,v $
 	Author(s):             Lukas Ruf, lr@lpr.ch
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 3014 $
 	Creation Date:         
 	Last Date of Change:   $Date: 2007-04-24 19:39:58 +0200 (Die, 24 Apr 2007) $      by: $Author: sryffel $
	
	
	$Log: TM8254Timer.c,v $
	Revision 1.5  2000/11/23 11:17:48  cjeker
	fixes for ia32 Now ia32 and mips should work again
	
	Revision 1.4  2000/11/15 10:13:34  ruf
	ia32Debug and Repository Reorganisation
	
	Revision 1.3  1999/12/13 21:48:34  ruf
	GNU General Public Licence Update
	
	Revision 1.2  1999/06/06 20:55:14  jeker
	putting everything together for Topsy 2.0
	
	Revision 1.1  1999/05/13 17:05:47  jeker
	Initial revision
 
*/
#include "TMHal.h"
#include "TMHalAsm.h"
#include "IOHal.h"
#include "IODevice.h"
#include "TMScheduler.h"
#include "Support.h"
#include "TMClock.h" 

#include "SupportAsm.h"
#include "Video.h"
#include "video.h"
#include "Tools.h" 
#include "Lock.h"



/*
 * This function initializes the clock on the board.
 */
Error setClockValue( ClockId cId,
                     int period,
                     ClockMode cMode)
{
  /* original Topsy supports only one mode: called RATEGENERATOR */
  /* so I simply ignore cMode for init now */
  unsigned short ldivisor = (unsigned short)(tFIXRATE * period / 1000);

  // printf("setClockValue: period = %i   ldivosor = %i\n", period, ldivisor);

  switch (cId)
  {
  case CLOCK0 :
    __timerSet(ldivisor, MODE2_COUNTER0, TIMER0);
    /* please note: orig. Topsy supports only one setClockValue() call
       in TMInit.c. The Timer Channel 0 is activated in TimerInit() in this
       file. */
    break;
  case CLOCK1 :
    /* NOTE: The PC uses TIMER CHANNEL 1 to generate the Memory Refresh Cycle
       So, only TIMER0 can be used to simply generate TIMER Interrupts
       without difficulties.
       Channel 2 of 8254 is hardwired to Speaker Frequency Output --> so forget
       it !! */
    break;
  default :
    break;

  }
  return TM_OK;
}

/* When a clock interrupt is generated, a reset is performed. If not done,
 * the interrupt is generated at once again and again ...
 */
void tmResetClockInterrupt(ClockId cId)
{
  /* i386: IRQ is generated. Handled by the  __general_IRQHandler the
           appropriate PIC is resetted.
   */
}


