Navigation Menu

Skip to content

Commit

Permalink
adding single thread example
Browse files Browse the repository at this point in the history
  • Loading branch information
lilltroll77 committed Oct 17, 2011
1 parent 540ad8f commit 11caa90
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app_example_singel_thread_fir_with_channels/Makefile
@@ -0,0 +1,44 @@
# The TARGET variable determines what target system the application is
# compiled for. It either refers to an XN file in the source directories
# or a valid argument for the --target option when compiling.

TARGET = XDK

# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name

APP_NAME = app_example_singel_fir

# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.

XCC_FLAGS = -O2

# The USED_MODULES variable lists other module used by the application.

USED_MODULES = module_fir

#=============================================================================
# The following part of the Makefile includes the common build infrastructure
# for compiling XMOS applications. You should not need to edit below here.


# Use the main Makefile from module_xcommon
-include ../module_xcommon/build/Makefile.common
-include ../../xcommon/module_xcommon/build/Makefile.common

# The final target of the build. This is usually dependent on a binary file
# in the $(BIN_DIR) directory e.g.
#
# all : $(BIN_DIR)/my_app.xe

all: $(BIN_DIR)/$(APP_NAME).xe
@echo Build Complete

clean: clean_common
84 changes: 84 additions & 0 deletions app_example_singel_thread_fir_with_channels/src/main.xc
@@ -0,0 +1,84 @@
/*
* main.xc
*
* Created on: 14 okt 2011
* Author: Mikael Bohman
*/
//FIR filter using a channel as Inut and Ouput running on 1 trhrad. Uses the double data method and Q8.24

#include <platform.h>
#include <print.h>
#include <xs1.h>
#include <fir.h>

#define sec XS1_TIMER_HZ
#define ntaps 3000 //Number of FIT filter taps
#define POLYNOMIAL 0xEDB88320 //Used for crc32 checksum



int test_performance(streaming chanend c) {
timer t;
int time;
unsigned crc = 0;
int ans = 0, i = 1;
printstrln("Testing performance, Running FIR-filter for 1 sec on a single thread with 3000 filter taps");
t:> time;
c<:i; //Send first sample directly after the timing started
time+=sec;
while(1) {
select {
default:
i++;
c<:i;
c:>ans;
crc32(crc, ans, POLYNOMIAL);
break;
case t when timerafter (time) :> void:
printstr("Filtered ");
printint(i);
printstrln(" samples during 1 second");
printint(i*3);
printstrln(" kTaps per sec.");
printstr("CRC32 checksum for all filtered samples was: 0x");
printhex(crc);
soutct(c,10); //end FIR thread
return i;
}
}
return -1;
}

int main() {
streaming chan c;

//Init the arrays
int ans;

unsigned crc = 0;
unsigned samples;
int x[2 * ntaps];
int h[ntaps];
for (int i = 0; i < ntaps; i++) {
h[i] = (i + 1)<<24;
x[i] = 0;
x[i + ntaps] = 0;
}par {
firASM_DoubleData_singleThread(c, h, x, ntaps);
samples = test_performance(c);
}
for (int i = 0; i < ntaps; i++) {
x[i] = 0;
}
printstrln(
"\nCalculating the CRC32 checksum from the XC implementation, this might take some time");
for (int i = 1; i < samples; i++) {
ans = fir(i, h, x, ntaps);
crc32(crc, ans, POLYNOMIAL);
}
printstr("Correct Checksum for filtered datasequence is: 0x");
printhex(crc);
while (1); // Program doesn't halt correctly ??

return 0;
}

0 comments on commit 11caa90

Please sign in to comment.