Example #1
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *io = pruio_new(PRUIO_ACT_PRU1, 0, 0, 0); //! create new driver structure
  do {
    uint32 pru_num, pru_iram, pru_dram, pru_intr;
//
// Check init success
//
    if(io->Errr) {
               printf("initialisation failed (%s)\n", io->Errr); break;}

    if(io->PruNo) { //                              we use the other PRU
      pru_num = 0;
      pru_iram = PRUSS0_PRU0_IRAM;
      pru_dram = PRUSS0_PRU0_DRAM;
      pru_intr = PRU0_ARM_INTERRUPT; }
    else {
      pru_num = 1;
      pru_iram = PRUSS0_PRU1_IRAM;
      pru_dram = PRUSS0_PRU1_DRAM;
      pru_intr = PRU1_ARM_INTERRUPT; }
//
// Now prepare the other PRU
//
    if(prussdrv_open(PRU_EVTOUT_0)) { // note: libpruio uses PRU_EVTOUT_5
                               printf("prussdrv_open failed\n"); break;}
    //Note: no prussdrv_pruintc_init(), libpruio did it already

    load_firmware(pru_iram);
//
// Pass parameters to PRU
//
    uint32 *dram;
    prussdrv_map_prumem(pru_dram, (void *) &dram); // get dram pointer
    dram[1] = 23; // start value
    dram[2] = 7;  // value to add
    dram[3] = 67; // loop count (max 16 bit = 65536)
    dram[4] = pru_intr + 16; // the interrupt we're waiting for
//
// Execute
//
    printf("instructions loaded, starting PRU-%d\n", pru_num);
    prussdrv_pru_enable(pru_num); // start
    prussdrv_pru_wait_event(PRU_EVTOUT_0); // wait until finished
    prussdrv_pru_clear_event(PRU_EVTOUT_0, pru_intr); // clear interrupt (optional, useful when starting again)
//
// Check result
//
    if(dram[0] == (dram[1] + (dram[2] * dram[3])))
      {printf("Test OK %d == %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}
    else
      {printf("Test failed: %d != %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}

    prussdrv_pru_disable(pru_num); // disable PRU
    // note: no prussdrv_exit(), libpruio does it in the destructor
  } while (0);

  pruio_destroy(io);        /* destroy driver structure */
	return 0;
}
Example #2
0
void init(){
   // Check if device tree overlay is loaded, load if needed.
   int device_tree_overlay_loaded = 0; 
   FILE* f;
   f = fopen("/sys/devices/bone_capemgr.9/slots","rt");
   if(f==NULL){
      printf("Initialisation failed (fopen rt)");
      exit(1);
   }
   char line[256];
   while(fgets(line, 256, f) != NULL){
      if(strstr(line, "SAMPLE-DTO") != NULL){
         device_tree_overlay_loaded = 1; 
      }
   }
   fclose(f);

   if(!device_tree_overlay_loaded){
      f = fopen("/sys/devices/bone_capemgr.9/slots","w");
      if(f==NULL){
         printf("Initialisation failed (fopen)");
         exit(1);
      }
      fprintf(f, "SAMPLE-DTO");
      fclose(f);
      usleep(100000);
   }

   // Init pruio instance
   io = pruio_new(0, 0x98, 0, 1);
   if (io->Errr) {
      printf("Initialisation failed (%s)\n", io->Errr);
      exit(1); 
   } 
}
Example #3
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  do {
    if (io->Errr) {
               printf("initialisation failed (%s)\n", io->Errr); break;}

    if (pruio_config(io, 1, 0x1FE, 0, 4)) {
                       printf("config failed (%s)\n", io->Errr); break;}

    struct termios oldt, newt; //             make terminal non-blocking
    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag &= ~( ICANON | ECHO );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 0;
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);

    while(!isleep(1)) { //                      run loop until keystroke
      printf("\r%1X", pruio_gpio_Value(io, PIN));
      fflush(STDIN_FILENO);
    }
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt); //           reset terminal

    printf("\n");
  } while (0);

  pruio_destroy(io);       /* destroy driver structure */
	return 0;
}
Example #4
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! ouvrir l'interruption Pruss (/ dev / uio5),charger les instructions de pasm_init.p au PRU et les exécute, et appeler les fonctions initialize des UDT du sous-système.
  do {
    if (Io->Errr) {
               printf("initialisation failed (%s)\n", Io->Errr); break;}

    if (pruio_cap_config(Io, P_IN, 2.)) { //         Cette fonction configure un axe d'en-tête pour la capture et Analyse Pulse (CAP) trains. La configuration des broches est vérifié. Si elle est pas configuré comme entrée pour le module de la Cap dans le sous-système PWM, libpruio essaie d'adapter le muxing broches.
          printf("failed setting input @P_IN (%s)\n", Io->Errr); break;}

    float_t
        f1 //                         Variable for calculated frequency.
      , d1 //                        Variable for calculated duty cycle.
      , f0 = 31250 //                            The required frequency.
      , d0 = .5;   //                           The required duty cycle.
      
    if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //Cette fonction définit la sortie PWM sur une broche d'en-tête. sortie PWM peuvent être soit générés par un eHRPWM ou d'un module eCAP. En fonction du nombre de broches spécifié (paramètre à billes), le module PWM correspondant est configuré pour la fréquence et le rapport cyclique déterminé.
        printf("failed setting output @P_OUT (%s)\n", Io->Errr); break;}


    if (pruio_config(Io, 1, 0x1FE, 0, 4)) { //Cette fonction est utilisée pour télécharger la configuration de l'hôte (ARM) au conducteur (PRU). Le PRU s'arrêté (si en cours d'exécution) et les nouvelles configurations se charger. Aussi les instructions Pru_Run se ré-initialisés.
                       printf("config failed (%s)\n", Io->Errr); break;}

    struct termios oldt, newt; //             make terminal non-blocking
    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    while(1) { //                                       run endless loop
      if (1 == isleep(1)) {
        
        if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //   set new output
           printf("failed setting PWM output (%s)\n", Io->Errr); break;}

        printf("\n--> Frequency: %10f , Duty: %10f\n", f0, d0); //  info
      }

      if (pruio_cap_Value(Io, P_IN, &f1, &d1)) { //    get current input
          printf("failed reading input @P_IN (%s)\n", Io->Errr); break;}

      printf("\r    Frequency: %10f , Duty: %10f     ", f1, d1); // info
      fflush(STDIN_FILENO);
    }

