1 /** 2 ***************************************************************************** 3 * @file cmem7_tim.c 4 * 5 * @brief CMEM7 timer source file 6 * 7 * 8 * @version V1.0 9 * @date 3. September 2013 10 * 11 * @note 12 * 13 ***************************************************************************** 14 * @attention 15 * 16 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 17 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 18 * TIME. AS A RESULT, CAPITAL-MICRO SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 19 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 20 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 21 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 22 * 23 * <h2><center>© COPYRIGHT 2013 Capital-micro </center></h2> 24 ***************************************************************************** 25 */ 26 27 #include "cmem7_tim.h" 28 tim_GetClock()29static uint32_t tim_GetClock() { 30 return SYSTEM_CLOCK_FREQ / (1 << (GLOBAL_CTRL->CLK_SEL_0_b.TIMER_CLK + 1)); 31 } 32 TIM_Init(TIMER0_Type * Timx,uint16_t Ms)33void TIM_Init(TIMER0_Type* Timx, uint16_t Ms) { 34 assert_param(IS_TIM_ALL_PERIPH(Timx)); 35 36 Timx->CTRL_b.EN = FALSE; 37 Timx->LEN = tim_GetClock() / 1000 * Ms; 38 Timx->TYPE_b.SIGNLE_SHOT = TRUE; 39 } 40 TIM_EnableInt(TIMER0_Type * Timx,BOOL Enable)41void TIM_EnableInt(TIMER0_Type* Timx, BOOL Enable) { 42 assert_param(IS_TIM_ALL_PERIPH(Timx)); 43 44 if (Enable == TRUE) { 45 Timx->INT_EN_b.EN_REVERSE = FALSE; 46 } else { 47 Timx->INT_EN_b.EN_REVERSE = TRUE; 48 } 49 } 50 TIM_GetIntStatus(TIMER0_Type * Timx)51BOOL TIM_GetIntStatus(TIMER0_Type* Timx) { 52 assert_param(IS_TIM_ALL_PERIPH(Timx)); 53 54 return (Timx->INT_STA_b.STA ? TRUE : FALSE); 55 } 56 TIM_ClearInt(TIMER0_Type * Timx)57void TIM_ClearInt(TIMER0_Type* Timx) { 58 assert_param(IS_TIM_ALL_PERIPH(Timx)); 59 60 Timx->INT_STA_b.STA = 1; 61 } 62 TIM_Enable(TIMER0_Type * Timx,BOOL Enable)63void TIM_Enable(TIMER0_Type* Timx, BOOL Enable) { 64 assert_param(IS_TIM_ALL_PERIPH(Timx)); 65 66 Timx->CTRL_b.EN = Enable; 67 } 68 TIM_IsOverflow(TIMER0_Type * Timx)69BOOL TIM_IsOverflow(TIMER0_Type* Timx) { 70 assert_param(IS_TIM_ALL_PERIPH(Timx)); 71 72 return (Timx->CNT == 0) ? TRUE : FALSE; 73 } 74 TIM_GetCounter(TIMER0_Type * Timx)75uint32_t TIM_GetCounter(TIMER0_Type* Timx) { 76 assert_param(IS_TIM_ALL_PERIPH(Timx)); 77 78 return Timx->CNT; 79 } 80 81