当前位置: 首页>>代码示例>>C++>>正文


C++ chThdSleepMilliseconds函数代码示例

本文整理汇总了C++中chThdSleepMilliseconds函数的典型用法代码示例。如果您正苦于以下问题:C++ chThdSleepMilliseconds函数的具体用法?C++ chThdSleepMilliseconds怎么用?C++ chThdSleepMilliseconds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了chThdSleepMilliseconds函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: THD_FUNCTION

static THD_FUNCTION(ThreadGFXEvent, arg)
{
	(void)arg;

	chRegSetThreadName("GFXEvent");

	GEvent* pe;
	static RTCDateTime timespec;
	struct tm timeinfo;
	struct tm tim;
	struct tm *canary;
	static time_t unix_time;
	while (true) {
		pe = geventEventWait(&gl, TIME_INFINITE);
		switch (pe->type) {
			case GEVENT_GWIN_BUTTON:
				if (((GEventGWinButton*)pe)->gwin == ghBtnSettings) {
					createSettingsFrame();
					gwinShow(ghFrame1);
					updateGraph = false;
					updateSettingTime = true;
				} else if (((GEventGWinButton*)pe)->gwin == ghBtnSave) {
					timeinfo.tm_hour = atoi(gwinListGetSelectedText(ghListHour));
					timeinfo.tm_min = atoi(gwinListGetSelectedText(ghListMin));
					timeinfo.tm_sec = 0;
					timeinfo.tm_mday = atoi(gwinListGetSelectedText(ghListDay));
					timeinfo.tm_mon = gwinListGetSelected(ghListMonth);
					timeinfo.tm_year = atoi(gwinListGetSelectedText(ghListYear))-1900;
					unix_time = mktime(&timeinfo);
					canary = localtime_r(&unix_time, &tim);
					osalDbgCheck(&tim == canary);
					rtcConvertStructTmToDateTime(&tim, 0, &timespec);
					rtcSetTime(RTC_DRIVER, &timespec);
				} else if (((GEventGWinButton*)pe)->gwin == ghBtnTime) {
					updateGraph = false;
					gwinShow(ghListFreq);
				}
				break;

			case GEVENT_GWIN_CHECKBOX:
				if (((GEventGWinCheckbox*)pe)->gwin == ghCheckBoxHR) {
					if (((GEventGWinCheckbox*)pe)->isChecked)
						use12HR = true;
					else
						use12HR = false;
				}
				break;

			case GEVENT_GWIN_CLOSE:
				updateGraph = true;
				updateSettingTime = false;
				switch (activeGraph) {
					case 0:
						drawGraphLines(ghContainerGraphC);
						break;

					case 1:
						drawGraphLines(ghContainerGraphV);
						break;

					case 2:
						drawGraphLines(ghContainerGraphW);
						break;

					case 3:
						drawGraphLines(ghContainerGraphCV_1);
						drawGraphLines(ghContainerGraphCV_2);
						break;

					default:
						break;
				}
				break;

			case GEVENT_GWIN_RADIO:
				activeGraph = atoi(gwinGetText(((GEventGWinRadio *)pe)->gwin));
				setActiveGraph(activeGraph);
				break;

			case GEVENT_GWIN_LIST:
				if (((GEventGWinList*)pe)->gwin == ghListFreq)  {
					char str[5];
					uint8_t val = atoi(gwinListGetSelectedText(ghListFreq));
					GRAPH_Refresh = ((1.0/val)*1000);
					snprintf(str, 5, "%d%s", val, "Hz");
					gwinSetText(ghBtnTime, str, true);
					chThdSleepMilliseconds(10);
					gwinHide(ghListFreq);
					updateGraph = true;

					switch (activeGraph) {
					case 0:
						drawGraphLines(ghContainerGraphC);
						break;

					case 1:
						drawGraphLines(ghContainerGraphV);
						break;

					case 2:palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 5);
//.........这里部分代码省略.........
开发者ID:FriedCircuits,项目名称:USBMultimeter,代码行数:101,代码来源:main.c

示例2: THD_FUNCTION

THD_FUNCTION(scMS5611Thread, arg)
{
  systime_t sleep_until;
  systime_t interval_st = MS2ST(ms5611_interval_ms);
  
  (void)arg;
  chRegSetThreadName(__func__);

  SC_LOG_PRINTF("d: ms5611 init\r\n");
  
  // We need to give a bit of time to the chip until we can ask it to shut down
  // i2c not ready initially? (This is inherited from the LSM9DS0 driver)
  chThdSleepMilliseconds(20);

  ms5611_reset();
  chThdSleepMilliseconds(100);
  ms5611_reset();
  chThdSleepMilliseconds(100);
  ms5611_reset();
  chThdSleepMilliseconds(100);
  ms5611_read_prom();
  uint8_t ref_crc = ms5611_prom[MS5611_PROM_SIZE - 1] & 0x0F;
  uint8_t calc_crc = ms5611_calc_crc();
  if (ref_crc != calc_crc) {
    SC_LOG_PRINTF("e: ms5611 crc failure: 0x%x vs 0x%x\r\n", ref_crc, calc_crc);
  }

  sleep_until = chVTGetSystemTime() + interval_st;
  
  // Loop initiating measurements and waiting for results
  while (!chThdShouldTerminateX()) {
    systime_t now = chVTGetSystemTime();
    systime_t wait_time = sleep_until - now;
    uint32_t temp;
    uint32_t pres;
    msg_t msg;

    // Using a semaphore allows to cancel the sleep outside the thread
    if (chBSemWaitTimeout(&ms5611_wait_sem, wait_time) != MSG_TIMEOUT) {
      continue;
    }

    sleep_until += interval_st;
    now = chVTGetSystemTime();
    
    temp = ms5611_read(true);
    
    if (chThdShouldTerminateX()) {
      break;
    }
    
    pres = ms5611_read(false);

    chMtxLock(&data_mtx);
    ms5611_temp = temp;
    ms5611_pres = pres;
    ms5611_time_st = now;
    chMtxUnlock(&data_mtx);

    // Notify main app about new measurements being available
    msg = sc_event_msg_create_type(SC_EVENT_TYPE_MS5611_AVAILABLE);
    sc_event_msg_post(msg, SC_EVENT_MSG_POST_FROM_NORMAL);
  }
}
开发者ID:snowcap-electronics,项目名称:control-board,代码行数:64,代码来源:sc_ms5611.c

示例3: THD_FUNCTION

static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  chRegSetThreadName("blinker");

  while (true) {
    unsigned i;

    for (i = 0; i < 4; i++) {
      palClearPad(PORT_D, PD_LED1);
      chThdSleepMilliseconds(100);
      palClearPad(PORT_D, PD_LED2);
      chThdSleepMilliseconds(100);
      palClearPad(PORT_D, PD_LED3);
      chThdSleepMilliseconds(100);
      palClearPad(PORT_D, PD_LED4);
      chThdSleepMilliseconds(100);
      palSetPad(PORT_D, PD_LED1);
      chThdSleepMilliseconds(100);
      palSetPad(PORT_D, PD_LED2);
      chThdSleepMilliseconds(100);
      palSetPad(PORT_D, PD_LED3);
      chThdSleepMilliseconds(100);
      palSetPad(PORT_D, PD_LED4);
      chThdSleepMilliseconds(300);
    }

    for (i = 0; i < 4; i++) {
      palTogglePort(PORT_D, PAL_PORT_BIT(PD_LED1) | PAL_PORT_BIT(PD_LED2) |
                            PAL_PORT_BIT(PD_LED3) | PAL_PORT_BIT(PD_LED4));
      chThdSleepMilliseconds(500);
      palTogglePort(PORT_D, PAL_PORT_BIT(PD_LED1) | PAL_PORT_BIT(PD_LED2) |
                            PAL_PORT_BIT(PD_LED3) | PAL_PORT_BIT(PD_LED4));
      chThdSleepMilliseconds(500);
    }

    for (i = 0; i < 4; i++) {
      palTogglePad(PORT_D, PD_LED1);
      chThdSleepMilliseconds(250);
      palTogglePad(PORT_D, PD_LED1);
      palTogglePad(PORT_D, PD_LED2);
      chThdSleepMilliseconds(250);
      palTogglePad(PORT_D, PD_LED2);
      palTogglePad(PORT_D, PD_LED3);
      chThdSleepMilliseconds(250);
      palTogglePad(PORT_D, PD_LED3);
      palTogglePad(PORT_D, PD_LED4);
      chThdSleepMilliseconds(250);
      palTogglePad(PORT_D, PD_LED4);
    }

    for (i = 0; i < 4; i++) {
      palClearPort(PORT_D, PAL_PORT_BIT(PD_LED1) | PAL_PORT_BIT(PD_LED3));
      palSetPort(PORT_D, PAL_PORT_BIT(PD_LED2) | PAL_PORT_BIT(PD_LED4));
      chThdSleepMilliseconds(500);
      palClearPort(PORT_D, PAL_PORT_BIT(PD_LED2) | PAL_PORT_BIT(PD_LED4));
      palSetPort(PORT_D, PAL_PORT_BIT(PD_LED1) | PAL_PORT_BIT(PD_LED3));
      chThdSleepMilliseconds(500);
    }

    palSetPort(PORT_D, PAL_PORT_BIT(PD_LED1) | PAL_PORT_BIT(PD_LED2) |
                       PAL_PORT_BIT(PD_LED3) | PAL_PORT_BIT(PD_LED4));
  }
}
开发者ID:jmcasallasg,项目名称:ChibiOS,代码行数:64,代码来源:main.c

示例4: main

/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Initializes the PWM driver 1 and ICU driver 1.
   * GPIOD10 is the PWM output.
   * GPIOA0 is the ICU input.
   * The two pins have to be externally connected together.
   */
  icuStart(&ICUD1, &icucfg);
  icuEnable(&ICUD1);

  /* Sets A0 alternative function.*/
  SIU.PCR[0].R = 0b0100010100000100;

  pwmStart(&PWMD1, &pwmcfg);
  /* Sets D10 alternative function.*/
  SIU.PCR[58].R = 0b0100010100000100;

  chThdSleepMilliseconds(2000);

  /*
   * Starts the PWM channel 0 using 75% duty cycle.
   */
  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));
  chThdSleepMilliseconds(5000);

  /*
   * Changes the PWM channel 0 to 50% duty cycle.
   */
  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
  chThdSleepMilliseconds(5000);

  /*
   * Changes the PWM channel 0 to 25% duty cycle.
   */
  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
  chThdSleepMilliseconds(5000);

  /*
   * Changes PWM period and the PWM channel 0 to 50% duty cycle.
   */
  pwmChangePeriod(&PWMD1, 25000);
  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
  chThdSleepMilliseconds(5000);

  /*
   * Disables channel 0 and stops the drivers.
   */
  pwmDisableChannel(&PWMD1, 0);
  pwmStop(&PWMD1);
  icuDisable(&ICUD1);
  icuStop(&ICUD1);
  palClearPad(PORT_D, PD_LED3);
  palClearPad(PORT_D, PD_LED4);

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (TRUE) {
    chThdSleepMilliseconds(500);
  }
  return 0;
}
开发者ID:0x00f,项目名称:ChibiOS,代码行数:76,代码来源:main.c

