2 FreeRTOS.org V5.1.1 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
50 /* Standard includes. */
\r
54 /* Scheduler include files. */
\r
55 #include "FreeRTOS.h"
\r
58 /* Demo file headers. */
\r
59 #include "int78K0R.h"
\r
61 #include "semtest.h"
\r
62 #include "GenQTest.h"
\r
63 #include "dynamic.h"
\r
64 #include "blocktim.h"
\r
67 * Priority definitions for most of the tasks in the demo application. Some
\r
68 * tasks just use the idle priority.
\r
70 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
71 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
72 #define mainSEMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
73 #define mainBUTTON_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
74 #define mainGEN_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
76 /* The period between executions of the check task. */
\r
77 #define mainNO_ERROR_TOGGLE_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
78 #define mainERROR_TOGGLE_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
80 #define LED00 P7_bit.no6
\r
81 #define LED01 P7_bit.no7
\r
84 * 78K0R/Kx3 Option Byte Definition
\r
85 * watchdog disabled, LVI enabled, OCD interface enabled
\r
87 __root __far const unsigned portCHAR OptionByte[OPT_BYTES_SIZE] @ 0x00C0 =
\r
89 WATCHDOG_DISABLED, LVI_ENABLED, RESERVED_FF, OCD_ENABLED
\r
92 /* Security Byte Definition */
\r
93 __root __far const unsigned portCHAR SecuIDCode[SECU_ID_SIZE] @ 0x00C4 =
\r
95 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
\r
98 /* The task function for the "Check" task. */
\r
99 static void vErrorChecks( void *pvParameters );
\r
102 /* 78K0R/Kx3 low level init Initialization of the System Clock */
\r
103 int __low_level_init(void);
\r
105 extern void vRegTest1( void *pvParameters );
\r
106 extern void vRegTest2( void *pvParameters );
\r
107 extern void vButtonTask( void *pvParameters );
\r
109 static short sRegTestStatus = pdPASS;
\r
111 portSHORT main( void )
\r
113 /* Create the standard demo tasks. */
\r
114 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
115 vStartSemaphoreTasks(mainSEMTEST_PRIORITY);
\r
116 vStartGenericQueueTasks( mainGEN_QUEUE_PRIORITY );
\r
117 vStartDynamicPriorityTasks();
\r
118 vCreateBlockTimeTasks();
\r
120 xTaskCreate( vButtonTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainBUTTON_PRIORITY, NULL );
\r
122 /* Create the tasks defined within this file. */
\r
123 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, (void*)0x12345678, mainCHECK_TASK_PRIORITY, NULL );
\r
125 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
126 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
129 vTaskStartScheduler();
\r
133 /*-----------------------------------------------------------*/
\r
135 static void vErrorChecks( void *pvParameters )
\r
137 portTickType xToggleRate = mainNO_ERROR_TOGGLE_PERIOD, xLastWakeTime;
\r
139 /* The pointer will only actually be either 3 or 2 bytes, depending on the
\r
141 if( pvParameters != ( void * ) 0x12345678 )
\r
143 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
146 xLastWakeTime = xTaskGetTickCount();
\r
148 /* Cycle for ever, delaying then checking all the other tasks are still
\r
149 operating without error. */
\r
152 vTaskDelayUntil( &xLastWakeTime, xToggleRate );
\r
154 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
156 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
159 if( xArePollingQueuesStillRunning() != pdTRUE)
\r
161 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
164 if( xAreSemaphoreTasksStillRunning() != pdTRUE)
\r
166 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
169 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
171 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
174 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
176 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
179 if( sRegTestStatus != pdPASS )
\r
181 xToggleRate = mainERROR_TOGGLE_PERIOD;
\r
184 /* Toggle the LED. */
\r
188 /*-----------------------------------------------------------*/
\r
190 int __low_level_init(void)
\r
192 unsigned portCHAR resetflag = RESF;
\r
194 portDISABLE_INTERRUPTS();
\r
197 * Clock Configuration:
\r
198 * In this port, to use the internal high speed clock source of the microcontroller
\r
199 * define the configCLOCK_SOURCE as 1 in FreeRTOSConfig.h. To use an external
\r
200 * clock define configCLOCK_SOURCE as 0.
\r
202 #if configCLOCK_SOURCE == 1
\r
205 * Set XT1 and XT2 in Input Port Mode
\r
206 * Set X1 and X2 in Input Port Mode
\r
207 * High speed oszillation frequency 2MHz <= fMX <= 10MHz
\r
211 /* X1 external oszillation stopped */
\r
214 /* enable internal high speed oszillation */
\r
218 /* stop internal subsystem clock */
\r
221 /* Set clock speed */
\r
223 CKC &= (unsigned portCHAR)~0x07;
\r
229 * XT1 and XT2 pin in input port mode
\r
230 * X1 and X2 pin in crystal resonator mode
\r
231 * High speed oszillation frequency 10MHz < fMX <= 20MHz
\r
235 /* Set oscillation stabilization time */
\r
238 /* Set speed mode: fMX > 10MHz for Flash memory high speed operation */
\r
242 * Start up X1 oscillator operation
\r
243 * Internal high-speed oscillator operating
\r
247 /* Check oscillation stabilization time status */
\r
250 /* wait until X1 clock stabilization time */
\r
254 /* Switch CPU clock to X1 oscillator */
\r
258 /* wait until CPU and peripherals operate with fX1 clock */
\r
262 /* Stop the internal high-speed oscillator operation */
\r
265 /* Stop the XT1 oscillator operation */
\r
269 * operating frequency f = fx
\r
270 * Change clock generator setting, if necessary
\r
274 /* From here onwards the X1 oscillator is supplied to the CPU */
\r
278 /* LED Port Initialization - set Port Register */
\r
281 /* Set Port Mode Register */
\r
284 /* Switch Pin Initialization - enable pull-up resistor */
\r
287 /* INTP0 disable */
\r
290 /* INTP0 IF clear */
\r
294 /* INTP0 priority low */
\r
298 /* enable ext. INTP0 interrupt */
\r
303 /*-----------------------------------------------------------*/
\r
305 void vRegTestError( void )
\r
307 sRegTestStatus = pdFAIL;
\r
310 /*-----------------------------------------------------------*/
\r
312 void vApplicationStackOverflowHook( void )
\r