دارای help قوی هست ، توی راهنماش یه قسمت به نام Impulse C Application Programming Interface (API) داره که در اون کلیه دستورات زبان c رو توضیح داده ( دستورات مخصوص fpga )
کد:
// ////////////////////////////////////////////////////////////////
// 3X3 kernel image fliter example. This test bench reads grayscale
// images from a BMP file. This means that the data is only 8-bit,
// although we are testing a 16-bit fliter. This test bench should
// probably read/write PICT files instead.
//
// Copyright(c) 2003-2006 Impulse Accelerated Technologies, Inc.
//
// img_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>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "co.h"
#include "co_math.h"
#include "cosim_log.h"
#include "img.h"
#include "bmp.h"
BITMAPFILEHEADER header; /* Bitmap header */
BITMAPINFO info; /* Bitmap information */
unsigned int infosize;
extern co_architecture co_initialize(void *);
void producer(co_stream pixels_raw, co_signal header_ready)
{
unsigned int i, i1, j;
cosim_logwindow log = cosim_logwindow_create("producer");
// Read bitmap from a BMP format file
const char * FileName = INPUT_FILE; // See .h
FILE * infile;
unsigned char *pBitMap;
unsigned int PixelCount;
unsigned int ByteCount;
co_uint16 pixelValue;
infile = fopen(FileName, "rb");
if ( infile == NULL ) {
fprintf(stderr, "Error opening BMP file %s\n", FileName);
exit(-1);
}
// Read the file header and info sections...
if (fread(&header, sizeof(BITMAPFILEHEADER), 1, infile) < 1)
{
fclose(infile);
fprintf(stderr, "Error reading BMP header for %s\n", FileName);
exit(-1);
}
if (header.bfType != 0x4d42) /* Check for BM magic number */
{
fclose(infile);
fprintf(stderr, "File %s does not appear to be a BMP file.\n", FileName);
exit(-1);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
if (fread(&info, 1, infosize, infile) < infosize)
{
fclose(infile);
fprintf(stderr, "Coudn't read the bitmap info for %s.\n", FileName);
exit(-1);
}
if (info.bmiHeader.biWidth != WIDTH ||
info.bmiHeader.biHeight != HEIGHT)
{
fclose(infile);
fprintf(stderr, "Bitmap must be %dW X %dH.\n", WIDTH, HEIGHT);
exit(-1);
}
// Tell the consumer that we've finished reading the header...
co_signal_post(header_ready,1);
// Now read the pixel data from the file...
PixelCount = WIDTH * HEIGHT;
ByteCount = header.bfSize - header.bfOffBits;
pBitMap = (unsigned char *) malloc(sizeof(unsigned char) * ByteCount);
if (fread(pBitMap, 1, ByteCount, infile) < ByteCount)
{
fclose(infile);
fprintf(stderr, "Coudn't read the pixel data for %s.\n", FileName);
exit(-1);
}
// Send the pixel data as 16-bit values to the Impulse C hardware process
co_stream_open(pixels_raw, O_WRONLY, UINT_TYPE(16));
cosim_logwindow_write(log, "Sending BMP pixels...\n");
// First send in an extra scan line (duplicate the first line)...
for (i=0, j=0; j < WIDTH; j++) {
pixelValue = (pBitMap[i++]);
co_stream_write(pixels_raw, &pixelValue, sizeof(pixelValue));
}
// Now send in all the pixels for the image
printf("Sending BMP pixels...\n");
for (i=0; i < ByteCount;) {
pixelValue = (pBitMap[i++]);
co_stream_write(pixels_raw, &pixelValue, sizeof(pixelValue));
}
// Now send in two more extra scan lines (duplicating the last line)...
for (i1=0; i1<2;i1++) {
i -= WIDTH;
for (j=0; j < WIDTH; j++) {
pixelValue = (pBitMap[i++]);
co_stream_write(pixels_raw, &pixelValue, sizeof(pixelValue));
}
}
cosim_logwindow_write(log, "Finished writing BMP pixels\n");
printf("Finished writing BMP pixels\n");
co_stream_close(pixels_raw);
fclose(infile);
}
void consumer(co_stream pixels_filtered, co_signal header_ready)
{
co_uint16 pixelValue;
co_int32 signaldata;
unsigned int pixelCount = 0;
const char * FileName = OUTPUT_FILE; // See img.h
FILE * outfile;
cosim_logwindow log = cosim_logwindow_create("consumer");
co_signal_wait(header_ready, &signaldata);
outfile = fopen(FileName, "wb");
if ( outfile == NULL ) {
fprintf(stderr, "Error opening BMP file %s for writing\n", FileName);
exit(-1);
}
// Read the file header and info sections...
if (fwrite(&header, 1, sizeof(BITMAPFILEHEADER), outfile) < 1)
{
fclose(outfile);
fprintf(stderr, "Error writing BMP header for %s\n", FileName);
exit(-1);
}
if (fwrite(&info, 1, infosize, outfile) < 1)
{
fclose(outfile);
fprintf(stderr, "Error writing BMP info for %s\n", FileName);
exit(-1);
}
co_stream_open(pixels_filtered, O_RDONLY, UINT_TYPE(16));
cosim_logwindow_write(log, "Consumer reading data...\n");
printf("Consumer reading data...\n");
while ( co_stream_read(pixels_filtered, &pixelValue, sizeof(co_uint16)) == co_err_none ) {
putc(pixelValue, outfile);
pixelCount++;
}
// Fill out any missing pixels
while (pixelCount < WIDTH*HEIGHT) {
putc(0, outfile);
pixelCount++;
}
cosim_logwindow_fwrite(log, "Consumer read %d pixels...\n", pixelCount);
printf("Consumer read %d pixels...\n", pixelCount);
co_stream_close(pixels_filtered);
fclose(outfile);
}
int main(int argc, char *argv[])
{
co_architecture my_arch;
void *param = NULL;
int c;
printf("Impulse C is Copyright 2003-2006 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);
}