コード例 #1
0
ファイル: error.c プロジェクト: glocklueng/stm32-dds
/**
 * Return number of errors/events in the queue
 * @param context
 * @return
 */
int32_t SCPI_ErrorCount(scpi_t * context) {
    int16_t result = 0;

    fifo_count(&context->error_queue, &result);

    return result;
}
コード例 #2
0
ファイル: s3cmci.c プロジェクト: maraz/linux-2.6
static void do_pio_read(struct s3cmci_host *host)
{
	int res;
	u32 fifo;
	void __iomem *from_ptr;

	/* write real prescaler to host, it might be set slow to fix */
	writel(host->prescaler, host->base + S3C2410_SDIPRE);

	from_ptr = host->base + host->sdidata;

	while ((fifo = fifo_count(host))) {
		if (!host->pio_words) {
			res = get_data_buffer(host, &host->pio_words,
					      &host->pio_ptr);
			if (res) {
				host->pio_active = XFER_NONE;
				host->complete_what = COMPLETION_FINALIZE;

				dbg(host, dbg_pio, "pio_read(): "
				    "complete (no more data).\n");
				return;
			}

			dbg(host, dbg_pio,
			    "pio_read(): new target: [%i]@[%p]\n",
			    host->pio_words, host->pio_ptr);
		}

		dbg(host, dbg_pio,
		    "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
		    fifo, host->pio_words,
		    readl(host->base + S3C2410_SDIDCNT));

		if (fifo > host->pio_words)
			fifo = host->pio_words;

		host->pio_words -= fifo;
		host->pio_count += fifo;

		while (fifo--)
			*(host->pio_ptr++) = readl(from_ptr);
	}

	if (!host->pio_words) {
		res = get_data_buffer(host, &host->pio_words, &host->pio_ptr);
		if (res) {
			dbg(host, dbg_pio,
			    "pio_read(): complete (no more buffers).\n");
			host->pio_active = XFER_NONE;
			host->complete_what = COMPLETION_FINALIZE;

			return;
		}
	}

	enable_imask(host,
		     S3C2410_SDIIMSK_RXFIFOHALF | S3C2410_SDIIMSK_RXFIFOLAST);
}
コード例 #3
0
ファイル: modem_io.c プロジェクト: Hero355/bdroid
void modem_update_pipe(struct m_pipe *pipe)
{
	unsigned long flags;
	spin_lock_irqsave(&pipe->mc->lock, flags);
	pipe->tx->avail = fifo_space(pipe->tx);
	pipe->rx->avail = fifo_count(pipe->rx);
	if (pipe->rx->avail)
		wake_lock(&pipe->wakelock);
	else
		wake_unlock(&pipe->wakelock);
	spin_unlock_irqrestore(&pipe->mc->lock, flags);
}
コード例 #4
0
ファイル: modem_io.c プロジェクト: Hero355/bdroid
/* Called with mc->lock held whenever we gain access
 * to the mmio region.
 */
void modem_update_state(struct modemctl *mc)
{
	/* update our idea of space available in fifos */
	mc->packet_tx.avail = fifo_space(&mc->packet_tx);
	mc->packet_rx.avail = fifo_count(&mc->packet_rx);
	if (mc->packet_rx.avail)
		wake_lock(&mc->packet_pipe.wakelock);
	else
		wake_unlock(&mc->packet_pipe.wakelock);

	/* wake up blocked or polling read/write operations */
	wake_up(&mc->wq);
}
コード例 #5
0
ファイル: error.c プロジェクト: jstamour802/DCS-100E
/**
 * Return number of errors/events in the queue
 * @param context
 * @return 
 */
