[BACK]Return to config.c CVS log [TXT][DIR] Up to [local] / funnyos / arch / sam7s64

Annotation of funnyos/arch/sam7s64/config.c, Revision 1.9

1.1       init        1: /*
1.9     ! nbrk        2:  * $Id: config.c,v 1.8 2007/11/19 10:53:57 nbrk Exp $
1.1       init        3:  */
                      4: #include <sys/types.h>
                      5: #include <sys/device.h>
                      6:
1.9     ! nbrk        7: #include <dev/cpuvar.h>
        !             8: #include <arch/sam7s64/dev/at91sam7.h>
1.4       nbrk        9:
1.1       init       10: /*
                     11:  * Configuration file for platform (AT91SAM7S64).
                     12:  */
                     13:
                     14: /* device drivers */
                     15: extern struct driver root_dr;
                     16: extern struct driver cpu_dr;
1.3       init       17: extern struct driver saapbus_dr;
1.7       nbrk       18: extern struct driver sapio_dr;
1.8       nbrk       19: extern struct driver gpioled_dr;
1.1       init       20:
                     21:
1.9     ! nbrk       22: extern void    (*putchar)(char);
        !            23: extern void    sausart_0_putchar(char ch);
1.1       init       24:
                     25: /* amount of physical memory, in Bytes */
1.5       nbrk       26: uint32_t physmem = 16384 /* 16KB :) */;
1.1       init       27:
                     28: /*
                     29:  * Where to attach each device.
                     30:  */
                     31: struct attachinfo config_attachinfo[] = {
                     32:        /* child,   parent, pminor, loc,        intrno, flags */
                     33:        { "cpu" ,       "root",         0, 0,                   0,      0 },
1.3       init       34:        { "saapbus","root",     0, 0,                   0,      0 },
1.7       nbrk       35:        { "sapio",  "saapbus",  0, 0,                   0,  0 },
1.8       nbrk       36:        { "gpioled","sapio",    0, 17,                  0,      0 },
                     37:        { "gpioled","sapio",    0, 18,                  0,      0 },
1.1       init       38:        { NULL,         NULL,           0, 0,                   0,  0 }
                     39: };
                     40:
                     41:
                     42: /*
                     43:  * Link device names with their drivers.
                     44:  */
                     45: struct driverinfo config_driverinfo[] = {
                     46: /* name, driverp, ninstances (should be -1) */
                     47:        { "root", &root_dr, -1 },
                     48:        { "cpu" , &cpu_dr, -1 },
1.3       init       49:        { "saapbus" , &saapbus_dr, -1 },
1.7       nbrk       50:        { "sapio", &sapio_dr, -1 },
1.8       nbrk       51:        { "gpioled", &gpioled_dr, -1 },
1.1       init       52:        { NULL, NULL, 0 }
                     53: };
                     54:
                     55:
                     56: /*
                     57:  * Machine early-stage initialization hooks.
                     58:  */
                     59:
                     60: void
