//-------------------------------------------------------------------------*
//文件名:  TMPCh.h (定时器和定时器通道设置头文件)                          *
//-------------------------------------------------------------------------*
#ifndef TPMCH_H             //防止重复定义
#define TPMCH_H
    //1 头文件
    #include "Type.h"           //类型别名定义
    #include <MC9S08AW60.h>  //映像寄存器地址头文件
    
    //2 中断宏定义
    #define EnableTPM1ChInInt(x)  AW60_TPM1_CHSCSTR(x) |=AW60_TPM_CHSCSTR_CHIE
                                                   //允许定时器1通道的输出比较中断
    #define DisableTPM1ChInInt(x) AW60_TPM1_CHSCSTR(x) &= ~AW60_TPM_CHSCSTR_CHIE
                                                   //禁止定时器1通道的输出比较中断
    #define EnableTPM2ChInInt(x)  AW60_TPM2_CHSCSTR(x) |=AW60_TPM_CHSCSTR_CHIE
                                                   //允许定时器2通道的输出比较中断
    #define DisableTPM2ChInInt(x) AW60_TPM2_CHSCSTR(x) &= ~AW60_TPM_CHSCSTR_CHIE
                                                   //禁止定时器2通道的输出比较中断                                         
 
    //3 函数声明
    //---------------------------------------------------------------------*
    //函数名:TPMChInit                                                     *
    //功能:初始化定时器通道                                                * 
    //参数:                                                                *
    //    (1)TPMNo:定时器号(1-2)                                           *
    //    (2)CHNo:通道号(定时器1通道号0-5,定时器2通道号0-1)                *
    //返回:无                                                              *
    //---------------------------------------------------------------------*
    void TPMChInit(uint8 TPMNo,uint8 CHNo);
    
    //4 寄存器有关的宏定义
    //标志位掩码的定义
    //定时器状态和控制寄存器各个位的掩码
    #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))
    //定时器1通道状态和控制寄存器
    #define  AW60_TPM1_CHSCSTR(x)  (*(vuint8 *)(0x00000025+(x)*3))
    //定时器2通道状态和控制寄存器
    #define AW60_TPM2_CHSCSTR(x)  (*(vuint8 *)(0x00000065+(x)*3))
    
#endif   