int32_t SCPI_ErrorCount(scpi_t * context) {
    int16_t result = 0;

    /*
     * // FreeRTOS
     * result = uxQueueMessagesWaiting((xQueueHandle)context->error_queue);
     */

    /* basic FIFO */
    fifo_count((fifo_t *)context->error_queue, &result);

    return result;
}
コード例 #6
0
ファイル: thread_pool.c プロジェクト: dwerner/libmelon
void thread_pool_exit_all( thread_pool_t *pool ) {
  dna_mutex_lock( pool->mutex );
  fifo_each( pool->tasks, &delete_task );
  fifo_empty(pool->tasks);
  fifo_each(
      pool->thread_queue,
      &kill_thread
  );
  /* push new "work" into the queue to unblock threads waiting on the list */
  int x = 0;
  for ( x = 0; x < fifo_count( pool->thread_queue ); x++) {
    /* We guard and don't execute NULL function pointers
       This merely meets the needs of the fifo for unblocking. */
    thread_pool_enqueue( pool, NULL, NULL );
  }
  dna_cond_signal( pool->wait );
  dna_mutex_unlock( pool->mutex );
}
コード例 #7
0
ファイル: s3cmci.c プロジェクト: AppEngine/linux-2.6
static void do_pio_read(struct s3cmci_host *host)
{
	int res;
	u32 fifo;
	u32 *ptr;
	u32 fifo_words;
	void __iomem *from_ptr;

	/* write real prescaler to host, it might be set slow to fix */
	writel(host->prescaler, host->base + S3C2410_SDIPRE);

	from_ptr = host->base + host->sdidata;

	while ((fifo = fifo_count(host))) {
		if (!host->pio_bytes) {
			res = get_data_buffer(host, &host->pio_bytes,
					      &host->pio_ptr);
			if (res) {
				host->pio_active = XFER_NONE;
				host->complete_what = COMPLETION_FINALIZE;

				dbg(host, dbg_pio, "pio_read(): "
				    "complete (no more data).\n");
				return;
			}

			dbg(host, dbg_pio,
			    "pio_read(): new target: [%i]@[%p]\n",
			    host->pio_bytes, host->pio_ptr);
		}

		dbg(host, dbg_pio,
		    "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
		    fifo, host->pio_bytes,
		    readl(host->base + S3C2410_SDIDCNT));

		/* If we have reached the end of the block, we can
		 * read a word and get 1 to 3 bytes.  If we in the
		 * middle of the block, we have to read full words,
		 * otherwise we will write garbage, so round down to
		 * an even multiple of 4. */
		if (fifo >= host->pio_bytes)
			fifo = host->pio_bytes;
		else
			fifo -= fifo & 3;

		host->pio_bytes -= fifo;
		host->pio_count += fifo;

		fifo_words = fifo >> 2;
		ptr = host->pio_ptr;
		while (fifo_words--)
			*ptr++ = readl(from_ptr);
		host->pio_ptr = ptr;

		if (fifo & 3) {
			u32 n = fifo & 3;
			u32 data = readl(from_ptr);
			u8 *p = (u8 *)host->pio_ptr;

			while (n--) {
				*p++ = data;
				data >>= 8;
			}
		}
	}
コード例 #8
0
ファイル: fifo.c プロジェクト: extsui/extkernel
inline int fifo_is_full(fifo_t *fifo)
{
  return fifo_count(fifo) - 1 == fifo->size;
}
コード例 #9
0
static void do_pio_read(struct s3cmci_host *host)
{
	int res;
	u32 fifo;
	u32 *ptr;
	u32 fifo_words;
	void __iomem *from_ptr;

	
	writel(host->prescaler, host->base + S3C2410_SDIPRE);

	from_ptr = host->base + host->sdidata;

	while ((fifo = fifo_count(host))) {
		if (!host->pio_bytes) {
			res = get_data_buffer(host, &host->pio_bytes,
					      &host->pio_ptr);
			if (res) {
				host->pio_active = XFER_NONE;
				host->complete_what = COMPLETION_FINALIZE;

				dbg(host, dbg_pio, "pio_read(): "
				    "complete (no more data).\n");
				return;
			}

			dbg(host, dbg_pio,
			    "pio_read(): new target: [%i]@[%p]\n",
			    host->pio_bytes, host->pio_ptr);
		}

		dbg(host, dbg_pio,
		    "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
		    fifo, host->pio_bytes,
		    readl(host->base + S3C2410_SDIDCNT));

		
		if (fifo >= host->pio_bytes)
			fifo = host->pio_bytes;
		else
			fifo -= fifo & 3;

		host->pio_bytes -= fifo;
		host->pio_count += fifo;

		fifo_words = fifo >> 2;
		ptr = host->pio_ptr;
		while (fifo_words--)
			*ptr++ = readl(from_ptr);
		host->pio_ptr = ptr;

		if (fifo & 3) {
			u32 n = fifo & 3;
			u32 data = readl(from_ptr);
			u8 *p = (u8 *)host->pio_ptr;

			while (n--) {
				*p++ = data;
				data >>= 8;
			}
		}
	}
コード例 #10
0
ファイル: main.c プロジェクト: 0x010C/AG44-Jeu
int main(int argc, char **argv)
{
	int **A = NULL;
	int **N = NULL;
	int **PLC = NULL;
	int *GL = NULL;
	FILE *fichier = NULL;
	int nbPlaces=0, nbLevels=0;
	int *listePositif = NULL;
	int *listeNegatif = NULL;
	int *listeAVisiter = NULL;
	int i, j, k, buf;

	/* 
	 * Récupération de la Matrice
	 */

	/* Ouverture du fichier */
	fichier = fopen("input.data", "r");
	if(fichier == NULL)
		fprintf(stderr,"Erreur : Ouverture du fichier impossible :'(\n");

	/* Récupération du nombre de zones */
	fscanf(fichier, "%d", &nbPlaces);

	/* Allocation de la mémoire pour contenir la matrice */
	A = (int**) malloc(sizeof(int*)*nbPlaces);
	for(i=0; i<nbPlaces; i++)
		A[i] = (int*) malloc(sizeof(int)*nbPlaces);

	/* Récupération des données et stoquage dans la matrice */
	for(i=0; i<nbPlaces; i++)
		for(j=0; j<nbPlaces; j++)
			fscanf(fichier, "%d", &A[i][j]);

	/* Fermeture du fichier */
	fclose(fichier);


	/*
	 * Recherche des composants fortement connectés
	 */

	/* Allocation de la mémoire pour enregistrer les niveaux et pour contenir des tableaux temporaires */
	GL = (int*) malloc(sizeof(int)*nbPlaces);
	listePositif = (int*) malloc(sizeof(int)*nbPlaces);
	listeNegatif = (int*) malloc(sizeof(int)*nbPlaces);
	listeAVisiter = (int*) malloc(sizeof(int)*nbPlaces);
	for(i=0; i<nbPlaces; i++)
	{
		listePositif[i] = -1;
		listeNegatif[i] = -1;
		listeAVisiter[i] = -1;
		GL[i] = -1;
	}

	/* On va effectuer la recherche depuis chaque point du graph (sauf si elle est déjà dans un level) */
	for(i=0; i<nbPlaces; i++)
	{
		printf("=====================================\n Research starting from the place %2d \n=====================================\n", i);
		if(GL[i] == -1)
		{
			/* Remplissage de la liste positive */
			fifo_add(listeAVisiter, nbPlaces, i);
			while(fifo_isEmpty(listeAVisiter, nbPlaces) == 0)
			{
				buf = fifo_pop(listeAVisiter, nbPlaces);
				fifo_add(listePositif, nbPlaces, buf);
				for(j=0;j<nbPlaces;j++)
					if(A[buf][j] == 1)
					{
						if(fifo_search(listePositif, nbPlaces, j) == -1)
						{
							fifo_add(listeAVisiter, nbPlaces, j);
						}
					}
			}
			printf("--> Places in the '+' list :\n    ");
			for(j=0;j<fifo_count(listePositif, nbPlaces);j++)
				printf("%2d ", listePositif[j]);
			printf("\n");

			/* Remplissage de la liste negative */
			fifo_add(listeAVisiter, nbPlaces, i);
			while(fifo_isEmpty(listeAVisiter, nbPlaces) == 0)
			{
				buf = fifo_pop(listeAVisiter, nbPlaces);
				fifo_add(listeNegatif, nbPlaces, buf);
				for(j=0;j<nbPlaces;j++)
					if(A[j][buf] == 1 && fifo_search(listeNegatif, nbPlaces, j) == -1)
						fifo_add(listeAVisiter, nbPlaces, j);

			}
			printf("--> Places in the '-' list :\n    ");
                        for(j=0;j<fifo_count(listeNegatif, nbPlaces);j++)
				printf("%2d ", listeNegatif[j]);
			printf("\n");

			/* Recherche d'elements presents dans les deux listes */
			printf("--> Intersection :\n    ");
			for(j=0;j<nbPlaces;j++)
			{
				for(k=0;k<nbPlaces;k++)
					if(listePositif[j] == listeNegatif[k] && listePositif[j] != -1)
					{
						GL[listePositif[j]] = nbLevels;
						printf("%2d ", listePositif[j]);
					}
			}
			printf("\n--> Saving them in the new level n°%2d\n\n", nbLevels);
			nbLevels++;

			/* Vidage des deux listes */
			for(j=0;j<nbPlaces;j++)
			{
				listePositif[j] = -1;
				listeNegatif[j] = -1;
			}
		}
		else
			printf("--> Already in the level n°%2d\n\n", GL[i]);
	}

	printf("\n\n\n========\n Levels\n========\n");
	for(i=0;i<nbPlaces;i++)
		printf("--> Place %2d is in the Level n°%2d\n", i, GL[i]);

	printf("\n");
	for(i=0;i<nbLevels;i++)
	{
		k = 0;
		printf("{");
		for(j=0; j<nbPlaces; j++)
			if(GL[j] == i)
			{
				if(k == 1)
					printf(";");
				else
					k = 1;
				printf("%2d", j);
			}
		printf(" } ");
	}
	printf("\n");


	/*
	 * Création de la matrice réduite
	 */

	/* Allocation et initialisation de la matrice réduite */
	N = (int**) malloc(sizeof(int*)*nbLevels);
	for(i=0; i<nbLevels; i++)
	{
		N[i] = (int*) malloc(sizeof(int)*nbLevels);
		for(j=0; j<nbLevels; j++)
			N[i][j] = 0;
	}

	/* Remplissage de la-dite matrice */
	for(i=0; i<nbPlaces; i++)
	{
		for(j=0; j<nbPlaces; j++)
		{
			if(A[i][j] == 1)
			{
				N[GL[i]][GL[j]]++;
			}
		}
	}

	printf("\n================\n Reduced Matrix\n================\n");
	for(i=0; i<nbLevels; i++)
	{
		for(j=0; j<nbLevels; j++)
			printf("%2d ", N[i][j]);
		printf("\n");
	}


	/*
	 * Calcul du plus long chemin entre le premier et le dernier niveau
	 */

	/* Allocation et Reallocation d'une partie de mémoire précédement utilisé et mise à zéro */
	listeAVisiter = (int*) realloc(listeAVisiter, sizeof(int)*nbLevels);
	PLC = (int**) malloc(sizeof(int*)*nbLevels);
	for(i=0; i<nbLevels; i++)
	{
		listeAVisiter[i] = -1;
		PLC[i] = (int*) malloc(sizeof(int)*nbLevels);
		for(j=0; j<nbLevels; j++)
			PLC[i][j] = -1;
	}	

	/* Application de l'algo de calcul du plus long chemin */
	fifo_add(listeAVisiter, nbLevels, GL[0]);
	while(fifo_isEmpty(listeAVisiter, nbLevels) == 0)
	{
		buf = fifo_pop(listeAVisiter, nbLevels);
		for(i=0; i<nbLevels; i++)
			if(N[buf][i] >= 1 && buf != i)
			{
				if(fifo_count(PLC[buf], nbLevels)+1 > fifo_count(PLC[i], nbLevels))
				{
					for(j=0; j<nbLevels; j++)
						PLC[i][j] = PLC[buf][j];
					fifo_add(PLC[i], nbLevels, buf);
					fifo_add(listeAVisiter, nbLevels, i);
				}
			}

	}

	printf("\n==============\n Longest path\n==============\n");
	if(fifo_isEmpty(PLC[GL[nbPlaces-1]], nbLevels) == 0)
		k = GL[nbPlaces-1];
	else
	{
		k = 0;
		for(i=1; i<nbLevels; i++)
			if(fifo_count(PLC[i], nbLevels) > fifo_count(PLC[k], nbLevels))
				k = i;
	}
	printf("--> { ");
	for(i=0; i<nbLevels && PLC[k][i] != -1; i++)
	{
		printf("%d ; ", PLC[k][i]);
	}
	printf("%d }\n", k);


	/*
	 * Generation d'une image du graph (idée par Jérome BOURSIER, merci à lui !)
	 */

	/* Création du fichier */
	fichier = fopen("graph.dot","w");
	fprintf(fichier, "digraph graphAG44\n{\n");

	/* Enregistrement des Niveaux */
	srand(time(NULL));
	for(i=0; i<nbLevels; i++)
	{
		fprintf(fichier, "\tsubgraph sub%d\n\t{\n\t\tnode [style=filled,color=\"#%2x%2x%2x\"];\n", i,rand()%225, rand()%225, rand()%225);
		for(j=0; j<nbPlaces; j++)
			if(GL[j] == i)
				fprintf(fichier, "\t\t%d;\n", j);
		fprintf(fichier, "\t}\n\n");
	}

	/* Enregistrement des Places */
	for(i=0; i<nbPlaces; i++)
		for(j=0; j<nbPlaces; j++)
			if(A[i][j] == 1)
				fprintf(fichier, "\t%d -> %d;\n", i, j);
	fprintf(fichier, "}");
	fclose(fichier);

	/* Appel au programme dot pour generer l'image a partir du fichier */
	if(fork() == 0)
		execlp("dot", "dot", "-Tpng", "graph.dot", "-o", "graph.png", NULL);
        if(fork() == 0)
                execlp("eog", "eog", "graph.png", NULL);


	/*
	 * Libération de la mémoire allouée
	 */

	for(i=0; i<nbPlaces; i++)
		free(A[i]);
	free(A);
	for(i=0; i<nbLevels; i++)
	{
		free(N[i]);
		free(PLC[i]);
	}
	free(N);
	free(PLC);
	free(GL);
	free(listePositif);
	free(listeNegatif);
	free(listeAVisiter);

	return 0;
}