kopia lustrzana https://github.com/OpenRTX/OpenRTX
API to access external nonvolatile memory, implementation for MD3x0 devices and testsuite for printing calibration values of MD3x0 devices
rodzic
9b14e9fae7
commit
310f19c6b7
|
@ -0,0 +1,49 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 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 NVMEM_H
|
||||
#define NVMEM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Interface for nonvolatile memory management, usually an external SPI flash
|
||||
* memory, containing calibration, contact data and so on.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialise NVM driver.
|
||||
*/
|
||||
void nvm_init();
|
||||
|
||||
/**
|
||||
* Terminate NVM driver.
|
||||
*/
|
||||
void nvm_terminate();
|
||||
|
||||
/**
|
||||
* Load calibration data from nonvolatile memory.
|
||||
*
|
||||
* @param buf: destination buffer for calibration data.
|
||||
*/
|
||||
void nvm_readCalibData(void *buf);
|
||||
|
||||
|
||||
#endif /* NVMEM_H */
|
|
@ -60,7 +60,7 @@ void extFlash_init()
|
|||
| SPI_CR1_SPE; /* Enable peripheral */
|
||||
}
|
||||
|
||||
void extFlash_shutdown()
|
||||
void extFlash_terminate()
|
||||
{
|
||||
extFlash_sleep();
|
||||
|
||||
|
@ -98,7 +98,7 @@ ssize_t extFlash_readSecurityRegister(uint32_t addr, uint8_t* buf, size_t len)
|
|||
size_t readLen = len;
|
||||
if((addrRange + len) > 0xFF)
|
||||
{
|
||||
readLen = len + (addrRange & 0xFF);
|
||||
readLen = 0xFF - (addrRange & 0xFF);
|
||||
}
|
||||
|
||||
gpio_clearPin(FLASH_CS);
|
||||
|
|
|
@ -39,7 +39,7 @@ void extFlash_init();
|
|||
/**
|
||||
* Terminate driver for external flash.
|
||||
*/
|
||||
void extFlash_shutdown();
|
||||
void extFlash_terminate();
|
||||
|
||||
/**
|
||||
* Release flash chip from power down mode, this function should be called at
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 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 NVMTYPES_MD3x0_H
|
||||
#define NVMTYPES_MD3x0_H
|
||||
|
||||
#include <datatypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Data types defining the structure of data stored in external flash memory of
|
||||
* MD3x0 devices.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Calibration data for MD-3x0.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t vox1;
|
||||
uint8_t vox10;
|
||||
uint8_t rxLowVoltage;
|
||||
uint8_t rxFullVoltage;
|
||||
uint8_t rssi1;
|
||||
uint8_t rssi4;
|
||||
uint8_t analogMic;
|
||||
uint8_t digitalMic;
|
||||
uint8_t freqAdjustHigh;
|
||||
uint8_t freqAdjustMid;
|
||||
uint8_t freqAdjustLow;
|
||||
freq_t rxFreq[9];
|
||||
freq_t txFreq[9];
|
||||
uint8_t txHighPower[9];
|
||||
uint8_t txLowPower[9];
|
||||
uint8_t rxSensitivity[9];
|
||||
uint8_t openSql9[9];
|
||||
uint8_t closeSql9[9];
|
||||
uint8_t openSql1[9];
|
||||
uint8_t closeSql1[9];
|
||||
uint8_t maxVolume[9];
|
||||
uint8_t ctcss67Hz[9];
|
||||
uint8_t ctcss151Hz[9];
|
||||
uint8_t ctcss254Hz[9];
|
||||
uint8_t dcsMod2[9];
|
||||
uint8_t dcsMod1[9];
|
||||
uint8_t mod1Partial[9];
|
||||
uint8_t analogVoiceAdjust[9];
|
||||
uint8_t lockVoltagePartial[9];
|
||||
uint8_t sendIpartial[9];
|
||||
uint8_t sendQpartial[9];
|
||||
uint8_t sendIrange[9];
|
||||
uint8_t sendQrange[9];
|
||||
uint8_t rxIpartial[9];
|
||||
uint8_t rxQpartial[9];
|
||||
uint8_t analogSendIrange[9];
|
||||
uint8_t analogSendQrange[9];
|
||||
}md3x0Calib_t;
|
||||
|
||||
#endif /* NVMTYPES_MD3x0_H */
|
|
@ -0,0 +1,95 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 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 "nvmem.h"
|
||||
#include "extFlash_MDx.h"
|
||||
#include <nvmTypes_MD3x0.h>
|
||||
#include <delays.h>
|
||||
|
||||
/**
|
||||
* \internal Utility function to convert 4 byte BCD values into a 32-bit
|
||||
* unsigned integer ones.
|
||||
*/
|
||||
uint32_t _bcd2bin(uint32_t bcd)
|
||||
{
|
||||
return ((bcd >> 28) & 0x0F) * 10000000 +
|
||||
((bcd >> 24) & 0x0F) * 1000000 +
|
||||
((bcd >> 20) & 0x0F) * 100000 +
|
||||
((bcd >> 16) & 0x0F) * 10000 +
|
||||
((bcd >> 12) & 0x0F) * 1000 +
|
||||
((bcd >> 8) & 0x0F) * 100 +
|
||||
((bcd >> 4) & 0x0F) * 10 +
|
||||
(bcd & 0x0F);
|
||||
}
|
||||
|
||||
void nvm_init()
|
||||
{
|
||||
extFlash_init();
|
||||
}
|
||||
|
||||
void nvm_terminate()
|
||||
{
|
||||
extFlash_terminate();
|
||||
}
|
||||
|
||||
void nvm_readCalibData(void *buf)
|
||||
{
|
||||
extFlash_wakeup();
|
||||
delayUs(5);
|
||||
|
||||
md3x0Calib_t *calib = ((md3x0Calib_t *) buf);
|
||||
|
||||
(void) extFlash_readSecurityRegister(0x1000, &(calib->vox1), 11);
|
||||
(void) extFlash_readSecurityRegister(0x1010, calib->txHighPower, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1020, calib->txLowPower, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1030, calib->rxSensitivity, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1040, calib->openSql9, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1050, calib->closeSql9, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1060, calib->openSql1, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1070, calib->closeSql1, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1080, calib->maxVolume, 9);
|
||||
(void) extFlash_readSecurityRegister(0x1090, calib->ctcss67Hz, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10a0, calib->ctcss151Hz, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10b0, calib->ctcss254Hz, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10c0, calib->dcsMod2, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10d0, calib->dcsMod1, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10e0, calib->mod1Partial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x10f0, calib->analogVoiceAdjust, 9);
|
||||
|
||||
(void) extFlash_readSecurityRegister(0x2000, calib->lockVoltagePartial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2010, calib->sendIpartial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2020, calib->sendQpartial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2030, calib->sendIrange, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2040, calib->sendQrange, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2050, calib->rxIpartial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2060, calib->rxQpartial, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2070, calib->analogSendIrange, 9);
|
||||
(void) extFlash_readSecurityRegister(0x2080, calib->analogSendQrange, 9);
|
||||
|
||||
uint32_t freqs[18];
|
||||
(void) extFlash_readSecurityRegister(0x20b0, ((uint8_t *) &freqs), 72);
|
||||
extFlash_sleep();
|
||||
|
||||
for(uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
calib->rxFreq[i] = ((freq_t) _bcd2bin(freqs[2*i]));
|
||||
calib->txFreq[i] = ((freq_t) _bcd2bin(freqs[2*i+1]));
|
||||
}
|
||||
}
|
|
@ -83,4 +83,10 @@
|
|||
#define CTCSS_OUT GPIOC,7 /* System "beep" */
|
||||
#define BEEP_OUT GPIOC,8 /* CTCSS tone */
|
||||
|
||||
/* External flash */
|
||||
#define FLASH_CS GPIOD,7
|
||||
#define FLASH_CLK GPIOB,3
|
||||
#define FLASH_SDO GPIOB,4
|
||||
#define FLASH_SDI GPIOB,5
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include "nvmem.h"
|
||||
#include "nvmTypes_MD3x0.h"
|
||||
#include "extFlash_MDx.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
nvm_init();
|
||||
|
||||
while(1)
|
||||
{
|
||||
getchar();
|
||||
|
||||
uint8_t i;
|
||||
md3x0Calib_t cal;
|
||||
nvm_readCalibData(&cal);
|
||||
|
||||
printf("vox1: %03d\r\n", cal.vox1);
|
||||
printf("vox10: %03d\r\n", cal.vox10);
|
||||
printf("rxLowVoltage: %03d\r\n", cal.rxLowVoltage);
|
||||
printf("rxFullVoltage: %03d\r\n", cal.rxFullVoltage);
|
||||
printf("rssi1: %03d\r\n", cal.rssi1);
|
||||
printf("rssi4: %03d\r\n", cal.rssi4);
|
||||
printf("analogMic: %03d\r\n", cal.analogMic);
|
||||
printf("digitalMic: %03d\r\n", cal.digitalMic);
|
||||
printf("freqAdjustHigh: %03d\r\n", cal.freqAdjustHigh);
|
||||
printf("freqAdjustMid: %03d\r\n", cal.freqAdjustMid);
|
||||
printf("freqAdjustLow: %03d", cal.freqAdjustLow);
|
||||
|
||||
printf("\r\n\r\nrxFreq: "); for(i = 0; i < 9; i++) printf("%d ", cal.rxFreq[i]);
|
||||
printf("\r\ntxFreq: "); for(i = 0; i < 9; i++) printf("%d ", cal.txFreq[i]);
|
||||
printf("\r\ntxHighPower: "); for(i = 0; i < 9; i++) printf("%03d ", cal.txHighPower[i]);
|
||||
printf("\r\ntxLowPower: "); for(i = 0; i < 9; i++) printf("%03d ", cal.txLowPower[i]);
|
||||
printf("\r\nrxSensitivity: "); for(i = 0; i < 9; i++) printf("%03d ", cal.rxSensitivity[i]);
|
||||
printf("\r\nopenSql9: "); for(i = 0; i < 9; i++) printf("%03d ", cal.openSql9[i]);
|
||||
printf("\r\ncloseSql9: "); for(i = 0; i < 9; i++) printf("%03d ", cal.closeSql9[i]);
|
||||
printf("\r\nopenSql1: "); for(i = 0; i < 9; i++) printf("%03d ", cal.openSql1[i]);
|
||||
printf("\r\ncloseSql1: "); for(i = 0; i < 9; i++) printf("%03d ", cal.closeSql1[i]);
|
||||
printf("\r\nmaxVolume: "); for(i = 0; i < 9; i++) printf("%03d ", cal.maxVolume[i]);
|
||||
printf("\r\nctcss67Hz: "); for(i = 0; i < 9; i++) printf("%03d ", cal.ctcss67Hz[i]);
|
||||
printf("\r\nctcss151Hz: "); for(i = 0; i < 9; i++) printf("%03d ", cal.ctcss151Hz[i]);
|
||||
printf("\r\nctcss254Hz: "); for(i = 0; i < 9; i++) printf("%03d ", cal.ctcss254Hz[i]);
|
||||
printf("\r\ndcsMod2: "); for(i = 0; i < 9; i++) printf("%03d ", cal.dcsMod2[i]);
|
||||
printf("\r\ndcsMod1: "); for(i = 0; i < 9; i++) printf("%03d ", cal.dcsMod1[i]);
|
||||
printf("\r\nmod1Partial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.mod1Partial[i]);
|
||||
printf("\r\nanalogVoiceAdjust: "); for(i = 0; i < 9; i++) printf("%03d ", cal.analogVoiceAdjust[i]);
|
||||
printf("\r\nlockVoltagePartial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.lockVoltagePartial[i]);
|
||||
printf("\r\nsendIpartial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.sendIpartial[i]);
|
||||
printf("\r\nsendQpartial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.sendQpartial[i]);
|
||||
printf("\r\nsendIrange: "); for(i = 0; i < 9; i++) printf("%03d ", cal.sendIrange[i]);
|
||||
printf("\r\nsendQrange: "); for(i = 0; i < 9; i++) printf("%03d ", cal.sendQrange[i]);
|
||||
printf("\r\nrxIpartial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.rxIpartial[i]);
|
||||
printf("\r\nrxQpartial: "); for(i = 0; i < 9; i++) printf("%03d ", cal.rxQpartial[i]);
|
||||
printf("\r\nanalogSendIrange: "); for(i = 0; i < 9; i++) printf("%03d ", cal.analogSendIrange[i]);
|
||||
printf("\r\nanalogSendQrange: "); for(i = 0; i < 9; i++) printf("%03d ", cal.analogSendQrange[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Ładowanie…
Reference in New Issue