MD3x0: updated nvm driver

This commit is contained in:
Silvano Seva 2024-09-22 16:28:13 +02:00
parent af5d10ec52
commit 3b877d20df
5 changed files with 41 additions and 22 deletions

View File

@ -154,9 +154,7 @@ openrtx_def += {'GIT_VERSION': git_version}
## TYT MDx family
##
mdx_src = ['openrtx/src/core/xmodem.c',
'openrtx/src/core/backup.c',
'platform/drivers/ADC/ADC1_MDx.c',
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',
@ -333,14 +331,14 @@ endif
## TYT MD-3x0 family
##
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',
'platform/drivers/baseband/HR_C5000_MDx.cpp',
'platform/drivers/keyboard/keyboard_MD3x.c',
'platform/drivers/display/HX8353_MD3x.cpp',
'platform/drivers/backlight/backlight_MDx.c',
'platform/targets/MD-3x0/platform.c']
'platform/targets/MD-3x0/platform.c',
'platform/targets/MD-3x0/hwconfig.c']
md3x0_inc = ['platform/targets/MD-3x0']
md3x0_def = {'PLATFORM_MD3x0': '', 'timegm': 'mktime'}

View File

@ -20,12 +20,15 @@
#include <interfaces/cps_io.h>
#include <interfaces/delays.h>
#include <nvmem_access.h>
#include <string.h>
#include <wchar.h>
#include <utils.h>
#include "cps_data_MD3x0.h"
#include "W25Qx.h"
extern const struct nvmDevice eflash;
static const uint32_t zoneBaseAddr = 0x149e0; /**< Base address of zones */
static const uint32_t chDataBaseAddr = 0x1ee00; /**< Base address of channel data */
static const uint32_t contactBaseAddr = 0x05f80; /**< Base address of contacts */
@ -33,6 +36,11 @@ static const uint32_t maxNumChannels = 1000; /**< Maximum number of channel
static const uint32_t maxNumZones = 250; /**< Maximum number of zones in memory */
static const uint32_t maxNumContacts = 10000; /**< Maximum number of contacts in memory */
static inline void W25Qx_readData(uint32_t addr, void *buf, size_t len)
{
nvm_devRead(&eflash, addr, buf, len);
}
/**
* This function does not apply to address-based codeplugs
@ -66,13 +74,9 @@ int cps_readChannel(channel_t *channel, uint16_t pos)
memset(channel, 0x00, sizeof(channel_t));
W25Qx_wakeup();
delayUs(5);
md3x0Channel_t chData;
uint32_t readAddr = chDataBaseAddr + pos * sizeof(md3x0Channel_t);
W25Qx_readData(readAddr, ((uint8_t *) &chData), sizeof(md3x0Channel_t));
W25Qx_sleep();
channel->mode = chData.channel_mode;
channel->bandwidth = (chData.bandwidth == 0) ? 0 : 1; // Consider 20kHz as 25kHz
@ -145,13 +149,9 @@ int cps_readBankHeader(bankHdr_t *b_header, uint16_t pos)
{
if(pos >= maxNumZones) return -1;
W25Qx_wakeup();
delayUs(5);
md3x0Zone_t zoneData;
uint32_t zoneAddr = zoneBaseAddr + pos * sizeof(md3x0Zone_t);
W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(md3x0Zone_t));
W25Qx_sleep();
// Check if zone is empty
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
@ -172,13 +172,9 @@ int cps_readBankData(uint16_t bank_pos, uint16_t ch_pos)
{
if(bank_pos >= maxNumZones) return -1;
W25Qx_wakeup();
delayUs(5);
md3x0Zone_t zoneData;
uint32_t zoneAddr = zoneBaseAddr + bank_pos * sizeof(md3x0Zone_t);
W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(md3x0Zone_t));
W25Qx_sleep();
// Check if zone is empty
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
@ -193,14 +189,10 @@ int cps_readContact(contact_t *contact, uint16_t pos)
{
if(pos >= maxNumContacts) return -1;
W25Qx_wakeup();
delayUs(5);
md3x0Contact_t contactData;
// Note: pos is 1-based to be consistent with channels
uint32_t contactAddr = contactBaseAddr + pos * sizeof(md3x0Contact_t);
W25Qx_readData(contactAddr, ((uint8_t *) &contactData), sizeof(md3x0Contact_t));
W25Qx_sleep();
// Check if contact is empty
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"

View File

@ -0,0 +1,27 @@
/***************************************************************************
* Copyright (C) 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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <spi_bitbang.h>
#include <spi_custom.h>
#include <spi_stm32.h>
#include <hwconfig.h>
#include <pinmap.h>
SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL)

View File

@ -27,6 +27,8 @@
extern "C" {
#endif
extern const struct spiDevice nvm_spi;
/* Device has a working real time clock */
#define CONFIG_RTC

View File

@ -81,7 +81,7 @@
#define BEEP_OUT GPIOC,8 /* CTCSS tone */
/* External flash */
#define FLASH_CS GPIOD,7
#define FLASH_CS &GpioD,7
#define FLASH_CLK GPIOB,3
#define FLASH_SDO GPIOB,4
#define FLASH_SDI GPIOB,5