Separated interface for CPS loading from the non volatile memory one

pull/68/head
Silvano Seva 2022-03-26 14:51:43 +01:00
rodzic c3cfaba4b2
commit da22d6ff64
12 zmienionych plików z 123 dodań i 71 usunięć

Wyświetl plik

@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (C) 2022 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/> *
***************************************************************************/
#ifndef CPS_IO_H
#define CPS_IO_H
#include <stdint.h>
#include <cps.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Interface for codeplug memory management.
*/
/**
* Read one channel entry from table stored in nonvolatile memory.
*
* @param channel: pointer to the channel_t data structure to be populated.
* @param pos: position, inside the channel table, from which read data.
* @return 0 on success, -1 on failure
*/
int cps_readChannelData(channel_t *channel, uint16_t pos);
/**
* Read one bank from the codeplug stored in the radio's filesystem.
*
* @param bank: pointer to the struct to be populated with the bank data.
* @param pos: position, inside the bank table, from which read data.
* @return 0 on success, -1 on failure
*/
int cps_readBankData(bank_t *bank, uint16_t pos);
/**
* Read one contact from table stored in nonvolatile memory.
*
* @param contact: pointer to the contact_t data structure to be populated.
* @param pos: position, inside the bank table, from which read data.
* @return 0 on success, -1 on failure
*/
int cps_readContactData(contact_t *contact, uint16_t pos);
#ifdef __cplusplus
}
#endif
#endif // CPS_IO_H

Wyświetl plik

@ -1,8 +1,8 @@
/***************************************************************************
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* Copyright (C) 2020 - 2022 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 *
@ -21,10 +21,14 @@
#ifndef NVMEM_H
#define NVMEM_H
#include "platform.h"
#include <stdint.h>
#include <cps.h>
#include <settings.h>
#include "platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Interface for nonvolatile memory management, usually an external SPI flash
@ -63,33 +67,6 @@ void nvm_loadHwInfo(hwInfo_t *info);
*/
int nvm_readVFOChannelData(channel_t *channel);
/**
* Read one channel entry from table stored in nonvolatile memory.
*
* @param channel: pointer to the channel_t data structure to be populated.
* @param pos: position, inside the channel table, from which read data.
* @return 0 on success, -1 on failure
*/
int nvm_readChannelData(channel_t *channel, uint16_t pos);
/**
* Read one bank from table stored in nonvolatile memory.
*
* @param bank: pointer to the bank_t data structure to be populated.
* @param pos: position, inside the bank table, from which read data.
* @return 0 on success, -1 on failure
*/
int nvm_readBankData(bank_t *bank, uint16_t pos);
/**
* Read one contact from table stored in nonvolatile memory.
*
* @param contact: pointer to the contact_t data structure to be populated.
* @param pos: position, inside the bank table, from which read data.
* @return 0 on success, -1 on failure
*/
int nvm_readContactData(contact_t *contact, uint16_t pos);
/**
* Read OpenRTX settings from storage.
*
@ -115,4 +92,8 @@ int nvm_writeSettings(const settings_t *settings);
*/
int nvm_writeSettingsAndVfo(const settings_t *settings, const channel_t *vfo);
#ifdef __cplusplus
}
#endif
#endif /* NVMEM_H */

Wyświetl plik

