?? mult_sw.c
字號:
//////////////////////////////////////////////////////////////////
// Multiplier example. Demonstrates how to write a multiply that
// will result in an 18X18 multiplier macro being properly
// instantiated. Generates a 36-bit result.
//
// Copyright(c) 2003-2005 Impulse Accelerated Technologies, Inc.
//
// mult_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 "co.h"
#include "co_math.h"
#include "cosim_log.h"
#include "mult.h"
extern co_architecture co_initialize(void *);
void test_producer(co_stream Operand, co_stream Result)
{
int c;
cosim_logwindow log = cosim_logwindow_create("test_producer");
// Operands from a file
const char * FileName = INPUT_FILE; // See mult.h
FILE * inFile;
co_int18 nValue;
co_int36 nResult;
inFile = fopen(FileName, "r");
if ( inFile == NULL ) {
fprintf(stderr, "Error opening operands file %s\n", FileName);
c = getc(stdin);
exit(-1);
}
// Now read the data...
co_stream_open(Operand, O_WRONLY, INT_TYPE(18));
co_stream_open(Result, O_RDONLY, INT_TYPE(36));
cosim_logwindow_write(log, "Sending Operands...\n");
while (1) {
if (fscanf(inFile,"%d",&nValue) < 1)
break;
co_stream_write(Operand, &nValue, sizeof(co_int18));
cosim_logwindow_fwrite(log, "Value A: %d\n", nValue);
printf("Value A: %d\n", nValue);
if (fscanf(inFile,"%d",&nValue) < 1)
break;
co_stream_write(Operand, &nValue, sizeof(co_int18));
cosim_logwindow_fwrite(log, "Value B: %d\n", nValue);
printf("Value B: %d\n", nValue);
if (co_stream_read_nb(Result, &nResult, sizeof(co_int36))) {
cosim_logwindow_fwrite(log, "Result : %ld\n", nResult);
printf("Result : %d\n", nResult);
}
}
while (co_stream_read(Result, &nResult, sizeof(co_int36)) == co_err_none) {
cosim_logwindow_fwrite(log, "Result : %ld\n", nResult);
printf("Result : %d\n", nResult);
}
co_stream_close(Operand);
co_stream_close(Result);
fclose(inFile);
}
int main(int argc, char *argv[])
{
co_architecture my_arch;
void *param = NULL;
int c;
printf("Impulse C is Copyright 2003-2005 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);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -