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