Speeduino
Loading...
Searching...
No Matches
board_native.h
Go to the documentation of this file.
1#pragma once
2
3#if defined(NATIVE_BOARD)
4#include <stdint.h>
5#include <array>
6#include <limits>
7#include <USBAPI.h>
8#include "../lib/ArduinoFake/SoftwareTimer.h"
9
10/*
11***********************************************************************************************************
12* General
13*/
14
19using COMPARE_TYPE = software_timer_t::counter_t;
20
22constexpr auto uS_TO_TIMER_COMPARE = software_timer_t::microsToTicks;
23
25constexpr auto ticksToMicros = software_timer_t::ticksToMicros;
26
27#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
28constexpr uint16_t BLOCKING_FACTOR = 121;
29constexpr uint16_t TABLE_BLOCKING_FACTOR = 64;
30#if !defined(IGN_CHANNELS)
31#warning Using default IGN_CHANNELS
32#define IGN_CHANNELS 8
33#endif
34#if !defined(INJ_CHANNELS)
35#warning Using default INJ_CHANNELS
36#define INJ_CHANNELS 8
37#endif
38#define TS_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)
39
40#define BOARD_MAX_DIGITAL_PINS NUM_DIGITAL_PINS
41#define BOARD_MAX_IO_PINS NUM_DIGITAL_PINS
42
43static inline bool pinIsReserved(uint8_t pin) { return pin==0U; } //Forbidden pins like USB on other boards
44
45#define PWM_FAN_AVAILABLE
46
47/*
48***********************************************************************************************************
49* Schedules
50*/
51#define DEFINE_TIMER_VARS(Prefix, index, array) \
52 static inline void Prefix##index##_TIMER_ENABLE(void) { array[index-1].enableTimer(); } \
53 static inline void Prefix##index##_TIMER_DISABLE(void) { array[index-1].disableTimer(); } \
54 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COUNTER = array[index-1].counter; \
55 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COMPARE = array[index-1].compare;
56
57extern std::array<software_timer_t, INJ_CHANNELS> fuelTimers;
58
59DEFINE_TIMER_VARS(FUEL, 1, fuelTimers)
60#if INJ_CHANNELS>=2
61DEFINE_TIMER_VARS(FUEL, 2, fuelTimers)
62#endif
63#if INJ_CHANNELS>=3
64DEFINE_TIMER_VARS(FUEL, 3, fuelTimers)
65#endif
66#if INJ_CHANNELS>=4
67DEFINE_TIMER_VARS(FUEL, 4, fuelTimers)
68#endif
69#if INJ_CHANNELS>=5
70DEFINE_TIMER_VARS(FUEL, 5, fuelTimers)
71#endif
72#if INJ_CHANNELS>=6
73DEFINE_TIMER_VARS(FUEL, 6, fuelTimers)
74#endif
75#if INJ_CHANNELS>=7
76DEFINE_TIMER_VARS(FUEL, 7, fuelTimers)
77#endif
78#if INJ_CHANNELS>=8
79DEFINE_TIMER_VARS(FUEL, 8, fuelTimers)
80#endif
81
82extern std::array<software_timer_t, IGN_CHANNELS> ignitionTimers;
83
84DEFINE_TIMER_VARS(IGN, 1, ignitionTimers)
85#if IGN_CHANNELS>=2
86DEFINE_TIMER_VARS(IGN, 2, ignitionTimers)
87#endif
88#if IGN_CHANNELS>=3
89DEFINE_TIMER_VARS(IGN, 3, ignitionTimers)
90#endif
91#if IGN_CHANNELS>=4
92DEFINE_TIMER_VARS(IGN, 4, ignitionTimers)
93#endif
94#if IGN_CHANNELS>=5
95DEFINE_TIMER_VARS(IGN, 5, ignitionTimers)
96#endif
97#if IGN_CHANNELS>=6
98DEFINE_TIMER_VARS(IGN, 6, ignitionTimers)
99#endif
100#if IGN_CHANNELS>=7
101DEFINE_TIMER_VARS(IGN, 7, ignitionTimers)
102#endif
103#if IGN_CHANNELS>=8
104DEFINE_TIMER_VARS(IGN, 8, ignitionTimers)
105#endif
106
107/*
108***********************************************************************************************************
109* Auxiliaries
110*/
111
112extern software_timer_t boostTimer;
113#define ENABLE_BOOST_TIMER() boostTimer.enableTimer()
114#define DISABLE_BOOST_TIMER() boostTimer.disableTimer()
115#define BOOST_TIMER_COMPARE boostTimer.compare
116#define BOOST_TIMER_COUNTER boostTimer.counter
117
118extern software_timer_t vvtTimer;
119#define ENABLE_VVT_TIMER() vvtTimer.enableTimer()
120#define DISABLE_VVT_TIMER() vvtTimer.disableTimer()
121#define VVT_TIMER_COMPARE vvtTimer.compare
122#define VVT_TIMER_COUNTER vvtTimer.counter
123
124extern software_timer_t fanTimer;
125#define ENABLE_FAN_TIMER() fanTimer.enableTimer()
126#define DISABLE_FAN_TIMER() fanTimer.disableTimer()
127#define FAN_TIMER_COMPARE fanTimer.compare
128#define FAN_TIMER_COUNTER fanTimer.counter
129
130/*
131***********************************************************************************************************
132* Idle
133*/
134extern software_timer_t idleTimer;
135#define IDLE_TIMER_ENABLE() idleTimer.enableTimer()
136#define IDLE_TIMER_DISABLE() idleTimer.disableTimer()
137#define IDLE_COUNTER idleTimer.counter
138#define IDLE_COMPARE idleTimer.compare
139
140#define ATOMIC() \
141 for ( \
142 struct { TickEventGuard guard; uint8_t done = 1; } loopGuard; \
143 loopGuard.done; loopGuard.done = 0U )
144
145#if !defined(max)
146template<typename _Tp>
147constexpr const _Tp& max(const _Tp& __a, const _Tp& __b) {
148 if (__b > __a) {
149 return __b;
150 }
151 return __a;
152}
153#endif
154#if !defined(min)
155template<typename _Tp>
156constexpr const _Tp& min(const _Tp& __a, const _Tp& __b) {
157 if (__b < __a) {
158 return __b;
159 }
160 return __a;
161}
162#endif
163
164/*
165***********************************************************************************************************
166* CAN / Second serial
167*/
168#define SECONDARY_SERIAL_T decltype(Serial)
169
170#define RTC_LIB_H <time.h>
171
172class inputPin_t;
174class outputPin_t;
176
178constexpr uint8_t ANALOG_PINS[] = { _ANALOG_PINS_A0_A14 };
179
184constexpr uint8_t SERIAL_BUFFER_THRESHOLD = 0U;
185
186#endif // NATIVE_BOARD
uint16_t COMPARE_TYPE
The timer overflow type.
Definition board_avr2560.h:32
static bool pinIsReserved(uint8_t pin)
Definition board_avr2560.h:62
constexpr uint16_t BLOCKING_FACTOR
Definition board_avr2560.h:60
static constexpr uint32_t ticksToMicros(COMPARE_TYPE ticks)
Convert timer ticks to µS.
Definition board_avr2560.h:48
constexpr uint8_t SERIAL_BUFFER_THRESHOLD
When the serial buffer is filled to greater than this threshold value, the serial processing operatio...
Definition board_avr2560.h:185
constexpr uint8_t ANALOG_PINS[]
Analog pin mapping.
Definition board_avr2560.h:179
constexpr uint16_t TABLE_BLOCKING_FACTOR
Definition board_avr2560.h:61
static constexpr COMPARE_TYPE uS_TO_TIMER_COMPARE(uint32_t micros)
Convert µS to timer ticks.
Definition board_avr2560.h:40
A class for input pin operations that is faster than standard Arduino digitalRead()
Definition fastInputPin.h:10
A class for output pin operations that is faster than standard Arduino digitalWrite()
Definition fastOutputPin.h:10
A class for input pin operations.
Definition inputPin.h:14
A class for output pin operations. Must have same signature as fastOutputPin_t to allow for interchan...
Definition outputPin.h:12