yosri ben salah Posted May 6, 2017 Report Share Posted May 6, 2017 hi all, i write in this forum asking for help to solve this problem that tooks a lot of my time,iwrite my first program using systemC, my program debug but run exception i will expain my aim as much as i can , i stored 2 matrix of pixel value of image in two dfferent text file, i write a systemC code that load two matrix and comapre them, if number of different superior of a Threshold the code dispalays message (motion) my code composed of two modules, the first module check if there a number in a text file, if yes this Module will automates the other module to load the two matrix and compare them, i really need this code for my project graduation any help or sugesstion, sorry for my bad english. thank you // All systemc modules should include systemc.h header file #include "systemc.h" #include "stdio.h" #define _CRT_SECURE_NO_WARNINGS SC_MODULE(synchronous) { sc_out<bool> in; SC_CTOR(synchronous) {} void verify() { FILE *ifp, *ofp; char *mode = "r"; char outputFilename[] = "F:/yosri.txt"; int val; ifp = fopen(outputFilename, mode); while (fscanf_s(ifp, "%d", &val) != 1) { cout << " Waiting for request..."; } in = true; } }; SC_MODULE(imageProcess) { sc_in<bool> in; SC_CTOR(imageProcess) { SC_METHOD(MotionDetection); sensitive<<in; } void MotionDetection() { int Threshold = 20; bool fileFound; char *mode1 = "r"; char *mode2 = "w"; FILE *ofp1 = fopen("F:/image1.txt", mode1); FILE *ofp2 = fopen("F:/images2.txt", mode1); FILE *Motion = fopen("F:/image3.txt", mode2); int rowCounter, colCounter, isEqual = 0; int firstMatrix[384][512], secondMatrix[384][512]; // if (!(ofp1 || ofp2)) //{ //printf("2222222222222222222"); //fileFound = false; //} //else fileFound = true; //if (fileFound) { while (!feof(ofp1) && !feof(ofp2)) { for (rowCounter = 0; rowCounter < 384; rowCounter++) { for (colCounter = 0; colCounter < 512; colCounter++) { scanf("%d", &firstMatrix[rowCounter][colCounter]); } } for (rowCounter = 0; rowCounter < 384; rowCounter++) { for (colCounter = 0; colCounter < 512; colCounter++) { scanf("%d", &secondMatrix[rowCounter][colCounter]); if (firstMatrix[rowCounter][colCounter] != secondMatrix[rowCounter][colCounter]) { isEqual++; break; } } } if (isEqual > Threshold) { fputc(secondMatrix[rowCounter][colCounter], Motion); } else cout<< "MOTION"; } cout << "%d", isEqual; } }; // sc_main in top level function like in C++ main int sc_main(int argc, char* argv[]) { sc_start(); synchronous yosri("A"); yosri.verify(); imageProcess go("B"); go.MotionDetection(); return(0); } Quote Edit Quote Link to comment Share on other sites More sharing options...
katang Posted May 7, 2017 Report Share Posted May 7, 2017 You start SystemC simulation before setting up what to simulate. Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 7, 2017 Author Report Share Posted May 7, 2017 can you explain more, as i said im not familiar with coding systemC Quote Link to comment Share on other sites More sharing options...
katang Posted May 7, 2017 Report Share Posted May 7, 2017 You use sc_start(); at the very beginning. SystemC kernel starts, but finds nothing to simulate. Move that call after the point where you did set up the simulation completely, i.e. before 'return(0)'. Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 7, 2017 Author Report Share Posted May 7, 2017 as you see, i used CS_START() in main function, nt sc_main(int argc, char* argv[]) { sc_start(); synchronous yosri("A"); yosri.verify(); imageProcess go("B"); go.MotionDetection(); return(0); } you have my code how can i deal to solve this problem my friend, Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 7, 2017 Author Report Share Posted May 7, 2017 debuging result : Exception levée à 0x76C2A932 dans ConsoleApplication1.exe : exception Microsoft C++ : sc_core::sc_report à l'emplacement de mémoire 0x00E0EDB8. Le programme '[15048] ConsoleApplication1.exe' s'est arrêté avec le code 1 (0x1). Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted May 8, 2017 Report Share Posted May 8, 2017 Hi. You can find a good starting point for SystemC at: https://www.doulos.com/knowhow/systemc/tutorial/ In general: in the sc_main function, you should first instantiate your modules and bind the ports. Then you should call sc_start. And, you should not call the process methods explicitly. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 8, 2017 Author Report Share Posted May 8, 2017 thank you dr Ralph for advices, the following is my attempt but it still displaying problems, // All systemc modules should include systemc.h header file #include "systemc.h" #include "stdio.h" #include "string.h" #include "stdio.h" #include"stdlib.h" #define _CRT_SECURE_NO_WARNINGS SC_MODULE(synchronous) { sc_out<bool> in; #define _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS bool synchronization() { sc_out<bool> in; 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"); cout<<"%d", ret; } //SWITCHCONTXT is a string written in a text file in = true; cout<<"Establishing communication"); return(in); } SC_MODULE(imageProcess) { sc_in<bool> in; 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_METHOD(synchronization) } SC_CTOR(imageProcess) { SC_METHOD(MotionDetector); sensitive << in; } sc_start(); return(0); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.