// © 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 <SoftPwmTimer.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     SoftPwmTimer::pwmLedInterruptCount     = 0;


void

     SoftPwmTimer::disableSoftPwmInterrupts() {


     TimerIntDisable(

          SoftPwmTimerBase,

          SoftPwmTimerTimeout ); };


void

     SoftPwmTimer::enableSoftPwmInterrupts() {

     

     TimerIntEnable(

          SoftPwmTimerBase,

          SoftPwmTimerTimeout ); };


void

     SoftPwmTimer::startSoftPwmTimerInterrupts( uint32_t hz ) {


     TimerLoadSet(

          SoftPwmTimerBase,

          SoftPwmTimerLoad,

          Timers::frequencyToPeriod( hz ) );

  

     TimerIntRegister(

          SoftPwmTimerBase,

          SoftPwmTimerLoad,

          SoftPwmTimer::SoftPwmTimerInterruptHandler );


     //     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 ) |= SoftPwmTimerPriorityLevel << NVIC_PRI9_INT36_S;


#elif defined( PART_LM4F120H5QR )


     IntPrioritySet(

          SoftPwmTimerInt,

          SoftPwmTimerPriorityLevel );


#endif


     SoftPwmTimer::enableSoftPwmInterrupts();


     TimerEnable(

          SoftPwmTimerBase,

          SoftPwmTimerLoad ); };


void

     SoftPwmTimer::SoftPwmTimerInterruptHandler( void ) {


     TimerIntClear(

          SoftPwmTimerBase,

          SoftPwmTimerTimeout );


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

     SoftPwmOutputPin::pwmInterrupt(); };