1 /***************************************************************************//**
2 * \file cybt_platform_freertos.c
3 *
4 * \brief
5 * Implementation for BT porting interface on FreeRTOS
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2018-2019 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 *     http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include "cybt_platform_interface.h"
28 #include "cybt_platform_trace.h"
29 #include "cybt_platform_config.h"
30 
31 #ifdef ENABLE_DEBUG_UART
32 #include "cybt_debug_uart.h"
33 #endif // ENABLE_DEBUG_UART
34 
35 /******************************************************************************
36  *                                Constants
37  ******************************************************************************/
38 
39 
40 /*****************************************************************************
41  *                           Type Definitions
42  *****************************************************************************/
43 
44 
45 /******************************************************************************
46  *                           Variables Definitions
47  ******************************************************************************/
48 
49 
50 
51 /******************************************************************************
52  *                          Function Declarations
53  ******************************************************************************/
54 extern void cybt_platform_stack_timer_init(void);
55 extern void cybt_platform_stack_timer_deinit(void);
56 
57 /******************************************************************************
58  *                           Function Definitions
59  ******************************************************************************/
cybt_platform_malloc(uint32_t req_size)60 void *cybt_platform_malloc(uint32_t req_size)
61 {
62     return malloc((size_t) req_size);
63 }
64 
cybt_platform_free(void * p_mem_block)65 void cybt_platform_free(void *p_mem_block)
66 {
67     free(p_mem_block);
68 }
69 
cybt_platform_disable_irq(void)70 void cybt_platform_disable_irq(void)
71 {
72     __disable_irq();
73 }
74 
cybt_platform_enable_irq(void)75 void cybt_platform_enable_irq(void)
76 {
77     __enable_irq();
78 }
79 
cybt_platform_init(void)80 void cybt_platform_init(void)
81 {
82     cybt_platform_stack_timer_init();
83 }
84 
cybt_platform_deinit(void)85 void cybt_platform_deinit(void)
86 {
87     MAIN_TRACE_DEBUG("cybt_platform_deinit()");
88     cybt_platform_stack_timer_deinit();
89 }
90 
cybt_platform_log_print(const char * fmt_str,...)91 void cybt_platform_log_print(const char *fmt_str, ...)
92 {
93     static char buffer[CYBT_TRACE_BUFFER_SIZE];
94     va_list ap;
95     int len;
96     cy_time_t time;
97 
98     cy_rtos_get_time(&time);
99     va_start(ap, fmt_str);
100     len = vsnprintf(buffer, CYBT_TRACE_BUFFER_SIZE, fmt_str, ap);
101     va_end(ap);
102 
103 #ifdef ENABLE_DEBUG_UART
104     cybt_debug_uart_send_trace(len, (uint8_t*)buffer);
105 #else // ENABLE_DEBUG_UART
106     UNUSED_VARIABLE(len);
107     printf("[%u] %s\r\n", (unsigned int)time, buffer);
108 #endif // ENABLE_DEBUG_UART
109 }
110