/*
 * Insertion monitor timer callback function.
 *
 * pointer to the p BaseBlockDevice object
 *
 */
static void tmrfunc( void *p ) 
{
    BaseBlockDevice *bbdp = p;
    
    chSysLockFromISR();
    if( cnt > 0 ) 
    {
        if( blkIsInserted( bbdp ) ) 
        {
            if( --cnt == 0 ) 
            {
                chEvtBroadcastI( &inserted_event );
            }
        }
        else
        {
            cnt = POLLING_INTERVAL;
        }
    }
    else if( ! blkIsInserted( bbdp ) ) 
    {
        cnt = POLLING_INTERVAL;
        chEvtBroadcastI( &removed_event );
    }
    
    chVTSetI( &tmr, MS2ST( POLLING_DELAY ), tmrfunc, bbdp );
    chSysUnlockFromISR();
}
Beispiel #2
0
/**
 * @brief   Insertion monitor timer callback function.
 *
 * @param[in] p         pointer to the @p BaseBlockDevice object
 *
 * @notapi
 */
static void tmrfunc(void *p) {
  BaseBlockDevice *bbdp = p;

  /* The presence check is performed only while the driver is not in a
     transfer state because it is often performed by changing the mode of
     the pin connected to the CS/D3 contact of the card, this could disturb
     the transfer.*/
  blkstate_t state = blkGetDriverState(bbdp);
  chSysLockFromIsr();
  if ((state != BLK_READING) && (state != BLK_WRITING)) {
    /* Safe to perform the check.*/
    if (cnt > 0) {
      if (blkIsInserted(bbdp)) {
        if (--cnt == 0) {
          chEvtBroadcastI(&inserted_event);
        }
      }
      else
        cnt = POLLING_INTERVAL;
    }
    else {
      if (!blkIsInserted(bbdp)) {
        cnt = POLLING_INTERVAL;
        chEvtBroadcastI(&removed_event);
      }
    }
  }
  chVTSetI(&tmr, MS2ST(POLLING_DELAY), tmrfunc, bbdp);
  chSysUnlockFromIsr();
}
Beispiel #3
0
// ============================= Interrupts ====================================
void cc1101_t::IHandleAsync() {
    if(State == ccTransmitting) {
        State = ccIdle;
        chEvtBroadcastI(&IEvtSrcTx);
    }
    else if(State == ccReceiving) {
        State = ccIdle;
        chEvtBroadcastI(&IEvtSrcRx);
    }
}
/**
 * @brief   Common IRQ handler.
 * @note    Tries hard to clear all the pending interrupt sources, we dont want
 *          to go through the whole ISR and have another interrupt soon after.
 *
 * @param[in] sdp       communication channel associated to the UART
 */
static void serve_interrupt(SerialDriver *sdp) {
  UART *u = sdp->uart;

  while (TRUE) {
    switch (u->UART_IIR & IIR_SRC_MASK) {
    case IIR_SRC_NONE:
      return;
    case IIR_SRC_ERROR:
      set_error(sdp, u->UART_LSR);
      break;
    case IIR_SRC_TIMEOUT:
    case IIR_SRC_RX:
      chSysLockFromIsr();
      if (chIQIsEmpty(&sdp->iqueue))
        chEvtBroadcastI(&sdp->ievent);
      chSysUnlockFromIsr();
      while (u->UART_LSR & LSR_RBR_FULL) {
        chSysLockFromIsr();
        if (chIQPutI(&sdp->iqueue, u->UART_RBR) < Q_OK)
           sdAddFlagsI(sdp, SD_OVERRUN_ERROR);
        chSysUnlockFromIsr();
      }
      break;
    case IIR_SRC_TX:
      {
        int i = LPC214x_UART_FIFO_PRELOAD;
        do {
          msg_t b;

          chSysLockFromIsr();
          b = chOQGetI(&sdp->oqueue);
          chSysUnlockFromIsr();
          if (b < Q_OK) {
            u->UART_IER &= ~IER_THRE;
            chSysLockFromIsr();
            chEvtBroadcastI(&sdp->oevent);
            chSysUnlockFromIsr();
            break;
          }
          u->UART_THR = b;
        } while (--i);
      }
      break;
    default:
      (void) u->UART_THR;
      (void) u->UART_RBR;
    }
  }
}
Beispiel #5
0
/**
 * @brief Stops the sound.
 *
 * @param[in] p pointer to the timer
 */
