1 /*******************************************************************************
2 * \file cybt_platform_task.c
3 *
4 * \brief
5 * Provides functions for OS task communication.
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 "cyabs_rtos.h"
25 #include "cybt_platform_config.h"
26 #include "cybt_platform_task.h"
27 #include "cybt_platform_interface.h"
28 #include "cybt_platform_util.h"
29 #include "cybt_platform_trace.h"
30 
31 /******************************************************************************
32  *                                Constants
33  ******************************************************************************/
34 #define NOT_IN_ISR             (false)
35 #define IN_ISR                 (true)
36 
37 /******************************************************************************
38  *                          Function Declarations
39  ******************************************************************************/
40 #ifdef ENABLE_DEBUG_UART
41 extern cybt_result_t cybt_init_debug_trans_task(void);
42 #endif // ENABLE_DEBUG_UART
43 extern cybt_result_t cybt_platform_msg_to_bt_task(const uint16_t msg, bool is_from_isr);
44 extern cybt_result_t cybt_bttask_init(void*);
45 extern void cybt_bttask_deinit(void);
46 
47 /******************************************************************************
48  *                           Function Definitions
49  ******************************************************************************/
cybt_platform_task_init(void * p_arg)50 cybt_result_t cybt_platform_task_init(void *p_arg)
51 {
52     cybt_result_t task_result;
53 
54     task_result = cybt_bttask_init(p_arg);
55     if(CYBT_SUCCESS != task_result)
56         return task_result;
57 
58 #ifdef ENABLE_DEBUG_UART
59     cybt_init_debug_trans_task();
60 #endif // ENABLE_DEBUG_UART
61     return CYBT_SUCCESS;
62 }
63 
cybt_platform_task_deinit(void)64 cybt_result_t cybt_platform_task_deinit(void)
65 {
66     cy_rslt_t result;
67 
68     MAIN_TRACE_DEBUG("cybt_platform_task_deinit()");
69 
70     result = cybt_platform_msg_to_bt_task(BT_EVT_TASK_SHUTDOWN, NOT_IN_ISR);
71 
72     if(CY_RSLT_SUCCESS != result)
73     {
74         MAIN_TRACE_ERROR("task_deinit(): send queue failure (0x%x)", result);
75         return CYBT_ERR_SEND_QUEUE_FAILED;
76     }
77 
78     cybt_bttask_deinit();
79 
80     return CYBT_SUCCESS;
81 }
82