summaryrefslogtreecommitdiff
path: root/src/mts_fpga_reg.h
blob: 39fbe14db2870a2ca15fec67850c4a50481d596e (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
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdbool.h> /* bool type */
#include <stdint.h>  /* C99 types */
#include <stdio.h>

/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */

struct mtac_reg_s {
  int8_t page;  /*!< page containing the register (-1 for all pages) */
  uint8_t addr; /*!< base address of the register (7 bit) */
  uint8_t offs; /*!< position of the register LSB (between 0 to 7) */
  bool sign;    /*!< 1 indicates the register is signed (2 complem.) */
  uint8_t leng; /*!< number of bits in the register */
  bool rdon;    /*!< 1 indicates a read-only register */
  int32_t dflt; /*!< register default value */
};

typedef struct mts {
  char creset[60];
  char mtac_hw[60];
  char spi_path[60];
  char dev_hw[40];
  int path;
} mts_hw;

/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */

#define MTAC_PAGE_REG 0
#define MTAC_SOFT_RESET 1
#define MTAC_VERSION 2
#define SPI_DEV_PATH_AP1 "/dev/spidev32766.2"
#define SPI_DEV_PATH_AP2 "/dev/spidev32765.2"
#define SPI_DEV_PATH_MTCAP "/dev/spidev0.1"
#define SPI_DEV_PATH_MTCDT "/dev/spidev0.0"
#define SPI_DEV_PATH_MTCDT3_AP1 "/dev/spidev0.2"
#define SPI_DEV_PATH_MTCDT3_AP2 "/dev/spidev1.2"
#define MTCDT "MTAC-LORA-1.5"
#define MTCDT3 "MTCDT3B-0.0"
#define MTCAP "MTCAP-LORA-1.5"
#define HW_FILE "/sys/devices/platform/mts-io/hw-version"
#define MTCDT_DEFAULT_FILE "/usr/lib/mts-flash-binaries/mtcdt-fpga-v31.hex"
#define MTCDT3_DEFAULT_FILE "/usr/lib/mts-flash-binaries/mtcdt3-fpga-v35.hex"
#define MTCAP_DEFAULT_FILE "/usr/lib/mts-flash-binaries/mtcap-fpga-v31.hex"
#define CRESET "/sys/devices/platform/mts-io/lora/creset"
#define CRESET_AP1 "/sys/devices/platform/mts-io/ap1/creset"
#define CRESET_AP2 "/sys/devices/platform/mts-io/ap2/creset"
#define MTAC_HW_VERSION "/sys/devices/platform/mts-io/lora/hw-version"
#define MTAC_HW_VERSION_AP1 "/sys/devices/platform/mts-io/ap1/hw-version"
#define MTAC_HW_VERSION_AP2 "/sys/devices/platform/mts-io/ap2/hw-version"
#define MTCDT3_HW_VERSION_AP1 "/sys/devices/platform/mts-io/lora/hw-version"
#define MTCDT3_HW_VERSION_AP2 "/sys/devices/platform/mts-io/lora-2/hw-version"
#define MTCDT3_CRESET_AP1 "/sys/devices/platform/mts-io/lora/creset"
#define MTCDT3_CRESET_AP2 "/sys/devices/platform/mts-io/lora-2/creset"

/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */

int mtac_get_version(int path);

int mtac_disconnect(void);

int bus_contention(void);

int mtac_reg_w(uint16_t register_id, int32_t reg_value);

int mtac_reg_r(uint16_t register_id, int32_t *reg_value);

int mtac_upgrade(char input_file[255], int path);

int mtac_erase(mts_hw *mts);

int mtac_program(mts_hw *mts, char input_file[]);

int mtac_check(mts_hw *mts);

int hw_check(mts_hw *mts);

void print_supported_versions();

int mtac_creset_write(mts_hw *mts, char num);
/* --- EOF ------------------------------------------------------------------ */