update processor ifdef to tidy code inc teensy options

This commit is contained in:
darren siepka 2016-10-14 12:17:17 +01:00
parent 6289f0cda2
commit 5f7ac06671
9 changed files with 63 additions and 39 deletions

View File

@ -21,7 +21,7 @@ void fanControl()
else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWrite(pinFan, fanLOW); }
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(PROCESSOR_MEGA_ALL)
void initialiseAuxPWM()
{
TCCR1B = 0x00; //Disbale Timer1 while we set it up
@ -64,7 +64,7 @@ void vvtControl()
byte vvtDuty = get3DTableValue(&vvtTable, currentStatus.TPS, currentStatus.RPM);
vvt_pwm_target_value = percentage(vvtDuty, vvt_pwm_max_count);
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(PROCESSOR_MEGA_ALL)
else { TIMSK1 &= ~(1 << OCIE1B); } // Disable timer channel
#endif
}
@ -105,7 +105,7 @@ ISR(TIMER1_COMPB_vect)
}
}
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
//YET TO BE IMPLEMENTED ON TEENSY
void initialiseAuxPWM() { }
void boostControl() { }

View File

@ -2,6 +2,30 @@
#define GLOBALS_H
#include <Arduino.h>
#if defined(__arm__)
#if defined(__MK20DX256__) && defined(CORE_TEENSY)
#define PROCESSOR_TEENSY_3_2 1 //compile for teensy 3.1/2 only
#elif defined(__MK64FX512__) && defined(CORE_TEENSY)
#define PROCESSOR_TEENSY_3_5 1 //compile for teensy 3.5 only
#endif
#if defined(__MK20DX256__) && defined(CORE_TEENSY) || defined(__MK64FX512__) && defined(CORE_TEENSY)
#define PROCESSOR_TEENSY_3_x 1 //compile for both teensy 3.1/2 and 3.5
#elif defined (CORE_TEENSY)
#error "Unknown Teensy"
#elif defined (__arm__)
#error "Unknown ARM chip"
#else
#error "Unknown board"
#endif
#elif defined(__AVR__)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define PROCESSOR_MEGA_NO61 1
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#define PROCESSOR_MEGA_ALL 1
#endif
#endif
#endif
//const byte ms_version = 20;
const byte signature = 20;

View File

