1 /******************************************************************************* 2 * \file cybt_platform_interface.h 3 * 4 * \brief 5 * Defines the Cypress BT platform porting Interface. Include all interface header 6 * and provides prototypes for functions that are used in Cypress WICED Bluetooth 7 * library. Functions which are required to be ported are defined 8 * in cybt_platform_sample.c file. 9 * 10 ******************************************************************************** 11 * \copyright 12 * Copyright 2018-2019 Cypress Semiconductor Corporation 13 * SPDX-License-Identifier: Apache-2.0 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 *******************************************************************************/ 27 28 #ifndef CYBT_PLATFORM_INTERFACE_H 29 #define CYBT_PLATFORM_INTERFACE_H 30 31 #include "cybt_result.h" 32 33 /** 34 * RTOS interface, including task, mutex, semaphore, queue and timer. 35 */ 36 #include "cyabs_rtos.h" 37 38 39 /** 40 * GPIO interface which is related to pin control of BT chip. 41 */ 42 #include "cyhal_gpio.h" 43 44 45 /** 46 * BT HCI transport interface, which is used to communicate with 47 * BT controller. 48 */ 49 #include "cybt_platform_hci.h" 50 51 52 /** 53 * Timer interface which supports timeout notification to BT stack. 54 */ 55 #include "cyhal_lptimer.h" 56 57 #include "cybt_platform_config.h" 58 59 60 /****************************************************************************** 61 * Constants 62 ******************************************************************************/ 63 #ifdef ENABLE_DEBUG_UART 64 #define CYBT_TRACE_BUFFER_SIZE (256) 65 #else 66 #define CYBT_TRACE_BUFFER_SIZE (128) 67 #endif //ENABLE_DEBUG_UART 68 69 70 /** Define start of the function placed to the SRAM area by the linker */ 71 #if defined(__ARMCC_VERSION) 72 /** To create cross compiler compatible code, use the CY_NOINIT, CY_SECTION, CY_UNUSED, CY_ALIGN 73 * attributes at the first place of declaration/definition. 74 * For example: CY_NOINIT uint32_t noinitVar; 75 */ 76 #define BTSTACK_PORTING_SECTION_BEGIN __attribute__((section(".text.cy_btstack_porting"))) 77 #define BTSTACK_PORTING_SECTION_END 78 79 #elif defined(__ICCARM__) 80 #define BTSTACK_PORTING_SECTION_BEGIN _Pragma("default_function_attributes = @\".text.cy_btstack_porting\"") 81 #define BTSTACK_PORTING_SECTION_END _Pragma("default_function_attributes = ") 82 #elif defined(__GNUC__) 83 #if defined(__clang__) 84 #define BTSTACK_PORTING_SECTION_BEGIN __attribute__((section("__DATA, .text.cy_btstack_porting"))) 85 #define BTSTACK_PORTING_SECTION_END 86 #else 87 #define BTSTACK_PORTING_SECTION_BEGIN __attribute__((section(".text.cy_btstack_porting"))) 88 #define BTSTACK_PORTING_SECTION_END 89 #endif 90 #else // if defined(__ARMCC_VERSION) 91 #define BTSTACK_PORTING_SECTION_BEGIN 92 #define BTSTACK_PORTING_SECTION_END 93 #endif // (__ARMCC_VERSION) 94 95 96 #ifdef __cplusplus 97 extern "C" 98 { 99 #endif 100 101 /***************************************************************************** 102 * Function Declarations 103 *****************************************************************************/ 104 105 /** 106 * The first platform-port function to be invoked. Initialization for 107 * everything (e.g. os components, peripheral driver, timer, etc.) can 108 * be put inside this function. 109 * 110 * @returns void 111 */ 112 void cybt_platform_init(void); 113 114 115 /** 116 * The platform-port function which is used to de-initialization all 117 * the components (e.g. os components, peripheral driver, timer, etc.) which 118 * had been intialized for Bluetooth. 119 * It will be invoked when BT stack shutdown API is called. 120 * 121 * @returns void 122 */ 123 void cybt_platform_deinit(void); 124 125 126 /** 127 * Get memory via OS malloc function. 128 * 129 * @param[in] req_size: the requested size of memory 130 * 131 * @returns the pointer of memory block 132 */ 133 void *cybt_platform_malloc(uint32_t req_size); 134 135 136 /** 137 * Return memory to OS via OS free function. 138 * 139 * @param[in] p_mem_block: the pointer of memory block which was allocated 140 * by cybt_platform_malloc() function. 141 * 142 * @return void 143 */ 144 void cybt_platform_free(void *p_mem_block); 145 146 147 /** 148 * Disable system interrupt. 149 * 150 * @return void 151 */ 152 void cybt_platform_disable_irq(void); 153 154 155 /** 156 * Enable system interrupt. 157 * 158 * @return void 159 */ 160 void cybt_platform_enable_irq(void); 161 162 163 /** 164 * Log printing function. It will be invoked whenever stack has log output. 165 * In this function these logs can be forwarded to UART, log task, file system, 166 * or somewhere else, depends on the implementation. 167 * 168 * @param[in] fmt_str : output trace string 169 * 170 * @return void 171 */ 172 void cybt_platform_log_print(const char *fmt_str, ...); 173 174 175 /** 176 * This function is used by BT stack to get current tick count. 177 * The unit is micro-second. 178 * 179 * @return the current tick count in micro-second 180 */ 181 uint64_t cybt_platform_get_tick_count_us(void); 182 183 184 /** 185 * This function is used by BT stack to set next timeout in absolute tick 186 * count in micro-second. 187 * 188 * @param[in] abs_tick_us_to_expire: absolute tick count in micro-second to be expired 189 * 190 * @return 191 */ 192 void cybt_platform_set_next_timeout(uint64_t abs_tick_us_to_expire); 193 194 #if (defined(BTSTACK_VER) && (BTSTACK_VER >= 0x03080000)) 195 /** 196 * Call back to the application in the BT stack context 197 * 198 * @param[in] void 199 * 200 * @returns void 201 */ 202 void cybt_call_app_in_stack_context(void); 203 #endif // BTSTACK_VER 204 205 #ifdef __cplusplus 206 } /* extern "C" */ 207 #endif 208 209 #endif 210 211