Speeduino
Loading...
Searching...
No Matches
board_teensy41.h
Go to the documentation of this file.
1#ifndef TEENSY41_H
2#define TEENSY41_H
3
4#if defined(CORE_TEENSY) && defined(__IMXRT1062__)
5
6/*
7***********************************************************************************************************
8* General
9*/
10 void initBoard();
12 void doSystemReset();
13 void jumpToBootloader();
16 bool pinIsSerial(uint8_t);
18 #define PORT_TYPE uint32_t //Size of the port variables
19 #define PINMASK_TYPE uint32_t
20 #define COMPARE_TYPE uint16_t
21 #define COUNTER_TYPE uint16_t
22 #define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
23 #define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
24 #define BOARD_MAX_DIGITAL_PINS 54
25 #define BOARD_MAX_IO_PINS 54
26 #define BOARD_MAX_ADC_PINS 17 //Number of analog pins
27 #define EEPROM_LIB_H <EEPROM.h>
28 typedef int eeprom_address_t;
29 #define RTC_ENABLED
30 #define SD_LOGGING //SD logging enabled by default for Teensy 4.1 as it has the slot built in
31 #define RTC_LIB_H "TimeLib.h"
32 #define SD_CONFIG SdioConfig(FIFO_SDIO) //Set Teensy to use SDIO in FIFO mode. This is the fastest SD mode on Teensy as it offloads most of the writes
33
34 #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()
35 //#define PWM_FAN_AVAILABLE
36 #define pinIsReserved(pin) ( ((pin) == 0) || ((pin) == 42) || ((pin) == 43) || ((pin) == 44) || ((pin) == 45) || ((pin) == 46) || ((pin) == 47) || pinIsSerial((pin)) ) //Forbidden pins like USB
37
38
39/*
40***********************************************************************************************************
41* Schedules
42*/
43 /*
44 https://github.com/luni64/TeensyTimerTool/wiki/Supported-Timers#pit---periodic-timer
45 https://github.com/luni64/TeensyTimerTool/wiki/Configuration#clock-setting-for-the-gpt-and-pit-timers
46 The Quad timer (TMR) provides 4 timers each with 4 usable compare channels. The down compare and alternating compares are not usable
47 FUEL 1-4: TMR1
48 IGN 1-4 : TMR2
49 FUEL 5-8: TMR3
50 IGN 5-8 : TMR4
51 */
52 #define FUEL1_COUNTER TMR1_CNTR0
53 #define FUEL2_COUNTER TMR1_CNTR1
54 #define FUEL3_COUNTER TMR1_CNTR2
55 #define FUEL4_COUNTER TMR1_CNTR3
56 #define FUEL5_COUNTER TMR3_CNTR0
57 #define FUEL6_COUNTER TMR3_CNTR1
58 #define FUEL7_COUNTER TMR3_CNTR2
59 #define FUEL8_COUNTER TMR3_CNTR3
60
61 #define IGN1_COUNTER TMR2_CNTR0
62 #define IGN2_COUNTER TMR2_CNTR1
63 #define IGN3_COUNTER TMR2_CNTR2
64 #define IGN4_COUNTER TMR2_CNTR3
65 #define IGN5_COUNTER TMR4_CNTR0
66 #define IGN6_COUNTER TMR4_CNTR1
67 #define IGN7_COUNTER TMR4_CNTR2
68 #define IGN8_COUNTER TMR4_CNTR3
69
70 #define FUEL1_COMPARE TMR1_COMP10
71 #define FUEL2_COMPARE TMR1_COMP11
72 #define FUEL3_COMPARE TMR1_COMP12
73 #define FUEL4_COMPARE TMR1_COMP13
74 #define FUEL5_COMPARE TMR3_COMP10
75 #define FUEL6_COMPARE TMR3_COMP11
76 #define FUEL7_COMPARE TMR3_COMP12
77 #define FUEL8_COMPARE TMR3_COMP13
78
79 #define IGN1_COMPARE TMR2_COMP10
80 #define IGN2_COMPARE TMR2_COMP11
81 #define IGN3_COMPARE TMR2_COMP12
82 #define IGN4_COMPARE TMR2_COMP13
83 #define IGN5_COMPARE TMR4_COMP10
84 #define IGN6_COMPARE TMR4_COMP11
85 #define IGN7_COMPARE TMR4_COMP12
86 #define IGN8_COMPARE TMR4_COMP13
87
88 static inline void FUEL1_TIMER_ENABLE(void) {TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1; TMR1_CSCTRL0 |= TMR_CSCTRL_TCF1EN;} //Write 1 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control
96
97 static inline void FUEL1_TIMER_DISABLE(void) {TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;} //Write 0 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control
98 static inline void FUEL2_TIMER_DISABLE(void) {TMR1_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;}
99 static inline void FUEL3_TIMER_DISABLE(void) {TMR1_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;}
100 static inline void FUEL4_TIMER_DISABLE(void) {TMR1_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;}
101 static inline void FUEL5_TIMER_DISABLE(void) {TMR3_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;}
102 static inline void FUEL6_TIMER_DISABLE(void) {TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;}
103 static inline void FUEL7_TIMER_DISABLE(void) {TMR3_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;}
104 static inline void FUEL8_TIMER_DISABLE(void) {TMR3_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;}
105
114
115 static inline void IGN1_TIMER_DISABLE(void) {TMR2_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;}
116 static inline void IGN2_TIMER_DISABLE(void) {TMR2_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;}
117 static inline void IGN3_TIMER_DISABLE(void) {TMR2_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;}
118 static inline void IGN4_TIMER_DISABLE(void) {TMR2_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;}
119 static inline void IGN5_TIMER_DISABLE(void) {TMR4_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;}
120 static inline void IGN6_TIMER_DISABLE(void) {TMR4_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;}
121 static inline void IGN7_TIMER_DISABLE(void) {TMR4_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;}
122 static inline void IGN8_TIMER_DISABLE(void) {TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;}
123
124 //Bus Clock is 150Mhz @ 600 Mhz CPU. Need to handle this dynamically in the future for other frequencies
125 //#define TMR_PRESCALE 128
126 //#define MAX_TIMER_PERIOD ((65535 * 1000000ULL) / (F_BUS_ACTUAL / TMR_PRESCALE)) //55923 @ 600Mhz.
127 #define MAX_TIMER_PERIOD 55923UL
128 #define uS_TO_TIMER_COMPARE(uS) ((uS * 75UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
129 /*
130 To calculate the above uS_TO_TIMER_COMPARE
131 Choose number of bit of precision. Eg: 6
132 Divide 2^6 by the time per tick (0.853333) = 75
133 Multiply and bitshift back by the precision: (uS * 75) >> 6
134 */
135
136/*
137***********************************************************************************************************
138* Auxiliaries
139*/
140 #define ENABLE_BOOST_TIMER() PIT_TCTRL1 |= PIT_TCTRL_TEN
141 #define DISABLE_BOOST_TIMER() PIT_TCTRL1 &= ~PIT_TCTRL_TEN
142
143 #define ENABLE_VVT_TIMER() PIT_TCTRL2 |= PIT_TCTRL_TEN
144 #define DISABLE_VVT_TIMER() PIT_TCTRL2 &= ~PIT_TCTRL_TEN
145
146 //Ran out of timers, this most likely won't work. This should be possible to implement with the GPT timer.
147 #define ENABLE_FAN_TIMER() TMR3_CSCTRL1 |= TMR_CSCTRL_TCF2EN
148 #define DISABLE_FAN_TIMER() TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF2EN
149
150 #define BOOST_TIMER_COMPARE PIT_LDVAL1
151 #define BOOST_TIMER_COUNTER 0
152 #define VVT_TIMER_COMPARE PIT_LDVAL2
153 #define VVT_TIMER_COUNTER 0
154
155 //these probaply need to be PIT_LDVAL something???
156 #define FAN_TIMER_COMPARE TMR3_COMP22
157 #define FAN_TIMER_COUNTER TMR3_CNTR1
158
159/*
160***********************************************************************************************************
161* Idle
162*/
163 #define IDLE_COUNTER 0
164 #define IDLE_COMPARE PIT_LDVAL0
165
166 #define IDLE_TIMER_ENABLE() PIT_TCTRL0 |= PIT_TCTRL_TEN
167 #define IDLE_TIMER_DISABLE() PIT_TCTRL0 &= ~PIT_TCTRL_TEN
168
169/*
170***********************************************************************************************************
171* CAN / Second serial
172*/
173 #define USE_SERIAL3
174 #define secondarySerial_AVAILABLE
175 #define SECONDARY_SERIAL_T HardwareSerial
176
177 #include <FlexCAN_T4.h>
178 /*
179 //These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
180 extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
181 extern FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can1;
182 extern FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> Can2;
183 */
184 #define NATIVE_CAN_AVAILABLE //Disable for now as it causes lockup
185
186#endif //CORE_TEENSY
187#endif //TEENSY41_H
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:348