finish:
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); //         reset terminal

    printf("\n");
  } while (0);

  pruio_destroy(Io);       /* destroy driver structure */
	return 0;
}
Example #5
0
//-------------------------------! The main function.
int main(int argc, char **argv)
{	char *ret;
	uint32 Samp, Mask, Tmr;
	uint16 Mds;
    pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); 				// create new driver structure

    if (Io->Errr)
    {	printf("initialisation failed (%s)\n", Io->Errr);
    }

    //pin config OK, transfer local settings to PRU and start
    //char* pruio_config(pruIo* Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds);
    Samp = 1;
    Mask = 0x1FE;
    Tmr = 0;
    Mds = 4;
    ret = pruio_config(Io, Samp, Mask, Tmr, Mds);
    if (ret)	//pruio_config(Io, 1, 0x1FE, 0, 4))
    {   printf("config failed (%s)\n", Io->Errr);
    }
    /*=============================================
//  char* pruio_gpio_setValue(pruIo* Io, uint8 Ball, uint8 Modus);
    ret = pruio_gpio_setValue(Io, P_FANA, 1);	//
	if (ret)	   // set HIGH to turn off fan
	{   printf("failed setting PWMA output (%s)\n", Io->Errr);
	}
    ret = pruio_gpio_setValue(Io, P_FANB, 1);
	if (ret)	   // set HIGH to turn off fan
	{   printf("failed setting PWMB output (%s)\n", Io->Errr);
	}
============================================*/

    ret = pruio_gpio_setValue(Io, P_FANA, 1);	//
	if (ret)	   // set HIGH to turn off fan
	{   printf("failed setting PWMA output (%s)\n", Io->Errr);
	}
    ret = pruio_gpio_setValue(Io, P_FANB, 1);
	if (ret)	   // set HIGH to turn off fan
	{   printf("failed setting PWMB output (%s)\n", Io->Errr);
	}

	sleep(5);
    pruio_destroy(Io);       /* destroy driver structure */
	return 0;
}
Example #6
0
File: 1.c Project: DTJF/libpruio
//! The main function.
int main(int argc, char **argv)
{
  int i, n;
  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0); //! create new driver structure
  if (pruio_config(io, 1, 0x1FE, 0, 4)){ // upload (default) settings, start IO mode
                              printf("config failed (%s)\n", io->Errr);}
  else {

/* now current ADC samples are available for AIN-0 to AIN-7 in array io->Adc->Value[] */
    for(n = 1; n <= 13; n++) { //                       print some lines
      for(i = 1; i < 9; i++) //                                all steps
        printf(" %4X", io->Adc->Value[i]); //  output one channel in hex
      printf("\n"); //                                         next line
    }
  }
