Exemplo n.º 1
0
/*! \brief Initialize ADIS driver
 *
 */
void adis_init() {
	uint8_t     i              = 0;

	//chMtxInit(&adis_driver.adis_mtx);
	//chCondInit(&adis_driver.adis_cv1);

	adis_driver.spi_instance    = &SPID1;
	adis_driver.state           = ADIS_IDLE;
	adis_driver.reg             = ADIS_PRODUCT_ID;
	adis_driver.debug_cb_count  = 0;
	adis_driver.debug_spi_count = 0;

	for(i=0; i<ADIS_MAX_TX_BUFFER; ++i) {
		adis_driver.adis_txbuf[i]        = 0;
		adis_cache_data.adis_tx_cache[i] = 0;
	}
	for(i=0; i<ADIS_MAX_RX_BUFFER; ++i) {
		adis_driver.adis_rxbuf[i]        = 0xa5;
		adis_cache_data.adis_rx_cache[i] = 0xa5;
	}
	chEvtInit(&adis_dio1_event);
	chEvtInit(&adis_spi_cb_txdone_event);
	chEvtInit(&adis_spi_cb_newdata);
	chEvtInit(&adis_spi_cb_releasebus);
}
Exemplo n.º 2
0
// Polling monitor start.
static void tmr_init(void *p) {
  chEvtInit(&inserted_event);
  chEvtInit(&removed_event);
  chSysLock();
  cnt = POLLING_INTERVAL;
  chVTSetI(&tmr, MS2ST(POLLING_DELAY), tmrfunc, p);
  chSysUnlock();
}
Exemplo n.º 3
0
/**
 * @brief   Polling monitor start.
 *
 * @param[in] sdcp      pointer to the @p SDCDriver object
 *
 * @notapi
 */
static void tmr_init(SDCDriver *sdcp) {

  chEvtInit(&inserted_event);
  chEvtInit(&removed_event);
  chSysLock();
  cnt = SDC_POLLING_INTERVAL;
  chVTSetI(&tmr, MS2ST(SDC_POLLING_DELAY), tmrfunc, sdcp);
  chSysUnlock();
}
Exemplo n.º 4
0
/**
 * @brief   Initializes an instance.
 *
 * @param[out] mmcp         pointer to the @p MMCDriver object
 * @param[in] spip          pointer to the SPI driver to be used as interface
 * @param[in] lscfg         low speed configuration for the SPI driver
 * @param[in] hscfg         high speed configuration for the SPI driver
 * @param[in] is_protected  function that returns the card write protection
 *                          setting
 * @param[in] is_inserted   function that returns the card insertion sensor
 *                          status
 *
 * @init
 */
void mmcObjectInit(MMCDriver *mmcp) {

  mmcp->vmt = &mmc_vmt;
  mmcp->state = MMC_STOP;
  mmcp->config = NULL;
  mmcp->block_addresses = FALSE;
  chEvtInit(&mmcp->inserted_event);
  chEvtInit(&mmcp->removed_event);
}
Exemplo n.º 5
0
/**
 * @brief   Polling monitor start.
 *
 * @param[in] p         pointer to an object implementing @p BaseBlockDevice
 *
 * @notapi
 */
void sdc_tmr_init(void *p) {

    chEvtInit(&sdc_inserted_event);
    chEvtInit(&sdc_removed_event);
    chEvtInit(&sdc_halt_event);
    chEvtInit(&sdc_start_event);
    chSysLock();
    sdc_debounce_count = sdc_polling_interval;
    chVTSetI(&sdc_tmr, MS2ST(sdc_polling_delay), sdc_tmrfunc, p);
    chSysUnlock();
}
Exemplo n.º 6
0
/*
 * 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();

	chEvtInit(&eventImuIrq);
	chEvtInit(&eventMagnIrq);
	chEvtInit(&eventImuRead);
	chEvtInit(&eventMagnRead);
	chEvtInit(&eventEKFDone);

	palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL); // BLUE
	palSetPadMode(GPIOB, 4, PAL_MODE_OUTPUT_PUSHPULL); // GREEN
	palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); // RED
	chThdCreateStatic(waThreadLed, sizeof(waThreadLed), NORMALPRIO, ThreadLed, NULL );

	I2CInitLocal();
	configInit();
	mavlinkInit();
	initSensors();

	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
	TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
	TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
	TIM_Cmd(TIM5, ENABLE);

	startEstimation();
	startSensors();
	radioInit();
	motorsInit();

	extStart(&EXTD1, &extcfg);
	extChannelEnable(&EXTD1, 0);
	extChannelEnable(&EXTD1, 1);

	chEvtBroadcastFlags(&eventEKFDone, EVT_EKF_DONE);

	while (TRUE) {
		chThdSleepMilliseconds(1000);
	}
}
Exemplo n.º 7
0
/**
 * @brief   Initializes an instance.
 *
 * @param[in] mmcp          pointer to the @p MMCDriver object
 * @param[in] spip          pointer to the SPI driver to be used as interface
 * @param[in] lscfg         low speed configuration for the SPI driver
 * @param[in] hscfg         high speed configuration for the SPI driver
 * @param[in] is_protected  function that returns the card write protection
 *                          setting
 * @param[in] is_inserted   function that returns the card insertion sensor
 *                          status
 */
