Пример #1
0
istack pos_val(int* arr){
/*stores the possible values at a position in an integer stack and returns the stack*/
	istack s, *p, t;
	int val, random;
	random = get_random(4, 0);
	i_init(&s);
	i_init(&t);
	int i;
	
	for(i = 9; i > 0; i--){
		if(arr[i] == 0){
			i_push(&s, i);
		}
	}
	p = &s;
	if(random % 2 == 1){
		while(!i_empty(p)){
			val = i_pop(p);
			i_push(&t, val);
		}
		return t;
	}
	else if(random % 2 == 0){
		return s;
	}
}
Пример #2
0
// 将缓冲区的数据读入到内核态 ibuffer 中(i 缓冲区)
int sysio_read(uint8_t *ibuffer, iLinkQueue *ibuff, other *info)
{
	i_operate temp;

	if (i_empty(ibuff)) {
		return;
	} else {
		temp = i_DeQueue(ibuff);
		strcpy(ibuffer, temp.Inputbuffer);
		info->num = temp.Inputnum;
		info->pid = temp.Inputpid;
	}
}
Пример #3
0
// 这里进行模拟内核线程
void sys_pthread(void *temp)
{
	ioqueue *io = (ioqueue *)temp;
	uint32_t leap = 1;
	uint8_t input[BUFFSIZE];
	uint8_t output[BUFFSIZE];
	other info;

	info.pid = pthread_self();
	info.num = 0;
	while (leap)
	{
		// 扫描队列中是否有数据
		leap = 0;
		while (i_empty(io->iqueue))
		{
			sleep(SLEEPTIME);
		}

		pthread_mutex_lock(&imutex);
		// 从队列中获取数据
		sysio_read(input, io->iqueue, &info);
		pthread_mutex_unlock(&imutex);
		printf("systhread (UI:%d,PID:%u)(input)缓冲区->内核 : %s\n", info.num, info.pid, input);

		leap = 1;

		// 内核态处理逻辑(对用户输入的数据进行处理)
		printf("\n\n内核处理输入数据:%s\n\n", input);
		strcat(input, "(内核处理后的数据)");

		printf("systhread  (UI:%d,PID:%u)内核->(output)缓冲区 : %s\n", info.num, info.pid, input);
		pthread_mutex_lock(&omutex);
		// 用户向队列写数据
		sysio_write(input, io->oqueue, &info);
		pthread_mutex_unlock(&omutex);
	}
}
Пример #4
0
int solve(int **puz, int *x, int *y, int display){
/*solves the given sudoku stored in puz, returns 1 if solve successful, returns WRONG_IP if i/p was invalid*/
	int *p, s = 0, count = 0, r, q;
	srand(time(NULL));
	int i, j, val;
	istack w;
	char c, chk;
	pstack POS;
	init(&POS);
	chk = check_ip(puz);
	if(chk == WRONG_IP){
		return WRONG_IP;
	}
	if(x == NULL){
		i = j = 0;
	}
	else{
		i = *x;
		j = *y;
	}
	while(i != ROW){
		empty_cell(puz, &i, &j);
		if(!f.found){
			if(display){
				display_puz(puz);
				refresh();
			}
			return 1;	
		}
		p = scan(puz, i, j);
		if(p == NULL){
			return WRONG_IP;	
		}
		w = pos_val(p);
		check:
		if(i_empty(&w)){
			/*no possible values*/
			if(!empty(&POS)){
				w = pop(&POS);
				puz[i][j] = EMPTY;
				if(display){
					display_puz(puz);
					refresh();
				}	
				count--;
				i = cell[count].x;
				j = cell[count].y;
				goto check;
			}	
		}
		else if(!i_empty(&w)){
			val = i_pop(&w);
			push(&POS, w);
			cell[count].x = i;
			cell[count].y = j;
			count++;
		}
		puz[i][j] = val;
		if(display){
			display_puz(puz);
			refresh();
		}
		traverse_line(&i, &j);
	}
	f.flag = 0;
	return 1;
}
Пример #5
0
int main( void )
{
	 puts("starting MAIN execution\n");
	 //unsigned char data[16] = {12, 15, 20, 210, 124, 16, 54, 156, 134, 21, 7, 15, 46, 97, 84, 161}; 

    unsigned short tmp;

	 unsigned char max, min;
	 unsigned short beta;
	 unsigned int data_pack, min_max_pack;
	 unsigned int beta_mini;
	 unsigned char mini, maxi;
	 int i;
	 unsigned int start_c, stop_c;
	 
	 unsigned int col_nb, row_nb, pixel_nb;
	 unsigned int A_row_ix, A_col_ix, B_row_ix, B_col_ix, row, col; 
	 volatile unsigned int dump;
	 A_row_ix = 25;
	 A_col_ix = 50;
	 B_row_ix = 75;
	 B_col_ix = 100;
	 
	 // on récupère le nombre de colonnes dans l'image
	 col_nb = i_read();
	 my_printf("nbre de colonnes dans l'image: ", col_nb);
	 
	 // on récupère le nombre de lignes dans l'image
	 row_nb = i_read();
	 my_printf("nbre de lignes dans l'image: ", row_nb);
	 
	 pixel_nb=col_nb*row_nb;
	 my_printf("nbre de pixel dans l'image: ", pixel_nb);

	 if(pixel_nb > 32768){
		  puts("WARNING :image trop volumineuse, taille max = 32768 octets");		  
	 }
	 
	 
#ifdef CROP
 row=col=i=0;
 
 while( i_empty() == 0 )//tant que la FIFO d'entrée n'est pas vide
  {	 
	 //if the pixel is in the zoom area, we store it
	 if(row < B_row_ix && row > A_row_ix && col < B_col_ix && col > A_col_ix){
		R[i] = i_read();
		G[i] = i_read();
		B[i] = i_read(); 
	   i++;
	 }
	 // otherwise, we dump 
	 else{
		dump = i_read();
		dump = i_read();
		dump = i_read();
	 }
	 col++;
	 if(col >= col_nb){
		col = 0;
		row++;
	 }
  }  
puts("Lecture de la FIFO d'entrée terminée\n");

  col_nb = B_col_ix-A_col_ix;
  my_printf("col_nb cropped: ", col_nb);
  row_nb = B_row_ix-A_row_ix;
  my_printf("row_nb cropped: ", row_nb);
  pixel_nb = row_nb*col_nb;
  my_printf("pixel_nb cropped: ", pixel_nb);
  
  o_write( col_nb);
  o_write( row_nb);
  o_write( 255 );
  for(i=0;i<pixel_nb;i++){ // pour chaque échantillon 
	 o_write( R[i] );
	 o_write( G[i] );
	 o_write( B[i] );
	 //my_printf("dataout", data[i]);
  } 
puts("Ecriture des resultats dans la FIFO de sortie\n");
#endif


  
#ifdef RED
  o_write( col_nb);
  o_write( row_nb);
  o_write( 255 );
  for(i=0;i<pixel_nb;i++){ // pour chaque échantillon 
	 o_write( i_read() );
	 o_write( 0 );
	 o_write( 0 );
	 dump = i_read();
	 dump = i_read();
	 //my_printf("dataout", data[i]);
  } 
  /*while( i_empty() == 0 )//tant que la FIFO d'entrée n'est pas vide
  {	 
	 o_write( i_read());
  }*/  
  
#endif

#ifdef DEBUG
  // Affichage des valeurs de sortie sur la sortie standard
	for(i=0;i<pixel_nb;i++){
		my_printf(" scaled val=> ", data[i]);
	}
#endif

  // arrêt du programme
  puts("Fin du programme\n");
  stop();
}