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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [OpenRISC_SIM_GCC/] [main.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 jeremybenn
 
2
/*
3
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
4
 
5
    ***************************************************************************
6
    *                                                                         *
7
    * If you are:                                                             *
8
    *                                                                         *
9
    *    + New to FreeRTOS,                                                   *
10
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
11
    *    + Looking for basic training,                                        *
12
    *    + Wanting to improve your FreeRTOS skills and productivity           *
13
    *                                                                         *
14
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
15
    *                                                                         *
16
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
17
    *                  http://www.FreeRTOS.org/Documentation                  *
18
    *                                                                         *
19
    * A pdf reference manual is also available.  Both are usually delivered   *
20
    * to your inbox within 20 minutes to two hours when purchased between 8am *
21
    * and 8pm GMT (although please allow up to 24 hours in case of            *
22
    * exceptional circumstances).  Thank you for your support!                *
23
    *                                                                         *
24
    ***************************************************************************
25
 
26
    This file is part of the FreeRTOS distribution.
27
 
28
    FreeRTOS is free software; you can redistribute it and/or modify it under
29
    the terms of the GNU General Public License (version 2) as published by the
30
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
31
    ***NOTE*** The exception to the GPL is included to allow you to distribute
32
    a combined work that includes FreeRTOS without being obliged to provide the
33
    source code for proprietary components outside of the FreeRTOS kernel.
34
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
35
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
37
    more details. You should have received a copy of the GNU General Public
38
    License and the FreeRTOS license exception along with FreeRTOS; if not it
39
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
40
    by writing to Richard Barry, contact details for whom are available on the
41
    FreeRTOS WEB site.
42
 
43
    1 tab == 4 spaces!
44
 
45
    http://www.FreeRTOS.org - Documentation, latest information, license and
46
    contact details.
47
 
48
    http://www.SafeRTOS.com - A version that is certified for use in safety
49
    critical systems.
50
 
51
    http://www.OpenRTOS.com - Commercial support, development, porting,
52
    licensing and training services.
53
*/
54
 
55
#include <stdlib.h>
56
#include <string.h>
57
 
58
/* Architecture specific header files. */
59
#include "spr_defs.h"
60
 
61
/* Scheduler header files. */
62
#include "FreeRTOS.h"
63
#include "task.h"
64
 
65
#include "uart.h"
66
#include "int.h"
67
 
68
#define TASK_STACK_SIZE (configMINIMAL_STACK_SIZE)
69
 
70
static void prvSetupHardware(void);
71
void vDemoTask(void *pvParameters);
72
void vClockTask(void *pvParameters);
73
 
74
void vApplicationTickHook(void);
75
void vApplicationIdleHook(void);
76
void vApplicationStackOverflowHook(xTaskHandle *pxTask, signed char *pcTaskName);
77
 
78
int main(int argc, char **argv) {
79
        argc = argc;
80
        argv = argv;
81
 
82
        portBASE_TYPE delay[3] = {600, 400, 200};
83
 
84
        prvSetupHardware();
85
 
86
        xTaskCreate(vDemoTask , (signed char *)"vTask0", TASK_STACK_SIZE, (void*)&delay[0], 1, (xTaskHandle)NULL);
87
        xTaskCreate(vDemoTask , (signed char *)"vTask1", TASK_STACK_SIZE, (void*)&delay[1], 2, (xTaskHandle)NULL);
88
        xTaskCreate(vDemoTask , (signed char *)"vTask2", TASK_STACK_SIZE, (void*)&delay[2], 3, (xTaskHandle)NULL);
89
        xTaskCreate(vClockTask, (signed char *)"vClock", TASK_STACK_SIZE, (void*)&delay[2], 3, (xTaskHandle)NULL);
90
 
91
        vTaskStartScheduler();
92
 
93
        // Control will not reach here
94
        return 0;
95
}
96
 
97
void vClockTask(void *pvParameters) {
98
        pvParameters = pvParameters;
99
        unsigned portBASE_TYPE ticks = xTaskGetTickCount();
100
 
101
        int hour = 0;
102
        int min = 0;
103
        int sec = -1;
104
        while(1) {
105
                sec += 1;
106
                if(sec == 60) {
107
                        sec = 0;
108
                        min += 1;
109
                }
110
                if(min == 60) {
111
                        min = 0;
112
                        hour += 1;
113
                }
114
                if(hour == 24) {
115
                        hour = 0;
116
                }
117
 
118
                portENTER_CRITICAL();
119
                {
120
                        uart_put_int(hour);
121
                        uart_print_str(" : ");
122
                        uart_put_int(min);
123
                        uart_print_str(" : ");
124
                        uart_put_int(sec);
125
                        uart_print_str(" , ");
126
                        uart_put_int(ticks);
127
                        uart_print_str("\n\r");
128
                }
129
                portEXIT_CRITICAL();
130
 
131
                vTaskDelay(1000);
132
                ticks = xTaskGetTickCount();
133
        }
134
}
135
 
136
void vDemoTask(void *pvParameters) {
137
        // unsigned portBASE_TYPE priority = uxTaskPriorityGet(NULL);
138
        unsigned portBASE_TYPE ticks = xTaskGetTickCount();
139
        portTickType delay = *((portTickType *)pvParameters);
140
 
141
        while(1) {
142
                portENTER_CRITICAL();
143
                {
144
                        uart_print_str("vTask ");
145
                        uart_put_int(delay);
146
                        uart_print_str(" : ");
147
                        // uart_put_int(priority);
148
                        // uart_print_str(" , ");
149
                        uart_put_int(ticks);
150
                        uart_print_str(" \n\r");
151
                }
152
                portEXIT_CRITICAL();
153
                vTaskDelay(delay);
154
                ticks = xTaskGetTickCount();
155
        }
156
}
157
 
158
static void prvSetupHardware(void) {
159
        // UART controller use 25 Mhz Wishbone bus clock, define in board.h
160
        uart_init();
161
 
162
        // Initialize internal Programmable Interrupt Controller
163
        int_init();
164
}
165
 
166
void vApplicationTickHook(void) {
167
        uart_print_str(".");
168
}
169
 
170
void vApplicationIdleHook(void) {
171
        uart_print_str(" i ");
172
}
173
 
174
void vApplicationStackOverflowHook(xTaskHandle *pxTask, signed char *pcTaskName) {
175
        pxTask = pxTask;
176
        pcTaskName = pcTaskName;
177
 
178
        uart_print_str(" S \n\r");
179
}

powered by: WebSVN 2.1.0

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