]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_CEC1302_Keil_GCC/main_full/IntQueueTimer.c
Rename CORTEX_M4F_CEC1302_Keil to CORTEX_M4F_CEC1302_Keil_GCC as it now contains...
[freertos] / FreeRTOS / Demo / CORTEX_M4F_CEC1302_Keil_GCC / main_full / IntQueueTimer.c
1 /*\r
2     FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * This file initialises three timers as follows:\r
72  *\r
73  * Basic timer channels 0 and 1 provide the interrupts that are used with the\r
74  * IntQ standard demo tasks, which test interrupt nesting and using queues from\r
75  * interrupts.  The interrupts use slightly different frequencies so will\r
76  * occasionally nest.\r
77  *\r
78  * Basic timer channel 2 provides a much higher frequency timer that tests the\r
79  * nesting of interrupts that don't use the FreeRTOS API.\r
80  *\r
81  * All the timers can nest with the tick interrupt - creating a maximum\r
82  * interrupt nesting depth of 4 (which is shown as a max nest count of 3 as the\r
83  * tick interrupt does not increment the nesting count variable).\r
84  *\r
85  */\r
86 \r
87 /* Scheduler includes. */\r
88 #include "FreeRTOS.h"\r
89 #include "task.h"\r
90 \r
91 /* Demo includes. */\r
92 #include "IntQueueTimer.h"\r
93 #include "IntQueue.h"\r
94 \r
95 /* Library includes. */\r
96 #include "common_lib.h"\r
97 #include "peripheral_library/interrupt/interrupt.h"\r
98 #include "peripheral_library/basic_timer/btimer.h"\r
99 \r
100 /* The frequencies at which the first two timers expire are slightly offset to\r
101 ensure they don't remain synchronised.  The frequency of the highest priority\r
102 interrupt is 20 times faster so really hammers the interrupt entry and exit\r
103 code. */\r
104 #define tmrTIMER_0_FREQUENCY    ( 2000UL )\r
105 #define tmrTIMER_1_FREQUENCY    ( 2003UL )\r
106 #define tmrTIMER_2_FREQUENCY    ( 20000UL )\r
107 \r
108 /* The basic timer channels used for generating the three interrupts. */\r
109 #define tmrTIMER_CHANNEL_0              0 /* At tmrTIMER_0_FREQUENCY */\r
110 #define tmrTIMER_CHANNEL_1              1 /* At tmrTIMER_1_FREQUENCY */\r
111 #define tmrTIMER_CHANNEL_2              2 /* At tmrTIMER_2_FREQUENCY */\r
112 \r
113 /* The high frequency interrupt is given a priority above the maximum at which\r
114 interrupt safe FreeRTOS calls can be made.  The priority of the lower frequency\r
115 timers must still be above the tick interrupt priority. */\r
116 #define tmrLOWER_PRIORITY               ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1 )\r
117 #define tmrMEDIUM_PRIORITY              ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 0 )\r
118 #define tmrHIGHER_PRIORITY              ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1 )\r
119 \r
120 /* Hardware register locations. */\r
121 #define tmrGIRQ23_ENABLE_SET                    ( * ( volatile uint32_t * ) 0x4000C130 )\r
122 #define tmrMMCR_EC_INTERRUPT_CONTROL    ( * ( volatile uint8_t * ) 0x4000FC18 )\r
123 \r
124 #define tmrRECORD_NESTING_DEPTH()                                               \\r
125         ulNestingDepth++;                                                                       \\r
126         if( ulNestingDepth > ulMaxRecordedNestingDepth )        \\r
127         {                                                                                                       \\r
128                 ulMaxRecordedNestingDepth = ulNestingDepth;             \\r
129         }\r
130 \r
131 /* Used to count the nesting depth, and record the maximum nesting depth. */\r
132 volatile uint32_t ulNestingDepth = 0, ulMaxRecordedNestingDepth = 0;\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 void vInitialiseTimerForIntQueueTest( void )\r
137 {\r
138 const uint32_t ulTimer0Count = configCPU_CLOCK_HZ / tmrTIMER_0_FREQUENCY;\r
139 const uint32_t ulTimer1Count = configCPU_CLOCK_HZ / tmrTIMER_1_FREQUENCY;\r
140 const uint32_t ulTimer2Count = configCPU_CLOCK_HZ / tmrTIMER_2_FREQUENCY;\r
141 \r
142         tmrGIRQ23_ENABLE_SET = 0x03;\r
143         tmrMMCR_EC_INTERRUPT_CONTROL = 1; \r
144         \r
145         /* Initialise the three timers as described at the top of this file, and \r
146         enable their interrupts in the NVIC. */\r
147         btimer_init( tmrTIMER_CHANNEL_0, BTIMER_AUTO_RESTART | BTIMER_COUNT_DOWN | BTIMER_INT_EN, 0, ulTimer0Count, ulTimer0Count );\r
148         btimer_interrupt_status_get_clr( tmrTIMER_CHANNEL_0 );  \r
149         enable_timer0_irq();\r
150         NVIC_SetPriority( TIMER0_IRQn, tmrLOWER_PRIORITY ); //0xc0 into 0xe000e431\r
151         NVIC_ClearPendingIRQ( TIMER0_IRQn );\r
152         NVIC_EnableIRQ( TIMER0_IRQn );\r
153         btimer_start( tmrTIMER_CHANNEL_0 );\r
154 \r
155         btimer_init( tmrTIMER_CHANNEL_1, BTIMER_AUTO_RESTART | BTIMER_COUNT_DOWN | BTIMER_INT_EN, 0, ulTimer1Count, ulTimer1Count );\r
156         btimer_interrupt_status_get_clr( tmrTIMER_CHANNEL_1 );\r
157         enable_timer1_irq();\r
158         NVIC_SetPriority( TIMER1_IRQn, tmrMEDIUM_PRIORITY ); //0xa0 into 0xe000e432\r
159         NVIC_ClearPendingIRQ( TIMER1_IRQn );\r
160         NVIC_EnableIRQ( TIMER1_IRQn );\r
161         btimer_start( tmrTIMER_CHANNEL_1 );\r
162 \r
163         btimer_init( tmrTIMER_CHANNEL_2, BTIMER_AUTO_RESTART | BTIMER_COUNT_DOWN | BTIMER_INT_EN, 0, ulTimer2Count, ulTimer2Count );\r
164         btimer_interrupt_status_get_clr( tmrTIMER_CHANNEL_2 );\r
165         enable_timer2_irq();\r
166         NVIC_SetPriority( TIMER2_IRQn, tmrHIGHER_PRIORITY );\r
167         NVIC_ClearPendingIRQ( TIMER2_IRQn );\r
168         NVIC_EnableIRQ( TIMER2_IRQn );\r
169         btimer_start( tmrTIMER_CHANNEL_2 );\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 /* The TMR0 interrupt is used for different purposes by the low power and full\r
174 demos respectively. */\r
175 #if( configCREATE_LOW_POWER_DEMO == 0 )\r
176 \r
177         void NVIC_Handler_TMR0( void )\r
178         {\r
179                 tmrRECORD_NESTING_DEPTH();\r
180 \r
181                 /* Call the IntQ test function for this channel. */\r
182                 portYIELD_FROM_ISR( xFirstTimerHandler() );\r
183 \r
184                 ulNestingDepth--;\r
185         }\r
186 \r
187 #endif /* configCREATE_LOW_POWER_DEMO */\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 void NVIC_Handler_TMR1( void )\r
191 {\r
192         tmrRECORD_NESTING_DEPTH();\r
193 \r
194         /* Just testing the xPortIsInsideInterrupt() functionality. */\r
195         configASSERT( xPortIsInsideInterrupt() == pdTRUE );\r
196 \r
197         /* Call the IntQ test function for this channel. */\r
198         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
199 \r
200         ulNestingDepth--;\r
201 }\r
202 /*-----------------------------------------------------------*/\r
203 \r
204 void NVIC_Handler_TMR2( void )\r
205 {\r
206         tmrRECORD_NESTING_DEPTH();\r
207         ulNestingDepth--;\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r