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

4.104.114.95
Last change on this file since e6233d25 was 0cb39e8, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/08 at 20:27:31

2008-08-30 Joel Sherrill <joel.sherrill@…>

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