- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一个简单的程序,它将数据从一个模块的二维数组发送到另一个模块,但是它似乎不起作用,我也不确定为什么。这是我的代码:
服务器.h
#include <iostream>
#include "stdafx.h"
using namespace std;
SC_MODULE(Server){
sc_in <bool> clock;
sc_fifo_out <sc_uint<20> > writePath;
bool init_flag;
int numRobots;
void Server_Main();
SC_CTOR(Server){
init_flag = 0;
numRobots = 4;
SC_METHOD(Server_Main){ sensitive << clock.pos(); }
}
};
服务器.cpp
#include "stdafx.h"
#include "Server.h"
void Server::Server_Main(){
if (init_flag == 0){
int robotPath[4][5] = {
{ 1, 2, 3, 4, 1 },
{ 2, 1, 6, 3, 4 },
{ 3, 2, 9, 5, 1 },
{ 4, 1, 6, 8, 7 }
};
//Write robot path to Sensor
for (int i = 0; i < numRobots; i++){
for (int j = 0; j < 5; j++){
cout << "SERVER MODULE: Write Robot Paths " << i << ": " << robotPath[i][j] << endl;
writePath.write(robotPath[i][j]);
}
}
init_flag = 1;
}
else{ sc_stop(); }
}
传感器.h
#include <iostream>
#include "stdafx.h"
using namespace std;
SC_MODULE(Sensor){
//sc_in <bool> clock;
sc_fifo_in <sc_uint<20> > readPath;
int robotPath[4][5];
void loadPath();
//void Sensor_Main();
SC_CTOR(Sensor){
//SC_METHOD(Sensor_Main){ sensitive << clock.pos(); }
SC_THREAD(loadPath){}
}
};
传感器.cpp
#include "stdafx.h"
#include "Sensor.h"
void Sensor::loadPath(){
int i = 0;
int j = 0;
while (1){
robotPath[i][j] = readPath.read();
cout << "SENSOR MODULE: Read Robot " << i << " Path " << j << " : " << robotPath[i][j] << endl;
if (j == 4){
j = 0; //Set index to beginning of array
i++; //Move to next robot
}
else{ j++; } //Continue loading path for current robot
}
}
main.cpp
#include "stdafx.h"
#include <iostream>
#include "Sensor.h"
#include "Server.h"
using namespace std;
int sc_main(int argc, char* argv[])
{
sc_clock clock("sysclock", 50, SC_MS, .5);
sc_fifo <sc_uint<20> > robotPath;
Sensor sensor_mod("Sensor");
sensor_mod.readPath(robotPath);
Server server_mod("Server");
server_mod.clock(clock);
server_mod.writePath(robotPath);
sc_start();
return 0;
}
这是我的输出:
程序似乎在尝试将 robotPath[3][1]
写入 fifo 时抛出异常,但我不确定为什么。我将我的 fifo 大小指定为 20,这样它可以一次存储 20 个值,但我发送的值不超过 20 个,当我尝试写入第 17 个值时会发生此异常,所以我可能误解了 sc_fifo_out< 的使用
。这可能是我忽略的一些明显错误,但此时我有点筋疲力尽,无法弄清楚我搞砸了什么。
最佳答案
您是尝试使用 SystemC 为硬件设计建模还是尝试使用 SystemC 进行软件建模?
看来你混淆了上下文。
以下是您需要考虑的要点列表:
在服务器模块 Server_Main() 中应该注册为 SC_THREAD:
SC_THREAD(Server_Main);
sensitive << clk.pos();
由于您正在使用内部调用 wait() 的 sc_fifo 的写入方法,因此在 SystemC 中,在 SC_METHOD 中使用 wait 是非法的。
如下修改Server.cpp:
void Server::Server_Main() {
int robotPath[4][5] = {{ 1, 2, 3, 4, 1 },
{ 2, 1, 6, 3, 4 },
{ 3, 2, 9, 5, 1 },
{ 4, 1, 6, 8, 7 }};
//Write robot path to Sensor
for (int i = 0; i < numRobots; i++){
for (int j = 0; j < 5; j++){
cout << "SERVER MODULE: Write Robot Paths " << i << ": " << robotPath[i][j] << endl;
writePath.write(robotPath[i][j]);
wait(); //< Notice this wait statement.
}
}
}
在 Sensor.cpp 的 while 循环中添加一个 wait() 语句。
此外,sc_fifo< sc_uint<20>> 并未像您想象的那样实例化深度为 20 的 sc_fifo。
它实际上是用sc_uint<20>实例化一个sc_fifo作为数据类型,用于建模一个20位无符号整数,fifo的默认深度为16 SystemC规范。
您可以实例化深度为 20 的 sc_fifo<>,如下所述:
sc_fifo<sc_uint<20> > robotPath("robotPath", 20);
注意:您不需要执行此操作,因为上述从 SC_METHOD 更改为 SC_THREAD 以及更新 Server_Main 将使此行为无效。
关于c++ - SC_FIFO 写入 : First chance exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42917674/
目前,我正在为网络开发类(class)做作业。 这些是说明:第一行和首字下沉样式Jakob 希望文章的第一行以小写大写字母显示。转到 First Line and Drop Cap Styles 部分
.first() 方法是在 jQuery 1.4 中添加的。 :first 选择器自 1.0 以来就已存在。 来自文档: :first The :first pseudo-class is equiv
我正在审查现有的 ASP.NET MVC (5.2.3) EF (6.1.3) 项目。 该项目使用 ASP.NET Identity,我检查了 web.config 中的 2 个连接字符串,一个用于
为什么人们使用 mid=first+(last-first)/2 而不是 (first+last)/2,在二进制搜索的情况下)两者有区别吗。如果有,请告诉我,因为我无法理解其中的区别。 最佳答案 如果
为什么人们使用 mid=first+(last-first)/2 而不是 (first+last)/2,在二进制搜索的情况下)两者有区别吗。如果有,请告诉我,因为我无法理解其中的区别。 最佳答案 如果
for(auto it = M.begin(); it!=M.end();it++) { coutfirstsecondsecond == 1) return it->firs
我试图从第二个循环中获取循环的第一项。 我知道我得到了这样的@key @../key 但@first 似乎不像@../first 那样工作 有什么想法吗? 问候 最佳答案 首先,无论是否在嵌套 blo
var tab1 = $('.tabs a:first-child').attr('href'); alert(tab1); .. 尽管同一页面上有两个 div.switch,但仅匹配一个。第二个位于
我想知道如何将节点*变量 NODE 分配给结构内的数据? struct node { int info; struct node *link; }; typedef struct nod
我有两个段落包含在一个 div 中。我想让第一段的文字变大一点,但使用 :first-child 并不能像我所说的那样工作。看不出有什么问题。
我有一个 ul li 列表 Parent child1 child2
我有三个表,即员工、部门和申诉。 Employees 表有超过一百万条记录。我需要找到员工的详细信息、他/她的部门以及他/她提出的申诉。 我可以想到以下两个查询来查找结果: 1。先过滤记录,只获取需要
我有三个表,即员工、部门和申诉。 Employees 表有超过一百万条记录。我需要找到员工的详细信息、他/她的部门以及他/她提出的申诉。 我可以想到以下两个查询来查找结果: 1。先过滤记录,只获取需要
这有什么区别吗: myList.Where(item => item == 0).First(); 还有这个: myList.First(item => item == 0); 后者对我来说更有意义,
我分不清 element:first-child 之间的区别和 element:first-of-type 例如,你有一个 div div:first-child → 全部 元素是其父元素的第一个子元
当我遇到一个奇怪的情况时,我正在研究 CSS 选择器。 如果我使用 :first-child 伪元素,我需要在它前面加上一个空格才能工作,否则它将无法工作。然而 :first-letter 伪元素的情
请考虑以下字符串数组: let strings = ["str1", "str2", "str10", "str20"] 假设需要获取包含 5 个字符的第一个元素 (String),我可以使用 fil
让我们假设我们要开始新项目 - 包含一些业务逻辑的应用程序、ASP.NET 上的用户界面、WPF 或两者。我们想使用 ORM 或 DAL 代码生成器并在 .NET 类中实现我们的业务逻辑。我们可以通过
我有一种树系统。我想做的是给所有 parent 一个 margin ,除了第一个。这是我的 HTML: Test
我分不清 element:first-child 之间的区别和 element:first-of-type 例如,你有一个 div div:first-child → 全部 元素是其父元素的第一个子元
我是一名优秀的程序员,十分优秀!