2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
32 /* Scheduler include files. */
\r
33 #include "FreeRTOS.h"
\r
36 /* Demo program include files. */
\r
38 #include "demoGpio.h"
\r
40 #define x7segSTACK_SIZE configMINIMAL_STACK_SIZE
\r
42 static void prvRefreshTask( void *pvParameters );
\r
43 static void prvCountTask( void *pvParameters );
\r
45 /* Value to output to 7 segment display
\r
46 led_digits[0] is the right most digit */
\r
47 static signed char seg7_digits[4];
\r
49 void vStart7SegTasks( unsigned portBASE_TYPE uxPriority )
\r
51 xTaskCreate( prvRefreshTask, "7SegRefresh", x7segSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t *) NULL );
\r
52 xTaskCreate( prvCountTask, "7SegCount", x7segSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t *) NULL );
\r
54 /*-----------------------------------------------------------*/
\r
56 static void prvRefreshTask( void *pvParameters )
\r
58 /* This is table 3.3 from the Spartan-3 Starter Kit board user guide */
\r
59 const unsigned char bits[ 16 ] =
\r
79 const unsigned char apsx[4] =
\r
87 TickType_t xRefreshRate, xLastRefreshTime;
\r
94 /* We need to initialise xLastRefreshTime prior to the first call to
\r
95 vTaskDelayUntil(). */
\r
96 xLastRefreshTime = xTaskGetTickCount();
\r
100 for( d = 0; d < 4; d++ )
\r
102 vTaskDelayUntil ( &xLastRefreshTime, xRefreshRate );
\r
104 /* Display digit */
\r
106 if( ( seg7_digits[ 1 ] == 4 ) || ( seg7_digits[ 1 ] == 5 ) )
\r
108 gpio->out.digit = apsx[ d ];
\r
112 gpio->out.digit = bits[ seg7_digits[ d ] ];
\r
116 gpio->out.an = ~(1 << d);
\r
120 /*-----------------------------------------------------------*/
\r
122 static void prvCountTask( void *pvParameters )
\r
124 TickType_t xCountRate, xLastCountTime;
\r
126 /* Approximately 20HZ */
\r
127 xCountRate = configTICK_RATE_HZ / 20;
\r
129 /* We need to initialise xLastCountTime prior to the first call to
\r
130 vTaskDelayUntil(). */
\r
131 xLastCountTime = xTaskGetTickCount();
\r
135 vTaskDelayUntil( &xLastCountTime, xCountRate );
\r
137 /* Really ugly way to do BCD arithmetic.... */
\r
138 seg7_digits[ 0 ] -= 1;
\r
139 if( seg7_digits[ 0 ] < 0 )
\r
141 seg7_digits[ 0 ] = 9;
\r
142 seg7_digits[ 1 ] -= 1;
\r
143 if( seg7_digits[ 1 ] < 0 )
\r
145 seg7_digits[ 1 ] = 9;
\r
146 seg7_digits[ 2 ] -= 1;
\r
147 if( seg7_digits[ 2 ] < 0 )
\r
149 seg7_digits[ 2 ] = 9;
\r
150 seg7_digits[ 3 ] -= 1;
\r
151 if( seg7_digits[ 3 ] < 0 )
\r
153 seg7_digits[ 3 ] = 9;
\r