@ -66,6 +66,7 @@
#include <ui.h>
#include <rtx.h>
#include <interfaces/platform.h>
#include <interfaces/cps_io.h>
#include <interfaces/nvmem.h>
#ifdef HAS_GPS
#include <interfaces/gps.h>
@ -551,7 +552,7 @@ int _ui_fsm_loadChannel(uint16_t bank_index, bool *sync_rtx) {
// Channel index is 1-based while bank array access is 0-based
channel_index = state.bank.member[bank_index - 1];
}
int result = nvm_readChannelData(&channel, channel_index);
int result = cps_readChannelData(&channel, channel_index);
// Read successful and channel is valid
if(result != -1 && _ui_channel_valid(&channel))
{
@ -1311,21 +1312,21 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
bank_t bank;
// menu_selected is 0-based while channels are 1-based
// menu_selected == 0 corresponds to "All Channels" bank
if(nvm_readBankData(&bank, ui_state.menu_selected + 1) != -1)
if(cps_readBankData(&bank, ui_state.menu_selected + 1) != -1)
ui_state.menu_selected += 1;
}
else if(state.ui_screen == MENU_CHANNEL)
{
channel_t channel;
// menu_selected is 0-based while channels are 1-based
if(nvm_readChannelData(&channel, ui_state.menu_selected + 2) != -1)
if(cps_readChannelData(&channel, ui_state.menu_selected + 2) != -1)
ui_state.menu_selected += 1;
}
else if(state.ui_screen == MENU_CONTACTS)
{
contact_t contact;
// menu_selected is 0-based while channels are 1-based
if(nvm_readContactData(&contact, ui_state.menu_selected + 2) != -1)
if(cps_readContactData(&contact, ui_state.menu_selected + 2) != -1)
ui_state.menu_selected += 1;
}
}
@ -1341,7 +1342,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
else
{
state.bank_enabled = true;
result = nvm_readBankData(&newbank, ui_state.menu_selected);
result = cps_readBankData(&newbank, ui_state.menu_selected);
}
if(result != -1)
{

Wyświetl plik

@ -24,6 +24,7 @@
#include <backup.h>
#include <ui.h>
#include <interfaces/nvmem.h>
#include <interfaces/cps_io.h>
#include <interfaces/platform.h>
/* UI main screen helper functions, their implementation is in "ui_main.c" */
@ -267,7 +268,7 @@ int _ui_getBankName(char *buf, uint8_t max_len, uint8_t index)
else
{
bank_t bank;
result = nvm_readBankData(&bank, index);
result = cps_readBankData(&bank, index);
if(result != -1)
snprintf(buf, max_len, "%s", bank.name);
}
@ -277,7 +278,7 @@ int _ui_getBankName(char *buf, uint8_t max_len, uint8_t index)
int _ui_getChannelName(char *buf, uint8_t max_len, uint8_t index)
{
channel_t channel;
int result = nvm_readChannelData(&channel, index + 1);
int result = cps_readChannelData(&channel, index + 1);
if(result != -1)
snprintf(buf, max_len, "%s", channel.name);
return result;
@ -286,7 +287,7 @@ int _ui_getChannelName(char *buf, uint8_t max_len, uint8_t index)
int _ui_getContactName(char *buf, uint8_t max_len, uint8_t index)
{
contact_t contact;
int result = nvm_readContactData(&contact, index + 1);
int result = cps_readContactData(&contact, index + 1);
if(result != -1)
snprintf(buf, max_len, "%s", contact.name);
return result;

Wyświetl plik

@ -22,6 +22,7 @@
#include <wchar.h>
#include <interfaces/delays.h>
#include <interfaces/nvmem.h>
#include <interfaces/cps_io.h>
#include <calibInfo_GDx.h>
#include "AT24Cx.h"
#include "W25Qx.h"
@ -252,7 +253,7 @@ int nvm_readVFOChannelData(channel_t *channel)
return 0;
}
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumChannels))
return -1;
@ -372,7 +373,7 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos)
return 0;
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumZones)) return -1;
@ -406,7 +407,7 @@ int nvm_readBankData(bank_t* bank, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumContacts)) return -1;

Wyświetl plik

@ -167,7 +167,7 @@ int nvm_readVFOChannelData(channel_t *channel)
}
*/
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumChannels)) return -1;
@ -252,7 +252,7 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos)
return 0;
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumZones)) return -1;
@ -285,7 +285,7 @@ int nvm_readBankData(bank_t* bank, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumContacts)) return -1;

Wyświetl plik

@ -57,7 +57,7 @@ uint32_t _bcd2bin(uint32_t bcd)
/**
* Used to read channel data from SPI flash into a channel_t struct
*/
int _nvm_readChannelAtAddress(channel_t *channel, uint32_t addr)
int _cps_readChannelAtAddress(channel_t *channel, uint32_t addr)
{
W25Qx_wakeup();
delayUs(5);
@ -173,20 +173,20 @@ TODO: temporarily implemented in "nvmem_settings_MDx.c"
int nvm_readVFOChannelData(channel_t *channel)
{
return _nvm_readChannelAtAddress(channel, vfoChannelBaseAddr);
return _cps_readChannelAtAddress(channel, vfoChannelBaseAddr);
}
*/
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumChannels)) return -1;
// Note: pos is 1-based because an empty slot in a zone contains index 0
uint32_t readAddr = chDataBaseAddr + (pos - 1) * sizeof(mduv3x0Channel_t);
return _nvm_readChannelAtAddress(channel, readAddr);
return _cps_readChannelAtAddress(channel, readAddr);
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumZones)) return -1;
@ -227,7 +227,7 @@ int nvm_readBankData(bank_t* bank, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumContacts)) return -1;

