Ejemplo n.º 1
0
/**
 * Closes the session to the myRIO FPGA Personality.
 *
 * This function resets the FPGA (unless there is another open session) and
 * unloads the NiFpga library.
 *
 * @warning  This function is not thread-safe.
 *           It should be called after all other function calls and only once
 *           per application.
 */
NiFpga_Status MyRio_Close()
{
    NiFpga_Status status;

    /*
     * Close and Reset the FPGA
     */
    status = NiFpga_Close(myrio_session, 0);
    if (MyRio_IsNotSuccess(status))
    {
        MyRio_PrintStatus(status);
        printf("Could not Close FPGA!\n");
        return status;
    }

    /*
     * Unload the NiFpga library
     */
    status = NiFpga_Finalize();
    if (MyRio_IsNotSuccess(status))
    {
        MyRio_PrintStatus(status);
        printf("Could not unload NiFpga library!\n");
        return status;
    }

    return status;
}
Ejemplo n.º 2
0
void stop_fpga(NiFpga_Session* session, NiFpga_Status* status)
{
	// close the session now that we're done 
	NiFpga_MergeStatus(status, NiFpga_Close(*session, 0));

	// must be called after all other calls 
	NiFpga_MergeStatus(status, NiFpga_Finalize());
}
Ejemplo n.º 3
0
bool nifpga::Close(uint32_t attribute) {
	bool status = false;
	if (sessionOpen) {
		if (sessionRunning) status = Abort();
		status = HandleStatus(NiFpga_Close(sessionHandle,attribute));
		if (status) sessionOpen = false;
	}
	return status;
}
Ejemplo n.º 4
0
// Closes the FPGA session
void FPGA_Close(void)
{
	// close the session now that we're done 
	printf("Closing the session...");
	if (NiFpga_IsNotError(FPGA_Status))
	{
		NiFpga_MergeStatus(&FPGA_Status, NiFpga_Close(FPGA_Session, 0));
	}
	// must be called after all other calls
	printf("Finalizing...");

	NiFpga_MergeStatus(&FPGA_Status, NiFpga_Finalize());
}
Ejemplo n.º 5
0
void lia_readI32(double control[], int32_t value[])
{
	
	/* Create status, initialize to good */
	NiFpga_Status status = NiFpga_Status_Success;
	
	/* Create a session variable */
	NiFpga_Session session;
	
	/* Load the NiFpga library */
	NiFpga_Initialize();
	
	/* Load bitfile */
	NiFpga_Open(NiFpga_lockin_fpga_Bitfile, NiFpga_lockin_fpga_Signature, "RIO0", NiFpga_OpenAttribute_NoRun,&session);
	
	/* Read value from control */
	NiFpga_ReadI32(session, control[0], value);
	
	/* Close session */
	NiFpga_Close(session,0);
	
	NiFpga_Finalize();
}
Ejemplo n.º 6
0
int main()
{
	double desired_angle;
	int32_t desired_tick;
	int32_t Kd = .5 * ACCURACY;
	int32_t Kp = 5 * ACCURACY; 
	int32_t Ki = .0001 * ACCURACY;  
	int32_t error=0xFFFF; 
   /* must be called before any other calls */
   printf("Initializing...\n");
   NiFpga_Status status = NiFpga_Initialize();
   if (NiFpga_IsNotError(status))
   {
      NiFpga_Session session;
      /* opens a session, downloads the bitstream, and runs the FPGA */
      printf("Opening a session...\n");
      NiFpga_MergeStatus(&status, 
			NiFpga_Open(NiFpga_Math_Pid_Bitfile, NiFpga_Math_Pid_Signature,
                     "rio://146.6.84.251/RIO0",
                      NiFpga_OpenAttribute_NoRun,&session));
      if (NiFpga_IsNotError(status))
      {
         /* run the FPGA application */
         printf("Running the FPGA...\n");
         NiFpga_MergeStatus(&status, NiFpga_Run(session, 0));	
/********************************************************************/
			/* Code goes here */
			NiFpga_MergeStatus(&status,
							NiFpga_WriteBool(session,NiFpga_Encoder_Reset,0)); 
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Kd,Kd));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Kp,Kp));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Ki,Ki));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Accuracy,ACCURACY));
			printf("Enter Desired(in degrees): ");
			scanf("%lf",&desired_angle); 
			desired_tick = degree_tick(desired_angle); 
			printf("Desired(in ticks) %d\n", desired_tick);  
			NiFpga_MergeStatus(&status, 
					NiFpga_WriteI32(session,NiFpga_Desired,desired_tick));
			printf("Entering loop\n"); 
			while(error != 0) {
				NiFpga_MergeStatus(&status, 
							NiFpga_ReadI32(session,NiFpga_RealError,&error));   				printf("Error:%d\n", error); 
			}	
/********************************************************************/
			/* Stopping */
			printf("Press <Enter> to stop and quit...");
         getchar(); 
         /* stop the FPGA loops */
         printf("Stopping the FPGA...\n");
	 		/* close the session now that we're done */
         printf("Closing the session...\n");
         NiFpga_MergeStatus(&status, NiFpga_Close(session, 0));
      }
      /* must be called after all other calls */
      printf("Finalizing...\n");
      NiFpga_MergeStatus(&status, NiFpga_Finalize());
   }
   /* check if anything went wrong */
   if (NiFpga_IsError(status))
   {
      printf("Error %d!\n", status);
      printf("Press <Enter> to quit...\n");
      getchar();
   }
   return status;
}