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

4.104.114.95
Last change on this file since d4886a06 was d4886a06, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/24/08 at 14:52:55

Changed bsp_get_workarea() to bsp_get_work_area() and
added support for an optional separate heap area.

  • Property mode set to 100644
File size: 5.1 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_pretasking_hook()
91{
92#ifdef STACK_CHECKER_ON
93        Stack_check_Initialize();
94#endif
95}
96
97void bsp_predriver_hook()
98{
99        rtems_status_code sc = RTEMS_SUCCESSFUL;
100
101        DEBUG_PRINT( "Initialize eDMA ...\n");
102        sc = mpc55xx_edma_init();
103        if (sc != RTEMS_SUCCESSFUL) {
104                BSP_panic( "Cannot initialize eDMA");
105        } else {
106                DEBUG_DONE();
107        }
108}
109
110static void mpc55xx_ebi_init()
111{
112        struct EBI_CS_tag cs = { BR : MPC55XX_ZERO_FLAGS, OR : MPC55XX_ZERO_FLAGS };
113        union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS;
114        int i = 0;
115
116        /* External SRAM (0 wait states, 512kB, 4 word burst) */
117        cs.BR.B.BA = 0;
118        cs.BR.B.PS = 1;
119        cs.BR.B.BL = 1;
120        cs.BR.B.WEBS = 0;
121        cs.BR.B.TBDIP = 0;
122        cs.BR.B.BI = 1; /* TODO: Enable burst */
123        cs.BR.B.V = 1;
124
125        cs.OR.B.AM = 0x1fff0;
126        cs.OR.B.SCY = 0;
127        cs.OR.B.BSCY = 0;
128
129        EBI.CS [0] = cs;
130
131        /* !CS [0] */
132        SIU.PCR [0].R = 0x443;
133
134        /* ADDR [8 : 31] */
135        for (i = 4; i < 4 + 24; ++i) {
136                SIU.PCR [i].R = 0x440;
137        }
138
139        /* DATA [0 : 15] */
140        for (i = 28; i < 28 + 16; ++i) {
141                SIU.PCR [i].R = 0x440;
142        }
143
144        /* RD_!WR */
145        SIU.PCR [62].R = 0x443;
146
147        /* !BDIP */
148        SIU.PCR [63].R = 0x443;
149
150        /* !WE [0 : 3] */
151        for (i = 64; i < 64 + 4; ++i) {
152                SIU.PCR [i].R = 0x443;
153        }
154
155        /* !OE */
156        SIU.PCR [68].R = 0x443;
157
158        /* !TS */
159        SIU.PCR [69].R = 0x443;
160}
161
162/**
163 * @brief Start BSP.
164 */
165void bsp_start(void)
166{
167        ppc_cpu_id_t myCpu;
168        ppc_cpu_revision_t myCpuRevision;
169
170        uint32_t interrupt_stack_start = bsp_ram_end - 2 * MPC55XX_INTERRUPT_STACK_SIZE;
171        uint32_t interrupt_stack_size = MPC55XX_INTERRUPT_STACK_SIZE;
172
173        /* ESCI pad configuration */
174        SIU.PCR [89].R = 0x400;
175        SIU.PCR [90].R = 0x400;
176
177        DEBUG_PRINT( "BSP start ...\n");
178
179        DEBUG_PRINT( "System clock          : %i\n", mpc55xx_get_system_clock());
180        DEBUG_PRINT( "Memory start          : 0x%08x\n", bsp_ram_start);
181        DEBUG_PRINT( "Memory end            : 0x%08x\n", bsp_ram_end);
182        DEBUG_PRINT( "Memory size           : 0x%08x\n", bsp_ram_end - bsp_ram_start);
183        DEBUG_PRINT( "Interrupt stack start : 0x%08x\n", interrupt_stack_start);
184        DEBUG_PRINT( "Interrupt stack end   : 0x%08x\n", interrupt_stack_start + interrupt_stack_size);
185        DEBUG_PRINT( "Interrupt stack size  : 0x%08x\n", interrupt_stack_size);
186       
187        /*
188         * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
189         * function store the result in global variables so that it can be used
190         * latter...
191         */
192        myCpu = get_ppc_cpu_type();
193        myCpuRevision = get_ppc_cpu_revision();
194       
195        /* Time reference value */
196        bsp_clicks_per_usec = bsp_clock_speed / 1000000;
197
198        /* Initialize External Bus Interface */
199        mpc55xx_ebi_init();
200       
201        /* Initialize exceptions */
202        DEBUG_PRINT( "Initialize exceptions ...\n");
203        ppc_exc_initialize( PPC_INTERRUPT_DISABLE_MASK_DEFAULT, interrupt_stack_start, interrupt_stack_size);
204        DEBUG_DONE();
205
206        /* Initialize interrupts */
207        DEBUG_PRINT( "Initialize interrupts ...\n");
208        if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
209                BSP_panic( "Cannot initialize interrupts");
210        } else {
211                DEBUG_DONE();
212        }
213       
214        DEBUG_PRINT( "BSP start done\n");
215
216        return;
217
218        /* TODO */
219        /*
220        * Enable instruction and data caches. Do not force writethrough mode.
221        */
222#if INSTRUCTION_CACHE_ENABLE
223        rtems_cache_enable_instruction();
224#endif
225#if DATA_CACHE_ENABLE
226        rtems_cache_enable_data();
227#endif
228}
229
230/**
231 * @brief Idle thread body.
232 */
233Thread _Thread_Idle_body( uint32_t ignored)
234{
235
236        while (1) {
237                asm volatile(
238                        "mfmsr 3;"
239                        "oris 3,3,4;"
240                        "sync;"
241                        "mtmsr 3;"
242                        "isync;"
243                        "ori 3,3,0;"
244                        "ori 3,3,0"
245                );
246        }
247        return 0;
248}
Note: See TracBrowser for help on using the repository browser.