From c731a9477bd4fbbadb4ac7c19726c4d5f812f461 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 13 Jun 2009 07:06:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1029 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-AT91SAM7X-GCC/board.c | 3 - demos/ARM7-AT91SAM7X-GCC/main.c | 9 +- demos/ARM7-AT91SAM7X-WEB-GCC/board.c | 28 ++--- demos/ARM7-AT91SAM7X-WEB-GCC/board.h | 59 ++++++----- demos/ARM7-AT91SAM7X-WEB-GCC/main.c | 9 +- ports/ARM7-AT91SAM7X/pal_lld.h | 197 +++++++++++++++++++++++++++++++++++ ports/ARM7-AT91SAM7X/sam7x_emac.c | 8 +- 7 files changed, 258 insertions(+), 55 deletions(-) create mode 100644 ports/ARM7-AT91SAM7X/pal_lld.h diff --git a/demos/ARM7-AT91SAM7X-GCC/board.c b/demos/ARM7-AT91SAM7X-GCC/board.c index 2b53c87b7..02ac5046d 100644 --- a/demos/ARM7-AT91SAM7X-GCC/board.c +++ b/demos/ARM7-AT91SAM7X-GCC/board.c @@ -101,9 +101,6 @@ void hwinit0(void) { * PIO initialization. */ palInit(); -/* AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB); - AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; - AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF;*/ } /* diff --git a/demos/ARM7-AT91SAM7X-GCC/main.c b/demos/ARM7-AT91SAM7X-GCC/main.c index c51c911c9..614b649cd 100644 --- a/demos/ARM7-AT91SAM7X-GCC/main.c +++ b/demos/ARM7-AT91SAM7X-GCC/main.c @@ -18,6 +18,7 @@ */ #include +#include #include #include "board.h" @@ -27,9 +28,9 @@ static WORKING_AREA(waThread1, 64); static msg_t Thread1(void *arg) { while (TRUE) { - AT91C_BASE_PIOB->PIO_SODR = PIOB_LCD_BL; // LCD on. + palSetPad(IOPORT_B, PIOB_LCD_BL); chThdSleepMilliseconds(100); - AT91C_BASE_PIOB->PIO_CODR = PIOB_LCD_BL; // LCD off. + palClearPad(IOPORT_B, PIOB_LCD_BL); chThdSleepMilliseconds(900); } return 0; @@ -51,9 +52,9 @@ int main(int argc, char **argv) { */ while (TRUE) { chThdSleepMilliseconds(500); - if (!(AT91C_BASE_PIOB->PIO_PDSR & PIOB_SW1)) + if (!palReadPad(IOPORT_B, PIOB_SW1)) chFDDWrite(&COM1, (uint8_t *)"Hello World!\r\n", 14); - if (!(AT91C_BASE_PIOB->PIO_PDSR & PIOB_SW2)) + if (!palReadPad(IOPORT_B, PIOB_SW2)) TestThread(&COM1); } diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/board.c b/demos/ARM7-AT91SAM7X-WEB-GCC/board.c index 630a0ad5d..e0b170120 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/board.c +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/board.c @@ -18,6 +18,7 @@ */ #include +#include #include "board.h" #include "at91lib/aic.h" @@ -26,7 +27,7 @@ #include /* - * FIQ Handler weak symbol defined in vectors.s. + * FIQ Handler weak symbol defined in vectors.s. */ void FiqHandler(void); @@ -98,11 +99,9 @@ void hwinit0(void) { ; /* - * I/O setup, enable clocks, initially all pins are inputs with pullups. + * PIO initialization. */ - AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB); - AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; - AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF; + palInit(); } /* @@ -127,24 +126,25 @@ void hwinit1(void) { /* * LCD pins setup. */ - AT91C_BASE_PIOB->PIO_CODR = PIOB_LCD_BL; // Set to low. - AT91C_BASE_PIOB->PIO_OER = PIOB_LCD_BL; // Configure as output. - AT91C_BASE_PIOB->PIO_PPUDR = PIOB_LCD_BL; // Disable internal pullup resistor. + palClearPad(IOPORT_B, PIOB_LCD_BL); + AT91C_BASE_PIOB->PIO_OER = PIOB_LCD_BL_MASK; // Configure as output. + AT91C_BASE_PIOB->PIO_PPUDR = PIOB_LCD_BL_MASK; // Disable internal pullup resistor. - AT91C_BASE_PIOA->PIO_SODR = PIOA_LCD_RESET; // Set to high. - AT91C_BASE_PIOA->PIO_OER = PIOA_LCD_RESET; // Configure as output. - AT91C_BASE_PIOA->PIO_PPUDR = PIOA_LCD_RESET; // Disable internal pullup resistor. + palSetPad(IOPORT_A, PIOA_LCD_RESET); + AT91C_BASE_PIOA->PIO_OER = PIOA_LCD_RESET_MASK; // Configure as output. + AT91C_BASE_PIOA->PIO_PPUDR = PIOA_LCD_RESET_MASK; // Disable internal pullup resistor. /* * Joystick and buttons, disable pullups, already inputs. */ - AT91C_BASE_PIOA->PIO_PPUDR = PIOA_B1 | PIOA_B2 | PIOA_B3 | PIOA_B4 | PIOA_B5; - AT91C_BASE_PIOB->PIO_PPUDR = PIOB_SW1 | PIOB_SW2; + AT91C_BASE_PIOA->PIO_PPUDR = PIOA_B1_MASK | PIOA_B2_MASK | PIOA_B3_MASK | + PIOA_B4_MASK | PIOA_B5_MASK; + AT91C_BASE_PIOB->PIO_PPUDR = PIOB_SW1_MASK | PIOB_SW2_MASK; /* * MMC/SD slot, disable pullups, already inputs. */ - AT91C_BASE_SYS->PIOB_PPUDR = PIOB_MMC_WP | PIOB_MMC_CP; + AT91C_BASE_SYS->PIOB_PPUDR = PIOB_MMC_WP_MASK | PIOB_MMC_CP_MASK; /* * PIT Initialization. diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/board.h b/demos/ARM7-AT91SAM7X-WEB-GCC/board.h index 57629be2f..fe9219aa3 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/board.h +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/board.h @@ -32,31 +32,38 @@ /* * I/O definitions. */ -#define PIOA_LCD_RESET (1 << 2) -#define PIOA_B1 (1 << 7) -#define PIOA_B2 (1 << 8) -#define PIOA_B3 (1 << 9) -#define PIOA_B4 (1 << 14) -#define PIOA_B5 (1 << 15) -#define PIOA_USB_PUP (1 << 25) -#define PIOA_USB_PR (1 << 26) -#define PIOA_PA27 (1 << 27) -#define PIOA_PA28 (1 << 28) -#define PIOA_PA29 (1 << 29) -#define PIOA_PA30 (1 << 30) - -#define PIOB_PHY_PD (1 << 18) -#define PIOB_AUDIO_OUT (1 << 19) -#define PIOB_LCD_BL (1 << 20) -#define PIOB_PB21 (1 << 21) -#define PIOB_MMC_WP (1 << 22) -#define PIOB_MMC_CP (1 << 23) -#define PIOB_SW1 (1 << 24) -#define PIOB_SW2 (1 << 25) -#define PIOB_PHY_IRQ (1 << 26) -#define PIOB_PB27_AD0 (1 << 27) -#define PIOB_PB28_AD1 (1 << 28) -#define PIOB_PB29_AD2 (1 << 29) -#define PIOB_PB30_AD3 (1 << 30) +#define PIOA_LCD_RESET 2 +#define PIOA_LCD_RESET_MASK (1 << PIOA_LCD_RESET) +#define PIOA_B1 7 +#define PIOA_B1_MASK (1 << PIOA_B1) +#define PIOA_B2 8 +#define PIOA_B2_MASK (1 << PIOA_B2) +#define PIOA_B3 9 +#define PIOA_B3_MASK (1 << PIOA_B3) +#define PIOA_B4 14 +#define PIOA_B4_MASK (1 << PIOA_B4) +#define PIOA_B5 15 +#define PIOA_B5_MASK (1 << PIOA_B5) +#define PIOA_USB_PUP 25 +#define PIOA_USB_PUP_MASK (1 << PIOA_USB_PUP) +#define PIOA_USB_PR 26 +#define PIOA_USB_PR_MASK (1 << PIOA_USB_PR) + +#define PIOB_PHY_PD 18 +#define PIOB_PHY_PD_MASK (1 << PIOB_PHY_PD) +#define PIOB_AUDIO_OUT 19 +#define PIOB_AUDIO_OUT_MASK (1 << PIOB_AUDIO_OUT) +#define PIOB_LCD_BL 20 +#define PIOB_LCD_BL_MASK (1 << PIOB_LCD_BL) +#define PIOB_MMC_WP 22 +#define PIOB_MMC_WP_MASK (1 << PIOB_MMC_WP) +#define PIOB_MMC_CP 23 +#define PIOB_MMC_CP_MASK (1 << PIOB_MMC_CP) +#define PIOB_SW1 24 +#define PIOB_SW1_MASK (1 << PIOB_SW1) +#define PIOB_SW2 25 +#define PIOB_SW2_MASK (1 << PIOB_SW2) +#define PIOB_PHY_IRQ 26 +#define PIOB_PHY_IRQ_MASK (1 << PIOB_PHY_IRQ) #endif /* _BOARD_H_ */ diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/main.c b/demos/ARM7-AT91SAM7X-WEB-GCC/main.c index 07af9b0bd..0eafb2260 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/main.c +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/main.c @@ -18,6 +18,7 @@ */ #include +#include #include #include "board.h" @@ -32,9 +33,9 @@ static WORKING_AREA(waThread1, 64); static msg_t Thread1(void *arg) { while (TRUE) { - AT91C_BASE_PIOB->PIO_SODR = PIOB_LCD_BL; // LCD on. + palSetPad(IOPORT_B, PIOB_LCD_BL); chThdSleepMilliseconds(100); - AT91C_BASE_PIOB->PIO_CODR = PIOB_LCD_BL; // LCD off. + palClearPad(IOPORT_B, PIOB_LCD_BL); chThdSleepMilliseconds(900); } return 0; @@ -57,9 +58,9 @@ int main(int argc, char **argv) { */ while (TRUE) { chThdSleepMilliseconds(500); - if (!(AT91C_BASE_PIOB->PIO_PDSR & PIOB_SW1)) + if (!palReadPad(IOPORT_B, PIOB_SW1)) chFDDWrite(&COM1, (uint8_t *)"Hello World!\r\n", 14); - if (!(AT91C_BASE_PIOB->PIO_PDSR & PIOB_SW2)) + if (!palReadPad(IOPORT_B, PIOB_SW2)) TestThread(&COM1); } diff --git a/ports/ARM7-AT91SAM7X/pal_lld.h b/ports/ARM7-AT91SAM7X/pal_lld.h new file mode 100644 index 000000000..37088a4cc --- /dev/null +++ b/ports/ARM7-AT91SAM7X/pal_lld.h @@ -0,0 +1,197 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 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 ports/ARM7-AT91SAM7X/pal_lld.h + * @brief AT91SAM7X PIO low level driver + * @addtogroup AT91SAM7X_PAL + * @{ + */ + +#ifndef _PAL_LLD_H_ +#define _PAL_LLD_H_ + +#ifndef AT91SAM7X256_H +#include "at91lib/AT91SAM7X256.h" +#endif + +/*===========================================================================*/ +/* I/O Ports Types and constants. */ +/*===========================================================================*/ + +/** + * @brief Width, in bits, of an I/O port. + */ +#define PAL_IOPORTS_WIDTH 32 + +/** + * @brief Digital I/O port sized unsigned type. + */ +typedef uint32_t ioportmask_t; + +/** + * @brief Port Identifier. + * @details This type can be a scalar or some kind of pointer, do not make + * any assumption about it, use the provided macros when populating + * variables of this type. + */ +typedef AT91PS_PIO ioportid_t; + +/*===========================================================================*/ +/* I/O Ports Identifiers. */ +/*===========================================================================*/ + +/** + * @brief PIO port A identifier. + */ +#define IOPORT_A AT91C_BASE_PIOA + +/** + * @brief PIO port B identifier. + */ +#define IOPORT_B AT91C_BASE_PIOB + +/*===========================================================================*/ +/* Implementation, some of the following macros could be implemented as */ +/* functions, if so please put them in a file named pal_lld.c. */ +/*===========================================================================*/ + +/** + * @brief Low level PAL subsystem initialization. + * @details Clocks are enabled and both PIO ports are reset to a known state + * and all pads are enabled a digital I/Os. + * + * @note The other PIO registers are not modified, the PIOs are supposed to + * have just been reset. The PIO_PSR is cleared because its status + * after the reset is not very clear in the documentation. + */ +#define pal_lld_init() { \ + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB); \ + AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; \ + AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF; \ +} + +/** + * @brief Reads the physical I/O port states. + * @details This function is implemented by reading the PIO_PDSR register, the + * implementation has no side effects. + * + * @param[in] port the port identifier + * @return The port bits. + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_readport(port) ((port)->PIO_PDSR) + +/** + * @brief Reads the output latch. + * @details This function is implemented by reading the PIO_ODSR register, the + * implementation has no side effects. + * + * @param[in] port the port identifier + * @return The latched logical states. + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_readlatch(port) ((port)->PIO_ODSR) + +/** + * @brief Writes a bits mask on a I/O port. + * @details This function is implemented by writing the PIO_ODSR register, the + * implementation has no side effects. + * + * @param[in] port the port identifier + * @param[in] bits the bits to be written on the specified port + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_writeport(port, bits) { \ + (port)->PIO_ODSR = (bits); \ +} + +/** + * @brief Sets a bits mask on a I/O port. + * @details This function is implemented by writing the PIO_SODR register, the + * implementation has no side effects. + * + * @param[in] port the port identifier + * @param[in] bits the bits to be ORed on the specified port + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_setport(port, bits) { \ + (port)->PIO_SODR = (bits); \ +} + + +/** + * @brief Clears a bits mask on a I/O port. + * @details This function is implemented by writing the PIO_CODR register, the + * implementation has no side effects. + * + * @param[in] port the port identifier + * @param[in] bits the bits to be cleared on the specified port + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_clearport(port, bits) { \ + (port)->PIO_CODR = (bits); \ +} + +/** + * @brief Writes a group of bits. + * @details This function is implemented by writing the PIO_OWER, PIO_ODSR and + * PIO_OWDR registers, the implementation is not atomic because the + * multiple accesses. + * + * @param[in] port the port identifier + * @param[in] mask the group mask + * @param[in] offset the group bit offset within the port + * @param[in] bits the bits to be written. Values exceeding the group width + * are masked. + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_writegroup(port, mask, offset, bits) { \ + (port)->PIO_OWER = (mask) << (offset); \ + (port)->PIO_ODSR = (bits) << (offset); \ + (port)->PIO_OWDR = (mask) << (offset); \ +} + +/** + * @brief Writes a logical state on an output pad. + * + * @param[in] port the port identifier + * @param[in] pad the pad number within the port + * @param[out] bit the logical value, the value must be @p 0 or @p 1 + * + * @note This function is not meant to be invoked directly by the application + * code. + */ +#define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit) + +#endif /* _PAL_LLD_H_ */ + +/** @} */ diff --git a/ports/ARM7-AT91SAM7X/sam7x_emac.c b/ports/ARM7-AT91SAM7X/sam7x_emac.c index 64467b440..b0db11dca 100644 --- a/ports/ARM7-AT91SAM7X/sam7x_emac.c +++ b/ports/ARM7-AT91SAM7X/sam7x_emac.c @@ -65,7 +65,7 @@ static BufDescriptorEntry *txptr; #define PHY_LATCHED_PINS (AT91C_PB4_ECRS | AT91C_PB5_ERX0 | AT91C_PB6_ERX1 | \ AT91C_PB7_ERXER | AT91C_PB13_ERX2 | AT91C_PB14_ERX3 | \ - AT91C_PB15_ERXDV | AT91C_PB16_ECOL | PIOB_PHY_IRQ) + AT91C_PB15_ERXDV | AT91C_PB16_ECOL | PIOB_PHY_IRQ_MASK) /* * PHY utilities. @@ -177,9 +177,9 @@ void emac_init(int prio) { /* * PHY power control. */ - AT91C_BASE_PIOB->PIO_OER = PIOB_PHY_PD; // Becomes an output. - AT91C_BASE_PIOB->PIO_PPUDR = PIOB_PHY_PD; // Default pullup disabled. - AT91C_BASE_PIOB->PIO_SODR = PIOB_PHY_PD; // Output to high level. + AT91C_BASE_PIOB->PIO_OER = PIOB_PHY_PD_MASK; // Becomes an output. + AT91C_BASE_PIOB->PIO_PPUDR = PIOB_PHY_PD_MASK; // Default pullup disabled. + AT91C_BASE_PIOB->PIO_SODR = PIOB_PHY_PD_MASK; // Output to high level. /* * PHY reset by pulsing the NRST pin. -- cgit v1.2.3