/******************************************************
*Name : LearnProj.cpp
*Device: TMS320F28335
*Date: 8.11.12
*Note: the simple program in CCS
*******************************************************/
//#include "filter.hpp"
#include "adcmodel.hpp"
#define WDCR *((volatile int *)0x7029) /* WD Control reg */
#define DISABLE_WD 0x0068
void Disable_WD(void)
{
asm(" eallow");
WDCR |= DISABLE_WD;
asm(" edis");
}
//this is the samples amount in the *.dat file
const int kLength = 5387;
float fileWithSamples[ kLength ];
static void dataIO();
float g_sample;
int main() {
Disable_WD();
//function to catch the breakPoint and read all massive of samples into
//fileWithSamples buffer
dataIO();
CAdcModel adc( fileWithSamples, kLength );
while(1) {
//reading ADC
adc.getSample( g_sample );
}
return 0;
}
/**
@function dataIO
The dataIO function acts as a placeholder.It is a convenient place to connect
a Probe Point (or BreakPoint in the new versions of CCS) that injects data from a PC file.
@detailed - for details see spru301, 4.3 Adding a Probe Point for File I/O
*/
static void dataIO() {
/* do data I/O */
return;
}
/**
@file adcmodel.hpp
@brief target platform - xxx
@date xx.11.2012
@note It is the adc model realized as file.dat which is contained signal samples
from MatLab. This model get the sample from the memory where file.dat is allocated.
All of this need only for checking an algorithm
*/
#ifndef ADCMODEL_HPP
#define ADCMODEL_HPP
/**
@class CAdcModelBase
Base class for modeling adc behavior.
@note Realize class hierarchy by means of "Non-Virtual interface" pattern
*/
class CAdcModelBase {
public:
///Standard types replacement for portability
///type for ADC samples
typedef float adc_valueT;
///define a synonym for "adc_valueT". "outputSampleT" contains function output
typedef adc_valueT outputSampleT;
public:
/// Standard constructor with initialization list
inline CAdcModelBase() : pAdcBuff(0), m_adcBuffLen(0), m_index(0) {}
explicit inline CAdcModelBase(const adc_valueT* buffer, const int& buffLength);
virtual ~CAdcModelBase();
inline void getSample(outputSampleT& out);
protected:
virtual void do_getSample(outputSampleT& out) = 0;
/// Reference to external buffer which allocates the MatLab signal samples
/// i.e. allocates some_file.dat
const adc_valueT *pAdcBuff;
/// to know the buffer length
int m_adcBuffLen;
///index for pAdcBuff
int m_index;
};
class CAdcModel : public CAdcModelBase {
public:
inline CAdcModel() {}
explicit inline CAdcModel(const adc_valueT* _buffer, const int& _buffLength);
virtual ~CAdcModel();
protected:
virtual void do_getSample(outputSampleT& out);
};
// !> inline-methods must be defined in h-files <!
/**
@brief Example of coding style
@code
inline Account::
Account( const char* name, double opening_bal )
: _name( name ), _balance( opening_bal )
{
_acct_nmbr = het_unique_acct_nmbr();
}
@endcode
*/
/**
@function CAdcModelBase::CAdcModelBase
@brief Constructor
@param buffer - address to external buffer containing FileOfSamples.dat
@code
//somewhere in the code
float samplesFromMatlab[ SAMPLES_AMOUNTS ];
<..>
//creating the new instance
CAdcModelBase AdcModel(samplesFromMatlab, SAMPLES_AMOUNTS);
<..>
@endcode
@param buffLength - it's the buffer length. We must passing it, because "buffer" is the
pointer to external non-dynamical buffer and we must know its
parameters
*/
inline CAdcModelBase::
CAdcModelBase(const adc_valueT* buffer, const int& buffLength)
: pAdcBuff( buffer ), m_adcBuffLen( buffLength ), m_index(0) {
}
/**
@function CAdcModelBase::getSample
@brief Interface to get one sample from virtual model of ADC
@detailed Part of the "Non-Virtual interface" pattern
@return one ADC sample with "adc_valueT" type
*/
inline void CAdcModelBase::
getSample(outputSampleT& out) {
//some code
do_getSample(out);
//some code
}
/**
@brief Constructor
*/
inline CAdcModel::
CAdcModel(const adc_valueT* _buffer, const int& _buffLength)
: CAdcModelBase(_buffer, _buffLength) {
}
#endif // ADCMODEL_HPP
/**
@file adcmodel.cpp
@brief target platform - xxx
@date xx.11.2012
*/
#include "adcmodel.hpp"
/**
@brief Destructor
*/
CAdcModelBase::~CAdcModelBase() {
}
/**
@function CAdcModel::~CAdcModel()
@brief Destructor
*/
CAdcModel::~CAdcModel() {
}
/**
@function CAdcModel::do_getSample
@brief Realization of interface for obtaining the sample
@return one ADC sample with "adc_valueT" type
*/
void CAdcModel::do_getSample(outputSampleT& out) {
out = *(pAdcBuff + m_index);
//Moving on fileOfSamples.dat : make looped index
//prefix form of decrement (++i) in the use because this way more efficient i.e.
//no temporary value is required.
m_index = (++m_index) % m_adcBuffLen;
}
Комментариев нет:
Отправить комментарий