mirror of
				https://github.com/FreeRTOS/FreeRTOS-Kernel.git
				synced 2025-11-03 18:22:45 -05:00 
			
		
		
		
	Continue FX16 demo development.
This commit is contained in:
		
							parent
							
								
									d61373702a
								
							
						
					
					
						commit
						d71ed5975c
					
				
					 6 changed files with 373 additions and 75 deletions
				
			
		| 
						 | 
				
			
			@ -59,6 +59,10 @@
 | 
			
		|||
#define diceSTATE_STARTUP		1
 | 
			
		||||
#define diceSTATE_RUNNING		2
 | 
			
		||||
 | 
			
		||||
#define diceEND_DELAY			( 5000 / portTICK_RATE_MS )
 | 
			
		||||
 | 
			
		||||
#define dice7SEG_Value( x )		*( pucDisplayOutput[ x ] )
 | 
			
		||||
 | 
			
		||||
static unsigned char prvButtonHit( unsigned char ucIndex );
 | 
			
		||||
 | 
			
		||||
static const char cDisplaySegments[ 2 ][ 11 ] =
 | 
			
		||||
| 
						 | 
				
			
			@ -67,13 +71,16 @@ static const char cDisplaySegments[ 2 ][ 11 ] =
 | 
			
		|||
	{ 0xa0, 0xf3, 0xc4, 0xc1, 0x93, 0x89, 0x88, 0xe3, 0x80, 0x81, 0x7f }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern volatile unsigned char *pucDisplayOutput[ 2 ];
 | 
			
		||||
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void vDiceTask( void *pvParameters )
 | 
			
		||||
{
 | 
			
		||||
char cDiceState = diceSTATE_STOPPED;
 | 
			
		||||
unsigned char ucDiceValue, ucIndex;
 | 
			
		||||
unsigned long ulDice1RunTime, ulDiceDelay, ulDiceDelayReload;
 | 
			
		||||
unsigned long ulDiceRunTime, ulDiceDelay, ulDiceDelayReload;
 | 
			
		||||
extern void vToggleFlashTaskSuspendState( void );
 | 
			
		||||
 | 
			
		||||
	ucIndex = ( unsigned char ) pvParameters;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -85,49 +92,64 @@ unsigned long ulDice1RunTime, ulDiceDelay, ulDiceDelayReload;
 | 
			
		|||
 | 
			
		||||
				if( prvButtonHit( ucIndex ) == pdTRUE )
 | 
			
		||||
				{
 | 
			
		||||
					ulDice1RunTime = diceRUN_MIN;
 | 
			
		||||
					srand( ( unsigned char ) ulDice1RunTime );
 | 
			
		||||
					ulDiceRunTime = diceRUN_MIN;
 | 
			
		||||
					srand( ( unsigned char ) ulDiceRunTime );
 | 
			
		||||
					cDiceState = diceSTATE_STARTUP;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case diceSTATE_STARTUP:
 | 
			
		||||
 | 
			
		||||
				if( ulDice1RunTime < diceRUN_MAX )     // variable running time
 | 
			
		||||
				if( ulDiceRunTime < diceRUN_MAX )     // variable running time
 | 
			
		||||
				{
 | 
			
		||||
					ulDice1RunTime++;
 | 
			
		||||
					ulDiceRunTime++;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					ulDice1RunTime = diceRUN_MIN;
 | 
			
		||||
					ulDiceRunTime = diceRUN_MIN;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if( PDR00_P0 == 0 )              // Key SW2:INT8 released
 | 
			
		||||
				if( prvButtonHit( ucIndex ) == pdFALSE )
 | 
			
		||||
				{
 | 
			
		||||
					if( ucIndex == 0 )
 | 
			
		||||
					{
 | 
			
		||||
						vToggleFlashTaskSuspendState();
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					ulDiceDelay = 1;
 | 
			
		||||
					ulDiceDelayReload = 1;
 | 
			
		||||
					cDiceState = diceSTATE_RUNNING;
 | 
			
		||||
				}   
 | 
			
		||||
				       
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case diceSTATE_RUNNING:
 | 
			
		||||
 | 
			
		||||
				ulDice1RunTime--;
 | 
			
		||||
				ulDiceRunTime--;
 | 
			
		||||
				ulDiceDelay--;
 | 
			
		||||
 | 
			
		||||
				if( !ulDiceDelay )
 | 
			
		||||
				{
 | 
			
		||||
					ucDiceValue = rand() % 6 + 1;
 | 
			
		||||
					PDR03 = ( PDR03 | 0xf7 ) & cDisplaySegments[ ucIndex ][ ucDiceValue ];
 | 
			
		||||
					dice7SEG_Value( ucIndex ) = ( dice7SEG_Value( ucIndex ) | 0xf7 ) & cDisplaySegments[ ucIndex ][ ucDiceValue ];
 | 
			
		||||
					ulDiceDelayReload = ulDiceDelayReload + 100;
 | 
			
		||||
					ulDiceDelay = ulDiceDelayReload;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if( ulDice1RunTime == 0 )         // dice stopped
 | 
			
		||||
				if( ulDiceRunTime == 0 )
 | 
			
		||||
				{
 | 
			
		||||
					PDR03 = ( PDR03 | 0xf7 ) & cDisplaySegments[ ucIndex ][ rand() % 6 + 1 ];
 | 
			
		||||
					dice7SEG_Value( ucIndex ) = ( dice7SEG_Value( ucIndex ) | 0xf7 ) & cDisplaySegments[ ucIndex ][ rand() % 6 + 1 ];
 | 
			
		||||
					cDiceState = diceSTATE_STOPPED;
 | 
			
		||||
 | 
			
		||||
					if( ucIndex == 0 )
 | 
			
		||||
					{
 | 
			
		||||
						vTaskDelay( diceEND_DELAY );
 | 
			
		||||
						*pucDisplayOutput[ ucIndex ] = 0xff;
 | 
			
		||||
						vToggleFlashTaskSuspendState();
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -152,69 +174,8 @@ static unsigned char prvButtonHit( unsigned char ucIndex )
 | 
			
		|||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
 | 
			
		||||
    // DICE 2
 | 
			
		||||
 | 
			
		||||
    switch (dice2state)
 | 
			
		||||
    {
 | 
			
		||||
      case 0x00: // dice2 stopped
 | 
			
		||||
                 if( PDR00_P1 == 1)              // Key SW3:INT9 pressed
 | 
			
		||||
                 {
 | 
			
		||||
                   dice2run = diceRUN_MIN;
 | 
			
		||||
                   srand((unsigned char)ulDice1RunTime);
 | 
			
		||||
                   dice2state = 0x01;
 | 
			
		||||
                 }
 | 
			
		||||
 | 
			
		||||
                 break;
 | 
			
		||||
 | 
			
		||||
      case 0x01: // dice2 startup
 | 
			
		||||
                 if( dice2run < diceRUN_MAX)     // variable running time
 | 
			
		||||
                   dice2run++;
 | 
			
		||||
                 else
 | 
			
		||||
                   dice2run = diceRUN_MIN;
 | 
			
		||||
            
 | 
			
		||||
                 if( dice2 == diceMAX)          // simple 'random' number
 | 
			
		||||
                   dice2 = diceMIN;
 | 
			
		||||
                 else dice2++;
 | 
			
		||||
 | 
			
		||||
                 if( PDR00_P1 == 0)              // Key SW3:INT9 released
 | 
			
		||||
                 {
 | 
			
		||||
                   dice2delay    = 1;
 | 
			
		||||
                   dice2delayrld = 1;
 | 
			
		||||
                   dice2state = 0x02;
 | 
			
		||||
                 }
 | 
			
		||||
                                  
 | 
			
		||||
                 break;
 | 
			
		||||
 | 
			
		||||
      case 0x02: // dice2 running
 | 
			
		||||
                 dice2run--;
 | 
			
		||||
                 dice2delay--;
 | 
			
		||||
 | 
			
		||||
                 if( !dice2delay)
 | 
			
		||||
                 {
 | 
			
		||||
                   do                       // get new random number
 | 
			
		||||
                   {
 | 
			
		||||
                    temp = rand() % 6 + 1;
 | 
			
		||||
                   }
 | 
			
		||||
                   while (temp == dice2);
 | 
			
		||||
                   dice2 = temp;
 | 
			
		||||
                   
 | 
			
		||||
                   PDR05 = DICE7SEG2[dice2];
 | 
			
		||||
                   dice2delayrld = dice2delayrld + 100;
 | 
			
		||||
                   dice2delay = dice2delayrld;
 | 
			
		||||
                 }
 | 
			
		||||
 | 
			
		||||
                 if( dice2run == 0)         // dice stopped
 | 
			
		||||
                 {
 | 
			
		||||
                   PDR05 = DICE7SEG2[rand() % 6 + 1];
 | 
			
		||||
                   dice2state = 0x00;
 | 
			
		||||
                 }
 | 
			
		||||
 | 
			
		||||
                 break;
 | 
			
		||||
 | 
			
		||||
    }//switch (dice2state)
 | 
			
		||||
    
 | 
			
		||||
  } // while(1)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,4 +17,6 @@
 | 
			
		|||
-a "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\heap_1.obj"
 | 
			
		||||
-a "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\croutine.obj"
 | 
			
		||||
-a "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\DiceTask.obj"
 | 
			
		||||
-a "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\ParTest.obj"
 | 
			
		||||
-a "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\flash.obj"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,4 +35,6 @@
 | 
			
		|||
"C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\heap_1.obj"
 | 
			
		||||
"C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\croutine.obj"
 | 
			
		||||
"C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\DiceTask.obj"
 | 
			
		||||
"C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\ParTest.obj"
 | 
			
		||||
"C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\MB96350_Softune_Dice_Kit\OBJ\flash.obj"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										160
									
								
								Demo/MB96350_Softune_Dice_Kit/ParTest/ParTest.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								Demo/MB96350_Softune_Dice_Kit/ParTest/ParTest.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,160 @@
 | 
			
		|||
/*
 | 
			
		||||
	FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 Richard Barry.
 | 
			
		||||
 | 
			
		||||
	This file is part of the FreeRTOS.org distribution.
 | 
			
		||||
 | 
			
		||||
	FreeRTOS.org is free software; you can redistribute it and/or modify
 | 
			
		||||
	it under the terms of the GNU General Public License as published by
 | 
			
		||||
	the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
	(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
	FreeRTOS.org is distributed in the hope that it will be useful,
 | 
			
		||||
	but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
	GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU General Public License
 | 
			
		||||
	along with FreeRTOS.org; if not, write to the Free Software
 | 
			
		||||
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
			
		||||
 | 
			
		||||
	A special exception to the GPL can be applied should you wish to distribute
 | 
			
		||||
	a combined work that includes FreeRTOS.org, without being obliged to provide
 | 
			
		||||
	the source code for any proprietary components.  See the licensing section
 | 
			
		||||
	of http://www.FreeRTOS.org for full details of how and when the exception
 | 
			
		||||
	can be applied.
 | 
			
		||||
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    *                                                                         *
 | 
			
		||||
    * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *
 | 
			
		||||
    * and even write all or part of your application on your behalf.          *
 | 
			
		||||
    * See http://www.OpenRTOS.com for details of the services we provide to   *
 | 
			
		||||
    * expedite your project.                                                  *
 | 
			
		||||
    *                                                                         *
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
 | 
			
		||||
	Please ensure to read the configuration and relevant port sections of the
 | 
			
		||||
	online documentation.
 | 
			
		||||
 | 
			
		||||
	http://www.FreeRTOS.org - Documentation, latest information, license and
 | 
			
		||||
	contact details.
 | 
			
		||||
 | 
			
		||||
	http://www.SafeRTOS.com - A version that is certified for use in safety
 | 
			
		||||
	critical systems.
 | 
			
		||||
 | 
			
		||||
	http://www.OpenRTOS.com - Commercial support, development, porting,
 | 
			
		||||
	licensing and training services.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*-----------------------------------------------------------
 | 
			
		||||
 * Simple parallel port IO routines.
 | 
			
		||||
 *-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/* FreeRTOS includes. */
 | 
			
		||||
#include "FreeRTOS.h"
 | 
			
		||||
#include "task.h"
 | 
			
		||||
 | 
			
		||||
/* Demo includes. */
 | 
			
		||||
#include "partest.h"
 | 
			
		||||
 | 
			
		||||
#define partstTOTAL_NUM_LEDs		16
 | 
			
		||||
#define partstNUM_LEDs_PER_DISPLAY	8
 | 
			
		||||
 | 
			
		||||
volatile unsigned char *pucDisplayOutput[ 2 ] = { ( unsigned portCHAR * ) 3, ( unsigned portCHAR * ) 5 };
 | 
			
		||||
 | 
			
		||||
void vParTestInitialise( void )
 | 
			
		||||
{
 | 
			
		||||
	/* In this case all the initialisation is performed in prvSetupHardware()
 | 
			
		||||
	in main.c. */	
 | 
			
		||||
}
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
 | 
			
		||||
{
 | 
			
		||||
unsigned portBASE_TYPE uxLEDMask = 0x01;
 | 
			
		||||
 | 
			
		||||
	if( uxLED < partstNUM_LEDs_PER_DISPLAY )
 | 
			
		||||
	{
 | 
			
		||||
		uxLEDMask <<= uxLED;
 | 
			
		||||
		
 | 
			
		||||
		taskENTER_CRITICAL();
 | 
			
		||||
		{
 | 
			
		||||
			if( xValue )
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 0 ] &= ~uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 0 ] |= uxLEDMask;				
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		taskEXIT_CRITICAL();
 | 
			
		||||
	}
 | 
			
		||||
	else if( uxLED < partstTOTAL_NUM_LEDs )
 | 
			
		||||
	{
 | 
			
		||||
		uxLED -= partstNUM_LEDs_PER_DISPLAY;
 | 
			
		||||
 | 
			
		||||
		uxLEDMask <<= uxLED;
 | 
			
		||||
		
 | 
			
		||||
		taskENTER_CRITICAL();
 | 
			
		||||
		{
 | 
			
		||||
			if( xValue )
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 1 ] &= ~uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 1 ] |= uxLEDMask;				
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		taskEXIT_CRITICAL();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
 | 
			
		||||
{
 | 
			
		||||
unsigned portBASE_TYPE uxLEDMask = 0x01;
 | 
			
		||||
 | 
			
		||||
	if( uxLED < partstNUM_LEDs_PER_DISPLAY )
 | 
			
		||||
	{
 | 
			
		||||
		uxLEDMask <<= uxLED;
 | 
			
		||||
		
 | 
			
		||||
		taskENTER_CRITICAL();
 | 
			
		||||
		{
 | 
			
		||||
			if( *pucDisplayOutput[ 0 ] & uxLEDMask )
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 0 ] &= ~uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 0 ] |= uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		taskEXIT_CRITICAL();
 | 
			
		||||
	}
 | 
			
		||||
	else if( uxLED < partstTOTAL_NUM_LEDs )
 | 
			
		||||
	{
 | 
			
		||||
		uxLED -= partstNUM_LEDs_PER_DISPLAY;
 | 
			
		||||
 | 
			
		||||
		uxLEDMask <<= uxLED;
 | 
			
		||||
		
 | 
			
		||||
		taskENTER_CRITICAL();
 | 
			
		||||
		{
 | 
			
		||||
			if( *pucDisplayOutput[ 1 ] & uxLEDMask )
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 1 ] &= ~uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				*pucDisplayOutput[ 1 ] |= uxLEDMask;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		taskEXIT_CRITICAL();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										164
									
								
								Demo/MB96350_Softune_Dice_Kit/flash.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								Demo/MB96350_Softune_Dice_Kit/flash.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,164 @@
 | 
			
		|||
/*
 | 
			
		||||
	FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 Richard Barry.
 | 
			
		||||
 | 
			
		||||
	This file is part of the FreeRTOS.org distribution.
 | 
			
		||||
 | 
			
		||||
	FreeRTOS.org is free software; you can redistribute it and/or modify
 | 
			
		||||
	it under the terms of the GNU General Public License as published by
 | 
			
		||||
	the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
	(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
	FreeRTOS.org is distributed in the hope that it will be useful,
 | 
			
		||||
	but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
	GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU General Public License
 | 
			
		||||
	along with FreeRTOS.org; if not, write to the Free Software
 | 
			
		||||
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
			
		||||
 | 
			
		||||
	A special exception to the GPL can be applied should you wish to distribute
 | 
			
		||||
	a combined work that includes FreeRTOS.org, without being obliged to provide
 | 
			
		||||
	the source code for any proprietary components.  See the licensing section 
 | 
			
		||||
	of http://www.FreeRTOS.org for full details of how and when the exception
 | 
			
		||||
	can be applied.
 | 
			
		||||
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    *                                                                         *
 | 
			
		||||
    * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *
 | 
			
		||||
    * and even write all or part of your application on your behalf.          *
 | 
			
		||||
    * See http://www.OpenRTOS.com for details of the services we provide to   *
 | 
			
		||||
    * expedite your project.                                                  *
 | 
			
		||||
    *                                                                         *
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
    ***************************************************************************
 | 
			
		||||
 | 
			
		||||
	Please ensure to read the configuration and relevant port sections of the
 | 
			
		||||
	online documentation.
 | 
			
		||||
 | 
			
		||||
	http://www.FreeRTOS.org - Documentation, latest information, license and 
 | 
			
		||||
	contact details.
 | 
			
		||||
 | 
			
		||||
	http://www.SafeRTOS.com - A version that is certified for use in safety 
 | 
			
		||||
	critical systems.
 | 
			
		||||
 | 
			
		||||
	http://www.OpenRTOS.com - Commercial support, development, porting, 
 | 
			
		||||
	licensing and training services.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This version of flash .c is for use on systems that have limited stack space
 | 
			
		||||
 * and no display facilities.  The complete version can be found in the 
 | 
			
		||||
 * Demo/Common/Full directory.
 | 
			
		||||
 * 
 | 
			
		||||
 * Three tasks are created, each of which flash an LED at a different rate.  The first 
 | 
			
		||||
 * LED flashes every 200ms, the second every 400ms, the third every 600ms.
 | 
			
		||||
 *
 | 
			
		||||
 * The LED flash tasks provide instant visual feedback.  They show that the scheduler 
 | 
			
		||||
 * is still operational.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
/* Scheduler include files. */
 | 
			
		||||
#include "FreeRTOS.h"
 | 
			
		||||
#include "task.h"
 | 
			
		||||
 | 
			
		||||
/* Demo program include files. */
 | 
			
		||||
#include "partest.h"
 | 
			
		||||
#include "flash.h"
 | 
			
		||||
 | 
			
		||||
#define ledSTACK_SIZE		configMINIMAL_STACK_SIZE
 | 
			
		||||
#define ledNUMBER_OF_LEDS	( 3 )
 | 
			
		||||
#define ledFLASH_RATE_BASE	( ( portTickType ) 333 )
 | 
			
		||||
 | 
			
		||||
/* Variable used by the created tasks to calculate the LED number to use, and
 | 
			
		||||
the rate at which they should flash the LED. */
 | 
			
		||||
static volatile unsigned portBASE_TYPE uxFlashTaskNumber = 0;
 | 
			
		||||
 | 
			
		||||
/* The task that is created three times. */
 | 
			
		||||
static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
 | 
			
		||||
 | 
			
		||||
static xTaskHandle xFlashTaskHandles[ ledNUMBER_OF_LEDS ] = { 0 };
 | 
			
		||||
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
 | 
			
		||||
{
 | 
			
		||||
signed portBASE_TYPE xLEDTask;
 | 
			
		||||
 | 
			
		||||
	/* Create the three tasks. */
 | 
			
		||||
	for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
 | 
			
		||||
	{
 | 
			
		||||
		/* Spawn the task. */
 | 
			
		||||
		xTaskCreate( vLEDFlashTask, ( signed portCHAR * ) "LEDx", ledSTACK_SIZE, NULL, uxPriority, &( xFlashTaskHandles[ xLEDTask ] ) );
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void vToggleFlashTaskSuspendState( void )
 | 
			
		||||
{
 | 
			
		||||
signed portBASE_TYPE xLEDTask;
 | 
			
		||||
 | 
			
		||||
	for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
 | 
			
		||||
	{
 | 
			
		||||
		if( xFlashTaskHandles[ xLEDTask ] != NULL )
 | 
			
		||||
		{
 | 
			
		||||
			if( xTaskIsTaskSuspended( xFlashTaskHandles[ xLEDTask ] ) == pdFALSE )
 | 
			
		||||
			{
 | 
			
		||||
				vTaskSuspend( xFlashTaskHandles[ xLEDTask ] );
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				vTaskResume( xFlashTaskHandles[ xLEDTask ] );
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
 | 
			
		||||
{
 | 
			
		||||
portTickType xFlashRate, xLastFlashTime;
 | 
			
		||||
unsigned portBASE_TYPE uxLED;
 | 
			
		||||
 | 
			
		||||
	/* The parameters are not used. */
 | 
			
		||||
	( void ) pvParameters;
 | 
			
		||||
 | 
			
		||||
	/* Calculate the LED and flash rate. */
 | 
			
		||||
	portENTER_CRITICAL();
 | 
			
		||||
	{
 | 
			
		||||
		/* See which of the eight LED's we should use. */
 | 
			
		||||
		uxLED = uxFlashTaskNumber;
 | 
			
		||||
 | 
			
		||||
		/* Update so the next task uses the next LED. */
 | 
			
		||||
		uxFlashTaskNumber++;
 | 
			
		||||
	}
 | 
			
		||||
	portEXIT_CRITICAL();
 | 
			
		||||
 | 
			
		||||
	xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( portTickType ) uxLED );
 | 
			
		||||
	xFlashRate /= portTICK_RATE_MS;
 | 
			
		||||
 | 
			
		||||
	/* We will turn the LED on and off again in the delay period, so each
 | 
			
		||||
	delay is only half the total period. */
 | 
			
		||||
	xFlashRate /= ( portTickType ) 2;
 | 
			
		||||
 | 
			
		||||
	/* We need to initialise xLastFlashTime prior to the first call to 
 | 
			
		||||
	vTaskDelayUntil(). */
 | 
			
		||||
	xLastFlashTime = xTaskGetTickCount();
 | 
			
		||||
 | 
			
		||||
	for(;;)
 | 
			
		||||
	{
 | 
			
		||||
		/* Delay for half the flash period then turn the LED on. */
 | 
			
		||||
		vTaskDelayUntil( &xLastFlashTime, xFlashRate );
 | 
			
		||||
		vParTestToggleLED( uxLED );
 | 
			
		||||
 | 
			
		||||
		/* Delay for half the flash period then turn the LED off. */
 | 
			
		||||
		vTaskDelayUntil( &xLastFlashTime, xFlashRate );
 | 
			
		||||
		vParTestToggleLED( uxLED );
 | 
			
		||||
	}
 | 
			
		||||
} /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -53,16 +53,25 @@
 | 
			
		|||
 | 
			
		||||
/* Demo includes. */
 | 
			
		||||
#include "DiceTask.h"
 | 
			
		||||
#include "ParTest.h"
 | 
			
		||||
#include "Flash.h"
 | 
			
		||||
 | 
			
		||||
static void prvSetupHardware( void );
 | 
			
		||||
 | 
			
		||||
#define mainDISPLAY_1		0
 | 
			
		||||
#define mainDISPLAY_2		1
 | 
			
		||||
 | 
			
		||||
#define mainFLASH_TASK_PRIORITY		( tskIDLE_PRIORITY + 1 )
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void main( void )
 | 
			
		||||
{
 | 
			
		||||
	prvSetupHardware();
 | 
			
		||||
 | 
			
		||||
	xTaskCreate( vDiceTask, ( signed char * ) "Dice", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
 | 
			
		||||
	vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
 | 
			
		||||
 | 
			
		||||
	xTaskCreate( vDiceTask, ( signed char * ) "Dice1", configMINIMAL_STACK_SIZE, ( void * ) mainDISPLAY_1, tskIDLE_PRIORITY, NULL );
 | 
			
		||||
	xTaskCreate( vDiceTask, ( signed char * ) "Dice2", configMINIMAL_STACK_SIZE, ( void * ) mainDISPLAY_2, tskIDLE_PRIORITY, NULL );
 | 
			
		||||
 | 
			
		||||
	vTaskStartScheduler();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue