summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libloragw/inc/config.h11
-rw-r--r--libloragw/inc/loragw_fpga.h3
-rw-r--r--libloragw/inc/loragw_hal.h9
-rw-r--r--libloragw/src/loragw_fpga.c30
-rw-r--r--libloragw/src/loragw_hal.c4
-rw-r--r--util_tx_continuous/src/util_tx_continuous.c13
6 files changed, 42 insertions, 28 deletions
diff --git a/libloragw/inc/config.h b/libloragw/inc/config.h
new file mode 100644
index 0000000..9b96c5f
--- /dev/null
+++ b/libloragw/inc/config.h
@@ -0,0 +1,11 @@
+#ifndef _LORAGW_CONFIGURATION_H
+#define _LORAGW_CONFIGURATION_H
+ #define LIBLORAGW_VERSION "0.1-16-gc05674a"
+ #define DEBUG_AUX 0
+ #define DEBUG_SPI 0
+ #define DEBUG_REG 0
+ #define DEBUG_HAL 0
+ #define DEBUG_GPS 0
+ #define DEBUG_GPIO
+ #define DEBUG_LBT 0
+#endif
diff --git a/libloragw/inc/loragw_fpga.h b/libloragw/inc/loragw_fpga.h
index 46246b6..d5b6f9d 100644
--- a/libloragw/inc/loragw_fpga.h
+++ b/libloragw/inc/loragw_fpga.h
@@ -135,7 +135,6 @@ int lgw_fpga_reg_wb(uint16_t register_id, uint8_t *data, uint16_t size);
*/
int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size);
-int lgw_set_attenuation(float attenuation);
-
+int lgw_set_attenuation(float *attn);
#endif
/* --- EOF ------------------------------------------------------------------ */
diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h
index fda8908..f5a6183 100644
--- a/libloragw/inc/loragw_hal.h
+++ b/libloragw/inc/loragw_hal.h
@@ -260,7 +260,7 @@ struct lgw_pkt_tx_s {
uint8_t tx_mode; /*!> select on what event/time the TX is triggered */
uint32_t count_us; /*!> timestamp or delay in microseconds for TX trigger */
uint8_t rf_chain; /*!> through which RF chain will the packet be sent */
- int8_t rf_power; /*!> TX power, in dBm */
+ float rf_power; /*!> TX power, in dBm */
uint8_t modulation; /*!> modulation to use for the packet */
uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for LoRa) */
@@ -415,13 +415,6 @@ const char* lgw_version_info(void);
*/
uint32_t lgw_time_on_air(struct lgw_pkt_tx_s *packet);
-/**
-@brief Set the attenuation for sending packets to get the exact power level
-@param attenuation is in dB, it can be between 0-31.75
-@return LGW_HAL_ERROR if the operation failed, LGW_HAL_SUCCESS else
-*/
-int lgw_set_attenuation(float attenuation);
-
#endif
/* --- EOF ------------------------------------------------------------------ */
diff --git a/libloragw/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c
index 279a3b8..368fe37 100644
--- a/libloragw/src/loragw_fpga.c
+++ b/libloragw/src/loragw_fpga.c
@@ -175,9 +175,14 @@ int lgw_fpga_configure(uint32_t tx_notch_freq) {
DEBUG_MSG("ERROR: Failed to configure FPGA polarity\n");
return LGW_REG_ERROR;
}
- /* Set Attenuator mode to be used for the full card*/
- if (fpga_supports_attenuator()) {
- lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 0);
+ }
+
+ /* Set Attenuator mode to 1 to allow it to use it*/
+ if (fpga_supports_attenuator()) {
+ x = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 1);
+ if (x != LGW_REG_SUCCESS) {
+ DEBUG_MSG("ERROR: Failed to configure Attenuator mode\n");
+ return LGW_REG_ERROR;
}
}
@@ -361,17 +366,22 @@ 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) {
+int lgw_set_attenuation(float *attn) {
+ if (*attn < 0) {
return LGW_HAL_ERROR;
}
- i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, (uint8_t)(attenuation * LGW_RF_ATTN_CONV_CONST));
+ int i;
+ int32_t val;
+ /* The max value allowed for 7 bits of a register */
+ uint8_t max_attn = 127;
+
+ /* Shifting the float value to apply get the adjusted integer */
+ uint8_t shifted_attn = (uint8_t)(*attn * LGW_RF_ATTN_CONV_CONST);
- i = lgw_fpga_reg_r(LGW_FPGA_RF_ATTN_VALUE, &val);
+ /* The attenuator value is bit 0-6 of the register hence must be limited to 127 */
+ uint8_t reg_attn = max_attn ^ ((shifted_attn ^ max_attn) & -(shifted_attn < max_attn));
+ i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, reg_attn);
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;
diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c
index 88bd874..386bd6d 100644
--- a/libloragw/src/loragw_hal.c
+++ b/libloragw/src/loragw_hal.c
@@ -426,7 +426,6 @@ int lgw_board_setconf(struct lgw_conf_board_s conf) {
rf_clkout = conf.clksrc;
if (fpga_supports_attenuator()) {
max_tx_power = conf.max_tx_power;
- printf("-------MAX TX POWER %d\n", max_tx_power);
DEBUG_PRINTF("Note: board configuration; lorawan_public:%d, clksrc:%d, max_tx_power:%d\n", lorawan_public, rf_clkout, max_tx_power);
} else {
DEBUG_PRINTF("Note: board configuration; lorawan_public:%d, clksrc:%d \n", lorawan_public, rf_clkout);
@@ -1424,7 +1423,8 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
/* Power is set to max and the attenuator brings down the level to match the packet's request */
target_mix_gain = 15; /* Mixer gain is not used for setting power*/
lgw_reg_w(LGW_TX_GAIN, 0); /* Dig gain is not used for setting power */
- x = lgw_set_attenuation((float)(max_tx_power - pkt_data.rf_power));
+ float attn = (float)(max_tx_power - pkt_data.rf_power);
+ x = lgw_set_attenuation(&attn);
if (x != LGW_HAL_SUCCESS) {
DEBUG_MSG("ERROR: Failed to set attenuation value\n");
return LGW_HAL_ERROR;
diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c
index 7768c22..275c3eb 100644
--- a/util_tx_continuous/src/util_tx_continuous.c
+++ b/util_tx_continuous/src/util_tx_continuous.c
@@ -149,7 +149,7 @@ int main(int argc, char **argv)
printf(" --br <float> FSK bitrate in kbps, [0.5:250]\n");
printf(" --fdev <uint> FSK frequency deviation in kHz, [1:250]\n");
printf(" --bt <uint> FSK gaussian filter BT trim, [0:3]\n");
- printf(" --attn <float> Attenuator value in dB, Full Card Only [0.0:31.75]\n");
+ printf(" --attn <float> Attenuator value in dB, required LGA module or MTAC full card\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
return EXIT_SUCCESS;
break;
@@ -268,8 +268,8 @@ int main(int argc, char **argv)
}
else if (strcmp(long_options[option_index].name,"attn") == 0) {
i = sscanf(optarg, "%f", &arg_f);
- if ((i != 1) || (arg_f < 0.0) || (arg_f > 31.75)) {
- printf("ERROR: argument parsing of --br argument. Use -h to print help\n");
+ if ((i != 1) || (arg_f < 0.0) ) {
+ printf("ERROR: argument parsing of --attn argument. Use -h to print help\n");
return EXIT_FAILURE;
}
else {
@@ -362,9 +362,10 @@ int main(int argc, char **argv)
txpkt.freq_hz = freq_hz;
txpkt.tx_mode = IMMEDIATE;
txpkt.rf_chain = TX_RF_CHAIN;
- txpkt.rf_power = 0;
- if (read_fpga_version() == 32) {
- i = lgw_set_attenuation(g_atten);
+ if (fpga_supports_attenuator()) {
+ txpkt.rf_power = 32.0 - g_atten;
+ } else {
+ txpkt.rf_power = 0.0;
}
if (strcmp(mod, "FSK") == 0) {