// © 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 <ThreePhaseTimer.h>

#include "Timers.h"

#include <MainCommands.h>

#include <SoftPwmOutputPin.h>


#include <driverlib/timer.h>

#include <driverlib/sysctl.h>

#include <driverlib/interrupt.h>


#include <inc/hw_ints.h>

#include <inc/hw_timer.h>


//volatile uint32_t     ThreePhaseTimer::pwmLedInterruptCount     = 0;


void

     ThreePhaseTimer::disableThreePhaseTimerInterrupts() {


     TimerIntDisable(

          ThreePhaseTimerBase,

          ThreePhaseTimerTimeout ); };


void

     ThreePhaseTimer::enableThreePhaseTimerInterrupts() {

     

     TimerIntEnable(

          ThreePhaseTimerBase,

          ThreePhaseTimerTimeout ); };


void

     ThreePhaseTimer::startThreePhaseTimerInterrupts( uint32_t hz ) {


     TimerLoadSet(

          ThreePhaseTimerBase,

          ThreePhaseTimerLoad,

          Timers::frequencyToPeriod( hz ) );

  

     TimerIntRegister(

          ThreePhaseTimerBase,

          ThreePhaseTimerLoad,

          ThreePhaseTimer::ThreePhaseTimerInterruptHandler );


     //     INT_TIMER0B = 36 - PRI9 36..39

#ifdef PART_TM4C1294NCPDT // IntPrioritySet not working for this µP


     HWREG( NVIC_PRI9 ) &= ~NVIC_PRI9_INT36_M;

     HWREG( NVIC_PRI9 ) |= ThreePhaseTimerPriorityLevel << NVIC_PRI9_INT36_S;


#elif defined( PART_LM4F120H5QR )


     IntPrioritySet(

          ThreePhaseTimerInt,

          ThreePhaseTimerPriorityLevel );


#endif


     ThreePhaseTimer::enableThreePhaseInterrupts();


     TimerEnable(

          ThreePhaseTimerBase,

          ThreePhaseTimerLoad ); };


void

     ThreePhaseTimer::ThreePhaseTimerInterruptHandler( void ) {


     TimerIntClear(

          ThreePhaseTimerBase,

          ThreePhaseTimerTimeout );


//     Timers::setD4LED( ++ThreePhaseTimer::pwmLedInterruptCount >> 14 );

     ThreePhaseTimerOutputPin::pwmInterrupt(); };