Jump to content

apfitch

Members
  • Posts

    613
  • Joined

  • Last visited

  • Days Won

    118

Posts posted by apfitch

  1. Hi Yosri,

     I don't understand why you want to do this in SystemC, the algorithm you've written just reads from a file and writes to a file, which is well suited to a plain C or C++ program.

    Some specific comments - you have declared "sig" and haven't used it.

    In sc_main you've called the SC_METHOD using master.MotionDetector. You don't need to do that, the SC_METHOD is a parallel thread and will run automatically at time 0.

    However as I said above, my main comment is why are you using SystemC? Why not just write a plain C/C++ program?

    regards

    Alan

  2. Hi Mr SystemCInDepth,

       I think it's important to realise that SC_CTHREAD is special, in that the specified sensitivity is a clock (the rising or falling edge event of a bool or sc_logic).

    There's no such thing as a "clock" for SC_METHOD and SC_THREAD - just events on channels such as sc_signal, sc_fifo, or any other channel that implements an event.

    So I would not say

    Quote

    As Method and thread are allowed to be added to the runnable queue with clock

    because an SC_METHOD or an SC_THREAD does not have a clock. That's what Philipp meant when he said

    Quote

    clocked threads are sensitive to an explicit clock

    Does that make it clearer?

    regards

    Alan

  3. If your goal is to synthesize the design, then your first step should be to check what is synthesisable - are you using a particular high level synthesis tool? Have you checked this it will support sc_fifo and sc_semaphore?

    If your tool supported std::map, couldn't you use use that?

    regards

    Alan

  4. Hi, in UVM people tend to talk about agents as being passive, active, or reactive instead of "master" or "slave".

    Each agent contains a driver, a monitor, and a sequencer.

    An active agent has all three.

    A passive agent monitors, but does not drive.

    A reactive agent drives, but depends on the DUT more closely (i.e. the agent drives data to the DUT, but reacts in some way with the DUT.

    So I guess you could be using "master" to mean active, and "slave" to mean reactive *or* passive.

    regards

    Alan

  5. There's lots wrong with your code - did you look at the tutorial on www.doulos.com as someone suggested in the earlier thread?

    Any way, I've tried to add some comments in your code
     

    #include "systemc.h"
    #include "stdio.h"
    #include "string.h"
    #include "stdio.h"
    #include"stdlib.h"
    #define _CRT_SECURE_NO_WARNINGS
    sc_out<bool> in;                        // DON'T DECLARE A PORT OUTSIDE A MODULE
    SC_MODULE(synchronous) {
        
        bool synchronization()
        {
            sc_out<bool> in;                // DON'T DECLARE A PORT INSIDE A FUNCTION
            FILE *workspace = fopen("F:/yosri.txt", "r");
            char buff[13];
            fgets(buff, 12, workspace);
            int ret = 0;
            while (ret == 0)
            {
                cout << "Waiting for  request...\n";
                ret = strcmp(buff, "SWITCHCONTEXT");
                printf("%d", ret);
            }
            //SWITCHCONTXT is a string written in  a text file
    
            in = true;
            cout << "Establishing communication";
    
            return(in);                         // YOU CAN'T RETURN A PORT CLASS LIKE THIS
        }
    };
        SC_MODULE(imageProcess)                 // WHY USE A MODULE HERE? I can't see what SystemC features you're using?
        {
            sc_in<bool> in;                     // WHAT'S THIS FOR?
    
            void MotionDetector(bool signal)
            {
                printf("\nCommuncation established");
                char *mode1 = "r";
                char *mode2 = "w";
                int i, j, k;
                int C = 0;
                int rows1, cols1, rows2, cols2;
    
                bool fileFound = false;
    
                bool multiplcation = true;
                FILE *image1;
                FILE *image2;
                FILE *image3;
                int sum = 0;
                image3 = fopen("F:/image3.txt", mode2);
                do
                {
                    char *mode1 = "r";
                    char *mode2 = "w";
                    image1 = fopen("F:/image1.txt", mode1);
    
                    if (!image1)
                    {
                        printf("File Not Found!!\n");
                        fileFound = true;
                    }
                    else
                        fileFound = false;
    
                } while (fileFound);
    
    
                do
                {
                    image2 = fopen("F:/image2.txt", mode1);
    
                    if (!image2)
                    {
                        cout << "File Not Found!!\n";
                        fileFound = true;
                    }
                    else
                        fileFound = false;
    
                } while (fileFound);
    
                //allocate Matrcies
                rows1 = rows2 = 384;
                cols1 = cols2 = 512;
                int **mat1 = (int **)malloc(rows1 * sizeof(int*));
                for (i = 0; i < rows1; i++)
                    mat1 = (int *)malloc(cols1 * sizeof(int));
    
                i = 0;
    
                int **mat2 = (int **)malloc(rows2 * sizeof(int*));
                for (i = 0; i < rows2; i++)
                    mat2 = (int *)malloc(cols2 * sizeof(int));
    
    
                i = 0;
    
    
                while (!feof(image1))
                {
                    for (i = 0; i < rows1; i++)
                    {
                        for (j = 0; j < cols1; j++)
                            fscanf(image1, "%d%", &mat1[j]);
                    }
                }
    
                i = 0;
                j = 0;
    
                while (!feof(image2))
                {
                    for (i = 0; i < rows2; i++)
                    {
                        for (j = 0; j < cols2; j++)
                            fscanf(image2, "%d%", &mat2[j]);
                    }
                }
    
                i = 0;
                j = 0;
                printf("\n\n");
    
                i = 0;
                k = 0;
                cout << "\n\n";
    
    
                for (i = 0; i < rows1; i++)
                {
                    for (j = 0; j < cols1; j++) {
    
                        if (mat1[j] != mat2[j])
                            C++;
                    }
                }
                i = j = 0;
                if (C > 20)
                {
                    printf("MOTION...DETECTED\a \a");
                    for (i = 0; i < rows1; i++) {
                        for (j = 0; j < cols1; j++) {
    
                            fprintf(image3, "%d ", mat2[j]);
                        }
    
                        fprintf(image3, "\n");
                    }
                    cout << "\n Image Saved....";
                }
    
                fclose(image1);
                fclose(image2);
                fclose(image3);
            }
        };
    
            // sc_main in top level function like in C++ main
            int sc_main(int argc, char* argv[]) {
    
                SC_CTOR(synchronous)                     // sc_main is not a class so you can't declare a constructor here.
                {
                    SC_METHOD(synchronization);
    
                }
    
                SC_CTOR(imageProcess)					// sc_main is not a class so you can't declare a constructor here.
                {
                    SC_METHOD(MotionDetector);
                    sensitive << in;
                }
    
                sc_start();
                return(0);
            }

    Your code shows a lot of confusion between ports, modules, sc_main, and processes. I highly recommend going back to that tutorial and getting a very simple example running (perhaps an AND gate) and checking you understand that first,

    kind regards

    Alan

  6. Hi,

    the reason for the error is that you're not binding all your ports. You bind the ports in this loop:

     

           for(int i=0;i<n;i++)
            {
                for (int j=0;j<=i;j++)
                {
                        std::cout << i << " " << j << " " << std::endl;
                    test_CHOL0->chol_in_data[i][j](chol_in_data[i][j]);
                    test_CHOL0->chol_out_data[i][j](chol_out_data[i][j]);
                }
            }

    but in the second loop you have j <= i. I've added printing and you can see that you only bind 6 of the 9 ports

     

            SystemC 2.3.1-Accellera --- Sep  3 2016 13:00:03
            Copyright (c) 1996-2014 by all Contributors,
            ALL RIGHTS RESERVED
    0 0 
    1 0 
    1 1 
    2 0 
    2 1 
    2 2 

    I think you need j < n

     

    regards

    Alan

  7. For that kind of modelling you probably need resolved types, e.g. sc_signal_resolved, sc_in/out resolved. These types model signal strength resolution, i.e. if you drive two values such as '1' and 'Z', '1' will be the resulting value because '1' is stronger than 'Z'.

    Have a look at the SystemC standard 1666-2011, especially section 6.13.5 where there's a little example that might help,

     

    regards

    Alan

  8. Hi Jean-Claude,

        one option would be to create an a process sensitive to each event, and then in that process assign (or perhaps toggle the value) of an sc_signal<bool>. You can then make a process sensitive to all the boolean signals, and find out which signal changed by calling the signal's event method.

     

    It's a bit messy, but it would work.

     

    You could combine the process, the event, and the boolean signal into a hierarchical channel (perhaps using sc_event_queue for guidance),

     

    regards

    Alan

  9. Hi, your approach seems odd to me. If I were you, I would re-write the C++ model to be more synthesisable. I would go back to your HLS vendor and say "what do I need to do to my algorithmic model to get good results?

     

    You seem to be taking the approach of using HLS, then re-writing the generated RTL code, which sounds like a very long-winded design flow,

     

    regards

    Alan

  10. Ok, as Roman says above, it's hard to help without the source code.

     

    This might be obvious, but if you can't post the code, I would try the following

    1. Try the same code on a different compiler and/or OS

    2. Try to narrow down exactly what line of code is causing the problem by commenting out code until the problem disappears

    3. Try setting breakpoints progressively further in the simulation until you can set a breakpoint just before the failure

     

    regards

    Alan

×
×
  • Create New...