Jump to content


New to impulse C. How to do a basic image processor


  • You cannot reply to this topic
6 replies to this topic

#1 rlbond86

    Member

  • Members
  • PipPip
  • 7 posts

Posted 29 June 2009 - 10:37 AM

Hi,

I have read the impulse C tutorials, I sort of understand the information but I am having a bit of trouble figuring out how to actually program. I've used Verilog before, but I'm not that great at it.

So, as a simple test, I wanted to make a simple program in impulse C to run on my FPGA. Basically, I want to send it a black and white image and have the FPGA invert the image.

So I think the code is something like


CODE
#define PIPELINE_SIZE 16
void invert(co_stream image_in, co_stream image_out)
{
    uint8 pixel[PIPELINE_SIZE];
    uint8 cur_pixel;
    int i;
    do
    {
        co_stream_open(image_in, O_RDONLY, INT_TYPE(8));
        co_stream_open(image_out, O_WRONLY, INT_TYPE(8));

        for (i = 0; i < PIPELINE_SIZE; ++i)
        {
#pragma CO UNROLL
            co_stream_read(image_in, &cur_pixel, sizeof(uint8));
            pixel[i] = 0xFF - cur_pixel;
        }

        for (i = 0; i < PIPELINE_SIZE; ++i)
        {
#pragma CO UNROLL
            co_stream_write(image_in, pixel[i], sizeof(uint8));
        }

        co_stream_close(image_in);
        co_stream_close(image_out);
    } while(1);
}



But I'm not sure if this is correct or the best way to do it. I also don't know how to tell the function that the data is "done".

Also, how do I actually test this by sending data from my PC to the FPGA?

Thank you for your help!

#2 RalphBodenner

    Advanced Member

  • Admin
  • PipPipPip
  • 348 posts

Posted 30 June 2009 - 05:42 PM

This looks good. Do you have some software processes to test the code, by sending and receiving pixel data? CoDeveloper ships with several projects that read/write BMP-format image files for testing such filters, for example EdgeDetect5X5.

How you get data to/from the FPGA depends on the FPGA platform you're using. What kind of board do you have?

Regards,
Ralph
Ralph Bodenner
Impulse Accelerated Technologies, Inc.

#3 rlbond86

    Member

  • Members
  • PipPip
  • 7 posts

Posted 06 July 2009 - 10:35 AM

QUOTE (RalphBodenner @ Jun 30 2009, 09:42 PM) <{POST_SNAPBACK}>
This looks good. Do you have some software processes to test the code, by sending and receiving pixel data? CoDeveloper ships with several projects that read/write BMP-format image files for testing such filters, for example EdgeDetect5X5.

How you get data to/from the FPGA depends on the FPGA platform you're using. What kind of board do you have?

Regards,
Ralph


Hi Ralph,

I have a Pico E-14. I think I read there's a C library for sending data to the FPGA?

Thanks,

Ross

#4 rlbond86

    Member

  • Members
  • PipPip
  • 7 posts

Posted 06 July 2009 - 11:30 AM

Ok so I tried the template to do this project. The code it generated is as follows:

CODE
///////////////////////////////////////////////////////////////////////////////
//
// Generated by Impulse CoDeveloper
// Impulse C is Copyright(c) 2003-2007 Impulse Accelerated Technologies, Inc.
//
// invert_hw.c: includes the hardware process and configuration
// function.
//
// See additional comments in invert.h.
//

#include "co.h"
#include "cosim_log.h"
#include "invert.h"

// Software process declarations (see invert_sw.c)
extern void Producer(co_stream invIn);
extern void Consumer(co_stream invOut);