示例5: TestThread

/**
 * @brief   Test execution thread function.
 *
 * @param[in] p         pointer to a @p BaseChannel object for test output
 * @return              A failure boolean value.
 */
msg_t TestThread(void *p) {
  int i, j;

  chp = p;
  test_println("");
  test_println("*** ChibiOS/RT test suite");
  test_println("***");
  test_print("*** Kernel:       ");
  test_println(CH_KERNEL_VERSION);
  test_print("*** Compiled:     ");
  test_println(__DATE__ " - " __TIME__);
#ifdef CH_COMPILER_NAME
  test_print("*** Compiler:     ");
  test_println(CH_COMPILER_NAME);
#endif
  test_print("*** Architecture: ");
  test_println(CH_ARCHITECTURE_NAME);
#ifdef CH_CORE_VARIANT_NAME
  test_print("*** Core Variant: ");
  test_println(CH_CORE_VARIANT_NAME);
#endif
#ifdef CH_PORT_INFO
  test_print("*** Port Info:    ");
  test_println(CH_PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  test_print("*** Platform:     ");
  test_println(PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  test_print("*** Test Board:   ");
  test_println(BOARD_NAME);
#endif
  test_println("");

  global_fail = FALSE;
  i = 0;
  while (patterns[i]) {
    j = 0;
    while (patterns[i][j]) {
      print_line();
      test_print("--- Test Case ");
      test_printn(i + 1);
      test_print(".");
      test_printn(j + 1);
      test_print(" (");
      test_print(patterns[i][j]->name);
      test_println(")");
#if DELAY_BETWEEN_TESTS > 0
      chThdSleepMilliseconds(DELAY_BETWEEN_TESTS);
#endif
      execute_test(patterns[i][j]);
      if (local_fail) {
        test_print("--- Result: FAILURE (#");
        test_printn(failpoint);
        test_print(" [");
        print_tokens();
        test_println("])");
      }
      else
        test_println("--- Result: SUCCESS");
      j++;
    }
    i++;
  }
  print_line();
  test_println("");
  test_print("Final result: ");
  if (global_fail)
    test_println("FAILURE");
  else
    test_println("SUCCESS");

  return (msg_t)global_fail;
}
开发者ID:rusefi,项目名称:rusefi,代码行数:81,代码来源:test.c

示例6: main

/*
 * Application entry point.
 */
int main(void) {
  thread_t *shelltp1 = NULL;
  thread_t *shelltp2 = NULL;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg1);
  sduObjectInit(&SDU2);
  sduStart(&SDU2, &serusbcfg2);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg1.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg1.usbp, &usbcfg);
  usbConnectBus(serusbcfg1.usbp);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state.
   */
  while (true) {
    if (!shelltp1 && (SDU1.config->usbp->state == USB_ACTIVE))
      shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminatedX(shelltp1)) {
      chThdRelease(shelltp1);   /* Recovers memory of the previous shell.   */
      shelltp1 = NULL;          /* Triggers spawning of a new shell.        */
    }
    if (!shelltp2 && (SDU2.config->usbp->state == USB_ACTIVE))
      shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminatedX(shelltp2)) {
      chThdRelease(shelltp2);   /* Recovers memory of the previous shell.   */
      shelltp2 = NULL;          /* Triggers spawning of a new shell.        */
    }
    chThdSleepMilliseconds(1000);
  }
}
开发者ID:MultiCalorNV,项目名称:verventa-web_Int,代码行数:65,代码来源:main.c

