|
|
@ -27,6 +27,7 @@ A full copy of the license may be found in the projects root directory
|
|
|
|
#include "globals.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "scheduler.h"
|
|
|
|
#include "scheduler.h"
|
|
|
|
#include "scheduledIO.h"
|
|
|
|
#include "scheduledIO.h"
|
|
|
|
|
|
|
|
#include "timers.h"
|
|
|
|
|
|
|
|
|
|
|
|
FuelSchedule fuelSchedule1;
|
|
|
|
FuelSchedule fuelSchedule1;
|
|
|
|
FuelSchedule fuelSchedule2;
|
|
|
|
FuelSchedule fuelSchedule2;
|
|
|
@ -148,7 +149,7 @@ void setFuelSchedule(struct Schedule *targetSchedule, unsigned long timeout, uns
|
|
|
|
targetSchedule->duration = duration;
|
|
|
|
targetSchedule->duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >16x (Each tick represents 16uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >16x (Each tick represents 16uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -161,7 +162,7 @@ void setFuelSchedule(struct Schedule *targetSchedule, unsigned long timeout, uns
|
|
|
|
targetSchedule->schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
targetSchedule->schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
|
|
|
|
|
|
|
|
//*targetSchedule->compare = targetSchedule->startCompare;
|
|
|
|
//*targetSchedule->compare = targetSchedule->startCompare;
|
|
|
|
FUEL1_COMPARE = (uint16_t)targetSchedule->startCompare; //Insert corrector compare HERE!
|
|
|
|
SET_COMPARE(FUEL1_COMPARE, targetSchedule->startCompare); //Insert corrector compare HERE!
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
|
FUEL1_TIMER_ENABLE();
|
|
|
|
FUEL1_TIMER_ENABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -195,10 +196,10 @@ void setFuelSchedule1(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule1.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule1.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule1.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule1.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
//Schedule 1 shares a timer with schedule 5
|
|
|
|
//Schedule 1 shares a timer with schedule 5
|
|
|
|
//if(channel5InjEnabled) { FUEL1_COMPARE = (uint16_t)setQueue(timer3Aqueue, &fuelSchedule1, &fuelSchedule5, FUEL1_COUNTER); }
|
|
|
|
//if(channel5InjEnabled) { SET_COMPARE(FUEL1_COMPARE, setQueue(timer3Aqueue, &fuelSchedule1, &fuelSchedule5, FUEL1_COUNTER) ); }
|
|
|
|
//else { timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1; FUEL1_COMPARE = (uint16_t)fuelSchedule1.startCompare; }
|
|
|
|
//else { timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1; SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.startCompare); }
|
|
|
|
//timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1;
|
|
|
|
//timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1;
|
|
|
|
FUEL1_COMPARE = (uint16_t)fuelSchedule1.startCompare;
|
|
|
|
SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.startCompare);
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
|
FUEL1_TIMER_ENABLE();
|
|
|
|
FUEL1_TIMER_ENABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -233,7 +234,7 @@ void setFuelSchedule2(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule2.duration = duration;
|
|
|
|
fuelSchedule2.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -241,7 +242,7 @@ void setFuelSchedule2(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule2.startCompare = FUEL2_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule2.startCompare = FUEL2_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule2.endCompare = fuelSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule2.endCompare = fuelSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL2_COMPARE = (uint16_t)fuelSchedule2.startCompare; //Use the B compare unit of timer 3
|
|
|
|
SET_COMPARE(FUEL2_COMPARE, fuelSchedule2.startCompare); //Use the B compare unit of timer 3
|
|
|
|
fuelSchedule2.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule2.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule2.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule2.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -271,7 +272,7 @@ void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule3.duration = duration;
|
|
|
|
fuelSchedule3.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -279,7 +280,7 @@ void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule3.startCompare = FUEL3_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule3.startCompare = FUEL3_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule3.endCompare = fuelSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule3.endCompare = fuelSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL3_COMPARE = (uint16_t)fuelSchedule3.startCompare; //Use the C compare unit of timer 3
|
|
|
|
SET_COMPARE(FUEL3_COMPARE, fuelSchedule3.startCompare); //Use the C compare unit of timer 3
|
|
|
|
fuelSchedule3.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule3.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule3.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule3.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -309,7 +310,7 @@ void setFuelSchedule4(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule4.duration = duration;
|
|
|
|
fuelSchedule4.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -317,7 +318,7 @@ void setFuelSchedule4(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule4.startCompare = FUEL4_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule4.startCompare = FUEL4_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule4.endCompare = fuelSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule4.endCompare = fuelSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL4_COMPARE = (uint16_t)fuelSchedule4.startCompare; //Use the B compare unit of timer 4
|
|
|
|
SET_COMPARE(FUEL4_COMPARE, fuelSchedule4.startCompare); //Use the B compare unit of timer 4
|
|
|
|
fuelSchedule4.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule4.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule4.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule4.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -345,7 +346,7 @@ void setFuelSchedule5(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule5.duration = duration;
|
|
|
|
fuelSchedule5.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +354,7 @@ void setFuelSchedule5(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule5.startCompare = FUEL5_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule5.startCompare = FUEL5_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule5.endCompare = fuelSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule5.endCompare = fuelSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL5_COMPARE = (uint16_t)fuelSchedule5.startCompare; //Use the C compare unit of timer 4
|
|
|
|
SET_COMPARE(FUEL5_COMPARE, fuelSchedule5.startCompare); //Use the C compare unit of timer 4
|
|
|
|
fuelSchedule5.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule5.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule5.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule5.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -382,7 +383,7 @@ void setFuelSchedule6(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule6.duration = duration;
|
|
|
|
fuelSchedule6.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -390,7 +391,7 @@ void setFuelSchedule6(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule6.startCompare = FUEL6_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule6.startCompare = FUEL6_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule6.endCompare = fuelSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule6.endCompare = fuelSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL6_COMPARE = (uint16_t)fuelSchedule6.startCompare; //Use the A compare unit of timer 4
|
|
|
|
SET_COMPARE(FUEL6_COMPARE, fuelSchedule6.startCompare); //Use the A compare unit of timer 4
|
|
|
|
fuelSchedule6.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule6.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule6.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule6.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -419,7 +420,7 @@ void setFuelSchedule7(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule7.duration = duration;
|
|
|
|
fuelSchedule7.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -427,7 +428,7 @@ void setFuelSchedule7(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule7.startCompare = FUEL7_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule7.startCompare = FUEL7_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule7.endCompare = fuelSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule7.endCompare = fuelSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL7_COMPARE = (uint16_t)fuelSchedule7.startCompare; //Use the C compare unit of timer 5
|
|
|
|
SET_COMPARE(FUEL7_COMPARE, fuelSchedule7.startCompare); //Use the C compare unit of timer 5
|
|
|
|
fuelSchedule7.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule7.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule7.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule7.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -456,7 +457,7 @@ void setFuelSchedule8(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
fuelSchedule8.duration = duration;
|
|
|
|
fuelSchedule8.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
@ -464,7 +465,7 @@ void setFuelSchedule8(unsigned long timeout, unsigned long duration) //Uses time
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
fuelSchedule8.startCompare = FUEL8_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule8.startCompare = FUEL8_COUNTER + timeout_timer_compare;
|
|
|
|
fuelSchedule8.endCompare = fuelSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
fuelSchedule8.endCompare = fuelSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration);
|
|
|
|
FUEL8_COMPARE = (uint16_t)fuelSchedule8.startCompare; //Use the B compare unit of timer 5
|
|
|
|
SET_COMPARE(FUEL8_COMPARE, fuelSchedule8.startCompare); //Use the B compare unit of timer 5
|
|
|
|
fuelSchedule8.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule8.Status = PENDING; //Turn this schedule on
|
|
|
|
fuelSchedule8.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
fuelSchedule8.schedulesSet++; //Increment the number of times this schedule has been set
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -492,7 +493,7 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule1.duration = duration;
|
|
|
|
ignitionSchedule1.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
//timeout -= (micros() - lastCrankAngleCalc);
|
|
|
|
//timeout -= (micros() - lastCrankAngleCalc);
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
@ -500,7 +501,7 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule1.startCompare = IGN1_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
ignitionSchedule1.startCompare = IGN1_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
if(ignitionSchedule1.endScheduleSetByDecoder == false) { ignitionSchedule1.endCompare = ignitionSchedule1.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule1.endScheduleSetByDecoder == false) { ignitionSchedule1.endCompare = ignitionSchedule1.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN1_COMPARE = (uint16_t)ignitionSchedule1.startCompare;
|
|
|
|
SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.startCompare);
|
|
|
|
ignitionSchedule1.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule1.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule1.schedulesSet++;
|
|
|
|
ignitionSchedule1.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -528,7 +529,7 @@ inline void refreshIgnitionSchedule1(unsigned long timeToEnd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE(timeToEnd);
|
|
|
|
ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE(timeToEnd);
|
|
|
|
IGN1_COMPARE = (uint16_t)ignitionSchedule1.endCompare;
|
|
|
|
SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.endCompare);
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -542,14 +543,14 @@ void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule2.duration = duration;
|
|
|
|
ignitionSchedule2.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule2.startCompare = IGN2_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
ignitionSchedule2.startCompare = IGN2_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
if(ignitionSchedule2.endScheduleSetByDecoder == false) { ignitionSchedule2.endCompare = ignitionSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule2.endScheduleSetByDecoder == false) { ignitionSchedule2.endCompare = ignitionSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN2_COMPARE = (uint16_t)ignitionSchedule2.startCompare;
|
|
|
|
SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.startCompare);
|
|
|
|
ignitionSchedule2.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule2.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule2.schedulesSet++;
|
|
|
|
ignitionSchedule2.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -577,14 +578,14 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule3.duration = duration;
|
|
|
|
ignitionSchedule3.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule3.startCompare = IGN3_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
ignitionSchedule3.startCompare = IGN3_COUNTER + timeout_timer_compare; //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
|
|
|
|
if(ignitionSchedule3.endScheduleSetByDecoder == false) { ignitionSchedule3.endCompare = ignitionSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule3.endScheduleSetByDecoder == false) { ignitionSchedule3.endCompare = ignitionSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN3_COMPARE = (uint16_t)ignitionSchedule3.startCompare;
|
|
|
|
SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.startCompare);
|
|
|
|
ignitionSchedule3.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule3.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule3.schedulesSet++;
|
|
|
|
ignitionSchedule3.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -612,14 +613,14 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule4.duration = duration;
|
|
|
|
ignitionSchedule4.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule4.startCompare = IGN4_COUNTER + timeout_timer_compare;
|
|
|
|
ignitionSchedule4.startCompare = IGN4_COUNTER + timeout_timer_compare;
|
|
|
|
if(ignitionSchedule4.endScheduleSetByDecoder == false) { ignitionSchedule4.endCompare = ignitionSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule4.endScheduleSetByDecoder == false) { ignitionSchedule4.endCompare = ignitionSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN4_COMPARE = (uint16_t)ignitionSchedule4.startCompare;
|
|
|
|
SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.startCompare);
|
|
|
|
ignitionSchedule4.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule4.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule4.schedulesSet++;
|
|
|
|
ignitionSchedule4.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -647,14 +648,14 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule5.duration = duration;
|
|
|
|
ignitionSchedule5.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule5.startCompare = IGN5_COUNTER + timeout_timer_compare;
|
|
|
|
ignitionSchedule5.startCompare = IGN5_COUNTER + timeout_timer_compare;
|
|
|
|
if(ignitionSchedule5.endScheduleSetByDecoder == false) { ignitionSchedule5.endCompare = ignitionSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule5.endScheduleSetByDecoder == false) { ignitionSchedule5.endCompare = ignitionSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN5_COMPARE = (uint16_t)ignitionSchedule5.startCompare;
|
|
|
|
SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.startCompare);
|
|
|
|
ignitionSchedule5.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule5.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule5.schedulesSet++;
|
|
|
|
ignitionSchedule5.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -682,14 +683,14 @@ void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule6.duration = duration;
|
|
|
|
ignitionSchedule6.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule6.startCompare = IGN6_COUNTER + timeout_timer_compare;
|
|
|
|
ignitionSchedule6.startCompare = IGN6_COUNTER + timeout_timer_compare;
|
|
|
|
if(ignitionSchedule6.endScheduleSetByDecoder == false) { ignitionSchedule6.endCompare = ignitionSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule6.endScheduleSetByDecoder == false) { ignitionSchedule6.endCompare = ignitionSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN6_COMPARE = (uint16_t)ignitionSchedule6.startCompare;
|
|
|
|
SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.startCompare);
|
|
|
|
ignitionSchedule6.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule6.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule6.schedulesSet++;
|
|
|
|
ignitionSchedule6.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -717,14 +718,14 @@ void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule7.duration = duration;
|
|
|
|
ignitionSchedule7.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule7.startCompare = IGN7_COUNTER + timeout_timer_compare;
|
|
|
|
ignitionSchedule7.startCompare = IGN7_COUNTER + timeout_timer_compare;
|
|
|
|
if(ignitionSchedule7.endScheduleSetByDecoder == false) { ignitionSchedule7.endCompare = ignitionSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule7.endScheduleSetByDecoder == false) { ignitionSchedule7.endCompare = ignitionSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN7_COMPARE = (uint16_t)ignitionSchedule7.startCompare;
|
|
|
|
SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.startCompare);
|
|
|
|
ignitionSchedule7.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule7.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule7.schedulesSet++;
|
|
|
|
ignitionSchedule7.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -752,14 +753,14 @@ void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsign
|
|
|
|
ignitionSchedule8.duration = duration;
|
|
|
|
ignitionSchedule8.duration = duration;
|
|
|
|
|
|
|
|
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
//Need to check that the timeout doesn't exceed the overflow
|
|
|
|
uint16_t timeout_timer_compare;
|
|
|
|
COMPARE_TYPE timeout_timer_compare;
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case
|
|
|
|
|
|
|
|
|
|
|
|
noInterrupts();
|
|
|
|
noInterrupts();
|
|
|
|
ignitionSchedule8.startCompare = IGN8_COUNTER + timeout_timer_compare;
|
|
|
|
ignitionSchedule8.startCompare = IGN8_COUNTER + timeout_timer_compare;
|
|
|
|
if(ignitionSchedule8.endScheduleSetByDecoder == false) { ignitionSchedule8.endCompare = ignitionSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
if(ignitionSchedule8.endScheduleSetByDecoder == false) { ignitionSchedule8.endCompare = ignitionSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden.
|
|
|
|
IGN8_COMPARE = (uint16_t)ignitionSchedule8.startCompare;
|
|
|
|
SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.startCompare);
|
|
|
|
ignitionSchedule8.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule8.Status = PENDING; //Turn this schedule on
|
|
|
|
ignitionSchedule8.schedulesSet++;
|
|
|
|
ignitionSchedule8.schedulesSet++;
|
|
|
|
interrupts();
|
|
|
|
interrupts();
|
|
|
@ -832,7 +833,7 @@ static inline void fuelSchedule1Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//To use timer queue, change fuelShedule1 to timer3Aqueue[0];
|
|
|
|
//To use timer queue, change fuelShedule1 to timer3Aqueue[0];
|
|
|
|
inj1StartFunction();
|
|
|
|
inj1StartFunction();
|
|
|
|
fuelSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL1_COMPARE = (uint16_t)(FUEL1_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule1.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL1_COMPARE, FUEL1_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule1.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule1.Status == RUNNING)
|
|
|
|
else if (fuelSchedule1.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -840,12 +841,12 @@ static inline void fuelSchedule1Interrupt() //Most ARM chips can simply call a f
|
|
|
|
inj1EndFunction();
|
|
|
|
inj1EndFunction();
|
|
|
|
fuelSchedule1.Status = OFF; //Turn off the schedule
|
|
|
|
fuelSchedule1.Status = OFF; //Turn off the schedule
|
|
|
|
fuelSchedule1.schedulesSet = 0;
|
|
|
|
fuelSchedule1.schedulesSet = 0;
|
|
|
|
//FUEL1_COMPARE = (uint16_t)fuelSchedule1.endCompare;
|
|
|
|
//SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.endCompare);
|
|
|
|
|
|
|
|
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule1.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule1.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL1_COMPARE = (uint16_t)fuelSchedule1.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.nextStartCompare);
|
|
|
|
fuelSchedule1.endCompare = fuelSchedule1.nextEndCompare;
|
|
|
|
fuelSchedule1.endCompare = fuelSchedule1.nextEndCompare;
|
|
|
|
fuelSchedule1.Status = PENDING;
|
|
|
|
fuelSchedule1.Status = PENDING;
|
|
|
|
fuelSchedule1.schedulesSet = 1;
|
|
|
|
fuelSchedule1.schedulesSet = 1;
|
|
|
@ -869,7 +870,7 @@ static inline void fuelSchedule2Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule2.StartCallback();
|
|
|
|
//fuelSchedule2.StartCallback();
|
|
|
|
inj2StartFunction();
|
|
|
|
inj2StartFunction();
|
|
|
|
fuelSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL2_COMPARE = (uint16_t)(FUEL2_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule2.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL2_COMPARE, FUEL2_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule2.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule2.Status == RUNNING)
|
|
|
|
else if (fuelSchedule2.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -881,7 +882,7 @@ static inline void fuelSchedule2Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule2.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule2.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL2_COMPARE = (uint16_t)fuelSchedule2.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL2_COMPARE, fuelSchedule2.nextStartCompare);
|
|
|
|
fuelSchedule2.endCompare = fuelSchedule2.nextEndCompare;
|
|
|
|
fuelSchedule2.endCompare = fuelSchedule2.nextEndCompare;
|
|
|
|
fuelSchedule2.Status = PENDING;
|
|
|
|
fuelSchedule2.Status = PENDING;
|
|
|
|
fuelSchedule2.schedulesSet = 1;
|
|
|
|
fuelSchedule2.schedulesSet = 1;
|
|
|
@ -904,7 +905,7 @@ static inline void fuelSchedule3Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule3.StartCallback();
|
|
|
|
//fuelSchedule3.StartCallback();
|
|
|
|
inj3StartFunction();
|
|
|
|
inj3StartFunction();
|
|
|
|
fuelSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL3_COMPARE = (uint16_t)(FUEL3_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule3.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL3_COMPARE, FUEL3_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule3.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule3.Status == RUNNING)
|
|
|
|
else if (fuelSchedule3.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -916,7 +917,7 @@ static inline void fuelSchedule3Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule3.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule3.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL3_COMPARE = (uint16_t)fuelSchedule3.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL3_COMPARE, fuelSchedule3.nextStartCompare);
|
|
|
|
fuelSchedule3.endCompare = fuelSchedule3.nextEndCompare;
|
|
|
|
fuelSchedule3.endCompare = fuelSchedule3.nextEndCompare;
|
|
|
|
fuelSchedule3.Status = PENDING;
|
|
|
|
fuelSchedule3.Status = PENDING;
|
|
|
|
fuelSchedule3.schedulesSet = 1;
|
|
|
|
fuelSchedule3.schedulesSet = 1;
|
|
|
@ -939,7 +940,7 @@ static inline void fuelSchedule4Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule4.StartCallback();
|
|
|
|
//fuelSchedule4.StartCallback();
|
|
|
|
inj4StartFunction();
|
|
|
|
inj4StartFunction();
|
|
|
|
fuelSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL4_COMPARE = (uint16_t)(FUEL4_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule4.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL4_COMPARE, FUEL4_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule4.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule4.Status == RUNNING)
|
|
|
|
else if (fuelSchedule4.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -951,7 +952,7 @@ static inline void fuelSchedule4Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule4.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule4.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL4_COMPARE = (uint16_t)fuelSchedule4.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL4_COMPARE, fuelSchedule4.nextStartCompare);
|
|
|
|
fuelSchedule4.endCompare = fuelSchedule4.nextEndCompare;
|
|
|
|
fuelSchedule4.endCompare = fuelSchedule4.nextEndCompare;
|
|
|
|
fuelSchedule4.Status = PENDING;
|
|
|
|
fuelSchedule4.Status = PENDING;
|
|
|
|
fuelSchedule4.schedulesSet = 1;
|
|
|
|
fuelSchedule4.schedulesSet = 1;
|
|
|
@ -973,7 +974,7 @@ static inline void fuelSchedule5Interrupt() //Most ARM chips can simply call a f
|
|
|
|
{
|
|
|
|
{
|
|
|
|
inj5StartFunction();
|
|
|
|
inj5StartFunction();
|
|
|
|
fuelSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL5_COMPARE = (uint16_t)(FUEL5_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule5.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL5_COMPARE, FUEL5_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule5.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule5.Status == RUNNING)
|
|
|
|
else if (fuelSchedule5.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -984,7 +985,7 @@ static inline void fuelSchedule5Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule5.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule5.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL5_COMPARE = (uint16_t)fuelSchedule5.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL5_COMPARE, fuelSchedule5.nextStartCompare);
|
|
|
|
fuelSchedule5.endCompare = fuelSchedule5.nextEndCompare;
|
|
|
|
fuelSchedule5.endCompare = fuelSchedule5.nextEndCompare;
|
|
|
|
fuelSchedule5.Status = PENDING;
|
|
|
|
fuelSchedule5.Status = PENDING;
|
|
|
|
fuelSchedule5.schedulesSet = 1;
|
|
|
|
fuelSchedule5.schedulesSet = 1;
|
|
|
@ -1007,7 +1008,7 @@ static inline void fuelSchedule6Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule6.StartCallback();
|
|
|
|
//fuelSchedule6.StartCallback();
|
|
|
|
inj6StartFunction();
|
|
|
|
inj6StartFunction();
|
|
|
|
fuelSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL6_COMPARE = (uint16_t)(FUEL6_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule6.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL6_COMPARE, FUEL6_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule6.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule6.Status == RUNNING)
|
|
|
|
else if (fuelSchedule6.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1019,7 +1020,7 @@ static inline void fuelSchedule6Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule6.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule6.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL6_COMPARE = (uint16_t)fuelSchedule6.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL6_COMPARE, fuelSchedule6.nextStartCompare);
|
|
|
|
fuelSchedule6.endCompare = fuelSchedule6.nextEndCompare;
|
|
|
|
fuelSchedule6.endCompare = fuelSchedule6.nextEndCompare;
|
|
|
|
fuelSchedule6.Status = PENDING;
|
|
|
|
fuelSchedule6.Status = PENDING;
|
|
|
|
fuelSchedule6.schedulesSet = 1;
|
|
|
|
fuelSchedule6.schedulesSet = 1;
|
|
|
@ -1042,7 +1043,7 @@ static inline void fuelSchedule7Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule7.StartCallback();
|
|
|
|
//fuelSchedule7.StartCallback();
|
|
|
|
inj7StartFunction();
|
|
|
|
inj7StartFunction();
|
|
|
|
fuelSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL7_COMPARE = (uint16_t)(FUEL7_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule7.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL7_COMPARE, FUEL7_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule7.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule7.Status == RUNNING)
|
|
|
|
else if (fuelSchedule7.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1054,7 +1055,7 @@ static inline void fuelSchedule7Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule7.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule7.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL7_COMPARE = (uint16_t)fuelSchedule7.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL7_COMPARE, fuelSchedule7.nextStartCompare);
|
|
|
|
fuelSchedule7.endCompare = fuelSchedule7.nextEndCompare;
|
|
|
|
fuelSchedule7.endCompare = fuelSchedule7.nextEndCompare;
|
|
|
|
fuelSchedule7.Status = PENDING;
|
|
|
|
fuelSchedule7.Status = PENDING;
|
|
|
|
fuelSchedule7.schedulesSet = 1;
|
|
|
|
fuelSchedule7.schedulesSet = 1;
|
|
|
@ -1077,7 +1078,7 @@ static inline void fuelSchedule8Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//fuelSchedule8.StartCallback();
|
|
|
|
//fuelSchedule8.StartCallback();
|
|
|
|
inj8StartFunction();
|
|
|
|
inj8StartFunction();
|
|
|
|
fuelSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
fuelSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
FUEL8_COMPARE = (uint16_t)(FUEL8_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule8.duration)); //Doing this here prevents a potential overflow on restarts
|
|
|
|
SET_COMPARE(FUEL8_COMPARE, FUEL8_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule8.duration) ); //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fuelSchedule8.Status == RUNNING)
|
|
|
|
else if (fuelSchedule8.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1089,7 +1090,7 @@ static inline void fuelSchedule8Interrupt() //Most ARM chips can simply call a f
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(fuelSchedule8.hasNextSchedule == true)
|
|
|
|
if(fuelSchedule8.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUEL8_COMPARE = (uint16_t)fuelSchedule8.nextStartCompare;
|
|
|
|
SET_COMPARE(FUEL8_COMPARE, fuelSchedule8.nextStartCompare);
|
|
|
|
fuelSchedule8.endCompare = fuelSchedule8.nextEndCompare;
|
|
|
|
fuelSchedule8.endCompare = fuelSchedule8.nextEndCompare;
|
|
|
|
fuelSchedule8.Status = PENDING;
|
|
|
|
fuelSchedule8.Status = PENDING;
|
|
|
|
fuelSchedule8.schedulesSet = 1;
|
|
|
|
fuelSchedule8.schedulesSet = 1;
|
|
|
@ -1112,8 +1113,8 @@ static inline void ignitionSchedule1Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule1.StartCallback();
|
|
|
|
ignitionSchedule1.StartCallback();
|
|
|
|
ignitionSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule1.startTime = micros();
|
|
|
|
ignitionSchedule1.startTime = micros();
|
|
|
|
if(ignitionSchedule1.endScheduleSetByDecoder == true) { IGN1_COMPARE = (uint16_t)ignitionSchedule1.endCompare; }
|
|
|
|
if(ignitionSchedule1.endScheduleSetByDecoder == true) { SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.endCompare); }
|
|
|
|
else { IGN1_COMPARE = (uint16_t)(IGN1_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule1.duration)); } //Doing this here prevents a potential overflow on restarts
|
|
|
|
else { SET_COMPARE(IGN1_COMPARE, IGN1_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule1.duration) ); } //Doing this here prevents a potential overflow on restarts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule1.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule1.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1126,7 +1127,7 @@ static inline void ignitionSchedule1Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule1.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule1.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN1_COMPARE = (uint16_t)ignitionSchedule1.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.nextStartCompare);
|
|
|
|
ignitionSchedule1.Status = PENDING;
|
|
|
|
ignitionSchedule1.Status = PENDING;
|
|
|
|
ignitionSchedule1.schedulesSet = 1;
|
|
|
|
ignitionSchedule1.schedulesSet = 1;
|
|
|
|
ignitionSchedule1.hasNextSchedule = false;
|
|
|
|
ignitionSchedule1.hasNextSchedule = false;
|
|
|
@ -1153,8 +1154,8 @@ static inline void ignitionSchedule2Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule2.StartCallback();
|
|
|
|
ignitionSchedule2.StartCallback();
|
|
|
|
ignitionSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule2.startTime = micros();
|
|
|
|
ignitionSchedule2.startTime = micros();
|
|
|
|
if(ignitionSchedule2.endScheduleSetByDecoder == true) { IGN2_COMPARE = (uint16_t)ignitionSchedule2.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule2.endScheduleSetByDecoder == true) { SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN2_COMPARE = (uint16_t)(IGN2_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule2.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs
|
|
|
|
else { SET_COMPARE(IGN2_COMPARE, IGN2_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule2.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule2.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule2.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1167,7 +1168,7 @@ static inline void ignitionSchedule2Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule2.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule2.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN2_COMPARE = (uint16_t)ignitionSchedule2.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.nextStartCompare);
|
|
|
|
ignitionSchedule2.Status = PENDING;
|
|
|
|
ignitionSchedule2.Status = PENDING;
|
|
|
|
ignitionSchedule2.schedulesSet = 1;
|
|
|
|
ignitionSchedule2.schedulesSet = 1;
|
|
|
|
ignitionSchedule2.hasNextSchedule = false;
|
|
|
|
ignitionSchedule2.hasNextSchedule = false;
|
|
|
@ -1194,8 +1195,8 @@ static inline void ignitionSchedule3Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule3.StartCallback();
|
|
|
|
ignitionSchedule3.StartCallback();
|
|
|
|
ignitionSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule3.startTime = micros();
|
|
|
|
ignitionSchedule3.startTime = micros();
|
|
|
|
if(ignitionSchedule3.endScheduleSetByDecoder == true) { IGN3_COMPARE = (uint16_t)ignitionSchedule3.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule3.endScheduleSetByDecoder == true) { SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.endCompare ); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN3_COMPARE = (uint16_t)(IGN3_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule3.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs
|
|
|
|
else { SET_COMPARE(IGN3_COMPARE, IGN3_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule3.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule3.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule3.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1208,7 +1209,7 @@ static inline void ignitionSchedule3Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule3.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule3.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN3_COMPARE = (uint16_t)ignitionSchedule3.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.nextStartCompare);
|
|
|
|
ignitionSchedule3.Status = PENDING;
|
|
|
|
ignitionSchedule3.Status = PENDING;
|
|
|
|
ignitionSchedule3.schedulesSet = 1;
|
|
|
|
ignitionSchedule3.schedulesSet = 1;
|
|
|
|
ignitionSchedule3.hasNextSchedule = false;
|
|
|
|
ignitionSchedule3.hasNextSchedule = false;
|
|
|
@ -1235,8 +1236,8 @@ static inline void ignitionSchedule4Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule4.StartCallback();
|
|
|
|
ignitionSchedule4.StartCallback();
|
|
|
|
ignitionSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule4.startTime = micros();
|
|
|
|
ignitionSchedule4.startTime = micros();
|
|
|
|
if(ignitionSchedule4.endScheduleSetByDecoder == true) { IGN4_COMPARE = (uint16_t)ignitionSchedule4.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule4.endScheduleSetByDecoder == true) { SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN4_COMPARE = (uint16_t)(IGN4_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule4.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
else { SET_COMPARE(IGN4_COMPARE, IGN4_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule4.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule4.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule4.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1249,7 +1250,7 @@ static inline void ignitionSchedule4Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule4.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule4.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN4_COMPARE = (uint16_t)ignitionSchedule4.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.nextStartCompare);
|
|
|
|
ignitionSchedule4.Status = PENDING;
|
|
|
|
ignitionSchedule4.Status = PENDING;
|
|
|
|
ignitionSchedule4.schedulesSet = 1;
|
|
|
|
ignitionSchedule4.schedulesSet = 1;
|
|
|
|
ignitionSchedule4.hasNextSchedule = false;
|
|
|
|
ignitionSchedule4.hasNextSchedule = false;
|
|
|
@ -1276,8 +1277,8 @@ static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule5.StartCallback();
|
|
|
|
ignitionSchedule5.StartCallback();
|
|
|
|
ignitionSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule5.startTime = micros();
|
|
|
|
ignitionSchedule5.startTime = micros();
|
|
|
|
if(ignitionSchedule5.endScheduleSetByDecoder == true) { IGN5_COMPARE = (uint16_t)ignitionSchedule5.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule5.endScheduleSetByDecoder == true) { SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN5_COMPARE = (uint16_t)(IGN5_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule5.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
else { SET_COMPARE(IGN5_COMPARE, IGN5_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule5.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule5.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule5.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1290,7 +1291,7 @@ static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule5.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule5.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN5_COMPARE = (uint16_t)ignitionSchedule5.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.nextStartCompare);
|
|
|
|
ignitionSchedule5.Status = PENDING;
|
|
|
|
ignitionSchedule5.Status = PENDING;
|
|
|
|
ignitionSchedule5.schedulesSet = 1;
|
|
|
|
ignitionSchedule5.schedulesSet = 1;
|
|
|
|
ignitionSchedule5.hasNextSchedule = false;
|
|
|
|
ignitionSchedule5.hasNextSchedule = false;
|
|
|
@ -1317,8 +1318,8 @@ static inline void ignitionSchedule6Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule6.StartCallback();
|
|
|
|
ignitionSchedule6.StartCallback();
|
|
|
|
ignitionSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule6.startTime = micros();
|
|
|
|
ignitionSchedule6.startTime = micros();
|
|
|
|
if(ignitionSchedule6.endScheduleSetByDecoder == true) { IGN6_COMPARE = (uint16_t)ignitionSchedule6.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule6.endScheduleSetByDecoder == true) { SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN6_COMPARE = (uint16_t)(IGN6_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule6.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
else { SET_COMPARE(IGN6_COMPARE, IGN6_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule6.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule6.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule6.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1331,7 +1332,7 @@ static inline void ignitionSchedule6Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule6.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule6.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN6_COMPARE = (uint16_t)ignitionSchedule6.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.nextStartCompare);
|
|
|
|
ignitionSchedule6.Status = PENDING;
|
|
|
|
ignitionSchedule6.Status = PENDING;
|
|
|
|
ignitionSchedule6.schedulesSet = 1;
|
|
|
|
ignitionSchedule6.schedulesSet = 1;
|
|
|
|
ignitionSchedule6.hasNextSchedule = false;
|
|
|
|
ignitionSchedule6.hasNextSchedule = false;
|
|
|
@ -1358,8 +1359,8 @@ static inline void ignitionSchedule7Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule7.StartCallback();
|
|
|
|
ignitionSchedule7.StartCallback();
|
|
|
|
ignitionSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule7.startTime = micros();
|
|
|
|
ignitionSchedule7.startTime = micros();
|
|
|
|
if(ignitionSchedule7.endScheduleSetByDecoder == true) { IGN7_COMPARE = (uint16_t)ignitionSchedule7.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule7.endScheduleSetByDecoder == true) { SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN7_COMPARE = (uint16_t)(IGN7_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule7.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
else { SET_COMPARE(IGN7_COMPARE, IGN7_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule7.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule7.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule7.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1372,7 +1373,7 @@ static inline void ignitionSchedule7Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule7.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule7.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN7_COMPARE = (uint16_t)ignitionSchedule7.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.nextStartCompare);
|
|
|
|
ignitionSchedule7.Status = PENDING;
|
|
|
|
ignitionSchedule7.Status = PENDING;
|
|
|
|
ignitionSchedule7.schedulesSet = 1;
|
|
|
|
ignitionSchedule7.schedulesSet = 1;
|
|
|
|
ignitionSchedule7.hasNextSchedule = false;
|
|
|
|
ignitionSchedule7.hasNextSchedule = false;
|
|
|
@ -1399,8 +1400,8 @@ static inline void ignitionSchedule8Interrupt() //Most ARM chips can simply call
|
|
|
|
ignitionSchedule8.StartCallback();
|
|
|
|
ignitionSchedule8.StartCallback();
|
|
|
|
ignitionSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
|
|
|
|
ignitionSchedule8.startTime = micros();
|
|
|
|
ignitionSchedule8.startTime = micros();
|
|
|
|
if(ignitionSchedule8.endScheduleSetByDecoder == true) { IGN8_COMPARE = (uint16_t)ignitionSchedule8.endCompare; } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
if(ignitionSchedule8.endScheduleSetByDecoder == true) { SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.endCompare); } //If the decoder has set the end compare value, assign it to the next compare
|
|
|
|
else { IGN8_COMPARE = (uint16_t)(IGN8_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule8.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
else { SET_COMPARE(IGN8_COMPARE, IGN8_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule8.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow tha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ignitionSchedule8.Status == RUNNING)
|
|
|
|
else if (ignitionSchedule8.Status == RUNNING)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1413,7 +1414,7 @@ static inline void ignitionSchedule8Interrupt() //Most ARM chips can simply call
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
//If there is a next schedule queued up, activate it
|
|
|
|
if(ignitionSchedule8.hasNextSchedule == true)
|
|
|
|
if(ignitionSchedule8.hasNextSchedule == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IGN8_COMPARE = (uint16_t)ignitionSchedule8.nextStartCompare;
|
|
|
|
SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.nextStartCompare);
|
|
|
|
ignitionSchedule8.Status = PENDING;
|
|
|
|
ignitionSchedule8.Status = PENDING;
|
|
|
|
ignitionSchedule8.schedulesSet = 1;
|
|
|
|
ignitionSchedule8.schedulesSet = 1;
|
|
|
|
ignitionSchedule8.hasNextSchedule = false;
|
|
|
|
ignitionSchedule8.hasNextSchedule = false;
|
|
|
|