Speeduino
Loading...
Searching...
No Matches
board_teensy35.h
Go to the documentation of this file.
1#ifndef TEENSY35_H
2#define TEENSY35_H
3#if defined(CORE_TEENSY) && defined(CORE_TEENSY35)
4
5/*
6***********************************************************************************************************
7* General
8*/
9 void initBoard();
11 void doSystemReset();
12 void jumpToBootloader();
14 #define PORT_TYPE uint8_t //Size of the port variables
15 #define PINMASK_TYPE uint8_t
16 #define COMPARE_TYPE uint16_t
17 #define COUNTER_TYPE uint16_t
18 #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)
19 #define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
20 #define SD_LOGGING //SD logging enabled by default for Teensy 3.5 as it has the slot built in
21 #define BOARD_MAX_DIGITAL_PINS 57
22 #define BOARD_MAX_IO_PINS 57
23 #define BOARD_MAX_ADC_PINS 26 //Number of analog pins
24 #ifdef USE_SPI_EEPROM
25 #define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
27 #else
28 #define EEPROM_LIB_H <EEPROM.h>
29 typedef int eeprom_address_t;
30 #endif
31 #define RTC_ENABLED
32 #define RTC_LIB_H "TimeLib.h"
33 #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
34
35 #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()
36 #define PWM_FAN_AVAILABLE
37 #define pinIsReserved(pin) ( ((pin) == 0) || ((pin) == 1) || ((pin) == 3) || ((pin) == 4) ) //Forbidden pins like USB
38
39/*
40***********************************************************************************************************
41* Schedules
42*/
43 //shawnhymel.com/661/learning-the-teensy-lc-interrupt-service-routines/
44 #define FUEL1_COUNTER FTM0_CNT
45 #define FUEL2_COUNTER FTM0_CNT
46 #define FUEL3_COUNTER FTM0_CNT
47 #define FUEL4_COUNTER FTM0_CNT
48 #define FUEL5_COUNTER FTM3_CNT
49 #define FUEL6_COUNTER FTM3_CNT
50 #define FUEL7_COUNTER FTM3_CNT
51 #define FUEL8_COUNTER FTM3_CNT
52
53 #define IGN1_COUNTER FTM0_CNT
54 #define IGN2_COUNTER FTM0_CNT
55 #define IGN3_COUNTER FTM0_CNT
56 #define IGN4_COUNTER FTM0_CNT
57 #define IGN5_COUNTER FTM3_CNT
58 #define IGN6_COUNTER FTM3_CNT
59 #define IGN7_COUNTER FTM3_CNT
60 #define IGN8_COUNTER FTM3_CNT
61
62 #define FUEL1_COMPARE FTM0_C0V
63 #define FUEL2_COMPARE FTM0_C1V
64 #define FUEL3_COMPARE FTM0_C2V
65 #define FUEL4_COMPARE FTM0_C3V
66 #define FUEL5_COMPARE FTM3_C0V
67 #define FUEL6_COMPARE FTM3_C1V
68 #define FUEL7_COMPARE FTM3_C2V
69 #define FUEL8_COMPARE FTM3_C3V
70
71 #define IGN1_COMPARE FTM0_C4V
72 #define IGN2_COMPARE FTM0_C5V
73 #define IGN3_COMPARE FTM0_C6V
74 #define IGN4_COMPARE FTM0_C7V
75 #define IGN5_COMPARE FTM3_C4V
76 #define IGN6_COMPARE FTM3_C5V
77 #define IGN7_COMPARE FTM3_C6V
78 #define IGN8_COMPARE FTM3_C7V
79
80 static inline void FUEL1_TIMER_ENABLE(void) {FTM0_C0SC |= FTM_CSC_CHIE;} //Write 1 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control
81 static inline void FUEL2_TIMER_ENABLE(void) {FTM0_C1SC |= FTM_CSC_CHIE;}
82 static inline void FUEL3_TIMER_ENABLE(void) {FTM0_C2SC |= FTM_CSC_CHIE;}
83 static inline void FUEL4_TIMER_ENABLE(void) {FTM0_C3SC |= FTM_CSC_CHIE;}
84 static inline void FUEL5_TIMER_ENABLE(void) {FTM3_C0SC |= FTM_CSC_CHIE;}
85 static inline void FUEL6_TIMER_ENABLE(void) {FTM3_C1SC |= FTM_CSC_CHIE;}
86 static inline void FUEL7_TIMER_ENABLE(void) {FTM3_C2SC |= FTM_CSC_CHIE;}
87 static inline void FUEL8_TIMER_ENABLE(void) {FTM3_C3SC |= FTM_CSC_CHIE;}
88
89 static inline void FUEL1_TIMER_DISABLE(void) {FTM0_C0SC &= ~FTM_CSC_CHIE;} //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control
90 static inline void FUEL2_TIMER_DISABLE(void) {FTM0_C1SC &= ~FTM_CSC_CHIE;}
91 static inline void FUEL3_TIMER_DISABLE(void) {FTM0_C2SC &= ~FTM_CSC_CHIE;}
92 static inline void FUEL4_TIMER_DISABLE(void) {FTM0_C3SC &= ~FTM_CSC_CHIE;}
93 static inline void FUEL5_TIMER_DISABLE(void) {FTM3_C0SC &= ~FTM_CSC_CHIE;} //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control
94 static inline void FUEL6_TIMER_DISABLE(void) {FTM3_C1SC &= ~FTM_CSC_CHIE;}
95 static inline void FUEL7_TIMER_DISABLE(void) {FTM3_C2SC &= ~FTM_CSC_CHIE;}
96 static inline void FUEL8_TIMER_DISABLE(void) {FTM3_C3SC &= ~FTM_CSC_CHIE;}
97
98 static inline void IGN1_TIMER_ENABLE(void) {FTM0_C4SC |= FTM_CSC_CHIE;}
99 static inline void IGN2_TIMER_ENABLE(void) {FTM0_C5SC |= FTM_CSC_CHIE;}
100 static inline void IGN3_TIMER_ENABLE(void) {FTM0_C6SC |= FTM_CSC_CHIE;}
101 static inline void IGN4_TIMER_ENABLE(void) {FTM0_C7SC |= FTM_CSC_CHIE;}
102 static inline void IGN5_TIMER_ENABLE(void) {FTM3_C4SC |= FTM_CSC_CHIE;}
103 static inline void IGN6_TIMER_ENABLE(void) {FTM3_C5SC |= FTM_CSC_CHIE;}
104 static inline void IGN7_TIMER_ENABLE(void) {FTM3_C6SC |= FTM_CSC_CHIE;}
105 static inline void IGN8_TIMER_ENABLE(void) {FTM3_C7SC |= FTM_CSC_CHIE;}
106
107 static inline void IGN1_TIMER_DISABLE(void) {FTM0_C4SC &= ~FTM_CSC_CHIE;}
108 static inline void IGN2_TIMER_DISABLE(void) {FTM0_C5SC &= ~FTM_CSC_CHIE;}
109 static inline void IGN3_TIMER_DISABLE(void) {FTM0_C6SC &= ~FTM_CSC_CHIE;}
110 static inline void IGN4_TIMER_DISABLE(void) {FTM0_C7SC &= ~FTM_CSC_CHIE;}
111 static inline void IGN5_TIMER_DISABLE(void) {FTM3_C4SC &= ~FTM_CSC_CHIE;}
112 static inline void IGN6_TIMER_DISABLE(void) {FTM3_C5SC &= ~FTM_CSC_CHIE;}
113 static inline void IGN7_TIMER_DISABLE(void) {FTM3_C6SC &= ~FTM_CSC_CHIE;}
114 static inline void IGN8_TIMER_DISABLE(void) {FTM3_C7SC &= ~FTM_CSC_CHIE;}
115
116 #define MAX_TIMER_PERIOD 139808UL // 2.13333333uS * 65535
117 #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.
118
119/*
120***********************************************************************************************************
121* Auxiliaries
122*/
123 #define ENABLE_BOOST_TIMER() FTM1_C0SC |= FTM_CSC_CHIE
124 #define DISABLE_BOOST_TIMER() FTM1_C0SC &= ~FTM_CSC_CHIE
125
126 #define ENABLE_VVT_TIMER() FTM1_C1SC |= FTM_CSC_CHIE
127 #define DISABLE_VVT_TIMER() FTM1_C1SC &= ~FTM_CSC_CHIE
128
129 #define ENABLE_FAN_TIMER() FTM2_C1SC |= FTM_CSC_CHIE
130 #define DISABLE_FAN_TIMER() FTM2_C1SC &= ~FTM_CSC_CHIE
131
132 #define BOOST_TIMER_COMPARE FTM1_C0V
133 #define BOOST_TIMER_COUNTER FTM1_CNT
134 #define VVT_TIMER_COMPARE FTM1_C1V
135 #define VVT_TIMER_COUNTER FTM1_CNT
136 #define FAN_TIMER_COMPARE FTM2_C1V
137 #define FAN_TIMER_COUNTER FTM2_CNT
138
139 void boostInterrupt();
140 void vvtInterrupt();
141 void fanInterrupt();
142
143/*
144***********************************************************************************************************
145* Idle
146*/
147 #define IDLE_COUNTER FTM2_CNT
148 #define IDLE_COMPARE FTM2_C0V
149
150 #define IDLE_TIMER_ENABLE() FTM2_C0SC |= FTM_CSC_CHIE
151 #define IDLE_TIMER_DISABLE() FTM2_C0SC &= ~FTM_CSC_CHIE
152
153 void idleInterrupt();
154
155/*
156***********************************************************************************************************
157* CAN / Second serial
158*/
159 #define USE_SERIAL3 // Secondary serial port to use
160 #define secondarySerial_AVAILABLE
161 #define SECONDARY_SERIAL_T HardwareSerial
162
163 #include <FlexCAN_T4.h>
164 /*
165 //These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
166#if defined(__MK64FX512__) // use for Teensy 3.5 only
167 extern FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
168 FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
169#elif defined(__MK66FX1M0__) // use for Teensy 3.6 only
170 extern FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
171 extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
172#endif
173*/
174 #define NATIVE_CAN_AVAILABLE
175#endif //CORE_TEENSY
176#endif //TEENSY35_H
void vvtInterrupt(void)
Definition auxiliaries.cpp:1146
void boostInterrupt(void)
Definition auxiliaries.cpp:1116
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:349
void idleInterrupt(void)
Definition idle.cpp:845