Example #1
0
// Just calls intervalTimer_reset on all timers.
u32 intervalTimer_resetAll() {
  int i;
  for (i=0; i<INTERVAL_TIMER_MAX_TIMER_INDEX; i++) {
    intervalTimer_reset(i);
  }
  return 0;
}
Example #2
0
//used to reset all of the timers at the same time
uint32_t intervalTimer_resetAll()
{
    for (int i=0; i<=2; i++)
    {
        intervalTimer_reset(i);//calls each of the timers
    }
}
uint32_t intervalTimer_runTest(uint32_t timerNumber) {

    intervalTimer_init(timerNumber);
    intervalTimer_reset(timerNumber);
    // Show that the timer is reset.
    printf("timer %ld TCR0 should be 0 at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    printf("timer %ld TCR1 should be 0 at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));

    // Statements returns false if TCR0 and TCR1 aren't 0
    if (readTimerRegister(INTERVALTIMER_TCR0_ADDRESS , timerNumber) !=INTERVALTIMER_INITIALIZE) {
        return INTERVALTIMER_VALID_TIMER_FALSE;
    }

    if (readTimerRegister(INTERVALTIMER_TCR1_ADDRESS , timerNumber) !=INTERVALTIMER_INITIALIZE) {
        return INTERVALTIMER_VALID_TIMER_FALSE;
    }

    intervalTimer_start(timerNumber);
    // Show that the timer is running.

    // Test points for comparison
    u32 TP_One;
    u32 TP_Two;

    printf("The following register values should be changing while reading them.\n\r");
    printf("timer %ld TCR0 should be changing at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    TP_One = readTimerRegister(INTERVALTIMER_TCR0_ADDRESS , timerNumber);
    printf("timer %ld TCR0 should be changing at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    printf("timer %ld TCR0 should be changing at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    printf("timer %ld TCR0 should be changing at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    TP_Two = readTimerRegister(INTERVALTIMER_TCR0_ADDRESS , timerNumber);
    printf("timer %ld TCR0 should be changing at this point:%ld\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));

    // Statement returns false if TCR0 isn't changing
    if (TP_One == TP_Two) {
        return INTERVALTIMER_VALID_TIMER_FALSE;
    }

    // Wait about 2 minutes so that you roll over to TCR1.
    // If you don't see a '1' in TCR1 after this long wait you probably haven't programmed the timer correctly.
    waitALongTime();
    printf("timer %ld TCR0 value after wait:%lx\n\r", timerNumber , readTimerRegister(INTERVALTIMER_TCR0_ADDRESS, timerNumber));
    printf("timer %ld TCR1 should have changed at this point:%ld\n\r", timerNumber ,readTimerRegister(INTERVALTIMER_TCR1_ADDRESS, timerNumber));

    // Statement returns false if TCR1 didn't change
    if (readTimerRegister(INTERVALTIMER_TCR1_ADDRESS,timerNumber) == INTERVALTIMER_INITIALIZE) {
        return INTERVALTIMER_VALID_TIMER_FALSE;
    }

    return INTERVALTIMER_VALID_TIMER_TRUE;
}
Example #4
0
// runs a test to see if timers are operating correctly
uint32_t intervalTimer_runTest(uint32_t timerNumber)
{
    intervalTimer_init(timerNumber); //initialize the timer
    intervalTimer_reset(timerNumber); //reset the timer
    printf("timer_0 TCR0 should be 0 at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET)); // Show that the timer is reset.
    printf("timer_0 TCR1 should be 0 at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR1_OFFSET)); //reset the TCR1 as well as TCR0
    intervalTimer_start(timerNumber); // Show that the timer is running.
    printf("The following register values should be changing while reading them.\n\r"); //print statement to the screen
    printf("timer_0 TCR0 should be changing at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET)); //these print the current values of the timer
    printf("timer_0 TCR0 should be changing at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET)); //repeat multiple times to show that change is continuous as time passes
    printf("timer_0 TCR0 should be changing at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET));
    printf("timer_0 TCR0 should be changing at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET));
    printf("timer_0 TCR0 should be changing at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET));
    waitALongTime(); // Wait about 2 minutes so that you roll over to TCR1.
    printf("timer_0 TCR0 value after wait:%lx\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR0_OFFSET));// If you don't see a '1' in TCR1 after this long wait you probably haven't programmed the timer correctly.
    printf("timer_0 TCR1 should have changed at this point:%ld\n\r", readTimerRegister(timerNumber, INTERVALTIMER_TCR1_OFFSET));//this shows the time that has passed
}
Example #5
0
//
// This will configure the counter, start it, see if it runs, stop it, see if it stays stopped.
// Pretty good way to test for the existence of the counter hardware.
u32 intervalTimer_test(u32 timerNumber) {
  u32 errorValue = 0;
  // See if the hardware appears to be present by writing a value to the load register and reading it back.
  u32 loadValue = 0x55AA;
  intervalTimer_writeRegister(timerNumber, INTERVAL_TIMER_TLR0_REG_OFFSET, loadValue);
  if (loadValue != intervalTimer_readRegister(timerNumber, INTERVAL_TIMER_TLR0_REG_OFFSET)) {
    printf("intervalTimer_test: hardware for timer: %lu does not appear to be present.\n\r", timerNumber);
  }
  intervalTimer_init(timerNumber);  // Init the timer.
  intervalTimer_reset(timerNumber); // Reset the timer to 0.
  u32 counter0Value = intervalTimer_readRegister(timerNumber, INTERVAL_TIMER_TCR0_REG_OFFSET);
  // See if the timer is reset. Timer should be zero at this point.
  if (counter0Value) {
    printf("intervalTimer_test: counter 0 should be zero after initialization. Value is: %lu.\n", counter0Value);
    errorValue = 1;
  } else {
	// OK, see if the timer will run.
    intervalTimer_start(timerNumber);
    volatile int i;  // Wait for a bit.
    for (i=0; i<1000; i++);
    counter0Value = intervalTimer_readRegister(timerNumber, INTERVAL_TIMER_TCR0_REG_OFFSET);
    if (!counter0Value) {
	  printf("intervalTimer_test: counter 0 does not seem to be running. Value is: %lu.\n\r", counter0Value);
	  errorValue = 1;
    } else {
      // OK. See if the timer will stop.
      intervalTimer_stop(timerNumber);
      counter0Value = intervalTimer_readRegister(timerNumber, INTERVAL_TIMER_TCR0_REG_OFFSET);
      int i;  // Wait for a bit.
      for (i=0; i<1000; i++);
      u32 secondCounter0Value = intervalTimer_readRegister(timerNumber, INTERVAL_TIMER_TCR0_REG_OFFSET);
      if (counter0Value != secondCounter0Value) {
  	    printf("intervalTimer_test: counter 0 does not seem to be stopped.\n\r");
	    errorValue = 1;
      }
    }
  }
  return errorValue;
}
uint32_t intervalTimer_resetAll() {

	// Returns 1 if timer0 and timer1 and timer2 are all reset.  Returns 0 if one isn't reset
	return intervalTimer_reset(INTERVALTIMER_2_ID) & intervalTimer_reset(INTERVALTIMER_1_ID) & intervalTimer_reset(INTERVALTIMER_0_ID);
}
int main() {
	//buttonHandler_runTest(10);
	//flashSequence_runTest();
	//verifySequence_runTest();



	  // The formula for computing the load value is based upon the formula from 4.1.1 (calculating timer intervals)
	  // in the Cortex-A9 MPCore Technical Reference Manual 4-2.
	  // Assuming that the prescaler = 0, the formula for computing the load value based upon the desired period is:
	  // load-value = (period * timer-clock) - 1

	    // Initialize the GPIO LED driver and print out an error message if it fails (argument = true).
		   // You need to init the LEDs so that LD4 can function as a heartbeat.
	    leds_init(true);
	    // Init all interrupts (but does not enable the interrupts at the devices).
	    // Prints an error message if an internal failure occurs because the argument = true.
	    interrupts_initAll(true);
	    interrupts_setPrivateTimerLoadValue(TIMER_LOAD_VALUE);
	    u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond();
	    printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond);
	    // Allow the timer to generate interrupts.
	    interrupts_enableTimerGlobalInts();
	    // Initialization of the Simon game state machines is not time-dependent so we do it outside of the state machine.
		display_init();
		display_fillScreen(DISPLAY_BLACK);
	    // Keep track of your personal interrupt count. Want to make sure that you don't miss any interrupts.
	     int32_t personalInterruptCount = 0;
	    // Start the private ARM timer running.
	    interrupts_startArmPrivateTimer();
	    // Enable interrupts at the ARM.
	    interrupts_enableArmInts();
	    // interrupts_isrInvocationCount() returns the number of times that the timer ISR was invoked.
	    // This value is maintained by the timer ISR. Compare this number with your own local
	    // interrupt count to determine if you have missed any interrupts.


	    double *seconds;


	     while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) {
	      if (interrupts_isrFlagGlobal) {  // This is a global flag that is set by the timer interrupt handler.
	    	  // Count ticks.
	      	personalInterruptCount++;
	      	verifySequence_tick();
	      	flashSequence_tick();
	      	buttonHandler_tick();
	      	intervalTimer_start(1);

	      	simonControl_tick();
	      	intervalTimer_stop(1);
	      	intervalTimer_getTotalDurationInSeconds(1,seconds);
	      	printf("%f \r\n",*seconds);
	      	//printf("interrupt count: %lu \r\n", interrupts_isrInvocationCount());
	      	intervalTimer_reset(1);
	    	  interrupts_isrFlagGlobal = 0;
	      }
	   }
	   interrupts_disableArmInts();
	   printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount());
	   printf("internal interrupt count: %ld\n\r", personalInterruptCount);

	return 0;
}