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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [PIC18_WizC/] [Demo1/] [main.c] - Blame information for rev 587

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 587 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
Changes from V3.0.0
56
 
57
Changes from V3.0.1
58
*/
59
 
60
/*
61
 * Instead of the normal single demo application, the PIC18F demo is split
62
 * into several smaller programs of which this is the first.  This enables the
63
 * demo's to be executed on the RAM limited PIC-devices.
64
 *
65
 * The Demo1 project is configured for a PIC18F4620 device.  Main.c starts 9
66
 * tasks (including the idle task).
67
 
68
 * This first demo is included to do a quick check on the FreeRTOS
69
 * installation. It is also included to demonstrate a minimal project-setup
70
 * to use FreeRTOS in a wizC environment.
71
 *
72
 * Eight independant tasks are created. All tasks share the same taskcode.
73
 * Each task blinks a different led on portB. The blinkrate for each task
74
 * is different, but chosen in such a way that portB will show a binary
75
 * counter pattern. All blinkrates are derived from a single master-rate.
76
 * By default, this  masterrate is set to 100 milliseconds. Although such
77
 * a low value will make it almost impossible to see some of the leds
78
 * actually blink, it is a good value when using the wizC-simulator.
79
 * When testing on a real chip, changing the value to eg. 500 milliseconds
80
 * would be appropiate.
81
 */
82
 
83
/* Scheduler include files. */
84
#include <FreeRTOS.h>
85
#include <task.h>
86
 
87
#define mainBLINK_LED_INTERVAL  ( ( portTickType ) 100 / ( portTICK_RATE_MS ) )
88
 
89
/* The LED that is flashed by the B0 task. */
90
#define mainBLINK_LED0_PORT             LATD
91
#define mainBLINK_LED0_TRIS             TRISD
92
#define mainBLINK_LED0_PIN              0
93
#define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))
94
 
95
/* The LED that is flashed by the B1 task. */
96
#define mainBLINK_LED1_PORT             LATD
97
#define mainBLINK_LED1_TRIS             TRISD
98
#define mainBLINK_LED1_PIN              1
99
#define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))
100
 
101
/* The LED that is flashed by the B2 task. */
102
#define mainBLINK_LED2_PORT             LATD
103
#define mainBLINK_LED2_TRIS             TRISD
104
#define mainBLINK_LED2_PIN              2
105
#define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))
106
 
107
/* The LED that is flashed by the B3 task. */
108
#define mainBLINK_LED3_PORT             LATD
109
#define mainBLINK_LED3_TRIS             TRISD
110
#define mainBLINK_LED3_PIN              3
111
#define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))
112
 
113
/* The LED that is flashed by the B4 task. */
114
#define mainBLINK_LED4_PORT             LATD
115
#define mainBLINK_LED4_TRIS             TRISD
116
#define mainBLINK_LED4_PIN              4
117
#define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))
118
 
119
/* The LED that is flashed by the B5 task. */
120
#define mainBLINK_LED5_PORT             LATD
121
#define mainBLINK_LED5_TRIS             TRISD
122
#define mainBLINK_LED5_PIN              5
123
#define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))
124
 
125
/* The LED that is flashed by the B6 task. */
126
#define mainBLINK_LED6_PORT             LATD
127
#define mainBLINK_LED6_TRIS             TRISD
128
#define mainBLINK_LED6_PIN              6
129
#define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))
130
 
131
/* The LED that is flashed by the B7 task. */
132
#define mainBLINK_LED7_PORT             LATD
133
#define mainBLINK_LED7_TRIS             TRISD
134
#define mainBLINK_LED7_PIN              7
135
#define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))
136
 
137
typedef struct {
138
        unsigned char *port;
139
        unsigned char *tris;
140
        unsigned char pin;
141
        portTickType  interval;
142
} SBLINK;
143
 
144
const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};
145
const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};
146
const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};
147
const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};
148
const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};
149
const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};
150
const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};
151
const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};
152
 
153
/*
154
 * The task code for the "vBlink" task.
155
 */
156
static portTASK_FUNCTION_PROTO(vBlink, pvParameters);
157
 
158
/*-----------------------------------------------------------*/
159
 
160
/*
161
 * Creates the tasks, then starts the scheduler.
162
 */
163
void main( void )
164
{
165
        /*
166
         * Start the blink tasks defined in this file.
167
         */
168
        xTaskCreate( vBlink,  "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );
169
        xTaskCreate( vBlink,  "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );
170
        xTaskCreate( vBlink,  "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );
171
        xTaskCreate( vBlink,  "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );
172
        xTaskCreate( vBlink,  "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );
173
        xTaskCreate( vBlink,  "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );
174
        xTaskCreate( vBlink,  "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );
175
        xTaskCreate( vBlink,  "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );
176
 
177
        /*
178
         * Start the scheduler.
179
         */
180
        vTaskStartScheduler( );
181
 
182
        while(1)        /* This point should never be reached. */
183
        {
184
        }
185
}
186
/*-----------------------------------------------------------*/
187
 
188
static portTASK_FUNCTION(vBlink, pvParameters)
189
{
190
        unsigned char   *Port           = ((SBLINK *)pvParameters)->port;
191
        unsigned char   *Tris           = ((SBLINK *)pvParameters)->tris;
192
        unsigned char   Pin                     = ((SBLINK *)pvParameters)->pin;
193
        portTickType    Interval        = ((SBLINK *)pvParameters)->interval;
194
 
195
        portTickType    xLastWakeTime;
196
 
197
        /*
198
         * Initialize the hardware
199
         */
200
        *Tris &= ~(1<<Pin);     // Set the pin that is used by this task to ouput
201
        *Port &= ~(1<<Pin);     // Drive the pin low
202
 
203
        /*
204
         * Initialise the xLastWakeTime variable with the current time.
205
         */
206
        xLastWakeTime = xTaskGetTickCount();
207
 
208
        /*
209
         * Cycle for ever, delaying then toggle the LED.
210
         */
211
        for( ;; )
212
        {
213
                /*
214
                 * Wait until it is time to toggle
215
                 */
216
                vTaskDelayUntil( &xLastWakeTime, Interval );
217
 
218
                /*
219
                 * Toggle the LED for visual feedback.
220
                 */
221
                *Port ^= 1<<Pin;
222
        }
223
}

powered by: WebSVN 2.1.0

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