@ -17,7 +17,7 @@ integerPID idlePID(&currentStatus.longRPM, &idle_pwm_target_value, &idle_cl_targ
void initialiseIdle()
{
//By default, turn off the PWM interrupt (It gets turned on below if needed)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(PROCESSOR_MEGA_ALL)
TIMSK4 &= ~(1 << OCIE4C); // Disable timer channel for idle
#endif
@ -239,7 +239,7 @@ void homeStepper()
}
//The interrupt to turn off the idle pwm
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(PROCESSOR_MEGA_ALL)
//This function simply turns off the idle PWM and sets the pin low
static inline void disableIdle()
{
@ -293,7 +293,7 @@ ISR(TIMER4_COMPC_vect)
}
}
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
//This function simply turns off the idle PWM and sets the pin low
static inline void disableIdle()
{

View File

@ -32,7 +32,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd
#include <avr/io.h>
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#if defined(PROCESSOR_MEGA_ALL)
//Refer to http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/iomxx0_1.h?root=avr-libc&view=markup
#define FUEL1_COUNTER TCNT3
#define FUEL2_COUNTER TCNT3
@ -74,7 +74,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd
#define IGN3_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5C) //Turn off this output compare unit
#define IGN4_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4A) //Turn off this output compare unit
#elif defined(CORE_TEENSY)
#elif defined(PROCESSOR_TEENSY_3_x)
//http://shawnhymel.com/661/learning-the-teensy-lc-interrupt-service-routines/
#define FUEL1_COUNTER FTM0_CNT
#define FUEL2_COUNTER FTM0_CNT

View File

@ -11,7 +11,7 @@ void initialiseSchedulers()
{
nullSchedule.Status = OFF;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
// Much help in this from http://arduinomega.blogspot.com.au/2011/05/timer2-and-overflow-interrupt-lets-get.html
//Fuel Schedules, which uses timer 3
TCCR3B = 0x00; //Disable Timer3 while we set it up
@ -35,7 +35,7 @@ void initialiseSchedulers()
TIFR4 = 0x00; //Timer4 INT Flag Reg: Clear Timer Overflow Flag
TCCR4A = 0x00; //Timer4 Control Reg A: Wave Gen Mode normal
TCCR4B = (1 << CS12); //Timer4 Control Reg B: aka Divisor = 256 = 122.5HzTimer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
#elif defined (CORE_TEENSY) && defined (__MK20DX256__)
#elif defined (PROCESSOR_TEENSY_3_x)
//Configure ARM timers here
#endif
@ -181,7 +181,7 @@ void setFuelSchedule5(void (*startCallback)(), unsigned long timeout, unsigned l
/*
* The following must be enclosed in the noIntterupts block to avoid contention caused if the relevant interrupts fires before the state is fully set
*/
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#if defined(PROCESSOR_MEGA_ALL)
noInterrupts();
fuelSchedule5.startCompare = TCNT3 + (timeout >> 4); //As above, but with bit shift instead of / 16
fuelSchedule5.endCompare = fuelSchedule5.startCompare + (duration >> 4);
@ -282,7 +282,7 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign
//As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency))
if (timeout > 262140) { timeout = 262100; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when applied causing erratic behaviour such as erroneous sparking. This must be set slightly lower than the max of 262140 to avoid strangeness
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#if defined(PROCESSOR_MEGA_ALL)
OCR5A = TCNT5 + (timeout >> 2); //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
ignitionSchedule5.Status = PENDING; //Turn this schedule on
TIMSK5 |= (1 << OCIE5A); //Turn on the A compare unit (ie turn on the interrupt)
@ -294,9 +294,9 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign
//This calls the relevant callback function (startCallback or endCallback) depending on the status of the schedule.
//If the startCallback function is called, we put the scheduler into RUNNING state
//Timer3A (fuel schedule 1) Compare Vector
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER3_COMPA_vect, ISR_NOBLOCK) //fuelSchedules 1 and 5
#elif defined (CORE_TEENSY)
#elif defined(PROCESSOR_TEENSY_3_x)
void timer3compareAinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -316,9 +316,9 @@ void timer3compareAinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER3_COMPB_vect, ISR_NOBLOCK) //fuelSchedule2
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer3compareBinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -337,9 +337,9 @@ void timer3compareBinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER3_COMPC_vect, ISR_NOBLOCK) //fuelSchedule3
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer3compareCinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -358,9 +358,9 @@ void timer3compareCinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER4_COMPB_vect, ISR_NOBLOCK) //fuelSchedule4
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer4compareBinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -379,9 +379,9 @@ void timer4compareBinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER5_COMPA_vect, ISR_NOBLOCK) //ignitionSchedule1
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer5compareAinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -402,9 +402,9 @@ void timer5compareAinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER5_COMPB_vect, ISR_NOBLOCK) //ignitionSchedule2
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer5compareBinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -425,9 +425,9 @@ void timer5compareBinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER5_COMPC_vect, ISR_NOBLOCK) //ignitionSchedule3
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer5compareCinterrupt() //Most ARM chips can simply call a function
#endif
{
@ -448,9 +448,9 @@ void timer5compareCinterrupt() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER4_COMPA_vect, ISR_NOBLOCK) //ignitionSchedule4
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void timer4compareAinterrupt() //Most ARM chips can simply call a function
#endif
{

View File

@ -151,7 +151,7 @@ volatile bool fpPrimed = false; //Tracks whether or not the fuel pump priming ha
void setup()
{
Serial.begin(115200);
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
#if defined(PROCESSOR_MEGA_NO61) //ATmega2561 does not have Serial3
if (configPage1.canEnable) { Serial3.begin(115200); }
#endif
@ -460,7 +460,7 @@ void setup()
currentLoopTime = micros();
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
//This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS)
//1Mhz is the fastest speed permitted by the CPU without affecting accuracy
//Please see chapter 11 of 'Practical Arduino' (http://books.google.com.au/books?id=HsTxON1L6D4C&printsec=frontcover#v=onepage&q&f=false) for more details
@ -775,7 +775,7 @@ void loop()
command();
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
#if defined(PROCESSOR_MEGA_NO61) //ATmega2561 does not have Serial3
//if Can interface is enabled then check for serial3 requests.
if (configPage1.canEnable)
{

View File

@ -24,7 +24,7 @@ volatile int loopSec;
volatile unsigned long targetOverdwellTime;
volatile unsigned long targetTachoPulseTime;
#if defined (CORE_TEENSY)
#if defined (PROCESSOR_TEENSY_3_x)
IntervalTimer lowResTimer;
#endif
void initialiseTimers();

View File

@ -16,7 +16,7 @@ Timers are typically low resolution (Compared to Schedulers), with maximum frequ
void initialiseTimers()
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
//Configure Timer2 for our low-freq interrupt code.
TCCR2B = 0x00; //Disbale Timer2 while we set it up
TCNT2 = 131; //Preload timer2 with 131 cycles, leaving 125 till overflow. As the timer runs at 125Khz, this causes overflow to occur at 1Khz = 1ms
@ -26,7 +26,7 @@ void initialiseTimers()
/* Now configure the prescaler to CPU clock divided by 128 = 125Khz */
TCCR2B |= (1<<CS22) | (1<<CS20); // Set bits
TCCR2B &= ~(1<<CS21); // Clear bit
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
//Uses the PIT timer on Teensy.
lowResTimer.begin(oneMSInterval, 1000);
#endif
@ -35,9 +35,9 @@ void initialiseTimers()
//Timer2 Overflow Interrupt Vector, called when the timer overflows.
//Executes every ~1ms.
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //AVR chips use the ISR for this
#if defined (PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
ISR(TIMER2_OVF_vect, ISR_NOBLOCK)
#elif defined (CORE_TEENSY)
#elif defined (PROCESSOR_TEENSY_3_x)
void oneMSInterval() //Most ARM chips can simply call a function
#endif
{
@ -131,7 +131,7 @@ void oneMSInterval() //Most ARM chips can simply call a function
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //AVR chips use the ISR for this
#if defined(PROCESSOR_MEGA_ALL) //AVR chips use the ISR for this
//Reset Timer2 to trigger in another ~1ms
TCNT2 = 131; //Preload timer2 with 100 cycles, leaving 156 till overflow.
TIFR2 = 0x00; //Timer2 INT Flag Reg: Clear Timer Overflow Flag

View File

@ -12,11 +12,11 @@ Returns how much free dynamic memory exists (between heap and stack)
int freeRam ()
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(PROCESSOR_MEGA_ALL)
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
#elif defined(CORE_TEENSY)
#elif defined(PROCESSOR_TEENSY_3_x)
return 0;
#endif
}