1 /* 2 * Copyright (c) 2018 omSquare s.r.o. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/irq.h> 9 #include <zephyr/init.h> 10 #include "SEGGER_RTT.h" 11 12 /* 13 * Common mutex for locking access to terminal buffer. 14 * Note that SEGGER uses same lock macros for both SEGGER_RTT_Write and 15 * SEGGER_RTT_Read functions. Because of this we are not able generally 16 * separate up and down access using two mutexes until SEGGER library fix 17 * this. 18 * 19 * If sharing access cause performance problems, consider using another 20 * non terminal buffers. 21 */ 22 23 K_MUTEX_DEFINE(rtt_term_mutex); 24 rtt_init(void)25static int rtt_init(void) 26 { 27 28 SEGGER_RTT_Init(); 29 30 return 0; 31 } 32 33 #ifdef CONFIG_MULTITHREADING 34 zephyr_rtt_mutex_lock(void)35void zephyr_rtt_mutex_lock(void) 36 { 37 k_mutex_lock(&rtt_term_mutex, K_FOREVER); 38 } 39 zephyr_rtt_mutex_unlock(void)40void zephyr_rtt_mutex_unlock(void) 41 { 42 k_mutex_unlock(&rtt_term_mutex); 43 } 44 45 #endif /* CONFIG_MULTITHREADING */ 46 zephyr_rtt_irq_lock(void)47unsigned int zephyr_rtt_irq_lock(void) 48 { 49 return irq_lock(); 50 } 51 zephyr_rtt_irq_unlock(unsigned int key)52void zephyr_rtt_irq_unlock(unsigned int key) 53 { 54 irq_unlock(key); 55 } 56 57 58 59 SYS_INIT(rtt_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS); 60