From 16178e1c45a76544d34ce63db37932838353637c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 28 Nov 2009 12:25:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1333 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 210 +++++++++++++++++++ os/hal/src/can.c | 224 ++++++++++++++++++++ os/hal/src/hal.c | 53 +++++ os/hal/src/mac.c | 178 ++++++++++++++++ os/hal/src/mii.c | 37 ++++ os/hal/src/mmc_spi.c | 575 +++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/pal.c | 98 +++++++++ os/hal/src/serial.c | 201 ++++++++++++++++++ os/hal/src/spi.c | 262 +++++++++++++++++++++++ 9 files changed, 1838 insertions(+) create mode 100644 os/hal/src/adc.c create mode 100644 os/hal/src/can.c create mode 100644 os/hal/src/hal.c create mode 100644 os/hal/src/mac.c create mode 100644 os/hal/src/mii.c create mode 100644 os/hal/src/mmc_spi.c create mode 100644 os/hal/src/pal.c create mode 100644 os/hal/src/serial.c create mode 100644 os/hal/src/spi.c (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c new file mode 100644 index 000000000..5a041f056 --- /dev/null +++ b/os/hal/src/adc.c @@ -0,0 +1,210 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file adc.c + * @brief ADC Driver code. + * @addtogroup ADC + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_ADC + +/** + * @brief ADC Driver initialization. + */ +void adcInit(void) { + + adc_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p ADCDriver structure. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcObjectInit(ADCDriver *adcp) { + + adcp->ad_state = ADC_STOP; + adcp->ad_config = NULL; + adcp->ad_callback = NULL; + adcp->ad_samples = NULL; + adcp->ad_depth = 0; + adcp->ad_grpp = NULL; + chSemInit(&adcp->ad_sem, 0); +} + +/** + * @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 + */ +void adcStart(ADCDriver *adcp, const ADCConfig *config) { + + chDbgCheck((adcp != NULL) && (config != NULL), "adcStart"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + "adcStart(), #1", + "invalid state"); + adcp->ad_config = config; + adc_lld_start(adcp); + adcp->ad_state = ADC_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the ADC peripheral. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStop(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStop"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + "adcStop(), #1", + "invalid state"); + adc_lld_stop(adcp); + adcp->ad_state = ADC_STOP; + chSysUnlock(); +} + +/** + * @brief Starts an ADC conversion. + * @details Starts a conversion operation, there are two kind of conversion + * modes: + * - LINEAR, this mode is activated when the @p callback + * parameter is set to @p NULL, in this mode the buffer is filled + * once and then the conversion stops automatically. + * - CIRCULAR, when a callback function is defined the + * conversion never stops and the buffer is filled circularly. + * During the conversion the callback function is invoked when + * the buffer is 50% filled and when the buffer is 100% filled, + * this way is possible to process the conversion stream in real + * time. This kind of conversion can only be stopped by explicitly + * invoking @p adcStopConversion(). + * . + * + * @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. + * @param[in] callback pointer to the conversion callback function + * @return The operation status. + * @retval FALSE the conversion has been started. + * @retval TRUE the driver is busy, conversion not started. + * + * @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. + */ +bool_t adcStartConversion(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth, + adccallback_t callback) { + + chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && + ((depth == 1) || ((depth & 1) == 0)), + "adcStartConversion"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING), + "adcStartConversion(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + chSysUnlock(); + return TRUE; + } + adcp->ad_callback = callback; + adcp->ad_samples = samples; + adcp->ad_depth = depth; + adcp->ad_grpp = grpp; + adc_lld_start_conversion(adcp); + adcp->ad_state = ADC_RUNNING; + chSysUnlock(); + return FALSE; +} + +/** + * @brief Stops an ongoing conversion. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStopConversion(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStopConversion"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING), + "adcStopConversion(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + adc_lld_stop_conversion(adcp); + adcp->ad_grpp = NULL; + adcp->ad_state = ADC_READY; + chSemResetI(&adcp->ad_sem, 0); + chSchRescheduleS(); + } + chSysUnlock(); +} + +/** + * @brief Waits for completion. + * + * @param[in] adcp pointer to the @p ADCDriver object + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK conversion finished (or not started). + * @retval RDY_TIMEOUT conversion not finished within the specified time. + */ +msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING), + "adcWaitConversion(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { + chSysUnlock(); + return RDY_TIMEOUT; + } + } + chSysUnlock(); + return RDY_OK; +} + +#endif /* CH_HAL_USE_ADC */ + +/** @} */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c new file mode 100644 index 000000000..bb3e0d1a5 --- /dev/null +++ b/os/hal/src/can.c @@ -0,0 +1,224 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file CAN.c + * @brief CAN Driver code. + * @addtogroup CAN + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_CAN + +/** + * @brief CAN Driver initialization. + */ +void canInit(void) { + + can_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p CANDriver structure. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canObjectInit(CANDriver *canp) { + + canp->can_state = CAN_STOP; + canp->can_config = NULL; + chSemInit(&canp->can_txsem, 0); + chSemInit(&canp->can_rxsem, 0); + chEvtInit(&canp->can_rxfull_event); + chEvtInit(&canp->can_txempty_event); +#if CAN_USE_SLEEP_MODE + chEvtInit(&canp->can_sleep_event); + chEvtInit(&canp->can_wakeup_event); +#endif /* CAN_USE_SLEEP_MODE */ +} + +/** + * @brief Configures and activates the CAN peripheral. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[in] config pointer to the @p CANConfig object + */ +void canStart(CANDriver *canp, const CANConfig *config) { + + chDbgCheck((canp != NULL) && (config != NULL), "canStart"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + "canStart(), #1", + "invalid state"); + canp->can_config = config; + can_lld_start(canp); + canp->can_state = CAN_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the CAN peripheral. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canStop(CANDriver *canp) { + + chDbgCheck(canp != NULL, "canStop"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + "canStop(), #1", + "invalid state"); + can_lld_stop(canp); + canp->can_state = CAN_STOP; + chSysUnlock(); +} + +/** + * @brief Can frame transmission. + * @details The specified frame is queued for transmission, if the hardware + * queue is full then the invoking thread is queued. + * @note Trying to transmit while in sleep mode simply enqueues the thread. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[in] cfp pointer to the CAN frame to be transmitted + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK the frame has been queued for transmission. + * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_RESET driver stopped while waiting. + */ +msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { + msg_t msg; + + chDbgCheck((canp != NULL) && (cfp != NULL), "canTransmit"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canTransmit(), #1", + "invalid state"); + if ((canp->can_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + msg = chSemWaitTimeoutS(&canp->can_txsem, timeout); + if (msg != RDY_OK) { + chSysUnlock(); + return msg; + } + } + msg = can_lld_transmit(canp, cfp); + chSysUnlock(); + return msg; +} + +/** + * @brief Can frame receive. + * @details The function waits until a frame is received. + * @note Trying to receive while in sleep mode simply enqueues the thread. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[out] cfp pointer to the buffer where the CAN frame is copied + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK a frame has been received and placed in the buffer. + * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_RESET driver stopped while waiting. + */ +msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { + msg_t msg; + + chDbgCheck((canp != NULL) && (cfp != NULL), "canReceive"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canReceive(), #1", + "invalid state"); + if ((canp->can_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + msg = chSemWaitTimeoutS(&canp->can_rxsem, timeout); + if (msg != RDY_OK) { + chSysUnlock(); + return msg; + } + } + msg = can_lld_receive(canp, cfp); + chSysUnlock(); + return msg; +} + +#if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) +/** + * @brief Enters the sleep mode. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canSleep(CANDriver *canp) { + + chDbgCheck(canp != NULL, "canSleep"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canSleep(), #1", + "invalid state"); + if (canp->can_state == CAN_READY) { + can_lld_sleep(canp); + canp->can_state = CAN_SLEEP; + chEvtBroadcastI(&canp->can_sleep_event); + chSchRescheduleS(); + } + chSysUnlock(); +} + +/** + * @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->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canWakeup(), #1", + "invalid state"); + if (canp->can_state == CAN_SLEEP) { + can_lld_wakeup(canp); + canp->can_state = CAN_READY; + chEvtBroadcastI(&canp->can_wakeup_event); + chSchRescheduleS(); + } + chSysUnlock(); +} +#endif /* CAN_USE_SLEEP_MODE */ + +#endif /* CH_HAL_USE_CAN */ + +/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c new file mode 100644 index 000000000..1aec1a478 --- /dev/null +++ b/os/hal/src/hal.c @@ -0,0 +1,53 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file hal.c + * @brief HAL subsystem code. + * @addtogroup HAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +void halInit(void) { + +#if CH_HAL_USE_PAL + palInit(&pal_default_config); +#endif +#if CH_HAL_USE_ADC + adcInit(); +#endif +#if CH_HAL_USE_CAN + canInit(); +#endif +#if CH_HAL_USE_MAC + macInit(); +#endif +#if CH_HAL_USE_SERIAL + sdInit(); +#endif +#if CH_HAL_USE_SPI + spiInit(); +#endif +#if CH_HAL_USE_MMC_SPI + mmcInit(); +#endif +} diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c new file mode 100644 index 000000000..8dfb400aa --- /dev/null +++ b/os/hal/src/mac.c @@ -0,0 +1,178 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mac.c + * @brief MAC Driver code. + * @addtogroup MAC + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_MAC + +/** + * @brief MAC Driver initialization. + */ +void macInit(void) { + + mac_lld_init(); +} + +/** + * @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 +} + +/** + * @brief MAC address setup. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[in] p pointer to a six bytes buffer containing the MAC address. If + * this parameter is set to @p NULL then a system default MAC is + * used. + * + * @note This function must be invoked only with the driver in the stopped + * state. If invoked on an active interface then it is ignored. + */ +void macSetAddress(MACDriver *macp, const uint8_t *p) { + + mac_lld_set_address(macp, p); +} + +/** + * @brief Allocates a transmission descriptor. + * @details One of the available transmission descriptors is locked and + * returned. If a descriptor is not currently available then the + * invoking thread is queued until one is freed. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[out] tdp pointer to a @p MACTransmitDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + */ +msg_t macWaitTransmitDescriptor(MACDriver *macp, + MACTransmitDescriptor *tdp, + systime_t time) { + msg_t msg; + + while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && + (time > 0)) { + chSysLock(); + systime_t now = chTimeNow(); + if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) + break; + if (time != TIME_INFINITE) + time -= (chTimeNow() - now); + chSysUnlock(); + } + return msg; +} + +/** + * @brief Releases a transmit descriptor and starts the transmission of the + * enqueued data as a single frame. + * + * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure + */ +void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { + + mac_lld_release_transmit_descriptor(tdp); +} + +/** + * @brief Waits for a received frame. + * @details Stops until a frame is received and buffered. If a frame is + * not immediately available then the invoking thread is queued + * until one is received. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[out] rdp pointer to a @p MACReceiveDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + */ +msg_t macWaitReceiveDescriptor(MACDriver *macp, + MACReceiveDescriptor *rdp, + systime_t time) { + msg_t msg; + + while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && + (time > 0)) { + chSysLock(); + systime_t now = chTimeNow(); + if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) + break; + if (time != TIME_INFINITE) + time -= (chTimeNow() - now); + chSysUnlock(); + } + return msg; +} + +/** + * @brief Releases a receive descriptor. + * @details The descriptor and its buffer are made available for more incoming + * frames. + * + * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure + */ +void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { + + mac_lld_release_receive_descriptor(rdp); +} + +/** + * @brief Updates and returns the link status. + * + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. + */ +bool_t macPollLinkStatus(MACDriver *macp) { + + return mac_lld_poll_link_status(macp); +} + +#endif /* CH_HAL_USE_MAC */ + +/** @} */ diff --git a/os/hal/src/mii.c b/os/hal/src/mii.c new file mode 100644 index 000000000..4618ecbbb --- /dev/null +++ b/os/hal/src/mii.c @@ -0,0 +1,37 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mii.c + * @brief mii Driver code. + * @addtogroup MII + * @{ + */ + +#include "ch.h" +#include "mac.h" +#include "mii.h" + +/* + * Currently there is no code, everything is done in the header, you may + * omit this file from the project but this may change in future releases. + * The file is here because the driver's naming pattern. + */ + +/** @} */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c new file mode 100644 index 000000000..7846da353 --- /dev/null +++ b/os/hal/src/mmc_spi.c @@ -0,0 +1,575 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mmc_spi.c + * @brief MMC over SPI driver code. + * @addtogroup MMC_SPI + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_MMC_SPI + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +void tmrfunc(void *p) { + MMCDriver *mmcp = p; + + if (mmcp->mmc_cnt > 0) { + if (mmcp->mmc_is_inserted()) { + if (--mmcp->mmc_cnt == 0) { + mmcp->mmc_state = MMC_INSERTED; + chEvtBroadcastI(&mmcp->mmc_inserted_event); + } + } + else + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + } + else { + if (!mmcp->mmc_is_inserted()) { + mmcp->mmc_state = MMC_WAIT; + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + chEvtBroadcastI(&mmcp->mmc_removed_event); + } + } + chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); +} + +/** + * @brief Waits an idle condition. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +static void wait(MMCDriver *mmcp) { + int i; + uint8_t buf[4]; + + for (i = 0; i < 16; i++) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; + } + /* Looks like it is a long wait.*/ + while (TRUE) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; +#ifdef MMC_NICE_WAITING + /* Trying to be nice with the other threads.*/ + chThdSleep(1); +#endif + } +} + +/** + * @brief Sends a command header. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param cmd[in] the command id + * @param arg[in] the command argument + */ +static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { + uint8_t buf[6]; + + /* Wait for the bus to become idle if a write operation was in progress. */ + wait(mmcp); + + buf[0] = 0x40 | cmd; + buf[1] = arg >> 24; + buf[2] = arg >> 16; + buf[3] = arg >> 8; + buf[4] = arg; + buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ + spiSend(mmcp->mmc_spip, 6, buf); +} + +/** + * @brief Receives a single byte response. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The response as an @p uint8_t value. + * @retval 0xFF timed out. + */ +static uint8_t recvr1(MMCDriver *mmcp) { + int i; + uint8_t r1[1]; + + for (i = 0; i < 9; i++) { + spiReceive(mmcp->mmc_spip, 1, r1); + if (r1[0] != 0xFF) + return r1[0]; + } + return 0xFF; +} + +/** + * @brief Sends a command an returns a single byte response. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param cmd[in] the command id + * @param arg[in] the command argument + * + * @return The response as an @p uint8_t value. + * @retval 0xFF timed out. + */ +static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { + uint8_t r1; + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, cmd, arg); + r1 = recvr1(mmcp); + spiUnselect(mmcp->mmc_spip); + return r1; +} + +/** + * @brief Waits that the card reaches an idle state. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +static void sync(MMCDriver *mmcp) { + uint8_t buf[1]; + + spiSelect(mmcp->mmc_spip); + while (TRUE) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; +#ifdef MMC_NICE_WAITING + chThdSleep(1); /* Trying to be nice with the other threads.*/ +#endif + } + spiUnselect(mmcp->mmc_spip); +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief MMC over SPI driver initialization. + */ +void mmcInit(void) { + +} + +/** + * @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); +} + +/** + * @brief Configures and activates the MMC peripheral. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] config pointer to the @p MMCConfig object + */ +void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { + + chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); + + chSysLock(); + chDbgAssert(mmcp->mmc_state == MMC_STOP, "mmcStart(), #1", "invalid state"); + mmcp->mmc_config = config; + mmcp->mmc_state = MMC_WAIT; + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + chSysUnlock(); +} + +/** + * @brief Disables the MMC peripheral. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +void mmcStop(MMCDriver *mmcp) { + + chDbgCheck(mmcp != NULL, "mmcStop"); + + chSysLock(); + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_READING) && + (mmcp->mmc_state != MMC_WRITING), + "mmcStop(), #1", + "invalid state"); + if (mmcp->mmc_state != MMC_STOP) { + mmcp->mmc_state = MMC_STOP; + chVTResetI(&mmcp->mmc_vt); + } + chSysUnlock(); + spiStop(mmcp->mmc_spip); +} + +/** + * @brief Performs the initialization procedure on the inserted card. + * @details This function should be invoked when a card is inserted and + * brings the driver in the @p MMC_READY state where it is possible + * to perform read and write operations. + * @note It is possible to invoke this function from the insertion event + * handler. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful and the driver is now + * in the @p MMC_READY state. + * @retval TRUE the operation failed. + */ +bool_t mmcConnect(MMCDriver *mmcp) { + unsigned i; + bool_t result; + + chDbgCheck(mmcp != NULL, "mmcConnect"); + + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_STOP), + "mmcConnect(), #1", + "invalid state"); + + if (mmcp->mmc_state == MMC_INSERTED) { + /* Slow clock mode and 128 clock pulses.*/ + spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); + spiIgnore(mmcp->mmc_spip, 16); + + /* SPI mode selection.*/ + i = 0; + while (TRUE) { + if (send_command(mmcp, MMC_CMDGOIDLE, 0) == 0x01) + break; + if (++i >= MMC_CMD0_RETRY) + return TRUE; + chThdSleepMilliseconds(10); + } + + /* Initialization. */ + i = 0; + while (TRUE) { + uint8_t b = send_command(mmcp, MMC_CMDINIT, 0); + if (b == 0x00) + break; + if (b != 0x01) + return TRUE; + if (++i >= MMC_CMD1_RETRY) + return TRUE; + chThdSleepMilliseconds(10); + } + + /* Initialization complete, full speed. */ + spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); + + /* Setting block size.*/ + if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) + return TRUE; + + /* Transition to MMC_READY state (if not extracted).*/ + chSysLock(); + if (mmcp->mmc_state == MMC_INSERTED) { + mmcp->mmc_state = MMC_READY; + result = FALSE; + } + else + result = TRUE; + chSysUnlock(); + return result; + } + if (mmcp->mmc_state == MMC_READY) + return FALSE; + /* Any other state is invalid.*/ + return TRUE; +} + +/** + * @brief Brings the driver in a state safe for card removal. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @return The operation status. + * @retval FALSE the operation was successful and the driver is now + * in the @p MMC_INSERTED state. + * @retval TRUE the operation failed. + */ +bool_t mmcDisconnect(MMCDriver *mmcp) { + + chDbgCheck(mmcp != NULL, "mmcConnect"); + + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_STOP), + "mmcDisconnect(), #1", + "invalid state"); + switch (mmcp->mmc_state) { + case MMC_READY: + /* Wait for the pending write operations to complete.*/ + sync(mmcp); + chSysLock(); + if (mmcp->mmc_state == MMC_READY) + mmcp->mmc_state = MMC_INSERTED; + chSysUnlock(); + case MMC_INSERTED: + return FALSE; + default: + return TRUE; + } +} + +/** + * @brief Starts a sequential read. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk first block to read + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { + + chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + mmcp->mmc_state = MMC_READING; + chSysUnlock(); + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; + } + return FALSE; +} + +/** + * @brief Reads a block within a sequential read operation. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to the read buffer + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { + int i; + + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + for (i = 0; i < MMC_WAIT_DATA; i++) { + spiReceive(mmcp->mmc_spip, 1, buffer); + if (buffer[0] == 0xFE) { + spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); + /* CRC ignored. */ + spiIgnore(mmcp->mmc_spip, 2); + return FALSE; + } + } + /* Timeout.*/ + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; +} + +/** + * @brief Stops a sequential read gracefully. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStopSequentialRead(MMCDriver *mmcp) { + static const uint8_t stopcmd[] = {0x40 | MMC_CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; + bool_t result; + + chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); + result = recvr1(mmcp) != 0x00; + spiUnselect(mmcp->mmc_spip); + + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return result; +} + +/** + * @brief Starts a sequential write. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk first block to write + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { + + chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + mmcp->mmc_state = MMC_WRITING; + chSysUnlock(); + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; + } + return FALSE; +} + +/** + * @brief Writes a block within a sequential write operation. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to the write buffer + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { + static const uint8_t start[] = {0xFF, 0xFC}; + uint8_t b[1]; + + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ + spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ + spiReceive(mmcp->mmc_spip, 1, b); + if ((b[0] & 0x1F) == 0x05) + return FALSE; + + /* Error.*/ + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; +} + +/** + * @brief Stops a sequential write gracefully. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { + static const uint8_t stop[] = {0xFD, 0xFF}; + + chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(stop), stop); + spiUnselect(mmcp->mmc_spip); + + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) { + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return FALSE; + } + chSysUnlock(); + return TRUE; +} + +#endif /* CH_HAL_USE_MMC_SPI */ + +/** @} */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c new file mode 100644 index 000000000..1f9d058d5 --- /dev/null +++ b/os/hal/src/pal.c @@ -0,0 +1,98 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file pal.c + * @brief I/O Ports Abstraction Layer code + * @addtogroup PAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_PAL + +/** + * @brief Read from an I/O bus. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @return The bus logical states. + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The function internally uses the @p palReadGroup() macro. The use of + * this function is preferred when you value code size, readability and + * error checking over speed. + */ +ioportmask_t palReadBus(IOBus *bus) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palReadBus"); + + return palReadGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset); +} + +/** + * @brief Write to an I/O bus. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] bits the bits to be written on the I/O bus. Values exceeding + * the bus width are masked so most significant bits are lost. + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + */ +void palWriteBus(IOBus *bus, ioportmask_t bits) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palWriteBus"); + + palWriteGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset, bits); +} + +/** + * @brief Programs a bus with the specified mode. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] mode the mode + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + */ +void palSetBusMode(IOBus *bus, uint_fast8_t mode) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); + + palSetGroupMode(bus->bus_portid, bus->bus_mask, mode); +} + +#endif /* CH_HAL_USE_PAL */ + +/** @} */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c new file mode 100644 index 000000000..2944a98ab --- /dev/null +++ b/os/hal/src/serial.c @@ -0,0 +1,201 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file serial.c + * @brief Serial Driver code. + * @addtogroup SERIAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SERIAL + +/* + * Interface implementation, the following functions just invoke the equivalent + * queue-level function or macro. + */ +static bool_t putwouldblock(void *ip) { + + return chOQIsFull(&((SerialDriver *)ip)->d2.oqueue); +} + +static bool_t getwouldblock(void *ip) { + + return chIQIsEmpty(&((SerialDriver *)ip)->d2.iqueue); +} + +static msg_t put(void *ip, uint8_t b, systime_t timeout) { + + return chOQPutTimeout(&((SerialDriver *)ip)->d2.oqueue, b, timeout); +} + +static msg_t get(void *ip, systime_t timeout) { + + return chIQGetTimeout(&((SerialDriver *)ip)->d2.iqueue, timeout); +} + +static size_t write(void *ip, uint8_t *buffer, size_t n) { + + return chOQWrite(&((SerialDriver *)ip)->d2.oqueue, buffer, n); +} + +static size_t read(void *ip, uint8_t *buffer, size_t n) { + + return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n); +} + +static const struct SerialDriverVMT vmt = { + {putwouldblock, getwouldblock, put, get}, + {write, read}, + {} +}; + +/** + * @brief Serial Driver initialization. + */ +void sdInit(void) { + + sd_lld_init(); +} + +/** + * @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. + */ +void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { + + sdp->vmt = &vmt; + chEvtInit(&sdp->d1.ievent); + chEvtInit(&sdp->d1.oevent); + chEvtInit(&sdp->d2.sevent); + sdp->d2.flags = SD_NO_ERROR; + chIQInit(&sdp->d2.iqueue, sdp->d2.ib, SERIAL_BUFFERS_SIZE, inotify); + chOQInit(&sdp->d2.oqueue, sdp->d2.ob, SERIAL_BUFFERS_SIZE, onotify); +} + +/** + * @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. + */ +void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { + + chSysLock(); + sd_lld_start(sdp, config); + chSysUnlock(); +} + +/** + * @brief Stops the driver. + * @details Any thread waiting on the driver's queues will be awakened with + * the message @p Q_RESET. + * + * @param[in] sdp pointer to a @p SerialDrive object + */ +void sdStop(SerialDriver *sdp) { + + chSysLock(); + sd_lld_stop(sdp); + chOQResetI(&sdp->d2.oqueue); + chIQResetI(&sdp->d2.iqueue); + chSchRescheduleS(); + chSysUnlock(); +} + +/** + * @brief Handles incoming data. + * @details This function must be called from the input interrupt service + * routine in order to enqueue incoming data and generate the + * related events. + * @param[in] sd pointer to a @p SerialDriver structure + * @param[in] b the byte to be written in the driver's Input Queue + */ +void sdIncomingDataI(SerialDriver *sd, uint8_t b) { + + if (chIQPutI(&sd->d2.iqueue, b) < Q_OK) + sdAddFlagsI(sd, SD_OVERRUN_ERROR); + else + chEvtBroadcastI(&sd->d1.ievent); +} + +/** + * @brief Handles outgoing data. + * @details Must be called from the output interrupt service routine in order + * to get the next byte to be transmitted. + * + * @param[in] sd pointer to a @p SerialDriver structure + * @return The byte value read from the driver's output queue. + * @retval Q_EMPTY if the queue is empty (the lower driver usually disables + * the interrupt source when this happens). + */ +msg_t sdRequestDataI(SerialDriver *sd) { + + msg_t b = chOQGetI(&sd->d2.oqueue); + if (b < Q_OK) + chEvtBroadcastI(&sd->d1.oevent); + return b; +} + +/** + * @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] sd pointer to a @p SerialDriver structure + * @param[in] mask condition flags to be added to the mask + */ +void sdAddFlagsI(SerialDriver *sd, sdflags_t mask) { + + sd->d2.flags |= mask; + chEvtBroadcastI(&sd->d2.sevent); +} + +/** + * @brief Returns and clears the errors mask associated to the driver. + * + * @param[in] sd pointer to a @p SerialDriver structure + * @return The condition flags modified since last time this function was + * invoked. + */ +sdflags_t sdGetAndClearFlags(SerialDriver *sd) { + sdflags_t mask; + + mask = sd->d2.flags; + sd->d2.flags = SD_NO_ERROR; + return mask; +} + +#endif /* CH_HAL_USE_SERIAL */ + +/** @} */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c new file mode 100644 index 000000000..8b8ea6f32 --- /dev/null +++ b/os/hal/src/spi.c @@ -0,0 +1,262 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file spi.c + * @brief SPI Driver code. + * @addtogroup SPI + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SPI + +/** + * @brief SPI Driver initialization. + */ +void spiInit(void) { + + spi_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p SPIDriver structure. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiObjectInit(SPIDriver *spip) { + + spip->spd_state = SPI_STOP; +#if CH_USE_MUTEXES + chMtxInit(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&spip->spd_semaphore, 1); +#endif + spip->spd_config = NULL; +} + +/** + * @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 + */ +void spiStart(SPIDriver *spip, const SPIConfig *config) { + + chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStart(), #1", + "invalid state"); + spip->spd_config = config; + spi_lld_start(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiStop(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiStop"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStop(), #1", + "invalid state"); + spi_lld_stop(spip); + spip->spd_state = SPI_STOP; + chSysUnlock(); +} + +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiSelect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiSelect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiSelect(), #1", + "not idle"); + spi_lld_select(spip); + spip->spd_state = SPI_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deasserts the slave select signal. + * @details The previously selected peripheral is unselected. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiUnselect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiUnselect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiUnselect(), #1", + "not locked"); + spi_lld_unselect(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Ignores data on the SPI bus. + * @details This function transmits a series of idle words on the SPI bus and + * ignores the received data. This function can be invoked even + * when a slave select signal has not been yet asserted. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + */ +void spiIgnore(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), + "spiIgnore(), #1", + "not active"); + + spi_lld_ignore(spip, n); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This function performs a simultaneous transmit/receive operation. + * + * @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 + * + * @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. + */ +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchange"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiExchange(), #1", + "not active"); + + spi_lld_exchange(spip, n, txbuf, rxbuf); +} + +/** + * @brief Sends data ever the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @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. + */ +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSend"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiSend(), #1", + "not active"); + + spi_lld_send(spip, n, txbuf); +} + +/** + * @brief Receives data from the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @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. + */ +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceive"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiReceive(), #1", + "not active"); + + spi_lld_receive(spip, n, rxbuf); +} + +#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the SPI bus. + * @details This function tries to gain ownership to the SPI bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiAcquireBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&spip->spd_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiReleaseBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiReleaseBus"); + +#if CH_USE_MUTEXES + (void)spip; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&spip->spd_semaphore); +#endif +} +#endif /*SPI_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_SPI */ + +/** @} */ -- cgit v1.2.3 From 8b412a5a708a025dd7291d8c235a1e93b85dcb29 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 28 Nov 2009 14:18:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1334 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 1aec1a478..b64ba49af 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -27,8 +27,13 @@ #include "ch.h" #include "hal.h" +/** + * @brief HAL initialization. + */ void halInit(void) { + hal_lld_init(); + #if CH_HAL_USE_PAL palInit(&pal_default_config); #endif -- cgit v1.2.3 From 2f43c85736e70a59c0b3675d01d4ddc521223263 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 28 Nov 2009 20:09:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1339 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 5a041f056..c074c0224 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -134,7 +134,8 @@ bool_t adcStartConversion(ADCDriver *adcp, chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING), + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), "adcStartConversion(), #1", "invalid state"); if (adcp->ad_state == ADC_RUNNING) { @@ -162,7 +163,8 @@ void adcStopConversion(ADCDriver *adcp) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING), + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), "adcStopConversion(), #1", "invalid state"); if (adcp->ad_state == ADC_RUNNING) { @@ -172,11 +174,15 @@ void adcStopConversion(ADCDriver *adcp) { chSemResetI(&adcp->ad_sem, 0); chSchRescheduleS(); } + else + adcp->ad_state = ADC_READY; chSysUnlock(); } /** * @brief Waits for completion. + * @details If the conversion is not completed or not yet started then the + * invoking thread waits for a conversion completion event. * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] timeout the number of ticks before the operation timeouts, @@ -185,17 +191,18 @@ void adcStopConversion(ADCDriver *adcp) { * - @a TIME_INFINITE no timeout. * . * @return The operation result. - * @retval RDY_OK conversion finished (or not started). + * @retval RDY_OK conversion finished. * @retval RDY_TIMEOUT conversion not finished within the specified time. */ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING), + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), "adcWaitConversion(), #1", "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { + if (adcp->ad_state != ADC_COMPLETE) { if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { chSysUnlock(); return RDY_TIMEOUT; -- cgit v1.2.3 From bd50dd065001e4534356b7eee1e67cb1c486cb04 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:05:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1340 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index b64ba49af..864789858 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -56,3 +56,5 @@ void halInit(void) { mmcInit(); #endif } + +/** @} */ -- cgit v1.2.3 From 0d0e4d619185ad86270ca5c0212c314f7f4529d5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:25:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1342 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 217 ------------------- os/hal/src/can.c | 224 -------------------- os/hal/src/hal.c | 60 ------ os/hal/src/mac.c | 178 ---------------- os/hal/src/mii.c | 37 ---- os/hal/src/mmc_spi.c | 575 --------------------------------------------------- os/hal/src/pal.c | 98 --------- os/hal/src/serial.c | 201 ------------------ os/hal/src/spi.c | 262 ----------------------- 9 files changed, 1852 deletions(-) delete mode 100644 os/hal/src/adc.c delete mode 100644 os/hal/src/can.c delete mode 100644 os/hal/src/hal.c delete mode 100644 os/hal/src/mac.c delete mode 100644 os/hal/src/mii.c delete mode 100644 os/hal/src/mmc_spi.c delete mode 100644 os/hal/src/pal.c delete mode 100644 os/hal/src/serial.c delete mode 100644 os/hal/src/spi.c (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c deleted file mode 100644 index c074c0224..000000000 --- a/os/hal/src/adc.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file adc.c - * @brief ADC Driver code. - * @addtogroup ADC - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_ADC - -/** - * @brief ADC Driver initialization. - */ -void adcInit(void) { - - adc_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p ADCDriver structure. - * - * @param[in] adcp pointer to the @p ADCDriver object - */ -void adcObjectInit(ADCDriver *adcp) { - - adcp->ad_state = ADC_STOP; - adcp->ad_config = NULL; - adcp->ad_callback = NULL; - adcp->ad_samples = NULL; - adcp->ad_depth = 0; - adcp->ad_grpp = NULL; - chSemInit(&adcp->ad_sem, 0); -} - -/** - * @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 - */ -void adcStart(ADCDriver *adcp, const ADCConfig *config) { - - chDbgCheck((adcp != NULL) && (config != NULL), "adcStart"); - - chSysLock(); - chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), - "adcStart(), #1", - "invalid state"); - adcp->ad_config = config; - adc_lld_start(adcp); - adcp->ad_state = ADC_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the ADC peripheral. - * - * @param[in] adcp pointer to the @p ADCDriver object - */ -void adcStop(ADCDriver *adcp) { - - chDbgCheck(adcp != NULL, "adcStop"); - - chSysLock(); - chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), - "adcStop(), #1", - "invalid state"); - adc_lld_stop(adcp); - adcp->ad_state = ADC_STOP; - chSysUnlock(); -} - -/** - * @brief Starts an ADC conversion. - * @details Starts a conversion operation, there are two kind of conversion - * modes: - * - LINEAR, this mode is activated when the @p callback - * parameter is set to @p NULL, in this mode the buffer is filled - * once and then the conversion stops automatically. - * - CIRCULAR, when a callback function is defined the - * conversion never stops and the buffer is filled circularly. - * During the conversion the callback function is invoked when - * the buffer is 50% filled and when the buffer is 100% filled, - * this way is possible to process the conversion stream in real - * time. This kind of conversion can only be stopped by explicitly - * invoking @p adcStopConversion(). - * . - * - * @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. - * @param[in] callback pointer to the conversion callback function - * @return The operation status. - * @retval FALSE the conversion has been started. - * @retval TRUE the driver is busy, conversion not started. - * - * @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. - */ -bool_t adcStartConversion(ADCDriver *adcp, - const ADCConversionGroup *grpp, - adcsample_t *samples, - size_t depth, - adccallback_t callback) { - - chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && - ((depth == 1) || ((depth & 1) == 0)), - "adcStartConversion"); - - chSysLock(); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || - (adcp->ad_state == ADC_COMPLETE), - "adcStartConversion(), #1", - "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { - chSysUnlock(); - return TRUE; - } - adcp->ad_callback = callback; - adcp->ad_samples = samples; - adcp->ad_depth = depth; - adcp->ad_grpp = grpp; - adc_lld_start_conversion(adcp); - adcp->ad_state = ADC_RUNNING; - chSysUnlock(); - return FALSE; -} - -/** - * @brief Stops an ongoing conversion. - * - * @param[in] adcp pointer to the @p ADCDriver object - */ -void adcStopConversion(ADCDriver *adcp) { - - chDbgCheck(adcp != NULL, "adcStopConversion"); - - chSysLock(); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || - (adcp->ad_state == ADC_COMPLETE), - "adcStopConversion(), #1", - "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { - adc_lld_stop_conversion(adcp); - adcp->ad_grpp = NULL; - adcp->ad_state = ADC_READY; - chSemResetI(&adcp->ad_sem, 0); - chSchRescheduleS(); - } - else - adcp->ad_state = ADC_READY; - chSysUnlock(); -} - -/** - * @brief Waits for completion. - * @details If the conversion is not completed or not yet started then the - * invoking thread waits for a conversion completion event. - * - * @param[in] adcp pointer to the @p ADCDriver object - * @param[in] timeout the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation result. - * @retval RDY_OK conversion finished. - * @retval RDY_TIMEOUT conversion not finished within the specified time. - */ -msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { - - chSysLock(); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || - (adcp->ad_state == ADC_COMPLETE), - "adcWaitConversion(), #1", - "invalid state"); - if (adcp->ad_state != ADC_COMPLETE) { - if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { - chSysUnlock(); - return RDY_TIMEOUT; - } - } - chSysUnlock(); - return RDY_OK; -} - -#endif /* CH_HAL_USE_ADC */ - -/** @} */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c deleted file mode 100644 index bb3e0d1a5..000000000 --- a/os/hal/src/can.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file CAN.c - * @brief CAN Driver code. - * @addtogroup CAN - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_CAN - -/** - * @brief CAN Driver initialization. - */ -void canInit(void) { - - can_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p CANDriver structure. - * - * @param[in] canp pointer to the @p CANDriver object - */ -void canObjectInit(CANDriver *canp) { - - canp->can_state = CAN_STOP; - canp->can_config = NULL; - chSemInit(&canp->can_txsem, 0); - chSemInit(&canp->can_rxsem, 0); - chEvtInit(&canp->can_rxfull_event); - chEvtInit(&canp->can_txempty_event); -#if CAN_USE_SLEEP_MODE - chEvtInit(&canp->can_sleep_event); - chEvtInit(&canp->can_wakeup_event); -#endif /* CAN_USE_SLEEP_MODE */ -} - -/** - * @brief Configures and activates the CAN peripheral. - * - * @param[in] canp pointer to the @p CANDriver object - * @param[in] config pointer to the @p CANConfig object - */ -void canStart(CANDriver *canp, const CANConfig *config) { - - chDbgCheck((canp != NULL) && (config != NULL), "canStart"); - - chSysLock(); - chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), - "canStart(), #1", - "invalid state"); - canp->can_config = config; - can_lld_start(canp); - canp->can_state = CAN_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the CAN peripheral. - * - * @param[in] canp pointer to the @p CANDriver object - */ -void canStop(CANDriver *canp) { - - chDbgCheck(canp != NULL, "canStop"); - - chSysLock(); - chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), - "canStop(), #1", - "invalid state"); - can_lld_stop(canp); - canp->can_state = CAN_STOP; - chSysUnlock(); -} - -/** - * @brief Can frame transmission. - * @details The specified frame is queued for transmission, if the hardware - * queue is full then the invoking thread is queued. - * @note Trying to transmit while in sleep mode simply enqueues the thread. - * - * @param[in] canp pointer to the @p CANDriver object - * @param[in] cfp pointer to the CAN frame to be transmitted - * @param[in] timeout the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation result. - * @retval RDY_OK the frame has been queued for transmission. - * @retval RDY_TIMEOUT operation not finished within the specified time. - * @retval RDY_RESET driver stopped while waiting. - */ -msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { - msg_t msg; - - chDbgCheck((canp != NULL) && (cfp != NULL), "canTransmit"); - - chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), - "canTransmit(), #1", - "invalid state"); - if ((canp->can_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { - msg = chSemWaitTimeoutS(&canp->can_txsem, timeout); - if (msg != RDY_OK) { - chSysUnlock(); - return msg; - } - } - msg = can_lld_transmit(canp, cfp); - chSysUnlock(); - return msg; -} - -/** - * @brief Can frame receive. - * @details The function waits until a frame is received. - * @note Trying to receive while in sleep mode simply enqueues the thread. - * - * @param[in] canp pointer to the @p CANDriver object - * @param[out] cfp pointer to the buffer where the CAN frame is copied - * @param[in] timeout the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation result. - * @retval RDY_OK a frame has been received and placed in the buffer. - * @retval RDY_TIMEOUT operation not finished within the specified time. - * @retval RDY_RESET driver stopped while waiting. - */ -msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { - msg_t msg; - - chDbgCheck((canp != NULL) && (cfp != NULL), "canReceive"); - - chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), - "canReceive(), #1", - "invalid state"); - if ((canp->can_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { - msg = chSemWaitTimeoutS(&canp->can_rxsem, timeout); - if (msg != RDY_OK) { - chSysUnlock(); - return msg; - } - } - msg = can_lld_receive(canp, cfp); - chSysUnlock(); - return msg; -} - -#if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) -/** - * @brief Enters the sleep mode. - * - * @param[in] canp pointer to the @p CANDriver object - */ -void canSleep(CANDriver *canp) { - - chDbgCheck(canp != NULL, "canSleep"); - - chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), - "canSleep(), #1", - "invalid state"); - if (canp->can_state == CAN_READY) { - can_lld_sleep(canp); - canp->can_state = CAN_SLEEP; - chEvtBroadcastI(&canp->can_sleep_event); - chSchRescheduleS(); - } - chSysUnlock(); -} - -/** - * @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->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), - "canWakeup(), #1", - "invalid state"); - if (canp->can_state == CAN_SLEEP) { - can_lld_wakeup(canp); - canp->can_state = CAN_READY; - chEvtBroadcastI(&canp->can_wakeup_event); - chSchRescheduleS(); - } - chSysUnlock(); -} -#endif /* CAN_USE_SLEEP_MODE */ - -#endif /* CH_HAL_USE_CAN */ - -/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c deleted file mode 100644 index 864789858..000000000 --- a/os/hal/src/hal.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file hal.c - * @brief HAL subsystem code. - * @addtogroup HAL - * @{ - */ - -#include "ch.h" -#include "hal.h" - -/** - * @brief HAL initialization. - */ -void halInit(void) { - - hal_lld_init(); - -#if CH_HAL_USE_PAL - palInit(&pal_default_config); -#endif -#if CH_HAL_USE_ADC - adcInit(); -#endif -#if CH_HAL_USE_CAN - canInit(); -#endif -#if CH_HAL_USE_MAC - macInit(); -#endif -#if CH_HAL_USE_SERIAL - sdInit(); -#endif -#if CH_HAL_USE_SPI - spiInit(); -#endif -#if CH_HAL_USE_MMC_SPI - mmcInit(); -#endif -} - -/** @} */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c deleted file mode 100644 index 8dfb400aa..000000000 --- a/os/hal/src/mac.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file mac.c - * @brief MAC Driver code. - * @addtogroup MAC - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_MAC - -/** - * @brief MAC Driver initialization. - */ -void macInit(void) { - - mac_lld_init(); -} - -/** - * @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 -} - -/** - * @brief MAC address setup. - * - * @param[in] macp pointer to the @p MACDriver object - * @param[in] p pointer to a six bytes buffer containing the MAC address. If - * this parameter is set to @p NULL then a system default MAC is - * used. - * - * @note This function must be invoked only with the driver in the stopped - * state. If invoked on an active interface then it is ignored. - */ -void macSetAddress(MACDriver *macp, const uint8_t *p) { - - mac_lld_set_address(macp, p); -} - -/** - * @brief Allocates a transmission descriptor. - * @details One of the available transmission descriptors is locked and - * returned. If a descriptor is not currently available then the - * invoking thread is queued until one is freed. - * - * @param[in] macp pointer to the @p MACDriver object - * @param[out] tdp pointer to a @p MACTransmitDescriptor structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK the descriptor was obtained. - * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. - */ -msg_t macWaitTransmitDescriptor(MACDriver *macp, - MACTransmitDescriptor *tdp, - systime_t time) { - msg_t msg; - - while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && - (time > 0)) { - chSysLock(); - systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) - break; - if (time != TIME_INFINITE) - time -= (chTimeNow() - now); - chSysUnlock(); - } - return msg; -} - -/** - * @brief Releases a transmit descriptor and starts the transmission of the - * enqueued data as a single frame. - * - * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure - */ -void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { - - mac_lld_release_transmit_descriptor(tdp); -} - -/** - * @brief Waits for a received frame. - * @details Stops until a frame is received and buffered. If a frame is - * not immediately available then the invoking thread is queued - * until one is received. - * - * @param[in] macp pointer to the @p MACDriver object - * @param[out] rdp pointer to a @p MACReceiveDescriptor structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK the descriptor was obtained. - * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. - */ -msg_t macWaitReceiveDescriptor(MACDriver *macp, - MACReceiveDescriptor *rdp, - systime_t time) { - msg_t msg; - - while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && - (time > 0)) { - chSysLock(); - systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) - break; - if (time != TIME_INFINITE) - time -= (chTimeNow() - now); - chSysUnlock(); - } - return msg; -} - -/** - * @brief Releases a receive descriptor. - * @details The descriptor and its buffer are made available for more incoming - * frames. - * - * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure - */ -void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { - - mac_lld_release_receive_descriptor(rdp); -} - -/** - * @brief Updates and returns the link status. - * - * @param[in] macp pointer to the @p MACDriver object - * @return The link status. - * @retval TRUE if the link is active. - * @retval FALSE if the link is down. - */ -bool_t macPollLinkStatus(MACDriver *macp) { - - return mac_lld_poll_link_status(macp); -} - -#endif /* CH_HAL_USE_MAC */ - -/** @} */ diff --git a/os/hal/src/mii.c b/os/hal/src/mii.c deleted file mode 100644 index 4618ecbbb..000000000 --- a/os/hal/src/mii.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file mii.c - * @brief mii Driver code. - * @addtogroup MII - * @{ - */ - -#include "ch.h" -#include "mac.h" -#include "mii.h" - -/* - * Currently there is no code, everything is done in the header, you may - * omit this file from the project but this may change in future releases. - * The file is here because the driver's naming pattern. - */ - -/** @} */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c deleted file mode 100644 index 7846da353..000000000 --- a/os/hal/src/mmc_spi.c +++ /dev/null @@ -1,575 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file mmc_spi.c - * @brief MMC over SPI driver code. - * @addtogroup MMC_SPI - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_MMC_SPI - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -void tmrfunc(void *p) { - MMCDriver *mmcp = p; - - if (mmcp->mmc_cnt > 0) { - if (mmcp->mmc_is_inserted()) { - if (--mmcp->mmc_cnt == 0) { - mmcp->mmc_state = MMC_INSERTED; - chEvtBroadcastI(&mmcp->mmc_inserted_event); - } - } - else - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; - } - else { - if (!mmcp->mmc_is_inserted()) { - mmcp->mmc_state = MMC_WAIT; - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; - chEvtBroadcastI(&mmcp->mmc_removed_event); - } - } - chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); -} - -/** - * @brief Waits an idle condition. - * - * @param[in] mmcp pointer to the @p MMCDriver object - */ -static void wait(MMCDriver *mmcp) { - int i; - uint8_t buf[4]; - - for (i = 0; i < 16; i++) { - spiReceive(mmcp->mmc_spip, 1, buf); - if (buf[0] == 0xFF) - break; - } - /* Looks like it is a long wait.*/ - while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); - if (buf[0] == 0xFF) - break; -#ifdef MMC_NICE_WAITING - /* Trying to be nice with the other threads.*/ - chThdSleep(1); -#endif - } -} - -/** - * @brief Sends a command header. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param cmd[in] the command id - * @param arg[in] the command argument - */ -static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { - uint8_t buf[6]; - - /* Wait for the bus to become idle if a write operation was in progress. */ - wait(mmcp); - - buf[0] = 0x40 | cmd; - buf[1] = arg >> 24; - buf[2] = arg >> 16; - buf[3] = arg >> 8; - buf[4] = arg; - buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ - spiSend(mmcp->mmc_spip, 6, buf); -} - -/** - * @brief Receives a single byte response. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The response as an @p uint8_t value. - * @retval 0xFF timed out. - */ -static uint8_t recvr1(MMCDriver *mmcp) { - int i; - uint8_t r1[1]; - - for (i = 0; i < 9; i++) { - spiReceive(mmcp->mmc_spip, 1, r1); - if (r1[0] != 0xFF) - return r1[0]; - } - return 0xFF; -} - -/** - * @brief Sends a command an returns a single byte response. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param cmd[in] the command id - * @param arg[in] the command argument - * - * @return The response as an @p uint8_t value. - * @retval 0xFF timed out. - */ -static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { - uint8_t r1; - - spiSelect(mmcp->mmc_spip); - send_hdr(mmcp, cmd, arg); - r1 = recvr1(mmcp); - spiUnselect(mmcp->mmc_spip); - return r1; -} - -/** - * @brief Waits that the card reaches an idle state. - * - * @param[in] mmcp pointer to the @p MMCDriver object - */ -static void sync(MMCDriver *mmcp) { - uint8_t buf[1]; - - spiSelect(mmcp->mmc_spip); - while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); - if (buf[0] == 0xFF) - break; -#ifdef MMC_NICE_WAITING - chThdSleep(1); /* Trying to be nice with the other threads.*/ -#endif - } - spiUnselect(mmcp->mmc_spip); -} - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * @brief MMC over SPI driver initialization. - */ -void mmcInit(void) { - -} - -/** - * @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); -} - -/** - * @brief Configures and activates the MMC peripheral. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] config pointer to the @p MMCConfig object - */ -void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { - - chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); - - chSysLock(); - chDbgAssert(mmcp->mmc_state == MMC_STOP, "mmcStart(), #1", "invalid state"); - mmcp->mmc_config = config; - mmcp->mmc_state = MMC_WAIT; - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; - chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); - chSysUnlock(); -} - -/** - * @brief Disables the MMC peripheral. - * - * @param[in] mmcp pointer to the @p MMCDriver object - */ -void mmcStop(MMCDriver *mmcp) { - - chDbgCheck(mmcp != NULL, "mmcStop"); - - chSysLock(); - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_READING) && - (mmcp->mmc_state != MMC_WRITING), - "mmcStop(), #1", - "invalid state"); - if (mmcp->mmc_state != MMC_STOP) { - mmcp->mmc_state = MMC_STOP; - chVTResetI(&mmcp->mmc_vt); - } - chSysUnlock(); - spiStop(mmcp->mmc_spip); -} - -/** - * @brief Performs the initialization procedure on the inserted card. - * @details This function should be invoked when a card is inserted and - * brings the driver in the @p MMC_READY state where it is possible - * to perform read and write operations. - * @note It is possible to invoke this function from the insertion event - * handler. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. - * @retval FALSE the operation was successful and the driver is now - * in the @p MMC_READY state. - * @retval TRUE the operation failed. - */ -bool_t mmcConnect(MMCDriver *mmcp) { - unsigned i; - bool_t result; - - chDbgCheck(mmcp != NULL, "mmcConnect"); - - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_STOP), - "mmcConnect(), #1", - "invalid state"); - - if (mmcp->mmc_state == MMC_INSERTED) { - /* Slow clock mode and 128 clock pulses.*/ - spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); - spiIgnore(mmcp->mmc_spip, 16); - - /* SPI mode selection.*/ - i = 0; - while (TRUE) { - if (send_command(mmcp, MMC_CMDGOIDLE, 0) == 0x01) - break; - if (++i >= MMC_CMD0_RETRY) - return TRUE; - chThdSleepMilliseconds(10); - } - - /* Initialization. */ - i = 0; - while (TRUE) { - uint8_t b = send_command(mmcp, MMC_CMDINIT, 0); - if (b == 0x00) - break; - if (b != 0x01) - return TRUE; - if (++i >= MMC_CMD1_RETRY) - return TRUE; - chThdSleepMilliseconds(10); - } - - /* Initialization complete, full speed. */ - spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); - - /* Setting block size.*/ - if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) - return TRUE; - - /* Transition to MMC_READY state (if not extracted).*/ - chSysLock(); - if (mmcp->mmc_state == MMC_INSERTED) { - mmcp->mmc_state = MMC_READY; - result = FALSE; - } - else - result = TRUE; - chSysUnlock(); - return result; - } - if (mmcp->mmc_state == MMC_READY) - return FALSE; - /* Any other state is invalid.*/ - return TRUE; -} - -/** - * @brief Brings the driver in a state safe for card removal. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @return The operation status. - * @retval FALSE the operation was successful and the driver is now - * in the @p MMC_INSERTED state. - * @retval TRUE the operation failed. - */ -bool_t mmcDisconnect(MMCDriver *mmcp) { - - chDbgCheck(mmcp != NULL, "mmcConnect"); - - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_STOP), - "mmcDisconnect(), #1", - "invalid state"); - switch (mmcp->mmc_state) { - case MMC_READY: - /* Wait for the pending write operations to complete.*/ - sync(mmcp); - chSysLock(); - if (mmcp->mmc_state == MMC_READY) - mmcp->mmc_state = MMC_INSERTED; - chSysUnlock(); - case MMC_INSERTED: - return FALSE; - default: - return TRUE; - } -} - -/** - * @brief Starts a sequential read. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] startblk first block to read - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { - - chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); - - chSysLock(); - if (mmcp->mmc_state != MMC_READY) { - chSysUnlock(); - return TRUE; - } - mmcp->mmc_state = MMC_READING; - chSysUnlock(); - - spiSelect(mmcp->mmc_spip); - send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); - if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->mmc_spip); - chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return TRUE; - } - return FALSE; -} - -/** - * @brief Reads a block within a sequential read operation. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param[out] buffer pointer to the read buffer - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { - int i; - - chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); - - chSysLock(); - if (mmcp->mmc_state != MMC_READING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); - - for (i = 0; i < MMC_WAIT_DATA; i++) { - spiReceive(mmcp->mmc_spip, 1, buffer); - if (buffer[0] == 0xFE) { - spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); - /* CRC ignored. */ - spiIgnore(mmcp->mmc_spip, 2); - return FALSE; - } - } - /* Timeout.*/ - spiUnselect(mmcp->mmc_spip); - chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return TRUE; -} - -/** - * @brief Stops a sequential read gracefully. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcStopSequentialRead(MMCDriver *mmcp) { - static const uint8_t stopcmd[] = {0x40 | MMC_CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; - bool_t result; - - chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); - - chSysLock(); - if (mmcp->mmc_state != MMC_READING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); - - spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); - result = recvr1(mmcp) != 0x00; - spiUnselect(mmcp->mmc_spip); - - chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return result; -} - -/** - * @brief Starts a sequential write. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] startblk first block to write - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { - - chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); - - chSysLock(); - if (mmcp->mmc_state != MMC_READY) { - chSysUnlock(); - return TRUE; - } - mmcp->mmc_state = MMC_WRITING; - chSysUnlock(); - - spiSelect(mmcp->mmc_spip); - send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); - if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->mmc_spip); - chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return TRUE; - } - return FALSE; -} - -/** - * @brief Writes a block within a sequential write operation. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * @param[out] buffer pointer to the write buffer - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { - static const uint8_t start[] = {0xFF, 0xFC}; - uint8_t b[1]; - - chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); - - chSysLock(); - if (mmcp->mmc_state != MMC_WRITING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); - - spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ - spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ - spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ - spiReceive(mmcp->mmc_spip, 1, b); - if ((b[0] & 0x1F) == 0x05) - return FALSE; - - /* Error.*/ - spiUnselect(mmcp->mmc_spip); - chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return TRUE; -} - -/** - * @brief Stops a sequential write gracefully. - * - * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. - * @retval FALSE the operation was successful. - * @retval TRUE the operation failed. - */ -bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { - static const uint8_t stop[] = {0xFD, 0xFF}; - - chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); - - chSysLock(); - if (mmcp->mmc_state != MMC_WRITING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); - - spiSend(mmcp->mmc_spip, sizeof(stop), stop); - spiUnselect(mmcp->mmc_spip); - - chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) { - mmcp->mmc_state = MMC_READY; - chSysUnlock(); - return FALSE; - } - chSysUnlock(); - return TRUE; -} - -#endif /* CH_HAL_USE_MMC_SPI */ - -/** @} */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c deleted file mode 100644 index 1f9d058d5..000000000 --- a/os/hal/src/pal.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file pal.c - * @brief I/O Ports Abstraction Layer code - * @addtogroup PAL - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_PAL - -/** - * @brief Read from an I/O bus. - * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @return The bus logical states. - * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The function internally uses the @p palReadGroup() macro. The use of - * this function is preferred when you value code size, readability and - * error checking over speed. - */ -ioportmask_t palReadBus(IOBus *bus) { - - chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palReadBus"); - - return palReadGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset); -} - -/** - * @brief Write to an I/O bus. - * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @param[in] bits the bits to be written on the I/O bus. Values exceeding - * the bus width are masked so most significant bits are lost. - * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - */ -void palWriteBus(IOBus *bus, ioportmask_t bits) { - - chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palWriteBus"); - - palWriteGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset, bits); -} - -/** - * @brief Programs a bus with the specified mode. - * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @param[in] mode the mode - * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - */ -void palSetBusMode(IOBus *bus, uint_fast8_t mode) { - - chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); - - palSetGroupMode(bus->bus_portid, bus->bus_mask, mode); -} - -#endif /* CH_HAL_USE_PAL */ - -/** @} */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c deleted file mode 100644 index 2944a98ab..000000000 --- a/os/hal/src/serial.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file serial.c - * @brief Serial Driver code. - * @addtogroup SERIAL - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_SERIAL - -/* - * Interface implementation, the following functions just invoke the equivalent - * queue-level function or macro. - */ -static bool_t putwouldblock(void *ip) { - - return chOQIsFull(&((SerialDriver *)ip)->d2.oqueue); -} - -static bool_t getwouldblock(void *ip) { - - return chIQIsEmpty(&((SerialDriver *)ip)->d2.iqueue); -} - -static msg_t put(void *ip, uint8_t b, systime_t timeout) { - - return chOQPutTimeout(&((SerialDriver *)ip)->d2.oqueue, b, timeout); -} - -static msg_t get(void *ip, systime_t timeout) { - - return chIQGetTimeout(&((SerialDriver *)ip)->d2.iqueue, timeout); -} - -static size_t write(void *ip, uint8_t *buffer, size_t n) { - - return chOQWrite(&((SerialDriver *)ip)->d2.oqueue, buffer, n); -} - -static size_t read(void *ip, uint8_t *buffer, size_t n) { - - return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n); -} - -static const struct SerialDriverVMT vmt = { - {putwouldblock, getwouldblock, put, get}, - {write, read}, - {} -}; - -/** - * @brief Serial Driver initialization. - */ -void sdInit(void) { - - sd_lld_init(); -} - -/** - * @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. - */ -void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { - - sdp->vmt = &vmt; - chEvtInit(&sdp->d1.ievent); - chEvtInit(&sdp->d1.oevent); - chEvtInit(&sdp->d2.sevent); - sdp->d2.flags = SD_NO_ERROR; - chIQInit(&sdp->d2.iqueue, sdp->d2.ib, SERIAL_BUFFERS_SIZE, inotify); - chOQInit(&sdp->d2.oqueue, sdp->d2.ob, SERIAL_BUFFERS_SIZE, onotify); -} - -/** - * @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. - */ -void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { - - chSysLock(); - sd_lld_start(sdp, config); - chSysUnlock(); -} - -/** - * @brief Stops the driver. - * @details Any thread waiting on the driver's queues will be awakened with - * the message @p Q_RESET. - * - * @param[in] sdp pointer to a @p SerialDrive object - */ -void sdStop(SerialDriver *sdp) { - - chSysLock(); - sd_lld_stop(sdp); - chOQResetI(&sdp->d2.oqueue); - chIQResetI(&sdp->d2.iqueue); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Handles incoming data. - * @details This function must be called from the input interrupt service - * routine in order to enqueue incoming data and generate the - * related events. - * @param[in] sd pointer to a @p SerialDriver structure - * @param[in] b the byte to be written in the driver's Input Queue - */ -void sdIncomingDataI(SerialDriver *sd, uint8_t b) { - - if (chIQPutI(&sd->d2.iqueue, b) < Q_OK) - sdAddFlagsI(sd, SD_OVERRUN_ERROR); - else - chEvtBroadcastI(&sd->d1.ievent); -} - -/** - * @brief Handles outgoing data. - * @details Must be called from the output interrupt service routine in order - * to get the next byte to be transmitted. - * - * @param[in] sd pointer to a @p SerialDriver structure - * @return The byte value read from the driver's output queue. - * @retval Q_EMPTY if the queue is empty (the lower driver usually disables - * the interrupt source when this happens). - */ -msg_t sdRequestDataI(SerialDriver *sd) { - - msg_t b = chOQGetI(&sd->d2.oqueue); - if (b < Q_OK) - chEvtBroadcastI(&sd->d1.oevent); - return b; -} - -/** - * @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] sd pointer to a @p SerialDriver structure - * @param[in] mask condition flags to be added to the mask - */ -void sdAddFlagsI(SerialDriver *sd, sdflags_t mask) { - - sd->d2.flags |= mask; - chEvtBroadcastI(&sd->d2.sevent); -} - -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] sd pointer to a @p SerialDriver structure - * @return The condition flags modified since last time this function was - * invoked. - */ -sdflags_t sdGetAndClearFlags(SerialDriver *sd) { - sdflags_t mask; - - mask = sd->d2.flags; - sd->d2.flags = SD_NO_ERROR; - return mask; -} - -#endif /* CH_HAL_USE_SERIAL */ - -/** @} */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c deleted file mode 100644 index 8b8ea6f32..000000000 --- a/os/hal/src/spi.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file spi.c - * @brief SPI Driver code. - * @addtogroup SPI - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_SPI - -/** - * @brief SPI Driver initialization. - */ -void spiInit(void) { - - spi_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p SPIDriver structure. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiObjectInit(SPIDriver *spip) { - - spip->spd_state = SPI_STOP; -#if CH_USE_MUTEXES - chMtxInit(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES - chSemInit(&spip->spd_semaphore, 1); -#endif - spip->spd_config = NULL; -} - -/** - * @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 - */ -void spiStart(SPIDriver *spip, const SPIConfig *config) { - - chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStart(), #1", - "invalid state"); - spip->spd_config = config; - spi_lld_start(spip); - spip->spd_state = SPI_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the SPI peripheral. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiStop(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiStop"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStop(), #1", - "invalid state"); - spi_lld_stop(spip); - spip->spd_state = SPI_STOP; - chSysUnlock(); -} - -/** - * @brief Asserts the slave select signal and prepares for transfers. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiSelect(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiSelect"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), - "spiSelect(), #1", - "not idle"); - spi_lld_select(spip); - spip->spd_state = SPI_ACTIVE; - chSysUnlock(); -} - -/** - * @brief Deasserts the slave select signal. - * @details The previously selected peripheral is unselected. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiUnselect(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiUnselect"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), - "spiUnselect(), #1", - "not locked"); - spi_lld_unselect(spip); - spip->spd_state = SPI_READY; - chSysUnlock(); -} - -/** - * @brief Ignores data on the SPI bus. - * @details This function transmits a series of idle words on the SPI bus and - * ignores the received data. This function can be invoked even - * when a slave select signal has not been yet asserted. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be ignored - */ -void spiIgnore(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); - chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), - "spiIgnore(), #1", - "not active"); - - spi_lld_ignore(spip, n); -} - -/** - * @brief Exchanges data on the SPI bus. - * @details This function performs a simultaneous transmit/receive operation. - * - * @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 - * - * @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. - */ -void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchange"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiExchange(), #1", - "not active"); - - spi_lld_exchange(spip, n, txbuf, rxbuf); -} - -/** - * @brief Sends data ever the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - * @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. - */ -void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiSend(), #1", - "not active"); - - spi_lld_send(spip, n, txbuf); -} - -/** - * @brief Receives data from the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * - * @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. - */ -void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceive"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiReceive(), #1", - "not active"); - - spi_lld_receive(spip, n, rxbuf); -} - -#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the SPI bus. - * @details This function tries to gain ownership to the SPI bus, if the bus - * is already being used then the invoking thread is queued. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void spiAcquireBus(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&spip->spd_semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void spiReleaseBus(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiReleaseBus"); - -#if CH_USE_MUTEXES - (void)spip; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&spip->spd_semaphore); -#endif -} -#endif /*SPI_USE_MUTUAL_EXCLUSION */ - -#endif /* CH_HAL_USE_SPI */ - -/** @} */ -- cgit v1.2.3 From d4c616e6eeb0587ca450c75b1086efa77ac690e5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:50:13 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1351 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 217 +++++++++++++++++++ os/hal/src/can.c | 224 ++++++++++++++++++++ os/hal/src/mac.c | 178 ++++++++++++++++ os/hal/src/mii.c | 37 ++++ os/hal/src/mmc_spi.c | 572 +++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/pal.c | 98 +++++++++ os/hal/src/serial.c | 201 ++++++++++++++++++ os/hal/src/spi.c | 262 +++++++++++++++++++++++ 8 files changed, 1789 insertions(+) create mode 100644 os/hal/src/adc.c create mode 100644 os/hal/src/can.c create mode 100644 os/hal/src/mac.c create mode 100644 os/hal/src/mii.c create mode 100644 os/hal/src/mmc_spi.c create mode 100644 os/hal/src/pal.c create mode 100644 os/hal/src/serial.c create mode 100644 os/hal/src/spi.c (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c new file mode 100644 index 000000000..c074c0224 --- /dev/null +++ b/os/hal/src/adc.c @@ -0,0 +1,217 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file adc.c + * @brief ADC Driver code. + * @addtogroup ADC + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_ADC + +/** + * @brief ADC Driver initialization. + */ +void adcInit(void) { + + adc_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p ADCDriver structure. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcObjectInit(ADCDriver *adcp) { + + adcp->ad_state = ADC_STOP; + adcp->ad_config = NULL; + adcp->ad_callback = NULL; + adcp->ad_samples = NULL; + adcp->ad_depth = 0; + adcp->ad_grpp = NULL; + chSemInit(&adcp->ad_sem, 0); +} + +/** + * @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 + */ +void adcStart(ADCDriver *adcp, const ADCConfig *config) { + + chDbgCheck((adcp != NULL) && (config != NULL), "adcStart"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + "adcStart(), #1", + "invalid state"); + adcp->ad_config = config; + adc_lld_start(adcp); + adcp->ad_state = ADC_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the ADC peripheral. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStop(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStop"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + "adcStop(), #1", + "invalid state"); + adc_lld_stop(adcp); + adcp->ad_state = ADC_STOP; + chSysUnlock(); +} + +/** + * @brief Starts an ADC conversion. + * @details Starts a conversion operation, there are two kind of conversion + * modes: + * - LINEAR, this mode is activated when the @p callback + * parameter is set to @p NULL, in this mode the buffer is filled + * once and then the conversion stops automatically. + * - CIRCULAR, when a callback function is defined the + * conversion never stops and the buffer is filled circularly. + * During the conversion the callback function is invoked when + * the buffer is 50% filled and when the buffer is 100% filled, + * this way is possible to process the conversion stream in real + * time. This kind of conversion can only be stopped by explicitly + * invoking @p adcStopConversion(). + * . + * + * @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. + * @param[in] callback pointer to the conversion callback function + * @return The operation status. + * @retval FALSE the conversion has been started. + * @retval TRUE the driver is busy, conversion not started. + * + * @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. + */ +bool_t adcStartConversion(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth, + adccallback_t callback) { + + chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && + ((depth == 1) || ((depth & 1) == 0)), + "adcStartConversion"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), + "adcStartConversion(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + chSysUnlock(); + return TRUE; + } + adcp->ad_callback = callback; + adcp->ad_samples = samples; + adcp->ad_depth = depth; + adcp->ad_grpp = grpp; + adc_lld_start_conversion(adcp); + adcp->ad_state = ADC_RUNNING; + chSysUnlock(); + return FALSE; +} + +/** + * @brief Stops an ongoing conversion. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStopConversion(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStopConversion"); + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), + "adcStopConversion(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + adc_lld_stop_conversion(adcp); + adcp->ad_grpp = NULL; + adcp->ad_state = ADC_READY; + chSemResetI(&adcp->ad_sem, 0); + chSchRescheduleS(); + } + else + adcp->ad_state = ADC_READY; + chSysUnlock(); +} + +/** + * @brief Waits for completion. + * @details If the conversion is not completed or not yet started then the + * invoking thread waits for a conversion completion event. + * + * @param[in] adcp pointer to the @p ADCDriver object + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK conversion finished. + * @retval RDY_TIMEOUT conversion not finished within the specified time. + */ +msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { + + chSysLock(); + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), + "adcWaitConversion(), #1", + "invalid state"); + if (adcp->ad_state != ADC_COMPLETE) { + if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { + chSysUnlock(); + return RDY_TIMEOUT; + } + } + chSysUnlock(); + return RDY_OK; +} + +#endif /* CH_HAL_USE_ADC */ + +/** @} */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c new file mode 100644 index 000000000..bb3e0d1a5 --- /dev/null +++ b/os/hal/src/can.c @@ -0,0 +1,224 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file CAN.c + * @brief CAN Driver code. + * @addtogroup CAN + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_CAN + +/** + * @brief CAN Driver initialization. + */ +void canInit(void) { + + can_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p CANDriver structure. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canObjectInit(CANDriver *canp) { + + canp->can_state = CAN_STOP; + canp->can_config = NULL; + chSemInit(&canp->can_txsem, 0); + chSemInit(&canp->can_rxsem, 0); + chEvtInit(&canp->can_rxfull_event); + chEvtInit(&canp->can_txempty_event); +#if CAN_USE_SLEEP_MODE + chEvtInit(&canp->can_sleep_event); + chEvtInit(&canp->can_wakeup_event); +#endif /* CAN_USE_SLEEP_MODE */ +} + +/** + * @brief Configures and activates the CAN peripheral. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[in] config pointer to the @p CANConfig object + */ +void canStart(CANDriver *canp, const CANConfig *config) { + + chDbgCheck((canp != NULL) && (config != NULL), "canStart"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + "canStart(), #1", + "invalid state"); + canp->can_config = config; + can_lld_start(canp); + canp->can_state = CAN_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the CAN peripheral. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canStop(CANDriver *canp) { + + chDbgCheck(canp != NULL, "canStop"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + "canStop(), #1", + "invalid state"); + can_lld_stop(canp); + canp->can_state = CAN_STOP; + chSysUnlock(); +} + +/** + * @brief Can frame transmission. + * @details The specified frame is queued for transmission, if the hardware + * queue is full then the invoking thread is queued. + * @note Trying to transmit while in sleep mode simply enqueues the thread. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[in] cfp pointer to the CAN frame to be transmitted + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK the frame has been queued for transmission. + * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_RESET driver stopped while waiting. + */ +msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { + msg_t msg; + + chDbgCheck((canp != NULL) && (cfp != NULL), "canTransmit"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canTransmit(), #1", + "invalid state"); + if ((canp->can_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + msg = chSemWaitTimeoutS(&canp->can_txsem, timeout); + if (msg != RDY_OK) { + chSysUnlock(); + return msg; + } + } + msg = can_lld_transmit(canp, cfp); + chSysUnlock(); + return msg; +} + +/** + * @brief Can frame receive. + * @details The function waits until a frame is received. + * @note Trying to receive while in sleep mode simply enqueues the thread. + * + * @param[in] canp pointer to the @p CANDriver object + * @param[out] cfp pointer to the buffer where the CAN frame is copied + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation result. + * @retval RDY_OK a frame has been received and placed in the buffer. + * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_RESET driver stopped while waiting. + */ +msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { + msg_t msg; + + chDbgCheck((canp != NULL) && (cfp != NULL), "canReceive"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canReceive(), #1", + "invalid state"); + if ((canp->can_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + msg = chSemWaitTimeoutS(&canp->can_rxsem, timeout); + if (msg != RDY_OK) { + chSysUnlock(); + return msg; + } + } + msg = can_lld_receive(canp, cfp); + chSysUnlock(); + return msg; +} + +#if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) +/** + * @brief Enters the sleep mode. + * + * @param[in] canp pointer to the @p CANDriver object + */ +void canSleep(CANDriver *canp) { + + chDbgCheck(canp != NULL, "canSleep"); + + chSysLock(); + chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canSleep(), #1", + "invalid state"); + if (canp->can_state == CAN_READY) { + can_lld_sleep(canp); + canp->can_state = CAN_SLEEP; + chEvtBroadcastI(&canp->can_sleep_event); + chSchRescheduleS(); + } + chSysUnlock(); +} + +/** + * @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->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + "canWakeup(), #1", + "invalid state"); + if (canp->can_state == CAN_SLEEP) { + can_lld_wakeup(canp); + canp->can_state = CAN_READY; + chEvtBroadcastI(&canp->can_wakeup_event); + chSchRescheduleS(); + } + chSysUnlock(); +} +#endif /* CAN_USE_SLEEP_MODE */ + +#endif /* CH_HAL_USE_CAN */ + +/** @} */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c new file mode 100644 index 000000000..8dfb400aa --- /dev/null +++ b/os/hal/src/mac.c @@ -0,0 +1,178 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mac.c + * @brief MAC Driver code. + * @addtogroup MAC + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_MAC + +/** + * @brief MAC Driver initialization. + */ +void macInit(void) { + + mac_lld_init(); +} + +/** + * @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 +} + +/** + * @brief MAC address setup. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[in] p pointer to a six bytes buffer containing the MAC address. If + * this parameter is set to @p NULL then a system default MAC is + * used. + * + * @note This function must be invoked only with the driver in the stopped + * state. If invoked on an active interface then it is ignored. + */ +void macSetAddress(MACDriver *macp, const uint8_t *p) { + + mac_lld_set_address(macp, p); +} + +/** + * @brief Allocates a transmission descriptor. + * @details One of the available transmission descriptors is locked and + * returned. If a descriptor is not currently available then the + * invoking thread is queued until one is freed. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[out] tdp pointer to a @p MACTransmitDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + */ +msg_t macWaitTransmitDescriptor(MACDriver *macp, + MACTransmitDescriptor *tdp, + systime_t time) { + msg_t msg; + + while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && + (time > 0)) { + chSysLock(); + systime_t now = chTimeNow(); + if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) + break; + if (time != TIME_INFINITE) + time -= (chTimeNow() - now); + chSysUnlock(); + } + return msg; +} + +/** + * @brief Releases a transmit descriptor and starts the transmission of the + * enqueued data as a single frame. + * + * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure + */ +void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { + + mac_lld_release_transmit_descriptor(tdp); +} + +/** + * @brief Waits for a received frame. + * @details Stops until a frame is received and buffered. If a frame is + * not immediately available then the invoking thread is queued + * until one is received. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[out] rdp pointer to a @p MACReceiveDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + */ +msg_t macWaitReceiveDescriptor(MACDriver *macp, + MACReceiveDescriptor *rdp, + systime_t time) { + msg_t msg; + + while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && + (time > 0)) { + chSysLock(); + systime_t now = chTimeNow(); + if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) + break; + if (time != TIME_INFINITE) + time -= (chTimeNow() - now); + chSysUnlock(); + } + return msg; +} + +/** + * @brief Releases a receive descriptor. + * @details The descriptor and its buffer are made available for more incoming + * frames. + * + * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure + */ +void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { + + mac_lld_release_receive_descriptor(rdp); +} + +/** + * @brief Updates and returns the link status. + * + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. + */ +bool_t macPollLinkStatus(MACDriver *macp) { + + return mac_lld_poll_link_status(macp); +} + +#endif /* CH_HAL_USE_MAC */ + +/** @} */ diff --git a/os/hal/src/mii.c b/os/hal/src/mii.c new file mode 100644 index 000000000..4618ecbbb --- /dev/null +++ b/os/hal/src/mii.c @@ -0,0 +1,37 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mii.c + * @brief mii Driver code. + * @addtogroup MII + * @{ + */ + +#include "ch.h" +#include "mac.h" +#include "mii.h" + +/* + * Currently there is no code, everything is done in the header, you may + * omit this file from the project but this may change in future releases. + * The file is here because the driver's naming pattern. + */ + +/** @} */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c new file mode 100644 index 000000000..4f6adaf7d --- /dev/null +++ b/os/hal/src/mmc_spi.c @@ -0,0 +1,572 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mmc_spi.c + * @brief MMC over SPI driver code + * @addtogroup MMC_SPI + * @{ + */ + +#include +#include +#include + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +void tmrfunc(void *p) { + MMCDriver *mmcp = p; + + if (mmcp->mmc_cnt > 0) { + if (mmcp->mmc_is_inserted()) { + if (--mmcp->mmc_cnt == 0) { + mmcp->mmc_state = MMC_INSERTED; + chEvtBroadcastI(&mmcp->mmc_inserted_event); + } + } + else + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + } + else { + if (!mmcp->mmc_is_inserted()) { + mmcp->mmc_state = MMC_WAIT; + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + chEvtBroadcastI(&mmcp->mmc_removed_event); + } + } + chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); +} + +/** + * @brief Waits an idle condition. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +static void wait(MMCDriver *mmcp) { + int i; + uint8_t buf[4]; + + for (i = 0; i < 16; i++) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; + } + /* Looks like it is a long wait.*/ + while (TRUE) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; +#ifdef MMC_NICE_WAITING + /* Trying to be nice with the other threads.*/ + chThdSleep(1); +#endif + } +} + +/** + * @brief Sends a command header. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param cmd[in] the command id + * @param arg[in] the command argument + */ +static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { + uint8_t buf[6]; + + /* Wait for the bus to become idle if a write operation was in progress. */ + wait(mmcp); + + buf[0] = 0x40 | cmd; + buf[1] = arg >> 24; + buf[2] = arg >> 16; + buf[3] = arg >> 8; + buf[4] = arg; + buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ + spiSend(mmcp->mmc_spip, 6, buf); +} + +/** + * @brief Receives a single byte response. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The response as an @p uint8_t value. + * @retval 0xFF timed out. + */ +static uint8_t recvr1(MMCDriver *mmcp) { + int i; + uint8_t r1[1]; + + for (i = 0; i < 9; i++) { + spiReceive(mmcp->mmc_spip, 1, r1); + if (r1[0] != 0xFF) + return r1[0]; + } + return 0xFF; +} + +/** + * @brief Sends a command an returns a single byte response. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param cmd[in] the command id + * @param arg[in] the command argument + * + * @return The response as an @p uint8_t value. + * @retval 0xFF timed out. + */ +static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { + uint8_t r1; + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, cmd, arg); + r1 = recvr1(mmcp); + spiUnselect(mmcp->mmc_spip); + return r1; +} + +/** + * @brief Waits that the card reaches an idle state. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +static void sync(MMCDriver *mmcp) { + uint8_t buf[1]; + + spiSelect(mmcp->mmc_spip); + while (TRUE) { + spiReceive(mmcp->mmc_spip, 1, buf); + if (buf[0] == 0xFF) + break; +#ifdef MMC_NICE_WAITING + chThdSleep(1); /* Trying to be nice with the other threads.*/ +#endif + } + spiUnselect(mmcp->mmc_spip); +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief MMC over SPI driver initialization. + */ +void mmcInit(void) { + +} + +/** + * @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); +} + +/** + * @brief Configures and activates the MMC peripheral. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] config pointer to the @p MMCConfig object + */ +void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { + + chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); + + chSysLock(); + chDbgAssert(mmcp->mmc_state == MMC_STOP, "mmcStart(), #1", "invalid state"); + mmcp->mmc_config = config; + mmcp->mmc_state = MMC_WAIT; + mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + chSysUnlock(); +} + +/** + * @brief Disables the MMC peripheral. + * + * @param[in] mmcp pointer to the @p MMCDriver object + */ +void mmcStop(MMCDriver *mmcp) { + + chDbgCheck(mmcp != NULL, "mmcStop"); + + chSysLock(); + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_READING) && + (mmcp->mmc_state != MMC_WRITING), + "mmcStop(), #1", + "invalid state"); + if (mmcp->mmc_state != MMC_STOP) { + mmcp->mmc_state = MMC_STOP; + chVTResetI(&mmcp->mmc_vt); + } + chSysUnlock(); + spiStop(mmcp->mmc_spip); +} + +/** + * @brief Performs the initialization procedure on the inserted card. + * @details This function should be invoked when a card is inserted and + * brings the driver in the @p MMC_READY state where it is possible + * to perform read and write operations. + * @note It is possible to invoke this function from the insertion event + * handler. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful and the driver is now + * in the @p MMC_READY state. + * @retval TRUE the operation failed. + */ +bool_t mmcConnect(MMCDriver *mmcp) { + unsigned i; + bool_t result; + + chDbgCheck(mmcp != NULL, "mmcConnect"); + + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_STOP), + "mmcConnect(), #1", + "invalid state"); + + if (mmcp->mmc_state == MMC_INSERTED) { + /* Slow clock mode and 128 clock pulses.*/ + spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); + spiIgnore(mmcp->mmc_spip, 16); + + /* SPI mode selection.*/ + i = 0; + while (TRUE) { + if (send_command(mmcp, MMC_CMDGOIDLE, 0) == 0x01) + break; + if (++i >= MMC_CMD0_RETRY) + return TRUE; + chThdSleepMilliseconds(10); + } + + /* Initialization. */ + i = 0; + while (TRUE) { + uint8_t b = send_command(mmcp, MMC_CMDINIT, 0); + if (b == 0x00) + break; + if (b != 0x01) + return TRUE; + if (++i >= MMC_CMD1_RETRY) + return TRUE; + chThdSleepMilliseconds(10); + } + + /* Initialization complete, full speed. */ + spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); + + /* Setting block size.*/ + if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) + return TRUE; + + /* Transition to MMC_READY state (if not extracted).*/ + chSysLock(); + if (mmcp->mmc_state == MMC_INSERTED) { + mmcp->mmc_state = MMC_READY; + result = FALSE; + } + else + result = TRUE; + chSysUnlock(); + return result; + } + if (mmcp->mmc_state == MMC_READY) + return FALSE; + /* Any other state is invalid.*/ + return TRUE; +} + +/** + * @brief Brings the driver in a state safe for card removal. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @return The operation status. + * @retval FALSE the operation was successful and the driver is now + * in the @p MMC_INSERTED state. + * @retval TRUE the operation failed. + */ +bool_t mmcDisconnect(MMCDriver *mmcp) { + + chDbgCheck(mmcp != NULL, "mmcConnect"); + + chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && + (mmcp->mmc_state != MMC_STOP), + "mmcDisconnect(), #1", + "invalid state"); + switch (mmcp->mmc_state) { + case MMC_READY: + /* Wait for the pending write operations to complete.*/ + sync(mmcp); + chSysLock(); + if (mmcp->mmc_state == MMC_READY) + mmcp->mmc_state = MMC_INSERTED; + chSysUnlock(); + case MMC_INSERTED: + return FALSE; + default: + return TRUE; + } +} + +/** + * @brief Starts a sequential read. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk first block to read + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { + + chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + mmcp->mmc_state = MMC_READING; + chSysUnlock(); + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; + } + return FALSE; +} + +/** + * @brief Reads a block within a sequential read operation. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to the read buffer + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { + int i; + + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + for (i = 0; i < MMC_WAIT_DATA; i++) { + spiReceive(mmcp->mmc_spip, 1, buffer); + if (buffer[0] == 0xFE) { + spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); + /* CRC ignored. */ + spiIgnore(mmcp->mmc_spip, 2); + return FALSE; + } + } + /* Timeout.*/ + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; +} + +/** + * @brief Stops a sequential read gracefully. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStopSequentialRead(MMCDriver *mmcp) { + static const uint8_t stopcmd[] = {0x40 | MMC_CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; + bool_t result; + + chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); + result = recvr1(mmcp) != 0x00; + spiUnselect(mmcp->mmc_spip); + + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return result; +} + +/** + * @brief Starts a sequential write. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk first block to write + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { + + chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + mmcp->mmc_state = MMC_WRITING; + chSysUnlock(); + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; + } + return FALSE; +} + +/** + * @brief Writes a block within a sequential write operation. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to the write buffer + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { + static const uint8_t start[] = {0xFF, 0xFC}; + uint8_t b[1]; + + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ + spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ + spiReceive(mmcp->mmc_spip, 1, b); + if ((b[0] & 0x1F) == 0x05) + return FALSE; + + /* Error.*/ + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; +} + +/** + * @brief Stops a sequential write gracefully. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { + static const uint8_t stop[] = {0xFD, 0xFF}; + + chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(stop), stop); + spiUnselect(mmcp->mmc_spip); + + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) { + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return FALSE; + } + chSysUnlock(); + return TRUE; +} + +/** @} */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c new file mode 100644 index 000000000..1f9d058d5 --- /dev/null +++ b/os/hal/src/pal.c @@ -0,0 +1,98 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file pal.c + * @brief I/O Ports Abstraction Layer code + * @addtogroup PAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_PAL + +/** + * @brief Read from an I/O bus. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @return The bus logical states. + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The function internally uses the @p palReadGroup() macro. The use of + * this function is preferred when you value code size, readability and + * error checking over speed. + */ +ioportmask_t palReadBus(IOBus *bus) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palReadBus"); + + return palReadGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset); +} + +/** + * @brief Write to an I/O bus. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] bits the bits to be written on the I/O bus. Values exceeding + * the bus width are masked so most significant bits are lost. + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + */ +void palWriteBus(IOBus *bus, ioportmask_t bits) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palWriteBus"); + + palWriteGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset, bits); +} + +/** + * @brief Programs a bus with the specified mode. + * + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] mode the mode + * + * @note The operation is not guaranteed to be atomic on all the architectures, + * for atomicity and/or portability reasons you may need to enclose port + * I/O operations between @p chSysLock() and @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + */ +void palSetBusMode(IOBus *bus, uint_fast8_t mode) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); + + palSetGroupMode(bus->bus_portid, bus->bus_mask, mode); +} + +#endif /* CH_HAL_USE_PAL */ + +/** @} */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c new file mode 100644 index 000000000..2944a98ab --- /dev/null +++ b/os/hal/src/serial.c @@ -0,0 +1,201 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file serial.c + * @brief Serial Driver code. + * @addtogroup SERIAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SERIAL + +/* + * Interface implementation, the following functions just invoke the equivalent + * queue-level function or macro. + */ +static bool_t putwouldblock(void *ip) { + + return chOQIsFull(&((SerialDriver *)ip)->d2.oqueue); +} + +static bool_t getwouldblock(void *ip) { + + return chIQIsEmpty(&((SerialDriver *)ip)->d2.iqueue); +} + +static msg_t put(void *ip, uint8_t b, systime_t timeout) { + + return chOQPutTimeout(&((SerialDriver *)ip)->d2.oqueue, b, timeout); +} + +static msg_t get(void *ip, systime_t timeout) { + + return chIQGetTimeout(&((SerialDriver *)ip)->d2.iqueue, timeout); +} + +static size_t write(void *ip, uint8_t *buffer, size_t n) { + + return chOQWrite(&((SerialDriver *)ip)->d2.oqueue, buffer, n); +} + +static size_t read(void *ip, uint8_t *buffer, size_t n) { + + return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n); +} + +static const struct SerialDriverVMT vmt = { + {putwouldblock, getwouldblock, put, get}, + {write, read}, + {} +}; + +/** + * @brief Serial Driver initialization. + */ +void sdInit(void) { + + sd_lld_init(); +} + +/** + * @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. + */ +void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { + + sdp->vmt = &vmt; + chEvtInit(&sdp->d1.ievent); + chEvtInit(&sdp->d1.oevent); + chEvtInit(&sdp->d2.sevent); + sdp->d2.flags = SD_NO_ERROR; + chIQInit(&sdp->d2.iqueue, sdp->d2.ib, SERIAL_BUFFERS_SIZE, inotify); + chOQInit(&sdp->d2.oqueue, sdp->d2.ob, SERIAL_BUFFERS_SIZE, onotify); +} + +/** + * @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. + */ +void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { + + chSysLock(); + sd_lld_start(sdp, config); + chSysUnlock(); +} + +/** + * @brief Stops the driver. + * @details Any thread waiting on the driver's queues will be awakened with + * the message @p Q_RESET. + * + * @param[in] sdp pointer to a @p SerialDrive object + */ +void sdStop(SerialDriver *sdp) { + + chSysLock(); + sd_lld_stop(sdp); + chOQResetI(&sdp->d2.oqueue); + chIQResetI(&sdp->d2.iqueue); + chSchRescheduleS(); + chSysUnlock(); +} + +/** + * @brief Handles incoming data. + * @details This function must be called from the input interrupt service + * routine in order to enqueue incoming data and generate the + * related events. + * @param[in] sd pointer to a @p SerialDriver structure + * @param[in] b the byte to be written in the driver's Input Queue + */ +void sdIncomingDataI(SerialDriver *sd, uint8_t b) { + + if (chIQPutI(&sd->d2.iqueue, b) < Q_OK) + sdAddFlagsI(sd, SD_OVERRUN_ERROR); + else + chEvtBroadcastI(&sd->d1.ievent); +} + +/** + * @brief Handles outgoing data. + * @details Must be called from the output interrupt service routine in order + * to get the next byte to be transmitted. + * + * @param[in] sd pointer to a @p SerialDriver structure + * @return The byte value read from the driver's output queue. + * @retval Q_EMPTY if the queue is empty (the lower driver usually disables + * the interrupt source when this happens). + */ +msg_t sdRequestDataI(SerialDriver *sd) { + + msg_t b = chOQGetI(&sd->d2.oqueue); + if (b < Q_OK) + chEvtBroadcastI(&sd->d1.oevent); + return b; +} + +/** + * @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] sd pointer to a @p SerialDriver structure + * @param[in] mask condition flags to be added to the mask + */ +void sdAddFlagsI(SerialDriver *sd, sdflags_t mask) { + + sd->d2.flags |= mask; + chEvtBroadcastI(&sd->d2.sevent); +} + +/** + * @brief Returns and clears the errors mask associated to the driver. + * + * @param[in] sd pointer to a @p SerialDriver structure + * @return The condition flags modified since last time this function was + * invoked. + */ +sdflags_t sdGetAndClearFlags(SerialDriver *sd) { + sdflags_t mask; + + mask = sd->d2.flags; + sd->d2.flags = SD_NO_ERROR; + return mask; +} + +#endif /* CH_HAL_USE_SERIAL */ + +/** @} */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c new file mode 100644 index 000000000..8b8ea6f32 --- /dev/null +++ b/os/hal/src/spi.c @@ -0,0 +1,262 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file spi.c + * @brief SPI Driver code. + * @addtogroup SPI + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SPI + +/** + * @brief SPI Driver initialization. + */ +void spiInit(void) { + + spi_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p SPIDriver structure. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiObjectInit(SPIDriver *spip) { + + spip->spd_state = SPI_STOP; +#if CH_USE_MUTEXES + chMtxInit(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&spip->spd_semaphore, 1); +#endif + spip->spd_config = NULL; +} + +/** + * @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 + */ +void spiStart(SPIDriver *spip, const SPIConfig *config) { + + chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStart(), #1", + "invalid state"); + spip->spd_config = config; + spi_lld_start(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiStop(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiStop"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStop(), #1", + "invalid state"); + spi_lld_stop(spip); + spip->spd_state = SPI_STOP; + chSysUnlock(); +} + +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiSelect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiSelect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiSelect(), #1", + "not idle"); + spi_lld_select(spip); + spip->spd_state = SPI_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deasserts the slave select signal. + * @details The previously selected peripheral is unselected. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiUnselect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiUnselect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiUnselect(), #1", + "not locked"); + spi_lld_unselect(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Ignores data on the SPI bus. + * @details This function transmits a series of idle words on the SPI bus and + * ignores the received data. This function can be invoked even + * when a slave select signal has not been yet asserted. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + */ +void spiIgnore(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), + "spiIgnore(), #1", + "not active"); + + spi_lld_ignore(spip, n); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This function performs a simultaneous transmit/receive operation. + * + * @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 + * + * @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. + */ +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchange"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiExchange(), #1", + "not active"); + + spi_lld_exchange(spip, n, txbuf, rxbuf); +} + +/** + * @brief Sends data ever the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @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. + */ +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSend"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiSend(), #1", + "not active"); + + spi_lld_send(spip, n, txbuf); +} + +/** + * @brief Receives data from the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @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. + */ +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceive"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiReceive(), #1", + "not active"); + + spi_lld_receive(spip, n, rxbuf); +} + +#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the SPI bus. + * @details This function tries to gain ownership to the SPI bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiAcquireBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&spip->spd_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiReleaseBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiReleaseBus"); + +#if CH_USE_MUTEXES + (void)spip; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&spip->spd_semaphore); +#endif +} +#endif /*SPI_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_SPI */ + +/** @} */ -- cgit v1.2.3 From 31c93cbb657b700e23863f2ef6bfa8fab0e12152 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:54:20 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1352 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 4f6adaf7d..7846da353 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -19,14 +19,15 @@ /** * @file mmc_spi.c - * @brief MMC over SPI driver code + * @brief MMC over SPI driver code. * @addtogroup MMC_SPI * @{ */ -#include -#include -#include +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_MMC_SPI /*===========================================================================*/ /* Driver local functions. */ @@ -569,4 +570,6 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { return TRUE; } +#endif /* CH_HAL_USE_MMC_SPI */ + /** @} */ -- cgit v1.2.3 From f90ae4d17df24cd6477f2557bc86ef9433e93414 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 10:37:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1354 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- os/hal/src/can.c | 2 +- os/hal/src/hal.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/mac.c | 2 +- os/hal/src/mmc_spi.c | 2 +- os/hal/src/pal.c | 2 +- os/hal/src/serial.c | 2 +- os/hal/src/spi.c | 2 +- 8 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 os/hal/src/hal.c (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index c074c0224..afa464212 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_ADC +#if CH_HAL_USE_ADC || defined(__DOXYGEN__) /** * @brief ADC Driver initialization. diff --git a/os/hal/src/can.c b/os/hal/src/can.c index bb3e0d1a5..387581d8c 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_CAN +#if CH_HAL_USE_CAN || defined(__DOXYGEN__) /** * @brief CAN Driver initialization. diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c new file mode 100644 index 000000000..864789858 --- /dev/null +++ b/os/hal/src/hal.c @@ -0,0 +1,60 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file hal.c + * @brief HAL subsystem code. + * @addtogroup HAL + * @{ + */ + +#include "ch.h" +#include "hal.h" + +/** + * @brief HAL initialization. + */ +void halInit(void) { + + hal_lld_init(); + +#if CH_HAL_USE_PAL + palInit(&pal_default_config); +#endif +#if CH_HAL_USE_ADC + adcInit(); +#endif +#if CH_HAL_USE_CAN + canInit(); +#endif +#if CH_HAL_USE_MAC + macInit(); +#endif +#if CH_HAL_USE_SERIAL + sdInit(); +#endif +#if CH_HAL_USE_SPI + spiInit(); +#endif +#if CH_HAL_USE_MMC_SPI + mmcInit(); +#endif +} + +/** @} */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 8dfb400aa..a18d3e4df 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_MAC +#if CH_HAL_USE_MAC || defined(__DOXYGEN__) /** * @brief MAC Driver initialization. diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 7846da353..24abf2a2b 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_MMC_SPI +#if CH_HAL_USE_MMC_SPI || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver local functions. */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 1f9d058d5..53cfeb1f0 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_PAL +#if CH_HAL_USE_PAL || defined(__DOXYGEN__) /** * @brief Read from an I/O bus. diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 2944a98ab..d2cb17c77 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SERIAL +#if CH_HAL_USE_SERIAL || defined(__DOXYGEN__) /* * Interface implementation, the following functions just invoke the equivalent diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 8b8ea6f32..08113a000 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SPI +#if CH_HAL_USE_SPI || defined(__DOXYGEN__) /** * @brief SPI Driver initialization. -- cgit v1.2.3 From 3f8c09fde198a3680a5de0628c0cfbaf7f4d3abb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 17:35:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1361 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mii.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 os/hal/src/mii.c (limited to 'os/hal/src') diff --git a/os/hal/src/mii.c b/os/hal/src/mii.c deleted file mode 100644 index 4618ecbbb..000000000 --- a/os/hal/src/mii.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file mii.c - * @brief mii Driver code. - * @addtogroup MII - * @{ - */ - -#include "ch.h" -#include "mac.h" -#include "mii.h" - -/* - * Currently there is no code, everything is done in the header, you may - * omit this file from the project but this may change in future releases. - * The file is here because the driver's naming pattern. - */ - -/** @} */ -- cgit v1.2.3 From 8a433087afe80e92aea1c558965994b53bfcfb48 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 30 Nov 2009 21:34:05 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1368 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 71 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 387581d8c..698bcfbc4 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -44,15 +44,15 @@ void canInit(void) { */ void canObjectInit(CANDriver *canp) { - canp->can_state = CAN_STOP; - canp->can_config = NULL; - chSemInit(&canp->can_txsem, 0); - chSemInit(&canp->can_rxsem, 0); - chEvtInit(&canp->can_rxfull_event); - chEvtInit(&canp->can_txempty_event); + canp->cd_state = CAN_STOP; + canp->cd_config = NULL; + chSemInit(&canp->cd_txsem, 0); + chSemInit(&canp->cd_rxsem, 0); + chEvtInit(&canp->cd_rxfull_event); + chEvtInit(&canp->cd_txempty_event); #if CAN_USE_SLEEP_MODE - chEvtInit(&canp->can_sleep_event); - chEvtInit(&canp->can_wakeup_event); + chEvtInit(&canp->cd_sleep_event); + chEvtInit(&canp->cd_wakeup_event); #endif /* CAN_USE_SLEEP_MODE */ } @@ -67,12 +67,12 @@ void canStart(CANDriver *canp, const CANConfig *config) { chDbgCheck((canp != NULL) && (config != NULL), "canStart"); chSysLock(); - chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), "canStart(), #1", "invalid state"); - canp->can_config = config; + canp->cd_config = config; can_lld_start(canp); - canp->can_state = CAN_READY; + canp->cd_state = CAN_READY; chSysUnlock(); } @@ -86,11 +86,11 @@ void canStop(CANDriver *canp) { chDbgCheck(canp != NULL, "canStop"); chSysLock(); - chDbgAssert((canp->can_state == CAN_STOP) || (canp->can_state == CAN_READY), + chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), "canStop(), #1", "invalid state"); can_lld_stop(canp); - canp->can_state = CAN_STOP; + canp->cd_state = CAN_STOP; chSysUnlock(); } @@ -118,11 +118,11 @@ msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { chDbgCheck((canp != NULL) && (cfp != NULL), "canTransmit"); chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); - if ((canp->can_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { - msg = chSemWaitTimeoutS(&canp->can_txsem, timeout); + if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; @@ -156,11 +156,11 @@ msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { chDbgCheck((canp != NULL) && (cfp != NULL), "canReceive"); chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canReceive(), #1", "invalid state"); - if ((canp->can_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { - msg = chSemWaitTimeoutS(&canp->can_rxsem, timeout); + if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; @@ -171,6 +171,23 @@ msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { return msg; } +/** + * @brief Returns the current status mask and clears it. + * + * @param[in] canp pointer to the @p CANDriver object + * + * @return The status flags mask. + */ +canstatus_t canGetAndClearFlags(CANDriver *canp) { + canstatus_t status; + + chSysLock(); + status = canp->cd_status; + canp->cd_status = 0; + chSysUnlock(); + return status; +} + #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** * @brief Enters the sleep mode. @@ -182,13 +199,13 @@ void canSleep(CANDriver *canp) { chDbgCheck(canp != NULL, "canSleep"); chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canSleep(), #1", "invalid state"); - if (canp->can_state == CAN_READY) { + if (canp->cd_state == CAN_READY) { can_lld_sleep(canp); - canp->can_state = CAN_SLEEP; - chEvtBroadcastI(&canp->can_sleep_event); + canp->cd_state = CAN_SLEEP; + chEvtBroadcastI(&canp->cd_sleep_event); chSchRescheduleS(); } chSysUnlock(); @@ -206,13 +223,13 @@ void canWakeup(CANDriver *canp) { chDbgCheck(canp != NULL, "canWakeup"); chSysLock(); - chDbgAssert((canp->can_state == CAN_READY) || (canp->can_state == CAN_SLEEP), + chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canWakeup(), #1", "invalid state"); - if (canp->can_state == CAN_SLEEP) { + if (canp->cd_state == CAN_SLEEP) { can_lld_wakeup(canp); - canp->can_state = CAN_READY; - chEvtBroadcastI(&canp->can_wakeup_event); + canp->cd_state = CAN_READY; + chEvtBroadcastI(&canp->cd_wakeup_event); chSchRescheduleS(); } chSysUnlock(); -- cgit v1.2.3 From 3d182788ee7386b0fa53b4aee08fe8146d67d3b0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 1 Dec 2009 16:32:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1369 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 698bcfbc4..7c6cdd656 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -50,6 +50,8 @@ void canObjectInit(CANDriver *canp) { chSemInit(&canp->cd_rxsem, 0); chEvtInit(&canp->cd_rxfull_event); chEvtInit(&canp->cd_txempty_event); + chEvtInit(&canp->cd_error_event); + canp->cd_status = 0; #if CAN_USE_SLEEP_MODE chEvtInit(&canp->cd_sleep_event); chEvtInit(&canp->cd_wakeup_event); @@ -90,7 +92,8 @@ void canStop(CANDriver *canp) { "canStop(), #1", "invalid state"); can_lld_stop(canp); - canp->cd_state = CAN_STOP; + canp->cd_state = CAN_STOP; + canp->cd_status = 0; chSysUnlock(); } -- cgit v1.2.3 From c2ad39132395d52a3894c13f978da2349f650201 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 2 Dec 2009 16:24:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1370 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 7c6cdd656..e4258050e 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -69,12 +69,18 @@ void canStart(CANDriver *canp, const CANConfig *config) { chDbgCheck((canp != NULL) && (config != NULL), "canStart"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), + chDbgAssert((canp->cd_state == CAN_STOP) || + (canp->cd_state == CAN_STARTING) || + (canp->cd_state == CAN_READY), "canStart(), #1", "invalid state"); - canp->cd_config = config; - can_lld_start(canp); - canp->cd_state = CAN_READY; + while (canp->cd_state == CAN_STARTING) + chThdSleepS(1); + if (canp->cd_state == CAN_STOP) { + canp->cd_config = config; + can_lld_start(canp); + canp->cd_state = CAN_READY; + } chSysUnlock(); } @@ -145,12 +151,15 @@ msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { * @param[out] cfp pointer to the buffer where the CAN frame is copied * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_IMMEDIATE immediate timeout (useful in an + * event driven scenario where a thread never blocks + * for I/O). * - @a TIME_INFINITE no timeout. * . * @return The operation result. * @retval RDY_OK a frame has been received and placed in the buffer. - * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_TIMEOUT operation not finished within the specified time or + * frame not immediately available if invoked using @p TIME_IMMEDIATE. * @retval RDY_RESET driver stopped while waiting. */ msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { -- cgit v1.2.3 From 980f0b675138676b1e977ca456dc73c3b2502596 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 3 Dec 2009 16:26:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1373 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e4258050e..3cd10126d 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -110,7 +110,7 @@ void canStop(CANDriver *canp) { * @note Trying to transmit while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object - * @param[in] cfp pointer to the CAN frame to be transmitted + * @param[in] ctfp pointer to the CAN frame to be transmitted * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -121,25 +121,24 @@ void canStop(CANDriver *canp) { * @retval RDY_TIMEOUT operation not finished within the specified time. * @retval RDY_RESET driver stopped while waiting. */ -msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { - msg_t msg; +msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { - chDbgCheck((canp != NULL) && (cfp != NULL), "canTransmit"); + chDbgCheck((canp != NULL) && (ctfp != NULL), "canTransmit"); chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { - msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); + msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - msg = can_lld_transmit(canp, cfp); + can_lld_transmit(canp, ctfp); chSysUnlock(); - return msg; + return RDY_OK; } /** @@ -162,25 +161,24 @@ msg_t canTransmit(CANDriver *canp, const CANFrame *cfp, systime_t timeout) { * frame not immediately available if invoked using @p TIME_IMMEDIATE. * @retval RDY_RESET driver stopped while waiting. */ -msg_t canReceive(CANDriver *canp, CANFrame *cfp, systime_t timeout) { - msg_t msg; +msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { - chDbgCheck((canp != NULL) && (cfp != NULL), "canReceive"); + chDbgCheck((canp != NULL) && (crfp != NULL), "canReceive"); chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canReceive(), #1", "invalid state"); if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { - msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); + msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - msg = can_lld_receive(canp, cfp); + can_lld_receive(canp, crfp); chSysUnlock(); - return msg; + return RDY_OK; } /** -- cgit v1.2.3 From aa9f517f87125bbe7e9520c838627cde509ffa8c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Dec 2009 14:09:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1378 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 3cd10126d..7359e57b7 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -98,6 +98,9 @@ void canStop(CANDriver *canp) { "canStop(), #1", "invalid state"); can_lld_stop(canp); + chSemResetI(&canp->cd_rxsem, 0); + chSemResetI(&canp->cd_txsem, 0); + chSchRescheduleS(); canp->cd_state = CAN_STOP; canp->cd_status = 0; chSysUnlock(); @@ -129,7 +132,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); - if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); @@ -169,7 +172,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), "canReceive(), #1", "invalid state"); - if ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); -- cgit v1.2.3 From 0b8fd860fa71b35bfe0a242471d3bc4b56c93089 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 7 Dec 2009 16:13:01 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1381 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 os/hal/src/pwm.c (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c new file mode 100644 index 000000000..ef4260629 --- /dev/null +++ b/os/hal/src/pwm.c @@ -0,0 +1,150 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file PWM.c + * @brief PWM Driver code. + * @addtogroup PWM + * @{ + */ + +#include "ch.h" +#include "hal.h" + +/** + * @brief PWM Driver initialization. + */ +void pwmInit(void) { + + pwm_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p PWMDriver structure. + * + * @param[in] pwmp pointer to the @p PWMDriver object + */ +void pwmObjectInit(PWMDriver *pwmp) { + + pwmp->pd_state = PWM_STOP; + pwmp->pwm_config = NULL; +} + +/** + * @brief Configures and activates the PWM peripheral. + * + * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] config pointer to the @p PWMConfig object + */ +void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { + + chDbgCheck((pwmp != NULL) && (config != NULL), "pwmStart"); + + chSysLock(); + chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), + "pwmStart(), #1", + "invalid state"); + pwmp->pd_config = config; + pwm_lld_start(pwmp); + pwmp->pd_state = PWM_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the PWM peripheral. + * + * @param[in] pwmp pointer to the @p PWMDriver object + */ +void pwmStop(PWMDriver *pwmp) { + + chDbgCheck(pwmp != NULL, "pwmStop"); + + chSysLock(); + chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), + "pwmStop(), #1", + "invalid state"); + pwm_lld_stop(pwmp); + pwmp->pd_state = PWM_STOP; + chSysUnlock(); +} + +/** + * @brief Enables a callback mode for the specified PWM channel. + * @details The callback mode must be set before starting a PWM channel. + * + * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] channel PWM channel identifier + * @param[in] edge output edge mode + * @param[in] callback the callback function + */ +void pwmSetCallback(PWMDriver *pwmp, pwmchannel_t channel, + pwmedge_t edge, pwmcallback_t callback) { + + chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), + "pwmSetCallback"); + + chSysLock(); + chDbgAssert((pwmp->pd_state == PWM_READY) && + !pwm_lld_is_enabled(pwmp, channel), + "pwmSetCallback(), #1", "invalid state"); + pwm_lld_set_callback(pwmp, channel, edge, callback); + chSysUnlock(); +} + +/** + * @brief Enables a PWM channel. + * + * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] channel PWM channel identifier + * @param[in] width PWM pulse width as clock pulses number + */ +void pwmEnableChannel(PWMDriver *pwmp, + pwmchannel_t channel, + pwmcnt_t width) { + + chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), + "pwmEnableChannel"); + + chSysLock(); + chDbgAssert(pwmp->pd_state == PWM_READY, + "pwmEnableChannel(), #1", "invalid state"); + pwm_lld_enable_channel(pwmp, channel, width); + chSysUnlock(); +} + +/** + * @brief Disables a PWM channel. + * @details The channel output line is returned to its idle state and disabled. + * + * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] channel PWM channel identifier + */ +void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { + + chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), + "pwmEnableChannel"); + + chSysLock(); + chDbgAssert(pwmp->pd_state == PWM_READY, + "pwmDisableChannel(), #1", "invalid state"); + pwm_lld_disable_channel(pwmp, channel); + chSysUnlock(); +} + +/** @} */ -- cgit v1.2.3 From 3b4b79d9bbaa2985d24cb94fd9833dbdabbddd79 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 07:42:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1383 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ef4260629..f026a62ef 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -43,7 +43,7 @@ void pwmInit(void) { void pwmObjectInit(PWMDriver *pwmp) { pwmp->pd_state = PWM_STOP; - pwmp->pwm_config = NULL; + pwmp->pd_config = NULL; } /** @@ -130,7 +130,8 @@ void pwmEnableChannel(PWMDriver *pwmp, /** * @brief Disables a PWM channel. - * @details The channel output line is returned to its idle state and disabled. + * @details The channel is disabled and its output line returned to the + * idle state. * * @param[in] pwmp pointer to the @p PWMDriver object * @param[in] channel PWM channel identifier -- cgit v1.2.3 From 3ff9afd04851ec97d66d6833520b49dc18f35ea4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 08:47:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1389 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index f026a62ef..0e4062124 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -27,6 +27,8 @@ #include "ch.h" #include "hal.h" +#if CH_HAL_USE_PWM || defined(__DOXYGEN__) + /** * @brief PWM Driver initialization. */ @@ -148,4 +150,6 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysUnlock(); } +#endif /* CH_HAL_USE_PWM */ + /** @} */ -- cgit v1.2.3 From 4682a4476ec53884628b1a2b61457938f5914038 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 09:06:48 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1391 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 7359e57b7..e48095bc0 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -150,7 +150,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * @note Trying to receive while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object - * @param[out] cfp pointer to the buffer where the CAN frame is copied + * @param[out] crfp pointer to the buffer where the CAN frame is copied * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout (useful in an -- cgit v1.2.3 From bdb7f4ab20bd3daf261ab93dfe733e0ff11dca0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 17:37:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 53cfeb1f0..a0f91b8d2 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -19,7 +19,7 @@ /** * @file pal.c - * @brief I/O Ports Abstraction Layer code + * @brief I/O Ports Abstraction Layer code. * @addtogroup PAL * @{ */ -- cgit v1.2.3 From 6716159ba1186d9360d80b4b2313b3a047055295 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 13 Dec 2009 13:37:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1423 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 0e4062124..ddae89d45 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -40,7 +40,7 @@ void pwmInit(void) { /** * @brief Initializes the standard part of a @p PWMDriver structure. * - * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] pwmp pointer to a @p PWMDriver object */ void pwmObjectInit(PWMDriver *pwmp) { @@ -51,8 +51,8 @@ void pwmObjectInit(PWMDriver *pwmp) { /** * @brief Configures and activates the PWM peripheral. * - * @param[in] pwmp pointer to the @p PWMDriver object - * @param[in] config pointer to the @p PWMConfig object + * @param[in] pwmp pointer to a @p PWMDriver object + * @param[in] config pointer to a @p PWMConfig object */ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { @@ -71,7 +71,7 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { /** * @brief Deactivates the PWM peripheral. * - * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] pwmp pointer to a @p PWMDriver object */ void pwmStop(PWMDriver *pwmp) { @@ -87,32 +87,31 @@ void pwmStop(PWMDriver *pwmp) { } /** - * @brief Enables a callback mode for the specified PWM channel. - * @details The callback mode must be set before starting a PWM channel. + * @brief Setups a PWM channel. * - * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier - * @param[in] edge output edge mode - * @param[in] callback the callback function + * @param[in] pccp pointer to a @p PWMChannelConfig object */ -void pwmSetCallback(PWMDriver *pwmp, pwmchannel_t channel, - pwmedge_t edge, pwmcallback_t callback) { +void pwmSetupChannel(PWMDriver *pwmp, pwmchannel_t channel, + const PWMChannelConfig *pccp) { - chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), - "pwmSetCallback"); + chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS) && (pccp != NULL), + "pwmSetupChannel"); chSysLock(); chDbgAssert((pwmp->pd_state == PWM_READY) && !pwm_lld_is_enabled(pwmp, channel), - "pwmSetCallback(), #1", "invalid state"); - pwm_lld_set_callback(pwmp, channel, edge, callback); + "pwmSetupChannel(), #1", "invalid state"); + pwmp->pd_channel_configs[channel] = pccp; + pwm_lld_setup_channel(pwmp, channel); chSysUnlock(); } /** * @brief Enables a PWM channel. * - * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier * @param[in] width PWM pulse width as clock pulses number */ @@ -135,7 +134,7 @@ void pwmEnableChannel(PWMDriver *pwmp, * @details The channel is disabled and its output line returned to the * idle state. * - * @param[in] pwmp pointer to the @p PWMDriver object + * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier */ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { -- cgit v1.2.3 From 494cd0f0953d131bb31dcda508abfbd4eaef9899 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 16 Dec 2009 15:48:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1425 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ddae89d45..ad3c15728 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -88,6 +88,9 @@ void pwmStop(PWMDriver *pwmp) { /** * @brief Setups a PWM channel. + * @details Associates a configuration to a PWM channel, this operation is + * required before a channel can be enabled using + * @p pwmEnableChannel(). * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier @@ -123,7 +126,8 @@ void pwmEnableChannel(PWMDriver *pwmp, "pwmEnableChannel"); chSysLock(); - chDbgAssert(pwmp->pd_state == PWM_READY, + chDbgAssert((pwmp->pd_state == PWM_READY) && + (pwmp->pd_channel_configs[channel] != NULL), "pwmEnableChannel(), #1", "invalid state"); pwm_lld_enable_channel(pwmp, channel, width); chSysUnlock(); @@ -143,7 +147,8 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { "pwmEnableChannel"); chSysLock(); - chDbgAssert(pwmp->pd_state == PWM_READY, + chDbgAssert((pwmp->pd_state == PWM_READY) && + (pwmp->pd_channel_configs[channel] != NULL), "pwmDisableChannel(), #1", "invalid state"); pwm_lld_disable_channel(pwmp, channel); chSysUnlock(); -- cgit v1.2.3 From a8863f265d188eb769257788beba012f672c909d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 17 Dec 2009 15:40:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1426 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ad3c15728..f6164ea35 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -86,31 +86,6 @@ void pwmStop(PWMDriver *pwmp) { chSysUnlock(); } -/** - * @brief Setups a PWM channel. - * @details Associates a configuration to a PWM channel, this operation is - * required before a channel can be enabled using - * @p pwmEnableChannel(). - * - * @param[in] pwmp pointer to a @p PWMDriver object - * @param[in] channel PWM channel identifier - * @param[in] pccp pointer to a @p PWMChannelConfig object - */ -void pwmSetupChannel(PWMDriver *pwmp, pwmchannel_t channel, - const PWMChannelConfig *pccp) { - - chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS) && (pccp != NULL), - "pwmSetupChannel"); - - chSysLock(); - chDbgAssert((pwmp->pd_state == PWM_READY) && - !pwm_lld_is_enabled(pwmp, channel), - "pwmSetupChannel(), #1", "invalid state"); - pwmp->pd_channel_configs[channel] = pccp; - pwm_lld_setup_channel(pwmp, channel); - chSysUnlock(); -} - /** * @brief Enables a PWM channel. * @@ -126,8 +101,7 @@ void pwmEnableChannel(PWMDriver *pwmp, "pwmEnableChannel"); chSysLock(); - chDbgAssert((pwmp->pd_state == PWM_READY) && - (pwmp->pd_channel_configs[channel] != NULL), + chDbgAssert(pwmp->pd_state == PWM_READY, "pwmEnableChannel(), #1", "invalid state"); pwm_lld_enable_channel(pwmp, channel, width); chSysUnlock(); @@ -147,8 +121,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { "pwmEnableChannel"); chSysLock(); - chDbgAssert((pwmp->pd_state == PWM_READY) && - (pwmp->pd_channel_configs[channel] != NULL), + chDbgAssert(pwmp->pd_state == PWM_READY, "pwmDisableChannel(), #1", "invalid state"); pwm_lld_disable_channel(pwmp, channel); chSysUnlock(); -- cgit v1.2.3 From ebcb2909b26b261f99ea242629a36a888c53551c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Dec 2009 08:52:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1427 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 864789858..0f5bb9148 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -46,6 +46,9 @@ void halInit(void) { #if CH_HAL_USE_MAC macInit(); #endif +#if CH_HAL_USE_PWM + pwmInit(); +#endif #if CH_HAL_USE_SERIAL sdInit(); #endif -- cgit v1.2.3 From fe24da9fcca4967e58b25a2698c46717995de0ad Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Dec 2009 11:12:05 +0000 Subject: Reorganized sections in HAL files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1473 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 16 ++++++++++++++++ os/hal/src/can.c | 16 ++++++++++++++++ os/hal/src/hal.c | 16 ++++++++++++++++ os/hal/src/mac.c | 20 ++++++++++++++++++++ os/hal/src/mmc_spi.c | 8 ++++++++ os/hal/src/pal.c | 16 ++++++++++++++++ os/hal/src/pwm.c | 16 ++++++++++++++++ os/hal/src/serial.c | 16 ++++++++++++++++ os/hal/src/spi.c | 18 +++++++++++++++++- 9 files changed, 141 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index afa464212..16bdeac43 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_ADC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief ADC Driver initialization. */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e48095bc0..e70c25617 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_CAN || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief CAN Driver initialization. */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 0f5bb9148..3631028e5 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -27,6 +27,22 @@ #include "ch.h" #include "hal.h" +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief HAL initialization. */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index a18d3e4df..6d31c7b9e 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -29,6 +29,26 @@ #if CH_HAL_USE_MAC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief MAC Driver initialization. */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 24abf2a2b..f9f8eef5a 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -29,6 +29,14 @@ #if CH_HAL_USE_MMC_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index a0f91b8d2..a04f4ed96 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_PAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief Read from an I/O bus. * diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index f6164ea35..404f3d8a7 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_PWM || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief PWM Driver initialization. */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index d2cb17c77..5df69d1a0 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -29,6 +29,18 @@ #if CH_HAL_USE_SERIAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + /* * Interface implementation, the following functions just invoke the equivalent * queue-level function or macro. @@ -69,6 +81,10 @@ static const struct SerialDriverVMT vmt = { {} }; +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief Serial Driver initialization. */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 08113a000..36bde9a3a 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief SPI Driver initialization. */ @@ -255,7 +271,7 @@ void spiReleaseBus(SPIDriver *spip) { chSemSignal(&spip->spd_semaphore); #endif } -#endif /*SPI_USE_MUTUAL_EXCLUSION */ +#endif /* SPI_USE_MUTUAL_EXCLUSION */ #endif /* CH_HAL_USE_SPI */ -- cgit v1.2.3 From f8c40043e469d81f2a9f380d6723b92c79bd30bc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 1 Jan 2010 13:41:31 +0000 Subject: Serial driver enhancements for STM32 and AT91SAM7. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1485 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 99 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 34 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 5df69d1a0..4c2cb71c9 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -47,32 +47,32 @@ */ static bool_t putwouldblock(void *ip) { - return chOQIsFull(&((SerialDriver *)ip)->d2.oqueue); + return chOQIsFull(&((SerialDriver *)ip)->sd.oqueue); } static bool_t getwouldblock(void *ip) { - return chIQIsEmpty(&((SerialDriver *)ip)->d2.iqueue); + return chIQIsEmpty(&((SerialDriver *)ip)->sd.iqueue); } static msg_t put(void *ip, uint8_t b, systime_t timeout) { - return chOQPutTimeout(&((SerialDriver *)ip)->d2.oqueue, b, timeout); + return chOQPutTimeout(&((SerialDriver *)ip)->sd.oqueue, b, timeout); } static msg_t get(void *ip, systime_t timeout) { - return chIQGetTimeout(&((SerialDriver *)ip)->d2.iqueue, timeout); + return chIQGetTimeout(&((SerialDriver *)ip)->sd.iqueue, timeout); } static size_t write(void *ip, uint8_t *buffer, size_t n) { - return chOQWrite(&((SerialDriver *)ip)->d2.oqueue, buffer, n); + return chOQWrite(&((SerialDriver *)ip)->sd.oqueue, buffer, n); } static size_t read(void *ip, uint8_t *buffer, size_t n) { - return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n); + return chIQRead(&((SerialDriver *)ip)->sd.iqueue, buffer, n); } static const struct SerialDriverVMT vmt = { @@ -109,12 +109,13 @@ void sdInit(void) { void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; - chEvtInit(&sdp->d1.ievent); - chEvtInit(&sdp->d1.oevent); - chEvtInit(&sdp->d2.sevent); - sdp->d2.flags = SD_NO_ERROR; - chIQInit(&sdp->d2.iqueue, sdp->d2.ib, SERIAL_BUFFERS_SIZE, inotify); - chOQInit(&sdp->d2.oqueue, sdp->d2.ob, SERIAL_BUFFERS_SIZE, onotify); + chEvtInit(&sdp->bac.ievent); + chEvtInit(&sdp->bac.oevent); + chEvtInit(&sdp->sd.sevent); + sdp->sd.flags = SD_NO_ERROR; + chIQInit(&sdp->sd.iqueue, sdp->sd.ib, SERIAL_BUFFERS_SIZE, inotify); + chOQInit(&sdp->sd.oqueue, sdp->sd.ob, SERIAL_BUFFERS_SIZE, onotify); + sdp->sd.state = SD_STOP; } /** @@ -125,10 +126,17 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { * If this parameter is set to @p NULL then a default * configuration is used. */ -void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { +void sdStart(SerialDriver *sdp, const SerialConfig *config) { + + chDbgCheck((sdp != NULL) && (config != NULL), "sdStart"); chSysLock(); - sd_lld_start(sdp, config); + chDbgAssert((sdp->sd.state == SD_STOP) || (sdp->sd.state == SD_READY), + "sdStart(), #1", + "invalid state"); + sdp->sd.config = config; + sd_lld_start(sdp); + sdp->sd.state = SD_READY; chSysUnlock(); } @@ -141,10 +149,16 @@ void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { */ void sdStop(SerialDriver *sdp) { + chDbgCheck(sdp != NULL, "sdStop"); + chSysLock(); + chDbgAssert((sdp->sd.state == SD_STOP) || (sdp->sd.state == SD_READY), + "sdStop(), #1", + "invalid state"); sd_lld_stop(sdp); - chOQResetI(&sdp->d2.oqueue); - chIQResetI(&sdp->d2.iqueue); + sdp->sd.state = SD_STOP; + chOQResetI(&sdp->sd.oqueue); + chIQResetI(&sdp->sd.iqueue); chSchRescheduleS(); chSysUnlock(); } @@ -154,32 +168,45 @@ void sdStop(SerialDriver *sdp) { * @details This function must be called from the input interrupt service * routine in order to enqueue incoming data and generate the * related events. - * @param[in] sd pointer to a @p SerialDriver structure + * @note The incoming data event is only generated when the input queue + * becomes non-empty. + * @note In order to gain some performance it is suggested to not use + * this function directly but copy this code directly into the + * interrupt service routine. + * + * @param[in] sdp pointer to a @p SerialDriver structure * @param[in] b the byte to be written in the driver's Input Queue */ -void sdIncomingDataI(SerialDriver *sd, uint8_t b) { +void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { + + chDbgCheck(sdp != NULL, "sdIncomingDataI"); - if (chIQPutI(&sd->d2.iqueue, b) < Q_OK) - sdAddFlagsI(sd, SD_OVERRUN_ERROR); - else - chEvtBroadcastI(&sd->d1.ievent); + if (chIQIsEmpty(&sdp->sd.iqueue)) + chEvtBroadcastI(&sdp->bac.ievent); + if (chIQPutI(&sdp->sd.iqueue, b) < Q_OK) + sdAddFlagsI(sdp, SD_OVERRUN_ERROR); } /** * @brief Handles outgoing data. * @details Must be called from the output interrupt service routine in order * to get the next byte to be transmitted. + * @note In order to gain some performance it is suggested to not use + * this function directly but copy this code directly into the + * interrupt service routine. * - * @param[in] sd pointer to a @p SerialDriver structure + * @param[in] sdp pointer to a @p SerialDriver structure * @return The byte value read from the driver's output queue. * @retval Q_EMPTY if the queue is empty (the lower driver usually disables * the interrupt source when this happens). */ -msg_t sdRequestDataI(SerialDriver *sd) { +msg_t sdRequestDataI(SerialDriver *sdp) { - msg_t b = chOQGetI(&sd->d2.oqueue); + chDbgCheck(sdp != NULL, "sdRequestDataI"); + + msg_t b = chOQGetI(&sdp->sd.oqueue); if (b < Q_OK) - chEvtBroadcastI(&sd->d1.oevent); + chEvtBroadcastI(&sdp->bac.oevent); return b; } @@ -188,27 +215,31 @@ msg_t sdRequestDataI(SerialDriver *sd) { * @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] sd pointer to a @p SerialDriver structure + * @param[in] sdp pointer to a @p SerialDriver structure * @param[in] mask condition flags to be added to the mask */ -void sdAddFlagsI(SerialDriver *sd, sdflags_t mask) { +void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { + + chDbgCheck(sdp != NULL, "sdAddFlagsI"); - sd->d2.flags |= mask; - chEvtBroadcastI(&sd->d2.sevent); + sdp->sd.flags |= mask; + chEvtBroadcastI(&sdp->sd.sevent); } /** * @brief Returns and clears the errors mask associated to the driver. * - * @param[in] sd pointer to a @p SerialDriver structure + * @param[in] sdp pointer to a @p SerialDriver structure * @return The condition flags modified since last time this function was * invoked. */ -sdflags_t sdGetAndClearFlags(SerialDriver *sd) { +sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { sdflags_t mask; - mask = sd->d2.flags; - sd->d2.flags = SD_NO_ERROR; + chDbgCheck(sdp != NULL, "sdGetAndClearFlags"); + + mask = sdp->sd.flags; + sdp->sd.flags = SD_NO_ERROR; return mask; } -- cgit v1.2.3 From 855fe2391d07c5dab27129ad626541482fe8d782 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 5 Jan 2010 17:14:09 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1501 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 4c2cb71c9..54db8e95d 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -45,6 +45,19 @@ * Interface implementation, the following functions just invoke the equivalent * queue-level function or macro. */ + +static size_t writes(void *ip, const uint8_t *bp, size_t n) { + + return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp, + n, TIME_INFINITE); +} + +static size_t reads(void *ip, uint8_t *bp, size_t n) { + + return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp, + n, TIME_INFINITE); +} + static bool_t putwouldblock(void *ip) { return chOQIsFull(&((SerialDriver *)ip)->sd.oqueue); @@ -55,29 +68,29 @@ static bool_t getwouldblock(void *ip) { return chIQIsEmpty(&((SerialDriver *)ip)->sd.iqueue); } -static msg_t put(void *ip, uint8_t b, systime_t timeout) { +static msg_t putt(void *ip, uint8_t b, systime_t timeout) { return chOQPutTimeout(&((SerialDriver *)ip)->sd.oqueue, b, timeout); } -static msg_t get(void *ip, systime_t timeout) { +static msg_t gett(void *ip, systime_t timeout) { return chIQGetTimeout(&((SerialDriver *)ip)->sd.iqueue, timeout); } -static size_t write(void *ip, uint8_t *buffer, size_t n) { +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { - return chOQWrite(&((SerialDriver *)ip)->sd.oqueue, buffer, n); + return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp, n, time); } -static size_t read(void *ip, uint8_t *buffer, size_t n) { +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { - return chIQRead(&((SerialDriver *)ip)->sd.iqueue, buffer, n); + return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp, n, time); } static const struct SerialDriverVMT vmt = { - {putwouldblock, getwouldblock, put, get}, - {write, read}, + {writes, reads}, + {putwouldblock, getwouldblock, putt, gett, writet, readt}, {} }; @@ -112,10 +125,10 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { chEvtInit(&sdp->bac.ievent); chEvtInit(&sdp->bac.oevent); chEvtInit(&sdp->sd.sevent); + sdp->sd.state = SD_STOP; sdp->sd.flags = SD_NO_ERROR; chIQInit(&sdp->sd.iqueue, sdp->sd.ib, SERIAL_BUFFERS_SIZE, inotify); chOQInit(&sdp->sd.oqueue, sdp->sd.ob, SERIAL_BUFFERS_SIZE, onotify); - sdp->sd.state = SD_STOP; } /** -- cgit v1.2.3 From eb9546632062a0a4747721869674922e2b6902af Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 15 Jan 2010 15:22:36 +0000 Subject: Fixed bug 2932922. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1513 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 54db8e95d..1372d5acc 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -141,7 +141,7 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { */ void sdStart(SerialDriver *sdp, const SerialConfig *config) { - chDbgCheck((sdp != NULL) && (config != NULL), "sdStart"); + chDbgCheck(sdp != NULL, "sdStart"); chSysLock(); chDbgAssert((sdp->sd.state == SD_STOP) || (sdp->sd.state == SD_READY), @@ -251,8 +251,10 @@ sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { chDbgCheck(sdp != NULL, "sdGetAndClearFlags"); + chSysLock(); mask = sdp->sd.flags; sdp->sd.flags = SD_NO_ERROR; + chSysUnlock(); return mask; } -- cgit v1.2.3 From 11215c3bcb0b0cbe5794cfc92d0c20de6c8696d9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Jan 2010 14:51:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1539 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 1372d5acc..49355ec33 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -48,50 +48,48 @@ static size_t writes(void *ip, const uint8_t *bp, size_t n) { - return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp, + return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, TIME_INFINITE); } static size_t reads(void *ip, uint8_t *bp, size_t n) { - return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp, + return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, TIME_INFINITE); } static bool_t putwouldblock(void *ip) { - return chOQIsFull(&((SerialDriver *)ip)->sd.oqueue); + return chOQIsFull(&((SerialDriver *)ip)->oqueue); } static bool_t getwouldblock(void *ip) { - return chIQIsEmpty(&((SerialDriver *)ip)->sd.iqueue); + return chIQIsEmpty(&((SerialDriver *)ip)->iqueue); } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { - return chOQPutTimeout(&((SerialDriver *)ip)->sd.oqueue, b, timeout); + return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, timeout); } static msg_t gett(void *ip, systime_t timeout) { - return chIQGetTimeout(&((SerialDriver *)ip)->sd.iqueue, timeout); + return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, timeout); } static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { - return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp, n, time); + return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, time); } static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { - return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp, n, time); + return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); } static const struct SerialDriverVMT vmt = { - {writes, reads}, - {putwouldblock, getwouldblock, putt, gett, writet, readt}, - {} + writes, reads, putwouldblock, getwouldblock, putt, gett, writet, readt }; /*===========================================================================*/ @@ -122,13 +120,13 @@ void sdInit(void) { void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; - chEvtInit(&sdp->bac.ievent); - chEvtInit(&sdp->bac.oevent); - chEvtInit(&sdp->sd.sevent); - sdp->sd.state = SD_STOP; - sdp->sd.flags = SD_NO_ERROR; - chIQInit(&sdp->sd.iqueue, sdp->sd.ib, SERIAL_BUFFERS_SIZE, inotify); - chOQInit(&sdp->sd.oqueue, sdp->sd.ob, SERIAL_BUFFERS_SIZE, onotify); + chEvtInit(&sdp->ievent); + chEvtInit(&sdp->oevent); + chEvtInit(&sdp->sevent); + sdp->state = SD_STOP; + sdp->flags = SD_NO_ERROR; + chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify); + chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify); } /** @@ -144,12 +142,12 @@ void sdStart(SerialDriver *sdp, const SerialConfig *config) { chDbgCheck(sdp != NULL, "sdStart"); chSysLock(); - chDbgAssert((sdp->sd.state == SD_STOP) || (sdp->sd.state == SD_READY), + chDbgAssert((sdp->state == SD_STOP) || (sdp->state == SD_READY), "sdStart(), #1", "invalid state"); - sdp->sd.config = config; + sdp->config = config; sd_lld_start(sdp); - sdp->sd.state = SD_READY; + sdp->state = SD_READY; chSysUnlock(); } @@ -165,13 +163,13 @@ void sdStop(SerialDriver *sdp) { chDbgCheck(sdp != NULL, "sdStop"); chSysLock(); - chDbgAssert((sdp->sd.state == SD_STOP) || (sdp->sd.state == SD_READY), + chDbgAssert((sdp->state == SD_STOP) || (sdp->state == SD_READY), "sdStop(), #1", "invalid state"); sd_lld_stop(sdp); - sdp->sd.state = SD_STOP; - chOQResetI(&sdp->sd.oqueue); - chIQResetI(&sdp->sd.iqueue); + sdp->state = SD_STOP; + chOQResetI(&sdp->oqueue); + chIQResetI(&sdp->iqueue); chSchRescheduleS(); chSysUnlock(); } @@ -194,9 +192,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { chDbgCheck(sdp != NULL, "sdIncomingDataI"); - if (chIQIsEmpty(&sdp->sd.iqueue)) - chEvtBroadcastI(&sdp->bac.ievent); - if (chIQPutI(&sdp->sd.iqueue, b) < Q_OK) + if (chIQIsEmpty(&sdp->iqueue)) + chEvtBroadcastI(&sdp->ievent); + if (chIQPutI(&sdp->iqueue, b) < Q_OK) sdAddFlagsI(sdp, SD_OVERRUN_ERROR); } @@ -217,9 +215,9 @@ msg_t sdRequestDataI(SerialDriver *sdp) { chDbgCheck(sdp != NULL, "sdRequestDataI"); - msg_t b = chOQGetI(&sdp->sd.oqueue); + msg_t b = chOQGetI(&sdp->oqueue); if (b < Q_OK) - chEvtBroadcastI(&sdp->bac.oevent); + chEvtBroadcastI(&sdp->oevent); return b; } @@ -235,8 +233,8 @@ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { chDbgCheck(sdp != NULL, "sdAddFlagsI"); - sdp->sd.flags |= mask; - chEvtBroadcastI(&sdp->sd.sevent); + sdp->flags |= mask; + chEvtBroadcastI(&sdp->sevent); } /** @@ -252,8 +250,8 @@ sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { chDbgCheck(sdp != NULL, "sdGetAndClearFlags"); chSysLock(); - mask = sdp->sd.flags; - sdp->sd.flags = SD_NO_ERROR; + mask = sdp->flags; + sdp->flags = SD_NO_ERROR; chSysUnlock(); return mask; } -- cgit v1.2.3 From a66602c99d316ecfb03e47dcf9b3fe4167edc580 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 25 Jan 2010 18:50:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1545 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 49355ec33..9b5219fca 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -43,7 +43,7 @@ /* * Interface implementation, the following functions just invoke the equivalent - * queue-level function or macro. + * queue-level function or macro. */ static size_t writes(void *ip, const uint8_t *bp, size_t n) { @@ -97,7 +97,7 @@ static const struct SerialDriverVMT vmt = { /*===========================================================================*/ /** - * @brief Serial Driver initialization. + * @brief Serial Driver initialization. */ void sdInit(void) { @@ -212,10 +212,11 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { * the interrupt source when this happens). */ msg_t sdRequestDataI(SerialDriver *sdp) { + msg_t b; chDbgCheck(sdp != NULL, "sdRequestDataI"); - msg_t b = chOQGetI(&sdp->oqueue); + b = chOQGetI(&sdp->oqueue); if (b < Q_OK) chEvtBroadcastI(&sdp->oevent); return b; -- cgit v1.2.3 From e3c7dc319ff582f9eb4a593950ac7bedb1d38b77 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 16:17:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1571 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 38 +++++++++++----------- os/hal/src/can.c | 53 ++++++++++++++++--------------- os/hal/src/hal.c | 7 +++-- os/hal/src/mac.c | 89 ++++++++++++++++++++++++++-------------------------- os/hal/src/mmc_spi.c | 81 +++++++++++++++++++++++------------------------ os/hal/src/pal.c | 68 ++++++++++++++++++++------------------- os/hal/src/pwm.c | 14 ++++----- os/hal/src/serial.c | 83 ++++++++++++++++++++++++------------------------ os/hal/src/spi.c | 51 ++++++++++++++---------------- 9 files changed, 242 insertions(+), 242 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 16bdeac43..dff7d828b 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -18,8 +18,9 @@ */ /** - * @file adc.c - * @brief ADC Driver code. + * @file adc.c + * @brief ADC Driver code. + * * @addtogroup ADC * @{ */ @@ -46,7 +47,7 @@ /*===========================================================================*/ /** - * @brief ADC Driver initialization. + * @brief ADC Driver initialization. */ void adcInit(void) { @@ -54,7 +55,7 @@ void adcInit(void) { } /** - * @brief Initializes the standard part of a @p ADCDriver structure. + * @brief Initializes the standard part of a @p ADCDriver structure. * * @param[in] adcp pointer to the @p ADCDriver object */ @@ -70,7 +71,7 @@ void adcObjectInit(ADCDriver *adcp) { } /** - * @brief Configures and activates the ADC peripheral. + * @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 @@ -90,7 +91,7 @@ void adcStart(ADCDriver *adcp, const ADCConfig *config) { } /** - * @brief Deactivates the ADC peripheral. + * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object */ @@ -108,7 +109,7 @@ void adcStop(ADCDriver *adcp) { } /** - * @brief Starts an ADC conversion. + * @brief Starts an ADC conversion. * @details Starts a conversion operation, there are two kind of conversion * modes: * - LINEAR, this mode is activated when the @p callback @@ -122,6 +123,10 @@ void adcStop(ADCDriver *adcp) { * time. This kind of conversion can only be stopped by explicitly * invoking @p adcStopConversion(). * . + * @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 @@ -129,14 +134,9 @@ void adcStop(ADCDriver *adcp) { * @param[in] depth buffer depth (matrix rows number). The buffer depth * must be one or an even number. * @param[in] callback pointer to the conversion callback function - * @return The operation status. + * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. - * - * @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. */ bool_t adcStartConversion(ADCDriver *adcp, const ADCConversionGroup *grpp, @@ -169,9 +169,9 @@ bool_t adcStartConversion(ADCDriver *adcp, } /** - * @brief Stops an ongoing conversion. + * @brief Stops an ongoing conversion. * - * @param[in] adcp pointer to the @p ADCDriver object + * @param[in] adcp pointer to the @p ADCDriver object */ void adcStopConversion(ADCDriver *adcp) { @@ -196,7 +196,7 @@ void adcStopConversion(ADCDriver *adcp) { } /** - * @brief Waits for completion. + * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the * invoking thread waits for a conversion completion event. * @@ -206,9 +206,9 @@ void adcStopConversion(ADCDriver *adcp) { * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . - * @return The operation result. - * @retval RDY_OK conversion finished. - * @retval RDY_TIMEOUT conversion not finished within the specified time. + * @return The operation result. + * @retval RDY_OK conversion finished. + * @retval RDY_TIMEOUT conversion not finished within the specified time. */ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e70c25617..a4da35b8e 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -18,8 +18,9 @@ */ /** - * @file CAN.c - * @brief CAN Driver code. + * @file can.c + * @brief CAN Driver code. + * * @addtogroup CAN * @{ */ @@ -46,7 +47,7 @@ /*===========================================================================*/ /** - * @brief CAN Driver initialization. + * @brief CAN Driver initialization. */ void canInit(void) { @@ -54,7 +55,7 @@ void canInit(void) { } /** - * @brief Initializes the standard part of a @p CANDriver structure. + * @brief Initializes the standard part of a @p CANDriver structure. * * @param[in] canp pointer to the @p CANDriver object */ @@ -75,7 +76,7 @@ void canObjectInit(CANDriver *canp) { } /** - * @brief Configures and activates the CAN peripheral. + * @brief Configures and activates the CAN peripheral. * * @param[in] canp pointer to the @p CANDriver object * @param[in] config pointer to the @p CANConfig object @@ -101,7 +102,7 @@ void canStart(CANDriver *canp, const CANConfig *config) { } /** - * @brief Deactivates the CAN peripheral. + * @brief Deactivates the CAN peripheral. * * @param[in] canp pointer to the @p CANDriver object */ @@ -123,10 +124,10 @@ void canStop(CANDriver *canp) { } /** - * @brief Can frame transmission. + * @brief Can frame transmission. * @details The specified frame is queued for transmission, if the hardware * queue is full then the invoking thread is queued. - * @note Trying to transmit while in sleep mode simply enqueues the thread. + * @note Trying to transmit while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object * @param[in] ctfp pointer to the CAN frame to be transmitted @@ -135,10 +136,10 @@ void canStop(CANDriver *canp) { * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . - * @return The operation result. - * @retval RDY_OK the frame has been queued for transmission. - * @retval RDY_TIMEOUT operation not finished within the specified time. - * @retval RDY_RESET driver stopped while waiting. + * @return The operation result. + * @retval RDY_OK the frame has been queued for transmission. + * @retval RDY_TIMEOUT operation not finished within the specified time. + * @retval RDY_RESET driver stopped while waiting. */ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { @@ -161,9 +162,9 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { } /** - * @brief Can frame receive. + * @brief Can frame receive. * @details The function waits until a frame is received. - * @note Trying to receive while in sleep mode simply enqueues the thread. + * @note Trying to receive while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object * @param[out] crfp pointer to the buffer where the CAN frame is copied @@ -174,11 +175,12 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * for I/O). * - @a TIME_INFINITE no timeout. * . - * @return The operation result. - * @retval RDY_OK a frame has been received and placed in the buffer. - * @retval RDY_TIMEOUT operation not finished within the specified time or - * frame not immediately available if invoked using @p TIME_IMMEDIATE. - * @retval RDY_RESET driver stopped while waiting. + * @return The operation result. + * @retval RDY_OK a frame has been received and placed in the buffer. + * @retval RDY_TIMEOUT operation not finished within the specified time or + * frame not immediately available if invoked using + * @p TIME_IMMEDIATE. + * @retval RDY_RESET driver stopped while waiting. */ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { @@ -201,11 +203,10 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { } /** - * @brief Returns the current status mask and clears it. + * @brief Returns the current status mask and clears it. * * @param[in] canp pointer to the @p CANDriver object - * - * @return The status flags mask. + * @return The status flags mask. */ canstatus_t canGetAndClearFlags(CANDriver *canp) { canstatus_t status; @@ -219,7 +220,7 @@ canstatus_t canGetAndClearFlags(CANDriver *canp) { #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** - * @brief Enters the sleep mode. + * @brief Enters the sleep mode. * * @param[in] canp pointer to the @p CANDriver object */ @@ -241,9 +242,9 @@ void canSleep(CANDriver *canp) { } /** - * @brief Enforces leaving the sleep mode. - * @note The sleep mode is supposed to be usually exited automatically by an - * hardware event. + * @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 */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 3631028e5..f93f036c6 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -18,8 +18,9 @@ */ /** - * @file hal.c - * @brief HAL subsystem code. + * @file hal.c + * @brief HAL subsystem code. + * * @addtogroup HAL * @{ */ @@ -44,7 +45,7 @@ /*===========================================================================*/ /** - * @brief HAL initialization. + * @brief HAL initialization. */ void halInit(void) { diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 6d31c7b9e..74e08bdf4 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -18,8 +18,9 @@ */ /** - * @file mac.c - * @brief MAC Driver code. + * @file mac.c + * @brief MAC Driver code. + * * @addtogroup MAC * @{ */ @@ -50,7 +51,7 @@ /*===========================================================================*/ /** - * @brief MAC Driver initialization. + * @brief MAC Driver initialization. */ void macInit(void) { @@ -58,9 +59,9 @@ void macInit(void) { } /** - * @brief Initialize the standard part of a @p MACDriver structure. + * @brief Initialize the standard part of a @p MACDriver structure. * - * @param[in] macp pointer to the @p MACDriver object + * @param[in] macp pointer to the @p MACDriver object */ void macObjectInit(MACDriver *macp) { @@ -72,15 +73,15 @@ void macObjectInit(MACDriver *macp) { } /** - * @brief MAC address setup. + * @brief MAC address setup. + * @note This function must be invoked only with the driver in the stopped + * state. If invoked on an active interface then it is ignored. * - * @param[in] macp pointer to the @p MACDriver object - * @param[in] p pointer to a six bytes buffer containing the MAC address. If - * this parameter is set to @p NULL then a system default MAC is - * used. + * @param[in] macp pointer to the @p MACDriver object + * @param[in] p pointer to a six bytes buffer containing the MAC + * address. If this parameter is set to @p NULL then MAC + * a system default is used. * - * @note This function must be invoked only with the driver in the stopped - * state. If invoked on an active interface then it is ignored. */ void macSetAddress(MACDriver *macp, const uint8_t *p) { @@ -88,21 +89,21 @@ void macSetAddress(MACDriver *macp, const uint8_t *p) { } /** - * @brief Allocates a transmission descriptor. + * @brief Allocates a transmission descriptor. * @details One of the available transmission descriptors is locked and * returned. If a descriptor is not currently available then the * invoking thread is queued until one is freed. * - * @param[in] macp pointer to the @p MACDriver object - * @param[out] tdp pointer to a @p MACTransmitDescriptor structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK the descriptor was obtained. - * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + * @param[in] macp pointer to the @p MACDriver object + * @param[out] tdp pointer to a @p MACTransmitDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. */ msg_t macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, @@ -123,10 +124,10 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, } /** - * @brief Releases a transmit descriptor and starts the transmission of the - * enqueued data as a single frame. + * @brief Releases a transmit descriptor and starts the transmission of the + * enqueued data as a single frame. * - * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure + * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure */ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { @@ -134,21 +135,21 @@ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { } /** - * @brief Waits for a received frame. + * @brief Waits for a received frame. * @details Stops until a frame is received and buffered. If a frame is * not immediately available then the invoking thread is queued * until one is received. * - * @param[in] macp pointer to the @p MACDriver object - * @param[out] rdp pointer to a @p MACReceiveDescriptor structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK the descriptor was obtained. - * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + * @param[in] macp pointer to the @p MACDriver object + * @param[out] rdp pointer to a @p MACReceiveDescriptor structure + * @param[in] time the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The operation status. + * @retval RDY_OK the descriptor was obtained. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. */ msg_t macWaitReceiveDescriptor(MACDriver *macp, MACReceiveDescriptor *rdp, @@ -169,11 +170,11 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, } /** - * @brief Releases a receive descriptor. + * @brief Releases a receive descriptor. * @details The descriptor and its buffer are made available for more incoming * frames. * - * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure + * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure */ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { @@ -181,12 +182,12 @@ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { } /** - * @brief Updates and returns the link status. + * @brief Updates and returns the link status. * - * @param[in] macp pointer to the @p MACDriver object - * @return The link status. - * @retval TRUE if the link is active. - * @retval FALSE if the link is down. + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. */ bool_t macPollLinkStatus(MACDriver *macp) { diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index f9f8eef5a..c1cb313ec 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -18,8 +18,9 @@ */ /** - * @file mmc_spi.c - * @brief MMC over SPI driver code. + * @file mmc_spi.c + * @brief MMC over SPI driver code. + * * @addtogroup MMC_SPI * @{ */ @@ -41,6 +42,11 @@ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Inserion monitor timer callback function. + * + * @param[in] p pointer to the @p MMCDriver object + */ void tmrfunc(void *p) { MMCDriver *mmcp = p; @@ -65,7 +71,7 @@ void tmrfunc(void *p) { } /** - * @brief Waits an idle condition. + * @brief Waits an idle condition. * * @param[in] mmcp pointer to the @p MMCDriver object */ @@ -91,7 +97,7 @@ static void wait(MMCDriver *mmcp) { } /** - * @brief Sends a command header. + * @brief Sends a command header. * * @param[in] mmcp pointer to the @p MMCDriver object * @param cmd[in] the command id @@ -113,11 +119,10 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { } /** - * @brief Receives a single byte response. + * @brief Receives a single byte response. * * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The response as an @p uint8_t value. + * @return The response as an @p uint8_t value. * @retval 0xFF timed out. */ static uint8_t recvr1(MMCDriver *mmcp) { @@ -133,13 +138,12 @@ static uint8_t recvr1(MMCDriver *mmcp) { } /** - * @brief Sends a command an returns a single byte response. + * @brief Sends a command an returns a single byte response. * * @param[in] mmcp pointer to the @p MMCDriver object * @param cmd[in] the command id * @param arg[in] the command argument - * - * @return The response as an @p uint8_t value. + * @return The response as an @p uint8_t value. * @retval 0xFF timed out. */ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { @@ -153,7 +157,7 @@ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { } /** - * @brief Waits that the card reaches an idle state. + * @brief Waits that the card reaches an idle state. * * @param[in] mmcp pointer to the @p MMCDriver object */ @@ -177,14 +181,14 @@ static void sync(MMCDriver *mmcp) { /*===========================================================================*/ /** - * @brief MMC over SPI driver initialization. + * @brief MMC over SPI driver initialization. */ void mmcInit(void) { } /** - * @brief Initializes an instance. + * @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 @@ -211,7 +215,7 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, } /** - * @brief Configures and activates the MMC peripheral. + * @brief Configures and activates the MMC peripheral. * * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] config pointer to the @p MMCConfig object @@ -230,7 +234,7 @@ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { } /** - * @brief Disables the MMC peripheral. + * @brief Disables the MMC peripheral. * * @param[in] mmcp pointer to the @p MMCDriver object */ @@ -253,16 +257,15 @@ void mmcStop(MMCDriver *mmcp) { } /** - * @brief Performs the initialization procedure on the inserted card. + * @brief Performs the initialization procedure on the inserted card. * @details This function should be invoked when a card is inserted and * brings the driver in the @p MMC_READY state where it is possible * to perform read and write operations. - * @note It is possible to invoke this function from the insertion event - * handler. + * @note It is possible to invoke this function from the insertion event + * handler. * * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful and the driver is now * in the @p MMC_READY state. * @retval TRUE the operation failed. @@ -331,10 +334,10 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /** - * @brief Brings the driver in a state safe for card removal. + * @brief Brings the driver in a state safe for card removal. * * @param[in] mmcp pointer to the @p MMCDriver object - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful and the driver is now * in the @p MMC_INSERTED state. * @retval TRUE the operation failed. @@ -363,12 +366,11 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { } /** - * @brief Starts a sequential read. + * @brief Starts a sequential read. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] startblk first block to read - * - * @return The operation status. + * @param[in] startblk first block to read + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ @@ -398,12 +400,11 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { } /** - * @brief Reads a block within a sequential read operation. + * @brief Reads a block within a sequential read operation. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param[out] buffer pointer to the read buffer - * - * @return The operation status. + * @param[out] buffer pointer to the read buffer + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ @@ -438,11 +439,10 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { } /** - * @brief Stops a sequential read gracefully. + * @brief Stops a sequential read gracefully. * * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ @@ -471,12 +471,11 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { } /** - * @brief Starts a sequential write. + * @brief Starts a sequential write. * * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] startblk first block to write - * - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ @@ -506,12 +505,11 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { } /** - * @brief Writes a block within a sequential write operation. + * @brief Writes a block within a sequential write operation. * * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the write buffer - * - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ @@ -545,11 +543,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { } /** - * @brief Stops a sequential write gracefully. + * @brief Stops a sequential write gracefully. * * @param[in] mmcp pointer to the @p MMCDriver object - * - * @return The operation status. + * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index a04f4ed96..cc898d2fd 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -18,8 +18,9 @@ */ /** - * @file pal.c - * @brief I/O Ports Abstraction Layer code. + * @file pal.c + * @brief I/O Ports Abstraction Layer code. + * * @addtogroup PAL * @{ */ @@ -46,17 +47,17 @@ /*===========================================================================*/ /** - * @brief Read from an I/O bus. - * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @return The bus logical states. + * @brief Read from an I/O bus. + * @note The operation is not guaranteed to be atomic on all the + * architectures, for atomicity and/or portability reasons you may + * need to enclose port I/O operations between @p chSysLock() and + * @p chSysUnlock(). + * @note The function internally uses the @p palReadGroup() macro. The use + * of this function is preferred when you value code size, readability + * and error checking over speed. * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The function internally uses the @p palReadGroup() macro. The use of - * this function is preferred when you value code size, readability and - * error checking over speed. + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @return The bus logical states. */ ioportmask_t palReadBus(IOBus *bus) { @@ -67,18 +68,19 @@ ioportmask_t palReadBus(IOBus *bus) { } /** - * @brief Write to an I/O bus. + * @brief Write to an I/O bus. + * @note The operation is not guaranteed to be atomic on all the + * architectures, for atomicity and/or portability reasons you may + * need to enclose port I/O operations between @p chSysLock() and + * @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @param[in] bits the bits to be written on the I/O bus. Values exceeding - * the bus width are masked so most significant bits are lost. - * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] bits the bits to be written on the I/O bus. Values exceeding + * the bus width are masked so most significant bits are + * lost. */ void palWriteBus(IOBus *bus, ioportmask_t bits) { @@ -89,17 +91,17 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { } /** - * @brief Programs a bus with the specified mode. + * @brief Programs a bus with the specified mode. + * @note The operation is not guaranteed to be atomic on all the + * architectures, for atomicity and/or portability reasons you may + * need to enclose port I/O operations between @p chSysLock() and + * @p chSysUnlock(). + * @note The default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. * - * @param[in] bus the I/O bus, pointer to a @p IOBus structure - * @param[in] mode the mode - * - * @note The operation is not guaranteed to be atomic on all the architectures, - * for atomicity and/or portability reasons you may need to enclose port - * I/O operations between @p chSysLock() and @p chSysUnlock(). - * @note The default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. + * @param[in] bus the I/O bus, pointer to a @p IOBus structure + * @param[in] mode the mode */ void palSetBusMode(IOBus *bus, uint_fast8_t mode) { diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 404f3d8a7..ddfb6dd83 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -18,8 +18,8 @@ */ /** - * @file PWM.c - * @brief PWM Driver code. + * @file pwm.c + * @brief PWM Driver code. * @addtogroup PWM * @{ */ @@ -46,7 +46,7 @@ /*===========================================================================*/ /** - * @brief PWM Driver initialization. + * @brief PWM Driver initialization. */ void pwmInit(void) { @@ -54,7 +54,7 @@ void pwmInit(void) { } /** - * @brief Initializes the standard part of a @p PWMDriver structure. + * @brief Initializes the standard part of a @p PWMDriver structure. * * @param[in] pwmp pointer to a @p PWMDriver object */ @@ -65,7 +65,7 @@ void pwmObjectInit(PWMDriver *pwmp) { } /** - * @brief Configures and activates the PWM peripheral. + * @brief Configures and activates the PWM peripheral. * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] config pointer to a @p PWMConfig object @@ -85,7 +85,7 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { } /** - * @brief Deactivates the PWM peripheral. + * @brief Deactivates the PWM peripheral. * * @param[in] pwmp pointer to a @p PWMDriver object */ @@ -103,7 +103,7 @@ void pwmStop(PWMDriver *pwmp) { } /** - * @brief Enables a PWM channel. + * @brief Enables a PWM channel. * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 9b5219fca..851f16ffb 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -18,8 +18,9 @@ */ /** - * @file serial.c - * @brief Serial Driver code. + * @file serial.c + * @brief Serial Driver code. + * * @addtogroup SERIAL * @{ */ @@ -97,7 +98,7 @@ static const struct SerialDriverVMT vmt = { /*===========================================================================*/ /** - * @brief Serial Driver initialization. + * @brief Serial Driver initialization. */ void sdInit(void) { @@ -105,17 +106,17 @@ void sdInit(void) { } /** - * @brief Initializes a generic full duplex driver object. + * @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. + * @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. */ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { @@ -130,12 +131,12 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { } /** - * @brief Configures and starts the driver. + * @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. + * @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. */ void sdStart(SerialDriver *sdp, const SerialConfig *config) { @@ -152,11 +153,11 @@ void sdStart(SerialDriver *sdp, const SerialConfig *config) { } /** - * @brief Stops the driver. + * @brief Stops the driver. * @details Any thread waiting on the driver's queues will be awakened with * the message @p Q_RESET. * - * @param[in] sdp pointer to a @p SerialDrive object + * @param[in] sdp pointer to a @p SerialDrive object */ void sdStop(SerialDriver *sdp) { @@ -175,18 +176,18 @@ void sdStop(SerialDriver *sdp) { } /** - * @brief Handles incoming data. + * @brief Handles incoming data. * @details This function must be called from the input interrupt service * routine in order to enqueue incoming data and generate the * related events. - * @note The incoming data event is only generated when the input queue - * becomes non-empty. - * @note In order to gain some performance it is suggested to not use - * this function directly but copy this code directly into the - * interrupt service routine. + * @note The incoming data event is only generated when the input queue + * becomes non-empty. + * @note In order to gain some performance it is suggested to not use + * this function directly but copy this code directly into the + * interrupt service routine. * - * @param[in] sdp pointer to a @p SerialDriver structure - * @param[in] b the byte to be written in the driver's Input Queue + * @param[in] sdp pointer to a @p SerialDriver structure + * @param[in] b the byte to be written in the driver's Input Queue */ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { @@ -199,17 +200,17 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { } /** - * @brief Handles outgoing data. + * @brief Handles outgoing data. * @details Must be called from the output interrupt service routine in order * to get the next byte to be transmitted. - * @note In order to gain some performance it is suggested to not use - * this function directly but copy this code directly into the - * interrupt service routine. + * @note In order to gain some performance it is suggested to not use + * this function directly but copy this code directly into the + * interrupt service routine. * - * @param[in] sdp pointer to a @p SerialDriver structure - * @return The byte value read from the driver's output queue. - * @retval Q_EMPTY if the queue is empty (the lower driver usually disables - * the interrupt source when this happens). + * @param[in] sdp pointer to a @p SerialDriver structure + * @return The byte value read from the driver's output queue. + * @retval Q_EMPTY if the queue is empty (the lower driver usually + * disables the interrupt source when this happens). */ msg_t sdRequestDataI(SerialDriver *sdp) { msg_t b; @@ -223,12 +224,12 @@ msg_t sdRequestDataI(SerialDriver *sdp) { } /** - * @brief Handles communication events/errors. + * @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] sdp pointer to a @p SerialDriver structure - * @param[in] mask condition flags to be added to the mask + * @param[in] sdp pointer to a @p SerialDriver structure + * @param[in] mask condition flags to be added to the mask */ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { @@ -239,11 +240,11 @@ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { } /** - * @brief Returns and clears the errors mask associated to the driver. + * @brief Returns and clears the errors mask associated to the driver. * - * @param[in] sdp pointer to a @p SerialDriver structure - * @return The condition flags modified since last time this function was - * invoked. + * @param[in] sdp pointer to a @p SerialDriver structure + * @return The condition flags modified since last time this + * function was invoked. */ sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { sdflags_t mask; diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 36bde9a3a..611a454a7 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -18,8 +18,9 @@ */ /** - * @file spi.c - * @brief SPI Driver code. + * @file spi.c + * @brief SPI Driver code. + * * @addtogroup SPI * @{ */ @@ -46,7 +47,7 @@ /*===========================================================================*/ /** - * @brief SPI Driver initialization. + * @brief SPI Driver initialization. */ void spiInit(void) { @@ -54,7 +55,7 @@ void spiInit(void) { } /** - * @brief Initializes the standard part of a @p SPIDriver structure. + * @brief Initializes the standard part of a @p SPIDriver structure. * * @param[in] spip pointer to the @p SPIDriver object */ @@ -70,7 +71,7 @@ void spiObjectInit(SPIDriver *spip) { } /** - * @brief Configures and activates the SPI peripheral. + * @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 @@ -108,7 +109,7 @@ void spiStop(SPIDriver *spip) { } /** - * @brief Asserts the slave select signal and prepares for transfers. + * @brief Asserts the slave select signal and prepares for transfers. * * @param[in] spip pointer to the @p SPIDriver object */ @@ -127,7 +128,7 @@ void spiSelect(SPIDriver *spip) { } /** - * @brief Deasserts the slave select signal. + * @brief Deasserts the slave select signal. * @details The previously selected peripheral is unselected. * * @param[in] spip pointer to the @p SPIDriver object @@ -147,7 +148,7 @@ void spiUnselect(SPIDriver *spip) { } /** - * @brief Ignores data on the SPI bus. + * @brief Ignores data on the SPI bus. * @details This function transmits a series of idle words on the SPI bus and * ignores the received data. This function can be invoked even * when a slave select signal has not been yet asserted. @@ -166,16 +167,15 @@ void spiIgnore(SPIDriver *spip, size_t n) { } /** - * @brief Exchanges data on the SPI bus. + * @brief Exchanges data on the SPI bus. * @details This function performs a simultaneous transmit/receive operation. + * @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 - * - * @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. */ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { @@ -189,14 +189,13 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { } /** - * @brief Sends data ever the SPI bus. + * @brief Sends data ever the SPI bus. + * @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 send * @param[in] txbuf the pointer to the transmit buffer - * - * @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. */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { @@ -210,14 +209,13 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { } /** - * @brief Receives data from the SPI bus. + * @brief Receives data from the SPI bus. + * @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 receive * @param[out] rxbuf the pointer to the receive buffer - * - * @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. */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { @@ -232,14 +230,14 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the SPI bus. + * @brief Gains exclusive access to the SPI bus. * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. * * @param[in] spip pointer to the @p SPIDriver object * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. */ void spiAcquireBus(SPIDriver *spip) { @@ -253,12 +251,11 @@ void spiAcquireBus(SPIDriver *spip) { } /** - * @brief Releases exclusive access to the SPI bus. + * @brief Releases exclusive access to the SPI bus. + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. * * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. */ void spiReleaseBus(SPIDriver *spip) { -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 18 +++++++++--------- os/hal/src/can.c | 14 +++++++------- os/hal/src/hal.c | 4 ++-- os/hal/src/mac.c | 22 +++++++++++----------- os/hal/src/mmc_spi.c | 30 +++++++++++++++--------------- os/hal/src/pal.c | 4 ++-- os/hal/src/pwm.c | 10 +++++----- os/hal/src/serial.c | 2 +- os/hal/src/spi.c | 12 ++++++------ 9 files changed, 58 insertions(+), 58 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index dff7d828b..2a329d003 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -126,10 +126,10 @@ void adcStop(ADCDriver *adcp) { * @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 + * 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. @@ -170,8 +170,8 @@ bool_t adcStartConversion(ADCDriver *adcp, /** * @brief Stops an ongoing conversion. - * - * @param[in] adcp pointer to the @p ADCDriver object + * + * @param[in] adcp pointer to the @p ADCDriver object */ void adcStopConversion(ADCDriver *adcp) { @@ -199,7 +199,7 @@ void adcStopConversion(ADCDriver *adcp) { * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the * invoking thread waits for a conversion completion event. - * + * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: @@ -208,7 +208,7 @@ void adcStopConversion(ADCDriver *adcp) { * . * @return The operation result. * @retval RDY_OK conversion finished. - * @retval RDY_TIMEOUT conversion not finished within the specified time. + * @retval RDY_TIMEOUT conversion not finished within the specified time. */ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { diff --git a/os/hal/src/can.c b/os/hal/src/can.c index a4da35b8e..7bb91173f 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -128,9 +128,9 @@ void canStop(CANDriver *canp) { * @details The specified frame is queued for transmission, if the hardware * queue is full then the invoking thread is queued. * @note Trying to transmit while in sleep mode simply enqueues the thread. - * - * @param[in] canp pointer to the @p CANDriver object - * @param[in] ctfp pointer to the CAN frame to be transmitted + * + * @param[in] canp pointer to the @p CANDriver object + * @param[in] ctfp pointer to the CAN frame to be transmitted * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -203,7 +203,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { } /** - * @brief Returns the current status mask and clears it. + * @brief Returns the current status mask and clears it. * * @param[in] canp pointer to the @p CANDriver object * @return The status flags mask. @@ -220,7 +220,7 @@ canstatus_t canGetAndClearFlags(CANDriver *canp) { #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** - * @brief Enters the sleep mode. + * @brief Enters the sleep mode. * * @param[in] canp pointer to the @p CANDriver object */ @@ -244,7 +244,7 @@ void canSleep(CANDriver *canp) { /** * @brief Enforces leaving the sleep mode. * @note The sleep mode is supposed to be usually exited automatically by - * an hardware event. + * an hardware event. * * @param[in] canp pointer to the @p CANDriver object */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index f93f036c6..d7e963f74 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -45,7 +45,7 @@ /*===========================================================================*/ /** - * @brief HAL initialization. + * @brief HAL initialization. */ void halInit(void) { diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 74e08bdf4..a079556fe 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -51,7 +51,7 @@ /*===========================================================================*/ /** - * @brief MAC Driver initialization. + * @brief MAC Driver initialization. */ void macInit(void) { @@ -59,7 +59,7 @@ void macInit(void) { } /** - * @brief Initialize the standard part of a @p MACDriver structure. + * @brief Initialize the standard part of a @p MACDriver structure. * * @param[in] macp pointer to the @p MACDriver object */ @@ -75,9 +75,9 @@ void macObjectInit(MACDriver *macp) { /** * @brief MAC address setup. * @note This function must be invoked only with the driver in the stopped - * state. If invoked on an active interface then it is ignored. + * state. If invoked on an active interface then it is ignored. * - * @param[in] macp pointer to the @p MACDriver object + * @param[in] macp pointer to the @p MACDriver object * @param[in] p pointer to a six bytes buffer containing the MAC * address. If this parameter is set to @p NULL then MAC * a system default is used. @@ -93,7 +93,7 @@ void macSetAddress(MACDriver *macp, const uint8_t *p) { * @details One of the available transmission descriptors is locked and * returned. If a descriptor is not currently available then the * invoking thread is queued until one is freed. - * + * * @param[in] macp pointer to the @p MACDriver object * @param[out] tdp pointer to a @p MACTransmitDescriptor structure * @param[in] time the number of ticks before the operation timeouts, @@ -103,7 +103,7 @@ void macSetAddress(MACDriver *macp, const uint8_t *p) { * . * @return The operation status. * @retval RDY_OK the descriptor was obtained. - * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. */ msg_t macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, @@ -126,8 +126,8 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, /** * @brief Releases a transmit descriptor and starts the transmission of the * enqueued data as a single frame. - * - * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure + * + * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure */ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { @@ -183,11 +183,11 @@ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { /** * @brief Updates and returns the link status. - * + * * @param[in] macp pointer to the @p MACDriver object * @return The link status. * @retval TRUE if the link is active. - * @retval FALSE if the link is down. + * @retval FALSE if the link is down. */ bool_t macPollLinkStatus(MACDriver *macp) { diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index c1cb313ec..6fb7a8332 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -45,7 +45,7 @@ /** * @brief Inserion monitor timer callback function. * - * @param[in] p pointer to the @p MMCDriver object + * @param[in] p pointer to the @p MMCDriver object */ void tmrfunc(void *p) { MMCDriver *mmcp = p; @@ -72,7 +72,7 @@ void tmrfunc(void *p) { /** * @brief Waits an idle condition. - * + * * @param[in] mmcp pointer to the @p MMCDriver object */ static void wait(MMCDriver *mmcp) { @@ -98,10 +98,10 @@ static void wait(MMCDriver *mmcp) { /** * @brief Sends a command header. - * + * * @param[in] mmcp pointer to the @p MMCDriver object - * @param cmd[in] the command id - * @param arg[in] the command argument + * @param cmd[in] the command id + * @param arg[in] the command argument */ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t buf[6]; @@ -120,10 +120,10 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { /** * @brief Receives a single byte response. - * + * * @param[in] mmcp pointer to the @p MMCDriver object * @return The response as an @p uint8_t value. - * @retval 0xFF timed out. + * @retval 0xFF timed out. */ static uint8_t recvr1(MMCDriver *mmcp) { int i; @@ -139,7 +139,7 @@ static uint8_t recvr1(MMCDriver *mmcp) { /** * @brief Sends a command an returns a single byte response. - * + * * @param[in] mmcp pointer to the @p MMCDriver object * @param cmd[in] the command id * @param arg[in] the command argument @@ -157,7 +157,7 @@ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { } /** - * @brief Waits that the card reaches an idle state. + * @brief Waits that the card reaches an idle state. * * @param[in] mmcp pointer to the @p MMCDriver object */ @@ -335,7 +335,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { /** * @brief Brings the driver in a state safe for card removal. - * + * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. * @retval FALSE the operation was successful and the driver is now @@ -367,9 +367,9 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { /** * @brief Starts a sequential read. - * + * * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] startblk first block to read + * @param[in] startblk first block to read * @return The operation status. * @retval FALSE the operation was successful. * @retval TRUE the operation failed. @@ -401,7 +401,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { /** * @brief Reads a block within a sequential read operation. - * + * * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the read buffer * @return The operation status. @@ -440,7 +440,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { /** * @brief Stops a sequential read gracefully. - * + * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. * @retval FALSE the operation was successful. diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index cc898d2fd..eef5c32ff 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -99,7 +99,7 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { * @note The default implementation is non atomic and not necessarily * optimal. Low level drivers may optimize the function by using * specific hardware or coding. - * + * * @param[in] bus the I/O bus, pointer to a @p IOBus structure * @param[in] mode the mode */ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ddfb6dd83..3aeec1309 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -104,10 +104,10 @@ void pwmStop(PWMDriver *pwmp) { /** * @brief Enables a PWM channel. - * + * * @param[in] pwmp pointer to a @p PWMDriver object - * @param[in] channel PWM channel identifier - * @param[in] width PWM pulse width as clock pulses number + * @param[in] channel PWM channel identifier + * @param[in] width PWM pulse width as clock pulses number */ void pwmEnableChannel(PWMDriver *pwmp, pwmchannel_t channel, @@ -127,7 +127,7 @@ void pwmEnableChannel(PWMDriver *pwmp, * @brief Disables a PWM channel. * @details The channel is disabled and its output line returned to the * idle state. - * + * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 851f16ffb..52a1772c8 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 611a454a7..29e69a283 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -110,7 +110,7 @@ void spiStop(SPIDriver *spip) { /** * @brief Asserts the slave select signal and prepares for transfers. - * + * * @param[in] spip pointer to the @p SPIDriver object */ void spiSelect(SPIDriver *spip) { @@ -130,7 +130,7 @@ void spiSelect(SPIDriver *spip) { /** * @brief Deasserts the slave select signal. * @details The previously selected peripheral is unselected. - * + * * @param[in] spip pointer to the @p SPIDriver object */ void spiUnselect(SPIDriver *spip) { @@ -152,7 +152,7 @@ void spiUnselect(SPIDriver *spip) { * @details This function transmits a series of idle words on the SPI bus and * ignores the received data. This function can be invoked even * when a slave select signal has not been yet asserted. - * + * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored */ @@ -171,9 +171,9 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @details This function performs a simultaneous transmit/receive operation. * @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] 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 */ -- cgit v1.2.3 From c2ba7ebf4611f2beec0ebdf537934f6f28513579 Mon Sep 17 00:00:00 2001 From: liamstask Date: Mon, 19 Apr 2010 15:29:44 +0000 Subject: * remove the SerialConfig pointer from the SerialDriver structure. This is now simply passed through from sdStart() to sd_lld_start() * implementation for AT91SAM7 port provided - others will need to be updated git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1875 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 52a1772c8..94418e46c 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -146,8 +146,7 @@ void sdStart(SerialDriver *sdp, const SerialConfig *config) { chDbgAssert((sdp->state == SD_STOP) || (sdp->state == SD_READY), "sdStart(), #1", "invalid state"); - sdp->config = config; - sd_lld_start(sdp); + sd_lld_start(sdp, config); sdp->state = SD_READY; chSysUnlock(); } -- cgit v1.2.3 From af639f7aa4633d0604bc58e2f925c732cf768945 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 24 Apr 2010 11:21:23 +0000 Subject: Fixed bug 2991714. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1886 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 6fb7a8332..fd63d7838 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -460,7 +460,10 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { chSysUnlock(); spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); - result = recvr1(mmcp) != 0x00; +/* result = recvr1(mmcp) != 0x00;*/ + /* Note, ignored r1 response, it can be not zero, unknown issue.*/ + recvr1(mmcp); + result = FALSE; spiUnselect(mmcp->mmc_spip); chSysLock(); @@ -530,8 +533,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ spiReceive(mmcp->mmc_spip, 1, b); - if ((b[0] & 0x1F) == 0x05) + if ((b[0] & 0x1F) == 0x05) { + wait(mmcp); return FALSE; + } /* Error.*/ spiUnselect(mmcp->mmc_spip); -- cgit v1.2.3 From b14c34d67db82417b171dbfe052be9ceacdf17e4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 22 May 2010 06:32:02 +0000 Subject: Fixed bug 3005628. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1947 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index fd63d7838..e5070de02 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -343,8 +343,9 @@ bool_t mmcConnect(MMCDriver *mmcp) { * @retval TRUE the operation failed. */ bool_t mmcDisconnect(MMCDriver *mmcp) { + bool_t status; - chDbgCheck(mmcp != NULL, "mmcConnect"); + chDbgCheck(mmcp != NULL, "mmcDisconnect"); chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && (mmcp->mmc_state != MMC_STOP), @@ -359,10 +360,12 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { mmcp->mmc_state = MMC_INSERTED; chSysUnlock(); case MMC_INSERTED: - return FALSE; + status = FALSE; default: - return TRUE; + status = TRUE; } + spiStop(mmcp->mmc_spip); + return status; } /** @@ -386,6 +389,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { mmcp->mmc_state = MMC_READING; chSysUnlock(); + spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); spiSelect(mmcp->mmc_spip); send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); if (recvr1(mmcp) != 0x00) { @@ -494,6 +498,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { mmcp->mmc_state = MMC_WRITING; chSysUnlock(); + spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); spiSelect(mmcp->mmc_spip); send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); if (recvr1(mmcp) != 0x00) { @@ -520,7 +525,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { static const uint8_t start[] = {0xFF, 0xFC}; uint8_t b[1]; - chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialWrite"); chSysLock(); if (mmcp->mmc_state != MMC_WRITING) { -- cgit v1.2.3 From ac1f65e8f8a10bd41d8c46b8427d676bd3385551 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 24 Jul 2010 09:03:11 +0000 Subject: UART driver model, no implementations yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2087 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 + os/hal/src/uart.c | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 os/hal/src/uart.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d7e963f74..d2b2fc528 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -75,6 +75,9 @@ void halInit(void) { #if CH_HAL_USE_MMC_SPI mmcInit(); #endif +#if CH_HAL_USE_UART + uartInit(); +#endif } /** @} */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c new file mode 100644 index 000000000..281d6ad78 --- /dev/null +++ b/os/hal/src/uart.c @@ -0,0 +1,299 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file uart.c + * @brief UART Driver code. + * + * @addtogroup UART + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_UART || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief UART Driver initialization. + */ +void uartInit(void) { + + uart_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p UARTDriver structure. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartObjectInit(UARTDriver *uartp) { + + uartp->ud_state = UART_STOP; + uartp->ud_txstate = UART_TX_IDLE; + uartp->ud_rxstate = UART_RX_IDLE; + uartp->ud_config = NULL; +} + +/** + * @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 + */ +void uartStart(UARTDriver *uartp, const UARTConfig *config) { + + chDbgCheck((uartp != NULL) && (config != NULL), "uartStart"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_STOP) || + (uartp->ud_state == UART_READY), + "uartStart(), #1", + "invalid state"); + + uartp->ud_config = config; + uart_lld_start(uartp); + uartp->ud_state = UART_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the UART peripheral. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStop(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStop"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_STOP) || + (uartp->ud_state == UART_READY), + "uartStop(), #1", + "invalid state"); + + uart_lld_stop(uartp); + uartp->ud_state = UART_STOP; + uartp->ud_txstate = UART_TX_IDLE; + uartp->ud_rxstate = UART_RX_IDLE; + chSysUnlock(); +} + +/** + * @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 + */ +void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), + "uartStartSend"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_txstate == UART_TX_IDLE), + "uartStartSend(), #1", + "not active"); + + uart_lld_start_send(uartp, n, txbuf); + uartp->ud_txstate = UART_TX_ACTIVE; + chSysUnlock(); +} + +/** + * @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. + * @note This function has to be invoked from a lock zone. + * + * @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 + */ +void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), + "uartStartSendI"); + + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_txstate != UART_TX_ACTIVE), + "uartStartSendI(), #1", + "not active"); + uart_lld_start_send(uartp, n, txbuf); + uartp->ud_txstate = UART_TX_ACTIVE; +} + +/** + * @brief Stops any ongoing transmission. + * @note Stopping a transmission also suppresses the transmission callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopSend(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopSend"); + + chSysLock() + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopSend(), #1", + "not active"); + + if (uartp->ud_txstate == UART_TX_ACTIVE) { + uart_lld_stop_send(uartp); + uartp->ud_txstate = UART_TX_IDLE; + } + chSysUnlock(); +} + +/** + * @brief Stops any ongoing transmission. + * @note Stopping a transmission also suppresses the transmission callbacks. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopSendI(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopSendI"); + + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopSendI(), #1", + "not active"); + + if (uartp->ud_txstate == UART_TX_ACTIVE) { + uart_lld_stop_send(uartp); + uartp->ud_txstate = UART_TX_IDLE; + } +} + +/** + * @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 send + * @param[in] rxbuf the pointer to the receive buffer + */ +void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), + "uartStartReceive"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_rxstate == UART_RX_IDLE), + "uartStartReceive(), #1", + "not active"); + + uart_lld_start_receive(uartp, n, txbuf); + uartp->ud_rxstate = UART_RX_ACTIVE; + chSysUnlock(); +} + +/** + * @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. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] rxbuf the pointer to the receive buffer + */ +void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), + "uartStartReceiveI"); + + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_rxstate == UART_RX_IDLE), + "uartStartReceiveI(), #1", + "not active"); + + uart_lld_start_receive(uartp, n, txbuf); + uartp->ud_rxstate = UART_RX_ACTIVE; +} + +/** + * @brief Stops any ongoing receive operation. + * @note Stopping a receive operation also suppresses the receive callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopReceive(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopReceive"); + + chSysLock() + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopReceive(), #1", + "not active"); + + if (uartp->ud_rxstate == UART_RX_ACTIVE) { + uart_lld_stop_receive(uartp); + uartp->ud_rxstate = UART_RX_IDLE; + } + chSysUnlock(); +} + +/** + * @brief Stops any ongoing receive operation. + * @note Stopping a receive operation also suppresses the receive callbacks. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopReceiveI(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopReceiveI"); + + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopReceiveI(), #1", + "not active"); + + if (uartp->ud_rxstate == UART_RX_ACTIVE) { + uart_lld_stop_receive(uartp); + uartp->ud_rxstate = UART_RX_IDLE; + } +} + +#endif /* CH_HAL_USE_UART */ + +/** @} */ -- cgit v1.2.3 From d7e91ec7012e4165f8127edaa8512469cdc6b583 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 26 Jul 2010 09:01:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2089 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/uart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 281d6ad78..9c200763f 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -222,7 +222,7 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { "uartStartReceive(), #1", "not active"); - uart_lld_start_receive(uartp, n, txbuf); + uart_lld_start_receive(uartp, n, rxbuf); uartp->ud_rxstate = UART_RX_ACTIVE; chSysUnlock(); } @@ -247,7 +247,7 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { "uartStartReceiveI(), #1", "not active"); - uart_lld_start_receive(uartp, n, txbuf); + uart_lld_start_receive(uartp, n, rxbuf); uartp->ud_rxstate = UART_RX_ACTIVE; } -- cgit v1.2.3 From 8e4fd21b2b79a1f9f3c3601d6d344a9bfd4cc060 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 31 Jul 2010 06:46:17 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2099 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/uart.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 9c200763f..4c1a2a55a 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -57,7 +57,7 @@ void uartInit(void) { /** * @brief Initializes the standard part of a @p UARTDriver structure. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object */ void uartObjectInit(UARTDriver *uartp) { @@ -70,7 +70,7 @@ void uartObjectInit(UARTDriver *uartp) { /** * @brief Configures and activates the UART peripheral. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object * @param[in] config pointer to the @p UARTConfig object */ void uartStart(UARTDriver *uartp, const UARTConfig *config) { @@ -92,7 +92,7 @@ void uartStart(UARTDriver *uartp, const UARTConfig *config) { /** * @brief Deactivates the UART peripheral. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object */ void uartStop(UARTDriver *uartp) { @@ -163,13 +163,13 @@ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { * @brief Stops any ongoing transmission. * @note Stopping a transmission also suppresses the transmission callbacks. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object */ void uartStopSend(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopSend"); - chSysLock() + chSysLock(); chDbgAssert(uartp->ud_state == UART_READY, "uartStopSend(), #1", "not active"); @@ -186,7 +186,7 @@ void uartStopSend(UARTDriver *uartp) { * @note Stopping a transmission also suppresses the transmission callbacks. * @note This function has to be invoked from a lock zone. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object */ void uartStopSendI(UARTDriver *uartp) { @@ -255,13 +255,13 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { * @brief Stops any ongoing receive operation. * @note Stopping a receive operation also suppresses the receive callbacks. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] uartp pointer to the @p UARTDriver object */ void uartStopReceive(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopReceive"); - chSysLock() + chSysLock(); chDbgAssert(uartp->ud_state == UART_READY, "uartStopReceive(), #1", "not active"); -- cgit v1.2.3 From 04e29829b64a64a405125595dc371bd731766c68 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 5 Aug 2010 10:30:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2114 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 12 ++++++------ os/hal/src/pwm.c | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 2a329d003..5348d7e93 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -112,11 +112,10 @@ void adcStop(ADCDriver *adcp) { * @brief Starts an ADC conversion. * @details Starts a conversion operation, there are two kind of conversion * modes: - * - LINEAR, this mode is activated when the @p callback - * parameter is set to @p NULL, in this mode the buffer is filled - * once and then the conversion stops automatically. - * - CIRCULAR, when a callback function is defined the - * conversion never stops and the buffer is filled circularly. + * - LINEAR, in this mode the buffer is filled once and then + * the conversion stops automatically. + * - CIRCULAR, in this mode the conversion never stops and + * the buffer is filled circularly.
* During the conversion the callback function is invoked when * the buffer is 50% filled and when the buffer is 100% filled, * this way is possible to process the conversion stream in real @@ -133,7 +132,8 @@ void adcStop(ADCDriver *adcp) { * @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. - * @param[in] callback pointer to the conversion callback function + * @param[in] callback pointer to the conversion callback function, this + * parameter can be @p NULL if a callback is not required * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 3aeec1309..4b797da0c 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -20,6 +20,7 @@ /** * @file pwm.c * @brief PWM Driver code. + * * @addtogroup PWM * @{ */ @@ -104,6 +105,7 @@ void pwmStop(PWMDriver *pwmp) { /** * @brief Enables a PWM channel. + * @details Programs (or reprograms) a PWM channel. * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier -- cgit v1.2.3 From b01b63ed5aa6d47ac5f165b9944bbe5e140cd817 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 12 Aug 2010 15:19:11 +0000 Subject: UART driver model improvements, templates and STM32 implementation updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2125 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/uart.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 4c1a2a55a..097bd364b 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -164,8 +164,13 @@ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { * @note Stopping a transmission also suppresses the transmission callbacks. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @return The number of data frames not transmitted by the + * stopped transmit operation. + * @retval 0 There was no transmit operation in progress. */ -void uartStopSend(UARTDriver *uartp) { +size_t uartStopSend(UARTDriver *uartp) { + size_t n; chDbgCheck(uartp != NULL, "uartStopSend"); @@ -175,10 +180,13 @@ void uartStopSend(UARTDriver *uartp) { "not active"); if (uartp->ud_txstate == UART_TX_ACTIVE) { - uart_lld_stop_send(uartp); + n = uart_lld_stop_send(uartp); uartp->ud_txstate = UART_TX_IDLE; } + else + n = 0; chSysUnlock(); + return n; } /** @@ -187,8 +195,12 @@ void uartStopSend(UARTDriver *uartp) { * @note This function has to be invoked from a lock zone. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @return The number of data frames not transmitted by the + * stopped transmit operation. + * @retval 0 There was no transmit operation in progress. */ -void uartStopSendI(UARTDriver *uartp) { +size_t uartStopSendI(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopSendI"); @@ -197,9 +209,11 @@ void uartStopSendI(UARTDriver *uartp) { "not active"); if (uartp->ud_txstate == UART_TX_ACTIVE) { - uart_lld_stop_send(uartp); + size_t n = uart_lld_stop_send(uartp); uartp->ud_txstate = UART_TX_IDLE; + return n; } + return 0; } /** @@ -256,8 +270,13 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { * @note Stopping a receive operation also suppresses the receive callbacks. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @return The number of data frames not received by the + * stopped receive operation. + * @retval 0 There was no receive operation in progress. */ -void uartStopReceive(UARTDriver *uartp) { +size_t uartStopReceive(UARTDriver *uartp) { + size_t n; chDbgCheck(uartp != NULL, "uartStopReceive"); @@ -267,10 +286,13 @@ void uartStopReceive(UARTDriver *uartp) { "not active"); if (uartp->ud_rxstate == UART_RX_ACTIVE) { - uart_lld_stop_receive(uartp); + n = uart_lld_stop_receive(uartp); uartp->ud_rxstate = UART_RX_IDLE; } + else + n = 0; chSysUnlock(); + return n; } /** @@ -279,9 +301,12 @@ void uartStopReceive(UARTDriver *uartp) { * @note This function has to be invoked from a lock zone. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @return The number of data frames not received by the + * stopped receive operation. + * @retval 0 There was no receive operation in progress. */ -void uartStopReceiveI(UARTDriver *uartp) { - +size_t uartStopReceiveI(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopReceiveI"); chDbgAssert(uartp->ud_state == UART_READY, @@ -289,9 +314,11 @@ void uartStopReceiveI(UARTDriver *uartp) { "not active"); if (uartp->ud_rxstate == UART_RX_ACTIVE) { - uart_lld_stop_receive(uartp); + size_t n = uart_lld_stop_receive(uartp); uartp->ud_rxstate = UART_RX_IDLE; + return n; } + return 0; } #endif /* CH_HAL_USE_UART */ -- cgit v1.2.3 From 8b45c58317683148179c9964e67c8f7d0683257b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Aug 2010 08:50:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2132 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 + os/hal/src/i2c.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d2b2fc528..156e75ea9 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -60,6 +60,9 @@ void halInit(void) { #if CH_HAL_USE_CAN canInit(); #endif +#if CH_HAL_USE_I2C + i2cInit(); +#endif #if CH_HAL_USE_MAC macInit(); #endif diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..03d882446 --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,222 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2c.c + * @brief I2C Driver code. + * + * @addtogroup I2C + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_I2C || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2C Driver initialization. + */ +void i2cInit(void) { + + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cObjectInit(I2CDriver *i2cp) { + + i2cp->i2c_state = I2C_STOP; + i2cp->i2c_config = NULL; +} + +/** + * @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 + */ +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + "i2cStart(), #1", + "invalid state"); + i2cp->i2c_config = config; + i2c_lld_start(i2cp); + i2cp->i2c_state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + "i2cStop(), #1", + "invalid state"); + i2c_lld_stop(i2cp); + i2cp->i2c_state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Initiates a master bus transaction. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); + chDbgAssert((i2cp->i2c_state == I2C_READY) || (i2cp->i2c_state == I2C_MREADY), + "i2cMasterStartI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_start(i2cp); +} + +/** + * @brief Terminates a master bus transaction. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterStopI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_stop(i2cp); +} + +/** + * @brief Master transmission. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] n number of bytes to be transmitted + * @param[in] txbuf transmit data buffer pointer + * @param[in] callback operation complete callback + */ +void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, + i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (n > 0) && + (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterTransmitI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_transmit(i2cp, n, txbuf); +} + +/** + * @brief Master receive. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] n number of bytes to be transmitted + * @param[in] rxbuf receive data buffer pointer + * @param[in] callback operation complete callback + */ +void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, + i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (n > 0) && + (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterReceiveI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_receive(i2cp, n, rxbuf); +} + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->id_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->id_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->id_semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_I2C */ + +/** @} */ -- cgit v1.2.3 From 4e26a3b42cb49974f63d1b8727d7b1d1830c9c81 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Aug 2010 13:23:41 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 03d882446..cc48c4147 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -104,19 +104,24 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Initiates a master bus transaction. + * @brief Initiates a master bus transaction. + * @details This function sends a start bit followed by an one or two bytes + * header. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] header transaction header * @param[in] callback operation complete callback */ -void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback) { +void i2cMasterStartI(I2CDriver *i2cp, + uint16_t header, + i2ccallback_t callback) { chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); - chDbgAssert((i2cp->i2c_state == I2C_READY) || (i2cp->i2c_state == I2C_MREADY), + chDbgAssert(i2cp->i2c_state == I2C_READY, "i2cMasterStartI(), #1", "invalid state"); i2cp->id_callback = callback; - i2c_lld_master_start(i2cp); + i2c_lld_master_start(i2cp, header); } /** @@ -135,6 +140,24 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { i2c_lld_master_stop(i2cp); } + +/** + * @brief Sends a restart bit. + * @details Restart bits are required by some types of I2C transactions. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterRestartI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_restart(i2cp); +} + /** * @brief Master transmission. * -- cgit v1.2.3 From f9fd465da5bd86e2c650fe7f8f6f54b528c46aff Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 11 Sep 2010 10:14:05 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2173 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 5348d7e93..4eafafac4 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -143,28 +143,67 @@ bool_t adcStartConversion(ADCDriver *adcp, adcsample_t *samples, size_t depth, adccallback_t callback) { + bool_t result; + + chSysLock(); + result = adcStartConversionI(adcp, grpp, samples, depth, callback); + chSysUnlock(); + return result; +} + +/** + * @brief Starts an ADC conversion. + * @details Starts a conversion operation, there are two kind of conversion + * modes: + * - LINEAR, in this mode the buffer is filled once and then + * the conversion stops automatically. + * - CIRCULAR, in this mode the conversion never stops and + * the buffer is filled circularly.
+ * During the conversion the callback function is invoked when + * the buffer is 50% filled and when the buffer is 100% filled, + * this way is possible to process the conversion stream in real + * time. This kind of conversion can only be stopped by explicitly + * invoking @p adcStopConversion(). + * . + * @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. + * @param[in] callback pointer to the conversion callback function, this + * parameter can be @p NULL if a callback is not required + * @return The operation status. + * @retval FALSE the conversion has been started. + * @retval TRUE the driver is busy, conversion not started. + */ +bool_t adcStartConversionI(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth, + adccallback_t callback) { chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && ((depth == 1) || ((depth & 1) == 0)), - "adcStartConversion"); + "adcStartConversionI"); - chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || (adcp->ad_state == ADC_RUNNING) || (adcp->ad_state == ADC_COMPLETE), - "adcStartConversion(), #1", + "adcStartConversionI(), #1", "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { - chSysUnlock(); + if (adcp->ad_state == ADC_RUNNING) return TRUE; - } adcp->ad_callback = callback; adcp->ad_samples = samples; adcp->ad_depth = depth; adcp->ad_grpp = grpp; adc_lld_start_conversion(adcp); adcp->ad_state = ADC_RUNNING; - chSysUnlock(); return FALSE; } @@ -195,6 +234,30 @@ void adcStopConversion(ADCDriver *adcp) { chSysUnlock(); } +/** + * @brief Stops an ongoing conversion. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStopConversionI(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStopConversionI"); + + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_COMPLETE), + "adcStopConversionI(), #1", + "invalid state"); + if (adcp->ad_state == ADC_RUNNING) { + adc_lld_stop_conversion(adcp); + adcp->ad_grpp = NULL; + adcp->ad_state = ADC_READY; + chSemResetI(&adcp->ad_sem, 0); + } + else + adcp->ad_state = ADC_READY; +} + /** * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the -- cgit v1.2.3 From d51840a0c799be3b684c5b379f4015475096b6b1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 11 Sep 2010 10:21:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2174 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 4eafafac4..23b096f3e 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -209,6 +209,9 @@ bool_t adcStartConversionI(ADCDriver *adcp, /** * @brief Stops an ongoing conversion. + * @details This function stops the currently ongoing conversion and returns + * the driver in the @p ADC_READY state. If there was no conversion + * being processed then the function does nothing. * * @param[in] adcp pointer to the @p ADCDriver object */ @@ -236,6 +239,9 @@ void adcStopConversion(ADCDriver *adcp) { /** * @brief Stops an ongoing conversion. + * @details This function stops the currently ongoing conversion and returns + * the driver in the @p ADC_READY state. If there was no conversion + * being processed then the function does nothing. * * @param[in] adcp pointer to the @p ADCDriver object */ -- cgit v1.2.3 From 781b0b129cccbecba160effce8c4ddd68295b8b9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 11 Sep 2010 10:57:11 +0000 Subject: Fixed bug 3064204. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2175 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 23b096f3e..df8b05fd5 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -67,7 +67,9 @@ void adcObjectInit(ADCDriver *adcp) { adcp->ad_samples = NULL; adcp->ad_depth = 0; adcp->ad_grpp = NULL; +#if ADC_USE_WAIT chSemInit(&adcp->ad_sem, 0); +#endif } /** @@ -229,8 +231,10 @@ void adcStopConversion(ADCDriver *adcp) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; +#if ADC_USE_WAIT chSemResetI(&adcp->ad_sem, 0); chSchRescheduleS(); +#endif } else adcp->ad_state = ADC_READY; @@ -258,12 +262,15 @@ void adcStopConversionI(ADCDriver *adcp) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; +#if ADC_USE_WAIT chSemResetI(&adcp->ad_sem, 0); +#endif } else adcp->ad_state = ADC_READY; } +#if ADC_USE_WAIT || defined(__DOXYGEN__) /** * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the @@ -296,6 +303,7 @@ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { chSysUnlock(); return RDY_OK; } +#endif /* ADC_USE_WAIT */ #endif /* CH_HAL_USE_ADC */ -- cgit v1.2.3 From 07351222e6d0b6b3dcd4f50ecb18bc09e7402d1c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Sep 2010 10:22:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 94418e46c..48518e66c 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -61,12 +61,12 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { static bool_t putwouldblock(void *ip) { - return chOQIsFull(&((SerialDriver *)ip)->oqueue); + return chOQIsFullI(&((SerialDriver *)ip)->oqueue); } static bool_t getwouldblock(void *ip) { - return chIQIsEmpty(&((SerialDriver *)ip)->iqueue); + return chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { @@ -192,7 +192,7 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { chDbgCheck(sdp != NULL, "sdIncomingDataI"); - if (chIQIsEmpty(&sdp->iqueue)) + if (chIQIsEmptyI(&sdp->iqueue)) chEvtBroadcastI(&sdp->ievent); if (chIQPutI(&sdp->iqueue, b) < Q_OK) sdAddFlagsI(sdp, SD_OVERRUN_ERROR); -- cgit v1.2.3 From 2891f7d645c4be187ac96ee4011207531d25c34a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 4 Oct 2010 17:16:18 +0000 Subject: Documentation improvements, fixed a small error in the STM32 serial driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2234 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 20 +++++++++++++++++++ os/hal/src/can.c | 21 ++++++++++++++++++++ os/hal/src/hal.c | 2 ++ os/hal/src/i2c.c | 30 +++++++++++++++++++++++++---- os/hal/src/mac.c | 17 ++++++++++++++++- os/hal/src/mmc_spi.c | 54 +++++++++++++++++++++++++++++++++++++++++++--------- os/hal/src/pal.c | 6 ++++++ os/hal/src/pwm.c | 12 ++++++++++++ os/hal/src/serial.c | 16 ++++++++++++++++ os/hal/src/spi.c | 31 ++++++++++++++++++++++++++---- os/hal/src/uart.c | 24 +++++++++++++++++++++++ 11 files changed, 215 insertions(+), 18 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index df8b05fd5..4983199ce 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -48,6 +48,8 @@ /** * @brief ADC Driver initialization. + * + * @init */ void adcInit(void) { @@ -58,6 +60,8 @@ void adcInit(void) { * @brief Initializes the standard part of a @p ADCDriver structure. * * @param[in] adcp pointer to the @p ADCDriver object + * + * @init */ void adcObjectInit(ADCDriver *adcp) { @@ -77,6 +81,8 @@ void adcObjectInit(ADCDriver *adcp) { * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] config pointer to the @p ADCConfig object + * + * @api */ void adcStart(ADCDriver *adcp, const ADCConfig *config) { @@ -96,6 +102,8 @@ void adcStart(ADCDriver *adcp, const ADCConfig *config) { * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object + * + * @api */ void adcStop(ADCDriver *adcp) { @@ -139,6 +147,8 @@ void adcStop(ADCDriver *adcp) { * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. + * + * @api */ bool_t adcStartConversion(ADCDriver *adcp, const ADCConversionGroup *grpp, @@ -182,6 +192,8 @@ bool_t adcStartConversion(ADCDriver *adcp, * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. + * + * @iclass */ bool_t adcStartConversionI(ADCDriver *adcp, const ADCConversionGroup *grpp, @@ -216,6 +228,8 @@ bool_t adcStartConversionI(ADCDriver *adcp, * being processed then the function does nothing. * * @param[in] adcp pointer to the @p ADCDriver object + * + * @api */ void adcStopConversion(ADCDriver *adcp) { @@ -248,6 +262,8 @@ void adcStopConversion(ADCDriver *adcp) { * being processed then the function does nothing. * * @param[in] adcp pointer to the @p ADCDriver object + * + * @iclass */ void adcStopConversionI(ADCDriver *adcp) { @@ -275,6 +291,8 @@ void adcStopConversionI(ADCDriver *adcp) { * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the * invoking thread waits for a conversion completion event. + * @pre In order to use this function the option @p ADC_USE_WAIT must be + * enabled. * * @param[in] adcp pointer to the @p ADCDriver object * @param[in] timeout the number of ticks before the operation timeouts, @@ -285,6 +303,8 @@ void adcStopConversionI(ADCDriver *adcp) { * @return The operation result. * @retval RDY_OK conversion finished. * @retval RDY_TIMEOUT conversion not finished within the specified time. + * + * @init */ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 7bb91173f..a1fb237f3 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -48,6 +48,8 @@ /** * @brief CAN Driver initialization. + * + * @init */ void canInit(void) { @@ -58,6 +60,8 @@ void canInit(void) { * @brief Initializes the standard part of a @p CANDriver structure. * * @param[in] canp pointer to the @p CANDriver object + * + * @init */ void canObjectInit(CANDriver *canp) { @@ -80,6 +84,8 @@ void canObjectInit(CANDriver *canp) { * * @param[in] canp pointer to the @p CANDriver object * @param[in] config pointer to the @p CANConfig object + * + * @api */ void canStart(CANDriver *canp, const CANConfig *config) { @@ -105,6 +111,8 @@ void canStart(CANDriver *canp, const CANConfig *config) { * @brief Deactivates the CAN peripheral. * * @param[in] canp pointer to the @p CANDriver object + * + * @api */ void canStop(CANDriver *canp) { @@ -140,6 +148,8 @@ void canStop(CANDriver *canp) { * @retval RDY_OK the frame has been queued for transmission. * @retval RDY_TIMEOUT operation not finished within the specified time. * @retval RDY_RESET driver stopped while waiting. + * + * @api */ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { @@ -181,6 +191,8 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * frame not immediately available if invoked using * @p TIME_IMMEDIATE. * @retval RDY_RESET driver stopped while waiting. + * + * @api */ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { @@ -207,6 +219,8 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { * * @param[in] canp pointer to the @p CANDriver object * @return The status flags mask. + * + * @api */ canstatus_t canGetAndClearFlags(CANDriver *canp) { canstatus_t status; @@ -221,8 +235,15 @@ canstatus_t canGetAndClearFlags(CANDriver *canp) { #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** * @brief Enters the sleep mode. + * @details This function puts the CAN driver in sleep mode and broadcasts + * the @p cd_sleep_event event source. + * @pre In order to use this function the option @p CAN_USE_SLEEP_MODE must + * be enabled and the @p CAN_SUPPORTS_SLEEP mode must be supported + * by the low level driver. * * @param[in] canp pointer to the @p CANDriver object + * + * @api */ void canSleep(CANDriver *canp) { diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 156e75ea9..c0e3d2c28 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -46,6 +46,8 @@ /** * @brief HAL initialization. + * + * @init */ void halInit(void) { diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cc48c4147..1a55f53cd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -48,6 +48,8 @@ /** * @brief I2C Driver initialization. + * + * @init */ void i2cInit(void) { @@ -58,6 +60,8 @@ void i2cInit(void) { * @brief Initializes the standard part of a @p I2CDriver structure. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @init */ void i2cObjectInit(I2CDriver *i2cp) { @@ -70,6 +74,8 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @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) { @@ -89,6 +95,8 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { * @brief Deactivates the I2C peripheral. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api */ void i2cStop(I2CDriver *i2cp) { @@ -111,6 +119,8 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] header transaction header * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterStartI(I2CDriver *i2cp, uint16_t header, @@ -129,6 +139,8 @@ void i2cMasterStartI(I2CDriver *i2cp, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { @@ -147,6 +159,8 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { @@ -165,6 +179,8 @@ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { * @param[in] n number of bytes to be transmitted * @param[in] txbuf transmit data buffer pointer * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, i2ccallback_t callback) { @@ -185,6 +201,8 @@ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, * @param[in] n number of bytes to be transmitted * @param[in] rxbuf receive data buffer pointer * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, i2ccallback_t callback) { @@ -203,11 +221,13 @@ void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, * @brief Gains exclusive access to the I2C bus. * @details This function tries to gain ownership to the I2C bus, if the bus * is already being used then the invoking thread is queued. - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * + * @api + * */ void i2cAcquireBus(I2CDriver *i2cp) { @@ -222,10 +242,12 @@ void i2cAcquireBus(I2CDriver *i2cp) { /** * @brief Releases exclusive access to the I2C bus. - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api */ void i2cReleaseBus(I2CDriver *i2cp) { diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index a079556fe..62340dc31 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -52,6 +52,8 @@ /** * @brief MAC Driver initialization. + * + * @init */ void macInit(void) { @@ -62,6 +64,8 @@ void macInit(void) { * @brief Initialize the standard part of a @p MACDriver structure. * * @param[in] macp pointer to the @p MACDriver object + * + * @init */ void macObjectInit(MACDriver *macp) { @@ -74,7 +78,7 @@ void macObjectInit(MACDriver *macp) { /** * @brief MAC address setup. - * @note This function must be invoked only with the driver in the stopped + * @pre This function must be invoked with the driver in the stopped * state. If invoked on an active interface then it is ignored. * * @param[in] macp pointer to the @p MACDriver object @@ -82,6 +86,7 @@ void macObjectInit(MACDriver *macp) { * address. If this parameter is set to @p NULL then MAC * a system default is used. * + * @api */ void macSetAddress(MACDriver *macp, const uint8_t *p) { @@ -104,6 +109,8 @@ void macSetAddress(MACDriver *macp, const uint8_t *p) { * @return The operation status. * @retval RDY_OK the descriptor was obtained. * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + * + * @api */ msg_t macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, @@ -128,6 +135,8 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, * enqueued data as a single frame. * * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure + * + * @api */ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { @@ -150,6 +159,8 @@ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { * @return The operation status. * @retval RDY_OK the descriptor was obtained. * @retval RDY_TIMEOUT the operation timed out, descriptor not initialized. + * + * @api */ msg_t macWaitReceiveDescriptor(MACDriver *macp, MACReceiveDescriptor *rdp, @@ -175,6 +186,8 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, * frames. * * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure + * + * @api */ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { @@ -188,6 +201,8 @@ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { * @return The link status. * @retval TRUE if the link is active. * @retval FALSE if the link is down. + * + * @api */ bool_t macPollLinkStatus(MACDriver *macp) { diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index e5070de02..49f75c3cc 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -46,8 +46,10 @@ * @brief Inserion monitor timer callback function. * * @param[in] p pointer to the @p MMCDriver object + * + * @notapi */ -void tmrfunc(void *p) { +static void tmrfunc(void *p) { MMCDriver *mmcp = p; if (mmcp->mmc_cnt > 0) { @@ -74,6 +76,8 @@ void tmrfunc(void *p) { * @brief Waits an idle condition. * * @param[in] mmcp pointer to the @p MMCDriver object + * + * @notapi */ static void wait(MMCDriver *mmcp) { int i; @@ -102,6 +106,8 @@ static void wait(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * @param cmd[in] the command id * @param arg[in] the command argument + * + * @notapi */ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t buf[6]; @@ -124,6 +130,8 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { * @param[in] mmcp pointer to the @p MMCDriver object * @return The response as an @p uint8_t value. * @retval 0xFF timed out. + * + * @notapi */ static uint8_t recvr1(MMCDriver *mmcp) { int i; @@ -145,6 +153,8 @@ static uint8_t recvr1(MMCDriver *mmcp) { * @param arg[in] the command argument * @return The response as an @p uint8_t value. * @retval 0xFF timed out. + * + * @notapi */ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t r1; @@ -160,6 +170,8 @@ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { * @brief Waits that the card reaches an idle state. * * @param[in] mmcp pointer to the @p MMCDriver object + * + * @notapi */ static void sync(MMCDriver *mmcp) { uint8_t buf[1]; @@ -182,6 +194,8 @@ static void sync(MMCDriver *mmcp) { /** * @brief MMC over SPI driver initialization. + * + * @init */ void mmcInit(void) { @@ -198,6 +212,8 @@ void mmcInit(void) { * 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, @@ -219,6 +235,8 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, * * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] config pointer to the @p MMCConfig object + * + * @api */ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { @@ -237,6 +255,8 @@ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { * @brief Disables the MMC peripheral. * * @param[in] mmcp pointer to the @p MMCDriver object + * + * @api */ void mmcStop(MMCDriver *mmcp) { @@ -266,9 +286,11 @@ void mmcStop(MMCDriver *mmcp) { * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. - * @retval FALSE the operation was successful and the driver is now + * @retval FALSE the operation succeeded and the driver is now * in the @p MMC_READY state. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; @@ -338,9 +360,11 @@ bool_t mmcConnect(MMCDriver *mmcp) { * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. - * @retval FALSE the operation was successful and the driver is now + * @retval FALSE the operation succeeded and the driver is now * in the @p MMC_INSERTED state. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcDisconnect(MMCDriver *mmcp) { bool_t status; @@ -374,8 +398,10 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] startblk first block to read * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { @@ -409,8 +435,10 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the read buffer * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { int i; @@ -447,8 +475,10 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { static const uint8_t stopcmd[] = {0x40 | MMC_CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; @@ -483,8 +513,10 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] startblk first block to write * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { @@ -518,8 +550,10 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the write buffer * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { static const uint8_t start[] = {0xFF, 0xFC}; @@ -557,8 +591,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. - * @retval FALSE the operation was successful. + * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. + * + * @api */ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { static const uint8_t stop[] = {0xFD, 0xFF}; diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index eef5c32ff..824ebae0d 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -58,6 +58,8 @@ * * @param[in] bus the I/O bus, pointer to a @p IOBus structure * @return The bus logical states. + * + * @api */ ioportmask_t palReadBus(IOBus *bus) { @@ -81,6 +83,8 @@ ioportmask_t palReadBus(IOBus *bus) { * @param[in] bits the bits to be written on the I/O bus. Values exceeding * the bus width are masked so most significant bits are * lost. + * + * @api */ void palWriteBus(IOBus *bus, ioportmask_t bits) { @@ -102,6 +106,8 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { * * @param[in] bus the I/O bus, pointer to a @p IOBus structure * @param[in] mode the mode + * + * @api */ void palSetBusMode(IOBus *bus, uint_fast8_t mode) { diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 4b797da0c..f4af775e3 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -48,6 +48,8 @@ /** * @brief PWM Driver initialization. + * + * @init */ void pwmInit(void) { @@ -58,6 +60,8 @@ void pwmInit(void) { * @brief Initializes the standard part of a @p PWMDriver structure. * * @param[in] pwmp pointer to a @p PWMDriver object + * + * @init */ void pwmObjectInit(PWMDriver *pwmp) { @@ -70,6 +74,8 @@ void pwmObjectInit(PWMDriver *pwmp) { * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] config pointer to a @p PWMConfig object + * + * @api */ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { @@ -89,6 +95,8 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { * @brief Deactivates the PWM peripheral. * * @param[in] pwmp pointer to a @p PWMDriver object + * + * @api */ void pwmStop(PWMDriver *pwmp) { @@ -110,6 +118,8 @@ void pwmStop(PWMDriver *pwmp) { * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier * @param[in] width PWM pulse width as clock pulses number + * + * @api */ void pwmEnableChannel(PWMDriver *pwmp, pwmchannel_t channel, @@ -132,6 +142,8 @@ void pwmEnableChannel(PWMDriver *pwmp, * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier + * + * @api */ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 48518e66c..6c47d7fc3 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -99,6 +99,8 @@ static const struct SerialDriverVMT vmt = { /** * @brief Serial Driver initialization. + * + * @init */ void sdInit(void) { @@ -117,6 +119,8 @@ void sdInit(void) { * @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) { @@ -137,6 +141,8 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { * @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) { @@ -157,6 +163,8 @@ void sdStart(SerialDriver *sdp, const SerialConfig *config) { * the message @p Q_RESET. * * @param[in] sdp pointer to a @p SerialDrive object + * + * @api */ void sdStop(SerialDriver *sdp) { @@ -187,6 +195,8 @@ void sdStop(SerialDriver *sdp) { * * @param[in] sdp pointer to a @p SerialDriver structure * @param[in] b the byte to be written in the driver's Input Queue + * + * @iclass */ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { @@ -210,6 +220,8 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { * @return The byte value read from the driver's output queue. * @retval Q_EMPTY if the queue is empty (the lower driver usually * disables the interrupt source when this happens). + * + * @iclass */ msg_t sdRequestDataI(SerialDriver *sdp) { msg_t b; @@ -229,6 +241,8 @@ msg_t sdRequestDataI(SerialDriver *sdp) { * * @param[in] sdp pointer to a @p SerialDriver structure * @param[in] mask condition flags to be added to the mask + * + * @iclass */ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { @@ -244,6 +258,8 @@ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { * @param[in] sdp pointer to a @p SerialDriver structure * @return The condition flags modified since last time this * function was invoked. + * + * @api */ sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { sdflags_t mask; diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 29e69a283..85cb941e6 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -48,6 +48,8 @@ /** * @brief SPI Driver initialization. + * + * @init */ void spiInit(void) { @@ -58,6 +60,8 @@ void spiInit(void) { * @brief Initializes the standard part of a @p SPIDriver structure. * * @param[in] spip pointer to the @p SPIDriver object + * + * @init */ void spiObjectInit(SPIDriver *spip) { @@ -75,6 +79,8 @@ void spiObjectInit(SPIDriver *spip) { * * @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) { @@ -94,6 +100,8 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { * @brief Deactivates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiStop(SPIDriver *spip) { @@ -112,6 +120,8 @@ void spiStop(SPIDriver *spip) { * @brief Asserts the slave select signal and prepares for transfers. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiSelect(SPIDriver *spip) { @@ -132,6 +142,8 @@ void spiSelect(SPIDriver *spip) { * @details The previously selected peripheral is unselected. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiUnselect(SPIDriver *spip) { @@ -155,6 +167,8 @@ void spiUnselect(SPIDriver *spip) { * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored + * + * @api */ void spiIgnore(SPIDriver *spip, size_t n) { @@ -176,6 +190,8 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @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) { @@ -196,6 +212,8 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to send * @param[in] txbuf the pointer to the transmit buffer + * + * @api */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { @@ -216,6 +234,8 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer + * + * @api */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { @@ -233,11 +253,12 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { * @brief Gains exclusive access to the SPI bus. * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] spip pointer to the @p SPIDriver object * + * @api */ void spiAcquireBus(SPIDriver *spip) { @@ -252,10 +273,12 @@ void spiAcquireBus(SPIDriver *spip) { /** * @brief Releases exclusive access to the SPI bus. - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiReleaseBus(SPIDriver *spip) { diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 097bd364b..e984655d4 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -48,6 +48,8 @@ /** * @brief UART Driver initialization. + * + * @init */ void uartInit(void) { @@ -58,6 +60,8 @@ void uartInit(void) { * @brief Initializes the standard part of a @p UARTDriver structure. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @init */ void uartObjectInit(UARTDriver *uartp) { @@ -72,6 +76,8 @@ void uartObjectInit(UARTDriver *uartp) { * * @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) { @@ -93,6 +99,8 @@ void uartStart(UARTDriver *uartp, const UARTConfig *config) { * @brief Deactivates the UART peripheral. * * @param[in] uartp pointer to the @p UARTDriver object + * + * @api */ void uartStop(UARTDriver *uartp) { @@ -119,6 +127,8 @@ void uartStop(UARTDriver *uartp) { * @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) { @@ -145,6 +155,8 @@ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { * @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 + * + * @iclass */ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { @@ -168,6 +180,8 @@ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { * @return The number of data frames not transmitted by the * stopped transmit operation. * @retval 0 There was no transmit operation in progress. + * + * @api */ size_t uartStopSend(UARTDriver *uartp) { size_t n; @@ -199,6 +213,8 @@ size_t uartStopSend(UARTDriver *uartp) { * @return The number of data frames not transmitted by the * stopped transmit operation. * @retval 0 There was no transmit operation in progress. + * + * @iclass */ size_t uartStopSendI(UARTDriver *uartp) { @@ -224,6 +240,8 @@ size_t uartStopSendI(UARTDriver *uartp) { * @param[in] uartp pointer to the @p UARTDriver object * @param[in] n number of data frames to send * @param[in] rxbuf the pointer to the receive buffer + * + * @api */ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { @@ -250,6 +268,8 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { * @param[in] uartp pointer to the @p UARTDriver object * @param[in] n number of data frames to send * @param[in] rxbuf the pointer to the receive buffer + * + * @iclass */ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { @@ -274,6 +294,8 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { * @return The number of data frames not received by the * stopped receive operation. * @retval 0 There was no receive operation in progress. + * + * @api */ size_t uartStopReceive(UARTDriver *uartp) { size_t n; @@ -305,6 +327,8 @@ size_t uartStopReceive(UARTDriver *uartp) { * @return The number of data frames not received by the * stopped receive operation. * @retval 0 There was no receive operation in progress. + * + * @iclass */ size_t uartStopReceiveI(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopReceiveI"); -- cgit v1.2.3 From f407e4a84fcf2cf3bb003ed36f80ec136f8683c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 8 Oct 2010 18:16:38 +0000 Subject: HAL improvements, mailboxes macro name changed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2238 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 4983199ce..1d407d927 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -67,7 +67,6 @@ void adcObjectInit(ADCDriver *adcp) { adcp->ad_state = ADC_STOP; adcp->ad_config = NULL; - adcp->ad_callback = NULL; adcp->ad_samples = NULL; adcp->ad_depth = 0; adcp->ad_grpp = NULL; @@ -142,8 +141,6 @@ void adcStop(ADCDriver *adcp) { * @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. - * @param[in] callback pointer to the conversion callback function, this - * parameter can be @p NULL if a callback is not required * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. @@ -153,12 +150,11 @@ void adcStop(ADCDriver *adcp) { bool_t adcStartConversion(ADCDriver *adcp, const ADCConversionGroup *grpp, adcsample_t *samples, - size_t depth, - adccallback_t callback) { + size_t depth) { bool_t result; chSysLock(); - result = adcStartConversionI(adcp, grpp, samples, depth, callback); + result = adcStartConversionI(adcp, grpp, samples, depth); chSysUnlock(); return result; } @@ -187,8 +183,6 @@ bool_t adcStartConversion(ADCDriver *adcp, * @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. - * @param[in] callback pointer to the conversion callback function, this - * parameter can be @p NULL if a callback is not required * @return The operation status. * @retval FALSE the conversion has been started. * @retval TRUE the driver is busy, conversion not started. @@ -198,8 +192,7 @@ bool_t adcStartConversion(ADCDriver *adcp, bool_t adcStartConversionI(ADCDriver *adcp, const ADCConversionGroup *grpp, adcsample_t *samples, - size_t depth, - adccallback_t callback) { + size_t depth) { chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && ((depth == 1) || ((depth & 1) == 0)), @@ -212,7 +205,6 @@ bool_t adcStartConversionI(ADCDriver *adcp, "invalid state"); if (adcp->ad_state == ADC_RUNNING) return TRUE; - adcp->ad_callback = callback; adcp->ad_samples = samples; adcp->ad_depth = depth; adcp->ad_grpp = grpp; -- cgit v1.2.3 From 70ab312f0f88f24cf1e4f33218cff877c6c0b3c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Oct 2010 15:14:49 +0000 Subject: New SPI driver model (callback based), not complete yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2242 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 96 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 24 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 85cb941e6..cd5857aa9 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -129,11 +129,10 @@ void spiSelect(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), + (spip->spd_state == SPI_SELECTED), "spiSelect(), #1", "not idle"); - spi_lld_select(spip); - spip->spd_state = SPI_ACTIVE; + spiSelectI(spip); chSysUnlock(); } @@ -151,19 +150,48 @@ void spiUnselect(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), + (spip->spd_state == SPI_SELECTED), "spiUnselect(), #1", "not locked"); - spi_lld_unselect(spip); - spip->spd_state = SPI_READY; + spiUnselectI(spip); + chSysUnlock(); +} + +/** + * @brief Emits a train of clock pulses on the SPI bus. + * @details This asynchronous function starts the emission of a train of + * clock pulses without asserting any slave, while this is not + * usually required by the SPI protocol it is required by + * initialization procedure of MMC/SD cards in SPI mode. + * @post At the end of the operation the configured callback is invoked. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be clocked. The number of pulses + * is equal to the number of words multiplied to the + * configured word size in bits. + * + * @api + */ +void spiSynchronize(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSynchronize(), #1", + "not ready"); + + spiSynchronizeI(spip, n); chSysUnlock(); } /** * @brief Ignores data on the SPI bus. - * @details This function transmits a series of idle words on the SPI bus and - * ignores the received data. This function can be invoked even - * when a slave select signal has not been yet asserted. + * @details This asynchronous function starts the transmission of a series of + * idle words on the SPI bus and ignores the received data. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored @@ -173,16 +201,22 @@ void spiUnselect(SPIDriver *spip) { void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); - chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), - "spiIgnore(), #1", - "not active"); - spi_lld_ignore(spip, n); + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiIgnore(), #1", + "not selected"); + spiIgnoreI(spip, n); + chSysUnlock(); } /** * @brief Exchanges data on the SPI bus. - * @details This function performs a simultaneous transmit/receive operation. + * @details This asynchronous function starts a simultaneous transmit/receive + * operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @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. * @@ -197,15 +231,21 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), "spiExchange"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiExchange(), #1", "not active"); - - spi_lld_exchange(spip, n, txbuf, rxbuf); + spiExchangeI(spip, n, txbuf, rxbuf); + chSysUnlock(); } /** - * @brief Sends data ever the SPI bus. + * @brief Sends data over the SPI bus. + * @details This asynchronous function starts a transmit operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @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. * @@ -219,15 +259,21 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), "spiSend"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiSend(), #1", "not active"); - - spi_lld_send(spip, n, txbuf); + spiSendI(spip, n, txbuf); + chSysUnlock(); } /** * @brief Receives data from the SPI bus. + * @details This asynchronous function starts a receive operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @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. * @@ -241,11 +287,13 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), "spiReceive"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiReceive(), #1", "not active"); - - spi_lld_receive(spip, n, rxbuf); + spiReceiveI(spip, n, rxbuf); + chSysUnlock(); } #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From 1c9c40543009ecd95b56362e6564d26a2755b92a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Oct 2010 16:28:34 +0000 Subject: Fixed bug 3084764. More enhancements to the SPI driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2244 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index cd5857aa9..75589c736 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -66,11 +66,16 @@ void spiInit(void) { void spiObjectInit(SPIDriver *spip) { spip->spd_state = SPI_STOP; +#if SPI_USE_WAIT + spip->spd_thread = NULL; +#endif /* SPI_USE_WAIT */ +#if SPI_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES chMtxInit(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES +#else chSemInit(&spip->spd_semaphore, 1); #endif +#endif /* SPI_USE_MUTUAL_EXCLUSION */ spip->spd_config = NULL; } @@ -296,6 +301,64 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chSysUnlock(); } +#if SPI_USE_WAIT || defined(__DOXYGEN__) +/** + * @brief Awakens the thread waiting for operation completion, if any. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @notapi + */ +void _spi_wakeup(SPIDriver *spip) { + + if (spip->spd_thread != NULL) { + Thread *tp = spip->spd_thread; + spip->spd_thread = NULL; + tp->p_u.rdymsg = RDY_RESET; + chSchReadyI(tp); + } +} + +/** + * @brief Wait for operation completion. + * @details This function waits for the driver to complete the current + * operation, if an operation is not running when the function is + * invoked then it immediately returns. + * @note No more than one thread can wait on a SPI driver using + * this function. + * + * @param[in] spip pointer to the @p SPIDriver object + * @return The wait status. + * @retval RDY_OK There was not operation running when the function + * has been invoked. + * @retval RDY_RESET The operation completed. + */ +msg_t spiWait(SPIDriver *spip) { + msg_t msg; + + chDbgCheck(spip != NULL, "spiWait"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_SELECTED) || + (spip->spd_state == SPI_ACTIVE) || + (spip->spd_state == SPI_SYNC), + "spiUnselect(), #1", + "invalid state"); + chDbgAssert(spip->spd_thread == NULL, "spiWait(), #3", "already waiting"); + if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) { + spip->spd_thread = chThdSelf(); + chSchGoSleepS(spip->spd_thread, THD_STATE_SUSPENDED); + msg = chThdSelf()->p_u.rdymsg; + } + else + msg = RDY_OK; + chSysUnlock(); + return msg; +} + +#endif /* SPI_USE_WAIT */ + #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the SPI bus. -- cgit v1.2.3 From 7c2a8e13d969029fb675e67c57349c1deaa09284 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Oct 2010 11:48:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2246 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 7 +- os/hal/src/pwm.c | 3 + os/hal/src/spi.c | 220 +++++++++++++++++++++++++++++++++++++++++++----------- os/hal/src/uart.c | 4 + 4 files changed, 189 insertions(+), 45 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 1a55f53cd..7558d6741 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -65,8 +65,11 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->i2c_state = I2C_STOP; - i2cp->i2c_config = NULL; + i2cp->i2c_state = I2C_STOP; + i2cp->i2c_config = NULL; +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif } /** diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index f4af775e3..978149ff6 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -67,6 +67,9 @@ void pwmObjectInit(PWMDriver *pwmp) { pwmp->pd_state = PWM_STOP; pwmp->pd_config = NULL; +#if defined(PWM_DRIVER_EXT_INIT_HOOK) + PWM_DRIVER_EXT_INIT_HOOK(pwmp); +#endif } /** diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 75589c736..414eb61db 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -77,6 +77,10 @@ void spiObjectInit(SPIDriver *spip) { #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ spip->spd_config = NULL; + /* Optional, user-defined initializer.*/ +#if defined(SPI_DRIVER_EXT_INIT_HOOK) + SPI_DRIVER_EXT_INIT_HOOK(spip); +#endif } /** @@ -165,9 +169,10 @@ void spiUnselect(SPIDriver *spip) { /** * @brief Emits a train of clock pulses on the SPI bus. * @details This asynchronous function starts the emission of a train of - * clock pulses without asserting any slave, while this is not - * usually required by the SPI protocol it is required by - * initialization procedure of MMC/SD cards in SPI mode. + * clock pulses without asserting any slave. + * @note This functionality is not usually required by the SPI protocol + * but it is required by initialization procedure of MMC/SD cards + * in SPI mode. * @post At the end of the operation the configured callback is invoked. * * @param[in] spip pointer to the @p SPIDriver object @@ -179,13 +184,12 @@ void spiUnselect(SPIDriver *spip) { */ void spiSynchronize(SPIDriver *spip, size_t n) { - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgCheck((spip != NULL) && (n > 0), "spiSynchronize"); chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, "spiSynchronize(), #1", "not ready"); - spiSynchronizeI(spip, n); chSysUnlock(); } @@ -240,7 +244,7 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiExchange(), #1", - "not active"); + "not selected"); spiExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -268,7 +272,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiSend(), #1", - "not active"); + "not selected"); spiSendI(spip, n, txbuf); chSysUnlock(); } @@ -296,45 +300,28 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiReceive(), #1", - "not active"); + "not selected"); spiReceiveI(spip, n, rxbuf); chSysUnlock(); } #if SPI_USE_WAIT || defined(__DOXYGEN__) /** - * @brief Awakens the thread waiting for operation completion, if any. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @notapi - */ -void _spi_wakeup(SPIDriver *spip) { - - if (spip->spd_thread != NULL) { - Thread *tp = spip->spd_thread; - spip->spd_thread = NULL; - tp->p_u.rdymsg = RDY_RESET; - chSchReadyI(tp); - } -} - -/** - * @brief Wait for operation completion. + * @brief Waits for operation completion. * @details This function waits for the driver to complete the current * operation, if an operation is not running when the function is * invoked then it immediately returns. + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post On exit the SPI driver is ready to accept more commands. * @note No more than one thread can wait on a SPI driver using * this function. - * + * * @param[in] spip pointer to the @p SPIDriver object - * @return The wait status. - * @retval RDY_OK There was not operation running when the function - * has been invoked. - * @retval RDY_RESET The operation completed. + * + * @api */ -msg_t spiWait(SPIDriver *spip) { - msg_t msg; +void spiWait(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiWait"); @@ -343,20 +330,167 @@ msg_t spiWait(SPIDriver *spip) { (spip->spd_state == SPI_SELECTED) || (spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC), - "spiUnselect(), #1", + "spiWait(), #1", "invalid state"); - chDbgAssert(spip->spd_thread == NULL, "spiWait(), #3", "already waiting"); - if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) { - spip->spd_thread = chThdSelf(); - chSchGoSleepS(spip->spd_thread, THD_STATE_SUSPENDED); - msg = chThdSelf()->p_u.rdymsg; - } - else - msg = RDY_OK; + if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Emits a train of clock pulses on the SPI bus. + * @details This synchronous function performs the emission of a train of + * clock pulses without asserting any slave. + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @note This functionality is not usually required by the SPI protocol + * but it is required by initialization procedure of MMC/SD cards + * in SPI mode. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be clocked. The number of pulses + * is equal to the number of words multiplied to the + * configured word size in bits. + * + * @api + */ +void spiSynchronizeWait(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiSynchronizeWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSynchronizeWait(), #1", + "not ready"); + spiSynchronizeI(spip, n); + spiWaitS(spip); chSysUnlock(); - return msg; } +/** + * @brief Ignores data on the SPI bus. + * @details This synchronous function performs the transmission of a series of + * idle words on the SPI bus and ignores the received data. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + * + * @api + */ +void spiIgnoreWait(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiIgnoreWait(), #1", + "not selected"); + spiIgnoreI(spip, n); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This synchronous function performs a simultaneous transmit/receive + * operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @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 spiExchangeWait(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchangeWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiExchangeWait(), #1", + "not selected"); + spiExchangeI(spip, n, txbuf, rxbuf); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Sends data over the SPI bus. + * @details This synchronous function performs a transmit operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @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 send + * @param[in] txbuf the pointer to the transmit buffer + * + * @api + */ +void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSendWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiSendWait(), #1", + "not selected"); + spiSendI(spip, n, txbuf); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Receives data from the SPI bus. + * @details This synchronous function performs a receive operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @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 receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @api + */ +void spiReceiveWait(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceiveWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiReceiveWait(), #1", + "not selected"); + spiReceiveI(spip, n, rxbuf); + spiWaitS(spip); + chSysUnlock(); +} #endif /* SPI_USE_WAIT */ #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index e984655d4..a2b21f6c8 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -69,6 +69,10 @@ void uartObjectInit(UARTDriver *uartp) { uartp->ud_txstate = UART_TX_IDLE; uartp->ud_rxstate = UART_RX_IDLE; uartp->ud_config = NULL; + /* Optional, user-defined initializer.*/ +#if defined(UART_DRIVER_EXT_INIT_HOOK) + UART_DRIVER_EXT_INIT_HOOK(uartp); +#endif } /** -- cgit v1.2.3 From 441509bc2c585151a5d5974337d6fd2e156eab2a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Oct 2010 18:55:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2247 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 49f75c3cc..76b710a03 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -84,13 +84,13 @@ static void wait(MMCDriver *mmcp) { uint8_t buf[4]; for (i = 0; i < 16; i++) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceiveWait(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; } /* Looks like it is a long wait.*/ while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceiveWait(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -121,7 +121,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[3] = arg >> 8; buf[4] = arg; buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ - spiSend(mmcp->mmc_spip, 6, buf); + spiSendWait(mmcp->mmc_spip, 6, buf); } /** @@ -138,7 +138,7 @@ static uint8_t recvr1(MMCDriver *mmcp) { uint8_t r1[1]; for (i = 0; i < 9; i++) { - spiReceive(mmcp->mmc_spip, 1, r1); + spiReceiveWait(mmcp->mmc_spip, 1, r1); if (r1[0] != 0xFF) return r1[0]; } @@ -178,7 +178,7 @@ static void sync(MMCDriver *mmcp) { spiSelect(mmcp->mmc_spip); while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceiveWait(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -306,7 +306,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { if (mmcp->mmc_state == MMC_INSERTED) { /* Slow clock mode and 128 clock pulses.*/ spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); - spiIgnore(mmcp->mmc_spip, 16); + spiSynchronizeWait(mmcp->mmc_spip, 16); /* SPI mode selection.*/ i = 0; @@ -453,11 +453,11 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chSysUnlock(); for (i = 0; i < MMC_WAIT_DATA; i++) { - spiReceive(mmcp->mmc_spip, 1, buffer); + spiReceiveWait(mmcp->mmc_spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); + spiReceiveWait(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* CRC ignored. */ - spiIgnore(mmcp->mmc_spip, 2); + spiIgnoreWait(mmcp->mmc_spip, 2); return FALSE; } } @@ -493,7 +493,7 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); + spiSendWait(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); /* result = recvr1(mmcp) != 0x00;*/ /* Note, ignored r1 response, it can be not zero, unknown issue.*/ recvr1(mmcp); @@ -568,10 +568,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ - spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ - spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ - spiReceive(mmcp->mmc_spip, 1, b); + spiSendWait(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ + spiSendWait(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiIgnoreWait(mmcp->mmc_spip, 2); /* CRC ignored. */ + spiReceiveWait(mmcp->mmc_spip, 1, b); if ((b[0] & 0x1F) == 0x05) { wait(mmcp); return FALSE; @@ -608,7 +608,7 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(stop), stop); + spiSendWait(mmcp->mmc_spip, sizeof(stop), stop); spiUnselect(mmcp->mmc_spip); chSysLock(); -- cgit v1.2.3 From 935e2fb27f56a3b81d4161d65e116e9da4fe441c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Oct 2010 15:19:15 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2250 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 207 +++++++++++++++++++++++---------------------- os/hal/src/mmc_spi.c | 30 +++---- os/hal/src/spi.c | 234 +++++++++++++++------------------------------------ 3 files changed, 189 insertions(+), 282 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 1d407d927..0d33cde4e 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -71,7 +71,17 @@ void adcObjectInit(ADCDriver *adcp) { adcp->ad_depth = 0; adcp->ad_grpp = NULL; #if ADC_USE_WAIT - chSemInit(&adcp->ad_sem, 0); + adcp->ad_thread = NULL; +#endif /* ADC_USE_WAIT */ +#if ADC_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&adcp->ad_mutex); +#else + chSemInit(&adcp->ad_semaphore, 1); +#endif +#endif /* ADC_USE_MUTUAL_EXCLUSION */ +#if defined(ADC_DRIVER_EXT_INIT_HOOK) + ADC_DRIVER_EXT_INIT_HOOK(adcp); #endif } @@ -89,8 +99,7 @@ void adcStart(ADCDriver *adcp, const ADCConfig *config) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), - "adcStart(), #1", - "invalid state"); + "adcStart(), #1", "invalid state"); adcp->ad_config = config; adc_lld_start(adcp); adcp->ad_state = ADC_READY; @@ -110,8 +119,7 @@ void adcStop(ADCDriver *adcp) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), - "adcStop(), #1", - "invalid state"); + "adcStop(), #1", "invalid state"); adc_lld_stop(adcp); adcp->ad_state = ADC_STOP; chSysUnlock(); @@ -119,18 +127,7 @@ void adcStop(ADCDriver *adcp) { /** * @brief Starts an ADC conversion. - * @details Starts a conversion operation, there are two kind of conversion - * modes: - * - LINEAR, in this mode the buffer is filled once and then - * the conversion stops automatically. - * - CIRCULAR, in this mode the conversion never stops and - * the buffer is filled circularly.
- * During the conversion the callback function is invoked when - * the buffer is 50% filled and when the buffer is 100% filled, - * this way is possible to process the conversion stream in real - * time. This kind of conversion can only be stopped by explicitly - * invoking @p adcStopConversion(). - * . + * @details Starts an asynchronous 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 @@ -141,38 +138,22 @@ void adcStop(ADCDriver *adcp) { * @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 status. - * @retval FALSE the conversion has been started. - * @retval TRUE the driver is busy, conversion not started. * * @api */ -bool_t adcStartConversion(ADCDriver *adcp, - const ADCConversionGroup *grpp, - adcsample_t *samples, - size_t depth) { - bool_t result; +void adcStartConversion(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth) { chSysLock(); - result = adcStartConversionI(adcp, grpp, samples, depth); + adcStartConversionI(adcp, grpp, samples, depth); chSysUnlock(); - return result; } /** * @brief Starts an ADC conversion. - * @details Starts a conversion operation, there are two kind of conversion - * modes: - * - LINEAR, in this mode the buffer is filled once and then - * the conversion stops automatically. - * - CIRCULAR, in this mode the conversion never stops and - * the buffer is filled circularly.
- * During the conversion the callback function is invoked when - * the buffer is 50% filled and when the buffer is 100% filled, - * this way is possible to process the conversion stream in real - * time. This kind of conversion can only be stopped by explicitly - * invoking @p adcStopConversion(). - * . + * @details Starts an asynchronous 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 @@ -183,34 +164,25 @@ bool_t adcStartConversion(ADCDriver *adcp, * @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 status. - * @retval FALSE the conversion has been started. - * @retval TRUE the driver is busy, conversion not started. * * @iclass */ -bool_t adcStartConversionI(ADCDriver *adcp, - const ADCConversionGroup *grpp, - adcsample_t *samples, - size_t depth) { +void adcStartConversionI(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth) { chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || - (adcp->ad_state == ADC_COMPLETE), - "adcStartConversionI(), #1", - "invalid state"); - if (adcp->ad_state == ADC_RUNNING) - return TRUE; + chDbgAssert(adcp->ad_state == ADC_READY, + "adcStartConversionI(), #1", "not ready"); adcp->ad_samples = samples; adcp->ad_depth = depth; adcp->ad_grpp = grpp; + adcp->ad_state = ADC_ACTIVE; adc_lld_start_conversion(adcp); - adcp->ad_state = ADC_RUNNING; - return FALSE; } /** @@ -229,21 +201,15 @@ void adcStopConversion(ADCDriver *adcp) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_ACTIVE) || (adcp->ad_state == ADC_COMPLETE), - "adcStopConversion(), #1", - "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { + "adcStopConversion(), #1", "invalid state"); + if (adcp->ad_state != ADC_READY) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; -#if ADC_USE_WAIT - chSemResetI(&adcp->ad_sem, 0); - chSchRescheduleS(); -#endif + _adc_reset_s(adcp); } - else - adcp->ad_state = ADC_READY; chSysUnlock(); } @@ -262,61 +228,102 @@ void adcStopConversionI(ADCDriver *adcp) { chDbgCheck(adcp != NULL, "adcStopConversionI"); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || + (adcp->ad_state == ADC_ACTIVE) || (adcp->ad_state == ADC_COMPLETE), - "adcStopConversionI(), #1", - "invalid state"); - if (adcp->ad_state == ADC_RUNNING) { + "adcStopConversionI(), #1", "invalid state"); + if (adcp->ad_state != ADC_READY) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; -#if ADC_USE_WAIT - chSemResetI(&adcp->ad_sem, 0); -#endif + _adc_reset_i(adcp); } - else - adcp->ad_state = ADC_READY; } #if ADC_USE_WAIT || defined(__DOXYGEN__) /** - * @brief Waits for completion. - * @details If the conversion is not completed or not yet started then the - * invoking thread waits for a conversion completion event. - * @pre In order to use this function the option @p ADC_USE_WAIT must be - * enabled. + * @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] timeout the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . + * @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 RDY_OK conversion finished. - * @retval RDY_TIMEOUT conversion not finished within the specified time. + * @retval RDY_OK Conversion finished. + * @retval RDY_RESET The conversion has been stopped using + * @p acdStopConversion() or @p acdStopConversionI(), + * the result buffer may contain incorrect data. * - * @init + * @api */ -msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { +msg_t adcConvert(ADCDriver *adcp, + const ADCConversionGroup *grpp, + adcsample_t *samples, + size_t depth) { + msg_t msg; chSysLock(); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_RUNNING) || - (adcp->ad_state == ADC_COMPLETE), - "adcWaitConversion(), #1", - "invalid state"); - if (adcp->ad_state != ADC_COMPLETE) { - if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { - chSysUnlock(); - return RDY_TIMEOUT; - } - } + chDbgAssert(adcp->ad_config->ac_endcb == NULL, + "adcConvert(), #1", "has callback"); + adcStartConversionI(adcp, grpp, samples, depth); + (adcp)->ad_thread = chThdSelf(); + chSchGoSleepS(THD_STATE_SUSPENDED); + msg = chThdSelf()->p_u.rdymsg; chSysUnlock(); - return RDY_OK; + return msg; } #endif /* ADC_USE_WAIT */ +#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the ADC peripheral. + * @details This function tries to gain ownership to the ADC bus, if the bus + * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p ADC_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @api + */ +void adcAcquireBus(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&adcp->ad_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&adcp->ad_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the ADC peripheral. + * @pre In order to use this function the option @p ADC_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @api + */ +void adcReleaseBus(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcReleaseBus"); + +#if CH_USE_MUTEXES + (void)adcp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&adcp->ad_semaphore); +#endif +} +#endif /* ADC_USE_MUTUAL_EXCLUSION */ + #endif /* CH_HAL_USE_ADC */ /** @} */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 76b710a03..49f75c3cc 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -84,13 +84,13 @@ static void wait(MMCDriver *mmcp) { uint8_t buf[4]; for (i = 0; i < 16; i++) { - spiReceiveWait(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; } /* Looks like it is a long wait.*/ while (TRUE) { - spiReceiveWait(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -121,7 +121,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[3] = arg >> 8; buf[4] = arg; buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ - spiSendWait(mmcp->mmc_spip, 6, buf); + spiSend(mmcp->mmc_spip, 6, buf); } /** @@ -138,7 +138,7 @@ static uint8_t recvr1(MMCDriver *mmcp) { uint8_t r1[1]; for (i = 0; i < 9; i++) { - spiReceiveWait(mmcp->mmc_spip, 1, r1); + spiReceive(mmcp->mmc_spip, 1, r1); if (r1[0] != 0xFF) return r1[0]; } @@ -178,7 +178,7 @@ static void sync(MMCDriver *mmcp) { spiSelect(mmcp->mmc_spip); while (TRUE) { - spiReceiveWait(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->mmc_spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -306,7 +306,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { if (mmcp->mmc_state == MMC_INSERTED) { /* Slow clock mode and 128 clock pulses.*/ spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); - spiSynchronizeWait(mmcp->mmc_spip, 16); + spiIgnore(mmcp->mmc_spip, 16); /* SPI mode selection.*/ i = 0; @@ -453,11 +453,11 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chSysUnlock(); for (i = 0; i < MMC_WAIT_DATA; i++) { - spiReceiveWait(mmcp->mmc_spip, 1, buffer); + spiReceive(mmcp->mmc_spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceiveWait(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); + spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* CRC ignored. */ - spiIgnoreWait(mmcp->mmc_spip, 2); + spiIgnore(mmcp->mmc_spip, 2); return FALSE; } } @@ -493,7 +493,7 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { } chSysUnlock(); - spiSendWait(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); + spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); /* result = recvr1(mmcp) != 0x00;*/ /* Note, ignored r1 response, it can be not zero, unknown issue.*/ recvr1(mmcp); @@ -568,10 +568,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { } chSysUnlock(); - spiSendWait(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ - spiSendWait(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ - spiIgnoreWait(mmcp->mmc_spip, 2); /* CRC ignored. */ - spiReceiveWait(mmcp->mmc_spip, 1, b); + spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ + spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ + spiReceive(mmcp->mmc_spip, 1, b); if ((b[0] & 0x1F) == 0x05) { wait(mmcp); return FALSE; @@ -608,7 +608,7 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { } chSysUnlock(); - spiSendWait(mmcp->mmc_spip, sizeof(stop), stop); + spiSend(mmcp->mmc_spip, sizeof(stop), stop); spiUnselect(mmcp->mmc_spip); chSysLock(); diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 414eb61db..fe7b729bd 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -66,6 +66,7 @@ void spiInit(void) { void spiObjectInit(SPIDriver *spip) { spip->spd_state = SPI_STOP; + spip->spd_config = NULL; #if SPI_USE_WAIT spip->spd_thread = NULL; #endif /* SPI_USE_WAIT */ @@ -76,8 +77,6 @@ void spiObjectInit(SPIDriver *spip) { chSemInit(&spip->spd_semaphore, 1); #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ - spip->spd_config = NULL; - /* Optional, user-defined initializer.*/ #if defined(SPI_DRIVER_EXT_INIT_HOOK) SPI_DRIVER_EXT_INIT_HOOK(spip); #endif @@ -97,8 +96,7 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStart(), #1", - "invalid state"); + "spiStart(), #1", "invalid state"); spip->spd_config = config; spi_lld_start(spip); spip->spd_state = SPI_READY; @@ -118,8 +116,7 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStop(), #1", - "invalid state"); + "spiStop(), #1", "invalid state"); spi_lld_stop(spip); spip->spd_state = SPI_STOP; chSysUnlock(); @@ -137,10 +134,8 @@ void spiSelect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiSelect"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED), - "spiSelect(), #1", - "not idle"); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSelect(), #1", "not ready"); spiSelectI(spip); chSysUnlock(); } @@ -157,40 +152,10 @@ void spiUnselect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiUnselect"); - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED), - "spiUnselect(), #1", - "not locked"); - spiUnselectI(spip); - chSysUnlock(); -} - -/** - * @brief Emits a train of clock pulses on the SPI bus. - * @details This asynchronous function starts the emission of a train of - * clock pulses without asserting any slave. - * @note This functionality is not usually required by the SPI protocol - * but it is required by initialization procedure of MMC/SD cards - * in SPI mode. - * @post At the end of the operation the configured callback is invoked. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be clocked. The number of pulses - * is equal to the number of words multiplied to the - * configured word size in bits. - * - * @api - */ -void spiSynchronize(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiSynchronize"); - chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, - "spiSynchronize(), #1", - "not ready"); - spiSynchronizeI(spip, n); + "spiUnselect(), #1", "not ready"); + spiUnselectI(spip); chSysUnlock(); } @@ -207,15 +172,14 @@ void spiSynchronize(SPIDriver *spip, size_t n) { * * @api */ -void spiIgnore(SPIDriver *spip, size_t n) { +void spiStartIgnore(SPIDriver *spip, size_t n) { - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgCheck((spip != NULL) && (n > 0), "spiStartIgnore"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiIgnore(), #1", - "not selected"); - spiIgnoreI(spip, n); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartIgnore(), #1", "not ready"); + spiStartIgnoreI(spip, n); chSysUnlock(); } @@ -236,16 +200,16 @@ void spiIgnore(SPIDriver *spip, size_t n) { * * @api */ -void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { +void spiStartExchange(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchange"); + "spiStartExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiExchange(), #1", - "not selected"); - spiExchangeI(spip, n, txbuf, rxbuf); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartExchange(), #1", "not ready"); + spiStartExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -264,16 +228,15 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { * * @api */ -void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { +void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); + "spiStartSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiSend(), #1", - "not selected"); - spiSendI(spip, n, txbuf); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartSend(), #1", "not ready"); + spiStartSendI(spip, n, txbuf); chSysUnlock(); } @@ -292,107 +255,44 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * * @api */ -void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { +void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceive"); - - chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiReceive(), #1", - "not selected"); - spiReceiveI(spip, n, rxbuf); - chSysUnlock(); -} - -#if SPI_USE_WAIT || defined(__DOXYGEN__) -/** - * @brief Waits for operation completion. - * @details This function waits for the driver to complete the current - * operation, if an operation is not running when the function is - * invoked then it immediately returns. - * @pre In order to use this function the option @p SPI_USE_WAIT must be - * enabled. - * @post On exit the SPI driver is ready to accept more commands. - * @note No more than one thread can wait on a SPI driver using - * this function. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @api - */ -void spiWait(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiWait"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED) || - (spip->spd_state == SPI_ACTIVE) || - (spip->spd_state == SPI_SYNC), - "spiWait(), #1", - "invalid state"); - if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) - spiWaitS(spip); - chSysUnlock(); -} - -/** - * @brief Emits a train of clock pulses on the SPI bus. - * @details This synchronous function performs the emission of a train of - * clock pulses without asserting any slave. - * @pre In order to use this function the option @p SPI_USE_WAIT must be - * enabled. - * @post At the end of the operation the configured callback is invoked. - * @note This functionality is not usually required by the SPI protocol - * but it is required by initialization procedure of MMC/SD cards - * in SPI mode. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be clocked. The number of pulses - * is equal to the number of words multiplied to the - * configured word size in bits. - * - * @api - */ -void spiSynchronizeWait(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiSynchronizeWait"); + "spiStartReceive"); chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, - "spiSynchronizeWait(), #1", - "not ready"); - spiSynchronizeI(spip, n); - spiWaitS(spip); + "spiStartReceive(), #1", "not ready"); + spiStartReceiveI(spip, n, rxbuf); chSysUnlock(); } +#if SPI_USE_WAIT || defined(__DOXYGEN__) /** * @brief Ignores data on the SPI bus. * @details This synchronous function performs the transmission of a series of * idle words on the SPI bus and ignores the received data. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @p NULL). * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored * * @api */ -void spiIgnoreWait(SPIDriver *spip, size_t n) { +void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiIgnoreWait(), #1", - "not selected"); - spiIgnoreI(spip, n); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiIgnore(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiIgnore(), #2", "has callback"); + spiStartIgnoreI(spip, n); + _spi_wait(spip); chSysUnlock(); } @@ -400,11 +300,10 @@ void spiIgnoreWait(SPIDriver *spip, size_t n) { * @brief Exchanges data on the SPI bus. * @details This synchronous function performs a simultaneous transmit/receive * operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @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. * @@ -415,29 +314,29 @@ void spiIgnoreWait(SPIDriver *spip, size_t n) { * * @api */ -void spiExchangeWait(SPIDriver *spip, size_t n, +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchangeWait"); + "spiExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiExchangeWait(), #1", - "not selected"); - spiExchangeI(spip, n, txbuf, rxbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiExchange(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiExchange(), #2", "has callback"); + spiStartExchangeI(spip, n, txbuf, rxbuf); + _spi_wait(spip); chSysUnlock(); } /** * @brief Sends data over the SPI bus. * @details This synchronous function performs a transmit operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @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. * @@ -447,28 +346,28 @@ void spiExchangeWait(SPIDriver *spip, size_t n, * * @api */ -void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSendWait"); + "spiSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiSendWait(), #1", - "not selected"); - spiSendI(spip, n, txbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSend(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiSend(), #2", "has callback"); + spiStartSendI(spip, n, txbuf); + _spi_wait(spip); chSysUnlock(); } /** * @brief Receives data from the SPI bus. * @details This synchronous function performs a receive operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @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. * @@ -478,17 +377,18 @@ void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { * * @api */ -void spiReceiveWait(SPIDriver *spip, size_t n, void *rxbuf) { +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceiveWait"); + "spiReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiReceiveWait(), #1", - "not selected"); - spiReceiveI(spip, n, rxbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiReceive(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiReceive(), #2", "has callback"); + spiStartReceiveI(spip, n, rxbuf); + _spi_wait(spip); chSysUnlock(); } #endif /* SPI_USE_WAIT */ -- cgit v1.2.3 From eaaf043cdab72623a15c957f44496b7bd0bd9873 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Oct 2010 17:59:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2251 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 0d33cde4e..c6968f11b 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -268,8 +268,7 @@ msg_t adcConvert(ADCDriver *adcp, msg_t msg; chSysLock(); - chDbgAssert(adcp->ad_config->ac_endcb == NULL, - "adcConvert(), #1", "has callback"); + chDbgAssert(grpp->acg_endcb == NULL, "adcConvert(), #1", "has callback"); adcStartConversionI(adcp, grpp, samples, depth); (adcp)->ad_thread = chThdSelf(); chSchGoSleepS(THD_STATE_SUSPENDED); -- cgit v1.2.3 From 4fab7c06d1b0c9e61f6106b5b2a5c2c0b5694c34 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 13 Oct 2010 11:45:07 +0000 Subject: ADC, SPI, PWM driver enhancements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 6 +++--- os/hal/src/pwm.c | 10 ++++------ os/hal/src/spi.c | 3 +++ 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index c6968f11b..e18995089 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -176,7 +176,8 @@ void adcStartConversionI(ADCDriver *adcp, ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); - chDbgAssert(adcp->ad_state == ADC_READY, + chDbgAssert((adcp->ad_state == ADC_READY) || + (adcp->ad_state == ADC_COMPLETE), "adcStartConversionI(), #1", "not ready"); adcp->ad_samples = samples; adcp->ad_depth = depth; @@ -201,8 +202,7 @@ void adcStopConversion(ADCDriver *adcp) { chSysLock(); chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_ACTIVE) || - (adcp->ad_state == ADC_COMPLETE), + (adcp->ad_state == ADC_ACTIVE), "adcStopConversion(), #1", "invalid state"); if (adcp->ad_state != ADC_READY) { adc_lld_stop_conversion(adcp); diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 978149ff6..13c77bfc6 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -86,8 +86,7 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { chSysLock(); chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), - "pwmStart(), #1", - "invalid state"); + "pwmStart(), #1", "invalid state"); pwmp->pd_config = config; pwm_lld_start(pwmp); pwmp->pd_state = PWM_READY; @@ -107,8 +106,7 @@ void pwmStop(PWMDriver *pwmp) { chSysLock(); chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), - "pwmStop(), #1", - "invalid state"); + "pwmStop(), #1", "invalid state"); pwm_lld_stop(pwmp); pwmp->pd_state = PWM_STOP; chSysUnlock(); @@ -133,7 +131,7 @@ void pwmEnableChannel(PWMDriver *pwmp, chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, - "pwmEnableChannel(), #1", "invalid state"); + "pwmEnableChannel(), #1", "not ready"); pwm_lld_enable_channel(pwmp, channel, width); chSysUnlock(); } @@ -155,7 +153,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, - "pwmDisableChannel(), #1", "invalid state"); + "pwmDisableChannel(), #1", "not ready"); pwm_lld_disable_channel(pwmp, channel); chSysUnlock(); } diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index fe7b729bd..be5cf9452 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -105,6 +105,8 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { /** * @brief Deactivates the SPI peripheral. + * @note Deactivating the peripheral also enforces a release of the slave + * select line. * * @param[in] spip pointer to the @p SPIDriver object * @@ -117,6 +119,7 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), "spiStop(), #1", "invalid state"); + spi_lld_unselect(spip); spi_lld_stop(spip); spip->spd_state = SPI_STOP; chSysUnlock(); -- cgit v1.2.3 From a122640ac69ce3fb8ae5c6e83d9e3a912bb96c98 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 14 Oct 2010 12:16:41 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2255 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index a1fb237f3..ec907de97 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -81,6 +81,9 @@ void canObjectInit(CANDriver *canp) { /** * @brief Configures and activates the CAN peripheral. + * @note Activating the CAN bus can be a slow operation this this function + * is not atomic, it waits internally for the initialization to + * complete. * * @param[in] canp pointer to the @p CANDriver object * @param[in] config pointer to the @p CANConfig object @@ -95,8 +98,7 @@ void canStart(CANDriver *canp, const CANConfig *config) { chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_STARTING) || (canp->cd_state == CAN_READY), - "canStart(), #1", - "invalid state"); + "canStart(), #1", "invalid state"); while (canp->cd_state == CAN_STARTING) chThdSleepS(1); if (canp->cd_state == CAN_STOP) { @@ -120,8 +122,7 @@ void canStop(CANDriver *canp) { chSysLock(); chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), - "canStop(), #1", - "invalid state"); + "canStop(), #1", "invalid state"); can_lld_stop(canp); chSemResetI(&canp->cd_rxsem, 0); chSemResetI(&canp->cd_txsem, 0); @@ -146,8 +147,8 @@ void canStop(CANDriver *canp) { * . * @return The operation result. * @retval RDY_OK the frame has been queued for transmission. - * @retval RDY_TIMEOUT operation not finished within the specified time. - * @retval RDY_RESET driver stopped while waiting. + * @retval RDY_TIMEOUT The operation has timed out. + * @retval RDY_RESET The driver has been stopped while waiting. * * @api */ @@ -157,8 +158,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), - "canTransmit(), #1", - "invalid state"); + "canTransmit(), #1", "invalid state"); while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); if (msg != RDY_OK) { @@ -187,10 +187,8 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * . * @return The operation result. * @retval RDY_OK a frame has been received and placed in the buffer. - * @retval RDY_TIMEOUT operation not finished within the specified time or - * frame not immediately available if invoked using - * @p TIME_IMMEDIATE. - * @retval RDY_RESET driver stopped while waiting. + * @retval RDY_TIMEOUT The operation has timed out. + * @retval RDY_RESET The driver has been stopped while waiting. * * @api */ @@ -200,8 +198,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), - "canReceive(), #1", - "invalid state"); + "canReceive(), #1", "invalid state"); while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); if (msg != RDY_OK) { @@ -251,8 +248,7 @@ void canSleep(CANDriver *canp) { chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), - "canSleep(), #1", - "invalid state"); + "canSleep(), #1", "invalid state"); if (canp->cd_state == CAN_READY) { can_lld_sleep(canp); canp->cd_state = CAN_SLEEP; @@ -275,8 +271,7 @@ void canWakeup(CANDriver *canp) { chSysLock(); chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), - "canWakeup(), #1", - "invalid state"); + "canWakeup(), #1", "invalid state"); if (canp->cd_state == CAN_SLEEP) { can_lld_wakeup(canp); canp->cd_state = CAN_READY; -- cgit v1.2.3 From d8be44136c1e6d02ee105ac0791f9e6732551fec Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 1 Nov 2010 17:29:56 +0000 Subject: Fixed bug 3100946, renamed HAL switches removing the CH_ part. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2326 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 4 ++-- os/hal/src/can.c | 4 ++-- os/hal/src/hal.c | 20 ++++++++++---------- os/hal/src/i2c.c | 4 ++-- os/hal/src/mac.c | 4 ++-- os/hal/src/mmc_spi.c | 4 ++-- os/hal/src/pal.c | 4 ++-- os/hal/src/pwm.c | 4 ++-- os/hal/src/serial.c | 4 ++-- os/hal/src/spi.c | 4 ++-- os/hal/src/uart.c | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index e18995089..2af890b63 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_ADC || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -323,6 +323,6 @@ void adcReleaseBus(ADCDriver *adcp) { } #endif /* ADC_USE_MUTUAL_EXCLUSION */ -#endif /* CH_HAL_USE_ADC */ +#endif /* HAL_USE_ADC */ /** @} */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index ec907de97..59a7b5dbf 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_CAN || defined(__DOXYGEN__) +#if HAL_USE_CAN || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -282,6 +282,6 @@ void canWakeup(CANDriver *canp) { } #endif /* CAN_USE_SLEEP_MODE */ -#endif /* CH_HAL_USE_CAN */ +#endif /* HAL_USE_CAN */ /** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index c0e3d2c28..4cf145059 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -53,34 +53,34 @@ void halInit(void) { hal_lld_init(); -#if CH_HAL_USE_PAL +#if HAL_USE_PAL palInit(&pal_default_config); #endif -#if CH_HAL_USE_ADC +#if HAL_USE_ADC adcInit(); #endif -#if CH_HAL_USE_CAN +#if HAL_USE_CAN canInit(); #endif -#if CH_HAL_USE_I2C +#if HAL_USE_I2C i2cInit(); #endif -#if CH_HAL_USE_MAC +#if HAL_USE_MAC macInit(); #endif -#if CH_HAL_USE_PWM +#if HAL_USE_PWM pwmInit(); #endif -#if CH_HAL_USE_SERIAL +#if HAL_USE_SERIAL sdInit(); #endif -#if CH_HAL_USE_SPI +#if HAL_USE_SPI spiInit(); #endif -#if CH_HAL_USE_MMC_SPI +#if HAL_USE_MMC_SPI mmcInit(); #endif -#if CH_HAL_USE_UART +#if HAL_USE_UART uartInit(); #endif } diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 7558d6741..b432fa89f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_I2C || defined(__DOXYGEN__) +#if HAL_USE_I2C || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -265,6 +265,6 @@ void i2cReleaseBus(I2CDriver *i2cp) { } #endif /* I2C_USE_MUTUAL_EXCLUSION */ -#endif /* CH_HAL_USE_I2C */ +#endif /* HAL_USE_I2C */ /** @} */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 62340dc31..bed07fbbb 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_MAC || defined(__DOXYGEN__) +#if HAL_USE_MAC || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -209,6 +209,6 @@ bool_t macPollLinkStatus(MACDriver *macp) { return mac_lld_poll_link_status(macp); } -#endif /* CH_HAL_USE_MAC */ +#endif /* HAL_USE_MAC */ /** @} */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 49f75c3cc..813ed9de1 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_MMC_SPI || defined(__DOXYGEN__) +#if HAL_USE_MMC_SPI || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -621,6 +621,6 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { return TRUE; } -#endif /* CH_HAL_USE_MMC_SPI */ +#endif /* HAL_USE_MMC_SPI */ /** @} */ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 824ebae0d..ce7c226e9 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_PAL || defined(__DOXYGEN__) +#if HAL_USE_PAL || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -117,6 +117,6 @@ void palSetBusMode(IOBus *bus, uint_fast8_t mode) { palSetGroupMode(bus->bus_portid, bus->bus_mask, mode); } -#endif /* CH_HAL_USE_PAL */ +#endif /* HAL_USE_PAL */ /** @} */ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 13c77bfc6..95c3f4750 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_PWM || defined(__DOXYGEN__) +#if HAL_USE_PWM || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -158,6 +158,6 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysUnlock(); } -#endif /* CH_HAL_USE_PWM */ +#endif /* HAL_USE_PWM */ /** @} */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 6c47d7fc3..8ec75d000 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SERIAL || defined(__DOXYGEN__) +#if HAL_USE_SERIAL || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -273,6 +273,6 @@ sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { return mask; } -#endif /* CH_HAL_USE_SERIAL */ +#endif /* HAL_USE_SERIAL */ /** @} */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index be5cf9452..4d9749962 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SPI || defined(__DOXYGEN__) +#if HAL_USE_SPI || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -441,6 +441,6 @@ void spiReleaseBus(SPIDriver *spip) { } #endif /* SPI_USE_MUTUAL_EXCLUSION */ -#endif /* CH_HAL_USE_SPI */ +#endif /* HAL_USE_SPI */ /** @} */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index a2b21f6c8..eb771bb7b 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_UART || defined(__DOXYGEN__) +#if HAL_USE_UART || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -349,6 +349,6 @@ size_t uartStopReceiveI(UARTDriver *uartp) { return 0; } -#endif /* CH_HAL_USE_UART */ +#endif /* HAL_USE_UART */ /** @} */ -- cgit v1.2.3 From a2e1f71fc25c29620af68246125f81151f80f733 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Nov 2010 08:55:48 +0000 Subject: Documentation related improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2403 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 95c3f4750..79cc73b30 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -117,7 +117,7 @@ void pwmStop(PWMDriver *pwmp) { * @details Programs (or reprograms) a PWM channel. * * @param[in] pwmp pointer to a @p PWMDriver object - * @param[in] channel PWM channel identifier + * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1]) * @param[in] width PWM pulse width as clock pulses number * * @api @@ -142,7 +142,7 @@ void pwmEnableChannel(PWMDriver *pwmp, * idle state. * * @param[in] pwmp pointer to a @p PWMDriver object - * @param[in] channel PWM channel identifier + * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1]) * * @api */ -- cgit v1.2.3 From 32e43fdb02ddb7582866c29dad5e6c87f3315605 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Nov 2010 13:45:22 +0000 Subject: Fixed bug 3114481. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2409 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 79cc73b30..ecf9eba3f 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -117,8 +117,9 @@ void pwmStop(PWMDriver *pwmp) { * @details Programs (or reprograms) a PWM channel. * * @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 + * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1) + * @param[in] width PWM pulse width as clock pulses number, setting the + * width at zero is equivalent to disabling the channel * * @api */ @@ -132,17 +133,17 @@ void pwmEnableChannel(PWMDriver *pwmp, chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, "pwmEnableChannel(), #1", "not ready"); - pwm_lld_enable_channel(pwmp, channel, width); + pwm_lld_set_channel(pwmp, channel, width); chSysUnlock(); } /** - * @brief Disables a PWM channel. + * @brief Disables a PWM channel. * @details The channel is disabled and its output line returned to the * idle state. * * @param[in] pwmp pointer to a @p PWMDriver object - * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1]) + * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1) * * @api */ @@ -154,7 +155,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, "pwmDisableChannel(), #1", "not ready"); - pwm_lld_disable_channel(pwmp, channel); + pwm_lld_set_channel(pwmp, channel, 0); chSysUnlock(); } -- cgit v1.2.3 From 955425572d170dc100034ce991911854bf600a30 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Nov 2010 21:31:35 +0000 Subject: Had to go back... git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2416 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ecf9eba3f..ec5bd65be 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -118,8 +118,7 @@ void pwmStop(PWMDriver *pwmp) { * * @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, setting the - * width at zero is equivalent to disabling the channel + * @param[in] width PWM pulse width as clock pulses number * * @api */ @@ -133,7 +132,7 @@ void pwmEnableChannel(PWMDriver *pwmp, chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, "pwmEnableChannel(), #1", "not ready"); - pwm_lld_set_channel(pwmp, channel, width); + pwm_lld_enable_channel(pwmp, channel, width); chSysUnlock(); } @@ -155,7 +154,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysLock(); chDbgAssert(pwmp->pd_state == PWM_READY, "pwmDisableChannel(), #1", "not ready"); - pwm_lld_set_channel(pwmp, channel, 0); + pwm_lld_disable_channel(pwmp, channel); chSysUnlock(); } -- cgit v1.2.3 From c852dcb3c960198f49c5fdd8619a6d5d581d9136 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 25 Nov 2010 18:32:45 +0000 Subject: Improved ADC and SPI driver models. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2426 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 4d9749962..d1102cc6e 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -295,7 +295,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiIgnore(), #2", "has callback"); spiStartIgnoreI(spip, n); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -329,7 +329,7 @@ void spiExchange(SPIDriver *spip, size_t n, chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiExchange(), #2", "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -360,7 +360,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiSend(), #2", "has callback"); spiStartSendI(spip, n, txbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -391,7 +391,7 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } #endif /* SPI_USE_WAIT */ -- cgit v1.2.3 From 7aa43aee7029b232c558174bcbdf90e8fbebd57b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Dec 2010 08:31:56 +0000 Subject: Documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2490 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 ++ os/hal/src/can.c | 2 ++ os/hal/src/hal.c | 22 ++++++++++++---------- os/hal/src/i2c.c | 2 ++ os/hal/src/mac.c | 2 ++ os/hal/src/mmc_spi.c | 2 ++ os/hal/src/pwm.c | 2 ++ os/hal/src/serial.c | 2 ++ os/hal/src/spi.c | 2 ++ os/hal/src/uart.c | 2 ++ 10 files changed, 30 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 2af890b63..e057ea425 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -48,6 +48,8 @@ /** * @brief ADC Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 59a7b5dbf..f389380ea 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -48,6 +48,8 @@ /** * @brief CAN Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 4cf145059..beff1c8ad 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -46,6 +46,8 @@ /** * @brief HAL initialization. + * @details This function invokes the low level initialization code then + * initializes all the drivers enabled in the HAL. * * @init */ @@ -53,34 +55,34 @@ void halInit(void) { hal_lld_init(); -#if HAL_USE_PAL +#if HAL_USE_PAL || defined(__DOXYGEN__) palInit(&pal_default_config); #endif -#if HAL_USE_ADC +#if HAL_USE_ADC || defined(__DOXYGEN__) adcInit(); #endif -#if HAL_USE_CAN +#if HAL_USE_CAN || defined(__DOXYGEN__) canInit(); #endif -#if HAL_USE_I2C +#if HAL_USE_I2C || defined(__DOXYGEN__) i2cInit(); #endif -#if HAL_USE_MAC +#if HAL_USE_MAC || defined(__DOXYGEN__) macInit(); #endif -#if HAL_USE_PWM +#if HAL_USE_PWM || defined(__DOXYGEN__) pwmInit(); #endif -#if HAL_USE_SERIAL +#if HAL_USE_SERIAL || defined(__DOXYGEN__) sdInit(); #endif -#if HAL_USE_SPI +#if HAL_USE_SPI || defined(__DOXYGEN__) spiInit(); #endif -#if HAL_USE_MMC_SPI +#if HAL_USE_MMC_SPI || defined(__DOXYGEN__) mmcInit(); #endif -#if HAL_USE_UART +#if HAL_USE_UART || defined(__DOXYGEN__) uartInit(); #endif } diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b432fa89f..429d4b521 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -48,6 +48,8 @@ /** * @brief I2C Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index bed07fbbb..89d6a689b 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -20,6 +20,8 @@ /** * @file mac.c * @brief MAC Driver code. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @addtogroup MAC * @{ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 813ed9de1..f98f3f435 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -194,6 +194,8 @@ static void sync(MMCDriver *mmcp) { /** * @brief MMC over SPI driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ec5bd65be..8a009e3b5 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -48,6 +48,8 @@ /** * @brief PWM Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 8ec75d000..166ca83d3 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -99,6 +99,8 @@ static const struct SerialDriverVMT vmt = { /** * @brief Serial Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index d1102cc6e..966db3de5 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -48,6 +48,8 @@ /** * @brief SPI Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index eb771bb7b..4bed0d71b 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -48,6 +48,8 @@ /** * @brief UART Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ -- cgit v1.2.3 From 7d7d9727f9a280d63157ac9997fe271610f05b1e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 19 Dec 2010 09:13:54 +0000 Subject: STM32 board files and demos now use the new organization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2497 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index beff1c8ad..0913ad7a4 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -47,7 +47,9 @@ /** * @brief HAL initialization. * @details This function invokes the low level initialization code then - * initializes all the drivers enabled in the HAL. + * initializes all the drivers enabled in the HAL. Finally the + * board-specific initialization is performed by invoking + * @p boardInit() (usually defined in @p board.c). * * @init */ @@ -85,6 +87,8 @@ void halInit(void) { #if HAL_USE_UART || defined(__DOXYGEN__) uartInit(); #endif + /* Board specific initialization.*/ + boardInit(); } /** @} */ -- cgit v1.2.3 From 0f395838d3782f0865ead3dacc7c5acb5cfc73f0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Dec 2010 18:25:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2516 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 5 +++-- os/hal/src/can.c | 5 +++-- os/hal/src/mmc_spi.c | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index e057ea425..c5ac7534a 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -91,13 +91,14 @@ void adcObjectInit(ADCDriver *adcp) { * @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 + * @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) { - chDbgCheck((adcp != NULL) && (config != NULL), "adcStart"); + chDbgCheck(adcp != NULL, "adcStart"); chSysLock(); chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), diff --git a/os/hal/src/can.c b/os/hal/src/can.c index f389380ea..22f816e73 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -88,13 +88,14 @@ void canObjectInit(CANDriver *canp) { * complete. * * @param[in] canp pointer to the @p CANDriver object - * @param[in] config pointer to the @p CANConfig object + * @param[in] config pointer to the @p CANConfig object. Depending on + * the implementation the value can be @p NULL. * * @api */ void canStart(CANDriver *canp, const CANConfig *config) { - chDbgCheck((canp != NULL) && (config != NULL), "canStart"); + chDbgCheck(canp != NULL, "canStart"); chSysLock(); chDbgAssert((canp->cd_state == CAN_STOP) || diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index f98f3f435..1004c26c2 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -236,13 +236,13 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, * @brief Configures and activates the MMC peripheral. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] config pointer to the @p MMCConfig object + * @param[in] config pointer to the @p MMCConfig object. Must be @p NULL. * * @api */ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { - chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); + chDbgCheck((mmcp != NULL) && (config == NULL), "mmcStart"); chSysLock(); chDbgAssert(mmcp->mmc_state == MMC_STOP, "mmcStart(), #1", "invalid state"); -- cgit v1.2.3 From f251925785f8c0823aa0a05b3667aa2864f131ff Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 31 Dec 2010 11:41:14 +0000 Subject: Fixed typo. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2559 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 166ca83d3..c769061bb 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -164,7 +164,7 @@ void sdStart(SerialDriver *sdp, const SerialConfig *config) { * @details Any thread waiting on the driver's queues will be awakened with * the message @p Q_RESET. * - * @param[in] sdp pointer to a @p SerialDrive object + * @param[in] sdp pointer to a @p SerialDriver object * * @api */ -- cgit v1.2.3 From 24cb881726f09c6bccba471b40bde76dc27036c7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 4 Jan 2011 15:08:29 +0000 Subject: Documentation related fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2580 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- os/hal/src/can.c | 2 +- os/hal/src/i2c.c | 2 +- os/hal/src/mac.c | 2 +- os/hal/src/mmc_spi.c | 2 +- os/hal/src/pwm.c | 2 +- os/hal/src/spi.c | 2 +- os/hal/src/uart.c | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index c5ac7534a..25cbfe750 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -61,7 +61,7 @@ void adcInit(void) { /** * @brief Initializes the standard part of a @p ADCDriver structure. * - * @param[in] adcp pointer to the @p ADCDriver object + * @param[out] adcp pointer to the @p ADCDriver object * * @init */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 22f816e73..d63cbfd8a 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -61,7 +61,7 @@ void canInit(void) { /** * @brief Initializes the standard part of a @p CANDriver structure. * - * @param[in] canp pointer to the @p CANDriver object + * @param[out] canp pointer to the @p CANDriver object * * @init */ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 429d4b521..2b5971b6f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -61,7 +61,7 @@ void i2cInit(void) { /** * @brief Initializes the standard part of a @p I2CDriver structure. * - * @param[in] i2cp pointer to the @p I2CDriver object + * @param[out] i2cp pointer to the @p I2CDriver object * * @init */ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 89d6a689b..48656a8a3 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -65,7 +65,7 @@ void macInit(void) { /** * @brief Initialize the standard part of a @p MACDriver structure. * - * @param[in] macp pointer to the @p MACDriver object + * @param[out] macp pointer to the @p MACDriver object * * @init */ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 1004c26c2..1b2d930c5 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -206,7 +206,7 @@ void mmcInit(void) { /** * @brief Initializes an instance. * - * @param[in] mmcp pointer to the @p MMCDriver object + * @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 diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 8a009e3b5..cf619e508 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -61,7 +61,7 @@ void pwmInit(void) { /** * @brief Initializes the standard part of a @p PWMDriver structure. * - * @param[in] pwmp pointer to a @p PWMDriver object + * @param[out] pwmp pointer to a @p PWMDriver object * * @init */ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 966db3de5..e99126b9e 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -61,7 +61,7 @@ void spiInit(void) { /** * @brief Initializes the standard part of a @p SPIDriver structure. * - * @param[in] spip pointer to the @p SPIDriver object + * @param[out] spip pointer to the @p SPIDriver object * * @init */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 4bed0d71b..4a21e907f 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -61,7 +61,7 @@ void uartInit(void) { /** * @brief Initializes the standard part of a @p UARTDriver structure. * - * @param[in] uartp pointer to the @p UARTDriver object + * @param[out] uartp pointer to the @p UARTDriver object * * @init */ @@ -273,7 +273,7 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { * * @param[in] uartp pointer to the @p UARTDriver object * @param[in] n number of data frames to send - * @param[in] rxbuf the pointer to the receive buffer + * @param[out] rxbuf the pointer to the receive buffer * * @iclass */ -- cgit v1.2.3 From ff333430f1317247299863b592293faa7799e0a4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 9 Jan 2011 10:10:39 +0000 Subject: Serial driver changes, bug 3153550 fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2625 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 59 +++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 47 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index c769061bb..aafedcc6b 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -89,8 +89,14 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); } +static ioflags_t getflags(void *ip) { + _ch_get_and_clear_flags_impl(ip); +} + static const struct SerialDriverVMT vmt = { - writes, reads, putwouldblock, getwouldblock, putt, gett, writet, readt + writes, reads, putwouldblock, getwouldblock, + putt, gett, writet, readt, + getflags }; /*===========================================================================*/ @@ -127,11 +133,9 @@ void sdInit(void) { void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; - chEvtInit(&sdp->ievent); - chEvtInit(&sdp->oevent); - chEvtInit(&sdp->sevent); + chEvtInit(&sdp->event); + sdp->flags = IO_NO_ERROR; sdp->state = SD_STOP; - sdp->flags = SD_NO_ERROR; chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify); chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify); } @@ -205,9 +209,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { chDbgCheck(sdp != NULL, "sdIncomingDataI"); if (chIQIsEmptyI(&sdp->iqueue)) - chEvtBroadcastI(&sdp->ievent); + chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE); if (chIQPutI(&sdp->iqueue, b) < Q_OK) - sdAddFlagsI(sdp, SD_OVERRUN_ERROR); + chIOAddFlagsI(sdp, SD_OVERRUN_ERROR); } /** @@ -232,49 +236,10 @@ msg_t sdRequestDataI(SerialDriver *sdp) { b = chOQGetI(&sdp->oqueue); if (b < Q_OK) - chEvtBroadcastI(&sdp->oevent); + chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY); return b; } -/** - * @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] sdp pointer to a @p SerialDriver structure - * @param[in] mask condition flags to be added to the mask - * - * @iclass - */ -void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) { - - chDbgCheck(sdp != NULL, "sdAddFlagsI"); - - sdp->flags |= mask; - chEvtBroadcastI(&sdp->sevent); -} - -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] sdp pointer to a @p SerialDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -sdflags_t sdGetAndClearFlags(SerialDriver *sdp) { - sdflags_t mask; - - chDbgCheck(sdp != NULL, "sdGetAndClearFlags"); - - chSysLock(); - mask = sdp->flags; - sdp->flags = SD_NO_ERROR; - chSysUnlock(); - return mask; -} - #endif /* HAL_USE_SERIAL */ /** @} */ -- cgit v1.2.3 From 063c6e138d59529b911235fe537bdefe60e0cfb8 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 25 Jan 2011 18:59:18 +0000 Subject: Initial commit of I2C driver code git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2684 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 163 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 103 insertions(+), 60 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 2b5971b6f..273bb5933 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -54,7 +54,6 @@ * @init */ void i2cInit(void) { - i2c_lld_init(); } @@ -67,8 +66,9 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->i2c_state = I2C_STOP; - i2cp->i2c_config = NULL; + i2cp->id_state = I2C_STOP; + i2cp->id_config = NULL; + i2cp->id_slave_config = NULL; #if defined(I2C_DRIVER_EXT_INIT_HOOK) I2C_DRIVER_EXT_INIT_HOOK(i2cp); #endif @@ -82,17 +82,17 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @api */ -void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { +void i2cStart(I2CDriver *i2cp, I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); chSysLock(); - chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), "i2cStart(), #1", "invalid state"); - i2cp->i2c_config = config; + i2cp->id_config = config; i2c_lld_start(i2cp); - i2cp->i2c_state = I2C_READY; + i2cp->id_state = I2C_READY; chSysUnlock(); } @@ -108,13 +108,56 @@ void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); chSysLock(); - chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), "i2cStop(), #1", "invalid state"); i2c_lld_stop(i2cp); - i2cp->i2c_state = I2C_STOP; + i2cp->id_state = I2C_STOP; chSysUnlock(); } +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, const void *txbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), + "i2cSend"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cSend(), #1", + "not active"); + + //i2c_lld_master_transmit(i2cp, slave_addr1, slave_addr2, n, txbuf); + +} + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, void *rxbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cReceive"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cReceive(), #1", + "not active"); + + //i2c_lld_master_receive(i2cp, slave_addr1, slave_addr2, n, rxbuf); + +} /** * @brief Initiates a master bus transaction. @@ -127,17 +170,17 @@ void i2cStop(I2CDriver *i2cp) { * * @iclass */ -void i2cMasterStartI(I2CDriver *i2cp, - uint16_t header, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); - chDbgAssert(i2cp->i2c_state == I2C_READY, - "i2cMasterStartI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_start(i2cp, header); -} +//void i2cMasterStartI(I2CDriver *i2cp, +// uint16_t header, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); +// chDbgAssert(i2cp->id_state == I2C_READY, +// "i2cMasterStartI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_start(i2cp, header); +//} /** * @brief Terminates a master bus transaction. @@ -147,15 +190,15 @@ void i2cMasterStartI(I2CDriver *i2cp, * * @iclass */ -void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterStopI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_stop(i2cp); -} +//void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterStopI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_stop(i2cp); +//} /** @@ -167,15 +210,15 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { * * @iclass */ -void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterRestartI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_restart(i2cp); -} +//void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterRestartI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_restart(i2cp); +//} /** * @brief Master transmission. @@ -187,17 +230,17 @@ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { * * @iclass */ -void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (n > 0) && - (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterTransmitI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_transmit(i2cp, n, txbuf); -} +//void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (n > 0) && +// (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterTransmitI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_transmit(i2cp, n, txbuf); +//} /** * @brief Master receive. @@ -209,17 +252,17 @@ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, * * @iclass */ -void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (n > 0) && - (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterReceiveI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_receive(i2cp, n, rxbuf); -} +//void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (n > 0) && +// (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterReceiveI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_receive(i2cp, n, rxbuf); +//} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 9c45802837b9053bbe32a8c8d5688cbf8c5d2706 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 25 Jan 2011 21:25:10 +0000 Subject: I2C. Some hy level functions created and tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2686 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 124 ++++++------------------------------------------------- 1 file changed, 12 insertions(+), 112 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 273bb5933..e621c652d 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -115,6 +115,7 @@ void i2cStop(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; chSysUnlock(); } + /** * @brief Sends data ever the I2C bus. * @@ -125,18 +126,18 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbuf the pointer to the transmit buffer * */ -void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, const void *txbuf) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) { - chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), - "i2cSend"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterTransmit"); chDbgAssert(i2cp->id_state == I2C_READY, - "i2cSend(), #1", + "i2cMasterTransmit(), #1", "not active"); - //i2c_lld_master_transmit(i2cp, slave_addr1, slave_addr2, n, txbuf); - + i2c_lld_master_transmit(i2cp, i2cscfg, restart); } + /** * @brief Receives data from the I2C bus. * @@ -147,122 +148,21 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2 * @param[out] rxbuf the pointer to the receive buffer * */ -void i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, void *rxbuf) { +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), - "i2cReceive"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterReceive"); chDbgAssert(i2cp->id_state == I2C_READY, - "i2cReceive(), #1", + "i2cMasterReceive(), #1", "not active"); - //i2c_lld_master_receive(i2cp, slave_addr1, slave_addr2, n, rxbuf); - + i2c_lld_master_receive(i2cp, i2cscfg); } -/** - * @brief Initiates a master bus transaction. - * @details This function sends a start bit followed by an one or two bytes - * header. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] header transaction header - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterStartI(I2CDriver *i2cp, -// uint16_t header, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); -// chDbgAssert(i2cp->id_state == I2C_READY, -// "i2cMasterStartI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_start(i2cp, header); -//} - -/** - * @brief Terminates a master bus transaction. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterStopI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_stop(i2cp); -//} -/** - * @brief Sends a restart bit. - * @details Restart bits are required by some types of I2C transactions. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterRestartI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_restart(i2cp); -//} -/** - * @brief Master transmission. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] n number of bytes to be transmitted - * @param[in] txbuf transmit data buffer pointer - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (n > 0) && -// (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterTransmitI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_transmit(i2cp, n, txbuf); -//} -/** - * @brief Master receive. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] n number of bytes to be transmitted - * @param[in] rxbuf receive data buffer pointer - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (n > 0) && -// (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterReceiveI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_receive(i2cp, n, rxbuf); -//} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 22781883e073a764779a36fe1a0b02baf8f946a0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 30 Jan 2011 19:18:26 +0000 Subject: Merged the USB branch and made the needed adjustments, not tested yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2695 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 10 +- os/hal/src/serial_usb.c | 328 +++++++++++++++++++++++++++++ os/hal/src/usb.c | 541 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 877 insertions(+), 2 deletions(-) create mode 100644 os/hal/src/serial_usb.c create mode 100644 os/hal/src/usb.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 0913ad7a4..bfbaa3e84 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -81,11 +81,17 @@ void halInit(void) { #if HAL_USE_SPI || defined(__DOXYGEN__) spiInit(); #endif +#if HAL_USE_UART || defined(__DOXYGEN__) + uartInit(); +#endif +#if HAL_USE_USB || defined(__DOXYGEN__) + usbInit(); +#endif #if HAL_USE_MMC_SPI || defined(__DOXYGEN__) mmcInit(); #endif -#if HAL_USE_UART || defined(__DOXYGEN__) - uartInit(); +#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) + sduInit(); #endif /* Board specific initialization.*/ boardInit(); diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c new file mode 100644 index 000000000..62a901162 --- /dev/null +++ b/os/hal/src/serial_usb.c @@ -0,0 +1,328 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file serial_usb.c + * @brief Serial over USB Driver code. + * + * @addtogroup SERIAL_USB + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#include "usb_cdc.h" + +#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/* + * Current Line Coding. + */ +static cdc_linecoding_t linecoding = { + {0x00, 0x96, 0x00, 0x00}, /* 38400. */ + LC_STOP_1, LC_PARITY_NONE, 8 +}; + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/* + * Interface implementation. + */ + +static size_t writes(void *ip, const uint8_t *bp, size_t n) { + + return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, + n, TIME_INFINITE); +} + +static size_t reads(void *ip, uint8_t *bp, size_t n) { + + return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, + n, TIME_INFINITE); +} + +static bool_t putwouldblock(void *ip) { + + return chOQIsFullI(&((SerialDriver *)ip)->oqueue); +} + +static bool_t getwouldblock(void *ip) { + + return chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); +} + +static msg_t putt(void *ip, uint8_t b, systime_t timeout) { + + return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, timeout); +} + +static msg_t gett(void *ip, systime_t timeout) { + + return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, timeout); +} + +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { + + return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, time); +} + +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { + + return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); +} + +static ioflags_t getflags(void *ip) { + _ch_get_and_clear_flags_impl(ip); +} + +static const struct SerialUSBDriverVMT vmt = { + writes, reads, putwouldblock, getwouldblock, + putt, gett, writet, readt, + getflags +}; + +/** + * @brief Notification of data removed from the input queue. + */ +static void inotify(GenericQueue *qp) { + SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; + size_t n; + + /* Writes to the input queue can only happen when the queue has been + emptied, then a whole packet is loaded in the queue.*/ + if (chIQIsEmptyI(&sdup->iqueue)) { + + n = usbReadI(sdup->config->usbp, sdup->config->data_available_ep, + sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); + if (n > 0) { + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + chSemSetCounterI(&sdup->iqueue.q_sem, n); + } + } +} + +/** + * @brief Notification of data inserted into the output queue. + */ +static void onotify(GenericQueue *qp) { + SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; + size_t n; + + /* If there is any data in the output queue then it is sent within a + single packet and the queue is emptied.*/ + n = usbWriteI(sdup->config->usbp, sdup->config->data_request_ep, + sdup->oqueue.q_buffer, chOQGetFullI(&sdup->oqueue)); + if (n > 0) { + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); + } +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Serial Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void sduInit(void) { +} + +/** + * @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 + * @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 sduObjectInit(SerialUSBDriver *sdup) { + + sdup->vmt = &vmt; + chEvtInit(&sdup->event); + sdup->flags = IO_NO_ERROR; + sdup->state = SDU_STOP; + chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify); + chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify); + /* This is a dirty trick but those pointers are never used because queues + are accessed in block mode from the low level.*/ + sdup->iqueue.q_wrptr = (uint8_t *)sdup; + sdup->oqueue.q_rdptr = (uint8_t *)sdup; +} + +/** + * @brief Configures and starts the driver. + * + * @param[in] sdup pointer to a @p SerialUSBDriver object + * @param[in] config the serial over USB driver configuration + * + * @api + */ +void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { + + chDbgCheck(sdup != NULL, "sduStart"); + + chSysLock(); + chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), + "sduStart(), #1", + "invalid state"); + sdup->config = config; + usbStart(config->usbp, &config->usb_config); + config->usbp->usb_param = sdup; + sdup->state = SDU_READY; + chSysUnlock(); +} + +/** + * @brief Stops the driver. + * @details Any thread waiting on the driver's queues will be awakened with + * the message @p Q_RESET. + * + * @param[in] sdup pointer to a @p SerialUSBDriver object + * + * @api + */ +void sduStop(SerialUSBDriver *sdup) { + + chDbgCheck(sdup != NULL, "sdStop"); + + chSysLock(); + chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), + "sduStop(), #1", + "invalid state"); + usbStop(sdup->config->usbp); + sdup->state = SDU_STOP; + chSysUnlock(); +} + +/** + * @brief Default requests hook. + * @details Applications wanting to use the Serial over USB driver can use + * this function as requests hook in the USB configuration. + * The following requests are emulated: + * - CDC_GET_LINE_CODING. + * - CDC_SET_LINE_CODING. + * - CDC_SET_CONTROL_LINE_STATE. + * . + */ +bool_t sduRequestsHook(USBDriver *usbp) { + + if ((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { + switch (usbp->usb_setup[1]) { + case CDC_GET_LINE_CODING: + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + return TRUE; + case CDC_SET_LINE_CODING: + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + return TRUE; + case CDC_SET_CONTROL_LINE_STATE: + /* Nothing to do, there are no control lines.*/ + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + default: + return FALSE; + } + } + return FALSE; +} + +/** + * @brief Default data request callback. + * @details The application must use this function as callback for the IN + * data endpoint. + */ +void sduDataRequest(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->usb_param; + size_t n; + + chSysLockFromIsr(); + /* If there is any data in the output queue then it is sent within a + single packet and the queue is emptied.*/ + n = chOQGetFullI(&sdup->oqueue); + if (n > 0) { + n = usbWriteI(usbp, ep, sdup->oqueue.q_buffer, n); + if (n > 0) { + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); + chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + } + } + chSysUnlockFromIsr(); +} + +/** + * @brief Default data available callback. + * @details The application must use this function as callback for the OUT + * data endpoint. + */ +void sduDataAvailable(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->usb_param; + + chSysLockFromIsr(); + /* Writes to the input queue can only happen when the queue has been + emptied, then a whole packet is loaded in the queue.*/ + if (chIQIsEmptyI(&sdup->iqueue)) { + size_t n; + + n = usbReadI(usbp, ep, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); + if (n > 0) { + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + chSemSetCounterI(&sdup->iqueue.q_sem, n); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + } + } + chSysUnlockFromIsr(); +} + +/** + * @brief Default data received callback. + * @details The application must use this function as callback for the IN + * interrupt endpoint. + */ +void sduInterruptRequest(USBDriver *usbp, usbep_t ep) { + + (void)usbp; + (void)ep; +} + +#endif /* HAL_USE_SERIAL */ + +/** @} */ diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c new file mode 100644 index 000000000..c89d5a8e9 --- /dev/null +++ b/os/hal/src/usb.c @@ -0,0 +1,541 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file usb.c + * @brief USB Driver code. + * + * @addtogroup USB + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "usb.h" + +#if HAL_USE_USB || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +static const uint8_t zero_status[] = {0x00, 0x00}; +static const uint8_t active_status[] ={0x00, 0x00}; +static const uint8_t halted_status[] = {0x01, 0x00}; + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/** + * @brief SET ADDRESS transaction callback. + * + * @param[in] usbp pointer to the @p USBDriver object + */ +void set_address(USBDriver *usbp) { + + usbp->usb_address = usbp->usb_setup[2]; + usb_lld_set_address(usbp, usbp->usb_address); + if (usbp->usb_config->uc_event_cb) + usbp->usb_config->uc_event_cb(usbp, USB_EVENT_ADDRESS); + usbp->usb_state = USB_SELECTED; +} + +/** + * @brief Starts a receive phase on the endpoint zero. + * + * @param[in] usbp pointer to the @p USBDriver object + */ +static void start_rx_ep0(USBDriver *usbp) { + + if (usbp->usb_ep0n > 0) { + /* The received data cannot exceed the available amount.*/ + if (usbp->usb_ep0n > usbp->usb_ep0max) + usbp->usb_ep0n = usbp->usb_ep0max; + + /* Determines the maximum amount that can be received using a + single packet.*/ + if (usbp->usb_ep0n > usb_lld_ep0config.uepc_out_maxsize) + usbp->usb_ep0lastsize = usb_lld_ep0config.uepc_out_maxsize; + else + usbp->usb_ep0lastsize = usbp->usb_ep0n; + usbp->usb_ep0state = USB_EP0_RX; + } + else { + /* Sending zero sized status packet.*/ + usb_lld_write(usbp, 0, NULL, 0); + usbp->usb_ep0state = USB_EP0_SENDING_STS; + } +} + +/** + * @brief Starts a transmission phase on the endpoint zero. + * + * @param[in] usbp pointer to the @p USBDriver object + */ +static void start_tx_ep0(USBDriver *usbp) { + + if (usbp->usb_ep0n > 0) { + /* The transmitted data cannot exceed the requested amount.*/ + if (usbp->usb_ep0n > usbp->usb_ep0max) + usbp->usb_ep0n = usbp->usb_ep0max; + + /* Determines the maximum amount that can be transmitted using a + single packet.*/ + if (usbp->usb_ep0n > usb_lld_ep0config.uepc_in_maxsize) + usbp->usb_ep0lastsize = usb_lld_ep0config.uepc_in_maxsize; + else + usbp->usb_ep0lastsize = usbp->usb_ep0n; + + /* Starts transmission.*/ + usb_lld_write(usbp, 0, usbp->usb_ep0next, usbp->usb_ep0lastsize); + usbp->usb_ep0state = USB_EP0_TX; + } + else + usbp->usb_ep0state = USB_EP0_WAITING_STS; +} + +/** + * @brief Standard requests handler. + * @details This is the standard requests default handler, most standard + * requests are handled here, the user can override the standard + * handling using the @p uc_requests_hook_cb hook in the + * @p USBConfig structure. + * + * @param[in] usbp pointer to the @p USBDriver object + * @return The request handling exit code. + * @retval FALSE Request not recognized by the handler or error. + * @retval TRUE Request handled. + */ +static bool_t default_handler(USBDriver *usbp) { + const USBDescriptor *dp; + + /* Decoding the request.*/ + switch (((usbp->usb_setup[0] & (USB_RTYPE_RECIPIENT_MASK | + USB_RTYPE_TYPE_MASK)) | + (usbp->usb_setup[1] << 8))) { + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_STATUS << 8): + /* Just returns the current status word.*/ + usbSetupTransfer(usbp, (uint8_t *)&usbp->usb_status, 2, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_CLEAR_FEATURE << 8): + /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature + number is handled as an error.*/ + if (usbp->usb_setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { + usbp->usb_status &= ~2; + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + } + return FALSE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_FEATURE << 8): + /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature + number is handled as an error.*/ + if (usbp->usb_setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { + usbp->usb_status |= 2; + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + } + return FALSE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_ADDRESS << 8): + /* The handling is posponed to after the status phase in order to allow + the proper completion of the transaction.*/ + usbSetupTransfer(usbp, NULL, 0, set_address); + return TRUE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_DESCRIPTOR << 8): + /* Handling descriptor requests from the host.*/ + dp = usbp->usb_config->uc_get_descriptor_cb( + usbp, usbp->usb_setup[3], usbp->usb_setup[2], + usb_lld_fetch_word(&usbp->usb_setup[4])); + if (dp == NULL) + return FALSE; + usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_CONFIGURATION << 8): + /* Returning the last selected configuration.*/ + usbSetupTransfer(usbp, &usbp->usb_configuration, 1, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_CONFIGURATION << 8): + /* Handling configuration selection from the host.*/ + usbp->usb_configuration = usbp->usb_setup[2]; + if (usbp->usb_configuration == 0) + usbp->usb_state = USB_SELECTED; + else + usbp->usb_state = USB_ACTIVE; + if (usbp->usb_config->uc_event_cb) + usbp->usb_config->uc_event_cb(usbp, USB_EVENT_CONFIGURED); + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8): + case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SYNCH_FRAME << 8): + /* Just sending two zero bytes, the application can change the behavior + using a hook..*/ + usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_GET_STATUS << 8): + /* Sending the EP status.*/ + if (usbp->usb_setup[4] & 0x80) { + switch (usb_lld_get_status_in(usbp, usbp->usb_setup[4] & 0x0F)) { + case EP_STATUS_STALLED: + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); + return TRUE; + case EP_STATUS_ACTIVE: + usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); + return TRUE; + default: + return FALSE; + } + } + else { + switch (usb_lld_get_status_out(usbp, usbp->usb_setup[4] & 0x0F)) { + case EP_STATUS_STALLED: + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); + return TRUE; + case EP_STATUS_ACTIVE: + usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); + return TRUE; + default: + return FALSE; + } + } + case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_CLEAR_FEATURE << 8): + /* Only ENDPOINT_HALT is handled as feature.*/ + if (usbp->usb_setup[2] != USB_FEATURE_ENDPOINT_HALT) + return FALSE; + /* Clearing the EP status, not valid for EP0, it is ignored in that case.*/ + if ((usbp->usb_setup[4] & 0x0F) > 0) { + if (usbp->usb_setup[4] & 0x80) + usb_lld_clear_in(usbp, usbp->usb_setup[4] & 0x0F); + else + usb_lld_clear_out(usbp, usbp->usb_setup[4] & 0x0F); + } + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SET_FEATURE << 8): + /* Only ENDPOINT_HALT is handled as feature.*/ + if (usbp->usb_setup[2] != USB_FEATURE_ENDPOINT_HALT) + return FALSE; + /* Stalling the EP, not valid for EP0, it is ignored in that case.*/ + if ((usbp->usb_setup[4] & 0x0F) > 0) { + if (usbp->usb_setup[4] & 0x80) + usb_lld_stall_in(usbp, usbp->usb_setup[4] & 0x0F); + else + usb_lld_stall_out(usbp, usbp->usb_setup[4] & 0x0F); + } + usbSetupTransfer(usbp, NULL, 0, NULL); + return TRUE; + case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_DESCRIPTOR << 8): + case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_CLEAR_FEATURE << 8): + case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_FEATURE << 8): + case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_INTERFACE << 8): + case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_INTERFACE << 8): + /* All the above requests are not handled here, if you need them then + use the hook mechanism and provide handling.*/ + default: + return FALSE; + } +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief USB Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void usbInit(void) { + + usb_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p USBDriver structure. + * + * @param[out] usbp pointer to the @p USBDriver object + * + * @init + */ +void usbObjectInit(USBDriver *usbp) { + + usbp->usb_state = USB_STOP; + usbp->usb_config = NULL; + usbp->usb_param = NULL; +} + +/** + * @brief Configures and activates the USB peripheral. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] config pointer to the @p USBConfig object + * + * @api + */ +void usbStart(USBDriver *usbp, const USBConfig *config) { + + chDbgCheck((usbp != NULL) && (config != NULL), "usbStart"); + + chSysLock(); + chDbgAssert((usbp->usb_state == USB_STOP) || (usbp->usb_state == USB_READY), + "usbStart(), #1", + "invalid state"); + usbp->usb_config = config; + usb_lld_start(usbp); + usbp->usb_state = USB_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the USB peripheral. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @api + */ +void usbStop(USBDriver *usbp) { + + chDbgCheck(usbp != NULL, "usbStop"); + + chSysLock(); + chDbgAssert((usbp->usb_state == USB_STOP) || (usbp->usb_state == USB_READY), + "usbStop(), #1", + "invalid state"); + usb_lld_stop(usbp); + usbp->usb_state = USB_STOP; + chSysUnlock(); +} + +/** + * @brief Enables an endpoint. + * @details This function enables an endpoint, both IN and/or OUT directions + * depending on the configuration structure. + * @note This function must be invoked in response of a SET_CONFIGURATION + * or SET_INTERFACE message. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] epcp the endpoint configuration + * + * @iclass + */ +void usbEnableEndpointI(USBDriver *usbp, usbep_t ep, + const USBEndpointConfig *epcp) { + + chDbgAssert(usbp->usb_state == USB_ACTIVE, + "usbEnableEndpointI(), #1", "invalid state"); + chDbgAssert(usbp->usb_epc[ep] != NULL, + "usbEnableEndpointI(), #2", "already enabled"); + + /* Logically enabling the endpoint in the USBDriver structure.*/ + usbp->usb_epc[ep] = epcp; + + /* Low level endpoint activation.*/ + usb_lld_enable_endpoint(usbp, ep, epcp); +} + +/** + * @brief Disables all the active endpoints. + * @details This function disables all the active endpoints except the + * endpoint zero. + * @note This function must be invoked in response of a SET_CONFIGURATION + * message with configuration number zero. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @iclass + */ +void usbDisableEndpointsI(USBDriver *usbp) { + unsigned i; + + chDbgAssert(usbp->usb_state == USB_SELECTED, + "usbDisableEndpointsI(), #1", "invalid state"); + + for (i = 1; i <= USB_MAX_ENDPOINTS; i++) + usbp->usb_epc[i] = NULL; + + /* Low level endpoints deactivation.*/ + usb_lld_disable_endpoints(usbp); +} + +/** + * @brief USB reset routine. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @notapi + */ +void _usb_reset(USBDriver *usbp) { + unsigned i; + + usbp->usb_state = USB_READY; + usbp->usb_status = 0; + usbp->usb_address = 0; + usbp->usb_configuration = 0; + + /* Invalidates all endpoints into the USBDriver structure.*/ + for (i = 0; i <= USB_MAX_ENDPOINTS; i++) + usbp->usb_epc[i] = NULL; + + /* EP0 state machine initialization.*/ + usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + + /* Low level reset.*/ + usb_lld_reset(usbp); + + /* Low level endpoint zero activation.*/ + usbp->usb_epc[0] = &usb_lld_ep0config; + usb_lld_enable_endpoint(usbp, 0, &usb_lld_ep0config); +} + +/** + * @brief Default EP0 IN callback. + * @details This function is used by the low level driver as default handler + * for EP0 IN events. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number, always zero + * + * @notapi + */ +void _usb_ep0in(USBDriver *usbp, usbep_t ep) { + + (void)ep; + switch (usbp->usb_ep0state) { + case USB_EP0_TX: + usbp->usb_ep0next += usbp->usb_ep0lastsize; + usbp->usb_ep0max -= usbp->usb_ep0lastsize; + usbp->usb_ep0n -= usbp->usb_ep0lastsize; + + /* The final condition is when the requested size has been transmitted or + when a packet has been sent with size less than the maximum packet + size.*/ + if ((usbp->usb_ep0max == 0) || + (usbp->usb_ep0lastsize < usb_lld_ep0config.uepc_in_maxsize)) + usbp->usb_ep0state = USB_EP0_WAITING_STS; + else { + usbp->usb_ep0lastsize = usbp->usb_ep0n > usb_lld_ep0config.uepc_in_maxsize ? + usb_lld_ep0config.uepc_in_maxsize : usbp->usb_ep0n; + usb_lld_write(usbp, 0, usbp->usb_ep0next, usbp->usb_ep0lastsize); + } + return; + case USB_EP0_SENDING_STS: + if (usbp->usb_ep0endcb) + usbp->usb_ep0endcb(usbp); + + usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + return; + default: + ; + } + /* Error response.*/ + usb_lld_stall_in(usbp, 0); + usb_lld_stall_out(usbp, 0); + if (usbp->usb_config->uc_event_cb) + usbp->usb_config->uc_event_cb(usbp, USB_EVENT_STALLED); + usbp->usb_ep0state = USB_EP0_WAITING_SETUP; +} + +/** + * @brief Default EP0 OUT callback. + * @details This function is used by the low level driver as default handler + * for EP0 OUT events. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number, always zero + * + * @notapi + */ +void _usb_ep0out(USBDriver *usbp, usbep_t ep) { + size_t n, size; + uint8_t buf[1]; + + (void)ep; + switch (usbp->usb_ep0state) { + case USB_EP0_WAITING_SETUP: + /* SETUP packet handling.*/ + n = usb_lld_read(usbp, 0, usbp->usb_setup, 8); + if (n != 8) + break; + + /* First verify if the application has an handler installed for this + request.*/ + if (!(usbp->usb_config->uc_requests_hook_cb) || + !(usbp->usb_config->uc_requests_hook_cb(usbp))) { + /* Invoking the default handler, if this fails then stalls the + endpoint zero as error.*/ + if (((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) || + !default_handler(usbp)) + break; + } + + /* Transfer preparation. The request handler must have populated + correctly the fields usb_ep0next, usb_ep0n and usb_ep0endcb using + the macro usbSetupTransfer().*/ + usbp->usb_ep0max = usb_lld_fetch_word(&usbp->usb_setup[6]); + if ((usbp->usb_setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) + start_tx_ep0(usbp); + else + start_rx_ep0(usbp); + return; + case USB_EP0_RX: + /* Check for buffer overflow.*/ + n = size = usb_lld_get_readable(usbp, 0); + if (n > usbp->usb_ep0n) + n = usbp->usb_ep0n; + /* Fetching received data packet.*/ + n = usb_lld_read(usbp, 0, usbp->usb_ep0next, n); + if (n > usbp->usb_ep0max) + break; + usbp->usb_ep0max -= size; + usbp->usb_ep0n -= n; + usbp->usb_ep0next += n; + if (usbp->usb_ep0max == 0) { + usb_lld_write(usbp, 0, NULL, 0); + usbp->usb_ep0state = USB_EP0_SENDING_STS; + } + return; + case USB_EP0_WAITING_STS: + /* STATUS received packet handling, it must be zero sized.*/ + n = usb_lld_read(usbp, 0, buf, 1); + if (n != 0) + break; + if (usbp->usb_ep0endcb) + usbp->usb_ep0endcb(usbp); + usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + return; + default: + ; + } + /* Error response.*/ + usb_lld_stall_in(usbp, 0); + usb_lld_stall_out(usbp, 0); + if (usbp->usb_config->uc_event_cb) + usbp->usb_config->uc_event_cb(usbp, USB_EVENT_STALLED); + usbp->usb_ep0state = USB_EP0_WAITING_SETUP; +} + +#endif /* HAL_USE_USB */ + +/** @} */ -- cgit v1.2.3 From f4bdefbd11466c09dbf47f3eb680c33987a12172 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 30 Jan 2011 21:19:51 +0000 Subject: I2C. Async transmit done. Need much of testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2697 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index e621c652d..5a0471e0f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -126,7 +126,7 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbuf the pointer to the transmit buffer * */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), "i2cMasterTransmit"); @@ -134,7 +134,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmit(i2cp, i2cscfg, restart); + i2c_lld_master_transmitI(i2cp, i2cscfg); } @@ -156,7 +156,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receive(i2cp, i2cscfg); + i2c_lld_master_receiveI(i2cp, i2cscfg); } -- cgit v1.2.3 From 200f020df922ac84ffc0e0c98c97a193e3180b1f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 5 Feb 2011 09:27:20 +0000 Subject: USB rework, step 1. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2708 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index c89d5a8e9..3cc076443 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -25,6 +25,8 @@ * @{ */ +#include + #include "ch.h" #include "hal.h" #include "usb.h" @@ -75,8 +77,8 @@ static void start_rx_ep0(USBDriver *usbp) { /* Determines the maximum amount that can be received using a single packet.*/ - if (usbp->usb_ep0n > usb_lld_ep0config.uepc_out_maxsize) - usbp->usb_ep0lastsize = usb_lld_ep0config.uepc_out_maxsize; + if (usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_out_maxsize) + usbp->usb_ep0lastsize = usbp->usb_ep[0]->uep_config->uepc_out_maxsize; else usbp->usb_ep0lastsize = usbp->usb_ep0n; usbp->usb_ep0state = USB_EP0_RX; @@ -102,8 +104,8 @@ static void start_tx_ep0(USBDriver *usbp) { /* Determines the maximum amount that can be transmitted using a single packet.*/ - if (usbp->usb_ep0n > usb_lld_ep0config.uepc_in_maxsize) - usbp->usb_ep0lastsize = usb_lld_ep0config.uepc_in_maxsize; + if (usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_in_maxsize) + usbp->usb_ep0lastsize = usbp->usb_ep[0]->uep_config->uepc_in_maxsize; else usbp->usb_ep0lastsize = usbp->usb_ep0n; @@ -294,14 +296,16 @@ void usbObjectInit(USBDriver *usbp) { * @api */ void usbStart(USBDriver *usbp, const USBConfig *config) { + unsigned i; chDbgCheck((usbp != NULL) && (config != NULL), "usbStart"); chSysLock(); chDbgAssert((usbp->usb_state == USB_STOP) || (usbp->usb_state == USB_READY), - "usbStart(), #1", - "invalid state"); + "usbStart(), #1", "invalid state"); usbp->usb_config = config; + for (i = 0; i <= USB_MAX_ENDPOINTS; i++) + usbp->usb_ep[i] = NULL; usb_lld_start(usbp); usbp->usb_state = USB_READY; chSysUnlock(); @@ -336,23 +340,26 @@ void usbStop(USBDriver *usbp) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number + * @param[out] epp pointer to an endpoint state descriptor structure * @param[in] epcp the endpoint configuration * * @iclass */ -void usbEnableEndpointI(USBDriver *usbp, usbep_t ep, - const USBEndpointConfig *epcp) { +void usbInitEndpointI(USBDriver *usbp, usbep_t ep, USBEndpointState *epp, + const USBEndpointConfig *epcp) { chDbgAssert(usbp->usb_state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); - chDbgAssert(usbp->usb_epc[ep] != NULL, - "usbEnableEndpointI(), #2", "already enabled"); + chDbgAssert(usbp->usb_ep[ep] != NULL, + "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ - usbp->usb_epc[ep] = epcp; + memset(epp, 0, sizeof(USBEndpointState)); + epp->uep_config = epcp; + usbp->usb_ep[ep] = epp; /* Low level endpoint activation.*/ - usb_lld_enable_endpoint(usbp, ep, epcp); + usb_lld_init_endpoint(usbp, ep); } /** @@ -373,7 +380,7 @@ void usbDisableEndpointsI(USBDriver *usbp) { "usbDisableEndpointsI(), #1", "invalid state"); for (i = 1; i <= USB_MAX_ENDPOINTS; i++) - usbp->usb_epc[i] = NULL; + usbp->usb_ep[i] = NULL; /* Low level endpoints deactivation.*/ usb_lld_disable_endpoints(usbp); @@ -396,7 +403,7 @@ void _usb_reset(USBDriver *usbp) { /* Invalidates all endpoints into the USBDriver structure.*/ for (i = 0; i <= USB_MAX_ENDPOINTS; i++) - usbp->usb_epc[i] = NULL; + usbp->usb_ep[i] = NULL; /* EP0 state machine initialization.*/ usbp->usb_ep0state = USB_EP0_WAITING_SETUP; @@ -404,9 +411,9 @@ void _usb_reset(USBDriver *usbp) { /* Low level reset.*/ usb_lld_reset(usbp); - /* Low level endpoint zero activation.*/ - usbp->usb_epc[0] = &usb_lld_ep0config; - usb_lld_enable_endpoint(usbp, 0, &usb_lld_ep0config); + /* Endpoint zero initialization.*/ +/* usbp->usb_ep[0].uep_config = &usb_lld_ep0config; + usb_lld_init_endpoint(usbp, 0, &usb_lld_ep0config);*/ } /** @@ -432,11 +439,13 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { when a packet has been sent with size less than the maximum packet size.*/ if ((usbp->usb_ep0max == 0) || - (usbp->usb_ep0lastsize < usb_lld_ep0config.uepc_in_maxsize)) + (usbp->usb_ep0lastsize < usbp->usb_ep[0]->uep_config->uepc_in_maxsize)) usbp->usb_ep0state = USB_EP0_WAITING_STS; else { - usbp->usb_ep0lastsize = usbp->usb_ep0n > usb_lld_ep0config.uepc_in_maxsize ? - usb_lld_ep0config.uepc_in_maxsize : usbp->usb_ep0n; + usbp->usb_ep0lastsize = + usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_in_maxsize ? + usbp->usb_ep[0]->uep_config->uepc_in_maxsize : + usbp->usb_ep0n; usb_lld_write(usbp, 0, usbp->usb_ep0next, usbp->usb_ep0lastsize); } return; -- cgit v1.2.3 From 34f9fdfb6260e91ae827a4b6edd49631c116576a Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 14:53:42 +0000 Subject: I2C. Move barthess driver to backup files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2709 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 215 -------------------------------------------------- os/hal/src/i2c_brts.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 215 deletions(-) delete mode 100644 os/hal/src/i2c.c create mode 100644 os/hal/src/i2c_brts.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c deleted file mode 100644 index 5a0471e0f..000000000 --- a/os/hal/src/i2c.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file i2c.c - * @brief I2C Driver code. - * - * @addtogroup I2C - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * @brief I2C Driver initialization. - * @note This function is implicitly invoked by @p halInit(), there is - * no need to explicitly initialize the driver. - * - * @init - */ -void i2cInit(void) { - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[out] i2cp pointer to the @p I2CDriver object - * - * @init - */ -void i2cObjectInit(I2CDriver *i2cp) { - - i2cp->id_state = I2C_STOP; - i2cp->id_config = NULL; - i2cp->id_slave_config = NULL; -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @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, I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStart(), #1", - "invalid state"); - i2cp->id_config = config; - i2c_lld_start(i2cp); - i2cp->id_state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStop(), #1", - "invalid state"); - i2c_lld_stop(i2cp); - i2cp->id_state = I2C_STOP; - chSysUnlock(); -} - -/** - * @brief Sends data ever the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterTransmit"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", - "not active"); - - i2c_lld_master_transmitI(i2cp, i2cscfg); -} - - -/** - * @brief Receives data from the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * - */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterReceive"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterReceive(), #1", - "not active"); - - i2c_lld_master_receiveI(i2cp, i2cscfg); -} - - - - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - * - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->id_semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->id_semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* HAL_USE_I2C */ - -/** @} */ diff --git a/os/hal/src/i2c_brts.c b/os/hal/src/i2c_brts.c new file mode 100644 index 000000000..5a0471e0f --- /dev/null +++ b/os/hal/src/i2c_brts.c @@ -0,0 +1,215 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2c.c + * @brief I2C Driver code. + * + * @addtogroup I2C + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2C Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void i2cInit(void) { + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[out] i2cp pointer to the @p I2CDriver object + * + * @init + */ +void i2cObjectInit(I2CDriver *i2cp) { + + i2cp->id_state = I2C_STOP; + i2cp->id_config = NULL; + i2cp->id_slave_config = NULL; +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @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, I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStart(), #1", + "invalid state"); + i2cp->id_config = config; + i2c_lld_start(i2cp); + i2cp->id_state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStop(), #1", + "invalid state"); + i2c_lld_stop(i2cp); + i2cp->id_state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterTransmit"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterTransmit(), #1", + "not active"); + + i2c_lld_master_transmitI(i2cp, i2cscfg); +} + + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterReceive"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterReceive(), #1", + "not active"); + + i2c_lld_master_receiveI(i2cp, i2cscfg); +} + + + + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + * + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->id_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->id_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->id_semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* HAL_USE_I2C */ + +/** @} */ -- cgit v1.2.3 From aad95ce0637a96ee81e60c5251a1a5851b6dfb7d Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 14:55:56 +0000 Subject: I2C. Added driver from albi. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2710 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..64bed78eb --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,268 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/** + * @brief I2C Driver initialization. + */ +void i2cInit(void) { + + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cObjectInit(I2CDriver *i2cp) { + chEvtInit(&i2cp->sevent); + i2cp->errors = I2CD_NO_ERROR; + i2cp->state = I2C_STOP; +// i2cp->i2cd_config = NULL; +#if I2C_USE_WAIT + i2cp->thread = NULL; +#endif /* I2C_USE_WAIT */ +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&i2cp->semaphore, 1); +#endif +#endif /* I2C_USE_MUTUAL_EXCLUSION */ +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @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 + */ +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), + "i2cStart(), #1", "invalid state"); + + i2cp->nbit_address = config->nBitAddress; + i2c_lld_start(i2cp); + i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); + i2c_lld_set_opmode(i2cp, config->opMode); + i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + "i2cStop(), #1", "invalid state"); + i2c_lld_stop(i2cp); + i2cp->state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), + "i2cMasterTransmit"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterTransmit(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of bytes to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cMasterReceive"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterReceive(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { + uint16_t slv_addr; + + i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); + return slv_addr; +} + + +/** + * @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); +} + +/** + * @brief Returns and clears the errors mask associated to the driver. + * + * @param[in] i2cp pointer to a @p I2CDriver structure + * @return The condition flags modified since last time this + * function was invoked. + * + * @api + */ +i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { + i2cflags_t mask; + + chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); + + chSysLock(); + mask = i2cp->errors; + i2cp->errors = I2CD_NO_ERROR; + chSysUnlock(); + return mask; +} + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_I2C */ -- cgit v1.2.3 From a74dd37c2cad661eee2070888a55a99e49745b6b Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 18:10:23 +0000 Subject: I2C. Moved Alberto drivers to backup. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2711 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 268 -------------------------------------------------- os/hal/src/i2c_albi.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 268 insertions(+), 268 deletions(-) delete mode 100644 os/hal/src/i2c.c create mode 100644 os/hal/src/i2c_albi.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c deleted file mode 100644 index 64bed78eb..000000000 --- a/os/hal/src/i2c.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/** - * @brief I2C Driver initialization. - */ -void i2cInit(void) { - - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cObjectInit(I2CDriver *i2cp) { - chEvtInit(&i2cp->sevent); - i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_STOP; -// i2cp->i2cd_config = NULL; -#if I2C_USE_WAIT - i2cp->thread = NULL; -#endif /* I2C_USE_WAIT */ -#if I2C_USE_MUTUAL_EXCLUSION -#if CH_USE_MUTEXES - chMtxInit(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemInit(&i2cp->semaphore, 1); -#endif -#endif /* I2C_USE_MUTUAL_EXCLUSION */ -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @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 - */ -void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), - "i2cStart(), #1", "invalid state"); - - i2cp->nbit_address = config->nBitAddress; - i2c_lld_start(i2cp); - i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); - i2c_lld_set_opmode(i2cp, config->opMode); - i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), - "i2cStop(), #1", "invalid state"); - i2c_lld_stop(i2cp); - i2cp->state = I2C_STOP; - chSysUnlock(); -} - -/** - * @brief Sends data ever the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), - "i2cMasterTransmit"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterTransmit(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Receives data from the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of bytes to receive - * @param[out] rxbuf the pointer to the receive buffer - * - */ -void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), - "i2cMasterReceive"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterReceive(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { - uint16_t slv_addr; - - i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); - return slv_addr; -} - - -/** - * @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); -} - -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { - i2cflags_t mask; - - chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); - - chSysLock(); - mask = i2cp->errors; - i2cp->errors = I2CD_NO_ERROR; - chSysUnlock(); - return mask; -} - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* CH_HAL_USE_I2C */ diff --git a/os/hal/src/i2c_albi.c b/os/hal/src/i2c_albi.c new file mode 100644 index 000000000..64bed78eb --- /dev/null +++ b/os/hal/src/i2c_albi.c @@ -0,0 +1,268 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/** + * @brief I2C Driver initialization. + */ +void i2cInit(void) { + + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cObjectInit(I2CDriver *i2cp) { + chEvtInit(&i2cp->sevent); + i2cp->errors = I2CD_NO_ERROR; + i2cp->state = I2C_STOP; +// i2cp->i2cd_config = NULL; +#if I2C_USE_WAIT + i2cp->thread = NULL; +#endif /* I2C_USE_WAIT */ +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&i2cp->semaphore, 1); +#endif +#endif /* I2C_USE_MUTUAL_EXCLUSION */ +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @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 + */ +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), + "i2cStart(), #1", "invalid state"); + + i2cp->nbit_address = config->nBitAddress; + i2c_lld_start(i2cp); + i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); + i2c_lld_set_opmode(i2cp, config->opMode); + i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + "i2cStop(), #1", "invalid state"); + i2c_lld_stop(i2cp); + i2cp->state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), + "i2cMasterTransmit"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterTransmit(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of bytes to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cMasterReceive"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterReceive(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { + uint16_t slv_addr; + + i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); + return slv_addr; +} + + +/** + * @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); +} + +/** + * @brief Returns and clears the errors mask associated to the driver. + * + * @param[in] i2cp pointer to a @p I2CDriver structure + * @return The condition flags modified since last time this + * function was invoked. + * + * @api + */ +i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { + i2cflags_t mask; + + chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); + + chSysLock(); + mask = i2cp->errors; + i2cp->errors = I2CD_NO_ERROR; + chSysUnlock(); + return mask; +} + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_I2C */ -- cgit v1.2.3 From d6f77c1ef14cc6b4636fde34d2025e5f23bc9e36 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 18:22:45 +0000 Subject: I2C. After comparing of two drivers decided to start of importing features from Alberto driver to mine. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2712 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..5a0471e0f --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,215 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2c.c + * @brief I2C Driver code. + * + * @addtogroup I2C + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2C Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void i2cInit(void) { + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[out] i2cp pointer to the @p I2CDriver object + * + * @init + */ +void i2cObjectInit(I2CDriver *i2cp) { + + i2cp->id_state = I2C_STOP; + i2cp->id_config = NULL; + i2cp->id_slave_config = NULL; +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @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, I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStart(), #1", + "invalid state"); + i2cp->id_config = config; + i2c_lld_start(i2cp); + i2cp->id_state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStop(), #1", + "invalid state"); + i2c_lld_stop(i2cp); + i2cp->id_state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterTransmit"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterTransmit(), #1", + "not active"); + + i2c_lld_master_transmitI(i2cp, i2cscfg); +} + + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr1 7-bit address of the slave + * @param[in] slave_addr1 used in 10-bit address mode + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterReceive"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterReceive(), #1", + "not active"); + + i2c_lld_master_receiveI(i2cp, i2cscfg); +} + + + + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + * + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->id_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->id_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->id_semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* HAL_USE_I2C */ + +/** @} */ -- cgit v1.2.3 From 4e68b68d5a799300bcbbfb3fdff0ea584239bcb0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Feb 2011 09:51:16 +0000 Subject: USB rework, step 2. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2714 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 427 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 230 insertions(+), 197 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 3cc076443..d0db0ed5c 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -56,72 +56,18 @@ static const uint8_t halted_status[] = {0x01, 0x00}; */ void set_address(USBDriver *usbp) { - usbp->usb_address = usbp->usb_setup[2]; - usb_lld_set_address(usbp, usbp->usb_address); - if (usbp->usb_config->uc_event_cb) - usbp->usb_config->uc_event_cb(usbp, USB_EVENT_ADDRESS); - usbp->usb_state = USB_SELECTED; -} - -/** - * @brief Starts a receive phase on the endpoint zero. - * - * @param[in] usbp pointer to the @p USBDriver object - */ -static void start_rx_ep0(USBDriver *usbp) { - - if (usbp->usb_ep0n > 0) { - /* The received data cannot exceed the available amount.*/ - if (usbp->usb_ep0n > usbp->usb_ep0max) - usbp->usb_ep0n = usbp->usb_ep0max; - - /* Determines the maximum amount that can be received using a - single packet.*/ - if (usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_out_maxsize) - usbp->usb_ep0lastsize = usbp->usb_ep[0]->uep_config->uepc_out_maxsize; - else - usbp->usb_ep0lastsize = usbp->usb_ep0n; - usbp->usb_ep0state = USB_EP0_RX; - } - else { - /* Sending zero sized status packet.*/ - usb_lld_write(usbp, 0, NULL, 0); - usbp->usb_ep0state = USB_EP0_SENDING_STS; - } -} - -/** - * @brief Starts a transmission phase on the endpoint zero. - * - * @param[in] usbp pointer to the @p USBDriver object - */ -static void start_tx_ep0(USBDriver *usbp) { - - if (usbp->usb_ep0n > 0) { - /* The transmitted data cannot exceed the requested amount.*/ - if (usbp->usb_ep0n > usbp->usb_ep0max) - usbp->usb_ep0n = usbp->usb_ep0max; - - /* Determines the maximum amount that can be transmitted using a - single packet.*/ - if (usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_in_maxsize) - usbp->usb_ep0lastsize = usbp->usb_ep[0]->uep_config->uepc_in_maxsize; - else - usbp->usb_ep0lastsize = usbp->usb_ep0n; - - /* Starts transmission.*/ - usb_lld_write(usbp, 0, usbp->usb_ep0next, usbp->usb_ep0lastsize); - usbp->usb_ep0state = USB_EP0_TX; - } - else - usbp->usb_ep0state = USB_EP0_WAITING_STS; + usbp->address = usbp->setup[2]; + usb_lld_set_address(usbp); + if (usbp->config->event_cb) + usbp->config->event_cb(usbp, USB_EVENT_ADDRESS); + usbp->state = USB_SELECTED; } /** * @brief Standard requests handler. * @details This is the standard requests default handler, most standard * requests are handled here, the user can override the standard - * handling using the @p uc_requests_hook_cb hook in the + * handling using the @p requests_hook_cb hook in the * @p USBConfig structure. * * @param[in] usbp pointer to the @p USBDriver object @@ -133,87 +79,93 @@ static bool_t default_handler(USBDriver *usbp) { const USBDescriptor *dp; /* Decoding the request.*/ - switch (((usbp->usb_setup[0] & (USB_RTYPE_RECIPIENT_MASK | - USB_RTYPE_TYPE_MASK)) | - (usbp->usb_setup[1] << 8))) { + switch (((usbp->setup[0] & (USB_RTYPE_RECIPIENT_MASK | + USB_RTYPE_TYPE_MASK)) | + (usbp->setup[1] << 8))) { case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_STATUS << 8): /* Just returns the current status word.*/ - usbSetupTransfer(usbp, (uint8_t *)&usbp->usb_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_CLEAR_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ - if (usbp->usb_setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { - usbp->usb_status &= ~2; - usbSetupTransfer(usbp, NULL, 0, NULL); + if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { + usbp->status &= ~2; + usbSetupTransfer(usbp, NULL, 0); return TRUE; } return FALSE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ - if (usbp->usb_setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { - usbp->usb_status |= 2; - usbSetupTransfer(usbp, NULL, 0, NULL); + if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { + usbp->status |= 2; + usbSetupTransfer(usbp, NULL, 0); return TRUE; } return FALSE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_ADDRESS << 8): - /* The handling is posponed to after the status phase in order to allow - the proper completion of the transaction.*/ - usbSetupTransfer(usbp, NULL, 0, set_address); + /* The SET_ADDRESS handling can be performed here or postponed after + the status packed depending on the USB_SET_ADDRESS_MODE low + driver setting.*/ +#if USB_SET_ADDRESS_MODE == USB_EARLY_SET_ADDRESS + if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && + (usbp->setup[1] == USB_REQ_SET_ADDRESS)) + set_address(usbp); +#endif + usbSetupTransfer(usbp, NULL, 0); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_DESCRIPTOR << 8): /* Handling descriptor requests from the host.*/ - dp = usbp->usb_config->uc_get_descriptor_cb( - usbp, usbp->usb_setup[3], usbp->usb_setup[2], - usb_lld_fetch_word(&usbp->usb_setup[4])); + dp = usbp->config->get_descriptor_cb( + usbp, usbp->setup[3], usbp->setup[2], + usb_lld_fetch_word(&usbp->setup[4])); if (dp == NULL) return FALSE; - usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); + usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_CONFIGURATION << 8): /* Returning the last selected configuration.*/ - usbSetupTransfer(usbp, &usbp->usb_configuration, 1, NULL); + usbSetupTransfer(usbp, &usbp->configuration, 1); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_CONFIGURATION << 8): /* Handling configuration selection from the host.*/ - usbp->usb_configuration = usbp->usb_setup[2]; - if (usbp->usb_configuration == 0) - usbp->usb_state = USB_SELECTED; + usbp->configuration = usbp->setup[2]; + if (usbp->configuration == 0) + usbp->state = USB_SELECTED; else - usbp->usb_state = USB_ACTIVE; - if (usbp->usb_config->uc_event_cb) - usbp->usb_config->uc_event_cb(usbp, USB_EVENT_CONFIGURED); - usbSetupTransfer(usbp, NULL, 0, NULL); + usbp->state = USB_ACTIVE; + if (usbp->config->event_cb) + usbp->config->event_cb(usbp, USB_EVENT_CONFIGURED); + usbSetupTransfer(usbp, NULL, 0); return TRUE; case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8): case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SYNCH_FRAME << 8): /* Just sending two zero bytes, the application can change the behavior using a hook..*/ - usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)zero_status, 2); return TRUE; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_GET_STATUS << 8): /* Sending the EP status.*/ - if (usbp->usb_setup[4] & 0x80) { - switch (usb_lld_get_status_in(usbp, usbp->usb_setup[4] & 0x0F)) { + if (usbp->setup[4] & 0x80) { + switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: - usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2); return TRUE; case EP_STATUS_ACTIVE: - usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)active_status, 2); return TRUE; default: return FALSE; } } else { - switch (usb_lld_get_status_out(usbp, usbp->usb_setup[4] & 0x0F)) { + switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: - usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2); return TRUE; case EP_STATUS_ACTIVE: - usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); + usbSetupTransfer(usbp, (uint8_t *)active_status, 2); return TRUE; default: return FALSE; @@ -221,29 +173,29 @@ static bool_t default_handler(USBDriver *usbp) { } case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_CLEAR_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ - if (usbp->usb_setup[2] != USB_FEATURE_ENDPOINT_HALT) + if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) return FALSE; /* Clearing the EP status, not valid for EP0, it is ignored in that case.*/ - if ((usbp->usb_setup[4] & 0x0F) > 0) { - if (usbp->usb_setup[4] & 0x80) - usb_lld_clear_in(usbp, usbp->usb_setup[4] & 0x0F); + if ((usbp->setup[4] & 0x0F) > 0) { + if (usbp->setup[4] & 0x80) + usb_lld_clear_in(usbp, usbp->setup[4] & 0x0F); else - usb_lld_clear_out(usbp, usbp->usb_setup[4] & 0x0F); + usb_lld_clear_out(usbp, usbp->setup[4] & 0x0F); } - usbSetupTransfer(usbp, NULL, 0, NULL); + usbSetupTransfer(usbp, NULL, 0); return TRUE; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SET_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ - if (usbp->usb_setup[2] != USB_FEATURE_ENDPOINT_HALT) + if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) return FALSE; /* Stalling the EP, not valid for EP0, it is ignored in that case.*/ - if ((usbp->usb_setup[4] & 0x0F) > 0) { - if (usbp->usb_setup[4] & 0x80) - usb_lld_stall_in(usbp, usbp->usb_setup[4] & 0x0F); + if ((usbp->setup[4] & 0x0F) > 0) { + if (usbp->setup[4] & 0x80) + usb_lld_stall_in(usbp, usbp->setup[4] & 0x0F); else - usb_lld_stall_out(usbp, usbp->usb_setup[4] & 0x0F); + usb_lld_stall_out(usbp, usbp->setup[4] & 0x0F); } - usbSetupTransfer(usbp, NULL, 0, NULL); + usbSetupTransfer(usbp, NULL, 0); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_DESCRIPTOR << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_CLEAR_FEATURE << 8): @@ -282,9 +234,9 @@ void usbInit(void) { */ void usbObjectInit(USBDriver *usbp) { - usbp->usb_state = USB_STOP; - usbp->usb_config = NULL; - usbp->usb_param = NULL; + usbp->state = USB_STOP; + usbp->config = NULL; + usbp->param = NULL; } /** @@ -301,13 +253,13 @@ void usbStart(USBDriver *usbp, const USBConfig *config) { chDbgCheck((usbp != NULL) && (config != NULL), "usbStart"); chSysLock(); - chDbgAssert((usbp->usb_state == USB_STOP) || (usbp->usb_state == USB_READY), + chDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY), "usbStart(), #1", "invalid state"); - usbp->usb_config = config; + usbp->config = config; for (i = 0; i <= USB_MAX_ENDPOINTS; i++) - usbp->usb_ep[i] = NULL; + usbp->ep[i] = NULL; usb_lld_start(usbp); - usbp->usb_state = USB_READY; + usbp->state = USB_READY; chSysUnlock(); } @@ -323,11 +275,10 @@ void usbStop(USBDriver *usbp) { chDbgCheck(usbp != NULL, "usbStop"); chSysLock(); - chDbgAssert((usbp->usb_state == USB_STOP) || (usbp->usb_state == USB_READY), - "usbStop(), #1", - "invalid state"); + chDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY), + "usbStop(), #1", "invalid state"); usb_lld_stop(usbp); - usbp->usb_state = USB_STOP; + usbp->state = USB_STOP; chSysUnlock(); } @@ -348,15 +299,15 @@ void usbStop(USBDriver *usbp) { void usbInitEndpointI(USBDriver *usbp, usbep_t ep, USBEndpointState *epp, const USBEndpointConfig *epcp) { - chDbgAssert(usbp->usb_state == USB_ACTIVE, + chDbgAssert(usbp->state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); - chDbgAssert(usbp->usb_ep[ep] != NULL, + chDbgAssert(usbp->ep[ep] != NULL, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ memset(epp, 0, sizeof(USBEndpointState)); - epp->uep_config = epcp; - usbp->usb_ep[ep] = epp; + epp->config = epcp; + usbp->ep[ep] = epp; /* Low level endpoint activation.*/ usb_lld_init_endpoint(usbp, ep); @@ -376,16 +327,100 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, USBEndpointState *epp, void usbDisableEndpointsI(USBDriver *usbp) { unsigned i; - chDbgAssert(usbp->usb_state == USB_SELECTED, + chDbgAssert(usbp->state == USB_SELECTED, "usbDisableEndpointsI(), #1", "invalid state"); for (i = 1; i <= USB_MAX_ENDPOINTS; i++) - usbp->usb_ep[i] = NULL; + usbp->ep[i] = NULL; /* Low level endpoints deactivation.*/ usb_lld_disable_endpoints(usbp); } +/** + * @brief Starts a receive operation on an OUT endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[out] buf buffer where to copy the endpoint data + * @param[in] n maximum number of bytes to copy in the buffer + * @return The operation status. + * @retval FALSE Receive operation started. + * @retval TRUE Endpoint already receiving. + * + * @iclass + */ +bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, + uint8_t *buf, size_t n) { + + if (usbp->ep[ep]->receiving) + return TRUE; + usbp->ep[ep]->receiving = TRUE; + usb_lld_start_out(usbp, ep, buf, n); + return FALSE; +} + +/** + * @brief Starts a transmit operation on an IN endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] buf buffer where to fetch the endpoint data + * @param[in] n maximum number of bytes to copy + * @return The operation status. + * @retval FALSE Transmit operation started. + * @retval TRUE Endpoint already transmitting. + * + * @iclass + */ +bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, + const uint8_t *buf, size_t n) { + + if (usbp->ep[ep]->transmitting) + return TRUE; + usbp->ep[ep]->transmitting = TRUE; + usb_lld_start_in(usbp, ep, buf, n); + return FALSE; +} + +/** + * @brief Stalls an OUT endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @return The operation status. + * @retval FALSE Endpoint stalled. + * @retval TRUE The endpoint was within a transaction, not stalled. + * + * @iclass + */ +bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { + + if (usbp->ep[ep]->receiving) + return TRUE; + usb_lld_stall_out(usbp, ep); + return FALSE; +} + +/** + * @brief Stalls an IN endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @return The operation status. + * @retval FALSE Endpoint stalled. + * @retval TRUE The endpoint was within a transaction, not stalled. + * + * @iclass + */ +bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) { + + if (usbp->ep[ep]->transmitting) + return TRUE; + usb_lld_stall_in(usbp, ep); + return FALSE; +} + /** * @brief USB reset routine. * @@ -396,24 +431,20 @@ void usbDisableEndpointsI(USBDriver *usbp) { void _usb_reset(USBDriver *usbp) { unsigned i; - usbp->usb_state = USB_READY; - usbp->usb_status = 0; - usbp->usb_address = 0; - usbp->usb_configuration = 0; + usbp->state = USB_READY; + usbp->status = 0; + usbp->address = 0; + usbp->configuration = 0; /* Invalidates all endpoints into the USBDriver structure.*/ for (i = 0; i <= USB_MAX_ENDPOINTS; i++) - usbp->usb_ep[i] = NULL; + usbp->ep[i] = NULL; /* EP0 state machine initialization.*/ - usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + usbp->ep0state = USB_EP0_WAITING_SETUP; /* Low level reset.*/ usb_lld_reset(usbp); - - /* Endpoint zero initialization.*/ -/* usbp->usb_ep[0].uep_config = &usb_lld_ep0config; - usb_lld_init_endpoint(usbp, 0, &usb_lld_ep0config);*/ } /** @@ -427,33 +458,30 @@ void _usb_reset(USBDriver *usbp) { * @notapi */ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { + size_t max; (void)ep; - switch (usbp->usb_ep0state) { + switch (usbp->ep0state) { case USB_EP0_TX: - usbp->usb_ep0next += usbp->usb_ep0lastsize; - usbp->usb_ep0max -= usbp->usb_ep0lastsize; - usbp->usb_ep0n -= usbp->usb_ep0lastsize; - - /* The final condition is when the requested size has been transmitted or - when a packet has been sent with size less than the maximum packet - size.*/ - if ((usbp->usb_ep0max == 0) || - (usbp->usb_ep0lastsize < usbp->usb_ep[0]->uep_config->uepc_in_maxsize)) - usbp->usb_ep0state = USB_EP0_WAITING_STS; - else { - usbp->usb_ep0lastsize = - usbp->usb_ep0n > usbp->usb_ep[0]->uep_config->uepc_in_maxsize ? - usbp->usb_ep[0]->uep_config->uepc_in_maxsize : - usbp->usb_ep0n; - usb_lld_write(usbp, 0, usbp->usb_ep0next, usbp->usb_ep0lastsize); - } + max = usb_lld_fetch_word(&usbp->setup[6]); + /* If the transmitted size is less than the requested size and it is a + multiple of the maximum packet size then a zero size packet must be + transmitted.*/ + if ((usbp->ep0n < max) && + ((usbp->ep0n % usbp->ep[0]->config->in_maxsize) == 0)) { + usb_lld_start_in(usbp, 0, NULL, 0); + return; + } + usbp->ep0state = USB_EP0_WAITING_STS; + usb_lld_start_out(usbp, 0, NULL, 0); return; case USB_EP0_SENDING_STS: - if (usbp->usb_ep0endcb) - usbp->usb_ep0endcb(usbp); - - usbp->usb_ep0state = USB_EP0_WAITING_SETUP; +#if USB_SET_ADDRESS_MODE == USB_LATE_SET_ADDRESS + if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && + (usbp->setup[1] == USB_REQ_SET_ADDRESS)) + set_address(usbp); +#endif + usbp->ep0state = USB_EP0_WAITING_SETUP; return; default: ; @@ -461,9 +489,9 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { /* Error response.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); - if (usbp->usb_config->uc_event_cb) - usbp->usb_config->uc_event_cb(usbp, USB_EVENT_STALLED); - usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + if (usbp->config->event_cb) + usbp->config->event_cb(usbp, USB_EVENT_STALLED); + usbp->ep0state = USB_EP0_WAITING_SETUP; } /** @@ -477,62 +505,67 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { * @notapi */ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { - size_t n, size; - uint8_t buf[1]; + size_t n, max; (void)ep; - switch (usbp->usb_ep0state) { + switch (usbp->ep0state) { case USB_EP0_WAITING_SETUP: - /* SETUP packet handling.*/ - n = usb_lld_read(usbp, 0, usbp->usb_setup, 8); - if (n != 8) - break; - - /* First verify if the application has an handler installed for this + /* SETUP packet handling. + First verify if the application has an handler installed for this request.*/ - if (!(usbp->usb_config->uc_requests_hook_cb) || - !(usbp->usb_config->uc_requests_hook_cb(usbp))) { + if (!(usbp->config->requests_hook_cb) || + !(usbp->config->requests_hook_cb(usbp))) { /* Invoking the default handler, if this fails then stalls the endpoint zero as error.*/ - if (((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) || + if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) || !default_handler(usbp)) break; } /* Transfer preparation. The request handler must have populated - correctly the fields usb_ep0next, usb_ep0n and usb_ep0endcb using + correctly the fields ep0next, ep0n and ep0endcb using the macro usbSetupTransfer().*/ - usbp->usb_ep0max = usb_lld_fetch_word(&usbp->usb_setup[6]); - if ((usbp->usb_setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) - start_tx_ep0(usbp); - else - start_rx_ep0(usbp); + max = usb_lld_fetch_word(&usbp->setup[6]); + /* The transfer size cannot exceed the specified amount.*/ + if (usbp->ep0n > max) + usbp->ep0n = max; + if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) { + /* IN phase.*/ + if (usbp->ep0n > 0) { + /* Starts transmission.*/ + usbp->ep0state = USB_EP0_TX; + usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); + } + else { + /* Receiving the zero sized status packet.*/ + usbp->ep0state = USB_EP0_WAITING_STS; + usb_lld_start_out(usbp, 0, NULL, 0); + } + } + else { + /* OUT phase.*/ + if (usbp->ep0n > 0) { + /* Starts reception.*/ + usbp->ep0state = USB_EP0_RX; + usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); + } + else { + /* Sending zero sized status packet.*/ + usbp->ep0state = USB_EP0_SENDING_STS; + usb_lld_start_in(usbp, 0, NULL, 0); + } + } return; case USB_EP0_RX: - /* Check for buffer overflow.*/ - n = size = usb_lld_get_readable(usbp, 0); - if (n > usbp->usb_ep0n) - n = usbp->usb_ep0n; - /* Fetching received data packet.*/ - n = usb_lld_read(usbp, 0, usbp->usb_ep0next, n); - if (n > usbp->usb_ep0max) - break; - usbp->usb_ep0max -= size; - usbp->usb_ep0n -= n; - usbp->usb_ep0next += n; - if (usbp->usb_ep0max == 0) { - usb_lld_write(usbp, 0, NULL, 0); - usbp->usb_ep0state = USB_EP0_SENDING_STS; - } + usbp->ep0state = USB_EP0_SENDING_STS; + usb_lld_start_in(usbp, 0, NULL, 0); return; case USB_EP0_WAITING_STS: /* STATUS received packet handling, it must be zero sized.*/ - n = usb_lld_read(usbp, 0, buf, 1); + n = usbp->ep[0]->rxsize; if (n != 0) break; - if (usbp->usb_ep0endcb) - usbp->usb_ep0endcb(usbp); - usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + usbp->ep0state = USB_EP0_WAITING_SETUP; return; default: ; @@ -540,9 +573,9 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { /* Error response.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); - if (usbp->usb_config->uc_event_cb) - usbp->usb_config->uc_event_cb(usbp, USB_EVENT_STALLED); - usbp->usb_ep0state = USB_EP0_WAITING_SETUP; + if (usbp->config->event_cb) + usbp->config->event_cb(usbp, USB_EVENT_STALLED); + usbp->ep0state = USB_EP0_WAITING_SETUP; } #endif /* HAL_USE_USB */ -- cgit v1.2.3 From 100573d2c30750a50c3dfd9f3e7a051dcc987724 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Feb 2011 13:51:08 +0000 Subject: Serial over USB changes, work in progress, the USB demo is not buildable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2717 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 62a901162..60976eca2 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -206,7 +206,7 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { "invalid state"); sdup->config = config; usbStart(config->usbp, &config->usb_config); - config->usbp->usb_param = sdup; + config->usbp->param = sdup; sdup->state = SDU_READY; chSysUnlock(); } @@ -245,17 +245,17 @@ void sduStop(SerialUSBDriver *sdup) { */ bool_t sduRequestsHook(USBDriver *usbp) { - if ((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { - switch (usbp->usb_setup[1]) { + if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { + switch (usbp->setup[1]) { case CDC_GET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); return TRUE; case CDC_SET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); return TRUE; case CDC_SET_CONTROL_LINE_STATE: /* Nothing to do, there are no control lines.*/ - usbSetupTransfer(usbp, NULL, 0, NULL); + usbSetupTransfer(usbp, NULL, 0); return TRUE; default: return FALSE; @@ -265,12 +265,12 @@ bool_t sduRequestsHook(USBDriver *usbp) { } /** - * @brief Default data request callback. + * @brief Default data transmitted callback. * @details The application must use this function as callback for the IN * data endpoint. */ -void sduDataRequest(USBDriver *usbp, usbep_t ep) { - SerialUSBDriver *sdup = usbp->usb_param; +void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->param; size_t n; chSysLockFromIsr(); @@ -289,12 +289,12 @@ void sduDataRequest(USBDriver *usbp, usbep_t ep) { } /** - * @brief Default data available callback. + * @brief Default data received callback. * @details The application must use this function as callback for the OUT * data endpoint. */ -void sduDataAvailable(USBDriver *usbp, usbep_t ep) { - SerialUSBDriver *sdup = usbp->usb_param; +void sduDataReceived(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->param; chSysLockFromIsr(); /* Writes to the input queue can only happen when the queue has been @@ -317,7 +317,7 @@ void sduDataAvailable(USBDriver *usbp, usbep_t ep) { * @details The application must use this function as callback for the IN * interrupt endpoint. */ -void sduInterruptRequest(USBDriver *usbp, usbep_t ep) { +void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep) { (void)usbp; (void)ep; -- cgit v1.2.3 From 77934792d53efe99678286bab123c42c546478a7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 Feb 2011 16:36:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2722 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 21 +++++++------- os/hal/src/usb.c | 76 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 17 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 60976eca2..29aec2650 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -119,9 +119,9 @@ static void inotify(GenericQueue *qp) { emptied, then a whole packet is loaded in the queue.*/ if (chIQIsEmptyI(&sdup->iqueue)) { - n = usbReadI(sdup->config->usbp, sdup->config->data_available_ep, - sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); - if (n > 0) { + n = usbReadPacketI(sdup->config->usbp, sdup->config->data_available_ep, + sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); + if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; chSemSetCounterI(&sdup->iqueue.q_sem, n); } @@ -137,9 +137,9 @@ static void onotify(GenericQueue *qp) { /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ - n = usbWriteI(sdup->config->usbp, sdup->config->data_request_ep, - sdup->oqueue.q_buffer, chOQGetFullI(&sdup->oqueue)); - if (n > 0) { + n = usbWritePacketI(sdup->config->usbp, sdup->config->data_request_ep, + sdup->oqueue.q_buffer, chOQGetFullI(&sdup->oqueue)); + if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); } @@ -278,8 +278,8 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); if (n > 0) { - n = usbWriteI(usbp, ep, sdup->oqueue.q_buffer, n); - if (n > 0) { + n = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); + if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); @@ -302,8 +302,9 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { if (chIQIsEmptyI(&sdup->iqueue)) { size_t n; - n = usbReadI(usbp, ep, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); - if (n > 0) { + n = usbReadPacketI(usbp, ep, sdup->iqueue.q_buffer, + SERIAL_USB_BUFFERS_SIZE); + if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; chSemSetCounterI(&sdup->iqueue.q_sem, n); chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index d0db0ed5c..afec3c645 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -337,16 +337,74 @@ void usbDisableEndpointsI(USBDriver *usbp) { usb_lld_disable_endpoints(usbp); } +/** + * @brief Reads a packet from the dedicated packet buffer. + * @pre In order to use this function he endpoint must have been + * initialized in packet mode. + * @post The endpoint is ready to accept another packet. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[out] buf buffer where to copy the packet data + * @param[in] n maximum number of bytes to copy. This value must + * not exceed the maximum packet size for this endpoint. + * @return The received packet size regardless the specified + * @p n parameter. + * @retval USB_ENDPOINT_BUSY Endpoint busy receiving. + * @retval 0 Zero size packet received. + * + * @iclass + */ +size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, + uint8_t *buf, size_t n) { + + if (usbp->ep[ep]->receiving) + return USB_ENDPOINT_BUSY; + + return usb_lld_read_packet(usbp, ep, buf, n);; +} + +/** + * @brief Writes a packet to the dedicated packet buffer. + * @pre In order to use this function he endpoint must have been + * initialized in packet mode. + * @post The endpoint is ready to transmit the packet. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] buf buffer where to fetch the packet data + * @param[in] n maximum number of bytes to copy. This value must + * not exceed the maximum packet size for this endpoint. + * @return The operation status. + * @retval USB_ENDPOINT_BUSY Endpoint busy transmitting. + * @retval 0 Operation complete. + * + * @iclass + */ +size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, + const uint8_t *buf, size_t n) { + + if (usbp->ep[ep]->transmitting) + return USB_ENDPOINT_BUSY; + + usb_lld_write_packet(usbp, ep, buf, n); + return 0; +} + /** * @brief Starts a receive operation on an OUT endpoint. + * @pre In order to use this function he endpoint must have been + * initialized in transaction mode. + * @post The endpoint callback is invoked when the transfer has been + * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[out] buf buffer where to copy the endpoint data - * @param[in] n maximum number of bytes to copy in the buffer + * @param[out] buf buffer where to copy the received data + * @param[in] n maximum number of bytes to copy * @return The operation status. - * @retval FALSE Receive operation started. - * @retval TRUE Endpoint already receiving. + * @retval FALSE Operation complete. + * @retval TRUE Endpoint busy receiving. * * @iclass */ @@ -362,14 +420,18 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, /** * @brief Starts a transmit operation on an IN endpoint. + * @pre In order to use this function he endpoint must have been + * initialized in transaction mode. + * @post The endpoint callback is invoked when the transfer has been + * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[in] buf buffer where to fetch the endpoint data + * @param[in] buf buffer where to fetch the data to be transmitted * @param[in] n maximum number of bytes to copy * @return The operation status. - * @retval FALSE Transmit operation started. - * @retval TRUE Endpoint already transmitting. + * @retval FALSE Operation complete. + * @retval TRUE Endpoint busy transmitting. * * @iclass */ -- cgit v1.2.3 From 76bac6bb8704e039a7f9e4b34da7af3bd909c2bd Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 9 Feb 2011 19:33:19 +0000 Subject: I2C. Added own slave address handling and error callback. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2723 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 5a0471e0f..04af9a6c2 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -161,9 +161,6 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3 From 400bb2ae040d1b78f53bf7eb08f68c8b9d8c56c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 Feb 2011 20:41:39 +0000 Subject: USB CDC demo working. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2725 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index afec3c645..08fa52a3e 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -361,6 +361,7 @@ size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, if (usbp->ep[ep]->receiving) return USB_ENDPOINT_BUSY; + usbp->ep[ep]->receiving = TRUE; return usb_lld_read_packet(usbp, ep, buf, n);; } @@ -387,6 +388,7 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, if (usbp->ep[ep]->transmitting) return USB_ENDPOINT_BUSY; + usbp->ep[ep]->transmitting = TRUE; usb_lld_write_packet(usbp, ep, buf, n); return 0; } -- cgit v1.2.3 From bbc2b91e9c2b438c97a2412b862f58a914d72394 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 Feb 2011 20:51:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2726 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 29aec2650..430218edb 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -124,6 +124,7 @@ static void inotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; chSemSetCounterI(&sdup->iqueue.q_sem, n); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); } } } @@ -142,6 +143,7 @@ static void onotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); + chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); } } -- cgit v1.2.3 From d749ecc10a40b21a22b3e7ab14ff9861fabe4685 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 12 Feb 2011 11:54:15 +0000 Subject: RAM optimization to the USB driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2732 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 4 ++-- os/hal/src/usb.c | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 430218edb..b17669c04 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -124,7 +124,7 @@ static void inotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; chSemSetCounterI(&sdup->iqueue.q_sem, n); - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); +// chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); } } } @@ -143,7 +143,7 @@ static void onotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); - chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); +// chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); } } diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 08fa52a3e..cbbe8f5b3 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -234,9 +234,11 @@ void usbInit(void) { */ void usbObjectInit(USBDriver *usbp) { - usbp->state = USB_STOP; - usbp->config = NULL; - usbp->param = NULL; + usbp->state = USB_STOP; + usbp->config = NULL; + usbp->param = NULL; + usbp->transmitting = 0; + usbp->receiving = 0; } /** @@ -358,10 +360,10 @@ void usbDisableEndpointsI(USBDriver *usbp) { size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { - if (usbp->ep[ep]->receiving) + if (usbGetReceiveStatusI(usbp, ep)) return USB_ENDPOINT_BUSY; - usbp->ep[ep]->receiving = TRUE; + usbp->receiving |= (1 << ep); return usb_lld_read_packet(usbp, ep, buf, n);; } @@ -385,10 +387,10 @@ size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) { - if (usbp->ep[ep]->transmitting) + if (usbGetTransmitStatusI(usbp, ep)) return USB_ENDPOINT_BUSY; - usbp->ep[ep]->transmitting = TRUE; + usbp->transmitting |= (1 << ep); usb_lld_write_packet(usbp, ep, buf, n); return 0; } @@ -413,9 +415,10 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { - if (usbp->ep[ep]->receiving) + if (usbGetReceiveStatusI(usbp, ep)) return TRUE; - usbp->ep[ep]->receiving = TRUE; + + usbp->receiving |= (1 << ep); usb_lld_start_out(usbp, ep, buf, n); return FALSE; } @@ -440,9 +443,10 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) { - if (usbp->ep[ep]->transmitting) + if (usbGetTransmitStatusI(usbp, ep)) return TRUE; - usbp->ep[ep]->transmitting = TRUE; + + usbp->transmitting |= (1 << ep); usb_lld_start_in(usbp, ep, buf, n); return FALSE; } @@ -460,8 +464,9 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, */ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { - if (usbp->ep[ep]->receiving) + if (usbGetReceiveStatusI(usbp, ep)) return TRUE; + usb_lld_stall_out(usbp, ep); return FALSE; } @@ -479,8 +484,9 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { */ bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) { - if (usbp->ep[ep]->transmitting) + if (usbGetTransmitStatusI(usbp, ep)) return TRUE; + usb_lld_stall_in(usbp, ep); return FALSE; } -- cgit v1.2.3 From 95d128420a70587ce2845df383ed9b6a165e58dc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 12 Feb 2011 18:59:34 +0000 Subject: Fixed a problem in the USB-CDC demo. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2733 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index b17669c04..430218edb 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -124,7 +124,7 @@ static void inotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; chSemSetCounterI(&sdup->iqueue.q_sem, n); -// chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); } } } @@ -143,7 +143,7 @@ static void onotify(GenericQueue *qp) { if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); -// chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); } } -- cgit v1.2.3 From f67eb2c108183bc6f037c0cabb95dbd5995207ca Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 13 Feb 2011 15:52:40 +0000 Subject: Fixed bug 3179783. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2735 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 48656a8a3..9d033fe33 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -123,8 +123,10 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, (time > 0)) { chSysLock(); systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) + if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) { + chSysUnlock(); break; + } if (time != TIME_INFINITE) time -= (chTimeNow() - now); chSysUnlock(); @@ -173,8 +175,10 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, (time > 0)) { chSysLock(); systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) + if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) { + chSysUnlock(); break; + } if (time != TIME_INFINITE) time -= (chTimeNow() - now); chSysUnlock(); -- cgit v1.2.3 From 2c15c4864f33c3c71c58e54494561eff1b291a0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 14 Feb 2011 19:37:40 +0000 Subject: More improvements in the USB driver model. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2738 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 6 +-- os/hal/src/usb.c | 109 ++++++++++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 49 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 430218edb..83f1c93ff 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -250,14 +250,14 @@ bool_t sduRequestsHook(USBDriver *usbp) { if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { switch (usbp->setup[1]) { case CDC_GET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); return TRUE; case CDC_SET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); return TRUE; case CDC_SET_CONTROL_LINE_STATE: /* Nothing to do, there are no control lines.*/ - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; default: return FALSE; diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index cbbe8f5b3..34e9a14fd 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -54,7 +54,7 @@ static const uint8_t halted_status[] = {0x01, 0x00}; * * @param[in] usbp pointer to the @p USBDriver object */ -void set_address(USBDriver *usbp) { +static void set_address(USBDriver *usbp) { usbp->address = usbp->setup[2]; usb_lld_set_address(usbp); @@ -84,14 +84,14 @@ static bool_t default_handler(USBDriver *usbp) { (usbp->setup[1] << 8))) { case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_STATUS << 8): /* Just returns the current status word.*/ - usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2); + usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2, NULL); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_CLEAR_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status &= ~2; - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; } return FALSE; @@ -100,7 +100,7 @@ static bool_t default_handler(USBDriver *usbp) { number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status |= 2; - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; } return FALSE; @@ -112,8 +112,10 @@ static bool_t default_handler(USBDriver *usbp) { if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && (usbp->setup[1] == USB_REQ_SET_ADDRESS)) set_address(usbp); + usbSetupTransfer(usbp, NULL, 0, NULL); +#else + usbSetupTransfer(usbp, NULL, 0, set_address); #endif - usbSetupTransfer(usbp, NULL, 0); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_DESCRIPTOR << 8): /* Handling descriptor requests from the host.*/ @@ -122,11 +124,11 @@ static bool_t default_handler(USBDriver *usbp) { usb_lld_fetch_word(&usbp->setup[4])); if (dp == NULL) return FALSE; - usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size); + usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_CONFIGURATION << 8): /* Returning the last selected configuration.*/ - usbSetupTransfer(usbp, &usbp->configuration, 1); + usbSetupTransfer(usbp, &usbp->configuration, 1, NULL); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_CONFIGURATION << 8): /* Handling configuration selection from the host.*/ @@ -137,23 +139,23 @@ static bool_t default_handler(USBDriver *usbp) { usbp->state = USB_ACTIVE; if (usbp->config->event_cb) usbp->config->event_cb(usbp, USB_EVENT_CONFIGURED); - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8): case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SYNCH_FRAME << 8): /* Just sending two zero bytes, the application can change the behavior using a hook..*/ - usbSetupTransfer(usbp, (uint8_t *)zero_status, 2); + usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL); return TRUE; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_GET_STATUS << 8): /* Sending the EP status.*/ if (usbp->setup[4] & 0x80) { switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: - usbSetupTransfer(usbp, (uint8_t *)halted_status, 2); + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); return TRUE; case EP_STATUS_ACTIVE: - usbSetupTransfer(usbp, (uint8_t *)active_status, 2); + usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); return TRUE; default: return FALSE; @@ -162,10 +164,10 @@ static bool_t default_handler(USBDriver *usbp) { else { switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: - usbSetupTransfer(usbp, (uint8_t *)halted_status, 2); + usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); return TRUE; case EP_STATUS_ACTIVE: - usbSetupTransfer(usbp, (uint8_t *)active_status, 2); + usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); return TRUE; default: return FALSE; @@ -182,7 +184,7 @@ static bool_t default_handler(USBDriver *usbp) { else usb_lld_clear_out(usbp, usbp->setup[4] & 0x0F); } - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SET_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ @@ -195,7 +197,7 @@ static bool_t default_handler(USBDriver *usbp) { else usb_lld_stall_out(usbp, usbp->setup[4] & 0x0F); } - usbSetupTransfer(usbp, NULL, 0); + usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_DESCRIPTOR << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_CLEAR_FEATURE << 8): @@ -259,7 +261,7 @@ void usbStart(USBDriver *usbp, const USBConfig *config) { "usbStart(), #1", "invalid state"); usbp->config = config; for (i = 0; i <= USB_MAX_ENDPOINTS; i++) - usbp->ep[i] = NULL; + usbp->epc[i] = NULL; usb_lld_start(usbp); usbp->state = USB_READY; chSysUnlock(); @@ -293,23 +295,24 @@ void usbStop(USBDriver *usbp) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[out] epp pointer to an endpoint state descriptor structure * @param[in] epcp the endpoint configuration * * @iclass */ -void usbInitEndpointI(USBDriver *usbp, usbep_t ep, USBEndpointState *epp, +void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp) { chDbgAssert(usbp->state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); - chDbgAssert(usbp->ep[ep] != NULL, + chDbgAssert(usbp->epc[ep] != NULL, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ - memset(epp, 0, sizeof(USBEndpointState)); - epp->config = epcp; - usbp->ep[ep] = epp; + if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) { + memset(epcp->in_state, 0, sizeof(USBInEndpointState)); + memset(epcp->out_state, 0, sizeof(USBOutEndpointState)); + } + usbp->epc[ep] = epcp; /* Low level endpoint activation.*/ usb_lld_init_endpoint(usbp, ep); @@ -333,7 +336,7 @@ void usbDisableEndpointsI(USBDriver *usbp) { "usbDisableEndpointsI(), #1", "invalid state"); for (i = 1; i <= USB_MAX_ENDPOINTS; i++) - usbp->ep[i] = NULL; + usbp->epc[i] = NULL; /* Low level endpoints deactivation.*/ usb_lld_disable_endpoints(usbp); @@ -493,6 +496,8 @@ bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) { /** * @brief USB reset routine. + * @details This function must be invoked when an USB bus reset condition is + * detected. * * @param[in] usbp pointer to the @p USBDriver object * @@ -508,7 +513,7 @@ void _usb_reset(USBDriver *usbp) { /* Invalidates all endpoints into the USBDriver structure.*/ for (i = 0; i <= USB_MAX_ENDPOINTS; i++) - usbp->ep[i] = NULL; + usbp->epc[i] = NULL; /* EP0 state machine initialization.*/ usbp->ep0state = USB_EP0_WAITING_SETUP; @@ -538,30 +543,32 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { multiple of the maximum packet size then a zero size packet must be transmitted.*/ if ((usbp->ep0n < max) && - ((usbp->ep0n % usbp->ep[0]->config->in_maxsize) == 0)) { + ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { usb_lld_start_in(usbp, 0, NULL, 0); return; } + + /* Transmit phase over, receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; usb_lld_start_out(usbp, 0, NULL, 0); return; case USB_EP0_SENDING_STS: -#if USB_SET_ADDRESS_MODE == USB_LATE_SET_ADDRESS - if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && - (usbp->setup[1] == USB_REQ_SET_ADDRESS)) - set_address(usbp); -#endif + /* Status packet sent, invoking the callback if defined.*/ + if (usbp->ep0endcb) + usbp->ep0endcb(usbp); usbp->ep0state = USB_EP0_WAITING_SETUP; return; default: ; } - /* Error response.*/ + /* Error response, the state machine goes into an error state, the low + level layer will have to reset it to USB_EP0_WAITING_SETUP after + receiving a SETUP packet.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); if (usbp->config->event_cb) usbp->config->event_cb(usbp, USB_EVENT_STALLED); - usbp->ep0state = USB_EP0_WAITING_SETUP; + usbp->ep0state = USB_EP0_ERROR; } /** @@ -575,13 +582,16 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { * @notapi */ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { - size_t n, max; + size_t max; (void)ep; switch (usbp->ep0state) { case USB_EP0_WAITING_SETUP: - /* SETUP packet handling. - First verify if the application has an handler installed for this + /* SETUP packet handling. The setup packet is expected to be already + placed into the setup[8] field of the USBDriver structure, the low + level layer has to take care of this.*/ + + /* First verify if the application has an handler installed for this request.*/ if (!(usbp->config->requests_hook_cb) || !(usbp->config->requests_hook_cb(usbp))) { @@ -593,8 +603,8 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { } /* Transfer preparation. The request handler must have populated - correctly the fields ep0next, ep0n and ep0endcb using - the macro usbSetupTransfer().*/ + correctly the fields ep0next, ep0n and ep0endcb using the macro + usbSetupTransfer().*/ max = usb_lld_fetch_word(&usbp->setup[6]); /* The transfer size cannot exceed the specified amount.*/ if (usbp->ep0n > max) @@ -602,12 +612,13 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) { /* IN phase.*/ if (usbp->ep0n > 0) { - /* Starts transmission.*/ + /* Starts the transmit phase.*/ usbp->ep0state = USB_EP0_TX; usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); } else { - /* Receiving the zero sized status packet.*/ + /* No transmission phase, directly receiving the zero sized status + packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; usb_lld_start_out(usbp, 0, NULL, 0); } @@ -615,37 +626,43 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { else { /* OUT phase.*/ if (usbp->ep0n > 0) { - /* Starts reception.*/ + /* Starts the receive phase.*/ usbp->ep0state = USB_EP0_RX; usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); } else { - /* Sending zero sized status packet.*/ + /* No receive phase, directly sending the zero sized status + packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; usb_lld_start_in(usbp, 0, NULL, 0); } } return; case USB_EP0_RX: + /* Receive phase over, sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; usb_lld_start_in(usbp, 0, NULL, 0); return; case USB_EP0_WAITING_STS: - /* STATUS received packet handling, it must be zero sized.*/ - n = usbp->ep[0]->rxsize; - if (n != 0) + /* Status packet received, it must be zero sized, invoking the callback + if defined.*/ + if (usbGetReceiveTransactionSizeI(usbp, 0) != 0) break; + if (usbp->ep0endcb) + usbp->ep0endcb(usbp); usbp->ep0state = USB_EP0_WAITING_SETUP; return; default: ; } - /* Error response.*/ + /* Error response, the state machine goes into an error state, the low + level layer will have to reset it to USB_EP0_WAITING_SETUP after + receiving a SETUP packet.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); if (usbp->config->event_cb) usbp->config->event_cb(usbp, USB_EVENT_STALLED); - usbp->ep0state = USB_EP0_WAITING_SETUP; + usbp->ep0state = USB_EP0_ERROR; } #endif /* HAL_USE_USB */ -- cgit v1.2.3 From 35ff7323526f5225d1a00c7812291e9fcdbfafac Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 15 Feb 2011 09:16:17 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2740 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 34e9a14fd..0dbe4b39d 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -335,6 +335,8 @@ void usbDisableEndpointsI(USBDriver *usbp) { chDbgAssert(usbp->state == USB_SELECTED, "usbDisableEndpointsI(), #1", "invalid state"); + usbp->transmitting &= ~1; + usbp->receiving &= ~1; for (i = 1; i <= USB_MAX_ENDPOINTS; i++) usbp->epc[i] = NULL; @@ -399,7 +401,7 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, } /** - * @brief Starts a receive operation on an OUT endpoint. + * @brief Starts a receive transaction on an OUT endpoint. * @pre In order to use this function he endpoint must have been * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been @@ -410,8 +412,8 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, * @param[out] buf buffer where to copy the received data * @param[in] n maximum number of bytes to copy * @return The operation status. - * @retval FALSE Operation complete. - * @retval TRUE Endpoint busy receiving. + * @retval FALSE Operation started successfully. + * @retval TRUE Endpoint busy, operation not started. * * @iclass */ @@ -427,7 +429,7 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, } /** - * @brief Starts a transmit operation on an IN endpoint. + * @brief Starts a transmit transaction on an IN endpoint. * @pre In order to use this function he endpoint must have been * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been @@ -438,8 +440,8 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, * @param[in] buf buffer where to fetch the data to be transmitted * @param[in] n maximum number of bytes to copy * @return The operation status. - * @retval FALSE Operation complete. - * @retval TRUE Endpoint busy transmitting. + * @retval FALSE Operation started successfully. + * @retval TRUE Endpoint busy, operation not started. * * @iclass */ @@ -461,7 +463,7 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, * @param[in] ep endpoint number * @return The operation status. * @retval FALSE Endpoint stalled. - * @retval TRUE The endpoint was within a transaction, not stalled. + * @retval TRUE Endpoint busy, not stalled. * * @iclass */ @@ -481,7 +483,7 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { * @param[in] ep endpoint number * @return The operation status. * @retval FALSE Endpoint stalled. - * @retval TRUE The endpoint was within a transaction, not stalled. + * @retval TRUE Endpoint busy, not stalled. * * @iclass */ @@ -510,6 +512,8 @@ void _usb_reset(USBDriver *usbp) { usbp->status = 0; usbp->address = 0; usbp->configuration = 0; + usbp->transmitting = 0; + usbp->receiving = 0; /* Invalidates all endpoints into the USBDriver structure.*/ for (i = 0; i <= USB_MAX_ENDPOINTS; i++) -- cgit v1.2.3 From 4f827c235aa25d0c0b45eca7ccd06ce2c1740a24 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 27 Feb 2011 15:22:18 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2776 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 04af9a6c2..7dede9f86 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -116,14 +116,35 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Generate (re)start on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStart(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + i2c_lld_master_start(i2cp); +} + +/** + * @brief Generate stop on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStop(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + i2c_lld_master_stop(i2cp); +} + /** * @brief Sends data ever the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object * */ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -134,19 +155,15 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmitI(i2cp, i2cscfg); + i2c_lld_master_transmit(i2cp, i2cscfg); } /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object */ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -156,7 +173,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receiveI(i2cp, i2cscfg); + i2c_lld_master_receive(i2cp, i2cscfg); } -- cgit v1.2.3 From 6b5ddb71fcb396ec826a283427b4771018d193e8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 28 Feb 2011 18:44:46 +0000 Subject: GPT driver model, STM32 GPT driver implementation, not tested, documentation not done yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2779 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/hal.c | 3 + 2 files changed, 231 insertions(+) create mode 100644 os/hal/src/gpt.c (limited to 'os/hal/src') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c new file mode 100644 index 000000000..5027079cf --- /dev/null +++ b/os/hal/src/gpt.c @@ -0,0 +1,228 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file gpt.c + * @brief GPT Driver code. + * + * @addtogroup GPT + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_GPT || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief GPT Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void gptInit(void) { + + gpt_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p GPTDriver structure. + * + * @param[out] gptp pointer to the @p GPTDriver object + * + * @init + */ +void gptObjectInit(GPTDriver *gptp) { + + gptp->state = GPT_STOP; + gptp->config = NULL; +} + +/** + * @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) { + + chDbgCheck((gptp != NULL) && (config != NULL), "ptStart"); + + chSysLock(); + chDbgAssert((gptp->state == GPT_STOP) || (gptp->state == GPT_READY), + "gptStart(), #1", "invalid state"); + gptp->config = config; + gpt_lld_start(gptp); + gptp->state = GPT_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the GPT peripheral. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStop(GPTDriver *gptp) { + + chDbgCheck(gptp != NULL, "gptStop"); + + chSysLock(); + chDbgAssert((gptp->state == GPT_STOP) || (gptp->state == GPT_READY), + "gptStop(), #1", "invalid state"); + gpt_lld_stop(gptp); + gptp->state = GPT_STOP; + chSysUnlock(); +} + +/** + * @brief Starts the timer in continuous mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval period in ticks + * + * @api + */ +void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval) { + + chSysLock(); + gptStartContinuousI(gptp, interval); + chSysUnlock(); +} + +/** + * @brief Starts the timer in continuous mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval period in ticks + * + * @iclass + */ +void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptStartContinuousI(), #1", "invalid state"); + gptp->state = GPT_CONTINUOUS; + gpt_lld_start_timer(gptp, interval); +} + +/** + * @brief Starts the timer in one shot mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval) { + + chSysLock(); + gptStartOneShotI(gptp, interval); + chSysUnlock(); +} + +/** + * @brief Starts the timer in one shot mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptStartOneShotI(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; + gpt_lld_start_timer(gptp, interval); +} + +/** + * @brief Stops the timer. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStopTimer(GPTDriver *gptp) { + + chSysLock(); + gptStopTimerI(gptp); + chSysUnlock(); +} + +/** + * @brief Stops the timer. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStopTimerI(GPTDriver *gptp) { + + chDbgAssert((gptp->state == GPT_READY) || (gptp->state == GPT_CONTINUOUS) || + (gptp->state == GPT_ONESHOT), + "gptStopTimerI(), #1", "invalid state"); + gptp->state = GPT_READY; + gpt_lld_stop_timer(gptp); +} + +/** + * @brief Starts the timer in one shot mode and waits for completion. + * @details This function specifically polls the timer waiting for completion + * in order to not have extra delays caused by interrupt servicing, + * this function is only recommended for short delays. + * @note The configured callback is not invoked when using this function. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptPolledDelay(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; + gpt_lld_polled_delay(gptp, interval); +} + +#endif /* HAL_USE_GPT */ + +/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index bfbaa3e84..d33dff30a 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -66,6 +66,9 @@ void halInit(void) { #if HAL_USE_CAN || defined(__DOXYGEN__) canInit(); #endif +#if HAL_USE_GPT || defined(__DOXYGEN__) + gptInit(); +#endif #if HAL_USE_I2C || defined(__DOXYGEN__) i2cInit(); #endif -- cgit v1.2.3 From eed6999aaf3a4579121b5e70d3a84ef620f896eb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 1 Mar 2011 13:49:53 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2784 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 83f1c93ff..0393ad141 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -167,12 +167,6 @@ void sduInit(void) { * outside, usually in the hardware initialization code. * * @param[out] sdup pointer to a @p SerialUSBDriver 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 */ @@ -244,6 +238,11 @@ void sduStop(SerialUSBDriver *sdup) { * - CDC_SET_LINE_CODING. * - CDC_SET_CONTROL_LINE_STATE. * . + * + * @param[in] usbp pointer to the @p USBDriver object + * @return The hook status. + * @retval TRUE Message handled internally. + * @retval FALSE Message not handled. */ bool_t sduRequestsHook(USBDriver *usbp) { @@ -270,6 +269,9 @@ bool_t sduRequestsHook(USBDriver *usbp) { * @brief Default data transmitted callback. * @details The application must use this function as callback for the IN * data endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; @@ -294,6 +296,9 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { * @brief Default data received callback. * @details The application must use this function as callback for the OUT * data endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number */ void sduDataReceived(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; @@ -319,6 +324,9 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { * @brief Default data received callback. * @details The application must use this function as callback for the IN * interrupt endpoint. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number */ void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep) { -- cgit v1.2.3 From 18fb8f676f0f650d83f69bc29ab45b04b73e86c1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Mar 2011 10:09:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2808 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 78 ++++++++++---------- os/hal/src/can.c | 80 ++++++++++----------- os/hal/src/mac.c | 10 +-- os/hal/src/mmc_spi.c | 199 +++++++++++++++++++++++++-------------------------- os/hal/src/pal.c | 12 ++-- os/hal/src/pwm.c | 18 ++--- os/hal/src/spi.c | 77 +++++++++----------- os/hal/src/uart.c | 97 +++++++++++-------------- 8 files changed, 268 insertions(+), 303 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 25cbfe750..956c7837f 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -67,19 +67,19 @@ void adcInit(void) { */ void adcObjectInit(ADCDriver *adcp) { - adcp->ad_state = ADC_STOP; - adcp->ad_config = NULL; - adcp->ad_samples = NULL; - adcp->ad_depth = 0; - adcp->ad_grpp = NULL; + adcp->state = ADC_STOP; + adcp->config = NULL; + adcp->samples = NULL; + adcp->depth = 0; + adcp->grpp = NULL; #if ADC_USE_WAIT - adcp->ad_thread = NULL; + adcp->thread = NULL; #endif /* ADC_USE_WAIT */ #if ADC_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES - chMtxInit(&adcp->ad_mutex); + chMtxInit(&adcp->mutex); #else - chSemInit(&adcp->ad_semaphore, 1); + chSemInit(&adcp->semaphore, 1); #endif #endif /* ADC_USE_MUTUAL_EXCLUSION */ #if defined(ADC_DRIVER_EXT_INIT_HOOK) @@ -101,11 +101,11 @@ void adcStart(ADCDriver *adcp, const ADCConfig *config) { chDbgCheck(adcp != NULL, "adcStart"); chSysLock(); - chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + chDbgAssert((adcp->state == ADC_STOP) || (adcp->state == ADC_READY), "adcStart(), #1", "invalid state"); - adcp->ad_config = config; + adcp->config = config; adc_lld_start(adcp); - adcp->ad_state = ADC_READY; + adcp->state = ADC_READY; chSysUnlock(); } @@ -121,10 +121,10 @@ void adcStop(ADCDriver *adcp) { chDbgCheck(adcp != NULL, "adcStop"); chSysLock(); - chDbgAssert((adcp->ad_state == ADC_STOP) || (adcp->ad_state == ADC_READY), + chDbgAssert((adcp->state == ADC_STOP) || (adcp->state == ADC_READY), "adcStop(), #1", "invalid state"); adc_lld_stop(adcp); - adcp->ad_state = ADC_STOP; + adcp->state = ADC_STOP; chSysUnlock(); } @@ -179,13 +179,13 @@ void adcStartConversionI(ADCDriver *adcp, ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_COMPLETE), + chDbgAssert((adcp->state == ADC_READY) || + (adcp->state == ADC_COMPLETE), "adcStartConversionI(), #1", "not ready"); - adcp->ad_samples = samples; - adcp->ad_depth = depth; - adcp->ad_grpp = grpp; - adcp->ad_state = ADC_ACTIVE; + adcp->samples = samples; + adcp->depth = depth; + adcp->grpp = grpp; + adcp->state = ADC_ACTIVE; adc_lld_start_conversion(adcp); } @@ -204,13 +204,13 @@ void adcStopConversion(ADCDriver *adcp) { chDbgCheck(adcp != NULL, "adcStopConversion"); chSysLock(); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_ACTIVE), + chDbgAssert((adcp->state == ADC_READY) || + (adcp->state == ADC_ACTIVE), "adcStopConversion(), #1", "invalid state"); - if (adcp->ad_state != ADC_READY) { + if (adcp->state != ADC_READY) { adc_lld_stop_conversion(adcp); - adcp->ad_grpp = NULL; - adcp->ad_state = ADC_READY; + adcp->grpp = NULL; + adcp->state = ADC_READY; _adc_reset_s(adcp); } chSysUnlock(); @@ -230,14 +230,14 @@ void adcStopConversionI(ADCDriver *adcp) { chDbgCheck(adcp != NULL, "adcStopConversionI"); - chDbgAssert((adcp->ad_state == ADC_READY) || - (adcp->ad_state == ADC_ACTIVE) || - (adcp->ad_state == ADC_COMPLETE), + chDbgAssert((adcp->state == ADC_READY) || + (adcp->state == ADC_ACTIVE) || + (adcp->state == ADC_COMPLETE), "adcStopConversionI(), #1", "invalid state"); - if (adcp->ad_state != ADC_READY) { + if (adcp->state != ADC_READY) { adc_lld_stop_conversion(adcp); - adcp->ad_grpp = NULL; - adcp->ad_state = ADC_READY; + adcp->grpp = NULL; + adcp->state = ADC_READY; _adc_reset_i(adcp); } } @@ -271,9 +271,9 @@ msg_t adcConvert(ADCDriver *adcp, msg_t msg; chSysLock(); - chDbgAssert(grpp->acg_endcb == NULL, "adcConvert(), #1", "has callback"); + chDbgAssert(grpp->end_cb == NULL, "adcConvert(), #1", "has callback"); adcStartConversionI(adcp, grpp, samples, depth); - (adcp)->ad_thread = chThdSelf(); + (adcp)->thread = chThdSelf(); chSchGoSleepS(THD_STATE_SUSPENDED); msg = chThdSelf()->p_u.rdymsg; chSysUnlock(); @@ -286,8 +286,8 @@ msg_t adcConvert(ADCDriver *adcp, * @brief Gains exclusive access to the ADC peripheral. * @details This function tries to gain ownership to the ADC bus, if the bus * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p ADC_USE_MUTUAL_EXCLUSION - * must be enabled. + * @pre In order to use this function the option + * @p ADC_USE_MUTUAL_EXCLUSION must be enabled. * * @param[in] adcp pointer to the @p ADCDriver object * @@ -298,16 +298,16 @@ void adcAcquireBus(ADCDriver *adcp) { chDbgCheck(adcp != NULL, "adcAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&adcp->ad_mutex); + chMtxLock(&adcp->mutex); #elif CH_USE_SEMAPHORES - chSemWait(&adcp->ad_semaphore); + chSemWait(&adcp->semaphore); #endif } /** * @brief Releases exclusive access to the ADC peripheral. - * @pre In order to use this function the option @p ADC_USE_MUTUAL_EXCLUSION - * must be enabled. + * @pre In order to use this function the option + * @p ADC_USE_MUTUAL_EXCLUSION must be enabled. * * @param[in] adcp pointer to the @p ADCDriver object * @@ -321,7 +321,7 @@ void adcReleaseBus(ADCDriver *adcp) { (void)adcp; chMtxUnlock(); #elif CH_USE_SEMAPHORES - chSemSignal(&adcp->ad_semaphore); + chSemSignal(&adcp->semaphore); #endif } #endif /* ADC_USE_MUTUAL_EXCLUSION */ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index d63cbfd8a..c240c9e44 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -67,17 +67,17 @@ void canInit(void) { */ void canObjectInit(CANDriver *canp) { - canp->cd_state = CAN_STOP; - canp->cd_config = NULL; - chSemInit(&canp->cd_txsem, 0); - chSemInit(&canp->cd_rxsem, 0); - chEvtInit(&canp->cd_rxfull_event); - chEvtInit(&canp->cd_txempty_event); - chEvtInit(&canp->cd_error_event); - canp->cd_status = 0; + 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->cd_sleep_event); - chEvtInit(&canp->cd_wakeup_event); + chEvtInit(&canp->sleep_event); + chEvtInit(&canp->wakeup_event); #endif /* CAN_USE_SLEEP_MODE */ } @@ -98,16 +98,16 @@ void canStart(CANDriver *canp, const CANConfig *config) { chDbgCheck(canp != NULL, "canStart"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_STOP) || - (canp->cd_state == CAN_STARTING) || - (canp->cd_state == CAN_READY), + chDbgAssert((canp->state == CAN_STOP) || + (canp->state == CAN_STARTING) || + (canp->state == CAN_READY), "canStart(), #1", "invalid state"); - while (canp->cd_state == CAN_STARTING) + while (canp->state == CAN_STARTING) chThdSleepS(1); - if (canp->cd_state == CAN_STOP) { - canp->cd_config = config; + if (canp->state == CAN_STOP) { + canp->config = config; can_lld_start(canp); - canp->cd_state = CAN_READY; + canp->state = CAN_READY; } chSysUnlock(); } @@ -124,14 +124,14 @@ void canStop(CANDriver *canp) { chDbgCheck(canp != NULL, "canStop"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), + chDbgAssert((canp->state == CAN_STOP) || (canp->state == CAN_READY), "canStop(), #1", "invalid state"); can_lld_stop(canp); - chSemResetI(&canp->cd_rxsem, 0); - chSemResetI(&canp->cd_txsem, 0); + chSemResetI(&canp->rxsem, 0); + chSemResetI(&canp->txsem, 0); chSchRescheduleS(); - canp->cd_state = CAN_STOP; - canp->cd_status = 0; + canp->state = CAN_STOP; + canp->status = 0; chSysUnlock(); } @@ -142,7 +142,7 @@ void canStop(CANDriver *canp) { * @note Trying to transmit while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object - * @param[in] ctfp pointer to the CAN frame to be transmitted + * @param[in] ctfp pointer to the CAN frame to be transmitted * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -160,10 +160,10 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { chDbgCheck((canp != NULL) && (ctfp != NULL), "canTransmit"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), + chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); - while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { - msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); + while ((canp->state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + msg_t msg = chSemWaitTimeoutS(&canp->txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; @@ -200,10 +200,10 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { chDbgCheck((canp != NULL) && (crfp != NULL), "canReceive"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), + chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canReceive(), #1", "invalid state"); - while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { - msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); + while ((canp->state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + msg_t msg = chSemWaitTimeoutS(&canp->rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; @@ -226,8 +226,8 @@ canstatus_t canGetAndClearFlags(CANDriver *canp) { canstatus_t status; chSysLock(); - status = canp->cd_status; - canp->cd_status = 0; + status = canp->status; + canp->status = 0; chSysUnlock(); return status; } @@ -236,7 +236,7 @@ canstatus_t canGetAndClearFlags(CANDriver *canp) { /** * @brief Enters the sleep mode. * @details This function puts the CAN driver in sleep mode and broadcasts - * the @p cd_sleep_event event source. + * the @p sleep_event event source. * @pre In order to use this function the option @p CAN_USE_SLEEP_MODE must * be enabled and the @p CAN_SUPPORTS_SLEEP mode must be supported * by the low level driver. @@ -250,12 +250,12 @@ void canSleep(CANDriver *canp) { chDbgCheck(canp != NULL, "canSleep"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), + chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canSleep(), #1", "invalid state"); - if (canp->cd_state == CAN_READY) { + if (canp->state == CAN_READY) { can_lld_sleep(canp); - canp->cd_state = CAN_SLEEP; - chEvtBroadcastI(&canp->cd_sleep_event); + canp->state = CAN_SLEEP; + chEvtBroadcastI(&canp->sleep_event); chSchRescheduleS(); } chSysUnlock(); @@ -273,12 +273,12 @@ void canWakeup(CANDriver *canp) { chDbgCheck(canp != NULL, "canWakeup"); chSysLock(); - chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), + chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canWakeup(), #1", "invalid state"); - if (canp->cd_state == CAN_SLEEP) { + if (canp->state == CAN_SLEEP) { can_lld_wakeup(canp); - canp->cd_state = CAN_READY; - chEvtBroadcastI(&canp->cd_wakeup_event); + canp->state = CAN_READY; + chEvtBroadcastI(&canp->wakeup_event); chSchRescheduleS(); } chSysUnlock(); diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 9d033fe33..0cf74a5c1 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -71,10 +71,10 @@ void macInit(void) { */ void macObjectInit(MACDriver *macp) { - chSemInit(&macp->md_tdsem, 0); - chSemInit(&macp->md_rdsem, 0); + chSemInit(&macp->tdsem, 0); + chSemInit(&macp->rdsem, 0); #if CH_USE_EVENTS - chEvtInit(&macp->md_rdevent); + chEvtInit(&macp->rdevent); #endif } @@ -123,7 +123,7 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, (time > 0)) { chSysLock(); systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_tdsem, time)) == RDY_TIMEOUT) { + if ((msg = chSemWaitTimeoutS(&macp->tdsem, time)) == RDY_TIMEOUT) { chSysUnlock(); break; } @@ -175,7 +175,7 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, (time > 0)) { chSysLock(); systime_t now = chTimeNow(); - if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT) { + if ((msg = chSemWaitTimeoutS(&macp->rdsem, time)) == RDY_TIMEOUT) { chSysUnlock(); break; } diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 1b2d930c5..df429c8d3 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -18,7 +18,7 @@ */ /** - * @file mmc_spi.c + * @file spi.c * @brief MMC over SPI driver code. * * @addtogroup MMC_SPI @@ -52,24 +52,24 @@ static void tmrfunc(void *p) { MMCDriver *mmcp = p; - if (mmcp->mmc_cnt > 0) { - if (mmcp->mmc_is_inserted()) { - if (--mmcp->mmc_cnt == 0) { - mmcp->mmc_state = MMC_INSERTED; - chEvtBroadcastI(&mmcp->mmc_inserted_event); + if (mmcp->cnt > 0) { + if (mmcp->is_inserted()) { + if (--mmcp->cnt == 0) { + mmcp->state = MMC_INSERTED; + chEvtBroadcastI(&mmcp->inserted_event); } } else - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; + mmcp->cnt = MMC_POLLING_INTERVAL; } else { - if (!mmcp->mmc_is_inserted()) { - mmcp->mmc_state = MMC_WAIT; - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; - chEvtBroadcastI(&mmcp->mmc_removed_event); + if (!mmcp->is_inserted()) { + mmcp->state = MMC_WAIT; + mmcp->cnt = MMC_POLLING_INTERVAL; + chEvtBroadcastI(&mmcp->removed_event); } } - chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); } /** @@ -84,13 +84,13 @@ static void wait(MMCDriver *mmcp) { uint8_t buf[4]; for (i = 0; i < 16; i++) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->spip, 1, buf); if (buf[0] == 0xFF) break; } /* Looks like it is a long wait.*/ while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -121,7 +121,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[3] = arg >> 8; buf[4] = arg; buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ - spiSend(mmcp->mmc_spip, 6, buf); + spiSend(mmcp->spip, 6, buf); } /** @@ -138,7 +138,7 @@ static uint8_t recvr1(MMCDriver *mmcp) { uint8_t r1[1]; for (i = 0; i < 9; i++) { - spiReceive(mmcp->mmc_spip, 1, r1); + spiReceive(mmcp->spip, 1, r1); if (r1[0] != 0xFF) return r1[0]; } @@ -159,10 +159,10 @@ static uint8_t recvr1(MMCDriver *mmcp) { static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t r1; - spiSelect(mmcp->mmc_spip); + spiSelect(mmcp->spip); send_hdr(mmcp, cmd, arg); r1 = recvr1(mmcp); - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); return r1; } @@ -176,16 +176,16 @@ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { static void sync(MMCDriver *mmcp) { uint8_t buf[1]; - spiSelect(mmcp->mmc_spip); + spiSelect(mmcp->spip); while (TRUE) { - spiReceive(mmcp->mmc_spip, 1, buf); + spiReceive(mmcp->spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING chThdSleep(1); /* Trying to be nice with the other threads.*/ #endif } - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); } /*===========================================================================*/ @@ -221,15 +221,15 @@ 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); + 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; + chEvtInit(&mmcp->inserted_event); + chEvtInit(&mmcp->removed_event); } /** @@ -245,11 +245,11 @@ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { chDbgCheck((mmcp != NULL) && (config == NULL), "mmcStart"); chSysLock(); - chDbgAssert(mmcp->mmc_state == MMC_STOP, "mmcStart(), #1", "invalid state"); - mmcp->mmc_config = config; - mmcp->mmc_state = MMC_WAIT; - mmcp->mmc_cnt = MMC_POLLING_INTERVAL; - chVTSetI(&mmcp->mmc_vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + chDbgAssert(mmcp->state == MMC_STOP, "mmcStart(), #1", "invalid state"); + mmcp->config = config; + mmcp->state = MMC_WAIT; + mmcp->cnt = MMC_POLLING_INTERVAL; + chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); chSysUnlock(); } @@ -265,17 +265,16 @@ void mmcStop(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStop"); chSysLock(); - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_READING) && - (mmcp->mmc_state != MMC_WRITING), - "mmcStop(), #1", - "invalid state"); - if (mmcp->mmc_state != MMC_STOP) { - mmcp->mmc_state = MMC_STOP; - chVTResetI(&mmcp->mmc_vt); + chDbgAssert((mmcp->state != MMC_UNINIT) && + (mmcp->state != MMC_READING) && + (mmcp->state != MMC_WRITING), + "mmcStop(), #1", "invalid state"); + if (mmcp->state != MMC_STOP) { + mmcp->state = MMC_STOP; + chVTResetI(&mmcp->vt); } chSysUnlock(); - spiStop(mmcp->mmc_spip); + spiStop(mmcp->spip); } /** @@ -300,15 +299,13 @@ bool_t mmcConnect(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcConnect"); - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_STOP), - "mmcConnect(), #1", - "invalid state"); + chDbgAssert((mmcp->state != MMC_UNINIT) && (mmcp->state != MMC_STOP), + "mmcConnect(), #1", "invalid state"); - if (mmcp->mmc_state == MMC_INSERTED) { + if (mmcp->state == MMC_INSERTED) { /* Slow clock mode and 128 clock pulses.*/ - spiStart(mmcp->mmc_spip, mmcp->mmc_lscfg); - spiIgnore(mmcp->mmc_spip, 16); + spiStart(mmcp->spip, mmcp->lscfg); + spiIgnore(mmcp->spip, 16); /* SPI mode selection.*/ i = 0; @@ -334,7 +331,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /* Initialization complete, full speed. */ - spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); + spiStart(mmcp->spip, mmcp->hscfg); /* Setting block size.*/ if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) @@ -342,8 +339,8 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* Transition to MMC_READY state (if not extracted).*/ chSysLock(); - if (mmcp->mmc_state == MMC_INSERTED) { - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_INSERTED) { + mmcp->state = MMC_READY; result = FALSE; } else @@ -351,7 +348,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { chSysUnlock(); return result; } - if (mmcp->mmc_state == MMC_READY) + if (mmcp->state == MMC_READY) return FALSE; /* Any other state is invalid.*/ return TRUE; @@ -373,24 +370,22 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcDisconnect"); - chDbgAssert((mmcp->mmc_state != MMC_UNINIT) && - (mmcp->mmc_state != MMC_STOP), - "mmcDisconnect(), #1", - "invalid state"); - switch (mmcp->mmc_state) { + chDbgAssert((mmcp->state != MMC_UNINIT) && (mmcp->state != MMC_STOP), + "mmcDisconnect(), #1", "invalid state"); + switch (mmcp->state) { case MMC_READY: /* Wait for the pending write operations to complete.*/ sync(mmcp); chSysLock(); - if (mmcp->mmc_state == MMC_READY) - mmcp->mmc_state = MMC_INSERTED; + if (mmcp->state == MMC_READY) + mmcp->state = MMC_INSERTED; chSysUnlock(); case MMC_INSERTED: status = FALSE; default: status = TRUE; } - spiStop(mmcp->mmc_spip); + spiStop(mmcp->spip); return status; } @@ -410,21 +405,21 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); chSysLock(); - if (mmcp->mmc_state != MMC_READY) { + if (mmcp->state != MMC_READY) { chSysUnlock(); return TRUE; } - mmcp->mmc_state = MMC_READING; + mmcp->state = MMC_READING; chSysUnlock(); - spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); - spiSelect(mmcp->mmc_spip); + spiStart(mmcp->spip, mmcp->hscfg); + spiSelect(mmcp->spip); send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_READING) + mmcp->state = MMC_READY; chSysUnlock(); return TRUE; } @@ -448,26 +443,26 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); chSysLock(); - if (mmcp->mmc_state != MMC_READING) { + if (mmcp->state != MMC_READING) { chSysUnlock(); return TRUE; } chSysUnlock(); for (i = 0; i < MMC_WAIT_DATA; i++) { - spiReceive(mmcp->mmc_spip, 1, buffer); + spiReceive(mmcp->spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceive(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); + spiReceive(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* CRC ignored. */ - spiIgnore(mmcp->mmc_spip, 2); + spiIgnore(mmcp->spip, 2); return FALSE; } } /* Timeout.*/ - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_READING) + mmcp->state = MMC_READY; chSysUnlock(); return TRUE; } @@ -489,22 +484,22 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); chSysLock(); - if (mmcp->mmc_state != MMC_READING) { + if (mmcp->state != MMC_READING) { chSysUnlock(); return TRUE; } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(stopcmd), stopcmd); + spiSend(mmcp->spip, sizeof(stopcmd), stopcmd); /* result = recvr1(mmcp) != 0x00;*/ /* Note, ignored r1 response, it can be not zero, unknown issue.*/ recvr1(mmcp); result = FALSE; - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_READING) - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_READING) + mmcp->state = MMC_READY; chSysUnlock(); return result; } @@ -525,21 +520,21 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); chSysLock(); - if (mmcp->mmc_state != MMC_READY) { + if (mmcp->state != MMC_READY) { chSysUnlock(); return TRUE; } - mmcp->mmc_state = MMC_WRITING; + mmcp->state = MMC_WRITING; chSysUnlock(); - spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); - spiSelect(mmcp->mmc_spip); + spiStart(mmcp->spip, mmcp->hscfg); + spiSelect(mmcp->spip); send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_WRITING) + mmcp->state = MMC_READY; chSysUnlock(); return TRUE; } @@ -564,26 +559,26 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialWrite"); chSysLock(); - if (mmcp->mmc_state != MMC_WRITING) { + if (mmcp->state != MMC_WRITING) { chSysUnlock(); return TRUE; } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(start), start); /* Data prologue. */ - spiSend(mmcp->mmc_spip, MMC_SECTOR_SIZE, buffer); /* Data. */ - spiIgnore(mmcp->mmc_spip, 2); /* CRC ignored. */ - spiReceive(mmcp->mmc_spip, 1, b); + spiSend(mmcp->spip, sizeof(start), start); /* Data prologue. */ + spiSend(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiIgnore(mmcp->spip, 2); /* CRC ignored. */ + spiReceive(mmcp->spip, 1, b); if ((b[0] & 0x1F) == 0x05) { wait(mmcp); return FALSE; } /* Error.*/ - spiUnselect(mmcp->mmc_spip); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_WRITING) + mmcp->state = MMC_READY; chSysUnlock(); return TRUE; } @@ -604,18 +599,18 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); chSysLock(); - if (mmcp->mmc_state != MMC_WRITING) { + if (mmcp->state != MMC_WRITING) { chSysUnlock(); return TRUE; } chSysUnlock(); - spiSend(mmcp->mmc_spip, sizeof(stop), stop); - spiUnselect(mmcp->mmc_spip); + spiSend(mmcp->spip, sizeof(stop), stop); + spiUnselect(mmcp->spip); chSysLock(); - if (mmcp->mmc_state == MMC_WRITING) { - mmcp->mmc_state = MMC_READY; + if (mmcp->state == MMC_WRITING) { + mmcp->state = MMC_READY; chSysUnlock(); return FALSE; } diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index ce7c226e9..de12baef6 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -64,9 +64,9 @@ ioportmask_t palReadBus(IOBus *bus) { chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palReadBus"); + (bus->offset > PAL_IOPORTS_WIDTH), "palReadBus"); - return palReadGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset); + return palReadGroup(bus->portid, bus->mask, bus->offset); } /** @@ -89,9 +89,9 @@ ioportmask_t palReadBus(IOBus *bus) { void palWriteBus(IOBus *bus, ioportmask_t bits) { chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palWriteBus"); + (bus->offset > PAL_IOPORTS_WIDTH), "palWriteBus"); - palWriteGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset, bits); + palWriteGroup(bus->portid, bus->mask, bus->offset, bits); } /** @@ -112,9 +112,9 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { void palSetBusMode(IOBus *bus, uint_fast8_t mode) { chDbgCheck((bus != NULL) && - (bus->bus_offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); + (bus->offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); - palSetGroupMode(bus->bus_portid, bus->bus_mask, mode); + palSetGroupMode(bus->portid, bus->mask, mode); } #endif /* HAL_USE_PAL */ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index cf619e508..40ad7428d 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -67,8 +67,8 @@ void pwmInit(void) { */ void pwmObjectInit(PWMDriver *pwmp) { - pwmp->pd_state = PWM_STOP; - pwmp->pd_config = NULL; + pwmp->state = PWM_STOP; + pwmp->config = NULL; #if defined(PWM_DRIVER_EXT_INIT_HOOK) PWM_DRIVER_EXT_INIT_HOOK(pwmp); #endif @@ -87,11 +87,11 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { chDbgCheck((pwmp != NULL) && (config != NULL), "pwmStart"); chSysLock(); - chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), + chDbgAssert((pwmp->state == PWM_STOP) || (pwmp->state == PWM_READY), "pwmStart(), #1", "invalid state"); - pwmp->pd_config = config; + pwmp->config = config; pwm_lld_start(pwmp); - pwmp->pd_state = PWM_READY; + pwmp->state = PWM_READY; chSysUnlock(); } @@ -107,10 +107,10 @@ void pwmStop(PWMDriver *pwmp) { chDbgCheck(pwmp != NULL, "pwmStop"); chSysLock(); - chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), + chDbgAssert((pwmp->state == PWM_STOP) || (pwmp->state == PWM_READY), "pwmStop(), #1", "invalid state"); pwm_lld_stop(pwmp); - pwmp->pd_state = PWM_STOP; + pwmp->state = PWM_STOP; chSysUnlock(); } @@ -132,7 +132,7 @@ void pwmEnableChannel(PWMDriver *pwmp, "pwmEnableChannel"); chSysLock(); - chDbgAssert(pwmp->pd_state == PWM_READY, + chDbgAssert(pwmp->state == PWM_READY, "pwmEnableChannel(), #1", "not ready"); pwm_lld_enable_channel(pwmp, channel, width); chSysUnlock(); @@ -154,7 +154,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { "pwmEnableChannel"); chSysLock(); - chDbgAssert(pwmp->pd_state == PWM_READY, + chDbgAssert(pwmp->state == PWM_READY, "pwmDisableChannel(), #1", "not ready"); pwm_lld_disable_channel(pwmp, channel); chSysUnlock(); diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index e99126b9e..686006e0d 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -67,16 +67,16 @@ void spiInit(void) { */ void spiObjectInit(SPIDriver *spip) { - spip->spd_state = SPI_STOP; - spip->spd_config = NULL; + spip->state = SPI_STOP; + spip->config = NULL; #if SPI_USE_WAIT - spip->spd_thread = NULL; + spip->thread = NULL; #endif /* SPI_USE_WAIT */ #if SPI_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES - chMtxInit(&spip->spd_mutex); + chMtxInit(&spip->mutex); #else - chSemInit(&spip->spd_semaphore, 1); + chSemInit(&spip->semaphore, 1); #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ #if defined(SPI_DRIVER_EXT_INIT_HOOK) @@ -97,11 +97,11 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStart(), #1", "invalid state"); - spip->spd_config = config; + spip->config = config; spi_lld_start(spip); - spip->spd_state = SPI_READY; + spip->state = SPI_READY; chSysUnlock(); } @@ -119,11 +119,11 @@ void spiStop(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiStop"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStop(), #1", "invalid state"); spi_lld_unselect(spip); spi_lld_stop(spip); - spip->spd_state = SPI_STOP; + spip->state = SPI_STOP; chSysUnlock(); } @@ -139,8 +139,7 @@ void spiSelect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiSelect"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiSelect(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiSelect(), #1", "not ready"); spiSelectI(spip); chSysUnlock(); } @@ -158,8 +157,7 @@ void spiUnselect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiUnselect"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiUnselect(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiUnselect(), #1", "not ready"); spiUnselectI(spip); chSysUnlock(); } @@ -182,8 +180,7 @@ void spiStartIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiStartIgnore"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartIgnore(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartIgnore(), #1", "not ready"); spiStartIgnoreI(spip, n); chSysUnlock(); } @@ -212,8 +209,7 @@ void spiStartExchange(SPIDriver *spip, size_t n, "spiStartExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartExchange(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartExchange(), #1", "not ready"); spiStartExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -239,8 +235,7 @@ void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf) { "spiStartSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartSend(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartSend(), #1", "not ready"); spiStartSendI(spip, n, txbuf); chSysUnlock(); } @@ -266,8 +261,7 @@ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { "spiStartReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartReceive(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartReceive(), #1", "not ready"); spiStartReceiveI(spip, n, rxbuf); chSysUnlock(); } @@ -280,7 +274,7 @@ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { * @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 spc_endcb = @p NULL). + * without callbacks (@p end_cb = @p NULL). * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored @@ -292,10 +286,8 @@ void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiIgnore(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, - "spiIgnore(), #2", "has callback"); + chDbgAssert(spip->state == SPI_READY, "spiIgnore(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiIgnore(), #2", "has callback"); spiStartIgnoreI(spip, n); _spi_wait_s(spip); chSysUnlock(); @@ -308,7 +300,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @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 spc_endcb = @p NULL). + * 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. * @@ -326,9 +318,8 @@ void spiExchange(SPIDriver *spip, size_t n, "spiExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiExchange(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, + chDbgAssert(spip->state == SPI_READY, "spiExchange(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiExchange(), #2", "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); _spi_wait_s(spip); @@ -341,7 +332,7 @@ void spiExchange(SPIDriver *spip, size_t n, * @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 spc_endcb = @p NULL). + * 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. * @@ -353,14 +344,11 @@ void spiExchange(SPIDriver *spip, size_t n, */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { - chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), "spiSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiSend(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, - "spiSend(), #2", "has callback"); + chDbgAssert(spip->state == SPI_READY, "spiSend(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiSend(), #2", "has callback"); spiStartSendI(spip, n, txbuf); _spi_wait_s(spip); chSysUnlock(); @@ -372,7 +360,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * @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 spc_endcb = @p NULL). + * 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. * @@ -388,9 +376,8 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { "spiReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiReceive(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, + chDbgAssert(spip->state == SPI_READY, "spiReceive(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); _spi_wait_s(spip); @@ -415,9 +402,9 @@ void spiAcquireBus(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&spip->spd_mutex); + chMtxLock(&spip->mutex); #elif CH_USE_SEMAPHORES - chSemWait(&spip->spd_semaphore); + chSemWait(&spip->semaphore); #endif } @@ -438,7 +425,7 @@ void spiReleaseBus(SPIDriver *spip) { (void)spip; chMtxUnlock(); #elif CH_USE_SEMAPHORES - chSemSignal(&spip->spd_semaphore); + chSemSignal(&spip->semaphore); #endif } #endif /* SPI_USE_MUTUAL_EXCLUSION */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 4a21e907f..2a9c6ce6f 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -67,10 +67,10 @@ void uartInit(void) { */ void uartObjectInit(UARTDriver *uartp) { - uartp->ud_state = UART_STOP; - uartp->ud_txstate = UART_TX_IDLE; - uartp->ud_rxstate = UART_RX_IDLE; - uartp->ud_config = NULL; + uartp->state = UART_STOP; + uartp->txstate = UART_TX_IDLE; + uartp->rxstate = UART_RX_IDLE; + uartp->config = NULL; /* Optional, user-defined initializer.*/ #if defined(UART_DRIVER_EXT_INIT_HOOK) UART_DRIVER_EXT_INIT_HOOK(uartp); @@ -90,14 +90,12 @@ void uartStart(UARTDriver *uartp, const UARTConfig *config) { chDbgCheck((uartp != NULL) && (config != NULL), "uartStart"); chSysLock(); - chDbgAssert((uartp->ud_state == UART_STOP) || - (uartp->ud_state == UART_READY), - "uartStart(), #1", - "invalid state"); + chDbgAssert((uartp->state == UART_STOP) || (uartp->state == UART_READY), + "uartStart(), #1", "invalid state"); - uartp->ud_config = config; + uartp->config = config; uart_lld_start(uartp); - uartp->ud_state = UART_READY; + uartp->state = UART_READY; chSysUnlock(); } @@ -113,15 +111,13 @@ void uartStop(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStop"); chSysLock(); - chDbgAssert((uartp->ud_state == UART_STOP) || - (uartp->ud_state == UART_READY), - "uartStop(), #1", - "invalid state"); + chDbgAssert((uartp->state == UART_STOP) || (uartp->state == UART_READY), + "uartStop(), #1", "invalid state"); uart_lld_stop(uartp); - uartp->ud_state = UART_STOP; - uartp->ud_txstate = UART_TX_IDLE; - uartp->ud_rxstate = UART_RX_IDLE; + uartp->state = UART_STOP; + uartp->txstate = UART_TX_IDLE; + uartp->rxstate = UART_RX_IDLE; chSysUnlock(); } @@ -142,13 +138,11 @@ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { "uartStartSend"); chSysLock(); - chDbgAssert((uartp->ud_state == UART_READY) && - (uartp->ud_txstate == UART_TX_IDLE), - "uartStartSend(), #1", - "not active"); + chDbgAssert((uartp->state == UART_READY) && (uartp->txstate == UART_TX_IDLE), + "uartStartSend(), #1", "not active"); uart_lld_start_send(uartp, n, txbuf); - uartp->ud_txstate = UART_TX_ACTIVE; + uartp->txstate = UART_TX_ACTIVE; chSysUnlock(); } @@ -169,12 +163,11 @@ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), "uartStartSendI"); - chDbgAssert((uartp->ud_state == UART_READY) && - (uartp->ud_txstate != UART_TX_ACTIVE), - "uartStartSendI(), #1", - "not active"); + chDbgAssert((uartp->state == UART_READY) && + (uartp->txstate != UART_TX_ACTIVE), + "uartStartSendI(), #1", "not active"); uart_lld_start_send(uartp, n, txbuf); - uartp->ud_txstate = UART_TX_ACTIVE; + uartp->txstate = UART_TX_ACTIVE; } /** @@ -195,13 +188,11 @@ size_t uartStopSend(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopSend"); chSysLock(); - chDbgAssert(uartp->ud_state == UART_READY, - "uartStopSend(), #1", - "not active"); + chDbgAssert(uartp->state == UART_READY, "uartStopSend(), #1", "not active"); - if (uartp->ud_txstate == UART_TX_ACTIVE) { + if (uartp->txstate == UART_TX_ACTIVE) { n = uart_lld_stop_send(uartp); - uartp->ud_txstate = UART_TX_IDLE; + uartp->txstate = UART_TX_IDLE; } else n = 0; @@ -226,13 +217,11 @@ size_t uartStopSendI(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopSendI"); - chDbgAssert(uartp->ud_state == UART_READY, - "uartStopSendI(), #1", - "not active"); + chDbgAssert(uartp->state == UART_READY, "uartStopSendI(), #1", "not active"); - if (uartp->ud_txstate == UART_TX_ACTIVE) { + if (uartp->txstate == UART_TX_ACTIVE) { size_t n = uart_lld_stop_send(uartp); - uartp->ud_txstate = UART_TX_IDLE; + uartp->txstate = UART_TX_IDLE; return n; } return 0; @@ -255,13 +244,11 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { "uartStartReceive"); chSysLock(); - chDbgAssert((uartp->ud_state == UART_READY) && - (uartp->ud_rxstate == UART_RX_IDLE), - "uartStartReceive(), #1", - "not active"); + chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE), + "uartStartReceive(), #1", "not active"); uart_lld_start_receive(uartp, n, rxbuf); - uartp->ud_rxstate = UART_RX_ACTIVE; + uartp->rxstate = UART_RX_ACTIVE; chSysUnlock(); } @@ -282,13 +269,11 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), "uartStartReceiveI"); - chDbgAssert((uartp->ud_state == UART_READY) && - (uartp->ud_rxstate == UART_RX_IDLE), - "uartStartReceiveI(), #1", - "not active"); + chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE), + "uartStartReceiveI(), #1", "not active"); uart_lld_start_receive(uartp, n, rxbuf); - uartp->ud_rxstate = UART_RX_ACTIVE; + uartp->rxstate = UART_RX_ACTIVE; } /** @@ -309,13 +294,12 @@ size_t uartStopReceive(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopReceive"); chSysLock(); - chDbgAssert(uartp->ud_state == UART_READY, - "uartStopReceive(), #1", - "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStopReceive(), #1", "not active"); - if (uartp->ud_rxstate == UART_RX_ACTIVE) { + if (uartp->rxstate == UART_RX_ACTIVE) { n = uart_lld_stop_receive(uartp); - uartp->ud_rxstate = UART_RX_IDLE; + uartp->rxstate = UART_RX_IDLE; } else n = 0; @@ -339,13 +323,12 @@ size_t uartStopReceive(UARTDriver *uartp) { size_t uartStopReceiveI(UARTDriver *uartp) { chDbgCheck(uartp != NULL, "uartStopReceiveI"); - chDbgAssert(uartp->ud_state == UART_READY, - "uartStopReceiveI(), #1", - "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStopReceiveI(), #1", "not active"); - if (uartp->ud_rxstate == UART_RX_ACTIVE) { + if (uartp->rxstate == UART_RX_ACTIVE) { size_t n = uart_lld_stop_receive(uartp); - uartp->ud_rxstate = UART_RX_IDLE; + uartp->rxstate = UART_RX_IDLE; return n; } return 0; -- cgit v1.2.3 From ebaac50aa4daa939814b783b1239073e3170860f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Mar 2011 21:09:14 +0000 Subject: Improvements to the Serial over USB driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2810 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 0393ad141..6ed5d324c 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -119,7 +119,7 @@ static void inotify(GenericQueue *qp) { emptied, then a whole packet is loaded in the queue.*/ if (chIQIsEmptyI(&sdup->iqueue)) { - n = usbReadPacketI(sdup->config->usbp, sdup->config->data_available_ep, + n = usbReadPacketI(sdup->config->usbp, DATA_AVAILABLE_EP, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; @@ -138,7 +138,7 @@ static void onotify(GenericQueue *qp) { /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ - n = usbWritePacketI(sdup->config->usbp, sdup->config->data_request_ep, + n = usbWritePacketI(sdup->config->usbp, DATA_REQUEST_EP, sdup->oqueue.q_buffer, chOQGetFullI(&sdup->oqueue)); if (n != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; -- cgit v1.2.3 From a849378300019b9d6c030ab7af46bfda646e619e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 Mar 2011 13:00:39 +0000 Subject: Fixed bug 3205410. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2813 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 956c7837f..b70c46e1c 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -271,7 +271,7 @@ msg_t adcConvert(ADCDriver *adcp, msg_t msg; chSysLock(); - chDbgAssert(grpp->end_cb == NULL, "adcConvert(), #1", "has callback"); + chDbgAssert(adcp->thread == NULL, "adcConvert(), #1", "already waiting"); adcStartConversionI(adcp, grpp, samples, depth); (adcp)->thread = chThdSelf(); chSchGoSleepS(THD_STATE_SUSPENDED); -- cgit v1.2.3 From 3d50b5c9e0eee6ca4eb2e9c1114fcd8ff109e984 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 Mar 2011 18:54:58 +0000 Subject: USB improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2815 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 140 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 77 insertions(+), 63 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 0dbe4b39d..b82af84d8 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -58,8 +58,7 @@ static void set_address(USBDriver *usbp) { usbp->address = usbp->setup[2]; usb_lld_set_address(usbp); - if (usbp->config->event_cb) - usbp->config->event_cb(usbp, USB_EVENT_ADDRESS); + _usb_isr_invoke_event_cb(usbp, USB_EVENT_ADDRESS); usbp->state = USB_SELECTED; } @@ -137,8 +136,7 @@ static bool_t default_handler(USBDriver *usbp) { usbp->state = USB_SELECTED; else usbp->state = USB_ACTIVE; - if (usbp->config->event_cb) - usbp->config->event_cb(usbp, USB_EVENT_CONFIGURED); + _usb_isr_invoke_event_cb(usbp, USB_EVENT_CONFIGURED); usbSetupTransfer(usbp, NULL, 0, NULL); return TRUE; case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8): @@ -526,6 +524,77 @@ void _usb_reset(USBDriver *usbp) { usb_lld_reset(usbp); } +/** + * @brief Default EP0 SETUP callback. + * @details This function is used by the low level driver as default handler + * for EP0 SETUP events. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number, always zero + * + * @notapi + */ +void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { + size_t max; + + usbp->ep0state = USB_EP0_WAITING_SETUP; + usbReadSetup(usbp, ep, usbp->setup); + + /* First verify if the application has an handler installed for this + request.*/ + if (!(usbp->config->requests_hook_cb) || + !(usbp->config->requests_hook_cb(usbp))) { + /* Invoking the default handler, if this fails then stalls the + endpoint zero as error.*/ + if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) || + !default_handler(usbp)) { + /* Error response, the state machine goes into an error state, the low + level layer will have to reset it to USB_EP0_WAITING_SETUP after + receiving a SETUP packet.*/ + usb_lld_stall_in(usbp, 0); + usb_lld_stall_out(usbp, 0); + _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED); + usbp->ep0state = USB_EP0_ERROR; + } + } + + /* Transfer preparation. The request handler must have populated + correctly the fields ep0next, ep0n and ep0endcb using the macro + usbSetupTransfer().*/ + max = usb_lld_fetch_word(&usbp->setup[6]); + /* The transfer size cannot exceed the specified amount.*/ + if (usbp->ep0n > max) + usbp->ep0n = max; + if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) { + /* IN phase.*/ + if (usbp->ep0n > 0) { + /* Starts the transmit phase.*/ + usbp->ep0state = USB_EP0_TX; + usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); + } + else { + /* No transmission phase, directly receiving the zero sized status + packet.*/ + usbp->ep0state = USB_EP0_WAITING_STS; + usb_lld_start_out(usbp, 0, NULL, 0); + } + } + else { + /* OUT phase.*/ + if (usbp->ep0n > 0) { + /* Starts the receive phase.*/ + usbp->ep0state = USB_EP0_RX; + usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); + } + else { + /* No receive phase, directly sending the zero sized status + packet.*/ + usbp->ep0state = USB_EP0_SENDING_STS; + usb_lld_start_in(usbp, 0, NULL, 0); + } + } +} + /** * @brief Default EP0 IN callback. * @details This function is used by the low level driver as default handler @@ -558,7 +627,7 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { return; case USB_EP0_SENDING_STS: /* Status packet sent, invoking the callback if defined.*/ - if (usbp->ep0endcb) + if (usbp->ep0endcb != NULL) usbp->ep0endcb(usbp); usbp->ep0state = USB_EP0_WAITING_SETUP; return; @@ -570,8 +639,7 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { receiving a SETUP packet.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); - if (usbp->config->event_cb) - usbp->config->event_cb(usbp, USB_EVENT_STALLED); + _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED); usbp->ep0state = USB_EP0_ERROR; } @@ -586,62 +654,9 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { * @notapi */ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { - size_t max; (void)ep; switch (usbp->ep0state) { - case USB_EP0_WAITING_SETUP: - /* SETUP packet handling. The setup packet is expected to be already - placed into the setup[8] field of the USBDriver structure, the low - level layer has to take care of this.*/ - - /* First verify if the application has an handler installed for this - request.*/ - if (!(usbp->config->requests_hook_cb) || - !(usbp->config->requests_hook_cb(usbp))) { - /* Invoking the default handler, if this fails then stalls the - endpoint zero as error.*/ - if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) || - !default_handler(usbp)) - break; - } - - /* Transfer preparation. The request handler must have populated - correctly the fields ep0next, ep0n and ep0endcb using the macro - usbSetupTransfer().*/ - max = usb_lld_fetch_word(&usbp->setup[6]); - /* The transfer size cannot exceed the specified amount.*/ - if (usbp->ep0n > max) - usbp->ep0n = max; - if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) { - /* IN phase.*/ - if (usbp->ep0n > 0) { - /* Starts the transmit phase.*/ - usbp->ep0state = USB_EP0_TX; - usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); - } - else { - /* No transmission phase, directly receiving the zero sized status - packet.*/ - usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_start_out(usbp, 0, NULL, 0); - } - } - else { - /* OUT phase.*/ - if (usbp->ep0n > 0) { - /* Starts the receive phase.*/ - usbp->ep0state = USB_EP0_RX; - usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); - } - else { - /* No receive phase, directly sending the zero sized status - packet.*/ - usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_start_in(usbp, 0, NULL, 0); - } - } - return; case USB_EP0_RX: /* Receive phase over, sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; @@ -652,7 +667,7 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { if defined.*/ if (usbGetReceiveTransactionSizeI(usbp, 0) != 0) break; - if (usbp->ep0endcb) + if (usbp->ep0endcb != NULL) usbp->ep0endcb(usbp); usbp->ep0state = USB_EP0_WAITING_SETUP; return; @@ -664,8 +679,7 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { receiving a SETUP packet.*/ usb_lld_stall_in(usbp, 0); usb_lld_stall_out(usbp, 0); - if (usbp->config->event_cb) - usbp->config->event_cb(usbp, USB_EVENT_STALLED); + _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED); usbp->ep0state = USB_EP0_ERROR; } -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 3 ++- os/hal/src/can.c | 3 ++- os/hal/src/gpt.c | 3 ++- os/hal/src/hal.c | 3 ++- os/hal/src/i2c.c | 3 ++- os/hal/src/mac.c | 3 ++- os/hal/src/mmc_spi.c | 3 ++- os/hal/src/pal.c | 3 ++- os/hal/src/pwm.c | 3 ++- os/hal/src/serial.c | 3 ++- os/hal/src/serial_usb.c | 3 ++- os/hal/src/spi.c | 3 ++- os/hal/src/uart.c | 3 ++- os/hal/src/usb.c | 3 ++- 14 files changed, 28 insertions(+), 14 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index b70c46e1c..4843ca90b 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/can.c b/os/hal/src/can.c index c240c9e44..f9a827c4e 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 5027079cf..e90a8911a 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d33dff30a..09b832fe2 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 2b5971b6f..86bfc16f6 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 0cf74a5c1..4d6a9b2cd 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index df429c8d3..e6dcf9287 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index de12baef6..877b372c4 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 40ad7428d..e510ba180 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index aafedcc6b..414689aac 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 6ed5d324c..b6ad10c13 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 686006e0d..aaf0115eb 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 2a9c6ce6f..05fdbb168 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index b82af84d8..484590f3b 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 34c2d747d216010589db37c0af865461c116883b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 19 Mar 2011 07:27:06 +0000 Subject: Fixed bug 3224681. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2828 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 877b372c4..534935a55 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -65,7 +65,7 @@ ioportmask_t palReadBus(IOBus *bus) { chDbgCheck((bus != NULL) && - (bus->offset > PAL_IOPORTS_WIDTH), "palReadBus"); + (bus->offset < PAL_IOPORTS_WIDTH), "palReadBus"); return palReadGroup(bus->portid, bus->mask, bus->offset); } @@ -90,7 +90,7 @@ ioportmask_t palReadBus(IOBus *bus) { void palWriteBus(IOBus *bus, ioportmask_t bits) { chDbgCheck((bus != NULL) && - (bus->offset > PAL_IOPORTS_WIDTH), "palWriteBus"); + (bus->offset < PAL_IOPORTS_WIDTH), "palWriteBus"); palWriteGroup(bus->portid, bus->mask, bus->offset, bits); } @@ -113,7 +113,7 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { void palSetBusMode(IOBus *bus, uint_fast8_t mode) { chDbgCheck((bus != NULL) && - (bus->offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); + (bus->offset < PAL_IOPORTS_WIDTH), "palSetBusMode"); palSetGroupMode(bus->portid, bus->mask, mode); } -- cgit v1.2.3 From 7a694b4402e8d47ef0fdc651492ee09084ebcad0 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 27 Mar 2011 21:12:43 +0000 Subject: I2C. Mutual exclusion support added. Need testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2847 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 7dede9f86..11d4fccfa 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,6 +69,19 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; i2cp->id_slave_config = NULL; + +#if I2C_USE_WAIT + i2cp->id_thread = NULL; +#endif /* I2C_USE_WAIT */ + +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->id_mutex); +#else + chSemInit(&i2cp->id_semaphore, 1); +#endif /* CH_USE_MUTEXES */ +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + #if defined(I2C_DRIVER_EXT_INIT_HOOK) I2C_DRIVER_EXT_INIT_HOOK(i2cp); #endif -- cgit v1.2.3 From ff676aee33d4061e9d8186a15ad72c78fa1466a0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 28 Mar 2011 15:32:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2848 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/icu.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 os/hal/src/icu.c (limited to 'os/hal/src') diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c new file mode 100644 index 000000000..3be67448e --- /dev/null +++ b/os/hal/src/icu.c @@ -0,0 +1,151 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file icu.c + * @brief ICU Driver code. + * + * @addtogroup ICU + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_ICU || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief ICU Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void icuInit(void) { + + icu_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p ICUDriver structure. + * + * @param[out] icup pointer to the @p ICUDriver object + * + * @init + */ +void icuObjectInit(ICUDriver *icup) { + + icup->state = ICU_STOP; + icup->config = NULL; +} + +/** + * @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) { + + chDbgCheck((icup != NULL) && (config != NULL), "icuStart"); + + chSysLock(); + chDbgAssert((icup->state == ICU_STOP) || (icup->state == ICU_READY), + "icuStart(), #1", "invalid state"); + icup->config = config; + icu_lld_start(icup); + icup->state = ICU_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the ICU peripheral. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @api + */ +void icuStop(ICUDriver *icup) { + + chDbgCheck(icup != NULL, "icuStop"); + + chSysLock(); + chDbgAssert((icup->state == ICU_STOP) || (icup->state == ICU_READY), + "icuStop(), #1", "invalid state"); + icu_lld_stop(icup); + icup->state = ICU_STOP; + chSysUnlock(); +} + +/** + * @brief Enables the input capture. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @api + */ +void icuEnable(ICUDriver *icup) { + + chSysLock(); + chDbgAssert(icup->state == ICU_READY, "icuEnable(), #1", "invalid state"); + icu_lld_enable(icup); + icup->state = ICU_WAITING; + chSysUnlock(); +} + +/** + * @brief Disables the input capture. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @api + */ +void icuDisable(ICUDriver *icup) { + + chSysLock(); + chDbgAssert((icup->state == ICU_READY) || (icup->state == ICU_WAITING) || + (icup->state == ICU_ACTIVE) || (icup->state == ICU_IDLE), + "icuDisable(), #1", "invalid state"); + icu_lld_disable(icup); + icup->state = ICU_READY; + chSysUnlock(); +} + +#endif /* HAL_USE_ICU */ + +/** @} */ -- cgit v1.2.3 From a58a524d4c7e58d03a0fa3698f09fb17985a70bc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 31 Mar 2011 10:21:52 +0000 Subject: Improvements to the PWM driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2853 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index e510ba180..eaa49bc56 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -77,6 +77,8 @@ void pwmObjectInit(PWMDriver *pwmp) { /** * @brief Configures and activates the PWM peripheral. + * @note Starting a driver that is already in the @p PWM_READY state + * disables all the active channels. * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] config pointer to a @p PWMConfig object @@ -91,6 +93,7 @@ void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { chDbgAssert((pwmp->state == PWM_STOP) || (pwmp->state == PWM_READY), "pwmStart(), #1", "invalid state"); pwmp->config = config; + pwmp->period = config->period; pwm_lld_start(pwmp); pwmp->state = PWM_READY; chSysUnlock(); @@ -115,9 +118,41 @@ void pwmStop(PWMDriver *pwmp) { chSysUnlock(); } +/** + * @brief Changes the period the PWM peripheral. + * @details This function changes the period of a PWM unit that has already + * been activated using @p pwmStart(). + * @pre The PWM unit must have been activated using @p pwmStart(). + * @post The PWM unit period is changed to the new value. + * @post Any active channel is disabled by this function and must be + * activated explicitly using @p pwmEnableChannel(). + * @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 + * + * @api + */ +void pwmChangePeriod(PWMDriver *pwmp, pwmcnt_t period) { + + chDbgCheck(pwmp != NULL, "pwmChangePeriod"); + + chSysLock(); + chDbgAssert(pwmp->state == PWM_READY, + "pwmChangePeriod(), #1", "invalid state"); + pwmp->period = period; + pwm_lld_change_period(pwmp, period); + chSysUnlock(); +} + /** * @brief Enables a PWM channel. - * @details Programs (or reprograms) 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) @@ -141,8 +176,12 @@ void pwmEnableChannel(PWMDriver *pwmp, /** * @brief Disables a PWM channel. - * @details The channel is disabled and its output line returned to the + * @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...PWM_CHANNELS-1) -- cgit v1.2.3 From 0b0fb6f88f6851842e89f19129b0dc535f41dcbc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 1 Apr 2011 08:45:34 +0000 Subject: ICU driver functional. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2857 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 09b832fe2..8555b44bb 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -73,6 +73,9 @@ void halInit(void) { #if HAL_USE_I2C || defined(__DOXYGEN__) i2cInit(); #endif +#if HAL_USE_ICU || defined(__DOXYGEN__) + icuInit(); +#endif #if HAL_USE_MAC || defined(__DOXYGEN__) macInit(); #endif -- cgit v1.2.3 From 01b0220ffa200db034b0be6b0f464ec3344e3c15 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 1 Apr 2011 13:14:47 +0000 Subject: Documentation related fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2862 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index eaa49bc56..ed80ec24b 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -131,6 +131,7 @@ void pwmStop(PWMDriver *pwmp) { * or immediately (fallback implementation). * * @param[in] pwmp pointer to a @p PWMDriver object + * @param[in] period new cycle time in ticks * * @api */ -- cgit v1.2.3 From 57fb5e703ba8ab824d1849d7436abd64684caf20 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 2 Apr 2011 09:33:46 +0000 Subject: I2C. Additional locks added to avoiding system hangups. Some mistypes in comments fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2865 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 11d4fccfa..ad9a5d0ac 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -138,7 +138,9 @@ void i2cMasterStart(I2CDriver *i2cp){ chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + chSysLock(); i2c_lld_master_start(i2cp); + chSysUnlock(); } /** @@ -149,8 +151,9 @@ void i2cMasterStart(I2CDriver *i2cp){ void i2cMasterStop(I2CDriver *i2cp){ chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); - + chSysLock(); i2c_lld_master_stop(i2cp); + chSysUnlock(); } /** @@ -168,7 +171,9 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); + chSysLock(); i2c_lld_master_transmit(i2cp, i2cscfg); + chSysUnlock(); } @@ -186,7 +191,9 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); + chSysLock(); i2c_lld_master_receive(i2cp, i2cscfg); + chSysUnlock(); } -- cgit v1.2.3 From ad009f46d58f4f555cd412aa2f2a267da01db4e0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 5 Apr 2011 18:21:00 +0000 Subject: STM32 PWM driver optimization, changed the behavior of pwmChangePeriod(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2869 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pwm.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ed80ec24b..e7dd6b64c 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -124,11 +124,9 @@ void pwmStop(PWMDriver *pwmp) { * been activated using @p pwmStart(). * @pre The PWM unit must have been activated using @p pwmStart(). * @post The PWM unit period is changed to the new value. - * @post Any active channel is disabled by this function and must be - * activated explicitly using @p pwmEnableChannel(). - * @note Depending on the hardware implementation this function has - * effect starting on the next cycle (recommended implementation) - * or immediately (fallback implementation). + * @note If a period is specified that is shorter than the pulse width + * programmed in one of the channels then the behavior is not + * guaranteed. * * @param[in] pwmp pointer to a @p PWMDriver object * @param[in] period new cycle time in ticks @@ -142,8 +140,7 @@ void pwmChangePeriod(PWMDriver *pwmp, pwmcnt_t period) { chSysLock(); chDbgAssert(pwmp->state == PWM_READY, "pwmChangePeriod(), #1", "invalid state"); - pwmp->period = period; - pwm_lld_change_period(pwmp, period); + pwmChangePeriodI(pwmp, period); chSysUnlock(); } -- cgit v1.2.3 From de877486efb49378065f769ff423eef19ceb12e6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 9 Apr 2011 15:10:15 +0000 Subject: Fixed bug 3276379. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2872 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index b6ad10c13..bc2c39426 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -59,44 +59,44 @@ static cdc_linecoding_t linecoding = { static size_t writes(void *ip, const uint8_t *bp, size_t n) { - return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, + return chOQWriteTimeout(&((SerialUSBDriver *)ip)->oqueue, bp, n, TIME_INFINITE); } static size_t reads(void *ip, uint8_t *bp, size_t n) { - return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, + return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, TIME_INFINITE); } static bool_t putwouldblock(void *ip) { - return chOQIsFullI(&((SerialDriver *)ip)->oqueue); + return chOQIsFullI(&((SerialUSBDriver *)ip)->oqueue); } static bool_t getwouldblock(void *ip) { - return chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); + return chIQIsEmptyI(&((SerialUSBDriver *)ip)->iqueue); } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { - return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, timeout); + return chOQPutTimeout(&((SerialUSBDriver *)ip)->oqueue, b, timeout); } static msg_t gett(void *ip, systime_t timeout) { - return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, timeout); + return chIQGetTimeout(&((SerialUSBDriver *)ip)->iqueue, timeout); } static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { - return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, time); + return chOQWriteTimeout(&((SerialUSBDriver *)ip)->oqueue, bp, n, time); } static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { - return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); + return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time); } static ioflags_t getflags(void *ip) { @@ -124,7 +124,7 @@ static void inotify(GenericQueue *qp) { sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - chSemSetCounterI(&sdup->iqueue.q_sem, n); + chSemAddCounterI(&sdup->iqueue.q_sem, n); chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); } } @@ -135,15 +135,16 @@ static void inotify(GenericQueue *qp) { */ static void onotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; - size_t n; + size_t w, n; /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ - n = usbWritePacketI(sdup->config->usbp, DATA_REQUEST_EP, - sdup->oqueue.q_buffer, chOQGetFullI(&sdup->oqueue)); - if (n != USB_ENDPOINT_BUSY) { + n = chOQGetFullI(&sdup->oqueue); + w = usbWritePacketI(sdup->config->usbp, DATA_REQUEST_EP, + sdup->oqueue.q_buffer, n); + if (w != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); + chSemAddCounterI(&sdup->oqueue.q_sem, n); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); } } @@ -276,17 +277,17 @@ bool_t sduRequestsHook(USBDriver *usbp) { */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; - size_t n; + size_t n, w; chSysLockFromIsr(); /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); if (n > 0) { - n = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); - if (n != USB_ENDPOINT_BUSY) { + w = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); + if (w != USB_ENDPOINT_BUSY) { sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); + chSemAddCounterI(&sdup->oqueue.q_sem, n); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); } } @@ -314,7 +315,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - chSemSetCounterI(&sdup->iqueue.q_sem, n); + chSemAddCounterI(&sdup->iqueue.q_sem, n); chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); } } -- cgit v1.2.3 From ccbfd6ecc058ba55899bcaa9b360887a0330c1a5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 25 Apr 2011 12:41:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2901 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 8555b44bb..1a15988f5 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -85,6 +85,9 @@ void halInit(void) { #if HAL_USE_SERIAL || defined(__DOXYGEN__) sdInit(); #endif +#if HAL_USE_SDC || defined(__DOXYGEN__) + sdcInit(); +#endif #if HAL_USE_SPI || defined(__DOXYGEN__) spiInit(); #endif -- cgit v1.2.3 From 2f4dba80ea1d68a1165ca04a6b4d1ccd5853c27d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 26 Apr 2011 16:59:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2903 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 os/hal/src/sdc.c (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c new file mode 100644 index 000000000..33f2b3612 --- /dev/null +++ b/os/hal/src/sdc.c @@ -0,0 +1,207 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sdc.c + * @brief SDC Driver code. + * + * @addtogroup SDC + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_SDC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief SDC Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void sdcInit(void) { + + sdc_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p SDCDriver structure. + * + * @param[out] sdcp pointer to the @p SDCDriver object + * + * @init + */ +void sdcObjectInit(SDCDriver *sdcp) { + + sdcp->state = SDC_STOP; + sdcp->config = NULL; +} + +/** + * @brief Configures and activates the SDC peripheral. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[in] config pointer to the @p SDCConfig object + * + * @api + */ +void sdcStart(SDCDriver *sdcp, const SDCConfig *config) { + + chDbgCheck((sdcp != NULL) && (config != NULL), "sdcStart"); + + chSysLock(); + chDbgAssert((sdcp->state == SDC_STOP) || (sdcp->state == SDC_READY), + "sdcStart(), #1", "invalid state"); + sdcp->config = config; + sdc_lld_start(sdcp); + sdcp->state = SDC_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the SDC peripheral. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * + * @api + */ +void sdcStop(SDCDriver *sdcp) { + + chDbgCheck(sdcp != NULL, "sdcStop"); + + chSysLock(); + chDbgAssert((sdcp->state == SDC_STOP) || (sdcp->state == SDC_READY), + "sdcStop(), #1", "invalid state"); + sdc_lld_stop(sdcp); + sdcp->state = SDC_STOP; + chSysUnlock(); +} + +/** + * @brief Performs the initialization procedure on the inserted card. + * @details This function should be invoked when a card is inserted and + * brings the driver in the @p SDC_ACTIVE state where it is possible + * to perform read and write operations. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @return The operation status. + * @retval FALSE operation succeeded, the driver is now + * in the @p SDC_ACTIVE state. + * @retval TRUE operation failed. + * + * @api + */ +bool_t sdcConnect(SDCDriver *sdcp) { + + chDbgCheck(sdcp != NULL, "sdcConnect"); + + chSysLock(); + chDbgAssert(sdcp->state == SDC_READY, "mmcConnect(), #1", "invalid state"); + sdcp->state = SDC_INITNG; + chSysUnlock(); + + sdcp->state = SDC_ACTIVE; + return FALSE; +} + +/** + * @brief Brings the driver in a state safe for card removal. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @return The operation status. + * @retval FALSE the operation succeeded and the driver is now + * in the @p SDC_READY state. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t sdcDisconnect(SDCDriver *sdcp) { + + chDbgCheck(sdcp != NULL, "sdcConnect"); + + chSysLock(); + chDbgAssert(sdcp->state == SDC_ACTIVE, + "sdcDisconnect(), #1", "invalid state"); + sdcp->state = SDC_READY; + chSysUnlock(); + return FALSE; +} + +/** + * @brief Reads one or more blocks. + * @pre The driver must be in the @p SDC_ACTIVE state after a successful + * sdcConnect() invocation. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[in] startblk first block to read + * @param[out] buffer pointer to the read buffer + * @return The operation status. + * @retval FALSE operation succeeded, the requested blocks have been + * read. + * @retval TRUE operation failed, the state of the buffer is uncertain. + * + * @api + */ +bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, + uint8_t *buffer, uint32_t n) { + +} + +/** + * @brief Writes one or more blocks. + * @pre The driver must be in the @p SDC_ACTIVE state after a successful + * sdcConnect() invocation. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[in] startblk first block to write + * @param[out] buffer pointer to the write buffer + * @return The operation status. + * @retval FALSE operation succeeded, the requested blocks have been + * written. + * @retval TRUE operation failed. + * + * @api + */ +bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, + const uint8_t *buffer, uint32_t n) { + +} + +#endif /* HAL_USE_SDC */ + +/** @} */ -- cgit v1.2.3 From 2e7866f634ddf31530c0c83ff8bdfc3b75f42e82 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 30 Apr 2011 07:52:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2905 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 33f2b3612..701071b8b 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -135,6 +135,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdcp->state = SDC_INITNG; chSysUnlock(); + sdc_lld_start_clk(sdcp); + sdcp->state = SDC_ACTIVE; return FALSE; } -- cgit v1.2.3 From dd9cac5ffa29031b1175bb750e587a20362f5276 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 30 Apr 2011 18:46:09 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2907 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 701071b8b..b64dcf9c5 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -137,6 +137,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdc_lld_start_clk(sdcp); + sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0); + sdcp->state = SDC_ACTIVE; return FALSE; } -- cgit v1.2.3 From 40c7b22bf43d795d9e6822f67907a1665aa6d7b6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 May 2011 09:10:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2908 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index b64dcf9c5..07f25aa65 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -127,6 +127,7 @@ void sdcStop(SDCDriver *sdcp) { * @api */ bool_t sdcConnect(SDCDriver *sdcp) { + uint32_t resp; chDbgCheck(sdcp != NULL, "sdcConnect"); @@ -135,12 +136,60 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdcp->state = SDC_INITNG; chSysUnlock(); + /* Resets card attributes.*/ + sdcp->cardmode = 0; + + /* Card clock initialization.*/ sdc_lld_start_clk(sdcp); + /* Enforces the initial card state.*/ sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0); + /* V2.0 cards detection.*/ + if (!sdc_lld_send_cmd_short(sdcp, SDC_CMD_SEND_IF_COND, + SDC_CMD8_PATTERN, &resp)) + sdcp->cardmode |= SDC_MODE_CARDTYPE_SDV20; + /* Voltage verification.*/ + if (((resp >> 8) & 0xF) != 1) + goto failed; + if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + goto failed; + else { + /* MMC or SD detection.*/ + if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + sdcp->cardmode |= SDC_MODE_CARDTYPE_MMC; + } + + if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { + } + else { + uint32_t ocr = 0x80100000; + unsigned i; + + if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_SDV20) + ocr |= 0x40000000; + + /* SD-type initialization. */ + i = 0; + while (TRUE) { + chThdSleepMilliseconds(10); + if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + goto failed; + if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, &resp)) + goto failed; + if ((resp & 0x80000000) != 0) + break; + if (++i >= SDC_ACMD41_RETRY) + goto failed; + } + } + sdcp->state = SDC_ACTIVE; return FALSE; +failed: + sdc_lld_stop_clk(sdcp); + sdcp->state = SDC_READY; + return TRUE; } /** -- cgit v1.2.3 From d5fb75afc4c7203500108fd573f90bfbbd1ac498 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 May 2011 10:33:44 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2909 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 07f25aa65..7cfac6705 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -146,17 +146,17 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0); /* V2.0 cards detection.*/ - if (!sdc_lld_send_cmd_short(sdcp, SDC_CMD_SEND_IF_COND, - SDC_CMD8_PATTERN, &resp)) + if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND, + SDC_CMD8_PATTERN, &resp)) sdcp->cardmode |= SDC_MODE_CARDTYPE_SDV20; /* Voltage verification.*/ if (((resp >> 8) & 0xF) != 1) goto failed; - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) goto failed; else { /* MMC or SD detection.*/ - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) sdcp->cardmode |= SDC_MODE_CARDTYPE_MMC; } @@ -173,7 +173,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { i = 0; while (TRUE) { chThdSleepMilliseconds(10); - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, &resp)) goto failed; -- cgit v1.2.3 From b33b5201ad65ed0dafb2b9e0a2c40bf06fe27dfc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 May 2011 11:14:23 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2910 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 7cfac6705..2fd4e7f7b 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -127,7 +127,7 @@ void sdcStop(SDCDriver *sdcp) { * @api */ bool_t sdcConnect(SDCDriver *sdcp) { - uint32_t resp; + uint32_t resp[1]; chDbgCheck(sdcp != NULL, "sdcConnect"); @@ -136,9 +136,6 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdcp->state = SDC_INITNG; chSysUnlock(); - /* Resets card attributes.*/ - sdcp->cardmode = 0; - /* Card clock initialization.*/ sdc_lld_start_clk(sdcp); @@ -147,17 +144,19 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* V2.0 cards detection.*/ if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND, - SDC_CMD8_PATTERN, &resp)) - sdcp->cardmode |= SDC_MODE_CARDTYPE_SDV20; + SDC_CMD8_PATTERN, resp)) + sdcp->cardmode = SDC_MODE_CARDTYPE_SDV20; /* Voltage verification.*/ - if (((resp >> 8) & 0xF) != 1) + if (((resp[0] >> 8) & 0xF) != 1) goto failed; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) goto failed; else { /* MMC or SD detection.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) - sdcp->cardmode |= SDC_MODE_CARDTYPE_MMC; + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) + sdcp->cardmode = SDC_MODE_CARDTYPE_MMC; + else + sdcp->cardmode = SDC_MODE_CARDTYPE_SDV11; } if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { @@ -173,17 +172,36 @@ bool_t sdcConnect(SDCDriver *sdcp) { i = 0; while (TRUE) { chThdSleepMilliseconds(10); - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) goto failed; - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, &resp)) + if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) goto failed; - if ((resp & 0x80000000) != 0) + if ((resp[0] & 0x80000000) != 0) break; if (++i >= SDC_ACMD41_RETRY) goto failed; } } + /* Reads CID.*/ + if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_ALL_SEND_CID, 0, sdcp->cid)) + goto failed; + + /* Asks for the RCA.*/ + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, 0, resp)) + goto failed; + + /* Reads CSD.*/ + if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_SEND_CSD, resp[0], sdcp->csd)) + goto failed; + + /* Switches to high speed.*/ + sdc_lld_set_data_clk(sdcp); + + /* Selects the card for operations.*/ + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, resp[0], resp)) + goto failed; + sdcp->state = SDC_ACTIVE; return FALSE; failed: -- cgit v1.2.3 From 82b9e1cf4c0de6be44e273f3e49c3efbd0895d3f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 May 2011 14:33:22 +0000 Subject: SDC card initialization works. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2911 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 2fd4e7f7b..a4b80e60b 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -176,8 +176,11 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) goto failed; - if ((resp[0] & 0x80000000) != 0) + if ((resp[0] & 0x80000000) != 0) { + if (resp[0] & 0x40000000) + sdcp->cardmode |= SDC_MODE_HIGH_CAPACITY; break; + } if (++i >= SDC_ACMD41_RETRY) goto failed; } @@ -202,6 +205,17 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, resp[0], resp)) goto failed; + /* Block lenght fixed at 512 bytes.*/ + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, 512, resp)) + goto failed; + + /* Switches to wide bus mode.*/ + switch (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) { + case SDC_MODE_CARDTYPE_SDV11: + case SDC_MODE_CARDTYPE_SDV20: + SDIO->CLKCR |= SDIO_CLKCR_WIDBUS_0; + } + sdcp->state = SDC_ACTIVE; return FALSE; failed: @@ -228,6 +242,7 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcDisconnect(), #1", "invalid state"); + sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; chSysUnlock(); return FALSE; -- cgit v1.2.3 From 31456cb4fea72d79b9c1af9a5b0cc7e3fed1ed6e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 2 May 2011 15:23:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2914 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index a4b80e60b..847647de4 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -205,8 +205,9 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, resp[0], resp)) goto failed; - /* Block lenght fixed at 512 bytes.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, 512, resp)) + /* Block length fixed at 512 bytes.*/ + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, + SDC_BLOCK_SIZE, resp)) goto failed; /* Switches to wide bus mode.*/ @@ -237,7 +238,7 @@ failed: */ bool_t sdcDisconnect(SDCDriver *sdcp) { - chDbgCheck(sdcp != NULL, "sdcConnect"); + chDbgCheck(sdcp != NULL, "sdcDisconnect"); chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, @@ -255,7 +256,8 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in] startblk first block to read - * @param[out] buffer pointer to the read buffer + * @param[out] buf pointer to the read buffer + * @param[in] n number of blocks to read * @return The operation status. * @retval FALSE operation succeeded, the requested blocks have been * read. @@ -264,8 +266,23 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @api */ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, - uint8_t *buffer, uint32_t n) { + uint8_t *buf, uint32_t n) { + bool_t sts; + uint32_t resp[1]; + + chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcRead"); + + if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) + startblk *= SDC_BLOCK_SIZE; + + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, + startblk, resp)) + return TRUE; + sts = sdc_lld_read_blocks(sdcp, buffer, n); + sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, + 0, resp); + return sts; } /** @@ -275,7 +292,8 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in] startblk first block to write - * @param[out] buffer pointer to the write buffer + * @param[out] buf pointer to the write buffer + * @param[in] n number of blocks to write * @return The operation status. * @retval FALSE operation succeeded, the requested blocks have been * written. @@ -284,8 +302,23 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @api */ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, - const uint8_t *buffer, uint32_t n) { + const uint8_t *buf, uint32_t n) { + bool_t sts; + uint32_t resp[1]; + + chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcWrite"); + + if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) + startblk *= SDC_BLOCK_SIZE; + + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, + startblk, resp)) + return TRUE; + sts = sdc_lld_write_blocks(sdcp, buffer, n); + sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, + 0, resp); + return sts; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From f6ed2f2a8427129c0d24dee81536dbcedaf2d793 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 2 May 2011 19:49:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2916 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 847647de4..3188afb64 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -270,7 +270,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, bool_t sts; uint32_t resp[1]; - chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcRead"); + chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; @@ -279,7 +279,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, startblk, resp)) return TRUE; - sts = sdc_lld_read_blocks(sdcp, buffer, n); + sts = sdc_lld_read_blocks(sdcp, buf, n); sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, 0, resp); return sts; @@ -306,7 +306,7 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, bool_t sts; uint32_t resp[1]; - chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcWrite"); + chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcWrite"); if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; @@ -315,7 +315,7 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, startblk, resp)) return TRUE; - sts = sdc_lld_write_blocks(sdcp, buffer, n); + sts = sdc_lld_write_blocks(sdcp, buf, n); sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, 0, resp); return sts; -- cgit v1.2.3 From 2459b2beb0af669675d93c57fc132c734981667c Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 4 May 2011 13:12:34 +0000 Subject: I2C. My driver really sucks. I'll try to use alberto driver with my improvements git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2918 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c_brts.c | 64 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c_brts.c b/os/hal/src/i2c_brts.c index 5a0471e0f..ad9a5d0ac 100644 --- a/os/hal/src/i2c_brts.c +++ b/os/hal/src/i2c_brts.c @@ -69,6 +69,19 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; i2cp->id_slave_config = NULL; + +#if I2C_USE_WAIT + i2cp->id_thread = NULL; +#endif /* I2C_USE_WAIT */ + +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->id_mutex); +#else + chSemInit(&i2cp->id_semaphore, 1); +#endif /* CH_USE_MUTEXES */ +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + #if defined(I2C_DRIVER_EXT_INIT_HOOK) I2C_DRIVER_EXT_INIT_HOOK(i2cp); #endif @@ -116,14 +129,38 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Generate (re)start on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStart(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + chSysLock(); + i2c_lld_master_start(i2cp); + chSysUnlock(); +} + +/** + * @brief Generate stop on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStop(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + chSysLock(); + i2c_lld_master_stop(i2cp); + chSysUnlock(); +} + /** * @brief Sends data ever the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object * */ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -134,19 +171,17 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmitI(i2cp, i2cscfg); + chSysLock(); + i2c_lld_master_transmit(i2cp, i2cscfg); + chSysUnlock(); } /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object */ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -156,14 +191,13 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receiveI(i2cp, i2cscfg); + chSysLock(); + i2c_lld_master_receive(i2cp, i2cscfg); + chSysUnlock(); } - - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3 From 4fda4dc84fcfcfa483f10a8b5043d124ad551ba0 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 5 May 2011 17:43:54 +0000 Subject: I2C. Code compiles successfully, but totally not tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2921 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 150 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 109 insertions(+), 41 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ad9a5d0ac..50767b3a9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -130,106 +130,174 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Generate (re)start on the bus. + * @brief Sends data ever the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * */ -void i2cMasterStart(I2CDriver *i2cp){ +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + size_t n; + i2cblock_t *txbuf; + + txbuf = i2cscfg->txbuf; + n = i2cscfg->tx_remaining_bytes; + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && (txbuf != NULL), + "i2cMasterTransmit"); - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + // init slave config field in driver + i2cp->id_slave_config = i2cscfg; + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif chSysLock(); - i2c_lld_master_start(i2cp); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterTransmit(), #1", "not ready"); + + i2cp->id_state = I2C_ACTIVE; + i2c_lld_master_transmit(i2cp); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->id_state == I2C_COMPLETE) + i2cp->id_state = I2C_READY; chSysUnlock(); } /** - * @brief Generate stop on the bus. + * @brief Receives data from the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * */ -void i2cMasterStop(I2CDriver *i2cp){ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ + + size_t n; + i2cblock_t *rxbuf; + + rxbuf = i2cscfg->rxbuf; + n = i2cscfg->rx_remaining_bytes; + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cMasterReceive"); + + // init slave config field in driver + i2cp->id_slave_config = i2cscfg; + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); chSysLock(); - i2c_lld_master_stop(i2cp); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterReceive(), #1", "not ready"); + + i2cp->id_state = I2C_ACTIVE; + i2c_lld_master_receive(i2cp); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->id_state == I2C_COMPLETE) + i2cp->id_state = I2C_READY; chSysUnlock(); } +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + i2cMasterReceive(i2cp, i2cscfg); + return i2cp->id_slave_config->slave_addr; +} + + /** - * @brief Sends data ever the I2C bus. + * @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 the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object + * @param[in] i2cp pointer to a @p I2CDriver structure + * @param[in] mask condition flags to be added to the mask * + * @iclass */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterTransmit"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", - "not active"); + chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - chSysLock(); - i2c_lld_master_transmit(i2cp, i2cscfg); - chSysUnlock(); + i2cp->id_slave_config->errors |= mask; + chEvtBroadcastI(&i2cp->id_slave_config->sevent); } - /** - * @brief Receives data from the I2C bus. + * @brief Returns and clears the errors mask associated to the driver. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object + * @param[in] i2cp pointer to a @p I2CDriver structure + * @return The condition flags modified since last time this + * function was invoked. + * + * @api */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { + i2cflags_t mask; - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterReceive"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterReceive(), #1", - "not active"); + chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); chSysLock(); - i2c_lld_master_receive(i2cp, i2cscfg); + mask = i2cp->id_slave_config->errors; + i2cp->id_slave_config->errors = I2CD_NO_ERROR; chSysUnlock(); + return mask; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the I2C bus. + * @brief Gains exclusive access to the I2C bus. * @details This function tries to gain ownership to the I2C bus, if the bus * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @api - * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. */ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); + chMtxLock(&i2cp->mutex); #elif CH_USE_SEMAPHORES chSemWait(&i2cp->id_semaphore); #endif } /** - * @brief Releases exclusive access to the I2C bus. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. + * @brief Releases exclusive access to the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @api + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. */ void i2cReleaseBus(I2CDriver *i2cp) { -- cgit v1.2.3 From 60975ca7fed0e2960bced2fe72239422f8376068 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 6 May 2011 15:16:15 +0000 Subject: I2C. Some fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2922 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 50767b3a9..1a2873a29 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -140,11 +140,14 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { size_t n; i2cblock_t *txbuf; + uint8_t nbit_addr; txbuf = i2cscfg->txbuf; + nbit_addr = i2cscfg->nbit_address; n = i2cscfg->tx_remaining_bytes; - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && (txbuf != NULL), + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ + ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), "i2cMasterTransmit"); // init slave config field in driver @@ -186,11 +189,14 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ size_t n; i2cblock_t *rxbuf; + uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; n = i2cscfg->rx_remaining_bytes; + nbit_addr = i2cscfg->nbit_address; - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ + ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), "i2cMasterReceive"); // init slave config field in driver @@ -221,6 +227,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ chSysUnlock(); } + uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { i2cMasterReceive(i2cp, i2cscfg); -- cgit v1.2.3 From 7109dcee27d7fbfa77f1c9b16c934f6ca550f5d5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 7 May 2011 13:24:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2923 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 3188afb64..1874510a0 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -211,11 +211,11 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; /* Switches to wide bus mode.*/ - switch (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) { +/* switch (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) { case SDC_MODE_CARDTYPE_SDV11: case SDC_MODE_CARDTYPE_SDV20: SDIO->CLKCR |= SDIO_CLKCR_WIDBUS_0; - } + }*/ sdcp->state = SDC_ACTIVE; return FALSE; @@ -268,20 +268,33 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { bool_t sts; - uint32_t resp[1]; + uint32_t resp[4]; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); + chSysLock(); + chDbgAssert(sdcp->state == SDC_ACTIVE, + "sdcDisconnect(), #1", "invalid state"); + sdcp->state = SDC_READING; + chSysUnlock(); + if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, - startblk, resp)) +/* if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) return TRUE; + if (sdc_lld_send_cmd_long_crc(sdcp, 51, 0, resp)) + return TRUE; + + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCK_COUNT, n, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) + return TRUE;*/ - sts = sdc_lld_read_blocks(sdcp, buf, n); + sts = sdc_lld_read(sdcp, startblk, buf, n); sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, 0, resp); + sdcp->state = SDC_ACTIVE; return sts; } @@ -315,7 +328,7 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, startblk, resp)) return TRUE; - sts = sdc_lld_write_blocks(sdcp, buf, n); + sts = sdc_lld_write(sdcp, startblk, buf, n); sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, 0, resp); return sts; -- cgit v1.2.3 From 6dc70a8453a1a2b5953330dcd688f2121ad62732 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 7 May 2011 16:16:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2924 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 1874510a0..25fe6a259 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -281,19 +281,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; -/* if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) - return TRUE; - if (sdc_lld_send_cmd_long_crc(sdcp, 51, 0, resp)) - return TRUE; - - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCK_COUNT, n, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) - return TRUE;*/ - sts = sdc_lld_read(sdcp, startblk, buf, n); - sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, - 0, resp); sdcp->state = SDC_ACTIVE; return sts; } -- cgit v1.2.3 From a8ea499b27805ce5fa109f64cfff073c9b077f3b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 8 May 2011 05:58:29 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2927 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 25fe6a259..3af421254 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -268,7 +268,6 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { bool_t sts; - uint32_t resp[4]; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); -- cgit v1.2.3 From eb36dbf4fe229a76e09219fc6ed0b3ce9d81095f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 8 May 2011 09:28:29 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2933 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 3af421254..42b7cd903 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -272,8 +272,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); chSysLock(); - chDbgAssert(sdcp->state == SDC_ACTIVE, - "sdcDisconnect(), #1", "invalid state"); + chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcRead(), #1", "invalid state"); sdcp->state = SDC_READING; chSysUnlock(); @@ -304,20 +303,19 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n) { bool_t sts; - uint32_t resp[1]; - chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcWrite"); + chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); + + chSysLock(); + chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcWrite(), #1", "invalid state"); + sdcp->state = SDC_WRITING; + chSysUnlock(); if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, - startblk, resp)) - return TRUE; - sts = sdc_lld_write(sdcp, startblk, buf, n); - sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, - 0, resp); + sdcp->state = SDC_ACTIVE; return sts; } -- cgit v1.2.3 From 732eaa72c18b9bc6ddb9b6c5ac2294420d14552e Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 8 May 2011 13:20:10 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2937 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 1a2873a29..18d1d78c0 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { txbuf = i2cscfg->txbuf; nbit_addr = i2cscfg->nbit_address; - n = i2cscfg->tx_remaining_bytes; + n = i2cscfg->tx_bytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), @@ -192,7 +192,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rx_remaining_bytes; + n = i2cscfg->rx_bytes; nbit_addr = i2cscfg->nbit_address; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ -- cgit v1.2.3 From 539fc8bfc35d0d03c46d553d21c8f332f4a9eb55 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 9 May 2011 17:54:23 +0000 Subject: Enabled 4 bits mode enabling in the SDC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2944 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 42b7cd903..334caec0d 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -173,7 +173,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { while (TRUE) { chThdSleepMilliseconds(10); if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) - goto failed; + goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) goto failed; if ((resp[0] & 0x80000000) != 0) { @@ -191,18 +191,18 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; /* Asks for the RCA.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, 0, resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, 0, &sdcp->rca)) goto failed; /* Reads CSD.*/ - if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_SEND_CSD, resp[0], sdcp->csd)) + if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_SEND_CSD, sdcp->rca, sdcp->csd)) goto failed; /* Switches to high speed.*/ sdc_lld_set_data_clk(sdcp); /* Selects the card for operations.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, resp[0], resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, sdcp->rca, resp)) goto failed; /* Block length fixed at 512 bytes.*/ @@ -211,11 +211,17 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; /* Switches to wide bus mode.*/ -/* switch (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) { + switch (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) { case SDC_MODE_CARDTYPE_SDV11: case SDC_MODE_CARDTYPE_SDV20: - SDIO->CLKCR |= SDIO_CLKCR_WIDBUS_0; - }*/ + sdc_lld_set_bus_mode(sdcp, SDC_MODE_4BIT); + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, sdcp->rca, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) + goto failed; + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BUS_WIDTH, 2, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) + goto failed; + } sdcp->state = SDC_ACTIVE; return FALSE; -- cgit v1.2.3 From f91dff51cc155f265a65417087f3402e99f6e5ae Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 9 May 2011 19:30:55 +0000 Subject: Added SDC status check to sdcWrite(); git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2945 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 334caec0d..5e1bede8f 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -149,11 +149,13 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* Voltage verification.*/ if (((resp[0] >> 8) & 0xF) != 1) goto failed; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) goto failed; else { /* MMC or SD detection.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) sdcp->cardmode = SDC_MODE_CARDTYPE_MMC; else sdcp->cardmode = SDC_MODE_CARDTYPE_SDV11; @@ -172,7 +174,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { i = 0; while (TRUE) { chThdSleepMilliseconds(10); - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) goto failed; @@ -207,7 +210,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* Block length fixed at 512 bytes.*/ if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, - SDC_BLOCK_SIZE, resp)) + SDC_BLOCK_SIZE, resp) || + (resp[0] & SDC_R1_ERROR_MASK)) goto failed; /* Switches to wide bus mode.*/ -- cgit v1.2.3 From 0cb8d71e9da98423ea75f0c77b05d4a441d57af8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 10 May 2011 18:33:49 +0000 Subject: SDC improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2946 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 103 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 23 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 5e1bede8f..7eaa8e631 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -43,6 +43,43 @@ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Wait for the card to complete pending operations. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @return The operation status. + * @retval FALSE the card is now in transfer state. + * @retval TRUE an error occurred while waiting or the card is in an + * unexpected state. + * + * @notapi + */ +bool_t sdc_wait_for_transfer_state(SDCDriver *sdcp) { + uint32_t resp[1]; + + while (TRUE) { + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS, + sdcp->rca, resp) || + SDC_R1_ERROR(resp[0])) + return TRUE; + switch (SDC_R1_STS(resp[0])) { + case SDC_STS_TRAN: + return FALSE; + case SDC_STS_DATA: + case SDC_STS_RCV: + case SDC_STS_PRG: +#if SDC_NICE_WAITING + chThdSleepMilliseconds(1); +#endif + continue; + default: + /* The card should have been initialized so any other state is not + valid and is reported as an error.*/ + return TRUE; + } + } +} + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -133,7 +170,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { chSysLock(); chDbgAssert(sdcp->state == SDC_READY, "mmcConnect(), #1", "invalid state"); - sdcp->state = SDC_INITNG; + sdcp->state = SDC_CONNECTING; chSysUnlock(); /* Card clock initialization.*/ @@ -150,32 +187,41 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (((resp[0] >> 8) & 0xF) != 1) goto failed; if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) goto failed; else { - /* MMC or SD detection.*/ +#if SDC_MMC_SUPPORT + /* MMC or SD V1.1 detection.*/ if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) sdcp->cardmode = SDC_MODE_CARDTYPE_MMC; else +#endif /* SDC_MMC_SUPPORT */ sdcp->cardmode = SDC_MODE_CARDTYPE_SDV11; } - if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { +#if SDC_MMC_SUPPORT + if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { + /* TODO: MMC initialization.*/ + return TRUE; } - else { - uint32_t ocr = 0x80100000; + else +#endif /* SDC_MMC_SUPPORT */ + { unsigned i; + uint32_t ocr; + /* SD initialization.*/ if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_SDV20) - ocr |= 0x40000000; + ocr = 0xC0100000; + else + ocr = 0x80100000; /* SD-type initialization. */ i = 0; while (TRUE) { - chThdSleepMilliseconds(10); if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) goto failed; @@ -184,8 +230,9 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdcp->cardmode |= SDC_MODE_HIGH_CAPACITY; break; } - if (++i >= SDC_ACMD41_RETRY) + if (++i >= SDC_INIT_RETRY) goto failed; + chThdSleepMilliseconds(10); } } @@ -194,7 +241,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; /* Asks for the RCA.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, 0, &sdcp->rca)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, + 0, &sdcp->rca)) goto failed; /* Reads CSD.*/ @@ -205,13 +253,14 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdc_lld_set_data_clk(sdcp); /* Selects the card for operations.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, sdcp->rca, resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, + sdcp->rca, resp)) goto failed; /* Block length fixed at 512 bytes.*/ if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, SDC_BLOCK_SIZE, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) goto failed; /* Switches to wide bus mode.*/ @@ -220,10 +269,10 @@ bool_t sdcConnect(SDCDriver *sdcp) { case SDC_MODE_CARDTYPE_SDV20: sdc_lld_set_bus_mode(sdcp, SDC_MODE_4BIT); if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, sdcp->rca, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) goto failed; if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BUS_WIDTH, 2, resp) || - (resp[0] & SDC_R1_ERROR_MASK)) + SDC_R1_ERROR(resp[0])) goto failed; } @@ -253,9 +302,17 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcDisconnect(), #1", "invalid state"); + sdcp->state = SDC_DISCONNECTING; + chSysUnlock(); + + /* Waits for eventual pending operations completion.*/ + if (sdc_wait_for_transfer_state(sdcp)) + return TRUE; + + /* Card clock stopped.*/ sdc_lld_stop_clk(sdcp); + sdcp->state = SDC_READY; - chSysUnlock(); return FALSE; } @@ -277,7 +334,7 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { */ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { - bool_t sts; + bool_t err; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); @@ -289,9 +346,9 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; - sts = sdc_lld_read(sdcp, startblk, buf, n); + err = sdc_lld_read(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; - return sts; + return err; } /** @@ -312,7 +369,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, */ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n) { - bool_t sts; + bool_t err; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); @@ -324,9 +381,9 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) startblk *= SDC_BLOCK_SIZE; - sts = sdc_lld_write(sdcp, startblk, buf, n); + err = sdc_lld_write(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; - return sts; + return err; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From 3cfb4077fb27e9ab51bc33d67def962ae68f26c7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 20 May 2011 07:29:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2982 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index bc2c39426..7fecd5f30 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -123,9 +123,12 @@ static void inotify(GenericQueue *qp) { n = usbReadPacketI(sdup->config->usbp, DATA_AVAILABLE_EP, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - chSemAddCounterI(&sdup->iqueue.q_sem, n); chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + if (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; + chSchRescheduleS(); } } } @@ -143,9 +146,12 @@ static void onotify(GenericQueue *qp) { w = usbWritePacketI(sdup->config->usbp, DATA_REQUEST_EP, sdup->oqueue.q_buffer, n); if (w != USB_ENDPOINT_BUSY) { - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - chSemAddCounterI(&sdup->oqueue.q_sem, n); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + sdup->oqueue.q_counter = n; + if (notempty(&sdup->oqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; + chSchRescheduleS(); } } @@ -286,9 +292,11 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { if (n > 0) { w = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); if (w != USB_ENDPOINT_BUSY) { - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - chSemAddCounterI(&sdup->oqueue.q_sem, n); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + sdup->oqueue.q_counter = n; + if (notempty(&sdup->oqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } } chSysUnlockFromIsr(); @@ -314,9 +322,11 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { n = usbReadPacketI(usbp, ep, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - chSemAddCounterI(&sdup->iqueue.q_sem, n); chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + if (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } } chSysUnlockFromIsr(); -- cgit v1.2.3 From f4ec81ae144ef2ae7ddd9a0e56082970420c0464 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 20 May 2011 12:46:24 +0000 Subject: USB CDC functionality restored, more improvements to the I/O queues. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2983 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 7fecd5f30..3f53d7df0 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -126,9 +126,8 @@ static void inotify(GenericQueue *qp) { chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; sdup->iqueue.q_counter = n; - if (notempty(&sdup->iqueue.q_waiting)) + while (notempty(&sdup->iqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; - chSchRescheduleS(); } } } @@ -148,10 +147,9 @@ static void onotify(GenericQueue *qp) { if (w != USB_ENDPOINT_BUSY) { chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = n; - if (notempty(&sdup->oqueue.q_waiting)) + sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); + while (notempty(&sdup->oqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; - chSchRescheduleS(); } } @@ -294,8 +292,8 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { if (w != USB_ENDPOINT_BUSY) { chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = n; - if (notempty(&sdup->oqueue.q_waiting)) + sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); + while (notempty(&sdup->oqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } } @@ -325,7 +323,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; sdup->iqueue.q_counter = n; - if (notempty(&sdup->iqueue.q_waiting)) + while (notempty(&sdup->iqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } } -- cgit v1.2.3 From 152f34a80c6ffe5fd17809732272823091b854e8 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 28 May 2011 12:31:47 +0000 Subject: I2C. Some refactorings. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3000 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 18d1d78c0..84dfcf958 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { txbuf = i2cscfg->txbuf; nbit_addr = i2cscfg->nbit_address; - n = i2cscfg->tx_bytes; + n = i2cscfg->txbytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), @@ -192,7 +192,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rx_bytes; + n = i2cscfg->rxbytes; nbit_addr = i2cscfg->nbit_address; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ -- cgit v1.2.3 From 88e92b3fc3a14ec04780815b1061e680dfbb9777 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 May 2011 09:09:22 +0000 Subject: Improvements to the STM32 SDC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3001 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 7eaa8e631..a7a39c268 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -343,9 +343,6 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, sdcp->state = SDC_READING; chSysUnlock(); - if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) - startblk *= SDC_BLOCK_SIZE; - err = sdc_lld_read(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; return err; @@ -371,16 +368,13 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n) { bool_t err; - chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); + chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcWrite"); chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcWrite(), #1", "invalid state"); sdcp->state = SDC_WRITING; chSysUnlock(); - if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) - startblk *= SDC_BLOCK_SIZE; - err = sdc_lld_write(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; return err; -- cgit v1.2.3 From 9b147c25513490e959acf299a0fed9beaee04457 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 5 Jun 2011 07:05:29 +0000 Subject: SDC driver state machine improved. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3027 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index a7a39c268..08c667df4 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -169,7 +169,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcConnect"); chSysLock(); - chDbgAssert(sdcp->state == SDC_READY, "mmcConnect(), #1", "invalid state"); + chDbgAssert((sdcp->state == SDC_READY) || (sdcp->state == SDC_ACTIVE), + "mmcConnect(), #1", "invalid state"); sdcp->state = SDC_CONNECTING; chSysUnlock(); @@ -302,6 +303,10 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcDisconnect(), #1", "invalid state"); + if (sdcp->state == SDC_READY) { + chSysUnlock(); + return FALSE; + } sdcp->state = SDC_DISCONNECTING; chSysUnlock(); -- cgit v1.2.3 From 03b4c7ddcb08a565104c91859f51e56e513e3fd0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 5 Jun 2011 08:39:49 +0000 Subject: FatFs demo for the STM32F103ZG using the SDC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3028 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 08c667df4..283a0ee75 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -113,13 +113,15 @@ void sdcObjectInit(SDCDriver *sdcp) { * @brief Configures and activates the SDC peripheral. * * @param[in] sdcp pointer to the @p SDCDriver object - * @param[in] config pointer to the @p SDCConfig object + * @param[in] config pointer to the @p SDCConfig object, can be @p NULL if + * the driver supports a default configuration or + * requires no configuration * * @api */ void sdcStart(SDCDriver *sdcp, const SDCConfig *config) { - chDbgCheck((sdcp != NULL) && (config != NULL), "sdcStart"); + chDbgCheck(sdcp != NULL, "sdcStart"); chSysLock(); chDbgAssert((sdcp->state == SDC_STOP) || (sdcp->state == SDC_READY), -- cgit v1.2.3 From 9e2d63e9dca04b460e36674dcb681d55f8cea5df Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 10:18:56 +0000 Subject: I2C. Deleted draft driver files git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3053 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c_albi.c | 268 -------------------------------------------------- os/hal/src/i2c_brts.c | 249 ---------------------------------------------- 2 files changed, 517 deletions(-) delete mode 100644 os/hal/src/i2c_albi.c delete mode 100644 os/hal/src/i2c_brts.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2c_albi.c b/os/hal/src/i2c_albi.c deleted file mode 100644 index 64bed78eb..000000000 --- a/os/hal/src/i2c_albi.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/** - * @brief I2C Driver initialization. - */ -void i2cInit(void) { - - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cObjectInit(I2CDriver *i2cp) { - chEvtInit(&i2cp->sevent); - i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_STOP; -// i2cp->i2cd_config = NULL; -#if I2C_USE_WAIT - i2cp->thread = NULL; -#endif /* I2C_USE_WAIT */ -#if I2C_USE_MUTUAL_EXCLUSION -#if CH_USE_MUTEXES - chMtxInit(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemInit(&i2cp->semaphore, 1); -#endif -#endif /* I2C_USE_MUTUAL_EXCLUSION */ -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @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 - */ -void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), - "i2cStart(), #1", "invalid state"); - - i2cp->nbit_address = config->nBitAddress; - i2c_lld_start(i2cp); - i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); - i2c_lld_set_opmode(i2cp, config->opMode); - i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), - "i2cStop(), #1", "invalid state"); - i2c_lld_stop(i2cp); - i2cp->state = I2C_STOP; - chSysUnlock(); -} - -/** - * @brief Sends data ever the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), - "i2cMasterTransmit"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterTransmit(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Receives data from the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of bytes to receive - * @param[out] rxbuf the pointer to the receive buffer - * - */ -void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), - "i2cMasterReceive"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterReceive(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { - uint16_t slv_addr; - - i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); - return slv_addr; -} - - -/** - * @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); -} - -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { - i2cflags_t mask; - - chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); - - chSysLock(); - mask = i2cp->errors; - i2cp->errors = I2CD_NO_ERROR; - chSysUnlock(); - return mask; -} - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* CH_HAL_USE_I2C */ diff --git a/os/hal/src/i2c_brts.c b/os/hal/src/i2c_brts.c deleted file mode 100644 index ad9a5d0ac..000000000 --- a/os/hal/src/i2c_brts.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file i2c.c - * @brief I2C Driver code. - * - * @addtogroup I2C - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * @brief I2C Driver initialization. - * @note This function is implicitly invoked by @p halInit(), there is - * no need to explicitly initialize the driver. - * - * @init - */ -void i2cInit(void) { - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[out] i2cp pointer to the @p I2CDriver object - * - * @init - */ -void i2cObjectInit(I2CDriver *i2cp) { - - i2cp->id_state = I2C_STOP; - i2cp->id_config = NULL; - i2cp->id_slave_config = NULL; - -#if I2C_USE_WAIT - i2cp->id_thread = NULL; -#endif /* I2C_USE_WAIT */ - -#if I2C_USE_MUTUAL_EXCLUSION -#if CH_USE_MUTEXES - chMtxInit(&i2cp->id_mutex); -#else - chSemInit(&i2cp->id_semaphore, 1); -#endif /* CH_USE_MUTEXES */ -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @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, I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStart(), #1", - "invalid state"); - i2cp->id_config = config; - i2c_lld_start(i2cp); - i2cp->id_state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStop(), #1", - "invalid state"); - i2c_lld_stop(i2cp); - i2cp->id_state = I2C_STOP; - chSysUnlock(); -} - -/** - * @brief Generate (re)start on the bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cMasterStart(I2CDriver *i2cp){ - - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); - - chSysLock(); - i2c_lld_master_start(i2cp); - chSysUnlock(); -} - -/** - * @brief Generate stop on the bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cMasterStop(I2CDriver *i2cp){ - - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); - chSysLock(); - i2c_lld_master_stop(i2cp); - chSysUnlock(); -} - -/** - * @brief Sends data ever the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterTransmit"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", - "not active"); - - chSysLock(); - i2c_lld_master_transmit(i2cp, i2cscfg); - chSysUnlock(); -} - - -/** - * @brief Receives data from the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object - */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterReceive"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterReceive(), #1", - "not active"); - - chSysLock(); - i2c_lld_master_receive(i2cp, i2cscfg); - chSysUnlock(); -} - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - * - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->id_semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->id_semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* HAL_USE_I2C */ - -/** @} */ -- cgit v1.2.3 From 350ae0a1a9721b8889b038cf2fce6a88f1c288e3 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 11:12:33 +0000 Subject: I2C. API BROKEN! Structure fields renamed in underscore naming style. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3055 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 6f99a1afb..b43be0261 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { uint8_t nbit_addr; txbuf = i2cscfg->txbuf; - nbit_addr = i2cscfg->nbit_address; + nbit_addr = i2cscfg->nbit_addr; n = i2cscfg->txbytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ @@ -194,7 +194,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ rxbuf = i2cscfg->rxbuf; n = i2cscfg->rxbytes; - nbit_addr = i2cscfg->nbit_address; + nbit_addr = i2cscfg->nbit_addr; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), -- cgit v1.2.3 From f3e571839bd7649073664d1c2c4ea3842695b6d5 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 13:35:26 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3056 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b43be0261..cd1a238ba 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -96,7 +96,7 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @api */ -void i2cStart(I2CDriver *i2cp, I2CConfig *config) { +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); -- cgit v1.2.3 From 79f477ba95384ef082a7f2ec71e228e02e62e864 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 14:31:27 +0000 Subject: I2C. "Slave_addr" and "nbit_addr" fields from I2CSlaveConfig structure merged together. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3057 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cd1a238ba..f31dcb7ba 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -139,17 +139,10 @@ void i2cStop(I2CDriver *i2cp) { */ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - size_t n; - i2cblock_t *txbuf; - uint8_t nbit_addr; - - txbuf = i2cscfg->txbuf; - nbit_addr = i2cscfg->nbit_addr; - n = i2cscfg->txbytes; - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ - ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), - "i2cMasterTransmit"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (i2cscfg->txbytes > 0) &&\ + (i2cscfg->txbuf != NULL), + "i2cMasterTransmit"); // init slave config field in driver i2cp->id_slave_config = i2cscfg; @@ -188,17 +181,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { */ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ - size_t n; - i2cblock_t *rxbuf; - uint8_t nbit_addr; - - rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rxbytes; - nbit_addr = i2cscfg->nbit_addr; - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ - ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), - "i2cMasterReceive"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (i2cscfg->rxbytes > 0) && \ + (i2cscfg->rxbuf != NULL), + "i2cMasterReceive"); // init slave config field in driver i2cp->id_slave_config = i2cscfg; -- cgit v1.2.3 From ec3ca5b4e615639dd3b4650eaa8d5739b78a1cbc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 19 Jun 2011 10:45:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3061 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 534935a55..10e57e284 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -110,7 +110,7 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { * * @api */ -void palSetBusMode(IOBus *bus, uint_fast8_t mode) { +void palSetBusMode(IOBus *bus, iomode_t mode) { chDbgCheck((bus != NULL) && (bus->offset < PAL_IOPORTS_WIDTH), "palSetBusMode"); -- cgit v1.2.3 From b54133ab1beba9d2923450d1d5f1b2c73dc2afa3 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 21 Jun 2011 18:30:50 +0000 Subject: I2C. Some fields from I2CSlaveConfig moved to driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3066 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f31dcb7ba..dc48b9478 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -137,10 +137,10 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] i2cscfg pointer to the @p I2C slave config * */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ - (i2cscfg->txbytes > 0) &&\ + (txbytes > 0) &&\ (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); @@ -162,7 +162,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp); + i2c_lld_master_transmit(i2cp, txbytes, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -179,10 +179,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { * @param[in] i2cscfg pointer to the @p I2C slave config * */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ - (i2cscfg->rxbytes > 0) && \ + (rxbytes > 0) && \ (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); @@ -204,7 +204,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp); + i2c_lld_master_receive(i2cp, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -215,11 +215,11 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ } -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - i2cMasterReceive(i2cp, i2cscfg); - return i2cp->id_slave_config->slave_addr; -} +//uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +// +// i2cMasterReceive(i2cp, i2cscfg); +// return i2cp->id_slave_config->slave_addr; +//} /** @@ -236,7 +236,7 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - i2cp->id_slave_config->errors |= mask; + i2cp->errors |= mask; chEvtBroadcastI(&i2cp->id_slave_config->sevent); } @@ -255,8 +255,8 @@ i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); chSysLock(); - mask = i2cp->id_slave_config->errors; - i2cp->id_slave_config->errors = I2CD_NO_ERROR; + mask = i2cp->errors; + i2cp->errors = I2CD_NO_ERROR; chSysUnlock(); return mask; } @@ -279,7 +279,7 @@ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->mutex); + chMtxLock(&i2cp->id_mutex); #elif CH_USE_SEMAPHORES chSemWait(&i2cp->id_semaphore); #endif -- cgit v1.2.3 From 70179f12dd387a82493d13fd51d5aab7e4e55674 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 21 Jun 2011 20:17:14 +0000 Subject: I2C. Slave config structure now have const qualifier. Moset of fields moved to the driver structure. May be broken events subsystem in driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3067 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index dc48b9478..4e3f5e5b9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,11 +135,17 @@ void i2cStop(I2CDriver *i2cp) { * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, size_t rxbytes) { +void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (slave_addr != 0) &&\ (txbytes > 0) &&\ (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); @@ -162,7 +168,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, txbytes, rxbytes); + i2c_lld_master_transmit(i2cp, slave_addr, txbytes, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -177,11 +183,16 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ +void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (slave_addr != 0) &&\ (rxbytes > 0) && \ (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); @@ -204,7 +215,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, rxbytes); + i2c_lld_master_receive(i2cp, slave_addr, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -215,6 +226,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ } +// FIXME: I do not know what this function must do. And can not test it //uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { // // i2cMasterReceive(i2cp, i2cscfg); -- cgit v1.2.3 From fbeff97d9230af12326c94e3875adf9438f16ed4 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:05:20 +0000 Subject: I2C. Variables shared among I2C1 and I2C2 interrupt handlers moved to driver structure. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3070 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4e3f5e5b9..56e2f4484 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,6 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; + i2cp->rxBuffp = NULL; + i2cp->txBuffp = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT -- cgit v1.2.3 From 10153a4f3062c85b4595558df5df41f8962c6aae Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:29:22 +0000 Subject: I2C. Fixed indent style. All tabs changed to 2 spaces. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3071 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 56e2f4484..75541494f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,14 +135,14 @@ void i2cStop(I2CDriver *i2cp) { /** * @brief Sends data ever the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited - * @param[in] rxbytes number of bytes to be received + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { @@ -183,13 +183,13 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ @@ -251,7 +251,7 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->id_slave_config->sevent); + chEvtBroadcastI(&i2cp->sevent); } /** -- cgit v1.2.3 From 97e643a2a2086bf8d52c77d599748849ff6a8148 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:50:13 +0000 Subject: I2C. Commetns style changed to /**/. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3073 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 75541494f..377b27ecf 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -152,7 +152,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); - // init slave config field in driver + /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; #if I2C_USE_WAIT @@ -199,7 +199,7 @@ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t s (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); - // init slave config field in driver + /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; #if I2C_USE_WAIT @@ -228,13 +228,12 @@ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t s } -// FIXME: I do not know what this function must do. And can not test it -//uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { -// -// i2cMasterReceive(i2cp, i2cscfg); -// return i2cp->id_slave_config->slave_addr; -//} - +/* FIXME: I do not know what this function must do. And can not test it +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + i2cMasterReceive(i2cp, i2cscfg); + return i2cp->id_slave_config->slave_addr; +} +*/ /** * @brief Handles communication events/errors. -- cgit v1.2.3 From b1d043cede9e37dccff9731978887f51a514c387 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 19:06:33 +0000 Subject: I2C. Some coding style improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3074 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 377b27ecf..490ecf656 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,8 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; - i2cp->rxBuffp = NULL; - i2cp->txBuffp = NULL; + i2cp->rxbuff_p = NULL; + i2cp->txbuff_p = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT @@ -144,7 +144,11 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbytes number of bytes to be transmited * @param[in] rxbytes number of bytes to be received */ -void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { +void i2cMasterTransmit(I2CDriver *i2cp, + const I2CSlaveConfig *i2cscfg, + uint16_t slave_addr, + size_t txbytes, + size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ @@ -191,7 +195,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t * Bits 10-14 unused. * @param[in] txbytes number of bytes to be transmited */ -void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ +void i2cMasterReceive(I2CDriver *i2cp, + const I2CSlaveConfig *i2cscfg, + uint16_t slave_addr, + size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ -- cgit v1.2.3 From 4a556f8a5eb68644ec0629bf5b792aacb82cdb55 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 29 Jun 2011 08:36:29 +0000 Subject: Fixed SDC driver when initializing high capacity cards. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3095 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 283a0ee75..59d7db005 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -184,7 +184,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* V2.0 cards detection.*/ if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND, - SDC_CMD8_PATTERN, resp)) + SDC_CMD8_PATTERN, resp)) { sdcp->cardmode = SDC_MODE_CARDTYPE_SDV20; /* Voltage verification.*/ if (((resp[0] >> 8) & 0xF) != 1) @@ -192,6 +192,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || SDC_R1_ERROR(resp[0])) goto failed; + } else { #if SDC_MMC_SUPPORT /* MMC or SD V1.1 detection.*/ -- cgit v1.2.3 From f73960c8dcbcc2f4f4b4aba8599a45485038ec82 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 30 Jun 2011 13:43:42 +0000 Subject: I2C. API changed. Transmit and receive buffers removed from I2CSlaveConfig. Now pointers to that buffers pass in functions arguments. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3099 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 490ecf656..dca7c6125 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -141,19 +141,23 @@ void i2cStop(I2CDriver *i2cp) { * device address. Bit 15 must be set to 1 if 10-bit * addressing modes used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] txbytes number of bytes to be transmitted + * @param[in] txbuf pointer to transmit buffer * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, + uint8_t *txbuf, size_t txbytes, + uint8_t *rxbuf, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ - (i2cscfg->txbuf != NULL), + (txbuf != NULL), "i2cMasterTransmit"); /* init slave config field in driver */ @@ -174,7 +178,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, slave_addr, txbytes, rxbytes); + i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -198,12 +202,13 @@ void i2cMasterTransmit(I2CDriver *i2cp, void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, + uint8_t *rxbuf, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ - (i2cscfg->rxbuf != NULL), + (rxbuf != NULL), "i2cMasterReceive"); /* init slave config field in driver */ @@ -224,7 +229,7 @@ void i2cMasterReceive(I2CDriver *i2cp, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, slave_addr, rxbytes); + i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); -- cgit v1.2.3 From 551a1c1f22fb53085ab9485115fc3d27af92083c Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 30 Jun 2011 21:37:34 +0000 Subject: I2C. Added dirty hack to realize thread safe dirver. Needs to be rewrited. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3100 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index dca7c6125..725e92d65 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -71,6 +71,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_config = NULL; i2cp->rxbuff_p = NULL; i2cp->txbuff_p = NULL; + i2cp->rxbuf = NULL; + i2cp->txbuf = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT @@ -154,6 +156,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes) { + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ @@ -180,11 +184,6 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } @@ -205,6 +204,8 @@ void i2cMasterReceive(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes){ + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ @@ -231,11 +232,6 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } -- cgit v1.2.3 From af0e40079ded13b8842e8d129fa6ed2f37fdf678 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 1 Jul 2011 13:36:59 +0000 Subject: I2C. Trying to add optional WAIT support. Driver broken. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3101 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 725e92d65..3f4095aa3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -156,8 +156,6 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes) { - i2cAcquireBus(i2cp); - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ @@ -167,15 +165,15 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif +//#if I2C_USE_WAIT +// i2c_lld_wait_bus_free(i2cp); +// if(i2c_lld_bus_is_busy(i2cp)) { +//#ifdef PRINTTRACE +// print("I2C Bus busy!\n"); +//#endif +// return; +// }; +//#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -204,8 +202,6 @@ void i2cMasterReceive(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes){ - i2cAcquireBus(i2cp); - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ @@ -215,15 +211,15 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif +//#if I2C_USE_WAIT +// i2c_lld_wait_bus_free(i2cp); +// if(i2c_lld_bus_is_busy(i2cp)) { +//#ifdef PRINTTRACE +// print("I2C Bus busy!\n"); +//#endif +// return; +// }; +//#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From ccb28114da9485c5e3f950fd31dfb67be1b8a173 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 3 Jul 2011 18:02:55 +0000 Subject: I2C. Driver looks working, but sometimes hangs up. I don't know, my big project cause troubles in it, or driver cause troubles in my project. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3116 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 3f4095aa3..93d00bcae 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,15 +165,18 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -//#if I2C_USE_WAIT -// i2c_lld_wait_bus_free(i2cp); -// if(i2c_lld_bus_is_busy(i2cp)) { -//#ifdef PRINTTRACE -// print("I2C Bus busy!\n"); -//#endif -// return; -// }; -//#endif +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); + return; +#else + /* the time is out */ + chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); +#endif + }; +#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -211,15 +214,18 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -//#if I2C_USE_WAIT -// i2c_lld_wait_bus_free(i2cp); -// if(i2c_lld_bus_is_busy(i2cp)) { -//#ifdef PRINTTRACE -// print("I2C Bus busy!\n"); -//#endif -// return; -// }; -//#endif +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); + return; +#else + /* the time is out */ + chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); +#endif + }; +#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From 03acd18161901b17be78e280ebbebbc0bbd47c8f Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 4 Jul 2011 14:27:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3117 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 93d00bcae..4aade6fe9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,18 +165,18 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT +#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { + if(i2c_lld_bus_is_busy(i2cp)) { /* Probably slave locks up and need reset. */ #ifdef PRINTTRACE print("I2C Bus busy!\n"); return; #else - /* the time is out */ + /* the time is out. Probably slave locks up. */ chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); -#endif +#endif /* PRINTTRACE */ }; -#endif +#endif /* CH_DBG_ENABLE_ASSERTS */ chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -214,18 +214,17 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT +#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); if(i2c_lld_bus_is_busy(i2cp)) { #ifdef PRINTTRACE print("I2C Bus busy!\n"); return; #else - /* the time is out */ chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); -#endif +#endif /* PRINTTRACE */ }; -#endif +#endif /* CH_DBG_ENABLE_ASSERTS */ chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From 6eca6554847f7a824fbbafd892c4b3797e74983d Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 7 Jul 2011 21:53:01 +0000 Subject: I2C. Driver still cause stack overflows. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3134 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4aade6fe9..4882330bd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -178,11 +178,11 @@ void i2cMasterTransmit(I2CDriver *i2cp, }; #endif /* CH_DBG_ENABLE_ASSERTS */ - chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; + chSysLock(); i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); chSysUnlock(); @@ -226,14 +226,12 @@ void i2cMasterReceive(I2CDriver *i2cp, }; #endif /* CH_DBG_ENABLE_ASSERTS */ - chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); - chSysUnlock(); } -- cgit v1.2.3 From b064c25e390f880570f119f5533e431aaae55721 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 9 Jul 2011 22:25:31 +0000 Subject: I2C. Main problem fixed, but some minor problems must to be fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3142 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4882330bd..4c9a46e5e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -182,10 +182,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - chSysLock(); i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); - chSysUnlock(); } /** -- cgit v1.2.3 From 0ada09b54288d8d632dad6cb4149234ccea34c43 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 11 Jul 2011 19:49:14 +0000 Subject: I2C. Code clean ups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3151 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4c9a46e5e..cd12d42eb 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,18 +165,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { /* Probably slave locks up and need reset. */ -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); - return; -#else - /* the time is out. Probably slave locks up. */ - chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); -#endif /* PRINTTRACE */ - }; -#endif /* CH_DBG_ENABLE_ASSERTS */ + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -212,17 +202,8 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); - return; -#else - chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); -#endif /* PRINTTRACE */ - }; -#endif /* CH_DBG_ENABLE_ASSERTS */ + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); -- cgit v1.2.3 From 621d794bf0d2a6456221f1e478de66e48c293063 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 12 Jul 2011 18:26:39 +0000 Subject: I2C. Documentation improvements. Dead code clenups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3153 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cd12d42eb..b169fb70d 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,18 +135,23 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Sends data ever the I2C bus. + * @brief Sends data via the I2C bus. + * + * @details Function designed to realize "read-through-write" transfer + * paradigm. If you want transmit data without any further read, + * than set @b rxbuf field to 0. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address. Bits 0-9 contain slave * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. + * addressing mode used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmitted * @param[in] txbuf pointer to transmit buffer - * @param[in] rxbytes number of bytes to be received + * @param[in] txbytes number of bytes to be transmitted * @param[in] rxbuf pointer to receive buffer + * @param[in] rxbytes number of bytes to be received, set it to 0 if + * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, @@ -183,9 +188,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address. Bits 0-9 contain slave * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. + * addressing mode used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, -- cgit v1.2.3 From b569145b24a59d0741a26885767efa04146f78a5 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 19 Jul 2011 20:45:57 +0000 Subject: I2C. STOP waitings was replaced by GPT callback functions. Need much of testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3166 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b169fb70d..b233764f5 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -176,7 +176,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); - i2cp->id_state = I2C_ACTIVE; + i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); } @@ -214,7 +214,7 @@ void i2cMasterReceive(I2CDriver *i2cp, chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); - i2cp->id_state = I2C_ACTIVE; + i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); } -- cgit v1.2.3 From 6ee04cf23282fff92b088ac6f408e5233eb3aa75 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 5 Aug 2011 17:24:23 +0000 Subject: I2C. Added template of synchronouse deriver. It does not work for a moment. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3190 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b233764f5..9676a3250 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -178,7 +178,11 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); +#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); +#else + i2cp->id_state = I2C_READY; +#endif /* I2C_SUPPORTS_CALLBACKS */ } /** @@ -216,7 +220,11 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); +#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); +#else + i2cp->id_state = I2C_READY; +#endif /* I2C_SUPPORTS_CALLBACKS */ } -- cgit v1.2.3 From f23670b728189b4549091d355e38218b31c0a0ad Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Aug 2011 13:19:48 +0000 Subject: Added I-class function checks to HAL APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3244 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 6 ++++-- os/hal/src/gpt.c | 10 ++++++++++ os/hal/src/icu.c | 4 ++++ os/hal/src/serial.c | 2 ++ os/hal/src/uart.c | 10 ++++++---- os/hal/src/usb.c | 22 ++++++++++++++++++++++ 6 files changed, 48 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 4843ca90b..f2bf4eadd 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -176,13 +176,14 @@ void adcStartConversionI(ADCDriver *adcp, adcsample_t *samples, size_t depth) { + chDbgCheckClassI(); chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) && ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); - chDbgAssert((adcp->state == ADC_READY) || (adcp->state == ADC_COMPLETE), "adcStartConversionI(), #1", "not ready"); + adcp->samples = samples; adcp->depth = depth; adcp->grpp = grpp; @@ -229,12 +230,13 @@ void adcStopConversion(ADCDriver *adcp) { */ void adcStopConversionI(ADCDriver *adcp) { + chDbgCheckClassI(); chDbgCheck(adcp != NULL, "adcStopConversionI"); - chDbgAssert((adcp->state == ADC_READY) || (adcp->state == ADC_ACTIVE) || (adcp->state == ADC_COMPLETE), "adcStopConversionI(), #1", "invalid state"); + if (adcp->state != ADC_READY) { adc_lld_stop_conversion(adcp); adcp->grpp = NULL; diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index e90a8911a..5f424453d 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -137,8 +137,11 @@ void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval) { */ void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStartContinuousI"); chDbgAssert(gptp->state == GPT_READY, "gptStartContinuousI(), #1", "invalid state"); + gptp->state = GPT_CONTINUOUS; gpt_lld_start_timer(gptp, interval); } @@ -168,8 +171,11 @@ void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval) { */ void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStartOneShotI"); chDbgAssert(gptp->state == GPT_READY, "gptStartOneShotI(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; gpt_lld_start_timer(gptp, interval); } @@ -197,9 +203,12 @@ void gptStopTimer(GPTDriver *gptp) { */ void gptStopTimerI(GPTDriver *gptp) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStopTimerI"); chDbgAssert((gptp->state == GPT_READY) || (gptp->state == GPT_CONTINUOUS) || (gptp->state == GPT_ONESHOT), "gptStopTimerI(), #1", "invalid state"); + gptp->state = GPT_READY; gpt_lld_stop_timer(gptp); } @@ -220,6 +229,7 @@ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { chDbgAssert(gptp->state == GPT_READY, "gptPolledDelay(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; gpt_lld_polled_delay(gptp, interval); } diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c index 3be67448e..79d38798e 100644 --- a/os/hal/src/icu.c +++ b/os/hal/src/icu.c @@ -121,6 +121,8 @@ void icuStop(ICUDriver *icup) { */ void icuEnable(ICUDriver *icup) { + chDbgCheck(icup != NULL, "icuEnable"); + chSysLock(); chDbgAssert(icup->state == ICU_READY, "icuEnable(), #1", "invalid state"); icu_lld_enable(icup); @@ -137,6 +139,8 @@ void icuEnable(ICUDriver *icup) { */ void icuDisable(ICUDriver *icup) { + chDbgCheck(icup != NULL, "icuDisable"); + chSysLock(); chDbgAssert((icup->state == ICU_READY) || (icup->state == ICU_WAITING) || (icup->state == ICU_ACTIVE) || (icup->state == ICU_IDLE), diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 414689aac..03b74be54 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -207,6 +207,7 @@ void sdStop(SerialDriver *sdp) { */ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { + chDbgCheckClassI(); chDbgCheck(sdp != NULL, "sdIncomingDataI"); if (chIQIsEmptyI(&sdp->iqueue)) @@ -233,6 +234,7 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { msg_t sdRequestDataI(SerialDriver *sdp) { msg_t b; + chDbgCheckClassI(); chDbgCheck(sdp != NULL, "sdRequestDataI"); b = chOQGetI(&sdp->oqueue); diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 05fdbb168..372a3ad02 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -161,12 +161,13 @@ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { */ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { + chDbgCheckClassI(); chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), "uartStartSendI"); - chDbgAssert((uartp->state == UART_READY) && (uartp->txstate != UART_TX_ACTIVE), "uartStartSendI(), #1", "not active"); + uart_lld_start_send(uartp, n, txbuf); uartp->txstate = UART_TX_ACTIVE; } @@ -216,8 +217,8 @@ size_t uartStopSend(UARTDriver *uartp) { */ size_t uartStopSendI(UARTDriver *uartp) { + chDbgCheckClassI(); chDbgCheck(uartp != NULL, "uartStopSendI"); - chDbgAssert(uartp->state == UART_READY, "uartStopSendI(), #1", "not active"); if (uartp->txstate == UART_TX_ACTIVE) { @@ -267,9 +268,9 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { */ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { + chDbgCheckClassI(); chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), "uartStartReceiveI"); - chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE), "uartStartReceiveI(), #1", "not active"); @@ -322,8 +323,9 @@ size_t uartStopReceive(UARTDriver *uartp) { * @iclass */ size_t uartStopReceiveI(UARTDriver *uartp) { - chDbgCheck(uartp != NULL, "uartStopReceiveI"); + chDbgCheckClassI(); + chDbgCheck(uartp != NULL, "uartStopReceiveI"); chDbgAssert(uartp->state == UART_READY, "uartStopReceiveI(), #1", "not active"); diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 484590f3b..8493b6f41 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -301,6 +301,8 @@ void usbStop(USBDriver *usbp) { void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp) { + chDbgCheckClassI(); + chDbgCheck((usbp != NULL) && (epcp != NULL), "usbInitEndpointI"); chDbgAssert(usbp->state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); chDbgAssert(usbp->epc[ep] != NULL, @@ -331,6 +333,8 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, void usbDisableEndpointsI(USBDriver *usbp) { unsigned i; + chDbgCheckClassI(); + chDbgCheck(usbp != NULL, "usbDisableEndpointsI"); chDbgAssert(usbp->state == USB_SELECTED, "usbDisableEndpointsI(), #1", "invalid state"); @@ -364,6 +368,9 @@ void usbDisableEndpointsI(USBDriver *usbp) { size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { + chDbgCheckClassI(); + chDbgCheck((usbp != NULL) && (buf != NULL), "usbReadPacketI"); + if (usbGetReceiveStatusI(usbp, ep)) return USB_ENDPOINT_BUSY; @@ -391,6 +398,9 @@ size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) { + chDbgCheckClassI(); + chDbgCheck((usbp != NULL) && (buf != NULL), "usbWritePacketI"); + if (usbGetTransmitStatusI(usbp, ep)) return USB_ENDPOINT_BUSY; @@ -419,6 +429,9 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { + chDbgCheckClassI(); + chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartReceiveI"); + if (usbGetReceiveStatusI(usbp, ep)) return TRUE; @@ -447,6 +460,9 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) { + chDbgCheckClassI(); + chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartTransmitI"); + if (usbGetTransmitStatusI(usbp, ep)) return TRUE; @@ -468,6 +484,9 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, */ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { + chDbgCheckClassI(); + chDbgCheck(usbp != NULL, "usbStallReceiveI"); + if (usbGetReceiveStatusI(usbp, ep)) return TRUE; @@ -488,6 +507,9 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { */ bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) { + chDbgCheckClassI(); + chDbgCheck(usbp != NULL, "usbStallTransmitI"); + if (usbGetTransmitStatusI(usbp, ep)) return TRUE; -- cgit v1.2.3 From da23780899ae4b9ce1bbe0cb9109da1c87fe0fa1 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 23 Aug 2011 08:38:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3250 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 974f65a08..8508bc682 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -147,7 +147,7 @@ void i2cStop(I2CDriver *i2cp) { * * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, - * than set @b rxbuf field to 0. + * than set @b rxbytes field to 0. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config -- cgit v1.2.3 From 718dc5084f7719f91eaacfc99e8c7de654eb2ad8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 23 Aug 2011 13:36:25 +0000 Subject: HAL documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3252 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 59d7db005..6bdaa2b5a 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -54,7 +54,7 @@ * * @notapi */ -bool_t sdc_wait_for_transfer_state(SDCDriver *sdcp) { +bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { uint32_t resp[1]; while (TRUE) { @@ -314,7 +314,7 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chSysUnlock(); /* Waits for eventual pending operations completion.*/ - if (sdc_wait_for_transfer_state(sdcp)) + if (_sdc_wait_for_transfer_state(sdcp)) return TRUE; /* Card clock stopped.*/ -- cgit v1.2.3 From fe0093f795b6c88db8f12e2f7e45e11355fc3340 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 26 Aug 2011 13:47:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 4 ++++ os/hal/src/can.c | 4 ++++ os/hal/src/gpt.c | 4 ++++ os/hal/src/hal.c | 4 ++++ os/hal/src/i2c.c | 4 ++++ os/hal/src/icu.c | 4 ++++ os/hal/src/mac.c | 4 ++++ os/hal/src/mmc_spi.c | 4 ++++ os/hal/src/pal.c | 4 ++++ os/hal/src/pwm.c | 4 ++++ os/hal/src/sdc.c | 4 ++++ os/hal/src/serial.c | 4 ++++ os/hal/src/serial_usb.c | 4 ++++ os/hal/src/spi.c | 4 ++++ os/hal/src/uart.c | 4 ++++ os/hal/src/usb.c | 4 ++++ 16 files changed, 64 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index f2bf4eadd..c375818a6 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -31,6 +31,10 @@ #if HAL_USE_ADC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index f9a827c4e..e888c2ae7 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -31,6 +31,10 @@ #if HAL_USE_CAN || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 5f424453d..c677f5284 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -31,6 +31,10 @@ #if HAL_USE_GPT || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 1a15988f5..ef7d7af8b 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -29,6 +29,10 @@ #include "ch.h" #include "hal.h" +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 86bfc16f6..260dcbb17 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -31,6 +31,10 @@ #if HAL_USE_I2C || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c index 79d38798e..c73ea5106 100644 --- a/os/hal/src/icu.c +++ b/os/hal/src/icu.c @@ -31,6 +31,10 @@ #if HAL_USE_ICU || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 4d6a9b2cd..0f1c47576 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -33,6 +33,10 @@ #if HAL_USE_MAC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index e6dcf9287..34d111c2d 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -31,6 +31,10 @@ #if HAL_USE_MMC_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 10e57e284..afb5c6b40 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -31,6 +31,10 @@ #if HAL_USE_PAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index e7dd6b64c..588b3df5c 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -31,6 +31,10 @@ #if HAL_USE_PWM || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 6bdaa2b5a..758edf8d8 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -31,6 +31,10 @@ #if HAL_USE_SDC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 03b74be54..d962bcdcd 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -31,6 +31,10 @@ #if HAL_USE_SERIAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 3f53d7df0..d9c25ecdf 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -33,6 +33,10 @@ #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index aaf0115eb..b91b44507 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -31,6 +31,10 @@ #if HAL_USE_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 372a3ad02..ed28ecb3b 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -31,6 +31,10 @@ #if HAL_USE_UART || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 8493b6f41..44a772ab1 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -34,6 +34,10 @@ #if HAL_USE_USB || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ -- cgit v1.2.3 From 339cbbd60e7c45bb21758cdfe264e8e1c78d4fd5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Aug 2011 12:55:02 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3260 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index d9c25ecdf..237d8e027 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -124,7 +124,7 @@ static void inotify(GenericQueue *qp) { emptied, then a whole packet is loaded in the queue.*/ if (chIQIsEmptyI(&sdup->iqueue)) { - n = usbReadPacketI(sdup->config->usbp, DATA_AVAILABLE_EP, + n = usbReadPacketI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP, sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); if (n != USB_ENDPOINT_BUSY) { chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); @@ -146,7 +146,7 @@ static void onotify(GenericQueue *qp) { /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); - w = usbWritePacketI(sdup->config->usbp, DATA_REQUEST_EP, + w = usbWritePacketI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, sdup->oqueue.q_buffer, n); if (w != USB_ENDPOINT_BUSY) { chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); @@ -211,10 +211,10 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { "sduStart(), #1", "invalid state"); sdup->config = config; - usbStart(config->usbp, &config->usb_config); config->usbp->param = sdup; sdup->state = SDU_READY; chSysUnlock(); + usbStart(config->usbp, &config->usb_config); } /** -- cgit v1.2.3 From 76f8d18aaf60c6d916a799ba3d8b09815da979b2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Aug 2011 12:57:21 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3261 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 237d8e027..16822502a 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -234,9 +234,9 @@ void sduStop(SerialUSBDriver *sdup) { chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), "sduStop(), #1", "invalid state"); - usbStop(sdup->config->usbp); sdup->state = SDU_STOP; chSysUnlock(); + usbStop(sdup->config->usbp); } /** -- cgit v1.2.3 From 22d2162db773e677c900b8b397889b7087470248 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 30 Aug 2011 22:52:11 +0000 Subject: RTC. Initial commit. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3269 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 ++ os/hal/src/rtc.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 os/hal/src/rtc.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index ef7d7af8b..3c8fb2fe6 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -106,6 +106,9 @@ void halInit(void) { #endif #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) sduInit(); +#endif +#if HAL_USE_RTC || defined(__DOXYGEN__) + rtcInit(); #endif /* Board specific initialization.*/ boardInit(); diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c new file mode 100644 index 000000000..bb0dc11f0 --- /dev/null +++ b/os/hal/src/rtc.c @@ -0,0 +1,108 @@ +/** + * @file rtc.c + * @brief Real Time Clock Abstraction Layer code. + * + * @addtogroup RTC + * @{ + */ + +#include "ch.h" +#include "hal.h" + + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ +/** + * @brief Enable access to registers and initialize RTC if BKP doamin + * was previously reseted. + */ +void rtcInit(void){ + rtc_lld_init(); +} + +#if RTC_SUPPORTS_CALLBACKS +/** + * @brief Configure and start interrupt servicing routines. + * @param[in] rtcp - pointer to RTC driver structure. + * @param[in] rtccfgp - pointer to RTC config structure. + */ +void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ + chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); + rtc_lld_start(rtcp, rtccfgp); +} + +/** + * @brief Stop interrupt servicing routines. + */ +void rtcStop(void){ + rtc_lld_stop(); +} +#endif /* RTC_SUPPORTS_CALLBACKS */ + +/** + * @brief Set current time. + * @param[in] tv_sec - time value in UNIX notation. + */ +void rtcSetTime(uint32_t tv_sec){ + rtc_lld_set_time(tv_sec); +} + +/** + * @brief Return current time in UNIX notation. + */ +uint32_t rtcGetSec(void){ + return rtc_lld_get_sec(); +} + +/** + * @brief Return fractional part of current time (milliseconds). + */ +uint16_t rtcGetMsec(void){ + return rtc_lld_get_msec(); +} + +/** + * @brief Set alarm date in UNIX notation. + */ +void rtcSetAlarm(uint32_t tv_alarm){ + rtc_lld_set_alarm(tv_alarm); +} + +/** + * @brief Get current alarm date in UNIX notation. + */ +uint32_t rtcGetAlarm(void){ + return rtc_lld_get_alarm(); +} + + + + + + +#endif /* HAL_USE_RTC */ + + + +/** @} */ + + -- cgit v1.2.3 From 2991a477339a28ec275647930df45443a9f8a253 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 09:34:42 +0000 Subject: RTC. nop git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3270 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index bb0dc11f0..c6edca4a2 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -9,6 +9,7 @@ #include "ch.h" #include "hal.h" +#include "rtc_lld.h" #if HAL_USE_RTC || defined(__DOXYGEN__) @@ -45,7 +46,7 @@ void rtcInit(void){ * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ -void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ +void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } -- cgit v1.2.3 From 3da3cc27891650180b1e725d1efb6f07005e9d3e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 15:31:32 +0000 Subject: RTC. Copyrights added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3274 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index c6edca4a2..0db21d4d5 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * @file rtc.c * @brief Real Time Clock Abstraction Layer code. @@ -40,12 +60,14 @@ void rtcInit(void){ rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS /** - * @brief Configure and start interrupt servicing routines. + * @brief Configure and start interrupt servicing routines. + * This function do nothing if callbacks disabled. + * * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ +#if RTC_SUPPORTS_CALLBACKS void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); @@ -95,15 +117,8 @@ uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } - - - - - #endif /* HAL_USE_RTC */ - - /** @} */ -- cgit v1.2.3 From 5e62285d1745cd498f89b1a42ae4b28b3ece59a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 16:32:34 +0000 Subject: RTC. Final polishing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3275 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 0db21d4d5..f1aa03a34 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -92,14 +92,14 @@ void rtcSetTime(uint32_t tv_sec){ /** * @brief Return current time in UNIX notation. */ -uint32_t rtcGetSec(void){ +inline uint32_t rtcGetSec(void){ return rtc_lld_get_sec(); } /** * @brief Return fractional part of current time (milliseconds). */ -uint16_t rtcGetMsec(void){ +inline uint16_t rtcGetMsec(void){ return rtc_lld_get_msec(); } @@ -113,7 +113,7 @@ void rtcSetAlarm(uint32_t tv_alarm){ /** * @brief Get current alarm date in UNIX notation. */ -uint32_t rtcGetAlarm(void){ +inline uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } -- cgit v1.2.3 From ac429a2a76727c72d6a7b8273c9643560fcd6222 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Sep 2011 18:09:40 +0000 Subject: RTC. Added state checks. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3279 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index f1aa03a34..1341bb2dd 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -68,7 +68,8 @@ void rtcInit(void){ * @param[in] rtccfgp - pointer to RTC config structure. */ #if RTC_SUPPORTS_CALLBACKS -void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ +void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ + chDbgCheckClassI(); chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } @@ -76,7 +77,8 @@ void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ /** * @brief Stop interrupt servicing routines. */ -void rtcStop(void){ +void rtcStopI(void){ + chDbgCheckClassI(); rtc_lld_stop(); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From c57e9ca9981e20e50630ace1656431ad84d73852 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 3 Sep 2011 08:22:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3285 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 1341bb2dd..bd934b11b 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -29,8 +29,6 @@ #include "ch.h" #include "hal.h" -#include "rtc_lld.h" - #if HAL_USE_RTC || defined(__DOXYGEN__) /*===========================================================================*/ -- cgit v1.2.3 From 792d85bcb5774e63100abef0125d5325312f916a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 3 Sep 2011 12:35:41 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3287 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 11 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 0f1c47576..edd15d087 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -21,8 +21,6 @@ /** * @file mac.c * @brief MAC Driver code. - * @note This function is implicitly invoked by @p halInit(), there is - * no need to explicitly initialize the driver. * * @addtogroup MAC * @{ @@ -59,6 +57,8 @@ /** * @brief MAC Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ @@ -76,28 +76,53 @@ void macInit(void) { */ void macObjectInit(MACDriver *macp) { + macp->state = MAC_STOP; + macp->config = NULL; chSemInit(&macp->tdsem, 0); chSemInit(&macp->rdsem, 0); -#if CH_USE_EVENTS +#if MAC_USE_EVENTS chEvtInit(&macp->rdevent); #endif } /** - * @brief MAC address setup. - * @pre This function must be invoked with the driver in the stopped - * state. If invoked on an active interface then it is ignored. + * @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) { + + chDbgCheck((macp != NULL) && (config != NULL), "macStart"); + + chSysLock(); + chDbgAssert(macp->state == MAC_STOP, + "macStart(), #1", "invalid state"); + macp->config = config; + mac_lld_start(macp); + macp->state = MAC_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deactivates the MAC peripheral. * * @param[in] macp pointer to the @p MACDriver object - * @param[in] p pointer to a six bytes buffer containing the MAC - * address. If this parameter is set to @p NULL then MAC - * a system default is used. * * @api */ -void macSetAddress(MACDriver *macp, const uint8_t *p) { +void macStop(MACDriver *macp) { + + chDbgCheck(macp != NULL, "macStop"); - mac_lld_set_address(macp, p); + chSysLock(); + chDbgAssert((macp->state == MAC_STOP) || (macp->state == MAC_ACTIVE), + "macStop(), #1", "invalid state"); + mac_lld_stop(macp); + macp->state = MAC_STOP; + chSysUnlock(); } /** @@ -124,6 +149,10 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, systime_t time) { msg_t msg; + chDbgCheck((macp != NULL) && (tdp != NULL), "macWaitTransmitDescriptor"); + chDbgAssert(macp->state == MAC_ACTIVE, "macWaitTransmitDescriptor(), #1", + "not active"); + while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && (time > 0)) { chSysLock(); @@ -149,6 +178,8 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, */ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { + chDbgCheck((tdp != NULL), "macReleaseTransmitDescriptor"); + mac_lld_release_transmit_descriptor(tdp); } @@ -176,6 +207,10 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, systime_t time) { msg_t msg; + chDbgCheck((macp != NULL) && (rdp != NULL), "macWaitReceiveDescriptor"); + chDbgAssert(macp->state == MAC_ACTIVE, "macWaitReceiveDescriptor(), #1", + "not active"); + while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && (time > 0)) { chSysLock(); @@ -202,6 +237,8 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, */ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { + chDbgCheck((rdp != NULL), "macReleaseReceiveDescriptor"); + mac_lld_release_receive_descriptor(rdp); } @@ -217,6 +254,10 @@ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { */ bool_t macPollLinkStatus(MACDriver *macp) { + chDbgCheck((macp != NULL), "macPollLinkStatus"); + chDbgAssert(macp->state == MAC_ACTIVE, "macPollLinkStatus(), #1", + "not active"); + return mac_lld_poll_link_status(macp); } -- cgit v1.2.3 From d15f612b861af72fffb8ee2e4f3b95e991bfcf10 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 3 Sep 2011 18:25:04 +0000 Subject: RTC. Tiny improvement in documentation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3288 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index bd934b11b..8f9025364 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -53,6 +53,9 @@ /** * @brief Enable access to registers and initialize RTC if BKP doamin * was previously reseted. + * + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. */ void rtcInit(void){ rtc_lld_init(); -- cgit v1.2.3 From d0771593893ef9f8a9ae4ab689c569b88e3631a9 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Sep 2011 12:53:27 +0000 Subject: RTC. rtcStart() and rtcStop() functions replaced by rtcSetCallback() git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3293 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 8f9025364..ab916cf52 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -61,26 +61,23 @@ void rtcInit(void){ rtc_lld_init(); } +#if RTC_SUPPORTS_CALLBACKS /** - * @brief Configure and start interrupt servicing routines. - * This function do nothing if callbacks disabled. + * @brief Enables and disables callbacks on the fly. + * @details Pass callback function(s) in argument(s) to enable callback(s). + * Pass NULL to disable callback. + * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS + * to @p TRUE. * * @param[in] rtcp - pointer to RTC driver structure. - * @param[in] rtccfgp - pointer to RTC config structure. - */ -#if RTC_SUPPORTS_CALLBACKS -void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ - chDbgCheckClassI(); - chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); - rtc_lld_start(rtcp, rtccfgp); -} - -/** - * @brief Stop interrupt servicing routines. + * @param[in] overflowcb - overflow callback function. + * @param[in] secondcb - every second callback function. + * @param[in] alarmcb - alarm callback function. */ -void rtcStopI(void){ - chDbgCheckClassI(); - rtc_lld_stop(); +void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, + rtccb_t secondcb, rtccb_t alarmcb){ + chDbgCheck((rtcp != NULL), "rtcStart"); + rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From a08f38d06c5dabf25751bac2deb4259e67fac530 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 11 Sep 2011 18:30:56 +0000 Subject: I2C. Remove const qualifier from pointer to I2CSlaveConfig. Step 2. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3307 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9ce2cc76f..68735b037 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -166,7 +166,7 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, + I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -210,7 +210,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, + I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ -- cgit v1.2.3 From 7148a664b5c73138a504cd61a1882cfb91ba3b7a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 12 Sep 2011 13:40:44 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3309 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/hal.c | 3 ++ 2 files changed, 124 insertions(+) create mode 100644 os/hal/src/ext.c (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c new file mode 100644 index 000000000..d68758684 --- /dev/null +++ b/os/hal/src/ext.c @@ -0,0 +1,121 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file ext.c + * @brief EXT Driver code. + * + * @addtogroup EXT + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_EXT || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief EXT Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void extInit(void) { + + ext_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p EXTDriver structure. + * + * @param[out] extp pointer to the @p EXTDriver object + * + * @init + */ +void extObjectInit(EXTDriver *extp) { + + extp->state = EXT_STOP; + extp->config = NULL; +} + +/** + * @brief Configures and activates the EXT peripheral. + * + * @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) { + + chDbgCheck((extp != NULL) && (config != NULL), "extStart"); + + chSysLock(); + chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), + "extStart(), #1", "invalid state"); + extp->config = config; + ext_lld_start(extp); + extp->state = EXT_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deactivates the EXT peripheral. + * + * @param[in] extp pointer to the @p EXTDriver object + * + * @api + */ +void extStop(EXTDriver *extp) { + + chDbgCheck(extp != NULL, "extStop"); + + chSysLock(); + chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), + "extStop(), #1", "invalid state"); + ext_lld_stop(extp); + extp->state = EXT_STOP; + chSysUnlock(); +} + +#endif /* HAL_USE_EXT */ + +/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 3c8fb2fe6..d5a8082e9 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -71,6 +71,9 @@ void halInit(void) { #if HAL_USE_CAN || defined(__DOXYGEN__) canInit(); #endif +#if HAL_USE_EXT || defined(__DOXYGEN__) + extInit(); +#endif #if HAL_USE_GPT || defined(__DOXYGEN__) gptInit(); #endif -- cgit v1.2.3 From d3e15bccfc41af4e4d3972003ff06b69de2225bc Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 12 Sep 2011 15:50:35 +0000 Subject: I2C. Revert const qualifier to the pointer to I2CSlaveConfig. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3310 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 68735b037..9ce2cc76f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -166,7 +166,7 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - I2CSlaveConfig *i2cscfg, + const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -210,7 +210,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - I2CSlaveConfig *i2cscfg, + const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ -- cgit v1.2.3 From fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 13 Sep 2011 12:40:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3314 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index d68758684..1c83cd2e6 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -78,6 +78,8 @@ void extObjectInit(EXTDriver *extp) { /** * @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 @@ -116,6 +118,50 @@ void extStop(EXTDriver *extp) { chSysUnlock(); } +/** + * @brief Enables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be enabled + * + * @api + */ +void extChannelEnable(EXTDriver *extp, expchannel_t channel) { + + chDbgCheck((extp != NULL) && + (channel < EXT_MAX_CHANNELS) && + (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + "extChannelEnable"); + + chSysLock(); + chDbgAssert(extp->state == EXT_ACTIVE, + "extChannelEnable(), #1", "invalid state"); + extChannelEnableI(extp, channel); + chSysUnlock(); +} + +/** + * @brief Disables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be disabled + * + * @api + */ +void extChannelDisable(EXTDriver *extp, expchannel_t channel) { + + chDbgCheck((extp != NULL) && + (channel < EXT_MAX_CHANNELS) && + (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + "extChannelDisable"); + + chSysLock(); + chDbgAssert(extp->state == EXT_ACTIVE, + "extChannelDisable(), #1", "invalid state"); + extChannelDisableI(extp, channel); + chSysUnlock(); +} + #endif /* HAL_USE_EXT */ /** @} */ -- cgit v1.2.3 From bae85ff69f0037ae22bb9bf1fada5762f7db4292 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Sep 2011 12:54:13 +0000 Subject: Fixed problem in gptPolledDelay(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3350 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index c677f5284..726936ca8 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -236,6 +236,7 @@ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { gptp->state = GPT_ONESHOT; gpt_lld_polled_delay(gptp, interval); + gptp->state = GPT_READY; } #endif /* HAL_USE_GPT */ -- cgit v1.2.3 From 95713cae20050dd58b41f52edead1b05c1c982a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 21 Sep 2011 12:46:09 +0000 Subject: RTC. API cnahge. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3376 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index ab916cf52..3b4b5824b 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -90,17 +90,15 @@ void rtcSetTime(uint32_t tv_sec){ } /** - * @brief Return current time in UNIX notation. - */ -inline uint32_t rtcGetSec(void){ - return rtc_lld_get_sec(); -} - -/** - * @brief Return fractional part of current time (milliseconds). + * @brief Return return seconds since UNIX epoch. + * + * @param[in] msec pointer to variable for storing fractional part of + * time (milliseconds). + * + * @notapi */ -inline uint16_t rtcGetMsec(void){ - return rtc_lld_get_msec(); +inline uint32_t rtcGetTime(uint16_t *msec){ + return rtc_lld_get_time(msec); } /** -- cgit v1.2.3 From 4a3e3fc01ec6dfb4a710db771bee262d5dc9327e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 22 Sep 2011 14:53:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3381 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index c375818a6..08aa830f0 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -162,6 +162,8 @@ void adcStartConversion(ADCDriver *adcp, /** * @brief Starts an ADC conversion. * @details Starts an asynchronous conversion operation. + * @post The callbacks associated to the conversion group will be invoked + * on buffer fill and error events. * @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 @@ -185,7 +187,8 @@ void adcStartConversionI(ADCDriver *adcp, ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); chDbgAssert((adcp->state == ADC_READY) || - (adcp->state == ADC_COMPLETE), + (adcp->state == ADC_COMPLETE) || + (adcp->state == ADC_ERROR), "adcStartConversionI(), #1", "not ready"); adcp->samples = samples; @@ -268,6 +271,8 @@ void adcStopConversionI(ADCDriver *adcp) { * @retval RDY_RESET The conversion has been stopped using * @p acdStopConversion() or @p acdStopConversionI(), * the result buffer may contain incorrect data. + * @retval RDY_TIMEOUT The conversion has been stopped because an hardware + * error. * * @api */ -- cgit v1.2.3 From 41fd0fb5fb2d446605e7a99c11f46d7c28071500 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 25 Sep 2011 10:03:59 +0000 Subject: RTC. API changes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3405 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 3b4b5824b..0c8959ea6 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -83,36 +83,42 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, /** * @brief Set current time. - * @param[in] tv_sec - time value in UNIX notation. + * + * @param[in] timespec pointer to variable storing time. */ -void rtcSetTime(uint32_t tv_sec){ - rtc_lld_set_time(tv_sec); +void rtcSetTime(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcSetTime"); + rtc_lld_set_time(timespec); } /** - * @brief Return return seconds since UNIX epoch. - * - * @param[in] msec pointer to variable for storing fractional part of - * time (milliseconds). + * @brief Get current time. * - * @notapi + * @param[in] timespec pointer to variable storing time. */ -inline uint32_t rtcGetTime(uint16_t *msec){ - return rtc_lld_get_time(msec); +void rtcGetTime(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetTime"); + rtc_lld_get_time(timespec); } /** - * @brief Set alarm date in UNIX notation. + * @brief Set alarm time. + * + * @param[in] timespec pointer to variable storing time of alarm. */ -void rtcSetAlarm(uint32_t tv_alarm){ - rtc_lld_set_alarm(tv_alarm); +void rtcSetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcSetAlarm"); + rtc_lld_set_alarm(timespec); } /** - * @brief Get current alarm date in UNIX notation. + * @brief Get current alarm. + * + * @param[in] timespec pointer to variable to store alarm time. */ -inline uint32_t rtcGetAlarm(void){ - return rtc_lld_get_alarm(); +void rtcGetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetAlarm"); + rtc_lld_get_alarm(timespec); } #endif /* HAL_USE_RTC */ -- cgit v1.2.3 From 0af85bab42eda2d80ce6efd2a0c1f5a94bad5f34 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 25 Sep 2011 10:32:39 +0000 Subject: RTC. Test updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3408 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 0c8959ea6..17c83f4b3 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -76,7 +76,7 @@ void rtcInit(void){ */ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, rtccb_t secondcb, rtccb_t alarmcb){ - chDbgCheck((rtcp != NULL), "rtcStart"); + chDbgCheck((rtcp != NULL), "rtcSetCallback"); rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From d2fa0e3fdee679a6cdd5dd6616aca527eca3f080 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 26 Sep 2011 08:23:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3412 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 65 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 17c83f4b3..24ccce84e 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -20,7 +20,7 @@ /** * @file rtc.c - * @brief Real Time Clock Abstraction Layer code. + * @brief RTC Driver code. * * @addtogroup RTC * @{ @@ -50,74 +50,85 @@ /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ + /** - * @brief Enable access to registers and initialize RTC if BKP doamin - * was previously reseted. - * + * @brief Enable access to registers and initialize RTC if BKP domain + * was previously reset. * @note This function is implicitly invoked by @p halInit(), there is * no need to explicitly initialize the driver. + * + * @init */ -void rtcInit(void){ +void rtcInit(void) { rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS +#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Enables and disables callbacks on the fly. - * @details Pass callback function(s) in argument(s) to enable callback(s). - * Pass NULL to disable callback. - * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS - * to @p TRUE. + * @brief Enables or disables callbacks. + * @details This function enables or disables callbacks, use a @p NULL pointer + * in order to disable a callback. + * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS + * to @p TRUE. * - * @param[in] rtcp - pointer to RTC driver structure. - * @param[in] overflowcb - overflow callback function. - * @param[in] secondcb - every second callback function. - * @param[in] alarmcb - alarm callback function. + * @param[in] rtcp pointer to RTC driver structure + * @param[in] overflowcb overflow callback function + * @param[in] secondcb every second callback function + * @param[in] alarmcb alarm callback function */ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, - rtccb_t secondcb, rtccb_t alarmcb){ + rtccb_t secondcb, rtccb_t alarmcb) { + chDbgCheck((rtcp != NULL), "rtcSetCallback"); + rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ /** - * @brief Set current time. + * @brief Set current time. * - * @param[in] timespec pointer to variable storing time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcSetTime(RTCDateTime *timespec){ +void rtcSetTime(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcSetTime"); + rtc_lld_set_time(timespec); } /** - * @brief Get current time. + * @brief Get current time. * - * @param[in] timespec pointer to variable storing time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcGetTime(RTCDateTime *timespec){ +void rtcGetTime(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcGetTime"); rtc_lld_get_time(timespec); } /** - * @brief Set alarm time. + * @brief Set alarm time. * - * @param[in] timespec pointer to variable storing time of alarm. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcSetAlarm(RTCDateTime *timespec){ +void rtcSetAlarm(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcSetAlarm"); + rtc_lld_set_alarm(timespec); } /** - * @brief Get current alarm. + * @brief Get current alarm. * - * @param[in] timespec pointer to variable to store alarm time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ void rtcGetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetAlarm"); + rtc_lld_get_alarm(timespec); } -- cgit v1.2.3 From 2950a0a7b8316a742a7a67b5acb4f224a98397ff Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 1 Oct 2011 08:04:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3413 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 95 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 38 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 24ccce84e..dda5a9c95 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -52,88 +52,107 @@ /*===========================================================================*/ /** - * @brief Enable access to registers and initialize RTC if BKP domain - * was previously reset. + * @brief RTC Driver initialization. * @note This function is implicitly invoked by @p halInit(), there is * no need to explicitly initialize the driver. * * @init */ void rtcInit(void) { + rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Enables or disables callbacks. - * @details This function enables or disables callbacks, use a @p NULL pointer - * in order to disable a callback. - * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS - * to @p TRUE. + * @brief Set current time. * * @param[in] rtcp pointer to RTC driver structure - * @param[in] overflowcb overflow callback function - * @param[in] secondcb every second callback function - * @param[in] alarmcb alarm callback function + * @param[in] timespec pointer to a @p RTCTime structure + * + * @api */ -void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, - rtccb_t secondcb, rtccb_t alarmcb) { +void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec) { - chDbgCheck((rtcp != NULL), "rtcSetCallback"); + chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcSetTime"); - rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); + rtc_lld_set_time(rtcp, timespec); } -#endif /* RTC_SUPPORTS_CALLBACKS */ /** - * @brief Set current time. + * @brief Get current time. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[out] timespec pointer to a @p RTCTime structure * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcSetTime(RTCDateTime *timespec) { +void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { - chDbgCheck((timespec != NULL), "rtcSetTime"); + chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcGetTime"); - rtc_lld_set_time(timespec); + rtc_lld_get_time(rtcp, timespec); } +#if (RTC_ALARMS > 0) || defined(__DOXYGEN__) /** - * @brief Get current time. + * @brief Set alarm time. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[in] alarmspec pointer to a @p RTCAlarm structure or @p NULL * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcGetTime(RTCDateTime *timespec) { +void rtcSetAlarm(RTCDriver *rtcp, + rtcalarm_t alarm, + const RTCAlarm *alarmspec) { - chDbgCheck((timespec != NULL), "rtcGetTime"); - rtc_lld_get_time(timespec); + chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS), "rtcSetAlarm"); + + rtc_lld_set_alarm(rtcp, alarm, alarmspec); } /** - * @brief Set alarm time. + * @brief Get current alarm. + * @note If an alarm has not been set then the returned alarm specification + * is not meaningful. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[out] alarmspec pointer to a @p RTCAlarm structure * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcSetAlarm(RTCDateTime *timespec) { +void rtcGetAlarm(RTCDriver *rtcp, + rtcalarm_t alarm, + RTCAlarm *alarmspec) { - chDbgCheck((timespec != NULL), "rtcSetAlarm"); + chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS) && (alarmspec != NULL), + "rtcGetAlarm"); - rtc_lld_set_alarm(timespec); + rtc_lld_get_alarm(rtcp, alarm, alarmspec); } +#endif /* RTC_ALARMS > 0 */ +#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Get current alarm. + * @brief Enables or disables RTC callbacks. + * @details This function enables or disables callbacks, use a @p NULL pointer + * in order to disable a callback. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] callback callback function pointer or @p NULL * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcGetAlarm(RTCDateTime *timespec){ +void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { - chDbgCheck((timespec != NULL), "rtcGetAlarm"); + chDbgCheck((rtcp != NULL), "rtcSetCallback"); - rtc_lld_get_alarm(timespec); + rtc_lld_set_callback(rtcp, callback); } +#endif /* RTC_SUPPORTS_CALLBACKS */ #endif /* HAL_USE_RTC */ /** @} */ - - -- cgit v1.2.3 From 309b1e411426e8d36d9a552ef2870da3db912a80 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 23 Oct 2011 11:39:45 +0000 Subject: Improvements to the USB driver, first phase. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3449 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 91 +++++++++++++++++++++++++--------------- os/hal/src/usb.c | 107 ++++++++++-------------------------------------- 2 files changed, 78 insertions(+), 120 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 16822502a..ea434b197 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -118,21 +118,26 @@ static const struct SerialUSBDriverVMT vmt = { */ static void inotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; - size_t n; /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ - if (chIQIsEmptyI(&sdup->iqueue)) { - - n = usbReadPacketI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP, - sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); - if (n != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && + chIQIsEmptyI(&sdup->iqueue)) { + chSysUnlock(); + + /* Unlocked to make the potentially long read operation preemptable.*/ + size_t n = usbReadPacketBuffer(sdup->config->usbp, + USB_CDC_DATA_AVAILABLE_EP, + sdup->iqueue.q_buffer, + SERIAL_USB_BUFFERS_SIZE); + + chSysLock(); + usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + while (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } } @@ -141,14 +146,20 @@ static void inotify(GenericQueue *qp) { */ static void onotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; - size_t w, n; + size_t n; /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); - w = usbWritePacketI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, - sdup->oqueue.q_buffer, n); - if (w != USB_ENDPOINT_BUSY) { + if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP)) { + chSysUnlock(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + usbWritePacketBuffer(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, + sdup->oqueue.q_buffer, n); + + chSysLock(); + usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); @@ -285,21 +296,27 @@ bool_t sduRequestsHook(USBDriver *usbp) { */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; - size_t n, w; + size_t n; chSysLockFromIsr(); /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); if (n > 0) { - w = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); - if (w != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); - while (notempty(&sdup->oqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + /* The endpoint cannot be busy, we are in the context of the callback, + so it is safe to transmit without a check.*/ + chSysUnlockFromIsr(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + usbWritePacketBuffer(usbp, ep, sdup->oqueue.q_buffer, n); + + chSysLockFromIsr(); + usbStartTransmitI(usbp, ep); + chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); + while (notempty(&sdup->oqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); } @@ -319,17 +336,23 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ if (chIQIsEmptyI(&sdup->iqueue)) { + /* The endpoint cannot be busy, we are in the context of the callback, + so a packet is in the buffer for sure.*/ size_t n; - n = usbReadPacketI(usbp, ep, sdup->iqueue.q_buffer, - SERIAL_USB_BUFFERS_SIZE); - if (n != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + chSysUnlockFromIsr(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + n = usbReadPacketBuffer(usbp, ep, sdup->iqueue.q_buffer, + SERIAL_USB_BUFFERS_SIZE); + + chSysLockFromIsr(); + usbStartReceiveI(usbp, ep); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + while (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); } diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 44a772ab1..30919580c 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -309,7 +309,7 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, chDbgCheck((usbp != NULL) && (epcp != NULL), "usbInitEndpointI"); chDbgAssert(usbp->state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); - chDbgAssert(usbp->epc[ep] != NULL, + chDbgAssert(usbp->epc[ep] == NULL, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ @@ -351,127 +351,55 @@ void usbDisableEndpointsI(USBDriver *usbp) { usb_lld_disable_endpoints(usbp); } -/** - * @brief Reads a packet from the dedicated packet buffer. - * @pre In order to use this function he endpoint must have been - * initialized in packet mode. - * @post The endpoint is ready to accept another packet. - * - * @param[in] usbp pointer to the @p USBDriver object - * @param[in] ep endpoint number - * @param[out] buf buffer where to copy the packet data - * @param[in] n maximum number of bytes to copy. This value must - * not exceed the maximum packet size for this endpoint. - * @return The received packet size regardless the specified - * @p n parameter. - * @retval USB_ENDPOINT_BUSY Endpoint busy receiving. - * @retval 0 Zero size packet received. - * - * @iclass - */ -size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, - uint8_t *buf, size_t n) { - - chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbReadPacketI"); - - if (usbGetReceiveStatusI(usbp, ep)) - return USB_ENDPOINT_BUSY; - - usbp->receiving |= (1 << ep); - return usb_lld_read_packet(usbp, ep, buf, n);; -} - -/** - * @brief Writes a packet to the dedicated packet buffer. - * @pre In order to use this function he endpoint must have been - * initialized in packet mode. - * @post The endpoint is ready to transmit the packet. - * - * @param[in] usbp pointer to the @p USBDriver object - * @param[in] ep endpoint number - * @param[in] buf buffer where to fetch the packet data - * @param[in] n maximum number of bytes to copy. This value must - * not exceed the maximum packet size for this endpoint. - * @return The operation status. - * @retval USB_ENDPOINT_BUSY Endpoint busy transmitting. - * @retval 0 Operation complete. - * - * @iclass - */ -size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, - const uint8_t *buf, size_t n) { - - chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbWritePacketI"); - - if (usbGetTransmitStatusI(usbp, ep)) - return USB_ENDPOINT_BUSY; - - usbp->transmitting |= (1 << ep); - usb_lld_write_packet(usbp, ep, buf, n); - return 0; -} - /** * @brief Starts a receive transaction on an OUT endpoint. - * @pre In order to use this function he endpoint must have been - * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[out] buf buffer where to copy the received data - * @param[in] n maximum number of bytes to copy * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. * * @iclass */ -bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, - uint8_t *buf, size_t n) { +bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep) { chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartReceiveI"); + chDbgCheck(usbp != NULL, "usbStartReceiveI"); if (usbGetReceiveStatusI(usbp, ep)) return TRUE; usbp->receiving |= (1 << ep); - usb_lld_start_out(usbp, ep, buf, n); + usb_lld_start_out(usbp, ep); return FALSE; } /** * @brief Starts a transmit transaction on an IN endpoint. - * @pre In order to use this function he endpoint must have been - * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[in] buf buffer where to fetch the data to be transmitted - * @param[in] n maximum number of bytes to copy * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. * * @iclass */ -bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, - const uint8_t *buf, size_t n) { +bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep) { chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartTransmitI"); + chDbgCheck(usbp != NULL, "usbStartTransmitI"); if (usbGetTransmitStatusI(usbp, ep)) return TRUE; usbp->transmitting |= (1 << ep); - usb_lld_start_in(usbp, ep, buf, n); + usb_lld_start_in(usbp, ep); return FALSE; } @@ -597,13 +525,15 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the transmit phase.*/ usbp->ep0state = USB_EP0_TX; - usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_prepare_transmit(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_start_in(usbp, 0); } else { /* No transmission phase, directly receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_start_out(usbp, 0, NULL, 0); + usb_lld_prepare_receive(usbp, 0, NULL, 0); + usb_lld_start_out(usbp, 0); } } else { @@ -611,13 +541,15 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the receive phase.*/ usbp->ep0state = USB_EP0_RX; - usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_prepare_receive(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_start_out(usbp, 0); } else { /* No receive phase, directly sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); } } } @@ -644,13 +576,15 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { transmitted.*/ if ((usbp->ep0n < max) && ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); return; } /* Transmit phase over, receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_start_out(usbp, 0, NULL, 0); + usb_lld_prepare_receive(usbp, 0, NULL, 0); + usb_lld_start_out(usbp, 0); return; case USB_EP0_SENDING_STS: /* Status packet sent, invoking the callback if defined.*/ @@ -687,7 +621,8 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { case USB_EP0_RX: /* Receive phase over, sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); return; case USB_EP0_WAITING_STS: /* Status packet received, it must be zero sized, invoking the callback -- cgit v1.2.3 From 2ad41625e0dc9ee78dadba2f2527857f9476e40d Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Dec 2011 14:32:59 +0000 Subject: I2C. Nop. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3545 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9ce2cc76f..abd3252cf 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -182,6 +182,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; + // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -224,6 +225,7 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; + // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); -- cgit v1.2.3 From 62608271adb730505a4a3d0a9ef49ef2efe91552 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Dec 2011 20:17:58 +0000 Subject: I2C. Code compiles but does not work. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3548 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index abd3252cf..0f46e4e64 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -111,10 +111,6 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { "i2cStart(), #1", "invalid state"); -#if (!(STM32_I2C_I2C2_USE_POLLING_WAIT) && I2C_SUPPORTS_CALLBACKS) - gptStart(i2cp->timer, i2cp->timer_cfg); -#endif /* !(STM32_I2C_I2C2_USE_POLLING_WAIT) */ - chSysLock(); i2cp->id_config = config; i2c_lld_start(i2cp); @@ -136,10 +132,6 @@ void i2cStop(I2CDriver *i2cp) { "i2cStop(), #1", "invalid state"); -#if (!(STM32_I2C_I2C2_USE_POLLING_WAIT) && I2C_SUPPORTS_CALLBACKS) - gptStop(i2cp->timer); -#endif /* !(STM32_I2C_I2C2_USE_POLLING_WAIT) */ - chSysLock(); i2c_lld_stop(i2cp); i2cp->id_state = I2C_STOP; -- cgit v1.2.3 From dbac0ef26b2977c9862ec6ddc22f10dac76b3239 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 2 Dec 2011 15:01:31 +0000 Subject: I2C. DMA works. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3550 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 0f46e4e64..3add2af98 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -210,7 +210,7 @@ void i2cMasterReceive(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ - (rxbytes > 0) && \ + (rxbytes > 1) && \ (rxbuf != NULL), "i2cMasterReceive"); -- cgit v1.2.3 From 59014aa2be0488eba89c6ec0fb1934aa43aeb224 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 4 Dec 2011 17:46:19 +0000 Subject: I2C. Tested on tmp75, mma8451, max1236. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3553 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 3add2af98..9f443be6c 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -73,8 +73,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; - i2cp->rxbuff_p = NULL; - i2cp->txbuff_p = NULL; i2cp->rxbuf = NULL; i2cp->txbuf = NULL; i2cp->id_slave_config = NULL; @@ -145,12 +143,12 @@ void i2cStop(I2CDriver *i2cp) { * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. * + * @details Number of receiving byts must be 0 or more than 1 because of stm32 + * hardware restrictions. + * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing mode used. Otherwise keep it cleared. - * Bits 10-14 unused. + * @param[in] slave_addr Slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted * @param[in] rxbuf pointer to receive buffer @@ -159,7 +157,7 @@ void i2cStop(I2CDriver *i2cp) { */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, - uint16_t slave_addr, + uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, @@ -168,7 +166,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ - (txbuf != NULL), + (txbuf != NULL) &&\ + ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), "i2cMasterTransmit"); /* init slave config field in driver */ @@ -183,28 +182,23 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); -#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); -#else - i2cp->id_state = I2C_READY; -#endif /* I2C_SUPPORTS_CALLBACKS */ } /** * @brief Receives data from the I2C bus. + * @details Number of receiving byts must be more than 1 because of stm32 + * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing mode used. Otherwise keep it cleared. - * Bits 10-14 unused. + * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, - uint16_t slave_addr, + uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ @@ -226,21 +220,9 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); -#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); -#else - i2cp->id_state = I2C_READY; -#endif /* I2C_SUPPORTS_CALLBACKS */ } - -/* FIXME: I do not know what this function must do. And can not test it -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - i2cMasterReceive(i2cp, i2cscfg); - return i2cp->id_slave_config->slave_addr; -} -*/ - /** * @brief Handles communication events/errors. * @details Must be called from the I/O interrupt service routine in order to -- cgit v1.2.3 From 2db3c769f1abba36a1e7a843d83e5006de58cbd5 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 6 Dec 2011 18:09:34 +0000 Subject: I2C. Bug fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3562 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9f443be6c..4b9160a68 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -238,7 +238,6 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->sevent); } /** -- cgit v1.2.3 From 0738591b023a4e2c6cacebadebfef08aafea4d6e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 17:57:42 +0000 Subject: I2C. Switch to synchronous model. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3570 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4b9160a68..996343104 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -75,11 +75,7 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_config = NULL; i2cp->rxbuf = NULL; i2cp->txbuf = NULL; - i2cp->id_slave_config = NULL; - -#if I2C_USE_WAIT i2cp->id_thread = NULL; -#endif /* I2C_USE_WAIT */ #if I2C_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES @@ -147,7 +143,6 @@ void i2cStop(I2CDriver *i2cp) { * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted @@ -156,24 +151,19 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes) { - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + chDbgCheck((i2cp != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ (txbuf != NULL) &&\ ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), "i2cMasterTransmit"); - /* init slave config field in driver */ - i2cp->id_slave_config = i2cscfg; - - // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -191,27 +181,21 @@ void i2cMasterTransmit(I2CDriver *i2cp, * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + chDbgCheck((i2cp != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 1) && \ (rxbuf != NULL), "i2cMasterReceive"); - /* init slave config field in driver */ - i2cp->id_slave_config = i2cscfg; - - // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -298,7 +282,6 @@ void i2cReleaseBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cReleaseBus"); #if CH_USE_MUTEXES - (void)i2cp; chMtxUnlock(); #elif CH_USE_SEMAPHORES chSemSignal(&i2cp->id_semaphore); -- cgit v1.2.3 From 3799bf56f52f7a5be9eeda6757c6642105c4ed66 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 19:23:09 +0000 Subject: I2C. Error handling from userland code added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3572 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 996343104..f20932ef3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -149,8 +149,10 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only + * + * @return Zero if no errors, otherwise return error code. */ -void i2cMasterTransmit(I2CDriver *i2cp, +i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -173,6 +175,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); + + return i2cGetAndClearFlags(i2cp); } /** @@ -184,8 +188,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer + * + * @return Zero if no errors, otherwise return error code. */ -void i2cMasterReceive(I2CDriver *i2cp, +i2cflags_t i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ @@ -205,6 +211,8 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); + + return i2cGetAndClearFlags(i2cp); } /** -- cgit v1.2.3 From c7c5942ac386fcfddcb77cb3c0e525d0e85063c4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 8 Dec 2011 08:36:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3578 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f20932ef3..ae5f9f7a8 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -133,13 +133,11 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Sends data via the I2C bus. - * + * @brief Sends data via the I2C bus. * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. - * - * @details Number of receiving byts must be 0 or more than 1 because of stm32 + * Number of receiving byts must be 0 or more than 1 because of stm32 * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object @@ -153,22 +151,21 @@ void i2cStop(I2CDriver *i2cp) { * @return Zero if no errors, otherwise return error code. */ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *txbuf, - size_t txbytes, - uint8_t *rxbuf, - size_t rxbytes) { - - chDbgCheck((i2cp != NULL) &&\ - (slave_addr != 0) &&\ - (txbytes > 0) &&\ - (txbuf != NULL) &&\ - ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), - "i2cMasterTransmit"); + uint8_t slave_addr, + uint8_t *txbuf, + size_t txbytes, + uint8_t *rxbuf, + size_t rxbytes) { + + chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + (txbytes > 0) && (txbuf != NULL) && + ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), + "i2cMasterTransmit"); i2c_lld_wait_bus_free(i2cp); - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), + "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -180,8 +177,8 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, } /** - * @brief Receives data from the I2C bus. - * @details Number of receiving byts must be more than 1 because of stm32 + * @brief Receives data from the I2C bus. + * Number of receiving byts must be more than 1 because of stm32 * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object @@ -192,19 +189,18 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, * @return Zero if no errors, otherwise return error code. */ i2cflags_t i2cMasterReceive(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *rxbuf, - size_t rxbytes){ + uint8_t slave_addr, + uint8_t *rxbuf, + size_t rxbytes){ - chDbgCheck((i2cp != NULL) &&\ - (slave_addr != 0) &&\ - (rxbytes > 1) && \ - (rxbuf != NULL), - "i2cMasterReceive"); + chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + (rxbytes > 1) && (rxbuf != NULL), + "i2cMasterReceive"); i2c_lld_wait_bus_free(i2cp); - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), + "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); @@ -253,8 +249,6 @@ i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { return mask; } - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3 From a524ec87f1fffcfea724d8485911fe94a503265f Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Dec 2011 14:34:44 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3581 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ae5f9f7a8..63c03565a 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -137,8 +137,6 @@ void i2cStop(I2CDriver *i2cp) { * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. - * Number of receiving byts must be 0 or more than 1 because of stm32 - * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] slave_addr Slave device address (7 bits) without R/W bit @@ -159,7 +157,7 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (slave_addr != 0) && (txbytes > 0) && (txbuf != NULL) && - ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), + ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))), "i2cMasterTransmit"); i2c_lld_wait_bus_free(i2cp); @@ -178,8 +176,6 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, /** * @brief Receives data from the I2C bus. - * Number of receiving byts must be more than 1 because of stm32 - * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] slave_addr slave device address (7 bits) without R/W bit @@ -194,7 +190,7 @@ i2cflags_t i2cMasterReceive(I2CDriver *i2cp, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (slave_addr != 0) && - (rxbytes > 1) && (rxbuf != NULL), + (rxbytes > 0) && (rxbuf != NULL), "i2cMasterReceive"); i2c_lld_wait_bus_free(i2cp); -- cgit v1.2.3 From edfa9d2fae1d667b3f71a8e61aa954ac2233e493 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Dec 2011 19:24:21 +0000 Subject: I2C. Added timeout in functions. Code clean ups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3583 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 94 ++++++++++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 58 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 63c03565a..f7f7c335e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -145,33 +145,40 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout operation timeout * - * @return Zero if no errors, otherwise return error code. + * @return timeout status + * @retval RDY_OK if timeout not reached + * @retval RDY_TIMEOUT if a timeout occurs */ -i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, +msg_t i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, - size_t rxbytes) { + size_t rxbytes, + i2cflags_t *errors, + systime_t timeout) { + msg_t rdymsg; chDbgCheck((i2cp != NULL) && (slave_addr != 0) && (txbytes > 0) && (txbuf != NULL) && - ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))), + ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && + (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterTransmit"); - - i2c_lld_wait_bus_free(i2cp); - - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), - "i2cMasterReceive(), #1", "time is out"); + i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); - _i2c_wait_s(i2cp); + _i2c_wait_s(i2cp, timeout, rdymsg); + + *errors = i2cp->errors; - return i2cGetAndClearFlags(i2cp); + return rdymsg; } /** @@ -181,69 +188,40 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout operation timeout * - * @return Zero if no errors, otherwise return error code. + * @return timeout status + * @retval RDY_OK if timeout not reached + * @retval RDY_TIMEOUT if a timeout occurs */ -i2cflags_t i2cMasterReceive(I2CDriver *i2cp, +msg_t i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *rxbuf, - size_t rxbytes){ + size_t rxbytes, + i2cflags_t *errors, + systime_t timeout){ + + msg_t rdymsg; chDbgCheck((i2cp != NULL) && (slave_addr != 0) && - (rxbytes > 0) && (rxbuf != NULL), + (rxbytes > 0) && (rxbuf != NULL) && + (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterReceive"); - - i2c_lld_wait_bus_free(i2cp); - - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), - "i2cMasterReceive(), #1", "time is out"); + i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); - _i2c_wait_s(i2cp); + _i2c_wait_s(i2cp, timeout, rdymsg); - return i2cGetAndClearFlags(i2cp); -} - -/** - * @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) { + *errors = i2cp->errors; - chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - - i2cp->errors |= mask; + return rdymsg; } -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { - i2cflags_t mask; - - chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); - - chSysLock(); - mask = i2cp->errors; - i2cp->errors = I2CD_NO_ERROR; - chSysUnlock(); - return mask; -} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 28cb4b4849c6e124baed09bdb4753d7b87a47483 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 9 Dec 2011 10:22:41 +0000 Subject: I2C. Added forgotten check of BUSY flag. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3587 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f7f7c335e..c67f3a8c6 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -168,6 +168,8 @@ msg_t i2cMasterTransmit(I2CDriver *i2cp, ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterTransmit"); + + i2c_lld_wait_bus_free(i2cp); i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -209,6 +211,8 @@ msg_t i2cMasterReceive(I2CDriver *i2cp, (rxbytes > 0) && (rxbuf != NULL) && (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterReceive"); + + i2c_lld_wait_bus_free(i2cp); i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); -- cgit v1.2.3 From 9d343de5f9f3620f8d915a2e6dadf874ef2d02cb Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 11 Dec 2011 23:40:49 +0000 Subject: RTC. Driver broken. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3598 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index dda5a9c95..f7ce21529 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -134,25 +134,55 @@ void rtcGetAlarm(RTCDriver *rtcp, } #endif /* RTC_ALARMS > 0 */ + + + + + + +/** + * @brief Sets periodic wakeup period. + */ +void rtcSetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { + chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcSetPeriodicWakeup"); + rtc_lld_set_periodic_wakeup(rtcp, wakeupspec); +} +/** + * @brief Gets periodic wakeup period. + */ +void rtcGetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { + chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcGetPeriodicWakeup"); + rtc_lld_get_periodic_wakeup(rtcp, wakeupspec); +} + + + + + + + #if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** * @brief Enables or disables RTC callbacks. - * @details This function enables or disables callbacks, use a @p NULL pointer - * in order to disable a callback. + * @details TODO: * * @param[in] rtcp pointer to RTC driver structure - * @param[in] callback callback function pointer or @p NULL + * @param[in] cb_cfg callback configuration struct * * @api */ -void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { +void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) { - chDbgCheck((rtcp != NULL), "rtcSetCallback"); + chDbgCheck(((rtcp != NULL) && (cb_cfg != NULL)), "rtcSetCallback"); - rtc_lld_set_callback(rtcp, callback); + rtc_lld_set_callback(rtcp, cb_cfg); } #endif /* RTC_SUPPORTS_CALLBACKS */ + + + + #endif /* HAL_USE_RTC */ /** @} */ -- cgit v1.2.3 From facfe77b186a05dde255b4c66d22cdddaf0fd0f6 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 12 Dec 2011 10:56:51 +0000 Subject: RTC. Development suspended until EXTI driver API will changed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3600 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index f7ce21529..52e35fd22 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -117,8 +117,8 @@ void rtcSetAlarm(RTCDriver *rtcp, * @note If an alarm has not been set then the returned alarm specification * is not meaningful. * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] alarm alarm identifier + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier * @param[out] alarmspec pointer to a @p RTCAlarm structure * * @api @@ -134,12 +134,6 @@ void rtcGetAlarm(RTCDriver *rtcp, } #endif /* RTC_ALARMS > 0 */ - - - - - - /** * @brief Sets periodic wakeup period. */ -- cgit v1.2.3 From dd834361e8d805cf5ecf89bcdc15b08f60268e76 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 12 Dec 2011 13:13:07 +0000 Subject: RTCv1 code cleanups and adding some safety checks. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3603 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 52e35fd22..37ab87c00 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -134,26 +134,6 @@ void rtcGetAlarm(RTCDriver *rtcp, } #endif /* RTC_ALARMS > 0 */ -/** - * @brief Sets periodic wakeup period. - */ -void rtcSetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { - chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcSetPeriodicWakeup"); - rtc_lld_set_periodic_wakeup(rtcp, wakeupspec); -} -/** - * @brief Gets periodic wakeup period. - */ -void rtcGetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { - chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcGetPeriodicWakeup"); - rtc_lld_get_periodic_wakeup(rtcp, wakeupspec); -} - - - - - - #if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 35ea7347004a31e1b850c41b60a3bf7457ed4418 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 13 Dec 2011 09:03:41 +0000 Subject: RTC. Added callback switch helper. Not tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3608 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 37ab87c00..9df399eeb 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -153,10 +153,6 @@ void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) { } #endif /* RTC_SUPPORTS_CALLBACKS */ - - - - #endif /* HAL_USE_RTC */ /** @} */ -- cgit v1.2.3 From 9a98744b28ecfda0d78d5983e3a2d264c36bcec7 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 15 Dec 2011 20:49:24 +0000 Subject: RTC. Testhal works on F4x, compiles (but not deeply tested) on F1x. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3615 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 9df399eeb..20a39ea7c 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -135,10 +135,38 @@ void rtcGetAlarm(RTCDriver *rtcp, #endif /* RTC_ALARMS > 0 */ + +/** + * @brief Set periodic wakeup period. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] wakeupspec pointer to a @p RTCWakeup structure + * + * @api + */ +void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { + + chDbgCheck((rtcp != NULL), "rtcGetAlarm"); + rtc_lld_set_periodic_wakeup(rtcp, wakeupspec); +} + +/** + * @brief Get periodic wakeup period. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[out] wakeupspec pointer to a @p RTCWakeup structure + * + * @api + */ +void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { + + chDbgCheck((rtcp != NULL), "rtcGetAlarm"); + rtc_lld_get_periodic_wakeup(rtcp, wakeupspec); +} + #if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** * @brief Enables or disables RTC callbacks. - * @details TODO: * * @param[in] rtcp pointer to RTC driver structure * @param[in] cb_cfg callback configuration struct -- cgit v1.2.3 From 968d0cf6e9e8f362021e4288cd3336fe7922e00e Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 16 Dec 2011 14:42:23 +0000 Subject: RTC. High level API rolled back. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3619 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 20a39ea7c..dda5a9c95 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -117,8 +117,8 @@ void rtcSetAlarm(RTCDriver *rtcp, * @note If an alarm has not been set then the returned alarm specification * is not meaningful. * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] alarm alarm identifier + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier * @param[out] alarmspec pointer to a @p RTCAlarm structure * * @api @@ -134,50 +134,22 @@ void rtcGetAlarm(RTCDriver *rtcp, } #endif /* RTC_ALARMS > 0 */ - - -/** - * @brief Set periodic wakeup period. - * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] wakeupspec pointer to a @p RTCWakeup structure - * - * @api - */ -void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { - - chDbgCheck((rtcp != NULL), "rtcGetAlarm"); - rtc_lld_set_periodic_wakeup(rtcp, wakeupspec); -} - -/** - * @brief Get periodic wakeup period. - * - * @param[in] rtcp pointer to RTC driver structure - * @param[out] wakeupspec pointer to a @p RTCWakeup structure - * - * @api - */ -void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) { - - chDbgCheck((rtcp != NULL), "rtcGetAlarm"); - rtc_lld_get_periodic_wakeup(rtcp, wakeupspec); -} - #if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** * @brief Enables or disables RTC callbacks. + * @details This function enables or disables callbacks, use a @p NULL pointer + * in order to disable a callback. * * @param[in] rtcp pointer to RTC driver structure - * @param[in] cb_cfg callback configuration struct + * @param[in] callback callback function pointer or @p NULL * * @api */ -void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) { +void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { - chDbgCheck(((rtcp != NULL) && (cb_cfg != NULL)), "rtcSetCallback"); + chDbgCheck((rtcp != NULL), "rtcSetCallback"); - rtc_lld_set_callback(rtcp, cb_cfg); + rtc_lld_set_callback(rtcp, callback); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From b30ba31603e2e1f130e9af44f1f140390fff65fe Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 18:03:49 +0000 Subject: I2C API proposal. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3684 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 154 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 66 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index c67f3a8c6..28dd99762 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -132,111 +132,132 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Returns the errors mask associated to the previous operation. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @return The errors mask. + * + * @api + */ +i2cflags_t i2cGetErrors(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cGetErrors"); + + return i2c_lld_get_errors(i2cp); +} + /** * @brief Sends data via the I2C bus. * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr Slave device address (7 bits) without R/W bit - * @param[in] txbuf pointer to transmit buffer - * @param[in] txbytes number of bytes to be transmitted - * @param[in] rxbuf pointer to receive buffer - * @param[in] rxbytes number of bytes to be received, set it to 0 if - * you want transmit only - * @param[in] errors pointer to variable to store error code, zero means - * no error. - * @param[in] timeout operation timeout + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] addr slave device address (7 bits) without R/W bit + * @param[in] txbuf pointer to transmit buffer + * @param[in] txbytes number of bytes to be transmitted + * @param[in] rxbuf pointer to receive buffer + * @param[in] rxbytes number of bytes to be received, set it to 0 if + * you want transmit only + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_INFINITE no timeout. + * . + * + * @return The number of received bytes or an exit code. + * @retval RDY_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval RDY_TIMEOUT if a timeout occurred before operation end. * - * @return timeout status - * @retval RDY_OK if timeout not reached - * @retval RDY_TIMEOUT if a timeout occurs + * @api */ -msg_t i2cMasterTransmit(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *txbuf, - size_t txbytes, - uint8_t *rxbuf, - size_t rxbytes, - i2cflags_t *errors, - systime_t timeout) { +msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, + i2caddr_t addr, + const uint8_t *txbuf, + size_t txbytes, + uint8_t *rxbuf, + size_t rxbytes, + systime_t timeout) { msg_t rdymsg; - chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + chDbgCheck((i2cp != NULL) && (addr != 0) && (txbytes > 0) && (txbuf != NULL) && ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && - (timeout > TIME_IMMEDIATE) && (errors != NULL), - "i2cMasterTransmit"); + (timeout != TIME_IMMEDIATE), + "i2cMasterTransmitTimeout"); - i2c_lld_wait_bus_free(i2cp); - i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", "not ready"); + "i2cMasterTransmitTimeout(), #1", "not ready"); + chSysLock(); + i2cp->errors = I2CD_NO_ERROR; i2cp->id_state = I2C_ACTIVE_TRANSMIT; - i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); - _i2c_wait_s(i2cp, timeout, rdymsg); - - *errors = i2cp->errors; - + rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, + rxbuf, rxbytes, timeout); + i2cp->id_state = I2C_READY; + chSysUnlock(); return rdymsg; } /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr slave device address (7 bits) without R/W bit - * @param[in] rxbytes number of bytes to be received - * @param[in] rxbuf pointer to receive buffer - * @param[in] errors pointer to variable to store error code, zero means - * no error. - * @param[in] timeout operation timeout + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] addr slave device address (7 bits) without R/W bit + * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_INFINITE no timeout. + * . * - * @return timeout status - * @retval RDY_OK if timeout not reached - * @retval RDY_TIMEOUT if a timeout occurs + * @return The number of received bytes or an exit code. + * @retval RDY_OK if the function succeeded. + * @retval RDY_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval RDY_TIMEOUT if a timeout occurred before operation end. + * + * @api */ -msg_t i2cMasterReceive(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *rxbuf, - size_t rxbytes, - i2cflags_t *errors, - systime_t timeout){ +msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, + i2caddr_t slave_addr, + uint8_t *rxbuf, + size_t rxbytes, + systime_t timeout){ msg_t rdymsg; - chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + chDbgCheck((i2cp != NULL) && (addr != 0) && (rxbytes > 0) && (rxbuf != NULL) && - (timeout > TIME_IMMEDIATE) && (errors != NULL), - "i2cMasterReceive"); + (timeout != TIME_IMMEDIATE), + "i2cMasterReceiveTimeout"); - i2c_lld_wait_bus_free(i2cp); - i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); + chSysLock(); + i2cp->errors = I2CD_NO_ERROR; i2cp->id_state = I2C_ACTIVE_RECEIVE; - i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); - _i2c_wait_s(i2cp, timeout, rdymsg); - - *errors = i2cp->errors; - + rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); + i2cp->id_state = I2C_READY; + chSysUnlock(); return rdymsg; } - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @api */ void i2cAcquireBus(I2CDriver *i2cp) { @@ -250,12 +271,13 @@ void i2cAcquireBus(I2CDriver *i2cp) { } /** - * @brief Releases exclusive access to the I2C bus. + * @brief Releases exclusive access to the I2C bus. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @api */ void i2cReleaseBus(I2CDriver *i2cp) { -- cgit v1.2.3 From 411418930f549e656dde9067446cfd52317fe33d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 18:07:02 +0000 Subject: Updated credits. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3685 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++++ os/hal/src/rtc.c | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 28dd99762..5cf5cb4f7 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Concepts and parts of this file have been contributed by Uladzimir Pylinsky + aka barthess. + */ /** * @file i2c.c diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index dda5a9c95..d7750001d 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Concepts and parts of this file have been contributed by Uladzimir Pylinsky + aka barthess. + */ /** * @file rtc.c -- cgit v1.2.3 From 08feb80580ca82cfebd77a43d14d1197ec7c4f99 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 22:18:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3686 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 5cf5cb4f7..598719d24 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -169,7 +169,8 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { * - @a TIME_INFINITE no timeout. * . * - * @return The number of received bytes or an exit code. + * @return The operation status. + * @retval RDY_OK if the function succeeded. * @retval RDY_RESET if one or more I2C errors occurred, the errors can * be retrieved using @p i2cGetErrors(). * @retval RDY_TIMEOUT if a timeout occurred before operation end. @@ -218,7 +219,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * - @a TIME_INFINITE no timeout. * . * - * @return The number of received bytes or an exit code. + * @return The operation status. * @retval RDY_OK if the function succeeded. * @retval RDY_RESET if one or more I2C errors occurred, the errors can * be retrieved using @p i2cGetErrors(). -- cgit v1.2.3 From 2234fd3e31d4ce6e2b3990340b52719951e65731 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 30 Dec 2011 20:45:56 +0000 Subject: I2C. API changes mostly done. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3692 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 598719d24..f48ca9e7e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -179,7 +179,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { */ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, - const uint8_t *txbuf, + uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, @@ -202,7 +202,10 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - return rdymsg; + if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) + return RDY_RESET; + else + return rdymsg; } /** @@ -228,7 +231,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * @api */ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, - i2caddr_t slave_addr, + i2caddr_t addr, uint8_t *rxbuf, size_t rxbytes, systime_t timeout){ @@ -249,7 +252,10 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - return rdymsg; + if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) + return RDY_RESET; + else + return rdymsg; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From 72266f8b591c6e7857f4578ba753eeea7222ac6b Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 31 Dec 2011 09:40:52 +0000 Subject: I2C. Fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3694 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f48ca9e7e..841349be4 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -78,7 +78,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; i2cp->rxbuf = NULL; - i2cp->txbuf = NULL; i2cp->id_thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION @@ -179,7 +178,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { */ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, - uint8_t *txbuf, + const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, @@ -202,10 +201,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) - return RDY_RESET; - else - return rdymsg; + return rdymsg; } /** @@ -252,10 +248,7 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) - return RDY_RESET; - else - return rdymsg; + return rdymsg; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From c397738010966f85c7ae841e21d74790ac49611c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 31 Dec 2011 10:07:43 +0000 Subject: Changes to palSetGroupMode(), various adjustments to the PAL driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3695 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/pal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index afb5c6b40..faa022f5d 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -119,7 +119,7 @@ void palSetBusMode(IOBus *bus, iomode_t mode) { chDbgCheck((bus != NULL) && (bus->offset < PAL_IOPORTS_WIDTH), "palSetBusMode"); - palSetGroupMode(bus->portid, bus->mask, mode); + palSetGroupMode(bus->portid, bus->mask, bus->offset, mode); } #endif /* HAL_USE_PAL */ -- cgit v1.2.3 From f76898bb0f7e6c894a1e5fb5d55f3e81a4f28fa6 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 2 Jan 2012 17:53:20 +0000 Subject: I2C. Rest of "id_" prefixes deleted from driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3708 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 841349be4..fb45ce6a5 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -75,16 +75,16 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->id_state = I2C_STOP; - i2cp->id_config = NULL; + i2cp->state = I2C_STOP; + i2cp->config = NULL; i2cp->rxbuf = NULL; - i2cp->id_thread = NULL; + i2cp->thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES - chMtxInit(&i2cp->id_mutex); + chMtxInit(&i2cp->mutex); #else - chSemInit(&i2cp->id_semaphore, 1); + chSemInit(&i2cp->semaphore, 1); #endif /* CH_USE_MUTEXES */ #endif /* I2C_USE_MUTUAL_EXCLUSION */ @@ -104,14 +104,14 @@ void i2cObjectInit(I2CDriver *i2cp) { void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), "i2cStart(), #1", "invalid state"); chSysLock(); - i2cp->id_config = config; + i2cp->config = config; i2c_lld_start(i2cp); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); } @@ -125,13 +125,13 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), "i2cStop(), #1", "invalid state"); chSysLock(); i2c_lld_stop(i2cp); - i2cp->id_state = I2C_STOP; + i2cp->state = I2C_STOP; chSysUnlock(); } @@ -191,15 +191,15 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, (timeout != TIME_IMMEDIATE), "i2cMasterTransmitTimeout"); - chDbgAssert(i2cp->id_state == I2C_READY, + chDbgAssert(i2cp->state == I2C_READY, "i2cMasterTransmitTimeout(), #1", "not ready"); chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->id_state = I2C_ACTIVE_TRANSMIT; + i2cp->state = I2C_ACTIVE_TRANSMIT; rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes, timeout); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -239,14 +239,14 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, (timeout != TIME_IMMEDIATE), "i2cMasterReceiveTimeout"); - chDbgAssert(i2cp->id_state == I2C_READY, + chDbgAssert(i2cp->state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->id_state = I2C_ACTIVE_RECEIVE; + i2cp->state = I2C_ACTIVE_RECEIVE; rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -268,9 +268,9 @@ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); + chMtxLock(&i2cp->mutex); #elif CH_USE_SEMAPHORES - chSemWait(&i2cp->id_semaphore); + chSemWait(&i2cp->semaphore); #endif } @@ -290,7 +290,7 @@ void i2cReleaseBus(I2CDriver *i2cp) { #if CH_USE_MUTEXES chMtxUnlock(); #elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->id_semaphore); + chSemSignal(&i2cp->semaphore); #endif } #endif /* I2C_USE_MUTUAL_EXCLUSION */ -- cgit v1.2.3 From 354a341507f6b174a576a8023f3f4bb2715b5b16 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 4 Jan 2012 10:36:13 +0000 Subject: Fixed some documentation errors. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3725 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index fb45ce6a5..42481a2fd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -160,7 +160,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { * @param[in] addr slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted - * @param[in] rxbuf pointer to receive buffer + * @param[out] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only * @param[in] timeout the number of ticks before the operation timeouts, @@ -209,10 +209,8 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] addr slave device address (7 bits) without R/W bit + * @param[out] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received - * @param[in] rxbuf pointer to receive buffer - * @param[in] errors pointer to variable to store error code, zero means - * no error. * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_INFINITE no timeout. -- cgit v1.2.3 From 8bd4ec7b8474fcfce5c4441131f841175d62e0b0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 4 Jan 2012 11:19:31 +0000 Subject: Removed two initializations that should go in the low level. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3727 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 42481a2fd..66b01e0f3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -77,8 +77,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->state = I2C_STOP; i2cp->config = NULL; - i2cp->rxbuf = NULL; - i2cp->thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES -- cgit v1.2.3 From 3f685aa996b5fd8af4ea87b67c32fa2ce311c273 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 4 Jan 2012 14:36:51 +0000 Subject: I2C. Merged changes from i2c_lld_2.zip git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3729 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 66b01e0f3..ea0df6589 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -29,7 +29,6 @@ * @addtogroup I2C * @{ */ - #include "ch.h" #include "hal.h" -- cgit v1.2.3 From 62b090c673675b2f519aced5f466a72e432b1417 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 5 Jan 2012 16:01:52 +0000 Subject: Improvements to the MMC over SPI driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3741 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 147 insertions(+), 13 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 34d111c2d..5d56125ca 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -17,15 +17,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Parts of this file have been contributed by Matthias Blaicher. + */ /** - * @file spi.c + * @file mmc_spi.c * @brief MMC over SPI driver code. * * @addtogroup MMC_SPI * @{ */ +#include + #include "ch.h" #include "hal.h" @@ -43,10 +48,53 @@ /* Driver local variables. */ /*===========================================================================*/ +/** + * @brief Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1). + */ +static const uint8_t crc7_lookup_table[256] = { + 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, + 0x6c, 0x65, 0x7e, 0x77, 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26, + 0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e, 0x32, 0x3b, 0x20, 0x29, + 0x16, 0x1f, 0x04, 0x0d, 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45, + 0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14, 0x63, 0x6a, 0x71, 0x78, + 0x47, 0x4e, 0x55, 0x5c, 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b, + 0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13, 0x7d, 0x74, 0x6f, 0x66, + 0x59, 0x50, 0x4b, 0x42, 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a, + 0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69, 0x1e, 0x17, 0x0c, 0x05, + 0x3a, 0x33, 0x28, 0x21, 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70, + 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38, 0x41, 0x48, 0x53, 0x5a, + 0x65, 0x6c, 0x77, 0x7e, 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36, + 0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67, 0x10, 0x19, 0x02, 0x0b, + 0x34, 0x3d, 0x26, 0x2f, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, + 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04, 0x6a, 0x63, 0x78, 0x71, + 0x4e, 0x47, 0x5c, 0x55, 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d, + 0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a, 0x6d, 0x64, 0x7f, 0x76, + 0x49, 0x40, 0x5b, 0x52, 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03, + 0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b, 0x17, 0x1e, 0x05, 0x0c, + 0x33, 0x3a, 0x21, 0x28, 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60, + 0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31, 0x46, 0x4f, 0x54, 0x5d, + 0x62, 0x6b, 0x70, 0x79 +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Calculate the MMC standard CRC-7 based on a lookup table. + * + * @param[in] crc start value for CRC + * @param[in] buffer pointer to data buffer + * @param[in] len length of data + * @return Calculated CRC + */ +static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { + + while (len--) + crc = crc7_lookup_table[(crc << 1) ^ (*buffer++)]; + return crc; +} + /** * @brief Inserion monitor timer callback function. * @@ -109,15 +157,15 @@ static void wait(MMCDriver *mmcp) { * @brief Sends a command header. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param cmd[in] the command id - * @param arg[in] the command argument + * @param[in] cmd the command id + * @param[in] arg the command argument * * @notapi */ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t buf[6]; - /* Wait for the bus to become idle if a write operation was in progress. */ + /* Wait for the bus to become idle if a write operation was in progress.*/ wait(mmcp); buf[0] = 0x40 | cmd; @@ -125,7 +173,9 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[2] = arg >> 16; buf[3] = arg >> 8; buf[4] = arg; - buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ + /* Calculate CRC for command header, shift to right position, add stop bit.*/ + buf[5] = ((crc7(0, buf, 5) & 0x7F) << 1) | 0x01; + spiSend(mmcp->spip, 6, buf); } @@ -150,18 +200,37 @@ static uint8_t recvr1(MMCDriver *mmcp) { return 0xFF; } +/** + * @brief Receives a three byte response. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to four bytes wide buffer + * @return First response byte as an @p uint8_t value. + * @retval 0xFF timed out. + * + * @notapi + */ +static uint8_t recvr3(MMCDriver *mmcp, uint8_t* buffer) { + uint8_t r1; + + r1 = recvr1(mmcp); + spiReceive(mmcp->spip, 4, buffer); + + return r1; +} + /** * @brief Sends a command an returns a single byte response. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param cmd[in] the command id - * @param arg[in] the command argument + * @param[in] cmd the command id + * @param[in] arg the command argument * @return The response as an @p uint8_t value. * @retval 0xFF timed out. * * @notapi */ -static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { +static uint8_t send_command_R1(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t r1; spiSelect(mmcp->spip); @@ -171,6 +240,30 @@ static uint8_t send_command(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { return r1; } +/** + * @brief Sends a command which returns a five bytes response (R3). + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] cmd the command id + * @param[in] arg the command argument + * @param[out] response pointer to four bytes wide uint8_t buffer + * @return The first byte of the response (R1) as an @p + * uint8_t value. + * @retval 0xFF timed out. + * + * @notapi + */ +static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, + uint8_t *response) { + uint8_t r1; + + spiSelect(mmcp->spip); + send_hdr(mmcp, cmd, arg); + r1 = recvr3(mmcp, response); + spiUnselect(mmcp->spip); + return r1; +} + /** * @brief Waits that the card reaches an idle state. * @@ -233,6 +326,7 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, 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); } @@ -315,17 +409,47 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* SPI mode selection.*/ i = 0; while (TRUE) { - if (send_command(mmcp, MMC_CMDGOIDLE, 0) == 0x01) + if (send_command_R1(mmcp, MMC_CMDGOIDLE, 0) == 0x01) break; if (++i >= MMC_CMD0_RETRY) return TRUE; chThdSleepMilliseconds(10); } + /* Try to detect if this is a high capacity card and switch to block + * addresses if possible. + * + * This method is based on "How to support SDC Ver2 and high capacity cards" + * by ElmChan. + * + * */ + uint8_t r3[4]; + if(send_command_R3(mmcp, MMC_CMDINTERFACE_CONDITION, 0x01AA, r3) != 0x05){ + + /* Switch to SDHC mode */ + i = 0; + while (TRUE) { + if ((send_command_R1(mmcp, MMC_CMDAPP, 0) == 0x01) && + (send_command_R3(mmcp, MMC_ACMDOPCONDITION, 0x400001aa, r3) == 0x00)) + break; + + if (++i >= MMC_ACMD41_RETRY) + return TRUE; + chThdSleepMilliseconds(10); + } + + /* Execute dedicated read on OCR register */ + send_command_R3(mmcp, MMC_CMDREADOCR, 0, r3); + + /* Check if CCS is set in response. Card operates in block mode if set */ + if(r3[0] & 0x40) + mmcp->block_addresses = TRUE; + } + /* Initialization. */ i = 0; while (TRUE) { - uint8_t b = send_command(mmcp, MMC_CMDINIT, 0); + uint8_t b = send_command_R1(mmcp, MMC_CMDINIT, 0); if (b == 0x00) break; if (b != 0x01) @@ -339,7 +463,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { spiStart(mmcp->spip, mmcp->hscfg); /* Setting block size.*/ - if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) + if (send_command_R1(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) return TRUE; /* Transition to MMC_READY state (if not extracted).*/ @@ -419,7 +543,12 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { spiStart(mmcp->spip, mmcp->hscfg); spiSelect(mmcp->spip); - send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); + + if(mmcp->block_addresses) + send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk); + else + send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); + if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->spip); chSysLock(); @@ -534,7 +663,12 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { spiStart(mmcp->spip, mmcp->hscfg); spiSelect(mmcp->spip); - send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); + if(mmcp->block_addresses) + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk); + else + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); + + if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->spip); chSysLock(); -- cgit v1.2.3 From 54c975bed0b0fbfbf6fdd1a5024c258150c4c5dc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 6 Jan 2012 19:05:13 +0000 Subject: I2C driver state diagram modified, documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3751 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ea0df6589..fcccd6a87 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -101,7 +101,8 @@ void i2cObjectInit(I2CDriver *i2cp) { void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || + (i2cp->state == I2C_LOCKED), "i2cStart(), #1", "invalid state"); @@ -122,7 +123,8 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || + (i2cp->state == I2C_LOCKED), "i2cStop(), #1", "invalid state"); @@ -193,10 +195,13 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_ACTIVE_TRANSMIT; + i2cp->state = I2C_ACTIVE_TX; rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes, timeout); - i2cp->state = I2C_READY; + if (rdymsg == RDY_TIMEOUT) + i2cp->state = I2C_LOCKED; + else + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -239,9 +244,12 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_ACTIVE_RECEIVE; + i2cp->state = I2C_ACTIVE_RX; rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); - i2cp->state = I2C_READY; + if (rdymsg == RDY_TIMEOUT) + i2cp->state = I2C_LOCKED; + else + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } -- cgit v1.2.3 From 7041c5b167918def8ad906cbd9a46d73acc73c56 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 9 Jan 2012 18:28:29 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3775 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 ++ os/hal/src/tm.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 os/hal/src/tm.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d5a8082e9..b469b57e5 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -62,6 +62,9 @@ void halInit(void) { hal_lld_init(); +#if HAL_USE_TM || defined(__DOXYGEN__) + tmInit(); +#endif #if HAL_USE_PAL || defined(__DOXYGEN__) palInit(&pal_default_config); #endif diff --git a/os/hal/src/tm.c b/os/hal/src/tm.c new file mode 100644 index 000000000..4d1eb57b8 --- /dev/null +++ b/os/hal/src/tm.c @@ -0,0 +1,105 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file tm.c + * @brief Time Measurement unit code. + * + * @addtogroup TM + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_TM + +/** + * @brief Subsystem calibration value. + */ +static halrtcnt_t measurement_offset; + + +/** + * @brief Starts a measurement. + * + * @param[in,out] tmp pointer to a @p TimeMeasurement structure + * + * @notapi + */ +static void tm_start(TimeMeasurement *tmp) { + + tmp->last = halGetCounterValue(); +} + +/** + * @brief Stops a measurement. + * + * @param[in,out] tmp pointer to a @p TimeMeasurement structure + * + * @notapi + */ +static void tm_stop(TimeMeasurement *tmp) { + + halrtcnt_t now = halGetCounterValue(); + tmp->last = now - tmp->last - measurement_offset; + if (tmp->last > tmp->worst) + tmp->worst = tmp->last; + else if (tmp->last < tmp->best) + tmp->best = tmp->last; +} + +/** + * @brief Initializes the Time Measurement unit. + * + * @init + */ +void tmInit(void) { + TimeMeasurement tm; + + /* Time Measurement subsystem calibration, it does a null measurement + and calculates the call overhead which is subtracted to real + measurements.*/ + measurement_offset = 0; + tmObjectInit(&tm); + tmStartMeasurement(&tm); + tmStopMeasurement(&tm); + measurement_offset = tm.last; +} + +/** + * @brief Initializes a @p TimeMeasurement object. + * + * @param[out] tmp pointer to a @p TimeMeasurement structure + * + * @init + */ +void tmObjectInit(TimeMeasurement *tmp) { + + tmp->start = tm_start; + tmp->stop = tm_stop; + tmp->last = (halrtcnt_t)0; + tmp->worst = (halrtcnt_t)0; + tmp->best = (halrtcnt_t)-1; +} + +#endif /* HAL_USE_TM */ + +/** @} */ -- cgit v1.2.3 From a2708c091beb3331967dff2af9a9232744427de4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 9 Jan 2012 19:37:58 +0000 Subject: Updated all halconf.h files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3777 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/tm.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/tm.c b/os/hal/src/tm.c index 4d1eb57b8..060a35b66 100644 --- a/os/hal/src/tm.c +++ b/os/hal/src/tm.c @@ -20,7 +20,7 @@ /** * @file tm.c - * @brief Time Measurement unit code. + * @brief Time Measurement driver code. * * @addtogroup TM * @{ @@ -29,13 +29,28 @@ #include "ch.h" #include "hal.h" -#if HAL_USE_TM +#if HAL_USE_TM || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ /** * @brief Subsystem calibration value. */ static halrtcnt_t measurement_offset; +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ /** * @brief Starts a measurement. @@ -66,6 +81,14 @@ static void tm_stop(TimeMeasurement *tmp) { tmp->best = tmp->last; } +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes the Time Measurement unit. * -- cgit v1.2.3 From 4e3e0d62789355cfc630012dfcab96c78d3fec2e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 12 Jan 2012 18:26:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3797 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index d7750001d..1f463eb38 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -141,8 +141,8 @@ void rtcGetAlarm(RTCDriver *rtcp, #if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** * @brief Enables or disables RTC callbacks. - * @details This function enables or disables callbacks, use a @p NULL pointer - * in order to disable a callback. + * @details This function enables or disables the callback, use a @p NULL + * pointer in order to disable it. * * @param[in] rtcp pointer to RTC driver structure * @param[in] callback callback function pointer or @p NULL -- cgit v1.2.3 From d29e6e338ec4da796225af4dbc9ab001406a14a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 14 Jan 2012 08:45:34 +0000 Subject: Added I-Class APIs to the RTC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3807 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 1f463eb38..6cf254706 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -79,7 +79,9 @@ void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec) { chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcSetTime"); - rtc_lld_set_time(rtcp, timespec); + chSysLock(); + rtcSetTimeI(rtcp, timespec); + chSysUnlock(); } /** @@ -94,7 +96,9 @@ void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcGetTime"); - rtc_lld_get_time(rtcp, timespec); + chSysLock(); + rtcGetTimeI(rtcp, timespec); + chSysUnlock(); } #if (RTC_ALARMS > 0) || defined(__DOXYGEN__) @@ -113,7 +117,9 @@ void rtcSetAlarm(RTCDriver *rtcp, chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS), "rtcSetAlarm"); - rtc_lld_set_alarm(rtcp, alarm, alarmspec); + chSysLock(); + rtcSetAlarmI(rtcp, alarm, alarmspec); + chSysUnlock(); } /** @@ -134,7 +140,9 @@ void rtcGetAlarm(RTCDriver *rtcp, chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS) && (alarmspec != NULL), "rtcGetAlarm"); - rtc_lld_get_alarm(rtcp, alarm, alarmspec); + chSysLock(); + rtcGetAlarmI(rtcp, alarm, alarmspec); + chSysUnlock(); } #endif /* RTC_ALARMS > 0 */ @@ -153,7 +161,9 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { chDbgCheck((rtcp != NULL), "rtcSetCallback"); - rtc_lld_set_callback(rtcp, callback); + chSysLock(); + rtcSetCallbackI(rtcp, callback); + chSysUnlock(); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- os/hal/src/can.c | 2 +- os/hal/src/ext.c | 2 +- os/hal/src/gpt.c | 2 +- os/hal/src/hal.c | 2 +- os/hal/src/i2c.c | 2 +- os/hal/src/icu.c | 2 +- os/hal/src/mac.c | 2 +- os/hal/src/mmc_spi.c | 2 +- os/hal/src/pal.c | 2 +- os/hal/src/pwm.c | 2 +- os/hal/src/rtc.c | 2 +- os/hal/src/sdc.c | 2 +- os/hal/src/serial.c | 2 +- os/hal/src/serial_usb.c | 2 +- os/hal/src/spi.c | 2 +- os/hal/src/tm.c | 2 +- os/hal/src/uart.c | 2 +- os/hal/src/usb.c | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 08aa830f0..d84e17faf 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e888c2ae7..041409c99 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index 1c83cd2e6..e89962dea 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 726936ca8..a0745da93 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index b469b57e5..3cf15226a 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index fcccd6a87..152a77840 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c index c73ea5106..240da1452 100644 --- a/os/hal/src/icu.c +++ b/os/hal/src/icu.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index edd15d087..5ffb42b8d 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 5d56125ca..8f11355b8 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index faa022f5d..21fe48e16 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 588b3df5c..6e67d5407 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 6cf254706..01f88e82d 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 758edf8d8..e8894a597 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index d962bcdcd..d0ea89297 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index ea434b197..f007e7bdd 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index b91b44507..3817143c8 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/tm.c b/os/hal/src/tm.c index 060a35b66..bb11fba0f 100644 --- a/os/hal/src/tm.c +++ b/os/hal/src/tm.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index ed28ecb3b..1ab95a8ee 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 30919580c..cbd009483 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 18b8b495244411bb33254ea0d8b868259077be7d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 8 Feb 2012 17:53:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3946 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 8f11355b8..f4bcb51fd 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -105,6 +105,7 @@ static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { static void tmrfunc(void *p) { MMCDriver *mmcp = p; + chSysLockFromIsr(); if (mmcp->cnt > 0) { if (mmcp->is_inserted()) { if (--mmcp->cnt == 0) { @@ -123,6 +124,7 @@ static void tmrfunc(void *p) { } } chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + chSysUnlockFromIsr(); } /** -- cgit v1.2.3 From 267cd61c1914bc1d71f47f020d391c2d3ac1c224 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 11 Feb 2012 08:57:22 +0000 Subject: Fixed bug 3485500. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3950 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 3cf15226a..dad579ad0 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -120,4 +120,75 @@ void halInit(void) { boardInit(); } +#if HAL_IMPLEMENTS_COUNTERS || defined(__DOXYGEN__) +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This is an optional service that could not be implemented in + * all HAL implementations. + * @note This function can be called from any context. + * + * @par Example 1 + * Example of a guarded loop using the realtime counter. The loop implements + * a timeout after one second. + * @code + * halrtcnt_t start = halGetCounterValue(); + * halrtcnt_t timeout = start + S2RTT(1); + * while (my_condition) { + * if (!halIsCounterWithin(start, timeout) + * return TIMEOUT; + * // Do something. + * } + * // Continue. + * @endcode + * + * @par Example 2 + * Example of a loop that lasts exactly 50 microseconds. + * @code + * halrtcnt_t start = halGetCounterValue(); + * halrtcnt_t timeout = start + US2RTT(50); + * while (halIsCounterWithin(start, timeout)) { + * // Do something. + * } + * // Continue. + * @endcode + * + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval TRUE current time within the specified time window. + * @retval FALSE current time not within the specified time window. + * + * @special + */ +bool_t halIsCounterWithin(halrtcnt_t start, halrtcnt_t end) { + halrtcnt_t now = halGetCounterValue(); + + return end > start ? (now >= start) && (now < end) : + (now >= start) || (now < end); +} + +/** + * @brief Polled delay. + * @note The real delays is always few cycles in excess of the specified + * value. + * @note This is an optional service that could not be implemented in + * all HAL implementations. + * @note This function can be called from any context. + * + * @param[in] ticks number of ticks + * + * @special + */ +void halPolledDelay(halrtcnt_t ticks) { + halrtcnt_t start = halGetCounterValue(); + halrtcnt_t timeout = start + (ticks); + while (halIsCounterWithin(start, timeout)) + ; +} +#endif /* HAL_IMPLEMENTS_COUNTERS */ + /** @} */ -- cgit v1.2.3 From aab3b75fc1a7db54dff630b74158a673b88f8fa1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 12 Feb 2012 09:30:37 +0000 Subject: Fixed bug 3486930. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3952 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index f4bcb51fd..06f2594bf 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -48,53 +48,10 @@ /* Driver local variables. */ /*===========================================================================*/ -/** - * @brief Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1). - */ -static const uint8_t crc7_lookup_table[256] = { - 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, - 0x6c, 0x65, 0x7e, 0x77, 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26, - 0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e, 0x32, 0x3b, 0x20, 0x29, - 0x16, 0x1f, 0x04, 0x0d, 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45, - 0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14, 0x63, 0x6a, 0x71, 0x78, - 0x47, 0x4e, 0x55, 0x5c, 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b, - 0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13, 0x7d, 0x74, 0x6f, 0x66, - 0x59, 0x50, 0x4b, 0x42, 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a, - 0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69, 0x1e, 0x17, 0x0c, 0x05, - 0x3a, 0x33, 0x28, 0x21, 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70, - 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38, 0x41, 0x48, 0x53, 0x5a, - 0x65, 0x6c, 0x77, 0x7e, 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36, - 0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67, 0x10, 0x19, 0x02, 0x0b, - 0x34, 0x3d, 0x26, 0x2f, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, - 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04, 0x6a, 0x63, 0x78, 0x71, - 0x4e, 0x47, 0x5c, 0x55, 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d, - 0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a, 0x6d, 0x64, 0x7f, 0x76, - 0x49, 0x40, 0x5b, 0x52, 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03, - 0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b, 0x17, 0x1e, 0x05, 0x0c, - 0x33, 0x3a, 0x21, 0x28, 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60, - 0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31, 0x46, 0x4f, 0x54, 0x5d, - 0x62, 0x6b, 0x70, 0x79 -}; - /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ -/** - * @brief Calculate the MMC standard CRC-7 based on a lookup table. - * - * @param[in] crc start value for CRC - * @param[in] buffer pointer to data buffer - * @param[in] len length of data - * @return Calculated CRC - */ -static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { - - while (len--) - crc = crc7_lookup_table[(crc << 1) ^ (*buffer++)]; - return crc; -} - /** * @brief Inserion monitor timer callback function. * @@ -141,7 +98,7 @@ static void wait(MMCDriver *mmcp) { for (i = 0; i < 16; i++) { spiReceive(mmcp->spip, 1, buf); if (buf[0] == 0xFF) - break; + return; } /* Looks like it is a long wait.*/ while (TRUE) { @@ -175,9 +132,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[2] = arg >> 16; buf[3] = arg >> 8; buf[4] = arg; - /* Calculate CRC for command header, shift to right position, add stop bit.*/ - buf[5] = ((crc7(0, buf, 5) & 0x7F) << 1) | 0x01; - + buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ spiSend(mmcp->spip, 6, buf); } -- cgit v1.2.3 From cf5dfef7a8e220f8d4d85edba664c526995ef8f6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 12 Feb 2012 09:45:06 +0000 Subject: Optimization in write operations of the MMC_SPI driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3953 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 06f2594bf..079dcf3c0 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -665,10 +665,8 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { spiSend(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* Data. */ spiIgnore(mmcp->spip, 2); /* CRC ignored. */ spiReceive(mmcp->spip, 1, b); - if ((b[0] & 0x1F) == 0x05) { - wait(mmcp); + if ((b[0] & 0x1F) == 0x05) return FALSE; - } /* Error.*/ spiUnselect(mmcp->spip); @@ -701,6 +699,10 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { } chSysUnlock(); + /* Wait completion of the last write operation.*/ + wait(mmcp); + + /* Semd stop command.*/ spiSend(mmcp->spip, sizeof(stop), stop); spiUnselect(mmcp->spip); -- cgit v1.2.3 From 995e1f732e43a5b85e5961e9791977b0cada7c50 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 12 Feb 2012 10:05:10 +0000 Subject: Reintroduced CRC7 calculation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3954 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 079dcf3c0..c7b3372f2 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -48,10 +48,53 @@ /* Driver local variables. */ /*===========================================================================*/ +/** + * @brief Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1). + */ +static const uint8_t crc7_lookup_table[256] = { + 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, + 0x6c, 0x65, 0x7e, 0x77, 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26, + 0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e, 0x32, 0x3b, 0x20, 0x29, + 0x16, 0x1f, 0x04, 0x0d, 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45, + 0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14, 0x63, 0x6a, 0x71, 0x78, + 0x47, 0x4e, 0x55, 0x5c, 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b, + 0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13, 0x7d, 0x74, 0x6f, 0x66, + 0x59, 0x50, 0x4b, 0x42, 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a, + 0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69, 0x1e, 0x17, 0x0c, 0x05, + 0x3a, 0x33, 0x28, 0x21, 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70, + 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38, 0x41, 0x48, 0x53, 0x5a, + 0x65, 0x6c, 0x77, 0x7e, 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36, + 0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67, 0x10, 0x19, 0x02, 0x0b, + 0x34, 0x3d, 0x26, 0x2f, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, + 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04, 0x6a, 0x63, 0x78, 0x71, + 0x4e, 0x47, 0x5c, 0x55, 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d, + 0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a, 0x6d, 0x64, 0x7f, 0x76, + 0x49, 0x40, 0x5b, 0x52, 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03, + 0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b, 0x17, 0x1e, 0x05, 0x0c, + 0x33, 0x3a, 0x21, 0x28, 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60, + 0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31, 0x46, 0x4f, 0x54, 0x5d, + 0x62, 0x6b, 0x70, 0x79 +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Calculate the MMC standard CRC-7 based on a lookup table. + * + * @param[in] crc start value for CRC + * @param[in] buffer pointer to data buffer + * @param[in] len length of data + * @return Calculated CRC + */ +static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { + + while (len--) + crc = crc7_lookup_table[(crc << 1) ^ (*buffer++)]; + return crc; +} + /** * @brief Inserion monitor timer callback function. * @@ -132,7 +175,9 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { buf[2] = arg >> 16; buf[3] = arg >> 8; buf[4] = arg; - buf[5] = 0x95; /* Valid for CMD0 ignored by other commands. */ + /* Calculate CRC for command header, shift to right position, add stop bit.*/ + buf[5] = ((crc7(0, buf, 5) & 0x7F) << 1) | 0x01; + spiSend(mmcp->spip, 6, buf); } @@ -665,8 +710,10 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { spiSend(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* Data. */ spiIgnore(mmcp->spip, 2); /* CRC ignored. */ spiReceive(mmcp->spip, 1, b); - if ((b[0] & 0x1F) == 0x05) + if ((b[0] & 0x1F) == 0x05) { + wait(mmcp); return FALSE; + } /* Error.*/ spiUnselect(mmcp->spip); @@ -699,10 +746,6 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { } chSysUnlock(); - /* Wait completion of the last write operation.*/ - wait(mmcp); - - /* Semd stop command.*/ spiSend(mmcp->spip, sizeof(stop), stop); spiUnselect(mmcp->spip); -- cgit v1.2.3 From 690fd6364bd682ade14f27e86cb3821c84524d78 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 5 Mar 2012 16:44:56 +0000 Subject: SDC. Code merged to fresh branch. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4021 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 134 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 30 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index e8894a597..62f3cb45a 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -47,14 +47,50 @@ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Get slice with data from uint32_t[4] array. + * + * @notapi + */ +static uint32_t _sdc_get_slice(uint32_t *data, int8_t end, int8_t start) { + uint32_t word = 0; + uint32_t mask = 0; + + chDbgCheck(((start >=0) && (end >=0) && (end >= start)), "sdc_get_slice"); + + while ((start - 32 * word) > 31){ + word++; + data++; + } + + end -= 32 * word; + start -= 32 * word; + + if (end < 31){ + /* Value lays in one word.*/ + mask = (1 << (end - start + 1)) - 1; + return (*data >> start) & mask; + } + else{ + /* Value spread on separate words.*/ + uint32_t lsb, msb; + lsb = *data >> start; + data++; + mask = (1 << (end - 32 + 1)) - 1; + msb = *data & mask; + msb = msb << (32 - start); + return (msb | lsb); + } +} + /** * @brief Wait for the card to complete pending operations. * * @param[in] sdcp pointer to the @p SDCDriver object + * * @return The operation status. - * @retval FALSE the card is now in transfer state. - * @retval TRUE an error occurred while waiting or the card is in an - * unexpected state. + * @retval SDC_SUCCESS operation succeeded. + * @retval SDC_FAILED operation failed. * * @notapi */ @@ -65,10 +101,10 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS, sdcp->rca, resp) || SDC_R1_ERROR(resp[0])) - return TRUE; + return SDC_FAILED; switch (SDC_R1_STS(resp[0])) { case SDC_STS_TRAN: - return FALSE; + return SDC_SUCCESS; case SDC_STS_DATA: case SDC_STS_RCV: case SDC_STS_PRG: @@ -79,9 +115,11 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { default: /* The card should have been initialized so any other state is not valid and is reported as an error.*/ - return TRUE; + return SDC_FAILED; } } + /* If something going too wrong.*/ + return SDC_FAILED; } /*===========================================================================*/ @@ -110,7 +148,9 @@ void sdcInit(void) { void sdcObjectInit(SDCDriver *sdcp) { sdcp->state = SDC_STOP; + sdcp->errors = SDC_NO_ERROR; sdcp->config = NULL; + sdcp->capacity = 0; } /** @@ -162,10 +202,10 @@ void sdcStop(SDCDriver *sdcp) { * to perform read and write operations. * * @param[in] sdcp pointer to the @p SDCDriver object + * * @return The operation status. - * @retval FALSE operation succeeded, the driver is now - * in the @p SDC_ACTIVE state. - * @retval TRUE operation failed. + * @retval SDC_SUCCESS operation succeeded. + * @retval SDC_FAILED operation failed. * * @api */ @@ -282,24 +322,48 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BUS_WIDTH, 2, resp) || SDC_R1_ERROR(resp[0])) goto failed; + break; + } + + /* Determine capacity.*/ + switch (sdcp->csd[3] >> 30) { + uint32_t a; + uint8_t b, c; + case 0: + /* CSD version 1.0 */ + a = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_SLICE); + b = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_MULT_SLICE); + c = _sdc_get_slice(sdcp->csd, SDC_CSD_10_READ_BL_LEN_SLICE); + sdcp->capacity = ((a + 1) << (b + 2) << c) / 512; + break; + case 1: + /* CSD version 2.0 */ + a = _sdc_get_slice(sdcp->csd, SDC_CSD_20_C_SIZE_SLICE); + sdcp->capacity = 1024 * (a + 1); + break; } + if (sdcp->capacity == 0) + goto failed; + /* Initialization complete.*/ sdcp->state = SDC_ACTIVE; - return FALSE; + return SDC_SUCCESS; + + /* Initialization failed.*/ failed: sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return TRUE; + return SDC_FAILED; } /** * @brief Brings the driver in a state safe for card removal. * * @param[in] sdcp pointer to the @p SDCDriver object + * * @return The operation status. - * @retval FALSE the operation succeeded and the driver is now - * in the @p SDC_READY state. - * @retval TRUE the operation failed. + * @retval SDC_SUCCESS operation succeeded. + * @retval SDC_FAILED operation failed. * * @api */ @@ -312,20 +376,20 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { "sdcDisconnect(), #1", "invalid state"); if (sdcp->state == SDC_READY) { chSysUnlock(); - return FALSE; + return SDC_SUCCESS; } sdcp->state = SDC_DISCONNECTING; chSysUnlock(); /* Waits for eventual pending operations completion.*/ if (_sdc_wait_for_transfer_state(sdcp)) - return TRUE; + return SDC_FAILED; /* Card clock stopped.*/ sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return FALSE; + return SDC_SUCCESS; } /** @@ -337,27 +401,32 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @param[in] startblk first block to read * @param[out] buf pointer to the read buffer * @param[in] n number of blocks to read + * * @return The operation status. - * @retval FALSE operation succeeded, the requested blocks have been - * read. - * @retval TRUE operation failed, the state of the buffer is uncertain. + * @retval SDC_SUCCESS operation succeeded. + * @retval SDC_FAILED operation failed. * * @api */ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { - bool_t err; + bool_t status; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); + if ((startblk + n - 1) > sdcp->capacity){ + sdcp->errors |= SDC_OVERFLOW_ERROR; + return SDC_FAILED; + } + chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcRead(), #1", "invalid state"); sdcp->state = SDC_READING; chSysUnlock(); - err = sdc_lld_read(sdcp, startblk, buf, n); + status = sdc_lld_read(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; - return err; + return status; } /** @@ -369,27 +438,32 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @param[in] startblk first block to write * @param[out] buf pointer to the write buffer * @param[in] n number of blocks to write + * * @return The operation status. - * @retval FALSE operation succeeded, the requested blocks have been - * written. - * @retval TRUE operation failed. + * @retval SDC_SUCCESS operation succeeded. + * @retval SDC_FAILED operation failed. * * @api */ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n) { - bool_t err; + bool_t status; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcWrite"); + if ((startblk + n - 1) > sdcp->capacity){ + sdcp->errors |= SDC_OVERFLOW_ERROR; + return SDC_FAILED; + } + chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcWrite(), #1", "invalid state"); sdcp->state = SDC_WRITING; chSysUnlock(); - err = sdc_lld_write(sdcp, startblk, buf, n); + status = sdc_lld_write(sdcp, startblk, buf, n); sdcp->state = SDC_ACTIVE; - return err; + return status; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From 2b35b5a2a5a9484332edebaca861a87910cf6715 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Mar 2012 19:52:44 +0000 Subject: SDC. Added RTC support. Improved testhal. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4031 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 01f88e82d..a6601fd1c 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -101,6 +101,26 @@ void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { chSysUnlock(); } +/** + * @brief Get current time in format suitable for usage in FatFS. + * + * @param[in] rtcp pointer to RTC driver structure + * @return FAT time value. + * + * @api + */ +uint32_t rtcGetFatTime(RTCDriver *rtcp) { + RTCTime timespec; + + chDbgCheck((rtcp != NULL), "rtcGetTime"); + + chSysLock(); + rtcGetTimeI(rtcp, ×pec); + chSysUnlock(); + + return rtc_lld_calc_fat_time(×pec); +} + #if (RTC_ALARMS > 0) || defined(__DOXYGEN__) /** * @brief Set alarm time. -- cgit v1.2.3 From 3c311dfe589b6a6b1fd46af2e3138512fe2135fa Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 9 Mar 2012 18:33:26 +0000 Subject: RTC. High level staff moved to chrtclib. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4032 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index a6601fd1c..01f88e82d 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -101,26 +101,6 @@ void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { chSysUnlock(); } -/** - * @brief Get current time in format suitable for usage in FatFS. - * - * @param[in] rtcp pointer to RTC driver structure - * @return FAT time value. - * - * @api - */ -uint32_t rtcGetFatTime(RTCDriver *rtcp) { - RTCTime timespec; - - chDbgCheck((rtcp != NULL), "rtcGetTime"); - - chSysLock(); - rtcGetTimeI(rtcp, ×pec); - chSysUnlock(); - - return rtc_lld_calc_fat_time(×pec); -} - #if (RTC_ALARMS > 0) || defined(__DOXYGEN__) /** * @brief Set alarm time. -- cgit v1.2.3 From 82984e1b5543228cfc3bd8bb40aa69046bc613e8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 13 Mar 2012 15:41:46 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4038 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2s.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 os/hal/src/i2s.c (limited to 'os/hal/src') diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c new file mode 100644 index 000000000..4eecfffbf --- /dev/null +++ b/os/hal/src/i2s.c @@ -0,0 +1,194 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2s.c + * @brief I2S Driver code. + * + * @addtogroup I2S + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2S || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2S Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void i2sInit(void) { + + i2s_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2SDriver structure. + * + * @param[out] i2sp pointer to the @p I2SDriver object + * + * @init + */ +void i2sObjectInit(I2SDriver *i2sp) { + + i2sp->state = I2S_STOP; + i2sp->config = NULL; +} + +/** + * @brief Configures and activates the I2S peripheral. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * @param[in] config pointer to the @p I2SConfig object + * + * @api + */ +void i2sStart(I2SDriver *i2sp, const I2SConfig *config) { + + chDbgCheck((i2sp != NULL) && (config != NULL), "i2sStart"); + + chSysLock(); + chDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY), + "i2sStart(), #1", "invalid state"); + i2sp->config = config; + i2s_lld_start(i2sp); + i2sp->state = I2S_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2S peripheral. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @api + */ +void i2sStop(I2SDriver *i2sp) { + + chDbgCheck(i2sp != NULL, "i2sStop"); + + chSysLock(); + chDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY), + "i2sStop(), #1", "invalid state"); + i2s_lld_stop(i2sp); + i2sp->state = I2S_STOP; + chSysUnlock(); +} + +/** + * @brief Starts a I2S transmission. + * @details The transmission is started and it is executes until the specified + * buffer has entirely transmitted. + * @post A callback is invoked when the buffer has been fully transmitted. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * @param[in] n number of samples to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @api + */ +void i2sStartSendOnce(I2SDriver *i2sp, size_t n, + const i2ssample_t *txbuf) { + + chDbgCheck((i2sp != NULL) && (n > 0) && (txbuf != NULL), + "i2sStartSendOnce"); + + chSysLock(); + chDbgAssert(i2sp->state == I2S_READY, "i2sStartSendOnce(), #1", + "not ready"); + i2sStartSendOnceI(i2sp, n, txbuf); + chSysUnlock(); +} + +/** + * @brief Starts a continuous I2S transmission. + * @details The transmission is started and it is executes continuously + * until @p i2sStopSend() has been explicitly invoked . + * @post A callback is invoked when the buffer has been half transmitted + * and fully transmitted. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * @param[in] n number of samples to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @api + */ +void i2sStartSendContinuous(I2SDriver *i2sp, size_t n, + const i2ssample_t *txbuf) { + + chDbgCheck((i2sp != NULL) && (n > 0) && (txbuf != NULL), + "i2sStartSendContinuous"); + + chSysLock(); + chDbgAssert(i2sp->state == I2S_READY, "i2sStartSendContinuous(), #1", + "not ready"); + i2sStartSendContinuousI(i2sp, n, txbuf); + chSysUnlock(); +} + +/** + * @brief Stops the ongoing transmission. + * @details The ongoing transmission, if any, is stopped, if the driver + * was not transmitting the function does nothing. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @api + */ +void i2sStopSend(I2SDriver *i2sp) { + + chDbgCheck((i2sp != NULL), "i2sStopSend"); + + chSysLock(); + chDbgAssert((i2sp->state == I2S_READY) || + (i2sp->state == I2S_ACTIVE) || + (i2sp->state == I2S_COMPLETE), + "i2sStopSend(), #1", "not ready"); + i2sStopSendI(i2sp); + chSysUnlock(); +} + +#endif /* HAL_USE_I2S */ + +/** @} */ -- cgit v1.2.3 From 3534921f053bb9ea25413e8b10424ad06ff9b677 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Mar 2012 14:21:45 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4047 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2s.c | 58 ++++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c index 4eecfffbf..e0c547847 100644 --- a/os/hal/src/i2s.c +++ b/os/hal/src/i2s.c @@ -117,75 +117,41 @@ void i2sStop(I2SDriver *i2sp) { } /** - * @brief Starts a I2S transmission. - * @details The transmission is started and it is executes until the specified - * buffer has entirely transmitted. - * @post A callback is invoked when the buffer has been fully transmitted. + * @brief Starts a I2S data exchange. * * @param[in] i2sp pointer to the @p I2SDriver object - * @param[in] n number of samples to send - * @param[in] txbuf the pointer to the transmit buffer * * @api */ -void i2sStartSendOnce(I2SDriver *i2sp, size_t n, - const i2ssample_t *txbuf) { +void i2sStartExchange(I2SDriver *i2sp) { - chDbgCheck((i2sp != NULL) && (n > 0) && (txbuf != NULL), - "i2sStartSendOnce"); + chDbgCheck(i2sp != NULL "i2sStartExchange"); chSysLock(); - chDbgAssert(i2sp->state == I2S_READY, "i2sStartSendOnce(), #1", - "not ready"); - i2sStartSendOnceI(i2sp, n, txbuf); + chDbgAssert(i2sp->state == I2S_READY, "i2sStartExchange(), #1", "not ready"); + i2sStartExchangeI(i2sp); chSysUnlock(); } /** - * @brief Starts a continuous I2S transmission. - * @details The transmission is started and it is executes continuously - * until @p i2sStopSend() has been explicitly invoked . - * @post A callback is invoked when the buffer has been half transmitted - * and fully transmitted. + * @brief Stops the ongoing data exchange. + * @details The ongoing data exchange, if any, is stopped, if the driver + * was not active the function does nothing. * * @param[in] i2sp pointer to the @p I2SDriver object - * @param[in] n number of samples to send - * @param[in] txbuf the pointer to the transmit buffer * * @api */ -void i2sStartSendContinuous(I2SDriver *i2sp, size_t n, - const i2ssample_t *txbuf) { +void i2sStopExchange(I2SDriver *i2sp) { - chDbgCheck((i2sp != NULL) && (n > 0) && (txbuf != NULL), - "i2sStartSendContinuous"); - - chSysLock(); - chDbgAssert(i2sp->state == I2S_READY, "i2sStartSendContinuous(), #1", - "not ready"); - i2sStartSendContinuousI(i2sp, n, txbuf); - chSysUnlock(); -} - -/** - * @brief Stops the ongoing transmission. - * @details The ongoing transmission, if any, is stopped, if the driver - * was not transmitting the function does nothing. - * - * @param[in] i2sp pointer to the @p I2SDriver object - * - * @api - */ -void i2sStopSend(I2SDriver *i2sp) { - - chDbgCheck((i2sp != NULL), "i2sStopSend"); + chDbgCheck((i2sp != NULL), "i2sStopExchange"); chSysLock(); chDbgAssert((i2sp->state == I2S_READY) || (i2sp->state == I2S_ACTIVE) || (i2sp->state == I2S_COMPLETE), - "i2sStopSend(), #1", "not ready"); - i2sStopSendI(i2sp); + "i2sStopExchange(), #1", "not ready"); + i2sStopExchangeI(i2sp); chSysUnlock(); } -- cgit v1.2.3 From e5c320a0d1a00915f88b379f27e981b89a787e33 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 18 Mar 2012 20:30:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4050 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2s.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c index e0c547847..99e4246ad 100644 --- a/os/hal/src/i2s.c +++ b/os/hal/src/i2s.c @@ -128,11 +128,30 @@ void i2sStartExchange(I2SDriver *i2sp) { chDbgCheck(i2sp != NULL "i2sStartExchange"); chSysLock(); - chDbgAssert(i2sp->state == I2S_READY, "i2sStartExchange(), #1", "not ready"); + chDbgAssert(i2sp->state == I2S_READY, + "i2sStartExchange(), #1", "not ready"); i2sStartExchangeI(i2sp); chSysUnlock(); } +/** + * @brief Starts a I2S data exchange in continuous mode. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @api + */ +void i2sStartExchangeContinuous(I2SDriver *i2sp) { + + chDbgCheck(i2sp != NULL "i2sStartExchangeContinuous"); + + chSysLock(); + chDbgAssert(i2sp->state == I2S_READY, + "i2sStartExchangeContinuous(), #1", "not ready"); + i2sStartExchangeContinuousI(i2sp); + chSysUnlock(); +} + /** * @brief Stops the ongoing data exchange. * @details The ongoing data exchange, if any, is stopped, if the driver -- cgit v1.2.3 From f5a3976c393fffdc95627f27d4c49136fa9ec8ca Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 26 Mar 2012 09:13:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4055 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index c7b3372f2..c022e4a68 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -96,7 +96,7 @@ static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { } /** - * @brief Inserion monitor timer callback function. + * @brief Insertion monitor timer callback function. * * @param[in] p pointer to the @p MMCDriver object * -- cgit v1.2.3 From 04da61495794ed3e22381cdead5a8f1919b512a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 17:45:19 +0000 Subject: SDC. Fixed mixed usage of uint8_t and uint32_t. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4098 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 62f3cb45a..6cb6dbe06 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -327,8 +327,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* Determine capacity.*/ switch (sdcp->csd[3] >> 30) { - uint32_t a; - uint8_t b, c; + uint32_t a, b, c; case 0: /* CSD version 1.0 */ a = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_SLICE); -- cgit v1.2.3 From 973d8da5eabeead58445937e5be4c740ffaf2c56 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 18:19:34 +0000 Subject: SDC. Added function sdcGetAndClearErrors. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4099 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 6cb6dbe06..10baa38e8 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -465,6 +465,21 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, return status; } +/** + * @brief Returns the errors mask associated to the previous operation. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @return The errors mask. + * + * @api + */ +sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { + + chDbgCheck(sdcp != NULL, "sdcGetAndClearErrors"); + + return sdc_lld_get_and_clear_errors(sdcp); +} + #endif /* HAL_USE_SDC */ /** @} */ -- cgit v1.2.3 From 6206a3c5a5a019bffd2db6fe6e9b3e7aca535fa7 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 19:18:14 +0000 Subject: SDC. sdcGetAndClearErrors() now reside in HL driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4100 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 10baa38e8..6fd4e211d 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -477,7 +477,9 @@ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcGetAndClearErrors"); - return sdc_lld_get_and_clear_errors(sdcp); + sdcflags_t flags = sdcp->errors; + sdcp->errors = SDC_NO_ERROR; + return flags; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From f41de7bb8b526fa9ad16120ed5b6a6505a132c92 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 19:20:30 +0000 Subject: SDC. One more uint8_t, uint32_t mixture fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4101 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 6fd4e211d..c2e6c1b74 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -52,7 +52,7 @@ * * @notapi */ -static uint32_t _sdc_get_slice(uint32_t *data, int8_t end, int8_t start) { +static uint32_t _sdc_get_slice(uint32_t *data, int32_t end, int32_t start) { uint32_t word = 0; uint32_t mask = 0; -- cgit v1.2.3 From 671cb8ab9dbbfaf9832f7529fc8966a5d042b6f4 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 20:12:16 +0000 Subject: SDC. Reverted from SDC_SUCCESS/SDC_FAILED to boolean values. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4103 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index c2e6c1b74..d883eac39 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -89,8 +89,8 @@ static uint32_t _sdc_get_slice(uint32_t *data, int32_t end, int32_t start) { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval SDC_SUCCESS operation succeeded. - * @retval SDC_FAILED operation failed. + * @retval FALSE operation succeeded. + * @retval TRUE operation failed. * * @notapi */ @@ -101,10 +101,10 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS, sdcp->rca, resp) || SDC_R1_ERROR(resp[0])) - return SDC_FAILED; + return TRUE; switch (SDC_R1_STS(resp[0])) { case SDC_STS_TRAN: - return SDC_SUCCESS; + return FALSE; case SDC_STS_DATA: case SDC_STS_RCV: case SDC_STS_PRG: @@ -115,11 +115,11 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { default: /* The card should have been initialized so any other state is not valid and is reported as an error.*/ - return SDC_FAILED; + return TRUE; } } /* If something going too wrong.*/ - return SDC_FAILED; + return TRUE; } /*===========================================================================*/ @@ -204,8 +204,8 @@ void sdcStop(SDCDriver *sdcp) { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval SDC_SUCCESS operation succeeded. - * @retval SDC_FAILED operation failed. + * @retval FALSE operation succeeded. + * @retval TRUE operation failed. * * @api */ @@ -346,13 +346,13 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* Initialization complete.*/ sdcp->state = SDC_ACTIVE; - return SDC_SUCCESS; + return FALSE; /* Initialization failed.*/ failed: sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return SDC_FAILED; + return TRUE; } /** @@ -361,8 +361,8 @@ failed: * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval SDC_SUCCESS operation succeeded. - * @retval SDC_FAILED operation failed. + * @retval FALSE operation succeeded. + * @retval TRUE operation failed. * * @api */ @@ -375,20 +375,20 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { "sdcDisconnect(), #1", "invalid state"); if (sdcp->state == SDC_READY) { chSysUnlock(); - return SDC_SUCCESS; + return FALSE; } sdcp->state = SDC_DISCONNECTING; chSysUnlock(); /* Waits for eventual pending operations completion.*/ if (_sdc_wait_for_transfer_state(sdcp)) - return SDC_FAILED; + return TRUE; /* Card clock stopped.*/ sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return SDC_SUCCESS; + return FALSE; } /** @@ -402,8 +402,8 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @param[in] n number of blocks to read * * @return The operation status. - * @retval SDC_SUCCESS operation succeeded. - * @retval SDC_FAILED operation failed. + * @retval FALSE operation succeeded. + * @retval TRUE operation failed. * * @api */ @@ -415,7 +415,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; - return SDC_FAILED; + return TRUE; } chSysLock(); @@ -439,8 +439,8 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @param[in] n number of blocks to write * * @return The operation status. - * @retval SDC_SUCCESS operation succeeded. - * @retval SDC_FAILED operation failed. + * @retval FALSE operation succeeded. + * @retval TRUE operation failed. * * @api */ @@ -452,7 +452,7 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; - return SDC_FAILED; + return TRUE; } chSysLock(); -- cgit v1.2.3 From 469211b330aaa187de511a8e3963feac1db51053 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 16 Apr 2012 20:14:08 +0000 Subject: SDC. Safety improvements in capacity detection code. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4104 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index d883eac39..96c1b4561 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -340,6 +340,10 @@ bool_t sdcConnect(SDCDriver *sdcp) { a = _sdc_get_slice(sdcp->csd, SDC_CSD_20_C_SIZE_SLICE); sdcp->capacity = 1024 * (a + 1); break; + default: + /* Reserved value detected. */ + sdcp->capacity = 0; + break; } if (sdcp->capacity == 0) goto failed; -- cgit v1.2.3 From 29fb7d1e9da06e21764e8cd89e2720c4b510d65a Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 17 Apr 2012 18:30:45 +0000 Subject: SDC. Added global macros CH_SUCCESS/CH_FAILED in ch.h. SDC driver changed respectively. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4107 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 96c1b4561..c46589bae 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -101,10 +101,10 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS, sdcp->rca, resp) || SDC_R1_ERROR(resp[0])) - return TRUE; + return CH_FAILED; switch (SDC_R1_STS(resp[0])) { case SDC_STS_TRAN: - return FALSE; + return CH_SUCCESS; case SDC_STS_DATA: case SDC_STS_RCV: case SDC_STS_PRG: @@ -115,11 +115,11 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { default: /* The card should have been initialized so any other state is not valid and is reported as an error.*/ - return TRUE; + return CH_FAILED; } } /* If something going too wrong.*/ - return TRUE; + return CH_FAILED; } /*===========================================================================*/ @@ -251,7 +251,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { #if SDC_MMC_SUPPORT if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { /* TODO: MMC initialization.*/ - return TRUE; + return CH_FAILED; } else #endif /* SDC_MMC_SUPPORT */ @@ -350,13 +350,13 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* Initialization complete.*/ sdcp->state = SDC_ACTIVE; - return FALSE; + return CH_SUCCESS; /* Initialization failed.*/ failed: sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return TRUE; + return CH_FAILED; } /** @@ -379,20 +379,20 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { "sdcDisconnect(), #1", "invalid state"); if (sdcp->state == SDC_READY) { chSysUnlock(); - return FALSE; + return CH_SUCCESS; } sdcp->state = SDC_DISCONNECTING; chSysUnlock(); /* Waits for eventual pending operations completion.*/ if (_sdc_wait_for_transfer_state(sdcp)) - return TRUE; + return CH_FAILED; /* Card clock stopped.*/ sdc_lld_stop_clk(sdcp); sdcp->state = SDC_READY; - return FALSE; + return CH_SUCCESS; } /** @@ -419,7 +419,7 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; - return TRUE; + return CH_FAILED; } chSysLock(); @@ -456,7 +456,7 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; - return TRUE; + return CH_FAILED; } chSysLock(); -- cgit v1.2.3 From 538f51c0dd53a758a317d8bc0484a4a169369982 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Apr 2012 19:34:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4109 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index c46589bae..3d0d495bb 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From e817b7032d9610508e39921c65cda6ba108db357 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 23 Apr 2012 17:43:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4128 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index e89962dea..bd175d483 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -120,6 +120,7 @@ void extStop(EXTDriver *extp) { /** * @brief Enables 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 enabled @@ -128,13 +129,13 @@ void extStop(EXTDriver *extp) { */ void extChannelEnable(EXTDriver *extp, expchannel_t channel) { - chDbgCheck((extp != NULL) && - (channel < EXT_MAX_CHANNELS) && - (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + chDbgCheck((extp != NULL) && (channel < EXT_MAX_CHANNELS), "extChannelEnable"); chSysLock(); - chDbgAssert(extp->state == EXT_ACTIVE, + chDbgAssert((extp->state == EXT_ACTIVE) && + ((extp->config->channels[channel].mode & + EXT_CH_MODE_EDGES_MASK) != EXT_CH_MODE_DISABLED), "extChannelEnable(), #1", "invalid state"); extChannelEnableI(extp, channel); chSysUnlock(); @@ -142,6 +143,7 @@ void extChannelEnable(EXTDriver *extp, expchannel_t channel) { /** * @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 @@ -150,18 +152,59 @@ void extChannelEnable(EXTDriver *extp, expchannel_t channel) { */ void extChannelDisable(EXTDriver *extp, expchannel_t channel) { - chDbgCheck((extp != NULL) && - (channel < EXT_MAX_CHANNELS) && - (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + chDbgCheck((extp != NULL) && (channel < EXT_MAX_CHANNELS), "extChannelDisable"); chSysLock(); - chDbgAssert(extp->state == EXT_ACTIVE, + chDbgAssert((extp->state == EXT_ACTIVE) && + ((extp->config->channels[channel].mode & + EXT_CH_MODE_EDGES_MASK) != EXT_CH_MODE_DISABLED), "extChannelDisable(), #1", "invalid state"); extChannelDisableI(extp, channel); chSysUnlock(); } +/** + * @brief Changes the operation mode of a channel. + * @note This function attempts to write over the current configuration + * structure that must have been not declared constant. This + * violates the @p const qualifier in @p extStart() but it is + * intentional. + * @note This function cannot be used if the configuration structure is + * declared @p const. + * @note The effect of this function on constant configuration structures + * is not defined. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be changed + * @param[in] extcp new configuration for the channel + * + * @iclass + */ +void extSetChannelModeI(EXTDriver *extp, + expchannel_t channel, + const EXTChannelConfig *extcp) { + EXTChannelConfig *oldcp; + + chDbgCheck((extp != NULL) && (channel < EXT_MAX_CHANNELS) && + (extcp != NULL), "extSetChannelModeI"); + + /* Note that here the access is enforced as non-const, known access + violation.*/ + oldcp = (EXTChannelConfig *)&extp->config->channels[channel]; + + chSysLock(); + + chDbgAssert(extp->state == EXT_ACTIVE, + "extSetChannelModeI(), #1", "invalid state"); + + /* Overwiting the old channels configuration then the channel is reconfigured + by the low level driver.*/ + *oldcp = *extcp; + ext_lld_channel_enable(extp, channel); + chSysUnlock(); +} + #endif /* HAL_USE_EXT */ /** @} */ -- cgit v1.2.3 From 010f8f1b07257938b44d032930919a061a03dbd0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 23 Apr 2012 20:53:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4132 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index bd175d483..c53cd95fe 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -189,20 +189,17 @@ void extSetChannelModeI(EXTDriver *extp, chDbgCheck((extp != NULL) && (channel < EXT_MAX_CHANNELS) && (extcp != NULL), "extSetChannelModeI"); + chDbgAssert(extp->state == EXT_ACTIVE, + "extSetChannelModeI(), #1", "invalid state"); + /* Note that here the access is enforced as non-const, known access violation.*/ oldcp = (EXTChannelConfig *)&extp->config->channels[channel]; - chSysLock(); - - chDbgAssert(extp->state == EXT_ACTIVE, - "extSetChannelModeI(), #1", "invalid state"); - /* Overwiting the old channels configuration then the channel is reconfigured by the low level driver.*/ *oldcp = *extcp; ext_lld_channel_enable(extp, channel); - chSysUnlock(); } #endif /* HAL_USE_EXT */ -- cgit v1.2.3 From 8ed6a8d9e3b4613a0d586d409f4c5706f21b5857 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 1 May 2012 16:53:58 +0000 Subject: Fixed bug 3522808, fixed problem with STM32 MAC driver checksum offload. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4156 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 5ffb42b8d..553613438 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -153,7 +153,7 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, chDbgAssert(macp->state == MAC_ACTIVE, "macWaitTransmitDescriptor(), #1", "not active"); - while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && + while (((msg = mac_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && (time > 0)) { chSysLock(); systime_t now = chTimeNow(); @@ -211,7 +211,7 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, chDbgAssert(macp->state == MAC_ACTIVE, "macWaitReceiveDescriptor(), #1", "not active"); - while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && + while (((msg = mac_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && (time > 0)) { chSysLock(); systime_t now = chTimeNow(); -- cgit v1.2.3 From 6ee956d7b6cf775fd85c51347b75e39daa412d38 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 7 May 2012 18:43:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4171 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 3d0d495bb..6e9dcabd4 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -204,8 +204,8 @@ void sdcStop(SDCDriver *sdcp) { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval FALSE operation succeeded. - * @retval TRUE operation failed. + * @retval CH_FAILED operation succeeded. + * @retval CH_SUCCESS operation failed. * * @api */ @@ -365,8 +365,8 @@ failed: * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval FALSE operation succeeded. - * @retval TRUE operation failed. + * @retval CH_FAILED operation succeeded. + * @retval CH_SUCCESS operation failed. * * @api */ @@ -406,8 +406,8 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @param[in] n number of blocks to read * * @return The operation status. - * @retval FALSE operation succeeded. - * @retval TRUE operation failed. + * @retval CH_FAILED operation succeeded. + * @retval CH_SUCCESS operation failed. * * @api */ @@ -443,8 +443,8 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @param[in] n number of blocks to write * * @return The operation status. - * @retval FALSE operation succeeded. - * @retval TRUE operation failed. + * @retval CH_FAILED operation succeeded. + * @retval CH_SUCCESS operation failed. * * @api */ -- cgit v1.2.3 From d0a2e55ed0cf97be924ebbdae2497fd77bfac5b6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 May 2012 17:09:20 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4175 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 12 ++++++------ os/hal/src/serial_usb.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index d0ea89297..aaeb5e6ee 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -94,8 +94,8 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); } -static ioflags_t getflags(void *ip) { - _ch_get_and_clear_flags_impl(ip); +static chnflags_t getflags(void *ip) { + _chn_get_and_clear_flags_impl(ip); } static const struct SerialDriverVMT vmt = { @@ -139,7 +139,7 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; chEvtInit(&sdp->event); - sdp->flags = IO_NO_ERROR; + sdp->flags = CHN_NO_ERROR; sdp->state = SD_STOP; chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify); chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify); @@ -215,9 +215,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) { chDbgCheck(sdp != NULL, "sdIncomingDataI"); if (chIQIsEmptyI(&sdp->iqueue)) - chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE); + chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE); if (chIQPutI(&sdp->iqueue, b) < Q_OK) - chIOAddFlagsI(sdp, SD_OVERRUN_ERROR); + chnAddFlagsI(sdp, SD_OVERRUN_ERROR); } /** @@ -243,7 +243,7 @@ msg_t sdRequestDataI(SerialDriver *sdp) { b = chOQGetI(&sdp->oqueue); if (b < Q_OK) - chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY); + chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY); return b; } diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index f007e7bdd..52c57c800 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -103,7 +103,7 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time); } -static ioflags_t getflags(void *ip) { +static chnflags_t getflags(void *ip) { _ch_get_and_clear_flags_impl(ip); } @@ -133,7 +133,7 @@ static void inotify(GenericQueue *qp) { chSysLock(); usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; sdup->iqueue.q_counter = n; while (notempty(&sdup->iqueue.q_waiting)) @@ -160,7 +160,7 @@ static void onotify(GenericQueue *qp) { chSysLock(); usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); - chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); while (notempty(&sdup->oqueue.q_waiting)) @@ -195,7 +195,7 @@ void sduObjectInit(SerialUSBDriver *sdup) { sdup->vmt = &vmt; chEvtInit(&sdup->event); - sdup->flags = IO_NO_ERROR; + sdup->flags = CHN_NO_ERROR; sdup->state = SDU_STOP; chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify); chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify); @@ -312,7 +312,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { chSysLockFromIsr(); usbStartTransmitI(usbp, ep); - chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); while (notempty(&sdup->oqueue.q_waiting)) @@ -348,7 +348,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { chSysLockFromIsr(); usbStartReceiveI(usbp, ep); - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; sdup->iqueue.q_counter = n; while (notempty(&sdup->iqueue.q_waiting)) -- cgit v1.2.3 From 7f87eee586adf22f28b1687ef92051065a0a5ee5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 May 2012 17:00:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4178 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 180 ++++++++++++++++++++++++++++++++++++++++++++------- os/hal/src/sdc.c | 72 +++++++++++++++++++++ 2 files changed, 228 insertions(+), 24 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index c022e4a68..4fdec3f12 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -48,6 +48,28 @@ /* Driver local variables. */ /*===========================================================================*/ +/* Forward declarations required by mmc_vmt.*/ +bool_t mmc_is_inserted(void *instance); +bool_t mmc_is_protected(void *instance); +bool_t mmc_read(void *instance, uint32_t startblk, + uint8_t *buffer, uint32_t n); +bool_t mmc_write(void *instance, uint32_t startblk, + const uint8_t *buffer, uint32_t n); + +/** + * @brief Virtual methods table. + */ +static const struct MMCSDBlockDeviceVMT mmc_vmt = { + mmc_is_inserted, + mmc_is_protected, + (bool_t (*)(void *))mmcConnect, + (bool_t (*)(void *))mmcDisconnect, + mmc_read, + mmc_write, + (bool_t (*)(void *))mmcSync, + (bool_t (*)(void *, BlockDeviceInfo *))mmcGetInfo +}; + /** * @brief Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1). */ @@ -80,6 +102,48 @@ static const uint8_t crc7_lookup_table[256] = { /* Driver local functions. */ /*===========================================================================*/ +bool_t mmc_is_inserted(void *instance) { + + return ((MMCDriver *)instance)->is_inserted(); +} + +bool_t mmc_is_protected(void *instance) { + + return ((MMCDriver *)instance)->is_protected(); +} + +bool_t mmc_read(void *instance, uint32_t startblk, + uint8_t *buffer, uint32_t n) { + + if (mmcStartSequentialRead((MMCDriver *)instance, startblk)) + return TRUE; + while (n > 0) { + if (mmcSequentialRead((MMCDriver *)instance, buffer)) + return TRUE; + buffer += SDMMC_BLOCK_SIZE; + n--; + } + if (mmcStopSequentialRead((MMCDriver *)instance)) + return TRUE; + return FALSE; +} + +bool_t mmc_write(void *instance, uint32_t startblk, + const uint8_t *buffer, uint32_t n) { + + if (mmcStartSequentialWrite((MMCDriver *)instance, startblk)) + return TRUE; + while (n > 0) { + if (mmcSequentialWrite((MMCDriver *)instance, buffer)) + return TRUE; + buffer += SDMMC_BLOCK_SIZE; + n--; + } + if (mmcStopSequentialWrite((MMCDriver *)instance)) + return TRUE; + return FALSE; +} + /** * @brief Calculate the MMC standard CRC-7 based on a lookup table. * @@ -321,6 +385,7 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, const SPIConfig *lscfg, const SPIConfig *hscfg, mmcquery_t is_protected, mmcquery_t is_inserted) { + mmcp->vmt = &mmc_vmt; mmcp->state = MMC_STOP; mmcp->config = NULL; mmcp->spip = spip; @@ -387,6 +452,7 @@ void mmcStop(MMCDriver *mmcp) { * handler. * * @param[in] mmcp pointer to the @p MMCDriver object + * * @return The operation status. * @retval FALSE the operation succeeded and the driver is now * in the @p MMC_READY state. @@ -411,7 +477,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* SPI mode selection.*/ i = 0; while (TRUE) { - if (send_command_R1(mmcp, MMC_CMDGOIDLE, 0) == 0x01) + if (send_command_R1(mmcp, SDMMC_CMD_GO_IDLE_STATE, 0) == 0x01) break; if (++i >= MMC_CMD0_RETRY) return TRUE; @@ -419,20 +485,19 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /* Try to detect if this is a high capacity card and switch to block - * addresses if possible. - * - * This method is based on "How to support SDC Ver2 and high capacity cards" - * by ElmChan. - * - * */ + addresses if possible. + This method is based on "How to support SDC Ver2 and high capacity cards" + by ElmChan.*/ uint8_t r3[4]; - if(send_command_R3(mmcp, MMC_CMDINTERFACE_CONDITION, 0x01AA, r3) != 0x05){ + if (send_command_R3(mmcp, SDMMC_CMD_SEND_IF_COND, + SDMMC_CMD8_PATTERN, r3) != 0x05) { - /* Switch to SDHC mode */ + /* Switch to SDHC mode.*/ i = 0; while (TRUE) { - if ((send_command_R1(mmcp, MMC_CMDAPP, 0) == 0x01) && - (send_command_R3(mmcp, MMC_ACMDOPCONDITION, 0x400001aa, r3) == 0x00)) + if ((send_command_R1(mmcp, SDMMC_CMD_APP_CMD, 0) == 0x01) && + (send_command_R3(mmcp, SDMMC_CMD_APP_OP_COND, + 0x400001aa, r3) == 0x00)) break; if (++i >= MMC_ACMD41_RETRY) @@ -441,17 +506,17 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /* Execute dedicated read on OCR register */ - send_command_R3(mmcp, MMC_CMDREADOCR, 0, r3); + send_command_R3(mmcp, SDMMC_CMD_READ_OCR, 0, r3); - /* Check if CCS is set in response. Card operates in block mode if set */ + /* Check if CCS is set in response. Card operates in block mode if set.*/ if(r3[0] & 0x40) mmcp->block_addresses = TRUE; } - /* Initialization. */ + /* Initialization.*/ i = 0; while (TRUE) { - uint8_t b = send_command_R1(mmcp, MMC_CMDINIT, 0); + uint8_t b = send_command_R1(mmcp, SDMMC_CMD_INIT, 0); if (b == 0x00) break; if (b != 0x01) @@ -461,11 +526,12 @@ bool_t mmcConnect(MMCDriver *mmcp) { chThdSleepMilliseconds(10); } - /* Initialization complete, full speed. */ + /* Initialization complete, full speed.*/ spiStart(mmcp->spip, mmcp->hscfg); /* Setting block size.*/ - if (send_command_R1(mmcp, MMC_CMDSETBLOCKLEN, MMC_SECTOR_SIZE) != 0x00) + if (send_command_R1(mmcp, SDMMC_CMD_SET_BLOCKLEN, + SDMMC_BLOCK_SIZE) != 0x00) return TRUE; /* Transition to MMC_READY state (if not extracted).*/ @@ -490,6 +556,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { * * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. + * * @retval FALSE the operation succeeded and the driver is now * in the @p MMC_INSERTED state. * @retval TRUE the operation failed. @@ -525,6 +592,7 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { * * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] startblk first block to read + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -547,9 +615,9 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { spiSelect(mmcp->spip); if(mmcp->block_addresses) - send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk); + send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk); else - send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_SECTOR_SIZE); + send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk * SDMMC_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->spip); @@ -567,6 +635,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { * * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the read buffer + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -588,7 +657,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { for (i = 0; i < MMC_WAIT_DATA; i++) { spiReceive(mmcp->spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceive(mmcp->spip, MMC_SECTOR_SIZE, buffer); + spiReceive(mmcp->spip, SDMMC_BLOCK_SIZE, buffer); /* CRC ignored. */ spiIgnore(mmcp->spip, 2); return FALSE; @@ -607,6 +676,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * @brief Stops a sequential read gracefully. * * @param[in] mmcp pointer to the @p MMCDriver object + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -614,7 +684,8 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * @api */ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { - static const uint8_t stopcmd[] = {0x40 | MMC_CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; + static const uint8_t stopcmd[] = {0x40 | SDMMC_CMD_STOP_TRANSMISSION, + 0, 0, 0, 0, 1, 0xFF}; bool_t result; chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); @@ -645,6 +716,7 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { * * @param[in] mmcp pointer to the @p MMCDriver object * @param[in] startblk first block to write + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -666,9 +738,10 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { spiStart(mmcp->spip, mmcp->hscfg); spiSelect(mmcp->spip); if(mmcp->block_addresses) - send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk); + send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK, startblk); else - send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_SECTOR_SIZE); + send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK, + startblk * SDMMC_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { @@ -687,6 +760,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { * * @param[in] mmcp pointer to the @p MMCDriver object * @param[out] buffer pointer to the write buffer + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -707,7 +781,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { chSysUnlock(); spiSend(mmcp->spip, sizeof(start), start); /* Data prologue. */ - spiSend(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* Data. */ + spiSend(mmcp->spip, SDMMC_BLOCK_SIZE, buffer); /* Data. */ spiIgnore(mmcp->spip, 2); /* CRC ignored. */ spiReceive(mmcp->spip, 1, b); if ((b[0] & 0x1F) == 0x05) { @@ -728,6 +802,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { * @brief Stops a sequential write gracefully. * * @param[in] mmcp pointer to the @p MMCDriver object + * * @return The operation status. * @retval FALSE the operation succeeded. * @retval TRUE the operation failed. @@ -759,6 +834,63 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { return TRUE; } +/** + * @brief Waits for card idle condition. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t mmcSync(MMCDriver *mmcp) { + + chDbgCheck(mmcp != NULL, "mmcSync"); + + chSysLock(); + if (mmcp->state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + sync(mmcp); + + return FALSE; +} + +/** + * @brief Returns the media info. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] bdip pointer to a @p BlockDeviceInfo structure + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { + + + chDbgCheck((mmcp != NULL) && (bdip != NULL), "mmcGetInfo"); + + chSysLock(); + if (mmcp->state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + bdip->blk_num = 0; /* NOTE: To be implemented.*/ + bdip->blk_size = SDMMC_BLOCK_SIZE; + + return FALSE; +} + #endif /* HAL_USE_MMC_SPI */ /** @} */ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 6e9dcabd4..483263776 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -43,6 +43,20 @@ /* Driver local variables. */ /*===========================================================================*/ +/** + * @brief Virtual methods table. + */ +static const struct MMCSDBlockDeviceVMT sdc_vmt = { + (bool_t (*)(void *))sdc_lld_is_card_inserted, + (bool_t (*)(void *))sdc_lld_is_write_protected, + (bool_t (*)(void *))sdcConnect, + (bool_t (*)(void *))sdcDisconnect, + (bool_t (*)(void *, uint32_t, uint8_t *, uint32_t))sdcRead, + (bool_t (*)(void *, uint32_t, const uint8_t *, uint32_t))sdcWrite, + (bool_t (*)(void *))sdcSync, + (bool_t (*)(void *, BlockDeviceInfo *))sdcGetInfo +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ @@ -147,6 +161,7 @@ void sdcInit(void) { */ void sdcObjectInit(SDCDriver *sdcp) { + sdcp->vmt = &sdc_vmt; sdcp->state = SDC_STOP; sdcp->errors = SDC_NO_ERROR; sdcp->config = NULL; @@ -486,6 +501,63 @@ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { return flags; } +/** + * @brief Waits for card idle condition. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t sdcSync(SDCDriver *sdcp) { + + chDbgCheck(sdcp != NULL, "sdcSync"); + + chSysLock(); + if (sdcp->state != SDC_READY) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + /* TODO: implement.*/ + + return FALSE; +} + +/** + * @brief Returns the media info. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[out] bdip pointer to a @p BlockDeviceInfo structure + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { + + + chDbgCheck((sdcp != NULL) && (bdip != NULL), "sdcGetInfo"); + + chSysLock(); + if (sdcp->state != SDC_READY) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + bdip->blk_num = 0; /* NOTE: To be implemented.*/ + bdip->blk_size = SDMMC_BLOCK_SIZE; + + return FALSE; +} + #endif /* HAL_USE_SDC */ /** @} */ -- cgit v1.2.3 From 6a8a643ab00e5964a3fb77e5b2394561bb797e55 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 May 2012 18:44:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 4fdec3f12..97f4f271d 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -49,8 +49,6 @@ /*===========================================================================*/ /* Forward declarations required by mmc_vmt.*/ -bool_t mmc_is_inserted(void *instance); -bool_t mmc_is_protected(void *instance); bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n); bool_t mmc_write(void *instance, uint32_t startblk, @@ -60,8 +58,8 @@ bool_t mmc_write(void *instance, uint32_t startblk, * @brief Virtual methods table. */ static const struct MMCSDBlockDeviceVMT mmc_vmt = { - mmc_is_inserted, - mmc_is_protected, + (bool_t (*)(void *))mmc_lld_is_card_inserted, + (bool_t (*)(void *))mmc_lld_is_write_protected, (bool_t (*)(void *))mmcConnect, (bool_t (*)(void *))mmcDisconnect, mmc_read, @@ -102,16 +100,6 @@ static const uint8_t crc7_lookup_table[256] = { /* Driver local functions. */ /*===========================================================================*/ -bool_t mmc_is_inserted(void *instance) { - - return ((MMCDriver *)instance)->is_inserted(); -} - -bool_t mmc_is_protected(void *instance) { - - return ((MMCDriver *)instance)->is_protected(); -} - bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n) { @@ -171,7 +159,7 @@ static void tmrfunc(void *p) { chSysLockFromIsr(); if (mmcp->cnt > 0) { - if (mmcp->is_inserted()) { + if (mmc_lld_is_card_inserted(mmcp)) { if (--mmcp->cnt == 0) { mmcp->state = MMC_INSERTED; chEvtBroadcastI(&mmcp->inserted_event); @@ -181,7 +169,7 @@ static void tmrfunc(void *p) { mmcp->cnt = MMC_POLLING_INTERVAL; } else { - if (!mmcp->is_inserted()) { + if (!mmc_lld_is_card_inserted(mmcp)) { mmcp->state = MMC_WAIT; mmcp->cnt = MMC_POLLING_INTERVAL; chEvtBroadcastI(&mmcp->removed_event); @@ -382,8 +370,7 @@ void mmcInit(void) { * @init */ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, - const SPIConfig *lscfg, const SPIConfig *hscfg, - mmcquery_t is_protected, mmcquery_t is_inserted) { + const SPIConfig *lscfg, const SPIConfig *hscfg) { mmcp->vmt = &mmc_vmt; mmcp->state = MMC_STOP; @@ -391,8 +378,6 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, 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); -- cgit v1.2.3 From 97dce7b94464b891a25170e6556daac5bb30f7ef Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 May 2012 12:26:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4180 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 114 +++++++++++++++++++++++------------------------- os/hal/src/mmcsd.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/sdc.c | 113 +++++++++++++----------------------------------- 3 files changed, 205 insertions(+), 142 deletions(-) create mode 100644 os/hal/src/mmcsd.c (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 97f4f271d..dad837613 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -108,7 +108,7 @@ bool_t mmc_read(void *instance, uint32_t startblk, while (n > 0) { if (mmcSequentialRead((MMCDriver *)instance, buffer)) return TRUE; - buffer += SDMMC_BLOCK_SIZE; + buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialRead((MMCDriver *)instance)) @@ -124,7 +124,7 @@ bool_t mmc_write(void *instance, uint32_t startblk, while (n > 0) { if (mmcSequentialWrite((MMCDriver *)instance, buffer)) return TRUE; - buffer += SDMMC_BLOCK_SIZE; + buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialWrite((MMCDriver *)instance)) @@ -191,13 +191,13 @@ static void wait(MMCDriver *mmcp) { uint8_t buf[4]; for (i = 0; i < 16; i++) { - spiReceive(mmcp->spip, 1, buf); + spiReceive(mmcp->config->spip, 1, buf); if (buf[0] == 0xFF) return; } /* Looks like it is a long wait.*/ while (TRUE) { - spiReceive(mmcp->spip, 1, buf); + spiReceive(mmcp->config->spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING @@ -230,7 +230,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { /* Calculate CRC for command header, shift to right position, add stop bit.*/ buf[5] = ((crc7(0, buf, 5) & 0x7F) << 1) | 0x01; - spiSend(mmcp->spip, 6, buf); + spiSend(mmcp->config->spip, 6, buf); } /** @@ -247,7 +247,7 @@ static uint8_t recvr1(MMCDriver *mmcp) { uint8_t r1[1]; for (i = 0; i < 9; i++) { - spiReceive(mmcp->spip, 1, r1); + spiReceive(mmcp->config->spip, 1, r1); if (r1[0] != 0xFF) return r1[0]; } @@ -268,7 +268,7 @@ static uint8_t recvr3(MMCDriver *mmcp, uint8_t* buffer) { uint8_t r1; r1 = recvr1(mmcp); - spiReceive(mmcp->spip, 4, buffer); + spiReceive(mmcp->config->spip, 4, buffer); return r1; } @@ -287,10 +287,10 @@ static uint8_t recvr3(MMCDriver *mmcp, uint8_t* buffer) { static uint8_t send_command_R1(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { uint8_t r1; - spiSelect(mmcp->spip); + spiSelect(mmcp->config->spip); send_hdr(mmcp, cmd, arg); r1 = recvr1(mmcp); - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); return r1; } @@ -311,10 +311,10 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, uint8_t *response) { uint8_t r1; - spiSelect(mmcp->spip); + spiSelect(mmcp->config->spip); send_hdr(mmcp, cmd, arg); r1 = recvr3(mmcp, response); - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); return r1; } @@ -328,16 +328,16 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, static void sync(MMCDriver *mmcp) { uint8_t buf[1]; - spiSelect(mmcp->spip); + spiSelect(mmcp->config->spip); while (TRUE) { - spiReceive(mmcp->spip, 1, buf); + spiReceive(mmcp->config->spip, 1, buf); if (buf[0] == 0xFF) break; #ifdef MMC_NICE_WAITING chThdSleep(1); /* Trying to be nice with the other threads.*/ #endif } - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); } /*===========================================================================*/ @@ -369,15 +369,11 @@ void mmcInit(void) { * * @init */ -void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, - const SPIConfig *lscfg, const SPIConfig *hscfg) { +void mmcObjectInit(MMCDriver *mmcp) { mmcp->vmt = &mmc_vmt; mmcp->state = MMC_STOP; mmcp->config = NULL; - mmcp->spip = spip; - mmcp->lscfg = lscfg; - mmcp->hscfg = hscfg; mmcp->block_addresses = FALSE; chEvtInit(&mmcp->inserted_event); chEvtInit(&mmcp->removed_event); @@ -425,7 +421,7 @@ void mmcStop(MMCDriver *mmcp) { chVTResetI(&mmcp->vt); } chSysUnlock(); - spiStop(mmcp->spip); + spiStop(mmcp->config->spip); } /** @@ -456,13 +452,13 @@ bool_t mmcConnect(MMCDriver *mmcp) { if (mmcp->state == MMC_INSERTED) { /* Slow clock mode and 128 clock pulses.*/ - spiStart(mmcp->spip, mmcp->lscfg); - spiIgnore(mmcp->spip, 16); + spiStart(mmcp->config->spip, mmcp->config->lscfg); + spiIgnore(mmcp->config->spip, 16); /* SPI mode selection.*/ i = 0; while (TRUE) { - if (send_command_R1(mmcp, SDMMC_CMD_GO_IDLE_STATE, 0) == 0x01) + if (send_command_R1(mmcp, MMCSD_CMD_GO_IDLE_STATE, 0) == 0x01) break; if (++i >= MMC_CMD0_RETRY) return TRUE; @@ -474,14 +470,14 @@ bool_t mmcConnect(MMCDriver *mmcp) { This method is based on "How to support SDC Ver2 and high capacity cards" by ElmChan.*/ uint8_t r3[4]; - if (send_command_R3(mmcp, SDMMC_CMD_SEND_IF_COND, - SDMMC_CMD8_PATTERN, r3) != 0x05) { + if (send_command_R3(mmcp, MMCSD_CMD_SEND_IF_COND, + MMCSD_CMD8_PATTERN, r3) != 0x05) { /* Switch to SDHC mode.*/ i = 0; while (TRUE) { - if ((send_command_R1(mmcp, SDMMC_CMD_APP_CMD, 0) == 0x01) && - (send_command_R3(mmcp, SDMMC_CMD_APP_OP_COND, + if ((send_command_R1(mmcp, MMCSD_CMD_APP_CMD, 0) == 0x01) && + (send_command_R3(mmcp, MMCSD_CMD_APP_OP_COND, 0x400001aa, r3) == 0x00)) break; @@ -491,7 +487,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /* Execute dedicated read on OCR register */ - send_command_R3(mmcp, SDMMC_CMD_READ_OCR, 0, r3); + send_command_R3(mmcp, MMCSD_CMD_READ_OCR, 0, r3); /* Check if CCS is set in response. Card operates in block mode if set.*/ if(r3[0] & 0x40) @@ -501,7 +497,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* Initialization.*/ i = 0; while (TRUE) { - uint8_t b = send_command_R1(mmcp, SDMMC_CMD_INIT, 0); + uint8_t b = send_command_R1(mmcp, MMCSD_CMD_INIT, 0); if (b == 0x00) break; if (b != 0x01) @@ -512,11 +508,11 @@ bool_t mmcConnect(MMCDriver *mmcp) { } /* Initialization complete, full speed.*/ - spiStart(mmcp->spip, mmcp->hscfg); + spiStart(mmcp->config->spip, mmcp->config->hscfg); /* Setting block size.*/ - if (send_command_R1(mmcp, SDMMC_CMD_SET_BLOCKLEN, - SDMMC_BLOCK_SIZE) != 0x00) + if (send_command_R1(mmcp, MMCSD_CMD_SET_BLOCKLEN, + MMCSD_BLOCK_SIZE) != 0x00) return TRUE; /* Transition to MMC_READY state (if not extracted).*/ @@ -568,7 +564,7 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { default: status = TRUE; } - spiStop(mmcp->spip); + spiStop(mmcp->config->spip); return status; } @@ -596,16 +592,16 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { mmcp->state = MMC_READING; chSysUnlock(); - spiStart(mmcp->spip, mmcp->hscfg); - spiSelect(mmcp->spip); + spiStart(mmcp->config->spip, mmcp->config->hscfg); + spiSelect(mmcp->config->spip); if(mmcp->block_addresses) - send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk); + send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk); else - send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk * SDMMC_BLOCK_SIZE); + send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_READING) mmcp->state = MMC_READY; @@ -640,16 +636,16 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chSysUnlock(); for (i = 0; i < MMC_WAIT_DATA; i++) { - spiReceive(mmcp->spip, 1, buffer); + spiReceive(mmcp->config->spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceive(mmcp->spip, SDMMC_BLOCK_SIZE, buffer); + spiReceive(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer); /* CRC ignored. */ - spiIgnore(mmcp->spip, 2); + spiIgnore(mmcp->config->spip, 2); return FALSE; } } /* Timeout.*/ - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_READING) mmcp->state = MMC_READY; @@ -669,7 +665,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * @api */ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { - static const uint8_t stopcmd[] = {0x40 | SDMMC_CMD_STOP_TRANSMISSION, + static const uint8_t stopcmd[] = {0x40 | MMCSD_CMD_STOP_TRANSMISSION, 0, 0, 0, 0, 1, 0xFF}; bool_t result; @@ -682,12 +678,12 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { } chSysUnlock(); - spiSend(mmcp->spip, sizeof(stopcmd), stopcmd); + spiSend(mmcp->config->spip, sizeof(stopcmd), stopcmd); /* result = recvr1(mmcp) != 0x00;*/ /* Note, ignored r1 response, it can be not zero, unknown issue.*/ recvr1(mmcp); result = FALSE; - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_READING) @@ -720,17 +716,17 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { mmcp->state = MMC_WRITING; chSysUnlock(); - spiStart(mmcp->spip, mmcp->hscfg); - spiSelect(mmcp->spip); + spiStart(mmcp->config->spip, mmcp->config->hscfg); + spiSelect(mmcp->config->spip); if(mmcp->block_addresses) - send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK, startblk); + send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, startblk); else - send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK, - startblk * SDMMC_BLOCK_SIZE); + send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, + startblk * MMCSD_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_WRITING) mmcp->state = MMC_READY; @@ -765,17 +761,17 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { } chSysUnlock(); - spiSend(mmcp->spip, sizeof(start), start); /* Data prologue. */ - spiSend(mmcp->spip, SDMMC_BLOCK_SIZE, buffer); /* Data. */ - spiIgnore(mmcp->spip, 2); /* CRC ignored. */ - spiReceive(mmcp->spip, 1, b); + spiSend(mmcp->config->spip, sizeof(start), start); /* Data prologue. */ + spiSend(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);/* Data. */ + spiIgnore(mmcp->config->spip, 2); /* CRC ignored. */ + spiReceive(mmcp->config->spip, 1, b); if ((b[0] & 0x1F) == 0x05) { wait(mmcp); return FALSE; } /* Error.*/ - spiUnselect(mmcp->spip); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_WRITING) mmcp->state = MMC_READY; @@ -806,8 +802,8 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { } chSysUnlock(); - spiSend(mmcp->spip, sizeof(stop), stop); - spiUnselect(mmcp->spip); + spiSend(mmcp->config->spip, sizeof(stop), stop); + spiUnselect(mmcp->config->spip); chSysLock(); if (mmcp->state == MMC_WRITING) { @@ -871,7 +867,7 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { chSysUnlock(); bdip->blk_num = 0; /* NOTE: To be implemented.*/ - bdip->blk_size = SDMMC_BLOCK_SIZE; + bdip->blk_size = MMCSD_BLOCK_SIZE; return FALSE; } diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c new file mode 100644 index 000000000..88f8a5505 --- /dev/null +++ b/os/hal/src/mmcsd.c @@ -0,0 +1,120 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file mmcsd.c + * @brief MMC/SD cards common code. + * + * @addtogroup MMCSD + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_MMC_SPI || HAL_USE_SDC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/** + * @brief Get slice with data from uint32_t[4] array. + * + * @notapi + */ +static uint32_t mmcsd_get_slice(uint32_t *data, uint32_t end, uint32_t start) { + uint32_t word = 0; + uint32_t mask = 0; + + chDbgCheck(end >= start, "sdc_get_slice"); + + while ((start - 32 * word) > 31){ + word++; + data++; + } + + end -= 32 * word; + start -= 32 * word; + + if (end < 31){ + /* Value lays in one word.*/ + mask = (1 << (end - start + 1)) - 1; + return (*data >> start) & mask; + } + else{ + /* Value spread on separate words.*/ + uint32_t lsb, msb; + lsb = *data >> start; + data++; + mask = (1 << (end - 32 + 1)) - 1; + msb = *data & mask; + msb = msb << (32 - start); + return msb | lsb; + } +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Extract card capacity from a CSD. + * @details The capacity is returned as number of available blocks. + * + * @param[in] csd the CSD record + * + * @return The card capacity. + * @retval 0 CSD format error + */ +uint32_t mmcsdGetCapacity(uint32_t csd[4]) { + + switch (csd[3] >> 30) { + uint32_t a, b, c; + case 0: + /* CSD version 1.0 */ + a = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_SLICE); + b = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_MULT_SLICE); + c = mmcsd_get_slice(csd, MMCSD_CSD_10_READ_BL_LEN_SLICE); + return (a + 1) << (b + 2) << (c - 9); /* 2^9 == MMCSD_BLOCK_SIZE. */ + case 1: + /* CSD version 2.0.*/ + return 1024 * (mmcsd_get_slice(csd, MMCSD_CSD_20_C_SIZE_SLICE) + 1); + default: + /* Reserved value detected.*/ + return 0; + } +} + +#endif /* HAL_USE_MMC_SPI || HAL_USE_SDC */ + +/** @} */ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 483263776..3ff938f98 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -61,42 +61,6 @@ static const struct MMCSDBlockDeviceVMT sdc_vmt = { /* Driver local functions. */ /*===========================================================================*/ -/** - * @brief Get slice with data from uint32_t[4] array. - * - * @notapi - */ -static uint32_t _sdc_get_slice(uint32_t *data, int32_t end, int32_t start) { - uint32_t word = 0; - uint32_t mask = 0; - - chDbgCheck(((start >=0) && (end >=0) && (end >= start)), "sdc_get_slice"); - - while ((start - 32 * word) > 31){ - word++; - data++; - } - - end -= 32 * word; - start -= 32 * word; - - if (end < 31){ - /* Value lays in one word.*/ - mask = (1 << (end - start + 1)) - 1; - return (*data >> start) & mask; - } - else{ - /* Value spread on separate words.*/ - uint32_t lsb, msb; - lsb = *data >> start; - data++; - mask = (1 << (end - 32 + 1)) - 1; - msb = *data & mask; - msb = msb << (32 - start); - return (msb | lsb); - } -} - /** * @brief Wait for the card to complete pending operations. * @@ -112,16 +76,16 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) { uint32_t resp[1]; while (TRUE) { - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS, + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_STATUS, sdcp->rca, resp) || - SDC_R1_ERROR(resp[0])) + MMCSD_R1_ERROR(resp[0])) return CH_FAILED; - switch (SDC_R1_STS(resp[0])) { - case SDC_STS_TRAN: + switch (MMCSD_R1_STS(resp[0])) { + case MMCSD_STS_TRAN: return CH_SUCCESS; - case SDC_STS_DATA: - case SDC_STS_RCV: - case SDC_STS_PRG: + case MMCSD_STS_DATA: + case MMCSD_STS_RCV: + case MMCSD_STS_PRG: #if SDC_NICE_WAITING chThdSleepMilliseconds(1); #endif @@ -239,23 +203,23 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdc_lld_start_clk(sdcp); /* Enforces the initial card state.*/ - sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0); + sdc_lld_send_cmd_none(sdcp, MMCSD_CMD_GO_IDLE_STATE, 0); /* V2.0 cards detection.*/ - if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND, - SDC_CMD8_PATTERN, resp)) { + if (!sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_IF_COND, + MMCSD_CMD8_PATTERN, resp)) { sdcp->cardmode = SDC_MODE_CARDTYPE_SDV20; /* Voltage verification.*/ if (((resp[0] >> 8) & 0xF) != 1) goto failed; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, 0, resp) || + MMCSD_R1_ERROR(resp[0])) goto failed; } else { #if SDC_MMC_SUPPORT /* MMC or SD V1.1 detection.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || + if (sdc_lld_send_cmd_short_crc(sdcp, SDMMC_CMD_APP_CMD, 0, resp) || SDC_R1_ERROR(resp[0])) sdcp->cardmode = SDC_MODE_CARDTYPE_MMC; else @@ -283,10 +247,10 @@ bool_t sdcConnect(SDCDriver *sdcp) { /* SD-type initialization. */ i = 0; while (TRUE) { - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, 0, resp) || + MMCSD_R1_ERROR(resp[0])) goto failed; - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp)) + if (sdc_lld_send_cmd_short(sdcp, MMCSD_CMD_APP_OP_COND, ocr, resp)) goto failed; if ((resp[0] & 0x80000000) != 0) { if (resp[0] & 0x40000000) @@ -300,30 +264,31 @@ bool_t sdcConnect(SDCDriver *sdcp) { } /* Reads CID.*/ - if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_ALL_SEND_CID, 0, sdcp->cid)) + if (sdc_lld_send_cmd_long_crc(sdcp, MMCSD_CMD_ALL_SEND_CID, 0, sdcp->cid)) goto failed; /* Asks for the RCA.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR, + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_RELATIVE_ADDR, 0, &sdcp->rca)) goto failed; /* Reads CSD.*/ - if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_SEND_CSD, sdcp->rca, sdcp->csd)) + if (sdc_lld_send_cmd_long_crc(sdcp, MMCSD_CMD_SEND_CSD, + sdcp->rca, sdcp->csd)) goto failed; /* Switches to high speed.*/ sdc_lld_set_data_clk(sdcp); /* Selects the card for operations.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEL_DESEL_CARD, sdcp->rca, resp)) goto failed; /* Block length fixed at 512 bytes.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, - SDC_BLOCK_SIZE, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_BLOCKLEN, + MMCSD_BLOCK_SIZE, resp) || + MMCSD_R1_ERROR(resp[0])) goto failed; /* Switches to wide bus mode.*/ @@ -331,35 +296,17 @@ bool_t sdcConnect(SDCDriver *sdcp) { case SDC_MODE_CARDTYPE_SDV11: case SDC_MODE_CARDTYPE_SDV20: sdc_lld_set_bus_mode(sdcp, SDC_MODE_4BIT); - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, sdcp->rca, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, sdcp->rca, resp) || + MMCSD_R1_ERROR(resp[0])) goto failed; - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BUS_WIDTH, 2, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_BUS_WIDTH, 2, resp) || + MMCSD_R1_ERROR(resp[0])) goto failed; break; } /* Determine capacity.*/ - switch (sdcp->csd[3] >> 30) { - uint32_t a, b, c; - case 0: - /* CSD version 1.0 */ - a = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_SLICE); - b = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_MULT_SLICE); - c = _sdc_get_slice(sdcp->csd, SDC_CSD_10_READ_BL_LEN_SLICE); - sdcp->capacity = ((a + 1) << (b + 2) << c) / 512; - break; - case 1: - /* CSD version 2.0 */ - a = _sdc_get_slice(sdcp->csd, SDC_CSD_20_C_SIZE_SLICE); - sdcp->capacity = 1024 * (a + 1); - break; - default: - /* Reserved value detected. */ - sdcp->capacity = 0; - break; - } + sdcp->capacity = mmcsdGetCapacity(sdcp->csd); if (sdcp->capacity == 0) goto failed; @@ -553,7 +500,7 @@ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { chSysUnlock(); bdip->blk_num = 0; /* NOTE: To be implemented.*/ - bdip->blk_size = SDMMC_BLOCK_SIZE; + bdip->blk_size = MMCSD_BLOCK_SIZE; return FALSE; } -- cgit v1.2.3 From b1653c7b3cac9131127bc12190e1fa89dd8c7ec1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 May 2012 12:38:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4181 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 3ff938f98..6ae84c98c 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -499,7 +499,7 @@ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { } chSysUnlock(); - bdip->blk_num = 0; /* NOTE: To be implemented.*/ + bdip->blk_num = sdcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; return FALSE; -- cgit v1.2.3 From eba4b7056128ae85402984fb03882a5a9eb88213 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 May 2012 15:07:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4182 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- os/hal/src/mmcsd.c | 6 +++--- 2 files changed, 60 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index dad837613..a4ce608e3 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -310,7 +310,7 @@ static uint8_t send_command_R1(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) { static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, uint8_t *response) { uint8_t r1; - + spiSelect(mmcp->config->spip); send_hdr(mmcp, cmd, arg); r1 = recvr3(mmcp, response); @@ -318,6 +318,53 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, return r1; } +/** + * @brief Reads the CSD. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] csd pointer to the CSD buffer + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @notapi + */ +static bool_t read_CSD(MMCDriver *mmcp, uint32_t csd[4]) { + unsigned i; + uint8_t *bp, buf[16]; + + spiSelect(mmcp->config->spip); + send_hdr(mmcp, MMCSD_CMD_SEND_CSD, 0); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->config->spip); + return TRUE; + } + + /* Wait for data availability.*/ + for (i = 0; i < MMC_WAIT_DATA; i++) { + spiReceive(mmcp->config->spip, 1, buf); + if (buf[0] == 0xFE) { + uint32_t *wp; + + spiReceive(mmcp->config->spip, 16, buf); + bp = buf; + for (wp = &csd[3]; wp >= csd; wp--) { + *wp = ((uint32_t)bp[0] << 24) | ((uint32_t)bp[1] << 16) | + ((uint32_t)bp[2] << 8) | (uint32_t)bp[3]; + bp += 4; + } + + /* CRC ignored then end of transaction. */ + spiIgnore(mmcp->config->spip, 2); + spiUnselect(mmcp->config->spip); + + return FALSE; + } + } + return TRUE; +} + /** * @brief Waits that the card reaches an idle state. * @@ -444,6 +491,7 @@ void mmcStop(MMCDriver *mmcp) { bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; bool_t result; + uint32_t csd[4]; chDbgCheck(mmcp != NULL, "mmcConnect"); @@ -515,6 +563,13 @@ bool_t mmcConnect(MMCDriver *mmcp) { MMCSD_BLOCK_SIZE) != 0x00) return TRUE; + /* Determine capacity.*/ + if (read_CSD(mmcp, csd)) + return TRUE; + mmcp->capacity = mmcsdGetCapacity(csd); + if (mmcp->capacity == 0) + return TRUE; + /* Transition to MMC_READY state (if not extracted).*/ chSysLock(); if (mmcp->state == MMC_INSERTED) { @@ -866,7 +921,7 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { } chSysUnlock(); - bdip->blk_num = 0; /* NOTE: To be implemented.*/ + bdip->blk_num = mmcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; return FALSE; diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c index 88f8a5505..44a552cbd 100644 --- a/os/hal/src/mmcsd.c +++ b/os/hal/src/mmcsd.c @@ -58,7 +58,7 @@ static uint32_t mmcsd_get_slice(uint32_t *data, uint32_t end, uint32_t start) { chDbgCheck(end >= start, "sdc_get_slice"); - while ((start - 32 * word) > 31){ + while ((start - 32 * word) > 31) { word++; data++; } @@ -66,12 +66,12 @@ static uint32_t mmcsd_get_slice(uint32_t *data, uint32_t end, uint32_t start) { end -= 32 * word; start -= 32 * word; - if (end < 31){ + if (end < 31) { /* Value lays in one word.*/ mask = (1 << (end - start + 1)) - 1; return (*data >> start) & mask; } - else{ + else { /* Value spread on separate words.*/ uint32_t lsb, msb; lsb = *data >> start; -- cgit v1.2.3 From 7e815ba913fb19597eddd708aaef789e3674093d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 May 2012 17:16:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4183 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 6ae84c98c..7722a0eb7 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -454,8 +454,8 @@ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -466,13 +466,13 @@ bool_t sdcSync(SDCDriver *sdcp) { chSysLock(); if (sdcp->state != SDC_READY) { chSysUnlock(); - return TRUE; + return CH_FAILED; } chSysUnlock(); /* TODO: implement.*/ - return FALSE; + return CH_SUCCESS; } /** @@ -482,8 +482,8 @@ bool_t sdcSync(SDCDriver *sdcp) { * @param[out] bdip pointer to a @p BlockDeviceInfo structure * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -495,14 +495,14 @@ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { chSysLock(); if (sdcp->state != SDC_READY) { chSysUnlock(); - return TRUE; + return CH_FAILED; } chSysUnlock(); bdip->blk_num = sdcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; - return FALSE; + return CH_SUCCESS; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From 1ae88ebc04851174eae446506f09463b5656ebdd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 10 May 2012 17:32:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 7722a0eb7..653819bb3 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -443,8 +443,10 @@ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcGetAndClearErrors"); + chSysLock(); sdcflags_t flags = sdcp->errors; sdcp->errors = SDC_NO_ERROR; + chSysUnlock(); return flags; } @@ -470,9 +472,7 @@ bool_t sdcSync(SDCDriver *sdcp) { } chSysUnlock(); - /* TODO: implement.*/ - - return CH_SUCCESS; + return sdc_lld_sync(sdcp); } /** -- cgit v1.2.3 From de193fdcff777b88d0fcf2733863993ad033b13f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 11 May 2012 16:41:55 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4185 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index aaeb5e6ee..3f06025c6 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -65,13 +65,21 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { } static bool_t putwouldblock(void *ip) { + bool_t b; - return chOQIsFullI(&((SerialDriver *)ip)->oqueue); + chSysLock(); + b = chOQIsFullI(&((SerialDriver *)ip)->oqueue); + chSysUnlock(); + return b; } static bool_t getwouldblock(void *ip) { + bool_t b; - return chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); + chSysLock(); + b = chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); + chSysUnlock(); + return b; } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { -- cgit v1.2.3 From ab9c48576c984d67cf3bc66e29e9e154e8c934ce Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 11 May 2012 18:14:39 +0000 Subject: Small optimization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4186 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmcsd.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c index 44a552cbd..62a3d368d 100644 --- a/os/hal/src/mmcsd.c +++ b/os/hal/src/mmcsd.c @@ -48,39 +48,33 @@ /*===========================================================================*/ /** - * @brief Get slice with data from uint32_t[4] array. + * @brief Gets a bit field from a words array. + * @note The bit zero is the LSb of the first word. + * + * @param[in] data pointer to the words array + * @param[in] end bit offset of the last bit of the field, inclusive + * @param[in] start bit offset of the first bit of the field, inclusive + * + * @return The bits field value, left aligned. * * @notapi */ static uint32_t mmcsd_get_slice(uint32_t *data, uint32_t end, uint32_t start) { - uint32_t word = 0; - uint32_t mask = 0; - - chDbgCheck(end >= start, "sdc_get_slice"); + unsigned startidx, endidx, startoff; + uint32_t endmask; - while ((start - 32 * word) > 31) { - word++; - data++; - } + chDbgCheck((end >= start) && ((end - start) < 32), "mmcsd_get_slice"); - end -= 32 * word; - start -= 32 * word; + startidx = start / 32; + startoff = start % 32; + endidx = end / 32; + endmask = (1 << ((end % 32) + 1)) - 1; - if (end < 31) { - /* Value lays in one word.*/ - mask = (1 << (end - start + 1)) - 1; - return (*data >> start) & mask; - } - else { - /* Value spread on separate words.*/ - uint32_t lsb, msb; - lsb = *data >> start; - data++; - mask = (1 << (end - 32 + 1)) - 1; - msb = *data & mask; - msb = msb << (32 - start); - return msb | lsb; - } + /* One or two pieces?*/ + if (startidx < endidx) + return (data[startidx] >> startoff) | /* Two pieces case. */ + ((data[endidx] & endmask) << (32 - startoff)); + return (data[startidx] & endmask) >> startoff; /* One piece case. */ } /*===========================================================================*/ @@ -105,7 +99,7 @@ uint32_t mmcsdGetCapacity(uint32_t csd[4]) { a = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_SLICE); b = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_MULT_SLICE); c = mmcsd_get_slice(csd, MMCSD_CSD_10_READ_BL_LEN_SLICE); - return (a + 1) << (b + 2) << (c - 9); /* 2^9 == MMCSD_BLOCK_SIZE. */ + return (a + 1) << (b + 2) << (c - 9); /* 2^9 == MMCSD_BLOCK_SIZE. */ case 1: /* CSD version 2.0.*/ return 1024 * (mmcsd_get_slice(csd, MMCSD_CSD_20_C_SIZE_SLICE) + 1); -- cgit v1.2.3 From 661cf8e8dc3793c0f716e783018514b9bd4e5551 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 22 May 2012 19:45:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4230 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 44 ++++++++++++++++++++++++++++++++++++++------ os/hal/src/sdc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index a4ce608e3..a6dda0dc1 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -330,12 +330,12 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, * * @notapi */ -static bool_t read_CSD(MMCDriver *mmcp, uint32_t csd[4]) { +static bool_t read_CxD(MMCDriver *mmcp, uint8_t cmd, uint32_t cxd[4]) { unsigned i; uint8_t *bp, buf[16]; spiSelect(mmcp->config->spip); - send_hdr(mmcp, MMCSD_CMD_SEND_CSD, 0); + send_hdr(mmcp, cmd, 0); if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->config->spip); return TRUE; @@ -349,7 +349,7 @@ static bool_t read_CSD(MMCDriver *mmcp, uint32_t csd[4]) { spiReceive(mmcp->config->spip, 16, buf); bp = buf; - for (wp = &csd[3]; wp >= csd; wp--) { + for (wp = &cxd[3]; wp >= cxd; wp--) { *wp = ((uint32_t)bp[0] << 24) | ((uint32_t)bp[1] << 16) | ((uint32_t)bp[2] << 8) | (uint32_t)bp[3]; bp += 4; @@ -491,7 +491,6 @@ void mmcStop(MMCDriver *mmcp) { bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; bool_t result; - uint32_t csd[4]; chDbgCheck(mmcp != NULL, "mmcConnect"); @@ -564,12 +563,15 @@ bool_t mmcConnect(MMCDriver *mmcp) { return TRUE; /* Determine capacity.*/ - if (read_CSD(mmcp, csd)) + if (read_CxD(mmcp, MMCSD_CMD_SEND_CSD, mmcp->csd)) return TRUE; - mmcp->capacity = mmcsdGetCapacity(csd); + mmcp->capacity = mmcsdGetCapacity(mmcp->csd); if (mmcp->capacity == 0) return TRUE; + if (read_CxD(mmcp, MMCSD_CMD_SEND_CID, mmcp->cid)) + return TRUE; + /* Transition to MMC_READY state (if not extracted).*/ chSysLock(); if (mmcp->state == MMC_INSERTED) { @@ -927,6 +929,36 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { return FALSE; } +/** + * @brief Erases blocks. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk starting block number + * @param[in] endblk ending block number + * + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed. + * + * @api + */ +bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) { + + chDbgCheck((mmcp != NULL), "mmcErase"); + + if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk)) + return TRUE; + + if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk)) + return TRUE; + + if (send_command_R1(mmcp, MMCSD_CMD_ERASE, 0)) + return TRUE; + + return FALSE; +} + + #endif /* HAL_USE_MMC_SPI */ /** @} */ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 653819bb3..ff90fdd62 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -505,6 +505,52 @@ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { return CH_SUCCESS; } + +/** + * @brief Erases the supplied blocks. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[in] startblk starting block number + * @param[in] endblk ending block number + * + * @return The operation status. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. + * + * @api + */ +bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { + uint32_t resp[1]; + + chDbgCheck((sdcp != NULL), "sdcErase"); + + /* Driver handles data in 512 bytes blocks (just like HC cards). But if we + have not HC card than we must convert address from blocks to bytes.*/ + if (!(sdcp->cardmode & SDC_MODE_HIGH_CAPACITY)) { + startblk *= MMCSD_BLOCK_SIZE; + endblk *= MMCSD_BLOCK_SIZE; + } + + _sdc_wait_for_transfer_state( sdcp ); + + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + return CH_FAILED; + + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + return CH_FAILED; + + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE, 0, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + return CH_FAILED; + + /* Quick sleep to allow it to transition to programming or receiving state */ + chThdSleepMilliseconds(2); + + /* Wait for it to return to transfer state to indicate it has finished erasing */ + _sdc_wait_for_transfer_state( sdcp ); + + return CH_SUCCESS; +} + #endif /* HAL_USE_SDC */ /** @} */ -- cgit v1.2.3 From ac2e9f7ffc14db090a75086a9a0469b0a90fdb90 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 May 2012 16:36:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4246 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 52c57c800..2c7a37b4d 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -104,7 +104,7 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { } static chnflags_t getflags(void *ip) { - _ch_get_and_clear_flags_impl(ip); + _chn_get_and_clear_flags_impl(ip); } static const struct SerialUSBDriverVMT vmt = { -- cgit v1.2.3 From d406f96c222902ec96a334f517be865dfe2eaf5b Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 1 Jun 2012 18:08:28 +0000 Subject: SDIO. Deleted unneded sleep. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4252 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index ff90fdd62..dd0170b4f 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -543,7 +543,6 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { return CH_FAILED; /* Quick sleep to allow it to transition to programming or receiving state */ - chThdSleepMilliseconds(2); /* Wait for it to return to transfer state to indicate it has finished erasing */ _sdc_wait_for_transfer_state( sdcp ); -- cgit v1.2.3 From 2e56d8e14eb9ffbcc533e5cb2484a6448ccb439a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 3 Jun 2012 09:18:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4258 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index cbd009483..1927581f1 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -571,20 +571,20 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { switch (usbp->ep0state) { case USB_EP0_TX: max = usb_lld_fetch_word(&usbp->setup[6]); - /* If the transmitted size is less than the requested size and it is a - multiple of the maximum packet size then a zero size packet must be - transmitted.*/ - if ((usbp->ep0n < max) && - ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { - usb_lld_prepare_transmit(usbp, 0, NULL, 0); - usb_lld_start_in(usbp, 0); - return; - } - - /* Transmit phase over, receiving the zero sized status packet.*/ - usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_prepare_receive(usbp, 0, NULL, 0); - usb_lld_start_out(usbp, 0); + /* If the transmitted size is less than the requested size and it is a + multiple of the maximum packet size then a zero size packet must be + transmitted.*/ + if ((usbp->ep0n < max) && + ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); + return; + } + + /* Transmit phase over, receiving the zero sized status packet.*/ + usbp->ep0state = USB_EP0_WAITING_STS; + usb_lld_prepare_receive(usbp, 0, NULL, 0); + usb_lld_start_out(usbp, 0); return; case USB_EP0_SENDING_STS: /* Status packet sent, invoking the callback if defined.*/ -- cgit v1.2.3 From c762926b68f6a6c7f1e71b8acf9b1dd29d6e481f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Jun 2012 16:31:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4265 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 8 ++++++++ os/hal/src/usb.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 2c7a37b4d..7f1658812 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -119,6 +119,7 @@ static const struct SerialUSBDriverVMT vmt = { static void inotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; +#if 0 /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && @@ -139,6 +140,7 @@ static void inotify(GenericQueue *qp) { while (notempty(&sdup->iqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } +#endif } /** @@ -148,6 +150,7 @@ static void onotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; size_t n; +#if 0 /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); @@ -166,6 +169,7 @@ static void onotify(GenericQueue *qp) { while (notempty(&sdup->oqueue.q_waiting)) chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } +#endif } /*===========================================================================*/ @@ -298,6 +302,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; size_t n; +#if 0 chSysLockFromIsr(); /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ @@ -319,6 +324,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); +#endif } /** @@ -332,6 +338,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { void sduDataReceived(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; +#if 0 chSysLockFromIsr(); /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ @@ -355,6 +362,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); +#endif } /** diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 1927581f1..ceae24770 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -313,10 +313,10 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ - if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) { +// if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) { memset(epcp->in_state, 0, sizeof(USBInEndpointState)); memset(epcp->out_state, 0, sizeof(USBOutEndpointState)); - } +// } usbp->epc[ep] = epcp; /* Low level endpoint activation.*/ -- cgit v1.2.3 From d094e348c5d1a3785289c69c5185bbaca1257de8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Jun 2012 16:54:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4266 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 4 +- os/hal/src/serial_usb.c | 115 ++++++++++++++++++++---------------------------- 2 files changed, 49 insertions(+), 70 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 3f06025c6..5b883e16a 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -149,8 +149,8 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { chEvtInit(&sdp->event); sdp->flags = CHN_NO_ERROR; sdp->state = SD_STOP; - chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify); - chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify); + chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp); + chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp); } /** diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 7f1658812..5fec52a68 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -117,59 +117,47 @@ static const struct SerialUSBDriverVMT vmt = { * @brief Notification of data removed from the input queue. */ static void inotify(GenericQueue *qp) { - SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; + size_t n, maxsize; + SerialUSBDriver *sdup = chQGetLink(qp); -#if 0 - /* Writes to the input queue can only happen when the queue has been - emptied, then a whole packet is loaded in the queue.*/ + /* If there is in the queue enough space to hold at least one packet and + a transaction is not yet started then a new transaction is started for + the available space.*/ + maxsize = sdup->config->usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && - chIQIsEmptyI(&sdup->iqueue)) { + ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize)) { chSysUnlock(); - /* Unlocked to make the potentially long read operation preemptable.*/ - size_t n = usbReadPacketBuffer(sdup->config->usbp, - USB_CDC_DATA_AVAILABLE_EP, - sdup->iqueue.q_buffer, - SERIAL_USB_BUFFERS_SIZE); + n = (n / maxsize) * maxsize; + usbPrepareQueuedReceive(sdup->config->usbp, + USB_CDC_DATA_AVAILABLE_EP, + &sdup->iqueue, n); chSysLock(); usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); - chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } -#endif } /** * @brief Notification of data inserted into the output queue. */ static void onotify(GenericQueue *qp) { - SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; size_t n; + SerialUSBDriver *sdup = chQGetLink(qp); -#if 0 - /* If there is any data in the output queue then it is sent within a - single packet and the queue is emptied.*/ - n = chOQGetFullI(&sdup->oqueue); - if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP)) { + /* If there is not an ongoing transaction and the output queue contains + data then a new transaction is started.*/ + if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP) && + ((n = chOQGetFullI(&sdup->oqueue)) > 0)) { chSysUnlock(); - /* Unlocked to make the potentially long write operation preemptable.*/ - usbWritePacketBuffer(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, - sdup->oqueue.q_buffer, n); + usbPrepareQueuedTransmit(sdup->config->usbp, + USB_CDC_DATA_REQUEST_EP, + &sdup->oqueue, n); chSysLock(); usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); - chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); - while (notempty(&sdup->oqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } -#endif } /*===========================================================================*/ @@ -201,12 +189,8 @@ void sduObjectInit(SerialUSBDriver *sdup) { chEvtInit(&sdup->event); sdup->flags = CHN_NO_ERROR; sdup->state = SDU_STOP; - chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify); - chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify); - /* This is a dirty trick but those pointers are never used because queues - are accessed in block mode from the low level.*/ - sdup->iqueue.q_wrptr = (uint8_t *)sdup; - sdup->oqueue.q_rdptr = (uint8_t *)sdup; + chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify, sdup); + chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify, sdup); } /** @@ -299,32 +283,28 @@ bool_t sduRequestsHook(USBDriver *usbp) { * @param[in] ep endpoint number */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { - SerialUSBDriver *sdup = usbp->param; size_t n; + SerialUSBDriver *sdup = usbp->param; + + (void)ep; -#if 0 + chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); chSysLockFromIsr(); - /* If there is any data in the output queue then it is sent within a - single packet and the queue is emptied.*/ - n = chOQGetFullI(&sdup->oqueue); - if (n > 0) { + + if ((n = chOQGetFullI(&sdup->oqueue)) > 0) { /* The endpoint cannot be busy, we are in the context of the callback, so it is safe to transmit without a check.*/ chSysUnlockFromIsr(); - /* Unlocked to make the potentially long write operation preemptable.*/ - usbWritePacketBuffer(usbp, ep, sdup->oqueue.q_buffer, n); + usbPrepareQueuedTransmit(sdup->config->usbp, + USB_CDC_DATA_REQUEST_EP, + &sdup->oqueue, n); chSysLockFromIsr(); - usbStartTransmitI(usbp, ep); - chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); - while (notempty(&sdup->oqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; + usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); } + chSysUnlockFromIsr(); -#endif } /** @@ -336,33 +316,32 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { * @param[in] ep endpoint number */ void sduDataReceived(USBDriver *usbp, usbep_t ep) { + size_t n, maxsize; SerialUSBDriver *sdup = usbp->param; -#if 0 + (void)ep; + + chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); chSysLockFromIsr(); - /* Writes to the input queue can only happen when the queue has been - emptied, then a whole packet is loaded in the queue.*/ - if (chIQIsEmptyI(&sdup->iqueue)) { + + /* Writes to the input queue can only happen when there is enough space + to hold at least one packet.*/ + maxsize = sdup->config->usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; + if ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize) { /* The endpoint cannot be busy, we are in the context of the callback, so a packet is in the buffer for sure.*/ - size_t n; - chSysUnlockFromIsr(); - /* Unlocked to make the potentially long write operation preemptable.*/ - n = usbReadPacketBuffer(usbp, ep, sdup->iqueue.q_buffer, - SERIAL_USB_BUFFERS_SIZE); + n = (n / maxsize) * maxsize; + usbPrepareQueuedReceive(sdup->config->usbp, + USB_CDC_DATA_AVAILABLE_EP, + &sdup->iqueue, n); chSysLockFromIsr(); - usbStartReceiveI(usbp, ep); - chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; + usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); } + chSysUnlockFromIsr(); -#endif } /** -- cgit v1.2.3 From 41eb1a7e7ec33ee7abd62fa954be6b995d6e9707 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Jun 2012 19:43:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4271 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 5fec52a68..52be6e975 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -288,8 +288,8 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { (void)ep; - chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); chSysLockFromIsr(); + chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); if ((n = chOQGetFullI(&sdup->oqueue)) > 0) { /* The endpoint cannot be busy, we are in the context of the callback, @@ -321,8 +321,8 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { (void)ep; - chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); chSysLockFromIsr(); + chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); /* Writes to the input queue can only happen when there is enough space to hold at least one packet.*/ -- cgit v1.2.3 From f620f29e0a803ed942134ac8a801d5204cebe034 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 13 Jun 2012 16:13:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4273 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 52be6e975..2b02ae02f 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -120,6 +120,11 @@ static void inotify(GenericQueue *qp) { size_t n, maxsize; SerialUSBDriver *sdup = chQGetLink(qp); + /* If the USB driver is not in the appropriate state then transactions + must not be started.*/ + if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + return; + /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ @@ -145,6 +150,11 @@ static void onotify(GenericQueue *qp) { size_t n; SerialUSBDriver *sdup = chQGetLink(qp); + /* If the USB driver is not in the appropriate state then transactions + must not be started.*/ + if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + return; + /* If there is not an ongoing transaction and the output queue contains data then a new transaction is started.*/ if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP) && @@ -238,6 +248,22 @@ void sduStop(SerialUSBDriver *sdup) { usbStop(sdup->config->usbp); } +/** + * @brief USB device configured handler. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @iclass + */ +void sduConfigureHookI(USBDriver *usbp) { + SerialUSBDriver *sdup = usbp->param; + + sdup->flags = CHN_NO_ERROR; + chIQResetI(&sdup->iqueue); + chOQResetI(&sdup->oqueue); + chnAddFlagsI(sdup, CHN_CONNECTED); +} + /** * @brief Default requests hook. * @details Applications wanting to use the Serial over USB driver can use -- cgit v1.2.3 From 2b1173e29246cbc82f45490d0b1b1443d7bf897a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 14 Jun 2012 16:45:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4276 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 9 +-------- os/hal/src/sdc.c | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index a6dda0dc1..cb045bcb4 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -57,7 +57,7 @@ bool_t mmc_write(void *instance, uint32_t startblk, /** * @brief Virtual methods table. */ -static const struct MMCSDBlockDeviceVMT mmc_vmt = { +static const struct MMCDriverVMT mmc_vmt = { (bool_t (*)(void *))mmc_lld_is_card_inserted, (bool_t (*)(void *))mmc_lld_is_write_protected, (bool_t (*)(void *))mmcConnect, @@ -406,13 +406,6 @@ void mmcInit(void) { * @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 */ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index dd0170b4f..728f05566 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -46,7 +46,7 @@ /** * @brief Virtual methods table. */ -static const struct MMCSDBlockDeviceVMT sdc_vmt = { +static const struct SDCDriverVMT sdc_vmt = { (bool_t (*)(void *))sdc_lld_is_card_inserted, (bool_t (*)(void *))sdc_lld_is_write_protected, (bool_t (*)(void *))sdcConnect, -- cgit v1.2.3 From c6914081835f10258d873af8526ae405ffe5b25c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 17 Jun 2012 06:53:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4283 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index ceae24770..fa79ea0c1 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -313,10 +313,11 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ -// if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) { + if (epcp->in_state != NULL) memset(epcp->in_state, 0, sizeof(USBInEndpointState)); + if (epcp->out_state != NULL) memset(epcp->out_state, 0, sizeof(USBOutEndpointState)); -// } + usbp->epc[ep] = epcp; /* Low level endpoint activation.*/ -- cgit v1.2.3 From 25ac1fcadfb483d74226f5e020ed8057896de6f2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 17 Jun 2012 07:49:08 +0000 Subject: USB driver API improvements. Revision of the low level drivers. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4284 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 14 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index fa79ea0c1..7f9d0456d 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -352,6 +352,118 @@ void usbDisableEndpointsI(USBDriver *usbp) { usb_lld_disable_endpoints(usbp); } +/** + * @brief Prepares for a receive transaction on an OUT endpoint. + * @pre In order to use this function the endpoint must have been + * initialized in transaction mode. + * @post The endpoint is ready for @p usbStartReceiveI(). + * @note This function can be called both in ISR and thread context. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[out] buf buffer where to copy the received data + * @param[in] n transaction size + * + * @special + */ +void usbPrepareReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { + USBOutEndpointState *osp = usbp->epc[ep]->out_state; + + osp->rxqueued = FALSE; + osp->mode.linear.rxbuf = buf; + osp->rxsize = n; + osp->rxcnt = 0; + + usb_lld_prepare_receive(usbp, ep); +} + +/** + * @brief Prepares for a transmit transaction on an IN endpoint. + * @pre In order to use this function the endpoint must have been + * initialized in transaction mode. + * @post The endpoint is ready for @p usbStartTransmitI(). + * @note This function can be called both in ISR and thread context. + * @note The queue must contain at least the amount of data specified + * as transaction size. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] buf buffer where to fetch the data to be transmitted + * @param[in] n transaction size + * + * @special + */ +void usbPrepareTransmit(USBDriver *usbp, usbep_t ep, + const uint8_t *buf, size_t n) { + USBInEndpointState *isp = usbp->epc[ep]->in_state; + + isp->txqueued = FALSE; + isp->mode.linear.txbuf = buf; + isp->txsize = n; + isp->txcnt = 0; + + usb_lld_prepare_transmit(usbp, ep); +} + +/** + * @brief Prepares for a receive transaction on an OUT endpoint. + * @pre In order to use this function the endpoint must have been + * initialized in transaction mode. + * @post The endpoint is ready for @p usbStartReceiveI(). + * @note This function can be called both in ISR and thread context. + * @note The queue must have enough free space to accommodate the + * specified transaction size rounded to the next packet size + * boundary. For example if the transaction size is 1 and the + * packet size is 64 then the queue must have space for at least + * 64 bytes. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] iqp input queue to be filled with incoming data + * @param[in] n transaction size + * + * @special + */ +void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep, + InputQueue *iqp, size_t n) { + USBOutEndpointState *osp = usbp->epc[ep]->out_state; + + osp->rxqueued = TRUE; + osp->mode.queue.rxqueue = iqp; + osp->rxsize = n; + osp->rxcnt = 0; + + usb_lld_prepare_receive(usbp, ep); +} + +/** + * @brief Prepares for a transmit transaction on an IN endpoint. + * @pre In order to use this function the endpoint must have been + * initialized in transaction mode. + * @post The endpoint is ready for @p usbStartTransmitI(). + * @note This function can be called both in ISR and thread context. + * @note The transmit transaction size is equal to the data contained + * in the queue. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] ep endpoint number + * @param[in] oqp output queue to be fetched for outgoing data + * @param[in] n transaction size + * + * @special + */ +void usbPrepareQueuedTransmit(USBDriver *usbp, usbep_t ep, + OutputQueue *oqp, size_t n) { + USBInEndpointState *isp = usbp->epc[ep]->in_state; + + isp->txqueued = TRUE; + isp->mode.queue.txqueue = oqp; + isp->txsize = n; + isp->txcnt = 0; + + usb_lld_prepare_transmit(usbp, ep); +} + /** * @brief Starts a receive transaction on an OUT endpoint. * @post The endpoint callback is invoked when the transfer has been @@ -359,6 +471,7 @@ void usbDisableEndpointsI(USBDriver *usbp) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number + * * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. @@ -385,6 +498,7 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number + * * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. @@ -409,6 +523,7 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number + * * @return The operation status. * @retval FALSE Endpoint stalled. * @retval TRUE Endpoint busy, not stalled. @@ -432,6 +547,7 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number + * * @return The operation status. * @retval FALSE Endpoint stalled. * @retval TRUE Endpoint busy, not stalled. @@ -526,15 +642,19 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the transmit phase.*/ usbp->ep0state = USB_EP0_TX; - usb_lld_prepare_transmit(usbp, 0, usbp->ep0next, usbp->ep0n); - usb_lld_start_in(usbp, 0); + usbPrepareTransmit(usbp, 0, usbp->ep0next, usbp->ep0n); + chSysLockFromIsr(); + usbStartTransmitI(usbp, 0); + chSysUnlockFromIsr(); } else { /* No transmission phase, directly receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_prepare_receive(usbp, 0, NULL, 0); - usb_lld_start_out(usbp, 0); + usbPrepareReceive(usbp, 0, NULL, 0); + chSysLockFromIsr(); + usbStartReceiveI(usbp, 0); + chSysUnlockFromIsr(); } } else { @@ -542,15 +662,19 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the receive phase.*/ usbp->ep0state = USB_EP0_RX; - usb_lld_prepare_receive(usbp, 0, usbp->ep0next, usbp->ep0n); - usb_lld_start_out(usbp, 0); + usbPrepareReceive(usbp, 0, usbp->ep0next, usbp->ep0n); + chSysLockFromIsr(); + usbStartReceiveI(usbp, 0); + chSysUnlockFromIsr(); } else { /* No receive phase, directly sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_prepare_transmit(usbp, 0, NULL, 0); - usb_lld_start_in(usbp, 0); + usbPrepareTransmit(usbp, 0, NULL, 0); + chSysLockFromIsr(); + usbStartTransmitI(usbp, 0); + chSysUnlockFromIsr(); } } } @@ -577,15 +701,19 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { transmitted.*/ if ((usbp->ep0n < max) && ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { - usb_lld_prepare_transmit(usbp, 0, NULL, 0); - usb_lld_start_in(usbp, 0); + usbPrepareTransmit(usbp, 0, NULL, 0); + chSysLockFromIsr(); + usbStartTransmitI(usbp, 0); + chSysUnlockFromIsr(); return; } /* Transmit phase over, receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_prepare_receive(usbp, 0, NULL, 0); - usb_lld_start_out(usbp, 0); + usbPrepareReceive(usbp, 0, NULL, 0); + chSysLockFromIsr(); + usbStartReceiveI(usbp, 0); + chSysUnlockFromIsr(); return; case USB_EP0_SENDING_STS: /* Status packet sent, invoking the callback if defined.*/ @@ -622,8 +750,10 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { case USB_EP0_RX: /* Receive phase over, sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_prepare_transmit(usbp, 0, NULL, 0); - usb_lld_start_in(usbp, 0); + usbPrepareTransmit(usbp, 0, NULL, 0); + chSysLockFromIsr(); + usbStartTransmitI(usbp, 0); + chSysUnlockFromIsr(); return; case USB_EP0_WAITING_STS: /* Status packet received, it must be zero sized, invoking the callback -- cgit v1.2.3 From 3626647d7b924ca07df4197f9cde4a7965b8cbdf Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 18 Jun 2012 08:52:26 +0000 Subject: Fixed bugs 3534767, 3534819, 3535887 and 3535938. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4293 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index cb045bcb4..0be587d14 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -423,13 +423,13 @@ void mmcObjectInit(MMCDriver *mmcp) { * @brief Configures and activates the MMC peripheral. * * @param[in] mmcp pointer to the @p MMCDriver object - * @param[in] config pointer to the @p MMCConfig object. Must be @p NULL. + * @param[in] config pointer to the @p MMCConfig object. * * @api */ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { - chDbgCheck((mmcp != NULL) && (config == NULL), "mmcStart"); + chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); chSysLock(); chDbgAssert(mmcp->state == MMC_STOP, "mmcStart(), #1", "invalid state"); -- cgit v1.2.3 From 9057c6c72be213bb7f07929e2ddd1ab1e942a1de Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 18 Jun 2012 16:22:34 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4294 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 18 +++++------------- os/hal/src/serial_usb.c | 10 +++++----- 2 files changed, 10 insertions(+), 18 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 5b883e16a..8b0d7c8cf 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -64,22 +64,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { n, TIME_INFINITE); } -static bool_t putwouldblock(void *ip) { - bool_t b; +static msg_t put(void *ip, uint8_t b) { - chSysLock(); - b = chOQIsFullI(&((SerialDriver *)ip)->oqueue); - chSysUnlock(); - return b; + return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, TIME_INFINITE); } -static bool_t getwouldblock(void *ip) { - bool_t b; +static msg_t get(void *ip) { - chSysLock(); - b = chIQIsEmptyI(&((SerialDriver *)ip)->iqueue); - chSysUnlock(); - return b; + return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, TIME_INFINITE); } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { @@ -107,7 +99,7 @@ static chnflags_t getflags(void *ip) { } static const struct SerialDriverVMT vmt = { - writes, reads, putwouldblock, getwouldblock, + writes, reads, put, get, putt, gett, writet, readt, getflags }; diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 2b02ae02f..466b65b0a 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -73,14 +73,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { n, TIME_INFINITE); } -static bool_t putwouldblock(void *ip) { +static msg_t put(void *ip, uint8_t b) { - return chOQIsFullI(&((SerialUSBDriver *)ip)->oqueue); + return chOQPutTimeout(&((SerialUSBDriver *)ip)->oqueue, b, TIME_INFINITE); } -static bool_t getwouldblock(void *ip) { +static msg_t get(void *ip) { - return chIQIsEmptyI(&((SerialUSBDriver *)ip)->iqueue); + return chIQGetTimeout(&((SerialUSBDriver *)ip)->iqueue, TIME_INFINITE); } static msg_t putt(void *ip, uint8_t b, systime_t timeout) { @@ -108,7 +108,7 @@ static chnflags_t getflags(void *ip) { } static const struct SerialUSBDriverVMT vmt = { - writes, reads, putwouldblock, getwouldblock, + writes, reads, put, get, putt, gett, writet, readt, getflags }; -- cgit v1.2.3 From 6af0806da3d9df7ea9f6410a74ad8c864926bd7f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jun 2012 08:39:04 +0000 Subject: Fixed bugs 3536522 and 3536523. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4309 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 6 +++--- os/hal/src/serial_usb.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 8b0d7c8cf..2bf7f396b 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -52,13 +52,13 @@ * queue-level function or macro. */ -static size_t writes(void *ip, const uint8_t *bp, size_t n) { +static size_t write(void *ip, const uint8_t *bp, size_t n) { return chOQWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, TIME_INFINITE); } -static size_t reads(void *ip, uint8_t *bp, size_t n) { +static size_t read(void *ip, uint8_t *bp, size_t n) { return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, TIME_INFINITE); @@ -99,7 +99,7 @@ static chnflags_t getflags(void *ip) { } static const struct SerialDriverVMT vmt = { - writes, reads, put, get, + write, read, put, get, putt, gett, writet, readt, getflags }; diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 466b65b0a..c3e9ae184 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -61,13 +61,13 @@ static cdc_linecoding_t linecoding = { * Interface implementation. */ -static size_t writes(void *ip, const uint8_t *bp, size_t n) { +static size_t write(void *ip, const uint8_t *bp, size_t n) { return chOQWriteTimeout(&((SerialUSBDriver *)ip)->oqueue, bp, n, TIME_INFINITE); } -static size_t reads(void *ip, uint8_t *bp, size_t n) { +static size_t read(void *ip, uint8_t *bp, size_t n) { return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, TIME_INFINITE); @@ -108,7 +108,7 @@ static chnflags_t getflags(void *ip) { } static const struct SerialUSBDriverVMT vmt = { - writes, reads, put, get, + write, read, put, get, putt, gett, writet, readt, getflags }; -- cgit v1.2.3 From 80443125b286868f18342a9e6884a65b3218bf99 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 25 Jun 2012 16:53:21 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4347 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 449 ++++++++++++++++++++------------------------------- os/hal/src/sdc.c | 4 +- 2 files changed, 174 insertions(+), 279 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 0be587d14..1b9271944 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -49,10 +49,10 @@ /*===========================================================================*/ /* Forward declarations required by mmc_vmt.*/ -bool_t mmc_read(void *instance, uint32_t startblk, - uint8_t *buffer, uint32_t n); -bool_t mmc_write(void *instance, uint32_t startblk, - const uint8_t *buffer, uint32_t n); +static bool_t mmc_read(void *instance, uint32_t startblk, + uint8_t *buffer, uint32_t n); +static bool_t mmc_write(void *instance, uint32_t startblk, + const uint8_t *buffer, uint32_t n); /** * @brief Virtual methods table. @@ -100,36 +100,36 @@ static const uint8_t crc7_lookup_table[256] = { /* Driver local functions. */ /*===========================================================================*/ -bool_t mmc_read(void *instance, uint32_t startblk, +static bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n) { if (mmcStartSequentialRead((MMCDriver *)instance, startblk)) - return TRUE; + return CH_FAILED; while (n > 0) { if (mmcSequentialRead((MMCDriver *)instance, buffer)) - return TRUE; + return CH_FAILED; buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialRead((MMCDriver *)instance)) - return TRUE; - return FALSE; + return CH_FAILED; + return CH_SUCCESS; } -bool_t mmc_write(void *instance, uint32_t startblk, +static bool_t mmc_write(void *instance, uint32_t startblk, const uint8_t *buffer, uint32_t n) { if (mmcStartSequentialWrite((MMCDriver *)instance, startblk)) - return TRUE; + return CH_FAILED; while (n > 0) { if (mmcSequentialWrite((MMCDriver *)instance, buffer)) - return TRUE; + return CH_FAILED; buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialWrite((MMCDriver *)instance)) - return TRUE; - return FALSE; + return CH_FAILED; + return CH_SUCCESS; } /** @@ -147,38 +147,6 @@ static uint8_t crc7(uint8_t crc, const uint8_t *buffer, size_t len) { return crc; } -/** - * @brief Insertion monitor timer callback function. - * - * @param[in] p pointer to the @p MMCDriver object - * - * @notapi - */ -static void tmrfunc(void *p) { - MMCDriver *mmcp = p; - - chSysLockFromIsr(); - if (mmcp->cnt > 0) { - if (mmc_lld_is_card_inserted(mmcp)) { - if (--mmcp->cnt == 0) { - mmcp->state = MMC_INSERTED; - chEvtBroadcastI(&mmcp->inserted_event); - } - } - else - mmcp->cnt = MMC_POLLING_INTERVAL; - } - else { - if (!mmc_lld_is_card_inserted(mmcp)) { - mmcp->state = MMC_WAIT; - mmcp->cnt = MMC_POLLING_INTERVAL; - chEvtBroadcastI(&mmcp->removed_event); - } - } - chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); - chSysUnlockFromIsr(); -} - /** * @brief Waits an idle condition. * @@ -325,8 +293,8 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, * @param[out] csd pointer to the CSD buffer * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @notapi */ @@ -338,7 +306,7 @@ static bool_t read_CxD(MMCDriver *mmcp, uint8_t cmd, uint32_t cxd[4]) { send_hdr(mmcp, cmd, 0); if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->config->spip); - return TRUE; + return CH_FAILED; } /* Wait for data availability.*/ @@ -359,10 +327,10 @@ static bool_t read_CxD(MMCDriver *mmcp, uint8_t cmd, uint32_t cxd[4]) { spiIgnore(mmcp->config->spip, 2); spiUnselect(mmcp->config->spip); - return FALSE; + return CH_SUCCESS; } } - return TRUE; + return CH_FAILED; } /** @@ -415,8 +383,6 @@ void mmcObjectInit(MMCDriver *mmcp) { mmcp->state = MMC_STOP; mmcp->config = NULL; mmcp->block_addresses = FALSE; - chEvtInit(&mmcp->inserted_event); - chEvtInit(&mmcp->removed_event); } /** @@ -432,11 +398,10 @@ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); chSysLock(); - chDbgAssert(mmcp->state == MMC_STOP, "mmcStart(), #1", "invalid state"); + chDbgAssert((mmcp->state == MMC_STOP) || (mmcp->state == MMC_READY), + "mmcStart(), #1", "invalid state"); mmcp->config = config; - mmcp->state = MMC_WAIT; - mmcp->cnt = MMC_POLLING_INTERVAL; - chVTSetI(&mmcp->vt, MS2ST(MMC_POLLING_DELAY), tmrfunc, mmcp); + mmcp->state = MMC_READY; chSysUnlock(); } @@ -452,14 +417,9 @@ void mmcStop(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStop"); chSysLock(); - chDbgAssert((mmcp->state != MMC_UNINIT) && - (mmcp->state != MMC_READING) && - (mmcp->state != MMC_WRITING), + chDbgAssert((mmcp->state == MMC_STOP) || (mmcp->state == MMC_READY), "mmcStop(), #1", "invalid state"); - if (mmcp->state != MMC_STOP) { - mmcp->state = MMC_STOP; - chVTResetI(&mmcp->vt); - } + mmcp->state = MMC_STOP; chSysUnlock(); spiStop(mmcp->config->spip); } @@ -475,111 +435,102 @@ void mmcStop(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval FALSE the operation succeeded and the driver is now + * @retval CH_FAILED the operation succeeded and the driver is now * in the @p MMC_READY state. - * @retval TRUE the operation failed. + * @retval CH_SUCCESS the operation failed. * * @api */ bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; - bool_t result; chDbgCheck(mmcp != NULL, "mmcConnect"); - chDbgAssert((mmcp->state != MMC_UNINIT) && (mmcp->state != MMC_STOP), + chSysLock(); + chDbgAssert((mmcp->state == MMC_READY) || (mmcp->state == MMC_ACTIVE), "mmcConnect(), #1", "invalid state"); + mmcp->state = MMC_CONNECTING; + chSysUnlock(); + + /* Slow clock mode and 128 clock pulses.*/ + spiStart(mmcp->config->spip, mmcp->config->lscfg); + spiIgnore(mmcp->config->spip, 16); + + /* SPI mode selection.*/ + i = 0; + while (TRUE) { + if (send_command_R1(mmcp, MMCSD_CMD_GO_IDLE_STATE, 0) == 0x01) + break; + if (++i >= MMC_CMD0_RETRY) + goto failed; + chThdSleepMilliseconds(10); + } - if (mmcp->state == MMC_INSERTED) { - /* Slow clock mode and 128 clock pulses.*/ - spiStart(mmcp->config->spip, mmcp->config->lscfg); - spiIgnore(mmcp->config->spip, 16); + /* Try to detect if this is a high capacity card and switch to block + addresses if possible. + This method is based on "How to support SDC Ver2 and high capacity cards" + by ElmChan.*/ + uint8_t r3[4]; + if (send_command_R3(mmcp, MMCSD_CMD_SEND_IF_COND, + MMCSD_CMD8_PATTERN, r3) != 0x05) { - /* SPI mode selection.*/ + /* Switch to SDHC mode.*/ i = 0; while (TRUE) { - if (send_command_R1(mmcp, MMCSD_CMD_GO_IDLE_STATE, 0) == 0x01) + if ((send_command_R1(mmcp, MMCSD_CMD_APP_CMD, 0) == 0x01) && + (send_command_R3(mmcp, MMCSD_CMD_APP_OP_COND, + 0x400001aa, r3) == 0x00)) break; - if (++i >= MMC_CMD0_RETRY) - return TRUE; + + if (++i >= MMC_ACMD41_RETRY) + goto failed; chThdSleepMilliseconds(10); } - /* Try to detect if this is a high capacity card and switch to block - addresses if possible. - This method is based on "How to support SDC Ver2 and high capacity cards" - by ElmChan.*/ - uint8_t r3[4]; - if (send_command_R3(mmcp, MMCSD_CMD_SEND_IF_COND, - MMCSD_CMD8_PATTERN, r3) != 0x05) { - - /* Switch to SDHC mode.*/ - i = 0; - while (TRUE) { - if ((send_command_R1(mmcp, MMCSD_CMD_APP_CMD, 0) == 0x01) && - (send_command_R3(mmcp, MMCSD_CMD_APP_OP_COND, - 0x400001aa, r3) == 0x00)) - break; - - if (++i >= MMC_ACMD41_RETRY) - return TRUE; - chThdSleepMilliseconds(10); - } + /* Execute dedicated read on OCR register */ + send_command_R3(mmcp, MMCSD_CMD_READ_OCR, 0, r3); - /* Execute dedicated read on OCR register */ - send_command_R3(mmcp, MMCSD_CMD_READ_OCR, 0, r3); + /* Check if CCS is set in response. Card operates in block mode if set.*/ + if(r3[0] & 0x40) + mmcp->block_addresses = TRUE; + } - /* Check if CCS is set in response. Card operates in block mode if set.*/ - if(r3[0] & 0x40) - mmcp->block_addresses = TRUE; - } + /* Initialization.*/ + i = 0; + while (TRUE) { + uint8_t b = send_command_R1(mmcp, MMCSD_CMD_INIT, 0); + if (b == 0x00) + break; + if (b != 0x01) + goto failed; + if (++i >= MMC_CMD1_RETRY) + goto failed; + chThdSleepMilliseconds(10); + } - /* Initialization.*/ - i = 0; - while (TRUE) { - uint8_t b = send_command_R1(mmcp, MMCSD_CMD_INIT, 0); - if (b == 0x00) - break; - if (b != 0x01) - return TRUE; - if (++i >= MMC_CMD1_RETRY) - return TRUE; - chThdSleepMilliseconds(10); - } + /* Initialization complete, full speed.*/ + spiStart(mmcp->config->spip, mmcp->config->hscfg); - /* Initialization complete, full speed.*/ - spiStart(mmcp->config->spip, mmcp->config->hscfg); - - /* Setting block size.*/ - if (send_command_R1(mmcp, MMCSD_CMD_SET_BLOCKLEN, - MMCSD_BLOCK_SIZE) != 0x00) - return TRUE; - - /* Determine capacity.*/ - if (read_CxD(mmcp, MMCSD_CMD_SEND_CSD, mmcp->csd)) - return TRUE; - mmcp->capacity = mmcsdGetCapacity(mmcp->csd); - if (mmcp->capacity == 0) - return TRUE; - - if (read_CxD(mmcp, MMCSD_CMD_SEND_CID, mmcp->cid)) - return TRUE; - - /* Transition to MMC_READY state (if not extracted).*/ - chSysLock(); - if (mmcp->state == MMC_INSERTED) { - mmcp->state = MMC_READY; - result = FALSE; - } - else - result = TRUE; - chSysUnlock(); - return result; - } - if (mmcp->state == MMC_READY) - return FALSE; - /* Any other state is invalid.*/ - return TRUE; + /* Setting block size.*/ + if (send_command_R1(mmcp, MMCSD_CMD_SET_BLOCKLEN, + MMCSD_BLOCK_SIZE) != 0x00) + goto failed; + + /* Determine capacity.*/ + if (read_CxD(mmcp, MMCSD_CMD_SEND_CSD, mmcp->csd)) + goto failed; + mmcp->capacity = mmcsdGetCapacity(mmcp->csd); + if (mmcp->capacity == 0) + goto failed; + + if (read_CxD(mmcp, MMCSD_CMD_SEND_CID, mmcp->cid)) + goto failed; + + mmcp->state = MMC_READY; + return CH_SUCCESS; +failed: + mmcp->state = MMC_READY; + return CH_FAILED; } /** @@ -588,34 +539,32 @@ bool_t mmcConnect(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. * - * @retval FALSE the operation succeeded and the driver is now + * @retval CH_FAILED the operation succeeded and the driver is now * in the @p MMC_INSERTED state. - * @retval TRUE the operation failed. + * @retval CH_SUCCESS the operation failed. * * @api */ bool_t mmcDisconnect(MMCDriver *mmcp) { - bool_t status; chDbgCheck(mmcp != NULL, "mmcDisconnect"); - chDbgAssert((mmcp->state != MMC_UNINIT) && (mmcp->state != MMC_STOP), + chSysLock(); + chDbgAssert((mmcp->state == MMC_READY) || (mmcp->state == MMC_ACTIVE), "mmcDisconnect(), #1", "invalid state"); - switch (mmcp->state) { - case MMC_READY: - /* Wait for the pending write operations to complete.*/ - sync(mmcp); - chSysLock(); - if (mmcp->state == MMC_READY) - mmcp->state = MMC_INSERTED; + if (mmcp->state == MMC_READY) { chSysUnlock(); - case MMC_INSERTED: - status = FALSE; - default: - status = TRUE; + return CH_SUCCESS; } + mmcp->state = MMC_DISCONNECTING; + chSysUnlock(); + + /* Wait for the pending write operations to complete.*/ + sync(mmcp); spiStop(mmcp->config->spip); - return status; + + mmcp->state = MMC_READY; + return CH_SUCCESS; } /** @@ -625,8 +574,8 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { * @param[in] startblk first block to read * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -635,13 +584,13 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); chSysLock(); - if (mmcp->state != MMC_READY) { - chSysUnlock(); - return TRUE; - } + chDbgAssert(mmcp->state == MMC_ACTIVE, + "mmcStartSequentialRead(), #1", "invalid state"); mmcp->state = MMC_READING; chSysUnlock(); + /* (Re)starting the SPI in case it has been reprogrammed externally, it can + happen if the SPI bus is shared among multiple peripherals.*/ spiStart(mmcp->config->spip, mmcp->config->hscfg); spiSelect(mmcp->config->spip); @@ -651,14 +600,10 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->config->spip); - chSysLock(); - if (mmcp->state == MMC_READING) - mmcp->state = MMC_READY; - chSysUnlock(); - return TRUE; + mmcp->state = MMC_READY; + return CH_FAILED; } - return FALSE; + return CH_SUCCESS; } /** @@ -668,8 +613,8 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { * @param[out] buffer pointer to the read buffer * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -678,12 +623,8 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); - chSysLock(); - if (mmcp->state != MMC_READING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_READING) + return CH_FAILED; for (i = 0; i < MMC_WAIT_DATA; i++) { spiReceive(mmcp->config->spip, 1, buffer); @@ -691,16 +632,13 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { spiReceive(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer); /* CRC ignored. */ spiIgnore(mmcp->config->spip, 2); - return FALSE; + return CH_SUCCESS; } } /* Timeout.*/ spiUnselect(mmcp->config->spip); - chSysLock(); - if (mmcp->state == MMC_READING) - mmcp->state = MMC_READY; - chSysUnlock(); - return TRUE; + mmcp->state = MMC_READY; + return CH_FAILED; } /** @@ -709,37 +647,28 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { static const uint8_t stopcmd[] = {0x40 | MMCSD_CMD_STOP_TRANSMISSION, 0, 0, 0, 0, 1, 0xFF}; - bool_t result; chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); - chSysLock(); - if (mmcp->state != MMC_READING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_READING) + return CH_FAILED; spiSend(mmcp->config->spip, sizeof(stopcmd), stopcmd); /* result = recvr1(mmcp) != 0x00;*/ /* Note, ignored r1 response, it can be not zero, unknown issue.*/ - recvr1(mmcp); - result = FALSE; - spiUnselect(mmcp->config->spip); + (void) recvr1(mmcp); - chSysLock(); - if (mmcp->state == MMC_READING) - mmcp->state = MMC_READY; - chSysUnlock(); - return result; + spiUnselect(mmcp->config->spip); + mmcp->state = MMC_READY; + return CH_SUCCESS; } /** @@ -749,8 +678,8 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { * @param[in] startblk first block to write * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -759,10 +688,8 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); chSysLock(); - if (mmcp->state != MMC_READY) { - chSysUnlock(); - return TRUE; - } + chDbgAssert(mmcp->state == MMC_ACTIVE, + "mmcStartSequentialWrite(), #1", "invalid state"); mmcp->state = MMC_WRITING; chSysUnlock(); @@ -774,16 +701,11 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE); - if (recvr1(mmcp) != 0x00) { - spiUnselect(mmcp->config->spip); - chSysLock(); - if (mmcp->state == MMC_WRITING) - mmcp->state = MMC_READY; - chSysUnlock(); - return TRUE; + mmcp->state = MMC_READY; + return CH_FAILED; } - return FALSE; + return CH_SUCCESS; } /** @@ -793,8 +715,8 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { * @param[out] buffer pointer to the write buffer * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -804,12 +726,8 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialWrite"); - chSysLock(); - if (mmcp->state != MMC_WRITING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_WRITING) + return CH_FAILED; spiSend(mmcp->config->spip, sizeof(start), start); /* Data prologue. */ spiSend(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);/* Data. */ @@ -817,16 +735,13 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { spiReceive(mmcp->config->spip, 1, b); if ((b[0] & 0x1F) == 0x05) { wait(mmcp); - return FALSE; + return CH_SUCCESS; } /* Error.*/ spiUnselect(mmcp->config->spip); - chSysLock(); - if (mmcp->state == MMC_WRITING) - mmcp->state = MMC_READY; - chSysUnlock(); - return TRUE; + mmcp->state = MMC_READY; + return CH_FAILED; } /** @@ -835,8 +750,8 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -845,24 +760,15 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); - chSysLock(); - if (mmcp->state != MMC_WRITING) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_WRITING) + return CH_FAILED; spiSend(mmcp->config->spip, sizeof(stop), stop); spiUnselect(mmcp->config->spip); chSysLock(); - if (mmcp->state == MMC_WRITING) { - mmcp->state = MMC_READY; - chSysUnlock(); - return FALSE; - } - chSysUnlock(); - return TRUE; + mmcp->state = MMC_READY; + return CH_SUCCESS; } /** @@ -871,8 +777,8 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -880,16 +786,11 @@ bool_t mmcSync(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcSync"); - chSysLock(); - if (mmcp->state != MMC_READY) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_READY) + return CH_FAILED; sync(mmcp); - - return FALSE; + return CH_SUCCESS; } /** @@ -899,27 +800,21 @@ bool_t mmcSync(MMCDriver *mmcp) { * @param[out] bdip pointer to a @p BlockDeviceInfo structure * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { - chDbgCheck((mmcp != NULL) && (bdip != NULL), "mmcGetInfo"); - chSysLock(); - if (mmcp->state != MMC_READY) { - chSysUnlock(); - return TRUE; - } - chSysUnlock(); + if (mmcp->state != MMC_READY) + return CH_FAILED; bdip->blk_num = mmcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; - - return FALSE; + return CH_SUCCESS; } /** @@ -930,8 +825,8 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { * @param[in] endblk ending block number * * @return The operation status. - * @retval FALSE the operation succeeded. - * @retval TRUE the operation failed. + * @retval CH_FAILED the operation succeeded. + * @retval CH_SUCCESS the operation failed. * * @api */ @@ -940,15 +835,15 @@ bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) { chDbgCheck((mmcp != NULL), "mmcErase"); if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk)) - return TRUE; + return CH_FAILED; if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk)) - return TRUE; + return CH_FAILED; if (send_command_R1(mmcp, MMCSD_CMD_ERASE, 0)) - return TRUE; + return CH_FAILED; - return FALSE; + return CH_SUCCESS; } diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 728f05566..19829f9b8 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -230,7 +230,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { #if SDC_MMC_SUPPORT if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { /* TODO: MMC initialization.*/ - return CH_FAILED; + goto failed; } else #endif /* SDC_MMC_SUPPORT */ @@ -337,7 +337,7 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcDisconnect"); chSysLock(); - chDbgAssert(sdcp->state == SDC_ACTIVE, + chDbgAssert((sdcp->state == SDC_READY) || (sdcp->state == SDC_ACTIVE), "sdcDisconnect(), #1", "invalid state"); if (sdcp->state == SDC_READY) { chSysUnlock(); -- cgit v1.2.3 From 853b0fd51c80d9b8640639321a950f16800d57d4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 26 Jun 2012 18:02:43 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4348 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 113 +++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 52 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 1b9271944..96167a950 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -380,7 +380,7 @@ void mmcInit(void) { void mmcObjectInit(MMCDriver *mmcp) { mmcp->vmt = &mmc_vmt; - mmcp->state = MMC_STOP; + mmcp->state = BLK_STOP; mmcp->config = NULL; mmcp->block_addresses = FALSE; } @@ -396,13 +396,11 @@ void mmcObjectInit(MMCDriver *mmcp) { void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { chDbgCheck((mmcp != NULL) && (config != NULL), "mmcStart"); - - chSysLock(); - chDbgAssert((mmcp->state == MMC_STOP) || (mmcp->state == MMC_READY), + chDbgAssert((mmcp->state == BLK_STOP) || (mmcp->state == BLK_ACTIVE), "mmcStart(), #1", "invalid state"); + mmcp->config = config; - mmcp->state = MMC_READY; - chSysUnlock(); + mmcp->state = BLK_ACTIVE; } /** @@ -415,13 +413,11 @@ void mmcStart(MMCDriver *mmcp, const MMCConfig *config) { void mmcStop(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStop"); - - chSysLock(); - chDbgAssert((mmcp->state == MMC_STOP) || (mmcp->state == MMC_READY), + chDbgAssert((mmcp->state == BLK_STOP) || (mmcp->state == BLK_ACTIVE), "mmcStop(), #1", "invalid state"); - mmcp->state = MMC_STOP; - chSysUnlock(); + spiStop(mmcp->config->spip); + mmcp->state = BLK_STOP; } /** @@ -446,11 +442,11 @@ bool_t mmcConnect(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcConnect"); - chSysLock(); - chDbgAssert((mmcp->state == MMC_READY) || (mmcp->state == MMC_ACTIVE), + chDbgAssert((mmcp->state == BLK_ACTIVE) || (mmcp->state == BLK_READY), "mmcConnect(), #1", "invalid state"); - mmcp->state = MMC_CONNECTING; - chSysUnlock(); + + /* Connection procedure in progress.*/ + mmcp->state = BLK_CONNECTING; /* Slow clock mode and 128 clock pulses.*/ spiStart(mmcp->config->spip, mmcp->config->lscfg); @@ -491,7 +487,7 @@ bool_t mmcConnect(MMCDriver *mmcp) { send_command_R3(mmcp, MMCSD_CMD_READ_OCR, 0, r3); /* Check if CCS is set in response. Card operates in block mode if set.*/ - if(r3[0] & 0x40) + if (r3[0] & 0x40) mmcp->block_addresses = TRUE; } @@ -526,10 +522,13 @@ bool_t mmcConnect(MMCDriver *mmcp) { if (read_CxD(mmcp, MMCSD_CMD_SEND_CID, mmcp->cid)) goto failed; - mmcp->state = MMC_READY; + mmcp->state = BLK_READY; return CH_SUCCESS; + + /* Connection failed, state reset to BLK_ACTIVE.*/ failed: - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); + mmcp->state = BLK_ACTIVE; return CH_FAILED; } @@ -550,20 +549,20 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcDisconnect"); chSysLock(); - chDbgAssert((mmcp->state == MMC_READY) || (mmcp->state == MMC_ACTIVE), + chDbgAssert((mmcp->state == BLK_ACTIVE) || (mmcp->state == BLK_READY), "mmcDisconnect(), #1", "invalid state"); - if (mmcp->state == MMC_READY) { + if (mmcp->state == BLK_ACTIVE) { chSysUnlock(); return CH_SUCCESS; } - mmcp->state = MMC_DISCONNECTING; + mmcp->state = BLK_DISCONNECTING; chSysUnlock(); /* Wait for the pending write operations to complete.*/ sync(mmcp); - spiStop(mmcp->config->spip); - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); + mmcp->state = BLK_ACTIVE; return CH_SUCCESS; } @@ -582,25 +581,24 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialRead"); - - chSysLock(); - chDbgAssert(mmcp->state == MMC_ACTIVE, + chDbgAssert(mmcp->state == BLK_READY, "mmcStartSequentialRead(), #1", "invalid state"); - mmcp->state = MMC_READING; - chSysUnlock(); + + /* Read operation in progress.*/ + mmcp->state = BLK_READING; /* (Re)starting the SPI in case it has been reprogrammed externally, it can happen if the SPI bus is shared among multiple peripherals.*/ spiStart(mmcp->config->spip, mmcp->config->hscfg); spiSelect(mmcp->config->spip); - if(mmcp->block_addresses) + if (mmcp->block_addresses) send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk); else send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); return CH_FAILED; } return CH_SUCCESS; @@ -623,7 +621,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); - if (mmcp->state != MMC_READING) + if (mmcp->state != BLK_READING) return CH_FAILED; for (i = 0; i < MMC_WAIT_DATA; i++) { @@ -637,7 +635,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { } /* Timeout.*/ spiUnselect(mmcp->config->spip); - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); return CH_FAILED; } @@ -658,7 +656,7 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStopSequentialRead"); - if (mmcp->state != MMC_READING) + if (mmcp->state != BLK_READING) return CH_FAILED; spiSend(mmcp->config->spip, sizeof(stopcmd), stopcmd); @@ -666,8 +664,9 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { /* Note, ignored r1 response, it can be not zero, unknown issue.*/ (void) recvr1(mmcp); + /* Read operation finished.*/ spiUnselect(mmcp->config->spip); - mmcp->state = MMC_READY; + mmcp->state = BLK_READY; return CH_SUCCESS; } @@ -686,23 +685,22 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); - - chSysLock(); - chDbgAssert(mmcp->state == MMC_ACTIVE, + chDbgAssert(mmcp->state == BLK_READY, "mmcStartSequentialWrite(), #1", "invalid state"); - mmcp->state = MMC_WRITING; - chSysUnlock(); + + /* Write operation in progress.*/ + mmcp->state = BLK_WRITING; spiStart(mmcp->config->spip, mmcp->config->hscfg); spiSelect(mmcp->config->spip); - if(mmcp->block_addresses) + if (mmcp->block_addresses) send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, startblk); else send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); return CH_FAILED; } return CH_SUCCESS; @@ -726,7 +724,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialWrite"); - if (mmcp->state != MMC_WRITING) + if (mmcp->state != BLK_WRITING) return CH_FAILED; spiSend(mmcp->config->spip, sizeof(start), start); /* Data prologue. */ @@ -740,7 +738,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { /* Error.*/ spiUnselect(mmcp->config->spip); - mmcp->state = MMC_READY; + spiStop(mmcp->config->spip); return CH_FAILED; } @@ -760,14 +758,14 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); - if (mmcp->state != MMC_WRITING) + if (mmcp->state != BLK_WRITING) return CH_FAILED; spiSend(mmcp->config->spip, sizeof(stop), stop); spiUnselect(mmcp->config->spip); - chSysLock(); - mmcp->state = MMC_READY; + /* Write operation finished.*/ + mmcp->state = BLK_READY; return CH_SUCCESS; } @@ -786,7 +784,7 @@ bool_t mmcSync(MMCDriver *mmcp) { chDbgCheck(mmcp != NULL, "mmcSync"); - if (mmcp->state != MMC_READY) + if (mmcp->state != BLK_READY) return CH_FAILED; sync(mmcp); @@ -809,11 +807,12 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { chDbgCheck((mmcp != NULL) && (bdip != NULL), "mmcGetInfo"); - if (mmcp->state != MMC_READY) + if (mmcp->state != BLK_READY) return CH_FAILED; bdip->blk_num = mmcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; + return CH_SUCCESS; } @@ -834,18 +833,28 @@ bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) { chDbgCheck((mmcp != NULL), "mmcErase"); + /* Handling command differences between HC and normal cards.*/ + if (!mmcp->block_addresses) { + startblk *= MMCSD_BLOCK_SIZE; + endblk *= MMCSD_BLOCK_SIZE; + } + if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk)) - return CH_FAILED; + goto failed; if (send_command_R1(mmcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk)) - return CH_FAILED; + goto failed; if (send_command_R1(mmcp, MMCSD_CMD_ERASE, 0)) - return CH_FAILED; + goto failed; return CH_SUCCESS; -} + /* Command failed, state reset to BLK_ACTIVE.*/ +failed: + spiStop(mmcp->config->spip); + return CH_FAILED; +} #endif /* HAL_USE_MMC_SPI */ -- cgit v1.2.3 From 9492ff4976cb9e8af40c9a6715b7d9f7ef5f9428 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 26 Jun 2012 18:18:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4349 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 111 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 54 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 19829f9b8..2773ab79c 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -125,10 +125,10 @@ void sdcInit(void) { */ void sdcObjectInit(SDCDriver *sdcp) { - sdcp->vmt = &sdc_vmt; - sdcp->state = SDC_STOP; - sdcp->errors = SDC_NO_ERROR; - sdcp->config = NULL; + sdcp->vmt = &sdc_vmt; + sdcp->state = BLK_STOP; + sdcp->errors = SDC_NO_ERROR; + sdcp->config = NULL; sdcp->capacity = 0; } @@ -147,11 +147,11 @@ void sdcStart(SDCDriver *sdcp, const SDCConfig *config) { chDbgCheck(sdcp != NULL, "sdcStart"); chSysLock(); - chDbgAssert((sdcp->state == SDC_STOP) || (sdcp->state == SDC_READY), + chDbgAssert((sdcp->state == BLK_STOP) || (sdcp->state == BLK_ACTIVE), "sdcStart(), #1", "invalid state"); sdcp->config = config; sdc_lld_start(sdcp); - sdcp->state = SDC_READY; + sdcp->state = BLK_ACTIVE; chSysUnlock(); } @@ -167,17 +167,17 @@ void sdcStop(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcStop"); chSysLock(); - chDbgAssert((sdcp->state == SDC_STOP) || (sdcp->state == SDC_READY), + chDbgAssert((sdcp->state == BLK_STOP) || (sdcp->state == BLK_ACTIVE), "sdcStop(), #1", "invalid state"); sdc_lld_stop(sdcp); - sdcp->state = SDC_STOP; + sdcp->state = BLK_STOP; chSysUnlock(); } /** * @brief Performs the initialization procedure on the inserted card. * @details This function should be invoked when a card is inserted and - * brings the driver in the @p SDC_ACTIVE state where it is possible + * brings the driver in the @p BLK_READY state where it is possible * to perform read and write operations. * * @param[in] sdcp pointer to the @p SDCDriver object @@ -192,12 +192,11 @@ bool_t sdcConnect(SDCDriver *sdcp) { uint32_t resp[1]; chDbgCheck(sdcp != NULL, "sdcConnect"); - - chSysLock(); - chDbgAssert((sdcp->state == SDC_READY) || (sdcp->state == SDC_ACTIVE), + chDbgAssert((sdcp->state == BLK_ACTIVE) || (sdcp->state == BLK_READY), "mmcConnect(), #1", "invalid state"); - sdcp->state = SDC_CONNECTING; - chSysUnlock(); + + /* Connection procedure in progress.*/ + sdcp->state = BLK_CONNECTING; /* Card clock initialization.*/ sdc_lld_start_clk(sdcp); @@ -228,7 +227,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { } #if SDC_MMC_SUPPORT - if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { + if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) { /* TODO: MMC initialization.*/ goto failed; } @@ -311,13 +310,13 @@ bool_t sdcConnect(SDCDriver *sdcp) { goto failed; /* Initialization complete.*/ - sdcp->state = SDC_ACTIVE; + sdcp->state = BLK_READY; return CH_SUCCESS; - /* Initialization failed.*/ + /* Connection failed, state reset to BLK_ACTIVE.*/ failed: sdc_lld_stop_clk(sdcp); - sdcp->state = SDC_READY; + sdcp->state = BLK_ACTIVE; return CH_FAILED; } @@ -337,29 +336,31 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcDisconnect"); chSysLock(); - chDbgAssert((sdcp->state == SDC_READY) || (sdcp->state == SDC_ACTIVE), + chDbgAssert((sdcp->state == BLK_ACTIVE) || (sdcp->state == BLK_READY), "sdcDisconnect(), #1", "invalid state"); - if (sdcp->state == SDC_READY) { + if (sdcp->state == BLK_ACTIVE) { chSysUnlock(); return CH_SUCCESS; } - sdcp->state = SDC_DISCONNECTING; + sdcp->state = BLK_DISCONNECTING; chSysUnlock(); /* Waits for eventual pending operations completion.*/ - if (_sdc_wait_for_transfer_state(sdcp)) + if (_sdc_wait_for_transfer_state(sdcp)) { + sdc_lld_stop_clk(sdcp); + sdcp->state = BLK_ACTIVE; return CH_FAILED; + } /* Card clock stopped.*/ sdc_lld_stop_clk(sdcp); - - sdcp->state = SDC_READY; + sdcp->state = BLK_ACTIVE; return CH_SUCCESS; } /** * @brief Reads one or more blocks. - * @pre The driver must be in the @p SDC_ACTIVE state after a successful + * @pre The driver must be in the @p BLK_READY state after a successful * sdcConnect() invocation. * * @param[in] sdcp pointer to the @p SDCDriver object @@ -378,25 +379,26 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, bool_t status; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead"); + chDbgAssert(sdcp->state == BLK_READY, "sdcRead(), #1", "invalid state"); if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; return CH_FAILED; } - chSysLock(); - chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcRead(), #1", "invalid state"); - sdcp->state = SDC_READING; - chSysUnlock(); + /* Read operation in progress.*/ + sdcp->state = BLK_READING; status = sdc_lld_read(sdcp, startblk, buf, n); - sdcp->state = SDC_ACTIVE; + + /* Read operation finished.*/ + sdcp->state = BLK_READY; return status; } /** * @brief Writes one or more blocks. - * @pre The driver must be in the @p SDC_ACTIVE state after a successful + * @pre The driver must be in the @p BLK_READY state after a successful * sdcConnect() invocation. * * @param[in] sdcp pointer to the @p SDCDriver object @@ -415,19 +417,20 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, bool_t status; chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcWrite"); + chDbgAssert(sdcp->state == BLK_READY, "sdcWrite(), #1", "invalid state"); if ((startblk + n - 1) > sdcp->capacity){ sdcp->errors |= SDC_OVERFLOW_ERROR; return CH_FAILED; } - chSysLock(); - chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcWrite(), #1", "invalid state"); - sdcp->state = SDC_WRITING; - chSysUnlock(); + /* Write operation in progress.*/ + sdcp->state = BLK_WRITING; status = sdc_lld_write(sdcp, startblk, buf, n); - sdcp->state = SDC_ACTIVE; + + /* Write operation finished.*/ + sdcp->state = BLK_READY; return status; } @@ -442,6 +445,8 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcGetAndClearErrors"); + chDbgAssert(sdcp->state == BLK_READY, + "sdcGetAndClearErrors(), #1", "invalid state"); chSysLock(); sdcflags_t flags = sdcp->errors; @@ -465,12 +470,8 @@ bool_t sdcSync(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcSync"); - chSysLock(); - if (sdcp->state != SDC_READY) { - chSysUnlock(); + if (sdcp->state != BLK_READY) return CH_FAILED; - } - chSysUnlock(); return sdc_lld_sync(sdcp); } @@ -489,15 +490,10 @@ bool_t sdcSync(SDCDriver *sdcp) { */ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) { - chDbgCheck((sdcp != NULL) && (bdip != NULL), "sdcGetInfo"); - chSysLock(); - if (sdcp->state != SDC_READY) { - chSysUnlock(); + if (sdcp->state != BLK_READY) return CH_FAILED; - } - chSysUnlock(); bdip->blk_num = sdcp->capacity; bdip->blk_size = MMCSD_BLOCK_SIZE; @@ -523,29 +519,36 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { uint32_t resp[1]; chDbgCheck((sdcp != NULL), "sdcErase"); + chDbgAssert(sdcp->state == BLK_READY, "sdcErase(), #1", "invalid state"); - /* Driver handles data in 512 bytes blocks (just like HC cards). But if we - have not HC card than we must convert address from blocks to bytes.*/ + /* Handling command differences between HC and normal cards.*/ if (!(sdcp->cardmode & SDC_MODE_HIGH_CAPACITY)) { startblk *= MMCSD_BLOCK_SIZE; endblk *= MMCSD_BLOCK_SIZE; } - _sdc_wait_for_transfer_state( sdcp ); + _sdc_wait_for_transfer_state(sdcp); - if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_START, + startblk, resp) != CH_SUCCESS) || + MMCSD_R1_ERROR(resp[0])) return CH_FAILED; - if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_END, + endblk, resp) != CH_SUCCESS) || + MMCSD_R1_ERROR(resp[0])) return CH_FAILED; - if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE, 0, resp) != CH_SUCCESS || MMCSD_R1_ERROR(resp[0])) + if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE, + 0, resp) != CH_SUCCESS) || + MMCSD_R1_ERROR(resp[0])) return CH_FAILED; /* Quick sleep to allow it to transition to programming or receiving state */ + /* TODO: ??????????????????????????? */ /* Wait for it to return to transfer state to indicate it has finished erasing */ - _sdc_wait_for_transfer_state( sdcp ); + _sdc_wait_for_transfer_state(sdcp); return CH_SUCCESS; } -- cgit v1.2.3 From d2e24645e8fb436c24781c154d12ebeec6791b7a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 27 Jun 2012 18:15:59 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4352 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 7f9d0456d..afe6f471c 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -125,7 +125,7 @@ static bool_t default_handler(USBDriver *usbp) { /* Handling descriptor requests from the host.*/ dp = usbp->config->get_descriptor_cb( usbp, usbp->setup[3], usbp->setup[2], - usb_lld_fetch_word(&usbp->setup[4])); + usbFetchWord(&usbp->setup[4])); if (dp == NULL) return FALSE; usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); @@ -633,7 +633,7 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { /* Transfer preparation. The request handler must have populated correctly the fields ep0next, ep0n and ep0endcb using the macro usbSetupTransfer().*/ - max = usb_lld_fetch_word(&usbp->setup[6]); + max = usbFetchWord(&usbp->setup[6]); /* The transfer size cannot exceed the specified amount.*/ if (usbp->ep0n > max) usbp->ep0n = max; @@ -695,7 +695,7 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { (void)ep; switch (usbp->ep0state) { case USB_EP0_TX: - max = usb_lld_fetch_word(&usbp->setup[6]); + max = usbFetchWord(&usbp->setup[6]); /* If the transmitted size is less than the requested size and it is a multiple of the maximum packet size then a zero size packet must be transmitted.*/ -- cgit v1.2.3 From bfa477e96da26b31d6907260b72037c67cd30d3d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 30 Jun 2012 14:41:51 +0000 Subject: Fixed few newly introduced documentation errors. Improved card detection. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4364 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 96167a950..f8056f392 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -293,8 +293,8 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg, * @param[out] csd pointer to the CSD buffer * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @notapi */ @@ -431,9 +431,9 @@ void mmcStop(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval CH_FAILED the operation succeeded and the driver is now + * @retval CH_SUCCESS the operation succeeded and the driver is now * in the @p MMC_READY state. - * @retval CH_SUCCESS the operation failed. + * @retval CH_FAILED the operation failed. * * @api */ @@ -538,9 +538,9 @@ failed: * @param[in] mmcp pointer to the @p MMCDriver object * @return The operation status. * - * @retval CH_FAILED the operation succeeded and the driver is now + * @retval CH_SUCCESS the operation succeeded and the driver is now * in the @p MMC_INSERTED state. - * @retval CH_SUCCESS the operation failed. + * @retval CH_FAILED the operation failed. * * @api */ @@ -573,8 +573,8 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { * @param[in] startblk first block to read * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -611,8 +611,8 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { * @param[out] buffer pointer to the read buffer * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -645,8 +645,8 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -677,8 +677,8 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { * @param[in] startblk first block to write * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -713,8 +713,8 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { * @param[out] buffer pointer to the write buffer * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -748,8 +748,8 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -775,8 +775,8 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { * @param[in] mmcp pointer to the @p MMCDriver object * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -798,8 +798,8 @@ bool_t mmcSync(MMCDriver *mmcp) { * @param[out] bdip pointer to a @p BlockDeviceInfo structure * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ @@ -824,8 +824,8 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) { * @param[in] endblk ending block number * * @return The operation status. - * @retval CH_FAILED the operation succeeded. - * @retval CH_SUCCESS the operation failed. + * @retval CH_SUCCESS the operation succeeded. + * @retval CH_FAILED the operation failed. * * @api */ -- cgit v1.2.3 From 228be31cd61c1cf26190431281a9ca9fd067c2e7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 Jul 2012 08:53:09 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4377 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 2773ab79c..cee9049fd 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -67,8 +67,8 @@ static const struct SDCDriverVMT sdc_vmt = { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval FALSE operation succeeded. - * @retval TRUE operation failed. + * @retval CH_SUCCESS operation succeeded. + * @retval CH_FAILED operation failed. * * @notapi */ @@ -183,8 +183,8 @@ void sdcStop(SDCDriver *sdcp) { * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval CH_FAILED operation succeeded. - * @retval CH_SUCCESS operation failed. + * @retval CH_SUCCESS operation succeeded. + * @retval CH_FAILED operation failed. * * @api */ @@ -326,8 +326,8 @@ failed: * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval CH_FAILED operation succeeded. - * @retval CH_SUCCESS operation failed. + * @retval CH_SUCCESS operation succeeded. + * @retval CH_FAILED operation failed. * * @api */ @@ -369,8 +369,8 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @param[in] n number of blocks to read * * @return The operation status. - * @retval CH_FAILED operation succeeded. - * @retval CH_SUCCESS operation failed. + * @retval CH_SUCCESS operation succeeded. + * @retval CH_FAILED operation failed. * * @api */ @@ -407,8 +407,8 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @param[in] n number of blocks to write * * @return The operation status. - * @retval CH_FAILED operation succeeded. - * @retval CH_SUCCESS operation failed. + * @retval CH_SUCCESS operation succeeded. + * @retval CH_FAILED operation failed. * * @api */ -- cgit v1.2.3 From ec9736a27d1572f1a8357cae3dd56470f00af974 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 2 Jul 2012 18:47:09 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4388 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index c3e9ae184..fc082b56b 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -322,12 +322,12 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { so it is safe to transmit without a check.*/ chSysUnlockFromIsr(); - usbPrepareQueuedTransmit(sdup->config->usbp, + usbPrepareQueuedTransmit(usbp, USB_CDC_DATA_REQUEST_EP, &sdup->oqueue, n); chSysLockFromIsr(); - usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); + usbStartTransmitI(usbp, USB_CDC_DATA_REQUEST_EP); } chSysUnlockFromIsr(); @@ -352,19 +352,19 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { /* Writes to the input queue can only happen when there is enough space to hold at least one packet.*/ - maxsize = sdup->config->usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; + maxsize = usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; if ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize) { /* The endpoint cannot be busy, we are in the context of the callback, so a packet is in the buffer for sure.*/ chSysUnlockFromIsr(); n = (n / maxsize) * maxsize; - usbPrepareQueuedReceive(sdup->config->usbp, + usbPrepareQueuedReceive(usbp, USB_CDC_DATA_AVAILABLE_EP, &sdup->iqueue, n); chSysLockFromIsr(); - usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); + usbStartReceiveI(usbp, USB_CDC_DATA_AVAILABLE_EP); } chSysUnlockFromIsr(); -- cgit v1.2.3 From 28e7808798ebb9c087d2ba15a0366362a50fea9e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 13 Aug 2012 08:27:51 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4561 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index afe6f471c..2bf845e6e 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -354,8 +354,6 @@ void usbDisableEndpointsI(USBDriver *usbp) { /** * @brief Prepares for a receive transaction on an OUT endpoint. - * @pre In order to use this function the endpoint must have been - * initialized in transaction mode. * @post The endpoint is ready for @p usbStartReceiveI(). * @note This function can be called both in ISR and thread context. * @@ -379,8 +377,6 @@ void usbPrepareReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { /** * @brief Prepares for a transmit transaction on an IN endpoint. - * @pre In order to use this function the endpoint must have been - * initialized in transaction mode. * @post The endpoint is ready for @p usbStartTransmitI(). * @note This function can be called both in ISR and thread context. * @note The queue must contain at least the amount of data specified @@ -407,8 +403,6 @@ void usbPrepareTransmit(USBDriver *usbp, usbep_t ep, /** * @brief Prepares for a receive transaction on an OUT endpoint. - * @pre In order to use this function the endpoint must have been - * initialized in transaction mode. * @post The endpoint is ready for @p usbStartReceiveI(). * @note This function can be called both in ISR and thread context. * @note The queue must have enough free space to accommodate the @@ -438,8 +432,6 @@ void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep, /** * @brief Prepares for a transmit transaction on an IN endpoint. - * @pre In order to use this function the endpoint must have been - * initialized in transaction mode. * @post The endpoint is ready for @p usbStartTransmitI(). * @note This function can be called both in ISR and thread context. * @note The transmit transaction size is equal to the data contained -- cgit v1.2.3 From e372aabda9da9309671e058839d668ec38c7e8c1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 17 Aug 2012 12:40:48 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4575 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index fc082b56b..f05c341fc 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -223,7 +223,6 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { config->usbp->param = sdup; sdup->state = SDU_READY; chSysUnlock(); - usbStart(config->usbp, &config->usb_config); } /** @@ -245,7 +244,6 @@ void sduStop(SerialUSBDriver *sdup) { "invalid state"); sdup->state = SDU_STOP; chSysUnlock(); - usbStop(sdup->config->usbp); } /** @@ -322,12 +320,23 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { so it is safe to transmit without a check.*/ chSysUnlockFromIsr(); - usbPrepareQueuedTransmit(usbp, - USB_CDC_DATA_REQUEST_EP, - &sdup->oqueue, n); + usbPrepareQueuedTransmit(usbp, ep, &sdup->oqueue, n); + + chSysLockFromIsr(); + usbStartTransmitI(usbp, ep); + } + else if (!(usbp->epc[ep]->in_state->txsize & + (usbp->epc[ep]->in_maxsize - 1))) { + /* Transmit zero sized packet in case the last one has maximum allowed + size. Otherwise the recipient may expect more data coming soon and + not return buffered data to app. See section 5.8.3 Bulk Transfer + Packet Size Constraints of the USB Specification document.*/ + chSysUnlockFromIsr(); + + usbPrepareQueuedTransmit(usbp, ep, &sdup->oqueue, 0); chSysLockFromIsr(); - usbStartTransmitI(usbp, USB_CDC_DATA_REQUEST_EP); + usbStartTransmitI(usbp, ep); } chSysUnlockFromIsr(); -- cgit v1.2.3 From aedb7fddf11a5c5fad8b1a7a15d22534f145c763 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 17 Aug 2012 12:43:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4576 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index f05c341fc..9b36be413 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -368,12 +368,10 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { chSysUnlockFromIsr(); n = (n / maxsize) * maxsize; - usbPrepareQueuedReceive(usbp, - USB_CDC_DATA_AVAILABLE_EP, - &sdup->iqueue, n); + usbPrepareQueuedReceive(usbp, ep, &sdup->iqueue, n); chSysLockFromIsr(); - usbStartReceiveI(usbp, USB_CDC_DATA_AVAILABLE_EP); + usbStartReceiveI(usbp, ep); } chSysUnlockFromIsr(); -- cgit v1.2.3 From 7c144ea54022c4b58865373f7bc2159b5a84cd8c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 6 Sep 2012 19:08:08 +0000 Subject: Fixed bug. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4634 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 2bf845e6e..db4d826c1 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -619,6 +619,7 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { usb_lld_stall_out(usbp, 0); _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED); usbp->ep0state = USB_EP0_ERROR; + return; } } -- cgit v1.2.3 From 954a365b01c1c755752e61f600408fe72759f47c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 15 Sep 2012 18:14:43 +0000 Subject: Fixed bug 3567992. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4665 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 9b36be413..9cef45524 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -260,6 +260,11 @@ void sduConfigureHookI(USBDriver *usbp) { chIQResetI(&sdup->iqueue); chOQResetI(&sdup->oqueue); chnAddFlagsI(sdup, CHN_CONNECTED); + + /* Starts the first OUT transaction immediately.*/ + usbPrepareQueuedReceive(usbp, USB_CDC_DATA_AVAILABLE_EP, &sdup->iqueue, + usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize); + usbStartReceiveI(usbp, USB_CDC_DATA_AVAILABLE_EP); } /** -- cgit v1.2.3 From f90a0f37906a9363a6e702d8ac1c4c8257370efa Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Sep 2012 09:08:43 +0000 Subject: Removed flags handling in BaseAsynchronousChannel. Modified serial drivers to use the new event flags. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4671 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial.c | 8 +------- os/hal/src/serial_usb.c | 9 +-------- 2 files changed, 2 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 2bf7f396b..999f4d6f9 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -94,14 +94,9 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); } -static chnflags_t getflags(void *ip) { - _chn_get_and_clear_flags_impl(ip); -} - static const struct SerialDriverVMT vmt = { write, read, put, get, - putt, gett, writet, readt, - getflags + putt, gett, writet, readt }; /*===========================================================================*/ @@ -139,7 +134,6 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; chEvtInit(&sdp->event); - sdp->flags = CHN_NO_ERROR; sdp->state = SD_STOP; chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp); chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp); diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 9cef45524..05cb60c3f 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -103,14 +103,9 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time); } -static chnflags_t getflags(void *ip) { - _chn_get_and_clear_flags_impl(ip); -} - static const struct SerialUSBDriverVMT vmt = { write, read, put, get, - putt, gett, writet, readt, - getflags + putt, gett, writet, readt }; /** @@ -197,7 +192,6 @@ 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); @@ -256,7 +250,6 @@ void sduStop(SerialUSBDriver *sdup) { void sduConfigureHookI(USBDriver *usbp) { SerialUSBDriver *sdup = usbp->param; - sdup->flags = CHN_NO_ERROR; chIQResetI(&sdup->iqueue); chOQResetI(&sdup->oqueue); chnAddFlagsI(sdup, CHN_CONNECTED); -- cgit v1.2.3 From c145c837da830279f68f6ba0431d856cc6bf67f2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Sep 2012 09:26:46 +0000 Subject: Removed flags handling in CAN driver, now it is done using the new event flags. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4672 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 041409c99..422825a83 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -79,7 +79,6 @@ void canObjectInit(CANDriver *canp) { 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); @@ -136,7 +135,6 @@ void canStop(CANDriver *canp) { chSemResetI(&canp->txsem, 0); chSchRescheduleS(); canp->state = CAN_STOP; - canp->status = 0; chSysUnlock(); } @@ -219,24 +217,6 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { return RDY_OK; } -/** - * @brief Returns the current status mask and clears it. - * - * @param[in] canp pointer to the @p CANDriver object - * @return The status flags mask. - * - * @api - */ -canstatus_t canGetAndClearFlags(CANDriver *canp) { - canstatus_t status; - - chSysLock(); - status = canp->status; - canp->status = 0; - chSysUnlock(); - return status; -} - #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** * @brief Enters the sleep mode. -- cgit v1.2.3 From 9eef4917a71115fb38adcaa8bc11d00884055917 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 19 Sep 2012 18:00:51 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4699 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 2 +- os/hal/src/sdc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index f8056f392..65d655212 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -439,6 +439,7 @@ void mmcStop(MMCDriver *mmcp) { */ bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; + uint8_t r3[4]; chDbgCheck(mmcp != NULL, "mmcConnect"); @@ -466,7 +467,6 @@ bool_t mmcConnect(MMCDriver *mmcp) { addresses if possible. This method is based on "How to support SDC Ver2 and high capacity cards" by ElmChan.*/ - uint8_t r3[4]; if (send_command_R3(mmcp, MMCSD_CMD_SEND_IF_COND, MMCSD_CMD8_PATTERN, r3) != 0x05) { diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index cee9049fd..c8dcbf18f 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -443,13 +443,14 @@ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, * @api */ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { + sdcflags_t flags; chDbgCheck(sdcp != NULL, "sdcGetAndClearErrors"); chDbgAssert(sdcp->state == BLK_READY, "sdcGetAndClearErrors(), #1", "invalid state"); chSysLock(); - sdcflags_t flags = sdcp->errors; + flags = sdcp->errors; sdcp->errors = SDC_NO_ERROR; chSysUnlock(); return flags; -- cgit v1.2.3 From 54cde6b85446a97d4e980109483b23a758324a8c Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 20 Sep 2012 15:01:28 +0000 Subject: RTCv2. Get fat time function moved to driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4701 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 01f88e82d..10f09409a 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -167,6 +167,18 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { } #endif /* RTC_SUPPORTS_CALLBACKS */ +/** + * @brief Get current time in format suitable for usage in FatFS. + * + * @param[in] rtcp pointer to RTC driver structure + * @return FAT time value. + * + * @api + */ +uint32_t rtcGetTimeFat(RTCDriver *rtcp) { + return rtc_lld_get_time_fat(rtcp); +} + #endif /* HAL_USE_RTC */ /** @} */ -- cgit v1.2.3 From 406ee2993e054209845889ced5e36ab17b423bea Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 20 Sep 2012 17:22:23 +0000 Subject: RTC. Added chDbgCheck() in rtcGetTimeFat(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4702 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 10f09409a..daf4f4102 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -175,7 +175,9 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { * * @api */ -uint32_t rtcGetTimeFat(RTCDriver *rtcp) { +uint32_t rtcGetTimeFat(RTCDriver *rtcp) { + + chDbgCheck((rtcp != NULL), "rtcSetTime"); return rtc_lld_get_time_fat(rtcp); } -- cgit v1.2.3 From 14d77f2af0c6be3d152924da23758bfe483e16ec Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 13 Oct 2012 09:30:13 +0000 Subject: Fixed bug 3575657. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4751 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 553613438..e052e0945 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -148,6 +148,7 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, systime_t time) { msg_t msg; + systime_t now; chDbgCheck((macp != NULL) && (tdp != NULL), "macWaitTransmitDescriptor"); chDbgAssert(macp->state == MAC_ACTIVE, "macWaitTransmitDescriptor(), #1", @@ -156,7 +157,7 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, while (((msg = mac_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && (time > 0)) { chSysLock(); - systime_t now = chTimeNow(); + now = chTimeNow(); if ((msg = chSemWaitTimeoutS(&macp->tdsem, time)) == RDY_TIMEOUT) { chSysUnlock(); break; @@ -206,6 +207,7 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, MACReceiveDescriptor *rdp, systime_t time) { msg_t msg; + systime_t now; chDbgCheck((macp != NULL) && (rdp != NULL), "macWaitReceiveDescriptor"); chDbgAssert(macp->state == MAC_ACTIVE, "macWaitReceiveDescriptor(), #1", @@ -214,7 +216,7 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, while (((msg = mac_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && (time > 0)) { chSysLock(); - systime_t now = chTimeNow(); + now = chTimeNow(); if ((msg = chSemWaitTimeoutS(&macp->rdsem, time)) == RDY_TIMEOUT) { chSysUnlock(); break; -- cgit v1.2.3 From 5649879b0ae63a5623a41bfcc43705002de36cd3 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 12 Nov 2012 10:21:48 +0000 Subject: White space formatting. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4818 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 3817143c8..d1d97f2e9 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -317,7 +317,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @api */ void spiExchange(SPIDriver *spip, size_t n, - const void *txbuf, void *rxbuf) { + const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), "spiExchange"); -- cgit v1.2.3 From 76d8262f134d41c05adda7edb27d9868ca847941 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 28 Dec 2012 17:40:45 +0000 Subject: Zero-copy API for the MAC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4984 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index e052e0945..130c81caf 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -35,6 +35,10 @@ /* Driver local definitions. */ /*===========================================================================*/ +#if MAC_USE_ZERO_COPY && !MAC_SUPPORTS_ZERO_COPY +#error "MAC_USE_ZERO_COPY not supported by this implementation" +#endif + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ -- cgit v1.2.3 From 65dcd4d72ec5cb99205ec348a769d68293a49222 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 14 Jan 2013 19:54:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5069 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index daf4f4102..4d14140f3 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -175,7 +175,7 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { * * @api */ -uint32_t rtcGetTimeFat(RTCDriver *rtcp) { +uint32_t rtcGetTimeFat(RTCDriver *rtcp) { chDbgCheck((rtcp != NULL), "rtcSetTime"); return rtc_lld_get_time_fat(rtcp); -- cgit v1.2.3 From 844c70e2e51206ffd54e563cb69eb60c9cccad1f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 19 Jan 2013 08:01:56 +0000 Subject: Fixed bug 3600789. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5080 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/uart.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 1ab95a8ee..8462aafb1 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -143,8 +143,10 @@ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { "uartStartSend"); chSysLock(); - chDbgAssert((uartp->state == UART_READY) && (uartp->txstate == UART_TX_IDLE), - "uartStartSend(), #1", "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStartSend(), #1", "is active"); + chDbgAssert(uartp->txstate != UART_TX_ACTIVE, + "uartStartSend(), #2", "tx active"); uart_lld_start_send(uartp, n, txbuf); uartp->txstate = UART_TX_ACTIVE; @@ -168,9 +170,10 @@ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { chDbgCheckClassI(); chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), "uartStartSendI"); - chDbgAssert((uartp->state == UART_READY) && - (uartp->txstate != UART_TX_ACTIVE), - "uartStartSendI(), #1", "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStartSendI(), #1", "is active"); + chDbgAssert(uartp->txstate != UART_TX_ACTIVE, + "uartStartSendI(), #2", "tx active"); uart_lld_start_send(uartp, n, txbuf); uartp->txstate = UART_TX_ACTIVE; @@ -250,8 +253,10 @@ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { "uartStartReceive"); chSysLock(); - chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE), - "uartStartReceive(), #1", "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStartReceive(), #1", "is active"); + chDbgAssert(uartp->rxstate != UART_RX_ACTIVE, + "uartStartReceive(), #2", "rx active"); uart_lld_start_receive(uartp, n, rxbuf); uartp->rxstate = UART_RX_ACTIVE; @@ -275,8 +280,10 @@ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { chDbgCheckClassI(); chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), "uartStartReceiveI"); - chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE), - "uartStartReceiveI(), #1", "not active"); + chDbgAssert(uartp->state == UART_READY, + "uartStartReceiveI(), #1", "is active"); + chDbgAssert(uartp->rxstate != UART_RX_ACTIVE, + "uartStartReceiveI(), #2", "rx active"); uart_lld_start_receive(uartp, n, rxbuf); uartp->rxstate = UART_RX_ACTIVE; -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- os/hal/src/can.c | 2 +- os/hal/src/ext.c | 2 +- os/hal/src/gpt.c | 2 +- os/hal/src/hal.c | 2 +- os/hal/src/i2c.c | 2 +- os/hal/src/i2s.c | 2 +- os/hal/src/icu.c | 2 +- os/hal/src/mac.c | 2 +- os/hal/src/mmc_spi.c | 2 +- os/hal/src/mmcsd.c | 2 +- os/hal/src/pal.c | 2 +- os/hal/src/pwm.c | 2 +- os/hal/src/rtc.c | 2 +- os/hal/src/sdc.c | 2 +- os/hal/src/serial.c | 2 +- os/hal/src/serial_usb.c | 2 +- os/hal/src/spi.c | 2 +- os/hal/src/tm.c | 2 +- os/hal/src/uart.c | 2 +- os/hal/src/usb.c | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index d84e17faf..e37e6b16b 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 422825a83..18d7b302b 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index c53cd95fe..3c4357b70 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index a0745da93..a4baf7146 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index dad579ad0..6ac8c15be 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 152a77840..9e2438ecd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c index 99e4246ad..f9ed8177c 100644 --- a/os/hal/src/i2s.c +++ b/os/hal/src/i2s.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c index 240da1452..8fc7a019a 100644 --- a/os/hal/src/icu.c +++ b/os/hal/src/icu.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 130c81caf..44d368e67 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 65d655212..c06ce3351 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c index 62a3d368d..d7b3a87a8 100644 --- a/os/hal/src/mmcsd.c +++ b/os/hal/src/mmcsd.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 21fe48e16..83c652e99 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index 6e67d5407..b865955c6 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 4d14140f3..68fcac909 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index c8dcbf18f..5a84f7fb7 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 999f4d6f9..ae11c0ba9 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 05cb60c3f..23a323356 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index d1d97f2e9..807db3f3b 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/tm.c b/os/hal/src/tm.c index bb11fba0f..f96cee161 100644 --- a/os/hal/src/tm.c +++ b/os/hal/src/tm.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 8462aafb1..13fbb94f9 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index db4d826c1..a5f32f737 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 4149bab2ca98e041d09d9908b04e634b84257f2c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Feb 2013 10:34:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5297 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index c06ce3351..b2fd5b724 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -559,6 +559,7 @@ bool_t mmcDisconnect(MMCDriver *mmcp) { chSysUnlock(); /* Wait for the pending write operations to complete.*/ + spiStart(mmcp->config->spip, mmcp->config->hscfg); sync(mmcp); spiStop(mmcp->config->spip); @@ -787,6 +788,7 @@ bool_t mmcSync(MMCDriver *mmcp) { if (mmcp->state != BLK_READY) return CH_FAILED; + spiStart(mmcp->config->spip, mmcp->config->hscfg); sync(mmcp); return CH_SUCCESS; } -- cgit v1.2.3 From 48506ff3481afe8e2490e78a451852bc4bbb1c0b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Feb 2013 13:42:10 +0000 Subject: CAN driver revision, work in progress. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5299 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 18d7b302b..e0d47d5c5 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -145,6 +145,7 @@ void canStop(CANDriver *canp) { * @note Trying to transmit while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object + * @param[in] mailbox mailbox number, @p CAN_ANY_TX_MAILBOX for any mailbox * @param[in] ctfp pointer to the CAN frame to be transmitted * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: @@ -158,21 +159,26 @@ void canStop(CANDriver *canp) { * * @api */ -msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { +msg_t canTransmit(CANDriver *canp, + canmbx_t mailbox, + const CANTxFrame *ctfp, + systime_t timeout) { - chDbgCheck((canp != NULL) && (ctfp != NULL), "canTransmit"); + chDbgCheck((canp != NULL) && (ctfp != NULL) && + (mailbox <= CAN_TX_MAILBOXES), + "canTransmit"); chSysLock(); chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); - while ((canp->state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + while ((canp->state == CAN_SLEEP) || !can_lld_is_tx_empty(canp, mailbox)) { msg_t msg = chSemWaitTimeoutS(&canp->txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - can_lld_transmit(canp, ctfp); + can_lld_transmit(canp, mailbox, ctfp); chSysUnlock(); return RDY_OK; } @@ -183,6 +189,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * @note Trying to receive while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object + * @param[in] mailbox mailbox number * @param[out] crfp pointer to the buffer where the CAN frame is copied * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: @@ -198,21 +205,26 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * * @api */ -msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { +msg_t canReceive(CANDriver *canp, + canmbx_t mailbox, + CANRxFrame *crfp, + systime_t timeout) { - chDbgCheck((canp != NULL) && (crfp != NULL), "canReceive"); + chDbgCheck((canp != NULL) && (crfp != NULL) && + (mailbox >= 1) && (mailbox < CAN_RX_MAILBOXES), + "canReceive"); chSysLock(); chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canReceive(), #1", "invalid state"); - while ((canp->state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + while ((canp->state == CAN_SLEEP) || !can_lld_is_rx_nonempty(canp, mailbox)) { msg_t msg = chSemWaitTimeoutS(&canp->rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - can_lld_receive(canp, crfp); + can_lld_receive(canp, mailbox, crfp); chSysUnlock(); return RDY_OK; } -- cgit v1.2.3 From 4256a9113fd16e1b8d7cef963f83931b7d9182ad Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 23 Feb 2013 09:04:38 +0000 Subject: CAN driver enhancements completed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5303 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e0d47d5c5..64aaa45c8 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -145,7 +145,7 @@ void canStop(CANDriver *canp) { * @note Trying to transmit while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object - * @param[in] mailbox mailbox number, @p CAN_ANY_TX_MAILBOX for any mailbox + * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox * @param[in] ctfp pointer to the CAN frame to be transmitted * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: @@ -164,8 +164,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { - chDbgCheck((canp != NULL) && (ctfp != NULL) && - (mailbox <= CAN_TX_MAILBOXES), + chDbgCheck((canp != NULL) && (ctfp != NULL) && (mailbox <= CAN_TX_MAILBOXES), "canTransmit"); chSysLock(); @@ -189,7 +188,7 @@ msg_t canTransmit(CANDriver *canp, * @note Trying to receive while in sleep mode simply enqueues the thread. * * @param[in] canp pointer to the @p CANDriver object - * @param[in] mailbox mailbox number + * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox * @param[out] crfp pointer to the buffer where the CAN frame is copied * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: @@ -210,8 +209,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { - chDbgCheck((canp != NULL) && (crfp != NULL) && - (mailbox >= 1) && (mailbox < CAN_RX_MAILBOXES), + chDbgCheck((canp != NULL) && (crfp != NULL) && (mailbox < CAN_RX_MAILBOXES), "canReceive"); chSysLock(); -- cgit v1.2.3 From c41614ea66196b2e05b57a24064be449aa8a8830 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 24 Feb 2013 07:08:44 +0000 Subject: Fixed bug 3605793. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5304 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 23a323356..000d13951 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -323,8 +323,9 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { chSysLockFromIsr(); usbStartTransmitI(usbp, ep); } - else if (!(usbp->epc[ep]->in_state->txsize & - (usbp->epc[ep]->in_maxsize - 1))) { + else if ((usbp->epc[ep]->in_state->txsize > 0) && + !(usbp->epc[ep]->in_state->txsize & + (usbp->epc[ep]->in_maxsize - 1))) { /* Transmit zero sized packet in case the last one has maximum allowed size. Otherwise the recipient may expect more data coming soon and not return buffered data to app. See section 5.8.3 Bulk Transfer -- cgit v1.2.3 From 5a6b1e42b07402faf42498282cb0bcf931d3b0d1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 24 Feb 2013 08:11:13 +0000 Subject: Fixed bug 3605794. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5306 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mmc_spi.c | 15 +++++++++++++++ os/hal/src/sdc.c | 23 +++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index b2fd5b724..0d5af82d7 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -600,6 +600,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { if (recvr1(mmcp) != 0x00) { spiStop(mmcp->config->spip); + mmcp->state = BLK_READY; return CH_FAILED; } return CH_SUCCESS; @@ -637,6 +638,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { /* Timeout.*/ spiUnselect(mmcp->config->spip); spiStop(mmcp->config->spip); + mmcp->state = BLK_READY; return CH_FAILED; } @@ -702,6 +704,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { if (recvr1(mmcp) != 0x00) { spiStop(mmcp->config->spip); + mmcp->state = BLK_READY; return CH_FAILED; } return CH_SUCCESS; @@ -740,6 +743,7 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { /* Error.*/ spiUnselect(mmcp->config->spip); spiStop(mmcp->config->spip); + mmcp->state = BLK_READY; return CH_FAILED; } @@ -788,8 +792,14 @@ bool_t mmcSync(MMCDriver *mmcp) { if (mmcp->state != BLK_READY) return CH_FAILED; + /* Synchronization operation in progress.*/ + mmcp->state = BLK_SYNCING; + spiStart(mmcp->config->spip, mmcp->config->hscfg); sync(mmcp); + + /* Synchronization operation finished.*/ + mmcp->state = BLK_READY; return CH_SUCCESS; } @@ -835,6 +845,9 @@ bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) { chDbgCheck((mmcp != NULL), "mmcErase"); + /* Erase operation in progress.*/ + mmcp->state = BLK_WRITING; + /* Handling command differences between HC and normal cards.*/ if (!mmcp->block_addresses) { startblk *= MMCSD_BLOCK_SIZE; @@ -850,11 +863,13 @@ bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) { if (send_command_R1(mmcp, MMCSD_CMD_ERASE, 0)) goto failed; + mmcp->state = BLK_READY; return CH_SUCCESS; /* Command failed, state reset to BLK_ACTIVE.*/ failed: spiStop(mmcp->config->spip); + mmcp->state = BLK_READY; return CH_FAILED; } diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 5a84f7fb7..30f24af5b 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -468,13 +468,21 @@ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp) { * @api */ bool_t sdcSync(SDCDriver *sdcp) { + bool_t result; chDbgCheck(sdcp != NULL, "sdcSync"); if (sdcp->state != BLK_READY) return CH_FAILED; - return sdc_lld_sync(sdcp); + /* Synchronization operation in progress.*/ + sdcp->state = BLK_SYNCING; + + result = sdc_lld_sync(sdcp); + + /* Synchronization operation finished.*/ + sdcp->state = BLK_READY; + return result; } /** @@ -522,6 +530,9 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { chDbgCheck((sdcp != NULL), "sdcErase"); chDbgAssert(sdcp->state == BLK_READY, "sdcErase(), #1", "invalid state"); + /* Erase operation in progress.*/ + sdcp->state = BLK_WRITING; + /* Handling command differences between HC and normal cards.*/ if (!(sdcp->cardmode & SDC_MODE_HIGH_CAPACITY)) { startblk *= MMCSD_BLOCK_SIZE; @@ -533,17 +544,17 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_START, startblk, resp) != CH_SUCCESS) || MMCSD_R1_ERROR(resp[0])) - return CH_FAILED; + goto failed; if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE_RW_BLK_END, endblk, resp) != CH_SUCCESS) || MMCSD_R1_ERROR(resp[0])) - return CH_FAILED; + goto failed; if ((sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_ERASE, 0, resp) != CH_SUCCESS) || MMCSD_R1_ERROR(resp[0])) - return CH_FAILED; + goto failed; /* Quick sleep to allow it to transition to programming or receiving state */ /* TODO: ??????????????????????????? */ @@ -552,6 +563,10 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { _sdc_wait_for_transfer_state(sdcp); return CH_SUCCESS; + +failed: + sdcp->state = BLK_READY; + return CH_FAILED; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3 From cced334724aec1f39d683adcda6984543095ba8c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 25 Feb 2013 11:58:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5318 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 30f24af5b..929f58a46 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -218,8 +218,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { else { #if SDC_MMC_SUPPORT /* MMC or SD V1.1 detection.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDMMC_CMD_APP_CMD, 0, resp) || - SDC_R1_ERROR(resp[0])) + if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, 0, resp) || + MMCSD_R1_ERROR(resp[0])) sdcp->cardmode = SDC_MODE_CARDTYPE_MMC; else #endif /* SDC_MMC_SUPPORT */ -- cgit v1.2.3 From dedffdd99c7b04a7440f86b387a5d8c92eac413a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 26 Feb 2013 14:20:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5331 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index e37e6b16b..412e407ae 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -285,7 +285,7 @@ msg_t adcConvert(ADCDriver *adcp, chSysLock(); chDbgAssert(adcp->thread == NULL, "adcConvert(), #1", "already waiting"); adcStartConversionI(adcp, grpp, samples, depth); - (adcp)->thread = chThdSelf(); + adcp->thread = chThdSelf(); chSchGoSleepS(THD_STATE_SUSPENDED); msg = chThdSelf()->p_u.rdymsg; chSysUnlock(); -- cgit v1.2.3 From 01f971ba1d63d8568789adf51cde22fb35f69e73 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Feb 2013 16:23:19 +0000 Subject: Adjusted C file templates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5339 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 2 +- os/hal/src/can.c | 2 +- os/hal/src/ext.c | 2 +- os/hal/src/gpt.c | 2 +- os/hal/src/hal.c | 2 +- os/hal/src/i2c.c | 2 +- os/hal/src/i2s.c | 2 +- os/hal/src/icu.c | 2 +- os/hal/src/mac.c | 2 +- os/hal/src/mmc_spi.c | 2 +- os/hal/src/mmcsd.c | 2 +- os/hal/src/pal.c | 2 +- os/hal/src/pwm.c | 2 +- os/hal/src/rtc.c | 2 +- os/hal/src/sdc.c | 2 +- os/hal/src/serial.c | 2 +- os/hal/src/serial_usb.c | 2 +- os/hal/src/spi.c | 2 +- os/hal/src/tm.c | 2 +- os/hal/src/uart.c | 2 +- os/hal/src/usb.c | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 412e407ae..d0e814ae2 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 64aaa45c8..a57f12356 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index 3c4357b70..a0dc9f38e 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index a4baf7146..48db68174 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 6ac8c15be..974a8854b 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -38,7 +38,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9e2438ecd..78519cc35 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -43,7 +43,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c index f9ed8177c..e43d51ab2 100644 --- a/os/hal/src/i2s.c +++ b/os/hal/src/i2s.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/icu.c b/os/hal/src/icu.c index 8fc7a019a..65d5de907 100644 --- a/os/hal/src/icu.c +++ b/os/hal/src/icu.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 44d368e67..cb62db612 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -44,7 +44,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 0d5af82d7..3a5958ec8 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -45,7 +45,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /* Forward declarations required by mmc_vmt.*/ diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c index d7b3a87a8..c83095981 100644 --- a/os/hal/src/mmcsd.c +++ b/os/hal/src/mmcsd.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/pal.c b/os/hal/src/pal.c index 83c652e99..cc382edab 100644 --- a/os/hal/src/pal.c +++ b/os/hal/src/pal.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index b865955c6..c6843a928 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 68fcac909..e0a1c227b 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -44,7 +44,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 929f58a46..3b034cf3d 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /** diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index ae11c0ba9..fdb802ccc 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 000d13951..7b7d255ed 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -42,7 +42,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /* diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 807db3f3b..b4eccb0af 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/tm.c b/os/hal/src/tm.c index f96cee161..5b002cd90 100644 --- a/os/hal/src/tm.c +++ b/os/hal/src/tm.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /** diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c index 13fbb94f9..71869538d 100644 --- a/os/hal/src/uart.c +++ b/os/hal/src/uart.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index a5f32f737..1e7c35121 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -43,7 +43,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ static const uint8_t zero_status[] = {0x00, 0x00}; -- cgit v1.2.3 From 152cacac1f47599a0a538c94900ba18d30f0ccc9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Mar 2013 11:21:07 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5403 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/sdc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src') diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 3b034cf3d..f95331d44 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -562,6 +562,7 @@ bool_t sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk) { /* Wait for it to return to transfer state to indicate it has finished erasing */ _sdc_wait_for_transfer_state(sdcp); + sdcp->state = BLK_READY; return CH_SUCCESS; failed: -- cgit v1.2.3 From f571b507132cc77e401dee68535c2b9f3370c60c Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 27 Mar 2013 20:03:40 +0000 Subject: STM32. GPT. Added abillity to change interval of running GPT unit on the fly. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5510 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 48db68174..9b7c0d9a6 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -116,6 +116,30 @@ void gptStop(GPTDriver *gptp) { chSysUnlock(); } +/** + * @brief Changes the interval of GPT peripheral. + * @details This function changes the interval of a running GPT unit. + * @pre The GPT unit must have been activated using @p gptStart(). + * @pre The GPT unit must have been running in continuous mode using + * @p gptStartContinuous(). + * @post The GPT unit interval is changed to the new value. + * + * @param[in] gptp pointer to a @p GPTDriver object + * @param[in] interval new cycle time in timer ticks + * + * @api + */ +void stm32_gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { + + chDbgCheck(gptp != NULL, "gptChangeInterval"); + + chSysLock(); + chDbgAssert(gptp->state == GPT_CONTINUOUS, + "gptChangeInterval(), #1", "invalid state"); + stm32_gptChangeIntervalI(gptp, interval); + chSysUnlock(); +} + /** * @brief Starts the timer in continuous mode. * -- cgit v1.2.3 From 042c2ddba82250d60de4882ae7b0293666747d2d Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 29 Mar 2013 19:27:32 +0000 Subject: STM32. GPT. Removed prefix "stm32" from names of functions changing interval. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5518 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 9b7c0d9a6..e37e1a5d8 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -129,14 +129,14 @@ void gptStop(GPTDriver *gptp) { * * @api */ -void stm32_gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { +void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { chDbgCheck(gptp != NULL, "gptChangeInterval"); chSysLock(); chDbgAssert(gptp->state == GPT_CONTINUOUS, "gptChangeInterval(), #1", "invalid state"); - stm32_gptChangeIntervalI(gptp, interval); + gptChangeIntervalI(gptp, interval); chSysUnlock(); } -- cgit v1.2.3 From 4434fed8d81d9bc3a41a02a645bfd719ff941f73 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 27 Apr 2013 10:06:06 +0000 Subject: Fixed stop procedure in the USB driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5634 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 1e7c35121..9c3825910 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -282,7 +282,8 @@ void usbStop(USBDriver *usbp) { chDbgCheck(usbp != NULL, "usbStop"); chSysLock(); - chDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY), + chDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY) || + (usbp->state == USB_SELECTED) || (usbp->state == USB_ACTIVE), "usbStop(), #1", "invalid state"); usb_lld_stop(usbp); usbp->state = USB_STOP; -- cgit v1.2.3 From 53ebb098cb632593656bba3a28730ca2bb3de1ce Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Apr 2013 13:12:20 +0000 Subject: Updated serial_usb driver and demos. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5637 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 7b7d255ed..37b1d3fe6 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -29,8 +29,6 @@ #include "ch.h" #include "hal.h" -#include "usb_cdc.h" - #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) /*===========================================================================*/ @@ -117,24 +115,25 @@ static void inotify(GenericQueue *qp) { /* If the USB driver is not in the appropriate state then transactions must not be started.*/ - if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) || + (sdup->state != SDU_READY)) return; /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ - maxsize = sdup->config->usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; - if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && + maxsize = sdup->config->usbp->epc[sdup->config->bulk_out]->out_maxsize; + if (!usbGetReceiveStatusI(sdup->config->usbp, sdup->config->bulk_out) && ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize)) { chSysUnlock(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(sdup->config->usbp, - USB_CDC_DATA_AVAILABLE_EP, + sdup->config->bulk_out, &sdup->iqueue, n); chSysLock(); - usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); + usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out); } } @@ -147,21 +146,22 @@ static void onotify(GenericQueue *qp) { /* If the USB driver is not in the appropriate state then transactions must not be started.*/ - if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) || + (sdup->state != SDU_READY)) return; /* If there is not an ongoing transaction and the output queue contains data then a new transaction is started.*/ - if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP) && + if (!usbGetTransmitStatusI(sdup->config->usbp, sdup->config->bulk_in) && ((n = chOQGetFullI(&sdup->oqueue)) > 0)) { chSysUnlock(); usbPrepareQueuedTransmit(sdup->config->usbp, - USB_CDC_DATA_REQUEST_EP, + sdup->config->bulk_in, &sdup->oqueue, n); chSysLock(); - usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); + usbStartTransmitI(sdup->config->usbp, sdup->config->bulk_in); } } @@ -236,6 +236,12 @@ void sduStop(SerialUSBDriver *sdup) { chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), "sduStop(), #1", "invalid state"); + + chIQResetI(&sdup->iqueue); + chOQResetI(&sdup->oqueue); + chSchRescheduleS(); + chnAddFlagsI(sdup, CHN_DISCONNECTED); + sdup->state = SDU_STOP; chSysUnlock(); } @@ -255,9 +261,9 @@ void sduConfigureHookI(USBDriver *usbp) { chnAddFlagsI(sdup, CHN_CONNECTED); /* Starts the first OUT transaction immediately.*/ - usbPrepareQueuedReceive(usbp, USB_CDC_DATA_AVAILABLE_EP, &sdup->iqueue, - usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize); - usbStartReceiveI(usbp, USB_CDC_DATA_AVAILABLE_EP); + usbPrepareQueuedReceive(usbp, sdup->config->bulk_out, &sdup->iqueue, + usbp->epc[sdup->config->bulk_out]->out_maxsize); + usbStartReceiveI(usbp, sdup->config->bulk_out); } /** @@ -308,7 +314,8 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { size_t n; SerialUSBDriver *sdup = usbp->param; - (void)ep; + if (sdup->state != SDU_READY) + return; chSysLockFromIsr(); chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY); @@ -353,14 +360,15 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { size_t n, maxsize; SerialUSBDriver *sdup = usbp->param; - (void)ep; + if (sdup->state != SDU_READY) + return; chSysLockFromIsr(); chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); /* Writes to the input queue can only happen when there is enough space to hold at least one packet.*/ - maxsize = usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; + maxsize = usbp->epc[ep]->out_maxsize; if ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize) { /* The endpoint cannot be busy, we are in the context of the callback, so a packet is in the buffer for sure.*/ -- cgit v1.2.3 From 30a552991b81cef1eb5eae1aa3937b960b6e0f08 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Apr 2013 13:27:37 +0000 Subject: Fixed bug #406. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5638 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 9c3825910..745b2d436 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -693,15 +693,16 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { /* If the transmitted size is less than the requested size and it is a multiple of the maximum packet size then a zero size packet must be transmitted.*/ - if ((usbp->ep0n < max) && - ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { + if ((usbp->ep0n < max) && ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { usbPrepareTransmit(usbp, 0, NULL, 0); chSysLockFromIsr(); usbStartTransmitI(usbp, 0); chSysUnlockFromIsr(); + usbp->ep0state = USB_EP0_WAITING_TX0; return; } - + /* Falls into, it is intentional.*/ + case USB_EP0_WAITING_TX0: /* Transmit phase over, receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; usbPrepareReceive(usbp, 0, NULL, 0); -- cgit v1.2.3 From 11ecb1a7586ddaf6276a087d51de829b00d5f386 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 1 May 2013 15:50:35 +0000 Subject: Fixed problem with multiple SerialUSB instances. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5651 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 31 +++++++++++++++++++++---------- os/hal/src/usb.c | 6 +++++- 2 files changed, 26 insertions(+), 11 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 37b1d3fe6..ff6e94b07 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -206,6 +206,7 @@ void sduObjectInit(SerialUSBDriver *sdup) { * @api */ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { + USBDriver *usbp = config->usbp; chDbgCheck(sdup != NULL, "sduStart"); @@ -213,8 +214,10 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), "sduStart(), #1", "invalid state"); + usbp->in_params[config->bulk_in - 1] = sdup; + usbp->out_params[config->bulk_out - 1] = sdup; + usbp->in_params[config->int_in - 1] = sdup; sdup->config = config; - config->usbp->param = sdup; sdup->state = SDU_READY; chSysUnlock(); } @@ -229,32 +232,40 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { * @api */ void sduStop(SerialUSBDriver *sdup) { + USBDriver *usbp = sdup->config->usbp; chDbgCheck(sdup != NULL, "sdStop"); chSysLock(); + chDbgAssert((sdup->state == SDU_STOP) || (sdup->state == SDU_READY), "sduStop(), #1", "invalid state"); + /* Driver in stopped state.*/ + usbp->in_params[sdup->config->bulk_in - 1] = NULL; + usbp->out_params[sdup->config->bulk_out - 1] = NULL; + usbp->in_params[sdup->config->int_in - 1] = NULL; + sdup->state = SDU_STOP; + + /* Queues reset in order to signal the driver stop to the application.*/ + chnAddFlagsI(sdup, CHN_DISCONNECTED); chIQResetI(&sdup->iqueue); chOQResetI(&sdup->oqueue); chSchRescheduleS(); - chnAddFlagsI(sdup, CHN_DISCONNECTED); - sdup->state = SDU_STOP; chSysUnlock(); } /** * @brief USB device configured handler. * - * @param[in] usbp pointer to the @p USBDriver object + * @param[in] sdup pointer to a @p SerialUSBDriver object * * @iclass */ -void sduConfigureHookI(USBDriver *usbp) { - SerialUSBDriver *sdup = usbp->param; +void sduConfigureHookI(SerialUSBDriver *sdup) { + USBDriver *usbp = sdup->config->usbp; chIQResetI(&sdup->iqueue); chOQResetI(&sdup->oqueue); @@ -312,9 +323,9 @@ bool_t sduRequestsHook(USBDriver *usbp) { */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { size_t n; - SerialUSBDriver *sdup = usbp->param; + SerialUSBDriver *sdup = usbp->in_params[ep - 1]; - if (sdup->state != SDU_READY) + if (sdup == NULL) return; chSysLockFromIsr(); @@ -358,9 +369,9 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { */ void sduDataReceived(USBDriver *usbp, usbep_t ep) { size_t n, maxsize; - SerialUSBDriver *sdup = usbp->param; + SerialUSBDriver *sdup = usbp->out_params[ep - 1]; - if (sdup->state != SDU_READY) + if (sdup == NULL) return; chSysLockFromIsr(); diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 745b2d436..1da532abf 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -238,10 +238,14 @@ void usbInit(void) { * @init */ void usbObjectInit(USBDriver *usbp) { + unsigned i; usbp->state = USB_STOP; usbp->config = NULL; - usbp->param = NULL; + for (i = 0; i < USB_MAX_ENDPOINTS; i++) { + usbp->in_params[i] = NULL; + usbp->out_params[i] = NULL; + } usbp->transmitting = 0; usbp->receiving = 0; } -- cgit v1.2.3 From e9edd478029209ba06f09a380590e4ae3e844985 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 28 May 2013 14:12:55 +0000 Subject: SPC5xx DSPI driver working on SPC563Mxx. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5766 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index b4eccb0af..2dc0cc6ee 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -126,7 +126,6 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStop(), #1", "invalid state"); - spi_lld_unselect(spip); spi_lld_stop(spip); spip->state = SPI_STOP; chSysUnlock(); -- cgit v1.2.3