2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
71 * Interrupt service routines that cannot nest have no special requirements and
\r
72 * can be written as per the compiler documentation. However interrupts written
\r
73 * in this manner will utilise the stack of whichever task was interrupts,
\r
74 * rather than the system stack, necessitating that adequate stack space be
\r
75 * allocated to each created task. It is therefore not recommended to write
\r
76 * interrupt service routines in this manner.
\r
78 * Interrupts service routines that can nest require a simple assembly wrapper.
\r
79 * This file is provided as a example of how this is done.
\r
81 * The example in this file creates a single task. The task blocks on a
\r
82 * semaphore which is periodically 'given' from a timer interrupt. The assembly
\r
83 * wrapper for the interrupt is implemented in ISRTriggeredTask_isr.S. The
\r
84 * C function called by the assembly wrapper is implemented in this file.
\r
86 * The task toggle LED mainISR_TRIGGERED_LED each time it is unblocked by the
\r
91 /* Standard includes. */
\r
94 /* Scheduler includes. */
\r
95 #include "FreeRTOS.h"
\r
99 /* Standard demo includes. */
\r
100 #include "ParTest.h"
\r
102 /*-----------------------------------------------------------*/
\r
104 /* The LED controlled by the ISR triggered task. */
\r
105 #define mainISR_TRIGGERED_LED ( 1 )
\r
107 /* Constants used to configure T5. */
\r
108 #define mainT5PRESCALAR ( 6 )
\r
109 #define mainT5_SEMAPHORE_RATE ( 31250 )
\r
111 /*-----------------------------------------------------------*/
\r
114 * The task that is periodically triggered by an interrupt, as described at the
\r
115 * top of this file.
\r
117 static void prvISRTriggeredTask( void* pvParameters );
\r
120 * Configures the T5 timer peripheral to generate the interrupts that unblock
\r
121 * the task implemented by the prvISRTriggeredTask() function.
\r
123 static void prvSetupT5( void );
\r
125 /* The timer 5 interrupt handler. As this interrupt uses the FreeRTOS assembly
\r
126 entry point the IPL setting in the following function prototype has no effect. */
\r
127 void __attribute__( (interrupt(IPL3AUTO), vector(_TIMER_5_VECTOR))) vT5InterruptWrapper( void );
\r
129 /*-----------------------------------------------------------*/
\r
131 /* The semaphore given by the T5 interrupt to unblock the task implemented by
\r
132 the prvISRTriggeredTask() function. */
\r
133 static SemaphoreHandle_t xBlockSemaphore = NULL;
\r
134 /*-----------------------------------------------------------*/
\r
136 void vStartISRTriggeredTask( void )
\r
138 /* Create the task described at the top of this file. The timer is
\r
139 configured by the task itself. */
\r
140 xTaskCreate( prvISRTriggeredTask, /* The function that implements the task. */
\r
141 "ISRt", /* Text name to help debugging - not used by the kernel. */
\r
142 configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task - defined in words, not bytes. */
\r
143 NULL, /* The parameter to pass into the task. Not used in this case. */
\r
144 configMAX_PRIORITIES - 1, /* The priority at which the task is created. */
\r
145 NULL ); /* Used to pass a handle to the created task out of the function. Not used in this case. */
\r
147 /*-----------------------------------------------------------*/
\r
149 void vT5InterruptHandler( void )
\r
151 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
153 /* This function is the handler for the peripheral timer interrupt.
\r
154 The interrupt is initially signalled in a separate assembly file
\r
155 which switches to the system stack and then calls this function.
\r
156 It gives a semaphore which signals the prvISRBlockTask */
\r
158 /* Give the semaphore. If giving the semaphore causes the task to leave the
\r
159 Blocked state, and the priority of the task is higher than the priority of
\r
160 the interrupted task, then xHigherPriorityTaskWoken will be set to pdTRUE
\r
161 inside the xSemaphoreGiveFromISR() function. xHigherPriorityTaskWoken is
\r
162 later passed into portEND_SWITCHING_ISR(), where a context switch is
\r
163 requested if it is pdTRUE. The context switch ensures the interrupt returns
\r
164 directly to the unblocked task. */
\r
165 xSemaphoreGiveFromISR( xBlockSemaphore, &xHigherPriorityTaskWoken );
\r
167 /* Clear the interrupt */
\r
168 IFS0CLR = _IFS0_T5IF_MASK;
\r
170 /* See comment above the call to xSemaphoreGiveFromISR(). */
\r
171 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
173 /*-----------------------------------------------------------*/
\r
175 static void prvISRTriggeredTask( void* pvParameters )
\r
177 /* Avoid compiler warnings. */
\r
178 ( void ) pvParameters;
\r
180 /* Create the semaphore used to signal this task */
\r
181 xBlockSemaphore = xSemaphoreCreateBinary();
\r
183 /* Configure the timer to generate the interrupts. */
\r
188 /* Block on the binary semaphore given by the T5 interrupt. */
\r
189 xSemaphoreTake( xBlockSemaphore, portMAX_DELAY );
\r
191 /* Toggle the LED. */
\r
192 vParTestToggleLED( mainISR_TRIGGERED_LED );
\r
195 /*-----------------------------------------------------------*/
\r
197 static void prvSetupT5( void )
\r
199 /* Set up timer 5 to generate an interrupt every 50 ms */
\r
202 T5CONbits.TCKPS = mainT5PRESCALAR;
\r
203 PR5 = mainT5_SEMAPHORE_RATE;
\r
205 /* Setup timer 5 interrupt priority to be the maximum from which interrupt
\r
206 safe FreeRTOS API functions can be called. Interrupt safe FreeRTOS API
\r
207 functions are those that end "FromISR". */
\r
208 IPC6bits.T5IP = configMAX_SYSCALL_INTERRUPT_PRIORITY;
\r
210 /* Clear the interrupt as a starting condition. */
\r
213 /* Enable the interrupt. */
\r
216 /* Start the timer. */
\r