diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-09-26 15:31:12 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-09-26 15:31:12 +0000 |
commit | a8f264a8188aa0a3995f762ce0742bfd3521f574 (patch) | |
tree | b6e69208fd7c053d0b8ffebdae82a0fca48cc036 | |
parent | 12af66627696ae5f8191a7d07f4e9e991aeda4ac (diff) | |
download | ChibiOS-a8f264a8188aa0a3995f762ce0742bfd3521f574.tar.gz ChibiOS-a8f264a8188aa0a3995f762ce0742bfd3521f574.tar.bz2 ChibiOS-a8f264a8188aa0a3995f762ce0742bfd3521f574.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4713 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | boards/GENERIC_SPC560P/board.c | 19 | ||||
-rw-r--r-- | boards/GENERIC_SPC560P/board.h | 22 | ||||
-rw-r--r-- | os/hal/include/pal.h | 8 | ||||
-rw-r--r-- | os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.c | 5 | ||||
-rw-r--r-- | os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h | 96 |
5 files changed, 114 insertions, 36 deletions
diff --git a/boards/GENERIC_SPC560P/board.c b/boards/GENERIC_SPC560P/board.c index 4b4af7f1d..9dece532c 100644 --- a/boards/GENERIC_SPC560P/board.c +++ b/boards/GENERIC_SPC560P/board.c @@ -22,10 +22,17 @@ #include "hal.h"
#if HAL_USE_PAL || defined(__DOXYGEN__)
-/* List of the PCR values to be setup initially, the list is terminated by a
- {0, 0}.*/
-static const spc560p_pcr_init_t spc560p_pcrs_init[] = {
- {0, 0}
+/* Initial setup of all defined pads, the list is terminated by a {0, 0}.*/
+static const spc560p_siul_init_t spc560p_siul_init[] = {
+ {PCR(PD, PD_BUTTON1), PAL_LOW, PAL_MODE_INPUT},
+ {PCR(PD, PD_BUTTON2), PAL_LOW, PAL_MODE_INPUT},
+ {PCR(PD, PD_BUTTON3), PAL_LOW, PAL_MODE_INPUT},
+ {PCR(PD, PD_BUTTON4), PAL_LOW, PAL_MODE_INPUT},
+ {PCR(PD, PD_LED1), PAL_HIGH, PAL_MODE_OUTPUT_PUSHPULL},
+ {PCR(PD, PD_LED2), PAL_HIGH, PAL_MODE_OUTPUT_PUSHPULL},
+ {PCR(PD, PD_LED3), PAL_HIGH, PAL_MODE_OUTPUT_PUSHPULL},
+ {PCR(PD, PD_LED4), PAL_HIGH, PAL_MODE_OUTPUT_PUSHPULL},
+ {0, 0, 0}
};
/* Initialization array for the PSMI registers.*/
@@ -40,8 +47,8 @@ static const uint8_t spc560p_padsels_init[36] = { */
const PALConfig pal_default_config =
{
- PAL_MODE_UNCONNECTED,
- spc560p_pcrs_init,
+ PAL_MODE_UNCONNECTED, /* Default mode for all undefined pads. */
+ spc560p_siul_init,
spc560p_padsels_init
};
#endif
diff --git a/boards/GENERIC_SPC560P/board.h b/boards/GENERIC_SPC560P/board.h index b3e74044f..6cbc6213a 100644 --- a/boards/GENERIC_SPC560P/board.h +++ b/boards/GENERIC_SPC560P/board.h @@ -41,18 +41,20 @@ /*
* I/O definitions.
*/
-#define GPIO_SCI_A_TX 89
-#define GPIO_SCI_A_RX 90
+#define PD_BUTTON1 0
+#define PD_BUTTON2 1
+#define PD_BUTTON3 2
+#define PD_BUTTON4 3
-#define GPIO_BUTTON1 179
-#define GPIO_BUTTON2 181
-#define GPIO_BUTTON3 183
-#define GPIO_BUTTON4 187
+#define PD_LED1 4
+#define PD_LED2 5
+#define PD_LED3 6
+#define PD_LED4 7
-#define GPIO_LED1 188
-#define GPIO_LED2 189
-#define GPIO_LED3 190
-#define GPIO_LED4 191
+/*
+ * Support macros.
+ */
+#define PCR(port, pin) (((port) * 16) + (pin))
#if !defined(_FROM_ASM_)
#ifdef __cplusplus
diff --git a/os/hal/include/pal.h b/os/hal/include/pal.h index da4c5fe51..62bf8270e 100644 --- a/os/hal/include/pal.h +++ b/os/hal/include/pal.h @@ -94,12 +94,12 @@ /**
* @brief Logical low state.
*/
-#define PAL_LOW 0
+#define PAL_LOW 0
/**
* @brief Logical high state.
*/
-#define PAL_HIGH 1
+#define PAL_HIGH 1
/** @} */
/*===========================================================================*/
@@ -151,7 +151,9 @@ typedef struct { * @param[in] n bit position within the port
* @return The bit mask.
*/
+#if !defined(PAL_PORT_BIT) || defined(__DOXYGEN__)
#define PAL_PORT_BIT(n) ((ioportmask_t)(1 << (n)))
+#endif
/**
* @brief Bits group mask helper.
@@ -160,7 +162,9 @@ typedef struct { * @param[in] width group width
* @return The group mask.
*/
+#if !defined(PAL_GROUP_MASK) || defined(__DOXYGEN__)
#define PAL_GROUP_MASK(width) ((ioportmask_t)(1 << (width)) - 1)
+#endif
/**
* @brief Data part of a static I/O bus initializer.
diff --git a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.c b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.c index f67fbce0e..601a58714 100644 --- a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.c +++ b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.c @@ -70,8 +70,9 @@ void _pal_lld_init(const PALConfig *config) { SIU.PCR[i].R = config->default_mode;
i = 0;
- while (config->pcrs[i].pcr_value != 0) {
- SIU.PCR[config->pcrs[i].pcr_index].R = config->pcrs[i].pcr_value;
+ while (config->inits[i].pcr_value != 0) {
+ SIU.GPDO[config->inits[i].pcr_index].R = config->inits[i].gpdo_value;
+ SIU.PCR[config->inits[i].pcr_index].R = config->inits[i].pcr_value;
i++;
}
diff --git a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h index 1bebea35d..2ec806b62 100644 --- a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h +++ b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h @@ -114,18 +114,18 @@ /**
* @brief Width, in bits, of an I/O port.
*/
-#define PAL_IOPORTS_WIDTH 32
+#define PAL_IOPORTS_WIDTH 16
/**
* @brief Whole port mask.
* @brief This macro specifies all the valid bits into a port.
*/
-#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFFFFF)
+#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF)
/**
* @brief Digital I/O port sized unsigned type.
*/
-typedef uint32_t ioportmask_t;
+typedef uint16_t ioportmask_t;
/**
* @brief Digital I/O modes.
@@ -141,12 +141,13 @@ typedef uint16_t iomode_t; typedef uint32_t ioportid_t;
/**
- * @brief PCR register initializer type.
+ * @brief SIUL register initializer type.
*/
typedef struct {
- uint16_t pcr_index;
+ uint8_t pcr_index;
+ uint8_t gpdo_value;
iomode_t pcr_value;
-} spc560p_pcr_init_t;
+} spc560p_siul_init_t;
/**
* @brief Generic I/O ports static initializer.
@@ -159,7 +160,7 @@ typedef struct { */
typedef struct {
iomode_t default_mode;
- const spc560p_pcr_init_t *pcrs;
+ const spc560p_siul_init_t *inits;
const uint8_t *padsels;
} PALConfig;
@@ -170,22 +171,22 @@ typedef struct { /**
* @brief I/O port 1 identifier.
*/
-#define IOPORT1 0
+#define PA 0
/**
* @brief I/O port 2 identifier.
*/
-#define IOPORT2 1
+#define PB 1
/**
* @brief I/O port 3 identifier.
*/
-#define IOPORT3 2
+#define PC 2
/**
* @brief I/O port 4 identifier.
*/
-#define IOPORT4 3
+#define PD 3
/*===========================================================================*/
/* Implementation, some of the following macros could be implemented as */
@@ -193,6 +194,47 @@ typedef struct { /*===========================================================================*/
/**
+ * @brief Port bit helper macro.
+ * @note Overrides the one in @p pal.h.
+ *
+ * @param[in] n bit position within the port
+ *
+ * @return The bit mask.
+ */
+#define PAL_PORT_BIT(n) ((ioportmask_t)(0x8000U >> (n)))
+
+/**
+ * @brief Workaround read port because bad header implementation.
+ *
+ * @param[in] port port identifier
+ * @return The port bits.
+ *
+ * @notapi
+ */
+#define PAL_SIUL_READ_PORT(port) (((volatile uint16_t *)SIU.PGPDI)[port])
+
+/**
+ * @brief Workaround read latch because bad header implementation.
+ *
+ * @param[in] port port identifier
+ * @return The port bits.
+ *
+ * @notapi
+ */
+#define PAL_SIUL_READ_LATCH(port) (((volatile uint16_t *)SIU.PGPDO)[port])
+
+/**
+ * @brief Workaround write port because bad header implementation.
+ *
+ * @param[in] port port identifier
+ * @param[in] bits bits to be written on the specified port
+ *
+ * @notapi
+ */
+#define PAL_SIUL_WRITE_PORT(port, bits) \
+ (((volatile uint16_t *)SIU.PGPDO)[port] = (bits))
+
+/**
* @brief Low level PAL subsystem initialization.
*
* @param[in] config architecture-dependent ports configuration
@@ -209,7 +251,7 @@ typedef struct { *
* @notapi
*/
-#define pal_lld_readport(port) (SIU.PGPDI[port].R)
+#define pal_lld_readport(port) PAL_SIUL_READ_PORT(port)
/**
* @brief Reads the output latch.
@@ -221,7 +263,7 @@ typedef struct { *
* @notapi
*/
-#define pal_lld_readlatch(port) (SIU.PGPDO[port].R)
+#define pal_lld_readlatch(port) PAL_SIUL_READ_LATCH(port)
/**
* @brief Writes a bits mask on a I/O port.
@@ -231,7 +273,7 @@ typedef struct { *
* @notapi
*/
-#define pal_lld_writeport(port, bits) (SIU.PGPDO[port].R = (bits))
+#define pal_lld_writeport(port, bits) PAL_SIUL_WRITE_PORT(port, bits)
/**
* @brief Pads group mode setup.
@@ -264,7 +306,7 @@ typedef struct { * @notapi
*/
#define pal_lld_readpad(port, pad) \
- (SIU.GPDI.R[((port) * 32) + (15 - (pad))])
+ (SIU.GPDI[((port) * 16) + (pad)].R)
/**
* @brief Writes a logical state on an output pad.
@@ -282,7 +324,29 @@ typedef struct { * @notapi
*/
#define pal_lld_writepad(port, pad, bit) \
- (SIU.GPDO.R[((port) * 32) + (15 - (pad))] = (bit))
+ (SIU.GPDO[((port) * 16) + (pad)].R = (bit))
+
+/**
+ * @brief Sets a pad logical state to @p PAL_HIGH.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @notapi
+ */
+#define pal_lld_setpad(port, pad) \
+ (SIU.GPDO[((port) * 16) + (pad)].R = 1)
+
+/**
+ * @brief Clears a pad logical state to @p PAL_LOW.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @notapi
+ */
+#define pal_lld_clearpad(port, pad) \
+ (SIU.GPDO[((port) * 16) + (pad)].R = 0)
/**
* @brief Pad mode setup.
|