void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
                   const SPIConfig *lscfg, const SPIConfig *hscfg,
                   mmcquery_t is_protected, mmcquery_t is_inserted) {

  mmcp->mmc_state = MMC_STOP;
  mmcp->mmc_config = NULL;
  mmcp->mmc_spip = spip;
  mmcp->mmc_lscfg = lscfg;
  mmcp->mmc_hscfg = hscfg;
  mmcp->mmc_is_protected = is_protected;
  mmcp->mmc_is_inserted = is_inserted;
  chEvtInit(&mmcp->mmc_inserted_event);
  chEvtInit(&mmcp->mmc_removed_event);
}
Exemplo n.º 8
0
/**
 * @brief   Initializes an instance.
 *
 * @param[out] mmcp         pointer to the @p MMCDriver object
 * @param[in] spip          pointer to the SPI driver to be used as interface
 * @param[in] lscfg         low speed configuration for the SPI driver
 * @param[in] hscfg         high speed configuration for the SPI driver
 * @param[in] is_protected  function that returns the card write protection
 *                          setting
 * @param[in] is_inserted   function that returns the card insertion sensor
 *                          status
 *
 * @init
 */
void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
                   const SPIConfig *lscfg, const SPIConfig *hscfg,
                   mmcquery_t is_protected, mmcquery_t is_inserted) {

  mmcp->state = MMC_STOP;
  mmcp->config = NULL;
  mmcp->spip = spip;
  mmcp->lscfg = lscfg;
  mmcp->hscfg = hscfg;
  mmcp->is_protected = is_protected;
  mmcp->is_inserted = is_inserted;
  mmcp->block_addresses = FALSE;
  chEvtInit(&mmcp->inserted_event);
  chEvtInit(&mmcp->removed_event);
}
Exemplo n.º 9
0
/**
 * @brief   Initializes the standard part of a @p CANDriver structure.
 *
 * @param[out] canp     pointer to the @p CANDriver object
 *
 * @init
 */
