]> begriffs open source - cmsis-freertos/blob - Demo/RL78_multiple_IAR/main.c
Set error state if no delay or already expired
[cmsis-freertos] / Demo / RL78_multiple_IAR / main.c
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /******************************************************************************
29  * This project provides two demo applications.  A simple blinky style project,
30  * and a more comprehensive test and demo application.  The
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
32  * select between the two.  The simply blinky demo is implemented and described
33  * in main_blinky.c.  The more comprehensive test and demo application is
34  * implemented and described in main_full.c.
35  *
36  * This file implements the code that is not demo specific, including the
37  * hardware setup and FreeRTOS hook functions.
38  *
39  * This project does not provide an example of how to write an RTOS compatible
40  * interrupt service routine (other than the tick interrupt itself), so this
41  * file contains the function vAnExampleISR_C_Handler() as a dummy example (that
42  * is not actually installed) that can be used as a reference.  Also see the
43  * file ExampleISR.s87, and the documentation page for this demo on the
44  * FreeRTOS.org website for full instructions.
45  *
46  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
47  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
48  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
49  *
50  */
51
52 /* Scheduler include files. */
53 #include "FreeRTOS.h"
54 #include "task.h"
55 #include "semphr.h"
56
57 /* Hardware includes. */
58 #include "demo_specific_io.h"
59
60 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
61 or 0 to run the more comprehensive test and demo application. */
62 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0
63
64 /*-----------------------------------------------------------*/
65
66 /*
67  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
68  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
69  */
70 extern void main_blinky( void );
71 extern void main_full( void );
72
73 /*
74  * This function is called from the C startup routine to setup the processor -
75  * in particular the clock source.
76  */
77 int __low_level_init(void);
78
79 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
80 within this file. */
81 void vApplicationMallocFailedHook( void );
82 void vApplicationIdleHook( void );
83 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
84 void vApplicationTickHook( void );
85
86 /*-----------------------------------------------------------*/
87
88 /* This variable is not actually used, but provided to allow an example of how
89 to write an ISR to be included in this file. */
90 static SemaphoreHandle_t xSemaphore = NULL;
91
92 /* RL78 Option Byte Definition. Watchdog disabled, LVI enabled, OCD interface
93 enabled. */
94 __root __far const unsigned char OptionByte[] @ 0x00C0 =
95 {
96         0x6eU, 0xffU, 0xe8U, 0x85U
97 };
98
99 /* Security byte definition */
100 __root __far const unsigned char ucSecurityCode[]  @ 0x00C4 =
101 {
102         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
103 };
104
105 /*-----------------------------------------------------------*/
106
107 void main( void )
108 {
109         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
110         of this file. */
111         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
112         {
113                 main_blinky();
114         }
115         #else
116         {
117                 main_full();
118         }
119         #endif
120 }
121 /*-----------------------------------------------------------*/
122
123 void vAnExampleISR_C_Handler( void )
124 {
125         /*
126          * This demo does not include a functional interrupt service routine - so
127          * this dummy handler (which is not actually installed) is provided as an
128          * example of how an ISR that needs to cause a context switch needs to be
129          * implemented.  ISRs that do not cause a context switch have no special
130          * requirements and can be written as per the compiler documentation.
131          *
132          * This C function is called from a wrapper function that is implemented
133          * in assembly code.  See vANExampleISR_ASM_Wrapper() in ExampleISR.s87.
134          * Also see the documentation page for this demo on the FreeRTOS.org website
135          * for full instructions.
136          */
137 short sHigherPriorityTaskWoken = pdFALSE;
138
139         /* Handler code goes here...*/
140
141         /* For purposes of demonstration, assume at some point the hander calls
142         xSemaphoreGiveFromISR().*/
143         xSemaphoreGiveFromISR( xSemaphore, &sHigherPriorityTaskWoken );
144
145         /* If giving the semaphore unblocked a task, and the unblocked task has a
146         priority higher than or equal to the currently running task, then
147         sHigherPriorityTaskWoken will have been set to pdTRUE internally within the
148         xSemaphoreGiveFromISR() function.  Passing a pdTRUE     value to
149         portYIELD_FROM_ISR() will cause this interrupt to return directly to the
150         higher priority unblocked task. */
151         portYIELD_FROM_ISR( sHigherPriorityTaskWoken );
152 }
153 /*-----------------------------------------------------------*/
154
155 int __low_level_init(void)
156 {
157         portDISABLE_INTERRUPTS();
158
159         /* Set fMX */
160         CMC = 0x00;
161         MSTOP = 1U;
162
163         /* Set fMAIN */
164         MCM0 = 0U;
165
166         /* Set fSUB */
167         XTSTOP = 1U;
168         OSMC = 0x10;
169
170         /* Set fCLK */
171         CSS = 0U;
172
173         /* Set fIH */
174         HIOSTOP = 0U;
175
176         /* LED port initialization. */
177         LED_INIT();
178
179         return pdTRUE;
180 }
181 /*-----------------------------------------------------------*/
182
183 void vApplicationMallocFailedHook( void )
184 {
185         /* Called if a call to pvPortMalloc() fails because there is insufficient
186         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
187         internally by FreeRTOS API functions that create tasks, queues, software
188         timers, and semaphores.  The size of the FreeRTOS heap is set by the
189         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
190         taskDISABLE_INTERRUPTS();
191         for( ;; );
192 }
193 /*-----------------------------------------------------------*/
194
195 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
196 {
197         ( void ) pcTaskName;
198         ( void ) pxTask;
199
200         /* Run time stack overflow checking is performed if
201         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
202         function is called if a stack overflow is detected. */
203         taskDISABLE_INTERRUPTS();
204         for( ;; );
205 }
206 /*-----------------------------------------------------------*/
207
208 void vApplicationIdleHook( void )
209 {
210 volatile size_t xFreeHeapSpace;
211
212         /* This is just a trivial example of an idle hook.  It is called on each
213         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
214         idle task just queries the amount of FreeRTOS heap that remains.  See the
215         memory management section on the http://www.FreeRTOS.org web site for memory
216         management options.  If there is a lot of heap memory free then the
217         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
218         RAM. */
219         xFreeHeapSpace = xPortGetFreeHeapSize();
220
221         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
222         ( void ) xFreeHeapSpace;
223 }
224
225