/**
 * Sets the minimum timeout.
 */
void
DiscardTracker::ReloadTimeout()
{
  nsresult rv;

  // read the timeout pref
  PRInt32 discardTimeout;
  nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (!branch) {
    NS_WARNING("nsIPrefBranch2 is not available!");
    return;
  }
  rv = branch->GetIntPref(DISCARD_TIMEOUT_PREF, &discardTimeout);

  // If we got something bogus, return
  if (!NS_SUCCEEDED(rv) || discardTimeout <= 0)
    return;

  // If the value didn't change, return
  if ((PRUint32) discardTimeout == sMinDiscardTimeoutMs)
    return;

  // Update the value
  sMinDiscardTimeoutMs = (PRUint32) discardTimeout;

  // If the timer's on, restart the clock to make changes take effect
  if (sTimerOn) {
    TimerOff();
    TimerOn();
  }
}
/**
 * Initialize the tracker.
 */
nsresult
DiscardTracker::Initialize()
{
  nsresult rv;

  // Set up the list. Head<->Sentinel<->Tail
  sHead.curr = sTail.curr = sSentinel.curr = nsnull;
  sHead.prev = sTail.next = nsnull;
  sHead.next = sTail.prev = &sSentinel;
  sSentinel.prev = &sHead;
  sSentinel.next = &sTail;

  // Load the timeout
  ReloadTimeout();

  // Create and start the timer
  nsCOMPtr<nsITimer> t = do_CreateInstance("@mozilla.org/timer;1");
  NS_ENSURE_TRUE(t, NS_ERROR_OUT_OF_MEMORY);
  t.forget(&sTimer);
  rv = TimerOn();
  NS_ENSURE_SUCCESS(rv, rv);

  // Mark us as initialized
  sInitialized = PR_TRUE;

  return NS_OK;
}
int main(void)
{
	//port B is output
	DDRB = 0xFF;
	
	//set and turn on timer
	TimerSet(500);
	TimerOn();
	
	//turn on PWM and set servo angle
	PWM_on();
	
	unsigned char testAngles[] = {0, 30, 60, 90, 120, 150, 180};
	unsigned char i = 0;
	//main loop
	while(1)
	{	
		
		
		if(i < 7){
			Servo_SetAngle(testAngles[i++]);
		}
		else{
			i = 0;
			Servo_SetAngle(testAngles[i++]);
		}
		
		
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
Esempio n. 4
0
int main(void)
{
	//---- PORT Initializations -----
	DDRB = 0xFF; PORTB = 0x00;
	DDRA = 0x00; PORTA = 0xFF;
	DDRC = 0xFF; PORTC = 0x00; //used for LCD display
	DDRD = 0xFF; PORTD = 0x00; //used for LCD display
	
	// --- Function Initializations ---
	TimerSet(5);
	TimerOn();
	PWM_on();
	initUSART();
	setCustomCharacters();
	LCD_init();

	//---if eeprom address was not initialized----
	if(eeprom_read_byte((uint8_t*)46) == 0xFF)
		eeprom_write_byte((uint8_t*)46 , 0);
		
	//----load old high score saved in EEPROM----
	currHighScore = eeprom_read_byte((uint8_t*)46);
	
	gameStatus = 0;
	soundStatus = 0;
	lcdTick();
	
	while(1){	
		mainTick();
		playSound();
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
int main(void)
{
	DDRA=0x00; PORTA=0xFF;
	DDRB=0x0FF;PORTB=0x00;
	Bl_state=Start;
	TLED_state=Start3;
	BZ_State=Start1;
	In_state=Start4;
	TimerSet(1);
	TimerOn();
	
	while (1)
	{
		valA=0x00;
		Tick_BL();
		Tick_3L();
		Tick_IN();
		Tick_Bz();
		Update_Port_B();
		while(!TimerFlag){}
		TimerFlag=0;
		time_elapsed+=1;
		if(time_elapsed>1000)
		time_elapsed=1;
	}
}
/**
 * Sets the minimum timeout.
 */
void
DiscardTracker::ReloadTimeout()
{
  nsresult rv;

  // read the timeout pref
  PRInt32 discardTimeout;
  rv = Preferences::GetInt(DISCARD_TIMEOUT_PREF, &discardTimeout);

  // If we got something bogus, return
  if (!NS_SUCCEEDED(rv) || discardTimeout <= 0)
    return;

  // If the value didn't change, return
  if ((PRUint32) discardTimeout == sMinDiscardTimeoutMs)
    return;

  // Update the value
  sMinDiscardTimeoutMs = (PRUint32) discardTimeout;

  // If the timer's on, restart the clock to make changes take effect
  if (sTimerOn) {
    TimerOff();
    TimerOn();
  }
}
Esempio n. 7
0
int main(void)
{
	
	DDRA = 0x00; PORTA = 0xFF;	//Input Port, joystick and buttons.
	DDRB = 0xFF; PORTB = 0x00;	//Output Port, test output to led.
	DDRD = 0xFF; PORTD = 0x00;
	DDRC = 0xFF; PORTC = 0x00;	//C0 is motor.

	unsigned char i=0;
	tasks[i].state = JS_SMStart;
	tasks[i].period = periodJoystick;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Joystick;
	i++;
	tasks[i].state = JP_SMStart;
	tasks[i].period = periodJump;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Jump;
	i++;
	tasks[i].state = CH_SMStart;
	tasks[i].period = periodCrouch;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Crouch;
	i++;
	tasks[i].state = RT_SMStart;
	tasks[i].period = periodReset;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Reset;
	i++;
	tasks[i].state = TN_SMStart;
	tasks[i].period = periodTransmission;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Transmission;
	i++;
	tasks[i].state = MR_SMStart;
	tasks[i].period = periodMotor;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Motor;
	i++;
	tasks[i].state = SE_SMStart;
	tasks[i].period = periodScore;
	tasks[i].elapsedTime = tasks[i].period;
	tasks[i].TickFct = &TickFct_Score;

	TimerSet(tasksPeriodGCD);
	TimerOn();
	ADC_init();
	SPI_SlaveInit();

	while (1)
	{
		while(!TimerFlag);
		TimerFlag = 0;
	}

	return 0;
}
Esempio n. 8
0
/***********************
** DoEmFloatIteration **
************************
** Perform an iteration of the emulated floating-point
** benchmark.  Note that "an iteration" can involve multiple
** loops through the benchmark.
*/
ulong DoEmFloatIteration(InternalFPF *abase,
                InternalFPF *bbase,
                InternalFPF *cbase,
                ulong arraysize, ulong loops, double *wat_time)
{
ulong elapsed;          /* For the stopwatch */
static uchar jtable[16] = {0,0,0,0,1,1,1,1,2,2,2,2,2,3,3,3};
ulong i;

/*
** Begin timing
*/
elapsed=StartStopwatch();
TimerOn();

/*
** Each pass through the array performs operations in
** the followingratios:
**   4 adds, 4 subtracts, 5 multiplies, 3 divides
** (adds and subtracts being nearly the same operation)
*/
while(loops--)
{
        for(i=0;i<arraysize;i++)
                switch(jtable[i % 16])
                {
                        case 0: /* Add */       
                                AddSubInternalFPF(0,abase+i,
                                  bbase+i,
                                  cbase+i);
                                break;
                        case 1: /* Subtract */
                                AddSubInternalFPF(1,abase+i,
                                  bbase+i,
                                  cbase+i);
                                break;
                        case 2: /* Multiply */
                                MultiplyInternalFPF(abase+i,
                                  bbase+i,
                                  cbase+i);
                                break;
                        case 3: /* Divide */
                                DivideInternalFPF(abase+i,
                                  bbase+i,
                                  cbase+i);
                                break;
                }
}

TimerOff();
elapsed = StopStopwatch(elapsed);
if( wat_time ) {
    *wat_time = TimerElapsed();
}
return(elapsed);
}
Esempio n. 9
0
int main(){
	DDRB = 0xFF; PORTB = 0x00;
	TimerSet(1000);
	TimerOn();
	tempB = 0x00;
	while(1) {
		while (!TimerFlag);
			TimerFlag = 0;
		led();
	}
}
int main(void)
{
	DDRA = 0x00; PORTA = 0xFF;
	DDRB = 0xFF; PORTB = 0x00;
	DDRD = 0xFF; PORTD = 0x0F;
	//PWM_on();
	TimerSet(500);
	TimerOn();
	StateSpeaker = SPEAKER_INIT;
	StatePitch = PITCH_INIT;
	TimerSet(100);
	TimerOn();

	//PWM_on();
    while(1)
    {
		//set_PWM(pitchScale[5]);
		SMSpeaker_tick();
		SMChoosePitch_tick();
		while(!TimerFlag);
		TimerFlag = 0;	
    }
}
Esempio n. 11
0
			break;
	}
}

int main(){
	DDRB = 0xFF; PORTB = 0x00;
	DDRA = 0x00; PORTA = 0xFF;
	TimerSet(50);
	TimerOn();
	
	tempB = 0x00;
	led_state = init;
	while(1) {
		while (!TimerFlag);
Esempio n. 12
0
int main() {

   const unsigned int periodState_machine_1 = 1000; // 1000 ms default
   TimerSet(periodState_machine_1);
   TimerOn();
   
   SM1_State = -1; // Initial state
   B = 0; // Init outputs

   while(1) {
      TickFct_State_machine_1();
      while(!SM1_Clk);
      SM1_Clk = 0;
   } // while (1)
} // Main
Esempio n. 13
0
int main(void)
{

    // PORT config
	DDRC = 0xFF; PORTC = 0x00;
	DDRB = 0xFF; PORTB = 0x00; 	
	DDRA = 0xFD; PORTA = 0x02;	//1111 1101 : 0000 0010
   
    static task motionSensorPoll, lcdDisplay;
    task *tasks[] = { &lcdDisplay, &motionSensorPoll };
    
    unsigned short numTasks = sizeof(tasks)/sizeof(task*);
    
	//LCD display task
    lcdDisplay.period = 500;
    lcdDisplay.TickFn = &lcdDisplayTick;

	//Motion sensor polling task
	motionSensorPoll.period = 100;
	motionSensorPoll.TickFn = &motionSensorTick;
    	
    unsigned short gcd = tasksInit(tasks, numTasks);
    
    // Timer
    TimerSet(gcd);
    TimerOn();


	//initialize LCD
	LCD_init();    

	ADC_init();

    unsigned short i; // Iterator
    while(1)
    {
		sensor = GetBit(PINA,1);

        tasksTick(tasks, numTasks);

        while(!TimerFlag); // Wait for a GCD period  
        TimerFlag = 0;
     
    }
    
    return 0;
}
Esempio n. 14
0
int main(void) {
	DDRB = 0xFF; PORTB = 0x00;
	DDRA = 0xFF; PORTA = 0x00;
	DDRD = 0xFF; PORTD = 0x00;
	DDRC = 0xF0; PORTC = 0x0F; // PC7..4 outputs init 0s, PC3..0 inputs init 1s
	
	TimerSet(200);
	TimerOn();
	LCD_init();
	LCD_DisplayString(1,"Congratulations!");
	state = start;
	while(1) {
		while (!TimerFlag);
		TimerFlag = 0;
		Tick();
	}
}
Esempio n. 15
0
int main(void)
{
	DDRA = 0xFF; PORTA = 0x00;
	DDRB = 0xFF; PORTB = 0x00;
	DDRC = 0xFF; PORTC = 0x00;
	DDRD = 0xBF; PORTD = 0x40;
	TimerSet(10);
	TimerOn();
	initUSART(0);
	state = init;
	while(1)
	{
		Tick_Fct();
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
Esempio n. 16
0
//Main
int main(void) {
    DDRB = 0xFF;
    PORTB = 0x00;
    DDRA = 0xFF;
    PORTA = 0x00;
    DDRD = 0xFF;
    PORTD = 0x00;
    DDRC = 0xF0;
    PORTC = 0x0F;

    //Task initializing
    unsigned char i=0;

    //Keypad Task
    tasks[i].state = keypad_start;
    tasks[i].period = keypadGCD;
    tasks[i].elapsedTime = 0;
    tasks[i].TickFct = &tickFct_Keypad;
    i++;

    //Obstacle Movement
    tasks[i].state = obs_start;
    tasks[i].period = obstacleGCD;
    tasks[i].elapsedTime = 0;
    tasks[i].TickFct = &tickFct_Obstacles;
    i++;

    //Collision Detection
    tasks[i].state = col_start;
    tasks[i].period = collisionGCD;
    tasks[i].elapsedTime = 0;
    tasks[i].TickFct = &tickFct_Collision;

    //Setup
    TimerSet(tasksPeriodGCD);
    TimerOn();
    LCD_init();
    LCD_DisplayString(1,(unsigned char*)" ");
    LCD_Cursor(1);
    LCD_WriteData('@');
    LCD_Cursor(0);
    while (1) {

    }
}
Esempio n. 17
0
int main(void)
{
    DDRA = 0xFF;
    DDRB = 0xBF; PORTB = 0x40;
    DDRC = 0xFF;
    DDRD = 0x8F; PORTD = 0x70;
    
    lcd_command_queue = QueueInit(10);
    sound_command_queue = QueueInit(10);
    lock_command_queue = QueueInit(10);
    
    task_monitor_lock.elapsedTime = 200;
    task_monitor_lock.period = 200;
    task_monitor_lock.state = st_lock_monitor_start;
    task_monitor_lock.TickFct = &lock_monitor_tick;
    
    task_lock_control.elapsedTime = 250;
    task_lock_control.period = 250;
    task_lock_control.state = st_lock_start;
    task_lock_control.TickFct = &lock_controller_tick;
    
    task_main.elapsedTime = 100;
    task_main.period = 100;
    task_main.state = st_main_start;
    task_main.TickFct = &main_controller_tick;
    
    task_sound.elapsedTime = 100;
    task_sound.period = 100;
    task_sound.state = st_sound_start;
    task_sound.TickFct = &sound_tick;
    
    task_lcd.elapsedTime = 100;
    task_lcd.period = 100;
    task_lcd.state = st_lcd_start;
    task_lcd.TickFct = &lcd_tick;
    
    A2D_init();
    TimerSet(tasksPeriodGCD);
    TimerOn();
    
    while(1)
    {
        ;
    }
}
Esempio n. 18
0
//MAIN ROUTINE
void main(void){
	tasks[0].period=periodKeypadRead;
	tasks[0].elapsedTime=tasks[0].period;
	tasks[0].TickFct=&TickFct_KeypadRead;
	tasks[1].period=periodDisplay7Seg;
	tasks[1].elapsedTime=tasks[1].period;
	tasks[1].TickFct=&TickFct_Display7Seg;
	IO_DDR2.byte=0xBF;	//set P26 as input (DAVBL)
	IO_DDR5.byte=0x0F;	//set P54-P57 as input (keypad data lines)
	IO_DDR1.byte=0xFF;	//set Port 1 as output (7-segment display)
	keypad_counter=0;	//initialize keypad_counter
	buffer=0x00;		//initialize buffer
	TimerSet(tasksPeriodGCD);
	TimerOn();
	while(1){
		Sleep();
	}
}
int main(void)
{
	DDRA=0x0F; PORTA=0xF0;
	DDRB=0xFF; PORTB=0x00;
	DDRC = 0xF0; PORTC = 0x0F; // LCD data lines
	DDRD = 0x7F; PORTD = 0x80; // LCD control lines
	unsigned long timeElapsed1=0x00;
	unsigned long timeElapsed2=0x00;
	unsigned long timeElapsed3=0x00;
	TimerOn();
	TimerSet(1);
	SM_state1=Start;
	SM_state2=Start2;
	SM_state3=Start3;
	SM_state4=Start4;
	SM_state5=Start5;
	LCD_init();
	while (1)
    {
		if(timeElapsed1>100)
		{
			SM_Tick1();
			timeElapsed1=0;
		}
		if(timeElapsed2>100)
		{
			SM_Tick2();
			timeElapsed2=0;
		}
		if(timeElapsed3>100)
		{
			SM_Tick3();
			timeElapsed3=0;
		}
		SM_Tick4();
		SM_Tick5();
		while(!TimerFlag){}
		TimerFlag=0;
		timeElapsed1++;
		timeElapsed2++;
		timeElapsed3++;
    }
}
int main(){
	//Initialize Registers
	DDRB = 0xFF; PORTB = 0x00;
	DDRA = 0x00; PORTA = 0xFF;
	
	//Set Timers
	TimerSet(1000);
	TimerOn();
	
	//Variables
	state1 = start1;
	state2 = start2;
	state3 = start3;
	
	while(1) {
		while (!TimerFlag);
		TimerFlag = 0;
		tick();
	}
}
Esempio n. 21
0
int main(void)
{
	DDRB = 0xFF; PORTB = 0x00;
	Three_state = Start;
	BL_state = BL_Start;
	Combine_State = COM_Start;
	cnt = 0;
	count = 0;
	
	TimerSet(1);
	TimerOn();
    while(1)
    {
		TickThree_LEDS();
		TickBL();
		TickCOM();
        while (!TimerFlag);
        TimerFlag = 0;
    }
}
Esempio n. 22
0
int main(void)
{
    DDRA = 0x00; PORTA = 0xFF;	// set PORTA to inputs and initialize
    DDRC = 0xFF; PORTC = 0x00;  // data lines
    DDRD = 0xFF; PORTD = 0x00;  // LCD control lines

    LCD_init();

    TimerSet(125);             // set Timer period
    TimerOn();                  // enable Timer

    state = START;              // initialize state
    
	while(1)
	{
		Tick();                 // step through states
        while (!TimerFlag);     // Wait for a period
        TimerFlag = 0;          // reset the timer flag
	}
}
int main(void)
{
	DDRA = 0xFF;	PORTA = 0x00;
	DDRB = 0xF0;	PORTB = 0x0F;
	DDRC = 0xFF;	PORTC = 0x00;
	DDRD = 0x00;	PORTD = 0xFF;
	initUSART(0);
	initUSART(1);
	LCD_init();
	tasks[0].state = controllerinit;
	tasks[0].period = 1;
	tasks[0].elapsedTime = 1;
	tasks[0].TickFct = &TickFct_Controller;
	
	tasks[1].state = bluetoothWait;
	tasks[1].period = 5;
	tasks[1].elapsedTime = 5;
	tasks[1].TickFct = &TickFct_BluetoothReceiver;
	
	tasks[2].state = keypadWait1;
	tasks[2].period = 10;
	tasks[2].elapsedTime = 10;
	tasks[2].TickFct = &TickFct_KeypadReceiver;
	
	tasks[3].state = checkInit;
	tasks[3].period = 15;
	tasks[3].elapsedTime = 15;
	tasks[3].TickFct = &TickFct_CheckPin;
	
	tasks[4].state = usartInit;
	tasks[4].period = 5;
	tasks[4].elapsedTime = 5;
	tasks[4].TickFct = &TickFct_USART;
	
	TimerSet(1);
	TimerOn();
	while(1)
    {
    }
}
/*
 * Puts an image in the back of the tracker queue. If the image is already
 * in the tracker, this removes it first.
 */
nsresult
DiscardTracker::Reset(DiscardTrackerNode *node)
{
  nsresult rv;
#ifdef DEBUG
  PRBool isSentinel = (node == &sSentinel);

  // Sanity check the node.
  NS_ABORT_IF_FALSE(isSentinel || node->curr, "Node doesn't point to anything!");

  // We should not call this function if we can't discard
  NS_ABORT_IF_FALSE(isSentinel || node->curr->CanDiscard(),
                    "trying to reset discarding but can't discard!");

  // As soon as an image becomes animated it is set non-discardable
  NS_ABORT_IF_FALSE(isSentinel || !node->curr->mAnim,
                    "Trying to reset discarding on animated image!");
#endif

  // Initialize the first time through
  if (NS_UNLIKELY(!sInitialized)) {
    rv = Initialize();
    NS_ENSURE_SUCCESS(rv, rv);
  }

  // Remove the node if it's in the list.
  Remove(node);

  // Append it to the list.
  node->prev = sTail.prev;
  node->next = &sTail;
  node->prev->next = sTail.prev = node;

  // Make sure the timer is running
  rv = TimerOn();
  NS_ENSURE_SUCCESS(rv,rv);

  return NS_OK;
}
int main(void)
{
	DDRB = 1 << 6 | 1 << 0; PORTB = 0xBE;
	DDRD = 0xFF;
	DDRC = 0x03;
	
	//set and turn on system timer
	TimerSet(50);
	TimerOn();
	
	LCD_init();//initialize lcd display for use
	//build custom characters for use throughout program
	LCD_build(0,angleLcdPattern);
	LCD_build(1,sunLcdPattern);
	LCD_build(2,moonLcdPattern);
	
	ADC_init();//initialize analog to digital converter
	PWM_on();//turn on PWM and servo control
	
	//Init SM states
	LcdDisplay_State = LcdInit;
	HumanDetect_State = InitDetection;
	LightSeek_State = LightSeekInit;
	ServoControl_State = ServoInit;
	
	//main loop
	while(1)
	{
		pirSensor = GetBit(PINB,1); //get reading from pir sensor
		
		HumanDetect_TickFct();
		LightSeek_TickFct();
		ServoControl_TickFct();
		LcdDisplay_TickFct();
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
Esempio n. 26
0
int main(void)
{
	DDRA = 0xFF; PORTA = 0x00;
	DDRB = 0xF0; PORTB = 0x0F;
   DDRD = 0xFF; PORTB = 0x00;
 DDRC = 0xF0; PORTC = 0x0F;

	room_state = init;
   LI_State = LI_Init1;
   outputRoom_state = initLCD;
   shotsFired_state = initShots;
	TimerSet(100);
	TimerOn();
    while(1)
    {
		rooms();
      LI_Tick ();
      outputRoom ();
	  shotsFired();
        while(!TimerFlag);
        TimerFlag = 0;
    }
}
Esempio n. 27
0
int main(void)
{
	// Set port B to output
	// Init port B to 0s
	DDRA = 0x00;
	PORTA = 0xFF;
	DDRB = 0xFF;
	PORTB = 0x00;
	state = Start;
	TimerSet(500);
	TimerOn();
	while(1) {
		// User code (i.e. synchSM calls)
		// Toggle PORTB; Temporary, bad programming style
		Tick();
		
		// Wait 1 sec
		while (!TimerFlag);
		TimerFlag = 0;
		// Note: For the above a better style would use a synchSM with TickSM()
		// This example just illustrates the use of the ISR and flag
	}
}
Esempio n. 28
0
int main(void)
{
    DDRB = 0xFF;
    PORTB = 0x00;
    DDRA = 0x00;
    PORTA = 0xFF;

    Three_state = Start;
    Speaker_state = SPEAK_Start;
    Combine_State = COM_Start;
    cnt = 0;
    count = 0;

    TimerSet(1);
    TimerOn();
    while(1)
    {
        TickThree_LEDS();
        TickSpeaker();
        TickCOM();
        while (!TimerFlag);
        TimerFlag = 0;
    }
}
Esempio n. 29
0
void main()
{

#ifdef ROPT
   register double s,u,v,w,x;
#else
   double s,u,v,w,x;
#endif

   long loops, NLimit;
   register long i, m, n;

   printf("\n");
   printf("   FLOPS C Program (Double Precision), V2.0 18 Dec 1992\n\n");

			 /****************************/
   loops = 15625;        /* Initial number of loops. */
			 /*     DO NOT CHANGE!       */
			 /****************************/

/****************************************************/
/* Set Variable Values.                             */
/* T[1] references all timing results relative to   */
/* one million loops.                               */
/*                                                  */
/* The program will execute from 31250 to 128000000 */
/* loops based on a runtime of Module 1 of at least */
/* TLimit = 3.0 seconds. That is, a runtime of 3    */
/* seconds for Module 1 is used to determine the    */
/* number of loops to execute.                      */
/*                                                  */
/* No more than NLimit = 128000000 loops are allowed*/
/****************************************************/

   T[1] = 1.0E+06/(double)loops;

   TLimit = 3.0;
   NLimit = 128000000;

   piref = 3.14159265358979324;
   one   = 1.0;
   two   = 2.0;
   three = 3.0;
   four  = 4.0;
   five  = 5.0;
   scale = one;

   printf("   Module     Error        RunTime      MFLOPS\n");
   printf("                            (usec)\n");
/*************************/
/* Initialize the timer. */
/*************************/
   
/*******************************************************/
/* Module 1.  Calculate integral of df(x)/f(x) defined */
/*            below.  Result is ln(f(1)). There are 14 */
/*            double precision operations per loop     */
/*            ( 7 +, 0 -, 6 *, 1 / ) that are included */
/*            in the timing.                           */
/*            50.0% +, 00.0% -, 42.9% *, and 07.1% /   */
/*******************************************************/
   n = loops;
   sa = 0.0;

   while ( sa < TLimit )
   {
   n = 2 * n;
   x = one / (double)n;                            /*********************/
   s = 0.0;                                        /*  Loop 1.          */
   v = 0.0;                                        /*********************/
   w = one;

	TimerOn();
	for( i = 1 ; i <= n-1 ; i++ )
	{
	v = v + w;
	u = v * x;
	s = s + (D1+u*(D2+u*D3))/(w+u*(D1+u*(E2+u*E3)));
	}
	TimerOff();
	sa = TimerElapsed();

   if ( n == NLimit ) break;
   /* printf(" %10ld  %12.5lf\n",n,sa); */
   }

   scale = 1.0E+06 / (double)n;
   T[1]  = scale;

/****************************************/
/* Estimate nulltime ('for' loop time). */
/****************************************/
   TimerOn();
   for( i = 1 ; i <= n-1 ; i++ )
   {
   }
   TimerOff();
   nulltime = T[1] * TimerElapsed();
   if ( nulltime < 0.0 ) nulltime = 0.0;

   T[2] = T[1] * sa - nulltime;

   sa = (D1+D2+D3)/(one+D1+E2+E3);
   sb = D1;

   T[3] = T[2] / 14.0;                             /*********************/
   sa = x * ( sa + sb + two * s ) / two;           /* Module 1 Results. */
   sb = one / sa;                                  /*********************/
   n  = (long)( (double)( 40000 * (long)sb ) / scale );
   sc = sb - 25.2;
   T[4] = one / T[3];
						    /********************/
						    /*  DO NOT REMOVE   */
						    /*  THIS PRINTOUT!  */
						    /********************/
   printf("     1   %13.4le  %10.4lf  %10.4lf\n",sc,T[2],T[4]);

   m = n;

/*******************************************************/
/* Module 2.  Calculate value of PI from Taylor Series */
/*            expansion of atan(1.0).  There are 7     */
/*            double precision operations per loop     */
/*            ( 3 +, 2 -, 1 *, 1 / ) that are included */
/*            in the timing.                           */
/*            42.9% +, 28.6% -, 14.3% *, and 14.3% /   */
/*******************************************************/

   s  = -five;                                      /********************/
   sa = -one;                                       /* Loop 2.          */
						    /********************/
   TimerOn();
   for ( i = 1 ; i <= m ; i++ )
   {
   s  = -s;
   sa = sa + s;
   }
   TimerOff();
   T[5] = T[1] * TimerElapsed();
   Report( "flops(1)", TimerElapsed() );
   if ( T[5] < 0.0 ) T[5] = 0.0;

   sc   = (double)m;

   u = sa;                                         /*********************/
   v = 0.0;                                        /* Loop 3.           */
   w = 0.0;                                        /*********************/
   x = 0.0;

   TimerOn();
   for ( i = 1 ; i <= m ; i++)
   {
   s  = -s;
   sa = sa + s;
   u  = u + two;
   x  = x +(s - u);
   v  = v - s * u;
   w  = w + s / u;
   }
   TimerOff();
   T[6] = T[1] * TimerElapsed();
   Report( "flops(2)", TimerElapsed() );

   T[7] = ( T[6] - T[5] ) / 7.0;                   /*********************/
   m  = (long)( sa * x  / sc );                    /*  PI Results       */
   sa = four * w / five;                           /*********************/
   sb = sa + five / v;
   sc = 31.25;
   piprg = sb - sc / (v * v * v);
   pierr = piprg - piref;
   T[8]  = one  / T[7];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     2   %13.4le  %10.4lf  %10.4lf\n",pierr,T[6]-T[5],T[8]);

/*******************************************************/
/* Module 3.  Calculate integral of sin(x) from 0.0 to */
/*            PI/3.0 using Trapazoidal Method. Result  */
/*            is 0.5. There are 17 double precision    */
/*            operations per loop (6 +, 2 -, 9 *, 0 /) */
/*            included in the timing.                  */
/*            35.3% +, 11.8% -, 52.9% *, and 00.0% /   */
/*******************************************************/

   x = piref / ( three * (double)m );              /*********************/
   s = 0.0;                                        /*  Loop 4.          */
   v = 0.0;                                        /*********************/

   TimerOn();
   for( i = 1 ; i <= m-1 ; i++ )
   {
   v = v + one;
   u = v * x;
   w = u * u;
   s = s + u * ((((((A6*w-A5)*w+A4)*w-A3)*w+A2)*w+A1)*w+one);
   }
   TimerOff();
   T[9]  = T[1] * TimerElapsed() - nulltime;
   Report( "flops(3)", TimerElapsed() );

   u  = piref / three;
   w  = u * u;
   sa = u * ((((((A6*w-A5)*w+A4)*w-A3)*w+A2)*w+A1)*w+one);

   T[10] = T[9] / 17.0;                            /*********************/
   sa = x * ( sa + two * s ) / two;                /* sin(x) Results.   */
   sb = 0.5;                                       /*********************/
   sc = sa - sb;
   T[11] = one / T[10];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     3   %13.4le  %10.4lf  %10.4lf\n",sc,T[9],T[11]);

/************************************************************/
/* Module 4.  Calculate Integral of cos(x) from 0.0 to PI/3 */
/*            using the Trapazoidal Method. Result is       */
/*            sin(PI/3). There are 15 double precision      */
/*            operations per loop (7 +, 0 -, 8 *, and 0 / ) */
/*            included in the timing.                       */
/*            50.0% +, 00.0% -, 50.0% *, 00.0% /            */
/************************************************************/
   A3 = -A3;
   A5 = -A5;
   x = piref / ( three * (double)m );              /*********************/
   s = 0.0;                                        /*  Loop 5.          */
   v = 0.0;                                        /*********************/

   TimerOn();
   for( i = 1 ; i <= m-1 ; i++ )
   {
   u = (double)i * x;
   w = u * u;
   s = s + w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
   }
   TimerOff();
   T[12]  = T[1] * TimerElapsed() - nulltime;
   Report( "flops(4)", TimerElapsed() );

   u  = piref / three;
   w  = u * u;
   sa = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;

   T[13] = T[12] / 15.0;                             /*******************/
   sa = x * ( sa + one + two * s ) / two;            /* Module 4 Result */
   u  = piref / three;                               /*******************/
   w  = u * u;
   sb = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+A0);
   sc = sa - sb;
   T[14] = one / T[13];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     4   %13.4le  %10.4lf  %10.4lf\n",sc,T[12],T[14]);

/************************************************************/
/* Module 5.  Calculate Integral of tan(x) from 0.0 to PI/3 */
/*            using the Trapazoidal Method. Result is       */
/*            ln(cos(PI/3)). There are 29 double precision  */
/*            operations per loop (13 +, 0 -, 15 *, and 1 /)*/
/*            included in the timing.                       */
/*            46.7% +, 00.0% -, 50.0% *, and 03.3% /        */
/************************************************************/

   x = piref / ( three * (double)m );              /*********************/
   s = 0.0;                                        /*  Loop 6.          */
   v = 0.0;                                        /*********************/

   TimerOn();
   for( i = 1 ; i <= m-1 ; i++ )
   {
   u = (double)i * x;
   w = u * u;
   v = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   s = s + v / (w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one);
   }
   TimerOff();
   T[15]  = T[1] * TimerElapsed() - nulltime;
   Report( "flops(5)", TimerElapsed() );

   u  = piref / three;
   w  = u * u;
   sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
   sa = sa / sb;

   T[16] = T[15] / 29.0;                             /*******************/
   sa = x * ( sa + two * s ) / two;                  /* Module 5 Result */
   sb = 0.6931471805599453;                          /*******************/
   sc = sa - sb;
   T[17] = one / T[16];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     5   %13.4le  %10.4lf  %10.4lf\n",sc,T[15],T[17]);

/************************************************************/
/* Module 6.  Calculate Integral of sin(x)*cos(x) from 0.0  */
/*            to PI/4 using the Trapazoidal Method. Result  */
/*            is sin(PI/4)^2. There are 29 double precision */
/*            operations per loop (13 +, 0 -, 16 *, and 0 /)*/
/*            included in the timing.                       */
/*            46.7% +, 00.0% -, 53.3% *, and 00.0% /        */
/************************************************************/

   x = piref / ( four * (double)m );               /*********************/
   s = 0.0;                                        /*  Loop 7.          */
   v = 0.0;                                        /*********************/

   TimerOn();
   for( i = 1 ; i <= m-1 ; i++ )
   {
   u = (double)i * x;
   w = u * u;
   v = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   s = s + v*(w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one);
   }
   TimerOff();
   T[18]  = T[1] * TimerElapsed() - nulltime;
   Report( "flops(6)", TimerElapsed() );

   u  = piref / four;
   w  = u * u;
   sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
   sa = sa * sb;

   T[19] = T[18] / 29.0;                             /*******************/
   sa = x * ( sa + two * s ) / two;                  /* Module 6 Result */
   sb = 0.25;                                        /*******************/
   sc = sa - sb;
   T[20] = one / T[19];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     6   %13.4le  %10.4lf  %10.4lf\n",sc,T[18],T[20]);


/*******************************************************/
/* Module 7.  Calculate value of the definite integral */
/*            from 0 to sa of 1/(x+1), x/(x*x+1), and  */
/*            x*x/(x*x*x+1) using the Trapizoidal Rule.*/
/*            There are 12 double precision operations */
/*            per loop ( 3 +, 3 -, 3 *, and 3 / ) that */
/*            are included in the timing.              */
/*            25.0% +, 25.0% -, 25.0% *, and 25.0% /   */
/*******************************************************/

						   /*********************/
   s = 0.0;                                        /* Loop 8.           */
   w = one;                                        /*********************/
   sa = 102.3321513995275;
   v = sa / (double)m;

   TimerOn();
   for ( i = 1 ; i <= m-1 ; i++)
   {
   x = (double)i * v;
   u = x * x;
   s = s - w / ( x + w ) - x / ( u + w ) - u / ( x * u + w );
   }
   TimerOff();
   T[21] = T[1] * TimerElapsed() - nulltime;
   Report( "flops(7)", TimerElapsed() );
						   /*********************/
						   /* Module 7 Results  */
						   /*********************/
   T[22] = T[21] / 12.0;                                  
   x  = sa;                                      
   u  = x * x;
   sa = -w - w / ( x + w ) - x / ( u + w ) - u / ( x * u + w );
   sa = 18.0 * v * (sa + two * s );

   m  = -2000 * (long)sa;
   m = (long)( (double)m / scale );

   sc = sa + 500.2;
   T[23] = one / T[22];
						   /********************/
						   /*  DO NOT REMOVE   */
						   /*  THIS PRINTOUT!  */
						   /********************/
   printf("     7   %13.4le  %10.4lf  %10.4lf\n",sc,T[21],T[23]);

/************************************************************/
/* Module 8.  Calculate Integral of sin(x)*cos(x)*cos(x)    */
/*            from 0 to PI/3 using the Trapazoidal Method.  */
/*            Result is (1-cos(PI/3)^3)/3. There are 30     */
/*            double precision operations per loop included */
/*            in the timing:                                */
/*               13 +,     0 -,    17 *          0 /        */
/*            46.7% +, 00.0% -, 53.3% *, and 00.0% /        */
/************************************************************/

   x = piref / ( three * (double)m );              /*********************/
   s = 0.0;                                        /*  Loop 9.          */
   v = 0.0;                                        /*********************/

   TimerOn();
   for( i = 1 ; i <= m-1 ; i++ )
   {
   u = (double)i * x;
   w = u * u;
   v = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
   s = s + v*v*u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   }
   TimerOff();
   T[24]  = T[1] * TimerElapsed() - nulltime;
   Report( "flops(8)", TimerElapsed() );

   u  = piref / three;
   w  = u * u;
   sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
   sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
   sa = sa * sb * sb;

   T[25] = T[24] / 30.0;                             /*******************/
   sa = x * ( sa + two * s ) / two;                  /* Module 8 Result */
   sb = 0.29166666666666667;                         /*******************/
   sc = sa - sb;
   T[26] = one / T[25];
						   /*********************/
						   /*   DO NOT REMOVE   */
						   /*   THIS PRINTOUT!  */
						   /*********************/
   printf("     8   %13.4le  %10.4lf  %10.4lf\n",sc,T[24],T[26]);

/**************************************************/   
/* MFLOPS(1) output. This is the same weighting   */
/* used for all previous versions of the flops.c  */
/* program. Includes Modules 2 and 3 only.        */
/**************************************************/ 
   T[27] = ( five * (T[6] - T[5]) + T[9] ) / 52.0;
   T[28] = one  / T[27];

/**************************************************/   
/* MFLOPS(2) output. This output does not include */
/* Module 2, but it still does 9.2% FDIV's.       */
/**************************************************/ 
   T[29] = T[2] + T[9] + T[12] + T[15] + T[18];
   T[29] = (T[29] + four * T[21]) / 152.0;
   T[30] = one / T[29];

/**************************************************/   
/* MFLOPS(3) output. This output does not include */
/* Module 2, but it still does 3.4% FDIV's.       */
/**************************************************/ 
   T[31] = T[2] + T[9] + T[12] + T[15] + T[18];
   T[31] = (T[31] + T[21] + T[24]) / 146.0;
   T[32] = one / T[31];

/**************************************************/   
/* MFLOPS(4) output. This output does not include */
/* Module 2, and it does NO FDIV's.               */
/**************************************************/ 
   T[33] = (T[9] + T[12] + T[18] + T[24]) / 91.0;
   T[34] = one / T[33];


   printf("\n");
   printf("   Iterations      = %10ld\n",m);
   printf("   NullTime (usec) = %10.4lf\n",nulltime);
   printf("   MFLOPS(1)       = %10.4lf\n",T[28]);
   printf("   MFLOPS(2)       = %10.4lf\n",T[30]);
   printf("   MFLOPS(3)       = %10.4lf\n",T[32]);
   printf("   MFLOPS(4)       = %10.4lf\n\n",T[34]);
   exit( EXIT_SUCCESS );
}
Esempio n. 30
0
int main(void)
{
		DDRA = 0xF0; PORTA = 0x0F;
		DDRB = 0x00;  PORTB = 0xFF;
		DDRC = 0xFF; PORTC = 0x00;
		DDRD = 0xFF; PORTD = 0x00;
		gameSelector = 0xFF;
		LINE_init();
	    TimerSet(1);
	    TimerOn();
	    srand(0);
	    InitADC();
		initUSART(1);
		
    while (1) 
    {
		if(SandM_period >= 10)
		{
			if(USART_HasReceived(1)){
				gameSelector = receiveData(1);
			}
			SandM_period = 0;
		}
		++SandM_period;
		
		if(gameSelector == 0x02)
		{
			if(TRLINES_period >= 9)
			{	       
				TRLINES_period = 0;
			}
			if(TRuser_period >= 80)
			{
				TunRun_ChkLoss();
				TunRun_JoyStk();
				TUNRUN_LINES();
				TunRun_Input();
				TRuser_period = 0;
			}
				displayMatrix();
				++TRLINES_period;
				++TRuser_period;
		}
		if(gameSelector == 0x04)
		{
			if(arrows_period >= 750)
			{
				DDR_arrows();
				if((arrow == 0) || (arrow == 2))
				{
					ADMUX = 0x40;
				}
				else
				{
					ADMUX = 0x41;
				}
				arrows_period = 0;
			}
			if(arrows_inputP >= 20)
			{
				DDR_Input();
				DDR_JoyStk();
				arrows_inputP = 0;
			}
			if(arrowsPeriod >= 250)
			{
				DDR_ChkLoss();
				arrowsPeriod = 0;
			}
			displayMatrix();
			++arrows_inputP;
			++arrows_period;
			++arrowsPeriod;
		}
		if(gameSelector == 0x03)
		{
			if(snakeJoystick > 30)
			{
				Snake_JoyStk();
				Snake_Input();
				snakeJoystick = 0;
			}
			if(body > body_period)
			{
				SnakeBody();
				Snake_Movement();
				body = 0;
			}
			++snakeJoystick;
			++joystick;
			++body;
			displayMatrix();
		}
		while(!TimerFlag);
		TimerFlag = 0;
    }
}