]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RL78_E2Studio_GCC/src/main.c
b3f0fc05a6758b525c7ec019623bac84b68c1f6d
[freertos] / FreeRTOS / Demo / RL78_E2Studio_GCC / src / main.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 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 simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup and FreeRTOS hook functions.\r
38  *\r
39  * This project does not provide an example of how to write an RTOS compatible\r
40  * interrupt service routine (other than the tick interrupt itself), so this\r
41  * file contains the function vAnExampleISR_C_Handler() as a dummy example (that\r
42  * is not actually installed) that can be used as a reference.  Also see the\r
43  * file ExampleISR.S, and the documentation page for this demo on the\r
44  * FreeRTOS.org website for full instructions.\r
45  *\r
46  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
47  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
48  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
49  *\r
50  */\r
51 \r
52 /* Scheduler include files. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 #include "semphr.h"\r
56 \r
57 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
58 or 0 to run the more comprehensive test and demo application. */\r
59 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
60 \r
61 /*-----------------------------------------------------------*/\r
62 \r
63 /*\r
64  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
65  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
66  */\r
67 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
68         extern void main_blinky( void );\r
69 #else\r
70     extern void main_full( void );\r
71 #endif\r
72 \r
73 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
74 within this file. */\r
75 void vApplicationMallocFailedHook( void );\r
76 void vApplicationIdleHook( void );\r
77 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
78 void vApplicationTickHook( void );\r
79 \r
80 /* This variable is not actually used, but provided to allow an example of how\r
81 to write an ISR to be included in this file. */\r
82 static SemaphoreHandle_t xSemaphore = NULL;\r
83 /*-----------------------------------------------------------*/\r
84 \r
85 #define portPSW ( 0xc6UL )\r
86 volatile uint32_t *pulAddress;\r
87 volatile uint32_t ulValue, ulError = 0;\r
88 \r
89 int main( void )\r
90 {\r
91         /* Store an address below 0x8000 */\r
92         pulAddress = ( uint32_t * ) 0x7fff;\r
93 \r
94         /* Cast and OR with a value that uses the two most significant\r
95         bytes. */\r
96         ulValue = ( ( uint32_t ) pulAddress ) | ( portPSW << 24UL );\r
97 \r
98         /* This test passes. */\r
99         if( ulValue != 0xc6007fff )\r
100         {\r
101                 /* This line of code is not executed. */\r
102                 ulError = 1;\r
103         }\r
104 \r
105         /* Now do the same, but with an address above 0x7fff, but\r
106         still slower than the max 16-bit value. */\r
107         pulAddress = ( uint32_t * ) 0x8000;\r
108         ulValue = ( ( uint32_t ) pulAddress ) | ( portPSW << 24UL );\r
109 \r
110         /* This test *fails*. */\r
111         if( ulValue != 0xc6008000 )\r
112         {\r
113                 /* This line of code *is* executed. */\r
114                 ulError = 1;\r
115         }\r
116 \r
117 \r
118         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is\r
119         described at the top of this file. */\r
120         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
121         {\r
122                 main_blinky();\r
123         }\r
124         #else\r
125         {\r
126                 main_full();\r
127         }\r
128         #endif\r
129 \r
130         /* Should not get here.  See the definitions of main_blinky() and\r
131         main_full(). */\r
132         return 0;\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 void vAnExampleISR_C_Handler( void )\r
137 {\r
138         /*\r
139          * This demo does not include a functional interrupt service routine - so\r
140          * this dummy handler (which is not actually installed) is provided as an\r
141          * example of how an ISR that needs to cause a context switch needs to be\r
142          * implemented.  ISRs that do not cause a context switch have no special\r
143          * requirements and can be written as per the compiler documentation.\r
144          *\r
145          * This C function is called from a wrapper function that is implemented\r
146          * in assembly code.  See vANExampleISR_ASM_Wrapper() in ExampleISR.S.  Also\r
147          * see the documentation page for this demo on the FreeRTOS.org website for\r
148          * full instructions.\r
149          */\r
150 short sHigherPriorityTaskWoken = pdFALSE;\r
151 \r
152         /* Handler code goes here...*/\r
153 \r
154         /* For purposes of demonstration, assume at some point the hander calls\r
155         xSemaphoreGiveFromISR().*/\r
156         xSemaphoreGiveFromISR( xSemaphore, &sHigherPriorityTaskWoken );\r
157 \r
158         /* If giving the semaphore unblocked a task, and the unblocked task has a\r
159         priority higher than or equal to the currently running task, then\r
160         sHigherPriorityTaskWoken will have been set to pdTRUE internally within the\r
161         xSemaphoreGiveFromISR() function.  Passing a pdTRUE     value to\r
162         portYIELD_FROM_ISR() will cause this interrupt to return directly to the\r
163         higher priority unblocked task. */\r
164         portYIELD_FROM_ISR( sHigherPriorityTaskWoken );\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 void vApplicationMallocFailedHook( void )\r
169 {\r
170         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
171         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
172         internally by FreeRTOS API functions that create tasks, queues, software\r
173         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
174         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
175         taskDISABLE_INTERRUPTS();\r
176         for( ;; );\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
181 {\r
182         ( void ) pcTaskName;\r
183         ( void ) pxTask;\r
184 \r
185         /* Run time stack overflow checking is performed if\r
186         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
187         function is called if a stack overflow is detected. */\r
188         taskDISABLE_INTERRUPTS();\r
189         for( ;; );\r
190 }\r
191 /*-----------------------------------------------------------*/\r
192 \r
193 void vApplicationIdleHook( void )\r
194 {\r
195 volatile size_t xFreeHeapSpace;\r
196 \r
197         /* This is just a trivial example of an idle hook.  It is called on each\r
198         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
199         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
200         memory management section on the http://www.FreeRTOS.org web site for memory\r
201         management options.  If there is a lot of heap memory free then the\r
202         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
203         RAM. */\r
204         xFreeHeapSpace = xPortGetFreeHeapSize();\r
205 \r
206         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
207         ( void ) xFreeHeapSpace;\r
208 }\r
209 \r
210 \r