void hitLedTimer_runTest() {
	printf("\r\n-----HitLed Timer Test-----\r\n");
	hitLedTimer_init();

	  // We want to use the interval timers.
	  intervalTimer_initAll();
	  intervalTimer_resetAll();
	  intervalTimer_testAll();
	  printf("Laser Tag Test Program\n\r");
	  // Find out how many timer ticks per second.
	  u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond();
	  printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond);
	  // Initialize the GPIO LED driver and print out an error message if it fails (argument = true).
	  // The LD4 LED provides a heart-beat that visually verifies that interrupts are running.
	  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);
	  // Enables the main interrupt on the time.
	  interrupts_enableTimerGlobalInts();
	  // Start the private ARM timer running.
	  interrupts_startArmPrivateTimer();
	  printf("This program will run for %d seconds and print out statistics at the end of the run.\n\r",
		 TOTAL_SECONDS);
	  printf("Starting timer interrupts.\n\r");
	  // Enable global interrupt of System Monitor. The system monitor contains the ADC. Mainly to detect EOC interrupts.
	  interrupts_enableSysMonGlobalInts();
	  // Start a duration timer and compare its timing against the time computed by the timerIsr().
	  // Assume that ENABLE_INTERVAL_TIMER_0_IN_TIMER_ISR is defined in interrupts.h so that time spent in timer-isr is measured.

	  int countInterruptsViaInterruptsIsrFlag = 0;
	  // Enable interrupts at the ARM.
	  interrupts_enableArmInts();
	  intervalTimer_start(1);
	  // Wait until TOTAL seconds have expired. globalTimerTickCount is incremented by timer isr.
	  while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) {
	    if (interrupts_isrFlagGlobal) {				// If this is true, an interrupt has occured (at least one).
	      countInterruptsViaInterruptsIsrFlag++;	// Note that you saw it.
	      interrupts_isrFlagGlobal = 0;			// Reset the shared flag.
	      // Place non-timing critical code here.
		  hitLedTimer_start();
	      while(hitLedTimer_running()) {}
	      utils_msDelay(300);
	    }
	  }
	  interrupts_disableArmInts();	// Disable ARM interrupts.
	  intervalTimer_stop(1);			// Stop the interval timer.
	  double runningSeconds, isrRunningSeconds;
	  intervalTimer_getTotalDurationInSeconds(1, &runningSeconds);
	  printf("Total run time as measured by interval timer in seconds: %g.\n\r", runningSeconds);
	  intervalTimer_getTotalDurationInSeconds(0, &isrRunningSeconds);
	  printf("Measured run time in timerIsr (using interval timer): %g.\n\r", isrRunningSeconds);
	  printf("Detected interrupts via global flag: %d\n\r", countInterruptsViaInterruptsIsrFlag);
	  printf("During %d seconds, an average of %7.3f ADC samples were collected per second.\n\r",
		 TOTAL_SECONDS, (float) isr_getTotalAdcSampleCount() / (float) TOTAL_SECONDS);
	  printf("\r\n-----End HitLed Timer Test-----\r\n");
}
示例#2
0
/**
 * More advanced test that uses timer interrupts
 */
void test_Full() {
  // Initialize the GPIO LED driver and print out an error message if it fails (argument = true).
  // You need to init the LEDs so that LED4 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 clock display is not time-dependent, do it outside of the state machine.
  //ticTacToeDisplay_init();
  // 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 duration_max = 0.0;
  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++;


      intervalTimer_initAll();
      intervalTimer_start(INTERVALTIMER_TIMER0);

      ticTacToeControl_tick();

      intervalTimer_stop(INTERVALTIMER_TIMER0);

      // print out the longest tick execution time for user reference.
      double duration;   // measured with the intervalTimer
      intervalTimer_getTotalDurationInSeconds(INTERVALTIMER_TIMER0, &duration);
      // If this duration was larger than the previous max, update the values
      // and print it out.
      if (duration_max < duration) {
        duration_max = duration;
        printf("Duration:%lf\n", duration);
      }
      intervalTimer_resetAll();

      interrupts_isrFlagGlobal = 0;
    }
  }
  interrupts_disableArmInts();
  printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount());
  printf("internal interrupt count: %ld\n\r", personalInterruptCount);

}