2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
68 /* Scheduler include files. */
\r
69 #include "FreeRTOS.h"
\r
72 /* Demo program include files. */
\r
74 #include "demoGpio.h"
\r
76 #define x7segSTACK_SIZE configMINIMAL_STACK_SIZE
\r
78 static void prvRefreshTask( void *pvParameters );
\r
79 static void prvCountTask( void *pvParameters );
\r
81 /* Value to output to 7 segment display
\r
82 led_digits[0] is the right most digit */
\r
83 static signed char seg7_digits[4];
\r
85 void vStart7SegTasks( unsigned portBASE_TYPE uxPriority )
\r
87 xTaskCreate( prvRefreshTask, ( signed char * ) "7SegRefresh", x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL );
\r
88 xTaskCreate( prvCountTask, ( signed char * ) "7SegCount", x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL );
\r
90 /*-----------------------------------------------------------*/
\r
92 static void prvRefreshTask( void *pvParameters )
\r
94 /* This is table 3.3 from the Spartan-3 Starter Kit board user guide */
\r
95 const unsigned char bits[ 16 ] =
\r
115 const unsigned char apsx[4] =
\r
123 portTickType xRefreshRate, xLastRefreshTime;
\r
125 /* Digit to scan */
\r
130 /* We need to initialise xLastRefreshTime prior to the first call to
\r
131 vTaskDelayUntil(). */
\r
132 xLastRefreshTime = xTaskGetTickCount();
\r
136 for( d = 0; d < 4; d++ )
\r
138 vTaskDelayUntil ( &xLastRefreshTime, xRefreshRate );
\r
140 /* Display digit */
\r
142 if( ( seg7_digits[ 1 ] == 4 ) || ( seg7_digits[ 1 ] == 5 ) )
\r
144 gpio->out.digit = apsx[ d ];
\r
148 gpio->out.digit = bits[ seg7_digits[ d ] ];
\r
152 gpio->out.an = ~(1 << d);
\r
156 /*-----------------------------------------------------------*/
\r
158 static void prvCountTask( void *pvParameters )
\r
160 portTickType xCountRate, xLastCountTime;
\r
162 /* Approximately 20HZ */
\r
163 xCountRate = configTICK_RATE_HZ / 20;
\r
165 /* We need to initialise xLastCountTime prior to the first call to
\r
166 vTaskDelayUntil(). */
\r
167 xLastCountTime = xTaskGetTickCount();
\r
171 vTaskDelayUntil( &xLastCountTime, xCountRate );
\r
173 /* Really ugly way to do BCD arithmetic.... */
\r
174 seg7_digits[ 0 ] -= 1;
\r
175 if( seg7_digits[ 0 ] < 0 )
\r
177 seg7_digits[ 0 ] = 9;
\r
178 seg7_digits[ 1 ] -= 1;
\r
179 if( seg7_digits[ 1 ] < 0 )
\r
181 seg7_digits[ 1 ] = 9;
\r
182 seg7_digits[ 2 ] -= 1;
\r
183 if( seg7_digits[ 2 ] < 0 )
\r
185 seg7_digits[ 2 ] = 9;
\r
186 seg7_digits[ 3 ] -= 1;
\r
187 if( seg7_digits[ 3 ] < 0 )
\r
189 seg7_digits[ 3 ] = 9;
\r