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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [RX600_RX62N-RDK_IAR/] [main-blinky.c] - Blame information for rev 773

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

Line No. Rev Author Line
1 585 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
 * This is a very simple demo that creates two tasks and one queue.  One task
56
 * (the queue receive task) blocks on the queue to wait for data to arrive,
57
 * toggling an LED each time '100' is received.  The other task (the queue send
58
 * task) repeatedly blocks for a fixed period before sending '100' to the queue
59
 * (causing the first task to toggle the LED).
60
 *
61
 * For a much more complete and complex example select either the Debug or
62
 * Debug_with_optimisation build configurations within the Embedded Workbench
63
 * IDE.
64
*/
65
 
66
/* Hardware specific includes. */
67
#include <iorx62n.h>
68
 
69
/* Kernel includes. */
70
#include "FreeRTOS.h"
71
#include "task.h"
72
#include "queue.h"
73
 
74
/* Demo includes. */
75
#include "partest.h"
76
 
77
/* Priorities at which the tasks are created. */
78
#define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )
79
#define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )
80
 
81
/* The rate at which data is sent to the queue, specified in milliseconds. */
82
#define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_RATE_MS )
83
 
84
/* The number of items the queue can hold.  This is 1 as the receive task
85
will remove items as they are added so the send task should always find the
86
queue empty. */
87
#define mainQUEUE_LENGTH                                        ( 1 )
88
 
89
/*
90
 * The tasks as defined at the top of this file.
91
 */
92
static void prvQueueReceiveTask( void *pvParameters );
93
static void prvQueueSendTask( void *pvParameters );
94
 
95
/* The queue used by both tasks. */
96
static xQueueHandle xQueue = NULL;
97
 
98
/* This variable is not used by this simple Blinky example.  It is defined
99
purely to allow the project to link as it is used by the full project. */
100
volatile unsigned long ulHighFrequencyTickCount = 0UL;
101
/*-----------------------------------------------------------*/
102
 
103
void main(void)
104
{
105
extern void HardwareSetup( void );
106
 
107
        /* Renesas provided CPU configuration routine.  The clocks are configured in
108
        here. */
109
        HardwareSetup();
110
 
111
        /* Create the queue. */
112
        xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
113
 
114
        if( xQueue != NULL )
115
        {
116
                /* Start the two tasks as described at the top of this file. */
117
                xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
118
                xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
119
 
120
                /* Start the tasks running. */
121
                vTaskStartScheduler();
122
        }
123
 
124
        /* If all is well we will never reach here as the scheduler will now be
125
        running.  If we do reach here then it is likely that there was insufficient
126
        heap available for the idle task to be created. */
127
        for( ;; );
128
}
129
/*-----------------------------------------------------------*/
130
 
131
static void prvQueueSendTask( void *pvParameters )
132
{
133
portTickType xNextWakeTime;
134
const unsigned long ulValueToSend = 100UL;
135
 
136
        /* Initialise xNextWakeTime - this only needs to be done once. */
137
        xNextWakeTime = xTaskGetTickCount();
138
 
139
        for( ;; )
140
        {
141
                /* Place this task in the blocked state until it is time to run again.
142
                The block state is specified in ticks, the constant used converts ticks
143
                to ms. */
144
                vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
145
 
146
                /* Send to the queue - causing the queue receive task to flash its LED.  0
147
                is used so the send does not block - it shouldn't need to as the queue
148
                should always be empty here. */
149
                xQueueSend( xQueue, &ulValueToSend, 0 );
150
        }
151
}
152
/*-----------------------------------------------------------*/
153
 
154
static void prvQueueReceiveTask( void *pvParameters )
155
{
156
unsigned long ulReceivedValue;
157
 
158
        for( ;; )
159
        {
160
                /* Wait until something arives in the queue - this will block
161
                indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
162
                FreeRTOSConfig.h. */
163
                xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
164
 
165
                /*  To get here something must have arrived, but is it the expected
166
                value?  If it is, toggle the LED. */
167
                if( ulReceivedValue == 100UL )
168
                {
169
                        vParTestToggleLED( 0 );
170
                }
171
        }
172
}
173
/*-----------------------------------------------------------*/
174
 
175
void vApplicationSetupTimerInterrupt( void )
176
{
177
        /* Enable compare match timer 0. */
178
        MSTP( CMT0 ) = 0;
179
 
180
        /* Interrupt on compare match. */
181
        CMT0.CMCR.BIT.CMIE = 1;
182
 
183
        /* Set the compare match value. */
184
        CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
185
 
186
        /* Divide the PCLK by 8. */
187
        CMT0.CMCR.BIT.CKS = 0;
188
 
189
        /* Enable the interrupt... */
190
        _IEN( _CMT0_CMI0 ) = 1;
191
 
192
        /* ...and set its priority to the application defined kernel priority. */
193
        _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
194
 
195
        /* Start the timer. */
196
        CMT.CMSTR0.BIT.STR0 = 1;
197
}
198
/*-----------------------------------------------------------*/
199
 
200
/* This function is explained by the comments above its prototype at the top
201
of this file. */
202
void vApplicationMallocFailedHook( void )
203
{
204
        for( ;; );
205
}
206
/*-----------------------------------------------------------*/
207
 
208
/* This function is explained by the comments above its prototype at the top
209
of this file. */
210
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
211
{
212
        for( ;; );
213
}
214
/*-----------------------------------------------------------*/
215
 
216
/* This function is explained by the comments above its prototype at the top
217
of this file. */
218
void vApplicationIdleHook( void )
219
{
220
        /* Just to prevent the variable getting optimised away. */
221
        ( void ) ulHighFrequencyTickCount;
222
}
223
/*-----------------------------------------------------------*/
224
 
225
/* The following two functions are here just to allow all three build
226
configurations to use the same vector table.  They are not used in this
227
demo, but linker errors will result if they are not defined.  They can
228
be ignored. */
229
void vT0_1InterruptHandler( void ) {}
230
void vT2_3InterruptHandler( void ) {}

powered by: WebSVN 2.1.0

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