From a27a1ba4d1fad8a9b9900ab1dd02adfec09da717 Mon Sep 17 00:00:00 2001 From: Peter Wallace Date: Wed, 11 Oct 2023 18:36:02 -0700 Subject: [PATCH] Add set ledmode option --- anyio.c | 17 +++++++++++++++++ anyio.h | 1 + eth_boards.c | 10 ++++++++++ eth_boards.h | 2 ++ lbp16.h | 6 ++++++ mesaflash.c | 26 ++++++++++++++++++++------ 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/anyio.c b/anyio.c index 65b95c2..196cc9f 100644 --- a/anyio.c +++ b/anyio.c @@ -354,6 +354,23 @@ int anyio_dev_set_remote_ip(board_t *board, char *lbp16_set_ip_addr) { } return ret; } +int anyio_dev_set_led_mode(board_t *board, char *lbp16_set_led_mode) { + int ret; + + if (board == NULL) { + return -EINVAL; + } + if ((board->type & BOARD_ETH) == 0) { + return -EPERM; + } + + ret = eth_set_led_mode(lbp16_set_led_mode); + if (ret == 0) { + printf("Board LED mode updated successfully.\n"); + printf("You must power cycle board to load updated eeprom settings.\n"); + } + return ret; +} int anyio_dev_reload(board_t *board, int fallback_flag) { if (board == NULL) { diff --git a/anyio.h b/anyio.h index 68d2095..c1abd23 100644 --- a/anyio.h +++ b/anyio.h @@ -35,6 +35,7 @@ int anyio_dev_backup_flash(board_t *board, char *bitfile_name); int anyio_dev_restore_flash(board_t *board, char *bitfile_name); int anyio_dev_program_fpga(board_t *board, char *bitfile_name); int anyio_dev_set_remote_ip(board_t *board, char *lbp16_set_ip_addr); +int anyio_dev_set_led_mode(board_t *board, char *lbp16_set_led_mode); int anyio_dev_reload(board_t *board, int fallback_flag); int anyio_dev_reset(board_t *board); void anyio_dev_print_hm2_info(board_t *board, int xml_flag); diff --git a/eth_boards.c b/eth_boards.c index e34a1e1..f126191 100644 --- a/eth_boards.c +++ b/eth_boards.c @@ -876,3 +876,13 @@ int eth_set_remote_ip(char *ip_addr) { sendto (sd, (char*) &write_ip_pck, sizeof(write_ip_pck), 0, (struct sockaddr *) &dst_addr, sizeof(dst_addr)); return 0; } + +int eth_set_led_mode(char *led_mode) { + lbp16_write_led_mode_packets write_led_pck; + u16 mode; + mode = atoi(led_mode); + LBP16_INIT_PACKET6(write_led_pck.write_ena_pck, CMD_WRITE_COMM_CTRL_ADDR16(1), COMM_CTRL_WRITE_ENA_REG, 0x5A02); + LBP16_INIT_PACKET6(write_led_pck.eth_write_led_pck, CMD_WRITE_ETH_EEPROM_ADDR16(1), ETH_EEPROM_LED_MODE_REG,mode ); + sendto (sd, (char*) &write_led_pck, sizeof(write_led_pck), 0, (struct sockaddr *) &dst_addr, sizeof(dst_addr)); + return 0; +} diff --git a/eth_boards.h b/eth_boards.h index 43e0f49..b27428b 100644 --- a/eth_boards.h +++ b/eth_boards.h @@ -31,5 +31,7 @@ int lbp16_read(u16 cmd, u32 addr, void *buffer, int size); int lbp16_write(u16 cmd, u32 addr, void *buffer, int size); void eth_socket_set_dest_ip(char *addr_name); int eth_set_remote_ip(char *ip_addr); +int eth_set_led_mode(char *led_mode); + #endif diff --git a/lbp16.h b/lbp16.h index 449da6a..2604aaa 100644 --- a/lbp16.h +++ b/lbp16.h @@ -41,6 +41,7 @@ #define FLASH_SEC_ERASE_REG 0x000C #define ETH_EEPROM_IP_REG 0x0020 +#define ETH_EEPROM_LED_MODE_REG 0x0028 #define COMM_CTRL_WRITE_ENA_REG 0x001A @@ -154,6 +155,11 @@ typedef struct { lbp16_cmd_addr_data32 eth_write_ip_pck; } lbp16_write_ip_addr_packets; +typedef struct { + lbp16_cmd_addr_data16 write_ena_pck; + lbp16_cmd_addr_data16 eth_write_led_pck; +} lbp16_write_led_mode_packets; + #define LBP16_INIT_PACKET4(packet, cmd, addr) do { \ packet.cmd_hi = LO_BYTE(cmd); \ packet.cmd_lo = HI_BYTE(cmd); \ diff --git a/mesaflash.c b/mesaflash.c index 402a19f..737b6ee 100644 --- a/mesaflash.c +++ b/mesaflash.c @@ -32,7 +32,7 @@ #endif #ifndef VERSION -#define VERSION "3.4.8" +#define VERSION "3.4.9" #endif static int device_flag; @@ -64,8 +64,11 @@ static u16 rpo_addr; static u16 wpo_addr; static u32 wpo_data; static int set_flag; +static int ipaddr_flag; +static int ledmode_flag; static int xml_flag; static char *lbp16_set_ip_addr; +static char *lbp16_set_led_mode; static int info_flag; static int verbose_flag; static char bitfile_name[255]; @@ -202,8 +205,10 @@ void print_usage() { printf(" --rpo addrs Read hostmot2 register directly at 'addrs'.\n"); printf(" --wpo addrs=data Write hostmot2 register directly at 'addrs'\n"); printf(" with 'data'.\n"); - printf(" --set ip=n.n.n.n Set board IP address in EEPROM memory to n.n.n.n (only\n"); + printf(" --set ip=n.n.n.n Set board IP address in EEPROM memory to n.n.n.n (Only\n"); printf(" Ethernet boards).\n"); + printf(" --set ledmode=n Set LED mode in EEPROM memory to n, 0 = Hostmot2, 1=Debug\n"); + printf(" Default debug is RX packet count. (Only Ethernet boards).\n"); printf(" --info Print info about configuration in 'filename'.\n"); printf(" --version Print the version.\n"); printf(" --help Print this help message.\n"); @@ -350,7 +355,15 @@ int process_cmd_line(int argc, char *argv[]) { pch = strtok(optarg, "="); pch = strtok(NULL, "="); lbp16_set_ip_addr = pch; - } else { + ipaddr_flag = 1; + } else if (strncmp(optarg, "ledmode=", 8) == 0) { + char *pch; + + pch = strtok(optarg, "="); + pch = strtok(NULL, "="); + lbp16_set_led_mode = pch; + ledmode_flag = 1; + } else { printf("Error: Unknown set command syntax, see --help for examples\n"); exit(-1); } @@ -473,7 +486,6 @@ int process_cmd_line(int argc, char *argv[]) { int main(int argc, char *argv[]) { int ret = 0; - if (argc == 1) { print_short_usage(); return 0; @@ -525,8 +537,10 @@ int main(int argc, char *argv[]) { printf("%08X\n", data); } else if (wpo_flag == 1) { board->llio.write(&(board->llio), wpo_addr, &wpo_data, sizeof(u32)); - } else if (set_flag == 1) { - ret = anyio_dev_set_remote_ip(board, lbp16_set_ip_addr); + } else if (ipaddr_flag == 1) { + ret = anyio_dev_set_remote_ip(board, lbp16_set_ip_addr); + } else if (ledmode_flag == 1) { + ret = anyio_dev_set_led_mode(board, lbp16_set_led_mode); } else if (write_flag == 1) { ret = anyio_dev_write_flash(board, bitfile_name, fallback_flag, fix_boot_flag, sha256_check_flag); if (ret == 0) {