/*
** ###################################################################
**
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**
**     Filename  : Cpu.C
**
**     Project   : LED
** 
**     Processor : MC68HC908AZ60MFU
**
**     Beantype  : MC68HC908AZ60
**
**     Version   : Bean 01.041, Driver 01.03, CPU db: 2.81.019
**
**     Compiler  : Metrowerks HC08 C Compiler V-5.0.13
**
**     Date/Time : 04-Apr-02, 12:49
**
**     Abstract  :
**
**         This bean "MC68HC908AZ60" implements properties, methods,
**         and events of the CPU.
**
**     Settings  :
**
**
**     Contents  :
**
**         GetSpeedMode - byte Cpu_GetSpeedMode(void);
**         EnableInt    - void Cpu_EnableInt(void);
**         DisableInt   - void Cpu_DisableInt(void);
**
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2002
**
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
**
** ###################################################################
*/

/* MODULE Cpu. */
#include "RedLED.h"
#include "GreenLED.h"
#include "Button.h"
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Events.h"
#include "Cpu.h"

#define CGM_DELAY  255UL


/* Global variables */
byte CCR_reg;                          /* Current CCR register */
byte CpuMode = HIGH_SPEED;             /* Current speed mode */


/*
** ===================================================================
**     Method      :  Cpu_Interrupt (bean MC68HC908AZ60)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
__interrupt void Cpu_Interrupt(void)
{
}

/*
** ===================================================================
**     Method      :  Cpu_DisableInt (bean MC68HC908AZ60)
**
**     Description :
**         Disable maskable interrupts
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_DisableInt(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_EnableInt (bean MC68HC908AZ60)
**
**     Description :
**         Enable maskable interrupts
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_EnableInt(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_GetSpeedMode (bean MC68HC908AZ60)
**
**     Description :
**         Get current speed mode
**     Parameters  : None
**     Returns     :
**         ---             - Speed mode (HIGH_SPEED, LOW_SPEED,
**                           SLOW_SPEED)
** ===================================================================
*/
byte Cpu_GetSpeedMode(void)
{
  return CpuMode;                      /* Result the actual cpu mode */
}

/*
** ===================================================================
**         There is beginning of initialization code for CPU 
**         and embedded beans.
** ===================================================================
*/
void __low_level_init(void)
{
  byte i;
  /* Common initialization of the CPU registers */
  output( PTB, input( PTB ) & ~1 | 2 );
  output( DDRB, input( DDRB ) | 3 );
  output( DDRG, input( DDRG ) & ~1 );
  /* ### MC68HC908AZ60 "Cpu" init code ... */
  CONFIG_1 = 1;                        /* Set the CONFIG_1 register */
  CONFIG_2 = 1;                        /* Set the CONFIG_2 register */
  /* ### External interrupt "Button" init code ... */
  KBSCR_MODEK = 0;
  KBSCR_IMASKK = 1;
  KBIE |= 1;
  KBSCR_ACKK = 1;
  KBSCR_IMASKK = 0;
  __EI();                              /* Enable interrupts */
}

/* END Cpu. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 02.85 for 
**     the Motorola HC08 series of microcontrollers.
**
** ###################################################################
*/
