/**
  ******************************************************************************
  * @file    TIMER_CFG.h
  * @author  SINOMCU-AE
  * @brief   Header file of TIMER_CFG.c file.
  *     
  *          This file describes the Timer macro definitions used:
  *    USER_TIMER1 or USER_TIMER2;
  *    UIF time setting macro.
  * 
  ******************************************************************************
  * @attention 
  *                           DISCLAIMER
  * The present firmware which is for guidance only aims at providing customers
  * with coding information regarding their products in order for them to save
  * time. As a result, SinoMCU shall not be held liable for any direct,indirect
  * or consequential damages with respect to any claims arising from the content 
  * of such firmware and/or the use made by customers of the coding information 
  * contained herein in connection with their products.
  *
  * <h2><center>&copy; Copyright (c) 2021 sinomcu All rights reserved.</center></h2>
  *
  ******************************************************************************
  */

#ifndef __TIMER_CFG_H
#define __TIMER_CFG_H

#include "ms32f0xx.h"

#define USER_TIMER1               1         // 1:use timer1,0:not use timer1
#define USER_TIMER2               0         // 1:use timer2,0:not use timer2

#if( USER_TIMER1 && USER_TIMER2)
#error "Select timer1 or timer2,not both of them"
#endif

#if( !(USER_TIMER1 || USER_TIMER2) )
#error "Select timer1 or timer2,must select one of them"
#endif

// APB1 Persacler 1,TIMclk =sysclk(8M)
#if( defined(USER_TIMER1) && USER_TIMER1)
#define USER_APB1_GRP2_PERIPH_TIMER   MS32_APB1_GRP2_PERIPH_TIM1
#define USER_TIMER_IRQn               TIM1_BRK_UP_TRG_COM_IRQn
#define USER_TIMER                    TIM1
#define USER_TIMER_BASIC_IRQHandler   TIM1_BRK_UP_TRG_COM_IRQHandler

#define USER_TIMER_PRESCALER          7          // 16bit,CK_CNT=TIMclk/(PSD+1)
#define USER_TIMER_AUTORELOAD         999U       // 16bit,CK_CNT*(USER_TIMER_AUTORELOAD+1),(0 ~ USER_TIMER_AUTORELOAD)
#define USER_TIMER_REPETCOUNT         249        // 8bit,UIF REPETCOUNT*(CK_CNT*(USER_TIMER_AUTORELOAD+1))
                                                 // CK_CNT 8M UIF 250ms
#endif

#if( defined(USER_TIMER2) && USER_TIMER2)
#define USER_APB1_GRP2_PERIPH_TIMER   MS32_APB1_GRP1_PERIPH_TIM2
#define USER_TIMER_IRQn               TIM2_IRQn
#define USER_TIMER                    TIM2
#define USER_TIMER_BASIC_IRQHandler   TIM2_IRQHandler

#define USER_TIMER_PRESCALER          7          // 16bit,CK_CNT=TIMclk/(PSD+1)
#define USER_TIMER_AUTORELOAD         99999U     // 32bit,CK_CNT*(USER_TIMER_AUTORELOAD+1),(0 ~ USER_TIMER_AUTORELOAD)
                                                 // 100ms
#endif

void Timer_Basic_Init(void);

#endif /* __TIMER_CFG_H */ 

/******************************** END OF FILE *********************************/
