Нравится? Делимся информацией!

четверг, 29 ноября 2012 г.

My first simple C++ program in Code Composer Studio

  1. /******************************************************
  2. *Name : LearnProj.cpp
  3. *Device: TMS320F28335
  4. *Date: 8.11.12
  5. *Note: the simple program in CCS
  6. *******************************************************/
  7. //#include "filter.hpp"
  8. #include "adcmodel.hpp"
  9.  
  10. #define WDCR *((volatile int *)0x7029) /* WD Control reg */
  11. #define DISABLE_WD 0x0068
  12.  
  13. void Disable_WD(void)
  14. {
  15. asm(" eallow");
  16. WDCR |= DISABLE_WD;
  17. asm(" edis");
  18. }
  19.  
  20. //this is the samples amount in the *.dat file
  21. const int kLength = 5387;
  22. float fileWithSamples[ kLength ];
  23.  
  24. static void dataIO();
  25. float g_sample;
  26.  
  27. int main() {
  28.  
  29. Disable_WD();
  30.  
  31. //function to catch the breakPoint and read all massive of samples into
  32. //fileWithSamples buffer
  33. dataIO();
  34.  
  35. CAdcModel adc( fileWithSamples, kLength );
  36.  
  37. while(1) {
  38. //reading ADC
  39. adc.getSample( g_sample );
  40. }
  41.  
  42. return 0;
  43. }
  44.  
  45. /**
  46. @function dataIO
  47. The dataIO function acts as a placeholder.It is a convenient place to connect
  48. a Probe Point (or BreakPoint in the new versions of CCS) that injects data from a PC file.
  49. @detailed - for details see spru301, 4.3 Adding a Probe Point for File I/O
  50. */
  51. static void dataIO() {
  52. /* do data I/O */
  53. return;
  54. }
  55.  
  56.  
  57. /**
  58. @file adcmodel.hpp
  59. @brief target platform - xxx
  60. @date xx.11.2012
  61. @note It is the adc model realized as file.dat which is contained signal samples
  62. from MatLab. This model get the sample from the memory where file.dat is allocated.
  63. All of this need only for checking an algorithm
  64. */
  65. #ifndef ADCMODEL_HPP
  66. #define ADCMODEL_HPP
  67. /**
  68. @class CAdcModelBase
  69. Base class for modeling adc behavior.
  70. @note Realize class hierarchy by means of "Non-Virtual interface" pattern
  71. */
  72.  
  73. class CAdcModelBase {
  74. public:
  75. ///Standard types replacement for portability
  76. ///type for ADC samples
  77. typedef float adc_valueT;
  78. ///define a synonym for "adc_valueT". "outputSampleT" contains function output
  79. typedef adc_valueT outputSampleT;
  80. public:
  81. /// Standard constructor with initialization list
  82. inline CAdcModelBase() : pAdcBuff(0), m_adcBuffLen(0), m_index(0) {}
  83. explicit inline CAdcModelBase(const adc_valueT* buffer, const int& buffLength);
  84. virtual ~CAdcModelBase();
  85.  
  86. inline void getSample(outputSampleT& out);
  87. protected:
  88. virtual void do_getSample(outputSampleT& out) = 0;
  89.  
  90. /// Reference to external buffer which allocates the MatLab signal samples
  91. /// i.e. allocates some_file.dat
  92. const adc_valueT *pAdcBuff;
  93. /// to know the buffer length
  94. int m_adcBuffLen;
  95. ///index for pAdcBuff
  96. int m_index;
  97. };
  98.  
  99. class CAdcModel : public CAdcModelBase {
  100. public:
  101. inline CAdcModel() {}
  102. explicit inline CAdcModel(const adc_valueT* _buffer, const int& _buffLength);
  103. virtual ~CAdcModel();
  104.  
  105. protected:
  106. virtual void do_getSample(outputSampleT& out);
  107. };
  108.  
  109.  
  110. // !> inline-methods must be defined in h-files <!
  111.  
  112. /**
  113. @brief Example of coding style
  114. @code
  115. inline Account::
  116. Account( const char* name, double opening_bal )
  117.   : _name( name ), _balance( opening_bal )
  118. {
  119.   _acct_nmbr = het_unique_acct_nmbr();
  120. }
  121. @endcode
  122. */
  123. /**
  124. @function CAdcModelBase::CAdcModelBase
  125. @brief Constructor
  126. @param buffer - address to external buffer containing FileOfSamples.dat
  127. @code
  128. //somewhere in the code
  129. float samplesFromMatlab[ SAMPLES_AMOUNTS ];
  130. <..>
  131. //creating the new instance
  132. CAdcModelBase AdcModel(samplesFromMatlab, SAMPLES_AMOUNTS);
  133. <..>
  134. @endcode
  135. @param buffLength - it's the buffer length. We must passing it, because "buffer" is the
  136. pointer to external non-dynamical buffer and we must know its
  137. parameters
  138. */
  139. inline CAdcModelBase::
  140. CAdcModelBase(const adc_valueT* buffer, const int& buffLength)
  141. : pAdcBuff( buffer ), m_adcBuffLen( buffLength ), m_index(0) {
  142.  
  143. }
  144. /**
  145. @function CAdcModelBase::getSample
  146. @brief Interface to get one sample from virtual model of ADC
  147. @detailed Part of the "Non-Virtual interface" pattern
  148. @return one ADC sample with "adc_valueT" type
  149. */
  150. inline void CAdcModelBase::
  151. getSample(outputSampleT& out) {
  152. //some code
  153. do_getSample(out);
  154. //some code
  155. }
  156.  
  157. /**
  158. @brief Constructor
  159. */
  160. inline CAdcModel::
  161. CAdcModel(const adc_valueT* _buffer, const int& _buffLength)
  162. : CAdcModelBase(_buffer, _buffLength) {
  163.  
  164. }
  165.  
  166. #endif // ADCMODEL_HPP
  167.  
  168.  
  169. /**
  170. @file adcmodel.cpp
  171. @brief target platform - xxx
  172. @date xx.11.2012
  173. */
  174. #include "adcmodel.hpp"
  175.  
  176. /**
  177. @brief Destructor
  178. */
  179. CAdcModelBase::~CAdcModelBase() {
  180. }
  181.  
  182.  
  183. /**
  184. @function CAdcModel::~CAdcModel()
  185. @brief Destructor
  186. */
  187. CAdcModel::~CAdcModel() {
  188.  
  189. }
  190. /**
  191. @function CAdcModel::do_getSample
  192. @brief Realization of interface for obtaining the sample
  193. @return one ADC sample with "adc_valueT" type
  194. */
  195. void CAdcModel::do_getSample(outputSampleT& out) {
  196. out = *(pAdcBuff + m_index);
  197.  
  198. //Moving on fileOfSamples.dat : make looped index
  199. //prefix form of decrement (++i) in the use because this way more efficient i.e.
  200. //no temporary value is required.
  201. m_index = (++m_index) % m_adcBuffLen;
  202. }

Комментариев нет:

Отправить комментарий