kopia lustrzana https://github.com/OpenRTX/OpenRTX
Created function for writing settings and VFO status to NVM, starting of temporary implementation writing data to the MCU's internal flash
rodzic
c91e306026
commit
756812ca31
|
@ -117,6 +117,7 @@ def = def + {'GIT_VERSION': git_version}
|
|||
mdx_src = ['platform/drivers/ADC/ADC1_MDx.c',
|
||||
'platform/drivers/GPS/GPS_MDx.cpp',
|
||||
'platform/drivers/NVM/W25Qx.c',
|
||||
'platform/drivers/NVM/nvmem_settings_MDx.c',
|
||||
'platform/drivers/audio/audio_MDx.c',
|
||||
'platform/drivers/audio/inputStream_MDx.cpp',
|
||||
'platform/drivers/baseband/HR_Cx000.cpp',
|
||||
|
|
|
@ -104,6 +104,15 @@ int nvm_readSettings(settings_t *settings);
|
|||
* @param settings: pointer to the settings_t data structure to be written.
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int nvm_writeSettings(settings_t *settings);
|
||||
int nvm_writeSettings(const settings_t *settings);
|
||||
|
||||
/**
|
||||
* Write OpenRTX settings and VFO channel configuration to storage.
|
||||
*
|
||||
* @param settings: pointer to the settings_t data structure to be written.
|
||||
* @param vfo: pointer to the VFO data structure to be written.
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int nvm_writeSettingsAndVfo(const settings_t *settings, const channel_t *vfo);
|
||||
|
||||
#endif /* NVMEM_H */
|
||||
|
|
|
@ -65,7 +65,7 @@ gps_t;
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
char callsign[10];
|
||||
// char callsign[10];
|
||||
char dst_addr[10];
|
||||
}
|
||||
m17_t;
|
||||
|
|
|
@ -31,30 +31,27 @@ state_t state;
|
|||
void state_init()
|
||||
{
|
||||
/*
|
||||
* TODO: Read current state parameters from hardware,
|
||||
* or initialize them to sane defaults
|
||||
* Try loading settings from nonvolatile memory and default to sane values
|
||||
* in case of failure.
|
||||
*/
|
||||
state.radioStateUpdated = true;
|
||||
#ifdef HAS_RTC
|
||||
state.time = rtc_getTime();
|
||||
#endif
|
||||
state.v_bat = platform_getVbat();
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
||||
// Set default channel index (it is 1-based)
|
||||
state.channel_index = 1;
|
||||
// Read VFO channel from Flash storage
|
||||
// NOTE: Disable reading VFO from flash until persistence is implemented
|
||||
//if(nvm_readVFOChannelData(&state.channel) != 0)
|
||||
if(1)
|
||||
if(nvm_readSettings(&state.settings) != 0)
|
||||
{
|
||||
// If the read fails set VFO channel default settings
|
||||
state.channel.mode = FM;
|
||||
state.settings = default_settings;
|
||||
strncpy(state.settings.callsign, "OPNRTX", 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try loading VFO configuration from nonvolatile memory and default to sane
|
||||
* values in case of failure.
|
||||
*/
|
||||
if(nvm_readVFOChannelData(&state.channel) != 0)
|
||||
{
|
||||
state.channel.mode = FM;
|
||||
state.channel.bandwidth = BW_25;
|
||||
state.channel.power = 1.0;
|
||||
const hwInfo_t* hwinfo = platform_getHwInfo();
|
||||
state.channel.power = 1.0;
|
||||
|
||||
// Set initial frequency based on supported bands
|
||||
const hwInfo_t* hwinfo = platform_getHwInfo();
|
||||
if(hwinfo->uhf_band)
|
||||
{
|
||||
state.channel.rx_frequency = 430000000;
|
||||
|
@ -65,39 +62,33 @@ void state_init()
|
|||
state.channel.rx_frequency = 144000000;
|
||||
state.channel.tx_frequency = 144000000;
|
||||
}
|
||||
|
||||
state.channel.fm.rxToneEn = 0;
|
||||
state.channel.fm.rxTone = 2; // 71.9Hz
|
||||
state.channel.fm.rxTone = 2; // 71.9Hz
|
||||
state.channel.fm.txToneEn = 1;
|
||||
state.channel.fm.txTone = 2; // 71.9Hz
|
||||
state.channel.fm.txTone = 2; // 71.9Hz
|
||||
}
|
||||
state.zone_enabled = false;
|
||||
state.rtxStatus = RTX_OFF;
|
||||
state.settings.sqlLevel = 4; // Default Squelch: S3 = 4
|
||||
state.settings.voxLevel = 0;
|
||||
|
||||
state.emergency = false;
|
||||
/*
|
||||
* Initialise remaining fields
|
||||
*/
|
||||
state.radioStateUpdated = true;
|
||||
#ifdef HAS_RTC
|
||||
state.time = rtc_getTime();
|
||||
#endif
|
||||
state.v_bat = platform_getVbat();
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
||||
// Initialize M17_data
|
||||
strncpy(state.m17_data.callsign, "OPNRTX", 10);
|
||||
|
||||
// Read settings from flash memory
|
||||
// NOTE: Disable reading VFO from flash until persistence is implemented
|
||||
//int valid = nvm_readSettings(&state.settings);
|
||||
// Settings in flash memory were not valid, restoring default settings
|
||||
//if(valid != 0)
|
||||
if(1)
|
||||
{
|
||||
state.settings = default_settings;
|
||||
// NOTE: Settings writing disabled until DFU is implemented
|
||||
//nvm_writeSettings(&state.settings);
|
||||
}
|
||||
state.channel_index = 1; // Set default channel index (it is 1-based)
|
||||
state.zone_enabled = false;
|
||||
state.rtxStatus = RTX_OFF;
|
||||
state.emergency = false;
|
||||
}
|
||||
|
||||
void state_terminate()
|
||||
{
|
||||
// Write settings to flash memory
|
||||
// NOTE: Disable writing settings to flash until persistence is implemented
|
||||
//nvm_writeSettings(&state.settings);
|
||||
nvm_writeSettingsAndVfo(&state.settings, &state.channel);
|
||||
}
|
||||
|
||||
curTime_t state_getLocalTime(curTime_t utc_time)
|
||||
|
|
|
@ -105,7 +105,7 @@ void *ui_task(void *arg)
|
|||
pthread_mutex_unlock(&rtx_mutex);
|
||||
|
||||
// Copy new M17 source and destination addresses
|
||||
strncpy(rtx_cfg.source_address, state.m17_data.callsign, 10);
|
||||
strncpy(rtx_cfg.source_address, state.settings.callsign, 10);
|
||||
strncpy(rtx_cfg.destination_address, state.m17_data.dst_addr, 10);
|
||||
|
||||
rtx_configure(&rtx_cfg);
|
||||
|
|
|
@ -1456,7 +1456,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
{
|
||||
_ui_textInputConfirm(ui_state.new_callsign);
|
||||
// Save selected callsign and disable input mode
|
||||
strncpy(state.m17_data.callsign, ui_state.new_callsign, 10);
|
||||
strncpy(state.settings.callsign, ui_state.new_callsign, 10);
|
||||
ui_state.edit_mode = false;
|
||||
*sync_rtx = true;
|
||||
}
|
||||
|
|
|
@ -539,7 +539,7 @@ void _ui_drawSettingsM17(ui_state_t* ui_state)
|
|||
// Print M17 current callsign
|
||||
gfx_printLine(1, 1, layout.top_h, SCREEN_HEIGHT - layout.bottom_h,
|
||||
layout.horizontal_pad, layout.input_font,
|
||||
TEXT_ALIGN_CENTER, color_white, last_state.m17_data.callsign);
|
||||
TEXT_ALIGN_CENTER, color_white, last_state.settings.callsign);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -441,9 +441,15 @@ int nvm_readSettings(settings_t *settings)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int nvm_writeSettings(settings_t *settings)
|
||||
int nvm_writeSettings(const settings_t *settings)
|
||||
{
|
||||
(void) settings;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvm_writeSettingsAndVfo(const settings_t *settings, const channel_t *vfo)
|
||||
{
|
||||
(void) settings;
|
||||
(void) vfo;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -157,12 +157,15 @@ void nvm_loadHwInfo(hwInfo_t *info)
|
|||
* The MD380 stock CPS does not have a VFO channel slot
|
||||
* because the stock firmware does not have a VFO
|
||||
* To enable this functionality reserve a Flash portion for saving the VFO
|
||||
*/
|
||||
*
|
||||
* TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readVFOChannelData(channel_t *channel)
|
||||
{
|
||||
(void) channel;
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_readChannelData(channel_t *channel, uint16_t pos)
|
||||
{
|
||||
|
@ -315,15 +318,19 @@ int nvm_readContactData(contact_t *contact, uint16_t pos)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readSettings(settings_t *settings)
|
||||
{
|
||||
(void) settings;
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_writeSettings(settings_t *settings)
|
||||
int nvm_writeSettings(const settings_t *settings)
|
||||
{
|
||||
(void) settings;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,10 +168,14 @@ void nvm_readCalibData(void *buf)
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readVFOChannelData(channel_t *channel)
|
||||
{
|
||||
return _nvm_readChannelAtAddress(channel, vfoChannelBaseAddr);
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_readChannelData(channel_t *channel, uint16_t pos)
|
||||
{
|
||||
|
@ -255,6 +259,10 @@ int nvm_readContactData(contact_t *contact, uint16_t pos)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readSettings(settings_t *settings)
|
||||
{
|
||||
settings_t newSettings;
|
||||
|
@ -267,8 +275,9 @@ int nvm_readSettings(settings_t *settings)
|
|||
memcpy(settings, &newSettings, sizeof(settings_t));
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_writeSettings(settings_t *settings)
|
||||
int nvm_writeSettings(const settings_t *settings)
|
||||
{
|
||||
// Disable settings write until DFU is implemented for flash backups
|
||||
return -1;
|
||||
|
|
|
@ -268,10 +268,14 @@ void nvm_loadHwInfo(hwInfo_t *info)
|
|||
info->lcd_type = lcdInfo & 0x03;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readVFOChannelData(channel_t *channel)
|
||||
{
|
||||
return _nvm_readChannelAtAddress(channel, vfoChannelBaseAddr);
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_readChannelData(channel_t *channel, uint16_t pos)
|
||||
{
|
||||
|
@ -355,6 +359,9 @@ int nvm_readContactData(contact_t *contact, uint16_t pos)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: temporarily implemented in "nvmem_settings_MDx.c"
|
||||
|
||||
int nvm_readSettings(settings_t *settings)
|
||||
{
|
||||
settings_t newSettings;
|
||||
|
@ -367,8 +374,9 @@ int nvm_readSettings(settings_t *settings)
|
|||
memcpy(settings, &newSettings, sizeof(settings_t));
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int nvm_writeSettings(settings_t *settings)
|
||||
int nvm_writeSettings(const settings_t *settings)
|
||||
{
|
||||
// Disable settings write until DFU is implemented for flash backups
|
||||
return -1;
|
||||
|
|
|
@ -91,9 +91,15 @@ int nvm_readSettings(settings_t *settings)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int nvm_writeSettings(settings_t *settings)
|
||||
int nvm_writeSettings(const settings_t *settings)
|
||||
{
|
||||
(void) settings;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvm_writeSettingsAndVfo(const settings_t *settings, const channel_t *vfo)
|
||||
{
|
||||
(void) settings;
|
||||
(void) vfo;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <interfaces/nvmem.h>
|
||||
#include <cps.h>
|
||||
|
||||
int nvm_readSettings(settings_t *settings)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvm_readVFOChannelData(channel_t *channel)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvm_writeSettingsAndVfo(const settings_t *settings, const channel_t *vfo)
|
||||
{
|
||||
return -1;
|
||||
}
|
Ładowanie…
Reference in New Issue