Ejemplo n.º 1
0
/* *** External visible functions *** */
void elect()
{
	// Delete current if terminated (so a terminated process does not wait at the end of list)
	if (current_process->status == TERMINATED)
	{
		terminate_if_last_process();

		current_process->previous->next = current_process->next;
		current_process->next->previous = current_process->previous;
		
		struct pcb_s* process_to_delete = current_process;
		
		choose_next_process();
		
		free_process(process_to_delete);
	}
	else if (current_process->status  == BLOCKED)
	{
		choose_next_process();
	}
	else
	{
		current_process->status = READY;
		choose_next_process();
	}
	
	#if DEBUG
	#if FB
		fb_print_char('\n');
		fb_print_text("The process with PID ");
		fb_print_int(current_process->pid);
		fb_print_text(" chosen with priority ");
		fb_print_int(current_process->priority);
		fb_print_char('\n');
		
	#else
		
		log_str("\n The process with PID ");
		log_int(current_process->pid);
		log_str(" chosen with priority ");
		log_int(current_process->priority);
		log_str("\n");
		
	#endif	
	#endif
	
	if (current_process->status == TERMINATED || current_process->status  == BLOCKED)
		elect(); // Elect the next one, and delete the current one
	else
		current_process->status = RUNNING; // Else, this one is now running
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*-
   fb_print_string
  -----------------------------------------------------------------------------
   Descriptif: Cette fonction permet d'afficher un texte (une chaîne de caractère)
   	   	   	   sur l'afficheur LCD. La fonction gère automatiquement le retour
   	   	   	   à la ligne si le texte est trop long ou si le caractère '\n' est
   	   	   	   présent.

   Remarque  : Il faut faire attention car aucun contrôle de dépassement du
    		   texte en bas de l'écran est effectué

   Entrée    : int color 					: couleur choisie.
   	   	   	   int color_fond 				: couleur de fond
      	   	   unsigned char *ptr_texte 	: texte à afficher
   	   	   	   int x 						: position de départ en x sur l'afficheur
   	   	   	   int y 						: position de déaprt en y sur l'afficheur
   Sortie    : Aucune
-*---------------------------------------------------------------------------*/
void fb_print_string(int color, int color_fond, unsigned char *ptr_texte, int x, int y)
{
	unsigned char pos_car = 0;			// Position du caractère sur l'afficheur.
	unsigned char pos_car_ligne = 0;	// Position d'un caractère au sein d'une ligne de l'afficheur.

	// Tant que la chaîne de caractère n'a pas été complétement parcourue
	while(*(pos_car + ptr_texte) != '\0')
	{
		// Si le caractère de retour à la ligne est présent
		if(*(pos_car + ptr_texte) == '\n')
		{
			pos_car_ligne = 0;
			x = 0;
			y += 10;
			pos_car++;
			continue;
		}
		// Si le nombre maximum de caractère est présent sur la ligne (30 caractères)?
		else if(((pos_car_ligne % 30) == 0) && pos_car_ligne)
		{
			pos_car_ligne = 0;
			x = 0;
			y += 10;
		}

		// Affichage du caractère sur l'afficheur LCD
		fb_print_char(color,color_fond, *(ptr_texte + pos_car), x + (8*pos_car_ligne), y);
		pos_car++;
		pos_car_ligne++;
	}
}
Ejemplo n.º 3
0
// ------------------------------------------------------------------
// fb_print_string prints a string at the specified location.
//
void
fb_print_string(uchar *pcbuffer, ulong x, ulong y, uchar color)
{
    // loop through each character in the string.
    while(*pcbuffer)
    {
        // print this character.
        fb_print_char(*pcbuffer++, x, y, color);

        // advance horizontaly past this character.
        x += FONT_WIDTH;
    }
}
Ejemplo n.º 4
0
int start_shell()
{
	int argc;
	
	while (1)
	{
		fb_prompt();
		sem_up(&cmd_buffer_sem);

		sem_down(&shell_sem); // wait until shell is ready

		char** args = parse_command(cmd_buffer, &argc);

		command_t* command = find_command(args[0]);
		if (command == NULL)
		{
			fb_print_text("Command not found\n");
		}
		else
		{
			/*fb_print_text("BEFORE FORK\n");
			int pid = sys_fork();
			fb_print_text("AFTER FORK\n");
			if (pid == 0)
			{
				command(argc-1, args+1); // skip command name
				sys_exit(0);
			}
			else
			{
				int cmd_status;
				sys_waitpid(pid, &cmd_status);
				fb_print_char('\n');
				// TODO fill shell variable of last return code: $?
			}*/
			command(argc-1, args+1);
			fb_print_char('\n');
		}
	}

	return 0;
}