Esempio n. 1
0
int Test_HostPC_to_HwAcc_to_HostPC_1_file()
{
	struct packet fiforead;
	struct packet fifowriteA;
  	HANDLE Handle_Of_Thread_1 = 0;       // variable to hold handle of Thread 1
	HANDLE Handle_Of_Thread_2 = 0;       // variable to hold handle of Thread 2 
 	HANDLE Array_Of_Thread_Handles[2];   // Aray to store thread handles 

	clear_flag();
	
	wait_flag(ADDR01, REQ);
	FilesizeUse = hostpc_rx_size();

	FilesizeA = hostpc_tx_sizeA(matrix_UA);
	//printf("\nFilesizeA: %d", FilesizeA);

	send_flag(ADDR00, REQ);
	
	// Create thread 1: Read
	Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_file, &fiforead, 0, NULL);
	if (Handle_Of_Thread_1 == NULL) {
	errorprint("Failed to create thread 1\n", GetLastError());
	exit(1);
	}
	//printf("\nThread 1 creation completed.");

	// Create thread 2: Write Matrix A and B
	Handle_Of_Thread_2 = CreateThread(NULL, 0, hostpc_tx_fileA, &fifowriteA, 0, NULL);
	if (Handle_Of_Thread_2 == NULL) {
	errorprint("Failed to create thread 2\n", GetLastError());
	exit(1);
	}
	//printf("\nThread 2 creation completed.");

	

	// Store Thread handles in Array of Thread Handles as per the requirement of WaitForMultipleObjects() 
	Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
	Array_Of_Thread_Handles[1] = Handle_Of_Thread_2;
    
	// Wait until all threads have terminated.
	WaitForMultipleObjects(2, Array_Of_Thread_Handles, TRUE, INFINITE);

	// Close all thread handles upon completion.
	CloseHandle(Handle_Of_Thread_1);
	CloseHandle(Handle_Of_Thread_2);

	//printf("\nAll threads are closed now.");
	
	wait_flag(ADDR01, ACK);
	send_flag(ADDR00, ACK);

	//printf("\nFinish!");


	return 0;
}
Esempio n. 2
0
void main(int argc, char *argv[]){
	/*Function Declaration*/
	void errorprint(char* arr );
	/*Variable */
	double size_grid, lambda;
	int n_grid=256;
	double radius = 0.0025;
	/* Processing the command line argument  */	
	if (argc < 3 || argc >4) {
		errorprint(argv[0]);
	}

	sscanf(argv[1],"%le",&size_grid);
	sscanf(argv[2],"%le",&lambda);
	/* reading the data from a command line */

	if(argc>3) 
		sscanf(argv[3],"%d",&n_grid);

	/*Create a new field and generate image for it*/
	begin(n_grid, size_grid, lambda, &field);
	//circ_ap(radius, 0, 0, &field);
	//file_pgm(0, 0, &field);
	fil_ter(&field, "out.pgm", "int", "subst");
}
Esempio n. 3
0
int Test_SDRAM_to_HwAcc_to_HostPC()
{
	struct packet fiforead;
  	HANDLE Handle_Of_Thread_1 = 0;       // variable to hold handle of Thread 1

	wait_flag(ADDR01, REQ);
	FilesizeUse = hostpc_rx_size();
	printf("\nHostPC will receive %d Bytes from FPGA.", FilesizeUse);
	send_flag(ADDR00, RDY);

	// Create thread 1: Read
	Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_file, &fiforead, 0, NULL);
	if (Handle_Of_Thread_1 == NULL) {
	errorprint("Failed to create thread 1\n", GetLastError());
	exit(1);
	}
	printf("\nThread 1 creation completed.");

	WaitForSingleObject(Handle_Of_Thread_1, INFINITE);
	CloseHandle(Handle_Of_Thread_1);

	wait_flag(ADDR01, FIN);
	send_flag(ADDR00, ACK);
	wait_flag(ADDR01, NCN);

	clear_flag(); // All flag from HostPC must be cleared before exit
	xillybus_close();
	return 0;
}
Esempio n. 4
0
int __cdecl main(int argc, char *argv[]) {
#define N_FRAME 100
#define N_PATCH 600000//(1<<LFSR_SIZE)
  const char* readfn = "\\\\.\\xillybus_rd"
	  , * writefn = "\\\\.\\xillybus_wr";
  HANDLE tid[2];
  struct xillyfifo fifo;
  unsigned int fifo_size = 4096*16;
  int write_fd, bTalk2FPGA = (int)(argc < 2);
  unsigned int n_frame = 0;
  unsigned int msg, n_msg;
  int rd;
  FILE* pixel_coeff_f = fopen("reducer_coeff_0.bin", "rb")
    , *ds_coeff_f = fopen("ds_0.bin", "rb");
  if(!pixel_coeff_f) {
    perror("Failed to open reducer_coeff");
    exit(errno);
  }
  if(!ds_coeff_f) {
    perror("Failed to open ds_coeff");
    exit(errno);
  }

  if(bTalk2FPGA) {
    //printf("Press any key to connect to FPGA\n"); getchar();
    write_fd = _open(writefn, O_WRONLY | _O_BINARY);
    if (write_fd < 0) {
      if (errno == ENODEV)
        fprintf(stderr, "(Maybe %s a write-only file?)\n", writefn);

      fprintf(stderr, "Failed to open %s", writefn);
      exit(1);
    }

    // If more than one FIFO is created, use the total memory needed instead
    // of fifo_size with SetProcessWorkingSetSize()
    if(fifo_size > 20000
      && !SetProcessWorkingSetSize(GetCurrentProcess()
            , 1024*1024 + fifo_size, 2048*1024 + fifo_size))
      errorprint("Failed to enlarge unswappable RAM limit", GetLastError());

    if (fifo_init(&fifo, fifo_size)) {
      perror("Failed to init");
      exit(1);
    }

    read_fd = _open(readfn, O_RDONLY | _O_BINARY);
    if (read_fd < 0) {
      perror("Failed to open read file");
      exit(1);
    }

    if (_setmode(1, _O_BINARY) < 0)
      fprintf(stderr, "Failed to set binary mode for standard output\n");

    // default security, default stack size, default startup flags
    tid[0] = CreateThread(NULL, 0, read_thread, &fifo, 0, NULL);
    if (tid[0] == NULL) {
      errorprint("Failed to create read thread", GetLastError());
      exit(1);
    }
    tid[1] = CreateThread(NULL, 0, report_thread, &fifo, 0, NULL);
    if (tid[1] == NULL) {
      errorprint("Failed to create report thread", GetLastError());
      exit(1);
    }
  }//end if(bTalk2FPGA)

  for(n_msg = 0; !feof(pixel_coeff_f); ) {
    rd = fread(&msg, sizeof(msg), 1, pixel_coeff_f);
    if(bTalk2FPGA) allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
    printf("weights 0x%08X\n", msg);
  } //end for

  for(; !feof(ds_coeff_f); ) {
    rd = fread(&msg, sizeof(msg), 1, ds_coeff_f);
    printf("DS 0x%08X\n", msg);
    if(bTalk2FPGA) allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
  } //end for

cleanup:
  if(bTalk2FPGA) {
    unsigned int msg = ~0;//Make the FPGA close the rd file
    allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
    _close(write_fd);
    _close(read_fd);

    // Wait for threads to exit
    if (WaitForSingleObject(tid[0], INFINITE) != WAIT_OBJECT_0) 
      errorprint("Failed waiting for read_thread to terminate"
        , GetLastError());
    fifo_destroy(&fifo);
  }
  fclose(ds_coeff_f);
  fclose(pixel_coeff_f);
  printf("Press any key to exit\n"); getchar();
  return 0;
}