summaryrefslogtreecommitdiff
path: root/src/mts_fpga_loader.c
blob: 11388037c41236169945f64f7e90c14db428e070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#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;
  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;
}