提交 e10b7c82 编写于 作者: 饶先宏's avatar 饶先宏

202107100849

上级 4921f1ad
......@@ -67,6 +67,11 @@ typedef struct sIBigNumber {
int (*GetUint32)(HOBJECT object, unsigned int* pvalue);
int (*GetUint64)(HOBJECT object, unsigned long long* pvalue);
int (*ReadInt32)(HOBJECT object);
long long (*ReadInt64)(HOBJECT object);
unsigned int (*ReadUint32)(HOBJECT object);
unsigned long long (*ReadUint64)(HOBJECT object);
int (*GetStr)(HOBJECT object, int base, char * str, int buflen);
int (*AssignInt32)(HOBJECT object, int value);
......@@ -155,6 +160,10 @@ typedef struct sIBigNumber {
static int _obj##_bn_GetInt64(HOBJECT object, long long* pvalue); \
static int _obj##_bn_GetUint32(HOBJECT object, unsigned int* pvalue); \
static int _obj##_bn_GetUint64(HOBJECT object, unsigned long long* pvalue); \
static int _obj##_bn_ReadInt32(HOBJECT object); \
static long long _obj##_bn_ReadInt64(HOBJECT object); \
static unsigned int _obj##_bn_ReadUint32(HOBJECT object); \
static unsigned long long _obj##_bn_ReadUint64(HOBJECT object); \
static int _obj##_bn_GetStr(HOBJECT object, int base, char* str, int buflen); \
static int _obj##_bn_AssignInt32(HOBJECT object, int value); \
static int _obj##_bn_AssignInt64(HOBJECT object, long long value); \
......
......@@ -325,6 +325,34 @@ static int bigint_bn_GetUint64(HOBJECT object, unsigned long long* pvalue)
return 0;
}
static int bigint_bn_ReadInt32(HOBJECT object)
{
int ret;
bigint_bn_GetInt32(object, &ret);
return ret;
}
static long long bigint_bn_ReadInt64(HOBJECT object)
{
long long ret;
bigint_bn_GetInt64(object, &ret);
return ret;
}
static unsigned int bigint_bn_ReadUint32(HOBJECT object)
{
unsigned int ret;
bigint_bn_GetUint32(object, &ret);
return ret;
}
static unsigned long long bigint_bn_ReadUint64(HOBJECT object)
{
unsigned long long ret;
bigint_bn_GetUint64(object, &ret);
return ret;
}
static int bigint_bn_GetStr2(sBigInteger* pobj, char* str, int buflen)
{
int i;
......
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* terris_blockwrite.c
修改记录:
202106221411: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "object.h"
#include "dlist.h"
#include "bignumber.h"
#include "hdl4secell.h"
#include "hdl4se_macros.h"
#include "terris.h"
#define MODULE_VERSION_STRING "0.3.0-20210622.1411 Terris BlockWrite module"
#define MODULE_NAME terris_block_write
#define MODULE_CLSID CLSID_TERRIS_BLOCKWRITE
#define PORT_COUNT 10
H4S_PORT(terris_block_write)
H4S_IN (0, wClk, 1)
H4S_IN (1, bCtrlState, 4)
H4S_OUT(2, wCtrlStateComplete, 1)
H4S_OUT(3, bBWReadAddr, 6)
H4S_IN (4, bBWReadData, 64)
H4S_OUT(5, wBWWrite, 1)
H4S_OUT(6, bBWWriteAddr, 6)
H4S_OUT(7, bBWWriteData, 64)
H4S_IN (8, bCurBlock, 64)
H4S_IN (9, bCurBlockPos, 16)
H4S_END_PORT
#if 0
MODULE_DECLARE
typedef struct _sTerrisBlockWrite {
OBJECT_HEADER
INTERFACE_DECLARE(IHDL4SEUnit)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule** parent;
char* name;
sc_signal <bool> *a, *b, *s, *c;
half_adder1 *padder;
IBigNumber** inputdata;
IHDL4SEUnit** input_unit[INPUTPORTCOUNT];
int input_index[INPUTPORTCOUNT];
unsigned int index;
unsigned int readindex; /* 模拟读地址寄存器,比index晚一拍 */
unsigned int readindex_1;
}sTerrisBlockWrite;
OBJECT_FUNCDECLARE(terris_blockwrite, CLSID_TERRIS_BLOCKWRITE);
HDL4SEUNIT_FUNCDECLARE(terris_blockwrite, CLSID_TERRIS_BLOCKWRITE, sTerrisBlockWrite);
DLIST_FUNCIMPL(terris_blockwrite, CLSID_TERRIS_BLOCKWRITE, sTerrisBlockWrite);
OBJECT_FUNCIMPL(terris_blockwrite, sTerrisBlockWrite, CLSID_TERRIS_BLOCKWRITE);
QUERYINTERFACE_BEGIN(terris_blockwrite, CLSID_TERRIS_BLOCKWRITE)
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sTerrisBlockWrite)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sTerrisBlockWrite)
QUERYINTERFACE_END
static const char* terris_blockwriteModuleInfo()
{
return "0.3.0-20210622.1411 Terris BlockWrite module";
}
static int terris_blockwriteCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject)
{
sTerrisBlockWrite* pobj;
int i;
pobj = (sTerrisBlockWrite*)malloc(sizeof(sTerrisBlockWrite));
if (pobj == NULL)
return -1;
*pObject = 0;
HDL4SEUNIT_VARINIT(pobj, CLSID_TERRIS_BLOCKWRITE);
INTERFACE_INIT(IHDL4SEUnit, pobj, terris_blockwrite, hdl4se_unit);
DLIST_VARINIT(pobj, terris_blockwrite);
pobj->name = NULL;
pobj->parent = NULL;
#if 1
pobj->padder = new half_adder1("adder_test1");
pobj->a = new sc_signal <bool>;
pobj->b = new sc_signal <bool>;
pobj->s = new sc_signal <bool>;
pobj->c = new sc_signal <bool>;
//pobj->padder->a(*pobj->a);
//pobj->padder->b(*pobj->b);
//pobj->padder->sum(*pobj->s);
//pobj->padder->carry(*pobj->c);
(*pobj->padder) << *pobj->a << *pobj->b << *pobj->s << *pobj->c;
#endif
for (i = 0;i< INPUTPORTCOUNT;i++)
pobj->input_unit[i] = NULL;
pobj->inputdata = bigintegerCreate(64);
pobj->index = 0;
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
free(pobj->name);
pobj->name = strdup((const char *)pParams[i].pvalue);
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) {
pobj->parent = (IHDL4SEModule **)pParams[i].pvalue;
}
}
/* 返回生成的对象 */
OBJECT_RETURN_GEN(terris_blockwrite, pobj, pObject, CLSID_TERRIS_BLOCKWRITE);
return EIID_OK;
}
static void terris_blockwriteDestroy(HOBJECT object)
{
sTerrisBlockWrite* pobj;
int i;
pobj = (sTerrisBlockWrite*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
for (i = 0; i < INPUTPORTCOUNT; i++)
objectRelease(pobj->input_unit[i]);
objectRelease(pobj->inputdata);
memset(pobj, 0, sizeof(sTerrisBlockWrite));
free(pobj);
}
static int terris_blockwriteValid(HOBJECT object)
{
sTerrisBlockWrite* pobj;
pobj = (sTerrisBlockWrite*)objectThis(object);
return 1;
}
static int terris_blockwrite_hdl4se_unit_GetName(HOBJECT object, const char** pname)
{
sTerrisBlockWrite* pobj;
pobj = (sTerrisBlockWrite*)objectThis(object);
*pname = pobj->name;
return 0;
}
static int terris_blockwrite_hdl4se_unit_ConnectInput(HOBJECT object, int index, HOBJECT from, int fromindex)
{
#define CONNECTPORT(ind, innerind) \
if (index == ind) { \
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (const void**)&unit)) { \
objectRelease(pobj->input_unit[innerind]); \
pobj->input_unit[innerind] = unit; \
pobj->input_index[innerind] = fromindex; \
} \
}
sTerrisBlockWrite* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sTerrisBlockWrite*)objectThis(object);
CONNECTPORT( 1, 0); /* bCtrlState */
CONNECTPORT( 4, 1); /* bBWReadData */
CONNECTPORT( 8, 2); /* bCurBlock */
CONNECTPORT( 9, 3); /* bCurBlockPos */
return 0;
}
static unsigned long long terris_blockwrite_hdl4se_unit_GetWriteData(sTerrisBlockWrite* pobj, int blockx, int blocky)
{
int i;
unsigned long long line, curblock, curblockline;
objectCall3(pobj->input_unit[1], GetValue, pobj->input_index[1], 64, pobj->inputdata);
objectCall1(pobj->inputdata, GetUint64, &line);
objectCall3(pobj->input_unit[2], GetValue, pobj->input_index[2], 64, pobj->inputdata);
objectCall1(pobj->inputdata, GetUint64, &curblock);
curblockline = (curblock >> ((3-pobj->readindex_1) * 16)) & 0xffff;
if (blockx < 3)
curblockline >>= ((3 - blockx) * 4);
else
curblockline <<= (blockx - 3) * 4;
return line | curblockline;
}
static int terris_blockwrite_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber ** value)
{
sTerrisBlockWrite* pobj;
pobj = (sTerrisBlockWrite*)objectThis(object);
unsigned int blockpos;
unsigned int blockx, blocky;
objectCall3(pobj->input_unit[3], GetValue, pobj->input_index[3], 16, pobj->inputdata);
objectCall1(pobj->inputdata, GetUint32, &blockpos);
blockx = blockpos & 0xff;
blocky = blockpos >> 8;
if (index == 2) { /* wCtrlStateComplete */
objectCall1(value, AssignUint32, (pobj->readindex_1 >= 4)?1:0);
}
else if (index == 3) {/* bBWReadAddr */
objectCall1(value, AssignUint32, pobj->readindex + blocky - 4);
}
else if (index == 5) {/* wBWWrite */
objectCall1(value, AssignUint32, ( (pobj->readindex > 0) && (pobj->readindex_1 >= 0) && (pobj->readindex_1 <= 3) ) ? 1 : 0);
}
else if (index == 6) {/* bBWWriteAddr */
objectCall1(value, AssignUint32, pobj->readindex_1 + blocky - 4);
}
else if (index == 7) {/* bBWWriteData */
objectCall1(value, AssignUint64, terris_blockwrite_hdl4se_unit_GetWriteData(pobj, blockx, blocky));
}
return 0;
}
static int terris_blockwrite_hdl4se_unit_ClkTick(HOBJECT object)
{
sTerrisBlockWrite* pobj;
pobj = (sTerrisBlockWrite*)objectThis(object);
unsigned int ctrlstate;
objectCall3(pobj->input_unit[0], GetValue, pobj->input_index[0], 32, pobj->inputdata);
objectCall1(pobj->inputdata, GetUint32, &ctrlstate);
if (ctrlstate == ST_BLOCKWRITE) {
pobj->index = pobj->readindex + 1;
}
else {
pobj->index = 0;
}
*pobj->a = rand() % 2;
*pobj->b = rand() % 2;
int a = pobj->a->read();
int b = pobj->b->read();
int s = pobj->s->read();
return 0;
}
static int terris_blockwrite_hdl4se_unit_Setup(HOBJECT object)
{
sTerrisBlockWrite* pobj;
pobj = (sTerrisBlockWrite*)objectThis(object);
pobj->readindex_1 = pobj->readindex;
pobj->readindex = pobj->index;
return 0;
}
#endif
\ No newline at end of file
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* hdl4se_macros.h
修改记录:
202107072033: rxh, initial version
*/
#ifndef __HDL4SE_MACROS_H
#define __HDL4SE_MACROS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ASMLANGUAGE
enum port_direct {
PORT_INPUT,
PORT_OUTPUT,
PORT_INOUT
};
typedef struct sModulePortInfo {
int index;
int portdirect;
const char* name;
int width;
int isunsigned;
}ModulePortInfo;
#define H4S_PORT(module_name) static const ModulePortInfo module_name##_port_info_list[PORT_COUNT] = {
#define H4S_IN(index, name, width) {index, PORT_INPUT, #name, width, 1},
#define H4S_OUT(index, name, width) {index, PORT_INPUT, #name, width, 1},
#define H4S_END_PORT };
typedef struct sHDL4SEREG {
int width;
IBigNumber ** vin;
IBigNumber ** vout;
}HDL4SEREG;
#define HDL_REG_DECL(name) HDL4SEREG __reg_##name;
#define HDL_REG_INIT(name, width) \
pobj->__reg_##name.r.vin = bignumberCreate(width); \
pobj->__reg_##name.r.vout = bignumberCreate(width);
#define REG_GET_UINT32(r, v) (objectCall1(pobj->__reg_##r.vout, GetUint32, ((unsigned int)&(v)))
#define REG_SET_UINT32(r, v) (objectCall1(pobj->__reg_##r.vin, AssignUint32, (v))
#define REG_GET_UINT64(r, v) (objectCall1(pobj->__reg_##r.vout, GetUint64, ((unsigned long long)&(v)))
#define REG_SET_UINT64(r, v) (objectCall1(pobj->__reg_##r.vin, AssignUint64, (v))
#define REG_SETUP(r) objectCall1(pobj->__reg_##r.vout, Assign, pobj->__reg_##r.vin)
#define REG_KEEP(r) objectCall1(pobj->__reg_##r.vin, Assign, pobj->__reg_##r.vout)
#define MODULE_DECLARE \
typedef struct _sHDL4SE_##MODULE_NAME{ \
OBJECT_HEADER \
INTERFACE_DECLARE(IHDL4SEUnit) \
HDL4SEUNIT_VARDECLARE \
DLIST_VARDECLARE \
\
IHDL4SEModule * *parent; \
char* name; \
int datavalid; \
\
IBigNumber** __data[PORT_COUNT];\
IHDL4SEUnit** input_unit[PORT_COUNT]; \
int input_index[PORT_COUNT]; \
#define END_DECLARE }_sHDL4SE_##MODULE_NAME; \
\
OBJECT_FUNCDECLARE(MODULE_NAME, MODULE_CLSID); \
HDL4SEUNIT_FUNCDECLARE(MODULE_NAME, MODULE_CLSID, _sHDL4SE_##MODULE_NAME); \
DLIST_FUNCIMPL(MODULE_NAME, clsid, _sHDL4SE_##MODULE_NAME); \
\
OBJECT_FUNCIMPL(MODULE_NAME, _sHDL4SE_##MODULE_NAME, MODULE_CLSID); \
\
QUERYINTERFACE_BEGIN(MODULE_NAME, MODULE_CLSID) \
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, _sHDL4SE_##MODULE_NAME) \
QUERYINTERFACE_ITEM(IID_DLIST, IDList, _sHDL4SE_##MODULE_NAME) \
QUERYINTERFACE_END \
\
static const char* MODULE_NAME##ModuleInfo() \
{ \
return MODULE_VERSION_STRING; \
} \
#define MODULE_INIT \
static int MODULE_NAME##Create(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject) \
{ \
_sHDL4SE_##name* pobj; \
int i; \
pobj = (_sHDL4SE_##name*)malloc(sizeof(_sHDL4SE_##name)); \
if (pobj == NULL) \
return -1; \
*pObject = 0; \
HDL4SEUNIT_VARINIT(pobj, clsid); \
INTERFACE_INIT(IHDL4SEUnit, pobj, name, hdl4se_unit); \
DLIST_VARINIT(pobj, name); \
\
for (i = 0; i < PORTCOUNT; i++) \
pobj->input_unit[i] = NULL; \
pobj->inputdata = bigintegerCreate(64); \
pobj->name = NULL; \
pobj->parent = NULL; \
pobj->datavalid = 0; \
#define PARAM_INIT \
{ \
for (i = 0; i < paramcount; i++) { \
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) { \
if (pobj->name != NULL) \
free(pobj->name); \
pobj->name = strdup(pParams[i].pvalue); \
} \
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) { \
pobj->parent = (IHDL4SEModule**)pParams[i].pvalue; \
} \
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) {
#define PARAM_ITEM pParams[i]
#define END_PARAM_INIT \
} \
} \
}
#define END_MODULE_INIT \
OBJECT_RETURN_GEN(MODULE_NAME, pobj, pObject, MODULE_CLSID); \
return EIID_OK; \
} \
#if 0
static void cnncell_coeffbufDestroy(HOBJECT object) \
{ \
sCNNCellCoeffBuf* pobj;
int i;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
for (i = 0; i < INPUTPORTCOUNT; i++)
objectRelease(pobj->input_unit[i]);
objectRelease(pobj->inputdata);
if (pobj->pCoeffFile != NULL)
fclose(pobj->pCoeffFile);
memset(pobj, 0, sizeof(sCNNCellCoeffBuf));
free(pobj);
}
static int cnncell_coeffbufValid(HOBJECT object)
{
sCNNCellCoeffBuf* pobj;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
if (pobj->pCoeffFile == NULL)
return 0;
return 1;
}
static int cnncell_coeffbuf_hdl4se_unit_GetName(HOBJECT object, const char** pname)
{
sCNNCellCoeffBuf* pobj;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
*pname = pobj->name;
return 0;
}
static int cnncell_coeffbuf_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex)
{
#define CONNECTPORT(ind, innerind) \
if (index == ind) { \
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { \
objectRelease(pobj->input_unit[innerind]); \
pobj->input_unit[innerind] = unit; \
pobj->input_index[innerind] = fromindex; \
} \
}
sCNNCellCoeffBuf* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
CONNECTPORT(1, 0); /* nwReset */
CONNECTPORT(2, 1); /* wCoeffRead */
CONNECTPORT(4, 2); /* bCoeffReadAddr */
return 0;
}
MODULE(cnncell_coeffbuf, CLSID_CNN_COEFFBUF)
MODULE_PARAM
HDL_STRING_PARAM(filename, "");
END_PARAM
MODULE_PORT
HDL_IN(wClk, 1);
HDL_IN(nwReset, 1);
HDL_IN(wCoeffRead, 1);
HDL_OUT(wCoeffReadValid, 1);
HDL_IN(bCoeffReadAddr, 32);
HDL_OUT(bCoeffReadData, 32);
END_PORT
MODULE_VARIABLE
HDL_REG(readcmd, 1);
HDL_REG(read_addr, 32);
HDL_INT(tt, 32);
HDL_UINT(utt, 58);
FILE * pFile;
END_VARIABLE
DEFINE_SUBMODULE
END_SUBMODULE
pFile = fopen(GET_PARAM(filename), "r");
if (pFile == NULL) {
HDL_RETURN(-1);
}
ENDMODULE
ON_DESTROY
if (OBJ(pFile) != NULL) {
fclose(OBJ(pFile));
OBJ(pFile) = NULL;
}
END_DESTROY
GENERATE_OUTPUT
END_GENERATE_OUTPUT
ON_CLOCK
END_ON_CLOCK
*/
#ifdef WIN32
#define DATADIR "d:/gitwork/hdl4se/examples/hdl4secnn/googlenet/model-data"
#else
#define DATADIR "/media/raoxianhong/_dde_data/gitwork/hdl4se/examples/hdl4secnn/googlenet/model-data"
#endif
/* wClk不算 */
#define INPUTPORTCOUNT 3
static int cnncell_coeffbuf_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber** value)
{
sCNNCellCoeffBuf* pobj;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
if (pobj->read_reg) {
if (fseek(pobj->pCoeffFile, pobj->read_addr_reg, SEEK_SET) == 0) {
if (index == 3) {
if (width <= 0) {
objectCall1(value, SetUnsigned, 1);
objectCall1(value, SetWidth, 1);
}
objectCall1(value, AssignInt32, 1);
}
else if (index == 5) {
unsigned int v;
fread(&v, 4, 1, pobj->pCoeffFile);
if (width <= 0) {
objectCall1(value, SetUnsigned, 1);
objectCall1(value, SetWidth, 32);
}
objectCall1(value, AssignUint32, v);
}
return 0;
}
}
if (index == 3) {
if (width <= 0) {
objectCall1(value, SetUnsigned, 1);
objectCall1(value, SetWidth, 1);
}
objectCall1(value, AssignInt32, 0);
}
return 0;
}
static int cnncell_coeffbuf_hdl4se_unit_ClkTick(HOBJECT object)
{
#define GetInputValue(ind, v) \
do { \
objectCall3(pobj->input_unit[ind], GetValue, pobj->input_index[ind], 32, pobj->inputdata); \
objectCall1(pobj->inputdata, GetUint32, &v); \
} while (0)
sCNNCellCoeffBuf* pobj;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
GetInputValue(1, pobj->readcmd);
GetInputValue(2, pobj->read_addr);
}
static int cnncell_coeffbuf_hdl4se_unit_Setup(HOBJECT object)
{
sCNNCellCoeffBuf* pobj;
pobj = (sCNNCellCoeffBuf*)objectThis(object);
pobj->read_reg = pobj->readcmd;
pobj->read_addr_reg = pobj->read_addr;
return 0;
}
#endif
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus
}
#endif
#endif /* __HDL4SE_MACROS_H */
\ No newline at end of file
......@@ -116,6 +116,7 @@ int hdl4sedetectorTraversal(HOBJECT object, hdl4se_detector_TraversalFunc func,
DEFINE_GUID(IID_HDL4SEMODULE, 0x88cf84f9, 0x17ac, 0x4edf, 0xbf, 0x0, 0xc7, 0x32, 0xd5, 0x26, 0x99, 0x2a);
typedef struct sModulePort {
int index;
int width;
int portdirect;
int isunsigned;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册