Nut/OS  4.10.3
API Reference
at91sam7x_ek.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 by egnite GmbH
00003  *
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the copyright holders nor the names of
00016  *    contributors may be used to endorse or promote products derived
00017  *    from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00026  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00027  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00028  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00029  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  * For additional information see http://www.ethernut.de/
00033  */
00034 
00035 /*
00036  * \file arch/arm/board/at91sam7x_ek.c
00037  * \brief AT91SAM7X-EK board initialization.
00038  *
00039  * \verbatim
00040  * $Id$
00041  * \endverbatim
00042  */
00043 
00044 #include <arch/arm.h>
00045 
00046 #define PHY_STRAP_AD0       _BV(PB5_ERX0_A)
00047 #define PHY_STRAP_AD1       _BV(PB6_ERX1_A)
00048 #define PHY_STRAP_AD2       _BV(PB13_ERX2_A)
00049 #define PHY_STRAP_AD3       _BV(PB14_ERX3_A)
00050 #define PHY_STRAP_AD4       _BV(PB4_ECRS_A)
00051 #define PHY_STRAP_ISOLATE   _BV(PB0_ETXCK_EREFCK_A)
00052 #define PHY_STRAP_10BTSER   _BV(PB17_ERXCK_A)
00053 #define PHY_STRAP_RPTR      _BV(PB7_ERXER_A)
00054 #define PHY_STRAP_RMII      _BV(PB16_ECOL_A)
00055 #define PHY_STRAP_TESTMODE  _BV(PB15_ERXDV_ECRSDV_A)
00056 
00057 #define PHY_PWRDWN          _BV(PB18_EF100_A)
00058 
00059 
00060 #define PHY_STRAP   ( \
00061     PHY_STRAP_AD0 | PHY_STRAP_AD1 | PHY_STRAP_AD2 | PHY_STRAP_AD3 | \
00062     PHY_STRAP_AD4 | PHY_STRAP_RMII | PHY_STRAP_TESTMODE )
00063 
00069 static void Sam7xekDelay(int n)
00070 {
00071     int l;
00072 
00073     for (l = 0; l < n; l++) {
00074         _NOP();
00075     }
00076 }
00077 
00081 static void Sam7xekClockInit(void)
00082 {
00083     outr(PMC_PCER, _BV(PIOB_ID));
00084     outr(PMC_PCER, _BV(EMAC_ID));
00085 }
00086 
00090 static void Sam7xekReset(void)
00091 {
00092     unsigned int mr;
00093 
00094     /* Save initial configuration. */
00095     mr = inr(RSTC_MR) & ~RSTC_KEY_MSK;
00096     /* Set reset pulse length to 250us, disable user reset. */
00097     outr(RSTC_MR, RSTC_KEY | (2 << RSTC_ERSTL_LSB));
00098     /* Invoke external reset. */
00099     outr(RSTC_CR, RSTC_KEY | RSTC_EXTRST);
00100     /* If we have 10k/100n RC, we need to wait 25us (1200 cycles) 
00101     ** for NRST becoming low. */
00102     Sam7xekDelay(250);
00103     /* Wait until reset pin is released. */
00104     while ((inr(RSTC_SR) & RSTC_NRSTL) == 0);
00105     /* Due to the RC filter, the pin is rising very slowly. */
00106     Sam7xekDelay(25000);
00107     /* Restore initial configuration. */
00108     outr(RSTC_MR, RSTC_KEY | mr);
00109 }
00110 
00119 static void Sam7xekPhyInit(void)
00120 {
00121     /* Power up the PHY. */
00122     outr(PIOB_PER, PHY_PWRDWN);
00123     outr(PIOB_OER, PHY_PWRDWN);
00124     outr(PIOB_CODR, PHY_PWRDWN);
00125     /* The PHY needs 25ms for powering up. */
00126     Sam7xekDelay(250000);
00127     /* Disable strap pin pull-ups. */
00128     outr(PIOB_PUDR, PHY_STRAP);
00129     /* Toggle reset line. */
00130     Sam7xekReset();
00131     /* Re-enable the pull-ups. */
00132     outr(PIOB_PUER, PHY_STRAP);
00133 }
00134 
00140 void NutBoardInit(void)
00141 {
00142     Sam7xekClockInit();
00143     Sam7xekPhyInit();
00144 }