| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc43xx_systick.c
Go to the documentation of this file.
1 /*
2 * @brief System Tick module functions for stand-alone configuration
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 // FIXME - is this file needed? outside of norm.
38 #include "chip.h"
39 #include "board.h"
40
41 #include "GUI.h"
42
72 /*****************************************************************************
73 * Private types/enumerations/variables
74 ****************************************************************************/
75 /* Saved reference period */
76 static uint32_t saved_period;
77 static int16_t old_tmp_x = -1, old_tmp_y = -1;
78
79 /* Check every 20ms for TSC events */
80 #define TSC_CHECK_DELAY (20)
81
82 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
83
84 #define RITIMER_IRQn_PRI (255)
85
86 /* RITimer Reload value */
87 static uint32_t reload_val;
88 #endif
89
90 /*****************************************************************************
91 * Public types/enumerations/variables
92 ****************************************************************************/
93
97 /* Saved total time in mS since timer was enabled */
98 volatile uint32_t systick_timems;
99
103 extern volatile int tsc_init_done;
104
108 extern uint32_t SystemCoreClock;
109
110 /*****************************************************************************
111 * Private functions
112 ****************************************************************************/
113
114 /*****************************************************************************
115 * Public functions
116 ****************************************************************************/
117
118 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
119
128 void SysTick_Enable(uint32_t period)
129 {
130 saved_period = period;
131
132 /* Clear any pending interrupt */
133 Chip_RIT_ClearInt(LPC_RITIMER);
134
135 /* Calculate reload value */
136 reload_val = ( SystemCoreClock / ( 1000 / period ) );
137 Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Let it tick */
138
139 /* Set the priority and enable the interrupt */
140 NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, RITIMER_IRQn_PRI);
141 NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn);
142 }
143
151 void SysTick_Disable(void)
152 {
153 Chip_RIT_Disable(LPC_RITIMER);
154 }
155
165 void RIT_IRQHandler(void)
166 {
167 int16_t tmp_x = -1, tmp_y = -1;
168 int16_t tmp_x1 = -1, tmp_y1 = -1;
169 static uint8_t tsc_tick = 0;
170 static uint8_t pressed = 0;
171 bool touched;
172
173 /* Clear RITimer Interrupt, Reload counter value */
174 Chip_RIT_ClearInt(LPC_RITIMER);
175 Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */
176
177 /* Increment tick count */
178 systick_timems += saved_period;
179
180 /* If TSC enabled, store Touch event */
181 if (tsc_init_done) {
182 tsc_tick += saved_period;
183 if (tsc_tick == TSC_CHECK_DELAY) {
184 touched = Board_GetTouchPos((int16_t *) &tmp_x, (int16_t *) &tmp_y);
185 if (touched == true) {
186 if (pressed == 1) {
187 if ((tmp_x >= 0) && (tmp_y > 0) && ((tmp_x != old_tmp_x) || (tmp_y != old_tmp_y))) {
188 tmp_x1 = tmp_y;
189 tmp_y1 = tmp_x;
190 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
191 old_tmp_x = tmp_x;
192 old_tmp_y = tmp_y;
193 }
194 }
195 else {
196 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
197 old_tmp_x = tmp_x;
198 old_tmp_y = tmp_y;
199 pressed = 1;
200 }
201 }
202 else {
203 if (pressed == 1) {
204 GUI_TOUCH_StoreState(-1, -1);
205 pressed = 0;
206 }
207 }
208 tsc_tick = 0;
209 }
210 }
211 }
212
213 #else
214
223 void SysTick_Enable(uint32_t period)
224 {
225 saved_period = period;
226 SysTick_Config((SystemCoreClock * period) / 1000);
227 }
228
234 void SysTick_Disable(void)
235 {
236 SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
237 }
238
247 void SysTick_Handler(void)
248 {
249 int16_t tmp_x = -1, tmp_y = -1;
250 int16_t tmp_x1 = -1, tmp_y1 = -1;
251 static uint8_t tsc_tick = 0;
252 static uint8_t pressed = 0;
253 bool touched;
254
255 /* Increment tick count */
256 systick_timems += saved_period;
257
258 /* If TSC enabled, store Touch event */
259 if (tsc_init_done) {
260 tsc_tick += saved_period;
261 if (tsc_tick == TSC_CHECK_DELAY) {
262 touched = Board_GetTouchPos((int16_t *) &tmp_x, (int16_t *) &tmp_y);
263 if (touched == true) {
264 if (pressed == 1) {
265 if ((tmp_x >= 0) && (tmp_y > 0) && ((tmp_x != old_tmp_x) || (tmp_y != old_tmp_y))) {
266 tmp_x1 = tmp_y;
267 tmp_y1 = tmp_x;
268 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
269 old_tmp_x = tmp_x;
270 old_tmp_y = tmp_y;
271 }
272 }
273 else {
274 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
275 old_tmp_x = tmp_x;
276 old_tmp_y = tmp_y;
277 pressed = 1;
278 }
279 }
280 else {
281 if (pressed == 1) {
282 GUI_TOUCH_StoreState(-1, -1);
283 pressed = 0;
284 }
285 }
286 tsc_tick = 0;
287 }
288 }
289 }
290
291 #endif
292
300 void msDelay(uint32_t ms)
301 {
302 uint32_t to = ms + systick_timems;
303
304 while (to > systick_timems) {}
305 }
306
312 uint32_t sys_now(void)
313 {
314 return systick_timems;;
315 }
316
321 /* --------------------------------- End Of File ------------------------------ */