Ejemplo n.º 1
0
/**
 * Overview:
 * myRIO main function. This template contains basic code to open the myRIO
 * FPGA session. You can remove this code if you only need to use the UART.
 *
 * Code in myRIO example projects is designed for reuse. You can copy source
 * files from the example project to use in this template.
 *
 * Note:
 * The Eclipse project defines the preprocessor symbol for the myRIO-1900.
 * Change the preprocessor symbol to use this example with the myRIO-1950.
 */
int main(int argc, char **argv)
{
    NiFpga_Status status;

    /*
     * Open the myRIO NiFpga Session.
     * This function MUST be called before all other functions. After this call
     * is complete the myRIO target will be ready to be used.
     */
    status = MyRio_Open();
    if (MyRio_IsNotSuccess(status))
    {
        return status;
    }

    /*
     * Your application code goes here.
     */

    //we're gonna need lots of ram boss
    //layout of memory:
    //0-MEM_WIDTH: memory blocks of MEM_DEPTH size
    //MEM_ITER = MEM_WIDTH+1: a table of current indexes for each block
    //MEM_VAL = MEM_WIDTH+2: a table of current averages for each block
    
    double  reference[MEM_WIDTH] = [0,1,5,2,7,8,2,6,7,3]; //something to test with
    double* memory[MEM_WIDTH+2];
    initializeMemory(memory);

    int keepGoing = 1;
    int index = getIndex(0);
    double Kp = 1;
    double Ki = 1;
    double lastError[MEM_WIDTH] = {0};
    while(keepGoing) {
    	index = getIndex(index);
	double toSet = (Kp*lastError[index])+(Ki*MEM_VAL[index])+reference[index];
    	setOutput(outputHandle, toSet);
	//wait for a bit (outputs aren't instantaneous!)
	double result = measureFeedback(feedbackHandle); //some sort of unit conversion needs to take place here
	lastError[index] = result-reference[index];
	updateBlock(memory, index, lastError[index]);
	
    }

    /*
     * Close the myRIO NiFpga Session.
     * This function MUST be called after all other functions.
     */
    freeTheMemory(memory);
    status = MyRio_Close();

    return status;
}
Ejemplo n.º 2
0
Archivo: mips.c Proyecto: matsimon/RA
/* Initialize the "hardware" and operation and function dispatcher */
void initialize() {
	int i;
	/* Initialize operations */
	for (i=0; i<OPERATION_COUNT; ++i) {
		assignOperation(i, "ndef", specialType, &undefinedOperation);
	}
	assignOperation(OC_ZERO, "zero", rType, &opCodeZeroOperation);
	/* To stop the MIPS machine */
	assignOperation(OC_STOP,"stop", specialType, &stopOperation);
	
	assignOperation(OC_ADDI, "addi", iType, &mips_addi);
	assignOperation(OC_LUI, "lui", iType ,&mips_lui);
	assignOperation(OC_LW, "lw", iType, &mips_lw);
	assignOperation(OC_ORI, "ori", iType, &mips_ori);
	assignOperation(OC_SW, "sw", iType, &mips_sw);
	
	/* Initialize operations with OpCode = 0 and corresponding functions */
	for (i=0; i<FUNCTION_COUNT; ++i) {
		assignFunction(i, "ndef", &undefinedFunction);
	}
	assignFunction(FC_ADD, "add", &mips_add);
	assignFunction(FC_DIV, "div", &mips_div);
	assignFunction(FC_MULT, "mult", &mips_mult);
	assignFunction(FC_SUB, "sub", &mips_sub);
	
    	initializeMemory();
    
	/* Initialize registers */
	for (i=0; i<REGISTER_COUNT; ++i) {
		registers[i]= 0;
	}
	
	/* Stack pointer */
	SP=65535;
	
	/* Initialize program counter */
	pc = 0;
	
	/* Yes, we want the machine to run */
	doRun = TRUE;       
	
}
Ejemplo n.º 3
0
/*
The main program. Gets input for contiguous memory scheduler.
*/
int main()
{     
  int initBytes = 0;
  int numBytes = 0;
  int pid = 0;
  
  //Initialize memory and get rid of newline at the end
  scanf("%d", &initBytes);
  printf("%d\n", initBytes);
  
  initializeMemory(initBytes);
  
  //Grab the command and call the appropiate method
  char c = getchar();
  while(c != EOF)
  {
    if(!isspace(c))
      printf("%c\n", c);
    if(c == 'A') //allocate
    {
      scanf("%d", &numBytes);
      scanf("%d", &pid);    
			printf("%d %d\n", numBytes, pid);
			allocate(numBytes, pid);
    }
    else if(c == 'D') //deallocate
    {
      scanf("%d", &pid);
			printf("%d\n", pid);
  	  deallocate(pid);
    }
    else if(c == 'P') //print memory
      printMemory();
		else if(isspace(c))
			; // do nothing but don't hit the else
		else
			fprintf(stderr, "Invalid command, must be 'A' 'D' or 'P'");
		c = getchar();
  }
	return 0;
}
Ejemplo n.º 4
0
Archivo: gb.c Proyecto: gruzzle/gb
int main(int argc, const char* argv[]) {
  initializeMemory();
  initializeCPU();
  mainLoop();
}