alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 22 | #include <inttypes.h> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 23 | |
| 24 | #if defined(MPS3_PLATFORM) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 25 | #define CREATE_MASK(msb, lsb) (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb)) |
| 26 | #define MASK_BITS(arg, msb, lsb) (int)((arg) & CREATE_MASK(msb, lsb)) |
| 27 | #define EXTRACT_BITS(arg, msb, lsb) (int)(MASK_BITS(arg, msb, lsb) >> (lsb)) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 28 | #endif /* MPS3_PLATFORM */ |
| 29 | |
| 30 | int system_init(void) |
| 31 | { |
| 32 | #if defined(MPS3_PLATFORM) |
| 33 | uint32_t id = 0; |
| 34 | uint32_t fpgaid = 0; |
| 35 | uint32_t apnote = 0; |
| 36 | uint32_t rev = 0; |
| 37 | uint32_t aid = 0; |
| 38 | uint32_t fpga_clk = 0; |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 39 | const uint32_t ascii_A = (uint32_t)('A'); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 40 | |
| 41 | /* Initialise the LEDs as the switches are */ |
| 42 | MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF; |
| 43 | #endif |
| 44 | |
| 45 | /* UART init - will enable valid use of printf (stdout |
| 46 | * re-directed at this UART (UART0) */ |
| 47 | UartStdOutInit(); |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 48 | info("Processor internal clock: %" PRIu32 "Hz\n", GetSystemCoreClock()); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 49 | |
| 50 | #if defined(MPS3_PLATFORM) |
| 51 | /* Get revision information from various registers */ |
| 52 | rev = MPS3_SCC->CFG_REG4; |
| 53 | fpgaid = MPS3_SCC->SCC_ID; |
| 54 | aid = MPS3_SCC->SCC_AID; |
| 55 | apnote = EXTRACT_BITS(fpgaid, 15, 4); |
| 56 | fpga_clk = GetMPS3CoreClock(); |
| 57 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 58 | info("V2M-MPS3 revision %c\n\n", (char)(rev + ascii_A)); |
| 59 | info("Application Note AN%" PRIx32 ", Revision %c\n", apnote, |
| 60 | (char)(EXTRACT_BITS(aid, 23, 20) + ascii_A)); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 61 | info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24)); |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 62 | info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 63 | |
| 64 | /* Display CPU ID */ |
| 65 | id = SCB->CPUID; |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 66 | info("CPU ID: 0x%08" PRIx32 "\n", id); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 67 | |
| 68 | if(EXTRACT_BITS(id, 15, 8) == 0xD2) { |
| 69 | if (EXTRACT_BITS(id, 7, 4) == 2) { |
| 70 | info ("CPU: Cortex-M55 r%dp%d\n\n", |
| 71 | EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0)); |
| 72 | #if defined (CPU_CORTEX_M55) |
| 73 | /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */ |
| 74 | return 0; |
| 75 | #endif /* CPU_CORTEX_M55 */ |
| 76 | } else if (EXTRACT_BITS(id, 7, 4) == 1) { |
| 77 | info ("CPU: Cortex-M33 r%dp%d\n\n", |
| 78 | EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0)); |
| 79 | #if defined (CPU_CORTEX_M33) |
| 80 | return 0; |
| 81 | #endif /* CPU_CORTEX_M33 */ |
| 82 | } else if (EXTRACT_BITS(id, 7, 4) == 0) { |
| 83 | info ("CPU: Cortex-M23 r%dp%d\n\n", |
| 84 | EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0)); |
| 85 | } else { |
| 86 | info ("CPU: Cortex-M processor family"); |
| 87 | } |
| 88 | } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) { |
| 89 | info ("CPU: Cortex-M%d+ r%dp%d\n\n", |
| 90 | EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20), |
| 91 | EXTRACT_BITS(id, 3, 0)); |
| 92 | } else { |
| 93 | info ("CPU: Cortex-M%d r%dp%d\n\n", |
| 94 | EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20), |
| 95 | EXTRACT_BITS(id, 3, 0)); |
| 96 | } |
| 97 | #else /* MPS3_PLATFORM */ |
| 98 | |
| 99 | info("ARM model environment ready..\n"); |
| 100 | return 0; |
| 101 | #endif /* MPS3_PLATFORM */ |
| 102 | |
| 103 | /* If the CPU is anything other than M33 or M55, we return 1 */ |
| 104 | printf_err("CPU mismatch!\n"); |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | void system_release(void) |
| 109 | { |
| 110 | __disable_irq(); |
| 111 | } |
| 112 | |
| 113 | void system_name(char* name, size_t size) |
| 114 | { |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 115 | strncpy(name, DESIGN_NAME, size); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 116 | } |