void canObjectInit(CANDriver *canp) {

  canp->state    = CAN_STOP;
  canp->config   = NULL;
  chSemInit(&canp->txsem, 0);
  chSemInit(&canp->rxsem, 0);
  chEvtInit(&canp->rxfull_event);
  chEvtInit(&canp->txempty_event);
  chEvtInit(&canp->error_event);
  canp->status = 0;
#if CAN_USE_SLEEP_MODE
  chEvtInit(&canp->sleep_event);
  chEvtInit(&canp->wakeup_event);
#endif /* CAN_USE_SLEEP_MODE */
}
Exemplo n.º 10
0
bool_t chibios_logInit(const bool_t binaryFile)
{
  nvicSetSystemHandlerPriority(HANDLER_PENDSV,
             CORTEX_PRIORITY_MASK(15));

  if (sdLogInit (NULL) != SDLOG_OK)
    goto error;

  if (sdLogOpenLog (&pprzLogFile, PPRZ_LOG_DIR, PPRZ_LOG_NAME) != SDLOG_OK)
    goto error;

#if LOG_PROCESS_STATE
  if (sdLogOpenLog (&processLogFile, PROCESS_LOG_NAME) != SDLOG_OK)
    goto error;
#endif

  if  (sdLoglaunchThread (binaryFile) != SDLOG_OK)
    goto error;

  chEvtInit (&powerOutageSource);

  launchBatterySurveyThread ();

  return TRUE;

error:
  return FALSE;
}
Exemplo n.º 11
0
void Infrared_t::RxInit() {
    chEvtInit(&IEvtSrcIrRx);
    // GPIO
    PinSetupOut(IR_RX_PWR_GPIO, IR_RX_PWR_PIN, omPushPull); // }
    PinSet(IR_RX_PWR_GPIO, IR_RX_PWR_PIN);                  // } Power
    PinSetupIn(IR_RX_IN_GPIO, IR_RX_IN_PIN, pudNone);       // Input
    // ==== Timer ====
    RxTimer.Init();
    RxTimer.Enable();
    RxTimer.SetTopValue(0xFFFF);        // Maximum
    RxTimer.SetupPrescaler(1000000);    // Input Freq: 1 MHz => one tick = 1 uS
    //RxTimer.Disable();
    // ==== Input queue ====
    chMBInit(&imailbox, IRxBuf, IR_RXBUF_SZ);
    // ==== Receiving thread ====
    chThdCreateStatic(waIRRxThread, sizeof(waIRRxThread), NORMALPRIO, IRRxThread, NULL);

    // ==== IRQ ==== PC5
    rccEnableAPB2(RCC_APB2ENR_SYSCFGEN, FALSE); // Enable sys cfg controller
    SYSCFG->EXTICR[1] &= 0xFFFFFF0F;    // EXTI5 is connected to PortC
    SYSCFG->EXTICR[1] |= 0x00000020;    // EXTI5 is connected to PortC
    // Configure EXTI line
    EXTI->IMR  |=  IR_IRQ_MASK;         // Interrupt mode enabled
    EXTI->EMR  &= ~IR_IRQ_MASK;         // Event mode disabled
    RxIrqWaitFalling();
    EXTI->PR    =  IR_IRQ_MASK;         // Clean irq flag
    nvicEnableVector(EXTI9_5_IRQn, CORTEX_PRIORITY_MASK(IRQ_PRIO_HIGH));
}
Exemplo n.º 12
0
int motor_init(void)
{
	_watchdog_id = watchdog_create(WATCHDOG_TIMEOUT_MSEC);
	if (_watchdog_id < 0) {
		return _watchdog_id;
	}

	int ret = motor_rtctl_init();
	if (ret) {
		return ret;
	}

	chMtxInit(&_mutex);
	chEvtInit(&_setpoint_update_event);

	configure();

	init_filters();
	if (_state.input_voltage < MIN_VALID_INPUT_VOLTAGE || _state.input_voltage > MAX_VALID_INPUT_VOLTAGE) {
		lowsyslog("Motor: Invalid input voltage: %f\n", _state.input_voltage);
		return -1;
	}

	ret = rpmctl_init();
	if (ret) {
		return ret;
	}

	motor_rtctl_stop();

	assert_always(chThdCreateStatic(_wa_control_thread, sizeof(_wa_control_thread),
	                                HIGHPRIO, control_thread, NULL));
	return 0;
}
Exemplo n.º 13
0
static void mpu9150_init(I2CDriver* i2cptr) {
	mpu9150_reg_data           rdata;

    chEvtInit(&mpu9150_data_event);
	
	mpu9150_reset(i2cptr);

	rdata = MPU9150_PM1_X_GYRO_CLOCKREF & (~(MPU9150_PM1_SLEEP));   // make sure device is 'awake'
	mpu9150_write_pm1(i2cptr, rdata);

	rdata = 16;                                          // 2 ms sample period.
	mpu9150_write_gyro_sample_rate_div(i2cptr, rdata);

	rdata = MPU9150_I2C_BYPASS | MPU9150_INT_LEVEL | MPU9150_LATCH_INT_EN;
	mpu9150_write_pin_cfg(i2cptr, rdata);

	rdata = MPU9150_A_HPF_RESET | MPU9150_A_SCALE_pm16g;
	mpu9150_write_accel_config(i2cptr, rdata);

	rdata = MPU9150_G_SCALE_pm2000;
	mpu9150_write_gyro_config(i2cptr, rdata);

	rdata = MPU9150_INT_EN_DATA_RD_EN;
	mpu9150_write_int_enable(i2cptr, rdata);

}
Exemplo n.º 14
0
/**
 * @brief   Initializes a generic full duplex driver object.
 * @details The HW dependent part of the initialization has to be performed
 *          outside, usually in the hardware initialization code.
 *
 * @param[out] bdup     pointer to a @p BulkUSBDriver structure
 *
 * @init
 */
