Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FlexFreq and fixed RSSI #1

Open
wants to merge 1 commit into
base: pprz_rssi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Firmware/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@
# error Must define a BOARD_ value before including this file.
#endif

#define FLEX_FREQ 1 // Enable the extra unofficial option to set frequency base

#endif // _BOARD_H_
8 changes: 4 additions & 4 deletions Firmware/include/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# modification, are permitted provided that the following conditions
# are met:
#
# o Redistributions of source code must retain the above copyright
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Expand All @@ -27,7 +27,7 @@
#
# Common rules and targets for the HopeRF radio apps
#
PPRZLINK_VERSION ?= PPRZLINK_1
PPRZLINK_VERSION ?= PPRZLINK_2

ifeq ($(BOARD),)
$(error Must define BOARD before attempting to build)
Expand Down
30 changes: 30 additions & 0 deletions Firmware/radio/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,25 @@ main(void)
// Stash board info from the bootloader before we let anything touch
// the SFRs.
//
#ifndef FLEX_FREQ
g_board_frequency = BOARD_FREQUENCY_REG;
#endif
g_board_bl_version = BOARD_BL_VERSION_REG;

#ifdef FLEX_FREQ
// Parameter to override the bootloader BOARD_FREQUENCY_REG
g_board_frequency = param_get(PARAM_MAIN_FREQ);
switch(g_board_frequency) {
case FREQ_433:
case FREQ_470:
case FREQ_868:
case FREQ_915:
break;
default: // Don't override (the default parameter value is FREQ_NONE)
g_board_frequency = BOARD_FREQUENCY_REG;
}
#endif

