⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mult_hw.c

📁 用impulse c编写的18x18位的乘法器。
💻 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.
//
// Note: for Version 1, co_int36 is aliased as co_int64.
// 
// Copyright(c) 2003-2005 Impulse Accelerated Technologies, Inc.
// 

#include <stdio.h>
#include "co.h"
#include "cosim_log.h"
#include "mult.h"

extern void test_producer(co_stream Operand, co_stream Result);

//////////////////////////////////////////////////
// This is the mult filter hardware process.
// The process accepts a stream of 18-bit arguments,
// reads them two at a time and produces a 36-bit
// result.
//
void mult(co_stream Operand, co_stream Result)
{
	co_int18 nA;
	co_int18 nB;
	co_int36 nResult;

	IF_SIM( cosim_logwindow log; )
	IF_SIM ( log = cosim_logwindow_create("mult"); )

    do {	// Hardware processes run forever

		co_stream_open(Operand, O_RDONLY, INT_TYPE(18));
		co_stream_open(Result, O_WRONLY, INT_TYPE(36));

		// Read values from the stream
		while ( co_stream_read(Operand, &nA, sizeof(co_int18)) == co_err_none ) {
#pragma CO PIPELINE
			if (co_stream_read(Operand, &nB, sizeof(co_int18)) != co_err_none)
				break;
			nResult = (co_int36) nA * (co_int36) nB;
			co_stream_write(Result, &nResult, sizeof(co_int36));
			IF_SIM(cosim_logwindow_fwrite(log, "A=%ld, B=%ld, Result=%ld\n", nA, nB, nResult);)
		}

		co_stream_close(Operand);
		co_stream_close(Result);

		IF_SIM(break;)	// Only run once for desktop simulation

	} while(1);
}

//
// Impulse C configuration function
//
void config_mult(void *arg)
{
	co_stream Operand;
	co_stream Result;

	co_process producer_process;
	co_process mult_process;

	IF_SIM(cosim_logwindow_init();)

	Operand = co_stream_create("Operand", INT_TYPE(18), BUFSIZE);
	Result = co_stream_create("Result", INT_TYPE(36), BUFSIZE);

	producer_process = co_process_create("producer_process", (co_function)test_producer,
                                         2, Operand, Result);

	mult_process = co_process_create("mult_process", (co_function)mult,
                                     2, Operand, Result);


	// Assign processes to hardware elements
	co_process_config(mult_process, co_loc, "PE0");  
}

co_architecture co_initialize(int param)
{
	return(co_architecture_create("mult_arch","Generic_VHDL",config_mult,(void *)param));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -