// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved


// This software makes use of tools and libraries obtained from open source projects or released for

// use by relevant hardware manufactures. However, this software is NOT a part of any open source project.

// It is released only on a "need to know" basis for beta testers of the "RiceCNC Interpolation Engine".

// Recipents of this source code must respect the confidential nature of this software and prevent any

// distribution that could result in counterfeit copies of the "RiceCNC Interpolation Engine".


// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved

#include <SysTick.h>

#include "Timers.h"

#include "AxisTimer.h"

#include "InterpolationTimer.h"

#include "MainCommands.h"


#include <driverlib/timer.h>

#include <driverlib/SysTick.h>

#include <inc/hw_ints.h>


volatile uint32_t     SysTick::microSecondTimer          = 0;


/*

wiring.c initializes SysTick to 100 Khz

Here I reinitialize it to 1 MHz ( microsecond ) and change the handler

This disables the Energia delay( milliseconds ) and the delayMicroseconds ( µS ) functions

that use the SysTick timer

It also disables the registerSysTickCb function


The micro() and millis() functions will still work as they use Timer5

*/


void

     SysTick::StartSysTickInterrupts() {


     // Use SysTick to drive microsecond counter

     SysTickPeriodSet( Timers::frequencyToPeriod( 1000000 ) ); // 1 µSec interrupts (119)

     SysTickIntRegister(

          SysTick::SysTickInterruptHandler );

     ROM_IntPrioritySet(

          FAULT_SYSTICK,

          SysTickPriorityLevel );

     SysTick::microSecondTimer          = 0;

     SysTickEnable();

     SysTickIntEnable(); };



void

     SysTick::SysTickInterruptHandler(void) {


     // At SysTickPriorityLevel priority level the timer interrupts are disabled

     // SysTick interrupt flag is automatically cleared

     SysTick::microSecondTimer++; };