Wyświetl plik

@ -57,7 +57,7 @@ uint32_t _bcd2bin(uint32_t bcd)
/**
* Used to read channel data from SPI flash into a channel_t struct
*/
int _nvm_readChannelAtAddress(channel_t *channel, uint32_t addr)
int _cps_readChannelAtAddress(channel_t *channel, uint32_t addr)
{
W25Qx_wakeup();
delayUs(5);
@ -273,20 +273,20 @@ TODO: temporarily implemented in "nvmem_settings_MDx.c"
int nvm_readVFOChannelData(channel_t *channel)
{
return _nvm_readChannelAtAddress(channel, vfoChannelBaseAddr);
return _cps_readChannelAtAddress(channel, vfoChannelBaseAddr);
}
*/
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumChannels)) return -1;
// Note: pos is 1-based because an empty slot in a zone contains index 0
uint32_t readAddr = chDataBaseAddr + (pos - 1) * sizeof(mduv3x0Channel_t);
return _nvm_readChannelAtAddress(channel, readAddr);
return _cps_readChannelAtAddress(channel, readAddr);
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumZones)) return -1;
@ -327,7 +327,7 @@ int nvm_readBankData(bank_t* bank, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumContacts)) return -1;

Wyświetl plik

@ -56,21 +56,21 @@ int nvm_readVFOChannelData(channel_t *channel)
return 0;
}
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
(void) channel;
(void) pos;
return -1;
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
(void) bank;
(void) pos;
return -1;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
(void) contact;
(void) pos;

Wyświetl plik

@ -111,7 +111,7 @@ int _nvm_write(const char *path, const void *data, size_t size)
* \param size: the size of the data to read
* \return 0 on success, -1 on failure
*/
int _nvm_read(const char *path, void *data, size_t size)
int _cps_read(const char *path, void *data, size_t size)
{
printf("Reading %s\n", path);
@ -231,10 +231,10 @@ void nvm_loadHwInfo(hwInfo_t *info)
int nvm_readVFOChannelData(channel_t *channel)
{
return _nvm_read(memory_paths[P_VFO], channel, sizeof(channel_t));
return _cps_read(memory_paths[P_VFO], channel, sizeof(channel_t));
}
int nvm_readChannelData(channel_t *channel, uint16_t pos)
int cps_readChannelData(channel_t *channel, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumChannels)) return -1;
@ -247,7 +247,7 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos)
return 0;
}
int nvm_readBankData(bank_t* bank, uint16_t pos)
int cps_readBankData(bank_t* bank, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumZones)) return -1;
@ -261,7 +261,7 @@ int nvm_readBankData(bank_t* bank, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
int cps_readContactData(contact_t *contact, uint16_t pos)
{
if((pos <= 0) || (pos > maxNumContacts)) return -1;
@ -273,7 +273,7 @@ int nvm_readContactData(contact_t *contact, uint16_t pos)
int nvm_readSettings(settings_t *settings)
{
return _nvm_read(memory_paths[P_SETTINGS], settings, sizeof(settings_t));
return _cps_read(memory_paths[P_SETTINGS], settings, sizeof(settings_t));
}
int nvm_writeSettings(const settings_t *settings)

Wyświetl plik

@ -34,7 +34,7 @@ int main()
for(int pos=0,result=0; result != -1; pos++)
{
channel_t ch;
result = nvm_readChannelData(&ch, pos);
result = cps_readChannelData(&ch, pos);
if(result != -1)
{
printf("Channel n.%d:\r\n", pos+1);
@ -52,7 +52,7 @@ int main()
for(int pos=0,result=0; result != -1; pos++)
{
zone_t bank;
result = nvm_readZoneData(&bank, pos);
result = cps_readZoneData(&bank, pos);
if(result != -1)
{
printf("Zone n.%d:\r\n", pos+1);
@ -71,7 +71,7 @@ int main()
for(int pos=0,result=0; result != -1; pos++)
{
contact_t contact;
result = nvm_readContactData(&contact, pos);
result = cps_readContactData(&contact, pos);
if(result != -1)
{
printf("Contact n.%d:\r\n", pos+1);

Wyświetl plik

@ -35,7 +35,7 @@ int main()
getchar();
channel_t ch;
nvm_readChannelData(&ch, pos);
cps_readChannelData(&ch, pos);
printf("Contact entry %d:\r\n", pos+1);
printf(" %s\r\n TX: %ld\r\n RX: %ld\r\n Mode: %s\r\n Bandwidth: %s\r\n",
ch.name,