Esempio n. 1
0
void loop()
{
	int ret;
	if(inloop)
	{
		printf("Error: loop() task overrun\n");
		inloop = 0;
		return;
	}
	inloop = 1;

	// ========================================================
	// We should not have any SPI devices enabled at this point
	ret = spi_chip_select_status();
	if(ret != 0xff)
	{
		printf("Error: loop() entered with spi_cs = %d\n",ret);
		spi_end(ret);
		return;
	}


	user_loop();

	// We should not have any SPI devices enabled at this point
	ret = spi_chip_select_status();
	if(ret != 0xff)
	{
		printf("Error: loop() entered with spi_cs = %d\n",ret);
		spi_end(ret);
		return;
	}

	inloop = 0;
}
Esempio n. 2
0
File: main.c Progetto: myixr/wshow
int main(void)
{

  /* USER CODE BEGIN 1 */
	user_init1();
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C2_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
		user_init2();

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */
		user_loop();

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Esempio n. 3
0
static int check_itimer(int which)
{
	int err;
	struct timeval start, end;
	struct itimerval val = {
		.it_value.tv_sec = DELAY,
	};

	printf("Check itimer ");

	if (which == ITIMER_VIRTUAL)
		printf("virtual... ");
	else if (which == ITIMER_PROF)
		printf("prof... ");
	else if (which == ITIMER_REAL)
		printf("real... ");

	fflush(stdout);

	done = 0;

	if (which == ITIMER_VIRTUAL)
		signal(SIGVTALRM, sig_handler);
	else if (which == ITIMER_PROF)
		signal(SIGPROF, sig_handler);
	else if (which == ITIMER_REAL)
		signal(SIGALRM, sig_handler);

	err = gettimeofday(&start, NULL);
	if (err < 0) {
		perror("Can't call gettimeofday()\n");
		return -1;
	}

	err = setitimer(which, &val, NULL);
	if (err < 0) {
		perror("Can't set timer\n");
		return -1;
	}

	if (which == ITIMER_VIRTUAL)
		user_loop();
	else if (which == ITIMER_PROF)
		kernel_loop();
	else if (which == ITIMER_REAL)
		idle_loop();

	gettimeofday(&end, NULL);
	if (err < 0) {
		perror("Can't call gettimeofday()\n");
		return -1;
	}

	if (!check_diff(start, end))
		printf("[OK]\n");
	else
		printf("[FAIL]\n");

	return 0;
}

static int check_timer_create(int which)
{
	int err;
	timer_t id;
	struct timeval start, end;
	struct itimerspec val = {
		.it_value.tv_sec = DELAY,
	};

	printf("Check timer_create() ");
	if (which == CLOCK_THREAD_CPUTIME_ID) {
		printf("per thread... ");
	} else if (which == CLOCK_PROCESS_CPUTIME_ID) {
		printf("per process... ");
	}
	fflush(stdout);

	done = 0;
	err = timer_create(which, NULL, &id);
	if (err < 0) {
		perror("Can't create timer\n");
		return -1;
	}
	signal(SIGALRM, sig_handler);

	err = gettimeofday(&start, NULL);
	if (err < 0) {
		perror("Can't call gettimeofday()\n");
		return -1;
	}

	err = timer_settime(id, 0, &val, NULL);
	if (err < 0) {
		perror("Can't set timer\n");
		return -1;
	}

	user_loop();

	gettimeofday(&end, NULL);
	if (err < 0) {
		perror("Can't call gettimeofday()\n");
		return -1;
	}

	if (!check_diff(start, end))
		printf("[OK]\n");
	else
		printf("[FAIL]\n");

	return 0;
}

int main(int argc, char **argv)
{
	printf("Testing posix timers. False negative may happen on CPU execution \n");
	printf("based timers if other threads run on the CPU...\n");

	if (check_itimer(ITIMER_VIRTUAL) < 0)
		return ksft_exit_fail();

	if (check_itimer(ITIMER_PROF) < 0)
		return ksft_exit_fail();

	if (check_itimer(ITIMER_REAL) < 0)
		return ksft_exit_fail();

	if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0)
		return ksft_exit_fail();

	/*
	 * It's unfortunately hard to reliably test a timer expiration
	 * on parallel multithread cputime. We could arm it to expire
	 * on DELAY * nr_threads, with nr_threads busy looping, then wait
	 * the normal DELAY since the time is elapsing nr_threads faster.
	 * But for that we need to ensure we have real physical free CPUs
	 * to ensure true parallelism. So test only one thread until we
	 * find a better solution.
	 */
	if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0)
		return ksft_exit_fail();

	return ksft_exit_pass();
}
Esempio n. 4
0
int run_client(struct list_loop *ls, struct task_loop *tl, int mask)
{
  struct mul_client *ci;
  int update, idle, result;
#if 0
  struct task_loop *tx;
#endif
  struct link_loop *lk;
  struct mul_msg *mm;
  
  ci = user_loop(ls, tl);
  if(ci == NULL){
    stop_loop(ls, tl);
    return 0;
  }

  ci->c_task = tl;

  idle = LO_STOP_MASK | LO_WAIT_MASK;

#ifdef DEBUG
  fprintf(stderr, "client[%p]: mask 0x%02x\n", tl, mask);
#endif

  update = idle;
  if(mask & LO_STOP_MASK){
    /* WARNING: may have to remove fd to prevent almost harmless but ugly double close */
    shutdown_client(ci);
    return 0;
  }

  /* handle read case */
  update |= LO_READ_MASK;
  if(mask & LO_READ_MASK){
    result = read_katcp(ci->c_dispatch);
#ifdef DEBUG
    fprintf(stderr, "client: read code is %d\n", result);
#endif
    if(result < 0){
      stop_loop(ls, tl);
      return 0;
    }
    if(result > 0){
      update &= ~(LO_READ_MASK); /* on EOF stop reading */
    }
  }

  /* handle work function */
  result = lookup_katcp(ci->c_dispatch);
  if(result < 0){
    stop_loop(ls, tl);
    return 0;
  }

  if(result > 0){
    /* WARNING: statement triggers dispatch if no request pending (new) or if something has arrived (with pending request) */
    if((ci->c_waiting == 0) || (mask & LO_WAIT_MASK)){
#ifdef DEBUG
      fprintf(stderr, "client[%p]: calling dispatch (queue=%d)\n", tl, ci->c_queue);
#endif
      result = call_katcp(ci->c_dispatch);
      if(result == KATCP_RESULT_RESUME){
        ci->c_waiting = (ci->c_queue > 0) ? 1 : 0;
      } else {
        ci->c_waiting = 0;
        if(ci->c_queue > 0){ /* WARNING: this should actually be an abort, as the dispatch routines have broken the queue */
          fprintf(stderr, "client[%p]: warning: finished with %d outstanding requests\n", tl, ci->c_queue);
          log_message_katcp(ci->c_dispatch, KATCP_LEVEL_ERROR, NULL, "client function has %d outstand requests", ci->c_queue);
        }
        ci->c_queue = 0;
      }
    }
  }

  if(mask & LO_WAIT_MASK){
    if(!(ci->c_waiting)){ /* no dispatch function busy, so we handle the informs and ditch everything else */
#ifdef DEBUG
      fprintf(stderr, "client[%p]: idle, handling queue\n", tl);
#endif
      while((lk = receive_link_loop(ls, tl)) != NULL){
#ifdef DEBUG
        fprintf(stderr, "client[%p]: received event type %d\n", tl, lk->k_type);
#endif
        if((lk->k_type == ci->c_overall->o_type_msg) && (lk->k_data != NULL)){
          mm = lk->k_data;
          if(arg_inform_msg(mm)){ /* inform messages get sent out */
            dispatch_from_msg(ci->c_dispatch, mm);
          }
        }
        discard_link_loop(ls, lk);
      } 
    }
  }

  /* handle write case */
  if(mask & LO_WRITE_MASK){
    if(write_katcp(ci->c_dispatch) < 0){
      stop_loop(ls, tl);
      return 0;
    }
  }

  if(flushing_katcp(ci->c_dispatch)){
    /* WARNING: could disable reads and running if flush buffer too large */
    update |= LO_WRITE_MASK;
  }

  if(update == idle){
    /* if we are only interested in stopping then stop */
    stop_loop(ls, tl);
  }

  set_mask_loop(ls, tl, update, 0);

  if(exited_katcp(ci->c_dispatch) != KATCP_EXIT_NOTYET){
    /* TODO: make it stop */
  }

  return 0;
}
Esempio n. 5
0
int main(int argc, Char *argv[])
{
  boolean canbeplotted;
  boolean wasplotted = false;
#ifdef MAC
  OSErr retcode;
  FInfo  fndrinfo;
#ifdef OSX_CARBON
  FSRef fileRef;
  FSSpec fileSpec;
#endif
#ifdef __MWERKS__
  SIOUXSetTitle("\pPHYLIP:  Drawtree");
#endif
  argv[0] = "Drawgram";
#endif

  grbg = NULL;
  progname = argv[0];

#ifndef X_DISPLAY_MISSING
  nargc=1;
  nargv=argv;
#endif
  
  init(argc, argv);
  emboss_getoptions("fdrawgram",argc,argv);

  setup_environment(argv, &canbeplotted);

  user_loop(&canbeplotted);
  if (!((previewer == winpreview || previewer == xpreview || previewer == mac)
        && (winaction == quitnow))) {
    
    previewing = false;
    initplotter(spp,fontname);
    numlines = dotmatrix ? ((long)floor(yunitspercm * ysize + 0.5)/strpdeep) : 1;
    if (plotter != ibm)
      printf("\nWriting plot file ...\n");
    drawit(fontname,&xoffset,&yoffset,numlines,root);
    finishplotter();
    FClose(plotfile);
    wasplotted = true;
    printf("\nPlot written to file \"%s\"\n\n", pltfilename);
  }
  FClose(intree);
#ifdef MAC
  if (plotter == pict && wasplotted){
#ifdef OSX_CARBON
    FSPathMakeRef((unsigned char *)pltfilename, &fileRef, NULL);
    FSGetCatalogInfo(&fileRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL);
    FSpGetFInfo(&fileSpec, &fndrinfo);
    fndrinfo.fdType='PICT';
    fndrinfo.fdCreator='MDRW';
    FSpSetFInfo(&fileSpec, &fndrinfo);
#else
    retcode=GetFInfo(CtoPstr(PLOTFILE),0,&fndrinfo);
    fndrinfo.fdType='PICT';
    fndrinfo.fdCreator='MDRW';
    retcode=SetFInfo(CtoPstr(PLOTFILE),0,&fndrinfo);
#endif
  }
  if (plotter == lw && wasplotted){
#ifdef OSX_CARBON
    FSPathMakeRef((unsigned char *)pltfilename, &fileRef, NULL);
    FSGetCatalogInfo(&fileRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL);
    FSpGetFInfo(&fileSpec, &fndrinfo);
    fndrinfo.fdType='TEXT';
    FSpSetFInfo(&fileSpec, &fndrinfo);
#else
    retcode=GetFInfo(CtoPstr(PLOTFILE),0,&fndrinfo);
    fndrinfo.fdType='TEXT';
    retcode=SetFInfo(CtoPstr(PLOTFILE),0,&fndrinfo);
#endif
  }
#endif
  printf("Done.\n\n");

#ifdef WIN32
  phyRestoreConsoleAttributes();
#endif

  embExit();
  return 0;
}