2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 #include "drivers/time.h"
21 #include "interface/msp.h"
23 // Each MSP port requires state and a receive buffer, revisit this default if someone needs more than 3 MSP ports.
24 #define MAX_MSP_PORT_COUNT 3
36 MSP_HEADER_V2_OVER_V1
,
37 MSP_PAYLOAD_V2_OVER_V1
,
38 MSP_CHECKSUM_V2_OVER_V1
,
41 MSP_PAYLOAD_V2_NATIVE
,
42 MSP_CHECKSUM_V2_NATIVE
,
53 MSP_EVALUATE_NON_MSP_DATA
,
55 } mspEvaluateNonMspData_e
;
59 MSP_PENDING_BOOTLOADER
,
61 } mspPendingSystemRequest_e
;
63 #define MSP_PORT_INBUF_SIZE 192
66 #define MSP_PORT_DATAFLASH_BUFFER_SIZE 1024
68 #define MSP_PORT_DATAFLASH_BUFFER_SIZE 4096
70 #define MSP_PORT_DATAFLASH_INFO_SIZE 16
71 #define MSP_PORT_OUTBUF_SIZE (MSP_PORT_DATAFLASH_BUFFER_SIZE + MSP_PORT_DATAFLASH_INFO_SIZE)
73 #define MSP_PORT_OUTBUF_SIZE 256
76 typedef struct __attribute__((packed
)) {
81 typedef struct __attribute__((packed
)) {
85 typedef struct __attribute__((packed
)) {
91 #define MSP_MAX_HEADER_SIZE 9
94 typedef struct mspPort_s
{
95 struct serialPort_s
*port
; // null when port unused.
96 timeMs_t lastActivityMs
;
97 mspPendingSystemRequest_e pendingRequest
;
99 mspPacketType_e packetType
;
100 uint8_t inBuf
[MSP_PORT_INBUF_SIZE
];
103 mspVersion_e mspVersion
;
104 uint_fast16_t offset
;
105 uint_fast16_t dataSize
;
110 void mspSerialInit(void);
111 bool mspSerialWaiting(void);
112 void mspSerialProcess(mspEvaluateNonMspData_e evaluateNonMspData
, mspProcessCommandFnPtr mspProcessCommandFn
, mspProcessReplyFnPtr mspProcessReplyFn
);
113 void mspSerialAllocatePorts(void);
114 void mspSerialReleasePortIfAllocated(struct serialPort_s
*serialPort
);
115 int mspSerialPush(uint8_t cmd
, uint8_t *data
, int datalen
, mspDirection_e direction
);
116 uint32_t mspSerialTxBytesFree(void);