/* we're done */

  pruio_destroy(io);        /* destroy driver structure */
	return 0;
}
Example #7
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  do {
    if (Io->Errr) {
               printf("initialisation failed (%s)\n", Io->Errr); break;}

    if (pruio_cap_config(Io, P_IN, 2.)) { //         configure input pin
          printf("failed setting input @P_IN (%s)\n", Io->Errr); break;}

    float_t
        f1 //                         Variable for calculated frequency.
      , d1 //                        Variable for calculated duty cycle.
      , f0 = .5 //                            The required frequency.
      , d0 = .5;   //                           The required duty cycle.
    if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) {
        printf("failed setting output @P_OUT (%s)\n", Io->Errr); break;}

    //           pin config OK, transfer local settings to PRU and start
    if (pruio_config(Io, 1, 0x1FE, 0, 4)) {
                       printf("config failed (%s)\n", Io->Errr); break;}

    struct termios oldt, newt; //             make terminal non-blocking
    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    while(1) { //                                       run endless loop
      if (1 == isleep(1)) {
        switch (getchar()) { //                       evaluate keystroke
          case '0' : d0 = 0.0; break;
          case '1' : d0 = 0.1; break;
          case '2' : d0 = 0.2; break;
          case '3' : d0 = 0.3; break;
          case '4' : d0 = 0.4; break;
          case '5' : d0 = 0.5; break;
          case '6' : d0 = 0.6; break;
          case '7' : d0 = 0.7; break;
          case '8' : d0 = 0.8; break;
          case '9' : d0 = 0.9; break;
          case ',' : d0 = 1.0; break;
          case 'm' : f0 = (f0 > 5.5 ? f0 - 5. : .5); break;
          case 'p' : f0 = (f0 < 999995. ? f0 + 5. : 1000000.); break;
          case '*' : f0 = (f0 < 1000000 ? f0 * 2 : 1000000.); break;
          case '/' : f0 = (f0 > .5 ? f0 / 2 : .5); break;
          case '+' : f0 = 1000000; break;
          case '-' : f0 = .5; break;
          default: goto finish;
        };
        if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //   set new output
           printf("failed setting PWM output (%s)\n", Io->Errr); break;}

        printf("\n--> Frequency: %10f , Duty: %10f\n", f0, d0); //  info
      }

      if (pruio_cap_Value(Io, P_IN, &f1, &d1)) { //    get current input
          printf("failed reading input @P_IN (%s)\n", Io->Errr); break;}

      printf("\r    Frequency: %10f , Duty: %10f     ", f1, d1); // info
      fflush(STDIN_FILENO);
    }

