1 /**********************************************************************
\r
2 * $Id$ lpc18xx_atimer.c 2011-06-02
\r
4 * @file lpc18xx_atimer.c
\r
5 * @brief Contains all functions support for Alarm Timer firmware
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
28 /** @addtogroup ATIMER
\r
32 /* Includes ------------------------------------------------------------------- */
\r
33 #include "lpc18xx_atimer.h"
\r
34 #include "lpc18xx_cgu.h"
\r
36 /* If this source file built with example, the LPC18xx FW library configuration
\r
37 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
38 * otherwise the default FW library configuration file must be included instead
\r
40 #ifdef __BUILD_WITH_EXAMPLE__
\r
41 #include "lpc18xx_libcfg.h"
\r
43 #include "lpc18xx_libcfg_default.h"
\r
44 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
48 /* Private Functions ---------------------------------------------------------- */
\r
50 /*********************************************************************//**
\r
51 * @brief Initial Alarm Timer device
\r
52 * @param[in] ATIMERx Timer selection, should be: LPC_ATIMER
\r
53 * @param[in] PresetValue Count of 1/1024s for Alarm
\r
55 **********************************************************************/
\r
56 void ATIMER_Init(LPC_ATIMER_Type *ATIMERx, uint32_t PresetValue)
\r
58 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
61 if (ATIMERx== LPC_ATIMER)
\r
64 CGU_EnableEntity(CGU_CLKSRC_32KHZ_OSC, ENABLE);
\r
67 ATIMER_UpdatePresetValue(ATIMERx, PresetValue);
\r
68 // Clear interrupt pending
\r
69 ATIMER_ClearIntStatus(ATIMERx);
\r
73 /*********************************************************************//**
\r
74 * @brief Close ATIMER device
\r
75 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
77 **********************************************************************/
\r
78 void ATIMER_DeInit (LPC_ATIMER_Type *ATIMERx)
\r
80 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
82 ATIMER_ClearIntStatus(ATIMERx);
\r
83 ATIMER_IntDisable(ATIMERx);
\r
86 // if (ATIMERx== LPC_ATIMER0)
\r
87 // CGU_ConfigPPWR (CGU_PCONP_PCATIMER0, DISABLE);
\r
91 /*********************************************************************//**
\r
92 * @brief Clear ATIMER Interrupt Status
\r
93 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
95 **********************************************************************/
\r
96 void ATIMER_ClearIntStatus(LPC_ATIMER_Type *ATIMERx)
\r
98 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
99 ATIMERx->CLR_STAT = 1;
\r
100 while((ATIMERx->STATUS & 1) == 1);
\r
103 /*********************************************************************//**
\r
104 * @brief Set ATIMER Interrupt Status
\r
105 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
107 **********************************************************************/
\r
108 void ATIMER_SetIntStatus(LPC_ATIMER_Type *ATIMERx)
\r
110 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
111 ATIMERx->SET_STAT = 1;
\r
112 while((ATIMERx->STATUS & 1) == 0);
\r
115 /*********************************************************************//**
\r
116 * @brief Enable ATIMER Interrupt
\r
117 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
119 **********************************************************************/
\r
120 void ATIMER_IntEnable(LPC_ATIMER_Type *ATIMERx)
\r
122 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
123 ATIMERx->SET_EN = 1;
\r
124 while((ATIMERx->ENABLE & 1) == 0);
\r
127 /*********************************************************************//**
\r
128 * @brief Disable ATIMER Interrupt
\r
129 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
131 **********************************************************************/
\r
132 void ATIMER_IntDisable(LPC_ATIMER_Type *ATIMERx)
\r
134 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
135 ATIMERx->CLR_EN = 1;
\r
136 while((ATIMERx->ENABLE & 1) == 1);
\r
138 /*********************************************************************//**
\r
139 * @brief Update Preset value
\r
140 * @param[in] ATIMERx Pointer to timer device, should be: LPC_ATIMER
\r
141 * @param[in] PresetValue updated preset value
\r
143 **********************************************************************/
\r
144 void ATIMER_UpdatePresetValue(LPC_ATIMER_Type *ATIMERx,uint32_t PresetValue)
\r
146 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
147 ATIMERx->PRESET = PresetValue;
\r
150 /*********************************************************************//**
\r
151 * @brief Read value of preset register
\r
152 * @param[in] ATIMERx Pointer to timer/counter device, should be: LPC_ATIMER
\r
153 * @return Value of capture register
\r
154 **********************************************************************/
\r
155 uint32_t ATIMER_GetPresetValue(LPC_ATIMER_Type *ATIMERx)
\r
157 CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
\r
158 return ATIMERx->PRESET;
\r
164 #endif /* _ATIMER */
\r
170 /* --------------------------------- End Of File ------------------------------ */
\r