blob: 0a6a1b3a00e7637288a40a6d6e18534a96247843 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include "system_init.h"
18
19#include "uart_stdout.h"
20
21#include <string.h>
22
23#if defined(MPS3_PLATFORM)
24#define CREATE_MASK(msb, lsb) (((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
25#define MASK_BITS(arg, msb, lsb) ((arg) & CREATE_MASK(msb, lsb))
26#define EXTRACT_BITS(arg, msb, lsb) (MASK_BITS(arg, msb, lsb) >> (lsb))
27#endif /* MPS3_PLATFORM */
28
29int system_init(void)
30{
31#if defined(MPS3_PLATFORM)
32 uint32_t id = 0;
33 uint32_t fpgaid = 0;
34 uint32_t apnote = 0;
35 uint32_t rev = 0;
36 uint32_t aid = 0;
37 uint32_t fpga_clk = 0;
38
39 /* Initialise the LEDs as the switches are */
40 MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF;
41#endif
42
43 /* UART init - will enable valid use of printf (stdout
44 * re-directed at this UART (UART0) */
45 UartStdOutInit();
46 info("Processor internal clock: %u Hz\n", GetSystemCoreClock());
47
48#if defined(MPS3_PLATFORM)
49 /* Get revision information from various registers */
50 rev = MPS3_SCC->CFG_REG4;
51 fpgaid = MPS3_SCC->SCC_ID;
52 aid = MPS3_SCC->SCC_AID;
53 apnote = EXTRACT_BITS(fpgaid, 15, 4);
54 fpga_clk = GetMPS3CoreClock();
55
56 info("V2M-MPS3 revision %c\n\n", rev + 'A');
57 info("Application Note AN%x, Revision %c\n", apnote,
58 EXTRACT_BITS(aid, 23, 20) + 'A');
59 info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24));
60 info("MPS3 core clock has been set to: %d Hz\n", fpga_clk);
61
62 /* Display CPU ID */
63 id = SCB->CPUID;
64 info("CPU ID: 0x%08x\n", id);
65
66 if(EXTRACT_BITS(id, 15, 8) == 0xD2) {
67 if (EXTRACT_BITS(id, 7, 4) == 2) {
68 info ("CPU: Cortex-M55 r%dp%d\n\n",
69 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
70#if defined (CPU_CORTEX_M55)
71 /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */
72 return 0;
73#endif /* CPU_CORTEX_M55 */
74 } else if (EXTRACT_BITS(id, 7, 4) == 1) {
75 info ("CPU: Cortex-M33 r%dp%d\n\n",
76 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
77#if defined (CPU_CORTEX_M33)
78 return 0;
79#endif /* CPU_CORTEX_M33 */
80 } else if (EXTRACT_BITS(id, 7, 4) == 0) {
81 info ("CPU: Cortex-M23 r%dp%d\n\n",
82 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
83 } else {
84 info ("CPU: Cortex-M processor family");
85 }
86 } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) {
87 info ("CPU: Cortex-M%d+ r%dp%d\n\n",
88 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
89 EXTRACT_BITS(id, 3, 0));
90 } else {
91 info ("CPU: Cortex-M%d r%dp%d\n\n",
92 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
93 EXTRACT_BITS(id, 3, 0));
94 }
95#else /* MPS3_PLATFORM */
96
97 info("ARM model environment ready..\n");
98 return 0;
99#endif /* MPS3_PLATFORM */
100
101 /* If the CPU is anything other than M33 or M55, we return 1 */
102 printf_err("CPU mismatch!\n");
103 return 1;
104}
105
106void system_release(void)
107{
108 __disable_irq();
109}
110
111void system_name(char* name, size_t size)
112{
113#if defined (MPS3_PLATFORM)
114 strncpy(name, "mps3-bare", size);
115#else /* MPS3_PLATFORM */
116 strncpy(name, "FVP", size);
117#endif /* MPS3_PLATFORM */
118}