2 * @brief Multi-Rate Timer (MRT) registers and driver functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __MRT_001_H_
\r
33 #define __MRT_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_MRT_001 IP: MRT register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief MRT register block structure
\r
51 __IO uint32_t INTVAL; /*!< Timer interval register */
\r
52 __O uint32_t TIMER; /*!< Timer register */
\r
53 __IO uint32_t CTRL; /*!< Timer control register */
\r
54 __IO uint32_t STAT; /*!< Timer status register */
\r
58 * @brief MRT register bit fields & masks
\r
60 /* MRT Time interval register bit fields */
\r
61 #define IP_MRT_001_INTVAL_IVALUE (0xFFFFFF)
\r
62 #define IP_MRT_001_INTVAL_LOAD (1 << 31)
\r
64 /* MRT Control register bit fields & masks */
\r
65 #define IP_MRT_001_CTRL_MODE_REPEAT (0x00)
\r
66 #define IP_MRT_001_CTRL_MODE_ONESHOT (0x01)
\r
67 #define IP_MRT_001_CTRL_INTEN_MASK (0x01)
\r
68 #define IP_MRT_001_CTRL_MODE_POS (0x01)
\r
69 #define IP_MRT_001_CTRL_MODE_MASK (0x06)
\r
70 #define IP_MRT_001_CTRL_MODE_SHIFT(x) (x << 1)
\r
72 /* MRT Status register bit fields & masks */
\r
73 #define IP_MRT_001_STAT_INTFLAG (0x01)
\r
74 #define IP_MRT_001_STAT_RUNNING (0x02)
\r
77 * @brief MRT Interrupt Modes enum
\r
79 typedef enum IP_MRT_001_MODE {
\r
80 MRT_MODE_REPEAT = 0, /*!< MRT Repeat interrupt mode */
\r
81 MRT_MODE_ONESHOT = 1 /*!< MRT One-shot interrupt mode */
\r
82 } IP_MRT_001_MODE_T;
\r
85 * @brief Initializes the MRT
\r
88 STATIC INLINE void IP_MRT_Init(void)
\r
92 * @brief De-initializes the MRT Channel
\r
95 STATIC INLINE void IP_MRT_DeInit(void)
\r
99 * @brief Returns the timer time interval value
\r
100 * @param pMRT : Pointer to selected MRT Channel
\r
101 * @return The time interval value
\r
103 STATIC INLINE uint32_t IP_MRT_GetInterval(IP_MRT_001_T *pMRT)
\r
105 return (uint32_t) pMRT->INTVAL;
\r
109 * @brief Sets the timer time interval value
\r
110 * @param pMRT : Pointer to selected MRT Channel
\r
111 * @param interval : Time interval value (24-bits)
\r
113 * @note Setting bit 31 in time interval register causes the time interval
\r
114 * to load immediately, otherwise the load will occur on the
\r
117 STATIC INLINE void IP_MRT_SetInterval(IP_MRT_001_T *pMRT, uint32_t interval)
\r
119 pMRT->INTVAL = interval;
\r
123 * @brief Returns the current timer value
\r
124 * @param pMRT : Pointer to selected MRT Channel
\r
125 * @return The current timer value
\r
127 STATIC INLINE uint32_t IP_MRT_GetTimer(IP_MRT_001_T *pMRT)
\r
129 return (uint32_t) pMRT->TIMER;
\r
133 * @brief Returns true if the timer is enabled
\r
134 * @param pMRT : Pointer to selected MRT Channel
\r
135 * @return True if enabled, False if not enabled
\r
137 STATIC INLINE bool IP_MRT_GetEnabled(IP_MRT_001_T *pMRT)
\r
139 return (bool) (pMRT->CTRL & IP_MRT_001_CTRL_INTEN_MASK);
\r
143 * @brief Enables the timer
\r
144 * @param pMRT : Pointer to selected MRT Channel
\r
147 STATIC INLINE void IP_MRT_SetEnabled(IP_MRT_001_T *pMRT)
\r
149 pMRT->CTRL |= IP_MRT_001_CTRL_INTEN_MASK;
\r
153 * @brief Returns the timer mode (repeat or one-shot).
\r
154 * @param pMRT : Pointer to selected MRT Channel
\r
155 * @return The mode (repeat or one-shot).
\r
157 STATIC INLINE IP_MRT_001_MODE_T IP_MRT_GetMode(IP_MRT_001_T *pMRT)
\r
159 return (IP_MRT_001_MODE_T) ((pMRT->CTRL & IP_MRT_001_CTRL_MODE_MASK) >> 1);
\r
163 * @brief Sets the timer mode to be repeat or one-shot.
\r
164 * @param pMRT : Pointer to selected MRT Channel
\r
165 * @param mode : 0 = repeat, 1 = one-shot
\r
168 STATIC INLINE void IP_MRT_SetMode(IP_MRT_001_T *pMRT, IP_MRT_001_MODE_T mode)
\r
170 pMRT->CTRL |= IP_MRT_001_CTRL_MODE_SHIFT(mode);
\r
174 * @brief Returns true if the timer is configured in repeat mode.
\r
175 * @param pMRT : Pointer to selected MRT Channel
\r
176 * @return True if in repeat mode, False if in one-shot mode
\r
178 STATIC INLINE bool IP_MRT_IsRepeatMode(IP_MRT_001_T *pMRT)
\r
180 return ((pMRT->CTRL & IP_MRT_001_CTRL_MODE_MASK) > 0) ? false : true;
\r
184 * @brief Returns true if the timer is configured in one-shot mode.
\r
185 * @param pMRT : Pointer to selected MRT Channel
\r
186 * @return True if in one-shot mode, False if in repeat mode.
\r
188 STATIC INLINE bool IP_MRT_IsOneShotMode(IP_MRT_001_T *pMRT)
\r
190 return ((pMRT->CTRL & IP_MRT_001_CTRL_MODE_MASK) > 0) ? true : false;
\r
194 * @brief Returns true if the timer has an interrupt pending.
\r
195 * @param pMRT : Pointer to selected MRT Channel
\r
196 * @return True if interrupt is pending, False if no interrupt is pending.
\r
198 STATIC INLINE bool IP_MRT_IntPending(IP_MRT_001_T *pMRT)
\r
200 return (bool) (pMRT->STAT & IP_MRT_001_STAT_INTFLAG);
\r
204 * @brief Clears the pending interrupt (if any).
\r
205 * @param pMRT : Pointer to selected MRT Channel
\r
208 STATIC INLINE void IP_MRT_IntClear(IP_MRT_001_T *pMRT)
\r
210 pMRT->STAT |= IP_MRT_001_STAT_INTFLAG;
\r
214 * @brief Returns true if the timer is running.
\r
215 * @param pMRT : Pointer to selected MRT Channel
\r
216 * @return True if running, False if stopped.
\r
218 STATIC INLINE bool IP_MRT_Running(IP_MRT_001_T *pMRT)
\r
220 return (bool) (pMRT->STAT & IP_MRT_001_STAT_RUNNING);
\r
231 #endif /* __MRT_001_H_ */
\r