rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
tunerstudio_io_serial.cpp
Go to the documentation of this file.
1/**
2 * Implementation for hardware-serial TunerStudio ports
3 */
4
5#include "tunerstudio_io.h"
6
7#if defined(TS_PRIMARY_UxART_PORT) || defined(TS_SECONDARY_UxART_PORT)
8#if HAL_USE_SERIAL
9void SerialTsChannel::start(uint32_t baud) {
10 SerialConfig cfg = {
11 #if EFI_PROD_CODE
12 .speed = baud,
13 .cr1 = 0,
14 .cr2 = USART_CR2_STOP1_BITS,
15 .cr3 = 0
16 #endif // EFI_PROD_CODE
17 };
18
19 sdStart(m_driver, &cfg);
20}
21
23 sdStop(m_driver);
24}
25
26void SerialTsChannel::write(const uint8_t* buffer, size_t size, bool /*isEndOfPacket*/) {
27 size_t transferred = chnWriteTimeout(m_driver, buffer, size, BINARY_IO_TIMEOUT);
28 bytesOut += transferred;
29}
30
31size_t SerialTsChannel::readTimeout(uint8_t* buffer, size_t size, int timeout) {
32 size_t transferred = chnReadTimeout(m_driver, buffer, size, timeout);
33 bytesIn += transferred;
34 return transferred;
35}
36
37#endif // HAL_USE_SERIAL
38
39#if HAL_USE_UART
40
41void UartTsChannel::start(uint32_t baud) {
42 m_config = {
43 .txend1_cb = NULL,
44 .txend2_cb = NULL,
45 .rxend_cb = NULL,
46 .rxchar_cb = NULL,
47 .rxerr_cb = NULL,
48 .timeout_cb = NULL,
49#if defined(STM32F7XX)
50 .timeout = 0,
51#endif
52 .speed = baud,
53 .cr1 = 0,
54 .cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN,
55 .cr3 = 0,
56#if defined(STM32F4XX) || defined(CPU_MKE16F512VLH16)
57 .rxhalf_cb = NULL
58#endif
59 };
60
61 uartStart(m_driver, &m_config);
62}
63
65 uartStop(m_driver);
66}
67
68void UartTsChannel::write(const uint8_t* buffer, size_t size, bool) {
69 size_t transferred = uartSendTimeout(m_driver, &size, buffer, BINARY_IO_TIMEOUT);
70 bytesOut += transferred;
71}
72
73size_t UartTsChannel::readTimeout(uint8_t* buffer, size_t size, int timeout) {
74 // nasty in/out parameter approach:
75 // in entry: number of data frames to receive
76 // on exit the number of frames actually received
77 uartReceiveTimeout(m_driver, &size, buffer, timeout);
78 bytesIn += size;
79 return size;
80}
81#endif // HAL_USE_UART
82#endif // defined(TS_PRIMARY_UxART_PORT) || defined(TS_SECONDARY_UxART_PORT)
SerialDriver *const m_driver
void write(const uint8_t *buffer, size_t size, bool isEndOfPacket) override
void start(uint32_t baud) override
size_t readTimeout(uint8_t *buffer, size_t size, int timeout) override
UARTDriver *const m_driver
UARTConfig m_config
void start(uint32_t baud) override
size_t readTimeout(uint8_t *buffer, size_t size, int timeout) override
void write(const uint8_t *buffer, size_t size, bool isEndOfPacket) override
uartcb_t txend1_cb
End of transmission buffer callback.
composite packet size
static BigBufferHandle buffer