static void stop(void *p) {

  StopCounter((TC *)p);
  chSysLockFromIsr();
  chEvtBroadcastI(&BuzzerSilentEventSource);
  chSysUnlockFromIsr();
}
Beispiel #6
0
/**
 * @brief   Handles communication events/errors.
 * @details Must be called from the I/O interrupt service routine in order to
 *          notify I/O conditions as errors, signals change etc.
 *
 * @param[in] i2cp      pointer to a @p I2CDriver structure
 * @param[in] mask      condition flags to be added to the mask
 *
 * @iclass
 */
void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) {

    chDbgCheck(i2cp != NULL, "i2cAddFlagsI");

    i2cp->errors |= mask;
    chEvtBroadcastI(&i2cp->sevent);
}
Beispiel #7
0
static void tmrcb(void *p) {
  event_timer_t *etp = p;

  chSysLockFromISR();
  chEvtBroadcastI(&etp->et_es);
  chVTDoSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
  chSysUnlockFromISR();
}
Beispiel #8
0
/*!
 * External interrupt from MPU9150
 *
 * @param extp
 * @param channel
 */
void extdetail_mpu9150_int(EXTDriver *extp, expchannel_t channel) {
	(void)extp;
	(void)channel;

	chSysLockFromIsr();
	chEvtBroadcastI(&mpu9150_int_event);
	chSysUnlockFromIsr();
}
static void tmrcb(void *p) {
  EvTimer *etp = p;

  chSysLockFromIsr();
  chEvtBroadcastI(&etp->et_es);
  chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
  chSysUnlockFromIsr();
}
Beispiel #10
0
/*!
 * External interrupt from ADIS
 *
 * @param extp
 * @param channel
 */
void extdetail_adis_dio1(EXTDriver *extp, expchannel_t channel) {
	(void)extp;
	(void)channel;

	chSysLockFromIsr();
	chEvtBroadcastI(&adis_dio1_event);
	chSysUnlockFromIsr();
}
Beispiel #11
0
/**
 * @brief   Terminates the shell.
 * @note    Must be invoked from the command handlers.
 * @note    Does not return.
 *
 * @param[in] msg       shell exit code
 *
 * @api
 */
void shellExit(msg_t msg) {

  /* Atomically broadcasting the event source and terminating the thread,
     there is not a chSysUnlock() because the thread terminates upon return.*/
  chSysLock();
  chEvtBroadcastI(&shell_terminated);
  chThdExitS(msg);
}
Beispiel #12
0
/**
 * @brief   Wake up ISR handler.
 *
 * @param[in] canp      pointer to the @p CANDriver object
 *
 * @notapi
 */
static void can_lld_wakeup_handler(CANDriver *canp) {

  /* Wakeup event.*/
  canp->state = CAN_READY;
  can_lld_wakeup(canp);
  chSysLockFromIsr();
  chEvtBroadcastI(&canp->wakeup_event);
  chSysUnlockFromIsr();

}
Beispiel #13
0
/*! Triggered when the pin changes state (both edges)
 *
 * Challenge: Add de-bouncing
 */
void extdetail_launch_detect(EXTDriver *extp, expchannel_t channel) {

    (void)extp;
    (void)channel;

    chSysLockFromIsr();
    chEvtBroadcastI(&extdetail_launch_detect_event);

    chSysUnlockFromIsr();
}
Beispiel #14
0
/**
 * @brief   Inserion monitor timer callback function.
 *
 * @param[in] p         pointer to the @p SDCDriver object
 *
 * @notapi
 */
static void tmrfunc(void *p) {
  SDCDriver *sdcp = p;

  if (cnt > 0) {
    if (sdcIsCardInserted(sdcp)) {
      if (--cnt == 0) {
        chEvtBroadcastI(&inserted_event);
      }
    }
    else
      cnt = SDC_POLLING_INTERVAL;
  }
  else {
    if (!sdcIsCardInserted(sdcp)) {
      cnt = SDC_POLLING_INTERVAL;
      chEvtBroadcastI(&removed_event);
    }
  }
  chVTSetI(&tmr, MS2ST(SDC_POLLING_DELAY), tmrfunc, sdcp);
}
Beispiel #15
0
/**
 * @brief Shell thread function.
 *
 * @param[in] p pointer to a @p BaseChannel object
 * @return Termination reason.
 * @retval RDY_OK terminated by command.
 * @retval RDY_RESET terminated by reset condition on the I/O channel.
 */
static msg_t shell_thread(void *p) {
  int n;
  msg_t msg = RDY_OK;
  BaseChannel *chp = ((ShellConfig *)p)->sc_channel;
  const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
  char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
  char *args[SHELL_MAX_ARGUMENTS + 1];

  shellPrintLine(chp, "");
  shellPrintLine(chp, "ChibiOS/RT Shell");
  while (TRUE) {
    shellPrint(chp, "ch> ");
    if (shellGetLine(chp, line, sizeof(line))) {
      shellPrint(chp, "\nlogout");
      break;
    }
    lp = strtok_r(line, " \009", &tokp);
    cmd = lp;
    n = 0;
    while ((lp = strtok_r(NULL, " \009", &tokp)) != NULL) {
      if (n >= SHELL_MAX_ARGUMENTS) {
        shellPrintLine(chp, "too many arguments");
        cmd = NULL;
        break;
      }
      args[n++] = lp;
    }
    args[n] = NULL;
    if (cmd != NULL) {
      if (strcasecmp(cmd, "exit") == 0) {
        if (n > 0)
          usage(chp, "exit");
        break;
      }
      else if (strcasecmp(cmd, "help") == 0) {
        if (n > 0)
          usage(chp, "help");
        shellPrint(chp, "Commands: help exit ");
        list_commands(chp, local_commands);
        if (scp != NULL)
          list_commands(chp, scp);
        shellPrintLine(chp, "");
      }
      else if (cmdexec(local_commands, chp, cmd, n, args) &&
          ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
        shellPrint(chp, cmd);
        shellPrintLine(chp, " ?");
      }
    }
  }
  chSysLock();
  chEvtBroadcastI(&shell_terminated);
  return msg;
}
Beispiel #16
0
/*!
 * @brief           Insertion monitor timer callback function.
 *
 * @param[in] p     pointer to the @p BaseBlockDevice object
 *
 * @notapi
 */
static void sdc_tmrfunc(void *p) {
    BaseBlockDevice *bbdp = p;

    chSysLockFromIsr();
    if (sdc_debounce_count > 0) {
        if (blkIsInserted(bbdp)) {
            if (--sdc_debounce_count == 0) {
                chEvtBroadcastI(&sdc_inserted_event);
            }
        }
        else
            sdc_debounce_count = sdc_polling_interval;
    }
    else {
        if (!blkIsInserted(bbdp)) {
            sdc_debounce_count = sdc_polling_interval;
            chEvtBroadcastI(&sdc_removed_event);
        }
    }
    chVTSetI(&sdc_tmr, MS2ST(sdc_polling_delay), sdc_tmrfunc, bbdp);
    chSysUnlockFromIsr();
}
Beispiel #17
0
/**
 * @brief   Insertion monitor timer callback function.
 *
 * @param[in] p         pointer to the @p MMCDriver object
 *
 * @notapi
 */
static void tmrfunc(void *p) {
  MMCDriver *mmcp = p;

  if (mmcp->cnt > 0) {
    if (mmcp->is_inserted()) {
      if (--mmcp->cnt == 0) {
        mmcp->state = MMC_INSERTED;
        chEvtBroadcastI(&mmcp->inserted_event);
      }
    }
    else
      mmcp->cnt = MMC_POLLING_INTERVAL;
  }
  else {
    if (!mmcp->is_inserted()) {
      mmcp->state = MMC_WAIT;
      mmcp->cnt = MMC_POLLING_INTERVAL;
      chEvtBroadcastI(&mmcp->removed_event);
    }
  }
  chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp);
}
Beispiel #18
0
/*! \brief adis_spi_cb
 *
 * What happens at end of ADIS SPI transaction
 *
 * This is executed during the SPI interrupt.
 *
 * @param spip
 */
void adis_spi_cb(SPIDriver *spip) {
	chSysLockFromIsr();

	uint8_t       i                              = 0;

	chDbgCheck(adis_driver.spi_instance == spip, "adis_spi_cb driver mismatch");
	if(adis_driver.state == ADIS_TX_PEND) {
		chEvtBroadcastI(&adis_spi_cb_txdone_event);
	} else {
		for(i=0; i<adis_driver.tx_numbytes; ++i) {
			adis_cache_data.adis_tx_cache[i] = adis_driver.adis_txbuf[i];
		}
		for(i=0; i<adis_driver.rx_numbytes; ++i) {
			adis_cache_data.adis_rx_cache[i] = adis_driver.adis_rxbuf[i];
		}
		adis_cache_data.reg                  = adis_driver.reg;
		adis_cache_data.current_rx_numbytes  = adis_driver.rx_numbytes;
		adis_cache_data.current_tx_numbytes  = adis_driver.tx_numbytes;
		chEvtBroadcastI(&adis_spi_cb_newdata);
		chEvtBroadcastI(&adis_spi_cb_releasebus);
	}
	chSysUnlockFromIsr();
}
Beispiel #19
0
/**
 * @brief   Enforces leaving the sleep mode.
 * @note    The sleep mode is supposed to be usually exited automatically by
 *          an hardware event.
 *
 * @param[in] canp      pointer to the @p CANDriver object
 */
void canWakeup(CANDriver *canp) {

  chDbgCheck(canp != NULL, "canWakeup");

  chSysLock();
  chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
              "canWakeup(), #1", "invalid state");
  if (canp->state == CAN_SLEEP) {
    can_lld_wakeup(canp);
    canp->state = CAN_READY;
    chEvtBroadcastI(&canp->wakeup_event);
    chSchRescheduleS();
  }
  chSysUnlock();
}
/**
 * @brief   Attempts a TX FIFO preload.
 */
static void preload(SerialDriver *sdp) {
  UART *u = sdp->uart;

  if (u->UART_LSR & LSR_THRE) {
    int i = LPC214x_UART_FIFO_PRELOAD;
    do {
      msg_t b = chOQGetI(&sdp->oqueue);
      if (b < Q_OK) {
        chEvtBroadcastI(&sdp->oevent);
        return;
      }
      u->UART_THR = b;
    } while (--i);
  }
  u->UART_IER |= IER_THRE;
}
Beispiel #21
0
/*! Triggered when the WKUP button is pressed or released. The LED is set to ON.
 *
 * Challenge: Add de-bouncing
 */
void extdetail_wkup_btn(EXTDriver *extp, expchannel_t channel) {
	//static VirtualTimer vt4;

	(void)extp;
	(void)channel;

	//palClearPad(GPIOC, GPIOC_LED);
	chSysLockFromIsr();
	chEvtBroadcastI(&extdetail_wkup_event);

//	if (chVTIsArmedI(&vt4))
//		chVTResetI(&vt4);

	/* LED4 set to OFF after 500mS.*/
	//chVTSetI(&vt4, MS2ST(500), green_led_off, NULL);
	chSysUnlockFromIsr();
}
Beispiel #22
0
/*
 * Handles the USB driver global events.
 */
