Пример #1
0
void pyro_fire(uint8_t channel, uint16_t duration_ms)
{
    uint8_t pad;

    if(channel == 1) {
        pad = GPIOE_PY1_TRG;
        chVTReset(&vt1);
        chVTSet(&vt1, MS2ST(duration_ms), pyro_off_1, NULL);
        log_s16(CHAN_PYRO_F, 1, 0, 0, 0);
    } else if(channel == 2) {
        pad = GPIOE_PY2_TRG;
        chVTReset(&vt2);
        chVTSet(&vt2, MS2ST(duration_ms), pyro_off_2, NULL);
        log_s16(CHAN_PYRO_F, 0, 1, 0, 0);

    } else if(channel == 3) {
        pad = GPIOE_PY3_TRG;
        chVTReset(&vt3);
        chVTSet(&vt3, MS2ST(duration_ms), pyro_off_3, NULL);
        log_s16(CHAN_PYRO_F, 0, 0, 1, 0);

    } else if(channel == 4) {
        pad = GPIOE_PY4_TRG;
        chVTReset(&vt4);
        chVTSet(&vt4, MS2ST(duration_ms), pyro_off_4, NULL);
        log_s16(CHAN_PYRO_F, 0, 0, 0, 1);

    } else {
        return;
    }

    palSetPad(GPIOE, pad);

}
Пример #2
0
/**
 * @brief   Delete a timer.
 */
osStatus osTimerDelete(osTimerId timer_id) {

  chVTReset(&timer_id->vt);
  chPoolFree(&timpool, (void *)timer_id);

  return osOK;
}
Пример #3
0
static THD_FUNCTION(spi_thread, p) {
  unsigned i;
  SPIDriver *spip = (SPIDriver *)p;
  virtual_timer_t vt;
  uint8_t txbuf[256];
  uint8_t rxbuf[256];

  chRegSetThreadName("SPI overlord");

  chVTObjectInit(&vt);

  /* Prepare transmit pattern.*/
  for (i = 0; i < sizeof(txbuf); i++)
    txbuf[i] = (uint8_t)i;

  /* Continuous transmission.*/
  while (true) {
    /* Starts a VT working as watchdog to catch a malfunction in the SPI
       driver.*/
    chVTSet(&vt, MS2ST(10), tmo, (void *)"SPI timeout");

    spiExchange(spip, sizeof(txbuf), txbuf, rxbuf);

    /* Stops the watchdog.*/
    chVTReset(&vt);
  }
}
Пример #4
0
Файл: led.cpp Проект: Kreyl/nute
void LedSmooth_t::SetSmoothly(uint16_t AValue) {
    IState = slsNone;
    if(INeededValue == AValue) return;
    chVTReset(&ITmr);
    INeededValue = AValue;
    uint32_t Delay = ISetupDelay(ICurrentValue);
    chVTSet(&ITmr, MS2ST(Delay), LedTmrCallback, NULL);
}
Пример #5
0
Файл: led.cpp Проект: Kreyl/nute
void LedSmooth_t::Glimmer(uint16_t AMax, uint16_t AMin) {
    chVTReset(&ITmr);
    IState = slsGlimmer;
    IMax = AMax;
    IMin = AMin;
    if(ICurrentValue < IMax) INeededValue = IMax;
    else INeededValue = IMin;
    uint32_t Delay = ISetupDelay(ICurrentValue);
    chVTSet(&ITmr, MS2ST(Delay), LedTmrCallback, NULL);
}
Пример #6
0
void App_t::ITask() {
    while(true) {
        chThdSleepMilliseconds(999);
//        uint32_t EvtMsk = chEvtWaitAny(ALL_EVENTS);
#if 0 // ==== Buttons ====
        if(EvtMsk & EVTMSK_BUTTONS) {
            BtnEvtInfo_t EInfo;
            while(ButtonEvtBuf.Get(&EInfo) == OK) {
//                Uart.Printf("\rEinfo: %u, %u,  %A", EInfo.Type, EInfo.BtnCnt, EInfo.BtnID, EInfo.BtnCnt, '-');
                Beeper.StartSequence(bsqButton);
                // Switch backlight on
                Lcd.Backlight(81);
                chVTRestart(&ITmrBacklight, MS2ST(4500), EVTMSK_BCKLT_OFF);
                // Process buttons
                switch(EInfo.BtnID[0]) {
                    case btnLTop:   // Iterate IDs
                        if(Settings.ID < ID_MAX) Settings.ID++;
                        else Settings.ID = ID_MIN;
                        SettingsHasChanged = true;
                        SaveSettings();
                        Interface.ShowID();
                        break;

                    case btnLBottom: // Deadtime on/off
                        Settings.DeadtimeEnabled = !Settings.DeadtimeEnabled;
                        SettingsHasChanged = true;
                        SaveSettings();
                        Interface.ShowDeadtimeSettings();
                        break;

                    case btnRTop:
                        if(Settings.DurationActive_s < DURATION_ACTIVE_MAX_S) {
                            Settings.DurationActive_s += 10;
                            SettingsHasChanged = true;
                            SaveSettings();
                            Interface.ShowDurationActive();
                        }
                        break;

                    case btnRBottom:
                        if(Settings.DurationActive_s > DURATION_ACTIVE_MIN_S) {
                            Settings.DurationActive_s -= 10;
                            SettingsHasChanged = true;
                            SaveSettings();
                            Interface.ShowDurationActive();
                        }
                        break;

                    default: break;
                } // switch
            } // while get
        } // if buttons
#endif

#if 0 // ==== Radio ====
        if(EvtMsk & EVTMSK_RADIO_RX) {
//            Uart.Printf("\rRadioRx");
            RadioIsOn = true;
            Interface.ShowRadio();
            chVTRestart(&ITmrRadioTimeout, S2ST(RADIO_NOPKT_TIMEOUT_S), EVTMSK_RADIO_ON_TIMEOUT);
            IProcessLedLogic();
            // Radio RX disables Deadtime if it is on
            DeadTimeIsNow = false;
            chVTReset(&ITmrDeadTime);
        }
        if(EvtMsk & EVTMSK_RADIO_ON_TIMEOUT) {
//            Uart.Printf("\rRadioTimeout");
            RadioIsOn = false;
            Interface.ShowRadio();
            IProcessLedLogic();
        }
#endif

#if 0 // ==== Saving settings ====
        if(EvtMsk & EVTMSK_SAVE) { ISaveSettingsReally(); }
#endif

    } // while true
}
Пример #7
0
/**
 * @brief Stops the timer.
 * @details If the timer was already stopped then the function has no effect.
 *
 * @param etp pointer to an initialized @p EvTimer structure.
 */