1.4       nbrk       61: config_machineinit(void)
1.1       init       62: {
                     63:        /*
1.4       nbrk       64:         * Initialize critical devices at startup.
1.1       init       65:         */
1.9     ! nbrk       66:        __cpu_disable_irq();
1.4       nbrk       67:
1.5       nbrk       68:        /* disable watchdog */
1.9     ! nbrk       69:        *AT91C_WDTC_WDMR = AT91C_WDTC_WDDIS;
1.5       nbrk       70:
1.9     ! nbrk       71:        /* set FLASH to high-speed */
        !            72:        *AT91C_MC_FMR = AT91C_MC_FWS_0FWS;
1.5       nbrk       73:
                     74:        /*
1.9     ! nbrk       75:         * Initialize oscillators.
        !            76:         * Taken from Atmel's examples.
1.6       nbrk       77:         */
1.9     ! nbrk       78:        /* Set MCK at 48 054 850 */
1.6       nbrk       79:
1.9     ! nbrk       80:        /* 1 Enabling the Main Oscillator */
        !            81:     /* SCK = 1/32768 = 30.51 uSecond
        !            82:      * Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
1.5       nbrk       83:         */
1.9     ! nbrk       84:        *AT91C_PMC_MOR = ( (AT91C_CKGR_OSCOUNT & (0x06 <<8)) | AT91C_CKGR_MOSCEN);
1.5       nbrk       85:
1.9     ! nbrk       86:        /* Wait the startup time */
        !            87:        while(!(*AT91C_PMC_SR & AT91C_PMC_MOSCS))
        !            88:                ;
1.5       nbrk       89:
1.9     ! nbrk       90:        /* 2 Checking the Main Oscillator Frequency (Optional) */
        !            91:        /* TODO */
1.5       nbrk       92:
1.9     ! nbrk       93:        /* 3 Setting PLL and divider: */
        !            94:        /* - div by 14 Fin = 1.3165 =(18,432 / 14)
        !            95:         * - Mul 72+1: Fout =   96.1097 =(3,6864 *73)
        !            96:         * for 96 MHz the erroe is 0.11%
        !            97:         * Field out NOT USED = 0
        !            98:         * PLLCOUNT pll startup time estimate at : 0.844 ms
        !            99:         * PLLCOUNT 28 = 0.000844 /(1/32768)
        !           100:         */
        !           101:        *AT91C_PMC_PLLR = ( (AT91C_CKGR_DIV & 14 )              |
        !           102:                                        (AT91C_CKGR_PLLCOUNT & (28<<8)) |
        !           103:                                        (AT91C_CKGR_MUL & (72<<16)) );
1.5       nbrk      104:
1.9     ! nbrk      105:        /* Wait the startup time */
        !           106:        while(!(*AT91C_PMC_SR & AT91C_PMC_LOCK))
        !           107:                ;
        !           108:        while(!(*AT91C_PMC_SR & AT91C_PMC_MCKRDY))
        !           109:                ;
1.5       nbrk      110:
1.9     ! nbrk      111:        /* 4. Selection of Master Clock and Processor Clock */
        !           112:        /* select the PLL clock divided by 2: */
        !           113:        *AT91C_PMC_MCKR = AT91C_PMC_PRES_CLK_2;
        !           114:        while(!(*AT91C_PMC_SR & AT91C_PMC_MCKRDY))
        !           115:                ;
        !           116:
        !           117:        *AT91C_PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
        !           118:        while(!(*AT91C_PMC_SR & AT91C_PMC_MCKRDY))
        !           119:                ;
1.5       nbrk      120:
1.9     ! nbrk      121:        /* enable clock to PIO and USART0 */
        !           122:        *AT91C_PMC_PCER = AT91C_ID_PIOA | AT91C_ID_US0 AT91C_ID_PDC;
        !           123:
        !           124:        *AT91C_PIOA_PER = (1 << 17 | 1 << 18);
        !           125:        *AT91C_PIOA_OER = (1 << 17 | 1 << 18);
        !           126:        *AT91C_PIOA_CODR= (1 << 17 | 1 << 18);
        !           127:
        !           128:        /* initialize USART0 (we clock it in PMC above) */
        !           129:
        !           130:   *AT91C_PIOA_PDR = AT91C_PA5_RXD0 |        /* Enable RxD0 Pin */
        !           131:                     AT91C_PA6_TXD0;         /* Enalbe TxD0 Pin */
        !           132:
        !           133:   *AT91C_US0_CR = AT91C_US_RSTRX |          /* Reset Receiver      */
        !           134:                   AT91C_US_RSTTX |          /* Reset Transmitter   */
        !           135:                   AT91C_US_RXDIS |          /* Receiver Disable    */
        !           136:                   AT91C_US_TXDIS;           /* Transmitter Disable */
        !           137:
        !           138:   *AT91C_US0_MR = AT91C_US_USMODE_NORMAL |  /* Normal Mode */
        !           139:                   AT91C_US_CLKS_CLOCK    |  /* Clock = MCK */
        !           140:                   AT91C_US_CHRL_8_BITS   |  /* 8-bit Data  */
        !           141:                   AT91C_US_PAR_NONE      |  /* No Parity   */
        !           142:                   AT91C_US_NBSTOP_1_BIT;    /* 1 Stop Bit  */
        !           143:
        !           144:   *AT91C_US0_BRGR = 48054857 / 16 / 9600;                    /* Baud Rate Divisor */
        !           145:
        !           146:   *AT91C_US0_CR = AT91C_US_RXEN  |          /* Receiver Enable     */
        !           147:                   AT91C_US_TXEN;            /* Transmitter Enable  */
        !           148:
        !           149:        /* redefine putchar */
        !           150:        putchar = sausart_0_putchar;
        !           151: //     putchar(0);
        !           152: //     putchar(0x46);
        !           153: //     putchar(0x46);
1.1       init      154: }
                    155:
                    156:

CVSweb