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#include "src/pins/inputPin.h"
10#include "src/pins/outputPin.h"
11
12/*
13***********************************************************************************************************
14* General
15*/
16
21using COMPARE_TYPE = software_timer_t::counter_t;
22
24constexpr auto uS_TO_TIMER_COMPARE = software_timer_t::microsToTicks;
25
27constexpr auto ticksToMicros = software_timer_t::ticksToMicros;
28
29#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
30constexpr uint16_t BLOCKING_FACTOR = 121;
31constexpr uint16_t TABLE_BLOCKING_FACTOR = 64;
32#define IGN_CHANNELS 8
33#define INJ_CHANNELS 8
34#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)
35
36#define BOARD_MAX_DIGITAL_PINS NUM_DIGITAL_PINS
37#define BOARD_MAX_IO_PINS NUM_DIGITAL_PINS
38
39static inline bool pinIsReserved(uint8_t pin) { return pin==0U; } //Forbidden pins like USB on other boards
40
41#define PWM_FAN_AVAILABLE
42
43/*
44***********************************************************************************************************
45* Schedules
46*/
47#define DEFINE_TIMER_VARS(Prefix, index, array) \
48 static inline void Prefix##index##_TIMER_ENABLE(void) { array[index-1].enableTimer(); } \
49 static inline void Prefix##index##_TIMER_DISABLE(void) { array[index-1].disableTimer(); } \
50 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COUNTER = array[index-1].counter; \
51 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COMPARE = array[index-1].compare;
52
53extern std::array<software_timer_t, INJ_CHANNELS> fuelTimers;
54
55DEFINE_TIMER_VARS(FUEL, 1, fuelTimers)
56DEFINE_TIMER_VARS(FUEL, 2, fuelTimers)
57DEFINE_TIMER_VARS(FUEL, 3, fuelTimers)
58DEFINE_TIMER_VARS(FUEL, 4, fuelTimers)
59DEFINE_TIMER_VARS(FUEL, 5, fuelTimers)
60DEFINE_TIMER_VARS(FUEL, 6, fuelTimers)
61DEFINE_TIMER_VARS(FUEL, 7, fuelTimers)
62DEFINE_TIMER_VARS(FUEL, 8, fuelTimers)
63
64extern std::array<software_timer_t, IGN_CHANNELS> ignitionTimers;
65
66DEFINE_TIMER_VARS(IGN, 1, ignitionTimers)
67DEFINE_TIMER_VARS(IGN, 2, ignitionTimers)
68DEFINE_TIMER_VARS(IGN, 3, ignitionTimers)
69DEFINE_TIMER_VARS(IGN, 4, ignitionTimers)
70DEFINE_TIMER_VARS(IGN, 5, ignitionTimers)
71DEFINE_TIMER_VARS(IGN, 6, ignitionTimers)
72DEFINE_TIMER_VARS(IGN, 7, ignitionTimers)
73DEFINE_TIMER_VARS(IGN, 8, ignitionTimers)
74
75/*
76***********************************************************************************************************
77* Auxiliaries
78*/
79
80extern software_timer_t boostTimer;
81#define ENABLE_BOOST_TIMER() boostTimer.enableTimer()
82#define DISABLE_BOOST_TIMER() boostTimer.disableTimer()
83#define BOOST_TIMER_COMPARE boostTimer.compare
84#define BOOST_TIMER_COUNTER boostTimer.counter
85
86extern software_timer_t vvtTimer;
87#define ENABLE_VVT_TIMER() vvtTimer.enableTimer()
88#define DISABLE_VVT_TIMER() vvtTimer.disableTimer()
89#define VVT_TIMER_COMPARE vvtTimer.compare
90#define VVT_TIMER_COUNTER vvtTimer.counter
91
92extern software_timer_t fanTimer;
93#define ENABLE_FAN_TIMER() fanTimer.enableTimer()
94#define DISABLE_FAN_TIMER() fanTimer.disableTimer()
95#define FAN_TIMER_COMPARE fanTimer.compare
96#define FAN_TIMER_COUNTER fanTimer.counter
97
98/*
99***********************************************************************************************************
100* Idle
101*/
102extern software_timer_t idleTimer;
103#define IDLE_TIMER_ENABLE() idleTimer.enableTimer()
104#define IDLE_TIMER_DISABLE() idleTimer.disableTimer()
105#define IDLE_COUNTER idleTimer.counter
106#define IDLE_COMPARE idleTimer.compare
107
108#define ATOMIC() \
109 for ( \
110 struct { TickEventGuard guard; uint8_t done = 1; } loopGuard; \
111 loopGuard.done; loopGuard.done = 0U )
112
113#if !defined(max)
114template<typename _Tp>
115constexpr const _Tp& max(const _Tp& __a, const _Tp& __b) {
116 if (__b > __a) {
117 return __b;
118 }
119 return __a;
120}
121#endif
122#if !defined(min)
123template<typename _Tp>
124constexpr const _Tp& min(const _Tp& __a, const _Tp& __b) {
125 if (__b < __a) {
126 return __b;
127 }
128 return __a;
129}
130#endif
131
132/*
133***********************************************************************************************************
134* CAN / Second serial
135*/
136#define SECONDARY_SERIAL_T decltype(Serial)
137
138#define RTC_LIB_H <time.h>
139
140using boardInputPin_t = inputPin_t;
141using boardOutputPin_t = outputPin_t;
142
144constexpr uint8_t ANALOG_PINS[] = { _ANALOG_PINS_A0_A14 };
145
150constexpr uint8_t SERIAL_BUFFER_THRESHOLD = 0U;
151
152#endif // NATIVE_BOARD
uint16_t COMPARE_TYPE
The timer overflow type.
Definition board_avr2560.h:34
static bool pinIsReserved(uint8_t pin)
Definition board_avr2560.h:64
fastInputPin_t boardInputPin_t
Definition board_avr2560.h:175
constexpr uint16_t BLOCKING_FACTOR
Definition board_avr2560.h:62
static constexpr uint32_t ticksToMicros(COMPARE_TYPE ticks)
Convert timer ticks to µS.
Definition board_avr2560.h:50
fastOutputPin_t boardOutputPin_t
Definition board_avr2560.h:176
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:63
static constexpr COMPARE_TYPE uS_TO_TIMER_COMPARE(uint32_t micros)
Convert µS to timer ticks.
Definition board_avr2560.h:42