I want to use the FIR51 sample with fixed point values and coefficients
changing types :
CODE
//////////////////////////////////////////////////////////////////
// Fir filter example.
//
// Copyright© 2003-2005 Impulse Accelerated Technologies, Inc.
//
// fir_hw.c: includes the hardware process and configuration
// function.
//
// See additional comments in fir.h.
//
#include <stdio.h>
#include "co.h"
#include "cosim_log.h"
#include "fir.h"
extern void test_producer(co_stream waveform_raw);
extern void test_consumer(co_stream waveform_filtered);
void fir(co_stream filter_in, co_stream filter_out)
{
co_uint32 coef[TAPS];
IF_SIM(int samplesread = 0;)
IF_SIM(int sampleswritten = 0;)
co_uint32 firbuffer[TAPS];
co_uint32 nSample;
co_uint32 nFiltered;
co_uint32 accum;
int tap;
IF_SIM( cosim_logwindow log; )
IF_SIM ( log = cosim_logwindow_create("fir"); )
do { // Hardware processes run forever
co_stream_open(filter_in, O_RDONLY, UINT_TYPE(32));
co_stream_open(filter_out, O_WRONLY, UINT_TYPE(32));
// First fill the coef array with the coefficients...
for (tap = 0; tap < TAPS; tap++) {
#pragma CO UNROLL
co_stream_read(filter_in, &nSample, sizeof(co_uint32));
coef[tap] = nSample;
}
// Now fill the firbuffer array with the first n values...
for (tap = 1; tap < TAPS; tap++) {
#pragma CO UNROLL
co_stream_read(filter_in, &nSample, sizeof(co_uint32));
IF_SIM(samplesread++
firbuffer[tap-1] = nSample;
}
// Now we have an almost full buffer and can start processing
// the streaming waveform samples.
//
// Read values from the stream
while ( co_stream_read(filter_in, &nSample, sizeof(co_uint32)) == co_err_none ) {
#pragma CO PIPELINE
IF_SIM(samplesread++
firbuffer[TAPS-1] = nSample;
accum = 0x00000000;
for (tap = 0; tap < TAPS; tap++) {
#pragma CO UNROLL
#pragma CO SET StageDelay 100
accum += FXMUL32(firbuffer[tap],coef[tap],8);
}
nFiltered = accum >> 2;
co_stream_write(filter_out, &nFiltered, sizeof(co_uint32));
IF_SIM(sampleswritten++
for (tap = 1; tap < TAPS; tap++) {
#pragma CO UNROLL
firbuffer[tap-1] = firbuffer[tap];
}
}
IF_SIM(cosim_logwindow_fwrite(log,
"Closing fir filter process, samples read: %d, samples written: %d\n",
samplesread, sampleswritten)
co_stream_close(filter_in);
co_stream_close(filter_out);
IF_SIM(break;) // Only run once for desktop simulation
} while(1);
}
//
// Impulse C configuration function
//
void config_fir(void *arg)
{
co_stream waveform_raw;
co_stream waveform_filtered;
co_process fir_process;
#ifdef IMPULSE_C_SYNTHESIS
co_port fir_input, fir_output;
#else
co_process producer_process;
co_process consumer_process;
cosim_logwindow_init();
#endif
waveform_raw = co_stream_create("waveform_raw", UINT_TYPE(32), BUFSIZE);
waveform_filtered = co_stream_create("waveform_filtered", UINT_TYPE(32), BUFSIZE);
fir_process = co_process_create("filter_process", (co_function)fir,
2,
waveform_raw,
waveform_filtered);
#ifdef IMPULSE_C_SYNTHESIS
// Assign the stream I/O to specific named ports...
fir_input = co_port_create("FIR_input", co_input, waveform_raw);
fir_output = co_port_create("FIR_output", co_output, waveform_filtered);
#else
producer_process = co_process_create("producer_process", (co_function)test_producer,
1,
waveform_raw);
consumer_process = co_process_create("consumer_process",(co_function)test_consumer,
1,
waveform_filtered);
#endif
// Assign processes to hardware elements
co_process_config(fir_process, co_loc, "PE0");
}
co_architecture co_initialize(int param)
{
return(co_architecture_create("fir_arch","Generic_VHDL",config_fir,(void *)param));
}
// Fir filter example.
//
// Copyright© 2003-2005 Impulse Accelerated Technologies, Inc.
//
// fir_hw.c: includes the hardware process and configuration
// function.
//
// See additional comments in fir.h.
//
#include <stdio.h>
#include "co.h"
#include "cosim_log.h"
#include "fir.h"
extern void test_producer(co_stream waveform_raw);
extern void test_consumer(co_stream waveform_filtered);
void fir(co_stream filter_in, co_stream filter_out)
{
co_uint32 coef[TAPS];
IF_SIM(int samplesread = 0;)
IF_SIM(int sampleswritten = 0;)
co_uint32 firbuffer[TAPS];
co_uint32 nSample;
co_uint32 nFiltered;
co_uint32 accum;
int tap;
IF_SIM( cosim_logwindow log; )
IF_SIM ( log = cosim_logwindow_create("fir"); )
do { // Hardware processes run forever
co_stream_open(filter_in, O_RDONLY, UINT_TYPE(32));
co_stream_open(filter_out, O_WRONLY, UINT_TYPE(32));
// First fill the coef array with the coefficients...
for (tap = 0; tap < TAPS; tap++) {
#pragma CO UNROLL
co_stream_read(filter_in, &nSample, sizeof(co_uint32));
coef[tap] = nSample;
}
// Now fill the firbuffer array with the first n values...
for (tap = 1; tap < TAPS; tap++) {
#pragma CO UNROLL
co_stream_read(filter_in, &nSample, sizeof(co_uint32));
IF_SIM(samplesread++
firbuffer[tap-1] = nSample;
}
// Now we have an almost full buffer and can start processing
// the streaming waveform samples.
//
// Read values from the stream
while ( co_stream_read(filter_in, &nSample, sizeof(co_uint32)) == co_err_none ) {
#pragma CO PIPELINE
IF_SIM(samplesread++
firbuffer[TAPS-1] = nSample;
accum = 0x00000000;
for (tap = 0; tap < TAPS; tap++) {
#pragma CO UNROLL
#pragma CO SET StageDelay 100
accum += FXMUL32(firbuffer[tap],coef[tap],8);
}
nFiltered = accum >> 2;
co_stream_write(filter_out, &nFiltered, sizeof(co_uint32));
IF_SIM(sampleswritten++
for (tap = 1; tap < TAPS; tap++) {
#pragma CO UNROLL
firbuffer[tap-1] = firbuffer[tap];
}
}
IF_SIM(cosim_logwindow_fwrite(log,
"Closing fir filter process, samples read: %d, samples written: %d\n",
samplesread, sampleswritten)
co_stream_close(filter_in);
co_stream_close(filter_out);
IF_SIM(break;) // Only run once for desktop simulation
} while(1);
}
//
// Impulse C configuration function
//
void config_fir(void *arg)
{
co_stream waveform_raw;
co_stream waveform_filtered;
co_process fir_process;
#ifdef IMPULSE_C_SYNTHESIS
co_port fir_input, fir_output;
#else
co_process producer_process;
co_process consumer_process;
cosim_logwindow_init();
#endif
waveform_raw = co_stream_create("waveform_raw", UINT_TYPE(32), BUFSIZE);
waveform_filtered = co_stream_create("waveform_filtered", UINT_TYPE(32), BUFSIZE);
fir_process = co_process_create("filter_process", (co_function)fir,
2,
waveform_raw,
waveform_filtered);
#ifdef IMPULSE_C_SYNTHESIS
// Assign the stream I/O to specific named ports...
fir_input = co_port_create("FIR_input", co_input, waveform_raw);
fir_output = co_port_create("FIR_output", co_output, waveform_filtered);
#else
producer_process = co_process_create("producer_process", (co_function)test_producer,
1,
waveform_raw);
consumer_process = co_process_create("consumer_process",(co_function)test_consumer,
1,
waveform_filtered);
#endif
// Assign processes to hardware elements
co_process_config(fir_process, co_loc, "PE0");
}
co_architecture co_initialize(int param)
{
return(co_architecture_create("fir_arch","Generic_VHDL",config_fir,(void *)param));
}
CODE
//////////////////////////////////////////////////////////////////
// Fir filter example.
//
// Written for Generic Platform Support Package.
//
// Copyright© 2003-2005 Impulse Accelerated Technologies, Inc.
//
// fir_sw.c: includes the software test bench processes and
// main() function.
//
#ifdef WIN32
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#else // ! WIN32
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#endif
#include <stdio.h>
#include "co.h"
#include "co_math.h"
#include "cosim_log.h"
#include "fir.h"
#define HARDWARE_FIXED
extern co_architecture co_initialize(void *);
void test_producer(co_stream waveform_raw)
{
int c;
cosim_logwindow log = cosim_logwindow_create("test_producer");
// Read waveform and coefficients from a file
const char * CoefFileName = COEF_FILE; // See fir.h
FILE * coefFile;
const char * FileName = INPUT_FILE; // See fir.h
FILE * inFile;
co_uint32 coefValue;
co_uint32 waveformValue;
int coefcount = 0;
coefFile = fopen(CoefFileName, "r");
if ( coefFile == NULL ) {
fprintf(stderr, "Error opening coefficients file %s\n", CoefFileName);
c = getc(stdin);
exit(-1);
}
// Read and write the coefficient data...
co_stream_open(waveform_raw, O_WRONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Sending coefficients...\n");
while (coefcount < TAPS) {
if (fscanf(coefFile,"%d",&coefValue) < 1)
{
break;
}
coefcount++;
co_stream_write(waveform_raw, &coefValue, sizeof(co_uint32));
cosim_logwindow_fwrite(log, "Coefficient: %x\n", coefValue);
}
cosim_logwindow_fwrite(log, "Finished writing %d coefficients.\n", coefcount);
fclose(coefFile);
inFile = fopen(FileName, "r");
if ( inFile == NULL ) {
fprintf(stderr, "Error opening waveform file %s\n", FileName);
c = getc(stdin);
exit(-1);
}
// Now read and write the waveform data...
co_stream_open(waveform_raw, O_WRONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Sending waveform...\n");
while (1) {
if (fscanf(inFile,"%d",&waveformValue) < 1)
{
break;
}
co_stream_write(waveform_raw, &waveformValue, sizeof(co_uint32));
cosim_logwindow_fwrite(log, "Value: %x\n", waveformValue);
}
cosim_logwindow_write(log, "Finished writing waveform.\n");
co_stream_close(waveform_raw);
fclose(inFile);
}
void test_consumer(co_stream waveform_filtered)
{
co_uint32 waveformValue;
unsigned int waveformCount = 0;
const char * FileName = OUTPUT_FILE; // See fir.h
FILE * outFile;
cosim_logwindow log = cosim_logwindow_create("test_consumer");
outFile = fopen(FileName, "w");
if ( outFile == NULL ) {
fprintf(stderr, "Error opening waveform file %s for writing\n", FileName);
exit(-1);
}
co_stream_open(waveform_filtered, O_RDONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Consumer reading data...\n");
while ( co_stream_read(waveform_filtered, &waveformValue, sizeof(co_uint32)) == co_err_none ) {
fprintf(outFile, "%d\n", waveformValue);
cosim_logwindow_fwrite(log, "Value: %x\n", waveformValue);
printf("Filtered value: %x\n", waveformValue);
waveformCount++;
}
cosim_logwindow_fwrite(log, "Consumer read %d waveform datapoints...\n", waveformCount);
co_stream_close(waveform_filtered);
fclose(outFile);
}
int main(int argc, char *argv[])
{
co_architecture my_arch;
void *param = NULL;
int c;
printf("Impulse C is Copyright 2003 Impulse Accelerated Technologies, Inc.\n");
my_arch = co_initialize(param);
co_execute(my_arch);
printf("\n\nApplication complete. Press the Enter key to continue.\n");
c = getc(stdin);
return(0);
}
// Fir filter example.
//
// Written for Generic Platform Support Package.
//
// Copyright© 2003-2005 Impulse Accelerated Technologies, Inc.
//
// fir_sw.c: includes the software test bench processes and
// main() function.
//
#ifdef WIN32
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#else // ! WIN32
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#endif
#include <stdio.h>
#include "co.h"
#include "co_math.h"
#include "cosim_log.h"
#include "fir.h"
#define HARDWARE_FIXED
extern co_architecture co_initialize(void *);
void test_producer(co_stream waveform_raw)
{
int c;
cosim_logwindow log = cosim_logwindow_create("test_producer");
// Read waveform and coefficients from a file
const char * CoefFileName = COEF_FILE; // See fir.h
FILE * coefFile;
const char * FileName = INPUT_FILE; // See fir.h
FILE * inFile;
co_uint32 coefValue;
co_uint32 waveformValue;
int coefcount = 0;
coefFile = fopen(CoefFileName, "r");
if ( coefFile == NULL ) {
fprintf(stderr, "Error opening coefficients file %s\n", CoefFileName);
c = getc(stdin);
exit(-1);
}
// Read and write the coefficient data...
co_stream_open(waveform_raw, O_WRONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Sending coefficients...\n");
while (coefcount < TAPS) {
if (fscanf(coefFile,"%d",&coefValue) < 1)
{
break;
}
coefcount++;
co_stream_write(waveform_raw, &coefValue, sizeof(co_uint32));
cosim_logwindow_fwrite(log, "Coefficient: %x\n", coefValue);
}
cosim_logwindow_fwrite(log, "Finished writing %d coefficients.\n", coefcount);
fclose(coefFile);
inFile = fopen(FileName, "r");
if ( inFile == NULL ) {
fprintf(stderr, "Error opening waveform file %s\n", FileName);
c = getc(stdin);
exit(-1);
}
// Now read and write the waveform data...
co_stream_open(waveform_raw, O_WRONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Sending waveform...\n");
while (1) {
if (fscanf(inFile,"%d",&waveformValue) < 1)
{
break;
}
co_stream_write(waveform_raw, &waveformValue, sizeof(co_uint32));
cosim_logwindow_fwrite(log, "Value: %x\n", waveformValue);
}
cosim_logwindow_write(log, "Finished writing waveform.\n");
co_stream_close(waveform_raw);
fclose(inFile);
}
void test_consumer(co_stream waveform_filtered)
{
co_uint32 waveformValue;
unsigned int waveformCount = 0;
const char * FileName = OUTPUT_FILE; // See fir.h
FILE * outFile;
cosim_logwindow log = cosim_logwindow_create("test_consumer");
outFile = fopen(FileName, "w");
if ( outFile == NULL ) {
fprintf(stderr, "Error opening waveform file %s for writing\n", FileName);
exit(-1);
}
co_stream_open(waveform_filtered, O_RDONLY, UINT_TYPE(32));
cosim_logwindow_write(log, "Consumer reading data...\n");
while ( co_stream_read(waveform_filtered, &waveformValue, sizeof(co_uint32)) == co_err_none ) {
fprintf(outFile, "%d\n", waveformValue);
cosim_logwindow_fwrite(log, "Value: %x\n", waveformValue);
printf("Filtered value: %x\n", waveformValue);
waveformCount++;
}
cosim_logwindow_fwrite(log, "Consumer read %d waveform datapoints...\n", waveformCount);
co_stream_close(waveform_filtered);
fclose(outFile);
}
int main(int argc, char *argv[])
{
co_architecture my_arch;
void *param = NULL;
int c;
printf("Impulse C is Copyright 2003 Impulse Accelerated Technologies, Inc.\n");
my_arch = co_initialize(param);
co_execute(my_arch);
printf("\n\nApplication complete. Press the Enter key to continue.\n");
c = getc(stdin);
return(0);
}
is this correct?
i have modified coefficients.dat with values like 0x000000ff, I only get the first '0'
thanks














