From cec33ff0e62d3666f6a1828d78891d63da191e20 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 2 Apr 2010 12:47:05 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1831 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- boards/EA_LPCXPRESSO_BB_1114/board.h | 26 +++ demos/ARMCM0-LPC1114-GCC/Makefile | 6 +- demos/ARMCM0-LPC1114-GCC/halconf.h | 2 +- demos/ARMCM0-LPC1114-GCC/main.c | 4 +- os/hal/platforms/LPC111x/hal_lld.c | 11 ++ os/hal/platforms/LPC111x/hal_lld.h | 2 +- os/hal/platforms/LPC111x/pal_lld.c | 94 ++++++++++ os/hal/platforms/LPC111x/pal_lld.h | 355 +++++++++++++++++++++++++++++++++++ os/hal/platforms/LPC111x/platform.mk | 5 +- os/ports/GCC/ARMCMx/LPC111x/port.mk | 2 +- 10 files changed, 497 insertions(+), 10 deletions(-) create mode 100644 os/hal/platforms/LPC111x/pal_lld.c create mode 100644 os/hal/platforms/LPC111x/pal_lld.h diff --git a/boards/EA_LPCXPRESSO_BB_1114/board.h b/boards/EA_LPCXPRESSO_BB_1114/board.h index 037bd3179..685ab4e64 100644 --- a/boards/EA_LPCXPRESSO_BB_1114/board.h +++ b/boards/EA_LPCXPRESSO_BB_1114/board.h @@ -36,9 +36,35 @@ */ #define SYSOSCCLK 12000000 +/* + * GPIO 0 initial setup. + * Bit7 - LPCxpresso LED, initially output at low level. + */ +#define VAL_GPIO0DIR 0x00000080 +#define VAL_GPIO0DATA 0x00000000 + +/* + * GPIO 1 initial setup. + */ +#define VAL_GPIO1DIR 0x00000000 +#define VAL_GPIO1DATA 0x00000000 + +/* + * GPIO 2 initial setup. + */ +#define VAL_GPIO2DIR 0x00000000 +#define VAL_GPIO2DATA 0x00000000 + +/* + * GPIO 3 initial setup. + */ +#define VAL_GPIO3DIR 0x00000000 +#define VAL_GPIO3DATA 0x00000000 + /* * Pin definitions. */ +#define GPIO0_LED 7 #ifdef __cplusplus extern "C" { diff --git a/demos/ARMCM0-LPC1114-GCC/Makefile b/demos/ARMCM0-LPC1114-GCC/Makefile index 6b828dee3..e776ab4c5 100644 --- a/demos/ARMCM0-LPC1114-GCC/Makefile +++ b/demos/ARMCM0-LPC1114-GCC/Makefile @@ -53,9 +53,9 @@ LDSCRIPT= ch.ld # Imported source files CHIBIOS = ../.. include $(CHIBIOS)/boards/EA_LPCXPRESSO_BB_1114/board.mk -include $(CHIBIOS)/os/hal/platforms/LPC11xx/platform.mk +include $(CHIBIOS)/os/hal/platforms/LPC111x/platform.mk include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/ports/GCC/ARMCMx/LPC11xx/port.mk +include $(CHIBIOS)/os/ports/GCC/ARMCMx/LPC111x/port.mk include $(CHIBIOS)/os/kernel/kernel.mk #include $(CHIBIOS)/test/test.mk @@ -97,7 +97,7 @@ TCPPSRC = # List ASM source files here ASMSRC = $(PORTASM) \ - $(CHIBIOS)/os/ports/GCC/ARMCMx/LPC11xx/vectors.s + $(CHIBIOS)/os/ports/GCC/ARMCMx/LPC111x/vectors.s INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) \ diff --git a/demos/ARMCM0-LPC1114-GCC/halconf.h b/demos/ARMCM0-LPC1114-GCC/halconf.h index ef45f36bd..eee631fe0 100644 --- a/demos/ARMCM0-LPC1114-GCC/halconf.h +++ b/demos/ARMCM0-LPC1114-GCC/halconf.h @@ -48,7 +48,7 @@ * @brief Enables the PAL subsystem. */ #if !defined(CH_HAL_USE_PAL) || defined(__DOXYGEN__) -#define CH_HAL_USE_PAL FALSE +#define CH_HAL_USE_PAL TRUE #endif /*===========================================================================*/ diff --git a/demos/ARMCM0-LPC1114-GCC/main.c b/demos/ARMCM0-LPC1114-GCC/main.c index 11c3eb76b..74b7f5a78 100644 --- a/demos/ARMCM0-LPC1114-GCC/main.c +++ b/demos/ARMCM0-LPC1114-GCC/main.c @@ -29,9 +29,9 @@ static msg_t Thread1(void *arg) { (void)arg; while (TRUE) { -// palClearPad(IOPORT3, GPIOC_LED); + palClearPad(IOPORT1, GPIO0_LED); chThdSleepMilliseconds(500); -// palSetPad(IOPORT3, GPIOC_LED); + palSetPad(IOPORT1, GPIO0_LED); chThdSleepMilliseconds(500); } return 0; diff --git a/os/hal/platforms/LPC111x/hal_lld.c b/os/hal/platforms/LPC111x/hal_lld.c index 31d9f5417..95a39553c 100644 --- a/os/hal/platforms/LPC111x/hal_lld.c +++ b/os/hal/platforms/LPC111x/hal_lld.c @@ -41,6 +41,17 @@ /* Driver local variables. */ /*===========================================================================*/ +/** + * @brief PAL setup. + * @details Digital I/O ports static configuration as defined in @p board.h. + */ +const PALConfig pal_default_config = { + {VAL_GPIO0DATA, VAL_GPIO0DIR}, + {VAL_GPIO1DATA, VAL_GPIO1DIR}, + {VAL_GPIO2DATA, VAL_GPIO2DIR}, + {VAL_GPIO3DATA, VAL_GPIO3DIR}, +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ diff --git a/os/hal/platforms/LPC111x/hal_lld.h b/os/hal/platforms/LPC111x/hal_lld.h index be2ecf09e..f29fa1418 100644 --- a/os/hal/platforms/LPC111x/hal_lld.h +++ b/os/hal/platforms/LPC111x/hal_lld.h @@ -38,7 +38,7 @@ /** * @brief Platform name. */ -#define PLATFORM_NAME "LPC11xx" +#define PLATFORM_NAME "LPC111x" #define IRCOSCCLK 12000000 /**< High speed internal clock. */ #define WDGOSCCLK 1600000 /**< Watchdog internal clock. */ diff --git a/os/hal/platforms/LPC111x/pal_lld.c b/os/hal/platforms/LPC111x/pal_lld.c new file mode 100644 index 000000000..dac2fe584 --- /dev/null +++ b/os/hal/platforms/LPC111x/pal_lld.c @@ -0,0 +1,94 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 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 . +*/ + +/** + * @file templates/pal_lld.c + * @brief PAL subsystem low level driver template. + * + * @addtogroup PAL_LLD + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_PAL || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ +/** + * @brief LPC111x I/O ports configuration. + * @details GPIO unit registers initialization. + * + * @param[in] config the LPC111x ports configuration + */ +void _pal_lld_init(const PALConfig *config) { + + LPC_GPIO0->DIR = config->P0.dir; + LPC_GPIO1->DIR = config->P1.dir; + LPC_GPIO2->DIR = config->P2.dir; + LPC_GPIO3->DIR = config->P3.dir; + LPC_GPIO0->DATA = config->P0.data; + LPC_GPIO1->DATA = config->P1.data; + LPC_GPIO2->DATA = config->P2.data; + LPC_GPIO3->DATA = config->P3.data; +} + +/** + * @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 mode + * + * @note This function is not meant to be invoked directly by the application + * code. + * @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high + * state. + * @note This function does not alter the @p PINSELx registers. Alternate + * functions setup must be handled by device-specific code. + */ +void _pal_lld_setgroupmode(ioportid_t port, + ioportmask_t mask, + uint_fast8_t mode) { + +} + +#endif /* CH_HAL_USE_PAL */ + +/** @} */ diff --git a/os/hal/platforms/LPC111x/pal_lld.h b/os/hal/platforms/LPC111x/pal_lld.h new file mode 100644 index 000000000..f3f1c7fc6 --- /dev/null +++ b/os/hal/platforms/LPC111x/pal_lld.h @@ -0,0 +1,355 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 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 . +*/ + +/** + * @file LPC111x/pal_lld.h + * @brief LPC111x GPIO low level driver header. + * + * @addtogroup LPC111x_PAL + * @{ + */ + +#ifndef _PAL_LLD_H_ +#define _PAL_LLD_H_ + +#if CH_HAL_USE_PAL || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Unsupported modes and specific modes */ +/*===========================================================================*/ + +#undef PAL_MODE_INPUT_PULLUP +#undef PAL_MODE_INPUT_PULLDOWN +#undef PAL_MODE_INPUT_ANALOG +#undef PAL_MODE_OUTPUT_OPENDRAIN + +/*===========================================================================*/ +/* I/O Ports Types and constants. */ +/*===========================================================================*/ + +/** + * @brief GPIO port setup info. + */ +typedef struct { + /** Initial value for FIO_PIN register.*/ + uint32_t data; + /** Initial value for FIO_DIR register.*/ + uint32_t dir; +} lpc111x_gpio_setup_t; + +/** + * @brief GPIO static initializer. + * @details An instance of this structure must be passed to @p palInit() at + * system startup time in order to initialized the digital I/O + * subsystem. This represents only the initial setup, specific pads + * or whole ports can be reprogrammed at later time. + * @note The @p IOCON block is not configured, initially all pins have + * enabled pullups and are programmed as GPIO. It is responsibility + * of the various drivers to reprogram the pins in the proper mode. + * Pins that are not handled by any driver may be programmed in + * @p board.c. + */ +typedef struct { + /** @brief GPIO 0 setup data.*/ + lpc111x_gpio_setup_t P0; + /** @brief GPIO 1 setup data.*/ + lpc111x_gpio_setup_t P1; + /** @brief GPIO 2 setup data.*/ + lpc111x_gpio_setup_t P2; + /** @brief GPIO 3 setup data.*/ + lpc111x_gpio_setup_t P3; +} PALConfig; + +/** + * @brief Width, in bits, of an I/O port. + */ +#define PAL_IOPORTS_WIDTH 32 + +/** + * @brief Whole port mask. + * @brief This macro specifies all the valid bits into a port. + */ +#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFFFFF) + +/** + * @brief Digital I/O port sized unsigned type. + */ +typedef uint32_t ioportmask_t; + +/** + * @brief Port Identifier. + */ +typedef LPC_GPIO_TypeDef *ioportid_t; + +/*===========================================================================*/ +/* I/O Ports Identifiers. */ +/*===========================================================================*/ + +/** + * @brief GPIO0 port identifier. + */ +#define IOPORT1 LPC_GPIO0 + +/** + * @brief GPIO1 port identifier. + */ +#define IOPORT2 LPC_GPIO1 + +/** + * @brief GPIO2 port identifier. + */ +#define IOPORT3 LPC_GPIO2 + +/** + * @brief GPIO3 port identifier. + */ +#define IOPORT4 LPC_GPIO3 + +/*===========================================================================*/ +/* Implementation, some of the following macros could be implemented as */ +/* functions, if so please put them in pal_lld.c. */ +/*===========================================================================*/ + +/** + * @brief Low level PAL subsystem initialization. + * + * @param[in] config architecture-dependent ports configuration + */ +#define pal_lld_init(config) _pal_lld_init(config) + +/** + * @brief Reads the physical I/O port states. + * @note This function is not meant to be invoked directly by the + * application code. + * + * @param[in] port port identifier + * @return The port bits. + */ +#define pal_lld_readport(port) ((port)->DATA) + +/** + * @brief Reads the output latch. + * @details The purpose of this function is to read back the latched output + * value. + * @note This function is not meant to be invoked directly by the + * application code. + * + * @param[in] port port identifier + * @return The latched logical states. + */ +#define pal_lld_readlatch(port) ((port)->DATA) + +/** + * @brief Writes a bits mask on a I/O port. + * @note This function is not meant to be invoked directly by the + * application code. + * + * @param[in] port port identifier + * @param[in] bits bits to be written on the specified port + */ +#define pal_lld_writeport(port, bits) ((port)->DATA = (bits)) + +/** + * @brief Sets a bits mask on a I/O port. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] bits bits to be ORed on the specified port + */ +//#define pal_lld_setport(port, bits) + +/** + * @brief Clears a bits mask on a I/O port. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] bits bits to be cleared on the specified port + */ +//#define pal_lld_clearport(port, bits) + +/** + * @brief Toggles a bits mask on a I/O port. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] bits bits to be XORed on the specified port + */ +//#define pal_lld_toggleport(port, bits) + +/** + * @brief Reads a group of bits. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] mask group mask + * @param[in] offset group bit offset within the port + * @return The group logical states. + */ +//#define pal_lld_readgroup(port, mask, offset) + +/** + * @brief Writes a group of bits. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] mask group mask + * @param[in] offset group bit offset within the port + * @param[in] bits bits to be written. Values exceeding the group width + * are masked. + */ +//#define pal_lld_writegroup(port, mask, offset, bits) + +/** + * @brief Pads group mode setup. + * @details This function programs a pads group belonging to the same port + * with the specified mode. + * @note This function is not meant to be invoked directly by the + * application code. + * @note Programming an unknown or unsupported mode is silently ignored. + * + * @param[in] port port identifier + * @param[in] mask group mask + * @param[in] mode group mode + */ +//#define pal_lld_setgroupmode(port, mask, mode) + +/** + * @brief Reads a logical state from an I/O pad. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @return The logical state. + * @retval PAL_LOW low logical state. + * @retval PAL_HIGH high logical state. + */ +//#define pal_lld_readpad(port, pad) + +/** + * @brief Writes a logical state on an output pad. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[out] bit logical value, the value must be @p PAL_LOW or + * @p PAL_HIGH + */ +//#define pal_lld_writepad(port, pad, bit) + +/** + * @brief Sets a pad logical state to @p PAL_HIGH. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + */ +//#define pal_lld_setpad(port, pad) + +/** + * @brief Clears a pad logical state to @p PAL_LOW. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + */ +//#define pal_lld_clearpad(port, pad) + +/** + * @brief Toggles a pad logical state. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + */ +//#define pal_lld_togglepad(port, pad) + +/** + * @brief Pad mode setup. + * @details This function programs a pad with the specified mode. + * @note This function is not meant to be invoked directly by the + * application code. + * @note The @ref PAL provides a default software implementation of this + * functionality, implement this function if can optimize it by using + * special hardware functionalities or special coding. + * @note Programming an unknown or unsupported mode is silently ignored. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] mode pad mode + */ +//#define pal_lld_setpadmode(port, pad, mode) + +extern const PALConfig pal_default_config; + +#ifdef __cplusplus +extern "C" { +#endif + void _pal_lld_init(const PALConfig *config); + void _pal_lld_setgroupmode(ioportid_t port, + ioportmask_t mask, + uint_fast8_t mode); +#ifdef __cplusplus +} +#endif + +#endif /* CH_HAL_USE_PAL */ + +#endif /* _PAL_LLD_H_ */ + +/** @} */ diff --git a/os/hal/platforms/LPC111x/platform.mk b/os/hal/platforms/LPC111x/platform.mk index 855ebb85e..b3f7fd976 100644 --- a/os/hal/platforms/LPC111x/platform.mk +++ b/os/hal/platforms/LPC111x/platform.mk @@ -1,5 +1,6 @@ # List of all the LPC111x platform files. -PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/LPC11xx/hal_lld.c +PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/LPC111x/hal_lld.c \ + ${CHIBIOS}/os/hal/platforms/LPC111x/pal_lld.c # Required include directories -PLATFORMINC = ${CHIBIOS}/os/hal/platforms/LPC11xx +PLATFORMINC = ${CHIBIOS}/os/hal/platforms/LPC111x diff --git a/os/ports/GCC/ARMCMx/LPC111x/port.mk b/os/ports/GCC/ARMCMx/LPC111x/port.mk index 3935b9195..59ea66517 100644 --- a/os/ports/GCC/ARMCMx/LPC111x/port.mk +++ b/os/ports/GCC/ARMCMx/LPC111x/port.mk @@ -7,5 +7,5 @@ PORTSRC = ${CHIBIOS}/os/ports/GCC/ARMCMx/chcore.c \ PORTASM = ${CHIBIOS}/os/ports/GCC/ARMCMx/crt0.s PORTINC = ${CHIBIOS}/os/ports/GCC/ARMCMx \ - ${CHIBIOS}/os/ports/GCC/ARMCMx/LPC11xx \ + ${CHIBIOS}/os/ports/GCC/ARMCMx/LPC111x \ ${CHIBIOS}/os/ports/GCC/ARMCMx/cmsis -- cgit v1.2.3