static void usb_event(USBDriver *usbp, usbevent_t event) {
    USBMassStorageDriver *msdp = (USBMassStorageDriver *)usbp->USBD_PARAM_NAME;
    switch (event) {
    case USB_EVENT_RESET:
        msdp->reconfigured_or_reset_event = TRUE;
        return;
    case USB_EVENT_ADDRESS:
        return;
    case USB_EVENT_CONFIGURED:
        chSysLockFromIsr();
        msdp->reconfigured_or_reset_event = TRUE;
        usbInitEndpointI(usbp, msdp->ms_ep_number, &epDataConfig);

        /* Enables the endpoints specified into the configuration.
         Note, this callback is invoked from an ISR so I-Class functions
         must be used.*/
        usbInitEndpointI(usbp, USB_CDC_DATA_REQUEST_EP, &epCDC1config);
        usbInitEndpointI(usbp, USB_CDC_INTERRUPT_REQUEST_EP, &epCDC2config);
        /* Resetting the state of the CDC subsystem.*/
        sduConfigureHookI(usbp);

        /* Initialize the thread */
        chBSemSignalI(&msdp->bsem);

        /* signal that the device is connected */
        chEvtBroadcastI(&msdp->evt_connected);
        chSysUnlockFromIsr();
        return;
    case USB_EVENT_SUSPEND:
        return;
    case USB_EVENT_WAKEUP:
        return;
    case USB_EVENT_STALLED:
        return;
    }
    return;
}
Beispiel #23
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;
}
Beispiel #24
0
/**
 * @brief   Shell thread function.
 *
 * @param[in] p         pointer to a @p BaseSequentialStream object
 * @return              Termination reason.
 * @retval RDY_OK       terminated by command.
 * @retval RDY_RESET    terminated by reset condition on the I/O channel.
 */
static msg_t shell_thread(void *p) {
  int n;
  msg_t msg = RDY_OK;
  BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
  const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
  char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
  char *args[SHELL_MAX_ARGUMENTS + 1];

  chRegSetThreadName("shell");
  chprintf(chp, "\r\nChibiOS/RT Shell\r\n");
  while (TRUE) {
    chprintf(chp, "ch> ");
    if (shellGetLine(chp, line, sizeof(line))) {
      chprintf(chp, "\r\nlogout");
      break;
    }
    lp = _strtok(line, " \009", &tokp);
    cmd = lp;
    n = 0;
    while ((lp = _strtok(NULL, " \009", &tokp)) != NULL) {
      if (n >= SHELL_MAX_ARGUMENTS) {
        chprintf(chp, "too many arguments\r\n");
        cmd = NULL;
        break;
      }
      args[n++] = lp;
    }
    args[n] = NULL;
    if (cmd != NULL) {
      if (strcasecmp(cmd, "exit") == 0) {
        if (n > 0) {
          usage(chp, "exit");
          continue;
        }
        break;
      }
      else if (strcasecmp(cmd, "help") == 0) {
        if (n > 0) {
          usage(chp, "help");
          continue;
        }
        chprintf(chp, "Commands: help exit ");
        list_commands(chp, local_commands);
        if (scp != NULL)
          list_commands(chp, scp);
        chprintf(chp, "\r\n");
      }
      else if (cmdexec(local_commands, chp, cmd, n, args) &&
          ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
        chprintf(chp, "%s", cmd);
        chprintf(chp, " ?\r\n");
      }
    }
  }
  /* Atomically broadcasting the event source and terminating the thread,
     there is not a chSysUnlock() because the thread terminates upon return.*/
  chSysLock();
  chEvtBroadcastI(&shell_terminated);
  chThdExitS(msg);
  return 0; /* Never executed.*/
}
Beispiel #25
0
/**
 * @brief Stops the sound.
 *
 * @param[in] p pointer to the timer
 */
static void stop(void *p) {

  StopCounter((TC *)p);
  chEvtBroadcastI(&BuzzerSilentEventSource);
}