示例7: main

/*
 * Application entry point.
 */
int main(void) {
  static const evhandler_t evhndl[] = {
    InsertHandler,
    RemoveHandler,
    ShellHandler
  };
  event_listener_t el0, el1, el2;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the card insertion monitor.
   */
  tmr_init(&SDCD1);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, handling SD card events and shell
   * start/exit.
   */
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  chEvtRegister(&shell_terminated, &el2, 2);
  while (true) {
    if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) {
      shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
                                    "shell", NORMALPRIO + 1,
                                    shellThread, (void *)&shell_cfg1);
    }
    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
  }
}
开发者ID:jmcasallasg,项目名称:ChibiOS,代码行数:68,代码来源:main.c

示例8: main

/*
 * Application entry point.
 */
int main(void) {
  unsigned i;
  gptcnt_t interval, threshold, worst;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Prepares the Serial driver 1 and GPT drivers 2 and 3.
   */
  sdStart(&SD1, NULL);          /* Default is 38400-8-N-1.*/
  palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7));
  gptStart(&GPTD2, &gpt2cfg);
  gptStart(&GPTD3, &gpt3cfg);

  /*
   * Initializes the mailboxes and creates the worker threads.
   */
  for (i = 0; i < NUM_THREADS; i++) {
    chMBInit(&mb[i], b[i], MAILBOX_SIZE);
    chThdCreateStatic(waWorkerThread[i], sizeof waWorkerThread[i],
                      NORMALPRIO - 20, WorkerThread, (void *)i);
  }

  /*
   * Test procedure.
   */
  println("");
  println("*** ChibiOS/RT IRQ-STORM long duration test");
  println("***");
  print("*** Kernel:       ");
  println(CH_KERNEL_VERSION);
  print("*** Compiled:     ");
  println(__DATE__ " - " __TIME__);
