示例#1
0
/** Claim this USART for exclusive use by the calling module.
 * This prevents the USART from being used by other modules, and inhibits
 * the standard protocols.  This allows modem (or other) drivers to claim
 * the USART and prevent SBP or other protocol driver from interfering with
 * communications.
 *
 * The same module may nest claims to the port.  The port must be released
 * as many times as it was claimed before it will be available for
 * for another module.
 *
 * \see ::usart_release
 * \param s The USART DMA state structure.
 * \param module A pointer to identify the calling module.  This is compared
 *               by value of the pointer.  The pointer target is unused.
 */
bool usart_claim(usart_state* s, const void *module)
{
  chSysLock();
  if (s->configured && (chBSemWaitTimeoutS(&s->claimed, 0) == MSG_OK)) {
    s->claimed_by = module;
    s->claim_nest = 0;
    chSysUnlock();
    return true;
  } else if (s->claimed_by == module) {
    s->claim_nest++;
    chSysUnlock();
    return true;
  }
  chSysUnlock();
  return false;
}
示例#2
0
/*
 * ADXL375 (high-g accelerometer) main thread.
 */
msg_t adxl375_thread(void *arg)
{
    (void)arg;

    const SPIConfig spi_cfg = {
        NULL,
        ADXL375_SPI_CS_PORT,
        ADXL375_SPI_CS_PIN,
        SPI_CR1_BR_2 | SPI_CR1_CPOL | SPI_CR1_CPHA
    };
    int16_t accels[3], axis, g;

    m2status_hg_accel_status(STATUS_WAIT);
    chRegSetThreadName("ADXL375");
    chBSemInit(&bs375, true);

    spiStart(&ADXL375_SPID, &spi_cfg);
    adxl3x5_init(&ADXL375_SPID, 7, &axis, &g);
    log_i16(M2T_CH_CAL_HG_ACCEL, axis, g, 0, 0);

    while(TRUE) {
        adxl3x5_read_accel(&ADXL375_SPID, accels);
        log_i16(M2T_CH_IMU_HG_ACCEL, accels[0], accels[1], accels[2], 0);
        m2status_set_hga(accels[0], accels[1], accels[2]);
        state_estimation_new_hg_accel(
            adxl3x5_accels_to_axis(accels, axis, g));

        /* Sleep until DRDY */
        chSysLock();
        chBSemWaitTimeoutS(&bs375, 100);
        /*tp375 = chThdSelf();*/
        /*chSchGoSleepTimeoutS(THD_STATE_SUSPENDED, 100);*/
        /*tp345 = NULL;*/
        chSysUnlock();
        m2status_hg_accel_status(STATUS_OK);
    }
}
示例#3
0
msg_t BinarySemaphore::waitTimeoutS(systime_t time) {

    return chBSemWaitTimeoutS(&bsem, time);
}