User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

interrupts_direct_invocation [2019/05/07 11:11] (current)
hutch created
Line 1: Line 1:
 +==== Interrupts Using the Direct-Invocation Method: isr_function() ====
 +For the second interrupt-based approach, you will learn to use the isr_function() to invoke the clockControl_tick() function. isr_function() is called by the timer interrupt code. Each time the timer generates an interrupt, isr_function() will be called. In the code I provide below I left the isr_function() partially implemented. You must add one line of code to isr_function():​ clockControl_tick(). Compare the two different versions of the interrupt code that I provide so that you can explain these differences to the TAs.
 +**This code uses the isr_function() approach for interrupts.** Simply use this file as your main.c when using this interrupt method. You will need to add your tick function to isr_function().
 +<code C>
 +********ISR Function Approach ******
 +#include "​xparameters.h"​
 +#include <​stdio.h>​
 +#include "​supportFiles/​leds.h"​
 +#include "​supportFiles/​globalTimer.h"​
 +#include "​supportFiles/​interrupts.h"​
 +#include <​stdbool.h>​
 +#include <​stdint.h>​
 +#include "​clockControl.h"​
 +#include "​clockDisplay.h"​
 +#include "​supportFiles/​display.h"​
 +#define TOTAL_SECONDS 60
 +// 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
 +#define TIMER_PERIOD 50.0E-3
 +static uint32_t isr_functionCallCount = 0;
 +int main()
 +    // 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);​
 +    printf("​timer load value:​%ld\n\r",​ (int32_t) TIMER_LOAD_VALUE);​
 +    u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond();​
 +    printf("​private timer ticks per second: %ld\n\r",​ privateTimerTicksPerSecond);​
 +    interrupts_enableTimerGlobalInts();​
 +    // Initialization of the clock display is not time-dependent,​ do it outside of the state machine.
 +    clockDisplay_init();​
 +    // Start the private ARM timer running.
 +    interrupts_startArmPrivateTimer();​
 +    // Enable interrupts at the ARM.
 +    interrupts_enableArmInts();​
 +    // The while-loop just waits until the total number of timer ticks have occurred before proceeding.
 +    while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond));​
 +    // All done, now disable interrupts and print out the interrupt counts.
 +    interrupts_disableArmInts();​
 +    printf("​isr invocation count: %ld\n\r",​ interrupts_isrInvocationCount());​
 +    printf("​internal interrupt count: %ld\n\r",​ isr_functionCallCount);​
 +    return 0;
 +// The clockControl_tick() function is now called directly by the timer interrupt service routine.
 +void isr_function() {
 +   ​isr_functionCallCount++;​
 +    // Add the necessary code here.
interrupts_direct_invocation.txt ยท Last modified: 2019/05/07 11:11 by hutch