2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
31 /* Scheduler include files. */
\r
32 #include "FreeRTOS.h"
\r
35 /* Demo program include files. */
\r
37 #include "demoGpio.h"
\r
39 #define x7segSTACK_SIZE configMINIMAL_STACK_SIZE
\r
41 static void prvRefreshTask( void *pvParameters );
\r
42 static void prvCountTask( void *pvParameters );
\r
44 /* Value to output to 7 segment display
\r
45 led_digits[0] is the right most digit */
\r
46 static signed char seg7_digits[4];
\r
48 void vStart7SegTasks( unsigned portBASE_TYPE uxPriority )
\r
50 xTaskCreate( prvRefreshTask, "7SegRefresh", x7segSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t *) NULL );
\r
51 xTaskCreate( prvCountTask, "7SegCount", x7segSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t *) NULL );
\r
53 /*-----------------------------------------------------------*/
\r
55 static void prvRefreshTask( void *pvParameters )
\r
57 /* This is table 3.3 from the Spartan-3 Starter Kit board user guide */
\r
58 const unsigned char bits[ 16 ] =
\r
78 const unsigned char apsx[4] =
\r
86 TickType_t xRefreshRate, xLastRefreshTime;
\r
93 /* We need to initialise xLastRefreshTime prior to the first call to
\r
94 vTaskDelayUntil(). */
\r
95 xLastRefreshTime = xTaskGetTickCount();
\r
99 for( d = 0; d < 4; d++ )
\r
101 vTaskDelayUntil ( &xLastRefreshTime, xRefreshRate );
\r
103 /* Display digit */
\r
105 if( ( seg7_digits[ 1 ] == 4 ) || ( seg7_digits[ 1 ] == 5 ) )
\r
107 gpio->out.digit = apsx[ d ];
\r
111 gpio->out.digit = bits[ seg7_digits[ d ] ];
\r
115 gpio->out.an = ~(1 << d);
\r
119 /*-----------------------------------------------------------*/
\r
121 static void prvCountTask( void *pvParameters )
\r
123 TickType_t xCountRate, xLastCountTime;
\r
125 /* Approximately 20HZ */
\r
126 xCountRate = configTICK_RATE_HZ / 20;
\r
128 /* We need to initialise xLastCountTime prior to the first call to
\r
129 vTaskDelayUntil(). */
\r
130 xLastCountTime = xTaskGetTickCount();
\r
134 vTaskDelayUntil( &xLastCountTime, xCountRate );
\r
136 /* Really ugly way to do BCD arithmetic.... */
\r
137 seg7_digits[ 0 ] -= 1;
\r
138 if( seg7_digits[ 0 ] < 0 )
\r
140 seg7_digits[ 0 ] = 9;
\r
141 seg7_digits[ 1 ] -= 1;
\r
142 if( seg7_digits[ 1 ] < 0 )
\r
144 seg7_digits[ 1 ] = 9;
\r
145 seg7_digits[ 2 ] -= 1;
\r
146 if( seg7_digits[ 2 ] < 0 )
\r
148 seg7_digits[ 2 ] = 9;
\r
149 seg7_digits[ 3 ] -= 1;
\r
150 if( seg7_digits[ 3 ] < 0 )
\r
152 seg7_digits[ 3 ] = 9;
\r