Beispiel #1
0
/*
 * Prints reports conditionally
 */
int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {
    if ( force != 0 ) {
        stats->info.cntOutofOrder = stats->cntOutofOrder;
        // assume most of the time out-of-order packets are not
        // duplicate packets, so conditionally subtract them from the lost packets.
        stats->info.cntError = stats->cntError;
        if ( stats->info.cntError > stats->info.cntOutofOrder ) {
            stats->info.cntError -= stats->info.cntOutofOrder;
        }
        stats->info.cntDatagrams = (isUDP(stats) ? stats->PacketID : stats->cntDatagrams);
        stats->info.TotalLen = stats->TotalLen;
        stats->info.startTime = 0;
        stats->info.endTime = TimeDifference( stats->packetTime, stats->startTime );
        stats->info.free = 1;
        reporter_print( stats, TRANSFER_REPORT, force );
        if ( isMultipleReport(stats) ) {
            reporter_handle_multiple_reports( multireport, &stats->info, force );
        }
    } else while ((stats->intervalTime.tv_sec != 0 ||
                   stats->intervalTime.tv_usec != 0) &&
                  TimeDifference( stats->nextTime,
                                  stats->packetTime ) < 0 ) {
        stats->info.cntOutofOrder = stats->cntOutofOrder - stats->lastOutofOrder;
        stats->lastOutofOrder = stats->cntOutofOrder;
        // assume most of the time out-of-order packets are not
        // duplicate packets, so conditionally subtract them from the lost packets.
        stats->info.cntError = stats->cntError - stats->lastError;
        if ( stats->info.cntError > stats->info.cntOutofOrder ) {
            stats->info.cntError -= stats->info.cntOutofOrder;
        }
        stats->lastError = stats->cntError;
        stats->info.cntDatagrams = (isUDP( stats ) ? stats->PacketID - stats->lastDatagrams :
                                                     stats->cntDatagrams - stats->lastDatagrams);
        stats->lastDatagrams = (isUDP( stats ) ? stats->PacketID : stats->cntDatagrams);
        stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
        stats->lastTotal = stats->TotalLen;
        stats->info.startTime = stats->info.endTime;
        stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
        TimeAdd( stats->nextTime, stats->intervalTime );
        stats->info.free = 0;
        reporter_print( stats, TRANSFER_REPORT, force );
        if ( isMultipleReport(stats) ) {
            reporter_handle_multiple_reports( multireport, &stats->info, force );
        }
    }
    return force;
}
Beispiel #2
0
/*
 *  Pauses a timer. Any further call to GetElapsedTime will
 * return the total time measured since it was started. The
 * timer can be further resumed by calling StartTimer.
 *
 */
void PauseTimer (Timer* t)
{
	Clock timeNow;

	GetTimeFunction(timeNow);
	t->elapsedTime += TimeDifference(timeNow, t->beginTime);
	t->status = PAUSED;
}
Beispiel #3
0
/*
 *  Stops a timer. This function is similar to PauseTimer,
 * with the diference that the timer cannot be resumed.
 *
 */
void StopTimer (Timer* t)
{
	Clock timeNow;

	GetTimeFunction(timeNow);
	t->elapsedTime += TimeDifference(timeNow, t->beginTime);
	t->status = STOPPED;
}
const TimeDifference RealTimeDifference::operator*(
  const TimePassageSpeed& passage) const
{
  auto duration_in_nanoseconds = (
    std::chrono::duration_cast<std::chrono::nanoseconds>(
      this->duration_).count());
  return TimeDifference(duration_in_nanoseconds * passage);
}
void ProtocolTest1()
{
#if defined(IS_ROUTER)
#if PROFILE_TEST_SERVICE == true
    double executionTime;
    Uint32 startTime;
#endif
    struct Packet newPacket;
    Uint16 x[100], i, j;

    for(i = 0; i < 100; i++)
        x[i] = i;

    TSK_sleep(3000);

    if(gpioDataRegisters.GPBDAT.bit.SWITCH1)
    {
        for(i = 0; i < 100; i++)
        {
            for(j = 0; j < 50; j++)
            {
                InitializePacket(&newPacket, PACKET_ID_UNDEFINED);

                // Create the data transfer packet
                newPacket.a.communicationType = COMM_TYPE_UNICAST;
                newPacket.transmissionInfo.destination = ROOT_ADDRESS;
                newPacket.b.command = COMMAND_DATA_TRANSFER;
                newPacket.b.packetSequenceStep = SEQUENCE_DATA_TRANSFER_REQUEST_TRANSFER;

                // Set the data
                newPacket.dataBuffer = x;
                newPacket.dataBufferInfo.dataBufferLength = 100;

#if PROFILE_TEST_SERVICE == true
                startTime = timer0Registers.TIM.all;
#endif
                SendDataPacket(&newPacket);
                while(globals.statistics.packet.numDataTransfersSucceeded + globals.statistics.packet.numDataTransfersExpired +
                        globals.statistics.packet.numDataTransfersFailed < globals.statistics.packet.numDataTransfersSetup);

#if PROFILE_TEST_SERVICE == true
                executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
                globals.statistics.profiling.avgTestServiceTime =
                    (globals.statistics.profiling.avgTestServiceTime * globals.statistics.profiling.numTestServiceSamples) + executionTime;
                globals.statistics.profiling.numTestServiceSamples++;
                globals.statistics.profiling.avgTestServiceTime /= globals.statistics.profiling.numTestServiceSamples;
                if(executionTime < globals.statistics.profiling.minTestServiceTime)
                    globals.statistics.profiling.minTestServiceTime = executionTime;
                else if(executionTime > globals.statistics.profiling.maxTestServiceTime)
                    globals.statistics.profiling.maxTestServiceTime = executionTime;
#endif
            }
            SetSevenSegmentDisplay(i);
        }
    }
#endif
}
Beispiel #6
0
/*
 *  Gets the elapsed time. This function works in any status
 * of the timer but notice that this function requires some
 * time and, if the timer is running, the final measure will
 * include it.
 *
 */
double GetElapsedTime(Timer *t)
{
	if (t->status == TIMER_RUNNING) {
		Clock timeNow;

		GetTimeFunction(timeNow);
		return (t->elapsedTime + TimeDifference(timeNow, t->beginTime));
	}

	return t->elapsedTime;
}
Beispiel #7
0
/***********************************************************************
 *
 * FUNCTION:    AdjustTimes
 *
 * DESCRIPTION: This routine adjusts the start or end times.  It's
 *              called when ever the start or end time are changed. If
 *              the start time has been changed then the end time is adjust
 *              such that the elasped time is maintained.  If the end
 *              time has been changed then the start time is adjusted so
 *              that it will not be before the end time.
 *
 * PARAMETERS:  startTime	    - pointer to TimeType
 *              endTime        - pointer to TimeType
 *              startTimeText  - buffer that holds start time string
 *              emdTimeText    - buffer that holds end time string
 *              timeFormat     - time format
 *              untimed  	    - true if there isn't a time.
 *
 * RETURNED:	 nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/4/96	Initial Revision
 *
 ***********************************************************************/
static Boolean AdjustTimes (TimePtr startTime, TimePtr endTime, 
		TimePtr timeDiff, ChangingTimeType changingTime)
	{
	Boolean changed = false;

	if (changingTime == changingStartTime)
		{
		// The start time has changed so update the end time.
		endTime->minutes = startTime->minutes + timeDiff->minutes;
		endTime->hours = startTime->hours + timeDiff->hours;

		// If there are 60 or more minutes wrap to the next hour
		if (endTime->minutes >= hoursInMinutes)
			{
			endTime->minutes -= hoursInMinutes;
			endTime->hours++;
			}

		// Don't allow the end time past 11:55 PM.
		//if (endTime->hours >= 24)
		//	{
		//	endTime->minutes = 55;
		//	endTime->hours = 23;
		//	}
		changed = true;
		}

	else if (changingTime == changingEndTime)
		{
		// The end time has changed so make sure it's valid
		// and calculate the new difference.
		TimeDifference (endTime, startTime, timeDiff);
		if (endTime->hours < startTime->hours ||
			(endTime->hours == startTime->hours && 
			endTime->minutes < startTime->minutes))
			{
			timeDiff->hours = 0;
			timeDiff->minutes = 0;
			endTime->hours = startTime->hours;
			endTime->minutes = startTime->minutes;	
			changed = true;
			}
		}
	// Don't allow the end time past 11:55 PM.
	if (endTime->hours >= 24)
		{
		endTime->minutes = 55;
		endTime->hours = 23;
		changed = true;
		}
	return (changed);
	}
