diff --git a/openrtx/include/interfaces/cps_io.h b/openrtx/include/interfaces/cps_io.h new file mode 100644 index 00000000..b350ab1e --- /dev/null +++ b/openrtx/include/interfaces/cps_io.h @@ -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 * + ***************************************************************************/ + +#ifndef CPS_IO_H +#define CPS_IO_H + +#include +#include + +#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 diff --git a/openrtx/include/interfaces/nvmem.h b/openrtx/include/interfaces/nvmem.h index 665cc0bf..cf046d4c 100644 --- a/openrtx/include/interfaces/nvmem.h +++ b/openrtx/include/interfaces/nvmem.h @@ -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 #include #include +#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 */ diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 1734d6be..ff1a1379 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -66,6 +66,7 @@ #include #include #include +#include #include #ifdef HAS_GPS #include @@ -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) { diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 205738e9..44a6e687 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -24,6 +24,7 @@ #include #include #include +#include #include /* 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; diff --git a/platform/drivers/NVM/nvmem_GDx.c b/platform/drivers/NVM/nvmem_GDx.c index 463a8222..4a51ec69 100644 --- a/platform/drivers/NVM/nvmem_GDx.c +++ b/platform/drivers/NVM/nvmem_GDx.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #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; diff --git a/platform/drivers/NVM/nvmem_MD3x0.c b/platform/drivers/NVM/nvmem_MD3x0.c index 4c66fd18..eaddc684 100644 --- a/platform/drivers/NVM/nvmem_MD3x0.c +++ b/platform/drivers/NVM/nvmem_MD3x0.c @@ -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; diff --git a/platform/drivers/NVM/nvmem_MD9600.c b/platform/drivers/NVM/nvmem_MD9600.c index e4e1b4a4..1e7e0b47 100644 --- a/platform/drivers/NVM/nvmem_MD9600.c +++ b/platform/drivers/NVM/nvmem_MD9600.c @@ -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; diff --git a/platform/drivers/NVM/nvmem_MDUV3x0.c b/platform/drivers/NVM/nvmem_MDUV3x0.c index f0cde89c..b027e44e 100644 --- a/platform/drivers/NVM/nvmem_MDUV3x0.c +++ b/platform/drivers/NVM/nvmem_MDUV3x0.c @@ -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; diff --git a/platform/drivers/NVM/nvmem_Mod17.c b/platform/drivers/NVM/nvmem_Mod17.c index 68e7e9e7..cac12aa3 100644 --- a/platform/drivers/NVM/nvmem_Mod17.c +++ b/platform/drivers/NVM/nvmem_Mod17.c @@ -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; diff --git a/platform/drivers/NVM/nvmem_linux.c b/platform/drivers/NVM/nvmem_linux.c index 08b6366b..49341914 100644 --- a/platform/drivers/NVM/nvmem_linux.c +++ b/platform/drivers/NVM/nvmem_linux.c @@ -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) diff --git a/tests/platform/codeplug_demo.c b/tests/platform/codeplug_demo.c index 255b7981..9c0383c5 100644 --- a/tests/platform/codeplug_demo.c +++ b/tests/platform/codeplug_demo.c @@ -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); diff --git a/tests/platform/printContacts_MDx.c b/tests/platform/printContacts_MDx.c index b14ab4cb..27cb9a25 100644 --- a/tests/platform/printContacts_MDx.c +++ b/tests/platform/printContacts_MDx.c @@ -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,