1 /*
2  * Copyright 2020 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  */
9 
10 #include "fsl_common.h"
11 
12 #include "fsl_component_log.h"
13 #include "fsl_debug_console.h"
14 
15 #include "fsl_component_log_backend_debugconsole.h"
16 
17 /*******************************************************************************
18  * Prototypes
19  ******************************************************************************/
20 
21 static void log_init_backend_debugconsole_puts(uint8_t *buffer, size_t length);
22 
23 /*******************************************************************************
24  * Variables
25  ******************************************************************************/
26 
27 static uint8_t initialized;
28 
29 LOG_BACKEND_DEFINE(backend_debug_console, log_init_backend_debugconsole_puts);
30 
31 /*******************************************************************************
32  * Code
33  ******************************************************************************/
34 
log_init_backend_debugconsole_puts(uint8_t * buffer,size_t length)35 static void log_init_backend_debugconsole_puts(uint8_t *buffer, size_t length)
36 {
37     if ((0U == initialized) || (0U == length))
38     {
39         return;
40     }
41 
42     for (size_t i = 0; i < length; i++)
43     {
44         (void)PUTCHAR((int)buffer[i]);
45     }
46 }
47 
LOG_InitBackendDebugconsole(void)48 void LOG_InitBackendDebugconsole(void)
49 {
50     log_status_t ret;
51     if (initialized > 0U)
52     {
53         return;
54     }
55 
56     ret = LOG_BackendRegister(&backend_debug_console);
57     if (kStatus_LOG_Success == ret)
58     {
59         initialized = 1U;
60     }
61     assert(kStatus_LOG_Success == ret);
62     return;
63 }
64 
LOG_DeinitBackendDebugconsole(void)65 void LOG_DeinitBackendDebugconsole(void)
66 {
67     log_status_t ret;
68 
69     ret = LOG_BackendUnregister(&backend_debug_console);
70     if (kStatus_LOG_Success == ret)
71     {
72         initialized = 0U;
73     }
74     assert(kStatus_LOG_Success == ret);
75     return;
76 }
77