@@ -44,7 +44,7 @@ Maintainer: Sylvain Miermont
4444
4545#define IF_HZ_TO_REG (f ) (f << 5)/15625
4646#define SET_PPM_ON (bw ,dr ) (((bw == BW_125KHZ) && ((dr == DR_LORA_SF11) || (dr == DR_LORA_SF12))) || ((bw == BW_250KHZ) && (dr == DR_LORA_SF12)))
47- #define TRACE () fprintf(stderr, "@ %s %d\n", __FUNCTION__, __LINE__);
47+ #define TRACE () fprintf(stderr, "@ %s %d\n", __FUNCTION__, __LINE__);
4848
4949/* -------------------------------------------------------------------------- */
5050/* --- PRIVATE CONSTANTS & TYPES -------------------------------------------- */
@@ -58,12 +58,13 @@ Maintainer: Sylvain Miermont
5858#define TX_METADATA_NB 16
5959#define RX_METADATA_NB 16
6060
61- #define AGC_CMD_WAIT 16
62- #define AGC_CMD_ABORT 17
61+ #define AGC_CMD_WAIT 16
62+ #define AGC_CMD_ABORT 17
6363
6464#define MIN_LORA_PREAMBLE 4
6565#define STD_LORA_PREAMBLE 6
6666#define MIN_FSK_PREAMBLE 3
67+ #define STD_FSK_PREAMBLE 5
6768#define PLL_LOCK_MAX_ATTEMPTS 5
6869
6970#define TX_START_DELAY 1500
@@ -100,23 +101,25 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz)
100101#define SX125x_XOSC_GM_STARTUP 13 /* (default 13) */
101102#define SX125x_XOSC_DISABLE 2 /* Disable of Xtal Oscillator blocks bit0:regulator, bit1:core(gm), bit2:amplifier */
102103
103- #define RSSI_MULTI_BIAS -34.5 /* difference between "multi" modem RSSI offset and "stand-alone" modem RSSI offset */
104- #define RSSI_FSK_BIAS -37.0 /* difference between FSK modem RSSI offset and "stand-alone" modem RSSI offset */
105- #define RSSI_FSK_REF -70.0 /* linearize FSK RSSI curve around -70 dBm */
106- #define RSSI_FSK_SLOPE 0.8
104+ #define RSSI_MULTI_BIAS -35 /* difference between "multi" modem RSSI offset and "stand-alone" modem RSSI offset */
105+ #define RSSI_FSK_BIAS -37.0 /* difference between FSK modem RSSI offset and "stand-alone" modem RSSI offset */
106+ #define RSSI_FSK_REF -70.0 /* linearize FSK RSSI curve around -70 dBm */
107+ #define RSSI_FSK_SLOPE 0.8
107108
108109/* Board-specific RSSI calibration constants */
109110#if (CFG_BRD_NANO868 == 1 )
110- #define RSSI_BOARD_OFFSET 176
111+ #define RSSI_BOARD_OFFSET 176
111112#elif (CFG_BRD_1301REF868 == 1 )
112- #define RSSI_BOARD_OFFSET 166
113+ #define RSSI_BOARD_OFFSET 169.5
114+ #elif (CFG_BRD_KERLINK868 == 1 )
115+ #define RSSI_BOARD_OFFSET 167
113116#elif (CFG_BRD_1301REF433 == 1 )
114- #define RSSI_BOARD_OFFSET 176
117+ #define RSSI_BOARD_OFFSET 176
115118/* === ADD CUSTOMIZATION FOR YOUR OWN BOARD HERE ===
116119#elif (CFG_BRD_MYBOARD == 1)
117120*/
118121#elif (CFG_BRD_NONE == 1 )
119- #define RSSI_BOARD_OFFSET 0
122+ #define RSSI_BOARD_OFFSET 0
120123#endif
121124
122125/* constant arrays defining hardware capability */
@@ -189,22 +192,22 @@ typedef struct {
189192#elif (CFG_BRD_1301REF868 == 1 )
190193 #define CUSTOM_TX_POW_TABLE 1
191194 const tx_pow_t tx_pow_table [TX_POW_LUT_SIZE ] = {\
192- { 0 , 3 , 8 , -9 },\
193- { 0 , 3 , 10 , -6 },\
194- { 0 , 3 , 12 , -3 },\
195- { 1 , 3 , 8 , 0 },\
196- { 1 , 3 , 10 , 4 },\
197- { 1 , 3 , 12 , 7 },\
198- { 1 , 3 , 13 , 8 },\
199- { 1 , 3 , 15 , 9 },\
200- { 2 , 3 , 9 , 10 },\
201- { 2 , 3 , 10 , 12 },\
202- { 2 , 3 , 11 , 13 },\
203- { 3 , 3 , 10 , 21 },\
204- { 3 , 3 , 12 , 23 },\
205- { 3 , 3 , 12 , 24 },\
206- { 3 , 3 , 13 , 25 },\
207- { 3 , 3 , 15 , 26 },\
195+ { 0 , 3 , 8 , -6 },\
196+ { 0 , 3 , 10 , -3 },\
197+ { 0 , 3 , 12 , 0 },\
198+ { 1 , 3 , 8 , 3 },\
199+ { 1 , 3 , 10 , 6 },\
200+ { 1 , 3 , 12 , 10 },\
201+ { 1 , 3 , 13 , 11 },\
202+ { 2 , 3 , 9 , 12 },\
203+ { 1 , 3 , 15 , 13 },\
204+ { 2 , 3 , 10 , 14 },\
205+ { 2 , 3 , 11 , 16 },\
206+ { 3 , 3 , 9 , 20 },\
207+ { 3 , 3 , 10 , 23 },\
208+ { 3 , 3 , 11 , 25 },\
209+ { 3 , 3 , 12 , 26 },\
210+ { 3 , 3 , 14 , 27 },\
208211 }; /* calibrated */
209212#elif (CFG_BRD_1301REF433 == 1 )
210213 #define CUSTOM_TX_POW_TABLE 1
@@ -226,7 +229,27 @@ typedef struct {
226229 { 3 , 3 , 12 , 24 },\
227230 { 3 , 3 , 13 , 25 },\
228231 { 3 , 3 , 15 , 26 },\
229- }; /* TODO: calibration */
232+ }; /* TODO: approximative calibration, needs to be adjusted */
233+ #elif (CFG_BRD_KERLINK868 == 1 )
234+ #define CUSTOM_TX_POW_TABLE 1
235+ const tx_pow_t tx_pow_table [TX_POW_LUT_SIZE ] = {\
236+ { 0 , 3 , 9 ,-10 },\
237+ { 0 , 3 , 12 , -6 },\
238+ { 0 , 3 , 15 , -3 },\
239+ { 1 , 3 , 9 , 0 },\
240+ { 1 , 3 , 12 , 5 },\
241+ { 1 , 3 , 14 , 7 },\
242+ { 1 , 3 , 15 , 8 },\
243+ { 2 , 3 , 10 , 10 },\
244+ { 2 , 3 , 11 , 12 },\
245+ { 2 , 3 , 13 , 15 },\
246+ { 3 , 3 , 9 , 17 },\
247+ { 3 , 3 , 10 , 19 },\
248+ { 3 , 3 , 11 , 21 },\
249+ { 3 , 3 , 12 , 22 },\
250+ { 3 , 3 , 13 , 23 },\
251+ { 3 , 3 , 15 , 24 },\
252+ }; /* calibrated */
230253/* === ADD CUSTOMIZATION FOR YOUR OWN BOARD HERE ===
231254#elif (CFG_BRD_MYBOARD == 1)
232255*/
@@ -298,6 +321,8 @@ typedef struct {
298321 #define CFG_BRD_STR "ref_1301_868"
299322#elif (CFG_BRD_1301REF433 == 1 )
300323 #define CFG_BRD_STR "ref_1301_433"
324+ #elif (CFG_BRD_KERLINK868 == 1 )
325+ #define CFG_BRD_STR "kerlink_868"
301326/* === ADD CUSTOMIZATION FOR YOUR OWN BOARD HERE ===
302327#elif (CFG_BRD_MYBOARD == 1)
303328*/
@@ -648,15 +673,14 @@ void lgw_constant_adjust(void) {
648673 /* FSK demodulator setup */
649674 lgw_reg_w (LGW_FSK_RSSI_LENGTH ,4 ); /* default 0 */
650675 lgw_reg_w (LGW_FSK_PKT_MODE ,1 ); /* variable length, default 0 */
651- lgw_reg_w (LGW_FSK_PSIZE ,3 ); /* ??? , default 0 */
676+ lgw_reg_w (LGW_FSK_PSIZE ,2 ); /* pattern size-1 , default 0 */
652677 lgw_reg_w (LGW_FSK_CRC_EN ,1 ); /* default 0 */
653- // lgw_reg_w(LGW_FSK_DCFREE_ENC,0 ); /* default 0 */
678+ lgw_reg_w (LGW_FSK_DCFREE_ENC ,2 ); /* default 0 */
654679 // lgw_reg_w(LGW_FSK_CRC_IBM,0); /* default 0 */
655680 lgw_reg_w (LGW_FSK_ERROR_OSR_TOL ,10 ); /* default 0 */
656681 lgw_reg_w (LGW_FSK_REF_PATTERN_LSB ,0x01010101 ); /* default 0 */
657- lgw_reg_w (LGW_FSK_REF_PATTERN_MSB ,0x01010101 ); /* default 0 */
682+ lgw_reg_w (LGW_FSK_REF_PATTERN_MSB ,0xC194C101 ); /* default 0 */
658683 lgw_reg_w (LGW_FSK_PKT_LENGTH ,255 ); /* max packet length in variable length mode */
659-
660684 // lgw_reg_w(LGW_FSK_NODE_ADRS,0); /* default 0 */
661685 // lgw_reg_w(LGW_FSK_BROADCAST,0); /* default 0 */
662686 // lgw_reg_w(LGW_FSK_AUTO_AFC_ON,0); /* default 0 */
@@ -671,9 +695,9 @@ void lgw_constant_adjust(void) {
671695
672696 /* TX FSK */
673697 // lgw_reg_w(LGW_FSK_TX_GAUSSIAN_EN,1); /* default 1 */
674- lgw_reg_w (LGW_FSK_TX_GAUSSIAN_SELECT_BT ,1 ); /* Gaussian filter always on TX, default 0 */
675- lgw_reg_w (LGW_FSK_TX_PSIZE ,3 ); /* default 0 */
676- // lgw_reg_w(LGW_FSK_TX_PATTERN_EN, 1); /* default 1 */
698+ lgw_reg_w (LGW_FSK_TX_GAUSSIAN_SELECT_BT ,2 ); /* Gaussian filter always on TX, default 0 */
699+ lgw_reg_w (LGW_FSK_TX_PSIZE ,2 ); /* default 0 */
700+ // lgw_reg_w(LGW_FSK_TX_PATTERN_EN,1); /* default 1 */
677701 // lgw_reg_w(LGW_FSK_TX_PREAMBLE_SEQ,0); /* default 0 */
678702
679703 return ;
@@ -905,7 +929,7 @@ int lgw_start(void) {
905929 cal_cmd |= 0x20 ; /* Bit 5: 0: SX1257, 1: SX1255 */
906930 #endif
907931
908- #if ((CFG_BRD_1301REF868 == 1 ) || (CFG_BRD_1301REF433 == 1 ))
932+ #if ((CFG_BRD_1301REF868 == 1 ) || (CFG_BRD_1301REF433 == 1 ) || ( CFG_BRD_KERLINK868 == 1 ) )
909933 cal_cmd |= 0x00 ; /* Bit 6-7: Board type 0: ref, 1: FPGA, 3: board X */
910934 cal_time = 2300 ; /* measured between 2.1 and 2.2 sec, because 1 TX only */
911935 #elif (CFG_BRD_NANO868 == 1 )
@@ -1587,7 +1611,9 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
15871611 buff [11 ] = (pkt_data .no_crc ?0 :0x02 ); /* always in fixed length packet mode, no DC-free encoding, CCITT CRC if CRC is not disabled */
15881612
15891613 /* metadata 12 & 13, FSK preamble size */
1590- if (pkt_data .preamble < MIN_FSK_PREAMBLE ) { /* enforce minimum preamble size */
1614+ if (pkt_data .preamble == 0 ) { /* if not explicit, use LoRa MAC preamble size */
1615+ pkt_data .preamble = STD_FSK_PREAMBLE ;
1616+ } else if (pkt_data .preamble < MIN_FSK_PREAMBLE ) { /* enforce minimum preamble size */
15911617 pkt_data .preamble = MIN_FSK_PREAMBLE ;
15921618 DEBUG_MSG ("Note: preamble length adjusted to respect minimum FSK preamble size\n" );
15931619 }
0 commit comments