Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | /* * Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016, Freescale Semiconductor, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file Board config file */ #include <device.h> #include <init.h> #include <nanokernel.h> #include "soc.h" #include <fsl_common.h> #ifdef CONFIG_UART_K20 #include <uart.h> #include <console/uart_console.h> #include <serial/uart_k20_priv.h> #endif /* CONFIG_UART_K20 */ /* * UART configuration */ #ifdef CONFIG_UART_K20 #if defined(CONFIG_UART_CONSOLE) && \ (defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)) static PORT_Type *const ports[] = PORT_BASE_PTRS; /** * @brief Initialize K20 serial port as console * * Initialize the UART port for console I/O. * * @param dev The UART device struct * * @return 0 if successful, otherwise failed. */ static ALWAYS_INLINE int uart_k20_console_init(void) { PORT_Type *port; uint32_t rxPin; uint32_t txPin; /* Port/pin ctrl module */ port = ports[CONFIG_UART_CONSOLE_PORT]; /* UART0 Rx and Tx pin assignments */ rxPin = CONFIG_UART_CONSOLE_PORT_RX_PIN; txPin = CONFIG_UART_CONSOLE_PORT_TX_PIN; /* Enable the UART Rx and Tx Pins */ port->PCR[rxPin] = PORT_PCR_MUX(CONFIG_UART_CONSOLE_PORT_MUX_FUNC); port->PCR[txPin] = PORT_PCR_MUX(CONFIG_UART_CONSOLE_PORT_MUX_FUNC); return 0; } #else #define uart_k20_console_init(...) #endif /* CONFIG_UART_CONSOLE && (CONFIG_PRINTK || CONFIG_STDOUT_CONSOLE) */ static int uart_k20_init(struct device *dev) { uint32_t scgc4; ARG_UNUSED(dev); /* Although it is possible to modify the bits through * *sim directly, the following code saves about 20 bytes * of ROM space, compared to direct modification. */ scgc4 = SIM->SCGC4; #ifdef CONFIG_UART_K20_PORT_0 scgc4 |= SIM_SCGC4_UART0(1); #endif #ifdef CONFIG_UART_K20_PORT_1 scgc4 |= SIM_SCGC4_UART1(1); #endif #ifdef CONFIG_UART_K20_PORT_2 scgc4 |= SIM_SCGC4_UART2(1); #endif #ifdef CONFIG_UART_K20_PORT_3 scgc4 |= SIM_SCGC4_UART3(1); #endif SIM->SCGC4 = scgc4; #ifdef CONFIG_UART_K20_PORT_4 SIM->SCGC1 |= SIM_SCGC1_UART4(1); #endif /* Initialize UART port for console if needed */ uart_k20_console_init(); return 0; } DEVICE_INIT(_uart_k20_init, "", uart_k20_init, NULL, NULL, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif /* CONFIG_UART_K20 */ |