diff options
Diffstat (limited to 'os/hal/include')
24 files changed, 863 insertions, 976 deletions
diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index 32b4c65a2..626840c5e 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -64,10 +64,6 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if ADC_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "ADC_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -102,14 +98,8 @@ typedef enum { *
* @notapi
*/
-#define _adc_reset_i(adcp) { \
- if ((adcp)->thread != NULL) { \
- Thread *tp = (adcp)->thread; \
- (adcp)->thread = NULL; \
- tp->p_u.rdymsg = RDY_RESET; \
- chSchReadyI(tp); \
- } \
-}
+#define _adc_reset_i(adcp) \
+ osalThreadResumeI(&(adcp)->thread, MSG_RESET)
/**
* @brief Resumes a thread waiting for a conversion completion.
@@ -118,13 +108,8 @@ typedef enum { *
* @notapi
*/
-#define _adc_reset_s(adcp) { \
- if ((adcp)->thread != NULL) { \
- Thread *tp = (adcp)->thread; \
- (adcp)->thread = NULL; \
- chSchWakeupS(tp, RDY_RESET); \
- } \
-}
+#define _adc_reset_s(adcp) \
+ osalThreadResumeS(&(adcp)->thread, MSG_RESET)
/**
* @brief Wakes up the waiting thread.
@@ -134,15 +119,9 @@ typedef enum { * @notapi
*/
#define _adc_wakeup_isr(adcp) { \
- chSysLockFromIsr(); \
- if ((adcp)->thread != NULL) { \
- Thread *tp; \
- tp = (adcp)->thread; \
- (adcp)->thread = NULL; \
- tp->p_u.rdymsg = RDY_OK; \
- chSchReadyI(tp); \
- } \
- chSysUnlockFromIsr(); \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(adcp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
}
/**
@@ -153,15 +132,9 @@ typedef enum { * @notapi
*/
#define _adc_timeout_isr(adcp) { \
- chSysLockFromIsr(); \
- if ((adcp)->thread != NULL) { \
- Thread *tp; \
- tp = (adcp)->thread; \
- (adcp)->thread = NULL; \
- tp->p_u.rdymsg = RDY_TIMEOUT; \
- chSchReadyI(tp); \
- } \
- chSysUnlockFromIsr(); \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(adcp)->thread, MSG_TIMEOUT); \
+ osalSysUnlockFromISR(); \
}
#else /* !ADC_USE_WAIT */
diff --git a/os/hal/include/can.h b/os/hal/include/can.h index 4d502c0d2..534f6f622 100644 --- a/os/hal/include/can.h +++ b/os/hal/include/can.h @@ -89,10 +89,6 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
-#error "CAN driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
diff --git a/os/hal/include/dac.h b/os/hal/include/dac.h index fc0a09d4c..3d1157ae0 100644 --- a/os/hal/include/dac.h +++ b/os/hal/include/dac.h @@ -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. @@ -64,10 +64,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if DAC_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES -#error "DAC_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES" -#endif - /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -107,12 +103,8 @@ typedef enum { * * @notapi */ -#define _dac_wait_s(dacp) { \ - chDbgAssert((dacp)->thread == NULL, \ - "_dac_wait_s(), #1", "already waiting"); \ - (dacp)->thread = chThdSelf(); \ - chSchGoSleepS(THD_STATE_SUSPENDED); \ -} +#define _dac_wait_s(dacp) osalThreadSuspendS(&(dacp)->thread) + /** * @brief Resumes a thread waiting for a conversion completion. * @@ -120,14 +112,7 @@ typedef enum { * * @notapi */ -#define _dac_reset_i(dacp) { \ - if ((dacp)->thread != NULL) { \ - Thread *tp = (dacp)->thread; \ - (dacp)->thread = NULL; \ - tp->p_u.rdymsg = RDY_RESET; \ - chSchReadyI(tp); \ - } \ -} +#define _dac_reset_i(dacp) osalThreadResumeI(&(dacp)->thread, MSG_RESET) /** * @brief Resumes a thread waiting for a conversion completion. @@ -136,13 +121,7 @@ typedef enum { * * @notapi */ -#define _dac_reset_s(dacp) { \ - if ((dacp)->thread != NULL) { \ - Thread *tp = (dacp)->thread; \ - (dacp)->thread = NULL; \ - chSchWakeupS(tp, RDY_RESET); \ - } \ -} +#define _dac_reset_s(dacp) osalThreadResumeS(&(dacp)->thread, MSG_RESET) /** * @brief Wakes up the waiting thread. @@ -152,15 +131,9 @@ typedef enum { * @notapi */ #define _dac_wakeup_isr(dacp) { \ - chSysLockFromIsr(); \ - if ((dacp)->thread != NULL) { \ - Thread *tp; \ - tp = (dacp)->thread; \ - (dacp)->thread = NULL; \ - tp->p_u.rdymsg = RDY_OK; \ - chSchReadyI(tp); \ - } \ - chSysUnlockFromIsr(); \ + osalSysLockFromISR(); \ + osalThreadResumeI(&(dacp)->thread, MSG_OK); \ + osalSysUnlockFromISR(); \ } /** @@ -171,15 +144,9 @@ typedef enum { * @notapi */ #define _dac_timeout_isr(dacp) { \ - chSysLockFromIsr(); \ - if ((dacp)->thread != NULL) { \ - Thread *tp; \ - tp = (dacp)->thread; \ - (dacp)->thread = NULL; \ - tp->p_u.rdymsg = RDY_TIMEOUT; \ - chSchReadyI(tp); \ - } \ - chSysUnlockFromIsr(); \ + osalSysLockFromISR(); \ + osalThreadResumeI(&(dacp)->thread, MSG_TIMEOUT); \ + osalSysUnlockFromISR(); \ } #else /* !DAC_USE_WAIT */ diff --git a/os/hal/include/ext.h b/os/hal/include/ext.h index 7f32c5f1f..89dc59df8 100644 --- a/os/hal/include/ext.h +++ b/os/hal/include/ext.h @@ -120,9 +120,9 @@ typedef struct EXTDriver EXTDriver; * @api
*/
#define extSetChannelMode(extp, channel, extcp) { \
- chSysLock(); \
+ osalSysLock(); \
extSetChannelModeI(extp, channel, extcp); \
- chSysUnlock(); \
+ osalSysUnlock(); \
}
/** @} */
diff --git a/os/hal/include/gpt.h b/os/hal/include/gpt.h index 3b474cb14..a900243ba 100644 --- a/os/hal/include/gpt.h +++ b/os/hal/include/gpt.h @@ -79,9 +79,7 @@ typedef void (*gptcallback_t)(GPTDriver *gptp); /**
* @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().
+ * @pre The GPT unit must be running in continuous mode.
* @post The GPT unit interval is changed to the new value.
*
* @param[in] gptp pointer to a @p GPTDriver object
@@ -89,10 +87,34 @@ typedef void (*gptcallback_t)(GPTDriver *gptp); *
* @iclass
*/
-#define gptChangeIntervalI(gptp, interval) { \
- gpt_lld_change_interval(gptp, interval); \
+#define gptChangeIntervalI(gptp, interval) { \
+ gpt_lld_change_interval(gptp, interval); \
}
+/**
+ * @brief Returns the interval of GPT peripheral.
+ * @pre The GPT unit must be running in continuous mode.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ * @return The current interval.
+ *
+ * @xclass
+ */
+#define gptGetIntervalX(gptp) gpt_lld_get_interval(gptp)
+
+/**
+ * @brief Returns the counter value of GPT peripheral.
+ * @pre The GPT unit must be running in continuous mode.
+ * @note The nature of the counter is not defined, it may count upward
+ * or downward, it could be continuously running or not.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ * @return The current counter value.
+ *
+ * @xclass
+ */
+#define gptGetCounterX(gptp) gpt_lld_get_counter(gptp)
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index ceff2e0a9..bab2196d3 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -29,21 +29,22 @@ #ifndef _HAL_H_
#define _HAL_H_
-#include "ch.h"
+#include "osal.h"
#include "board.h"
#include "halconf.h"
#include "hal_lld.h"
/* Abstract interfaces.*/
-#include "io_channel.h"
-#include "io_block.h"
+#include "hal_streams.h"
+#include "hal_channels.h"
+#include "hal_ioblock.h"
+#include "hal_mmcsd.h"
/* Shared headers.*/
-#include "mmcsd.h"
+#include "hal_queues.h"
-/* Layered drivers.*/
-#include "tm.h"
+/* Normal drivers.*/
#include "pal.h"
#include "adc.h"
#include "can.h"
@@ -51,13 +52,15 @@ #include "ext.h"
#include "gpt.h"
#include "i2c.h"
+#include "i2s.h"
#include "icu.h"
-#include "mac.h"
+//#include "mac.h"
#include "pwm.h"
-#include "rtc.h"
+//#include "rtc.h"
#include "serial.h"
#include "sdc.h"
#include "spi.h"
+#include "st.h"
#include "uart.h"
#include "usb.h"
@@ -69,6 +72,14 @@ /* Driver constants. */
/*===========================================================================*/
+/**
+ * @name Return codes
+ * @{
+ */
+#define HAL_SUCCESS false
+#define HAL_FAILED true
+/** @} */
+
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
@@ -85,113 +96,6 @@ /* Driver macros. */
/*===========================================================================*/
-#if HAL_IMPLEMENTS_COUNTERS || defined(__DOXYGEN__)
-/**
- * @name Time conversion utilities for the realtime counter
- * @{
- */
-/**
- * @brief Seconds to realtime ticks.
- * @details Converts from seconds to realtime ticks number.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] sec number of seconds
- * @return The number of ticks.
- *
- * @api
- */
-#define S2RTT(sec) (halGetCounterFrequency() * (sec))
-
-/**
- * @brief Milliseconds to realtime ticks.
- * @details Converts from milliseconds to realtime ticks number.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] msec number of milliseconds
- * @return The number of ticks.
- *
- * @api
- */
-#define MS2RTT(msec) (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec))
-
-/**
- * @brief Microseconds to realtime ticks.
- * @details Converts from microseconds to realtime ticks number.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] usec number of microseconds
- * @return The number of ticks.
- *
- * @api
- */
-#define US2RTT(usec) (((halGetCounterFrequency() + 999999UL) / 1000000UL) * \
- (usec))
-
-/**
- * @brief Realtime ticks to seconds to.
- * @details Converts from realtime ticks number to seconds.
- *
- * @param[in] ticks number of ticks
- * @return The number of seconds.
- *
- * @api
- */
-#define RTT2S(ticks) ((ticks) / halGetCounterFrequency())
-
-/**
- * @brief Realtime ticks to milliseconds.
- * @details Converts from realtime ticks number to milliseconds.
- *
- * @param[in] ticks number of ticks
- * @return The number of milliseconds.
- *
- * @api
- */
-#define RTT2MS(ticks) ((ticks) / (halGetCounterFrequency() / 1000UL))
-
-/**
- * @brief Realtime ticks to microseconds.
- * @details Converts from realtime ticks number to microseconds.
- *
- * @param[in] ticks number of ticks
- * @return The number of microseconds.
- *
- * @api
- */
-#define RTT2US(ticks) ((ticks) / (halGetCounterFrequency() / 1000000UL))
-/** @} */
-
-/**
- * @name Macro Functions
- * @{
- */
-/**
- * @brief Returns the current value of the system free running counter.
- * @note This is an optional service that could not be implemented in
- * all HAL implementations.
- * @note This function can be called from any context.
- *
- * @return The value of the system free running counter of
- * type halrtcnt_t.
- *
- * @special
- */
-#define halGetCounterValue() hal_lld_get_counter_value()
-
-/**
- * @brief Realtime counter frequency.
- * @note This is an optional service that could not be implemented in
- * all HAL implementations.
- * @note This function can be called from any context.
- *
- * @return The realtime counter frequency of type halclock_t.
- *
- * @special
- */
-#define halGetCounterFrequency() hal_lld_get_counter_frequency()
-/** @} */
-#endif /* HAL_IMPLEMENTS_COUNTERS */
-
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -200,10 +104,6 @@ extern "C" {
#endif
void halInit(void);
-#if HAL_IMPLEMENTS_COUNTERS
- bool_t halIsCounterWithin(halrtcnt_t start, halrtcnt_t end);
- void halPolledDelay(halrtcnt_t ticks);
-#endif /* HAL_IMPLEMENTS_COUNTERS */
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/io_channel.h b/os/hal/include/hal_channels.h index 66c81b683..a5abe67b8 100644 --- a/os/hal/include/io_channel.h +++ b/os/hal/include/hal_channels.h @@ -19,7 +19,7 @@ */
/**
- * @file io_channel.h
+ * @file hal_channels.h
* @brief I/O channels access.
* @details This header defines an abstract interface useful to access generic
* I/O serial devices in a standardized way.
@@ -37,8 +37,8 @@ * @{
*/
-#ifndef _IO_CHANNEL_H_
-#define _IO_CHANNEL_H_
+#ifndef _HAL_CHANNELS_H_
+#define _HAL_CHANNELS_H_
/**
* @brief @p BaseChannel specific methods.
@@ -102,9 +102,9 @@ typedef struct { * - @a TIME_INFINITE no timeout.
* .
* @return The operation status.
- * @retval Q_OK if the operation succeeded.
- * @retval Q_TIMEOUT if the specified time expired.
- * @retval Q_RESET if the channel associated queue (if any) was reset.
+ * @retval STM_OK if the operation succeeded.
+ * @retval STM_TIMEOUT if the specified time expired.
+ * @retval STM_RESET if the channel associated queue (if any) was reset.
*
* @api
*/
@@ -122,8 +122,8 @@ typedef struct { * - @a TIME_INFINITE no timeout.
* .
* @return A byte value from the queue.
- * @retval Q_TIMEOUT if the specified time expired.
- * @retval Q_RESET if the channel associated queue (if any) has been
+ * @retval STM_TIMEOUT if the specified time expired.
+ * @retval STM_RESET if the channel associated queue (if any) has been
* reset.
*
* @api
@@ -143,7 +143,7 @@ typedef struct { *
* @api
*/
-#define chnWrite(ip, bp, n) chSequentialStreamWrite(ip, bp, n)
+#define chnWrite(ip, bp, n) streamWrite(ip, bp, n)
/**
* @brief Channel blocking write with timeout.
@@ -177,7 +177,7 @@ typedef struct { *
* @api
*/
-#define chnRead(ip, bp, n) chSequentialStreamRead(ip, bp, n)
+#define chnRead(ip, bp, n) streamRead(ip, bp, n)
/**
* @brief Channel blocking read with timeout.
@@ -199,7 +199,6 @@ typedef struct { #define chnReadTimeout(ip, bp, n, time) ((ip)->vmt->readt(ip, bp, n, time))
/** @} */
-#if CH_USE_EVENTS || defined(__DOXYGEN__)
/**
* @name I/O status flags added to the event listener
* @{
@@ -230,7 +229,7 @@ typedef struct { #define _base_asynchronous_channel_data \
_base_channel_data \
/* I/O condition event source.*/ \
- EventSource event;
+ event_source_t event;
/**
* @extends BaseChannelVMT
@@ -283,12 +282,10 @@ typedef struct { * @iclass
*/
#define chnAddFlagsI(ip, flags) { \
- chEvtBroadcastFlagsI(&(ip)->event, flags); \
+ osalEventBroadcastFlagsI(&(ip)->event, flags); \
}
/** @} */
-#endif /* CH_USE_EVENTS */
-
-#endif /* _IO_CHANNEL_H_ */
+#endif /* _HAL_CHANNELS_H_ */
/** @} */
diff --git a/os/hal/include/io_block.h b/os/hal/include/hal_ioblock.h index 7a2970f9f..f759a5dff 100644 --- a/os/hal/include/io_block.h +++ b/os/hal/include/hal_ioblock.h @@ -19,7 +19,7 @@ */
/**
- * @file io_block.h
+ * @file hal_ioblock.h
* @brief I/O block devices access.
* @details This header defines an abstract interface useful to access generic
* I/O block devices in a standardized way.
@@ -35,8 +35,8 @@ * @{
*/
-#ifndef _IO_BLOCK_H_
-#define _IO_BLOCK_H_
+#ifndef _HAL_IOBLOCK_H_
+#define _HAL_IOBLOCK_H_
/**
* @brief Driver state machine possible states.
@@ -66,23 +66,23 @@ typedef struct { */
#define _base_block_device_methods \
/* Removable media detection.*/ \
- bool_t (*is_inserted)(void *instance); \
+ bool (*is_inserted)(void *instance); \
/* Removable write protection detection.*/ \
- bool_t (*is_protected)(void *instance); \
+ bool (*is_protected)(void *instance); \
/* Connection to the block device.*/ \
- bool_t (*connect)(void *instance); \
+ bool (*connect)(void *instance); \
/* Disconnection from the block device.*/ \
- bool_t (*disconnect)(void *instance); \
+ bool (*disconnect)(void *instance); \
/* Reads one or more blocks.*/ \
- bool_t (*read)(void *instance, uint32_t startblk, \
+ bool (*read)(void *instance, uint32_t startblk, \
uint8_t *buffer, uint32_t n); \
/* Writes one or more blocks.*/ \
- bool_t (*write)(void *instance, uint32_t startblk, \
+ bool (*write)(void *instance, uint32_t startblk, \
const uint8_t *buffer, uint32_t n); \
/* Write operations synchronization.*/ \
- bool_t (*sync)(void *instance); \
+ bool (*sync)(void *instance); \
/* Obtains info about the media.*/ \
- bool_t (*get_info)(void *instance, BlockDeviceInfo *bdip);
+ bool (*get_info)(void *instance, BlockDeviceInfo *bdip);
/**
* @brief @p BaseBlockDevice specific data.
@@ -180,8 +180,8 @@ typedef struct { * @param[in] ip pointer to a @p BaseBlockDevice or derived class
*
* @return The operation status.
- * @retval CH_SUCCESS operation succeeded.
- * @retval CH_FAILED operation failed.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
*
* @api
*/
@@ -194,8 +194,8 @@ typedef struct { * @param[in] ip pointer to a @p BaseBlockDevice or derived class
*
* @return The operation status.
- * @retval CH_SUCCESS operation succeeded.
- * @retval CH_FAILED operation failed.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
*
* @api
*/
@@ -210,8 +210,8 @@ typedef struct { * @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.
*
* @api
*/
@@ -227,8 +227,8 @@ typedef struct { * @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.
*
* @api
*/
@@ -241,8 +241,8 @@ typedef struct { * @param[in] ip pointer to a @p BaseBlockDevice or derived class
*
* @return The operation status.
- * @retval CH_SUCCESS operation succeeded.
- * @retval CH_FAILED operation failed.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
*
* @api
*/
@@ -255,8 +255,8 @@ typedef struct { * @param[out] bdip pointer to a @p BlockDeviceInfo structure
*
* @return The operation status.
- * @retval CH_SUCCESS operation succeeded.
- * @retval CH_FAILED operation failed.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
*
* @api
*/
@@ -264,6 +264,6 @@ typedef struct { /** @} */
-#endif /* _IO_BLOCK_H_ */
+#endif /* _HAL_IOBLOCK_H_ */
/** @} */
diff --git a/os/hal/include/mmcsd.h b/os/hal/include/hal_mmcsd.h index 5ff3082c7..09a789549 100644 --- a/os/hal/include/mmcsd.h +++ b/os/hal/include/hal_mmcsd.h @@ -19,7 +19,7 @@ */
/**
- * @file mmcsd.h
+ * @file hal_mmcsd.h
* @brief MMC/SD cards common header.
* @details This header defines an abstract interface useful to access MMC/SD
* I/O block devices in a standardized way.
@@ -28,8 +28,8 @@ * @{
*/
-#ifndef _MMCSD_H_
-#define _MMCSD_H_
+#ifndef _HAL_MMCSD_H_
+#define _HAL_MMCSD_H_
#if HAL_USE_MMC_SPI || HAL_USE_SDC || defined(__DOXYGEN__)
@@ -274,6 +274,6 @@ extern "C" { #endif /* HAL_USE_MMC_SPI || HAL_USE_MMC_SDC*/
-#endif /* _MMCSD_H_ */
+#endif /* _HAL_MMCSD_H_ */
/** @} */
diff --git a/os/hal/include/hal_queues.h b/os/hal/include/hal_queues.h new file mode 100644 index 000000000..4eb21d076 --- /dev/null +++ b/os/hal/include/hal_queues.h @@ -0,0 +1,403 @@ +/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012,2013 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 <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file hal_queues.h
+ * @brief I/O Queues macros and structures.
+ *
+ * @addtogroup io_queues
+ * @{
+ */
+
+#ifndef _HAL_QUEUES_H_
+#define _HAL_QUEUES_H_
+
+/* The ChibiOS/RT kernel provides the following definitions by itself, this
+ check is performed in order to avoid conflicts. */
+#if !defined(_CHIBIOS_RT_) || !CH_CFG_USE_QUEUES
+
+/**
+ * @name Queue functions returned status value
+ * @{
+ */
+#define Q_OK MSG_OK /**< @brief Operation successful. */
+#define Q_TIMEOUT MSG_TIMEOUT /**< @brief Timeout condition. */
+#define Q_RESET MSG_RESET /**< @brief Queue has been reset. */
+#define Q_EMPTY -3 /**< @brief Queue empty. */
+#define Q_FULL -4 /**< @brief Queue full, */
+/** @} */
+
+/**
+ * @brief Type of a generic I/O queue structure.
+ */
+typedef struct io_queue_t io_queue_t;
+
+/** @brief Queue notification callback type.*/
+typedef void (*qnotify_t)(io_queue_t *qp);
+
+/**
+ * @brief Generic I/O queue structure.
+ * @details This structure represents a generic Input or Output asymmetrical
+ * queue. The queue is asymmetrical because one end is meant to be
+ * accessed from a thread context, and thus can be blocking, the other
+ * end is accessible from interrupt handlers or from within a kernel
+ * lock zone (see <b>I-Locked</b> and <b>S-Locked</b> states in
+ * @ref system_states) and is non-blocking.
+ */
+struct io_queue_t {
+ threads_queue_t q_waiting; /**< @brief Waiting thread. */
+ size_t q_counter; /**< @brief Resources counter. */
+ uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
+ uint8_t *q_top; /**< @brief Pointer to the first
+ location after the buffer. */
+ uint8_t *q_wrptr; /**< @brief Write pointer. */
+ uint8_t *q_rdptr; /**< @brief Read pointer. */
+ qnotify_t q_notify; /**< @brief Data notification callback. */
+ void *q_link; /**< @brief Application defined field. */
+};
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the queue's buffer size.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure.
+ * @return The buffer size.
+ *
+ * @iclass
+ */
+#define qSizeI(qp) ((size_t)((qp)->q_top - (qp)->q_buffer))
+
+/**
+ * @brief Queue space.
+ * @details Returns the used space if used on an input queue or the empty
+ * space if used on an output queue.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure.
+ * @return The buffer space.
+ *
+ * @iclass
+ */
+#define qSpaceI(qp) ((qp)->q_counter)
+
+/**
+ * @brief Returns the queue application-defined link.
+ * @note This function can be called in any context.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure.
+ * @return The application-defined link.
+ *
+ * @special
+ */
+#define qGetLink(qp) ((qp)->q_link)
+/** @} */
+
+/**
+ * @extends io_queue_t
+ *
+ * @brief Type of an input queue structure.
+ * @details This structure represents a generic asymmetrical input queue.
+ * Writing to the queue is non-blocking and can be performed from
+ * interrupt handlers or from within a kernel lock zone (see
+ * <b>I-Locked</b> and <b>S-Locked</b> states in @ref system_states).
+ * Reading the queue can be a blocking operation and is supposed to
+ * be performed by a system thread.
+ */
+typedef io_queue_t input_queue_t;
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the filled space into an input queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The number of full bytes in the queue.
+ * @retval 0 if the queue is empty.
+ *
+ * @iclass
+ */
+#define iqGetFullI(iqp) qSpaceI(iqp)
+
+/**
+ * @brief Returns the empty space into an input queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The number of empty bytes in the queue.
+ * @retval 0 if the queue is full.
+ *
+ * @iclass
+ */
+#define iqGetEmptyI(iqp) (qSizeI(iqp) - qSpaceI(iqp))
+
+/**
+ * @brief Evaluates to @p TRUE if the specified input queue is empty.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure.
+ * @return The queue status.
+ * @retval FALSE if the queue is not empty.
+ * @retval TRUE if the queue is empty.
+ *
+ * @iclass
+ */
+#define iqIsEmptyI(iqp) ((bool)(qSpaceI(iqp) <= 0))
+
+/**
+ * @brief Evaluates to @p TRUE if the specified input queue is full.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure.
+ * @return The queue status.
+ * @retval FALSE if the queue is not full.
+ * @retval TRUE if the queue is full.
+ *
+ * @iclass
+ */
+#define iqIsFullI(iqp) ((bool)(((iqp)->q_wrptr == (iqp)->q_rdptr) && \
+ ((iqp)->q_counter != 0)))
+
+/**
+ * @brief Input queue read.
+ * @details This function reads a byte value from an input queue. If the queue
+ * is empty then the calling thread is suspended until a byte arrives
+ * in the queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return A byte value from the queue.
+ * @retval Q_RESET if the queue has been reset.
+ *
+ * @api
+ */
+#define iqGet(iqp) iqGetTimeout(iqp, TIME_INFINITE)
+/** @} */
+
+/**
+ * @brief Data part of a static input queue initializer.
+ * @details This macro should be used when statically initializing an
+ * input queue that is part of a bigger structure.
+ *
+ * @param[in] name the name of the input queue variable
+ * @param[in] buffer pointer to the queue buffer area
+ * @param[in] size size of the queue buffer area
+ * @param[in] inotify input notification callback pointer
+ * @param[in] link application defined pointer
+ */
+#define _INPUTQUEUE_DATA(name, buffer, size, inotify, link) { \
+ NULL, \
+ 0, \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer) + (size), \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer), \
+ (inotify), \
+ (link) \
+}
+
+/**
+ * @brief Static input queue initializer.
+ * @details Statically initialized input queues require no explicit
+ * initialization using @p iqInit().
+ *
+ * @param[in] name the name of the input queue variable
+ * @param[in] buffer pointer to the queue buffer area
+ * @param[in] size size of the queue buffer area
+ * @param[in] inotify input notification callback pointer
+ * @param[in] link application defined pointer
+ */
+#define INPUTQUEUE_DECL(name, buffer, size, inotify, link) \
+ input_queue_t name = _INPUTQUEUE_DATA(name, buffer, size, inotify, link)
+
+/**
+ * @extends io_queue_t
+ *
+ * @brief Type of an output queue structure.
+ * @details This structure represents a generic asymmetrical output queue.
+ * Reading from the queue is non-blocking and can be performed from
+ * interrupt handlers or from within a kernel lock zone (see
+ * <b>I-Locked</b> and <b>S-Locked</b> states in @ref system_states).
+ * Writing the queue can be a blocking operation and is supposed to
+ * be performed by a system thread.
+ */
+typedef io_queue_t output_queue_t;
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the filled space into an output queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The number of full bytes in the queue.
+ * @retval 0 if the queue is empty.
+ *
+ * @iclass
+ */
+#define oqGetFullI(oqp) (qSizeI(oqp) - qSpaceI(oqp))
+
+/**
+ * @brief Returns the empty space into an output queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The number of empty bytes in the queue.
+ * @retval 0 if the queue is full.
+ *
+ * @iclass
+ */
+#define oqGetEmptyI(oqp) qSpaceI(oqp)
+
+/**
+ * @brief Evaluates to @p TRUE if the specified output queue is empty.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure.
+ * @return The queue status.
+ * @retval FALSE if the queue is not empty.
+ * @retval TRUE if the queue is empty.
+ *
+ * @iclass
+ */
+#define oqIsEmptyI(oqp) ((bool)(((oqp)->q_wrptr == (oqp)->q_rdptr) && \
+ ((oqp)->q_counter != 0)))
+
+/**
+ * @brief Evaluates to @p TRUE if the specified output queue is full.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure.
+ * @return The queue status.
+ * @retval FALSE if the queue is not full.
+ * @retval TRUE if the queue is full.
+ *
+ * @iclass
+ */
+#define oqIsFullI(oqp) ((bool)(qSpaceI(oqp) <= 0))
+
+/**
+ * @brief Output queue write.
+ * @details This function writes a byte value to an output queue. If the queue
+ * is full then the calling thread is suspended until there is space
+ * in the queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @param[in] b the byte value to be written in the queue
+ * @return The operation status.
+ * @retval Q_OK if the operation succeeded.
+ * @retval Q_RESET if the queue has been reset.
+ *
+ * @api
+ */
+#define oqPut(oqp, b) oqPutTimeout(oqp, b, TIME_INFINITE)
+ /** @} */
+
+/**
+ * @brief Data part of a static output queue initializer.
+ * @details This macro should be used when statically initializing an
+ * output queue that is part of a bigger structure.
+ *
+ * @param[in] name the name of the output queue variable
+ * @param[in] buffer pointer to the queue buffer area
+ * @param[in] size size of the queue buffer area
+ * @param[in] onotify output notification callback pointer
+ * @param[in] link application defined pointer
+ */
+#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) { \
+ NULL, \
+ (size), \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer) + (size), \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer), \
+ (onotify), \
+ (link) \
+}
+
+/**
+ * @brief Static output queue initializer.
+ * @details Statically initialized output queues require no explicit
+ * initialization using @p oqInit().
+ *
+ * @param[in] name the name of the output queue variable
+ * @param[in] buffer pointer to the queue buffer area
+ * @param[in] size size of the queue buffer area
+ * @param[in] onotify output notification callback pointer
+ * @param[in] link application defined pointer
+ */
+#define OUTPUTQUEUE_DECL(name, buffer, size, onotify, link) \
+ output_queue_t name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void iqObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
+ qnotify_t infy, void *link);
+ void iqResetI(input_queue_t *iqp);
+ msg_t iqPutI(input_queue_t *iqp, uint8_t b);
+ msg_t iqGetTimeout(input_queue_t *iqp, systime_t time);
+ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
+ size_t n, systime_t time);
+
+ void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
+ qnotify_t onfy, void *link);
+ void oqResetI(output_queue_t *oqp);
+ msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time);
+ msg_t oqGetI(output_queue_t *oqp);
+ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
+ size_t n, systime_t time);
+#ifdef __cplusplus
+}
+#endif
+
+
+#else /* defined(_CHIBIOS_RT_) && CH_USE_QUEUES */
+
+/* If ChibiOS is being used and its own queues subsystem is activated then
+ this module will use the ChibiOS queues code.*/
+#define qSizeI(qp) chQSizeI(qp)
+#define qSpaceI(qp) chQSpaceI(qp)
+#define qGetLink(qp) chQGetLinkX(qp)
+#define iqGetFullI(iqp) chIQGetFullI(iqp)
+#define iqGetEmptyI(iqp) chIQGetEmptyI(iqp)
+#define iqIsEmptyI(iqp) chIQIsEmptyI(iqp)
+#define iqIsFullI(iqp) chIQIsFullI(iqp)
+#define iqGet(iqp) chIQGet(iqp)
+#define oqGetFullI(oqp) chOQGetFullI(oqp)
+#define oqGetEmptyI(oqp) chOQGetEmptyI(oqp)
+#define oqIsEmptyI(oqp) chOQIsEmptyI(oqp)
+#define oqIsFullI(oqp) chOQIsFullI(oqp)
+#define oqPut(oqp, b) chOQPut(oqp, b)
+#define iqObjectInit(iqp, bp, size, infy, link) \
+ chIQObjectInit(iqp, bp, size, infy, link)
+#define iqResetI(iqp) chIQResetI(iqp)
+#define iqPutI(iqp, b) chIQPutI(iqp, b)
+#define iqGetTimeout(iqp, time) chIQGetTimeout(iqp, time)
+#define iqReadTimeout(iqp, bp, n, time) chIQReadTimeout(iqp, bp, n, time)
+#define oqObjectInit(oqp, bp, size, onfy, link) \
+ chOQObjectInit(oqp, bp, size, onfy, link)
+#define oqResetI(oqp) chOQResetI(oqp)
+#define oqPutTimeout(oqp, b, time) chOQPutTimeout(oqp, b, time)
+#define oqGetI(oqp) chOQGetI(oqp)
+#define oqWriteTimeout(oqp, bp, n, time) chOQWriteTimeout(oqp, bp, n, time)
+
+#endif /* defined(_CHIBIOS_RT_) && CH_USE_QUEUES */
+
+#endif /* _HAL_QUEUES_H_ */
+
+/** @} */
diff --git a/os/hal/include/hal_streams.h b/os/hal/include/hal_streams.h new file mode 100644 index 000000000..e18a7e461 --- /dev/null +++ b/os/hal/include/hal_streams.h @@ -0,0 +1,162 @@ +/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012,2013 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 <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file hal_streams.h
+ * @brief Data streams.
+ * @details This header defines abstract interfaces useful to access generic
+ * data streams in a standardized way.
+ *
+ * @addtogroup data_streams
+ * @details This module define an abstract interface for generic data streams.
+ * Note that no code is present, just abstract interfaces-like
+ * structures, you should look at the system as to a set of
+ * abstract C++ classes (even if written in C). This system
+ * has then advantage to make the access to data streams
+ * independent from the implementation logic.<br>
+ * The stream interface can be used as base class for high level
+ * object types such as files, sockets, serial ports, pipes etc.
+ * @{
+ */
+
+#ifndef _HAL_STREAMS_H_
+#define _HAL_STREAMS_H_
+
+/**
+ * @name Streams return codes
+ * @{
+ */
+#define STM_OK Q_OK
+#define STM_TIMEOUT Q_TIMEOUT
+#define STM_RESET Q_RESET
+/** @} */
+
+/* The ChibiOS/RT kernel provides the following definitions by itself, this
+ check is performed in order to avoid conflicts. */
+#if !defined(_CHIBIOS_RT_) || defined(__DOXYGEN__)
+
+/**
+ * @brief BaseSequentialStream specific methods.
+ */
+#define _base_sequential_stream_methods \
+ /* Stream write buffer method.*/ \
+ size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
+ /* Stream read buffer method.*/ \
+ size_t (*read)(void *instance, uint8_t *bp, size_t n); \
+ /* Channel put method, blocking.*/ \
+ msg_t (*put)(void *instance, uint8_t b); \
+ /* Channel get method, blocking.*/ \
+ msg_t (*get)(void *instance); \
+
+/**
+ * @brief @p BaseSequentialStream specific data.
+ * @note It is empty because @p BaseSequentialStream is only an interface
+ * without implementation.
+ */
+#define _base_sequential_stream_data
+
+/**
+ * @brief @p BaseSequentialStream virtual methods table.
+ */
+struct BaseSequentialStreamVMT {
+ _base_sequential_stream_methods
+};
+
+/**
+ * @brief Base stream class.
+ * @details This class represents a generic blocking unbuffered sequential
+ * data stream.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseSequentialStreamVMT *vmt;
+ _base_sequential_stream_data
+} BaseSequentialStream;
+
+#endif /* !defined(_CHIBIOS_RT_)*/
+
+/**
+ * @name Macro Functions (BaseSequentialStream)
+ * @{
+ */
+/**
+ * @brief Sequential Stream write.
+ * @details The function writes data from a buffer to a stream.
+ *
+ * @param[in] ip pointer to a @p BaseSequentialStream or derived class
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamWrite(ip, bp, n) ((ip)->vmt->write(ip, bp, n))
+
+/**
+ * @brief Sequential Stream read.
+ * @details The function reads data from a stream into a buffer.
+ *
+ * @param[in] ip pointer to a @p BaseSequentialStream or derived class
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))
+
+/**
+ * @brief Sequential Stream blocking byte write.
+ * @details This function writes a byte value to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] b the byte value to be written to the channel
+ *
+ * @return The operation status.
+ * @retval STM_OK if the operation succeeded.
+ * @retval STM_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamPut(ip, b) ((ip)->vmt->put(ip, b))
+
+/**
+ * @brief Sequential Stream blocking byte read.
+ * @details This function reads a byte value from a channel. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ *
+ * @return A byte value from the queue.
+ * @retval STM_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamGet(ip) ((ip)->vmt->get(ip))
+/** @} */
+
+#endif /* _HAL_STREAMS_H_ */
+
+/** @} */
diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index 2e45450ee..dfae26e64 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -39,19 +39,20 @@ /* Driver constants. */
/*===========================================================================*/
+/* TODO: To be reviewed, too STM32-centric.*/
/**
* @name I2C bus error conditions
* @{
*/
-#define I2CD_NO_ERROR 0x00 /**< @brief No error. */
-#define I2CD_BUS_ERROR 0x01 /**< @brief Bus Error. */
-#define I2CD_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
-#define I2CD_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
-#define I2CD_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
-#define I2CD_PEC_ERROR 0x10 /**< @brief PEC Error in
+#define I2C_NO_ERROR 0x00 /**< @brief No error. */
+#define I2C_BUS_ERROR 0x01 /**< @brief Bus Error. */
+#define I2C_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
+#define I2C_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
+#define I2C_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
+#define I2C_PEC_ERROR 0x10 /**< @brief PEC Error in
reception. */
-#define I2CD_TIMEOUT 0x20 /**< @brief Hardware timeout. */
-#define I2CD_SMB_ALERT 0x40 /**< @brief SMBus Alert. */
+#define I2C_TIMEOUT 0x20 /**< @brief Hardware timeout. */
+#define I2C_SMB_ALERT 0x40 /**< @brief SMBus Alert. */
/** @} */
/*===========================================================================*/
@@ -69,10 +70,6 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if I2C_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "I2C_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -96,6 +93,32 @@ typedef enum { /*===========================================================================*/
/**
+ * @brief Wakes up the waiting thread notifying no errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+} while(0)
+
+/**
+ * @brief Wakes up the waiting thread notifying errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_error_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_RESET); \
+ osalSysUnlockFromISR(); \
+} while(0)
+
+/**
* @brief Wrap i2cMasterTransmitTimeout function with TIME_INFINITE timeout.
* @api
*/
diff --git a/os/hal/include/i2s.h b/os/hal/include/i2s.h index b2dacbb49..711ec3b5c 100644 --- a/os/hal/include/i2s.h +++ b/os/hal/include/i2s.h @@ -41,9 +41,6 @@ */
#define I2S_MODE_SLAVE 0
#define I2S_MODE_MASTER 1
-#define I2S_MODE_TX 2
-#define I2S_MODE_RX 4
-#define I2S_MODE_TXRX (I2S_MODE_TX | I2S_MODE_RX)
/** @} */
/*===========================================================================*/
@@ -69,11 +66,6 @@ typedef enum { I2S_COMPLETE = 4 /**< Transmission complete. */
} i2sstate_t;
-/**
- * @brief Type of a structure representing a I2S driver.
- */
-typedef struct I2SDriver I2SDriver;
-
#include "i2s_lld.h"
/*===========================================================================*/
@@ -88,6 +80,10 @@ typedef struct I2SDriver I2SDriver; * @brief Starts a I2S data exchange.
*
* @param[in] i2sp pointer to the @p I2SDriver object
+ * @param[in] n size of the transmit buffer, must be even and greater
+ * than zero
+ * @param[out] txbuf the pointer to the transmit buffer
+ * @param[out] rxbuf the pointer to the receive buffer
*
* @iclass
*/
@@ -97,18 +93,6 @@ typedef struct I2SDriver I2SDriver; }
/**
- * @brief Starts a I2S data exchange in continuous mode.
- *
- * @param[in] i2sp pointer to the @p I2SDriver object
- *
- * @iclass
- */
-#define i2sStartExchangeContinuousI(i2sp) { \
- i2s_lld_start_exchange_continuous(i2sp); \
- (i2sp)->state = I2S_ACTIVE; \
-}
-
-/**
* @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.
@@ -122,6 +106,49 @@ typedef struct I2SDriver I2SDriver; (i2sp)->state = I2S_READY; \
}
+/**
+ * @brief Common ISR code, half buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] i2sp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2s_isr_half_code(i2sp) { \
+ if ((i2sp)->config->end_cb != NULL) { \
+ (i2sp)->config->end_cb(i2sp, 0, (i2sp)->config->size / 2); \
+ } \
+}
+
+/**
+ * @brief Common ISR code.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] i2sp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2s_isr_full_code(i2sp) { \
+ if ((i2sp)->config->end_cb) { \
+ (i2sp)->state = I2S_COMPLETE; \
+ (i2sp)->config->end_cb(i2sp, \
+ (i2sp)->config->size / 2, \
+ (i2sp)->config->size / 2); \
+ if ((i2sp)->state == I2S_COMPLETE) \
+ (i2sp)->state = I2S_READY; \
+ } \
+ else \
+ (i2sp)->state = I2S_READY; \
+}
/** @} */
/*===========================================================================*/
diff --git a/os/hal/include/mac.h b/os/hal/include/mac.h deleted file mode 100644 index 868460ad5..000000000 --- a/os/hal/include/mac.h +++ /dev/null @@ -1,214 +0,0 @@ -/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012,2013 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 <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file mac.h
- * @brief MAC Driver macros and structures.
- * @addtogroup MAC
- * @{
- */
-
-#ifndef _MAC_H_
-#define _MAC_H_
-
-#if HAL_USE_MAC || defined(__DOXYGEN__)
-
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
-
-/**
- * @name MAC configuration options
- * @{
- */
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
-#define MAC_USE_ZERO_COPY FALSE
-#endif
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
-#define MAC_USE_EVENTS TRUE
-#endif
-/** @} */
-
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
-
-#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
-#error "the MAC driver requires CH_USE_SEMAPHORES"
-#endif
-
-#if MAC_USE_EVENTS && !CH_USE_EVENTS
-#error "the MAC driver requires CH_USE_EVENTS"
-#endif
-
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
-
-/**
- * @brief Driver state machine possible states.
- */
-typedef enum {
- MAC_UNINIT = 0, /**< Not initialized. */
- MAC_STOP = 1, /**< Stopped. */
- MAC_ACTIVE = 2 /**< Active. */
-} macstate_t;
-
-/**
- * @brief Type of a structure representing a MAC driver.
- */
-typedef struct MACDriver MACDriver;
-
-#include "mac_lld.h"
-
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
-
-/**
- * @name Macro Functions
- * @{
- */
-/**
- * @brief Returns the received frames event source.
- *
- * @param[in] macp pointer to the @p MACDriver object
- * @return The pointer to the @p EventSource structure.
- *
- * @api
- */
-#if MAC_USE_EVENTS || defined(__DOXYGEN__)
-#define macGetReceiveEventSource(macp) (&(macp)->rdevent)
-#endif
-
-/**
- * @brief Writes to a transmit descriptor's stream.
- *
- * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
- * @param[in] buf pointer to the buffer containing the data to be written
- * @param[in] size number of bytes to be written
- * @return The number of bytes written into the descriptor's
- * stream, this value can be less than the amount
- * specified in the parameter @p size if the maximum frame
- * size is reached.
- *
- * @api
- */
-#define macWriteTransmitDescriptor(tdp, buf, size) \
- mac_lld_write_transmit_descriptor(tdp, buf, size)
-
-/**
- * @brief Reads from a receive descriptor's stream.
- *
- * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
- * @param[in] buf pointer to the buffer that will receive the read data
- * @param[in] size number of bytes to be read
- * @return The number of bytes read from the descriptor's stream,
- * this value can be less than the amount specified in the
- * parameter @p size if there are no more bytes to read.
- *
- * @api
- */
-#define macReadReceiveDescriptor(rdp, buf, size) \
- mac_lld_read_receive_descriptor(rdp, buf, size)
-
-#if MAC_USE_ZERO_COPY || defined(__DOXYGEN__)
-/**
- * @brief Returns a pointer to the next transmit buffer in the descriptor
- * chain.
- * @note The API guarantees that enough buffers can be requested to fill
- * a whole frame.
- *
- * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
- * @param[in] size size of the requested buffer. Specify the frame size
- * on the first call then scale the value down subtracting
- * the amount of data already copied into the previous
- * buffers.
- * @param[out] sizep pointer to variable receiving the real buffer size.
- * The returned value can be less than the amount
- * requested, this means that more buffers must be
- * requested in order to fill the frame data entirely.
- * @return Pointer to the returned buffer.
- *
- * @api
- */
-#define macGetNextTransmitBuffer(tdp, size, sizep) \
- mac_lld_get_next_transmit_buffer(tdp, size, sizep)
-
-/**
- * @brief Returns a pointer to the next receive buffer in the descriptor
- * chain.
- * @note The API guarantees that the descriptor chain contains a whole
- * frame.
- *
- * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
- * @param[out] sizep pointer to variable receiving the buffer size, it is
- * zero when the last buffer has already been returned.
- * @return Pointer to the returned buffer.
- * @retval NULL if the buffer chain has been entirely scanned.
- *
- * @api
- */
-#define macGetNextReceiveBuffer(rdp, sizep) \
- mac_lld_get_next_receive_buffer(rdp, sizep)
-#endif /* MAC_USE_ZERO_COPY */
-/** @} */
-
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- void macInit(void);
- void macObjectInit(MACDriver *macp);
- void macStart(MACDriver *macp, const MACConfig *config);
- void macStop(MACDriver *macp);
- void macSetAddress(MACDriver *macp, const uint8_t *p);
- msg_t macWaitTransmitDescriptor(MACDriver *macp,
- MACTransmitDescriptor *tdp,
- systime_t time);
- void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
- msg_t macWaitReceiveDescriptor(MACDriver *macp,
- MACReceiveDescriptor *rdp,
- systime_t time);
- void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp);
- bool_t macPollLinkStatus(MACDriver *macp);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HAL_USE_MAC */
-
-#endif /* _MAC_H_ */
-
-/** @} */
diff --git a/os/hal/include/mii.h b/os/hal/include/mii.h deleted file mode 100644 index d4b65da54..000000000 --- a/os/hal/include/mii.h +++ /dev/null @@ -1,162 +0,0 @@ -/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012,2013 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 <http://www.gnu.org/licenses/>.
-*/
-
-/*-*
- * @file mii.h
- * @brief MII Driver macros and structures.
- *
- * @addtogroup MII
- * @{
- */
-
-#ifndef _MII_H_
-#define _MII_H_
-
-/*
- * Generic MII registers. Note, not all registers are present on all PHY
- * devices and some extra registers may be present.
- */
-#define MII_BMCR 0x00 /**< Basic mode control register. */
-#define MII_BMSR 0x01 /**< Basic mode status register. */
-#define MII_PHYSID1 0x02 /**< PHYS ID 1. */
-#define MII_PHYSID2 0x03 /**< PHYS ID 2. */
-#define MII_ADVERTISE 0x04 /**< Advertisement control reg. */
-#define MII_LPA 0x05 /**< Link partner ability reg. */
-#define MII_EXPANSION 0x06 /**< Expansion register. */
-#define MII_ANNPTR 0x07 /**< 1000BASE-T control. */
-#define MII_CTRL1000 0x09 /**< 1000BASE-T control. */
-#define MII_STAT1000 0x0a /**< 1000BASE-T status. */
-#define MII_ESTATUS 0x0f /**< Extended Status. */
-#define MII_PHYSTS 0x10 /**< PHY Status register. */
-#define MII_MICR 0x11 /**< MII Interrupt ctrl register. */
-#define MII_DCOUNTER 0x12 /**< Disconnect counter. */
-#define MII_FCSCOUNTER 0x13 /**< False carrier counter. */
-#define MII_NWAYTEST 0x14 /**< N-way auto-neg test reg. */
-#define MII_RERRCOUNTER 0x15 /**< Receive error counter. */
-#define MII_SREVISION 0x16 /**< Silicon revision. */
-#define MII_RESV1 0x17 /**< Reserved. */
-#define MII_LBRERROR 0x18 /**< Lpback, rx, bypass error. */
-#define MII_PHYADDR 0x19 /**< PHY address. */
-#define MII_RESV2 0x1a /**< Reserved. */
-#define MII_TPISTATUS 0x1b /**< TPI status for 10Mbps. */
-#define MII_NCONFIG 0x1c /**< Network interface config. */
-
-/*
- * Basic mode control register.
- */
-#define BMCR_RESV 0x007f /**< Unused. */
-#define BMCR_CTST 0x0080 /**< Collision test. */
-#define BMCR_FULLDPLX 0x0100 /**< Full duplex. */
-#define BMCR_ANRESTART 0x0200 /**< Auto negotiation restart. */
-#define BMCR_ISOLATE 0x0400 /**< Disconnect DP83840 from MII. */
-#define BMCR_PDOWN 0x0800 /**< Powerdown. */
-#define BMCR_ANENABLE 0x1000 /**< Enable auto negotiation. */
-#define BMCR_SPEED100 0x2000 /**< Select 100Mbps. */
-#define BMCR_LOOPBACK 0x4000 /**< TXD loopback bit. */
-#define BMCR_RESET 0x8000 /**< Reset. */
-
-/*
- * Basic mode status register.
- */
-#define BMSR_ERCAP 0x0001 /**< Ext-reg capability. */
-#define BMSR_JCD 0x0002 /**< Jabber detected. */
-#define BMSR_LSTATUS 0x0004 /**< Link status. */
-#define BMSR_ANEGCAPABLE 0x0008 /**< Able to do auto-negotiation. */
-#define BMSR_RFAULT 0x0010 /**< Remote fault detected. */
-#define BMSR_ANEGCOMPLETE 0x0020 /**< Auto-negotiation complete. */
-#define BMSR_MFPRESUPPCAP 0x0040 /**< Able to suppress preamble. */
-#define BMSR_RESV 0x0780 /**< Unused. */
-#define BMSR_10HALF 0x0800 /**< Can do 10mbps, half-duplex. */
-#define BMSR_10FULL 0x1000 /**< Can do 10mbps, full-duplex. */
-#define BMSR_100HALF 0x2000 /**< Can do 100mbps, half-duplex. */
-#define BMSR_100FULL 0x4000 /**< Can do 100mbps, full-duplex. */
-#define BMSR_100BASE4 0x8000 /**< Can do 100mbps, 4k packets. */
-
-/*
- * Advertisement control register.
- */
-#define ADVERTISE_SLCT 0x001f /**< Selector bits. */
-#define ADVERTISE_CSMA 0x0001 /**< Only selector supported. */
-#define ADVERTISE_10HALF 0x0020 /**< Try for 10mbps half-duplex. */
-#define ADVERTISE_10FULL 0x0040 /**< Try for 10mbps full-duplex. */
-#define ADVERTISE_100HALF 0x0080 /**< Try for 100mbps half-duplex. */
-#define ADVERTISE_100FULL 0x0100 /**< Try for 100mbps full-duplex. */
-#define ADVERTISE_100BASE4 0x0200 /**< Try for 100mbps 4k packets. */
-#define ADVERTISE_PAUSE_CAP 0x0400 /**< Try for pause. */
-#define ADVERTISE_PAUSE_ASYM 0x0800 /**< Try for asymetric pause. */
-#define ADVERTISE_RESV 0x1000 /**< Unused. */
-#define ADVERTISE_RFAULT 0x2000 /**< Say we can detect faults. */
-#define ADVERTISE_LPACK 0x4000 /**< Ack link partners response. */
-#define ADVERTISE_NPAGE 0x8000 /**< Next page bit. */
-
-#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
- ADVERTISE_CSMA)
-#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
- ADVERTISE_100HALF | ADVERTISE_100FULL)
-
-/*
- * Link partner ability register.
- */
-#define LPA_SLCT 0x001f /**< Same as advertise selector. */
-#define LPA_10HALF 0x0020 /**< Can do 10mbps half-duplex. */
-#define LPA_10FULL 0x0040 /**< Can do 10mbps full-duplex. */
-#define LPA_100HALF 0x0080 /**< Can do 100mbps half-duplex. */
-#define LPA_100FULL 0x0100 /**< Can do 100mbps full-duplex. */
-#define LPA_100BASE4 0x0200 /**< Can do 100mbps 4k packets. */
-#define LPA_PAUSE_CAP 0x0400 /**< Can pause. */
-#define LPA_PAUSE_ASYM 0x0800 /**< Can pause asymetrically. */
-#define LPA_RESV 0x1000 /**< Unused. */
-#define LPA_RFAULT 0x2000 /**< Link partner faulted. */
-#define LPA_LPACK 0x4000 /**< Link partner acked us. */
-#define LPA_NPAGE 0x8000 /**< Next page bit. */
-
-#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
-#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
-
-/*
- * Expansion register for auto-negotiation.
- */
-#define EXPANSION_NWAY 0x0001 /**< Can do N-way auto-nego. */
-#define EXPANSION_LCWP 0x0002 /**< Got new RX page code word. */
-#define EXPANSION_ENABLENPAGE 0x0004 /**< This enables npage words. */
-#define EXPANSION_NPCAPABLE 0x0008 /**< Link partner supports npage. */
-#define EXPANSION_MFAULTS 0x0010 /**< Multiple faults detected. */
-#define EXPANSION_RESV 0xffe0 /**< Unused. */
-
-/*
- * N-way test register.
- */
-#define NWAYTEST_RESV1 0x00ff /**< Unused. */
-#define NWAYTEST_LOOPBACK 0x0100 /**< Enable loopback for N-way. */
-#define NWAYTEST_RESV2 0xfe00 /**< Unused. */
-
-/*
- * PHY identifiers.
- */
-#define MII_DM9161_ID 0x0181b8a0
-#define MII_AM79C875_ID 0x00225540
-#define MII_KS8721_ID 0x00221610
-#define MII_STE101P_ID 0x00061C50
-#define MII_DP83848I_ID 0x20005C90
-#define MII_LAN8710A_ID 0x0007C0F1
-
-#endif /* _MII_H_ */
-
-/** @} */
diff --git a/os/hal/include/mmc_spi.h b/os/hal/include/mmc_spi.h index 2610d0024..9f51f7e2b 100644 --- a/os/hal/include/mmc_spi.h +++ b/os/hal/include/mmc_spi.h @@ -124,7 +124,7 @@ typedef struct { /***
* @brief Addresses use blocks instead of bytes.
*/
- bool_t block_addresses;
+ bool block_addresses;
} MMCDriver;
/*===========================================================================*/
@@ -175,19 +175,19 @@ extern "C" { void mmcObjectInit(MMCDriver *mmcp);
void mmcStart(MMCDriver *mmcp, const MMCConfig *config);
void mmcStop(MMCDriver *mmcp);
- bool_t mmcConnect(MMCDriver *mmcp);
- bool_t mmcDisconnect(MMCDriver *mmcp);
- bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk);
- bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer);
- bool_t mmcStopSequentialRead(MMCDriver *mmcp);
- bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
- bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
- bool_t mmcStopSequentialWrite(MMCDriver *mmcp);
- bool_t mmcSync(MMCDriver *mmcp);
- bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
- bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk);
- bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp);
- bool_t mmc_lld_is_write_protected(MMCDriver *mmcp);
+ bool mmcConnect(MMCDriver *mmcp);
+ bool mmcDisconnect(MMCDriver *mmcp);
+ bool mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk);
+ bool mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer);
+ bool mmcStopSequentialRead(MMCDriver *mmcp);
+ bool mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
+ bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
+ bool mmcStopSequentialWrite(MMCDriver *mmcp);
+ bool mmcSync(MMCDriver *mmcp);
+ bool mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
+ bool mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk);
+ bool mmc_lld_is_card_inserted(MMCDriver *mmcp);
+ bool mmc_lld_is_write_protected(MMCDriver *mmcp);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/pwm.h b/os/hal/include/pwm.h index cdd1f43ca..4ece68d70 100644 --- a/os/hal/include/pwm.h +++ b/os/hal/include/pwm.h @@ -169,13 +169,13 @@ typedef void (*pwmcallback_t)(PWMDriver *pwmp); * guaranteed.
*
* @param[in] pwmp pointer to a @p PWMDriver object
- * @param[in] value new cycle time in ticks
+ * @param[in] period new cycle time in ticks
*
* @iclass
*/
-#define pwmChangePeriodI(pwmp, value) { \
- (pwmp)->period = (value); \
- pwm_lld_change_period(pwmp, value); \
+#define pwmChangePeriodI(pwmp, period) { \
+ (pwmp)->period = (period); \
+ pwm_lld_change_period(pwmp, period); \
}
/**
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h deleted file mode 100644 index b510df907..000000000 --- a/os/hal/include/rtc.h +++ /dev/null @@ -1,171 +0,0 @@ -/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012,2013 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 <http://www.gnu.org/licenses/>.
-*/
-/*
- Concepts and parts of this file have been contributed by Uladzimir Pylinsky
- aka barthess.
- */
-
-/**
- * @file rtc.h
- * @brief RTC Driver macros and structures.
- *
- * @addtogroup RTC
- * @{
- */
-
-#ifndef _RTC_H_
-#define _RTC_H_
-
-#if HAL_USE_RTC || defined(__DOXYGEN__)
-
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
-
-/**
- * @name Date/Time bit masks
- * @{
- */
-#define RTC_TIME_SECONDS_MASK 0x0000001F /* @brief Seconds mask. */
-#define RTC_TIME_MINUTES_MASK 0x000007E0 /* @brief Minutes mask. */
-#define RTC_TIME_HOURS_MASK 0x0000F800 /* @brief Hours mask. */
-#define RTC_DATE_DAYS_MASK 0x001F0000 /* @brief Days mask. */
-#define RTC_DATE_MONTHS_MASK 0x01E00000 /* @brief Months mask. */
-#define RTC_DATE_YEARS_MASK 0xFE000000 /* @brief Years mask. */
-/** @} */
-
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
-
-/**
- * @brief Type of a structure representing an RTC driver.
- */
-typedef struct RTCDriver RTCDriver;
-
-/**
- * @brief Type of a structure representing an RTC time stamp.
- */
-typedef struct RTCTime RTCTime;
-
-#include "rtc_lld.h"
-
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
-
-/**
- * @brief Set current time.
- *
- * @param[in] rtcp pointer to RTC driver structure
- * @param[in] timespec pointer to a @p RTCTime structure
- *
- * @iclass
- */
-#define rtcSetTimeI(rtcp, timespec) rtc_lld_set_time(rtcp, timespec)
-
-/**
- * @brief Get current time.
- *
- * @param[in] rtcp pointer to RTC driver structure
- * @param[out] timespec pointer to a @p RTCTime structure
- *
- * @iclass
- */
-#define rtcGetTimeI(rtcp, timespec) rtc_lld_get_time(rtcp, timespec)
-
-#if (RTC_ALARMS > 0) || defined(__DOXYGEN__)
-/**
- * @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
- *
- * @iclass
- */
-#define rtcSetAlarmI(rtcp, alarm, alarmspec) \
- rtc_lld_set_alarm(rtcp, alarm, alarmspec)
-
-/**
- * @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
- *
- * @iclass
- */
-#define rtcGetAlarmI(rtcp, alarm, alarmspec) \
- rtc_lld_get_alarm(rtcp, alarm, alarmspec)
-#endif /* RTC_ALARMS > 0 */
-
-#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
-/**
- * @brief Enables or disables RTC callbacks.
- * @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
- *
- * @iclass
- */
-#define rtcSetCallbackI(rtcp, callback) rtc_lld_set_callback(rtcp, callback)
-#endif /* RTC_SUPPORTS_CALLBACKS */
-
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- void rtcInit(void);
- void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
- void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec);
-#if RTC_ALARMS > 0
- void rtcSetAlarm(RTCDriver *rtcp,
- rtcalarm_t alarm,
- const RTCAlarm *alarmspec);
- void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec);
-#endif
- uint32_t rtcGetTimeFat(RTCDriver *rtcp);
-#if RTC_SUPPORTS_CALLBACKS
- void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HAL_USE_RTC */
-#endif /* _RTC_H_ */
-
-/** @} */
diff --git a/os/hal/include/sdc.h b/os/hal/include/sdc.h index 0975ed167..3948a6189 100644 --- a/os/hal/include/sdc.h +++ b/os/hal/include/sdc.h @@ -36,30 +36,30 @@ /*===========================================================================*/
/**
- * @name SD cart types
+ * @name SD card types
* @{
*/
-#define SDC_MODE_CARDTYPE_MASK 0xF /**< @brief Card type mask. */
-#define SDC_MODE_CARDTYPE_SDV11 0 /**< @brief Card is SD V1.1.*/
-#define SDC_MODE_CARDTYPE_SDV20 1 /**< @brief Card is SD V2.0.*/
-#define SDC_MODE_CARDTYPE_MMC 2 /**< @brief Card is MMC. */
-#define SDC_MODE_HIGH_CAPACITY 0x10 /**< @brief High cap.card. */
+#define SDC_MODE_CARDTYPE_MASK 0xF /**< @brief Card type mask. */
+#define SDC_MODE_CARDTYPE_SDV11 0
+#define SDC_MODE_CARDTYPE_SDV20 1
+#define SDC_MODE_CARDTYPE_MMC 2
+#define SDC_MODE_HIGH_CAPACITY 0x10
/** @} */
/**
* @name SDC bus error conditions
* @{
*/
-#define SDC_NO_ERROR 0 /**< @brief No error. */
-#define SDC_CMD_CRC_ERROR 1 /**< @brief Command CRC error. */
-#define SDC_DATA_CRC_ERROR 2 /**< @brief Data CRC error. */
-#define SDC_DATA_TIMEOUT 4 /**< @brief HW write timeout. */
-#define SDC_COMMAND_TIMEOUT 8 /**< @brief HW read timeout. */
-#define SDC_TX_UNDERRUN 16 /**< @brief TX buffer underrun. */
-#define SDC_RX_OVERRUN 32 /**< @brief RX buffer overrun. */
-#define SDC_STARTBIT_ERROR 64 /**< @brief Start bit missing. */
-#define SDC_OVERFLOW_ERROR 128 /**< @brief Card overflow error. */
-#define SDC_UNHANDLED_ERROR 0xFFFFFFFF
+#define SDC_NO_ERROR 0
+#define SDC_CMD_CRC_ERROR 1
+#define SDC_DATA_CRC_ERROR 2
+#define SDC_DATA_TIMEOUT 4
+#define SDC_COMMAND_TIMEOUT 8
+#define SDC_TX_UNDERRUN 16
+#define SDC_RX_OVERRUN 32
+#define SDC_STARTBIT_ERROR 64
+#define SDC_OVERFLOW_ERROR 128
+#define SDC_UNHANDLED_ERROR 0xFFFFFFFF
/** @} */
/*===========================================================================*/
@@ -75,7 +75,7 @@ * @note Attempts are performed at 10mS intervals.
*/
#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
-#define SDC_INIT_RETRY 100
+#define SDC_INIT_RETRY 100
#endif
/**
@@ -84,7 +84,7 @@ * at @p FALSE.
*/
#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
-#define SDC_MMC_SUPPORT FALSE
+#define SDC_MMC_SUPPORT FALSE
#endif
/**
@@ -94,7 +94,7 @@ * lower priority, this may slow down the driver a bit however.
*/
#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
-#define SDC_NICE_WAITING TRUE
+#define SDC_NICE_WAITING TRUE
#endif
/** @} */
@@ -160,17 +160,17 @@ extern "C" { void sdcObjectInit(SDCDriver *sdcp);
void sdcStart(SDCDriver *sdcp, const SDCConfig *config);
void sdcStop(SDCDriver *sdcp);
- bool_t sdcConnect(SDCDriver *sdcp);
- bool_t sdcDisconnect(SDCDriver *sdcp);
- bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk,
- uint8_t *buffer, uint32_t n);
- bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk,
- const uint8_t *buffer, uint32_t n);
+ bool sdcConnect(SDCDriver *sdcp);
+ bool sdcDisconnect(SDCDriver *sdcp);
+ bool sdcRead(SDCDriver *sdcp, uint32_t startblk,
+ uint8_t *buffer, uint32_t n);
+ bool sdcWrite(SDCDriver *sdcp, uint32_t startblk,
+ const uint8_t *buffer, uint32_t n);
sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp);
- bool_t sdcSync(SDCDriver *sdcp);
- bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
- bool_t sdcErase(SDCDriver *mmcp, uint32_t startblk, uint32_t endblk);
- bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp);
+ bool sdcSync(SDCDriver *sdcp);
+ bool sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
+ bool sdcErase(SDCDriver *mmcp, uint32_t startblk, uint32_t endblk);
+ bool _sdc_wait_for_transfer_state(SDCDriver *sdcp);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/serial.h b/os/hal/include/serial.h index 213a3c132..8ea2248bd 100644 --- a/os/hal/include/serial.h +++ b/os/hal/include/serial.h @@ -79,10 +79,6 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if !CH_USE_QUEUES && !CH_USE_EVENTS
-#error "Serial Driver requires CH_USE_QUEUES and CH_USE_EVENTS"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -149,7 +145,7 @@ struct SerialDriver { *
* @api
*/
-#define sdPutWouldBlock(sdp) chOQIsFullI(&(sdp)->oqueue)
+#define sdPutWouldBlock(sdp) oqIsFullI(&(sdp)->oqueue)
/**
* @brief Direct input check on a @p SerialDriver.
@@ -161,7 +157,7 @@ struct SerialDriver { *
* @api
*/
-#define sdGetWouldBlock(sdp) chIQIsEmptyI(&(sdp)->iqueue)
+#define sdGetWouldBlock(sdp) iqIsEmptyI(&(sdp)->iqueue)
/**
* @brief Direct write to a @p SerialDriver.
@@ -173,7 +169,7 @@ struct SerialDriver { *
* @api
*/
-#define sdPut(sdp, b) chOQPut(&(sdp)->oqueue, b)
+#define sdPut(sdp, b) oqPut(&(sdp)->oqueue, b)
/**
* @brief Direct write to a @p SerialDriver with timeout specification.
@@ -185,7 +181,7 @@ struct SerialDriver { *
* @api
*/
-#define sdPutTimeout(sdp, b, t) chOQPutTimeout(&(sdp)->oqueue, b, t)
+#define sdPutTimeout(sdp, b, t) oqPutTimeout(&(sdp)->oqueue, b, t)
/**
* @brief Direct read from a @p SerialDriver.
@@ -197,7 +193,7 @@ struct SerialDriver { *
* @api
*/
-#define sdGet(sdp) chIQGet(&(sdp)->iqueue)
+#define sdGet(sdp) iqGet(&(sdp)->iqueue)
/**
* @brief Direct read from a @p SerialDriver with timeout specification.
@@ -209,7 +205,7 @@ struct SerialDriver { *
* @api
*/
-#define sdGetTimeout(sdp, t) chIQGetTimeout(&(sdp)->iqueue, t)
+#define sdGetTimeout(sdp, t) iqGetTimeout(&(sdp)->iqueue, t)
/**
* @brief Direct blocking write to a @p SerialDriver.
@@ -222,7 +218,7 @@ struct SerialDriver { * @api
*/
#define sdWrite(sdp, b, n) \
- chOQWriteTimeout(&(sdp)->oqueue, b, n, TIME_INFINITE)
+ oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_INFINITE)
/**
* @brief Direct blocking write to a @p SerialDriver with timeout
@@ -236,7 +232,7 @@ struct SerialDriver { * @api
*/
#define sdWriteTimeout(sdp, b, n, t) \
- chOQWriteTimeout(&(sdp)->oqueue, b, n, t)
+ oqWriteTimeout(&(sdp)->oqueue, b, n, t)
/**
* @brief Direct non-blocking write to a @p SerialDriver.
@@ -249,7 +245,7 @@ struct SerialDriver { * @api
*/
#define sdAsynchronousWrite(sdp, b, n) \
- chOQWriteTimeout(&(sdp)->oqueue, b, n, TIME_IMMEDIATE)
+ oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_IMMEDIATE)
/**
* @brief Direct blocking read from a @p SerialDriver.
@@ -262,7 +258,7 @@ struct SerialDriver { * @api
*/
#define sdRead(sdp, b, n) \
- chIQReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)
+ iqReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)
/**
* @brief Direct blocking read from a @p SerialDriver with timeout
@@ -276,7 +272,7 @@ struct SerialDriver { * @api
*/
#define sdReadTimeout(sdp, b, n, t) \
- chIQReadTimeout(&(sdp)->iqueue, b, n, t)
+ iqReadTimeout(&(sdp)->iqueue, b, n, t)
/**
* @brief Direct non-blocking read from a @p SerialDriver.
@@ -289,7 +285,7 @@ struct SerialDriver { * @api
*/
#define sdAsynchronousRead(sdp, b, n) \
- chIQReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE)
+ iqReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE)
/** @} */
/*===========================================================================*/
diff --git a/os/hal/include/serial_usb.h b/os/hal/include/serial_usb.h index 28ab3a940..fb4ab25d5 100644 --- a/os/hal/include/serial_usb.h +++ b/os/hal/include/serial_usb.h @@ -99,9 +99,8 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if !HAL_USE_USB || !CH_USE_QUEUES || !CH_USE_EVENTS
-#error "Serial over USB Driver requires HAL_USE_USB, CH_USE_QUEUES, "
- "CH_USE_EVENTS"
+#if !HAL_USE_USB
+#error "Serial over USB Driver requires HAL_USE_USB"
#endif
/*===========================================================================*/
@@ -164,9 +163,9 @@ typedef struct { /* Driver state.*/ \
sdustate_t state; \
/* Input queue.*/ \
- InputQueue iqueue; \
+ input_queue_t iqueue; \
/* Output queue.*/ \
- OutputQueue oqueue; \
+ output_queue_t oqueue; \
/* Input buffer.*/ \
uint8_t ib[SERIAL_USB_BUFFERS_SIZE]; \
/* Output buffer.*/ \
@@ -219,7 +218,7 @@ extern "C" { void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config);
void sduStop(SerialUSBDriver *sdup);
void sduConfigureHookI(SerialUSBDriver *sdup);
- bool_t sduRequestsHook(USBDriver *usbp);
+ bool sduRequestsHook(USBDriver *usbp);
void sduDataTransmitted(USBDriver *usbp, usbep_t ep);
void sduDataReceived(USBDriver *usbp, usbep_t ep);
void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep);
diff --git a/os/hal/include/spi.h b/os/hal/include/spi.h index 5e0fa9e53..48182e65d 100644 --- a/os/hal/include/spi.h +++ b/os/hal/include/spi.h @@ -64,10 +64,6 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -229,12 +225,7 @@ typedef enum { *
* @notapi
*/
-#define _spi_wait_s(spip) { \
- chDbgAssert((spip)->thread == NULL, \
- "_spi_wait(), #1", "already waiting"); \
- (spip)->thread = chThdSelf(); \
- chSchGoSleepS(THD_STATE_SUSPENDED); \
-}
+#define _spi_wait_s(spip) osalThreadSuspendS(&(spip)->thread)
/**
* @brief Wakes up the waiting thread.
@@ -244,14 +235,9 @@ typedef enum { * @notapi
*/
#define _spi_wakeup_isr(spip) { \
- chSysLockFromIsr(); \
- if ((spip)->thread != NULL) { \
- Thread *tp = (spip)->thread; \
- (spip)->thread = NULL; \
- tp->p_u.rdymsg = RDY_OK; \
- chSchReadyI(tp); \
- } \
- chSysUnlockFromIsr(); \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(spip)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
}
#else /* !SPI_USE_WAIT */
#define _spi_wait_s(spip)
diff --git a/os/hal/include/tm.h b/os/hal/include/st.h index 14578a167..ebe906f1c 100644 --- a/os/hal/include/tm.h +++ b/os/hal/include/st.h @@ -19,17 +19,17 @@ */
/**
- * @file tm.h
- * @brief Time Measurement driver header.
+ * @file st.h
+ * @brief ST Driver macros and structures.
+ * @details This header is designed to be include-able without having to
+ * include other files from the HAL.
*
- * @addtogroup TM
+ * @addtogroup ST
* @{
*/
-#ifndef _TM_H_
-#define _TM_H_
-
-#if HAL_USE_TM || defined(__DOXYGEN__)
+#ifndef _ST_H_
+#define _ST_H_
/*===========================================================================*/
/* Driver constants. */
@@ -47,56 +47,38 @@ /* Driver data structures and types. */
/*===========================================================================*/
-/**
- * @brief Type of a Time Measurement object.
- * @note Start/stop of measurements is performed through the function
- * pointers in order to avoid inlining of those functions which
- * could compromise measurement accuracy.
- * @note The maximum measurable time period depends on the implementation
- * of the realtime counter in the HAL driver.
- * @note The measurement is not 100% cycle-accurate, it can be in excess
- * of few cycles depending on the compiler and target architecture.
- * @note Interrupts can affect measurement if the measurement is performed
- * with interrupts enabled.
- */
-typedef struct TimeMeasurement TimeMeasurement;
-
-/**
- * @brief Time Measurement structure.
- */
-struct TimeMeasurement {
- void (*start)(TimeMeasurement *tmp); /**< @brief Starts a measurement. */
- void (*stop)(TimeMeasurement *tmp); /**< @brief Stops a measurement. */
- halrtcnt_t last; /**< @brief Last measurement. */
- halrtcnt_t worst; /**< @brief Worst measurement. */
- halrtcnt_t best; /**< @brief Best measurement. */
-};
+#include "st_lld.h"
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/**
- * @brief Starts a measurement.
- * @pre The @p TimeMeasurement must be initialized.
- * @note This function can be invoked in any context.
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the time counter value.
+ * @note This functionality is only available in free running mode, the
+ * behaviour in periodic mode is undefined.
*
- * @param[in,out] tmp pointer to a @p TimeMeasurement structure
+ * @return The counter value.
*
- * @special
+ * @api
*/
-#define tmStartMeasurement(tmp) (tmp)->start(tmp)
+#define stGetCounter() st_lld_get_counter()
/**
- * @brief Stops a measurement.
- * @pre The @p TimeMeasurement must be initialized.
- * @note This function can be invoked in any context.
+ * @brief Determines if the alarm is active.
*
- * @param[in,out] tmp pointer to a @p TimeMeasurement structure
+ * @return The alarm status.
+ * @retval false if the alarm is not active.
+ * @retval true is the alarm is active
*
- * @special
+ * @api
*/
-#define tmStopMeasurement(tmp) (tmp)->stop(tmp)
+#define stIsAlarmActive() st_lld_is_alarm_active()
+/** @} */
/*===========================================================================*/
/* External declarations. */
@@ -105,14 +87,15 @@ struct TimeMeasurement { #ifdef __cplusplus
extern "C" {
#endif
- void tmInit(void);
- void tmObjectInit(TimeMeasurement *tmp);
+ void stInit(void);
+ void stStartAlarm(systime_t time);
+ void stStopAlarm(void);
+ void stSetAlarm(systime_t time);
+ systime_t stGetAlarm(void);
#ifdef __cplusplus
}
#endif
-#endif /* HAL_USE_TM */
-
-#endif /* _TM_H_ */
+#endif /* _ST_H_ */
/** @} */
diff --git a/os/hal/include/usb.h b/os/hal/include/usb.h index 3d34708eb..790a08fab 100644 --- a/os/hal/include/usb.h +++ b/os/hal/include/usb.h @@ -325,7 +325,7 @@ typedef void (*usbeventcb_t)(USBDriver *usbp, usbevent_t event); * @retval FALSE Request not recognized by the handler.
* @retval TRUE Request handled.
*/
-typedef bool_t (*usbreqhandler_t)(USBDriver *usbp);
+typedef bool (*usbreqhandler_t)(USBDriver *usbp);
/**
* @brief Type of an USB descriptor-retrieving callback.
@@ -556,13 +556,13 @@ extern "C" { void usbPrepareTransmit(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n);
void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep,
- InputQueue *iqp, size_t n);
+ input_queue_t *iqp, size_t n);
void usbPrepareQueuedTransmit(USBDriver *usbp, usbep_t ep,
- OutputQueue *oqp, size_t n);
- bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep);
- bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep);
- bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep);
- bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep);
+ output_queue_t *oqp, size_t n);
+ bool usbStartReceiveI(USBDriver *usbp, usbep_t ep);
+ bool usbStartTransmitI(USBDriver *usbp, usbep_t ep);
+ bool usbStallReceiveI(USBDriver *usbp, usbep_t ep);
+ bool usbStallTransmitI(USBDriver *usbp, usbep_t ep);
void _usb_reset(USBDriver *usbp);
void _usb_ep0setup(USBDriver *usbp, usbep_t ep);
void _usb_ep0in(USBDriver *usbp, usbep_t ep);
|