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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [Minimal/] [integer.c] - Blame information for rev 609

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

Line No. Rev Author Line
1 606 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 version of integer. c is for use on systems that have limited stack
56
 * space and no display facilities.  The complete version can be found in
57
 * the Demo/Common/Full directory.
58
 *
59
 * As with the full version, the tasks created in this file are a good test
60
 * of the scheduler context switch mechanism.  The processor has to access
61
 * 32bit variables in two or four chunks (depending on the processor).  The low
62
 * priority of these tasks means there is a high probability that a context
63
 * switch will occur mid calculation.  See flop. c documentation for
64
 * more information.
65
 *
66
 */
67
 
68
/*
69
Changes from V1.2.1
70
 
71
        + The constants used in the calculations are larger to ensure the
72
          optimiser does not truncate them to 16 bits.
73
 
74
Changes from V1.2.3
75
 
76
        + uxTaskCheck is now just used as a boolean.  Instead of incrementing
77
          the variable each cycle of the task, the variable is simply set to
78
          true.  sAreIntegerMathsTaskStillRunning() sets it back to false and
79
          expects it to have been set back to true by the time it is called
80
          again.
81
        + A division has been included in the calculation.
82
*/
83
 
84
#include <stdlib.h>
85
 
86
/* Scheduler include files. */
87
#include "FreeRTOS.h"
88
#include "task.h"
89
 
90
/* Demo program include files. */
91
#include "integer.h"
92
 
93
/* The constants used in the calculation. */
94
#define intgCONST1                              ( ( long ) 123 )
95
#define intgCONST2                              ( ( long ) 234567 )
96
#define intgCONST3                              ( ( long ) -3 )
97
#define intgCONST4                              ( ( long ) 7 )
98
#define intgEXPECTED_ANSWER             ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
99
 
100
#define intgSTACK_SIZE                  configMINIMAL_STACK_SIZE
101
 
102
/* As this is the minimal version, we will only create one task. */
103
#define intgNUMBER_OF_TASKS             ( 1 )
104
 
105
/* The task function.  Repeatedly performs a 32 bit calculation, checking the
106
result against the expected result.  If the result is incorrect then the
107
context switch must have caused some corruption. */
108
static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
109
 
110
/* Variables that are set to true within the calculation task to indicate
111
that the task is still executing.  The check task sets the variable back to
112
false, flagging an error if the variable is still false the next time it
113
is called. */
114
static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
115
 
116
/*-----------------------------------------------------------*/
117
 
118
void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
119
{
120
short sTask;
121
 
122
        for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
123
        {
124
                xTaskCreate( vCompeteingIntMathTask, ( signed char * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
125
        }
126
}
127
/*-----------------------------------------------------------*/
128
 
129
static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
130
{
131
/* These variables are all effectively set to constants so they are volatile to
132
ensure the compiler does not just get rid of them. */
133
volatile long lValue;
134
short sError = pdFALSE;
135
volatile signed portBASE_TYPE *pxTaskHasExecuted;
136
 
137
        /* Set a pointer to the variable we are going to set to true each
138
        iteration.  This is also a good test of the parameter passing mechanism
139
        within each port. */
140
        pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
141
 
142
        /* Keep performing a calculation and checking the result against a constant. */
143
        for( ;; )
144
        {
145
                /* Perform the calculation.  This will store partial value in
146
                registers, resulting in a good test of the context switch mechanism. */
147
                lValue = intgCONST1;
148
                lValue += intgCONST2;
149
 
150
                /* Yield in case cooperative scheduling is being used. */
151
                #if configUSE_PREEMPTION == 0
152
                {
153
                        taskYIELD();
154
                }
155
                #endif
156
 
157
                /* Finish off the calculation. */
158
                lValue *= intgCONST3;
159
                lValue /= intgCONST4;
160
 
161
                /* If the calculation is found to be incorrect we stop setting the
162
                TaskHasExecuted variable so the check task can see an error has
163
                occurred. */
164
                if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
165
                {
166
                        sError = pdTRUE;
167
                }
168
 
169
                if( sError == pdFALSE )
170
                {
171
                        /* We have not encountered any errors, so set the flag that show
172
                        we are still executing.  This will be periodically cleared by
173
                        the check task. */
174
                        portENTER_CRITICAL();
175
                                *pxTaskHasExecuted = pdTRUE;
176
                        portEXIT_CRITICAL();
177
                }
178
 
179
                /* Yield in case cooperative scheduling is being used. */
180
                #if configUSE_PREEMPTION == 0
181
                {
182
                        taskYIELD();
183
                }
184
                #endif
185
        }
186
}
187
/*-----------------------------------------------------------*/
188
 
189
/* This is called to check that all the created tasks are still running. */
190
portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
191
{
192
portBASE_TYPE xReturn = pdTRUE;
193
short sTask;
194
 
195
        /* Check the maths tasks are still running by ensuring their check variables
196
        are still being set to true. */
197
        for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
198
        {
199
                if( xTaskCheck[ sTask ] == pdFALSE )
200
                {
201
                        /* The check has not incremented so an error exists. */
202
                        xReturn = pdFALSE;
203
                }
204
 
205
                /* Reset the check variable so we can tell if it has been set by
206
                the next time around. */
207
                xTaskCheck[ sTask ] = pdFALSE;
208
        }
209
 
210
        return xReturn;
211
}
212
 

powered by: WebSVN 2.1.0

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