rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
console
binary
tunerstudio_io_serial_ports.cpp
Go to the documentation of this file.
1
/**
2
* @file This file initializes the hardware serial ports that run the TS protocol.
3
*
4
* @date Mar 26, 2021
5
*/
6
7
#include "
pch.h
"
8
9
#if (EFI_PROD_CODE || EFI_SIMULATOR) && EFI_TUNER_STUDIO
10
#include "
tunerstudio.h
"
11
#include "
tunerstudio_io.h
"
12
#include "
connector_uart_dma.h
"
13
#if HW_HELLEN
14
#include "
hellen_meta.h
"
15
#endif
// HW_HELLEN
16
17
#ifdef TS_PRIMARY_UxART_PORT
18
19
#ifndef EFI_CONSOLE_RX_BRAIN_PIN_MODE
20
#define EFI_CONSOLE_RX_BRAIN_PIN_MODE (PAL_MODE_ALTERNATE(EFI_CONSOLE_AF))
21
#endif
22
23
#ifndef EFI_CONSOLE_TX_BRAIN_PIN_MODE
24
#define EFI_CONSOLE_TX_BRAIN_PIN_MODE (PAL_MODE_ALTERNATE(EFI_CONSOLE_AF))
25
#endif
26
27
#if EFI_TS_PRIMARY_IS_SERIAL
28
SerialTsChannel
29
#elif EFI_USE_UART_DMA
30
UartDmaTsChannel
31
#else
32
UartTsChannel
33
#endif
34
primaryChannel
(TS_PRIMARY_UxART_PORT);
35
36
struct
PrimaryChannelThread :
public
TunerstudioThread
{
37
PrimaryChannelThread() :
TunerstudioThread
(
"Primary TS Channel"
) { }
38
39
TsChannelBase
*
setupChannel
() {
40
#if EFI_PROD_CODE
41
// historically the idea was that primary UART has to be very hard-coded as the last line of reliability defense
42
// as of 2022 it looks like sometimes we just need the GPIO on MRE for instance more than we need UART
43
efiSetPadMode
(
"Primary UART RX"
, EFI_CONSOLE_RX_BRAIN_PIN, EFI_CONSOLE_RX_BRAIN_PIN_MODE);
44
efiSetPadMode
(
"Primary UART TX"
, EFI_CONSOLE_TX_BRAIN_PIN, EFI_CONSOLE_TX_BRAIN_PIN_MODE);
45
#endif
/* EFI_PROD_CODE */
46
47
primaryChannel
.
start
(
engineConfiguration
->
uartConsoleSerialSpeed
);
48
49
return
&
primaryChannel
;
50
}
51
};
52
53
static
PrimaryChannelThread
primaryChannelThread
;
54
#endif
// defined(TS_PRIMARY_UxART_PORT)
55
56
#ifdef TS_SECONDARY_UxART_PORT
57
58
#ifndef TS_SERIAL_RX_BRAIN_PIN_MODE
59
#define TS_SERIAL_RX_BRAIN_PIN_MODE (PAL_MODE_ALTERNATE(TS_SERIAL_AF))
60
#endif
61
62
#ifndef TS_SERIAL_TX_BRAIN_PIN_MODE
63
#define TS_SERIAL_TX_BRAIN_PIN_MODE (PAL_MODE_ALTERNATE(TS_SERIAL_AF))
64
#endif
65
66
#if EFI_TS_SECONDARY_IS_SERIAL
67
SerialTsChannel
68
#elif EFI_USE_UART_DMA
69
UartDmaTsChannel
70
#else
71
UartTsChannel
72
#endif
73
secondaryChannel
(TS_SECONDARY_UxART_PORT);
74
75
struct
SecondaryChannelThread :
public
TunerstudioThread
{
76
SecondaryChannelThread() :
TunerstudioThread
(
"Secondary TS Channel"
) { }
77
78
TsChannelBase
*
setupChannel
() {
79
#if EFI_PROD_CODE
80
efiSetPadMode
(
"Secondary UART RX"
,
engineConfiguration
->
binarySerialRxPin
, TS_SERIAL_RX_BRAIN_PIN_MODE);
81
efiSetPadMode
(
"Secondary UART TX"
,
engineConfiguration
->
binarySerialTxPin
, TS_SERIAL_TX_BRAIN_PIN_MODE);
82
#endif
/* EFI_PROD_CODE */
83
84
secondaryChannel
.
start
(
engineConfiguration
->
tunerStudioSerialSpeed
);
85
86
return
&
secondaryChannel
;
87
}
88
};
89
90
static
SecondaryChannelThread
secondaryChannelThread
;
91
#endif
// defined(TS_SECONDARY_UxART_PORT)
92
93
void
startSerialChannels
() {
94
#if defined(TS_PRIMARY_UxART_PORT)
95
primaryChannelThread
.
start
();
96
#endif
97
98
#if defined(TS_SECONDARY_UxART_PORT)
99
// do not start thread if not configured - give user a chance to use same peripheral for kline
100
if
(
isBrainPinValid
(
engineConfiguration
->
binarySerialTxPin
)) {
101
secondaryChannelThread
.start();
102
}
103
#endif
104
}
105
106
SerialTsChannelBase
*
getBluetoothChannel
() {
107
#if defined(TS_SECONDARY_UxART_PORT)
108
// Prefer secondary channel for bluetooth
109
return
&
secondaryChannel
;
110
#elif defined(TS_PRIMARY_UxART_PORT)
111
// Use primary channel for BT if no secondary exists
112
return
&
primaryChannel
;
113
#endif
114
115
// no HW serial channels on this board, fail
116
return
nullptr
;
117
}
118
119
#endif
// EFI_PROD_CODE
efiSetPadMode
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
Definition
bootloader_main.cpp:207
SerialTsChannelBase
Definition
tunerstudio_io.h:98
SerialTsChannel
Definition
tunerstudio_io.h:107
SerialTsChannel::start
void start(uint32_t baud) override
Definition
tunerstudio_io_serial.cpp:9
TsChannelBase
Definition
tunerstudio_io.h:30
TunerstudioThread
Definition
tunerstudio.h:79
TunerstudioThread::setupChannel
virtual TsChannelBase * setupChannel()=0
UartDmaTsChannel
Definition
connector_uart_dma.h:19
UartTsChannel
Definition
tunerstudio_io.h:124
connector_uart_dma.h
engineConfiguration
static constexpr engine_configuration_s * engineConfiguration
Definition
engine_configuration.h:80
hellen_meta.h
pch.h
isBrainPinValid
bool isBrainPinValid(brain_pin_e brainPin)
Definition
pin_repository.cpp:25
engine_configuration_s::tunerStudioSerialSpeed
uint32_t tunerStudioSerialSpeed
Definition
engine_configuration_generated_structures_alphax-2chan.h:5111
engine_configuration_s::uartConsoleSerialSpeed
uint32_t uartConsoleSerialSpeed
Definition
engine_configuration_generated_structures_alphax-2chan.h:3576
engine_configuration_s::binarySerialTxPin
Gpio binarySerialTxPin
Definition
engine_configuration_generated_structures_alphax-2chan.h:3359
engine_configuration_s::binarySerialRxPin
Gpio binarySerialRxPin
Definition
engine_configuration_generated_structures_alphax-2chan.h:3363
tunerstudio.h
tunerstudio_io.h
primaryChannel
SerialTsChannel UartDmaTsChannel UartTsChannel primaryChannel(TS_PRIMARY_UxART_PORT)
primaryChannelThread
static PrimaryChannelThread primaryChannelThread
Definition
tunerstudio_io_serial_ports.cpp:53
secondaryChannelThread
static SecondaryChannelThread secondaryChannelThread
Definition
tunerstudio_io_serial_ports.cpp:90
startSerialChannels
void startSerialChannels()
Definition
tunerstudio_io_serial_ports.cpp:93
getBluetoothChannel
SerialTsChannelBase * getBluetoothChannel()
Definition
tunerstudio_io_serial_ports.cpp:106
secondaryChannel
SerialTsChannel UartDmaTsChannel UartTsChannel secondaryChannel(TS_SECONDARY_UxART_PORT)
Generated on Sat Sep 27 2025 00:10:04 for rusEFI by
1.9.8