Speeduino
Loading...
Searching...
No Matches
board_same51.h
Go to the documentation of this file.
1#pragma once
2
5#define CORE_SAME51
6#define CORE_SAM
7
8#include "sam.h"
9
10/*
11***********************************************************************************************************
12* General
13*/
14#define BOARD_MAX_DIGITAL_PINS 54 //digital pins +1
15#define BOARD_MAX_IO_PINS 58 //digital pins + analog channels + 1
16
17#define COMPARE_TYPE uint16_t
18#define SERIAL_BUFFER_SIZE 257 //Size of the serial buffer used by new comms protocol. Additional 1 byte is for flag
19#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
20#ifdef USE_SPI_EEPROM
21 #define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
23 #include EEPROM_LIB_H
24 SPIClass SPI_for_flash = SPI; //SPI1_MOSI, SPI1_MISO, SPI1_SCK
25
26 EEPROM_Emulation_Config EmulatedEEPROMMconfig{255UL, 4096UL, 31, 0x00100000UL};
28#else
29 #define EEPROM_LIB_H "src/FlashStorage/FlashAsEEPROM.h"
31#endif
32#define RTC_LIB_H "TimeLib.h"
33
34#define pinIsReserved(pin) ( ((pin) == 0) ) //Forbidden pins like USB on other boards
35
36//Additional analog pins (These won't work without other changes)
37#define PIN_A6 (8ul)
38#define PIN_A7 (9ul)
39#define PIN_A8 (10ul)
40#define PIN_A9 (11ul)
41#define PIN_A13 (9ul)
42#define PIN_A14 (9ul)
43#define PIN_A15 (9ul)
44
45static const uint8_t A7 = PIN_A7;
46static const uint8_t A8 = PIN_A8;
47static const uint8_t A9 = PIN_A9;
48static const uint8_t A13 = PIN_A13;
49static const uint8_t A14 = PIN_A14;
50static const uint8_t A15 = PIN_A15;
51
52/*
53***********************************************************************************************************
54* Schedules
55*/
56#define INJ_CHANNELS 8
57#define IGN_CHANNELS 8
58
59//See : https://electronics.stackexchange.com/questions/325159/the-value-of-the-tcc-counter-on-an-atsam-controller-always-reads-as-zero
60// SAME512 Timer channel list: https://user-images.githubusercontent.com/11770912/62131781-2e150b80-b31f-11e9-9970-9a6c2356a17c.png
61#define FUEL1_COUNTER TCC0->COUNT.reg
62#define FUEL2_COUNTER TCC0->COUNT.reg
63#define FUEL3_COUNTER TCC0->COUNT.reg
64#define FUEL4_COUNTER TCC0->COUNT.reg
65//The below are NOT YET RIGHT!
66#define FUEL5_COUNTER TCC1->COUNT.reg
67#define FUEL6_COUNTER TCC1->COUNT.reg
68#define FUEL7_COUNTER TCC1->COUNT.reg
69#define FUEL8_COUNTER TCC1->COUNT.reg
70
71#define IGN1_COUNTER TCC1->COUNT.reg
72#define IGN2_COUNTER TCC1->COUNT.reg
73#define IGN3_COUNTER TCC2->COUNT.reg
74#define IGN4_COUNTER TCC2->COUNT.reg
75//The below are NOT YET RIGHT!
76#define IGN5_COUNTER TCC1->COUNT.reg
77#define IGN6_COUNTER TCC1->COUNT.reg
78#define IGN7_COUNTER TCC2->COUNT.reg
79#define IGN8_COUNTER TCC2->COUNT.reg
80
81#define FUEL1_COMPARE TCC0->CC[0].bit.CC
82#define FUEL2_COMPARE TCC0->CC[1].bit.CC
83#define FUEL3_COMPARE TCC0->CC[2].bit.CC
84#define FUEL4_COMPARE TCC0->CC[3].bit.CC
85//The below are NOT YET RIGHT!
86#define FUEL5_COMPARE TCC1->CC[0].bit.CC
87#define FUEL6_COMPARE TCC1->CC[1].bit.CC
88#define FUEL7_COMPARE TCC1->CC[2].bit.CC
89#define FUEL8_COMPARE TCC1->CC[3].bit.CC
90
91#define IGN1_COMPARE TCC1->CC[0].bit.CC
92#define IGN2_COMPARE TCC1->CC[1].bit.CC
93#define IGN3_COMPARE TCC2->CC[0].bit.CC
94#define IGN4_COMPARE TCC2->CC[1].bit.CC
95//The below are NOT YET RIGHT!
96#define IGN5_COMPARE TCC1->CC[0].bit.CC
97#define IGN6_COMPARE TCC1->CC[1].bit.CC
98#define IGN7_COMPARE TCC2->CC[0].bit.CC
99#define IGN8_COMPARE TCC2->CC[1].bit.CC
100
101static inline void FUEL1_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC0 = 0x1; }
102static inline void FUEL2_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC1 = 0x1; }
103static inline void FUEL3_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC2 = 0x1; }
104static inline void FUEL4_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC3 = 0x1; }
105 //The below are NOT YET RIGHT!
106static inline void FUEL5_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC0 = 0x1; }
107static inline void FUEL6_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC1 = 0x1; }
108static inline void FUEL7_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC2 = 0x1; }
109static inline void FUEL8_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC3 = 0x1; }
110
111static inline void FUEL1_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
112static inline void FUEL2_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
113static inline void FUEL3_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
114static inline void FUEL4_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
115 //The below are NOT YET RIGHT!
116static inline void FUEL5_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
117static inline void FUEL6_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
118static inline void FUEL7_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
119static inline void FUEL9_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; }
120
121static inline void IGN1_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC0 = 0x1; }
122static inline void IGN2_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC1 = 0x1; }
123static inline void IGN3_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC0 = 0x1; }
124static inline void IGN4_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC1 = 0x1; }
125//The below are NOT YET RIGHT!
126static inline void IGN5_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC0 = 0x1; }
127static inline void IGN6_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC1 = 0x1; }
128static inline void IGN7_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC0 = 0x1; }
129static inline void IGN8_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC1 = 0x1; }
130
131static inline void IGN1_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC0 = 0x0; }
132static inline void IGN2_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC1 = 0x0; }
133static inline void IGN3_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC0 = 0x0; }
134static inline void IGN4_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC1 = 0x0; }
135//The below are NOT YET RIGHT!
136static inline void IGN5_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC0 = 0x0; }
137static inline void IGN6_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC1 = 0x0; }
138static inline void IGN7_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC0 = 0x0; }
139static inline void IGN8_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC1 = 0x0; }
140
141#define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535
142#define MAX_TIMER_PERIOD_SLOW 139808
143#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.
144//Hack compatibility with AVR timers that run at different speeds
145#define uS_TO_TIMER_COMPARE_SLOW(uS) (((uS) * 15) >> 5)
146
147/*
148***********************************************************************************************************
149* Auxiliaries
150*/
151//Uses the 2nd TC
152//The 2nd TC is referred to as TC4
153#define ENABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x1 // Enable match interrupts on compare channel 0
154#define DISABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x0
155
156#define ENABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x1
157#define DISABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x0
158
159#define BOOST_TIMER_COMPARE TC4->COUNT16.CC[0].reg
160#define BOOST_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
161#define VVT_TIMER_COMPARE TC4->COUNT16.CC[1].reg
162#define VVT_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
163
164/*
165***********************************************************************************************************
166* Idle
167*/
168//3rd TC is aliased as TC5
169#define IDLE_COUNTER TC5->COUNT16.COUNT.bit.COUNT
170#define IDLE_COMPARE TC5->COUNT16.CC[0].reg
171
172#define IDLE_TIMER_ENABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x1
173#define IDLE_TIMER_DISABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x0
174
175/*
176***********************************************************************************************************
177* CAN / Second serial
178*/
#define PIN_A7
Definition board_same51.h:38
static void IGN1_TIMER_ENABLE(void)
Definition board_same51.h:121
static void IGN3_TIMER_DISABLE(void)
Definition board_same51.h:133
static void IGN1_TIMER_DISABLE(void)
Definition board_same51.h:131
#define PIN_A9
Definition board_same51.h:40
static void FUEL2_TIMER_ENABLE(void)
Definition board_same51.h:102
static const uint8_t A14
Definition board_same51.h:49
static void FUEL1_TIMER_DISABLE(void)
Definition board_same51.h:111
static void FUEL4_TIMER_DISABLE(void)
Definition board_same51.h:114
static void IGN3_TIMER_ENABLE(void)
Definition board_same51.h:123
static void FUEL4_TIMER_ENABLE(void)
Definition board_same51.h:104
#define PIN_A14
Definition board_same51.h:42
static const uint8_t A8
Definition board_same51.h:46
static void FUEL5_TIMER_DISABLE(void)
Definition board_same51.h:116
static void FUEL9_TIMER_DISABLE(void)
Definition board_same51.h:119
static void FUEL2_TIMER_DISABLE(void)
Definition board_same51.h:112
static void FUEL3_TIMER_DISABLE(void)
Definition board_same51.h:113
static void IGN5_TIMER_ENABLE(void)
Definition board_same51.h:126
static void FUEL7_TIMER_DISABLE(void)
Definition board_same51.h:118
#define PIN_A13
Definition board_same51.h:41
static void FUEL7_TIMER_ENABLE(void)
Definition board_same51.h:108
static void FUEL3_TIMER_ENABLE(void)
Definition board_same51.h:103
static void FUEL6_TIMER_ENABLE(void)
Definition board_same51.h:107
#define PIN_A8
Definition board_same51.h:39
static void IGN6_TIMER_DISABLE(void)
Definition board_same51.h:137
uint16_t eeprom_address_t
Definition board_same51.h:30
static void FUEL6_TIMER_DISABLE(void)
Definition board_same51.h:117
static void IGN7_TIMER_DISABLE(void)
Definition board_same51.h:138
static void IGN2_TIMER_DISABLE(void)
Definition board_same51.h:132
static void IGN8_TIMER_DISABLE(void)
Definition board_same51.h:139
static void IGN6_TIMER_ENABLE(void)
Definition board_same51.h:127
static const uint8_t A15
Definition board_same51.h:50
static void IGN2_TIMER_ENABLE(void)
Definition board_same51.h:122
static void IGN8_TIMER_ENABLE(void)
Definition board_same51.h:129
static const uint8_t A13
Definition board_same51.h:48
static void IGN4_TIMER_ENABLE(void)
Definition board_same51.h:124
Uart secondarySerial & sercom3
Definition board_same51.h:179
static void IGN7_TIMER_ENABLE(void)
Definition board_same51.h:128
static void IGN5_TIMER_DISABLE(void)
Definition board_same51.h:136
static void IGN4_TIMER_DISABLE(void)
Definition board_same51.h:134
static void FUEL1_TIMER_ENABLE(void)
Definition board_same51.h:101
static const uint8_t A9
Definition board_same51.h:47
static void FUEL8_TIMER_ENABLE(void)
Definition board_same51.h:109
static void FUEL5_TIMER_ENABLE(void)
Definition board_same51.h:106
static const uint8_t A7
Definition board_same51.h:45
#define PIN_A15
Definition board_same51.h:43
InternalSTM32F4_EEPROM_Class EEPROM
#define secondarySerial
Definition comms_secondary.h:15
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:348