Previous Page
    /******************************************************************************
    * SysTickDelay.c - A delay module based on the system timer
    * 01/07/13 TDM
    *
    * Edited By: Spencer Black April 4, 2015
    *     - Changed SysTickDlyInit() to allow module to work with KDS. reference
    *       'SDK/platform/CMSIS/Include/device/core_cm4.h' file for function.
    *     - Changed Clock cycles to 80000 due to 80MHz K02 core clock
    *     - Changed the Isr handler name to SysTick_Handler which vectors to
    *       the MCU startup file (startup_MK02F12810.S).
    *******************************************************************************
    * Project master header file
    ******************************************************************************/
    #include "includes.h"

    /******************************************************************************
    * Public Resources
    ******************************************************************************/
    void SysTickDlyInit(void);   /* SysTickDelay Initialization Routine*/
    void SysTickDelay(INT32U ms);   /* SysTickDelay Function           */
    INT32U GetmsCnt(void);          /* Read the current ms count       */

    /******************************************************************************
    * Private Resources
    ******************************************************************************/
    void SysTick_Handler(void);  /* SysTick interrupt service routine*/
    volatile INT32U SysTickmsCnt; /* 1ms counter variable            */

    /******************************************************************************
    * Module Defines
    ******************************************************************************/
    #define CLOCK_CYCLES 80000  //Clock cycles per 1ms (80MHz core)

    /******************************************************************************
    * SysTickDlyInit() - Initialization routine for SysTickDelay()
    *    MCU: K02
    ******************************************************************************/
    void SysTickDlyInit(void){
        while(SysTick_Config(CLOCK_CYCLES)){} //Returns 0 if successful
    }

    /******************************************************************************
    * SysTickDelay Function
    *    - Public
    *    - Delays 'ms' milliseconds (with 32 bit 'ms', max is 50 days)
    *    - Accuracy +0/-1 ms
    ******************************************************************************/
    void SysTickDelay(INT32U ms){
        INT32U start_cnt;
        start_cnt = SysTickmsCnt;
        while((SysTickmsCnt - start_cnt) < ms){} /* wait for ms to pass*/
    }

    /******************************************************************************
    * GetmsCnt() - Read the current ms counter value. (Public)
    ******************************************************************************/
    INT32U GetmsCnt(void) {
        return SysTickmsCnt;
    }

    /******************************************************************************
    * SysTickIsr() - System Tick Interrupt Service Routine. (Private)
    *    MCU: K02
    *    - setup for a 1ms periodic interrupt.
    ******************************************************************************/
    void SysTick_Handler(void){
         SysTickmsCnt++;                    /* Increment 1ms counter    */
    }
    

Previous Page