#include /* printf fprintf */ #include /* getopt */ #include "mts_error_codes.h" /* list of utility error codes */ #include "mts_fpga_reg.h" /* core utility functions a*/ /* -------------------------------------------------------------------------- */ /* --- MACROS & CONSTANTS --------------------------------------------------- */ #define DEFAULT_PATH 0 /* default path, points to spidev0.0 */ void usage(int argc, char *argv[]) { printf("Usage: %s -option \n", argv[0]); printf("Example\n"); printf(" %s -h See all available options and examples\n", argv[0]); printf(" %s -c Check existing FPGA version\n", argv[0]); printf(" %s -i Upgrade the FPGA on the default port using the file specified\n", argv[0]); printf(" %s -p 2 -i Upgrade the FPGA on ap2 using the file specified\n", argv[0]); printf(" %s Upgrade the FPGA on the default port and upgrade file\n", argv[0]); printf("Options\n"); printf(" -c Check FPGA Version on MTAC card\n"); printf(" -i Specify input file. Default is mtcdt-fpga-v31.hex for a MultiConnect Conduit & mtcap-fpga-v31.hex for MultiConnect Access Point\n"); printf(" -p Specify port 1 or 2. Only required for a MultiConnect Conduit when dual cards are installed\n"); printf(" -s Print FPGA versions supported by the utility\n"); } int main(int argc, char **argv) { int index; int c; int ret; char *upgrade_file; int path = DEFAULT_PATH; opterr = 0; if (argc < 2) { usage(argc, argv); return 0; } while ((c = getopt(argc, argv, "shp:ci:")) != -1) switch (c) { case 's': print_supported_versions(); return 0; case 'h': usage(argc, argv); return 0; case 'p': path = atoi(optarg); if (path == 1) { printf("Using ap1\n"); } else if (path == 2) { printf("Using ap2\n"); } else { fprintf(stderr, "Path %d must be set to 1(ap1) or 2(ap2)\n", path); return 1; } break; case 'i': upgrade_file = optarg; break; case 'c': ret = mtac_get_version(path); if (ret != MTAC_SUCCESS) { fprintf(stderr, "Version Check failed. Error Code: %d\n", ret); return 1; } return 0; case '?': if (optopt == 'i') fprintf(stderr, "Option -%c requires a file argument.\n", optopt); else if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt); else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); return 1; default: usage(argc, argv); } ret = mtac_upgrade(upgrade_file, path); if (ret != MTAC_SUCCESS) { fprintf(stderr, "Upgrade Failed, Error Code: %d\n", ret); return 1; } else { printf("FPGA Upgrade Successful\n"); return 0; } return 0; }