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