]> begriffs open source - cmsis-freertos/blob - Demo/RX100-RSK_IAR/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / RX100-RSK_IAR / main.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /******************************************************************************
71  * This project provides two demo applications.  A low power project that
72  * demonstrates the FreeRTOS tickless mode, and a more comprehensive test and
73  * demo application.  The configCREATE_LOW_POWER_DEMO setting (defined at the
74  * top of FreeRTOSConfig.h) is used to select between the two.  The low power
75  * demo is implemented and described in main_low_power.c.  The more
76  * comprehensive test and demo application is implemented and described in
77  * main_full.c.
78  *
79  * This file implements the code that is not demo specific, including the
80  * hardware setup and FreeRTOS hook functions.
81  */
82
83 /* Kernel includes. */
84 #include "FreeRTOS.h"
85 #include "task.h"
86
87 /* Platform includes. */
88 #include "lcd.h"
89
90 /*-----------------------------------------------------------*/
91
92 /*
93  * Prepare the board of the demo.
94  */
95 extern void vHardwareSetup( void );
96
97 /*
98  * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
99  * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
100  */
101 extern void main_low_power( void );
102 extern void main_full( void );
103
104 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
105 within this file. */
106 void vApplicationMallocFailedHook( void );
107 void vApplicationIdleHook( void );
108 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
109 void vApplicationTickHook( void );
110
111 /*-----------------------------------------------------------*/
112
113 /* See the documentation page for this demo on the FreeRTOS.org web site for
114 full information - including hardware setup requirements. */
115
116 void main( void )
117 {
118         /* Call the Renesas provided setup. */
119         vHardwareSetup();
120         lcd_initialize();
121         lcd_display( LCD_LINE1, "FreeRTOS" );
122
123         /* The configCREATE_LOW_POWER_DEMO setting is described in FreeRTOSConfig.h. */
124         #if configCREATE_LOW_POWER_DEMO == 1
125         {
126                 lcd_display( LCD_LINE2, "LP Demo" );
127                 main_low_power();
128         }
129         #else
130         {
131                 lcd_display( LCD_LINE2, "Ful Demo" );
132                 main_full();
133         }
134         #endif
135 }
136 /*-----------------------------------------------------------*/
137
138 void vApplicationMallocFailedHook( void )
139 {
140         /* vApplicationMallocFailedHook() will only be called if
141         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
142         function that will get called if a call to pvPortMalloc() fails.
143         pvPortMalloc() is called internally by the kernel whenever a task, queue,
144         timer or semaphore is created.  It is also called by various parts of the
145         demo application.  If heap_1.c, heap_2.c or heap_4.c are used, then the size
146         of the heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE
147         in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
148         to query the size of free heap space that remains (although it does not
149         provide information on how the remaining heap might be fragmented). */
150         taskDISABLE_INTERRUPTS();
151         for( ;; );
152 }
153 /*-----------------------------------------------------------*/
154
155 void vApplicationIdleHook( void )
156 {
157         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
158         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
159         task.  It is essential that code added to this hook function never attempts
160         to block in any way (for example, call xQueueReceive() with a block time
161         specified, or call vTaskDelay()).  If the application makes use of the
162         vTaskDelete() API function (as this demo application does) then it is also
163         important that vApplicationIdleHook() is permitted to return to its calling
164         function, because it is the responsibility of the idle task to clean up
165         memory allocated by the kernel to any task that has since been deleted. */
166 }
167 /*-----------------------------------------------------------*/
168
169 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
170 {
171         ( void ) pcTaskName;
172         ( void ) pxTask;
173
174         /* Run time stack overflow checking is performed if
175         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook function is
176         called if a stack overflow is detected. */
177         taskDISABLE_INTERRUPTS();
178         for( ;; );
179 }
180 /*-----------------------------------------------------------*/
181
182 void vApplicationTickHook( void )
183 {
184         /* This function will be called by each tick interrupt if
185         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
186         added here, but the tick hook is called from an interrupt context, so
187         code must not attempt to block, and only the interrupt safe FreeRTOS API
188         functions can be used (those that end in FromISR()). */
189 }
190 /*-----------------------------------------------------------*/
191
192 void vAssertCalled( void )
193 {
194 volatile unsigned long ul = 0;
195
196         taskENTER_CRITICAL();
197         {
198                 /* Set ul to a non-zero value using the debugger to step out of this
199                 function. */
200                 while( ul == 0 )
201                 {
202                         __asm volatile( "NOP" );
203                 }
204         }
205         taskEXIT_CRITICAL();
206 }