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#if false
42static constexpr uint8_t A0 = 0U;
43static constexpr uint8_t A1 = 0U;
44static constexpr uint8_t A2 = 0U;
45static constexpr uint8_t A3 = 0U;
46static constexpr uint8_t A5 = 0U;
47static constexpr uint8_t A6 = 0U;
48static constexpr uint8_t A7 = 0U;
49#endif
50static constexpr uint8_t A8 = 0U;
51static constexpr uint8_t A9 = 0U;
52static constexpr uint8_t A10 = 0U;
53static constexpr uint8_t A11 = 0U;
54static constexpr uint8_t A12 = 0U;
55static constexpr uint8_t A13 = 0U;
56static constexpr uint8_t A14 = 0U;
57static constexpr uint8_t A15 = 0U;
58
59#define PWM_FAN_AVAILABLE
60
61/*
62***********************************************************************************************************
63* Schedules
64*/
65#define DEFINE_TIMER_VARS(Prefix, index, array) \
66 static inline void Prefix##index##_TIMER_ENABLE(void) { array[index-1].enableTimer(); } \
67 static inline void Prefix##index##_TIMER_DISABLE(void) { array[index-1].disableTimer(); } \
68 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COUNTER = array[index-1].counter; \
69 static std::atomic<software_timer_t::counter_t>& Prefix##index##_COMPARE = array[index-1].compare;
70
71extern std::array<software_timer_t, INJ_CHANNELS> fuelTimers;
72
73DEFINE_TIMER_VARS(FUEL, 1, fuelTimers)
74DEFINE_TIMER_VARS(FUEL, 2, fuelTimers)
75DEFINE_TIMER_VARS(FUEL, 3, fuelTimers)
76DEFINE_TIMER_VARS(FUEL, 4, fuelTimers)
77DEFINE_TIMER_VARS(FUEL, 5, fuelTimers)
78DEFINE_TIMER_VARS(FUEL, 6, fuelTimers)
79DEFINE_TIMER_VARS(FUEL, 7, fuelTimers)
80DEFINE_TIMER_VARS(FUEL, 8, fuelTimers)
81
82extern std::array<software_timer_t, IGN_CHANNELS> ignitionTimers;
83
84DEFINE_TIMER_VARS(IGN, 1, ignitionTimers)
85DEFINE_TIMER_VARS(IGN, 2, ignitionTimers)
86DEFINE_TIMER_VARS(IGN, 3, ignitionTimers)
87DEFINE_TIMER_VARS(IGN, 4, ignitionTimers)
88DEFINE_TIMER_VARS(IGN, 5, ignitionTimers)
89DEFINE_TIMER_VARS(IGN, 6, ignitionTimers)
90DEFINE_TIMER_VARS(IGN, 7, ignitionTimers)
91DEFINE_TIMER_VARS(IGN, 8, ignitionTimers)
92
93/*
94***********************************************************************************************************
95* Auxiliaries
96*/
97
98extern software_timer_t boostTimer;
99#define ENABLE_BOOST_TIMER() boostTimer.enableTimer()
100#define DISABLE_BOOST_TIMER() boostTimer.disableTimer()
101#define BOOST_TIMER_COMPARE boostTimer.compare
102#define BOOST_TIMER_COUNTER boostTimer.counter
103
104extern software_timer_t vvtTimer;
105#define ENABLE_VVT_TIMER() vvtTimer.enableTimer()
106#define DISABLE_VVT_TIMER() vvtTimer.disableTimer()
107#define VVT_TIMER_COMPARE vvtTimer.compare
108#define VVT_TIMER_COUNTER vvtTimer.counter
109
110extern software_timer_t fanTimer;
111#define ENABLE_FAN_TIMER() fanTimer.enableTimer()
112#define DISABLE_FAN_TIMER() fanTimer.disableTimer()
113#define FAN_TIMER_COMPARE fanTimer.compare
114#define FAN_TIMER_COUNTER fanTimer.counter
115
116/*
117***********************************************************************************************************
118* Idle
119*/
120extern software_timer_t idleTimer;
121#define IDLE_TIMER_ENABLE() idleTimer.enableTimer()
122#define IDLE_TIMER_DISABLE() idleTimer.disableTimer()
123#define IDLE_COUNTER idleTimer.counter
124#define IDLE_COMPARE idleTimer.compare
125
126#define ATOMIC() \
127 for ( \
128 struct { TickEventGuard guard; uint8_t done = 1; } loopGuard; \
129 loopGuard.done; loopGuard.done = 0U )
130
131#if !defined(max)
132template<typename _Tp>
133constexpr const _Tp& max(const _Tp& __a, const _Tp& __b) {
134 if (__b > __a) {
135 return __b;
136 }
137 return __a;
138}
139#endif
140#if !defined(min)
141template<typename _Tp>
142constexpr const _Tp& min(const _Tp& __a, const _Tp& __b) {
143 if (__b < __a) {
144 return __b;
145 }
146 return __a;
147}
148#endif
149
150/*
151***********************************************************************************************************
152* CAN / Second serial
153*/
154#define SECONDARY_SERIAL_T decltype(Serial)
155
156#define RTC_LIB_H <time.h>
157
158using boardInputPin_t = inputPin_t;
159using boardOutputPin_t = outputPin_t;
160
162constexpr uint8_t ANALOG_PINS[] = { _ANALOG_PINS_A0_A14 };
163
164#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 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