From a94bfc5f713ee3b7659c53458b61f40ff39dc660 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 2 Nov 2014 15:24:30 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7461 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/SPIv1/spi_lld.h | 2 +- os/hal/ports/STM32/LLD/SPIv2/spi_lld.h | 2 +- os/hal/ports/STM32/LLD/USBv1/usb_lld.h | 14 --- os/hal/templates/sdc_lld.c | 113 +++++++++++++++---------- os/hal/templates/sdc_lld.h | 69 ++++----------- os/hal/templates/spi_lld.c | 9 +- os/hal/templates/spi_lld.h | 31 +++---- os/hal/templates/usb_lld.c | 7 +- os/hal/templates/usb_lld.h | 35 ++++++-- 9 files changed, 135 insertions(+), 147 deletions(-) diff --git a/os/hal/ports/STM32/LLD/SPIv1/spi_lld.h b/os/hal/ports/STM32/LLD/SPIv1/spi_lld.h index d4159a9a0..72a7c83de 100644 --- a/os/hal/ports/STM32/LLD/SPIv1/spi_lld.h +++ b/os/hal/ports/STM32/LLD/SPIv1/spi_lld.h @@ -437,7 +437,7 @@ typedef struct { } SPIConfig; /** - * @brief Structure representing a SPI driver. + * @brief Structure representing an SPI driver. */ struct SPIDriver { /** diff --git a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h index d52acebae..3ca12284e 100644 --- a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h +++ b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h @@ -275,7 +275,7 @@ typedef struct { } SPIConfig; /** - * @brief Structure representing a SPI driver. + * @brief Structure representing an SPI driver. */ struct SPIDriver { /** diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h index 1f0e5e45b..3af0f6ded 100644 --- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h +++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h @@ -388,20 +388,6 @@ struct USBDriver { #define usb_lld_get_transaction_size(usbp, ep) \ ((usbp)->epc[ep]->out_state->rxcnt) -/** - * @brief Returns the exact size of a received packet. - * @pre The OUT endpoint must have been configured in packet mode - * in order to use this function. - * - * @param[in] usbp pointer to the @p USBDriver object - * @param[in] ep endpoint number - * @return Received data size. - * - * @notapi - */ -#define usb_lld_get_packet_size(usbp, ep) \ - ((size_t)USB_GET_DESCRIPTOR(ep)->RXCOUNT & RXCOUNT_COUNT_MASK) - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/templates/sdc_lld.c b/os/hal/templates/sdc_lld.c index c0d311b87..77a339fd9 100644 --- a/os/hal/templates/sdc_lld.c +++ b/os/hal/templates/sdc_lld.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ /** - * @file templates/sdc_lld.c - * @brief SDC Driver subsystem low level driver source template. + * @file PLATFORM/sdc_lld.c + * @brief PLATFORM SDC subsystem low level driver source. * * @addtogroup SDC * @{ */ -#include "ch.h" #include "hal.h" #if HAL_USE_SDC || defined(__DOXYGEN__) @@ -183,20 +182,17 @@ void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg) { * @param[out] resp pointer to the response buffer (one word) * * @return The operation status. - * @retval CH_SUCCESS operation succeeded. - * @retval CH_FAILED operation failed. + * @retval HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. * * @notapi */ -bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp) { +bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp) { (void)sdcp; - (void)cmd; - (void)arg; - (void)resp; - return CH_SUCCESS; + return HAL_SUCCESS; } /** @@ -208,20 +204,17 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, * @param[out] resp pointer to the response buffer (one word) * * @return The operation status. - * @retval CH_SUCCESS operation succeeded. - * @retval CH_FAILED operation failed. + * @retval HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. * * @notapi */ -bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp) { +bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp) { (void)sdcp; - (void)cmd; - (void)arg; - (void)resp; - return CH_SUCCESS; + return HAL_SUCCESS; } /** @@ -233,20 +226,17 @@ bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, * @param[out] resp pointer to the response buffer (four words) * * @return The operation status. - * @retval CH_SUCCESS operation succeeded. - * @retval CH_FAILED operation failed. + * @retval HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. * * @notapi */ -bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp) { +bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp) { (void)sdcp; - (void)cmd; - (void)arg; - (void)resp; - return CH_SUCCESS; + return HAL_SUCCESS; } /** @@ -258,20 +248,20 @@ bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, * @param[in] n number of blocks to read * * @return The operation status. - * @retval CH_SUCCESS operation succeeded. - * @retval CH_FAILED operation failed. + * @retval HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. * * @notapi */ -bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, - uint8_t *buf, uint32_t n) { +bool sdc_lld_read_aligned(SDCDriver *sdcp, uint32_t startblk, + uint8_t *buf, uint32_t n) { (void)sdcp; (void)startblk; (void)buf; (void)n; - return CH_SUCCESS; + return HAL_SUCCESS; } /** @@ -283,20 +273,58 @@ bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, * @param[in] n number of blocks to write * * @return The operation status. - * @retval CH_SUCCESS operation succeeded. - * @retval CH_FAILED operation failed. + * @retval HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. * * @notapi */ -bool_t sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, - const uint8_t *buf, uint32_t n) { +bool sdc_lld_write_aligned(SDCDriver *sdcp, uint32_t startblk, + const uint8_t *buf, uint32_t n) { (void)sdcp; (void)startblk; (void)buf; (void)n; - return CH_SUCCESS; + return HAL_SUCCESS; +} + +/** + * @brief Reads one or more blocks. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @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 HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. + * + * @notapi + */ +bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, + uint8_t *buf, uint32_t n) { + +} + +/** + * @brief Writes one or more blocks. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @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 HAL_SUCCESS operation succeeded. + * @retval HAL_FAILED operation failed. + * + * @notapi + */ +bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, + const uint8_t *buf, uint32_t n) { + } /** @@ -305,16 +333,15 @@ bool_t sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, * @param[in] sdcp pointer to the @p SDCDriver object * * @return The operation status. - * @retval CH_SUCCESS the operation succeeded. - * @retval CH_FAILED the operation failed. + * @retval HAL_SUCCESS the operation succeeded. + * @retval HAL_FAILED the operation failed. * * @api */ -bool_t sdc_lld_sync(SDCDriver *sdcp) { +bool sdc_lld_sync(SDCDriver *sdcp) { (void)sdcp; - - return CH_SUCCESS; + return HAL_SUCCESS; } #endif /* HAL_USE_SDC */ diff --git a/os/hal/templates/sdc_lld.h b/os/hal/templates/sdc_lld.h index aa3c7effd..4611fe783 100644 --- a/os/hal/templates/sdc_lld.h +++ b/os/hal/templates/sdc_lld.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ /** - * @file templates/sdc_lld.h - * @brief SDC Driver subsystem low level driver header template. + * @file PLATFORM/sdc_lld.h + * @brief PLATFORM SDC subsystem low level driver header. * * @addtogroup SDC * @{ @@ -39,13 +39,6 @@ * @name Configuration options * @{ */ -/** - * @brief SDC driver enable switch. - * @details If set to @p TRUE the support for SDC1 is included. - */ -#if !defined(PLATFORM_SDC_USE_SDC1) || defined(__DOXYGEN__) -#define PLATFORM_SDC_USE_SDC1 TRUE -#endif /** @} */ /*===========================================================================*/ @@ -85,7 +78,7 @@ typedef struct SDCDriver SDCDriver; * @note It could be empty on some architectures. */ typedef struct { - uint32_t dummy; + uint32_t dummy; } SDCConfig; /** @@ -135,37 +128,11 @@ struct SDCDriver { /* Driver macros. */ /*===========================================================================*/ -/** - * @name R1 response utilities - * @{ - */ -/** - * @brief Evaluates to @p TRUE if the R1 response contains error flags. - * - * @param[in] r1 the r1 response - */ -#define MMCSD_R1_ERROR(r1) (((r1) & MMCSD_R1_ERROR_MASK) != 0) - -/** - * @brief Returns the status field of an R1 response. - * - * @param[in] r1 the r1 response - */ -#define MMCSD_R1_STS(r1) (((r1) >> 9) & 15) - -/** - * @brief Evaluates to @p TRUE if the R1 response indicates a locked card. - * - * @param[in] r1 the r1 response - */ -#define MMCSD_R1_IS_CARD_LOCKED(r1) (((r1) >> 21) & 1) -/** @} */ - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ -#if PLATFORM_SDC_USE_SDC1 && !defined(__DOXYGEN__) +#if !defined(__DOXYGEN__) extern SDCDriver SDCD1; #endif @@ -180,19 +147,19 @@ extern "C" { void sdc_lld_stop_clk(SDCDriver *sdcp); void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode); void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg); - bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp); - bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp); - bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp); - bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, - uint8_t *buf, uint32_t n); - bool_t sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, - const uint8_t *buf, uint32_t n); - bool_t sdc_lld_sync(SDCDriver *sdcp); - bool_t sdc_lld_is_card_inserted(SDCDriver *sdcp); - bool_t sdc_lld_is_write_protected(SDCDriver *sdcp); + bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp); + bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp); + bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp); + bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, + uint8_t *buf, uint32_t n); + bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, + const uint8_t *buf, uint32_t n); + bool sdc_lld_sync(SDCDriver *sdcp); + bool sdc_lld_is_card_inserted(SDCDriver *sdcp); + bool sdc_lld_is_write_protected(SDCDriver *sdcp); #ifdef __cplusplus } #endif diff --git a/os/hal/templates/spi_lld.c b/os/hal/templates/spi_lld.c index a53f1ef43..e4987fc7c 100644 --- a/os/hal/templates/spi_lld.c +++ b/os/hal/templates/spi_lld.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ /** - * @file templates/spi_lld.c - * @brief SPI Driver subsystem low level driver source template. + * @file PLATFORM/SPIv2/spi_lld.c + * @brief PLATFORM SPI subsystem low level driver source. * * @addtogroup SPI * @{ */ -#include "ch.h" #include "hal.h" #if HAL_USE_SPI || defined(__DOXYGEN__) @@ -102,8 +101,6 @@ void spi_lld_start(SPIDriver *spip) { void spi_lld_stop(SPIDriver *spip) { if (spip->state == SPI_READY) { - /* Resets the peripheral.*/ - /* Disables the peripheral.*/ #if PLATFORM_SPI_USE_SPI1 if (&SPID1 == spip) { diff --git a/os/hal/templates/spi_lld.h b/os/hal/templates/spi_lld.h index 690054f43..c5c69d3fc 100644 --- a/os/hal/templates/spi_lld.h +++ b/os/hal/templates/spi_lld.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ /** - * @file templates/spi_lld.h - * @brief SPI Driver subsystem low level driver header template. + * @file PLATFORM/spi_lld.h + * @brief PLATFORM SPI subsystem low level driver header. * * @addtogroup SPI * @{ @@ -40,11 +40,10 @@ * @{ */ /** - * @brief SPI driver enable switch. - * @details If set to @p TRUE the support for SPI1 is included. + * @brief SPI1 driver enable switch. */ #if !defined(PLATFORM_SPI_USE_SPI1) || defined(__DOXYGEN__) -#define PLATFORM_SPI_USE_SPI1 FALSE +#define PLATFORM_SPI_USE_SPI1 FALSE #endif /** @} */ @@ -76,9 +75,9 @@ typedef void (*spicallback_t)(SPIDriver *spip); */ typedef struct { /** - * @brief Operation complete callback. + * @brief Operation complete callback or @p NULL. */ - spicallback_t end_cb; + spicallback_t end_cb; /* End of the mandatory fields.*/ } SPIConfig; @@ -91,26 +90,22 @@ struct SPIDriver { /** * @brief Driver state. */ - spistate_t state; + spistate_t state; /** * @brief Current configuration data. */ - const SPIConfig *config; + const SPIConfig *config; #if SPI_USE_WAIT || defined(__DOXYGEN__) /** - * @brief Waiting thread. + * @brief Waiting thread. */ - Thread *thread; + thread_reference_t thread; #endif /* SPI_USE_WAIT */ #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -#if CH_USE_MUTEXES || defined(__DOXYGEN__) /** - * @brief Mutex protecting the bus. + * @brief Mutex protecting the peripheral. */ - Mutex mutex; -#elif CH_USE_SEMAPHORES - Semaphore semaphore; -#endif + mutex_t mutex; #endif /* SPI_USE_MUTUAL_EXCLUSION */ #if defined(SPI_DRIVER_EXT_FIELDS) SPI_DRIVER_EXT_FIELDS diff --git a/os/hal/templates/usb_lld.c b/os/hal/templates/usb_lld.c index 9a63b149c..e48413353 100644 --- a/os/hal/templates/usb_lld.c +++ b/os/hal/templates/usb_lld.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ /** - * @file templates/usb_lld.c - * @brief USB Driver subsystem low level driver source template. + * @file PLATFORM/usb_lld.c + * @brief PLATFORM USB subsystem low level driver source. * * @addtogroup USB * @{ */ -#include "ch.h" #include "hal.h" #if HAL_USE_USB || defined(__DOXYGEN__) diff --git a/os/hal/templates/usb_lld.h b/os/hal/templates/usb_lld.h index 7dbf8b4b9..40970043a 100644 --- a/os/hal/templates/usb_lld.h +++ b/os/hal/templates/usb_lld.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS/HAL - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ /** - * @file templates/usb_lld.h - * @brief USB Driver subsystem low level driver header template. + * @file PLATFORM/usb_lld.h + * @brief PLATFORM USB subsystem low level driver header. * * @addtogroup USB * @{ @@ -36,10 +36,15 @@ */ #define USB_MAX_ENDPOINTS 4 +/** + * @brief Status stage handling method. + */ +#define USB_EP0_STATUS_STAGE USB_EP0_STATUS_STAGE_SW + /** * @brief The address can be changed immediately upon packet reception. */ -#define USB_SET_ADDRESS_MODE USB_EARLY_SET_ADDRESS +#define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS /*===========================================================================*/ /* Driver pre-compile time settings. */ @@ -54,7 +59,7 @@ * @details If set to @p TRUE the support for USB1 is included. */ #if !defined(PLATFORM_USB_USE_USB1) || defined(__DOXYGEN__) -#define PLATFORM_USB_USE_USB1 FALSE +#define PLATFORM_USB_USE_USB1 FALSE #endif /** @} */ @@ -73,7 +78,7 @@ typedef struct { /** * @brief Buffer mode, queue or linear. */ - bool_t txqueued; + bool txqueued; /** * @brief Requested transmit transfer size. */ @@ -93,8 +98,9 @@ typedef struct { /** * @brief Pointer to the output queue. */ - OutputQueue *txqueue; + output_queue_t *txqueue; } queue; + /* End of the mandatory fields.*/ } mode; } USBInEndpointState; @@ -105,7 +111,7 @@ typedef struct { /** * @brief Buffer mode, queue or linear. */ - bool_t rxqueued; + bool rxqueued; /** * @brief Requested receive transfer size. */ @@ -125,9 +131,10 @@ typedef struct { /** * @brief Pointer to the input queue. */ - InputQueue *rxqueue; + input_queue_t *rxqueue; } queue; } mode; + /* End of the mandatory fields.*/ } USBOutEndpointState; /** @@ -294,6 +301,16 @@ struct USBDriver { /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Returns the current frame number. + * + * @param[in] usbp pointer to the @p USBDriver object + * @return The current frame number. + * + * @notapi + */ +#define usb_lld_get_frame_number(usbp) 0 + /** * @brief Returns the exact size of a receive transaction. * @details The received size can be different from the size specified in