From 1c7e52eb35c244e5855ea7978ab02d9540829e00 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Jun 2009 08:52:44 +0000 Subject: Added abstract port setup to PAL and to the MSP430 port. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1042 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/lib/pal.c | 8 +++++++ src/lib/pal.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pal.c b/src/lib/pal.c index abe3db3f6..95ab43883 100644 --- a/src/lib/pal.c +++ b/src/lib/pal.c @@ -70,4 +70,12 @@ void palWriteBus(IOBus *bus, ioportmask_t bits) { palWriteGroup(bus->bus_portid, bus->bus_mask, bus->bus_offset, bits); } +void palSetBusMode(IOBus *bus, uint_fast8_t mode) { + + chDbgCheck((bus != NULL) && + (bus->bus_offset > PAL_IOPORTS_WIDTH), "palSetBusMode"); + + palSetMode(bus->bus_portid, bus->bus_mask, mode); +} + /** @} */ diff --git a/src/lib/pal.h b/src/lib/pal.h index d4190e500..96ed8c312 100644 --- a/src/lib/pal.h +++ b/src/lib/pal.h @@ -27,6 +27,48 @@ #ifndef _PAL_H_ #define _PAL_H_ +/** + * @brief After reset state. + * @details The state itself is not specified and is architecture dependent, + * it is guaranteed to be equal to the after-reset state. It is + * usually an input state. + */ +#define PAL_MODE_RESET 0 + +/** + * @brief Safe state for unconnected pads. + * @details The state itself is not specified and is architecture dependent, + * it may be mapped on @p PAL_MODE_INPUT_PULLUP, + * @p PAL_MODE_INPUT_PULLDOWN or @p PAL_MODE_OUTPUT_PUSHPULL as + * example. + */ +#define PAL_MODE_UNCONNECTED 1 + +/** + * @brief Regular input high-Z pad. + */ +#define PAL_MODE_INPUT 2 + +/** + * @brief Input pad with weak pull up resistor. + */ +#define PAL_MODE_INPUT_PULLUP 3 + +/** + * @brief Input pad with weak pull down resistor. + */ +#define PAL_MODE_INPUT_PULLDOWN 4 + +/** + * @brief Push-pull output pad. + */ +#define PAL_MODE_OUTPUT_PUSHPULL 5 + +/** + * @brief Open-drain output pad. + */ +#define PAL_MODE_OUTPUT_OPENDRAIN 6 + #ifndef _PAL_LLD_H_ #include "pal_lld.h" #endif @@ -70,7 +112,7 @@ * @param width the bus width in bits * @param offset the bus bit offset within the port */ -#define _IOBUS_DATA(name, port, width, offset) \ +#define _IOBUS_DATA(name, port, width, offset) \ {port, PAL_GROUP_MASK(width), offset} /** @@ -102,9 +144,13 @@ typedef struct { } IOBus; /** - * @brief PAL subsystem initialization. + * @brief PAL subsystem initialization. + * + * @param[in] config pointer to an architecture specific configuration + * structure. This structure is defined in the low level driver + * header. */ -#define palInit() pal_lld_init() +#define palInit(config) pal_lld_init(config) /** * @brief Reads the physical I/O port states. @@ -354,11 +400,29 @@ typedef struct { #define palTogglePad(port, pad) pal_lld_togglepad(port, pad) #endif +/** + * @brief Pads mode setup. + * @details This function programs a pads group belonging to the same port + * with the specified mode. + * + * @param[in] port the port identifier + * @param[in] mask the group mask + * @param[in] mode the setup mode + * + * @note Programming an unknown or unsupported mode is silently ignored. + */ +#if !defined(pal_lld_setmode) || defined(__DOXYGEN__) +#define palSetMode(port, mask, mode) +#else +#define palSetMode(port, mask, mode) pal_lld_setmode(port, mask, mode) +#endif + #ifdef __cplusplus extern "C" { #endif ioportmask_t palReadBus(IOBus *bus); void palWriteBus(IOBus *bus, ioportmask_t bits); + void palSetBusMode(IOBus *bus, uint_fast8_t mode); #ifdef __cplusplus } #endif -- cgit v1.2.3