Пример #1
0
void YOS_DbgPrintf(const char *format, ...) {
   va_list args;
   int iarg,len = 0;
   char *sarg;
   bool open;

   open=false;

   va_start (args, format);
   while(*format != 0) {
	   if (open) {
		   switch(*format) {
		   	   case '%':
		   		   YOS_DbgPutc('%');
		   		   open = false;
		   		   break;

		   	   case 'X':
		   		   len |= 0x200;
		   		   /* no break */

		   	   case 'x':
		   		   iarg = va_arg(args,int);
		   		   print_i(iarg,16,len);
		   		   open = false;
		   		   break;

		   	   case 'd':
		   		   iarg = va_arg(args,int);
		   		   print_i(iarg,10,len);
		   		   open = false;
		   		   break;

		   	   case 's':
		   		   sarg = va_arg(args,char*);
		   		   YOS_DbgPuts(sarg);
		   		   open = false;
		   		   break;

		   	   case '0':
		   		   len |= 0x100;
		   		   break;

		   	   default:
		   		   if (*format > '0' && *format <= '9') {
		   			   len |= (int)(*format-0x30);
		   		   }
		   		   break;
		   }
	   } else if (*format == '%') {
		   open = true;
		   len = 0;
	   } else {
		   if (*format == '\n')
			   YOS_DbgPutc('\r');
		   YOS_DbgPutc(*format);
	   }
	   format++;
   }
Пример #2
0
int main(int argc, char const* argv[])
{ 
	const int n=15;
	int a[n]={11,7,3,9,14,90,12,5,15,10,2,8,1,4,6};

	printf("before sort:\n");
	print_i(n,a);

	heapsort3(n,a); 

	printf("after sort:\n");
	print_i(n,a);

	return 0;
}
/*
* Parcours en parcours_en_profondeur
*/
void parcours_en_profondeur(tGraphe graphe, tNumeroSommet sommet, char *outfile){
  tTabCouleurs couleurs;
  tPileSommets pile;
  tNumeroSommet xSommet;

  int i[MAX_SOMMETS];
  int nSommet = grapheNbSommets(graphe);
  int entrer;

  /* On Initialise les couleurs et l'indice i*/
  init_parcours(graphe, couleurs, i, nSommet);
  /* On dépile tout en affichant */
  pile = pileSommetsAlloue();

  /* On colorie le promier sommet en vert et on l'enpile */
  couleurs[sommet] = VERT;
  pileSommetsEmpile(pile, sommet);

  while (!pileSommetsEstVide(pile)) {
    graphe_visu_color(graphe, couleurs, outfile);
    xSommet = pileSommetsTete(pile);
    traitement_pile(pile, xSommet, i, graphe, couleurs);
    scanf("%d", &entrer);
  }
  graphe_visu_color(graphe, couleurs, outfile);
  pileSommetsLibere(pile);
  printf("resultat du parcours en profondeur: ---------------------------------------\n");
  print_i(graphe, i, nSommet);
}
Пример #4
0
int main(int argc, char const* argv[])
{ 
	const int n=15;
	int a[n]={11,7,3,9,14,90,12,5,15,10,2,8,1,4,6};

	printf("before sort:\n");
	print_i(n,a);

	srand((unsigned int)time(0));
	quicksort(n,a); 

	printf("after sort:\n");
	print_i(n,a);

	return 0;
}
Пример #5
0
void do_op(char C)
{
  switch(C)
  {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9': push(C-'0'); break;
    case '+': addition(); break;
    case '-': subtraction(); break;
    case '*': multiplication(); break;
    case '/': division(); break;
    case '%': modulo(); break;
    case '^': north(); break;
    case '>': east(); break;
    case 'V':
    case 'v': south(); break;
    case '<': west(); break;
    case '?': spin(); break;
    case '!': lnot(); break;
    case '`': gt(); break;
    case '_': hif(); break;
    case '|': vif(); break;
    case '"': tsm(); break;
    case ':': dup(); break;
    case '\\': swap(); break;
    case '$': chomp(); break;
    case '#': jump(); break;
    case 'p': put(); break;
    case 'g': get(); break;
    case 'H': gate(); break;
    case '.': print_i(); break;
    case ',': print_c(); break;
    case '&': input_i(); break;
    case '~': input_c(); break;
    case '@': hacf(); break;
    case '{': left_b(); break;
    case '}': right_b(); break;
    case '[': carry_l(); break;
    case ']': carry_r(); break;
    case ';': empty(); break;
    case 'O': portal_o(); break;
    case 'B': portal_b(); break;
    default: /* DO NOTHING! */ break;
  }
}
Пример #6
0
void print_hi(struct buffer *b)
/*@ requires [?f]buffer(?id, b) &*& token(?t1) &*& split(t1, ?th1, ?ti1)
          &*& putchar_io(id, th1, 'h', ?th2)
          &*& putchar_io(id, ti1, 'i', ?ti2)
          &*& join(th2, ti2, ?t2); @*/
//@ ensures [f]buffer(id, b) &*& token(t2);
{
  //@ split();
  //@ close thread_run_pre(print_h)(b, pair(f/2, pair(id, pair(th1, th2))));
  struct thread *thread = thread_start_joinable(print_h, b);
  print_i(b);
  thread_join(thread);
  //@ open thread_run_post(print_h)(b, pair(f/2, pair(id, pair(th1, th2))));
  //@ join();
}
Пример #7
0
// main 
int main (void)
{
    // Open dictionary    
    FILE* file = fopen("large_dictionary.txt", "r");

    /* begin loop to read words from file.  "143091" is being hard coded in as 
       the known value of total words in the file. */
    for (int i = 0; i < 143091; i++)
    {
        // allocate new node and check for NULL
        node* new_node = malloc(sizeof(node)); {if (new_node == NULL) return false;}
    
        // scan word from file into the "word" portion of the new node struct
        fscanf(file, "%s", new_node->word);
        
        // initial insertion scenario (i.e., the spot in the table array is empty)
        if (table[hash(new_node->word)] == NULL)  {table[hash(new_node->word)] = new_node;}
    
        /* otherwise, put the new string in the first position and link the
           previous node to the new head of the list */
        else 
        {
            // create a node equal to the current value of the table
            node* curr = table[hash(new_node->word)];  
            /* point "new_node" (the struct holding the value of the desired
               word to be inserted) to the newly created node that equals what
               to this point was the start of the list */ 
            new_node->next = curr;
            /* set the head pointer of the "k"th spot in the array (i.e., the 
               "head") to be the node containing the desired string to be 
               inserted.  */ 
            table[hash(new_node->word)] = new_node;
        }        
    }
    printf(".\n\n\n");

    // prompt the user to print dictionary
    
    // switch case
    while (true)
    {
        printf("\nPlease enter a valid option\n"); 
        printf("\n 1 - Quit\n"); 
        printf("\n 2 - Print a letter of the dictionary\n");
        printf("\n 3 - Print the full dictionary\n");
        printf("\n 4 - Check to see if a specific word is in the dictionary\n\n");
        int option = GetInt();

        switch (option)
        {
            // quit
            case 1: free_table(); printf("\nGoodbye!\n\n"); fclose(file); return 0;
            
            // print an individual section ("Letter") of the dictionary
            case 2: printf("\nWhich letter of the dictionary would you like to print?\n\n"); // prompt user
                    char* c = GetString(); // get string from user
                    int alpha = c[0];
                    if (isalpha(alpha) == 0) {printf("\nNot a letter!\n"); break;}
                    int h = hash(c); // determine hash key
                    print_i(h); free(c); break; // print table for letter & free memory

            // print dictionary
            case 3: print_all(); break;
            
            case 4: printf("\nWhich word would you like to check?\n\n"); // prompt user
                    char* w = GetString(); // get string from user
                    // check the first character of the word to avoid seg fault                   
                    if (isalpha(w[0]) == 0) {printf("\nThat's not a word!\n"); free(w); break;}
                    check(w); free(w); break; // check word and free memory   

            default: printf("Not a valid option.\n"); break;
        }   
    }  
} 
Пример #8
0
void ls(char* fp,char* dotPath, int type){
  int count , ind;
  struct direct **files;
  int file();
  count = scandir(fp, &files, file, alphasort);
  if(count <=0){
    
    printf("No files in the directory \n");
    chdir("..");
    getwd(path);
    return;
  };
  getwd(path);
  for(ind=0;ind < count;++ind){
      if(type== -1 || type == 3){
        if((ind%5)==0) printf("\n");
        print_name(files[ind]->d_name);
      }
            
      if(type==1 || type == 6){
        if((ind%3)==0) printf("\n");
        print_i(files[ind]->d_name);
       }
       
      if(type==2 || type == 9 ){
       //printf(" total %d \n", count);
       file_info(files[ind]->d_name);
      }
      
      if(type==5 || type == 12){
      
       inode(files[ind]->d_name);
       file_info(files[ind]->d_name);
      }
  }
  
 
 if((type%3)==0){
  

  char str[MAXPATHLEN];

  char temp[MAXPATHLEN];
  strcpy(temp,dotPath);
  
  for(ind=0;ind < count;++ind){ 
      
      strcpy(dotPath,temp); 
      strcat(dotPath,"/");
       
      if(is_directory(files[ind]->d_name)){
      
      strcat(dotPath,files[ind]->d_name);   
      printf("\n\n%s :\n",dotPath);
        
         getwd(str);
         strcat(str,"/");
         strcat(str,files[ind]->d_name);
         chdir(str);
        // printf(" directory changed to %s \n",str);
                                    
         ls(str,dotPath,type);
        
       };
  
   }
           
   
   chdir(".."); 
 } 
   printf("\n"); //flush buffer      
   getwd(path);
   //printf(" directory changed back to to %s \n",path); 
  
  return;      
}
/*!
 * \brief main function : do init and loop (poll if configured so)
 */
int main(void)
{
	char temp[20];
	char *ptemp;

	static const gpio_map_t USART_GPIO_MAP = {
		{EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
		{EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
	};

	/* USART options */
	static const usart_options_t USART_OPTIONS = {
		.baudrate     = 57600,
		.charlength   = 8,
		.paritytype   = USART_NO_PARITY,
		.stopbits     = USART_1_STOPBIT,
		.channelmode  = 0
	};

#if BOARD == UC3L_EK
	scif_osc32_opt_t opt = {
		/* 
		 * 2-pin Crystal connected to XIN32/XOUT32 and high current
		 * mode.
		 */
		SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR,
		/* oscillator startup time */
		AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC,
		/* 
		 * select alternate xin32_2 and xout32_2 for 32kHz crystal
		 * oscillator 
		 */
		true,
		/* disable the 1kHz output */
		false,
		/* enable the 32kHz output */
		true
	};

#else
	scif_osc32_opt_t opt;
	opt.mode = SCIF_OSC_MODE_2PIN_CRYSTAL;
	opt.startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC;
#endif

#if BOARD == UC3L_EK

	/*
	 * Note: on the AT32UC3L-EK board, there is no crystal/external clock
	 * connected to the OSC0 pinout XIN0/XOUT0. We shall then program the
	 * DFLL and switch the main clock source to the DFLL.
	 */
	pcl_configure_clocks(&pcl_dfll_freq_param);

	/*
	 * Note: since it is dynamically computing the appropriate field values
	 * of the configuration registers from the parameters structure, this
	 * function is not optimal in terms of code size. For a code size
	 * optimal solution, it is better to create a new function from
	 * pcl_configure_clocks_dfll0() and modify it to use preprocessor
	 * computation from pre-defined target frequencies.
	 */
#else
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
#endif

	/* Start OSC_32KHZ */
	scif_start_osc32(&opt, true);

	/* Assign GPIO pins to USART0. */
	gpio_enable_module(USART_GPIO_MAP,
			sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

	/* Initialize USART in RS232 mode */
	usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FPBA);

	/* Welcome message */
	usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n");
	usart_write_line(EXAMPLE_USART, "AVR32 UC3 - AST example\r\n");

	usart_write_line(EXAMPLE_USART,
			"AST 32 KHz oscillator program test.\r\n");

	ast_calendar_t ast_calendar;
	ast_calendar.FIELD.sec  = 0;
	ast_calendar.FIELD.min  = 15;
	ast_calendar.FIELD.hour = 12;
	ast_calendar.FIELD.day  = 5;
	ast_calendar.FIELD.month = 6;
	ast_calendar.FIELD.year = 9;

	/* Initialize the AST */
	if (!ast_init_calendar(&AVR32_AST,
			AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_calendar)) {
		usart_write_line(EXAMPLE_USART,
				"Error initializing the AST\r\n");
		while (1) {
		}
	}

	/* Enable the AST */
	ast_enable(&AVR32_AST);

	volatile int i;
	while (1) {
		/* slow down operations */
		for (i = 0; i < 10000; i++) {
		}
		gpio_tgl_gpio_pin(LED0_GPIO);

		/* Set cursor to the position (1; 5) */
		usart_write_line(EXAMPLE_USART, "\x1B[5;1H");
		ast_calendar = ast_get_calendar_value(&AVR32_AST);
		usart_write_line(EXAMPLE_USART, "Timer: ");
		ptemp = print_i(temp, ast_calendar.FIELD.sec);
		usart_write_line(EXAMPLE_USART, ptemp);
		usart_write_line(EXAMPLE_USART, " sec ");
	}
}
Пример #10
0
/*!
 * \brief main function : do init and loop (poll if configured so)
 */
int main(void)
{
	char temp[20];
	char *ptemp;
	uint32_t ast_alarm;

	static const gpio_map_t USART_GPIO_MAP = {
		{EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
		{EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
	};

	/* USART options */
	static const usart_options_t USART_OPTIONS = {
		.baudrate     = 57600,
		.charlength   = 8,
		.paritytype   = USART_NO_PARITY,
		.stopbits     = USART_1_STOPBIT,
		.channelmode  = 0
	};

#if BOARD == UC3L_EK
	scif_osc32_opt_t opt = {
		/* 2-pin Crystal connected to XIN32/XOUT32 and high current
		 * mode. */
		SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR,
		/* oscillator startup time */
		AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC,
		/* select alternate xin32_2 and xout32_2 for 32kHz crystal
		 * oscillator */
		true,
		/* disable the 1kHz output */
		false,
		/* enable the 32kHz output */
		true
	};
#else
	scif_osc32_opt_t opt;
	opt.mode = SCIF_OSC_MODE_2PIN_CRYSTAL;
	opt.startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC;
#endif

#if BOARD == UC3L_EK

	/*
	 * Note: on the AT32UC3L-EK board, there is no crystal/external clock
	 * connected to the OSC0 pinout XIN0/XOUT0. We shall then program the
	 * DFLL and switch the main clock source to the DFLL.
	 */
	pcl_configure_clocks(&pcl_dfll_freq_param);

	/*
	 * Note: since it is dynamically computing the appropriate field values
	 * of the configuration registers from the parameters structure, this
	 * function is not optimal in terms of code size. For a code size
	 * optimal solution, it is better to create a new function from
	 * pcl_configure_clocks_dfll0() and modify it to use preprocessor
	 * computation from pre-defined target frequencies.
	 */
#else
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
#endif

	/* Start OSC_32KHZ */
	scif_start_osc32(&opt, true);

	/* Assign GPIO pins to USART0. */
	gpio_enable_module(USART_GPIO_MAP,
			sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

	/* Initialize USART in RS232 mode */
	usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FPBA);

	/* Welcome sentence // 2-pin Crystal and high current mode. */
	/* Crystal is connected to XIN32/XOUT32. */
	usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n");
	usart_write_line(EXAMPLE_USART, "AVR32 UC3 - AST example 2\r\n");
	usart_write_line(EXAMPLE_USART,
			"AST 32 KHz oscillator counter example.\r\n");
	usart_write_line(EXAMPLE_USART,
			"Alarm0 wakeup from static sleep mode every second.\r\n");

	/* Using counter mode and set it to 0 */
	unsigned long ast_counter = 0;

	/* Initialize the AST */
	if (!ast_init_counter(&AVR32_AST,
			AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_counter)) {
		usart_write_line(EXAMPLE_USART,
				"Error initializing the AST\r\n");
		while (1) {
		}
	}

	/* Alarm 0 sends a wakeup signal to the Power manager */
	ast_enable_alarm_async_wakeup(&AVR32_AST, 0);

	/* Enable the AST */
	ast_enable(&AVR32_AST);

	while (1) {
		/* disable alarm 0 */
		ast_disable_alarm0(&AVR32_AST);

		/* ast_init_counter Set Alarm to current time+30 seconds */
		ast_alarm = ast_counter + 1;
		ast_set_alarm0_value(&AVR32_AST, ast_alarm);

		/* Enable alarm 0 */
		ast_enable_alarm0(&AVR32_AST);

		/*
		 * Precautions when entering a sleep mode
		 * Modules communicating with external circuits should normally
		 * be disabled before entering a sleep mode that will stop the
		 * module operation.
		 * Make sure the USART dumps the last message completely before
		 * turning it off.
		 */
		while (!usart_tx_empty(EXAMPLE_USART)) {
		}
		pcl_disable_module(EXAMPLE_USART_CLOCK_MASK);

		/*
		 * Since we're going into a sleep mode deeper than IDLE, all HSB
		 * masters must be stopped before entering the sleep mode.
		 * Note: since we're not using the PDCA, we don't have to stop
		 *it.
		 */

		/*
		 * If there is a chance that any PB write operations are
		 *incomplete,
		 * the CPU should perform a read operation from any register on
		 *the
		 * PB bus before executing the sleep instruction.
		 */
		AVR32_INTC.ipr[0];  /* Dummy read */

		/* Go into static sleep mode */
		SLEEP(AVR32_PM_SMODE_STATIC);

		/* We're out of the static sleep mode now => re-enable the USART
		 * module */
		pcl_enable_module(EXAMPLE_USART_CLOCK_MASK);

		/* After wake up, clear the Alarm0 */
		ast_clear_alarm_status_flag(&AVR32_AST, 0);

		/* Toggle Led0 */
		gpio_tgl_gpio_pin(LED0_GPIO);

		/* Set cursor to the position (1; 6) */
		usart_write_line(EXAMPLE_USART, "\x1B[6;1H");
		ast_counter = ast_get_counter_value(&AVR32_AST);
		usart_write_line(EXAMPLE_USART, "Timer: ");
		ptemp = print_i(temp, ast_counter);
		usart_write_line(EXAMPLE_USART, ptemp);
		usart_write_line(EXAMPLE_USART, " sec ");
	}
}
Пример #11
0
/*!
 * \brief main function : do init and loop (poll if configured so)
 */
int main( void )
{
  char temp[20];
  char *ptemp;

  static const gpio_map_t USART_GPIO_MAP =
  {
    {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
    {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
  };

  // USART options
  static const usart_options_t USART_OPTIONS =
  {
    .baudrate     = 57600,
    .charlength   = 8,
    .paritytype   = USART_NO_PARITY,
    .stopbits     = USART_1_STOPBIT,
    .channelmode  = 0
  };

  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Assign GPIO pins to USART0.
  gpio_enable_module(USART_GPIO_MAP,
                     sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

  // Initialize USART in RS232 mode at 12MHz.
  usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, 12000000);

  // Welcome sentence
  usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n");
  usart_write_line(EXAMPLE_USART, "AVR32 UC3 - RTC example\r\n");

  usart_write_line(EXAMPLE_USART, "RTC 32 KHz oscillator program test.\r\n");

  // Disable all interrupts. */
  Disable_global_interrupt();

  // The INTC driver has to be used only for GNU GCC for AVR32.
#if __GNUC__
  // Initialize interrupt vectors.
  INTC_init_interrupts();

  // Register the RTC interrupt handler to the interrupt controller.
  INTC_register_interrupt(&rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT0);
#endif

  // Initialize the RTC
  if (!rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ))
  {
    usart_write_line(&AVR32_USART0, "Error initializing the RTC\r\n");
    while(1);
  }
  // Set top value to 0 to generate an interrupt every seconds */
  rtc_set_top_value(&AVR32_RTC, 0);
  // Enable the interrupts
  rtc_enable_interrupt(&AVR32_RTC);
  // Enable the RTC
  rtc_enable(&AVR32_RTC);

  // Enable global interrupts
  Enable_global_interrupt();

  while(1)
  {
    if (print_sec)
    {
      // Set cursor to the position (1; 5)
      usart_write_line(EXAMPLE_USART, "\x1B[5;1H");
      ptemp = print_i(temp, sec);
      usart_write_line(EXAMPLE_USART, "Timer: ");
      usart_write_line(EXAMPLE_USART, ptemp);
      usart_write_line(EXAMPLE_USART, "s");
      print_sec = 0;
    }
  }
}