1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSBSPsPowerPCMPC55XX |
---|
7 | * |
---|
8 | * @brief BSP startup code. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (C) 2008, 2013 embedded brains GmbH & Co. KG |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions |
---|
16 | * are met: |
---|
17 | * 1. Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer in the |
---|
21 | * documentation and/or other materials provided with the distribution. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
33 | * POSSIBILITY OF SUCH DAMAGE. |
---|
34 | */ |
---|
35 | |
---|
36 | #include <mpc55xx/mpc55xx.h> |
---|
37 | #include <mpc55xx/regs.h> |
---|
38 | #include <mpc55xx/edma.h> |
---|
39 | #include <mpc55xx/emios.h> |
---|
40 | |
---|
41 | #include <string.h> |
---|
42 | |
---|
43 | #include <rtems.h> |
---|
44 | #include <rtems/config.h> |
---|
45 | #include <rtems/counter.h> |
---|
46 | |
---|
47 | #include <libcpu/powerpc-utility.h> |
---|
48 | #include <bsp/vectors.h> |
---|
49 | |
---|
50 | #include <bsp.h> |
---|
51 | #include <bsp/bootcard.h> |
---|
52 | #include <bsp/irq.h> |
---|
53 | #include <bsp/irq-generic.h> |
---|
54 | #include <bsp/linker-symbols.h> |
---|
55 | #include <bsp/start.h> |
---|
56 | #include <bsp/mpc55xx-config.h> |
---|
57 | |
---|
58 | /* Symbols defined in linker command file */ |
---|
59 | LINKER_SYMBOL(mpc55xx_exc_vector_base); |
---|
60 | |
---|
61 | unsigned int bsp_clock_speed = 0; |
---|
62 | |
---|
63 | uint32_t bsp_clicks_per_usec = 0; |
---|
64 | |
---|
65 | static void null_pointer_protection(void) |
---|
66 | { |
---|
67 | #ifdef MPC55XX_NULL_POINTER_PROTECTION |
---|
68 | struct MMU_tag mmu = { .MAS0 = { .B = { .TLBSEL = 1, .ESEL = 1 } } }; |
---|
69 | |
---|
70 | PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS0, mmu.MAS0.R); |
---|
71 | __asm__ volatile ("tlbre"); |
---|
72 | PPC_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, mmu.MAS1.R); |
---|
73 | mmu.MAS1.B.VALID = 0; |
---|
74 | PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, mmu.MAS1.R); |
---|
75 | __asm__ volatile ("tlbwe"); |
---|
76 | #endif |
---|
77 | } |
---|
78 | |
---|
79 | uint32_t _CPU_Counter_frequency(void) |
---|
80 | { |
---|
81 | return bsp_clock_speed; |
---|
82 | } |
---|
83 | |
---|
84 | void bsp_start(void) |
---|
85 | { |
---|
86 | null_pointer_protection(); |
---|
87 | |
---|
88 | /* |
---|
89 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
90 | * function store the result in global variables so that it can be used |
---|
91 | * latter... |
---|
92 | */ |
---|
93 | get_ppc_cpu_type(); |
---|
94 | get_ppc_cpu_revision(); |
---|
95 | |
---|
96 | /* |
---|
97 | * determine clock speed |
---|
98 | */ |
---|
99 | bsp_clock_speed = mpc55xx_get_system_clock() / MPC55XX_SYSTEM_CLOCK_DIVIDER; |
---|
100 | |
---|
101 | /* Time reference value */ |
---|
102 | bsp_clicks_per_usec = bsp_clock_speed / 1000000; |
---|
103 | |
---|
104 | ppc_exc_initialize_with_vector_base( |
---|
105 | (uintptr_t) _ISR_Stack_area_begin, |
---|
106 | mpc55xx_exc_vector_base |
---|
107 | ); |
---|
108 | bsp_interrupt_initialize(); |
---|
109 | |
---|
110 | #if MPC55XX_CHIP_FAMILY != 566 |
---|
111 | mpc55xx_edma_init(); |
---|
112 | #endif |
---|
113 | |
---|
114 | #ifdef MPC55XX_EMIOS_PRESCALER |
---|
115 | mpc55xx_emios_initialize(MPC55XX_EMIOS_PRESCALER); |
---|
116 | #endif |
---|
117 | } |
---|