]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX100-RSK_IAR/main.c
1972a90e517662eeae72b9e440a4982dd7db9784
[freertos] / FreeRTOS / Demo / RX100-RSK_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A low power project that\r
30  * demonstrates the FreeRTOS tickless mode, and a more comprehensive test and\r
31  * demo application.  The configCREATE_LOW_POWER_DEMO setting (defined at the\r
32  * top of FreeRTOSConfig.h) is used to select between the two.  The low power\r
33  * demo is implemented and described in main_low_power.c.  The more\r
34  * comprehensive test and demo application is implemented and described in\r
35  * main_full.c.\r
36  *\r
37  * This file implements the code that is not demo specific, including the\r
38  * hardware setup and FreeRTOS hook functions.\r
39  */\r
40 \r
41 /* Kernel includes. */\r
42 #include "FreeRTOS.h"\r
43 #include "task.h"\r
44 \r
45 /* Platform includes. */\r
46 #include "lcd.h"\r
47 \r
48 /*-----------------------------------------------------------*/\r
49 \r
50 /*\r
51  * Prepare the board of the demo.\r
52  */\r
53 extern void vHardwareSetup( void );\r
54 \r
55 /*\r
56  * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.\r
57  * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.\r
58  */\r
59 extern void main_low_power( void );\r
60 extern void main_full( void );\r
61 \r
62 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
63 within this file. */\r
64 void vApplicationMallocFailedHook( void );\r
65 void vApplicationIdleHook( void );\r
66 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
67 void vApplicationTickHook( void );\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 /* See the documentation page for this demo on the FreeRTOS.org web site for\r
72 full information - including hardware setup requirements. */\r
73 \r
74 void main( void )\r
75 {\r
76         /* Call the Renesas provided setup. */\r
77         vHardwareSetup();\r
78         lcd_initialize();\r
79         lcd_display( LCD_LINE1, "FreeRTOS" );\r
80 \r
81         /* The configCREATE_LOW_POWER_DEMO setting is described in FreeRTOSConfig.h. */\r
82         #if configCREATE_LOW_POWER_DEMO == 1\r
83         {\r
84                 lcd_display( LCD_LINE2, "LP Demo" );\r
85                 main_low_power();\r
86         }\r
87         #else\r
88         {\r
89                 lcd_display( LCD_LINE2, "Ful Demo" );\r
90                 main_full();\r
91         }\r
92         #endif\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 void vApplicationMallocFailedHook( void )\r
97 {\r
98         /* vApplicationMallocFailedHook() will only be called if\r
99         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
100         function that will get called if a call to pvPortMalloc() fails.\r
101         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
102         timer or semaphore is created.  It is also called by various parts of the\r
103         demo application.  If heap_1.c, heap_2.c or heap_4.c are used, then the size\r
104         of the heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE\r
105         in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
106         to query the size of free heap space that remains (although it does not\r
107         provide information on how the remaining heap might be fragmented). */\r
108         taskDISABLE_INTERRUPTS();\r
109         for( ;; );\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vApplicationIdleHook( void )\r
114 {\r
115         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
116         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
117         task.  It is essential that code added to this hook function never attempts\r
118         to block in any way (for example, call xQueueReceive() with a block time\r
119         specified, or call vTaskDelay()).  If the application makes use of the\r
120         vTaskDelete() API function (as this demo application does) then it is also\r
121         important that vApplicationIdleHook() is permitted to return to its calling\r
122         function, because it is the responsibility of the idle task to clean up\r
123         memory allocated by the kernel to any task that has since been deleted. */\r
124 }\r
125 /*-----------------------------------------------------------*/\r
126 \r
127 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
128 {\r
129         ( void ) pcTaskName;\r
130         ( void ) pxTask;\r
131 \r
132         /* Run time stack overflow checking is performed if\r
133         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook function is\r
134         called if a stack overflow is detected. */\r
135         taskDISABLE_INTERRUPTS();\r
136         for( ;; );\r
137 }\r
138 /*-----------------------------------------------------------*/\r
139 \r
140 void vApplicationTickHook( void )\r
141 {\r
142         /* This function will be called by each tick interrupt if\r
143         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
144         added here, but the tick hook is called from an interrupt context, so\r
145         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
146         functions can be used (those that end in FromISR()). */\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 void vAssertCalled( void )\r
151 {\r
152 volatile unsigned long ul = 0;\r
153 \r
154         taskENTER_CRITICAL();\r
155         {\r
156                 /* Set ul to a non-zero value using the debugger to step out of this\r
157                 function. */\r
158                 while( ul == 0 )\r
159                 {\r
160                         __asm volatile( "NOP" );\r
161                 }\r
162         }\r
163         taskEXIT_CRITICAL();\r
164 }\r