2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file tunerstudio_io.h
|
2020-05-25 09:55:26 -07:00
|
|
|
* @file TS protocol commands and methods are here
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
* @date Mar 8, 2015
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2020-04-01 16:00:56 -07:00
|
|
|
#pragma once
|
2018-09-16 19:25:17 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#include "usbconsole.h"
|
|
|
|
#include "pin_repository.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PROTOCOL "001"
|
|
|
|
|
|
|
|
#define TS_RESPONSE_OK 0x00
|
|
|
|
#define TS_RESPONSE_BURN_OK 0x04
|
|
|
|
#define TS_RESPONSE_COMMAND_OK 0x07
|
|
|
|
|
|
|
|
#define TS_RESPONSE_UNDERRUN 0x80
|
|
|
|
#define TS_RESPONSE_CRC_FAILURE 0x82
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TS_PLAIN = 0,
|
|
|
|
TS_CRC = 1
|
|
|
|
} ts_response_format_e;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
BaseChannel * channel;
|
2017-05-23 10:10:43 -07:00
|
|
|
uint8_t writeBuffer[7]; // size(2 bytes) + response(1 byte) + crc32 (4 bytes)
|
2015-08-22 10:01:35 -07:00
|
|
|
/**
|
2017-06-20 21:16:19 -07:00
|
|
|
* See 'blockingFactor' in rusefi.ini
|
2015-08-22 10:01:35 -07:00
|
|
|
*/
|
2016-12-29 18:02:50 -08:00
|
|
|
char crcReadBuffer[BLOCKING_FACTOR + 30];
|
2015-07-10 06:01:56 -07:00
|
|
|
} ts_channel_s;
|
|
|
|
|
2017-05-23 10:10:43 -07:00
|
|
|
// See uart_dma_s
|
|
|
|
#define TS_FIFO_BUFFER_SIZE (BLOCKING_FACTOR + 30)
|
|
|
|
// This must be a power of 2!
|
|
|
|
#define TS_DMA_BUFFER_SIZE 32
|
|
|
|
|
|
|
|
// struct needed for async DMA transfer mode (see TS_UART_DMA_MODE)
|
|
|
|
typedef struct {
|
|
|
|
// circular DMA buffer
|
|
|
|
uint8_t dmaBuffer[TS_DMA_BUFFER_SIZE];
|
|
|
|
// current read position for the DMA buffer
|
|
|
|
volatile int readPos;
|
|
|
|
// secondary FIFO buffer for async. transfer
|
|
|
|
uint8_t buffer[TS_FIFO_BUFFER_SIZE];
|
|
|
|
// input FIFO Rx queue
|
|
|
|
input_queue_t fifoRxQueue;
|
|
|
|
} uart_dma_s;
|
|
|
|
|
2019-01-05 04:55:21 -08:00
|
|
|
// These commands are used exclusively by the rusEfi console
|
2016-12-22 11:02:38 -08:00
|
|
|
#define TS_TEST_COMMAND 't' // 0x74
|
2019-01-05 04:55:21 -08:00
|
|
|
#define TS_GET_TEXT 'G' // 0x47
|
2019-06-17 09:18:55 -07:00
|
|
|
#define TS_GET_FILE_RANGE '2' // 0x32
|
2019-01-05 04:55:21 -08:00
|
|
|
#define TS_EXECUTE 'E' // 0x45
|
2019-06-17 09:18:55 -07:00
|
|
|
#define TS_GET_STRUCT '9' // 0x39
|
2019-01-05 04:55:21 -08:00
|
|
|
|
|
|
|
// These commands are used by TunerStudio and the rusEfi console
|
|
|
|
#define TS_HELLO_COMMAND 'S' // 0x53 queryCommand
|
2017-05-26 20:02:13 -07:00
|
|
|
#define TS_OUTPUT_COMMAND 'O' // 0x4F ochGetCommand
|
2016-12-22 11:02:38 -08:00
|
|
|
#define TS_READ_COMMAND 'R' // 0x52
|
|
|
|
#define TS_PAGE_COMMAND 'P' // 0x50
|
|
|
|
#define TS_COMMAND_F 'F' // 0x46
|
2017-05-26 20:02:13 -07:00
|
|
|
#define TS_GET_FIRMWARE_VERSION 'V' // versionInfo
|
2020-05-20 19:15:47 -07:00
|
|
|
#define TS_GET_CONFIG_ERROR 'e' // returns getFirmwareError(), works together with ind_hasFatalError
|
2019-07-06 17:48:58 -07:00
|
|
|
|
|
|
|
// High speed logger commands
|
2020-05-25 10:12:15 -07:00
|
|
|
#define TS_SET_LOGGER_SWITCH 'l'
|
|
|
|
#define TS_GET_LOGGER_GET_BUFFER 'L'
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-14 23:40:51 -07:00
|
|
|
// Performance tracing
|
|
|
|
#define TS_PERF_TRACE_BEGIN 'r'
|
|
|
|
#define TS_PERF_TRACE_GET_BUFFER 'b'
|
|
|
|
|
2017-05-26 20:02:13 -07:00
|
|
|
#define TS_SINGLE_WRITE_COMMAND 'W' // 0x57 pageValueWrite
|
|
|
|
#define TS_CHUNK_WRITE_COMMAND 'C' // 0x43 pageChunkWrite
|
|
|
|
#define TS_BURN_COMMAND 'B' // 0x42 burnCommand
|
2016-12-22 11:02:38 -08:00
|
|
|
#define TS_IO_TEST_COMMAND 'w' // 0x77
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-12-22 11:02:38 -08:00
|
|
|
#define TS_CRC_CHECK_COMMAND 'k' // 0x6B
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#define CRC_VALUE_SIZE 4
|
|
|
|
// todo: double-check this
|
|
|
|
#define CRC_WRAPPING_SIZE (CRC_VALUE_SIZE + 3)
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if HAL_USE_SERIAL_USB
|
2019-04-01 11:18:21 -07:00
|
|
|
#define CONSOLE_USB_DEVICE SDU1
|
|
|
|
#endif /* HAL_USE_SERIAL_USB */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-23 10:10:43 -07:00
|
|
|
void startTsPort(ts_channel_s *tsChannel);
|
2017-06-04 05:48:53 -07:00
|
|
|
bool stopTsPort(ts_channel_s *tsChannel);
|
2017-05-23 10:10:43 -07:00
|
|
|
|
|
|
|
// that's 1 second
|
2019-01-28 17:00:17 -08:00
|
|
|
#define BINARY_IO_TIMEOUT TIME_MS2I(1000)
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-23 11:54:40 -07:00
|
|
|
// that's 1 second
|
2019-01-28 17:00:17 -08:00
|
|
|
#define SR5_READ_TIMEOUT TIME_MS2I(1000)
|
2017-05-23 11:37:03 -07:00
|
|
|
|
|
|
|
void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size);
|
|
|
|
void sr5WriteCrcPacket(ts_channel_s *tsChannel, const uint8_t responseCode, const void *buf, const uint16_t size);
|
|
|
|
void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const uint8_t * buffer, int size);
|
|
|
|
int sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size);
|
2017-05-30 11:08:12 -07:00
|
|
|
int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout);
|
2019-04-01 11:18:21 -07:00
|
|
|
bool sr5IsReady(ts_channel_s *tsChannel);
|
2015-07-10 06:01:56 -07:00
|
|
|
|