From 099fc179cc2ce75fd43ed6c5524aea4ca5d77ea0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 2 Nov 2014 10:06:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7456 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/mac.h | 8 --- os/hal/templates/adc_lld.h | 40 ++++++------- os/hal/templates/can_lld.h | 70 +++++++--------------- os/hal/templates/i2s_lld.c | 136 ++++++++++++++++++++++++++++++++++++++++++ os/hal/templates/i2s_lld.h | 143 +++++++++++++++++++++++++++++++++++++++++++++ os/hal/templates/mac_lld.c | 20 +++---- os/hal/templates/mac_lld.h | 16 ++--- 7 files changed, 336 insertions(+), 97 deletions(-) create mode 100644 os/hal/templates/i2s_lld.c create mode 100644 os/hal/templates/i2s_lld.h (limited to 'os/hal') diff --git a/os/hal/include/mac.h b/os/hal/include/mac.h index e418f5bb8..3c2ccd0e6 100644 --- a/os/hal/include/mac.h +++ b/os/hal/include/mac.h @@ -61,14 +61,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if !CH_CFG_USE_SEMAPHORES || !CH_CFG_USE_EVENTS -#error "the MAC driver requires CH_CFG_USE_SEMAPHORES" -#endif - -#if MAC_USE_EVENTS && !CH_CFG_USE_EVENTS -#error "the MAC driver requires CH_CFG_USE_EVENTS" -#endif - /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ diff --git a/os/hal/templates/adc_lld.h b/os/hal/templates/adc_lld.h index c7b4ca9cf..1ee25bf48 100644 --- a/os/hal/templates/adc_lld.h +++ b/os/hal/templates/adc_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/adc_lld.h - * @brief ADC Driver subsystem low level driver header template. + * @file PLATFORMF/adc_lld.h + * @brief PLATFORMF ADC subsystem low level driver header. * * @addtogroup ADC * @{ @@ -45,7 +45,7 @@ * @note The default is @p FALSE. */ #if !defined(PLATFORM_ADC_USE_ADC1) || defined(__DOXYGEN__) -#define PLATFORM_ADC_USE_ADC1 FALSE +#define PLATFORM_ADC_USE_ADC1 FALSE #endif /** @} */ @@ -74,7 +74,8 @@ typedef uint16_t adc_channels_num_t; */ typedef enum { ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */ - ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */ + ADC_ERR_OVERFLOW = 1, /**< ADC overflow condition. */ + ADC_ERR_AWD = 2 /**< Analog watchdog triggered. */ } adcerror_t; /** @@ -105,14 +106,15 @@ typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); * @brief Conversion group configuration structure. * @details This implementation-dependent structure describes a conversion * operation. - * @note Implementations may extend this structure to contain more, - * architecture dependent, fields. + * @note The use of this configuration structure requires knowledge of + * PLATFORM ADC cell registers interface, please refer to the PLATFORM + * reference manual for details. */ typedef struct { /** * @brief Enables the circular buffer mode for the group. */ - bool_t circular; + bool circular; /** * @brief Number of the analog channels belonging to the conversion group. */ @@ -141,40 +143,36 @@ typedef struct { */ struct ADCDriver { /** - * @brief Driver state. + * @brief Driver state. */ adcstate_t state; /** - * @brief Current configuration data. + * @brief Current configuration data. */ const ADCConfig *config; /** - * @brief Current samples buffer pointer or @p NULL. + * @brief Current samples buffer pointer or @p NULL. */ adcsample_t *samples; /** - * @brief Current samples buffer depth or @p 0. + * @brief Current samples buffer depth or @p 0. */ size_t depth; /** - * @brief Current conversion group pointer or @p NULL. + * @brief Current conversion group pointer or @p NULL. */ const ADCConversionGroup *grpp; #if ADC_USE_WAIT || defined(__DOXYGEN__) /** - * @brief Waiting thread. + * @brief Waiting thread. */ - Thread *thread; + thread_reference_t thread; #endif #if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -#if CH_USE_MUTEXES || defined(__DOXYGEN__) /** - * @brief Mutex protecting the peripheral. + * @brief Mutex protecting the peripheral. */ - Mutex mutex; -#elif CH_USE_SEMAPHORES - Semaphore semaphore; -#endif + mutex_t mutex; #endif /* ADC_USE_MUTUAL_EXCLUSION */ #if defined(ADC_DRIVER_EXT_FIELDS) ADC_DRIVER_EXT_FIELDS diff --git a/os/hal/templates/can_lld.h b/os/hal/templates/can_lld.h index bfa9bb1e5..1c3eefeb9 100644 --- a/os/hal/templates/can_lld.h +++ b/os/hal/templates/can_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/can_lld.h - * @brief CAN Driver subsystem low level driver header template. + * @file PLATFORM/can_lld.h + * @brief PLATFORM CAN subsystem low level driver header. * * @addtogroup CAN * @{ @@ -31,22 +31,6 @@ /* Driver constants. */ /*===========================================================================*/ -/** - * @brief This switch defines whether the driver implementation supports - * a low power switch mode with automatic an wakeup feature. - */ -#define CAN_SUPPORTS_SLEEP TRUE - -/** - * @brief This implementation supports three transmit mailboxes. - */ -#define CAN_TX_MAILBOXES 3 - -/** - * @brief This implementation supports two receive mailboxes. - */ -#define CAN_RX_MAILBOXES 2 - /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -60,7 +44,7 @@ * @details If set to @p TRUE the support for CAN1 is included. */ #if !defined(PLATFORM_CAN_USE_CAN1) || defined(__DOXYGEN__) -#define PLATFORM_CAN_USE_CAN1 FALSE +#define PLATFORM_CAN_USE_CAN1 FALSE #endif /** @} */ @@ -68,10 +52,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if CAN_USE_SLEEP_MODE && !CAN_SUPPORTS_SLEEP -#error "CAN sleep mode not supported in this architecture" -#endif - /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -113,6 +93,10 @@ typedef struct { * machine data endianness, it can be still useful for a quick filling. */ typedef struct { + struct { + uint8_t FMI; /**< @brief Filter id. */ + uint16_t TIME; /**< @brief Time stamp. */ + }; struct { uint8_t DLC:4; /**< @brief Data length. */ uint8_t RTR:1; /**< @brief Frame type. */ @@ -133,23 +117,11 @@ typedef struct { }; } CANRxFrame; -/** - * @brief CAN filter. - * @note Implementations may extend this structure to contain more, - * architecture dependent, fields. - * @note It could not be present on some architectures. - */ -typedef struct { - uint32_t dummy; -} CANFilter; - /** * @brief Driver configuration structure. - * @note Implementations may extend this structure to contain more, - * architecture dependent, fields. - * @note It could be empty on some architectures. */ typedef struct { + /* End of the mandatory fields.*/ uint32_t dummy; } CANConfig; @@ -166,13 +138,13 @@ typedef struct { */ const CANConfig *config; /** - * @brief Transmission queue semaphore. + * @brief Transmission threads queue. */ - Semaphore txsem; + threads_queue_t txqueue; /** - * @brief Receive queue semaphore. + * @brief Receive threads queue. */ - Semaphore rxsem; + threads_queue_t rxqueue; /** * @brief One or more frames become available. * @note After broadcasting this event it will not be broadcasted again @@ -185,29 +157,29 @@ typedef struct { * @note The flags associated to the listeners will indicate which * receive mailboxes become non-empty. */ - EventSource rxfull_event; + event_source_t rxfull_event; /** * @brief One or more transmission mailbox become available. * @note The flags associated to the listeners will indicate which * transmit mailboxes become empty. * */ - EventSource txempty_event; + event_source_t txempty_event; /** * @brief A CAN bus error happened. * @note The flags associated to the listeners will indicate the * error(s) that have occurred. */ - EventSource error_event; + event_source_t error_event; #if CAN_USE_SLEEP_MODE || defined (__DOXYGEN__) /** * @brief Entering sleep state event. */ - EventSource sleep_event; + event_source_t sleep_event; /** * @brief Exiting sleep state event. */ - EventSource wakeup_event; + event_source_t wakeup_event; #endif /* CAN_USE_SLEEP_MODE */ /* End of the mandatory fields.*/ } CANDriver; @@ -230,13 +202,11 @@ extern "C" { void can_lld_init(void); void can_lld_start(CANDriver *canp); void can_lld_stop(CANDriver *canp); - bool_t can_lld_is_tx_empty(CANDriver *canp, - canmbx_t mailbox); + bool can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox); void can_lld_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *crfp); - bool_t can_lld_is_rx_nonempty(CANDriver *canp, - canmbx_t mailbox); + bool can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox); void can_lld_receive(CANDriver *canp, canmbx_t mailbox, CANRxFrame *ctfp); diff --git a/os/hal/templates/i2s_lld.c b/os/hal/templates/i2s_lld.c new file mode 100644 index 000000000..3b218cc8d --- /dev/null +++ b/os/hal/templates/i2s_lld.c @@ -0,0 +1,136 @@ +/* + 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file PLATFORM/i2s_lld.c + * @brief PLATFORM I2S subsystem low level driver source. + * + * @addtogroup I2S + * @{ + */ + +#include "hal.h" + +#if HAL_USE_I2S || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/** @brief I2S2 driver identifier.*/ +#if PLATFORM_I2S_USE_I2S1 || defined(__DOXYGEN__) +I2SDriver I2SD1; +#endif + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level I2S driver initialization. + * + * @notapi + */ +void i2s_lld_init(void) { + +#if PLATFORM_I2S_USE_I2S1 + i2sObjectInit(&I2SD1); +#endif +} + +/** + * @brief Configures and activates the I2S peripheral. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @notapi + */ +void i2s_lld_start(I2SDriver *i2sp) { + + /* If in stopped state then enables the SPI and DMA clocks.*/ + if (i2sp->state == I2S_STOP) { + +#if PLATFORM_I2S_USE_I2S1 + if (&I2SD1 == i2sp) { + + } +#endif +} + +/** + * @brief Deactivates the I2S peripheral. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @notapi + */ +void i2s_lld_stop(I2SDriver *i2sp) { + + /* If in ready state then disables the SPI clock.*/ + if (i2sp->state == I2S_READY) { +#if PLATFORM_I2S_USE_I2S1 + if (&I2SD1 == i2sp) { + + } +#endif + } +} + +/** + * @brief Starts a I2S data exchange. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @notapi + */ +void i2s_lld_start_exchange(I2SDriver *i2sp) { + + (void)i2sp; +} + +/** + * @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 + * + * @notapi + */ +void i2s_lld_stop_exchange(I2SDriver *i2sp) { + + (void)i2sp; +} + +#endif /* HAL_USE_I2S */ + +/** @} */ diff --git a/os/hal/templates/i2s_lld.h b/os/hal/templates/i2s_lld.h new file mode 100644 index 000000000..22c7b4ff3 --- /dev/null +++ b/os/hal/templates/i2s_lld.h @@ -0,0 +1,143 @@ +/* + 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file i2s_lld.h + * @brief PLATFORM I2S subsystem low level driver header. + * + * @addtogroup I2S + * @{ + */ + +#ifndef _I2S_LLD_H_ +#define _I2S_LLD_H_ + +#if HAL_USE_I2S || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @name Configuration options + * @{ + */ +/** + * @brief I2S2 driver enable switch. + * @details If set to @p TRUE the support for I2S2 is included. + * @note The default is @p TRUE. + */ +#if !defined(PLATFORM_I2S_USE_I2S1) || defined(__DOXYGEN__) +#define PLATFORM_I2S_USE_I2S1 FALSE +#endif +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of a structure representing an I2S driver. + */ +typedef struct I2SDriver I2SDriver; + +/** + * @brief I2S notification callback type. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * @param[in] offset offset in buffers of the data to read/write + * @param[in] n number of samples to read/write + */ +typedef void (*i2scallback_t)(I2SDriver *i2sp, size_t offset, size_t n); + +/** + * @brief Driver configuration structure. + * @note It could be empty on some architectures. + */ +typedef struct { + /** + * @brief Transmission buffer pointer. + * @note Can be @p NULL if TX is not required. + */ + const void *tx_buffer; + /** + * @brief Receive buffer pointer. + * @note Can be @p NULL if RX is not required. + */ + void *rx_buffer; + /** + * @brief TX and RX buffers size as number of samples. + */ + size_t size; + /** + * @brief Callback function called during streaming. + */ + i2scallback_t end_cb; + /* End of the mandatory fields.*/ +} I2SConfig; + +/** + * @brief Structure representing an I2S driver. + */ +struct I2SDriver { + /** + * @brief Driver state. + */ + i2sstate_t state; + /** + * @brief Current configuration data. + */ + const I2SConfig *config; + /* End of the mandatory fields.*/ +}; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#if PLATFORM_I2S_USE_I2S1 && !defined(__DOXYGEN__) +extern I2SDriver I2SD1; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + void i2s_lld_init(void); + void i2s_lld_start(I2SDriver *i2sp); + void i2s_lld_stop(I2SDriver *i2sp); + void i2s_lld_start_exchange(I2SDriver *i2sp); + void i2s_lld_stop_exchange(I2SDriver *i2sp); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_I2S */ + +#endif /* _I2S_LLD_H_ */ + +/** @} */ diff --git a/os/hal/templates/mac_lld.c b/os/hal/templates/mac_lld.c index d4de2ce5c..7eb327e7b 100644 --- a/os/hal/templates/mac_lld.c +++ b/os/hal/templates/mac_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,8 +15,8 @@ */ /** - * @file templates/mac_lld.c - * @brief MAC Driver subsystem low level driver source template. + * @file PLATFORM/mac_lld.c + * @brief PLATFORM low level MAC driver code. * * @addtogroup MAC * @{ @@ -24,12 +24,12 @@ #include -#include "ch.h" #include "hal.h" -#include "mii.h" #if HAL_USE_MAC || defined(__DOXYGEN__) +#include "mii.h" + /*===========================================================================*/ /* Driver local definitions. */ /*===========================================================================*/ @@ -104,7 +104,7 @@ void mac_lld_start(MACDriver *macp) { */ void mac_lld_stop(MACDriver *macp) { - if (macp->state == MAC_ACTIVE) { + if (macp->state != MAC_STOP) { /* Resets the peripheral.*/ /* Disables the peripheral.*/ @@ -135,7 +135,7 @@ msg_t mac_lld_get_transmit_descriptor(MACDriver *macp, (void)macp; (void)tdp; - return RDY_OK; + return MSG_OK; } /** @@ -192,8 +192,8 @@ void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) { * * @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 true if the link is active. + * @retval false if the link is down. * * @notapi */ @@ -201,7 +201,7 @@ bool_t mac_lld_poll_link_status(MACDriver *macp) { (void)macp; - return FALSE; + return false; } /** diff --git a/os/hal/templates/mac_lld.h b/os/hal/templates/mac_lld.h index ed278f514..5f4631c16 100644 --- a/os/hal/templates/mac_lld.h +++ b/os/hal/templates/mac_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/mac_lld.h - * @brief MAC Driver subsystem low level driver header template. + * @file PLATFORM/mac_lld.h + * @brief PLATFORM low level MAC driver header. * * @addtogroup MAC * @{ @@ -34,7 +34,7 @@ /** * @brief This implementation supports the zero-copy mode API. */ -#define MAC_SUPPORTS_ZERO_COPY TRUE +#define MAC_SUPPORTS_ZERO_COPY TRUE /*===========================================================================*/ /* Driver pre-compile time settings. */ @@ -87,16 +87,16 @@ struct MACDriver { /** * @brief Transmit semaphore. */ - Semaphore tdsem; + semaphore_t tdsem; /** * @brief Receive semaphore. */ - Semaphore rdsem; + semaphore_t rdsem; #if MAC_USE_EVENTS || defined(__DOXYGEN__) /** * @brief Receive event. */ - EventSource rdevent; + event_source_t rdevent; #endif /* End of the mandatory fields.*/ }; @@ -155,7 +155,7 @@ extern "C" { msg_t mac_lld_get_receive_descriptor(MACDriver *macp, MACReceiveDescriptor *rdp); void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp); - bool_t mac_lld_poll_link_status(MACDriver *macp); + bool mac_lld_poll_link_status(MACDriver *macp); size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp, uint8_t *buf, size_t size); -- cgit v1.2.3