PJSC(Pump Jet Solenoid Controller)はArduinoを使用したバイク用燃料噴射コントローラです。このプロジェクトは、オープンソースECUプロジェクト『Speeduino』をベースにしています。
Speeduino Feb.2019 version.
| @@ -0,0 +1,143 @@ | ||
| 1 | +#ifndef AVR2560_H | |
| 2 | +#define AVR2560_H | |
| 3 | +#if defined(CORE_AVR) | |
| 4 | + | |
| 5 | +#include <avr/interrupt.h> | |
| 6 | +#include <avr/io.h> | |
| 7 | + | |
| 8 | +/* | |
| 9 | +*********************************************************************************************************** | |
| 10 | +* General | |
| 11 | +*/ | |
| 12 | + #define PORT_TYPE uint8_t //Size of the port variables (Eg inj1_pin_port). | |
| 13 | + void initBoard(); | |
| 14 | + uint16_t freeRam(); | |
| 15 | + | |
| 16 | + #if defined(TIMER5_MICROS) | |
| 17 | + //#define micros() (((timer5_overflow_count << 16) + TCNT5) * 4) //Fast version of micros() that uses the 4uS tick of timer5. See timers.ino for the overflow ISR of timer5 | |
| 18 | + #define millis() (ms_counter) //Replaces the standard millis() function with this macro. It is both faster and more accurate. See timers.ino for its counter increment. | |
| 19 | + static inline unsigned long micros_safe(); //A version of micros() that is interrupt safe | |
| 20 | + #else | |
| 21 | + #define micros_safe() micros() //If the timer5 method is not used, the micros_safe() macro is simply an alias for the normal micros() | |
| 22 | + #endif | |
| 23 | + | |
| 24 | + //Mega 2561 MCU does not have a serial3 available. | |
| 25 | + #if not defined(__AVR_ATmega2561__) | |
| 26 | + #define USE_SERIAL3 | |
| 27 | + #endif | |
| 28 | + | |
| 29 | +/* | |
| 30 | +*********************************************************************************************************** | |
| 31 | +* Schedules | |
| 32 | +*/ | |
| 33 | + //Refer to http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/iomxx0_1.h?root=avr-libc&view=markup | |
| 34 | + #define FUEL1_COUNTER TCNT3 | |
| 35 | + #define FUEL2_COUNTER TCNT3 | |
| 36 | + #define FUEL3_COUNTER TCNT3 | |
| 37 | + #define FUEL4_COUNTER TCNT4 | |
| 38 | + #define FUEL5_COUNTER TCNT1 | |
| 39 | + #define FUEL6_COUNTER TCNT4 //Replaces ignition 4 | |
| 40 | + #define FUEL7_COUNTER TCNT5 //Replaces ignition 3 | |
| 41 | + #define FUEL8_COUNTER TCNT5 //Replaces ignition 2 | |
| 42 | + | |
| 43 | + #define IGN1_COUNTER TCNT5 | |
| 44 | + #define IGN2_COUNTER TCNT5 | |
| 45 | + #define IGN3_COUNTER TCNT5 | |
| 46 | + #define IGN4_COUNTER TCNT4 | |
| 47 | + #define IGN5_COUNTER TCNT1 | |
| 48 | + #define IGN6_COUNTER TCNT4 //Replaces injector 4 | |
| 49 | + #define IGN7_COUNTER TCNT3 //Replaces injector 3 | |
| 50 | + #define IGN8_COUNTER TCNT3 //Replaces injector 2 | |
| 51 | + | |
| 52 | + #define FUEL1_COMPARE OCR3A | |
| 53 | + #define FUEL2_COMPARE OCR3B | |
| 54 | + #define FUEL3_COMPARE OCR3C | |
| 55 | + #define FUEL4_COMPARE OCR4B | |
| 56 | + #define FUEL5_COMPARE OCR1C //Shared with FUEL1 | |
| 57 | + #define FUEL6_COMPARE OCR4A //Replaces ignition4 | |
| 58 | + #define FUEL7_COMPARE OCR5C //Replaces ignition3 | |
| 59 | + #define FUEL8_COMPARE OCR5B //Replaces ignition2 | |
| 60 | + | |
| 61 | + #define IGN1_COMPARE OCR5A | |
| 62 | + #define IGN2_COMPARE OCR5B | |
| 63 | + #define IGN3_COMPARE OCR5C | |
| 64 | + #define IGN4_COMPARE OCR4A | |
| 65 | + #define IGN5_COMPARE OCR1C | |
| 66 | + #define IGN6_COMPARE OCR4B //Replaces injector 4 | |
| 67 | + #define IGN7_COMPARE OCR3C //Replaces injector 3 | |
| 68 | + #define IGN8_COMPARE OCR3B //Replaces injector 2 | |
| 69 | + | |
| 70 | + #define FUEL1_TIMER_ENABLE() TIMSK3 |= (1 << OCIE3A) //Turn on the A compare unit (ie turn on the interrupt) | |
| 71 | + #define FUEL2_TIMER_ENABLE() TIMSK3 |= (1 << OCIE3B) //Turn on the B compare unit (ie turn on the interrupt) | |
| 72 | + #define FUEL3_TIMER_ENABLE() TIMSK3 |= (1 << OCIE3C) //Turn on the C compare unit (ie turn on the interrupt) | |
| 73 | + #define FUEL4_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4B) //Turn on the B compare unit (ie turn on the interrupt) | |
| 74 | + #define FUEL5_TIMER_ENABLE() TIMSK1 |= (1 << OCIE1C) // | |
| 75 | + #define FUEL6_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4A) // | |
| 76 | + #define FUEL7_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5C) // | |
| 77 | + #define FUEL8_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5B) // | |
| 78 | + | |
| 79 | + #define FUEL1_TIMER_DISABLE() TIMSK3 &= ~(1 << OCIE3A); //Turn off this output compare unit | |
| 80 | + #define FUEL2_TIMER_DISABLE() TIMSK3 &= ~(1 << OCIE3B); //Turn off this output compare unit | |
| 81 | + #define FUEL3_TIMER_DISABLE() TIMSK3 &= ~(1 << OCIE3C); //Turn off this output compare unit | |
| 82 | + #define FUEL4_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4B); //Turn off this output compare unit | |
| 83 | + #define FUEL5_TIMER_DISABLE() TIMSK1 &= ~(1 << OCIE1C); // | |
| 84 | + #define FUEL6_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4A); // | |
| 85 | + #define FUEL7_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5C); // | |
| 86 | + #define FUEL8_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5B); // | |
| 87 | + | |
| 88 | + #define IGN1_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5A) //Turn on the A compare unit (ie turn on the interrupt) | |
| 89 | + #define IGN2_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5B) //Turn on the B compare unit (ie turn on the interrupt) | |
| 90 | + #define IGN3_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5C) //Turn on the C compare unit (ie turn on the interrupt) | |
| 91 | + #define IGN4_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4A) //Turn on the A compare unit (ie turn on the interrupt) | |
| 92 | + #define IGN5_TIMER_ENABLE() TIMSK1 |= (1 << OCIE1C) //Turn on the A compare unit (ie turn on the interrupt) | |
| 93 | + #define IGN6_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4B) //Replaces injector 4 | |
| 94 | + #define IGN7_TIMER_ENABLE() TIMSK3 |= (1 << OCIE3C) //Replaces injector 3 | |
| 95 | + #define IGN8_TIMER_ENABLE() TIMSK3 |= (1 << OCIE3B) //Replaces injector 2 | |
| 96 | + | |
| 97 | + #define IGN1_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5A) //Turn off this output compare unit | |
| 98 | + #define IGN2_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5B) //Turn off this output compare unit | |
| 99 | + #define IGN3_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5C) //Turn off this output compare unit | |
| 100 | + #define IGN4_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4A) //Turn off this output compare unit | |
| 101 | + #define IGN5_TIMER_DISABLE() TIMSK1 &= ~(1 << OCIE1C) //Turn off this output compare unit | |
| 102 | + #define IGN6_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4B) //Replaces injector 4 | |
| 103 | + #define IGN7_TIMER_DISABLE() TIMSK3 &= ~(1 << OCIE3C) //Replaces injector 3 | |
| 104 | + #define IGN8_TIMER_DISABLE() TIMSK3 &= ~(1 << OCIE3B) //Replaces injector 2 | |
| 105 | + | |
| 106 | + #define MAX_TIMER_PERIOD 262140UL //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 4, as each timer tick is 4uS) | |
| 107 | + #define MAX_TIMER_PERIOD_SLOW 1048560UL //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 16, as each timer tick is 16uS) | |
| 108 | + #define uS_TO_TIMER_COMPARE(uS1) (uS1 >> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed | |
| 109 | + //This is a hack until I make all the AVR timers run at the same speed | |
| 110 | + #define uS_TO_TIMER_COMPARE_SLOW(uS1) (uS1 >> 4) | |
| 111 | + | |
| 112 | +/* | |
| 113 | +*********************************************************************************************************** | |
| 114 | +* Auxilliaries | |
| 115 | +*/ | |
| 116 | + #define ENABLE_BOOST_TIMER() TIMSK1 |= (1 << OCIE1A) | |
| 117 | + #define DISABLE_BOOST_TIMER() TIMSK1 &= ~(1 << OCIE1A) | |
| 118 | + #define ENABLE_VVT_TIMER() TIMSK1 |= (1 << OCIE1B) | |
| 119 | + #define DISABLE_VVT_TIMER() TIMSK1 &= ~(1 << OCIE1B) | |
| 120 | + | |
| 121 | + #define BOOST_TIMER_COMPARE OCR1A | |
| 122 | + #define BOOST_TIMER_COUNTER TCNT1 | |
| 123 | + #define VVT_TIMER_COMPARE OCR1B | |
| 124 | + #define VVT_TIMER_COUNTER TCNT1 | |
| 125 | + | |
| 126 | +/* | |
| 127 | +*********************************************************************************************************** | |
| 128 | +* Idle | |
| 129 | +*/ | |
| 130 | + #define IDLE_COUNTER TCNT4 | |
| 131 | + #define IDLE_COMPARE OCR4C | |
| 132 | + | |
| 133 | + #define IDLE_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4C) | |
| 134 | + #define IDLE_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4C) | |
| 135 | + | |
| 136 | +/* | |
| 137 | +*********************************************************************************************************** | |
| 138 | +* CAN / Second serial | |
| 139 | +*/ | |
| 140 | + | |
| 141 | + | |
| 142 | +#endif //CORE_AVR | |
| 143 | +#endif //AVR2560_H |
| @@ -0,0 +1,295 @@ | ||
| 1 | +#ifndef STM32_H | |
| 2 | +#define STM32_H | |
| 3 | +#if defined(CORE_STM32) | |
| 4 | + | |
| 5 | +/* | |
| 6 | +*********************************************************************************************************** | |
| 7 | +* General | |
| 8 | +*/ | |
| 9 | + #define PORT_TYPE uint8_t | |
| 10 | + #define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros() | |
| 11 | + #define USE_SERIAL3 | |
| 12 | + void initBoard(); | |
| 13 | + uint16_t freeRam(); | |
| 14 | + | |
| 15 | + #if defined(USE_STM32GENERIC) | |
| 16 | + #define Serial Serial1 | |
| 17 | + #endif | |
| 18 | + | |
| 19 | + //Much of the below is not correct, but included to allow compilation | |
| 20 | + //STM32F1/variants/.../board.cpp | |
| 21 | + #if defined (STM32F4) | |
| 22 | + #define A0 PA0 | |
| 23 | + #define A1 PA1 | |
| 24 | + #define A2 PA2 | |
| 25 | + #define A3 PA3 | |
| 26 | + #define A4 PA4 | |
| 27 | + #define A5 PA5 | |
| 28 | + #define A6 PA6 | |
| 29 | + #define A7 PA7 | |
| 30 | + #define A8 PB0 | |
| 31 | + #define A9 PB1 | |
| 32 | + #define A10 PC0 | |
| 33 | + #define A11 PC1 | |
| 34 | + #define A12 PC2 | |
| 35 | + #define A13 PC3 | |
| 36 | + #define A14 PC4 | |
| 37 | + #define A15 PC5 | |
| 38 | + #else | |
| 39 | + #define A0 PB0 | |
| 40 | + #define A1 PA7 | |
| 41 | + #define A2 PA6 | |
| 42 | + #define A3 PA5 | |
| 43 | + #define A4 PA4 | |
| 44 | + #define A5 PA3 | |
| 45 | + #define A6 PA2 | |
| 46 | + #define A7 PA1 | |
| 47 | + #define A8 PA0 | |
| 48 | + //STM32F1 have only 9 12bit adc | |
| 49 | + #define A9 PB0 | |
| 50 | + #define A10 PA7 | |
| 51 | + #define A11 PA6 | |
| 52 | + #define A12 PA5 | |
| 53 | + #define A13 PA4 | |
| 54 | + #define A14 PA3 | |
| 55 | + #define A15 PA2 | |
| 56 | + #endif | |
| 57 | + | |
| 58 | + | |
| 59 | +/* | |
| 60 | +*********************************************************************************************************** | |
| 61 | +* Schedules | |
| 62 | +*/ | |
| 63 | + #define MAX_TIMER_PERIOD 131070 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) | |
| 64 | + #define MAX_TIMER_PERIOD_SLOW 131070 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) | |
| 65 | + #define uS_TO_TIMER_COMPARE(uS) (uS >> 1) //Converts a given number of uS into the required number of timer ticks until that time has passed. | |
| 66 | + #define uS_TO_TIMER_COMPARE_SLOW(uS) (uS >> 1) //Converts a given number of uS into the required number of timer ticks until that time has passed. | |
| 67 | + #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core | |
| 68 | + #define FUEL1_COUNTER (TIM2)->CNT | |
| 69 | + #define FUEL2_COUNTER (TIM2)->CNT | |
| 70 | + #define FUEL3_COUNTER (TIM2)->CNT | |
| 71 | + #define FUEL4_COUNTER (TIM2)->CNT | |
| 72 | + | |
| 73 | + #define FUEL1_COMPARE (TIM2)->CCR1 | |
| 74 | + #define FUEL2_COMPARE (TIM2)->CCR2 | |
| 75 | + #define FUEL3_COMPARE (TIM2)->CCR3 | |
| 76 | + #define FUEL4_COMPARE (TIM2)->CCR4 | |
| 77 | + | |
| 78 | + #define IGN1_COUNTER (TIM3)->CNT | |
| 79 | + #define IGN2_COUNTER (TIM3)->CNT | |
| 80 | + #define IGN3_COUNTER (TIM3)->CNT | |
| 81 | + #define IGN4_COUNTER (TIM3)->CNT | |
| 82 | + | |
| 83 | + #define IGN1_COMPARE (TIM3)->CCR1 | |
| 84 | + #define IGN2_COMPARE (TIM3)->CCR2 | |
| 85 | + #define IGN3_COMPARE (TIM3)->CCR3 | |
| 86 | + #define IGN4_COMPARE (TIM3)->CCR4 | |
| 87 | + | |
| 88 | + #ifndef SMALL_FLASH_MODE | |
| 89 | + #define FUEL5_COUNTER (TIM5)->CNT | |
| 90 | + #define FUEL6_COUNTER (TIM5)->CNT | |
| 91 | + #define FUEL7_COUNTER (TIM5)->CNT | |
| 92 | + #define FUEL8_COUNTER (TIM5)->CNT | |
| 93 | + | |
| 94 | + #define FUEL5_COMPARE (TIM5)->CCR1 | |
| 95 | + #define FUEL6_COMPARE (TIM5)->CCR2 | |
| 96 | + #define FUEL7_COMPARE (TIM5)->CCR3 | |
| 97 | + #define FUEL8_COMPARE (TIM5)->CCR4 | |
| 98 | + | |
| 99 | + #define IGN5_COUNTER (TIM4)->CNT | |
| 100 | + #define IGN6_COUNTER (TIM4)->CNT | |
| 101 | + #define IGN7_COUNTER (TIM4)->CNT | |
| 102 | + #define IGN8_COUNTER (TIM4)->CNT | |
| 103 | + | |
| 104 | + #define IGN5_COMPARE (TIM4)->CCR1 | |
| 105 | + #define IGN6_COMPARE (TIM4)->CCR2 | |
| 106 | + #define IGN7_COMPARE (TIM4)->CCR3 | |
| 107 | + #define IGN8_COMPARE (TIM4)->CCR4 | |
| 108 | + #endif | |
| 109 | + //https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444 | |
| 110 | + #define FUEL1_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC1E | |
| 111 | + #define FUEL2_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC2E | |
| 112 | + #define FUEL3_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC3E | |
| 113 | + #define FUEL4_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC4E | |
| 114 | + | |
| 115 | + #define FUEL1_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC1E | |
| 116 | + #define FUEL2_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC2E | |
| 117 | + #define FUEL3_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC3E | |
| 118 | + #define FUEL4_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC4E | |
| 119 | + | |
| 120 | + #define IGN1_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC1E | |
| 121 | + #define IGN2_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC2E | |
| 122 | + #define IGN3_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC3E | |
| 123 | + #define IGN4_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC4E | |
| 124 | + | |
| 125 | + #define IGN1_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC1E | |
| 126 | + #define IGN2_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC2E | |
| 127 | + #define IGN3_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC3E | |
| 128 | + #define IGN4_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC4E | |
| 129 | + | |
| 130 | + #ifndef SMALL_FLASH_MODE | |
| 131 | + #define FUEL5_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC1E | |
| 132 | + #define FUEL6_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC2E | |
| 133 | + #define FUEL7_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC3E | |
| 134 | + #define FUEL8_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC4E | |
| 135 | + | |
| 136 | + #define FUEL5_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC1E | |
| 137 | + #define FUEL6_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC2E | |
| 138 | + #define FUEL7_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC3E | |
| 139 | + #define FUEL8_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC4E | |
| 140 | + | |
| 141 | + #define IGN5_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC1E | |
| 142 | + #define IGN6_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC2E | |
| 143 | + #define IGN7_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC3E | |
| 144 | + #define IGN8_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC4E | |
| 145 | + | |
| 146 | + #define IGN5_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC1E | |
| 147 | + #define IGN6_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC2E | |
| 148 | + #define IGN7_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC3E | |
| 149 | + #define IGN8_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC4E | |
| 150 | + #endif | |
| 151 | + #else //libmaple core aka STM32DUINO | |
| 152 | + #define FUEL1_COUNTER (TIMER2->regs).gen->CNT | |
| 153 | + #define FUEL2_COUNTER (TIMER2->regs).gen->CNT | |
| 154 | + #define FUEL3_COUNTER (TIMER2->regs).gen->CNT | |
| 155 | + #define FUEL4_COUNTER (TIMER2->regs).gen->CNT | |
| 156 | + | |
| 157 | + #define FUEL1_COMPARE (TIMER2->regs).gen->CCR1 | |
| 158 | + #define FUEL2_COMPARE (TIMER2->regs).gen->CCR2 | |
| 159 | + #define FUEL3_COMPARE (TIMER2->regs).gen->CCR3 | |
| 160 | + #define FUEL4_COMPARE (TIMER2->regs).gen->CCR4 | |
| 161 | + | |
| 162 | + #define IGN1_COUNTER (TIMER3->regs).gen->CNT | |
| 163 | + #define IGN2_COUNTER (TIMER3->regs).gen->CNT | |
| 164 | + #define IGN3_COUNTER (TIMER3->regs).gen->CNT | |
| 165 | + #define IGN4_COUNTER (TIMER3->regs).gen->CNT | |
| 166 | + | |
| 167 | + #define IGN1_COMPARE (TIMER3->regs).gen->CCR1 | |
| 168 | + #define IGN2_COMPARE (TIMER3->regs).gen->CCR2 | |
| 169 | + #define IGN3_COMPARE (TIMER3->regs).gen->CCR3 | |
| 170 | + #define IGN4_COMPARE (TIMER3->regs).gen->CCR4 | |
| 171 | + | |
| 172 | + #ifndef SMALL_FLASH_MODE | |
| 173 | + #define FUEL5_COUNTER (TIMER5->regs).gen->CNT | |
| 174 | + #define FUEL6_COUNTER (TIMER5->regs).gen->CNT | |
| 175 | + #define FUEL7_COUNTER (TIMER5->regs).gen->CNT | |
| 176 | + #define FUEL8_COUNTER (TIMER5->regs).gen->CNT | |
| 177 | + | |
| 178 | + #define FUEL5_COMPARE (TIMER5->regs).gen->CCR1 | |
| 179 | + #define FUEL6_COMPARE (TIMER5->regs).gen->CCR2 | |
| 180 | + #define FUEL7_COMPARE (TIMER5->regs).gen->CCR3 | |
| 181 | + #define FUEL8_COMPARE (TIMER5->regs).gen->CCR4 | |
| 182 | + | |
| 183 | + #define IGN5_COUNTER (TIMER4->regs).gen->CNT | |
| 184 | + #define IGN6_COUNTER (TIMER4->regs).gen->CNT | |
| 185 | + #define IGN7_COUNTER (TIMER4->regs).gen->CNT | |
| 186 | + #define IGN8_COUNTER (TIMER4->regs).gen->CNT | |
| 187 | + | |
| 188 | + #define IGN5_COMPARE (TIMER4->regs).gen->CCR1 | |
| 189 | + #define IGN6_COMPARE (TIMER4->regs).gen->CCR2 | |
| 190 | + #define IGN7_COMPARE (TIMER4->regs).gen->CCR3 | |
| 191 | + #define IGN8_COMPARE (TIMER4->regs).gen->CCR4 | |
| 192 | + #endif | |
| 193 | + //https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444 | |
| 194 | + #define FUEL1_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC1E | |
| 195 | + #define FUEL2_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC2E | |
| 196 | + #define FUEL3_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC3E | |
| 197 | + #define FUEL4_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC4E | |
| 198 | + | |
| 199 | + #define FUEL1_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC1E | |
| 200 | + #define FUEL2_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC2E | |
| 201 | + #define FUEL3_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC3E | |
| 202 | + #define FUEL4_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC4E | |
| 203 | + | |
| 204 | + #define IGN1_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC1E | |
| 205 | + #define IGN2_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC2E | |
| 206 | + #define IGN3_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC3E | |
| 207 | + #define IGN4_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC4E | |
| 208 | + | |
| 209 | + #define IGN1_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC1E | |
| 210 | + #define IGN2_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC2E | |
| 211 | + #define IGN3_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC3E | |
| 212 | + #define IGN4_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC4E | |
| 213 | + | |
| 214 | + #ifndef SMALL_FLASH_MODE | |
| 215 | + #define FUEL5_TIMER_ENABLE() (TIMER5->regs).gen->CCER |= TIMER_CCER_CC1E | |
| 216 | + #define FUEL6_TIMER_ENABLE() (TIMER5->regs).gen->CCER |= TIMER_CCER_CC2E | |
| 217 | + #define FUEL7_TIMER_ENABLE() (TIMER5->regs).gen->CCER |= TIMER_CCER_CC3E | |
| 218 | + #define FUEL8_TIMER_ENABLE() (TIMER5->regs).gen->CCER |= TIMER_CCER_CC4E | |
| 219 | + | |
| 220 | + #define IGN5_TIMER_ENABLE() (TIMER4->regs).gen->CCER |= TIMER_CCER_CC1E | |
| 221 | + #define IGN6_TIMER_ENABLE() (TIMER4->regs).gen->CCER |= TIMER_CCER_CC2E | |
| 222 | + #define IGN7_TIMER_ENABLE() (TIMER4->regs).gen->CCER |= TIMER_CCER_CC3E | |
| 223 | + #define IGN8_TIMER_ENABLE() (TIMER4->regs).gen->CCER |= TIMER_CCER_CC4E | |
| 224 | + | |
| 225 | + #define FUEL5_TIMER_DISABLE() (TIMER5->regs).gen->CCER &= ~TIMER_CCER_CC1E | |
| 226 | + #define FUEL6_TIMER_DISABLE() (TIMER5->regs).gen->CCER &= ~TIMER_CCER_CC2E | |
| 227 | + #define FUEL7_TIMER_DISABLE() (TIMER5->regs).gen->CCER &= ~TIMER_CCER_CC3E | |
| 228 | + #define FUEL8_TIMER_DISABLE() (TIMER5->regs).gen->CCER &= ~TIMER_CCER_CC4E | |
| 229 | + | |
| 230 | + #define IGN5_TIMER_DISABLE() (TIMER4->regs).gen->CCER &= ~TIMER_CCER_CC1E | |
| 231 | + #define IGN6_TIMER_DISABLE() (TIMER4->regs).gen->CCER &= ~TIMER_CCER_CC2E | |
| 232 | + #define IGN7_TIMER_DISABLE() (TIMER4->regs).gen->CCER &= ~TIMER_CCER_CC3E | |
| 233 | + #define IGN8_TIMER_DISABLE() (TIMER4->regs).gen->CCER &= ~TIMER_CCER_CC4E | |
| 234 | + #endif | |
| 235 | +#endif | |
| 236 | + | |
| 237 | +/* | |
| 238 | +*********************************************************************************************************** | |
| 239 | +* Auxilliaries | |
| 240 | +*/ | |
| 241 | + #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core | |
| 242 | + #define ENABLE_BOOST_TIMER() (TIM1)->CCER |= TIM_CCER_CC2E | |
| 243 | + #define DISABLE_BOOST_TIMER() (TIM1)->CCER &= ~TIM_CCER_CC2E | |
| 244 | + | |
| 245 | + #define ENABLE_VVT_TIMER() (TIM1)->CCER |= TIM_CCER_CC3E | |
| 246 | + #define DISABLE_VVT_TIMER() (TIM1)->CCER &= ~TIM_CCER_CC3E | |
| 247 | + | |
| 248 | + #define BOOST_TIMER_COMPARE (TIM1)->CCR2 | |
| 249 | + #define BOOST_TIMER_COUNTER (TIM1)->CNT | |
| 250 | + #define VVT_TIMER_COMPARE (TIM1)->CCR3 | |
| 251 | + #define VVT_TIMER_COUNTER (TIM1)->CNT | |
| 252 | + #else //libmaple core aka STM32DUINO | |
| 253 | + #define ENABLE_BOOST_TIMER() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC2E | |
| 254 | + #define DISABLE_BOOST_TIMER() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC2E | |
| 255 | + | |
| 256 | + #define ENABLE_VVT_TIMER() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC3E | |
| 257 | + #define DISABLE_VVT_TIMER() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC3E | |
| 258 | + | |
| 259 | + #define BOOST_TIMER_COMPARE (TIMER1->regs).gen->CCR2 | |
| 260 | + #define BOOST_TIMER_COUNTER (TIMER1->regs).gen->CNT | |
| 261 | + #define VVT_TIMER_COMPARE (TIMER1->regs).gen->CCR3 | |
| 262 | + #define VVT_TIMER_COUNTER (TIMER1->regs).gen->CNT | |
| 263 | + #endif | |
| 264 | + | |
| 265 | +/* | |
| 266 | +*********************************************************************************************************** | |
| 267 | +* Idle | |
| 268 | +*/ | |
| 269 | + #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core | |
| 270 | + #define IDLE_COUNTER (TIM1)->CNT | |
| 271 | + #define IDLE_COMPARE (TIM1)->CCR4 | |
| 272 | + | |
| 273 | + #define IDLE_TIMER_ENABLE() (TIM1)->CCER |= TIM_CCER_CC4E | |
| 274 | + #define IDLE_TIMER_DISABLE() (TIM1)->CCER &= ~TIM_CCER_CC4E | |
| 275 | + #else //libmaple core aka STM32DUINO | |
| 276 | + #define IDLE_COUNTER (TIMER1->regs).gen->CNT | |
| 277 | + #define IDLE_COMPARE (TIMER1->regs).gen->CCR4 | |
| 278 | + | |
| 279 | + #define IDLE_TIMER_ENABLE() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC4E | |
| 280 | + #define IDLE_TIMER_DISABLE() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC4E | |
| 281 | + #endif | |
| 282 | + | |
| 283 | +/* | |
| 284 | +*********************************************************************************************************** | |
| 285 | +* Timers | |
| 286 | +*/ | |
| 287 | + | |
| 288 | + | |
| 289 | +/* | |
| 290 | +*********************************************************************************************************** | |
| 291 | +* CAN / Second serial | |
| 292 | +*/ | |
| 293 | + | |
| 294 | +#endif //CORE_STM32 | |
| 295 | +#endif //STM32_H | |
| \ No newline at end of file |
| @@ -0,0 +1,138 @@ | ||
| 1 | +#ifndef TEENSY35_H | |
| 2 | +#define TEENSY35_H | |
| 3 | +#if defined(CORE_TEENSY) | |
| 4 | + | |
| 5 | +/* | |
| 6 | +*********************************************************************************************************** | |
| 7 | +* General | |
| 8 | +*/ | |
| 9 | + void initBoard(); | |
| 10 | + uint16_t freeRam(); | |
| 11 | + #define PORT_TYPE uint8_t //Size of the port variables | |
| 12 | + #define BOARD_DIGITAL_GPIO_PINS 34 | |
| 13 | + #define BOARD_NR_GPIO_PINS 34 | |
| 14 | + #define USE_SERIAL3 | |
| 15 | + | |
| 16 | + #define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros() | |
| 17 | + | |
| 18 | +/* | |
| 19 | +*********************************************************************************************************** | |
| 20 | +* Schedules | |
| 21 | +*/ | |
| 22 | + //http://shawnhymel.com/661/learning-the-teensy-lc-interrupt-service-routines/ | |
| 23 | + #define FUEL1_COUNTER FTM0_CNT | |
| 24 | + #define FUEL2_COUNTER FTM0_CNT | |
| 25 | + #define FUEL3_COUNTER FTM0_CNT | |
| 26 | + #define FUEL4_COUNTER FTM0_CNT | |
| 27 | + #define FUEL5_COUNTER FTM3_CNT | |
| 28 | + #define FUEL6_COUNTER FTM3_CNT | |
| 29 | + #define FUEL7_COUNTER FTM3_CNT | |
| 30 | + #define FUEL8_COUNTER FTM3_CNT | |
| 31 | + | |
| 32 | + #define IGN1_COUNTER FTM0_CNT | |
| 33 | + #define IGN2_COUNTER FTM0_CNT | |
| 34 | + #define IGN3_COUNTER FTM0_CNT | |
| 35 | + #define IGN4_COUNTER FTM0_CNT | |
| 36 | + #define IGN5_COUNTER FTM3_CNT | |
| 37 | + #define IGN6_COUNTER FTM3_CNT | |
| 38 | + #define IGN7_COUNTER FTM3_CNT | |
| 39 | + #define IGN8_COUNTER FTM3_CNT | |
| 40 | + | |
| 41 | + #define FUEL1_COMPARE FTM0_C0V | |
| 42 | + #define FUEL2_COMPARE FTM0_C1V | |
| 43 | + #define FUEL3_COMPARE FTM0_C2V | |
| 44 | + #define FUEL4_COMPARE FTM0_C3V | |
| 45 | + #define FUEL5_COMPARE FTM3_C0V | |
| 46 | + #define FUEL6_COMPARE FTM3_C1V | |
| 47 | + #define FUEL7_COMPARE FTM3_C2V | |
| 48 | + #define FUEL8_COMPARE FTM3_C3V | |
| 49 | + | |
| 50 | + #define IGN1_COMPARE FTM0_C4V | |
| 51 | + #define IGN2_COMPARE FTM0_C5V | |
| 52 | + #define IGN3_COMPARE FTM0_C6V | |
| 53 | + #define IGN4_COMPARE FTM0_C7V | |
| 54 | + #define IGN5_COMPARE FTM3_C4V | |
| 55 | + #define IGN6_COMPARE FTM3_C5V | |
| 56 | + #define IGN7_COMPARE FTM3_C6V | |
| 57 | + #define IGN8_COMPARE FTM3_C7V | |
| 58 | + | |
| 59 | + #define FUEL1_TIMER_ENABLE() FTM0_C0SC |= FTM_CSC_CHIE //Write 1 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control | |
| 60 | + #define FUEL2_TIMER_ENABLE() FTM0_C1SC |= FTM_CSC_CHIE | |
| 61 | + #define FUEL3_TIMER_ENABLE() FTM0_C2SC |= FTM_CSC_CHIE | |
| 62 | + #define FUEL4_TIMER_ENABLE() FTM0_C3SC |= FTM_CSC_CHIE | |
| 63 | + #define FUEL5_TIMER_ENABLE() FTM3_C0SC |= FTM_CSC_CHIE | |
| 64 | + #define FUEL6_TIMER_ENABLE() FTM3_C1SC |= FTM_CSC_CHIE | |
| 65 | + #define FUEL7_TIMER_ENABLE() FTM3_C2SC |= FTM_CSC_CHIE | |
| 66 | + #define FUEL8_TIMER_ENABLE() FTM3_C3SC |= FTM_CSC_CHIE | |
| 67 | + | |
| 68 | + #define FUEL1_TIMER_DISABLE() FTM0_C0SC &= ~FTM_CSC_CHIE //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control | |
| 69 | + #define FUEL2_TIMER_DISABLE() FTM0_C1SC &= ~FTM_CSC_CHIE | |
| 70 | + #define FUEL3_TIMER_DISABLE() FTM0_C2SC &= ~FTM_CSC_CHIE | |
| 71 | + #define FUEL4_TIMER_DISABLE() FTM0_C3SC &= ~FTM_CSC_CHIE | |
| 72 | + #define FUEL5_TIMER_DISABLE() FTM3_C0SC &= ~FTM_CSC_CHIE //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control | |
| 73 | + #define FUEL6_TIMER_DISABLE() FTM3_C1SC &= ~FTM_CSC_CHIE | |
| 74 | + #define FUEL7_TIMER_DISABLE() FTM3_C2SC &= ~FTM_CSC_CHIE | |
| 75 | + #define FUEL8_TIMER_DISABLE() FTM3_C3SC &= ~FTM_CSC_CHIE | |
| 76 | + | |
| 77 | + #define IGN1_TIMER_ENABLE() FTM0_C4SC |= FTM_CSC_CHIE | |
| 78 | + #define IGN2_TIMER_ENABLE() FTM0_C5SC |= FTM_CSC_CHIE | |
| 79 | + #define IGN3_TIMER_ENABLE() FTM0_C6SC |= FTM_CSC_CHIE | |
| 80 | + #define IGN4_TIMER_ENABLE() FTM0_C7SC |= FTM_CSC_CHIE | |
| 81 | + #define IGN5_TIMER_ENABLE() FTM3_C4SC |= FTM_CSC_CHIE | |
| 82 | + #define IGN6_TIMER_ENABLE() FTM3_C5SC |= FTM_CSC_CHIE | |
| 83 | + #define IGN7_TIMER_ENABLE() FTM3_C6SC |= FTM_CSC_CHIE | |
| 84 | + #define IGN8_TIMER_ENABLE() FTM3_C7SC |= FTM_CSC_CHIE | |
| 85 | + | |
| 86 | + #define IGN1_TIMER_DISABLE() FTM0_C4SC &= ~FTM_CSC_CHIE | |
| 87 | + #define IGN2_TIMER_DISABLE() FTM0_C5SC &= ~FTM_CSC_CHIE | |
| 88 | + #define IGN3_TIMER_DISABLE() FTM0_C6SC &= ~FTM_CSC_CHIE | |
| 89 | + #define IGN4_TIMER_DISABLE() FTM0_C7SC &= ~FTM_CSC_CHIE | |
| 90 | + #define IGN5_TIMER_DISABLE() FTM3_C4SC &= ~FTM_CSC_CHIE | |
| 91 | + #define IGN6_TIMER_DISABLE() FTM3_C5SC &= ~FTM_CSC_CHIE | |
| 92 | + #define IGN7_TIMER_DISABLE() FTM3_C6SC &= ~FTM_CSC_CHIE | |
| 93 | + #define IGN8_TIMER_DISABLE() FTM3_C7SC &= ~FTM_CSC_CHIE | |
| 94 | + | |
| 95 | + #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535 | |
| 96 | + #define MAX_TIMER_PERIOD_SLOW 139808 | |
| 97 | + #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. | |
| 98 | + //Hack compatibility with AVR timers that run at different speeds | |
| 99 | + #define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5) | |
| 100 | + | |
| 101 | +/* | |
| 102 | +*********************************************************************************************************** | |
| 103 | +* Auxilliaries | |
| 104 | +*/ | |
| 105 | + #define ENABLE_BOOST_TIMER() FTM1_C0SC |= FTM_CSC_CHIE | |
| 106 | + #define DISABLE_BOOST_TIMER() FTM1_C0SC &= ~FTM_CSC_CHIE | |
| 107 | + | |
| 108 | + #define ENABLE_VVT_TIMER() FTM1_C1SC |= FTM_CSC_CHIE | |
| 109 | + #define DISABLE_VVT_TIMER() FTM1_C1SC &= ~FTM_CSC_CHIE | |
| 110 | + | |
| 111 | + #define BOOST_TIMER_COMPARE FTM1_C0V | |
| 112 | + #define BOOST_TIMER_COUNTER FTM1_CNT | |
| 113 | + #define VVT_TIMER_COMPARE FTM1_C1V | |
| 114 | + #define VVT_TIMER_COUNTER FTM1_CNT | |
| 115 | + | |
| 116 | + static inline void boostInterrupt(); | |
| 117 | + static inline void vvtInterrupt(); | |
| 118 | + | |
| 119 | +/* | |
| 120 | +*********************************************************************************************************** | |
| 121 | +* Idle | |
| 122 | +*/ | |
| 123 | + #define IDLE_COUNTER FTM2_CNT | |
| 124 | + #define IDLE_COMPARE FTM2_C0V | |
| 125 | + | |
| 126 | + #define IDLE_TIMER_ENABLE() FTM2_C0SC |= FTM_CSC_CHIE | |
| 127 | + #define IDLE_TIMER_DISABLE() FTM2_C0SC &= ~FTM_CSC_CHIE | |
| 128 | + | |
| 129 | + static inline void idleInterrupt(); | |
| 130 | + | |
| 131 | +/* | |
| 132 | +*********************************************************************************************************** | |
| 133 | +* CAN / Second serial | |
| 134 | +*/ | |
| 135 | + //Uart CANSerial (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0); | |
| 136 | + | |
| 137 | +#endif //CORE_TEENSY | |
| 138 | +#endif //TEENSY35_H | |
| \ No newline at end of file |
| @@ -0,0 +1,142 @@ | ||
| 1 | +#ifndef TEMPLATE_H | |
| 2 | +#define TEMPLATE_H | |
| 3 | +#if defined(CORE_TEMPLATE) | |
| 4 | + | |
| 5 | +/* | |
| 6 | +*********************************************************************************************************** | |
| 7 | +* General | |
| 8 | +*/ | |
| 9 | + #define PORT_TYPE uint32_t //Size of the port variables (Eg inj1_pin_port). Most systems use a byte, but SAMD21 and possibly others are a 32-bit unsigned int | |
| 10 | + #define BOARD_NR_GPIO_PINS 52 //Not sure this is correct | |
| 11 | + #define BOARD_DIGITAL_GPIO_PINS 52 //Pretty sure this isn't right | |
| 12 | + #define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros() | |
| 13 | + void initBoard(); | |
| 14 | + uint16_t freeRam(); | |
| 15 | + | |
| 16 | + | |
| 17 | +/* | |
| 18 | +*********************************************************************************************************** | |
| 19 | +* Schedules | |
| 20 | +*/ | |
| 21 | + | |
| 22 | + #define FUEL1_COUNTER <register here> | |
| 23 | + #define FUEL2_COUNTER <register here> | |
| 24 | + #define FUEL3_COUNTER <register here> | |
| 25 | + #define FUEL4_COUNTER <register here> | |
| 26 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 27 | + #define FUEL5_COUNTER <register here> | |
| 28 | + #define FUEL6_COUNTER <register here> | |
| 29 | + #define FUEL7_COUNTER <register here> | |
| 30 | + #define FUEL8_COUNTER <register here> | |
| 31 | + | |
| 32 | + #define IGN1_COUNTER <register here> | |
| 33 | + #define IGN2_COUNTER <register here> | |
| 34 | + #define IGN3_COUNTER <register here> | |
| 35 | + #define IGN4_COUNTER <register here> | |
| 36 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 37 | + #define IGN5_COUNTER <register here> | |
| 38 | + #define IGN6_COUNTER <register here> | |
| 39 | + #define IGN7_COUNTER <register here> | |
| 40 | + #define IGN8_COUNTER <register here> | |
| 41 | + | |
| 42 | + #define FUEL1_COMPARE <register here> | |
| 43 | + #define FUEL2_COMPARE <register here> | |
| 44 | + #define FUEL3_COMPARE <register here> | |
| 45 | + #define FUEL4_COMPARE <register here> | |
| 46 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 47 | + #define FUEL5_COMPARE <register here> | |
| 48 | + #define FUEL6_COMPARE <register here> | |
| 49 | + #define FUEL7_COMPARE <register here> | |
| 50 | + #define FUEL8_COMPARE <register here> | |
| 51 | + | |
| 52 | + #define IGN1_COMPARE <register here> | |
| 53 | + #define IGN2_COMPARE <register here> | |
| 54 | + #define IGN3_COMPARE <register here> | |
| 55 | + #define IGN4_COMPARE <register here> | |
| 56 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 57 | + #define IGN5_COMPARE <register here> | |
| 58 | + #define IGN6_COMPARE <register here> | |
| 59 | + #define IGN7_COMPARE <register here> | |
| 60 | + #define IGN8_COMPARE <register here> | |
| 61 | + | |
| 62 | + #define FUEL1_TIMER_ENABLE() <macro here> | |
| 63 | + #define FUEL2_TIMER_ENABLE() <macro here> | |
| 64 | + #define FUEL3_TIMER_ENABLE() <macro here> | |
| 65 | + #define FUEL4_TIMER_ENABLE() <macro here> | |
| 66 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 67 | + #define FUEL5_TIMER_ENABLE() <macro here> | |
| 68 | + #define FUEL6_TIMER_ENABLE() <macro here> | |
| 69 | + #define FUEL7_TIMER_ENABLE() <macro here> | |
| 70 | + #define FUEL8_TIMER_ENABLE() <macro here> | |
| 71 | + | |
| 72 | + #define FUEL1_TIMER_DISABLE() <macro here> | |
| 73 | + #define FUEL2_TIMER_DISABLE() <macro here> | |
| 74 | + #define FUEL3_TIMER_DISABLE() <macro here> | |
| 75 | + #define FUEL4_TIMER_DISABLE() <macro here> | |
| 76 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 77 | + #define FUEL5_TIMER_DISABLE() <macro here> | |
| 78 | + #define FUEL6_TIMER_DISABLE() <macro here> | |
| 79 | + #define FUEL7_TIMER_DISABLE() <macro here> | |
| 80 | + #define FUEL8_TIMER_DISABLE() <macro here> | |
| 81 | + | |
| 82 | + #define IGN1_TIMER_ENABLE() <macro here> | |
| 83 | + #define IGN2_TIMER_ENABLE() <macro here> | |
| 84 | + #define IGN3_TIMER_ENABLE() <macro here> | |
| 85 | + #define IGN4_TIMER_ENABLE() <macro here> | |
| 86 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 87 | + #define IGN5_TIMER_ENABLE() <macro here> | |
| 88 | + #define IGN6_TIMER_ENABLE() <macro here> | |
| 89 | + #define IGN7_TIMER_ENABLE() <macro here> | |
| 90 | + #define IGN8_TIMER_ENABLE() <macro here> | |
| 91 | + | |
| 92 | + #define IGN1_TIMER_DISABLE() <macro here> | |
| 93 | + #define IGN2_TIMER_DISABLE() <macro here> | |
| 94 | + #define IGN3_TIMER_DISABLE() <macro here> | |
| 95 | + #define IGN4_TIMER_DISABLE() <macro here> | |
| 96 | + //The below are optional, but recommended if there are sufficient timers/compares | |
| 97 | + #define IGN5_TIMER_DISABLE() <macro here> | |
| 98 | + #define IGN6_TIMER_DISABLE() <macro here> | |
| 99 | + #define IGN7_TIMER_DISABLE() <macro here> | |
| 100 | + #define IGN8_TIMER_DISABLE() <macro here> | |
| 101 | + | |
| 102 | + | |
| 103 | + #define MAX_TIMER_PERIOD 139808 //This is the maximum time, in uS, that the compare channels can run before overflowing. It is typically 65535 * <how long each tick represents> | |
| 104 | + #define MAX_TIMER_PERIOD_SLOW 139808 //If there is a second timer speed used, this is the same as above for that | |
| 105 | + #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. | |
| 106 | + #define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5) //As above, but for the alternative slow timer if required | |
| 107 | + | |
| 108 | +/* | |
| 109 | +*********************************************************************************************************** | |
| 110 | +* Auxilliaries | |
| 111 | +*/ | |
| 112 | + //macro functions for enabling and disabling timer interrupts for the boost and vvt functions | |
| 113 | + #define ENABLE_BOOST_TIMER() <macro here> | |
| 114 | + #define DISABLE_BOOST_TIMER() <macro here> | |
| 115 | + | |
| 116 | + #define ENABLE_VVT_TIMER() <macro here> | |
| 117 | + #define DISABLE_VVT_TIMER() <macro here> | |
| 118 | + | |
| 119 | + #define BOOST_TIMER_COMPARE <register here> | |
| 120 | + #define BOOST_TIMER_COUNTER <register here> | |
| 121 | + #define VVT_TIMER_COMPARE <register here> | |
| 122 | + #define VVT_TIMER_COUNTER <register here> | |
| 123 | + | |
| 124 | +/* | |
| 125 | +*********************************************************************************************************** | |
| 126 | +* Idle | |
| 127 | +*/ | |
| 128 | + //Same as above, but for the timer controlling PWM idle | |
| 129 | + #define IDLE_COUNTER <register here> | |
| 130 | + #define IDLE_COMPARE <register here> | |
| 131 | + | |
| 132 | + #define IDLE_TIMER_ENABLE() <macro here> | |
| 133 | + #define IDLE_TIMER_DISABLE() <macro here> | |
| 134 | + | |
| 135 | +/* | |
| 136 | +*********************************************************************************************************** | |
| 137 | +* CAN / Second serial | |
| 138 | +*/ | |
| 139 | + | |
| 140 | + | |
| 141 | +#endif //CORE_TEMPLATE | |
| 142 | +#endif //TEMPLATE_H | |
| \ No newline at end of file |
| @@ -0,0 +1,8 @@ | ||
| 1 | +#ifndef INIT_H | |
| 2 | +#define INIT_H | |
| 3 | + | |
| 4 | +void initialiseAll(); | |
| 5 | +void initialiseTriggers(); | |
| 6 | +void setPinMapping(byte); | |
| 7 | + | |
| 8 | +#endif | |
| \ No newline at end of file |
| @@ -0,0 +1,76 @@ | ||
| 1 | +/* | |
| 2 | + EEPROM like API that uses Arduino Zero's flash memory. | |
| 3 | + Written by A. Christian | |
| 4 | + | |
| 5 | + Copyright (c) 2015-2016 Arduino LLC. All right reserved. | |
| 6 | + | |
| 7 | + This library is free software; you can redistribute it and/or | |
| 8 | + modify it under the terms of the GNU Lesser General Public | |
| 9 | + License as published by the Free Software Foundation; either | |
| 10 | + version 2.1 of the License, or (at your option) any later version. | |
| 11 | + | |
| 12 | + This library is distributed in the hope that it will be useful, | |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 15 | + See the GNU Lesser General Public License for more details. | |
| 16 | + | |
| 17 | + You should have received a copy of the GNU Lesser General Public | |
| 18 | + License along with this library; if not, write to the Free Software | |
| 19 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | +*/ | |
| 21 | +#if defined(__SAMD21G18A__) | |
| 22 | +#include "FlashAsEEPROM.h" | |
| 23 | + | |
| 24 | +FlashStorage(eeprom_storage, EEPROM_EMULATION); | |
| 25 | + | |
| 26 | +EEPROMClass::EEPROMClass(void) : _initialized(false), _dirty(false) { | |
| 27 | + // Empty | |
| 28 | +} | |
| 29 | + | |
| 30 | +uint8_t EEPROMClass::read(int address) | |
| 31 | +{ | |
| 32 | + if (!_initialized) init(); | |
| 33 | + return _eeprom.data[address]; | |
| 34 | +} | |
| 35 | + | |
| 36 | +void EEPROMClass::update(int address, uint8_t value) | |
| 37 | +{ | |
| 38 | + if (!_initialized) init(); | |
| 39 | + if (_eeprom.data[address] != value) { | |
| 40 | + _dirty = true; | |
| 41 | + _eeprom.data[address] = value; | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +void EEPROMClass::write(int address, uint8_t value) | |
| 46 | +{ | |
| 47 | + update(address, value); | |
| 48 | +} | |
| 49 | + | |
| 50 | +void EEPROMClass::init() | |
| 51 | +{ | |
| 52 | + _eeprom = eeprom_storage.read(); | |
| 53 | + if (!_eeprom.valid) { | |
| 54 | + memset(_eeprom.data, 0xFF, EEPROM_EMULATION_SIZE); | |
| 55 | + } | |
| 56 | + _initialized = true; | |
| 57 | +} | |
| 58 | + | |
| 59 | +bool EEPROMClass::isValid() | |
| 60 | +{ | |
| 61 | + if (!_initialized) init(); | |
| 62 | + return _eeprom.valid; | |
| 63 | +} | |
| 64 | + | |
| 65 | +void EEPROMClass::commit() | |
| 66 | +{ | |
| 67 | + if (!_initialized) init(); | |
| 68 | + if (_dirty) { | |
| 69 | + _eeprom.valid = true; | |
| 70 | + eeprom_storage.write(_eeprom); | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +EEPROMClass EEPROM; | |
| 75 | + | |
| 76 | +#endif | |
| \ No newline at end of file |
| @@ -0,0 +1,87 @@ | ||
| 1 | +/* | |
| 2 | + EEPROM like API that uses Arduino Zero's flash memory. | |
| 3 | + Written by A. Christian | |
| 4 | + | |
| 5 | + Copyright (c) 2015-2016 Arduino LLC. All right reserved. | |
| 6 | + | |
| 7 | + This library is free software; you can redistribute it and/or | |
| 8 | + modify it under the terms of the GNU Lesser General Public | |
| 9 | + License as published by the Free Software Foundation; either | |
| 10 | + version 2.1 of the License, or (at your option) any later version. | |
| 11 | + | |
| 12 | + This library is distributed in the hope that it will be useful, | |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 15 | + See the GNU Lesser General Public License for more details. | |
| 16 | + | |
| 17 | + You should have received a copy of the GNU Lesser General Public | |
| 18 | + License along with this library; if not, write to the Free Software | |
| 19 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | +*/ | |
| 21 | + | |
| 22 | +#ifndef FLASH_AS_EEPROM_h | |
| 23 | +#define FLASH_AS_EEPROM_h | |
| 24 | + | |
| 25 | +#include "FlashStorage.h" | |
| 26 | + | |
| 27 | +#ifndef EEPROM_EMULATION_SIZE | |
| 28 | +#define EEPROM_EMULATION_SIZE 1024 | |
| 29 | +#endif | |
| 30 | + | |
| 31 | +typedef struct { | |
| 32 | + byte data[EEPROM_EMULATION_SIZE]; | |
| 33 | + boolean valid; | |
| 34 | +} EEPROM_EMULATION; | |
| 35 | + | |
| 36 | + | |
| 37 | +class EEPROMClass { | |
| 38 | + | |
| 39 | + public: | |
| 40 | + EEPROMClass(void); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Read an eeprom cell | |
| 44 | + * @param index | |
| 45 | + * @return value | |
| 46 | + */ | |
| 47 | + uint8_t read(int); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Write value to an eeprom cell | |
| 51 | + * @param index | |
| 52 | + * @param value | |
| 53 | + */ | |
| 54 | + void write(int, uint8_t); | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Update a eeprom cell | |
| 58 | + * @param index | |
| 59 | + * @param value | |
| 60 | + */ | |
| 61 | + void update(int, uint8_t); | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Check whether the eeprom data is valid | |
| 65 | + * @return true, if eeprom data is valid (has been written at least once), false if not | |
| 66 | + */ | |
| 67 | + bool isValid(); | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Write previously made eeprom changes to the underlying flash storage | |
| 71 | + * Use this with care: Each and every commit will harm the flash and reduce it's lifetime (like with every flash memory) | |
| 72 | + */ | |
| 73 | + void commit(); | |
| 74 | + | |
| 75 | + uint16_t length() { return EEPROM_EMULATION_SIZE; } | |
| 76 | + | |
| 77 | + private: | |
| 78 | + void init(); | |
| 79 | + | |
| 80 | + bool _initialized; | |
| 81 | + EEPROM_EMULATION _eeprom; | |
| 82 | + bool _dirty; | |
| 83 | +}; | |
| 84 | + | |
| 85 | +extern EEPROMClass EEPROM; | |
| 86 | + | |
| 87 | +#endif |
| @@ -0,0 +1,104 @@ | ||
| 1 | +/* | |
| 2 | + Copyright (c) 2015 Arduino LLC. All right reserved. | |
| 3 | + Written by Cristian Maglie | |
| 4 | + | |
| 5 | + This library is free software; you can redistribute it and/or | |
| 6 | + modify it under the terms of the GNU Lesser General Public | |
| 7 | + License as published by the Free Software Foundation; either | |
| 8 | + version 2.1 of the License, or (at your option) any later version. | |
| 9 | + | |
| 10 | + This library is distributed in the hope that it will be useful, | |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 13 | + See the GNU Lesser General Public License for more details. | |
| 14 | + | |
| 15 | + You should have received a copy of the GNU Lesser General Public | |
| 16 | + License along with this library; if not, write to the Free Software | |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | +*/ | |
| 19 | +#if defined(__SAMD21G18A__) | |
| 20 | +#include "FlashStorage.h" | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | +static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 }; | |
| 25 | + | |
| 26 | +FlashClass::FlashClass(const void *flash_addr, uint32_t size) : | |
| 27 | + PAGE_SIZE(pageSizes[NVMCTRL->PARAM.bit.PSZ]), | |
| 28 | + PAGES(NVMCTRL->PARAM.bit.NVMP), | |
| 29 | + MAX_FLASH(PAGE_SIZE * PAGES), | |
| 30 | + ROW_SIZE(PAGE_SIZE * 4), | |
| 31 | + flash_address((volatile void *)flash_addr), | |
| 32 | + flash_size(size) | |
| 33 | +{ | |
| 34 | +} | |
| 35 | + | |
| 36 | +static inline uint32_t read_unaligned_uint32(const void *data) | |
| 37 | +{ | |
| 38 | + union { | |
| 39 | + uint32_t u32; | |
| 40 | + uint8_t u8[4]; | |
| 41 | + } res; | |
| 42 | + const uint8_t *d = (const uint8_t *)data; | |
| 43 | + res.u8[0] = d[0]; | |
| 44 | + res.u8[1] = d[1]; | |
| 45 | + res.u8[2] = d[2]; | |
| 46 | + res.u8[3] = d[3]; | |
| 47 | + return res.u32; | |
| 48 | +} | |
| 49 | + | |
| 50 | +void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size) | |
| 51 | +{ | |
| 52 | + // Calculate data boundaries | |
| 53 | + size = (size + 3) / 4; | |
| 54 | + volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr; | |
| 55 | + const uint8_t *src_addr = (uint8_t *)data; | |
| 56 | + | |
| 57 | + // Disable automatic page write | |
| 58 | + NVMCTRL->CTRLB.bit.MANW = 1; | |
| 59 | + | |
| 60 | + // Do writes in pages | |
| 61 | + while (size) { | |
| 62 | + // Execute "PBC" Page Buffer Clear | |
| 63 | + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC; | |
| 64 | + while (NVMCTRL->INTFLAG.bit.READY == 0) { } | |
| 65 | + | |
| 66 | + // Fill page buffer | |
| 67 | + uint32_t i; | |
| 68 | + for (i=0; i<(PAGE_SIZE/4) && size; i++) { | |
| 69 | + *dst_addr = read_unaligned_uint32(src_addr); | |
| 70 | + src_addr += 4; | |
| 71 | + dst_addr++; | |
| 72 | + size--; | |
| 73 | + } | |
| 74 | + | |
| 75 | + // Execute "WP" Write Page | |
| 76 | + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP; | |
| 77 | + while (NVMCTRL->INTFLAG.bit.READY == 0) { } | |
| 78 | + } | |
| 79 | +} | |
| 80 | + | |
| 81 | +void FlashClass::erase(const volatile void *flash_ptr, uint32_t size) | |
| 82 | +{ | |
| 83 | + const uint8_t *ptr = (const uint8_t *)flash_ptr; | |
| 84 | + while (size > ROW_SIZE) { | |
| 85 | + erase(ptr); | |
| 86 | + ptr += ROW_SIZE; | |
| 87 | + size -= ROW_SIZE; | |
| 88 | + } | |
| 89 | + erase(ptr); | |
| 90 | +} | |
| 91 | + | |
| 92 | +void FlashClass::erase(const volatile void *flash_ptr) | |
| 93 | +{ | |
| 94 | + NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr) / 2; | |
| 95 | + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER; | |
| 96 | + while (!NVMCTRL->INTFLAG.bit.READY) { } | |
| 97 | +} | |
| 98 | + | |
| 99 | +void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size) | |
| 100 | +{ | |
| 101 | + memcpy(data, (const void *)flash_ptr, size); | |
| 102 | +} | |
| 103 | + | |
| 104 | +#endif | |
| \ No newline at end of file |
| @@ -0,0 +1,77 @@ | ||
| 1 | +/* | |
| 2 | + Copyright (c) 2015 Arduino LLC. All right reserved. | |
| 3 | + Written by Cristian Maglie | |
| 4 | + | |
| 5 | + This library is free software; you can redistribute it and/or | |
| 6 | + modify it under the terms of the GNU Lesser General Public | |
| 7 | + License as published by the Free Software Foundation; either | |
| 8 | + version 2.1 of the License, or (at your option) any later version. | |
| 9 | + | |
| 10 | + This library is distributed in the hope that it will be useful, | |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 13 | + See the GNU Lesser General Public License for more details. | |
| 14 | + | |
| 15 | + You should have received a copy of the GNU Lesser General Public | |
| 16 | + License along with this library; if not, write to the Free Software | |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | +*/ | |
| 19 | + | |
| 20 | +#pragma once | |
| 21 | + | |
| 22 | +#include <Arduino.h> | |
| 23 | + | |
| 24 | +// Concatenate after macro expansion | |
| 25 | +#define PPCAT_NX(A, B) A ## B | |
| 26 | +#define PPCAT(A, B) PPCAT_NX(A, B) | |
| 27 | + | |
| 28 | +#define Flash(name, size) \ | |
| 29 | + __attribute__((__aligned__(256))) \ | |
| 30 | + static const uint8_t PPCAT(_data,name)[(size+255)/256*256] = { }; \ | |
| 31 | + FlashClass name(PPCAT(_data,name), size); | |
| 32 | + | |
| 33 | +#define FlashStorage(name, T) \ | |
| 34 | + __attribute__((__aligned__(256))) \ | |
| 35 | + static const uint8_t PPCAT(_data,name)[(sizeof(T)+255)/256*256] = { }; \ | |
| 36 | + FlashStorageClass<T> name(PPCAT(_data,name)); | |
| 37 | + | |
| 38 | +class FlashClass { | |
| 39 | +public: | |
| 40 | + FlashClass(const void *flash_addr = NULL, uint32_t size = 0); | |
| 41 | + | |
| 42 | + void write(const void *data) { write(flash_address, data, flash_size); } | |
| 43 | + void erase() { erase(flash_address, flash_size); } | |
| 44 | + void read(void *data) { read(flash_address, data, flash_size); } | |
| 45 | + | |
| 46 | + void write(const volatile void *flash_ptr, const void *data, uint32_t size); | |
| 47 | + void erase(const volatile void *flash_ptr, uint32_t size); | |
| 48 | + void read(const volatile void *flash_ptr, void *data, uint32_t size); | |
| 49 | + | |
| 50 | +private: | |
| 51 | + void erase(const volatile void *flash_ptr); | |
| 52 | + | |
| 53 | + const uint32_t PAGE_SIZE, PAGES, MAX_FLASH, ROW_SIZE; | |
| 54 | + const volatile void *flash_address; | |
| 55 | + const uint32_t flash_size; | |
| 56 | +}; | |
| 57 | + | |
| 58 | +template<class T> | |
| 59 | +class FlashStorageClass { | |
| 60 | +public: | |
| 61 | + FlashStorageClass(const void *flash_addr) : flash(flash_addr, sizeof(T)) { }; | |
| 62 | + | |
| 63 | + // Write data into flash memory. | |
| 64 | + // Compiler is able to optimize parameter copy. | |
| 65 | + inline void write(T data) { flash.erase(); flash.write(&data); } | |
| 66 | + | |
| 67 | + // Read data from flash into variable. | |
| 68 | + inline void read(T *data) { flash.read(data); } | |
| 69 | + | |
| 70 | + // Overloaded version of read. | |
| 71 | + // Compiler is able to optimize copy-on-return. | |
| 72 | + inline T read() { T data; read(&data); return data; } | |
| 73 | + | |
| 74 | +private: | |
| 75 | + FlashClass flash; | |
| 76 | +}; | |
| 77 | + |