uc-sdk
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
lpc17xx_rit.c
Go to the documentation of this file.
1
/***********************************************************************/
20
/* Peripheral group ----------------------------------------------------------- */
25
/* Includes ------------------------------------------------------------------- */
26
#include "
lpc17xx_rit.h
"
27
#include "
lpc17xx_clkpwr.h
"
28
29
/* If this source file built with example, the LPC17xx FW library configuration
30
* file in each example directory ("lpc17xx_libcfg.h") must be included,
31
* otherwise the default FW library configuration file must be included instead
32
*/
33
#ifdef __BUILD_WITH_EXAMPLE__
34
#include "lpc17xx_libcfg.h"
35
#else
36
#include "
lpc17xx_libcfg_default.h
"
37
#endif
/* __BUILD_WITH_EXAMPLE__ */
38
39
#ifdef _RIT
40
41
/* Public Functions ----------------------------------------------------------- */
46
/******************************************************************************/
/*
47
* @brief Initial for RIT
48
* - Turn on power and clock
49
* - Setup default register values
50
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
51
* @return None
52
*******************************************************************************/
53
void
RIT_Init
(
LPC_RIT_TypeDef
*RITx)
54
{
55
CHECK_PARAM
(
PARAM_RITx
(RITx));
56
CLKPWR_ConfigPPWR
(
CLKPWR_PCONP_PCRIT
,
ENABLE
);
57
//Set up default register values
58
RITx->
RICOMPVAL
= 0xFFFFFFFF;
59
RITx->
RIMASK
= 0x00000000;
60
RITx->
RICTRL
= 0x0C;
61
RITx->
RICOUNTER
= 0x00000000;
62
// Turn on power and clock
63
64
}
65
/******************************************************************************/
/*
66
* @brief DeInitial for RIT
67
* - Turn off power and clock
68
* - ReSetup default register values
69
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
70
* @return None
71
*******************************************************************************/
72
void
RIT_DeInit
(
LPC_RIT_TypeDef
*RITx)
73
{
74
CHECK_PARAM
(
PARAM_RITx
(RITx));
75
76
// Turn off power and clock
77
CLKPWR_ConfigPPWR
(
CLKPWR_PCONP_PCRIT
,
DISABLE
);
78
//ReSetup default register values
79
RITx->
RICOMPVAL
= 0xFFFFFFFF;
80
RITx->
RIMASK
= 0x00000000;
81
RITx->
RICTRL
= 0x0C;
82
RITx->
RICOUNTER
= 0x00000000;
83
}
84
85
/******************************************************************************/
/*
86
* @brief Set compare value, mask value and time counter value
87
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
88
* @param[in] time_interval: timer interval value (ms)
89
* @return None
90
*******************************************************************************/
91
void
RIT_TimerConfig
(
LPC_RIT_TypeDef
*RITx, uint32_t time_interval)
92
{
93
uint32_t clock_rate, cmp_value;
94
CHECK_PARAM
(
PARAM_RITx
(RITx));
95
96
// Get PCLK value of RIT
97
clock_rate =
CLKPWR_GetPCLK
(
CLKPWR_PCLKSEL_RIT
);
98
99
/* calculate compare value for RIT to generate interrupt at
100
* specified time interval
101
* COMPVAL = (RIT_PCLK * time_interval)/1000
102
* (with time_interval unit is millisecond)
103
*/
104
cmp_value = (clock_rate /1000) * time_interval;
105
RITx->
RICOMPVAL
= cmp_value;
106
107
/* Set timer enable clear bit to clear timer to 0 whenever
108
* counter value equals the contents of RICOMPVAL
109
*/
110
RITx->
RICTRL
|= (1<<1);
111
}
112
113
114
/******************************************************************************/
/*
115
* @brief Enable/Disable Timer
116
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
117
* @param[in] NewState New State of this function
118
* -ENABLE: Enable Timer
119
* -DISABLE: Disable Timer
120
* @return None
121
*******************************************************************************/
122
void
RIT_Cmd
(
LPC_RIT_TypeDef
*RITx,
FunctionalState
NewState)
123
{
124
CHECK_PARAM
(
PARAM_RITx
(RITx));
125
CHECK_PARAM
(
PARAM_FUNCTIONALSTATE
(NewState));
126
127
//Enable or Disable Timer
128
if
(NewState==
ENABLE
)
129
{
130
RITx->
RICTRL
|=
RIT_CTRL_TEN
;
131
}
132
else
133
{
134
RITx->
RICTRL
&= ~
RIT_CTRL_TEN
;
135
}
136
}
137
138
/******************************************************************************/
/*
139
* @brief Timer Enable/Disable on debug
140
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
141
* @param[in] NewState New State of this function
142
* -ENABLE: The timer is halted whenever a hardware break condition occurs
143
* -DISABLE: Hardware break has no effect on the timer operation
144
* @return None
145
*******************************************************************************/
146
void
RIT_TimerDebugCmd
(
LPC_RIT_TypeDef
*RITx,
FunctionalState
NewState)
147
{
148
CHECK_PARAM
(
PARAM_RITx
(RITx));
149
CHECK_PARAM
(
PARAM_FUNCTIONALSTATE
(NewState));
150
151
//Timer Enable/Disable on break
152
if
(NewState==
ENABLE
)
153
{
154
RITx->
RICTRL
|=
RIT_CTRL_ENBR
;
155
}
156
else
157
{
158
RITx->
RICTRL
&= ~
RIT_CTRL_ENBR
;
159
}
160
}
161
/******************************************************************************/
/*
162
* @brief Check whether interrupt flag is set or not
163
* @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
164
* @return Current interrupt status, could be: SET/RESET
165
*******************************************************************************/
166
IntStatus
RIT_GetIntStatus
(
LPC_RIT_TypeDef
*RITx)
167
{
168
uint8_t result;
169
CHECK_PARAM
(
PARAM_RITx
(RITx));
170
if
((RITx->
RICTRL
&
RIT_CTRL_INTEN
)==1) result=
SET
;
171
else
return
RESET
;
172
//clear interrupt flag
173
RITx->
RICTRL
|=
RIT_CTRL_INTEN
;
174
return
result;
175
}
176
181
#endif
/* _RIT */
182
187
/* --------------------------------- End Of File ------------------------------ */
arch
arm
lpc17xx
Drivers
source
lpc17xx_rit.c
Generated on Fri Nov 15 2013 05:00:16 for uc-sdk by
1.8.4