void bduObjectInit(BulkUSBDriver *bdup) {

  bdup->vmt = &vmt;
  chEvtInit(&bdup->event);
  bdup->state = BDU_STOP;
  chIQInit(&bdup->iqueue, bdup->ib, BULK_USB_BUFFERS_SIZE, inotify, bdup);
  chOQInit(&bdup->oqueue, bdup->ob, BULK_USB_BUFFERS_SIZE, onotify, bdup);
}
Exemplo n.º 15
0
/**
 * @brief   Initialize the standard part of a @p MACDriver structure.
 *
 * @param[in] macp      pointer to the @p MACDriver object
 */
void macObjectInit(MACDriver *macp) {

  chSemInit(&macp->md_tdsem, 0);
  chSemInit(&macp->md_rdsem, 0);
#if CH_USE_EVENTS
  chEvtInit(&macp->md_rdevent);
#endif
}
Exemplo n.º 16
0
void mpl3115a2_start(I2CDriver* i2c) {
    uint8_t         i = 0;

    mpl3115a2_driver.i2c_errors           = 0;
    mpl3115a2_driver.i2c_instance         = i2c;
    for(i=0; i<MPL3115A2_MAX_TX_BUFFER; ++i) {
        mpl3115a2_driver.txbuf[i] = 0;
    }
    for(i=0; i<MPL3115A2_MAX_RX_BUFFER; ++i) {
        mpl3115a2_driver.rxbuf[i] = 0xa5;
    }
    mpl3115a2_current_read.mpl_pressure    = 0xa5a5a5a5;
    mpl3115a2_current_read.mpl_temperature = 0xa5a5a5a5;

    chEvtInit(&mpl3115a2_data_event);
    chEvtInit(&mpl3115a2_int_event);
}
Exemplo n.º 17
0
/**
 * @brief   Initializes a generic full duplex driver object.
 * @details The HW dependent part of the initialization has to be performed
 *          outside, usually in the hardware initialization code.
 *
 * @param[out] sdp      pointer to a @p SerialDriver structure
 * @param[in] inotify   pointer to a callback function that is invoked when
 *                      some data is read from the Queue. The value can be
 *                      @p NULL.
 * @param[in] onotify   pointer to a callback function that is invoked when
 *                      some data is written in the Queue. The value can be
 *                      @p NULL.
 *
 * @init
 */
void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {

  sdp->vmt = &vmt;
  chEvtInit(&sdp->event);
  sdp->state = SD_STOP;
  chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp);
  chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp);
}
Exemplo n.º 18
0
/**
 * @brief   Initializes a generic full duplex driver object.
 * @details The HW dependent part of the initialization has to be performed
 *          outside, usually in the hardware initialization code.
 *
 * @param[out] sdup     pointer to a @p SerialUSBDriver structure
 *
 * @init
 */
void sduObjectInit(SerialUSBDriver *sdup) {

  sdup->vmt = &vmt;
  chEvtInit(&sdup->event);
  sdup->flags = CHN_NO_ERROR;
  sdup->state = SDU_STOP;
  chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify, sdup);
  chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify, sdup);
}
Exemplo n.º 19
0
/**
 * @brief   Initialize the standard part of a @p MACDriver structure.
 *
 * @param[out] macp     pointer to the @p MACDriver object
 *
 * @init
 */
