Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:56

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsPowerPCMPC55XX
0007  *
0008  * @brief BSP startup code.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2008, 2013 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <mpc55xx/mpc55xx.h>
0037 #include <mpc55xx/regs.h>
0038 #include <mpc55xx/edma.h>
0039 #include <mpc55xx/emios.h>
0040 
0041 #include <string.h>
0042 
0043 #include <rtems.h>
0044 #include <rtems/config.h>
0045 #include <rtems/counter.h>
0046 
0047 #include <libcpu/powerpc-utility.h>
0048 #include <bsp/vectors.h>
0049 
0050 #include <bsp.h>
0051 #include <bsp/bootcard.h>
0052 #include <bsp/irq.h>
0053 #include <bsp/irq-generic.h>
0054 #include <bsp/linker-symbols.h>
0055 #include <bsp/start.h>
0056 #include <bsp/mpc55xx-config.h>
0057 
0058 /* Symbols defined in linker command file */
0059 LINKER_SYMBOL(mpc55xx_exc_vector_base);
0060 
0061 unsigned int bsp_clock_speed = 0;
0062 
0063 uint32_t bsp_clicks_per_usec = 0;
0064 
0065 static void null_pointer_protection(void)
0066 {
0067 #ifdef MPC55XX_NULL_POINTER_PROTECTION
0068     struct MMU_tag mmu = { .MAS0 = { .B = { .TLBSEL = 1, .ESEL = 1 } } };
0069 
0070     PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS0, mmu.MAS0.R);
0071     __asm__ volatile ("tlbre");
0072     PPC_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, mmu.MAS1.R);
0073     mmu.MAS1.B.VALID = 0;
0074     PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, mmu.MAS1.R);
0075     __asm__ volatile ("tlbwe");
0076 #endif
0077 }
0078 
0079 uint32_t _CPU_Counter_frequency(void)
0080 {
0081     return bsp_clock_speed;
0082 }
0083 
0084 void bsp_start(void)
0085 {
0086     null_pointer_protection();
0087 
0088     /*
0089      * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
0090      * function store the result in global variables so that it can be used
0091      * latter...
0092      */
0093     get_ppc_cpu_type();
0094     get_ppc_cpu_revision();
0095 
0096     /*
0097      * determine clock speed
0098      */
0099     bsp_clock_speed = mpc55xx_get_system_clock() / MPC55XX_SYSTEM_CLOCK_DIVIDER;
0100 
0101     /* Time reference value */
0102     bsp_clicks_per_usec = bsp_clock_speed / 1000000;
0103 
0104     ppc_exc_initialize_with_vector_base(
0105         (uintptr_t) _ISR_Stack_area_begin,
0106         mpc55xx_exc_vector_base
0107     );
0108     bsp_interrupt_initialize();
0109 
0110     #if MPC55XX_CHIP_FAMILY != 566
0111         mpc55xx_edma_init();
0112     #endif
0113 
0114     #ifdef MPC55XX_EMIOS_PRESCALER
0115         mpc55xx_emios_initialize(MPC55XX_EMIOS_PRESCALER);
0116     #endif
0117 }