| 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
lpc18xx_43xx_systick_arch.c
Go to the documentation of this file.
1 /**********************************************************************
2 * @brief Setups up the LWIP timebase (tick)
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 #include "lwip/opt.h"
33
34 #if NO_SYS == 1
35
36 #include "chip.h"
37 #include "lpc_arch.h"
38
43 /*****************************************************************************
44 * Private types/enumerations/variables
45 ****************************************************************************/
46
47 /* Saved reference period foe standalone mode */
48 static uint32_t saved_period;
49
50 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
51
52 #define RITIMER_IRQn_PRI (255)
53
54 /* RITimer Reload value */
55 static uint32_t reload_val;
56 #endif
57
58 /* Saved total time in mS since timer was enabled */
59 static volatile u32_t systick_timems;
60
61 /*****************************************************************************
62 * Public types/enumerations/variables
63 ****************************************************************************/
64
65 /* Current system clock rate, mainly used for sysTick */
66 extern uint32_t SystemCoreClock;
67
68 /*****************************************************************************
69 * Private functions
70 ****************************************************************************/
71
72 /*****************************************************************************
73 * Public functions
74 ****************************************************************************/
75
76 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
77
78 /* Enable LWIP tick and interrupt */
79 void SysTick_Enable(uint32_t period)
80 {
81 saved_period = period;
82
83 /* Clear any pending interrupt */
84 Chip_RIT_ClearInt(LPC_RITIMER);
85
86 /* Calculate reload value */
87 reload_val = ( SystemCoreClock / ( 1000 / period ) );
88 Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Let it tick */
89
90 /* Set the priority and enable the interrupt */
91 NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, RITIMER_IRQn_PRI);
92 NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn);
93 }
94
95 /* Disable LWIP tick */
96 void SysTick_Disable(void)
97 {
98 Chip_RIT_Disable(LPC_RITIMER);
99 }
100
107 void RIT_IRQHandler(void)
108 {
109 /* Clear RITimer Interrupt, Reload counter value */
110 Chip_RIT_ClearInt(LPC_RITIMER);
111 Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */
112
113 /* Increment tick count */
114 systick_timems += saved_period;
115 }
116
117 #else
118
119 /* Enable LWIP tick and interrupt */
120 void SysTick_Enable(uint32_t period)
121 {
122 saved_period = period;
123 SysTick_Config((SystemCoreClock * period) / 1000);
124 }
125
126 /* Disable LWIP tick */
127 void SysTick_Disable(void)
128 {
129 SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
130 }
131
138 void SysTick_Handler(void)
139 {
140 /* Increment tick count */
141 systick_timems += saved_period;
142 }
143
144 #endif
145
146 /* Get the current systick time in milliSeconds */
147 uint32_t SysTick_GetMS(void)
148 {
149 return systick_timems;
150 }
151
152 /* Delay for the specified number of milliSeconds */
153 void msDelay(uint32_t ms)
154 {
155 uint32_t to = ms + systick_timems;
156
157 while (to > systick_timems) {}
158 }
159
165 u32_t sys_now(void)
166 {
167 return (u32_t) SysTick_GetMS();
168 }
169
174 #endif /* NO_SYS == 1 */