void macObjectInit(MACDriver *macp) {

  macp->state  = MAC_STOP;
  macp->config = NULL;
  chSemInit(&macp->tdsem, 0);
  chSemInit(&macp->rdsem, 0);
#if MAC_USE_EVENTS
  chEvtInit(&macp->rdevent);
#endif
}
Exemplo n.º 20
0
void rtcInit(uint32_t time)
{
    RCC->APB1ENR |= RCC_APB1ENR_BKPEN | RCC_APB1ENR_PWREN; // Enable PWR and RTC perif
    PWR->CR |= PWR_CR_DBP; // enable access to RTC, BDC registers

#ifdef EXT32768
    RCC->BDCR |= RCC_BDCR_LSEON;
    while( (RCC->BDCR & RCC_BDCR_LSERDY) == 0 ) ; // Wait for LSERDY = 1 (LSE is ready)
#else
    RCC->CSR |= RCC_CSR_LSION;
    while( (RCC->CSR & RCC_CSR_LSIRDY) == 0 ) ; // Wait for LSIRDY = 1 (iternal 40khz rtc oscillator ready)
#endif

    RCC->BDCR |= RCC_BDCR_RTCEN | RCC_BDCR_RTCSEL_0;
    while( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) ; // Poll RTOFF, wait until its value goes to ‘1’

    RTC->CRL |= RTC_CRL_CNF;
    RTC->PRLH = 0;
    RTC->PRLL = 32768-1;
    if(time)
    {
        RTC->CNTL = time & 0xFFFF;
        RTC->CNTH = time >> 16;
        RTC->ALRL = 0xFFFF;
        RTC->ALRH = 0xFFFF;
    }

    RTC->CRH = RTC_CRH_SECIE;

    RTC->CRL &= ~RTC_CRL_CNF;
    while( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) ; // Poll RTOFF, wait until its value goes to ‘1’ to check the end of the write operation.

    PWR->CR &= ~PWR_CR_DBP; // disable access to RTC registers

    // Init OS depended functions
    chEvtInit(&rtcEvtSecond);
    chEvtInit(&rtcEvtAlarm);

    // Enable interrupt
    NVICEnableVector(RTC_IRQn, 0xC0);
}
Exemplo n.º 21
0
Arquivo: pill.cpp Projeto: Kreyl/nute
void PillInit() {
    PillDeinit();
    PinSetupOut(PERIPH_PWR_GPIO, PERIPH_PWR_PIN, omPushPull);   // Power
    PinSet(PERIPH_PWR_GPIO, PERIPH_PWR_PIN);
    chThdSleepMilliseconds(1);  // Allow power to rise
    i2c.Init(PILL_I2C, PILL_I2C_GPIO, PILL_SCL_PIN, PILL_SDA_PIN, PILL_I2C_BITRATE_HZ, PILL_DMATX, PILL_DMARX);
    // Firmware
    chEvtInit(&IEvtPillChange);
    // Pills
    for(uint8_t i=0; i<PILL_CNT; i++) Pill[i].Init(i);
    // Thread
    chThdCreateStatic(waPillThread, sizeof(waPillThread), NORMALPRIO, PillThread, NULL);
}
Exemplo n.º 22
0
void cc1101_t::Init() {
    // ==== GPIO ====
    PinSetupOut(GPIOA, CC_CS,   omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_SCK,  omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_MISO, omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_MOSI, omPushPull);
    PinSetupIn(GPIOA, CC_GDO0, pudNone);
    PinSetupIn(GPIOA, CC_GDO2, pudNone);
    CsHi();

    // ==== SPI ====    MSB first, master, ClkLowIdle, FirstEdge, Baudrate=f/2
    SpiSetup(CC_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv2);
    SpiEnable(CC_SPI);

    // ==== Init CC ====
    CReset();
    FlushRxFIFO();
    RfConfig();
    chEvtInit(&IEvtSrcRx);
    chEvtInit(&IEvtSrcTx);
    State = ccIdle;

    // ==== IRQ ====
    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Enable AFIO clock
    uint8_t tmp = CC_GDO0 / 4;          // Indx of EXTICR register
    uint8_t Shift = (CC_GDO0 & 0x03) * 4;
    AFIO->EXTICR[tmp] &= ~((uint32_t)0b1111 << Shift);    // Clear bits and leave clear to select GPIOA
    tmp = 1<<CC_GDO0;   // IRQ mask
    // Configure EXTI line
    EXTI->IMR  |=  tmp;      // Interrupt mode enabled
    EXTI->EMR  &= ~tmp;      // Event mode disabled
    EXTI->RTSR &= ~tmp;      // Rising trigger disabled
    EXTI->FTSR |=  tmp;      // Falling trigger enabled
    EXTI->PR    =  tmp;      // Clean irq flag
    nvicEnableVector(EXTI4_IRQn, CORTEX_PRIORITY_MASK(IRQ_PRIO_MEDIUM));
}
Exemplo n.º 23
0
/**
 * @brief Buzzer driver initialization.
 */
