9
0
Fork 0

Add Reliable Asynchronous Transfer Protocol

This patch adds support for Reliable Asynchronous Transfer Protocol (RATP)
as described in RFC916.

Communication over RS232 is often unreliable as characters are lost or
misinterpreted. This protocol allows for a reliable packet based communication
over serial lines.

The implementation simply follows the state machine described in the RFC
text with one exception. RFC916 uses a plain checksum for the
transferred data. We decided to use CRC16 for greater robustness. Since
this is the only RFC916 implementation we currently know of interoperability
with other implementations should not matter.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
This commit is contained in:
Sascha Hauer 2015-06-03 00:38:09 +02:00
parent 51e97d11dc
commit bbdbda0a74
4 changed files with 1865 additions and 0 deletions

22
include/ratp.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __RATP_H
#define __RATP_H
struct ratp {
struct ratp_internal *internal;
int (*send)(struct ratp *, void *pkt, int len);
int (*recv)(struct ratp *, uint8_t *data);
};
int ratp_establish(struct ratp *ratp, bool active, int timeout_ms);
void ratp_close(struct ratp *ratp);
int ratp_recv(struct ratp *ratp, void **data, size_t *len);
int ratp_send(struct ratp *ratp, const void *data, size_t len);
int ratp_send_complete(struct ratp *ratp, const void *data, size_t len,
void (*complete)(void *ctx, int status), void *complete_ctx);
int ratp_poll(struct ratp *ratp);
bool ratp_closed(struct ratp *ratp);
bool ratp_busy(struct ratp *ratp);
void ratp_run_command(void);
#endif /* __RATP_H */

View File

@ -55,6 +55,14 @@ config LIBMTD
config STMP_DEVICE
bool
config RATP
select CRC16
bool
help
Reliable Asynchronous Transfer Protocol (RATP) is a protocol for reliably
transferring packets over serial links described in RFC916. This implementation
is used for controlling barebox over serial ports.
source lib/gui/Kconfig
source lib/fonts/Kconfig

View File

@ -56,3 +56,4 @@ obj-y += gcd.o
obj-y += hexdump.o
obj-$(CONFIG_FONTS) += fonts/
obj-$(CONFIG_BAREBOX_LOGO) += logo/
obj-$(CONFIG_RATP) += ratp.o

1834
lib/ratp.c Normal file

File diff suppressed because it is too large Load Diff