LPCOpen Platform for LPC112X microcontrollers  112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
FreeRTOS_lpc43xx_m0_Tick.c
Go to the documentation of this file.
1 /*
2  * @brief FreeRTOS LPC43xx M0 core tick function using RITimer
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 "chip.h"
33 #include "FreeRTOS.h"
34 
43  #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
44 
45  /*****************************************************************************
46  * Private types/enumerations/variables
47  ****************************************************************************/
48 
49 #define portNVIC_PENDSVSET 0x10000000
50 #ifndef portNVIC_INT_CTRL
51 #define portNVIC_INT_CTRL ((volatile unsigned long *) 0xe000ed04)
52 #endif
53 #define portMIN_INTERRUPT_PRIORITY (255UL)
54 #define portNVIC_SYSTICK_PRI portMIN_INTERRUPT_PRIORITY
55 
56 #define RITENCLR (1 << 1)
57 #define RITINT (1 << 0)
58 
59 /* Timer reload value for next tick */
60 static uint32_t reload_val;
61 
62 /*****************************************************************************
63  * Public types/enumerations/variables
64  ****************************************************************************/
65 
66 /* FreeRTOS tick update function */
67 extern BaseType_t xTaskIncrementTick(void);
68 
69 /*****************************************************************************
70  * Private functions
71  ****************************************************************************/
72 
73 /*****************************************************************************
74  * Public functions
75  ****************************************************************************/
76 
82 void RIT_IRQHandler(void)
83 {
84  unsigned long ulPreviousMask;
85 
86  /* TODO: check if WWDT interrupt and redirect */
87  Chip_RIT_ClearInt(LPC_RITIMER);
88  Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */
89 
90 #if configUSE_PREEMPTION == 1
91  /* If using preemption, also force a context switch. */
92  *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
93 #endif
94 
95  ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR();
96  {
97  /* Increment the RTOS tick. */
98  if( xTaskIncrementTick() != pdFALSE )
99  {
100  /* Pend a context switch. */
101  *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
102  }
103  }
104  portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask );
105 }
106 
113 void ritimer_setup(void)
114 {
115  /* Clear any pending interrupt */
116  Chip_RIT_ClearInt(LPC_RITIMER);
117 
118  /* Calculate reload value */
119  reload_val = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);
120  Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Start tick */
121 
122  /* Set the priority and enable the interrupt */
123  NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, portNVIC_SYSTICK_PRI);
124  NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn);
125 }
126 
127 #endif
128