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