PP6b.systick Interrupts

Embed Size (px)

Citation preview

  • 7/25/2019 PP6b.systick Interrupts

    1/10

    SysTick Interrupt Example

    Basic timer included in all

    Cortex-M4 devices.

  • 7/25/2019 PP6b.systick Interrupts

    2/10

    Interrupt Summary

    Determine the name of the interrupthandler (from vector table) & interruptindex (from derivative.h)

    Create interrupt handler function Create interrupt setup function

    11/09/2015 EEE20003 Embedded Microcontrollers 2

  • 7/25/2019 PP6b.systick Interrupts

    3/10

    Interrupt handler

    Use whatever name is given in thevector table.

    Should clear the interrupt flag (if it

    exists) check hardware details. Carry out whatever function is needed.

    May need to do some setup for the

    next interrupt e.g. schedule timer.

    11/09/2015 EEE20003 Embedded Microcontrollers 3

  • 7/25/2019 PP6b.systick Interrupts

    4/10

    Interrupt Setup

    Initialise hardware Do whatever setup is required e.g. set tick

    rate etc.

    Enable interrupt signal (unmask it) inhardware

    Enable interrupt signal (unmask it) inNVIC

    NVIC_EnableIrq(int interruptIndex)

    11/09/2015 EEE20003 Embedded Microcontrollers 4

  • 7/25/2019 PP6b.systick Interrupts

    5/10

    11/09/2015 EEE20003 Embedded Microcontrollers 5

    IRQ Handler or ISR

    The interrupt handler resembles a subroutineor C function.

    Its address must be placed in the appropriateentry of the vector tableso that it may be

    calledwhen triggered.

    The Cortex-M family uses a interrupttechnique that allows the direct use of C

    functionsas interrupt handlers. The correctregisters are saved and restored

    by hardware (matches ARM-ABI used by C).

  • 7/25/2019 PP6b.systick Interrupts

    6/10

    SysTick Timer

    This is a basic timer that is included inall Cortex-M3 & M4 devices.

    Real-time Operating Systems (RTOSs)

    require at least a basic timer that isable to generate regular interrupts.

    Inclusion in the processor core allows

    the creation of chip independent RTOS.A good (simple) example of a interrupt

    source.

    11/09/2015 EEE20003 Embedded Microcontrollers 6

  • 7/25/2019 PP6b.systick Interrupts

    7/10

    Hardware

    11/09/2015 EEE20003 Embedded Microcontrollers 7

    24-bit down counter0

    1

    Referenceclock

    Core clock

    Reload register

    SysTick->VAL

    SysTick->LOAD

    CLKSOURCE_MASK TICKINT_MASK

    SysTick->CTRL

    ENABLE_MASK

    Control

    CPU

    Interrupt Request

    Timer automatically re-loadswhen it reaches zero.

  • 7/25/2019 PP6b.systick Interrupts

    8/10

    Software Routine

    11/09/2015 EEE20003 Embedded Microcontrollers 8

    uint32_tSysTick_Config(uint32_tticks) {

    if((ticks - 1) > SysTick_LOAD_RELOAD_Msk) {

    /* Reload value impossible */return(1);

    }/* Set reload register */SysTick->LOAD = ticks - 1;

    /* Set Priority for Systick Interrupt */NVIC_SetPriority (SysTick_IRQn, (1CTRL =

    SysTick_CTRL_CLKSOURCE_Msk | // Use system core clockSysTick_CTRL_TICKINT_Msk | // Enable interruptsSysTick_CTRL_ENABLE_Msk; // Enable timer

    /* Function successful */return(0);}

    Code to Set period (interrupt rate)

    Enable interrupts

    Enable timer

  • 7/25/2019 PP6b.systick Interrupts

    9/10

    Vector Table

    11/09/2015 EEE20003 Embedded Microcontrollers 9

    ...

    voidSysTick_Handler(void) WEAK_DEFAULT_HANDLER;...

    VectorTable const__vector_table = {

    /* omitted rows */

    SVC_Handler, /* System Service Call via SVC instruction */

    DebugMon_Handler, /* Debug Monitor*/

    0, /* Reserved */PendSV_Handler, /* Pendable request for system service */

    SysTick_Handler, /* System Tick Timer */

    /* External Interrupts */

    DMA0_IRQHandler, /* DMA channel 0 interrupt */

    DMA1_IRQHandler, /* DMA channel 1 interrupt */

    /* omitted rows */

    };

    Vector table entry for

    SysTick Timer

    The name of the actual interrupt handler functionmust agree exactly with the vector table entry

    It must also have "C" linkage.

    Weakly assigns to thedefault handler

    Can be overridden.

  • 7/25/2019 PP6b.systick Interrupts

    10/10

    SysTick Handler

    11/09/2015 EEE20003 Embedded Microcontrollers 10

    /*

    * This function is used for the

    * System Timer interrupt handler.

    */

    voidSysTick_Handler(void) {

    ...

    }

    Name agrees withVector Table entry

    Code to

    Handle Tick