It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new to TLM.
Someone can give me an example code for connecting two processes by a TLM fifo?
Thank you
I searched in doulos, but I only saw examples of sockets.
Someone helped me and I leave here a code example of a tlm fifo
#include "systemc"
#include "tlm.h"
// PRODUCER 1
SC_MODULE(producer)
{
sc_core::sc_port< tlm::tlm_fifo_put_if<int> > out; //FIFO OUT
SC_CTOR(producer)
: out("out")
{
SC_THREAD(run); //função
}
void run()
{
int i = 42;
std::cout << name() << ": " << i << std::endl;
out->put(i);
}
}; // producer
// CONSUMER
SC_MODULE(consumer)
{
sc_core::sc_port< tlm::tlm_fifo_get_if<int> > in;
SC_CTOR(consumer)
: in("in")
{
SC_THREAD(run); //função
}
void run()
{
int i = in->get();
std::cout << name() << ": " << i << std::endl;
}
}; // consumer
// MAIN
int sc_main(int, char*[] )
{
tlm::tlm_fifo<int> fifo("fifo");
producer prod("producer");
prod.out(fifo);
consumer cons("consumer");
cons.in(fifo);
sc_core::sc_start();
char myLine[100];
cin.getline(myLine, 100);
return 0;
}
Thank you
there are some good examples in doulos website.
Related
In the follwing program I was searching of lowest comman ancesstor in a BST.
The main problem here is that !root doesn't works like root!=nullptr.
Here line 1 works perfect. But line 2 gives wrong answer.
Please tell why line 2 desn't works but line 1 does.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
int small=min(p->val, q->val);
int big=max(p->val, q->val);
while(root!=nullptr){ // line 1
// while(!root){ // line 2
int x=(root->val);
if(x>big){
root=root->left;
}
else if(x<small){
root=root->right;
}
else{
return root;
}
}
return nullptr;
}
};
Short of defining nullptr to be something weird (like 7), there should be no difference between x != nullptr and ! x, for any given pointer x.
It may be worthwhile printing out nullptr and root just inside the loop as well as the comparison results (and pointers, just in case your tree is corrupt), to see if something weird is happening, something like:
while (!root) {
std::cout
<< static_cast<void*>(root) << ' '
<< static_cast<void*>(root->left) << ' '
<< static_cast<void*>(root->right) << ' '
<< static_cast<void*>(nullptr) << ' '
<< (! root) << ' '
<< (root != nullptr) << std::endl;
int x=(root->val);
// ... and so on
The output of that may go a great deal toward showing what's wrong with your situation(a).
(a) One of my favourite mantras is "when in doubt, print it out", right up there with:
Get it working first, then get it working fast.
You can't get any less optimised than "wrong".
:-)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am new in programming but I have a yacc/lex project and some difficulty in writing the error message in detail (line and type of error). Any help with a small example, please.
Add the following to your flex scanner definition, to cause the scanner to track line numbers:
%option yylineno
(See the flex manual.)
Then add the following declarations to your bison grammar:
%define parse.error verbose
%define parse.lac full
(See the bison manual chapters on error reporting and LAC (lookahead correction).
Finally, use a definition of yyerror which uses the line number information. At a minimum, something like:
void yyerror(const char* msg) {
fprintf(stderr, "At line %d: %s\n", yylineno, msg);
}
Ask bad questions get correct but uninformative answers
void yyerror(const char *s);
extern int line_num;
void yyerror(const char *s)
{
std::cerr << "PARSING ERROR: " << line_num << " " << s << std::endl;
exit(1);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have been assigned a project in my lab to implement CAN protocol on ARM 7.
I looked for some tutorials and sample code, but all looks so much complex that I think I should get some help on the coding part. Can anybody explain me the basic transmitter and receiver coding on any ARM board?
The sender code is the following. I have used question marks where I don't understand the full meaning of an expression.
#include <lpc23xx.h>
#include "type.h
#include "can.h"
#include <LPC23xx.H>
CAN_MSG MsgBuf_RX1,MsgBuf_RX2; // TX and RX Buffers for CAN message
volatile DWORD CAN1RxDone, CAN2RxDone;
int main(void)
{
DWORD tempbuf1,tempbuf2;
int current;
FIO2DIR=0x000000FF;
CAN_Init(BITRATE100K28_8MHZ);
MsgBuf_RX2.Frame = 0x0;
MsgBuf_RX2.MsgID = 0x0;
MsgBuf_RX2.DataA = 0x0;
MsgBuf_RX2.DataB = 0x0;
CAN_SetACCF(ACCF_BYPASS);
while (1)
{
while (!(CAN2GSR & (1 << 0)) )
;
if (CAN2RxDone == TRUE)
{
tempbuf1 = MsgBuf_RX2.DataA; // Data A has 32 bits, of which only the
// first 16 bits are actual data
tempbuf2 = (tempbuf1 & 0x0000ffff); //??
current = tempbuf2;
if ((current/3) >= 25)
FIO2SET |= 0x00000001; ///??
}
CAN2RxDone = FALSE;
if (MsgBuf_RX2.Frame & (1 << 10)) //?
{
MsgBuf_RX2.Frame &= ~(1 << 10); //?
}
}
}
Keil provides some examples and programs for CAN development: http://www.keil.com/dd/vtr/4152/7837.htm
Here you can find CAN source for LPC2129: http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/
Here some examples: http://mbed.org/handbook/CAN
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have been reading a programming book and it wants me to write a program listing a table of the first 10 factorial numbers. I have been trying for the past 45 minutes, but can't come up with a solution. Please Help! I'm pretty sure the program involves using loops.
The easiest way to calculate the factorial is with a recursive function or a simple loop as shown below. I'll leave it up to you to figure out how to list the information in a table as there are lots of ways to skin that cat.
Header File Function Declaration:
-(int)factorialRecursive:(int)operand;
-(int)factorialLoop:(int)operand;
Implementation File Function Declaration:
-(int)factorialRecursive:(int)operand
{
if( operand == 1 || operand == 0) {
return(1);
} else if( operand < 0 ) {
return(-1);
}
return( operand * [self factorialRecursive:operand-1] );
}
-(int)factorialLoop:(int)operand
{
if( operand == 1 || operand == 0) {
return(1);
} else if( operand < 0 ) {
return(-1);
}
int factorial = 1;
for(int i = operand; i > 1; i-- ) {
factorial *= i;
}
return( factorial );
}
Sample Call:
int factNumber = 10;
NSLog(#"%d! = %d",factNumber,[self factorialRecursive:factNumber]);
NSLog(#"%d! = %d",factNumber,[self factorialLoop:factNumber]);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In need some help with this little programming .. I just got 3 errors ..
:'(
**[
#include <stdio.h>
int main (void)
{
char A , B , C , D , E , F;
float id1[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float grade[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float marks[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float average;
float num1, kk=0;
/********* Jami, Abdulrahman *********/
printf("Enter The Student ID: ");
scanf("%d", &num1);
for (kk=0; kk<num1; kk++);
{
scanf("%d", &id1[kk]);
scanf("%d", &grade[kk]);
}
for (kk=0; kk<num1; kk++);
{
if (grade [kk]>85 &grade [kk]<=100);
A=A+1;
if (grade [kk]>70 &grade [kk]<85);
B=B+1;
if (grade [kk]>55 &grade [kk]<70);
C=C+1;
if (grade [kk]>40 &grade [kk]<55);
D=D+1;
if (grade [kk]>25 &grade [kk]<40);
E=E+1;
if (grade [kk]>=0 &grade [kk]<25);
F=F+1;
}
/********* Jami, Abdulrahman *********/
float aveerage;
float avrg, sum, lk;
sum = sum + marks[lk];
average = sum / num1;
for (lk=0; lk<num1; lk++);
return average;
}
]**
You must give it a size like 3 (it can be any integer though) or something:
For example:
float id1[];
//Should be:
float id1[3]; //Or whatever number you want.
Or you can do:
float id1[] = { 0, 0, 0 }; //To get the same effect as id1[3] where they would all be initialized at zero.
Or even better:
float id1[3] = { }; //Initialize all 3 elements to zero.
The error tells you that you need to set a size on these arrays. Try defining them as float myArray[maxMarks];
Of course maxMarks is the maximal number of marks, not the highest mark...
Try something like
float *id1;
or
float id1[100];
or
float id1[] = { 1.0, 2.0, 3.3, 7.2, 9.1, 1.5, 4.1 };
The [] can only be empty if you initialize the array with values. if you use float *id1;, you'll have to malloc() memory to use it. The other two are real arrays.
As other said: read the error messages you get and think about what they could mean.