unsigned SystemMicroSecondWait(void *time0,unsigned us) {
  unsigned start,t1=0,t2,end;
  Time *time = time0;

  // system wait
  if (us >= 10000) {
    struct timeval start,end;

    gettimeofday(&start,0);
    usleep(us - us % 10000);
    gettimeofday(&end,0);
    t1 = TimeDifference(start,end);
    if (t1 > us) return t1;
    us -= t1;
  }
  start = time->Tick(time);
  end = time->usFuture(time,start,us);
  while (!time->TimeoutQ(time,start,end));
  //while ((t2=time->usElapsed(time,start)) < us);
  t2=time->usElapsed(time,start);
  return t1+t2;
}
Beispiel #9
0
void TimeOneNE10RFFT(int count, int fft_log_size, float signal_value,
                     int signal_type) {
    OMX_F32* x;                   /* Source */
    OMX_FC32* y;                  /* Transform */
    OMX_F32* z;                   /* Inverse transform */
    OMX_F32* temp;

    OMX_F32* y_true;              /* True FFT */

    struct AlignedPtr* x_aligned;
    struct AlignedPtr* y_aligned;
    struct AlignedPtr* z_aligned;

    int n;
    ne10_result_t status;
    ne10_fft_r2c_cfg_float32_t fft_fwd_spec;

    int fft_size;
    struct timeval start_time;
    struct timeval end_time;
    double elapsed_time;
    struct SnrResult snr_forward;
    struct SnrResult snr_inverse;

    fft_size = 1 << fft_log_size;

    x_aligned = AllocAlignedPointer(32, sizeof(*x) * 4 * fft_size);
    /* The transformed value is in CCS format and is has fft_size + 2 values */
    y_aligned = AllocAlignedPointer(32, sizeof(*y) * (4 * fft_size + 2));
    z_aligned = AllocAlignedPointer(32, sizeof(*z) * 4 * fft_size);

    x = x_aligned->aligned_pointer_;
    y = y_aligned->aligned_pointer_;
    z = z_aligned->aligned_pointer_;

    y_true = (OMX_F32*) malloc(sizeof(*y_true) * (fft_size + 2));

    GenerateRealFloatSignal(x, (struct ComplexFloat*) y_true, fft_size, signal_type,
                            signal_value);

    fft_fwd_spec = ne10_fft_alloc_r2c_float32(fft_size);

    if (!fft_fwd_spec) {
        fprintf(stderr, "NE10 RFFT: Cannot initialize FFT structure for order %d\n", fft_log_size);
        return;
    }

    if (do_forward_test) {
        GetUserTime(&start_time);
        for (n = 0; n < count; ++n) {
            ne10_fft_r2c_1d_float32_neon((ne10_fft_cpx_float32_t *) y,
                                         x,
                                         fft_fwd_spec);
        }
        GetUserTime(&end_time);

        elapsed_time = TimeDifference(&start_time, &end_time);

        CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size / 2 + 1);

        PrintResult("Forward NE10 RFFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);

        if (verbose >= 255) {
            printf("FFT Actual:\n");
            DumpArrayComplexFloat("y", fft_size / 2 + 1, y);
            printf("FFT Expected:\n");
            DumpArrayComplexFloat("true", fft_size / 2 + 1, (OMX_FC32*) y_true);
        }
    }

    if (do_inverse_test) {
        // Ne10 FFTs destroy the input.

        GetUserTime(&start_time);
        for (n = 0; n < count; ++n) {
            //memcpy(y, y_true, (fft_size >> 1) * sizeof(*y));
            // The inverse appears not to be working.
            ne10_fft_c2r_1d_float32_neon(z,
                                         (ne10_fft_cpx_float32_t *) y_true,
                                         fft_fwd_spec);
        }
        GetUserTime(&end_time);

        elapsed_time = TimeDifference(&start_time, &end_time);

        CompareFloat(&snr_inverse, (OMX_F32*) z, (OMX_F32*) x, fft_size);

        PrintResult("Inverse NE10 RFFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);

        if (verbose >= 255) {
            printf("IFFT Actual:\n");
            DumpArrayFloat("z", fft_size, z);
            printf("IFFT Expected:\n");
            DumpArrayFloat("x", fft_size, x);
        }
    }

    ne10_fft_destroy_r2c_float32(fft_fwd_spec);
    FreeAlignedPointer(x_aligned);
    FreeAlignedPointer(y_aligned);
    FreeAlignedPointer(z_aligned);
}
Beispiel #10
0
/*
 * Prints reports conditionally
 */
int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {

    if ( force ) {
#ifdef HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS
	gettcpistats(stats);
#endif
        stats->info.cntOutofOrder = stats->cntOutofOrder;
        // assume most of the time out-of-order packets are not
        // duplicate packets, so conditionally subtract them from the lost packets.
        stats->info.cntError = stats->cntError;
        if ( stats->info.cntError > stats->info.cntOutofOrder ) {
            stats->info.cntError -= stats->info.cntOutofOrder;
        }
        stats->info.cntDatagrams = ((stats->info.mUDP == kMode_Server) ? stats->PacketID : stats->cntDatagrams);
        stats->info.TotalLen = stats->TotalLen;
        stats->info.startTime = 0;
        stats->info.endTime = TimeDifference( stats->packetTime, stats->startTime );
	stats->info.transit.minTransit = stats->info.transit.totminTransit;
	stats->info.transit.maxTransit = stats->info.transit.totmaxTransit;
	stats->info.transit.cntTransit = stats->info.transit.totcntTransit;
	stats->info.transit.sumTransit = stats->info.transit.totsumTransit;
	stats->info.transit.meanTransit = stats->info.transit.totmeanTransit;
	stats->info.transit.m2Transit = stats->info.transit.totm2Transit;
	stats->info.transit.vdTransit = stats->info.transit.totvdTransit;
	if (stats->info.mTCP == kMode_Client) {
	    stats->info.tcp.write.WriteErr = stats->info.tcp.write.totWriteErr;
	    stats->info.tcp.write.WriteCnt = stats->info.tcp.write.totWriteCnt;
	    stats->info.tcp.write.TCPretry = stats->info.tcp.write.totTCPretry;
	}
	if (stats->info.mTCP == kMode_Server) {
	    int ix;
	    stats->info.tcp.read.cntRead = stats->info.tcp.read.totcntRead;
	    for (ix = 0; ix < 8; ix++) {
		stats->info.tcp.read.bins[ix] = stats->info.tcp.read.totbins[ix];
	    }
	}
	if (stats->info.endTime > 0) {
	    stats->info.IPGcnt = (int) (stats->cntDatagrams / stats->info.endTime);
	} else {
	    stats->info.IPGcnt = 0;
	}
	stats->info.IPGsum = 1;
        stats->info.free = 1;

        reporter_print( stats, TRANSFER_REPORT, force );
        if ( isMultipleReport(stats) ) {
            reporter_handle_multiple_reports( multireport, &stats->info, force );
        }
    } else while ((stats->intervalTime.tv_sec != 0 ||
                   stats->intervalTime.tv_usec != 0) &&
                  TimeDifference( stats->nextTime, 
                                  stats->packetTime ) < 0 ) {
#ifdef HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS
	    gettcpistats(stats);
#endif
	    stats->info.cntOutofOrder = stats->cntOutofOrder - stats->lastOutofOrder;
	    stats->lastOutofOrder = stats->cntOutofOrder;
	    // assume most of the  time out-of-order packets are not
	    // duplicate packets, so conditionally subtract them from the lost packets.
	    stats->info.cntError = stats->cntError - stats->lastError;
	    if ( stats->info.cntError > stats->info.cntOutofOrder ) {
		stats->info.cntError -= stats->info.cntOutofOrder;
	    }
	    stats->lastError = stats->cntError;
	    stats->info.cntDatagrams = ((stats->info.mUDP == kMode_Server) ? stats->PacketID - stats->lastDatagrams :
					stats->cntDatagrams - stats->lastDatagrams);
	    stats->lastDatagrams = ((stats->info.mUDP == kMode_Server) ? stats->PacketID : stats->cntDatagrams);
	    stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
	    stats->lastTotal = stats->TotalLen;
	    stats->info.startTime = stats->info.endTime;
	    stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
	    TimeAdd( stats->nextTime, stats->intervalTime );
	    stats->info.free = 0;
	    reporter_print( stats, TRANSFER_REPORT, force );
	    if ( isMultipleReport(stats) ) {
		reporter_handle_multiple_reports( multireport, &stats->info, force );
	    }
	    // Reset stats used by SUM now that the SUM has been reported
	    if (stats->info.mEnhanced) {
		if (stats->info.mUDP) {
		    stats->info.IPGcnt = 0;
		    stats->info.IPGsum = 0;
		} else if (stats->info.mTCP == (char)kMode_Client) {
		    stats->info.tcp.write.WriteCnt = 0;
		    stats->info.tcp.write.WriteErr = 0;
		} else if (stats->info.mTCP == (char)kMode_Server) {
		    int ix;
		    stats->info.tcp.read.cntRead = 0;
		    for (ix = 0; ix < 8; ix++) { 
			stats->info.tcp.read.bins[ix] = 0;
		    }
		}
	    }
	}
    return force;
}
Beispiel #11
0
/*
 * Updates connection stats
 */
int reporter_handle_packet( ReportHeader *reporthdr ) {
    ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
    ReporterData *data = &reporthdr->report;
    Transfer_Info *stats = &reporthdr->report.info;
    int finished = 0;
    double usec_transit;

    data->packetTime = packet->packetTime;
    stats->socket = packet->socket;
    if ( packet->packetID < 0 ) {
        finished = 1;
        if ( reporthdr->report.mThreadMode != kMode_Client ) {
            data->TotalLen += packet->packetLen;
        }
    } else {
	if (!packet->emptyreport) {
	    // update fields common to TCP and UDP, client and server
	    data->TotalLen += packet->packetLen;
	    // update fields common to UDP client and server
            if ( isUDP( data ) ) {
		data->cntDatagrams++;
		stats->IPGsum += TimeDifference(data->packetTime, data->IPGstart );
		stats->IPGcnt++;
		data->IPGstart = data->packetTime;
		// Finally, update UDP server fields
		if (stats->mUDP == kMode_Server) {
		    //subsequent packets
		    double transit;
		    double deltaTransit;            
		    transit = TimeDifference( packet->packetTime, packet->sentTime );
		    // packet loss occured if the datagram numbers aren't sequential 
		    if ( packet->packetID != data->PacketID + 1 ) {
			if (packet->packetID < data->PacketID + 1 ) {
			    data->cntOutofOrder++;
			} else {
			    data->cntError += packet->packetID - data->PacketID - 1;
			}
		    }
		    // never decrease datagramID (e.g. if we get an out-of-order packet)
		    if ( packet->packetID > data->PacketID ) {
			data->PacketID = packet->packetID;
		    }
		    if (stats->transit.totcntTransit == 0) {
			// Very first packet
			stats->transit.minTransit = transit;
			stats->transit.maxTransit = transit;
			stats->transit.sumTransit = transit;
			stats->transit.cntTransit = 1;
			stats->transit.totminTransit = transit;
			stats->transit.totmaxTransit = transit;
			stats->transit.totsumTransit = transit;
			stats->transit.totcntTransit = 1;
			// For variance, working units is microseconds
			usec_transit = transit * 1e6;
			stats->transit.vdTransit = usec_transit;
			stats->transit.meanTransit = usec_transit;
			stats->transit.m2Transit = usec_transit * usec_transit;
			stats->transit.totvdTransit = usec_transit;
			stats->transit.totmeanTransit = usec_transit;
			stats->transit.totm2Transit = usec_transit * usec_transit;
		    } else {
			// from RFC 1889, Real Time Protocol (RTP) 
			// J = J + ( | D(i-1,i) | - J ) / 
			// Compute jitter
			deltaTransit = transit - stats->transit.lastTransit;
			if ( deltaTransit < 0.0 ) {
			    deltaTransit = -deltaTransit;
			}
			stats->jitter += (deltaTransit - stats->jitter) / (16.0);
			// Compute end/end delay stats
			stats->transit.sumTransit += transit;
			stats->transit.cntTransit++;
			stats->transit.totsumTransit += transit;
			stats->transit.totcntTransit++;
			// mean min max tests
			if (transit < stats->transit.minTransit) {
			    stats->transit.minTransit=transit;
			}
			if (transit < stats->transit.totminTransit) {
			    stats->transit.totminTransit=transit;
			}
			if (transit > stats->transit.maxTransit) {
			    stats->transit.maxTransit=transit;
			}
			if (transit > stats->transit.totmaxTransit) {
			    stats->transit.totmaxTransit=transit;
			}
			// For variance, working units is microseconds
			// variance interval
			usec_transit = transit * 1e6;
			stats->transit.vdTransit = usec_transit - stats->transit.meanTransit;
			stats->transit.meanTransit = stats->transit.meanTransit + (stats->transit.vdTransit / stats->transit.cntTransit);
			stats->transit.m2Transit = stats->transit.m2Transit + (stats->transit.vdTransit * (usec_transit - stats->transit.meanTransit));
			// variance total
			stats->transit.totvdTransit = usec_transit - stats->transit.totmeanTransit;
			stats->transit.totmeanTransit = stats->transit.totmeanTransit + (stats->transit.totvdTransit / stats->transit.totcntTransit);
			stats->transit.totm2Transit = stats->transit.totm2Transit + (stats->transit.totvdTransit * (usec_transit - stats->transit.totmeanTransit));
		    }
		    stats->transit.lastTransit = transit;
		}
	    } else if (reporthdr->report.mThreadMode == kMode_Server && (packet->packetLen > 0)) {
		int bin;
		// mean min max tests
		stats->tcp.read.cntRead++;
		stats->tcp.read.totcntRead++;
		bin = (int)floor((packet->packetLen -1)/stats->tcp.read.binsize);
		stats->tcp.read.bins[bin]++;
		stats->tcp.read.totbins[bin]++;
	    } else if (reporthdr->report.mThreadMode == kMode_Client) {
		if (packet->errwrite) { 
		    stats->tcp.write.WriteErr++;
		    stats->tcp.write.totWriteErr++;
		}
		else { 
		    stats->tcp.write.WriteCnt++;
		    stats->tcp.write.totWriteCnt++;
		}
	    }
	} else if ((stats->mUDP == kMode_Server) &&	\
		   (stats->transit.cntTransit == 0)) {
	    // This is the case when empty reports
	    // cross the report interval boundary
	    // Hence, set the per interval min to infinity
	    // and the per interval max and sum to zero
	    stats->transit.minTransit = FLT_MAX;
	    stats->transit.maxTransit = FLT_MIN;
	    stats->transit.sumTransit = 0;
	    stats->transit.vdTransit = 0;
	    stats->transit.meanTransit = 0;
	    stats->transit.m2Transit = 0;
	}
    }
    // Print a report if appropriate
    return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
}
Beispiel #12
0
void TimeOnePfRFFT(int count, int fft_log_size, float signal_value,
                     int signal_type) {
  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_tmp_aligned;

  float* x;
  struct ComplexFloat* y;
  OMX_F32* z;

  float* y_true;
  float* y_tmp;

  int n;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  PFFFT_Setup *s;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;
  
  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
  y_tmp_aligned = AllocAlignedPointer(32, sizeof(*y_tmp) * (fft_size + 2));

  y_true = (float*) malloc(sizeof(*y_true) * 2 * fft_size);

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_tmp = y_tmp_aligned->aligned_pointer_;

  s = pffft_new_setup(fft_size, PFFFT_REAL);
  if (!s) {
    fprintf(stderr, "TimeOnePfRFFT: Could not initialize structure for order %d\n",
            fft_log_size);
  }

  GenerateRealFloatSignal(x, (struct ComplexFloat*) y_true, fft_size, signal_type, signal_value);

  if (do_forward_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      pffft_transform_ordered(s, (float*)x, (float*)y, NULL, PFFFT_FORWARD);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    /*
     * Arrange the output of the FFT to match the expected output.
     */
    y[fft_size / 2].Re = y[0].Im;
    y[fft_size / 2].Im = 0;
    y[0].Im = 0;

    CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size / 2 + 1);

    PrintResult("Forward PFFFT RFFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);

    if (verbose >= 255) {
      printf("FFT Actual:\n");
      DumpArrayComplexFloat("y", fft_size / 2 + 1, (OMX_FC32*) y);
      printf("FFT Expected:\n");
      DumpArrayComplexFloat("true", fft_size / 2 + 1, (OMX_FC32*) y_true);
    }
  }

  if (do_inverse_test) {
    float scale = 1.0 / fft_size;

    /* Copy y_true to true, but arrange the values according to what rdft wants. */

    memcpy(y_tmp, y_true, sizeof(y_tmp[0]) * fft_size);
    y_tmp[1] = y_true[fft_size / 2];

    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      int m;
      
      pffft_transform_ordered(s, (float*)y_tmp, (float*)z, NULL, PFFFT_BACKWARD);
      /*
       * Need to include cost of scaling the inverse
       */
      ScaleVector(z, fft_size, fft_size);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareFloat(&snr_inverse, (OMX_F32*) z, (OMX_F32*) x, fft_size);

    PrintResult("Inverse PFFFT RFFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);

    if (verbose >= 255) {
      printf("IFFT Actual:\n");
      DumpArrayFloat("z", fft_size, z);
      printf("IFFT Expected:\n");
      DumpArrayFloat("x", fft_size, x);
    }
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  FreeAlignedPointer(y_tmp_aligned);
  pffft_destroy_setup(s);
  free(y_true);
}
void MPITest()
{
    int rank, numNodes;
    Uint16 sendBuf[1], *receiveBuf;
    Uint16 i, j;
    MPI_Status status;
    Uint32 startTime;
    double elapsedTime;

    SEM_pend(&TestServiceSem,SYS_FOREVER);

    // Generate the x data
    for(i = 0; i < 14; i++)
    {
        for(j = 0; j < 25; j++)
            xglobal[i * 50 + j] = (j / 4);
        for(j = 0; j < 25; j++)
            xglobal[i * 50 + j + 25] = 6 - (j / 4);
    }

    // Generate the y data
    for(i = 0; i < 28; i++)
    {
        for(j = 0; j < 25; j++)
            yglobal[i * 25 + j] = j / 2;
    }

    // Initialize MPI
    MPI_Init(NULL,NULL);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    globals.processing.sevenSegmentUpperDigit = SEVENSEG_1DASH;

    // Distribute the number of nodes to use
    if(rank == 0)
    {
        numNodes = (gpioDataRegisters.GPBDAT.bit.SWITCH1 << 3) + (gpioDataRegisters.GPBDAT.bit.SWITCH2 << 2) +
                   (gpioDataRegisters.GPADAT.bit.SWITCH3 << 1) + (gpioDataRegisters.GPADAT.bit.SWITCH4);
        sendBuf[0] = numNodes;
        for(i = 1; i <= 6; i++)
            MPI_Send(sendBuf,1,MPI_SHORT,i,0,MPI_COMM_WORLD);
    }
    else
    {
        MPI_Recv((void**)(&receiveBuf),1,MPI_SHORT,0,0,MPI_COMM_WORLD,&status);
        numNodes = receiveBuf[0];
        MemFree(receiveBuf);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    // If this node is participating in the convolution
    if(rank < numNodes)
    {
        globals.processing.sevenSegmentUpperDigit = SEVENSEG_2DASH;

        startTime = timer0Registers.TIM.all;
        Convolution(xglobal,yglobal,100,100,resultglobal,numNodes);
        elapsedTime = TimeDifference(startTime, timer0Registers.TIM.all);

        // Finalize MPI
        if(rank == 0)
        {
            globals.processing.sevenSegmentLowerDigit = SEVENSEG_FINAL;
            globals.processing.sevenSegmentUpperDigit = SEVENSEG_FINAL;
        }
        else
            globals.processing.sevenSegmentUpperDigit = SEVENSEG_3DASH;
    }
    else
    {
        globals.processing.sevenSegmentUpperDigit = SEVENSEG_FINAL;
    }
    SEM_pend(&TestServiceSem,SYS_FOREVER);
}
void ProtocolTest3()
{
#if PROFILE_TEST_SERVICE == true
    double executionTime;
    Uint32 startTime;
#endif
    struct Packet newPacket;
    Uns interruptStatus;
    Uint16 x[100], i, j, destination;
    double executionTime = 0;
    double avgTime[9] = {0,0,0,0,0,0,0,0,0};
    double minTime[9] = {DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX};
    double maxTime[9] = {DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN};
    Uint32 startTime = 0;
    Uint32 numSamples;

    SEM_pend(&TestServiceSem,SYS_FOREVER);

    for(i = 0; i < 100; i++)
        x[i] = i;

    if(globals.protocol.address == 1)
    {
        globals.processing.sevenSegmentUpperDigit = SEVENSEG_1DASH;

        destination = (gpioDataRegisters.GPBDAT.bit.SWITCH1 << 3) + (gpioDataRegisters.GPBDAT.bit.SWITCH2 << 2) +
                      (gpioDataRegisters.GPADAT.bit.SWITCH3 << 1) + (gpioDataRegisters.GPADAT.bit.SWITCH4);

        interruptStatus = HWI_disable();
        numSamples = 0;
        for(j = 0; j < 100; j++)
        {
            startTime = timer0Registers.TIM.all;
            GenerateRoutingPath(globals.protocol.address, 1, &newPacket);
            executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
            avgTime[1] = (avgTime[1] * numSamples) + executionTime;
            numSamples++;
            avgTime[1] /= numSamples;
            if(executionTime < minTime[1])
                minTime[1] = executionTime;
            else if(executionTime > maxTime[1])
                maxTime[1] = executionTime;
        }
        for(i = 3; i <= 8; i++)
        {
            numSamples = 0;
            for(j = 0; j < 100; j++)
            {
                startTime = timer0Registers.TIM.all;
                GenerateRoutingPath(globals.protocol.address, i, &newPacket);
                executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
                avgTime[i] = (avgTime[i] * numSamples) + executionTime;
                numSamples++;
                avgTime[i] /= numSamples;
                if(executionTime < minTime[i])
                    minTime[i] = executionTime;
                else if(executionTime > maxTime[i])
                    maxTime[i] = executionTime;
            }
        }
        HWI_restore(interruptStatus);
        asm(" NOP");

        for(i = 0; i < 100; i++)
        {
            for(j = 0; j < 50; j++)
            {
                InitializePacket(&newPacket, PACKET_ID_UNDEFINED);

                // Create the data transfer packet
                newPacket.a.communicationType = COMM_TYPE_UNICAST;
                newPacket.transmissionInfo.destination = 7;
                newPacket.b.command = COMMAND_DATA_TRANSFER;
                newPacket.b.packetSequenceStep = SEQUENCE_DATA_TRANSFER_REQUEST_TRANSFER;

                // Set the data
                newPacket.dataBuffer = x;
                newPacket.dataBufferInfo.dataBufferLength = 10;

                SendDataPacket(&newPacket);

                InitializePacket(&newPacket, PACKET_ID_UNDEFINED);

                // Create the data transfer packet
                newPacket.a.communicationType = COMM_TYPE_UNICAST;
                newPacket.transmissionInfo.destination = 8;
                newPacket.b.command = COMMAND_DATA_TRANSFER;
                newPacket.b.packetSequenceStep = SEQUENCE_DATA_TRANSFER_REQUEST_TRANSFER;

                // Set the data
                newPacket.dataBuffer = x;
                newPacket.dataBufferInfo.dataBufferLength = 10;

                SendDataPacket(&newPacket);

                while(globals.statistics.packet.numDataTransfersSucceeded + globals.statistics.packet.numDataTransfersExpired +
                        globals.statistics.packet.numDataTransfersFailed < globals.statistics.packet.numDataTransfersSetup);

            }
            if(globals.processing.sevenSegmentUpperDigit == SEVENSEG_2DASH)
                globals.processing.sevenSegmentUpperDigit = SEVENSEG_1DASH;
            else
                globals.processing.sevenSegmentUpperDigit = SEVENSEG_2DASH;
        }
        globals.processing.sevenSegmentUpperDigit = SEVENSEG_3DASH;
    }
}
Beispiel #15
0
void TimeOnePfFFT(int count, int fft_log_size, float signal_value,
                     int signal_type) {
  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_true_aligned;

  struct ComplexFloat* x;
  struct ComplexFloat* y;
  OMX_FC32* z;

  struct ComplexFloat* y_true;

  int n;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  PFFFT_Setup *s;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;
  
  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
  y_true_aligned = AllocAlignedPointer(32, sizeof(*y_true) * fft_size);

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_true = y_true_aligned->aligned_pointer_;

  s = pffft_new_setup(fft_size, PFFFT_COMPLEX);
  if (!s) {
    fprintf(stderr, "TimeOnePfFFT: Could not initialize structure for order %d\n",
            fft_log_size);
  }

  GenerateTestSignalAndFFT(x, y_true, fft_size, signal_type, signal_value, 0);

  if (do_forward_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      pffft_transform_ordered(s, (float*)x, (float*)y, NULL, PFFFT_FORWARD);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size);

    PrintResult("Forward PFFFT FFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);

    if (verbose >= 255) {
      printf("FFT Actual:\n");
      DumpArrayComplexFloat("y", fft_size, (OMX_FC32*) y);
      printf("FFT Expected:\n");
      DumpArrayComplexFloat("true", fft_size, (OMX_FC32*) y_true);
    }
  }

  if (do_inverse_test) {
    float scale = 1.0 / fft_size;

    memcpy(y, y_true, sizeof(*y) * (fft_size + 2));
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      int m;
      
      pffft_transform_ordered(s, (float*)y_true, (float*)z, NULL, PFFFT_BACKWARD);
      /*
       * Need to include cost of scaling the inverse
       */
      ScaleVector((OMX_F32*) z, 2 * fft_size, fft_size);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplexFloat(&snr_inverse, (OMX_FC32*) z, (OMX_FC32*) x, fft_size);

    PrintResult("Inverse PFFFT FFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);

    if (verbose >= 255) {
      printf("IFFT Actual:\n");
      DumpArrayComplexFloat("z", fft_size, z);
      printf("IFFT Expected:\n");
      DumpArrayComplexFloat("x", fft_size, (OMX_FC32*) x);
    }
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  FreeAlignedPointer(y_true_aligned);
  pffft_destroy_setup(s);
}
Beispiel #16
0
/*
 * Updates connection stats
 */
int reporter_handle_packet( ReportHeader *reporthdr ) {
    ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
    ReporterData *data = &reporthdr->report;
    Transfer_Info *stats = &reporthdr->report.info;
    int finished = 0;

    data->cntDatagrams++;
    // If this is the last packet set the endTime
    if ( packet->packetID < 0 ) {
        data->packetTime = packet->packetTime;
        finished = 1;
        if ( reporthdr->report.mThreadMode != kMode_Client ) {
            data->TotalLen += packet->packetLen;
        }
    } else {
        // update recieved amount and time
        data->packetTime = packet->packetTime;
        reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
        data->TotalLen += packet->packetLen;
        if ( packet->packetID != 0 ) {
            // UDP packet
            double transit = 0.0;
            double deltaTransit;

            // from RFC 1889, Real Time Protocol (RTP)
            // J = J + ( | D(i-1,i) | - J ) / 16
            transit = TimeDifference( packet->packetTime, packet->sentTime );
            if ( data->lastTransit != 0.0 ) {
                deltaTransit = transit - data->lastTransit;
                if ( deltaTransit < 0.0 ) {
                    deltaTransit = -deltaTransit;
                }
                stats->jitter += (deltaTransit - stats->jitter) / (16.0);
                stats->delay += transit*1000;
                stats->delay_total += transit*1000;
            }
            data->lastTransit = transit;

            // packet loss occured if the datagram numbers aren't sequential
            if ( packet->packetID != data->PacketID + 1 ) {
                if ( packet->packetID < data->PacketID + 1 ) {
                    data->cntOutofOrder++;
                    if (reporthdr->report.mThreadMode != kMode_Client)
                    {
                        struct out_of_order_packet *oop;
                        if (!(oop = (struct out_of_order_packet *) malloc(sizeof(struct out_of_order_packet))))
                        {
                            fprintf(stderr, "Out of memory");
                            exit(1);
                        }
                        oop->packetID = packet->packetID;
#ifndef WIN32
                        //printf("Packet %d out of order\n", packet->packetID);
                        LIST_INSERT_HEAD(&(data->out_of_order_packets), oop, list);
#endif
                    }
                } else {
                    data->cntError += packet->packetID - data->PacketID - 1;
                    if (reporthdr->report.mThreadMode != kMode_Client)
                    {
                        struct lost_packet_interval *lpi;
                        if (!(lpi = (struct lost_packet_interval *) malloc(sizeof(struct lost_packet_interval))))
                        {
                            fprintf(stderr, "Out of memory");
                            exit(1);
                        }
                        lpi->from = (data->PacketID + 1);
                        lpi->to = (packet->packetID - 1);
#ifndef WIN32
                        LIST_INSERT_HEAD(&data->lost_packets, lpi, list);
                        /*
                        printf("Packet %d revealed a loss gap from %d, "
                            "total loss %d\n", packet->packetID,
                            data->PacketID, data->cntError);
                        */
#endif
                    }
                }
            }
            // never decrease datagramID (e.g. if we get an out-of-order packet)
            if ( packet->packetID > data->PacketID ) {
                data->PacketID = packet->packetID;
            }
        }
    }

    // Print a report if appropriate
    return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
}
Beispiel #17
0
void TimeOneFloatRFFT(int count, int fft_log_size, float signal_value,
                      int signal_type) {
  OMX_F32* x;                   /* Source */
  OMX_F32* y;                   /* Transform */
  OMX_F32* z;                   /* Inverse transform */

  OMX_F32* y_true;              /* True FFT */

  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_true_aligned;


  OMX_INT n, fft_spec_buffer_size;
  OMXResult status;
  OMXFFTSpec_R_F32 * fft_fwd_spec = NULL;
  OMXFFTSpec_R_F32 * fft_inv_spec = NULL;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;

  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  /* The transformed value is in CCS format and is has fft_size + 2 values */
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
  y_true_aligned = AllocAlignedPointer(32, sizeof(*z) * (fft_size + 2));

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_true = y_true_aligned->aligned_pointer_;

  GenerateRealFloatSignal(x, (OMX_FC32*) y_true, fft_size, signal_type,
                          signal_value);

  status = omxSP_FFTGetBufSize_R_F32(fft_log_size, &fft_spec_buffer_size);

  fft_fwd_spec = (OMXFFTSpec_R_F32*) malloc(fft_spec_buffer_size);
  fft_inv_spec = (OMXFFTSpec_R_F32*) malloc(fft_spec_buffer_size);
  status = omxSP_FFTInit_R_F32(fft_fwd_spec, fft_log_size);

  status = omxSP_FFTInit_R_F32(fft_inv_spec, fft_log_size);

  if (do_forward_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      FORWARD_FLOAT_RFFT(x, y, fft_fwd_spec);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size / 2 + 1);

    PrintResult("Forward Float RFFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);
  }

  if (do_inverse_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      INVERSE_FLOAT_RFFT(y_true, z, fft_inv_spec);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareFloat(&snr_inverse, (OMX_F32*) z, (OMX_F32*) x, fft_size);

    PrintResult("Inverse Float RFFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  free(fft_fwd_spec);
  free(fft_inv_spec);
}
void InitializeSystem(void* parameter, Uint16 followUpItemIndex)
{

	Uns interruptStatus;
	Uint16 i, j;
	double executionTime = 0;
	double genAvgTime = 0;
	double genMinTime = DBL_MAX;
	double genMaxTime = DBL_MIN;
	double avgTime[9] = {0,0,0,0,0,0,0,0,0};
	double minTime[9] = {DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX};
	double maxTime[9] = {DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN};
	Uint32 startTime = 0;
	Uint32 numSamples;
	struct Packet newPacket;

	// Allow the system to write to the system registers
	EALLOW;

	// Set up the heartbeat
	gpioCtrlRegisters.GPBDIR.bit.HEARTBEAT = 1;
	gpioDataRegisters.GPBDAT.bit.HEARTBEAT = 1;

	// Set up the seven segment display
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_A = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_A = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_B = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_B = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_C = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_C = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_D = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_D = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_E = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_E = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_F = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_F = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_G = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_G = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_DIGIT = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_DIGIT = 1;
	
	// Set up timer 0 for use with SPI related timings
	sysCtrlRegisters.HISPCP.all = 0;				// Set the HSPCLK to run at SYSCLK
	sysCtrlRegisters.LOSPCP.bit.LSPCLK = 0; 		// Set the LSPCLK to run at SYSCLK
	timer0Registers.TCR.bit.TSS = 1;				// Stop the timer
	timer0Registers.TPR.bit.TDDR = 0;				// Do not prescale the timer
	timer0Registers.PRD.all = 0xFFFFFFFF;			// Set the period register to it's largest possible value
	timer0Registers.TCR.bit.TIE = false;			// Disable timer interrupts
	timer0Registers.TCR.bit.FREE = 0;				// Set the timer to stop when a breakpoint occrs
	timer0Registers.TCR.bit.SOFT = 0;
	timer0Registers.TCR.bit.TRB = 1;				// Load the period register
	timer0Registers.TCR.bit.TSS = 0;				// Start the timer
	
	// Set up the global SPI-related settings
	IER |= 0x20;									// Enable CPU INT6
	
	// Disallow the system to write to the system registers
	EDIS;

	interruptStatus = HWI_disable();
	numSamples = 0;
	for(j = 0; j < 1000; j++)
	{
		
		InitializeGlobalVariables();

		globals.root.availableAddresses[0].address = 1;
		globals.root.availableAddresses[0].addressTaken = true;
		globals.root.availableAddresses[1].address = 2;
		globals.root.availableAddresses[1].addressTaken = true;
		globals.root.availableAddresses[2].address = 3;
		globals.root.availableAddresses[2].addressTaken = true;
		globals.root.availableAddresses[3].address = 4;
		globals.root.availableAddresses[3].addressTaken = true;
		globals.root.availableAddresses[4].address = 5;
		globals.root.availableAddresses[4].addressTaken = true;
		globals.root.availableAddresses[5].address = 6;
		globals.root.availableAddresses[5].addressTaken = true;
		globals.root.availableAddresses[6].address = 7;
		globals.root.availableAddresses[6].addressTaken = true;
		globals.root.availableAddresses[7].address = 8;
		globals.root.availableAddresses[7].addressTaken = true;	

		globals.protocol.globalNeighborInfo[1][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[1][PORTB].nodeAddress = 3;

		globals.protocol.globalNeighborInfo[2][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[2][PORTB].nodeAddress = 4;

		globals.protocol.globalNeighborInfo[3][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[3][PORTB].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[3][PORTC].nodeAddress = 5;

		globals.protocol.globalNeighborInfo[4][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[4][PORTB].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[4][PORTC].nodeAddress = 6;

		globals.protocol.globalNeighborInfo[5][PORTA].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[5][PORTB].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[5][PORTC].nodeAddress = 7;

		globals.protocol.globalNeighborInfo[6][PORTA].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[6][PORTB].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[6][PORTC].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[7][PORTA].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[7][PORTB].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[8][PORTA].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[8][PORTB].nodeAddress = 7;

		startTime = timer0Registers.TIM.all;
		GenerateRoutingTree();
		executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
		genAvgTime = (genAvgTime * numSamples) + executionTime;
		numSamples++;
		genAvgTime /= numSamples;
		if(executionTime < genMinTime)
			genMinTime = executionTime;
		else if(executionTime > genMaxTime)
			genMaxTime = executionTime;
	}

	for(i = 2; i <= 8; i++)
	{
		numSamples = 0;
		for(j = 0; j < 1000; j++)
		{
			startTime = timer0Registers.TIM.all;
			GenerateRoutingPath(1, i, &newPacket);
			executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
			avgTime[i] = (avgTime[i] * numSamples) + executionTime;
			numSamples++;
			avgTime[i] /= numSamples;
			if(executionTime < minTime[i])
				minTime[i] = executionTime;
			else if(executionTime > maxTime[i])
				maxTime[i] = executionTime;
		}
	}
	HWI_restore(interruptStatus);
	asm(" NOP");

	// Set the seed for the random number generator
	SetRandomSeed(0x175E);

	// Set up each individual port
	SetupPort(PORTA);
	SetupPort(PORTB);
	SetupPort(PORTC);
	SetupPort(PORTD);

	// Create the direct data cleanup follow-up item
	AddFollowUpItem(&CleanupDirectData,NULL,DIRECT_DATA_CLEANUP_RATE,true);

	// Create the neighbor check follow-up item
#if defined(IS_ROOT)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);
	globals.processing.sevenSegmentLowerDigit = globals.protocol.address;

#elif defined (IS_ROUTER)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE_WITHOUT_ADDRESS,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);

	// Register the test service
	RegisterServiceProvider(TEST_SERVICE_TAG,TEST_SERVICE_TASK_PRIORITY,&TestServiceTask,&TestServiceSem);

#endif

	

	// Let the other threads know that initialization is finished
	SEM_post(&ProcessInboundFlitsSem);
	SEM_post(&TestServiceSem);
}
Beispiel #19
0
void TimeOneRFFT32(int count, int fft_log_size, float signal_value,
                   int signal_type) {
  OMX_S32* x;
  OMX_S32* y;
  OMX_S32* z;
  OMX_S32* y_true;
  OMX_F32* xr;
  OMX_F32* yrTrue;

  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_true_aligned;

  OMX_S32* temp1;
  OMX_S32* temp2;

  OMX_INT n, fft_spec_buffer_size;
  OMXResult status;
  OMXFFTSpec_R_S16S32 * fft_fwd_spec = NULL;
  OMXFFTSpec_R_S16S32 * fft_inv_spec = NULL;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  int scaleFactor = 0;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;

  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);

  y_true_aligned = AllocAlignedPointer(32, sizeof(*y_true) * (fft_size + 2));

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_true = y_true_aligned->aligned_pointer_;

  if (verbose > 3) {
    printf("x = %p\n", (void*)x);
    printf("y = %p\n", (void*)y);
    printf("z = %p\n", (void*)z);
  }

  xr = (OMX_F32*) malloc(sizeof(*x) * fft_size);
  yrTrue = (OMX_F32*) malloc(sizeof(*y) * (fft_size + 2));
  temp1 = (OMX_S32*) malloc(sizeof(*temp1) * fft_size);
  temp2 = (OMX_S32*) malloc(sizeof(*temp2) * (fft_size + 2));

  GenerateRFFT32Signal(x, (OMX_SC32*) y_true, fft_size, signal_type,
                       signal_value);

  if (verbose > 63) {
    printf("Signal\n");
    printf("n\tx[n]\n");
    for (n = 0; n < fft_size; ++n) {
      printf("%4d\t%d\n", n, x[n]);
    }
  }

  status = omxSP_FFTGetBufSize_R_S32(fft_log_size, &fft_spec_buffer_size);
  if (verbose > 3) {
    printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
  }

  fft_fwd_spec = (OMXFFTSpec_R_S32*) malloc(fft_spec_buffer_size);
  fft_inv_spec = (OMXFFTSpec_R_S32*) malloc(fft_spec_buffer_size);
  status = omxSP_FFTInit_R_S32(fft_fwd_spec, fft_log_size);
  if (status) {
    printf("Failed to init forward FFT:  status = %d\n", status);
  }

  status = omxSP_FFTInit_R_S32(fft_inv_spec, fft_log_size);
  if (status) {
    printf("Failed to init backward FFT:  status = %d\n", status);
  }

  if (do_forward_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        /*
         * Spend some time computing the max of the signal, and then scaling it.
         */
        for (n = 0; n < fft_size; ++n) {
          if (abs(xr[n]) > factor) {
            factor = abs(xr[n]);
          }
        }

        factor = (1 << 20) / factor;
        for (n = 0; n < fft_size; ++n) {
          temp1[n] = factor * xr[n];
        }

        status = omxSP_FFTFwd_RToCCS_S32_Sfs(x, y, fft_fwd_spec,
                                             (OMX_INT) scaleFactor);

        /*
         * Now spend some time converting the fixed-point FFT back to float.
         */
        factor = 1 / factor;
        for (n = 0; n < fft_size + 2; ++n) {
          xr[n] = y[n] * factor;
        }
      }
      GetUserTime(&end_time);
    } else {
      float factor = -1;

      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
        status = omxSP_FFTFwd_RToCCS_S32_Sfs(x, y, fft_fwd_spec,
                                             (OMX_INT) scaleFactor);
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplex32(&snr_forward, (OMX_SC32*) y, (OMX_SC32*) y_true, fft_size / 2 + 1);

    PrintResult("Forward RFFT32", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);
  }

  if (do_inverse_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        /*
         * Spend some time scaling the FFT signal to fixed point.
         */
        for (n = 0; n < fft_size + 2; ++n) {
          if (abs(yrTrue[n]) > factor) {
            factor = abs(yrTrue[n]);
          }
        }
        for (n = 0; n < fft_size + 2; ++n) {
          temp2[n] = factor * yrTrue[n];
        }

        status = omxSP_FFTInv_CCSToR_S32_Sfs(y_true, z, fft_inv_spec, 0);

        /*
         * Spend some time converting the result back to float
         */
        factor = 1 / factor;
        for (n = 0; n < fft_size; ++n) {
          xr[n] = factor * z[n];
        }
      }
      GetUserTime(&end_time);
    } else {
      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
        status = omxSP_FFTInv_CCSToR_S32_Sfs(y_true, z, fft_inv_spec, 0);
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareReal32(&snr_inverse, z, x, fft_size);

    PrintResult("Inverse RFFT32", fft_log_size, elapsed_time, count, snr_inverse.real_snr_);
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  FreeAlignedPointer(y_true_aligned);
  free(fft_fwd_spec);
  free(fft_inv_spec);
}
Beispiel #20
0
/* Argument s16s32:
 *     S32:       Calculate RFFT16 with 32 bit complex FFT;
 *     otherwise: Calculate RFFT16 with 16 bit complex FFT.
 */
void TimeOneRFFT16(int count, int fft_log_size, float signal_value,
                   int signal_type, s16_s32 s16s32) {
  OMX_S16* x;
  OMX_S32* y;
  OMX_S16* z;
  OMX_S32* y_true;
  OMX_F32* xr;
  OMX_F32* yrTrue;

  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_trueAligned;
  struct AlignedPtr* xr_aligned;
  struct AlignedPtr* yr_true_aligned;


  OMX_S16* temp16;
  OMX_S32* temp32;


  OMX_INT n, fft_spec_buffer_size;
  OMXResult status;
  OMXFFTSpec_R_S16 * fft_fwd_spec = NULL;
  OMXFFTSpec_R_S16 * fft_inv_spec = NULL;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  int scaleFactor;

  fft_size = 1 << fft_log_size;
  scaleFactor = fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);

  y_trueAligned = AllocAlignedPointer(32, sizeof(*y_true) * (fft_size + 2));

  xr_aligned = AllocAlignedPointer(32, sizeof(*xr) * fft_size);
  yr_true_aligned = AllocAlignedPointer(32, sizeof(*yrTrue) * (fft_size + 2));

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_true = y_trueAligned->aligned_pointer_;
  xr = xr_aligned->aligned_pointer_;
  yrTrue = yr_true_aligned->aligned_pointer_;

  temp16 = (OMX_S16*) malloc(sizeof(*temp16) * fft_size);
  temp32 = (OMX_S32*) malloc(sizeof(*temp32) * fft_size);


  GenerateRFFT16Signal(x, (OMX_SC32*) y_true, fft_size, signal_type,
                       signal_value);
  /*
   * Generate a real version so we can measure scaling costs
   */
  GenerateRealFloatSignal(xr, (OMX_FC32*) yrTrue, fft_size, signal_type,
                          signal_value);

  if(s16s32 == S32) {
    status = omxSP_FFTGetBufSize_R_S16S32(fft_log_size, &fft_spec_buffer_size);
    fft_fwd_spec = malloc(fft_spec_buffer_size);
    fft_inv_spec = malloc(fft_spec_buffer_size);
    status = omxSP_FFTInit_R_S16S32(fft_fwd_spec, fft_log_size);
    status = omxSP_FFTInit_R_S16S32(fft_inv_spec, fft_log_size);
  }
  else {
    status = omxSP_FFTGetBufSize_R_S16(fft_log_size, &fft_spec_buffer_size);
    fft_fwd_spec = malloc(fft_spec_buffer_size);
    fft_inv_spec = malloc(fft_spec_buffer_size);
    status = omxSP_FFTInit_R_S16(fft_fwd_spec, fft_log_size);
    status = omxSP_FFTInit_R_S16(fft_inv_spec, fft_log_size);
  }

  if (do_forward_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        /*
         * Spend some time computing the max of the signal, and then scaling it.
         */
        for (n = 0; n < fft_size; ++n) {
          if (abs(xr[n]) > factor) {
            factor = abs(xr[n]);
          }
        }

        factor = 32767 / factor;
        for (n = 0; n < fft_size; ++n) {
          temp16[n] = factor * xr[n];
        }

        if(s16s32 == S32) {
          status = omxSP_FFTFwd_RToCCS_S16S32_Sfs(x, y,
              (OMXFFTSpec_R_S16S32*)fft_fwd_spec, (OMX_INT) scaleFactor);
        }
        else {
          status = omxSP_FFTFwd_RToCCS_S16_Sfs(x,  (OMX_S16*)y,
              (OMXFFTSpec_R_S16*)fft_fwd_spec, (OMX_INT) scaleFactor);
        }
        /*
         * Now spend some time converting the fixed-point FFT back to float.
         */
        factor = 1 / factor;
        for (n = 0; n < fft_size + 2; ++n) {
          xr[n] = y[n] * factor;
        }
      }
      GetUserTime(&end_time);
    } else {
      float factor = -1;

      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
      if(s16s32 == S32) {
        status = omxSP_FFTFwd_RToCCS_S16S32_Sfs(x, y, 
            (OMXFFTSpec_R_S16S32*)fft_fwd_spec, (OMX_INT) scaleFactor);
      }
      else {
        status = omxSP_FFTFwd_RToCCS_S16_Sfs(x, (OMX_S16*)y,
            (OMXFFTSpec_R_S16*)fft_fwd_spec, (OMX_INT) scaleFactor);
      }
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    if(s16s32 == S32) {
      PrintResultNoSNR("Forward RFFT16 (with S32)",
                       fft_log_size, elapsed_time, count);
    }
    else {
      PrintResultNoSNR("Forward RFFT16 (with S16)",
                       fft_log_size, elapsed_time, count);
    }
  }

  if (do_inverse_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        /*
         * Spend some time scaling the FFT signal to fixed point.
         */
        for (n = 0; n < fft_size; ++n) {
          if (abs(yrTrue[n]) > factor) {
            factor = abs(yrTrue[n]);
          }
        }
        for (n = 0; n < fft_size; ++n) {
          temp32[n] = factor * yrTrue[n];
        }

        if(s16s32 == S32) {
          status = omxSP_FFTInv_CCSToR_S32S16_Sfs(y, z,
              (OMXFFTSpec_R_S16S32*)fft_inv_spec, 0);
        }
        else {
          status = omxSP_FFTInv_CCSToR_S16_Sfs((OMX_S16*)y, z,
              (OMXFFTSpec_R_S16*)fft_inv_spec, 0);
        }
        /*
         * Spend some time converting the result back to float
         */
        factor = 1 / factor;
        for (n = 0; n < fft_size; ++n) {
          xr[n] = factor * z[n];
        }
      }
      GetUserTime(&end_time);
    } else {
      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
        if(s16s32 == S32) {
          status = omxSP_FFTInv_CCSToR_S32S16_Sfs(y, z,
              (OMXFFTSpec_R_S16S32*)fft_inv_spec, 0);
        }
        else {
          status = omxSP_FFTInv_CCSToR_S16_Sfs((OMX_S16*)y, z,
              (OMXFFTSpec_R_S16*)fft_inv_spec, 0);
        }
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    if(s16s32 == S32) {
      PrintResultNoSNR("Inverse RFFT16 (with S32)",
                       fft_log_size, elapsed_time, count);
    }
    else {
      PrintResultNoSNR("Inverse RFFT16 (with S16)",
                       fft_log_size, elapsed_time, count);
    }
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  FreeAlignedPointer(y_trueAligned);
  FreeAlignedPointer(xr_aligned);
  FreeAlignedPointer(yr_true_aligned);
  free(fft_fwd_spec);
  free(fft_inv_spec);
}
Beispiel #21
0
void TimeOneSC16FFT(int count, int fft_log_size, float signal_value,
                    int signal_type) {
  OMX_SC16* x;
  OMX_SC16* y;
  OMX_SC16* z;

  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;

  OMX_SC16* y_true;
  OMX_SC16* temp16a;
  OMX_SC16* temp16b;

  OMX_INT n, fft_spec_buffer_size;
  OMXResult status;
  OMXFFTSpec_C_SC16 * fft_fwd_spec = NULL;
  OMXFFTSpec_C_SC16 * fft_inv_spec = NULL;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;

  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * fft_size);
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
  y_true = (OMX_SC16*) malloc(sizeof(*y_true) * fft_size);
  temp16a = (OMX_SC16*) malloc(sizeof(*temp16a) * fft_size);
  temp16b = (OMX_SC16*) malloc(sizeof(*temp16b) * fft_size);

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;

  generateSC16Signal(x, y_true, fft_size, signal_type, signal_value);

  status = omxSP_FFTGetBufSize_C_SC16(fft_log_size, &fft_spec_buffer_size);

  fft_fwd_spec = (OMXFFTSpec_C_SC16*) malloc(fft_spec_buffer_size);
  fft_inv_spec = (OMXFFTSpec_C_SC16*) malloc(fft_spec_buffer_size);
  status = omxSP_FFTInit_C_SC16(fft_fwd_spec, fft_log_size);

  status = omxSP_FFTInit_C_SC16(fft_inv_spec, fft_log_size);

  if (do_forward_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        for (n = 0; n < fft_size; ++n) {
          if (abs(x[n].Re) > factor) {
            factor = abs(x[n].Re);
          }
          if (abs(x[n].Im) > factor) {
            factor = abs(x[n].Im);
          }
        }

        factor = ((1 << 15) - 1) / factor;
        for (n = 0; n < fft_size; ++n) {
          temp16a[n].Re = factor * x[n].Re;
          temp16a[n].Im = factor * x[n].Im;
        }

        omxSP_FFTFwd_CToC_SC16_Sfs(x, y, fft_fwd_spec, 0);

        factor = 1 / factor;
        for (n = 0; n < fft_size; ++n) {
          temp16b[n].Re = y[n].Re * factor;
          temp16b[n].Im = y[n].Im * factor;
        }
      }
      GetUserTime(&end_time);
    } else {
      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
        omxSP_FFTFwd_CToC_SC16_Sfs(x, y, fft_fwd_spec, 0);
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplex16(&snr_forward, y, y_true, fft_size);

    PrintResult("Forward SC16 FFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);
  }

  if (do_inverse_test) {
    if (include_conversion) {
      int k;
      float factor = -1;

      GetUserTime(&start_time);
      for (k = 0; k < count; ++k) {
        for (n = 0; n < fft_size; ++n) {
          if (abs(x[n].Re) > factor) {
            factor = abs(x[n].Re);
          }
          if (abs(x[n].Im) > factor) {
            factor = abs(x[n].Im);
          }
        }
        factor = ((1 << 15) - 1) / factor;
        for (n = 0; n < fft_size; ++n) {
          temp16a[n].Re = factor * x[n].Re;
          temp16a[n].Im = factor * x[n].Im;
        }

        status = omxSP_FFTInv_CToC_SC16_Sfs(y, z, fft_inv_spec, 0);

        factor = 1 / factor;
        for (n = 0; n < fft_size; ++n) {
          temp16b[n].Re = y[n].Re * factor;
          temp16b[n].Im = y[n].Im * factor;
        }
      }
      GetUserTime(&end_time);
    } else {
      GetUserTime(&start_time);
      for (n = 0; n < count; ++n) {
        status = omxSP_FFTInv_CToC_SC16_Sfs(y, z, fft_inv_spec, 0);
      }
      GetUserTime(&end_time);
    }

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplex16(&snr_inverse, z, x, fft_size);

    PrintResult("Inverse SC16 FFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  free(temp16a);
  free(temp16b);
  free(fft_fwd_spec);
  free(fft_inv_spec);
}
Beispiel #22
0
void TimeOneFloatFFT(int count, int fft_log_size, float signal_value,
                     int signal_type) {
  struct AlignedPtr* x_aligned;
  struct AlignedPtr* y_aligned;
  struct AlignedPtr* z_aligned;
  struct AlignedPtr* y_true_aligned;

  struct ComplexFloat* x;
  struct ComplexFloat* y;
  OMX_FC32* z;

  struct ComplexFloat* y_true;

  OMX_INT n, fft_spec_buffer_size;
  OMXFFTSpec_C_FC32 * fft_fwd_spec = NULL;
  OMXFFTSpec_C_FC32 * fft_inv_spec = NULL;
  int fft_size;
  struct timeval start_time;
  struct timeval end_time;
  double elapsed_time;
  struct SnrResult snr_forward;
  struct SnrResult snr_inverse;

  fft_size = 1 << fft_log_size;

  x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
  y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
  z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
  y_true_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);

  x = x_aligned->aligned_pointer_;
  y = y_aligned->aligned_pointer_;
  z = z_aligned->aligned_pointer_;
  y_true = y_true_aligned->aligned_pointer_;

  GenerateTestSignalAndFFT(x, y_true, fft_size, signal_type, signal_value, 0);

  omxSP_FFTGetBufSize_C_FC32(fft_log_size, &fft_spec_buffer_size);

  fft_fwd_spec = (OMXFFTSpec_C_FC32*) malloc(fft_spec_buffer_size);
  fft_inv_spec = (OMXFFTSpec_C_FC32*) malloc(fft_spec_buffer_size);
  omxSP_FFTInit_C_FC32(fft_fwd_spec, fft_log_size);
  omxSP_FFTInit_C_FC32(fft_inv_spec, fft_log_size);

  if (do_forward_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      FORWARD_FLOAT_FFT((OMX_FC32*) x, (OMX_FC32*) y, fft_fwd_spec);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size);

    PrintResult("Forward Float FFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);
  }

  if (do_inverse_test) {
    GetUserTime(&start_time);
    for (n = 0; n < count; ++n) {
      INVERSE_FLOAT_FFT((OMX_FC32*) y_true, z, fft_inv_spec);
    }
    GetUserTime(&end_time);

    elapsed_time = TimeDifference(&start_time, &end_time);

    CompareComplexFloat(&snr_inverse, (OMX_FC32*) z, (OMX_FC32*) x, fft_size);

    PrintResult("Inverse Float FFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);
  }

  FreeAlignedPointer(x_aligned);
  FreeAlignedPointer(y_aligned);
  FreeAlignedPointer(z_aligned);
  FreeAlignedPointer(y_true_aligned);
  free(fft_fwd_spec);
  free(fft_inv_spec);
}
Beispiel #23
0
/***********************************************************************
 *
 * FUNCTION:    SelectTime
 *
 * DESCRIPTION: Display a form showing a start and end time.
 *					 Allow the user to change the time and then
 *              return them.
 *					 pTimeDiff.
 *
 * PARAMETERS:  pStartTime	- pointer to TimeType
 *              pEndTime   - pointer to TimeType
 *              untimed  	- true if there isn't a time.
 *              title	   - string containing the title
 *              startOfDay - used when "All Day" button selected.
 *					 endOfDay	- our used when "All Day" button selected.
 *              startOfDisplay - first hour initially visible
 *
 * RETURNED:	 True if the time was changed by the user.
 * 				 The first three parameters may change.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	12/2/94	Initial Revision
 *			trev	08/12/97	made non modified passed variables constant
 *			css	06/08/99	added new parameter & "All Day" button for gromit change.
 *
 ***********************************************************************/
Boolean SelectTime (TimeType * startTimeP, TimeType * endTimeP, 
	Boolean untimed, const Char * titleP, Int16 startOfDay, Int16 endOfDay, 
	Int16 startOfDisplay)
{
	Int16							firstHour;
	Char 							startTimeText [timeStringLength];
	Char 							endTimeText [timeStringLength];
	Char							timeChars [timeStringLength];
	TimePtr						timeP;
	FormType 					*originalForm, *frm;
	ListPtr 						hoursLst, minutesLst;
	ControlPtr 					startTimeCtl, endTimeCtl;
	EventType 					event;
	Boolean 						confirmed = false;
	MemHandle 						hoursItems;
	TimeType 					startTime, endTime, timeDiff;
	TimeFormatType 			timeFormat;
	ChangingTimeType			changingTime;

	// Get the time format from the system preerances;
	timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);


	// Because this routine only deals with minutes in five minute
	// intervals we convert the proposed times from those passed.
	startTime.hours = startTimeP->hours;
	startTime.minutes = startTimeP->minutes;
	endTime.hours = endTimeP->hours;
	endTime.minutes = endTimeP->minutes;
	TimeDifference (&endTime, &startTime, &timeDiff);
	
	// Make sure the end time is displayable (clips at 11:55 pm)
	AdjustTimes (&startTime, &endTime, &timeDiff, changingStartTime);
	
	// Clear the buffer that holds written characters.
	*timeChars = 0;

	startOfDisplay = min (startOfDisplay, 12);

	originalForm = FrmGetActiveForm();
	frm = (FormType *) FrmInitForm (TimeSelectorForm);
	FrmSetActiveForm (frm);

	hoursLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorHourList));
	minutesLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorMinuteList));
	startTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorStartTimeButton));
	endTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorEndTimeButton));


	// Set list to use either 12 or 24 hour time
	hoursItems = SysFormPointerArrayToStrings (
		((timeFormat == tfColon24h) || (timeFormat == tfDot24h)) ? 
			(Char *) Hours24Array() : (Char *) Hours12Array(), 24);
 
 	LstSetListChoices (hoursLst, MemHandleLock(hoursItems), 24);
	LstSetTopItem (hoursLst, startOfDisplay);
	//	Used to do LstMakeItemVisible (hoursLst, startTime.hours); no longer.


	if (! untimed)
		{
		LstSetSelection (hoursLst, startTime.hours);
		LstSetSelection (minutesLst, startTime.minutes / 5);

		CtlSetValue (startTimeCtl, true);
		changingTime = changingStartTime;
		}
	else
		{
		// The hour list is dynamically created and doesn't have a selection
		LstSetSelection (minutesLst, noListSelection);

		changingTime = changingNoTime;
		}


	// Set the start and end time buttons to the current times or blank them
	// if No Time is selected.
	SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, 
		timeFormat, untimed);
		

	// This needs to be taken out when SelectTimeV33 goes away.  It allows for backward 
	// compatibility for this change of adding the end of day variable as a parameter.
	if (endOfDay != noDisplayOfAllDay)
	{
	  FrmShowObject (frm, FrmGetObjectIndex (frm, TimeSelectorAllDayButton));
	}
	
	FrmSetTitle (frm, (Char *) titleP);
	FrmDrawForm (frm);
	
	
	while (true)
		{
		EvtGetEvent (&event, evtWaitForever);

		if (SysHandleEvent ((EventType *)&event))
			continue;
			
		if (event.eType == appStopEvent)
			{
			// Cancel the dialog and repost this event for the app
			EvtAddEventToQueue(&event);
			confirmed = false;
			break;
			}
			
		// Handle these before the form does to overide the default behavior
		if (changingTime == changingNoTime &&
			event.eType == lstEnterEvent && 
			event.data.lstEnter.listID == TimeSelectorMinuteList)
			{
			SndPlaySystemSound(sndError);
			continue;
			}

		FrmHandleEvent (frm, &event);


		// If the start or end time buttons are pressed then change
		// the time displayed in the lists.
		if (event.eType == ctlSelectEvent)
			{
			// "Ok" button pressed?
			if (event.data.ctlSelect.controlID == TimeSelectorOKButton)
				{
				confirmed = true;
				}

			// "Cancel" button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorCancelButton)
				{
				break;
				}

			// Start time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorStartTimeButton)
				{
				if (changingTime != changingStartTime)
					{
					if (changingTime == changingNoTime)
						{
						SetTimeTriggers (startTime, endTime, startTimeText, 
							endTimeText, timeFormat, false);
						}

					CtlSetValue (endTimeCtl, false);
					LstSetSelection (hoursLst, startTime.hours);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					changingTime = changingStartTime;
					}
				else
					CtlSetValue(startTimeCtl, true);
				}

			// End time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorEndTimeButton)
				{
				if (changingTime != changingEndTime)
					{
					if (changingTime == changingNoTime)
						{
						SetTimeTriggers (startTime, endTime, startTimeText, 
							endTimeText, timeFormat, false);
						}

					CtlSetValue(startTimeCtl, false);
					LstSetSelection (hoursLst, endTime.hours);
					LstSetSelection (minutesLst, endTime.minutes / 5);
					changingTime = changingEndTime;
					}
				else
					CtlSetValue(endTimeCtl, true);
				}

			// No time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorNoTimeButton)
				{
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue(startTimeCtl, false);
					else
						CtlSetValue(endTimeCtl, false);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
					// Get us out of this form display now.
					confirmed = true;
				}

			// All day button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorAllDayButton)
				{
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue(startTimeCtl, false);
					else
						CtlSetValue(endTimeCtl, false);
					
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
											
					// No matter what, the minutes are 0 for both because only the hour is registered for start/end
					// times.
					startTime.minutes = 0;
					endTime.minutes 	= 0;
					startTime.hours 	= startOfDay;
					endTime.hours 		= endOfDay;
					
					// Set the times to the new times.
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					// Get us out of this form display now.  First set the changing time to anything but the changingNoTime value
					// so that the pointers at the end of this function get set correctly.
					changingTime = changingStartTime;
					confirmed = true;
				}

			// Clear the buffer that holds written characters.
			*timeChars = 0;
			}


		// If either list is changed then get the new time.  If the
		// start time is changed then change the end time so that the
		// the time difference remains the same.  If the end time is
		// changed then make sure the end time isn't before the start
		// time.  Also calculate a new time difference.
		else if (event.eType == lstSelectEvent)
			{
         // First, get the info from the list which has changed.
			if (event.data.lstSelect.listID == TimeSelectorHourList)
				{
				if (changingTime == changingStartTime)
               startTime.hours = (UInt8) LstGetSelection (hoursLst);
           	else if (changingTime == changingEndTime)
               endTime.hours = (UInt8) LstGetSelection (hoursLst);
           	else if (changingTime == changingNoTime)
           		{
               startTime.hours = (UInt8) LstGetSelection (hoursLst);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, false);
					CtlSetValue (endTimeCtl, false);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					changingTime = changingStartTime;
					}
				}
         else if (event.data.lstSelect.listID == TimeSelectorMinuteList)
				{
				if (changingTime == changingStartTime)
               startTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5;
           	else if (changingTime == changingEndTime)
					endTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5;
           	else if (changingTime == changingNoTime)
           		{
               ErrNonFatalDisplay("lstEnterEvent not being filtered.");
               }
				}


			if (AdjustTimes (&startTime, &endTime, &timeDiff, changingTime))
				{
				if (changingTime == changingStartTime)
					{
					TimeToAscii (startTime.hours, startTime.minutes, timeFormat, 
						startTimeText);
					CtlSetLabel (startTimeCtl, startTimeText);
					}
				else if (changingTime == changingEndTime)
					{
					LstSetSelection (hoursLst, startTime.hours);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					}
				}
			TimeToAscii(endTime.hours, endTime.minutes, timeFormat, endTimeText);
			CtlSetLabel(endTimeCtl, endTimeText);


			// Clear the buffer that holds written characters.
			*timeChars = 0;
			}


		// Handle character written in the time picker.
		else if (event.eType == keyDownEvent)
			{
			if (changingTime == changingEndTime)
				{
				timeP = &endTime;
				firstHour = startTime.hours;
				}
			else
				{
				timeP = &startTime;
				firstHour = startOfDisplay;
				}
		
			// If a backspace character was written, change the time picker's
			// current setting to "no-time".
			if (event.data.keyDown.chr == backspaceChr)
				{
				*timeChars = 0;
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue (startTimeCtl, false);
					else
						CtlSetValue (endTimeCtl, false);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
				}

			// A linefeed character confirms the dialog box.
			else if (event.data.keyDown.chr == linefeedChr)
				{
				confirmed = true;
				}

			// If next-field character toggle between start time in end
			// time.
			else if (event.data.keyDown.chr == nextFieldChr)
				{
				*timeChars = 0;
				if (changingTime == changingStartTime)
					{
					CtlSetValue (startTimeCtl, false);
					CtlSetValue (endTimeCtl, true);
					changingTime = changingEndTime;
					}
				else
					{
					CtlSetValue (endTimeCtl, false);
					CtlSetValue (startTimeCtl, true);
					changingTime = changingStartTime;
					}
				}


			// If a valid time character was written, translate the written 
			// character into a time and update the time picker's UI.
			else if (TranslateTime (timeFormat, event.data.keyDown.chr, 
				firstHour, timeChars, timeP))
				{
				if (changingTime == changingNoTime)
					{
					changingTime = changingStartTime;
					CtlSetValue (startTimeCtl, true);
					}

				AdjustTimes (&startTime, &endTime, &timeDiff, changingTime);
				
				SetTimeTriggers (startTime, endTime, startTimeText, 
					endTimeText, timeFormat, false);

				LstSetSelection (hoursLst, timeP->hours);
				LstSetSelection (minutesLst, timeP->minutes / 5);
				}
			}

		// Has the dialog been confirmed.
		if (confirmed)
			{
			if (changingTime != changingNoTime)
				{
				*startTimeP = startTime;
				*endTimeP = endTime;
				}
			else
				{
				TimeToInt(*startTimeP) = noTime;
				TimeToInt(*endTimeP) = noTime;
				}
			break;
			}

		}

	FrmEraseForm (frm);
	FrmDeleteForm (frm);
	MemHandleFree (hoursItems);
	
	FrmSetActiveForm(originalForm);
	
	return (confirmed);
	}