void buzzInit(void) {

  chEvtInit(&BuzzerSilentEventSource);

  /*
   * Switches P0.12 and P0.13 to MAT1.0 and MAT1.1 functions.
   * Enables Timer1 clock.
   */
  PINSEL0 &= 0xF0FFFFFF;
  PINSEL0 |= 0x0A000000;
  PCONP = (PCONP & PCALL) | PCTIM1;

  /*
   * Timer setup.
   */
  TC *tc = T1Base;
  StopCounter(tc);
  tc->TC_CTCR = 0;                      /* Clock source is PCLK.        */
  tc->TC_PR   = 0;                      /* Prescaler disabled.          */
  tc->TC_MCR  = 2;                      /* Clear TC on match MR0.       */
}
Exemplo n.º 24
0
static void evt1_execute(void) {
  EventListener el1, el2;

  /*
   * Testing chEvtRegisterMask() and chEvtUnregister().
   */
  chEvtInit(&es1);
  chEvtRegisterMask(&es1, &el1, 1);
  chEvtRegisterMask(&es1, &el2, 2);
  test_assert(1, chEvtIsListeningI(&es1), "no listener");
  chEvtUnregister(&es1, &el1);
  test_assert(2, chEvtIsListeningI(&es1), "no listener");
  chEvtUnregister(&es1, &el2);
  test_assert(3, !chEvtIsListeningI(&es1), "stuck listener");

  /*
   * Testing chEvtDispatch().
   */
  chEvtDispatch(evhndl, 7);
  test_assert_sequence(4, "ABC");
}
Exemplo n.º 25
0
static msg_t
vexAudioTask( void *arg )
{
    uint32_t    tmpCounter;

    (void)arg;

    chRegSetThreadName("audio");
    chEvtInit(&sound_done);

    while(!chThdShouldTerminate())
        {
        if(VSL_Counter > 0)
            {
            tmpCounter = VSL_Counter;
            VSL_Counter = 0;
            // wait for semaphore timeout or other thread reseting the semaphore
            chSemWaitTimeout( &vslSem, tmpCounter );

            chSysLock();
            if( chEvtIsListeningI(&sound_done) )
                chEvtBroadcastI(&sound_done);
            chSysUnlock();

            if( VSL_Counter == 0 )
                {
                if( !vexAudioPlayNextChipTone() )
                    VSL_Deinit();
                }
            }
        else
            chSemWait( &vslSem );
        }

    return (msg_t)0;
}
Exemplo n.º 26
0
/*!
 * Initialize event for wakup button on olimex board.
 */
void extdetail_init() {
	chEvtInit(&extdetail_wkup_event);
	 chEvtInit(&extdetail_launch_detect_event);
}
Exemplo n.º 27
0
/*------------------------------------------------------------------------*
 * chibios_rt::EvtSource                                                *
 *------------------------------------------------------------------------*/
EvtSource::EvtSource(void) {

    chEvtInit(&ev_source);
}
Exemplo n.º 28
0
Arquivo: main.c Projeto: pfhnr/stm32
int main(void) {
  static Thread *shelltp = NULL;
  static const evhandler_t evhndl[] = {
    InsertHandler,
    RemoveHandler,
	 packetReceivedHandler
  };
  struct EventListener el0, el1, el2;
	chEvtRegister(&packet_event, &el2, 0);
	chEvtInit(&packet_event);

  /*
   * 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(1000);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

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

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

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

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

  /*
   * Creates the LWIP threads (it changes priority internally).
   */
  chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 2,
                    lwip_thread, NULL);

  /*
   * Creates the HTTP thread (it changes priority internally).
   */
	/*
  chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1,
                    http_server, NULL);

	*/

	WORKING_AREA(wa_udp_receive_server, PWM_REC_STACK_SIZE);
	chThdCreateStatic(wa_udp_receive_server, sizeof(wa_udp_receive_server), NORMALPRIO +1,
							udp_receive_server_init, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and listen for events.
   */
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  while (TRUE) {
    if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE))
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminated(shelltp)) {
      chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
      shelltp = NULL;           /* Triggers spawning of a new shell.        */
    }
    if (palReadPad(GPIOA, GPIOA_BUTTON_WKUP) != 0) {
    }
    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
  }
}
Exemplo n.º 29
0
  /*------------------------------------------------------------------------*
   * chibios_rt::Event                                                      *
   *------------------------------------------------------------------------*/
  Event::Event(void) {

    chEvtInit(&event);
  }
Exemplo n.º 30
0
/*!
 * Initialize event for wakup button on olimex board.
 */
void extdetail_init() {
	chEvtInit(&extdetail_wkup_event);
}