summaryrefslogtreecommitdiff
path: root/libloragw/src/loragw_fpga.c
diff options
context:
space:
mode:
Diffstat (limited to 'libloragw/src/loragw_fpga.c')
-rw-r--r--libloragw/src/loragw_fpga.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/libloragw/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c
index 1379679..ce1c9c6 100644
--- a/libloragw/src/loragw_fpga.c
+++ b/libloragw/src/loragw_fpga.c
@@ -130,7 +130,7 @@ float lgw_fpga_get_tx_notch_delay(void) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-int lgw_fpga_configure(uint32_t tx_notch_freq, bool fpga_attn_used) {
+int lgw_fpga_configure(uint32_t tx_notch_freq) {
int x;
int32_t val;
bool spectral_scan_support, lbt_support;
@@ -175,17 +175,9 @@ int lgw_fpga_configure(uint32_t tx_notch_freq, bool fpga_attn_used) {
DEBUG_MSG("ERROR: Failed to configure FPGA polarity\n");
return LGW_REG_ERROR;
}
- /* Set Attenuator mode to be used or not depending on if a full card with valid conf settings are given*/
+ /* Set Attenuator mode to be used for the full card*/
if (fpga_version == 32) {
- if (fpga_attn_used == true) {
- lgw_reg_w(LGW_FPGA_RF_ATTN_MODE, 0);
- printf("INFO: Valid attenuation settings detected. Using Attenuator mode\n");
- } else {
- printf("INFO: Valid attenuation settings not detected. Using Legacy mode\n");
- lgw_reg_w(LGW_FPGA_RF_ATTN_MODE, 1);
- }
- } else {
- lgw_reg_w(LGW_FPGA_RF_ATTN_MODE, 1);
+ lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 0);
}
}
@@ -367,4 +359,23 @@ int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size) {
}
}
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int lgw_set_attenuation(float attenuation) {
+ int i;
+ int32_t val;
+ if (attenuation > 31.75 || attenuation < 0) {
+ return LGW_HAL_ERROR;
+ }
+ i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, (uint8_t)(attenuation * LGW_RF_ATTN_CONV_CONST));
+
+ i = lgw_fpga_reg_r(LGW_FPGA_RF_ATTN_VALUE, &val);
+ if (i == LGW_REG_SUCCESS) {
+ DEBUG_PRINTF("INFO: Attenuator set to %u \n", (uint8_t)val);
+ return LGW_HAL_SUCCESS;
+ } else {
+ return LGW_HAL_ERROR;
+ }
+}
+
/* --- EOF ------------------------------------------------------------------ */