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