Beispiel #24
0
void TimeOneNE10FFT(int count, int fft_log_size, float signal_value,
                    int signal_type) {
    struct AlignedPtr* x_aligned;
    struct AlignedPtr* y_aligned;
    struct AlignedPtr* z_aligned;

    struct ComplexFloat* x;
    struct ComplexFloat* y;
    OMX_FC32* z;

    struct ComplexFloat* y_true;

    int n;
    ne10_result_t status;
    ne10_fft_cfg_float32_t fft_fwd_spec;
    int fft_size;
    struct timeval start_time;
    struct timeval end_time;
    double elapsed_time;
    struct SnrResult snr_forward;
    struct SnrResult snr_inverse;

    fft_size = 1 << fft_log_size;

    x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
    y_aligned = AllocAlignedPointer(32, sizeof(*y) * 2 * fft_size);
    z_aligned = AllocAlignedPointer(32, sizeof(*z) * 2 * fft_size);

    y_true = (struct ComplexFloat*) malloc(sizeof(*y_true) * fft_size);

    x = x_aligned->aligned_pointer_;
    y = y_aligned->aligned_pointer_;
    z = z_aligned->aligned_pointer_;

    GenerateTestSignalAndFFT(x, y_true, fft_size, signal_type, signal_value, 0);

    fft_fwd_spec = ne10_fft_alloc_c2c_float32(fft_size);
    if (!fft_fwd_spec) {
        fprintf(stderr, "NE10 FFT: Cannot initialize FFT structure for order %d\n", fft_log_size);
        return;
    }

    if (do_forward_test) {
        GetUserTime(&start_time);
        for (n = 0; n < count; ++n) {
            ne10_fft_c2c_1d_float32_neon((ne10_fft_cpx_float32_t *) y,
                                         (ne10_fft_cpx_float32_t *) x,
                                         fft_fwd_spec,
                                         0);
        }
        GetUserTime(&end_time);

        elapsed_time = TimeDifference(&start_time, &end_time);

        CompareComplexFloat(&snr_forward, (OMX_FC32*) y, (OMX_FC32*) y_true, fft_size);

        PrintResult("Forward NE10 FFT", fft_log_size, elapsed_time, count, snr_forward.complex_snr_);

        if (verbose >= 255) {
            printf("Input data:\n");
            DumpArrayComplexFloat("x", fft_size, (OMX_FC32*) x);
            printf("FFT Actual:\n");
            DumpArrayComplexFloat("y", fft_size, (OMX_FC32*) y);
            printf("FFT Expected:\n");
            DumpArrayComplexFloat("true", fft_size, (OMX_FC32*) y_true);
        }
    }

    if (do_inverse_test) {
        GetUserTime(&start_time);
        for (n = 0; n < count; ++n) {
            ne10_fft_c2c_1d_float32_neon((ne10_fft_cpx_float32_t *) z,
                                         (ne10_fft_cpx_float32_t *) y_true,
                                         fft_fwd_spec,
                                         1);
        }
        GetUserTime(&end_time);

        elapsed_time = TimeDifference(&start_time, &end_time);

        CompareComplexFloat(&snr_inverse, (OMX_FC32*) z, (OMX_FC32*) x, fft_size);

        PrintResult("Inverse NE10 FFT", fft_log_size, elapsed_time, count, snr_inverse.complex_snr_);

        if (verbose >= 255) {
            printf("Input data:\n");
            DumpArrayComplexFloat("y", fft_size, (OMX_FC32*) y_true);
            printf("IFFT Actual:\n");
            DumpArrayComplexFloat("z", fft_size, z);
            printf("IFFT Expected:\n");
            DumpArrayComplexFloat("x", fft_size, (OMX_FC32*) x);
        }
    }

    ne10_fft_destroy_c2c_float32(fft_fwd_spec);
    FreeAlignedPointer(x_aligned);
    FreeAlignedPointer(y_aligned);
    FreeAlignedPointer(z_aligned);
    free(y_true);
}