summaryrefslogtreecommitdiff
path: root/src/mts_fpga_loader.c
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2017-08-18 15:14:17 -0500
committerJohn Klug <john.klug@multitech.com>2017-08-18 15:14:17 -0500
commit3ff432faedee2ec0b93d163e4808f391d65f1ba2 (patch)
tree59df462ea8586a664a59d4cf62f1a58af6507f7e /src/mts_fpga_loader.c
parentc2da95882ea7a4218a4432ee5da8165aa61addfc (diff)
downloadmts-id-eeprom-3ff432faedee2ec0b93d163e4808f391d65f1ba2.tar.gz
mts-id-eeprom-3ff432faedee2ec0b93d163e4808f391d65f1ba2.tar.bz2
mts-id-eeprom-3ff432faedee2ec0b93d163e4808f391d65f1ba2.zip
mts-fpga-loader
Diffstat (limited to 'src/mts_fpga_loader.c')
-rw-r--r--src/mts_fpga_loader.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mts_fpga_loader.c b/src/mts_fpga_loader.c
new file mode 100644
index 0000000..3648eeb
--- /dev/null
+++ b/src/mts_fpga_loader.c
@@ -0,0 +1,85 @@
+#include <stdio.h> /* printf fprintf */
+#include <unistd.h> /* 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 <argument>\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 file> Upgrade the FPGA on the default port using the file specified\n", argv[0]);
+ printf(" %s -p 2 -i <upgrade file> 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;
+ 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 - /dev/spidev32766.2\n");
+ }
+ else if (path == 2) {
+ printf("Using ap2 - /dev/spidev32765.2\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 Sucessful\n");
+ return 0;
+ }
+ return 0;
+} \ No newline at end of file