//-------------------------------------------------------------------------*
// 文件名: OUTTMPCh.h                                                         *
// 说  明: 定时器和定时器通道设置头文件                                    *
//-------------------------------------------------------------------------*

#ifndef OUTTPMCH_H
#define OUTTPMCH_H
  //1 头文件
  #include "Type.h"           //类型别名定义
  #include "MC9S08AW60.h"     //映像寄存器地址头文件

  //2 中断宏定义
  #define EnableT1ChOutInt(n)  AW60_TPM1_CHSCSTR(n) |=AW60_TPM_CHSCSTR_CHIE   
                                    //允许定时器1通道n的输出比较中断,n=0~5
  #define DisableT1ChOutInt(n) AW60_TPM1_CHSCSTR(n) &= ~AW60_TPM_CHSCSTR_CHIE   
                                    //禁止定时器1通道n的输出比较中断,n=0~5
  #define EnableT2ChOutInt(n)  AW60_TPM2_CHSCSTR(n) |=AW60_TPM_CHSCSTR_CHIE   
                                    //允许定时器2通道n的输出比较中断,n=0~1
  #define DisableT2ChOutInt(n) AW60_TPM2_CHSCSTR(n) &= ~AW60_TPM_CHSCSTR_CHIE   
                                    //禁止定时器2通道n的输出比较中断,n=0~1    
  
  //3 函数声明
  //-----------------------------------------------------------------------*
  //函数名: OUTTPMChInit                                                      *
  //功  能: 定时器输出比较功能设置                                         * 
  //参  数:                                                                *
  //    (1)TPMNo:定时器号(1-2)                                             *
  //    (2)CHNo:通道号(定时器1通道号0-5,定时器2通道号0-1)                  *
  //    (3)Period:输出比较周期(0-65535)                                    *
  //返  回:无                                                              *
  //说  明:无                                                              *
  //-----------------------------------------------------------------------*
  void OUTTPMChInit(uint8 TPMNo,uint8 CHNo,uint16 Period);
  
  //3 寄存器有关的宏定义
  //标志位掩码的定义
  //定时器状态和控制寄存器各个位的掩码
  #define AW60_TPM_CSTR_TOF             (0x80)   //定时器溢出标志位掩码
  #define AW60_TPM_CSTR_TOIE            (0x40)   //定时器溢出中断使能位掩码
  #define AW60_TPM_CSTR_CPWMS           (0x20)   //PWM选择位掩码
  #define AW60_TPM_CSTR_CLKSB           (0x10)   //时钟源选择位B掩码
  #define AW60_TPM_CSTR_CLKSA           (0x08)   //时钟源选择位A掩码
  #define AW60_TPM_CSTR_PS2             (0x04)   //预分频位2掩码
  #define AW60_TPM_CSTR_PS1             (0x02)   //预分频位1掩码
  #define AW60_TPM_CSTR_PS0             (0x01)   //预分频位0掩码
  //定时器通道状态和控制寄存器各个位的掩码
  #define AW60_TPM_CHSCSTR_CHF          (0x80)   //标志位
  #define AW60_TPM_CHSCSTR_CHIE         (0x40)   //中断使能位
  #define AW60_TPM_CHSCSTR_MSB          (0x20)   //模式选择位B
  #define AW60_TPM_CHSCSTR_MSA          (0x10)   //模式选择位A
  #define AW60_TPM_CHSCSTR_ELSB         (0x08)   //沿跳变/输出电平选择位B
  #define AW60_TPM_CHSCSTR_ELSA         (0x04)   //沿跳变/输出电平选择位A
  //AW60的定时器模块相关寄存器的定义
  //x=1表示定时器1模块 x=2表示定时器2模块
  //定时器状态和控制寄存器
  #define AW60_TPM_CSTR(x)      (*(vuint8 *)(0x00000020+(x-1)*64))
  //定时器计数寄存器(高)
  #define AW60_TPM_CNTH(x)  (*(vuint8 *)(0x00000021+(x-1)*64))
  //定时器计数寄存器(低)
  #define AW60_TPM_CNTL(x)  (*(vuint8 *)(0x00000022+(x-1)*64))    
  //定时器预置寄存器(高)
  #define AW60_TPM_MODH(x)   (*(vuint8 *)(0x00000023+(x-1)*64))
  //定时器预置寄存器(低)
  #define AW60_TPM_MODL(x)   (*(vuint8 *)(0x00000024+(x-1)*64))
  //定时器1通道状态和控制寄存器
  #define AW60_TPM1_CHSCSTR(x)  (*(vuint8 *)(0x00000025+(x)*3))
  //定时器1通道状态和控制寄存器(高)
  #define AW60_TPM1_CHVH(x)  (*(vuint8 *)(0x00000026+(x)*3))
  //定时器1通道状态和控制寄存器(低)
  #define AW60_TPM1_CHVL(x)  (*(vuint8 *)(0x00000027+(x)*3))
  //定时器2通道状态和控制寄存器
  #define AW60_TPM2_CHSCSTR(x)  (*(vuint8 *)(0x00000065+(x)*3))
  //定时器1通道状态和控制寄存器(高)
  #define AW60_TPM2_CHVH(x)  (*(vuint8 *)(0x00000066+(x)*3))
  //定时器1通道状态和控制寄存器(低)
  #define AW60_TPM2_CHVL(x)  (*(vuint8 *)(0x00000067+(x)*3))
    
#endif    