コード例 #1
0
//*********************************************************************************************
// verifySequence_runTest()
// Tests the verifySequence state machine.
// It prints instructions to the touch-screen. The user responds by tapping the
// correct colors to match the sequence.
// Users can test the error conditions by waiting too long to tap a color or
// by tapping an incorrect color.
//*********************************************************************************************
void verifySequence_runTest()
{
    display_init();  // Always must do this.
    buttons_init();  // Need to use the push-button package so user can quit.
    int16_t sequenceLength = ONE;  // Start out with a sequence length of 1.
    verifySequence_printInstructions(sequenceLength, false);  // Tell the user what to do.
    utils_msDelay(MESSAGE_WAIT_MS);  // Give them a few seconds to read the instructions.
    simonDisplay_drawAllButtons()    // Now, draw the buttons.
    // Set the test sequence and it's length.
    globals_setSequence(verifySequence_testSequence, MAX_TEST_SEQUENCE_LENGTH);
    globals_setSequenceIterationLength(sequenceLength);
    // Enable the verifySequence state machine.
    verifySequence_enable();           // Everything is interlocked, so first enable the machine.
    while (!(buttons_read() & BTN0))// Need to hold button until it quits as you might be stuck in a delay.
    {
        // verifySequence uses the buttonHandler state machine so you need to "tick" both of them.
        verifySequence_tick();  // Advance the verifySequence state machine.
        simonbuttonHandler_tick();   // Advance the buttonHandler state machine.
        utils_msDelay(ONE_MS);       // Wait 1 ms.
        // If the verifySequence state machine has finished, check the result, otherwise just keep ticking both machines.
    if (verifySequence_isComplete())
    {
      if (verifySequence_isTimeOutError())
      {                      // Was the user too slow?
        verifySequence_printInfoMessage(user_time_out_e);         // Yes, tell the user that they were too slow.
      }
      else if (verifySequence_isUserInputError())
      {             // Did the user tap the wrong color?
        verifySequence_printInfoMessage(user_wrong_sequence_e);   // Yes, tell them so.
      }
      else
      {
        verifySequence_printInfoMessage(user_correct_sequence_e); // User was correct if you get here.
      }
      utils_msDelay(MESSAGE_WAIT_MS);                            // Allow the user to read the message.
      sequenceLength = incrementSequenceLength(sequenceLength);  // Increment the sequence.
      globals_setSequenceIterationLength(sequenceLength);  // Set the length for the verifySequence state machine.
      verifySequence_printInstructions(sequenceLength, V_ENABLED);    // Print the instructions.
      utils_msDelay(MESSAGE_WAIT_MS);                            // Let the user read the instructions.
      verifySequence_drawButtons();                              // Draw the buttons.
      verifySequence_disable();                                  // Interlock: first step of handshake.
      verifySequence_tick();                                     // Advance the verifySequence machine.
      utils_msDelay(ONE_MS);                                          // Wait for 1 ms.
      verifySequence_enable();                                   // Interlock: second step of handshake.
      utils_msDelay(ONE_MS);                                          // Wait 1 ms.
    }
  }
  verifySequence_printInfoMessage(user_quit_e);  // Quitting, print out an informational message.
}
コード例 #2
0
ファイル: main.c プロジェクト: catskull/ECEN-330
// This will call all the state machine's tick functions and
// increment isr_functionCallCount.
void isr_function() {
    simonControl_tick();
    flashSequence_tick();
    verifySequence_tick();
    buttonHandler_tick();
    isr_functionCallCount++;
}
コード例 #3
0
ファイル: simonMain.c プロジェクト: brianlwatson/ZYBO
int main()
{
		srand(LARGE_PRIME_NUMBER);
	    // 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 clock display is not time-dependent, do it outside of the state machine.
	    //TicTacToeDisplay_init();
	    display_init();
	    display_fillScreen(DISPLAY_BLACK);
	    buttons_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.
	     while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) {
	      if (interrupts_isrFlagGlobal) {  // This is a global flag that is set by the timer interrupt handler.
	    	  // Count ticks.
	    	  double duration0;
	      	personalInterruptCount++;
	      	 SimonControl_tick();
	      	verifySequence_tick();
	      	flashSequence_tick();
	      	simonbuttonHandler_tick();
	    	  interrupts_isrFlagGlobal = FLAG_DOWN;
	      }
	   }
	   interrupts_disableArmInts();
	   printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount());
	   printf("internal interrupt count: %ld\n\r", personalInterruptCount);
	   return 0;

}
コード例 #4
0
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;
}