From 979da150361becdb50625d056915f81099710122 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 4 Jul 2009 14:05:29 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1055 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-LPC214x-GCC-minimal/Makefile | 1 + demos/ARM7-LPC214x-GCC-minimal/board.c | 28 +++++++++++++++------ demos/ARM7-LPC214x-GCC-minimal/board.h | 2 ++ demos/ARMCM3-STM32F103-GCC/board.c | 8 +++--- ports/ARM7-LPC214x/pal_lld.c | 19 ++++++++++++++- ports/ARM7-LPC214x/pal_lld.h | 43 +++++++++++++++++++++++++++++---- 6 files changed, 83 insertions(+), 18 deletions(-) diff --git a/demos/ARM7-LPC214x-GCC-minimal/Makefile b/demos/ARM7-LPC214x-GCC-minimal/Makefile index 2ea142e81..a00eb9c65 100644 --- a/demos/ARM7-LPC214x-GCC-minimal/Makefile +++ b/demos/ARM7-LPC214x-GCC-minimal/Makefile @@ -50,6 +50,7 @@ include ../../src/kernel.mk # setting. CSRC = ../../ports/ARM7/chcore.c \ ../../ports/ARM7-LPC214x/vic.c \ + ../../ports/ARM7-LPC214x/pal_lld.c \ ${KERNSRC} \ board.c main.c diff --git a/demos/ARM7-LPC214x-GCC-minimal/board.c b/demos/ARM7-LPC214x-GCC-minimal/board.c index 2e56028cc..980626ab5 100644 --- a/demos/ARM7-LPC214x-GCC-minimal/board.c +++ b/demos/ARM7-LPC214x-GCC-minimal/board.c @@ -58,6 +58,18 @@ static CH_IRQ_HANDLER(T0IrqHandler) { CH_IRQ_EPILOGUE(); } +/* + * Digital I/O ports static configuration as defined in @p board.h. + */ +static const LPC214xFIOConfig config = +{ + VAL_PINSEL0, + VAL_PINSEL1, + VAL_PINSEL2, + {VAL_FIO0PIN, VAL_FIO0DIR}, + {VAL_FIO1PIN, VAL_FIO1DIR} +}; + /* * Early initialization code. * This initialization is performed just after reset before BSS and DATA @@ -101,14 +113,14 @@ void hwinit0(void) { /* * I/O pins configuration. */ - PINSEL0 = VAL_PINSEL0; - PINSEL1 = VAL_PINSEL1; - PINSEL2 = VAL_PINSEL2; - palInit(); - pal_lld_lpc214x_set_direction(IOPORT_A, VAL_FIO0DIR); - palWritePort(IOPORT_A, 0xFFFFFFFF); - pal_lld_lpc214x_set_direction(IOPORT_B, VAL_FIO1DIR); - palWritePort(IOPORT_B, 0xFFFFFFFF); +// PINSEL0 = VAL_PINSEL0; +// PINSEL1 = VAL_PINSEL1; +// PINSEL2 = VAL_PINSEL2; + palInit(&config); +// pal_lld_lpc214x_set_direction(IOPORT_A, VAL_FIO0DIR); +// palWritePort(IOPORT_A, 0xFFFFFFFF); +// pal_lld_lpc214x_set_direction(IOPORT_B, VAL_FIO1DIR); +// palWritePort(IOPORT_B, 0xFFFFFFFF); } /* diff --git a/demos/ARM7-LPC214x-GCC-minimal/board.h b/demos/ARM7-LPC214x-GCC-minimal/board.h index fee4baa61..ab4aa76f6 100644 --- a/demos/ARM7-LPC214x-GCC-minimal/board.h +++ b/demos/ARM7-LPC214x-GCC-minimal/board.h @@ -64,6 +64,8 @@ #define VAL_PINSEL2 0x00000004 #define VAL_FIO0DIR 0xB0703C00 #define VAL_FIO1DIR 0x00000000 +#define VAL_FIO0PIN 0x00000000 +#define VAL_FIO1PIN 0x00000000 #define PA_LED1 10 #define PA_LED2 11 diff --git a/demos/ARMCM3-STM32F103-GCC/board.c b/demos/ARMCM3-STM32F103-GCC/board.c index 34349b827..0f6c5be6b 100644 --- a/demos/ARMCM3-STM32F103-GCC/board.c +++ b/demos/ARMCM3-STM32F103-GCC/board.c @@ -29,10 +29,10 @@ */ static const STM32GPIOConfig config = { - {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH}, - {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH}, - {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH}, - {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH}, + {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH}, + {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH}, + {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH}, + {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH}, }; /* diff --git a/ports/ARM7-LPC214x/pal_lld.c b/ports/ARM7-LPC214x/pal_lld.c index 3c06f39ce..3d300bb55 100644 --- a/ports/ARM7-LPC214x/pal_lld.c +++ b/ports/ARM7-LPC214x/pal_lld.c @@ -29,11 +29,28 @@ /** * @brief LPC214x I/O ports configuration. - * @details Ports A-D clocks enabled, AFIO clock enabled. + * @details . * * @param[in] config the LPC214x ports configuration */ void _pal_lld_init(const LPC214xFIOConfig *config) { + + /* Enables the access through the fast registers.*/ + SCS = 3; + + /* I/O pads initial assignment, device drivers may change this setup at a + * later time.*/ + PINSEL0 = config->pinsel0; + PINSEL1 = config->pinsel1; + PINSEL2 = config->pinsel2; + + /* I/O pads direction initial setting.*/ + FIO0Base->FIO_MASK = 0; + FIO0Base->FIO_PIN = config->P0Data.pin; + FIO0Base->FIO_DIR = config->P0Data.dir; + FIO1Base->FIO_MASK = 0; + FIO1Base->FIO_PIN = config->P1Data.pin; + FIO1Base->FIO_DIR = config->P1Data.dir; } /** diff --git a/ports/ARM7-LPC214x/pal_lld.h b/ports/ARM7-LPC214x/pal_lld.h index bb0f2efac..2bbb0676b 100644 --- a/ports/ARM7-LPC214x/pal_lld.h +++ b/ports/ARM7-LPC214x/pal_lld.h @@ -43,6 +43,16 @@ /* I/O Ports Types and constants. */ /*===========================================================================*/ +/** + * @brief FIO port setup info. + */ +typedef struct { + /** Initial value for FIO_PIN register.*/ + uint32_t pin; + /** Initial value for FIO_DIR register.*/ + uint32_t dir; +} lpc214x_fio_setup_t; + /** * @brief LPC214x FIO static initializer. * @details An instance of this structure must be passed to @p palInit() at @@ -51,10 +61,16 @@ * or whole ports can be reprogrammed at later time. */ typedef struct { + /** @brief PINSEL0 initial value.*/ + uint32_t pinsel0; + /** @brief PINSEL1 initial value.*/ + uint32_t pinsel1; + /** @brief PINSEL2 initial value.*/ + uint32_t pinsel2; /** @brief Port 0 setup data.*/ - ioportmask_t P0Data; + lpc214x_fio_setup_t P0Data; /** @brief Port 1 setup data.*/ - ioportmask_t P1Data; + lpc214x_fio_setup_t P1Data; } LPC214xFIOConfig; /** @@ -95,9 +111,7 @@ typedef FIO * ioportid_t; * @brief FIO subsystem initialization. * @details Enables the access through the fast registers. */ -#define pal_lld_init() { \ - SCS = 3; \ -} +#define pal_lld_init(config) _pal_lld_init(config) /** * @brief Reads an I/O port. @@ -185,6 +199,25 @@ typedef FIO * ioportid_t; (port)->FIO_MASK = 0; \ } +/** + * @brief Pads group 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 mode + * + * @note This function is not meant to be invoked directly by the application + * code. + * @note @p PAL_MODE_UNCONNECTED is implemented as output as recommended by + * the MSP430x1xx Family User's Guide. + * @note This function does not alter the @p PxSEL registers. Alternate + * functions setup must be handled by device-specific code. + */ +#define pal_lld_setgroupmode(port, mask, mode) \ + _pal_lld_setgroupmode(port, mask, mode) + /** * @brief Writes a logical state on an output pad. * -- cgit v1.2.3