#ifdef CH_COMPILER_NAME
  print("*** Compiler:     ");
  println(CH_COMPILER_NAME);
#endif
  print("*** Architecture: ");
  println(CH_ARCHITECTURE_NAME);
#ifdef CH_CORE_VARIANT_NAME
  print("*** Core Variant: ");
  println(CH_CORE_VARIANT_NAME);
#endif
#ifdef CH_PORT_INFO
  print("*** Port Info:    ");
  println(CH_PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  print("*** Platform:     ");
  println(PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  print("*** Test Board:   ");
  println(BOARD_NAME);
#endif
  println("***");
  print("*** System Clock: ");
  printn(STM32_SYSCLK);
  println("");
  print("*** Iterations:   ");
  printn(ITERATIONS);
  println("");
  print("*** Randomize:    ");
  printn(RANDOMIZE);
  println("");
  print("*** Threads:      ");
  printn(NUM_THREADS);
  println("");
  print("*** Mailbox size: ");
  printn(MAILBOX_SIZE);
  println("");

  println("");
  worst = 0;
  for (i = 1; i <= ITERATIONS; i++){
    print("Iteration ");
    printn(i);
    println("");
    saturated = FALSE;
    threshold = 0;
    for (interval = 2000; interval >= 20; interval -= interval / 10) {
      gptStartContinuous(&GPTD2, interval - 1); /* Slightly out of phase.*/
      gptStartContinuous(&GPTD3, interval + 1); /* Slightly out of phase.*/
      chThdSleepMilliseconds(1000);
      gptStopTimer(&GPTD2);
      gptStopTimer(&GPTD3);
      if (!saturated)
        print(".");
//.........这里部分代码省略.........
开发者ID:ColonelPanic42,项目名称:ChibiOS-RPi,代码行数:101,代码来源:main.c

示例9: main

/*
 * Application entry point.
 */
int main(void) {
  Thread *shelltp = NULL;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1000);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Activates the serial driver 2 using the driver default configuration.
   * PA2(TX) and PA3(RX) are routed to USART2.
   */
  sdStart(&SD2, NULL);
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));

  /*
   * Initializes the SPI driver 1 in order to access the MEMS. The signals
   * are already initialized in the board file.
   */
  spiStart(&SPID1, &spi1cfg);

  /*
   * Initializes the SPI driver 2. The SPI2 signals are routed as follow:
   * PB12 - NSS.
   * PB13 - SCK.
   * PB14 - MISO.
   * PB15 - MOSI.
   */
  spiStart(&SPID2, &spi2cfg);
  palSetPad(GPIOB, 12);
  palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
                           PAL_STM32_OSPEED_HIGHEST);           /* NSS.     */
  palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
                           PAL_STM32_OSPEED_HIGHEST);           /* SCK.     */
  palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5));              /* MISO.    */
  palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) |
                           PAL_STM32_OSPEED_HIGHEST);           /* MOSI.    */

  /*
   * Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs.
   */
  pwmStart(&PWMD4, &pwmcfg);
  palSetPadMode(GPIOD, GPIOD_LED4, PAL_MODE_ALTERNATE(2));      /* Green.   */
  palSetPadMode(GPIOD, GPIOD_LED3, PAL_MODE_ALTERNATE(2));      /* Orange.  */
  palSetPadMode(GPIOD, GPIOD_LED5, PAL_MODE_ALTERNATE(2));      /* Red.     */
  palSetPadMode(GPIOD, GPIOD_LED6, PAL_MODE_ALTERNATE(2));      /* Blue.    */

  /*
   * Creates the example thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1),
                    NORMALPRIO + 10, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it just performs
   * a shell respawn upon its termination.
   */
  while (TRUE) {
    if (!shelltp) {
      if (SDU1.config->usbp->state == USB_ACTIVE) {
        /* Spawns a new shell.*/
        shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
      }
    }
    else {
      /* If the previous shell exited.*/
      if (chThdTerminated(shelltp)) {
        /* Recovers memory of the previous shell.*/
        chThdRelease(shelltp);
        shelltp = NULL;
//.........这里部分代码省略.........
开发者ID:DuinoPilot,项目名称:ChibiOS,代码行数:101,代码来源:main.c

示例10: thdUsbStorage

static msg_t     thdUsbStorage(void *arg)
{
  (void) arg; // unused
  chRegSetThreadName("UsbStorage:polling");
  uint antiBounce=5;
  EventListener connected;

  // Should use EXTI interrupt instead of active polling,
  // but in the chibios_opencm3 implementation, since EXTI is
  // used via libopencm3, ISR are routed on pprz/opencm3 and cannot
  // be used concurrently by chibios api
  // Should be fixed when using chibios-rt branch
  while (!chThdShouldTerminate() && antiBounce) {
    const bool_t usbConnected = palReadPad (GPIOA, GPIOA_OTG_FS_VBUS);
    if (usbConnected)
      antiBounce--;
    else
      antiBounce=5;

    chThdSleepMilliseconds(20);
  }
  isRunning = true;
  chRegSetThreadName("UsbStorage:connected");

  /* Stop the logs*/
  chibios_logFinish (true);


  /* connect sdcard sdc interface sdio */
  if (sdioConnect () == false)
    chThdExit (RDY_TIMEOUT);

  /* initialize the USB mass storage driver */
  msdInit(&UMSD1);

  /* start the USB mass storage service */
  msdStart(&UMSD1, &msdConfig);

  /* start the USB driver */
  usbDisconnectBus(&USBD1);
  chThdSleepMilliseconds(1000);
  usbStart(&USBD1, &usbConfig);
  usbConnectBus(&USBD1);

  /* wait for a real usb storage connexion before shutting down autopilot */
  chEvtRegisterMask(&UMSD1.evt_connected, &connected, EVENT_MASK(1));
  chEvtWaitOne(EVENT_MASK(1));

  /* stop autopilot */
  if (pprzThdPtr != NULL) {
    chThdTerminate (pprzThdPtr);
    chThdWait (pprzThdPtr);
    pprzThdPtr = NULL;
  }

  /* wait until usb-storage is unmount and usb cable is unplugged*/
  while (!chThdShouldTerminate() && palReadPad (GPIOA, GPIOA_OTG_FS_VBUS)) {
    chThdSleepMilliseconds(10);
  }


  /* then close open descriptors and reboot autopilot */
  usbDisconnectBus(&USBD1);
  chThdSleepMilliseconds(500);
  msdStop(&UMSD1);
  sdioDisconnect ();

  MCU_RESTART();
  return RDY_OK;
}
开发者ID:AE4317group07,项目名称:paparazzi,代码行数:70,代码来源:usbStorage.c

示例11: sleepMilliseconds

 static void sleepMilliseconds(uint32_t ms)
 {
     chThdSleepMilliseconds(ms);
 }
开发者ID:vazk,项目名称:Norse,代码行数:4,代码来源:yggChibiosTraits.hpp

示例12: THD_FUNCTION

THD_FUNCTION(Thread1, arg) {

  (void)arg;

  /*
   * Activate the serial driver 0 using the driver default configuration.
   */
  sdStart(&SD0, NULL);

  while (chnGetTimeout(&SD0, TIME_INFINITE)) {
    chnWrite(&SD0, (const uint8_t *)start_msg, strlen(start_msg));
    chThdSleepMilliseconds(2000);

    /* Test 1 - use DMA engine to execute a word-wise memory-to-memory copy. */
    chnWrite(&SD0, (const uint8_t *)test_1_msg, strlen(test_1_msg));
    strcpy(instring, "After DMA test  \r\n");
    strcpy(outstring, "Before DMA test \r\n");
    if (strcmp("Before DMA test \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    request = &test_1_req;
    chSysLock();
    dmaRequestS(request, TIME_INFINITE);
    chSysUnlock();
    if (strcmp("After DMA test  \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    else {
      chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string));
    }

    /* Test 2 - use DMA engine to execute a byte-wise memory-to-memory copy. */
    chnWrite(&SD0, (const uint8_t *)test_2_msg, strlen(test_2_msg));
    strcpy(instring, "After DMA test  \r\n");
    strcpy(outstring, "Before DMA test \r\n");
    if (strcmp("Before DMA test \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    request = &test_2_req;
    chSysLock();
    dmaRequestS(request, TIME_INFINITE);
    chSysUnlock();
    if (strcmp("After DMA test  \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    else {
      chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string));
    }

    /* Test 3 - use DMA engine to execute a word-wise memory-to-memory set. */
    chnWrite(&SD0, (const uint8_t *)test_3_msg, strlen(test_3_msg));
    strcpy(instring, "After DMA test  \r\n");
    strcpy(outstring, "Before DMA test \r\n");
    if (strcmp("Before DMA test \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    request = &test_3_req;
    chSysLock();
    dmaRequestS(request, TIME_INFINITE);
    chSysUnlock();
    if (strcmp("AAAAAAAAAAAAAAAA\r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    else {
      chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string));
    }

    /* Test 4 - use DMA engine to execute a word-wise memory-to-memory copy,
     * then call a callback. */
    chnWrite(&SD0, (const uint8_t *)test_4_msg, strlen(test_4_msg));
    strcpy(instring, "After DMA test  \r\n");
    strcpy(outstring, "Before DMA test \r\n");
    cb_arg = 1;
    if (strcmp("Before DMA test \r\n", outstring) || (cb_arg != 1)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    request = &test_4_req;
    chSysLock();
    dmaRequestS(request, TIME_INFINITE);
    chSysUnlock();
    if (strcmp("After DMA test  \r\n", outstring) || cb_arg) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    else {
      chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string));
    }

    /* Test 5 - use exclusive DMA channel 0 to execute a word-wise
     * memory-to-memory copy. */
    chnWrite(&SD0, (const uint8_t *)test_5_msg, strlen(test_5_msg));
    strcpy(instring, "After DMA test  \r\n");
    strcpy(outstring, "Before DMA test \r\n");
    if (strcmp("Before DMA test \r\n", outstring)) {
      chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string));
    }
    request = &test_5_req;
    chSysLock();
    dmaAcquireI(&ch, 0);
    chSysUnlock();
    dmaTransfer(&ch, request);
//.........这里部分代码省略.........
开发者ID:ChibiOS,项目名称:ChibiOS-Contrib,代码行数:101,代码来源:main.c

示例13: main

/*
 * Application entry point.
 */
int main(void) {
  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 2 and SDC driver 1 using default
   * configuration.
   */
  sdStart(&SD6, NULL);

  BaseSequentialStream *chp = (BaseSequentialStream *)&SD6;
  chprintf(chp, "running main()\r\n");
  chThdSleepMilliseconds(50);

#if STM32_USB_USE_OTG2
  USBDriver *usb_driver = &USBD2;
#else
  USBDriver *usb_driver = &USBD1;
#endif

  /*
   * Activates the card insertion monitor.
   */
  init_sd();
  chprintf(chp, "done starting SDC\r\n");
  const bool_t sdcConnectStatus = sdcConnect(&SDCD1);
  if( sdcConnectStatus != CH_SUCCESS ) {
    chprintf(chp, "failed to connect to SD Card, sdcConnectStatus = %u\r\n", sdcConnectStatus);
    for(;;) {
      chThdSleepMilliseconds(3000);
    }
  }

  chprintf(chp, "setting up MSD\r\n");
  const usb_msd_driver_state_t msd_driver_state = msdInit(usb_driver, (BaseBlockDevice*)&SDCD1, &UMSD1, USB_MS_DATA_EP, USB_MSD_INTERFACE_NUMBER);
  if( msd_driver_state != USB_MSD_DRIVER_OK ) {
    chprintf(chp, "Error initing USB MSD, %d %s\r\n", msd_driver_state, usb_msd_driver_state_t_to_str(msd_driver_state));
  }
  UMSD1.chp = chp;

  chprintf(chp, "Initializing SDU1...\r\n");
  serusbcfg.usbp = usb_driver;
  sduObjectInit(&SDU1);

  /*Disconnect the USB Bus*/
  usbDisconnectBus(usb_driver);
  chThdSleepMilliseconds(200);

  /*Start the useful functions*/
  sduStart(&SDU1, &serusbcfg);
  msdStart(&UMSD1);
  usbStart(usb_driver, &msd_usb_config);

  /*Connect the USB Bus*/
  usbConnectBus(usb_driver);

  /*
   * Creates the blinker thread.
   */
  chprintf(chp, "starting blinker thread\r\n");
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  while (TRUE) {
    palTogglePad(GPIOC, GPIOC_LED);
    chThdSleepMilliseconds(500);
  }
}
开发者ID:GotoHack,项目名称:ChibiOS,代码行数:77,代码来源:main.c

示例14: main

int main(void) {
	Thread * pub_tp = NULL;
	Thread * sub_tp = NULL;

	halInit();
	chSysInit();

	/*
	 * Initializes a serial-over-USB CDC driver.
	 */
#if USE_USB_SERIAL
	sduObjectInit(&SDU1);
	sduStart(&SDU1, &serusbcfg);
#endif

	/*
	 * Activates the USB driver and then the USB bus pull-up on D+.
	 * Note, a delay is inserted in order to not have to disconnect the cable
	 * after a reset.
	 */
#if USE_USB_SERIAL
	usbDisconnectBus(serusbcfg.usbp);
	chThdSleepMilliseconds(500);
	usbStart(serusbcfg.usbp, &usbcfg);
	usbConnectBus(serusbcfg.usbp);
#endif

	/* Start the serial driver. */
#if !USE_USB_SERIAL
	sdStart(&SD3, NULL);
#endif

	for (;;) {
#if USE_USB_SERIAL
		if (!pub_tp && (SDU1.config->usbp->state == USB_ACTIVE)) {
#else
		if (!pub_tp) {
#endif
			pub_tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(2048), NORMALPRIO, rosserial_pub_thread, NULL);
		} else if (chThdTerminated(pub_tp)) {
			chThdRelease(pub_tp);
			pub_tp = NULL;
		}

		chThdSleepMilliseconds(123);

#if USE_USB_SERIAL
		if (!sub_tp && (SDU1.config->usbp->state == USB_ACTIVE)) {
#else
		if (!sub_tp) {
#endif
			sub_tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(2048), NORMALPRIO, rosserial_sub_thread, NULL);
		} else if (chThdTerminated(sub_tp)) {
			chThdRelease(sub_tp);
			sub_tp = NULL;
		}

		chThdSleepMilliseconds(500);
	}

	return CH_SUCCESS;
}
}
开发者ID:ianathompson,项目名称:eDO_boards_firmware,代码行数:63,代码来源:pubsub_test.cpp

示例15: main

/*
 * Application entry point.
 */
int main(void) {

  /* Initialization of all the imported components in the order specified in
	 the application wizard. The function is generated automatically.*/
  componentsInit();

  palClearPad(PORT11, P11_LED4);

  /*
   * Initializes the PWM driver 8 and ICU driver 1.
   * PIN80 is the PWM output.
   * PIN63 is the ICU input.
   * The two pins have to be externally connected together.
   */

  /* Sets PIN63 alternative function.*/
  SIU.PCR[179].R = 0b0000010100001100;

  /* Sets PIN80 alternative function.*/
  SIU.PCR[202].R = 0b0000011000001100;

  icuStart(&ICUD1, &icucfg);
  icuEnable(&ICUD1);
  pwmStart(&PWMD8, &pwmcfg);

  chThdSleepMilliseconds(2000);

  /*
   * Starts the PWM channel 0 using 75% duty cycle.
   */
  pwmEnableChannel(&PWMD8, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD8, 7500));
  chThdSleepMilliseconds(5000);

  /*
   * Changes the PWM channel 0 to 50% duty cycle.
   */
  pwmEnableChannel(&PWMD8, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD8, 5000));
  chThdSleepMilliseconds(5000);

  /*
   * Changes the PWM channel 0 to 25% duty cycle.
   */
  pwmEnableChannel(&PWMD8, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD8, 2500));
  chThdSleepMilliseconds(5000);

  /*
   * Changes PWM period and the PWM channel 0 to 50% duty cycle.
   */
  pwmChangePeriod(&PWMD8, 25000);
  pwmEnableChannel(&PWMD8, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD8, 5000));
  chThdSleepMilliseconds(5000);

  /*
   * Disables PWM channel 0 and stops the drivers.
   */
  pwmDisableChannel(&PWMD8, 0);
  pwmStop(&PWMD8);

  /*
   * Disables and stops the ICU drivers.
   */

  icuDisable(&ICUD1);
  icuStop(&ICUD1);

  palClearPad(PORT11, P11_LED3);
  palClearPad(PORT11, P11_LED4);

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (TRUE) {
    chThdSleepMilliseconds(500);
  }
  return 0;
}
开发者ID:0x00f,项目名称:ChibiOS,代码行数:79,代码来源:main.c


注:本文中的chThdSleepMilliseconds函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。