diff --git a/meson.build b/meson.build
index 0d849d15..e7f2a717 100644
--- a/meson.build
+++ b/meson.build
@@ -160,6 +160,7 @@ mdx_src = ['openrtx/src/core/xmodem.c',
'platform/drivers/GPS/GPS_MDx.cpp',
'platform/drivers/NVM/W25Qx.c',
'platform/drivers/NVM/nvmem_settings_MDx.c',
+ 'platform/drivers/NVM/nvmem_MDx.c',
'platform/drivers/audio/audio_MDx.c',
'platform/drivers/baseband/HR_Cx000.cpp',
'platform/drivers/tones/toneGenerator_MDx.cpp']
@@ -331,8 +332,7 @@ endif
##
## TYT MD-3x0 family
##
-md3x0_src = ['platform/drivers/NVM/nvmem_MD3x0.c',
- 'platform/drivers/CPS/cps_io_native_MD3x0.c',
+md3x0_src = ['platform/drivers/CPS/cps_io_native_MD3x0.c',
'platform/drivers/NVM/spiFlash_MD3x.c',
'platform/drivers/baseband/SKY72310.c',
'platform/drivers/baseband/radio_MD3x0.cpp',
@@ -352,8 +352,7 @@ md3x0_def += openrtx_def + stm32f405_def + miosix_cm4f_def
##
## TYT MD-UV380
##
-mduv3x0_src = ['platform/drivers/NVM/nvmem_MDUV3x0.c',
- 'platform/drivers/NVM/spiFlash_MD3x.c',
+mduv3x0_src = ['platform/drivers/NVM/spiFlash_MD3x.c',
'platform/drivers/CPS/cps_io_native_MDUV3x0.c',
'platform/targets/MD-UV3x0/platform.c',
'platform/drivers/keyboard/keyboard_MD3x.c',
@@ -379,7 +378,6 @@ md9600_src = ['platform/targets/MD-9600/platform.c',
'platform/drivers/keyboard/keyboard_MD9600.c',
'platform/drivers/chSelector/chSelector_MD9600.c',
'platform/drivers/baseband/radio_MD9600.cpp',
- 'platform/drivers/NVM/nvmem_MD9600.c',
'platform/drivers/NVM/spiFlash_MD9600.c',
'platform/drivers/CPS/cps_io_native_MD9600.c']
diff --git a/platform/drivers/NVM/nvmem_MD3x0.c b/platform/drivers/NVM/nvmem_MD3x0.c
deleted file mode 100644
index 7e996d98..00000000
--- a/platform/drivers/NVM/nvmem_MD3x0.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2020 - 2024 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 *
- ***************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "W25Qx.h"
-
-W25Qx_DEVICE_DEFINE(eflash, 0x1000000) // 16 MB, 128 Mbit
-W25Qx_SECREG_DEFINE(cal1, 0x1000, 0x100) // 256 byte
-W25Qx_SECREG_DEFINE(cal2, 0x2000, 0x100) // 256 byte
-
-static const struct nvmDescriptor nvmDevices[] =
-{
- {
- .name = "External flash",
- .dev = &eflash,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 1",
- .dev = (const struct nvmDevice *) &cal1,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 2",
- .dev = (const struct nvmDevice *) &cal2,
- .partNum = 0,
- .partitions = NULL
- }
-};
-
-
-void nvm_init()
-{
- W25Qx_init();
-}
-
-void nvm_terminate()
-{
- W25Qx_terminate();
-}
-
-const struct nvmDescriptor *nvm_getDesc(const size_t index)
-{
- if(index > 3)
- return NULL;
-
- return &nvmDevices[index];
-}
-
-void nvm_readCalibData(void *buf)
-{
- W25Qx_wakeup();
- delayUs(5);
-
- md3x0Calib_t *calib = ((md3x0Calib_t *) buf);
-
- (void) W25Qx_readSecurityRegister(0x1000, &(calib->vox1), 1);
- (void) W25Qx_readSecurityRegister(0x1001, &(calib->vox10), 1);
- (void) W25Qx_readSecurityRegister(0x1002, &(calib->rxLowVoltage), 1);
- (void) W25Qx_readSecurityRegister(0x1003, &(calib->rxFullVoltage), 1);
- (void) W25Qx_readSecurityRegister(0x1004, &(calib->rssi1), 1);
- (void) W25Qx_readSecurityRegister(0x1005, &(calib->rssi4), 1);
- (void) W25Qx_readSecurityRegister(0x1006, &(calib->analogMic), 1);
- (void) W25Qx_readSecurityRegister(0x1007, &(calib->digitalMic), 1);
- (void) W25Qx_readSecurityRegister(0x1008, &(calib->freqAdjustHigh), 1);
- (void) W25Qx_readSecurityRegister(0x1009, &(calib->freqAdjustMid), 1);
- (void) W25Qx_readSecurityRegister(0x100A, &(calib->freqAdjustLow), 1);
- (void) W25Qx_readSecurityRegister(0x1010, calib->txHighPower, 9);
- (void) W25Qx_readSecurityRegister(0x1020, calib->txLowPower, 9);
- (void) W25Qx_readSecurityRegister(0x1030, calib->rxSensitivity, 9);
- (void) W25Qx_readSecurityRegister(0x1040, calib->openSql9, 9);
- (void) W25Qx_readSecurityRegister(0x1050, calib->closeSql9, 9);
- (void) W25Qx_readSecurityRegister(0x1060, calib->openSql1, 9);
- (void) W25Qx_readSecurityRegister(0x1070, calib->closeSql1, 9);
- (void) W25Qx_readSecurityRegister(0x1080, calib->maxVolume, 9);
- (void) W25Qx_readSecurityRegister(0x1090, calib->ctcss67Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10a0, calib->ctcss151Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10b0, calib->ctcss254Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10c0, calib->dcsMod2, 9);
- (void) W25Qx_readSecurityRegister(0x10d0, calib->dcsMod1, 9);
- (void) W25Qx_readSecurityRegister(0x10e0, calib->mod1Partial, 9);
- (void) W25Qx_readSecurityRegister(0x10f0, calib->analogVoiceAdjust, 9);
-
- (void) W25Qx_readSecurityRegister(0x2000, calib->lockVoltagePartial, 9);
- (void) W25Qx_readSecurityRegister(0x2010, calib->sendIpartial, 9);
- (void) W25Qx_readSecurityRegister(0x2020, calib->sendQpartial, 9);
- (void) W25Qx_readSecurityRegister(0x2030, calib->sendIrange, 9);
- (void) W25Qx_readSecurityRegister(0x2040, calib->sendQrange, 9);
- (void) W25Qx_readSecurityRegister(0x2050, calib->rxIpartial, 9);
- (void) W25Qx_readSecurityRegister(0x2060, calib->rxQpartial, 9);
- (void) W25Qx_readSecurityRegister(0x2070, calib->analogSendIrange, 9);
- (void) W25Qx_readSecurityRegister(0x2080, calib->analogSendQrange, 9);
-
- uint32_t freqs[18];
- (void) W25Qx_readSecurityRegister(0x20b0, ((uint8_t *) &freqs), 72);
- W25Qx_sleep();
-
- /*
- * Ugly quirk: frequency stored in calibration data is divided by ten, so,
- * after bcdToBin conversion we have something like 40'135'000. To ajdust
- * things, frequency has to be multiplied by ten.
- */
- for(uint8_t i = 0; i < 9; i++)
- {
- calib->rxFreq[i] = ((freq_t) bcdToBin(freqs[2*i])) * 10;
- calib->txFreq[i] = ((freq_t) bcdToBin(freqs[2*i+1])) * 10;
- }
-}
-
-void nvm_readHwInfo(hwInfo_t *info)
-{
- uint16_t freqMin = 0;
- uint16_t freqMax = 0;
- uint8_t lcdInfo = 0;
-
- /*
- * Hardware information data in MD3x0 devices is stored in security register
- * 0x3000.
- */
- W25Qx_wakeup();
- delayUs(5);
-
- (void) W25Qx_readSecurityRegister(0x3000, info->name, 8);
- (void) W25Qx_readSecurityRegister(0x3014, &freqMin, 2);
- (void) W25Qx_readSecurityRegister(0x3016, &freqMax, 2);
- (void) W25Qx_readSecurityRegister(0x301D, &lcdInfo, 1);
- W25Qx_sleep();
-
- /* Ensure correct null-termination of device name by removing the 0xff. */
- for(uint8_t i = 0; i < sizeof(info->name); i++)
- {
- if(info->name[i] == 0xFF) info->name[i] = '\0';
- }
-
- /* These devices are single-band only, either VHF or UHF. */
- freqMin = ((uint16_t) bcdToBin(freqMin))/10;
- freqMax = ((uint16_t) bcdToBin(freqMax))/10;
-
- if(freqMin < 200)
- {
- info->vhf_maxFreq = freqMax;
- info->vhf_minFreq = freqMin;
- info->vhf_band = 1;
- }
- else
- {
- info->uhf_maxFreq = freqMax;
- info->uhf_minFreq = freqMin;
- info->uhf_band = 1;
- }
-
- info->hw_version = lcdInfo & 0x03;
-}
-
-/**
- * TODO: functions temporarily implemented in "nvmem_settings_MDx.c"
-
-int nvm_readVFOChannelData(channel_t *channel)
-int nvm_readSettings(settings_t *settings)
-int nvm_writeSettings(const settings_t *settings)
-
-*/
diff --git a/platform/drivers/NVM/nvmem_MD9600.c b/platform/drivers/NVM/nvmem_MD9600.c
deleted file mode 100644
index e13598c4..00000000
--- a/platform/drivers/NVM/nvmem_MD9600.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2020 - 2024 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 *
- ***************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "W25Qx.h"
-
-W25Qx_DEVICE_DEFINE(eflash, 0x1000000) // 16 MB, 128 Mbit
-W25Qx_SECREG_DEFINE(cal1, 0x1000, 0x100) // 256 byte
-W25Qx_SECREG_DEFINE(cal2, 0x2000, 0x100) // 256 byte
-
-static const struct nvmDescriptor nvmDevices[] =
-{
- {
- .name = "External flash",
- .dev = &eflash,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 1",
- .dev = (const struct nvmDevice *) &cal1,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 2",
- .dev = (const struct nvmDevice *) &cal2,
- .partNum = 0,
- .partitions = NULL
- }
-};
-
-
-void nvm_init()
-{
- W25Qx_init();
-}
-
-void nvm_terminate()
-{
- W25Qx_terminate();
-}
-
-const struct nvmDescriptor *nvm_getDesc(const size_t index)
-{
- if(index > 3)
- return NULL;
-
- return &nvmDevices[index];
-}
-
-void nvm_readCalibData(void *buf)
-{
- (void) buf;
- return;
-}
-
-void nvm_readHwInfo(hwInfo_t *info)
-{
- (void) info;
-}
-
-/**
- * TODO: functions temporarily implemented in "nvmem_settings_MDx.c"
-
-int nvm_readVFOChannelData(channel_t *channel)
-int nvm_readSettings(settings_t *settings)
-int nvm_writeSettings(const settings_t *settings)
-
-*/
diff --git a/platform/drivers/NVM/nvmem_MDUV3x0.c b/platform/drivers/NVM/nvmem_MDUV3x0.c
deleted file mode 100644
index a491979a..00000000
--- a/platform/drivers/NVM/nvmem_MDUV3x0.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2020 - 2024 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 *
- ***************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "W25Qx.h"
-
-W25Qx_DEVICE_DEFINE(eflash, 0x1000000) // 16 MB, 128 Mbit
-W25Qx_SECREG_DEFINE(cal1, 0x1000, 0x100) // 256 byte
-W25Qx_SECREG_DEFINE(cal2, 0x2000, 0x100) // 256 byte
-
-static const struct nvmDescriptor nvmDevices[] =
-{
- {
- .name = "External flash",
- .dev = &eflash,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 1",
- .dev = (const struct nvmDevice *) &cal1,
- .partNum = 0,
- .partitions = NULL
- },
- {
- .name = "Cal. data 2",
- .dev = (const struct nvmDevice *) &cal2,
- .partNum = 0,
- .partitions = NULL
- }
-};
-
-
-void nvm_init()
-{
- W25Qx_init();
-}
-
-void nvm_terminate()
-{
- W25Qx_terminate();
-}
-
-const struct nvmDescriptor *nvm_getDesc(const size_t index)
-{
- if(index > 3)
- return NULL;
-
- return &nvmDevices[index];
-}
-
-void nvm_readCalibData(void *buf)
-{
- W25Qx_wakeup();
- delayUs(5);
-
- mduv3x0Calib_t *calib = ((mduv3x0Calib_t *) buf);
-
- /* Common calibration data */
- (void) W25Qx_readSecurityRegister(0x1000, (&calib->vox1), 6);
-
- /* UHF-band calibration data */
- (void) W25Qx_readSecurityRegister(0x1009, (&calib->uhfCal.freqAdjustMid), 1);
- (void) W25Qx_readSecurityRegister(0x1010, calib->uhfCal.txHighPower, 9);
- (void) W25Qx_readSecurityRegister(0x2090, calib->uhfCal.txMidPower, 9);
- (void) W25Qx_readSecurityRegister(0x1020, calib->uhfCal.txLowPower, 9);
- (void) W25Qx_readSecurityRegister(0x1030, calib->uhfCal.rxSensitivity, 9);
- (void) W25Qx_readSecurityRegister(0x1040, calib->uhfCal.openSql9, 9);
- (void) W25Qx_readSecurityRegister(0x1050, calib->uhfCal.closeSql9, 9);
- (void) W25Qx_readSecurityRegister(0x1070, calib->uhfCal.closeSql1, 9);
- (void) W25Qx_readSecurityRegister(0x1060, calib->uhfCal.openSql1, 9);
- (void) W25Qx_readSecurityRegister(0x1090, calib->uhfCal.ctcss67Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10a0, calib->uhfCal.ctcss151Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10b0, calib->uhfCal.ctcss254Hz, 9);
- (void) W25Qx_readSecurityRegister(0x10d0, calib->uhfCal.dcsMod1, 9);
- (void) W25Qx_readSecurityRegister(0x2030, calib->uhfCal.sendIrange, 9);
- (void) W25Qx_readSecurityRegister(0x2040, calib->uhfCal.sendQrange, 9);
- (void) W25Qx_readSecurityRegister(0x2070, calib->uhfCal.analogSendIrange, 9);
- (void) W25Qx_readSecurityRegister(0x2080, calib->uhfCal.analogSendQrange, 9);
-
- uint32_t freqs[18];
- (void) W25Qx_readSecurityRegister(0x20b0, ((uint8_t *) &freqs), 72);
-
- for(uint8_t i = 0; i < 9; i++)
- {
- calib->uhfCal.rxFreq[i] = ((freq_t) bcdToBin(freqs[2*i]));
- calib->uhfCal.txFreq[i] = ((freq_t) bcdToBin(freqs[2*i+1]));
- }
-
- /* VHF-band calibration data */
- (void) W25Qx_readSecurityRegister(0x100c, (&calib->vhfCal.freqAdjustMid), 1);
- (void) W25Qx_readSecurityRegister(0x1019, calib->vhfCal.txHighPower, 5);
- (void) W25Qx_readSecurityRegister(0x2099, calib->vhfCal.txMidPower, 5);
- (void) W25Qx_readSecurityRegister(0x1029, calib->vhfCal.txLowPower, 5);
- (void) W25Qx_readSecurityRegister(0x1039, calib->vhfCal.rxSensitivity, 5);
- (void) W25Qx_readSecurityRegister(0x109b, calib->vhfCal.ctcss67Hz, 5);
- (void) W25Qx_readSecurityRegister(0x10ab, calib->vhfCal.ctcss151Hz, 5);
- (void) W25Qx_readSecurityRegister(0x10bb, calib->vhfCal.ctcss254Hz, 5);
- (void) W25Qx_readSecurityRegister(0x10e0, calib->vhfCal.openSql9, 5);
- (void) W25Qx_readSecurityRegister(0x10e5, calib->vhfCal.closeSql9, 5);
- (void) W25Qx_readSecurityRegister(0x10ea, calib->vhfCal.closeSql1, 5);
- (void) W25Qx_readSecurityRegister(0x10ef, calib->vhfCal.openSql1, 5);
- (void) W25Qx_readSecurityRegister(0x10db, calib->vhfCal.dcsMod1, 5);
- (void) W25Qx_readSecurityRegister(0x2039, calib->vhfCal.sendIrange, 5);
- (void) W25Qx_readSecurityRegister(0x2049, calib->vhfCal.sendQrange, 5);
- (void) W25Qx_readSecurityRegister(0x2079, calib->uhfCal.analogSendIrange, 5);
- (void) W25Qx_readSecurityRegister(0x2089, calib->vhfCal.analogSendQrange, 5);
-
- (void) W25Qx_readSecurityRegister(0x2000, ((uint8_t *) &freqs), 40);
- W25Qx_sleep();
-
- for(uint8_t i = 0; i < 5; i++)
- {
- calib->vhfCal.rxFreq[i] = ((freq_t) bcdToBin(freqs[2*i]));
- calib->vhfCal.txFreq[i] = ((freq_t) bcdToBin(freqs[2*i+1]));
- }
-}
-
-void nvm_readHwInfo(hwInfo_t *info)
-{
- uint16_t vhf_freqMin = 0;
- uint16_t vhf_freqMax = 0;
- uint16_t uhf_freqMin = 0;
- uint16_t uhf_freqMax = 0;
- uint8_t lcdInfo = 0;
-
- /*
- * Hardware information data in MDUV3x0 devices is stored in security register
- * 0x3000.
- */
- W25Qx_wakeup();
- delayUs(5);
-
- (void) W25Qx_readSecurityRegister(0x3000, info->name, 8);
- (void) W25Qx_readSecurityRegister(0x3014, &uhf_freqMin, 2);
- (void) W25Qx_readSecurityRegister(0x3016, &uhf_freqMax, 2);
- (void) W25Qx_readSecurityRegister(0x3018, &vhf_freqMin, 2);
- (void) W25Qx_readSecurityRegister(0x301a, &vhf_freqMax, 2);
- (void) W25Qx_readSecurityRegister(0x301D, &lcdInfo, 1);
- W25Qx_sleep();
-
- /* Ensure correct null-termination of device name by removing the 0xff. */
- for(uint8_t i = 0; i < sizeof(info->name); i++)
- {
- if(info->name[i] == 0xFF) info->name[i] = '\0';
- }
-
- info->vhf_minFreq = ((uint16_t) bcdToBin(vhf_freqMin))/10;
- info->vhf_maxFreq = ((uint16_t) bcdToBin(vhf_freqMax))/10;
- info->uhf_minFreq = ((uint16_t) bcdToBin(uhf_freqMin))/10;
- info->uhf_maxFreq = ((uint16_t) bcdToBin(uhf_freqMax))/10;
- info->vhf_band = 1;
- info->uhf_band = 1;
- info->hw_version = lcdInfo & 0x03;
-}
-
-/**
- * TODO: functions temporarily implemented in "nvmem_settings_MDx.c"
-
-int nvm_readVFOChannelData(channel_t *channel)
-int nvm_readSettings(settings_t *settings)
-int nvm_writeSettings(const settings_t *settings)
-
-*/
diff --git a/platform/drivers/NVM/nvmem_MDx.c b/platform/drivers/NVM/nvmem_MDx.c
new file mode 100644
index 00000000..b60fcf48
--- /dev/null
+++ b/platform/drivers/NVM/nvmem_MDx.c
@@ -0,0 +1,210 @@
+/***************************************************************************
+ * Copyright (C) 2020 - 2024 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 *
+ ***************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "W25Qx.h"
+
+#define SECREG_READ(dev, offs, data, len) \
+ nvm_devRead((const struct nvmDevice *) dev, offs, data, len)
+
+static const struct W25QxCfg eflashCfg =
+{
+ .spi = &nvm_spi,
+ .cs = { FLASH_CS }
+};
+
+W25Qx_DEVICE_DEFINE(eflash, eflashCfg, 0x1000000) // 16 MB, 128 Mbit
+W25Qx_SECREG_DEFINE(cal1, eflashCfg, 0x1000, 0x100) // 256 byte
+W25Qx_SECREG_DEFINE(cal2, eflashCfg, 0x2000, 0x100) // 256 byte
+W25Qx_SECREG_DEFINE(hwInfo, eflashCfg, 0x3000, 0x100) // 256 byte
+
+static const struct nvmDescriptor nvmDevices[] =
+{
+ {
+ .name = "External flash",
+ .dev = &eflash,
+ .partNum = 0,
+ .partitions = NULL
+ },
+ {
+ .name = "Cal. data 1",
+ .dev = (const struct nvmDevice *) &cal1,
+ .partNum = 0,
+ .partitions = NULL
+ },
+ {
+ .name = "Cal. data 2",
+ .dev = (const struct nvmDevice *) &cal2,
+ .partNum = 0,
+ .partitions = NULL
+ }
+};
+
+
+void nvm_init()
+{
+ gpio_setMode(FLASH_CLK, ALTERNATE | ALTERNATE_FUNC(5));
+ gpio_setMode(FLASH_SDO, ALTERNATE | ALTERNATE_FUNC(5));
+ gpio_setMode(FLASH_SDI, ALTERNATE | ALTERNATE_FUNC(5));
+
+ spiStm32_init(&nvm_spi, 21000000, 0);
+ W25Qx_init(&eflash);
+}
+
+void nvm_terminate()
+{
+ W25Qx_terminate(&eflash);
+}
+
+const struct nvmDescriptor *nvm_getDesc(const size_t index)
+{
+ if(index > 3)
+ return NULL;
+
+ return &nvmDevices[index];
+}
+
+void nvm_readCalibData(void *buf)
+{
+ uint32_t freqs[18];
+
+ // Common calibration data between single and dual-band radios
+ struct CalData *calib = ((struct CalData *) buf);
+
+ // Security register 1: base address 0x1000
+ SECREG_READ(&cal1, 0x0009, &(calib->freqAdjustMid), 1);
+ SECREG_READ(&cal1, 0x0010, calib->txHighPower, 9);
+ SECREG_READ(&cal1, 0x0020, calib->txLowPower, 9);
+ SECREG_READ(&cal1, 0x0030, calib->rxSensitivity, 9);
+
+ // Security register 2: base address 0x2000
+ SECREG_READ(&cal2, 0x0030, calib->sendIrange, 9);
+ SECREG_READ(&cal2, 0x0040, calib->sendQrange, 9);
+ SECREG_READ(&cal2, 0x0070, calib->analogSendIrange, 9);
+ SECREG_READ(&cal2, 0x0080, calib->analogSendQrange, 9);
+ SECREG_READ(&cal2, 0x00b0, ((uint8_t *) &freqs), 72);
+
+ /*
+ * Frequency stored in calibration data is divided by ten: so, after
+ * bcdToBin conversion, we have something like 40'135'000. To ajdust
+ * things, frequency has to be multiplied by ten.
+ */
+ for(uint8_t i = 0; i < 9; i++)
+ {
+ calib->rxFreq[i] = ((freq_t) bcdToBin(freqs[2*i])) * 10;
+ calib->txFreq[i] = ((freq_t) bcdToBin(freqs[2*i+1])) * 10;
+ }
+
+ // Calibration data for dual-band radios only
+ #ifndef PLATFORM_MD3x0
+ mduv3x0Calib_t *cal = (mduv3x0Calib_t *) buf;
+ struct CalData *vhfCal = &(cal->vhfCal);
+
+ // Security register 1: base address 0x1000
+ SECREG_READ(&cal1, 0x000c, (&vhfCal->freqAdjustMid), 1);
+ SECREG_READ(&cal1, 0x0019, vhfCal->txHighPower, 5);
+ SECREG_READ(&cal1, 0x0029, vhfCal->txLowPower, 5);
+ SECREG_READ(&cal1, 0x0039, vhfCal->rxSensitivity, 5);
+
+ // Security register 2: base address 0x2000
+ SECREG_READ(&cal2, 0x0039, vhfCal->sendIrange, 5);
+ SECREG_READ(&cal2, 0x0049, vhfCal->sendQrange, 5);
+ SECREG_READ(&cal2, 0x0079, vhfCal->analogSendIrange, 5);
+ SECREG_READ(&cal2, 0x0089, vhfCal->analogSendQrange, 5);
+ SECREG_READ(&cal2, 0x0000, ((uint8_t *) &freqs), 40);
+
+ for(uint8_t i = 0; i < 5; i++)
+ {
+ vhfCal->rxFreq[i] = ((freq_t) bcdToBin(freqs[2*i]));
+ vhfCal->txFreq[i] = ((freq_t) bcdToBin(freqs[2*i+1]));
+ }
+ #endif
+}
+
+void nvm_readHwInfo(hwInfo_t *info)
+{
+ uint16_t freqMin = 0;
+ uint16_t freqMax = 0;
+ uint8_t lcdInfo = 0;
+
+ // Security register 3: base address 0x3000
+ SECREG_READ(&hwInfo, 0x0000, info->name, 8);
+ SECREG_READ(&hwInfo, 0x0014, &freqMin, 2);
+ SECREG_READ(&hwInfo, 0x0016, &freqMax, 2);
+ SECREG_READ(&hwInfo, 0x001D, &lcdInfo, 1);
+
+ // Ensure correct null-termination of device name by removing the 0xff.
+ for(uint8_t i = 0; i < sizeof(info->name); i++)
+ {
+ if(info->name[i] == 0xFF)
+ info->name[i] = '\0';
+ }
+
+ freqMin = ((uint16_t) bcdToBin(freqMin))/10;
+ freqMax = ((uint16_t) bcdToBin(freqMax))/10;
+
+ info->hw_version = lcdInfo & 0x03;
+
+ #ifdef PLATFORM_MD3x0
+ // Single band device, either VHF or UHF
+ if(freqMin < 200)
+ {
+ info->vhf_maxFreq = freqMax;
+ info->vhf_minFreq = freqMin;
+ info->vhf_band = 1;
+ }
+ else
+ {
+ info->uhf_maxFreq = freqMax;
+ info->uhf_minFreq = freqMin;
+ info->uhf_band = 1;
+ }
+ #else
+ // For dual band devices load the remaining data
+ uint16_t vhf_freqMin = 0;
+ uint16_t vhf_freqMax = 0;
+
+ SECREG_READ(&hwInfo, 0x0018, &vhf_freqMin, 2);
+ SECREG_READ(&hwInfo, 0x001a, &vhf_freqMax, 2);
+
+ info->vhf_minFreq = ((uint16_t) bcdToBin(vhf_freqMin))/10;
+ info->vhf_maxFreq = ((uint16_t) bcdToBin(vhf_freqMax))/10;
+ info->uhf_minFreq = freqMin;
+ info->uhf_maxFreq = freqMax;
+ info->vhf_band = 1;
+ info->uhf_band = 1;
+ #endif
+}
+
+/**
+ * TODO: functions temporarily implemented in "nvmem_settings_MDx.c"
+
+int nvm_readVFOChannelData(channel_t *channel)
+int nvm_readSettings(settings_t *settings)
+int nvm_writeSettings(const settings_t *settings)
+
+*/