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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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