Continue FX16 demo development.

This commit is contained in:
Richard Barry 2009-01-30 14:06:37 +00:00
parent 7551ede806
commit d61373702a
10 changed files with 435 additions and 206 deletions

View file

@ -1,201 +1,124 @@
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
/* ELIGIBILITY FOR ANY PURPOSES. */
/* (C) Fujitsu Microelectronics Europe GmbH */
/*---------------------------------------------------------------------------
MAIN.C
- description
- See README.TXT for project description and disclaimer.
/*
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.
#include "mb96356rs.h"
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.
#define DICE_MIN 1
#define DICE_MAX 6
#define DICERUN_MIN 600000L
#define DICERUN_MAX 1200000L
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
const char DICE7SEG1[11]={0x48, 0xeb, 0x8c, 0x89, 0x2b, 0x19, 0x18, 0xcb, 0x08, 0x09, 0xf7};
const char DICE7SEG2[11]={0xa0, 0xf3, 0xc4, 0xc1, 0x93, 0x89, 0x88, 0xe3, 0x80, 0x81, 0x7f};
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.
unsigned char temp;
unsigned char dice1, dice2;
unsigned long dice1run, dice2run;
unsigned long dice1state, dice2state;
unsigned long dice1delay, dice2delay;
unsigned long dice1delayrld, dice2delayrld;
/*===========================================================================*/
/*====== MAIN ===============================================================*/
/*===========================================================================*/
***************************************************************************
***************************************************************************
* *
* 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. *
* *
***************************************************************************
***************************************************************************
void main(void)
{
InitIrqLevels();
__set_il(7); // allow all levels
__EI(); // globally enable interrupts
// initialize I/O-ports
PIER00 = 0x03; // Enable P00_0/INT8 and P00_1/INT9 as input
PDR00 = 0x00;
DDR00 = 0xfc; // P00_0: SW2(INT8) P00_1: SW3(INT9)
Please ensure to read the configuration and relevant port sections of the
online documentation.
/* Do not use when Background Debugging is enabled
PIER01 = 0x04; // enable P01_2/SIN3 as input
PDR01 = 0x08; // SOT3 = 1
DDR01 = 0xfb; // SIN3 = input
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.
*/
PIER02 = 0x00; // All inputs are disabled on this port
PDR02 = 0x00;
DDR02 = 0xff;
PIER03 = 0x00; // All inputs are disabled on this port
PDR03 = 0xff;
DDR03 = 0xff; // Set Port3 as output (7Segment Display)
PIER04 = 0x04; // Enable P04_2/RX as input
PDR04 = 0x08; // CAN TX = 1
DDR04 = 0xfb; // CAN RX = input
PIER05 = 0x00; // All inputs are disabled on this port
ADER1 = 0; // Use Port 5 as I/O-Port
PDR05 = 0x7f;
DDR05 = 0xff; // Set Port5 as output (7Segment Display)
PIER06 = 0x00; // All inputs are disabled on this port
PDR06 = 0x00;
DDR06 = 0xff;
while (1)
{
// DICE 1
switch (dice1state)
{
case 0x00: // dice1 stopped
if (PDR00_P0 == 1) // Key SW2:INT8 pressed
{
dice1run = DICERUN_MIN;
srand((unsigned char)dice1run);
dice1state = 0x01;
}
break;
case 0x01: // dice1 startup
if (dice1run < DICERUN_MAX) // variable running time
dice1run++;
else
dice1run = DICERUN_MIN;
if (PDR00_P0 == 0) // Key SW2:INT8 released
{
dice1delay = 1;
dice1delayrld = 1;
dice1state = 0x02;
}
break;
/* Kernel includes. */
#include "FreeRTOS.h"
#include "Task.h"
case 0x02: // dice1 running
dice1run--;
dice1delay--;
/* Demo includes. */
#include "DiceTask.h"
if (!dice1delay)
{
do // get new random number
{
temp = rand() % 6 + 1;
}
while (temp == dice1);
dice1 = temp;
PDR03 = (PDR03 | 0xf7) & DICE7SEG1[dice1];
dice1delayrld = dice1delayrld + 100;
dice1delay = dice1delayrld;
}
static void prvSetupHardware( void );
if (dice1run == 0) // dice stopped
{
PDR03 = (PDR03 | 0xf7) & DICE7SEG1[rand() % 6 + 1];
dice1state = 0x00;
}
/*-----------------------------------------------------------*/
break;
void main( void )
{
prvSetupHardware();
}//switch (dice1state)
// DICE 2
switch (dice2state)
{
case 0x00: // dice2 stopped
if (PDR00_P1 == 1) // Key SW3:INT9 pressed
{
dice2run = DICERUN_MIN;
srand((unsigned char)dice1run);
dice2state = 0x01;
}
xTaskCreate( vDiceTask, ( signed char * ) "Dice", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
break;
case 0x01: // dice2 startup
if (dice2run < DICERUN_MAX) // variable running time
dice2run++;
else
dice2run = DICERUN_MIN;
if (dice2 == DICE_MAX) // simple 'random' number
dice2 = DICE_MIN;
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)
vTaskStartScheduler();
while( 1 );
}
/*-----------------------------------------------------------*/
void vApplicationIdleHook( void )
{
}
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
/* Setup interrupt hardware - interrupts are kept disabled for now to
prevent any interrupts attempting to cause a context switch before the
scheduler has been started. */
InitIrqLevels();
portDISABLE_INTERRUPTS();
__set_il( 7 );
/* Enable P00_0/INT8 and P00_1/INT9 as input. */
PIER00 = 0x03;
PDR00 = 0x00;
DDR00 = 0xfc;
/* Set Port3 as output (7Segment Display). */
DDR03 = 0xff;
/* Enable P04_2/RX as input. */
PIER04 = 0x04;
/* CAN TX = 1. */
PDR04 = 0x08;
/* CAN RX = input. */
DDR04 = 0xfb;
/* All inputs are disabled on this port. */
PIER05 = 0x00;
/* Use Port 5 as I/O-Port. */
ADER1 = 0;
PDR05 = 0x7f;
/* Set Port5 as output (7Segment Display). */
DDR05 = 0xff;
/* Disable inputs on the following ports. */
PIER02 = 0x00;
PDR02 = 0x00;
DDR02 = 0xff;
PIER03 = 0x00;
PDR03 = 0xff;
PIER06 = 0x00;
PDR06 = 0x00;
DDR06 = 0xff;
}