Speeduino
Loading...
Searching...
No Matches
board_avr2560.h
Go to the documentation of this file.
1#pragma once
2
5#define CORE_AVR
6
7#include <avr/interrupt.h>
8#include <avr/io.h>
9
10/*
11***********************************************************************************************************
12* General
13*/
14#define BOARD_MAX_DIGITAL_PINS 54 //digital pins +1
15#define BOARD_MAX_IO_PINS 70 //digital pins + analog channels + 1
16#define BOARD_MAX_ADC_PINS 15 //Number of analog pins
17#ifndef LED_BUILTIN
18 #define LED_BUILTIN 13
19#endif
20
21#ifndef INJ_CHANNELS
22 #define INJ_CHANNELS 4
23#endif
24#ifndef IGN_CHANNELS
25 #define IGN_CHANNELS 5
26#endif
27
28#define COMPARE_TYPE uint16_t
29#define SERIAL_BUFFER_SIZE (256+7+1) //Size of the serial buffer used by new comms protocol. The largest single packet is the O2 calibration which is 256 bytes + 7 bytes of overhead
30#define FPU_MAX_SIZE 0 //Size of the FPU buffer. 0 means no FPU.
31#ifdef USE_SPI_EEPROM
32 #define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
34#else
35 #define EEPROM_LIB_H <EEPROM.h>
36 typedef int eeprom_address_t;
37#endif
38#ifdef PLATFORMIO
39 #define RTC_LIB_H <TimeLib.h>
40#else
41 #define RTC_LIB_H <Time.h>
42#endif
43
44#define pinIsReserved(pin) ( ((pin) == 0) ) //Forbidden pins like USB on other boards
45
46/*
47***********************************************************************************************************
48* Schedules
49*/
50 //Refer to svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/iomxx0_1.h?root=avr-libc&view=markup
51#define FUEL1_COUNTER TCNT3
52#define FUEL2_COUNTER TCNT3
53#define FUEL3_COUNTER TCNT3
54#define FUEL4_COUNTER TCNT4
55#define FUEL5_COUNTER TCNT4
56#define FUEL6_COUNTER TCNT4 //Replaces ignition 4
57#define FUEL7_COUNTER TCNT5 //Replaces ignition 3
58#define FUEL8_COUNTER TCNT5 //Replaces ignition 2
59
60#define IGN1_COUNTER TCNT5
61#define IGN2_COUNTER TCNT5
62#define IGN3_COUNTER TCNT5
63#define IGN4_COUNTER TCNT4
64#define IGN5_COUNTER TCNT4
65#define IGN6_COUNTER TCNT4 //Replaces injector 4
66#define IGN7_COUNTER TCNT3 //Replaces injector 3
67#define IGN8_COUNTER TCNT3 //Replaces injector 2
68
69#define FUEL1_COMPARE OCR3A
70#define FUEL2_COMPARE OCR3B
71#define FUEL3_COMPARE OCR3C
72#define FUEL4_COMPARE OCR4B //Replaces ignition 6
73#define FUEL5_COMPARE OCR4C //Replaces ignition 5
74#define FUEL6_COMPARE OCR4A //Replaces ignition 4
75#define FUEL7_COMPARE OCR5C //Replaces ignition 3
76#define FUEL8_COMPARE OCR5B //Replaces ignition 2
77
78#define IGN1_COMPARE OCR5A
79#define IGN2_COMPARE OCR5B
80#define IGN3_COMPARE OCR5C
81#define IGN4_COMPARE OCR4A //Replaces injector 6
82#define IGN5_COMPARE OCR4C //Replaces injector 5
83#define IGN6_COMPARE OCR4B //Replaces injector 4
84#define IGN7_COMPARE OCR3C //Replaces injector 3
85#define IGN8_COMPARE OCR3B //Replaces injector 2
86
87//Note that the interrupt flag is reset BEFORE the interrupt is enabled
88static inline void FUEL1_TIMER_ENABLE(void) { TIFR3 |= (1<<OCF3A) ; TIMSK3 |= (1 << OCIE3A); } //Turn on the A compare unit (ie turn on the interrupt)
89static inline void FUEL2_TIMER_ENABLE(void) { TIFR3 |= (1<<OCF3B); TIMSK3 |= (1 << OCIE3B); } //Turn on the B compare unit (ie turn on the interrupt)
90static inline void FUEL3_TIMER_ENABLE(void) { TIFR3 |= (1<<OCF3C); TIMSK3 |= (1 << OCIE3C); } //Turn on the C compare unit (ie turn on the interrupt)
91static inline void FUEL4_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4B); TIMSK4 |= (1 << OCIE4B); } //Turn on the B compare unit (ie turn on the interrupt)
92static inline void FUEL5_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4C); TIMSK4 |= (1 << OCIE4C); } //Turn on the C compare unit (ie turn on the interrupt)
93static inline void FUEL6_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4A); TIMSK4 |= (1 << OCIE4A); } //Turn on the A compare unit (ie turn on the interrupt)
94static inline void FUEL7_TIMER_ENABLE(void) { TIFR5 |= (1<<OCF5C); TIMSK5 |= (1 << OCIE5C); } //
95static inline void FUEL8_TIMER_ENABLE(void) { TIFR5 |= (1<<OCF5B); TIMSK5 |= (1 << OCIE5B); } //
96
97static inline void FUEL1_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3A); } // //Turn off this output compare unit
98static inline void FUEL2_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3B); } // //Turn off this output compare unit
99static inline void FUEL3_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3C); } // //Turn off this output compare unit
100static inline void FUEL4_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4B); }
101static inline void FUEL5_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4C); } // //
102static inline void FUEL6_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4A); } // //
103static inline void FUEL7_TIMER_DISABLE(void) { TIMSK5 &= ~(1 << OCIE5C); } // //
104static inline void FUEL8_TIMER_DISABLE(void) { TIMSK5 &= ~(1 << OCIE5B); } //
105
106 //These have the TIFR5 bits set to 1 to clear the interrupt flag. This prevents a false interrupt being called the first time the channel is enabled.
107static inline void IGN1_TIMER_ENABLE(void) { TIFR5 |= (1<<OCF5A); TIMSK5 |= (1 << OCIE5A); } //Turn on the A compare unit (ie turn on the interrupt)
108static inline void IGN2_TIMER_ENABLE(void) { TIFR5 |= (1<<OCF5B); TIMSK5 |= (1 << OCIE5B); }//Turn on the B compare unit (ie turn on the interrupt)
109static inline void IGN3_TIMER_ENABLE(void) { TIFR5 |= (1<<OCF5C); TIMSK5 |= (1 << OCIE5C); }//Turn on the C compare unit (ie turn on the interrupt)
110static inline void IGN4_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4A); TIMSK4 |= (1 << OCIE4A); }//Turn on the A compare unit (ie turn on the interrupt)
111static inline void IGN5_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4C); TIMSK4 |= (1 << OCIE4C); } //Turn on the A compare unit (ie turn on the interrupt)
112static inline void IGN6_TIMER_ENABLE(void) { TIFR4 |= (1<<OCF4B); TIMSK4 |= (1 << OCIE4B); } //Replaces injector 4
113static inline void IGN7_TIMER_ENABLE(void) { TIMSK3 |= (1 << OCIE3C); }//Replaces injector 3
114static inline void IGN8_TIMER_ENABLE(void) { TIMSK3 |= (1 << OCIE3B); } //Replaces injector 2
115
116static inline void IGN1_TIMER_DISABLE(void) { TIMSK5 &= ~(1 << OCIE5A); } //Turn off this output compare unit
117static inline void IGN2_TIMER_DISABLE(void) { TIMSK5 &= ~(1 << OCIE5B); } //Turn off this output compare unit
118static inline void IGN3_TIMER_DISABLE(void) { TIMSK5 &= ~(1 << OCIE5C); } //Turn off this output compare unit
119static inline void IGN4_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4A); } //Turn off this output compare unit
120static inline void IGN5_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4C); } //Turn off this output compare unit
121static inline void IGN6_TIMER_DISABLE(void) { TIMSK4 &= ~(1 << OCIE4B); } //Replaces injector 4
122static inline void IGN7_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3C); } //Replaces injector 3
123static inline void IGN8_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3B); } //Replaces injector 2
124
125#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)
126#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
127
128/*
129***********************************************************************************************************
130* Auxiliaries
131*/
132#define ENABLE_BOOST_TIMER() TIMSK1 |= (1 << OCIE1A)
133#define DISABLE_BOOST_TIMER() TIMSK1 &= ~(1 << OCIE1A)
134#define ENABLE_VVT_TIMER() TIMSK1 |= (1 << OCIE1B)
135#define DISABLE_VVT_TIMER() TIMSK1 &= ~(1 << OCIE1B)
136
137#define BOOST_TIMER_COMPARE OCR1A
138#define BOOST_TIMER_COUNTER TCNT1
139#define VVT_TIMER_COMPARE OCR1B
140#define VVT_TIMER_COUNTER TCNT1
141
142/*
143***********************************************************************************************************
144* Idle
145*/
146#define IDLE_COUNTER TCNT1
147#define IDLE_COMPARE OCR1C
148
149#define IDLE_TIMER_ENABLE() TIMSK1 |= (1 << OCIE1C)
150#define IDLE_TIMER_DISABLE() TIMSK1 &= ~(1 << OCIE1C)
151
152/*
153***********************************************************************************************************
154* CAN / Second serial
155*/
156#define SECONDARY_SERIAL_T HardwareSerial
static void IGN1_TIMER_ENABLE(void)
Definition board_avr2560.h:107
static void IGN3_TIMER_DISABLE(void)
Definition board_avr2560.h:118
static void IGN1_TIMER_DISABLE(void)
Definition board_avr2560.h:116
static void FUEL2_TIMER_ENABLE(void)
Definition board_avr2560.h:89
static void FUEL1_TIMER_DISABLE(void)
Definition board_avr2560.h:97
static void FUEL4_TIMER_DISABLE(void)
Definition board_avr2560.h:100
static void IGN3_TIMER_ENABLE(void)
Definition board_avr2560.h:109
static void FUEL4_TIMER_ENABLE(void)
Definition board_avr2560.h:91
int eeprom_address_t
Definition board_avr2560.h:36
static void FUEL5_TIMER_DISABLE(void)
Definition board_avr2560.h:101
static void FUEL2_TIMER_DISABLE(void)
Definition board_avr2560.h:98
static void FUEL3_TIMER_DISABLE(void)
Definition board_avr2560.h:99
static void IGN5_TIMER_ENABLE(void)
Definition board_avr2560.h:111
static void FUEL7_TIMER_DISABLE(void)
Definition board_avr2560.h:103
static void FUEL7_TIMER_ENABLE(void)
Definition board_avr2560.h:94
static void FUEL3_TIMER_ENABLE(void)
Definition board_avr2560.h:90
static void FUEL6_TIMER_ENABLE(void)
Definition board_avr2560.h:93
static void IGN6_TIMER_DISABLE(void)
Definition board_avr2560.h:121
static void FUEL6_TIMER_DISABLE(void)
Definition board_avr2560.h:102
static void IGN7_TIMER_DISABLE(void)
Definition board_avr2560.h:122
static void IGN2_TIMER_DISABLE(void)
Definition board_avr2560.h:117
static void IGN8_TIMER_DISABLE(void)
Definition board_avr2560.h:123
static void IGN6_TIMER_ENABLE(void)
Definition board_avr2560.h:112
static void IGN2_TIMER_ENABLE(void)
Definition board_avr2560.h:108
static void IGN8_TIMER_ENABLE(void)
Definition board_avr2560.h:114
static void FUEL8_TIMER_DISABLE(void)
Definition board_avr2560.h:104
static void IGN4_TIMER_ENABLE(void)
Definition board_avr2560.h:110
static void IGN7_TIMER_ENABLE(void)
Definition board_avr2560.h:113
static void IGN5_TIMER_DISABLE(void)
Definition board_avr2560.h:120
static void IGN4_TIMER_DISABLE(void)
Definition board_avr2560.h:119
static void FUEL1_TIMER_ENABLE(void)
Definition board_avr2560.h:88
static void FUEL8_TIMER_ENABLE(void)
Definition board_avr2560.h:95
static void FUEL5_TIMER_ENABLE(void)
Definition board_avr2560.h:92
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:348