void evtStop(EvTimer *etp) {

  chVTReset(&etp->et_vt);
}
Пример #8
0
/**
 * @brief   Stop a timer.
 */
osStatus osTimerStop(osTimerId timer_id) {

  chVTReset(&timer_id->vt);

  return osOK;
}
Пример #9
0
/*
 * Application entry point.
 */
int main(void) {
  unsigned i;
  static uint8_t patterns1[4096], patterns2[4096], buf1[4096], buf2[4096];

  /* 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();

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

  /* Activates the ADC1 driver and the temperature sensor.*/
  adcStart(&ADCD1, NULL);
  adcSTM32EnableTSVREFE();

  /* Starts an ADC continuous conversion and its watchdog virtual timer.*/
  chVTSet(&adcvt, MS2ST(10), tmo, (void *)"ADC timeout");
  adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);

  /* Activating SPI drivers.*/
  spiStart(&SPID1, &hs_spicfg);
  spiStart(&SPID2, &hs_spicfg);
  spiStart(&SPID3, &hs_spicfg);

  /* Starting SPI threads instances.*/
  chThdCreateStatic(waSPI1, sizeof(waSPI1), NORMALPRIO + 1, spi_thread, &SPID1);
  chThdCreateStatic(waSPI2, sizeof(waSPI2), NORMALPRIO + 1, spi_thread, &SPID2);
  chThdCreateStatic(waSPI3, sizeof(waSPI3), NORMALPRIO + 1, spi_thread, &SPID3);

  /* Allocating two DMA2 streams for memory copy operations.*/
  if (dmaStreamAllocate(STM32_DMA2_STREAM6, 0, NULL, NULL))
    chSysHalt("DMA already in use");
  if (dmaStreamAllocate(STM32_DMA2_STREAM7, 0, NULL, NULL))
    chSysHalt("DMA already in use");
  for (i = 0; i < sizeof (patterns1); i++)
    patterns1[i] = (uint8_t)i;
  for (i = 0; i < sizeof (patterns2); i++)
    patterns2[i] = (uint8_t)(i ^ 0xAA);

  /* Normal main() thread activity, it does continues memory copy operations
     using 2 DMA streams at the lowest priority.*/
  while (true) {
    virtual_timer_t vt;

    chVTObjectInit(&vt);

    /* Starts a VT working as watchdog to catch a malfunction in the DMA
       driver.*/
    chVTSet(&vt, MS2ST(10), tmo, (void *)"copy timeout");

    /* Copy pattern 1.*/
    dmaStartMemCopy(STM32_DMA2_STREAM6,
                    STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_BYTE |
                                         STM32_DMA_CR_MSIZE_BYTE,
                    patterns1, buf1, sizeof (patterns1));
    dmaStartMemCopy(STM32_DMA2_STREAM7,
                    STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_BYTE |
                                         STM32_DMA_CR_MSIZE_BYTE,
                    patterns1, buf2, sizeof (patterns1));
    dmaWaitCompletion(STM32_DMA2_STREAM6);
    dmaWaitCompletion(STM32_DMA2_STREAM7);
    if (memcmp(patterns1, buf1, sizeof (patterns1)))
      chSysHalt("pattern error");
    if (memcmp(patterns1, buf2, sizeof (patterns1)))
      chSysHalt("pattern error");

    /* Copy pattern 2.*/
    dmaStartMemCopy(STM32_DMA2_STREAM6,
                    STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_BYTE |
                                         STM32_DMA_CR_MSIZE_BYTE,
                    patterns2, buf1, sizeof (patterns2));
    dmaStartMemCopy(STM32_DMA2_STREAM7,
                    STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_BYTE |
                                         STM32_DMA_CR_MSIZE_BYTE,
                    patterns2, buf2, sizeof (patterns2));
    dmaWaitCompletion(STM32_DMA2_STREAM6);
    dmaWaitCompletion(STM32_DMA2_STREAM7);
    if (memcmp(patterns2, buf1, sizeof (patterns2)))
      chSysHalt("pattern error");
    if (memcmp(patterns2, buf2, sizeof (patterns2)))
      chSysHalt("pattern error");

    /* Stops the watchdog.*/
    chVTReset(&vt);

    chThdSleepMilliseconds(2);
  }
  return 0;
}
Пример #10
0
void Pin_t::Pulse(uint32_t ms) {
    chVTReset(&ITmr);
    High();
    // Start timer to switch off
    chVTSet(&ITmr, MS2ST(ms), PinTmrCallback, NULL);
}