// Load parameters from flash or defaults
// this is done before hardware_init() to get the serial speed
if (!param_load())
Expand Down Expand Up @@ -317,7 +333,11 @@ radio_init(void)
case FREQ_868:
freq_min = 868000000UL;
freq_max = 870000000UL;
#ifdef FLEX_FREQ
txpower = 20;
#else
txpower = 10;
#endif
num_fh_channels = 10;
break;
case FREQ_915:
Expand Down Expand Up @@ -362,12 +382,22 @@ radio_init(void)
freq_max = constrain(freq_max, 450000000UL, 490000000UL);
break;
case FREQ_868:
#ifdef FLEX_FREQ
freq_min = constrain(freq_min, 849000000UL, 935000000UL);
freq_max = constrain(freq_max, 849000000UL, 935000000UL);
#else
freq_min = constrain(freq_min, 849000000UL, 889000000UL);
freq_max = constrain(freq_max, 849000000UL, 889000000UL);
#endif
break;
case FREQ_915:
#ifdef FLEX_FREQ
freq_min = constrain(freq_min, 849000000UL, 935000000UL);
freq_max = constrain(freq_max, 849000000UL, 935000000UL);
#else
freq_min = constrain(freq_min, 868000000UL, 935000000UL);
freq_max = constrain(freq_max, 868000000UL, 935000000UL);
#endif
break;
default:
panic("bad board frequency %d", g_board_frequency);
Expand Down
9 changes: 9 additions & 0 deletions Firmware/radio/parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ __code const struct parameter_info {
{"MAX_WINDOW", 131},
{"PPRZLINK", 1},
{"PPRZLINK_SENDER_ID", 0},
#ifdef FLEX_FREQ
{"MAIN_FREQ", FREQ_NONE}, //Note that the mainfreq is not overridden by default, we're oh so polite ;)
#endif

#ifdef INCLUDE_AES
{"ENCRYPTION_LEVEL", 0}, // no Enycryption (0), 128 or 256 bit key
#endif
Expand Down Expand Up @@ -181,6 +185,11 @@ param_check(__pdata enum ParamID id, __data uint32_t val)
return false;
break;

//case PARAM_MAIN_FREQ:
// if ((val != 0x43) || (val != 0x47) || (val != 0x86) || (val != 0x91))
// return false;
// break;

default:
// no sanity check for this value
break;
Expand Down
9 changes: 6 additions & 3 deletions Firmware/radio/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ enum ParamID {
PARAM_MANCHESTER, // enable manchester encoding
PARAM_RTSCTS, // enable hardware flow control
PARAM_MAX_WINDOW, // The maximum window size allowed
PARAM_PPRZLINK, // if 1 then inject RSSI PPRZLINK packet into the incoming data stream (PPRZLINK version has to be defined)
PARAM_PPRZLINK_SENDER_ID, // optional Pprzlink sender ID (0 by default)
PARAM_PPRZLINK, // if 1 then inject RSSI PPRZLINK packet into the incoming data stream (PPRZLINK version has to be defined)
PARAM_PPRZLINK_SENDER_ID, // optional Pprzlink sender ID (0 by default)
#ifdef FLEX_FREQ
PARAM_MAIN_FREQ, // Be able to override override BOARD_FREQUENCY_REG with 0x43, 0x47, 0x86 or 0x91
#endif
#ifdef INCLUDE_AES
PARAM_ENCRYPTION, // no Enycryption (0), 128 or 256 bit key
PARAM_ENCRYPTION, // no Encryption (0), 128 or 256 bit key
#endif
PARAM_MAX // must be last
};
Expand Down
2 changes: 1 addition & 1 deletion Firmware/radio/pins_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pins_user_set_io(__pdata uint8_t pin, bool in_out)
pin_values[pin].output = in_out;
pin_values[pin].pin_mirror = PIN_NULL;

// Esure we are on the Legacy page (SFR Page 0x0)
// Ensure we are on the Legacy page (SFR Page 0x0)
SFRPAGE = LEGACY_PAGE;

switch(pins_user_map[pin].port)
Expand Down
48 changes: 24 additions & 24 deletions Firmware/radio/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,34 +685,34 @@ __code static const uint8_t reg_table_433[NUM_RADIO_REGISTERS][NUM_DATA_RATES] =

// register table for 470MHz radios
__code static const uint8_t reg_table_470[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = {
{0x2B, 0x2B, 0x2B, 0x2E, 0x16, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D},
{0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03},
{0xF4, 0xFA, 0x7D, 0x3F, 0x69, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30},
{0x20, 0x00, 0x01, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02},
{0x41, 0x83, 0x06, 0x0C, 0x37, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA},
{0x89, 0x12, 0x25, 0x4A, 0x4C, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB},
{0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07},
{0x85, 0x08, 0x0E, 0x12, 0x72, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF},
{0x1E, 0x1E, 0x1E, 0x21, 0x21, 0x21, 0x21, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00},
{0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE}
{0x2B, 0x2B, 0x2B, 0x2E, 0x16, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D},
{0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03},
{0xF4, 0xFA, 0x7D, 0x3F, 0x69, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30},
{0x20, 0x00, 0x01, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02},
{0x41, 0x83, 0x06, 0x0C, 0x37, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA},
{0x89, 0x12, 0x25, 0x4A, 0x4C, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB},
{0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07},
{0x85, 0x08, 0x0E, 0x12, 0x72, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF},
{0x1E, 0x1E, 0x1E, 0x21, 0x21, 0x21, 0x21, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00},
{0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE}
};

// register table for 868MHz radios
__code static const uint8_t reg_table_868[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = {
{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D},
{0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03},
{0xD0, 0xE8, 0xF4, 0xFA, 0xD3, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30},
{0xE0, 0x60, 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB},
{0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07},
{0x23, 0x44, 0x85, 0x08, 0x39, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF},
{0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1E, 0x20, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00},
{0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE}
{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D},
{0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03},
{0xD0, 0xE8, 0xF4, 0xFA, 0xD3, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30},
{0xE0, 0x60, 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB},
{0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07},
{0x23, 0x44, 0x85, 0x08, 0x39, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF},
{0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1E, 0x20, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50},
{0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40},
{0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00},
{0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE}
};

// register table for 915MHz radios
Expand Down
26 changes: 15 additions & 11 deletions Firmware/radio/tdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,12 @@ tdm_serial_loop(void)
}


// check if there is enough space in the buffer
if ((len+PPRZ_RSSI_LENGTH) < sizeof(pbuf)){
// Check if there is enough space in the buffer inject the RSSI data
// #ifdef INCLUDE_GOLAY FIXME: and seet if feature_golay is used PPRZ_RSSI_LENGTH*2
if ((len+PPRZ_RSSI_LENGTH) < sizeof(pbuf)/2) { //ECC has only half of possible bytes, so if used, half buffer
// #else
// if ((len+PPRZ_RSSI_LENGTH) < sizeof(pbuf))
// #endif
__pdata uint8_t i;
for(i=0;i<len-PPRZ_MSG_ID_IDX;i++){

Expand Down Expand Up @@ -684,24 +688,24 @@ tdm_serial_loop(void)
ck_b_tx += ck_a_tx;
i++;

#if defined PPRZLINK_2 || defined PPRZLINK_2_GEC
pbuf[i] = PPRZ_GCS_ID; // Dest ID (typically zero for GCS)
#if defined PPRZLINK_2 || defined PPRZLINK_2_GEC //for Pprzlink v2.0 only
pbuf[i] = PPRZ_GCS_ID; // Dest ID. Typically zero for GCS, fix the code to have different behaviour
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;

pbuf[i] = PPRZ_TELEMETRY_ID; // class/component ID (1 for telemetry)
pbuf[i] = PPRZ_TELEMETRY_ID; // class and component ID 4bit nibble (1 for telemetry)
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;
#endif // Pprzlink 2.0 only
#endif // PPRZLINK_2 or PPRZLINK_2_GEC

pbuf[i] = PPRZ_RSSI_ID; // MSG ID
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;

pbuf[i] = remote_statistics.average_rssi; // ac rssi
pbuf[i] = remote_statistics.average_rssi; // remote rssi (AC)
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;
Expand All @@ -711,17 +715,17 @@ tdm_serial_loop(void)
ck_b_tx += ck_a_tx;
i++;

pbuf[i] = statistics.average_rssi; // gcs rssi
pbuf[i] = statistics.average_rssi; // local rssi (Typically the GCS)
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;

pbuf[i] = statistics.average_noise; // gcs noise
pbuf[i] = statistics.average_noise; // local noise (Typically the GCS)
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;

pbuf[i] = remote_statistics.average_noise; // ac noise
pbuf[i] = remote_statistics.average_noise; // remote noise (AC)
ck_a_tx += pbuf[i];
ck_b_tx += ck_a_tx;
i++;
Expand Down Expand Up @@ -1161,7 +1165,7 @@ tdm_init(void)
window_width = param_get(PARAM_MAX_WINDOW)*(1000/16);
}

// make sure it fits in the 13 bits of the trailer window
// to make sure it fits in the 13 bits of the trailer window
if (window_width > 0x1fff) {
window_width = 0x1fff;
}
Expand Down
Loading