finish:
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); //         reset terminal

    printf("\n");
  } while (0);

  pruio_destroy(Io);       /* destroy driver structure */
	return 0;
}
Example #8
0
int main( int argc, char *argv[] )
{
    float temp;
    uint32 cur_time;
    uint32 start_time;
    float duty_cycle;
    float target_temp;
    char print_string[ 200 ];

    util_print_procId();

    force_stop = FALSE;
    door_open = FALSE;

    timer_init();

    if( argc != 2 )
    {
        util_print_debug( "Error: The only argument is the path to the JSON file.\n" );
        return( -1 );
    }

    //Set up signal handler:
    if( signal( SIGINT, signalHandler ) == SIG_ERR )
    {
        util_print_debug( "MPU: Error setting up ctrl-c interrupt.\n" );
        return( -1 );
    }

    util_print_debug( argv[ 1 ] );

    if( !pid_init( argv[ 1 ] ) )
    {
        util_print_debug( "Error: There was an error loading the profile.\n" );
        return( -1 );
    }

    pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);

    start_time = 0;
    cur_time = 0;
    duty_cycle = 1.0;

    if( pruio_config( io, 1, 0x1FE, 0, 4 ) )
    {
        sprintf( print_string, "config failed (%s)\n", io->Errr );
        util_print_debug( print_string );
        return( -1 );
    }
    
    pruio_pwm_setValue( io, P_OUT, PWM_FREQ, duty_cycle );
    pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE ); //close door

    while( !force_stop )
    {
        temp = util_calc_temp( io->Adc->Value[ 1 ] );
        target_temp = pid_find_target( cur_time / 1000.0 );
        duty_cycle = pid_calc( target_temp, temp );
        pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_IDLE );

        if( duty_cycle == -1 )
        {
            force_stop = TRUE;
        }

        // DOOR CRACKING CODE
        if ( ( temp - target_temp) > 5.0 )
        {
          // OPEN DOOR
            pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_OPEN );
            door_open = TRUE;
        }

        else if ( ( duty_cycle > 0.0 ) && door_open )
        {
          // CLOSE DOOR
            pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE );
            door_open = FALSE;
        }

        pruio_pwm_setValue( io, P_OUT, -1, duty_cycle );

        util_print_point( cur_time / 1000, target_temp, temp );

        //block for 2 seconds.
        while( ( cur_time - start_time <= PWM_PERIOD_MS ) && !force_stop )
        {
            if( !timer_get( &cur_time ) )
            {
                printf( "There was an error with the timer.\n" );
                return( 0 );
            }
        }

        start_time = start_time + PWM_PERIOD_MS;
    }

    // I WISH WE COULD WAIT UNTIL THE OVEN IS AT 100 DEGREES C TO CLOSE THIS DOWN
    pruio_pwm_setValue( io, P_OUT, -1, 0.0f );
    pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE ); // CLOSE THE DOOR
    
    // STALL BEFORE SHUTTING DOWN PWM
    timer_get( &start_time );
    cur_time = start_time;
    while( ( cur_time - start_time ) < 500 )
    {
        timer_get( &cur_time );
    }

    pruio_destroy(io);       /* destroy driver structure */ 
    
    return 0;
}
Example #9
0
//-------------------------------! The main function.
int main(int argc, char **argv)
{   float_t f1 = 500.0F; 			//      Variable for calculated frequency.
    float_t d1 = 0.9F; 				//      Variable for calculated duty cycle.
    float_t f0 = 500.0F;   			//      The required frequency.
    float_t d0 = .9F;    			//      The required duty cycle.
    float_t MINFREQ = 2.0F;         //
    char buffer[256], *msg = buffer;
    pruIo *Io;
    int charX=0;

    Io = pruio_new(PRUIO_DEF_ACTIVE, 16, 0x98, 0); 		//pruIo* pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD);
    pruio_destroy(Io);       							//destroy driver structure
    Io = pruio_new(PRUIO_DEF_ACTIVE, 16, 0x98, 0); 		//pruIo* pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD);

    //output GpioUdt::setValue PwmMod::setValue
    //input  GpioUdt::config   CapMod::config

    msg= pruio_pwm_setValue(Io, P_FANA, f0, d0);
    if(msg)printf("1%s\n",msg);	//char* pruio_pwm_setValue(pruIo* Io, uint8 Ball, float_t Hz, float_t Du);
    msg= pruio_pwm_setValue(Io, P_FANB, f0, d0);
    if(msg)printf("2%s\n",msg);	//char* pruio_pwm_setValue(pruIo* Io, uint8 Ball, float_t Hz, float_t Du);
    msg= pruio_config(Io, 1, 0x1FE, 1e6, 0);
    if(msg)printf("3%s\n",msg);	//char* pruio_config(pruIo* Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds);
    msg= pruio_cap_config(Io, (uint8)P_IN, MINFREQ);			//NO NON-FLOAT with decimal, get interpreted at double
    if(msg)printf("4%s\n",msg);	//char* pruio_cap_config(pruIo* Io, uint8 Ball, float_t FLow);


// not using ring buffer mode. couldn't get 2 PWM outputs to work with SAMP>1
// So TMR value is ignored
//	msg= pruio_rb_start(Io);						if(msg)printf("5%s\n",msg);	//char* pruio_rb_start(pruIo* Io);

	printf("Samples: %d\n",    Io->Adc->Samples);
	printf("TimerVal: %d ns\n",Io->Adc->TimerVal);
//	printf("Dram[0]= %d\n",Io->DRam[0] );			//most recent write position

    struct termios oldt, newt; //             make terminal non-blocking
    int localerr=0;
    if( 0>tcgetattr( STDIN_FILENO, &oldt ) )
   	{	localerr = errno;
    	printf("tcgetattr failed, error = %d\n",localerr);
   	}
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    int irun=1;
    while(irun)								// Terminate on ESC, else run endless loop
    {	if (1 == isleep(1000)) 				// got a char
    	{	charX = getchar();
    		switch (charX)					// evaluate keystroke
			{ 	case '0' : d0 = 0.0; break;
				case '1' : d0 = 0.1; break;
				case '2' : d0 = 0.2; break;
				case '3' : d0 = 0.3; break;
				case '4' : d0 = 0.4; break;
				case '5' : d0 = 0.5; break;
				case '6' : d0 = 0.6; break;
				case '7' : d0 = 0.7; break;
				case '8' : d0 = 0.8; break;
				case '9' : d0 = 0.9; break;
				case ',' : d0 = 1.0; break;
				case 'm' : f0 = (f0 > 5.5 ? f0 - 5. : .5); break;
				case 'p' : f0 = (f0 < 999995. ? f0 + 5. : 1000000.); break;
				case '*' : f0 = (f0 < 1000000 ? f0 * 2 : 1000000.); break;
				case '/' : f0 = (f0 > .5 ? f0 / 2 : .5); break;
				case '+' : f0 = 1000000; break;
				case '-' : f0 = .5; break;
				default: {irun = 0; break;}				//anything other than above, quit
			};

    		if(irun)
    		{	msg = pruio_pwm_setValue(Io, P_FANA, f0, d0);
				if(msg)
				{	printf("6failed setting PWMA output (%s)\n", Io->Errr); irun=0;
				}else
				{	printf("6\n");
				}
				msg = pruio_pwm_setValue(Io, P_FANB, f0, d0);
				if(msg)
				{	printf("7failed setting PWMB output (%s)\n", Io->Errr); irun=0;
				}else
				{	printf("7\n");
				}
    		}
    	}

    	if(irun)
    	{	  if (pruio_cap_Value(Io, P_IN, &f1, &d1)) 		//    get current input
			  {		printf("8failed reading input @P_IN=%d (%s)\n", P_IN, Io->Errr); break;
			  }
			   printf("Freq %6.1f Duty: %6.1f Freq: %6.1f Duty: %6.1f ADC: %4d %4d %4d\n", f0, d0, f1, d1,Io->Adc->Value[1],Io->Adc->Value[2],Io->Adc->Value[3]); // info
			  fflush(STDIN_FILENO);
    	}
    } //end while


    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); 		//         reset terminal
    printf("Exiting\n");

    if (pruio_pwm_setValue(Io, P_FANA, f0, 1))	   //   set new output
	{   printf("failed setting PWMA output (%s)\n", Io->Errr);
	}
    if (pruio_pwm_setValue(Io, P_FANB, f0, 1))	   //   set new output
	{   printf("failed setting PWMB output (%s)\n", Io->Errr);
	}

    pruio_destroy(Io);       					//destroy driver structure
	return 0;
}