Skip to content

Commit

Permalink
uartbone: add -h arg and compile+run it in CI
Browse files Browse the repository at this point in the history
-h prints usage/help and returns 0 (success).
In CI so far we just compile the Linux CLI and runs it with -h
  • Loading branch information
fallen committed Dec 27, 2023
1 parent d12f8b7 commit e36d483
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ jobs:
run: |
nextpnr-ecp5 --version
yosys --version
pipenv run python3 ./sucrela.py --build
pipenv run python3 ./sucrela.py --build
- name: Build the software
run: |
cd software/libuartbone
make
./uartbone_cli -h
33 changes: 24 additions & 9 deletions software/libuartbone/linux_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ int get_reg_addr(FILE *csv, char *reg_name, uint32_t *res) {
return 0;
}

void print_usage(char *prog_name) {
printf("usage: %s uart_port [-V] [-b baudrate] [-r addr|reg_name] [-w addr|reg_name -v value] [-i] [-a addr_width]\n", prog_name);
}

int main(int argc, char **argv) {
struct uartbone_ctx ctx;
char ident_str[256];
Expand All @@ -95,13 +99,11 @@ int main(int argc, char **argv) {
char *addr_string = NULL;
uint32_t res, val;
char *prog_name = argv[0];
char *uart_port = argv[1];
char *uart_port = NULL;
char *csv_file = NULL;
FILE *csv;

optind = 2;

while ((opt = getopt(argc, argv, ":w:r:b:a:v:c:Vi")) != -1) {
while ((opt = getopt(argc, argv, ":w:r:b:a:v:c:u:Vih")) != -1) {
switch (opt) {
case 'r':
char *endptr;
Expand All @@ -124,32 +126,45 @@ int main(int argc, char **argv) {
case 'b':
baudrate = strtol(optarg, &endptr, 0);
if (errno != 0 || endptr == optarg)
goto print_usage;
goto err_print_usage;
break;
case 'a':
addr_width = strtol(optarg, &endptr, 0);
if (errno != 0 || endptr == optarg)
goto print_usage;
goto err_print_usage;
break;
case 'c':
csv_file = optarg;
break;
case 'u':
uart_port = optarg;
break;
case 'V':
verbose = true;
break;
case 'v':
val = strtol(optarg, &endptr, 0);
if (errno != 0 || endptr == optarg)
goto print_usage;
goto err_print_usage;
break;
case 'h':
print_usage(prog_name);
return 0;
break;
case '?':
default:
print_usage:
printf("usage: %s uart_port [-V] [-b baudrate] [-r addr|reg_name] [-w addr|reg_name -v value] [-i] [-a addr_width]\n", prog_name);
err_print_usage:
print_usage(prog_name);
return -1;
}
}

if (!uart_port) {
printf("You must specify an uart port using -u uart_port\n");
print_usage(prog_name);
return -1;
}

uartbone_unix_init(&ctx, uart_port, baudrate, addr_width);

if (!ctx.open) {
Expand Down

0 comments on commit e36d483

Please sign in to comment.