//
// This is the hardware process.
//
void inverter(co_stream invIn, co_stream invOut)
{
    co_uint1 nSample;
    IF_SIM(int samplesread; int sampleswritten;)
    
    IF_SIM(cosim_logwindow log;)
    IF_SIM(log = cosim_logwindow_create("inverter");)
    
    do {    // Hardware processes run forever
        IF_SIM(samplesread=0; sampleswritten=0;)
    
        co_stream_open(invIn, O_RDONLY, UINT_TYPE(STREAMWIDTH));
        co_stream_open(invOut, O_WRONLY, UINT_TYPE(STREAMWIDTH));
    
        // Read values from the stream
        while ( co_stream_read(invIn, &nSample, sizeof(co_uint1)) == co_err_none ) {
        #pragma CO PIPELINE
            IF_SIM(samplesread++;)
    
            // Sample is now in variable nSample.
            // Add your processing code here.
            nSample = 0xFF - nSample;
    
            co_stream_write(invOut, &nSample, sizeof(co_uint1));
            IF_SIM(sampleswritten++;)
        }
        co_stream_close(invIn);
        co_stream_close(invOut);
        IF_SIM(cosim_logwindow_fwrite(log,
            "Closing filter process, samples read: %d, samples written: %d\n",
            samplesread, sampleswritten);)
    
        IF_SIM(break;)    // Only run once for desktop simulation
    } while(1);
}

//
// Impulse C configuration function
//
void config_invert(void *arg)
{
    co_stream invIn;
    co_stream invOut;
    
    co_process inverter_process;
    co_process producer_process;
    co_process consumer_process;

    IF_SIM(cosim_logwindow_init();)
    
    invIn = co_stream_create("invIn", INT_TYPE(STREAMWIDTH), STREAMDEPTH);
    invOut = co_stream_create("invOut", INT_TYPE(STREAMWIDTH), STREAMDEPTH);
    
    producer_process = co_process_create("Producer", (co_function)Producer,
                                         1,
                                         invIn);
    
    inverter_process = co_process_create("inverter", (co_function)inverter,
                                    2,
                                    invIn,
                                    invOut);
    
    consumer_process = co_process_create("Consumer",(co_function)Consumer,
                                         1,
                                         invOut);
    
    co_process_config(inverter_process, co_loc, "pe0");  
}

co_architecture co_initialize(int param)
{
    return(co_architecture_create("invert_arch","Generic",config_invert,(void *)param));
}


I put some data in filter_in.dat and tried to run the simulation, but it doesn't seem to work. Am I doing something wrong?

#5 RalphBodenner

    Advanced Member

  • Admin
  • PipPipPip
  • 348 posts

Posted 06 July 2009 - 02:16 PM

In what way does the simulation not work? Do you see an error message at compile time? At run time? Have you tried to use a debugger on the simulation program?

There is a Pico API for moving data on the host to/from the FPGA. Look at a Ready To Run example for the Pico E-16 platform, which uses the same host library as the E-14:

http://www.impulseaccelerated.com/ReadyToR...er_Pico_E16.zip

Ralph
Ralph Bodenner
Impulse Accelerated Technologies, Inc.

#6 rlbond86

    Member

  • Members
  • PipPip
  • 7 posts

Posted 07 July 2009 - 11:12 AM

QUOTE (RalphBodenner @ Jul 6 2009, 06:16 PM) <{POST_SNAPBACK}>
In what way does the simulation not work? Do you see an error message at compile time? At run time? Have you tried to use a debugger on the simulation program?

There is a Pico API for moving data on the host to/from the FPGA. Look at a Ready To Run example for the Pico E-16 platform, which uses the same host library as the E-14:

http://www.impulseaccelerated.com/ReadyToR...er_Pico_E16.zip

Ralph


When the Stage Master Debugger pops up, invIn says (1/16) on it, and invOut says (0/16). After a few presses of the step button, both are at (0/16). When I press stop, I get the message "The instruction at "0x006cbfc6" referenced memory at "0x0000000c". The memory could not be "read"."
Is there another debugging utility? Am I doing this wrong?

When I run invert.exe from the command line, I get the message "ERROR: Stream "invIn" must be created and opened with the same data type"

Thanks,

Ross

#7 RalphBodenner

    Advanced Member

  • Admin
  • PipPipPip
  • 348 posts

Posted 08 July 2009 - 01:13 PM

QUOTE
ERROR: Stream "invIn" must be created and opened with the same data type


There's your problem right there. Make sure the same datatype is used in all calls to co_stream_open and co_stream_create for the "invIn" stream.

Ralph
Ralph Bodenner
Impulse Accelerated Technologies, Inc.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users