aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-06-03 20:32:28 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-06-03 20:32:28 +0000
commit9148fd36b23a5ffcdd2f358627370a697fb49cef (patch)
tree6ca0223c9209094fff1b36c11945425fbb95ee9c /src
parent2a7941ee58016ce7641ab8010aff5fe711e0bedc (diff)
downloadChibiOS-9148fd36b23a5ffcdd2f358627370a697fb49cef.tar.gz
ChibiOS-9148fd36b23a5ffcdd2f358627370a697fb49cef.tar.bz2
ChibiOS-9148fd36b23a5ffcdd2f358627370a697fb49cef.zip
Added default implementations for I/O ports functions in ioports.h. Adjusted the documentation accordingly.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1017 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/include/ioports.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/include/ioports.h b/src/include/ioports.h
index 94488640a..5fd330d51 100644
--- a/src/include/ioports.h
+++ b/src/include/ioports.h
@@ -71,16 +71,30 @@ typedef struct {
*
* @param[in] port the port identifier
* @param[in] bits the bits to be written on the specified port
+ *
+ * @note The default implementation does nothing except computing the
+ * parameters eventual side effects.
*/
+#if !defined(ioport_write_lld) || defined(__DOXYGEN__)
+#define chPortWrite(port, bits) ((void)(port), (void)(bits))
+#else
#define chPortWrite(port, bits) ioport_write_lld(port, bits)
+#endif
/**
* @brief Reads an I/O port.
*
* @param[in] port the port identifier
* @return the port bits
+ *
+ * @note The default implementation always return zero and computes the
+ * parameter eventual side effects.
*/
+#if !defined(ioport_read_lld) || defined(__DOXYGEN__)
+#define chPortRead(port) ((void)(port), 0)
+#else
#define chPortRead(port) ioport_read_lld(port)
+#endif
/**
* @brief Sets a bits mask on a I/O port.
@@ -91,8 +105,18 @@ typedef struct {
* @note The operation is not guaranteed to be atomic on all the architectures,
* for atomicity and/or portability reasons you may need to enclose port
* I/O operations between @p chSysLock() and @p chSysUnlock().
+ * @note The default implementation is non atomical and not necessarily
+ * optimal. Low level drivers may optimize the function by using
+ * specific hardware or coding.
*/
+#if !defined(ioport_set_lld) || defined(__DOXYGEN__)
+#define chPortSet(port, bits) { \
+ ioport_t p = (port); \
+ chPortWrite(p, chPortRead(p) | (bits)); \
+}
+#else
#define chPortSet(port, bits) ioport_set_lld(port, bits)
+#endif
/**
* @brief Clears a bits mask on a I/O port.
@@ -103,8 +127,18 @@ typedef struct {
* @note The operation is not guaranteed to be atomic on all the architectures,
* for atomicity and/or portability reasons you may need to enclose port
* I/O operations between @p chSysLock() and @p chSysUnlock().
+ * @note The default implementation is non atomical and not necessarily
+ * optimal. Low level drivers may optimize the function by using
+ * specific hardware or coding.
*/
+#if !defined(ioport_clear_lld) || defined(__DOXYGEN__)
+#define chPortClear(port, bits) { \
+ ioport_t p = (port); \
+ chPortWrite(p, chPortRead(p) & ~(bits)); \
+}
+#else
#define chPortClear(port, bits) ioport_clear_lld(port, bits)
+#endif
/**
* @brief Toggles a bits mask on a I/O port.
@@ -115,8 +149,18 @@ typedef struct {
* @note The operation is not guaranteed to be atomic on all the architectures,
* for atomicity and/or portability reasons you may need to enclose port
* I/O operations between @p chSysLock() and @p chSysUnlock().
+ * @note The default implementation is non atomical and not necessarily
+ * optimal. Low level drivers may optimize the function by using
+ * specific hardware or coding.
*/
+#if !defined(ioport_toggle_lld) || defined(__DOXYGEN__)
+#define chPortToggle(port, bits) { \
+ ioport_t p = (port); \
+ chPortWrite(p, chPortRead(p) ^ (bits)); \
+}
+#else
#define chPortToggle(port, bits) ioport_toggle_lld(port, bits)
+#endif
/**
* @brief Writes a value on an I/O bus.
@@ -128,8 +172,19 @@ typedef struct {
* @note The operation is not guaranteed to be atomic on all the architectures,
* for atomicity and/or portability reasons you may need to enclose port
* I/O operations between @p chSysLock() and @p chSysUnlock().
+ * @note The default implementation is non atomical and not necessarily
+ * optimal. Low level drivers may optimize the function by using
+ * specific hardware or coding.
*/
+#if !defined(ioport_writebus_lld) || defined(__DOXYGEN__)
+#define chPortWriteBus(bus, bits) { \
+ IOBus *b = (bus); \
+ chPortWrite(b->bus_port, (chPortRead(b->bus_port) & ~b->bus_mask) | \
+ (((bits) << b->bus_offset) & b->bus_mask)); \
+}
+#else
#define chPortWriteBus(bus, bits) ioport_writebus_lld(bus, bits)
+#endif
/**
* @brief Reads a value from an I/O bus.
@@ -140,8 +195,17 @@ typedef struct {
* @note The operation is not guaranteed to be atomic on all the architectures,
* for atomicity and/or portability reasons you may need to enclose port
* I/O operations between @p chSysLock() and @p chSysUnlock().
+ * @note The default implementation not necessarily optimal. Low level drivers
+ * may optimize the function by using specific hardware or coding.
+ * @note The default implementation evaluates the parameter three times, be
+ * careful with side effects.
*/
+#if !defined(ioport_readbus_lld) || defined(__DOXYGEN__)
+#define chPortReadBus(bus) \
+ ((chPortRead((bus)->bus_port) >> (bus)->bus_offset) & (bus)->bus_mask)
+#else
#define chPortReadBus(bus) ioport_readbus_lld(bus)
+#endif
#endif /* _IOPORTS_H_ */