From 3f8c09fde198a3680a5de0628c0cfbaf7f4d3abb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 17:35:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1361 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/mii.h | 34 +-------- os/hal/platforms/AT91SAM7/at91sam7_mii.c | 115 +++++++++++++++++++++++++++++++ os/hal/platforms/AT91SAM7/at91sam7_mii.h | 101 +++++++++++++++++++++++++++ os/hal/platforms/AT91SAM7/mac_lld.c | 2 + os/hal/platforms/AT91SAM7/mii_lld.c | 114 ------------------------------ os/hal/platforms/AT91SAM7/mii_lld.h | 101 --------------------------- os/hal/platforms/AT91SAM7/platform.mk | 2 +- os/hal/src/mii.c | 37 ---------- 8 files changed, 220 insertions(+), 286 deletions(-) create mode 100644 os/hal/platforms/AT91SAM7/at91sam7_mii.c create mode 100644 os/hal/platforms/AT91SAM7/at91sam7_mii.h delete mode 100644 os/hal/platforms/AT91SAM7/mii_lld.c delete mode 100644 os/hal/platforms/AT91SAM7/mii_lld.h delete mode 100644 os/hal/src/mii.c (limited to 'os') diff --git a/os/hal/include/mii.h b/os/hal/include/mii.h index a236c6dc3..c72a5f96d 100644 --- a/os/hal/include/mii.h +++ b/os/hal/include/mii.h @@ -32,9 +32,6 @@ #ifndef _MII_H_ #define _MII_H_ -#include "mac_lld.h" -#include "mii_lld.h" - /* * Generic MII registers. Note, not all registers are present on all PHY * devices and some extra registers may be present. @@ -185,36 +182,7 @@ #define MII_AM79C875_ID 0x00225540 #define MII_KS8721_ID 0x00221610 -/** - * @brief MII Driver initialization. - */ -#define miiInit() mii_lld_init() - -/** - * Resets a MII device. - * - * @param[in] macp pointer to the @p MACDriver object - */ -#define miiReset(macp) mii_lld_reset(macp) - -/** - * @brief Reads a MII register. - * - * @param[in] macp pointer to the @p MACDriver object - * @param addr the register address - * @return The register value. - */ -#define miiGet(macp, addr) mii_lld_get(macp, addr) - -/** - * @brief Writes a MII register. - * - * @param[in] macp pointer to the @p MACDriver object - * @param addr the register address - * @param value the new register value - */ -#define miiPut(macp, addr, value) mii_lld_put(macp, addr, value) -#endif /**< _MII_H_ */ +#endif /* _MII_H_ */ /** @} */ diff --git a/os/hal/platforms/AT91SAM7/at91sam7_mii.c b/os/hal/platforms/AT91SAM7/at91sam7_mii.c new file mode 100644 index 000000000..2b7491e38 --- /dev/null +++ b/os/hal/platforms/AT91SAM7/at91sam7_mii.c @@ -0,0 +1,115 @@ +/* + 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 AT91SAM7/at91sam7_mii.c + * @brief AT91SAM7 low level MII driver code + * @addtogroup AT91SAM7_MII + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#include "at91sam7_mii.h" + +/** + * @brief Low level MII driver initialization. + */ +void miiInit(void) { + +} + +/** + * @brief Resets a PHY device. + * + * @param[in] macp pointer to the @p MACDriver object + */ +void miiReset(MACDriver *macp) { + + (void)macp; + + /* + * Disables the pullups on all the pins that are latched on reset by the PHY. + */ + AT91C_BASE_PIOB->PIO_PPUDR = PHY_LATCHED_PINS; + +#ifdef PIOB_PHY_PD_MASK + /* + * PHY power control. + */ + AT91C_BASE_PIOB->PIO_OER = PIOB_PHY_PD_MASK; // Becomes an output. + AT91C_BASE_PIOB->PIO_PPUDR = PIOB_PHY_PD_MASK; // Default pullup disabled. +#if (PHY_HARDWARE == PHY_DAVICOM_9161) + AT91C_BASE_PIOB->PIO_CODR = PIOB_PHY_PD_MASK; // Output to low level. +#else + AT91C_BASE_PIOB->PIO_SODR = PIOB_PHY_PD_MASK; // Output to high level. +#endif +#endif // PIOB_PHY_PD_MASK + + /* + * PHY reset by pulsing the NRST pin. + */ + AT91C_BASE_RSTC->RSTC_RMR = 0xA5000100; + AT91C_BASE_RSTC->RSTC_RCR = 0xA5000000 | AT91C_RSTC_EXTRST; + while (!(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_NRSTL)) + ; +} + +/** + * @brief Reads a PHY register through the MII interface. + * + * @param[in] macp pointer to the @p MACDriver object + * @param addr the register address + * @return The register value. + */ +phyreg_t miiGet(MACDriver *macp, phyaddr_t addr) { + + (void)macp; + AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */ + (0b10 << 28) | /* RW */ + (PHY_ADDRESS << 23) | /* PHYA */ + (addr << 18) | /* REGA */ + (0b10 << 16); /* CODE */ + while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) + ; + return (phyreg_t)(AT91C_BASE_EMAC->EMAC_MAN & 0xFFFF); +} + +/** + * @brief Writes a PHY register through the MII interface. + * + * @param[in] macp pointer to the @p MACDriver object + * @param addr the register address + * @param value the new register value + */ +void miiPut(MACDriver *macp, phyaddr_t addr, phyreg_t value) { + + (void)macp; + AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */ + (0b01 << 28) | /* RW */ + (PHY_ADDRESS << 23) | /* PHYA */ + (addr << 18) | /* REGA */ + (0b10 << 16) | /* CODE */ + value; + while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) + ; +} + +/** @} */ diff --git a/os/hal/platforms/AT91SAM7/at91sam7_mii.h b/os/hal/platforms/AT91SAM7/at91sam7_mii.h new file mode 100644 index 000000000..6db87e31c --- /dev/null +++ b/os/hal/platforms/AT91SAM7/at91sam7_mii.h @@ -0,0 +1,101 @@ +/* + 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 AT91SAM7/at91sam7_mii.h + * @brief AT91SAM7 low level MII driver header + * @addtogroup AT91SAM7_MII + * @{ + */ + +#ifndef _AT91SAM7_MII_H_ +#define _AT91SAM7_MII_H_ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @brief PHY manufacturer and model. + */ +#if !defined(PHY_HARDWARE) || defined(__DOXYGEN__) +#define PHY_HARDWARE PHY_MICREL_KS8721 +#endif + +/*===========================================================================*/ +/* PHY specific constants. */ +/*===========================================================================*/ + +#define PHY_MICREL_KS8721 0 +#define PHY_DAVICOM_9161 1 + +/** + * @brief Pins latched by the PHY at reset. + */ +#if PHY_HARDWARE == PHY_MICREL_KS8721 +#define PHY_ADDRESS 1 +#define PHY_ID MII_KS8721_ID +#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_ECRSDV | AT91C_PB16_ECOL | \ + AT91C_PIO_PB26) + +#elif PHY_HARDWARE == PHY_DAVICOM_9161 +#define PHY_ADDRESS 0 +#define PHY_ID MII_DM9161_ID +#define PHY_LATCHED_PINS (AT91C_PB0_ETXCK_EREFCK | AT91C_PB4_ECRS | \ + AT91C_PB5_ERX0 | AT91C_PB6_ERX1 | \ + AT91C_PB7_ERXER | AT91C_PB13_ERX2 | \ + AT91C_PB14_ERX3 | AT91C_PB15_ERXDV_ECRSDV | \ + AT91C_PB16_ECOL | AT91C_PB17_ERXCK) +#endif /* PHY_HARDWARE */ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of a PHY register value. + */ +typedef uint16_t phyreg_t; + +/** + * @brief Type of a PHY register address. + */ +typedef uint8_t phyaddr_t; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void miiInit(void); + void miiReset(MACDriver *macp); + phyreg_t miiGet(MACDriver *macp, phyaddr_t addr); + void miiPut(MACDriver *macp, phyaddr_t addr, phyreg_t value); +#ifdef __cplusplus +} +#endif + +#endif /* _AT91SAM7_MII_H_ */ + +/** @} */ diff --git a/os/hal/platforms/AT91SAM7/mac_lld.c b/os/hal/platforms/AT91SAM7/mac_lld.c index 037502d94..6112a13ad 100644 --- a/os/hal/platforms/AT91SAM7/mac_lld.c +++ b/os/hal/platforms/AT91SAM7/mac_lld.c @@ -30,6 +30,8 @@ #include "hal.h" #include "mii.h" +#include "at91sam7_mii.h" + #if CH_HAL_USE_MAC || defined(__DOXYGEN__) /** diff --git a/os/hal/platforms/AT91SAM7/mii_lld.c b/os/hal/platforms/AT91SAM7/mii_lld.c deleted file mode 100644 index b21a349eb..000000000 --- a/os/hal/platforms/AT91SAM7/mii_lld.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - 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 AT91SAM7/mii_lld.c - * @brief AT91SAM7 low level MII driver code - * @addtogroup AT91SAM7_MII - * @{ - */ - -#include "ch.h" -#include "hal.h" -#include "mii.h" - -/** - * @brief Low level MII driver initialization. - */ -void mii_lld_init(void) { - -} - -/** - * @brief Resets a PHY device. - * - * @param[in] macp pointer to the @p MACDriver object - */ -void mii_lld_reset(MACDriver *macp) { - - (void)macp; - - /* - * Disables the pullups on all the pins that are latched on reset by the PHY. - */ - AT91C_BASE_PIOB->PIO_PPUDR = PHY_LATCHED_PINS; - -#ifdef PIOB_PHY_PD_MASK - /* - * PHY power control. - */ - AT91C_BASE_PIOB->PIO_OER = PIOB_PHY_PD_MASK; // Becomes an output. - AT91C_BASE_PIOB->PIO_PPUDR = PIOB_PHY_PD_MASK; // Default pullup disabled. -#if (PHY_HARDWARE == PHY_DAVICOM_9161) - AT91C_BASE_PIOB->PIO_CODR = PIOB_PHY_PD_MASK; // Output to low level. -#else - AT91C_BASE_PIOB->PIO_SODR = PIOB_PHY_PD_MASK; // Output to high level. -#endif -#endif // PIOB_PHY_PD_MASK - - /* - * PHY reset by pulsing the NRST pin. - */ - AT91C_BASE_RSTC->RSTC_RMR = 0xA5000100; - AT91C_BASE_RSTC->RSTC_RCR = 0xA5000000 | AT91C_RSTC_EXTRST; - while (!(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_NRSTL)) - ; -} - -/** - * @brief Reads a PHY register through the MII interface. - * - * @param[in] macp pointer to the @p MACDriver object - * @param addr the register address - * @return The register value. - */ -phyreg_t mii_lld_get(MACDriver *macp, phyaddr_t addr) { - - (void)macp; - AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */ - (0b10 << 28) | /* RW */ - (PHY_ADDRESS << 23) | /* PHYA */ - (addr << 18) | /* REGA */ - (0b10 << 16); /* CODE */ - while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) - ; - return (phyreg_t)(AT91C_BASE_EMAC->EMAC_MAN & 0xFFFF); -} - -/** - * @brief Writes a PHY register through the MII interface. - * - * @param[in] macp pointer to the @p MACDriver object - * @param addr the register address - * @param value the new register value - */ -void mii_lld_put(MACDriver *macp, phyaddr_t addr, phyreg_t value) { - - (void)macp; - AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */ - (0b01 << 28) | /* RW */ - (PHY_ADDRESS << 23) | /* PHYA */ - (addr << 18) | /* REGA */ - (0b10 << 16) | /* CODE */ - value; - while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) - ; -} - -/** @} */ diff --git a/os/hal/platforms/AT91SAM7/mii_lld.h b/os/hal/platforms/AT91SAM7/mii_lld.h deleted file mode 100644 index 4e1bc4139..000000000 --- a/os/hal/platforms/AT91SAM7/mii_lld.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - 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 AT91SAM7/mii_lld.h - * @brief AT91SAM7 low level MII driver header - * @addtogroup AT91SAM7_MII - * @{ - */ - -#ifndef _MII_LLD_H_ -#define _MII_LLD_H_ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/** - * @brief PHY manufacturer and model. - */ -#if !defined(PHY_HARDWARE) || defined(__DOXYGEN__) -#define PHY_HARDWARE PHY_MICREL_KS8721 -#endif - -/*===========================================================================*/ -/* PHY specific constants. */ -/*===========================================================================*/ - -#define PHY_MICREL_KS8721 0 -#define PHY_DAVICOM_9161 1 - -/** - * @brief Pins latched by the PHY at reset. - */ -#if PHY_HARDWARE == PHY_MICREL_KS8721 -#define PHY_ADDRESS 1 -#define PHY_ID MII_KS8721_ID -#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_ECRSDV | AT91C_PB16_ECOL | \ - AT91C_PIO_PB26) - -#elif PHY_HARDWARE == PHY_DAVICOM_9161 -#define PHY_ADDRESS 0 -#define PHY_ID MII_DM9161_ID -#define PHY_LATCHED_PINS (AT91C_PB0_ETXCK_EREFCK | AT91C_PB4_ECRS | \ - AT91C_PB5_ERX0 | AT91C_PB6_ERX1 | \ - AT91C_PB7_ERXER | AT91C_PB13_ERX2 | \ - AT91C_PB14_ERX3 | AT91C_PB15_ERXDV_ECRSDV | \ - AT91C_PB16_ECOL | AT91C_PB17_ERXCK) -#endif /* PHY_HARDWARE */ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Type of a PHY register value. - */ -typedef uint16_t phyreg_t; - -/** - * @brief Type of a PHY register address. - */ -typedef uint8_t phyaddr_t; - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void mii_lld_init(void); - void mii_lld_reset(MACDriver *macp); - phyreg_t mii_lld_get(MACDriver *macp, phyaddr_t addr); - void mii_lld_put(MACDriver *macp, phyaddr_t addr, phyreg_t value); -#ifdef __cplusplus -} -#endif - -#endif /* _MII_LLD_H_ */ - -/** @} */ diff --git a/os/hal/platforms/AT91SAM7/platform.mk b/os/hal/platforms/AT91SAM7/platform.mk index c3fc8c6fd..a6293dfdd 100644 --- a/os/hal/platforms/AT91SAM7/platform.mk +++ b/os/hal/platforms/AT91SAM7/platform.mk @@ -3,7 +3,7 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/AT91SAM7/hal_lld.c \ ${CHIBIOS}/os/hal/platforms/AT91SAM7/pal_lld.c \ ${CHIBIOS}/os/hal/platforms/AT91SAM7/serial_lld.c \ ${CHIBIOS}/os/hal/platforms/AT91SAM7/mac_lld.c \ - ${CHIBIOS}/os/hal/platforms/AT91SAM7/mii_lld.c \ + ${CHIBIOS}/os/hal/platforms/AT91SAM7/at91sam7_mii.c \ ${CHIBIOS}/os/hal/platforms/AT91SAM7/at91lib/aic.c # Required include directories diff --git a/os/hal/src/mii.c b/os/hal/src/mii.c deleted file mode 100644 index 4618ecbbb..000000000 --- a/os/hal/src/mii.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - 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 mii.c - * @brief mii Driver code. - * @addtogroup MII - * @{ - */ - -#include "ch.h" -#include "mac.h" -#include "mii.h" - -/* - * Currently there is no code, everything is done in the header, you may - * omit this file from the project but this may change in future releases. - * The file is here because the driver's naming pattern. - */ - -/** @} */ -- cgit v1.2.3