| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE CostasLoop. |
|---|
| 6 | |
|---|
| 7 | OSSIE CostasLoop is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE CostasLoop is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE CostasLoop; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include <string> |
|---|
| 25 | #include <iostream> |
|---|
| 26 | #include <fstream> |
|---|
| 27 | #include <sys/time.h> |
|---|
| 28 | #include <sys/resource.h> |
|---|
| 29 | #include "CostasLoop.h" |
|---|
| 30 | |
|---|
| 31 | #include "CostasLoopFPGAInterface.h" |
|---|
| 32 | |
|---|
| 33 | CostasLoop_i::CostasLoop_i(const char *uuid, omni_condition *condition) : |
|---|
| 34 | Resource_impl(uuid), component_running(condition) |
|---|
| 35 | { |
|---|
| 36 | dataOut_0 = new standardInterfaces_i::complexShort_u("dataOut"); |
|---|
| 37 | dataIn_0 = new standardInterfaces_i::complexShort_p("dataIn"); |
|---|
| 38 | |
|---|
| 39 | //Create the thread for the writer's processing function |
|---|
| 40 | processing_thread = new omni_thread(Run, (void *) this); |
|---|
| 41 | |
|---|
| 42 | //Start the thread containing the writer's processing function |
|---|
| 43 | processing_thread->start(); |
|---|
| 44 | |
|---|
| 45 | // open interface to FPGA |
|---|
| 46 | openFPGAInterface(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | CostasLoop_i::~CostasLoop_i(void) |
|---|
| 50 | { |
|---|
| 51 | // close interface to FPGA |
|---|
| 52 | closeFPGAInterface(); |
|---|
| 53 | |
|---|
| 54 | delete dataOut_0; |
|---|
| 55 | delete dataIn_0; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | // Static function for omni thread |
|---|
| 59 | void CostasLoop_i::Run( void * data ) |
|---|
| 60 | { |
|---|
| 61 | ((CostasLoop_i*)data)->ProcessData(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | CORBA::Object_ptr CostasLoop_i::getPort( const char* portName ) throw ( |
|---|
| 65 | CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 66 | { |
|---|
| 67 | DEBUG(3, CostasLoop, "getPort() invoked with " << portName) |
|---|
| 68 | |
|---|
| 69 | CORBA::Object_var p; |
|---|
| 70 | |
|---|
| 71 | p = dataOut_0->getPort(portName); |
|---|
| 72 | |
|---|
| 73 | if (!CORBA::is_nil(p)) |
|---|
| 74 | return p._retn(); |
|---|
| 75 | |
|---|
| 76 | p = dataIn_0->getPort(portName); |
|---|
| 77 | |
|---|
| 78 | if (!CORBA::is_nil(p)) |
|---|
| 79 | return p._retn(); |
|---|
| 80 | |
|---|
| 81 | /*exception*/ |
|---|
| 82 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | void CostasLoop_i::start() throw (CORBA::SystemException, |
|---|
| 86 | CF::Resource::StartError) |
|---|
| 87 | { |
|---|
| 88 | DEBUG(3, CostasLoop, "start() invoked") |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void CostasLoop_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 92 | { |
|---|
| 93 | DEBUG(3, CostasLoop, "stop() invoked") |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | void CostasLoop_i::releaseObject() throw (CORBA::SystemException, |
|---|
| 97 | CF::LifeCycle::ReleaseError) |
|---|
| 98 | { |
|---|
| 99 | DEBUG(3, CostasLoop, "releaseObject() invoked") |
|---|
| 100 | |
|---|
| 101 | component_running->signal(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void CostasLoop_i::initialize() throw (CF::LifeCycle::InitializeError, |
|---|
| 105 | CORBA::SystemException) |
|---|
| 106 | { |
|---|
| 107 | DEBUG(3, CostasLoop, "initialize() invoked") |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | void CostasLoop_i::configure(const CF::Properties& props) |
|---|
| 111 | throw (CORBA::SystemException, |
|---|
| 112 | CF::PropertySet::InvalidConfiguration, |
|---|
| 113 | CF::PropertySet::PartialConfiguration) |
|---|
| 114 | { |
|---|
| 115 | DEBUG(3, CostasLoop, "configure() invoked") |
|---|
| 116 | |
|---|
| 117 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 118 | |
|---|
| 119 | for (unsigned int i = 0; i <props.length(); i++) |
|---|
| 120 | { |
|---|
| 121 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 122 | |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void CostasLoop_i::ProcessData() |
|---|
| 127 | { |
|---|
| 128 | DEBUG(3, CostasLoop, "ProcessData() invoked") |
|---|
| 129 | |
|---|
| 130 | PortTypes::ShortSequence I_out_0, Q_out_0; |
|---|
| 131 | PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL); |
|---|
| 132 | CORBA::UShort I_in_0_length, Q_in_0_length; |
|---|
| 133 | |
|---|
| 134 | // vector to be passed to FPGA |
|---|
| 135 | unsigned long fpgaData[512]; |
|---|
| 136 | |
|---|
| 137 | // bit masks for FPGA data |
|---|
| 138 | unsigned long Imask = 0xFFFF0000; |
|---|
| 139 | unsigned long Qmask = 0x0000FFFF; |
|---|
| 140 | |
|---|
| 141 | while(1) |
|---|
| 142 | { |
|---|
| 143 | |
|---|
| 144 | dataIn_0->getData(I_in_0, Q_in_0); |
|---|
| 145 | |
|---|
| 146 | I_in_0_length = I_in_0->length(); |
|---|
| 147 | Q_in_0_length = Q_in_0->length(); |
|---|
| 148 | |
|---|
| 149 | I_out_0.length(I_in_0_length); //must define length of output |
|---|
| 150 | Q_out_0.length(Q_in_0_length); //must define length of output |
|---|
| 151 | |
|---|
| 152 | // verify that input samples are length of 512 |
|---|
| 153 | if (I_out_0.length() != 512) |
|---|
| 154 | { |
|---|
| 155 | std::cout << "[CostasLoop::ProcessData] Error: Input sequences to CostasLoop "; |
|---|
| 156 | std::cout << "must be of length 512\n"; |
|---|
| 157 | exit(EXIT_FAILURE); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | // pull data from CORBA sequence, add to data vector |
|---|
| 161 | // (only I vector will be used, Q vector carries no valid data) |
|---|
| 162 | for (unsigned int i = 0; i < I_out_0.length(); i++) |
|---|
| 163 | { |
|---|
| 164 | fpgaData[i] = (*I_in_0)[i]; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | // get wall clock, user and system time |
|---|
| 168 | struct timeval start, end; |
|---|
| 169 | int who = RUSAGE_SELF; |
|---|
| 170 | struct rusage usageSTART, usageEND; |
|---|
| 171 | |
|---|
| 172 | getrusage(who,&usageSTART); |
|---|
| 173 | gettimeofday(&start,NULL); |
|---|
| 174 | for (int l = 0; l < 1000000; l++) |
|---|
| 175 | CostasLoopProcessing(fpgaData); |
|---|
| 176 | gettimeofday(&end,NULL); |
|---|
| 177 | getrusage(who,&usageEND); |
|---|
| 178 | |
|---|
| 179 | // calculate wall statistics |
|---|
| 180 | float Wsec = end.tv_sec - start.tv_sec; |
|---|
| 181 | float Wmicrosec = end.tv_usec - start.tv_usec; |
|---|
| 182 | std::cout << "Wall Clock Difference: " << (Wsec*1000) + (Wmicrosec/1000.0) << "\n"; |
|---|
| 183 | |
|---|
| 184 | // calculate usage statistics |
|---|
| 185 | struct timeval StimeStart = usageSTART.ru_stime; |
|---|
| 186 | struct timeval StimeEnd = usageEND.ru_stime; |
|---|
| 187 | |
|---|
| 188 | float Usec = usageEND.ru_utime.tv_sec - usageSTART.ru_utime.tv_sec; |
|---|
| 189 | float Umicrosec = usageEND.ru_utime.tv_usec - usageSTART.ru_utime.tv_usec; |
|---|
| 190 | |
|---|
| 191 | std::cout << "User Time: " << (Usec*1000) + (Umicrosec/1000.0) << "\n"; |
|---|
| 192 | |
|---|
| 193 | float Ssec = usageEND.ru_stime.tv_sec - usageSTART.ru_stime.tv_sec; |
|---|
| 194 | float Smicrosec = usageEND.ru_stime.tv_usec - usageEND.ru_stime.tv_usec; |
|---|
| 195 | |
|---|
| 196 | std::cout << "System Time: " << (Ssec*1000) + (Smicrosec/1000.0) << "\n"; |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | exit(EXIT_FAILURE); |
|---|
| 200 | |
|---|
| 201 | for (unsigned int k = 0; k < 512; k++) |
|---|
| 202 | { |
|---|
| 203 | I_out_0[k] = (signed(Imask & fpgaData[k])) >> 16; |
|---|
| 204 | Q_out_0[k] = (signed(Qmask & fpgaData[k])); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | dataIn_0->bufferEmptied(); |
|---|
| 208 | dataOut_0->pushPacket(I_out_0, Q_out_0); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | |
|---|