Skip to content

Commit

Permalink
Add set ledmode option
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw-mesa committed Oct 12, 2023
1 parent bea2911 commit a27a1ba
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
17 changes: 17 additions & 0 deletions anyio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions anyio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions eth_boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions eth_boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions lbp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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); \
Expand Down
26 changes: 20 additions & 6 deletions mesaflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#endif

#ifndef VERSION
#define VERSION "3.4.8"
#define VERSION "3.4.9"
#endif

static int device_flag;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a27a1ba

Please sign in to comment.