OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTUS_APS3_GCC/] [Demo/] [7seg.c] - Blame information for rev 579

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 579 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
 
55
#include <stdlib.h>
56
 
57
/* Scheduler include files. */
58
#include "FreeRTOS.h"
59
#include "task.h"
60
 
61
/* Demo program include files. */
62
#include "7seg.h"
63
#include "demoGpio.h"
64
 
65
#define x7segSTACK_SIZE                 configMINIMAL_STACK_SIZE
66
 
67
static void prvRefreshTask( void *pvParameters );
68
static void prvCountTask( void *pvParameters );
69
 
70
/* Value to output to 7 segment display
71
led_digits[0] is the right most digit */
72
static signed char seg7_digits[4];
73
 
74
void vStart7SegTasks( unsigned portBASE_TYPE uxPriority )
75
{
76
        xTaskCreate( prvRefreshTask, ( signed char * ) "7SegRefresh", x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL );
77
        xTaskCreate( prvCountTask,   ( signed char * ) "7SegCount",     x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL );
78
}
79
/*-----------------------------------------------------------*/
80
 
81
static void prvRefreshTask( void *pvParameters )
82
{
83
/* This is table 3.3 from the Spartan-3 Starter Kit board user guide */
84
const unsigned char bits[ 16 ] =
85
{
86
        0x01,
87
        0x4f,
88
        0x12,
89
        0x06,
90
        0x4c,
91
        0x24,
92
        0x20,
93
        0x0f,
94
        0x00,
95
        0x04,
96
        0x08,
97
        0x60,
98
        0x31,
99
        0x42,
100
        0x30,
101
        0x38
102
};
103
 
104
const unsigned char apsx[4] =
105
{
106
        0x06, /* 3 */
107
        0x24, /* S */
108
        0x18, /* P */
109
        0x08  /* A */
110
};
111
 
112
portTickType xRefreshRate, xLastRefreshTime;
113
 
114
/* Digit to scan */
115
static int d = 0;
116
 
117
        xRefreshRate = 2;
118
 
119
        /* We need to initialise xLastRefreshTime prior to the first call to
120
        vTaskDelayUntil(). */
121
        xLastRefreshTime = xTaskGetTickCount();
122
 
123
        for (;;)
124
        {
125
                for( d = 0; d < 4; d++ )
126
                {
127
                        vTaskDelayUntil ( &xLastRefreshTime, xRefreshRate );
128
 
129
                        /* Display digit */
130
                        gpio->out.an  = -1;
131
                        if( ( seg7_digits[ 1 ] == 4 ) || ( seg7_digits[ 1 ] == 5 ) )
132
                        {
133
                                gpio->out.digit = apsx[ d ];
134
                        }
135
                        else
136
                        {
137
                                gpio->out.digit = bits[ seg7_digits[ d ] ];
138
                        }
139
 
140
                        gpio->out.dp = 1;
141
                        gpio->out.an  = ~(1 << d);
142
                }
143
        }
144
}
145
/*-----------------------------------------------------------*/
146
 
147
static void prvCountTask( void *pvParameters )
148
{
149
portTickType xCountRate, xLastCountTime;
150
 
151
        /* Approximately 20HZ */
152
        xCountRate = configTICK_RATE_HZ / 20;
153
 
154
        /* We need to initialise xLastCountTime prior to the first call to
155
        vTaskDelayUntil(). */
156
        xLastCountTime = xTaskGetTickCount();
157
 
158
        for (;;)
159
        {
160
                vTaskDelayUntil( &xLastCountTime, xCountRate );
161
 
162
                /* Really ugly way to do BCD arithmetic.... */
163
                seg7_digits[ 0 ] -= 1;
164
                if( seg7_digits[ 0 ] < 0 )
165
                {
166
                        seg7_digits[ 0 ] = 9;
167
                        seg7_digits[ 1 ] -= 1;
168
                        if( seg7_digits[ 1 ] < 0 )
169
                        {
170
                                seg7_digits[ 1 ] = 9;
171
                                seg7_digits[ 2 ] -= 1;
172
                                if( seg7_digits[ 2 ] < 0 )
173
                                {
174
                                        seg7_digits[ 2 ] = 9;
175
                                        seg7_digits[ 3 ] -= 1;
176
                                        if( seg7_digits[ 3 ] < 0 )
177
                                        {
178
                                                seg7_digits[ 3 ] = 9;
179
                                        }
180
                                }
181
                        }
182
                }
183
        }
184
}
185
 
186
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.