/** * @brief Configures and starts the driver. * * @param[in] sdp pointer to a @p SerialDriver object * @param[in] config the architecture-dependent serial driver configuration. * If this parameter is set to @p NULL then a default * configuration is used. * * @api */ void sdStart(SerialDriver *sdp, const SerialConfig *config) { osalDbgCheck(sdp != NULL); osalSysLock(); osalDbgAssert((sdp->state == SD_STOP) || (sdp->state == SD_READY), "invalid state"); sd_lld_start(sdp, config); sdp->state = SD_READY; osalSysUnlock(); }
/** * @brief Deactivates the EXT peripheral. * * @param[in] extp pointer to the @p EXTDriver object * * @api */ void extStop(EXTDriver *extp) { osalDbgCheck(extp != NULL); osalSysLock(); osalDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), "invalid state"); ext_lld_stop(extp); extp->state = EXT_STOP; osalSysUnlock(); }
/** * @brief Deactivates the MAC peripheral. * * @param[in] macp pointer to the @p MACDriver object * * @api */ void macStop(MACDriver *macp) { osalDbgCheck(macp != NULL); osalSysLock(); osalDbgAssert((macp->state == MAC_STOP) || (macp->state == MAC_ACTIVE), "invalid state"); mac_lld_stop(macp); macp->state = MAC_STOP; osalSysUnlock(); }
/** * @brief Enables a PWM channel. * @pre The PWM unit must have been activated using @p pwmStart(). * @post The channel is active using the specified configuration. * @note Depending on the hardware implementation this function has * effect starting on the next cycle (recommended implementation) * or immediately (fallback implementation). * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1) * @param[in] width PWM pulse width as clock pulses number * * @api */ void pwmEnableChannel(PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width) { osalDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS)); osalSysLock(); osalDbgAssert(pwmp->state == PWM_READY, "not ready"); pwm_lld_enable_channel(pwmp, channel, width); osalSysUnlock(); }
/** * @brief Deactivates the PWM peripheral. * * @param[in] pwmp pointer to a @p PWMDriver object * * @api */ void pwmStop(PWMDriver *pwmp) { osalDbgCheck(pwmp != NULL); osalSysLock(); osalDbgAssert((pwmp->state == PWM_STOP) || (pwmp->state == PWM_READY), "invalid state"); pwm_lld_stop(pwmp); pwmp->state = PWM_STOP; osalSysUnlock(); }
/** * @brief Deactivates the I2C peripheral. * * @param[in] i2cp pointer to the @p I2CDriver object * * @api */ void i2cStop(I2CDriver *i2cp) { osalDbgCheck(i2cp != NULL); osalDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || (i2cp->state == I2C_LOCKED), "invalid state"); osalSysLock(); i2c_lld_stop(i2cp); i2cp->state = I2C_STOP; osalSysUnlock(); }
/** * @brief Configures and activates the I2C peripheral. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] config pointer to the @p I2CConfig object * * @api */ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { osalDbgCheck((i2cp != NULL) && (config != NULL)); osalDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || (i2cp->state == I2C_LOCKED), "invalid state"); osalSysLock(); i2cp->config = config; i2c_lld_start(i2cp); i2cp->state = I2C_READY; osalSysUnlock(); }
/** * @brief Disables a PWM channel and its notification. * @pre The PWM unit must have been activated using @p pwmStart(). * @post The channel is disabled and its output line returned to the * idle state. * @note Depending on the hardware implementation this function has * effect starting on the next cycle (recommended implementation) * or immediately (fallback implementation). * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier (0...channels-1) * * @api */ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { osalDbgCheck((pwmp != NULL) && (channel < pwmp->channels)); osalSysLock(); osalDbgAssert(pwmp->state == PWM_READY, "not ready"); pwmDisableChannelI(pwmp, channel); osalSysUnlock(); }
/** * @brief Configures and activates the ICU peripheral. * * @param[in] icup pointer to the @p ICUDriver object * @param[in] config pointer to the @p ICUConfig object * * @api */ void icuStart(ICUDriver *icup, const ICUConfig *config) { osalDbgCheck((icup != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((icup->state == ICU_STOP) || (icup->state == ICU_READY), "invalid state"); icup->config = config; icu_lld_start(icup); icup->state = ICU_READY; osalSysUnlock(); }
/** * @brief Configures and activates the EXT peripheral. * @post After activation all EXT channels are in the disabled state, * use @p extChannelEnable() in order to activate them. * * @param[in] extp pointer to the @p EXTDriver object * @param[in] config pointer to the @p EXTConfig object * * @api */ void extStart(EXTDriver *extp, const EXTConfig *config) { osalDbgCheck((extp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), "invalid state"); extp->config = config; ext_lld_start(extp); extp->state = EXT_ACTIVE; osalSysUnlock(); }
/** * @brief Disables an EXT channel. * @pre The channel must not be in @p EXT_CH_MODE_DISABLED mode. * * @param[in] extp pointer to the @p EXTDriver object * @param[in] channel channel to be disabled * * @api */ void extChannelDisable(EXTDriver *extp, expchannel_t channel) { osalDbgCheck((extp != NULL) && (channel < (expchannel_t)EXT_MAX_CHANNELS)); osalSysLock(); osalDbgAssert((extp->state == EXT_ACTIVE) && ((extp->config->channels[channel].mode & EXT_CH_MODE_EDGES_MASK) != EXT_CH_MODE_DISABLED), "invalid state"); extChannelDisableI(extp, channel); osalSysUnlock(); }
/** * @brief Configures and activates the WDG peripheral. * * @param[in] wdgp pointer to the @p WDGDriver object * @param[in] config pointer to the @p WDGConfig object * * @api */ void wdgStart(WDGDriver *wdgp, const WDGConfig *config) { osalDbgCheck((wdgp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((wdgp->state == WDG_STOP) || (wdgp->state == WDG_READY), "invalid state"); wdgp->config = config; wdg_lld_start(wdgp); wdgp->state = WDG_READY; osalSysUnlock(); }
/** * @brief Configures and activates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] config pointer to the @p SPIConfig object * * @api */ void spiStart(SPIDriver *spip, const SPIConfig *config) { osalDbgCheck((spip != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "invalid state"); spip->config = config; spi_lld_start(spip); spip->state = SPI_READY; osalSysUnlock(); }
/** * @brief Starts a transmission on the UART peripheral. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] uartp pointer to the @p UARTDriver object * @param[in] n number of data frames to send * @param[in] txbuf the pointer to the transmit buffer * * @api */ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { osalDbgCheck((uartp != NULL) && (n > 0U) && (txbuf != NULL)); osalSysLock(); osalDbgAssert(uartp->state == UART_READY, "is active"); osalDbgAssert(uartp->txstate != UART_TX_ACTIVE, "tx active"); uart_lld_start_send(uartp, n, txbuf); uartp->txstate = UART_TX_ACTIVE; osalSysUnlock(); }
/** * @brief Deactivates the USB peripheral. * * @param[in] usbp pointer to the @p USBDriver object * * @api */ void usbStop(USBDriver *usbp) { osalDbgCheck(usbp != NULL); osalSysLock(); osalDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY) || (usbp->state == USB_SELECTED) || (usbp->state == USB_ACTIVE), "invalid state"); usb_lld_stop(usbp); usbp->state = USB_STOP; osalSysUnlock(); }
/** * @brief Starts a receive operation on the UART peripheral. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] uartp pointer to the @p UARTDriver object * @param[in] n number of data frames to receive * @param[in] rxbuf the pointer to the receive buffer * * @api */ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { osalDbgCheck((uartp != NULL) && (n > 0U) && (rxbuf != NULL)); osalSysLock(); osalDbgAssert(uartp->state == UART_READY, "is active"); osalDbgAssert(uartp->rxstate != UART_RX_ACTIVE, "rx active"); uart_lld_start_receive(uartp, n, rxbuf); uartp->rxstate = UART_RX_ACTIVE; osalSysUnlock(); }
/** * @brief Sends a command without data phase. * @post At the end of the operation the configured callback is invoked. * * @param[in] qspip pointer to the @p QSPIDriver object * @param[in] cmd pointer to the command descriptor * * @api */ void qspiStartCommand(QSPIDriver *qspip, const qspi_command_t *cmdp) { osalDbgCheck((qspip != NULL) && (cmdp != NULL)); osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); qspiStartCommandI(qspip, cmdp); osalSysUnlock(); }
/** * @brief Configures and activates the GPT peripheral. * * @param[in] gptp pointer to the @p GPTDriver object * @param[in] config pointer to the @p GPTConfig object * * @api */ void gptStart(GPTDriver *gptp, const GPTConfig *config) { osalDbgCheck((gptp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((gptp->state == GPT_STOP) || (gptp->state == GPT_READY), "invalid state"); gptp->config = config; gpt_lld_start(gptp); gptp->state = GPT_READY; osalSysUnlock(); }
/** * @brief Configures and activates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] config pointer to the @p ADCConfig object. Depending on * the implementation the value can be @p NULL. * * @api */ void adcStart(ADCDriver *adcp, const ADCConfig *config) { osalDbgCheck(adcp != NULL); osalSysLock(); osalDbgAssert((adcp->state == ADC_STOP) || (adcp->state == ADC_READY), "invalid state"); adcp->config = config; adc_lld_start(adcp); adcp->state = ADC_READY; osalSysUnlock(); }
/** * @brief Disables the extended input capture. * * @param[in] eicup Pointer to the @p EICUDriver object * * @api */ void eicuDisable(EICUDriver *eicup) { osalDbgCheck(eicup != NULL); osalSysLock(); osalDbgAssert((eicup->state == EICU_READY) || (eicup->state == EICU_IDLE) || (eicup->state == EICU_ACTIVE) || (eicup->state == EICU_WAITING), "invalid state"); eicu_lld_disable(eicup); eicup->state = EICU_READY; osalSysUnlock(); }
/** * @brief Configures and activates the EICU peripheral. * * @param[in] eicup Pointer to the @p EICUDriver object * @param[in] config Pointer to the @p EICUConfig object * * @api */ void eicuStart(EICUDriver *eicup, const EICUConfig *config) { osalDbgCheck((eicup != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((eicup->state == EICU_STOP) || (eicup->state == EICU_READY), "invalid state"); eicup->config = config; eicu_lld_start(eicup); eicup->state = EICU_READY; osalSysUnlock(); }
/** * @brief Configures and activates the OPAMP peripheral. * * @param[in] opampp pointer to the @p OPAMPDriver object * @param[in] config pointer to the @p OPAMPConfig object * * @api */ void opampStart(OPAMPDriver *opampp, const OPAMPConfig *config) { osalDbgCheck((opampp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((opampp->state == OPAMP_STOP) || (opampp->state == OPAMP_ACTIVE), "invalid state"); opampp->config = config; opamp_lld_start(opampp); opampp->state = OPAMP_ACTIVE; osalSysUnlock(); }
/** * @brief Configures and activates the MAC peripheral. * * @param[in] macp pointer to the @p MACDriver object * @param[in] config pointer to the @p MACConfig object * * @api */ void macStart(MACDriver *macp, const MACConfig *config) { osalDbgCheck((macp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert(macp->state == MAC_STOP, "invalid state"); macp->config = config; mac_lld_start(macp); macp->state = MAC_ACTIVE; osalSysUnlock(); }
/** * @brief Configures and activates the UART peripheral. * * @param[in] uartp pointer to the @p UARTDriver object * @param[in] config pointer to the @p UARTConfig object * * @api */ void uartStart(UARTDriver *uartp, const UARTConfig *config) { osalDbgCheck((uartp != NULL) && (config != NULL)); osalSysLock(); osalDbgAssert((uartp->state == UART_STOP) || (uartp->state == UART_READY), "invalid state"); uartp->config = config; uart_lld_start(uartp); uartp->state = UART_READY; osalSysUnlock(); }
/** * @brief Maps in memory space a QSPI flash device. * @post The memory flash device must be re-initialized for normal * commands exchange. * * @param[in] qspip pointer to the @p QSPIDriver object * * @api */ void qspiUnmapFlash(QSPIDriver *qspip) { osalDbgCheck(qspip != NULL); osalSysLock(); osalDbgAssert(qspip->state == QSPI_MEMMAP, "not ready"); qspiUnmapFlashI(qspip); qspip->state = QSPI_READY; osalSysUnlock(); }
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) { systime_t time, tmo; osalSysLock(); tmo = timeout > 0 ? (systime_t)timeout : TIME_INFINITE; time = osalOsGetSystemTimeX(); if (chMBFetchS(*mbox, (msg_t *)msg, tmo) != MSG_OK) time = SYS_ARCH_TIMEOUT; else time = osalOsGetSystemTimeX() - time; osalSysUnlock(); return time; }
/** * @brief Configures and starts the driver. * * @param[in] hiddp pointer to a @p HIDDebugDriver object * @param[in] config the teensy HID debug driver configuration * * @api */ void hidDebugStart(HIDDebugDriver *hiddp, const HIDDebugConfig *config) { USBDriver *usbp = config->usbp; osalDbgCheck(hiddp != NULL); osalSysLock(); osalDbgAssert((hiddp->state == HIDDEBUG_STOP) || (hiddp->state == HIDDEBUG_READY), "invalid state"); usbp->in_params[config->ep_in - 1U] = hiddp; hiddp->config = config; hiddp->state = HIDDEBUG_READY; osalSysUnlock(); }
/** * @brief Exchanges data on the SPI bus. * @details This synchronous function performs a simultaneous transmit/receive * operation. * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. * @pre In order to use this function the driver must have been configured * without callbacks (@p end_cb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be exchanged * @param[in] txbuf the pointer to the transmit buffer * @param[out] rxbuf the pointer to the receive buffer * * @api */ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL) && (txbuf != NULL)); osalSysLock(); osalDbgAssert(spip->state == SPI_READY, "not ready"); osalDbgAssert(spip->config->end_cb == NULL, "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); (void) osalThreadSuspendS(&spip->thread); osalSysUnlock(); }
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { systime_t time, tmo; osalSysLock(); tmo = timeout > 0 ? (systime_t)timeout : TIME_INFINITE; time = osalOsGetSystemTimeX(); if (chSemWaitTimeoutS(*sem, tmo) != MSG_OK) time = SYS_ARCH_TIMEOUT; else time = osalOsGetSystemTimeX() - time; osalSysUnlock(); return time; }
/** * @brief Performs an ADC conversion. * @details Performs a synchronous conversion operation. * @note The buffer is organized as a matrix of M*N elements where M is the * channels number configured into the conversion group and N is the * buffer depth. The samples are sequentially written into the buffer * with no gaps. * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] grpp pointer to a @p ADCConversionGroup object * @param[out] samples pointer to the samples buffer * @param[in] depth buffer depth (matrix rows number). The buffer depth * must be one or an even number. * @return The operation result. * @retval MSG_OK Conversion finished. * @retval MSG_RESET The conversion has been stopped using * @p acdStopConversion() or @p acdStopConversionI(), * the result buffer may contain incorrect data. * @retval MSG_TIMEOUT The conversion has been stopped because an hardware * error. * * @api */ msg_t adcConvert(ADCDriver *adcp, const ADCConversionGroup *grpp, adcsample_t *samples, size_t depth) { msg_t msg; osalSysLock(); osalDbgAssert(adcp->thread == NULL, "already waiting"); adcStartConversionI(adcp, grpp, samples, depth); msg = osalThreadSuspendS(&adcp->thread); osalSysUnlock(); return msg; }