1 /**********************************************************************
\r
2 * $Id$ lpc18xx_rit.c 2011-06-02
\r
4 * @file lpc18xx_rit.c
\r
5 * @brief Contains all functions support for RIT firmware library on LPC18xx
\r
7 * @date 02. June. 2011
\r
8 * @author NXP MCU SW Application Team
\r
10 * Copyright(C) 2011, NXP Semiconductor
\r
11 * All rights reserved.
\r
13 ***********************************************************************
\r
14 * Software that is described herein is for illustrative purposes only
\r
15 * which provides customers with programming information regarding the
\r
16 * products. This software is supplied "AS IS" without any warranties.
\r
17 * NXP Semiconductors assumes no responsibility or liability for the
\r
18 * use of the software, conveys no license or title under any patent,
\r
19 * copyright, or mask work right to the product. NXP Semiconductors
\r
20 * reserves the right to make changes in the software without
\r
21 * notification. NXP Semiconductors also make no representation or
\r
22 * warranty that such application will be suitable for the specified
\r
23 * use without further testing or modification.
\r
24 **********************************************************************/
\r
26 /* Peripheral group ----------------------------------------------------------- */
\r
31 /* Includes ------------------------------------------------------------------- */
\r
32 #include "lpc18xx_rit.h"
\r
33 #include "lpc18xx_cgu.h"
\r
35 /* If this source file built with example, the LPC18xx FW library configuration
\r
36 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
37 * otherwise the default FW library configuration file must be included instead
\r
39 #ifdef __BUILD_WITH_EXAMPLE__
\r
40 #include "lpc18xx_libcfg.h"
\r
42 #include "lpc18xx_libcfg_default.h"
\r
43 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
47 /* Public Functions ----------------------------------------------------------- */
\r
48 /** @addtogroup RIT_Public_Functions
\r
52 /******************************************************************************//*
\r
53 * @brief Initial for RIT
\r
54 * - Turn on power and clock
\r
55 * - Setup default register values
\r
56 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
58 *******************************************************************************/
\r
59 void RIT_Init(LPC_RITIMER_Type *RITx)
\r
61 CHECK_PARAM(PARAM_RITx(RITx));
\r
62 //CGU_ConfigPPWR (CGU_PCONP_PCRIT, ENABLE);
\r
63 //Set up default register values
\r
64 RITx->COMPVAL = 0xFFFFFFFF;
\r
65 RITx->MASK = 0x00000000;
\r
67 RITx->COUNTER = 0x00000000;
\r
68 // Turn on power and clock
\r
71 /******************************************************************************//*
\r
72 * @brief DeInitial for RIT
\r
73 * - Turn off power and clock
\r
74 * - ReSetup default register values
\r
75 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
77 *******************************************************************************/
\r
78 void RIT_DeInit(LPC_RITIMER_Type *RITx)
\r
80 CHECK_PARAM(PARAM_RITx(RITx));
\r
82 // Turn off power and clock
\r
83 //CGU_ConfigPPWR (CGU_PCONP_PCRIT, DISABLE);
\r
84 //ReSetup default register values
\r
85 RITx->COMPVAL = 0xFFFFFFFF;
\r
86 RITx->MASK = 0x00000000;
\r
88 RITx->COUNTER = 0x00000000;
\r
91 /******************************************************************************//*
\r
92 * @brief Set compare value, mask value and time counter value
\r
93 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
94 * @param[in] time_interval timer interval value (ms)
\r
96 *******************************************************************************/
\r
98 void RIT_TimerConfig(LPC_RITIMER_Type *RITx, uint32_t time_interval)
\r
100 uint32_t clock_rate, cmp_value;
\r
101 CHECK_PARAM(PARAM_RITx(RITx));
\r
103 // Get PCLK value of RIT
\r
104 clock_rate = /*CGU_GetPCLK(CGU_PCLKSEL_RIT)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE);
\r
106 /* calculate compare value for RIT to generate interrupt at
\r
107 * specified time interval
\r
108 * COMPVAL = (RIT_PCLK * time_interval)/1000
\r
109 * (with time_interval unit is millisecond)
111 cmp_value = (clock_rate /1000) * time_interval;
\r
112 RITx->COMPVAL = cmp_value;
\r
114 /* Set timer enable clear bit to clear timer to 0 whenever
\r
115 * counter value equals the contents of RICOMPVAL
117 RITx->CTRL |= (1<<1);
\r
121 /******************************************************************************//*
\r
122 * @brief Enable/Disable Timer
\r
123 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
124 * @param[in] NewState New State of this function
\r
125 * -ENABLE :Enable Timer
\r
126 * -DISABLE :Disable Timer
\r
128 *******************************************************************************/
\r
129 void RIT_Cmd(LPC_RITIMER_Type *RITx, FunctionalState NewState)
\r
131 CHECK_PARAM(PARAM_RITx(RITx));
\r
132 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
134 //Enable or Disable Timer
\r
135 if(NewState==ENABLE)
\r
137 RITx->CTRL |= RIT_CTRL_TEN;
\r
141 RITx->CTRL &= ~RIT_CTRL_TEN;
\r
145 /******************************************************************************//*
\r
146 * @brief Timer Enable/Disable on debug
\r
147 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
148 * @param[in] NewState New State of this function
\r
149 * -ENABLE :The timer is halted whenever a hardware break condition occurs
\r
150 * -DISABLE :Hardware break has no effect on the timer operation
\r
152 *******************************************************************************/
\r
153 void RIT_TimerDebugCmd(LPC_RITIMER_Type *RITx, FunctionalState NewState)
\r
155 CHECK_PARAM(PARAM_RITx(RITx));
\r
156 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
158 //Timer Enable/Disable on break
\r
159 if(NewState==ENABLE)
\r
161 RITx->CTRL |= RIT_CTRL_ENBR;
\r
165 RITx->CTRL &= ~RIT_CTRL_ENBR;
\r
168 /******************************************************************************//*
\r
169 * @brief Check whether interrupt flag is set or not
\r
170 * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
\r
171 * @return Current interrupt status, could be
\r
174 *******************************************************************************/
\r
175 IntStatus RIT_GetIntStatus(LPC_RITIMER_Type *RITx)
\r
178 CHECK_PARAM(PARAM_RITx(RITx));
\r
179 if((RITx->CTRL&RIT_CTRL_INTEN)==1) result= SET;
\r
181 //clear interrupt flag
\r
182 RITx->CTRL |= RIT_CTRL_INTEN;
\r
183 return (IntStatus)result;
\r
196 /* --------------------------------- End Of File ------------------------------ */
\r