source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/bspstart.c @ e76068d

4.104.115
Last change on this file since e76068d was e76068d, checked in by Joel Sherrill <joel.sherrill@…>, on 09/16/08 at 19:06:45

2008-09-16 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, startup/bspstart.c: Add use of bsp_get_work_area() in its own file and rely on BSP Framework to perform more initialization. Remove unnecessary includes of rtems/libio.h and rtems/libcsupport.h.
  • startup/bspgetworkarea.c: New file.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief BSP startup code.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be found in the file
18 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
19 */
20
21#include <mpc55xx/mpc55xx.h>
22#include <mpc55xx/regs.h>
23#include <mpc55xx/edma.h>
24
25#include <rtems.h>
26
27#include <libcpu/powerpc-utility.h>
28
29#include <bsp.h>
30#include <bsp/bootcard.h>
31#include <bsp/irq.h>
32#include <bsp/irq-generic.h>
33#include <bsp/ppc_exc_bspsupp.h>
34
35#define RTEMS_STATUS_CHECKS_USE_PRINTK
36
37#include <rtems/status-checks.h>
38
39#define DEBUG_DONE() DEBUG_PRINT( "Done\n")
40
41#define MPC55XX_INTERRUPT_STACK_SIZE 0x1000
42
43/* Symbols defined in linker command file */
44LINKER_SYMBOL(bsp_ram_start);
45LINKER_SYMBOL(bsp_ram_end);
46LINKER_SYMBOL(bsp_external_ram_start);
47LINKER_SYMBOL(bsp_external_ram_size);
48LINKER_SYMBOL(bsp_section_bss_end);
49
50unsigned int bsp_clock_speed = 0;
51
52uint32_t bsp_clicks_per_usec = 0;
53
54void BSP_panic( char *s)
55{
56        rtems_interrupt_level level;
57
58        rtems_interrupt_disable( level);
59
60        printk( "%s PANIC %s\n", _RTEMS_version, s);
61
62        while (1) {
63                /* Do nothing */
64        }
65}
66
67void _BSP_Fatal_error( unsigned n)
68{
69        rtems_interrupt_level level;
70
71        rtems_interrupt_disable( level);
72
73        printk( "%s PANIC ERROR %u\n", _RTEMS_version, n);
74
75        while (1) {
76                /* Do nothing */
77        }
78}
79
80void bsp_predriver_hook()
81{
82        rtems_status_code sc = RTEMS_SUCCESSFUL;
83
84        DEBUG_PRINT( "Initialize eDMA ...\n");
85        sc = mpc55xx_edma_init();
86        if (sc != RTEMS_SUCCESSFUL) {
87                BSP_panic( "Cannot initialize eDMA");
88        } else {
89                DEBUG_DONE();
90        }
91}
92
93static void mpc55xx_ebi_init()
94{
95        struct EBI_CS_tag cs = { BR : MPC55XX_ZERO_FLAGS, OR : MPC55XX_ZERO_FLAGS };
96        union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS;
97        int i = 0;
98
99        /* External SRAM (0 wait states, 512kB, 4 word burst) */
100        cs.BR.B.BA = 0;
101        cs.BR.B.PS = 1;
102        cs.BR.B.BL = 1;
103        cs.BR.B.WEBS = 0;
104        cs.BR.B.TBDIP = 0;
105        cs.BR.B.BI = 1; /* TODO: Enable burst */
106        cs.BR.B.V = 1;
107
108        cs.OR.B.AM = 0x1fff0;
109        cs.OR.B.SCY = 0;
110        cs.OR.B.BSCY = 0;
111
112        EBI.CS [0] = cs;
113
114        /* !CS [0] */
115        SIU.PCR [0].R = 0x443;
116
117        /* ADDR [8 : 31] */
118        for (i = 4; i < 4 + 24; ++i) {
119                SIU.PCR [i].R = 0x440;
120        }
121
122        /* DATA [0 : 15] */
123        for (i = 28; i < 28 + 16; ++i) {
124                SIU.PCR [i].R = 0x440;
125        }
126
127        /* RD_!WR */
128        SIU.PCR [62].R = 0x443;
129
130        /* !BDIP */
131        SIU.PCR [63].R = 0x443;
132
133        /* !WE [0 : 3] */
134        for (i = 64; i < 64 + 4; ++i) {
135                SIU.PCR [i].R = 0x443;
136        }
137
138        /* !OE */
139        SIU.PCR [68].R = 0x443;
140
141        /* !TS */
142        SIU.PCR [69].R = 0x443;
143}
144
145/**
146 * @brief Start BSP.
147 */
148void bsp_start(void)
149{
150        ppc_cpu_id_t myCpu;
151        ppc_cpu_revision_t myCpuRevision;
152
153        uint32_t interrupt_stack_start = bsp_ram_end - 2 * MPC55XX_INTERRUPT_STACK_SIZE;
154        uint32_t interrupt_stack_size = MPC55XX_INTERRUPT_STACK_SIZE;
155
156        /* ESCI pad configuration */
157        SIU.PCR [89].R = 0x400;
158        SIU.PCR [90].R = 0x400;
159
160        DEBUG_PRINT( "BSP start ...\n");
161
162        DEBUG_PRINT( "System clock          : %i\n", mpc55xx_get_system_clock());
163        DEBUG_PRINT( "Memory start          : 0x%08x\n", bsp_ram_start);
164        DEBUG_PRINT( "Memory end            : 0x%08x\n", bsp_ram_end);
165        DEBUG_PRINT( "Memory size           : 0x%08x\n", bsp_ram_end - bsp_ram_start);
166        DEBUG_PRINT( "Interrupt stack start : 0x%08x\n", interrupt_stack_start);
167        DEBUG_PRINT( "Interrupt stack end   : 0x%08x\n", interrupt_stack_start + interrupt_stack_size);
168        DEBUG_PRINT( "Interrupt stack size  : 0x%08x\n", interrupt_stack_size);
169       
170        /*
171         * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
172         * function store the result in global variables so that it can be used
173         * latter...
174         */
175        myCpu = get_ppc_cpu_type();
176        myCpuRevision = get_ppc_cpu_revision();
177       
178        /* Time reference value */
179        bsp_clicks_per_usec = bsp_clock_speed / 1000000;
180
181        /* Initialize External Bus Interface */
182        mpc55xx_ebi_init();
183       
184        /* Initialize exceptions */
185        DEBUG_PRINT( "Initialize exceptions ...\n");
186        ppc_exc_initialize(
187          PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
188          interrupt_stack_start,
189          interrupt_stack_size
190        );
191        DEBUG_DONE();
192
193        /* Initialize interrupts */
194        DEBUG_PRINT( "Initialize interrupts ...\n");
195        if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
196                BSP_panic( "Cannot initialize interrupts");
197        } else {
198                DEBUG_DONE();
199        }
200       
201        DEBUG_PRINT( "BSP start done\n");
202
203        return;
204
205        /* TODO */
206        /*
207        * Enable instruction and data caches. Do not force writethrough mode.
208        */
209#if INSTRUCTION_CACHE_ENABLE
210        rtems_cache_enable_instruction();
211#endif
212#if DATA_CACHE_ENABLE
213        rtems_cache_enable_data();
214#endif
215}
216
217/**
218 * @brief Idle thread body.
219 */
220Thread _Thread_Idle_body( uint32_t ignored)
221{
222
223        while (1) {
224                asm volatile(
225                        "mfmsr 3;"
226                        "oris 3,3,4;"
227                        "sync;"
228                        "mtmsr 3;"
229                        "isync;"
230                        "ori 3,3,0;"
231                        "ori 3,3,0"
232                );
233        }
234        return 0;
235}
Note: See TracBrowser for help on using the repository browser.