mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #5635 from aabadie/ethos_baudrate_select
dist/tools: ethos baudrate configuration
This commit is contained in:
commit
54a1b7a4d0
82
dist/tools/ethos/ethos.c
vendored
82
dist/tools/ethos/ethos.c
vendored
@ -28,9 +28,16 @@
|
||||
|
||||
#define TRACE(x)
|
||||
|
||||
#define case_baudrate(val) \
|
||||
case val: \
|
||||
*baudrate = B ## val; \
|
||||
break
|
||||
|
||||
#define BAUDRATE_DEFAULT B115200
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: ethos <tap> <serial>\n");
|
||||
fprintf(stderr, "usage: ethos <tap> <serial> [baudrate]\n");
|
||||
}
|
||||
|
||||
static void checked_write(int handle, void *buffer, int nbyte)
|
||||
@ -267,9 +274,75 @@ static void _clear_neighbor_cache(const char *ifname)
|
||||
}
|
||||
}
|
||||
|
||||
static int _parse_baudrate(const char *arg, unsigned *baudrate)
|
||||
{
|
||||
switch(strtol(arg, (char**)NULL, 10)) {
|
||||
case 9600:
|
||||
*baudrate = B9600;
|
||||
break;
|
||||
case 19200:
|
||||
*baudrate = B19200;
|
||||
break;
|
||||
case 38400:
|
||||
*baudrate = B38400;
|
||||
break;
|
||||
case 57600:
|
||||
*baudrate = B57600;
|
||||
break;
|
||||
case 115200:
|
||||
*baudrate = B115200;
|
||||
break;
|
||||
/* the following baudrates might not be available on all platforms */
|
||||
#ifdef B234000
|
||||
case_baudrate(230400);
|
||||
#endif
|
||||
#ifdef B460800
|
||||
case_baudrate(460800);
|
||||
#endif
|
||||
#ifdef B500000
|
||||
case_baudrate(500000);
|
||||
#endif
|
||||
#ifdef B576000
|
||||
case_baudrate(576000);
|
||||
#endif
|
||||
#ifdef B921600
|
||||
case_baudrate(921600);
|
||||
#endif
|
||||
#ifdef B1000000
|
||||
case_baudrate(1000000);
|
||||
#endif
|
||||
#ifdef B1152000
|
||||
case_baudrate(1152000);
|
||||
#endif
|
||||
#ifdef B1500000
|
||||
case_baudrate(1500000);
|
||||
#endif
|
||||
#ifdef B2000000
|
||||
case_baudrate(2000000);
|
||||
#endif
|
||||
#ifdef B2500000
|
||||
case_baudrate(2500000);
|
||||
#endif
|
||||
#ifdef B3000000
|
||||
case_baudrate(3000000);
|
||||
#endif
|
||||
#ifdef B3500000
|
||||
case_baudrate(3500000);
|
||||
#endif
|
||||
#ifdef B4000000
|
||||
case_baudrate(4000000);
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char inbuf[MTU];
|
||||
unsigned baudrate = BAUDRATE_DEFAULT;
|
||||
|
||||
serial_t serial = {0};
|
||||
|
||||
@ -278,6 +351,11 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc >= 4 && _parse_baudrate(argv[3], &baudrate) == -1) {
|
||||
fprintf(stderr, "Invalid baudrate specified: %s\n", argv[3]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char ifname[IFNAMSIZ];
|
||||
strncpy(ifname, argv[1], IFNAMSIZ);
|
||||
int tap_fd = tun_alloc(ifname, IFF_TAP | IFF_NO_PI);
|
||||
@ -293,7 +371,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
set_serial_attribs(serial_fd, B115200, 0);
|
||||
set_serial_attribs(serial_fd, baudrate, 0);
|
||||
set_blocking(serial_fd, 1);
|
||||
|
||||
fd_set readfds;
|
||||
|
9
dist/tools/ethos/start_network.sh
vendored
9
dist/tools/ethos/start_network.sh
vendored
@ -32,14 +32,19 @@ start_uhcpd() {
|
||||
PORT=$1
|
||||
TAP=$2
|
||||
PREFIX=$3
|
||||
BAUDRATE=115200
|
||||
UHCPD="$(readlink -f "${ETHOS_DIR}/../uhcpd/bin")/uhcpd"
|
||||
|
||||
[ -z "${PORT}" -o -z "${TAP}" -o -z "${PREFIX}" ] && {
|
||||
echo "usage: $0 <serial-port> <tap-device> <prefix>"
|
||||
echo "usage: $0 <serial-port> <tap-device> <prefix> [baudrate]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ ! -z $4 ] && {
|
||||
BAUDRATE=$4
|
||||
}
|
||||
|
||||
trap "cleanup" INT QUIT TERM EXIT
|
||||
|
||||
|
||||
create_tap && start_uhcpd && "${ETHOS_DIR}/ethos" ${TAP} ${PORT}
|
||||
create_tap && start_uhcpd && "${ETHOS_DIR}/ethos" ${TAP} ${PORT} ${BAUDRATE}
|
||||
|
@ -17,7 +17,10 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon cc2650stk msb-430 msb-430h pca10000 pc
|
||||
ifeq (,$(filter native,$(BOARD)))
|
||||
GNRC_NETIF_NUMOF := 2
|
||||
USEMODULE += ethos gnrc_netdev2
|
||||
CFLAGS += '-DETHOS_UART=UART_DEV(0)' -DETHOS_BAUDRATE=115200 -DUSE_ETHOS_FOR_STDIO
|
||||
|
||||
# ethos baudrate can be configured from make command
|
||||
ETHOS_BAUDRATE ?= 115200
|
||||
CFLAGS += '-DETHOS_UART=UART_DEV(0)' -DETHOS_BAUDRATE=$(ETHOS_BAUDRATE) -DUSE_ETHOS_FOR_STDIO
|
||||
FEATURES_REQUIRED += periph_uart
|
||||
endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user