1 /***************************************************************************//**
2 * \file cy_ble_controller.c
3 * \version 3.60
4 *
5 * \brief
6 *  This file contains the source code for the API of the PSoC 6 BLE Middleware.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2017-2021, Cypress Semiconductor Corporation.  All rights reserved.
11 * You may use this file only in accordance with the license, terms, conditions,
12 * disclaimers, and limitations in the end user license agreement accompanying
13 * the software package with which this file was provided.
14 *******************************************************************************/
15 #include "cy_ble_event_handler.h"
16 #include "cy_ble_hal_pvt.h"
17 #include "cy_ble.h"
18 
19 #include "cy_ble_stack_pvt.h"
20 
21 #if defined(CY_IP_MXBLESS)
22 
23 /*******************************************************************************
24 * Private Function Prototypes
25 *******************************************************************************/
26 
27 static cy_en_syspm_status_t
28     Cy_BLE_ControllerDeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams,
29                                        cy_en_syspm_callback_mode_t mode);
30 
31 
32 /*******************************************************************************
33 * Global Variables
34 *******************************************************************************/
35 
36 /** Pointer to the global BLE configuration structures */
37 static const cy_stc_ble_config_t *cy_ble_controllerConfigPtr = NULL;
38 
39 
40 /*******************************************************************************
41 * Internal Defines
42 *******************************************************************************/
43 
44 #define CY_BLE_SEND_IPC_MESSAGE_TIMEOUT                 (2000u)
45 #define CY_BLE_WAIT_CONTR_START_TIMEOUT                 (2000u)
46 
47 
48 /******************************************************************************
49 * Function Name: Cy_BLE_InitController
50 ***************************************************************************//**
51 *
52 *  Initializes the PSoC 6 BLE Middleware (controller part).
53 *
54 *  This function must used only in HCI or BLE dual CPU mode and called on CPU core,
55 *  where BLE controller is running.
56 *
57 *  \param config: The configuration structure for the PSoC 6 BLE Middleware.
58 *
59 *  \return
60 *  \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded or
61 *  failed. The following are possible error codes.
62 *
63 *   Error codes                     | Description
64 *   ------------                    | -----------
65 *   CY_BLE_SUCCESS                  | The function completed successfully.
66 *   CY_BLE_ERROR_INVALID_PARAMETER  | On specifying NULL as the input parameter.
67 *
68 ******************************************************************************/
Cy_BLE_InitController(const cy_stc_ble_config_t * config)69 cy_en_ble_api_result_t Cy_BLE_InitController(const cy_stc_ble_config_t *config)
70 {
71     cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
72 
73     if(config != NULL)
74     {
75         /* Register a pointer to the BLE controller configuration structure */
76         cy_ble_controllerConfigPtr = config;
77         Cy_BLE_HAL_SetConfigStructure(cy_ble_controllerConfigPtr);
78         apiResult = CY_BLE_SUCCESS;
79     }
80 
81     return(apiResult);
82 }
83 
84 
85 /******************************************************************************
86 * Function Name: Cy_BLE_EnableController
87 ***************************************************************************//**
88 *
89 *  This function enables the BLE Stack controller.
90 *
91 *  This function must used only in BLE dual CPU mode and called on CPU core,
92 *  where BLE controller is running.
93 *
94 *  \return
95 *  \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded
96 *       or failed. The following are possible error codes.
97 *
98 *  <table>
99 *    <tr>
100 *      <th>Error codes</th>
101 *      <th>Description</th>
102 *    </tr>
103 *    <tr>
104 *      <td>CY_BLE_SUCCESS</td>
105 *      <td>On successful operation.</td>
106 *    </tr>
107 *    <tr>
108 *      <td>CY_BLE_ERROR_REPEATED_ATTEMPTS</td>
109 *      <td>On invoking this function more than once without calling
110 *          Cy_BLE_Disable() function between calls to this function.</td>
111 *    </tr>
112 *    <tr>
113 *      <td>CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED</td>
114 *      <td>There is insufficient memory available.</td>
115 *    </tr>
116 *    <tr>
117 *      <td>CY_BLE_ERROR_INVALID_STATE</td>
118 *      <td>The PSoC 6 BLE Middleware was not initialized</td>
119 *    </tr>
120 *  </table>
121 *
122 ******************************************************************************/
Cy_BLE_EnableController(void)123 cy_en_ble_api_result_t Cy_BLE_EnableController(void)
124 {
125     cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_STATE;
126 
127 #if defined(COMPONENT_BLESS_CONTROLLER_IPC)
128     if (cy_ble_controllerConfigPtr != NULL)
129     {
130         cy_stc_ble_stack_init_info_t stackInitParam;
131        (void) memset(&stackInitParam, 0, sizeof(cy_stc_ble_stack_init_info_t));
132 
133         /* BLE Stack memory heap size */
134         stackInitParam.memParam.totalHeapSz =
135                 cy_ble_controllerConfigPtr->stackParam->controllerTotalHeapSz;
136 
137         /* Configure DLE */
138         stackInitParam.stackConfig.dleConfig.dleMaxTxCapability =
139                 cy_ble_controllerConfigPtr->stackParam->dleMaxTxCapability;
140         stackInitParam.stackConfig.dleConfig.dleMaxRxCapability =
141                 cy_ble_controllerConfigPtr->stackParam->dleMaxRxCapability;
142 
143         stackInitParam.stackConfig.dleConfig.dleNumTxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_TX_PACKETS;
144         stackInitParam.stackConfig.dleConfig.dleNumRxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_RX_PACKETS;
145 
146         /* Configure BLE Stack features */
147         stackInitParam.stackConfig.featureMask =
148                 cy_ble_controllerConfigPtr->stackParam->featureMask;
149 
150         /* Configure maximum connection support */
151         stackInitParam.stackConfig.maxBleConnections =
152                 cy_ble_controllerConfigPtr->stackParam->maxConnCount;
153 
154         /* Configure bonded device list */
155         stackInitParam.stackConfig.bondListConfig.bondListSize =
156                 cy_ble_controllerConfigPtr->stackParam->maxBondedDevListSize;
157 
158         /* Configure white list */
159         stackInitParam.stackConfig.whiteListConfig.whiteListSize =
160                 cy_ble_controllerConfigPtr->stackParam->maxWhiteListSize;
161 
162         /* Configure LL Privacy */
163         stackInitParam.stackConfig.privacyConfig.resolvingListSize =
164                 cy_ble_controllerConfigPtr->stackParam->maxResolvableDevListSize;
165 
166         /* Configure BLE features */
167         /* Enable DLE code in the stack */
168         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_DLE_FEATURE_MASK) != 0u)
169         {
170             Cy_BLE_EnableDleFeature();
171         }
172 
173         /* Enable LL Privacy code in the stack */
174         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_PRIVACY_1_2_FEATURE_MASK) != 0u)
175         {
176             Cy_BLE_EnablePrivacyFeature();
177         }
178 
179         /* Enable PHY Update code in the stack */
180         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_PHY_UPDATE_FEATURE_MASK) != 0u)
181         {
182             Cy_BLE_EnablePhyUpdateFeature();
183         }
184 
185         apiResult = Cy_BLE_StackSetFeatureConfig(&stackInitParam.stackConfig);
186 
187 
188         if(apiResult == CY_BLE_SUCCESS)
189         {
190             /* Set pointer to memory RAM buffer */
191             stackInitParam.memParam.memoryHeapPtr = cy_ble_controllerConfigPtr->stackParam->controllerMemoryHeapPtr;
192 
193             /* Configure parameter for Radio PA calibration */
194             if(cy_ble_controllerConfigPtr->stackParam->paCalConfig != NULL)
195             {
196                 stackInitParam.stackConfig.paCalConfig = *cy_ble_controllerConfigPtr->stackParam->paCalConfig;
197             }
198 
199             /* Initialize the BLE Stack */
200             apiResult = Cy_BLE_StackInit(&stackInitParam);
201         }
202     }
203 #endif /* defined(COMPONENT_BLESS_CONTROLLER_IPC) */
204     return(apiResult);
205 }
206 
207 
208 /******************************************************************************
209 * Function Name: Cy_BLE_EnableHCIModeController
210 ***************************************************************************//**
211 *
212 *  This function enables the BLE Stack controller in HCI only mode.
213 *
214 *  This function must used only in HCI mode and called on CPU core,
215 *  where BLE controller is running.
216 *
217 *  \return
218 *  \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded
219 *       or failed. The following are possible error codes.
220 *
221 *  <table>
222 *    <tr>
223 *      <th>Error codes</th>
224 *      <th>Description</th>
225 *    </tr>
226 *    <tr>
227 *      <td>CY_BLE_SUCCESS</td>
228 *      <td>On successful operation.</td>
229 *    </tr>
230 *    <tr>
231 *      <td>CY_BLE_ERROR_REPEATED_ATTEMPTS</td>
232 *      <td>On invoking this function more than once without calling
233 *          Cy_BLE_Disable() function between calls to this function.</td>
234 *    </tr>
235 *    <tr>
236 *      <td>CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED</td>
237 *      <td>There is insufficient memory available.</td>
238 *    </tr>
239 *    <tr>
240 *      <td>CY_BLE_ERROR_INVALID_STATE</td>
241 *      <td>The PSoC 6 BLE Middleware was not initialized</td>
242 *    </tr>
243 *  </table>
244 *
245 ******************************************************************************/
Cy_BLE_EnableHCIModeController(void)246 cy_en_ble_api_result_t Cy_BLE_EnableHCIModeController(void)
247 {
248     cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_STATE;
249 
250 #if defined(COMPONENT_BLESS_CONTROLLER)
251     if (cy_ble_controllerConfigPtr != NULL)
252     {
253         cy_stc_ble_stack_init_info_t stackInitParam;
254        (void) memset(&stackInitParam, 0, sizeof(cy_stc_ble_stack_init_info_t));
255 
256         /* BLE Stack memory heap size */
257         stackInitParam.memParam.totalHeapSz =
258                 cy_ble_controllerConfigPtr->stackParam->totalHeapSz;
259 
260         /* Configure DLE */
261         stackInitParam.stackConfig.dleConfig.dleMaxTxCapability =
262                 cy_ble_controllerConfigPtr->stackParam->dleMaxTxCapability;
263         stackInitParam.stackConfig.dleConfig.dleMaxRxCapability =
264                 cy_ble_controllerConfigPtr->stackParam->dleMaxRxCapability;
265 
266         stackInitParam.stackConfig.dleConfig.dleNumTxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_TX_PACKETS;
267         stackInitParam.stackConfig.dleConfig.dleNumRxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_RX_PACKETS;
268 
269         /* Configure BLE Stack features */
270         stackInitParam.stackConfig.featureMask =
271                 cy_ble_controllerConfigPtr->stackParam->featureMask;
272 
273         /* Configure maximum connection support */
274         stackInitParam.stackConfig.maxBleConnections =
275                 cy_ble_controllerConfigPtr->stackParam->maxConnCount;
276 
277         /* Configure bonded device list */
278         stackInitParam.stackConfig.bondListConfig.bondListSize =
279                 cy_ble_controllerConfigPtr->stackParam->maxBondedDevListSize;
280 
281         /* Configure white list */
282         stackInitParam.stackConfig.whiteListConfig.whiteListSize =
283                 cy_ble_controllerConfigPtr->stackParam->maxWhiteListSize;
284 
285         /* Configure LL Privacy */
286         stackInitParam.stackConfig.privacyConfig.resolvingListSize =
287                 cy_ble_controllerConfigPtr->stackParam->maxResolvableDevListSize;
288 
289         /* Configure BLE features */
290         /* Enable DLE code in the stack */
291         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_DLE_FEATURE_MASK) != 0u)
292         {
293             Cy_BLE_ControllerEnableDleFeature();
294         }
295 
296         /* Enable LL Privacy code in the stack */
297         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_PRIVACY_1_2_FEATURE_MASK) != 0u)
298         {
299             Cy_BLE_ControllerEnablePrivacyFeature();
300         }
301 
302         /* Enable PHY Update code in the stack */
303         if((cy_ble_controllerConfigPtr->stackParam->featureMask & CY_BLE_PHY_UPDATE_FEATURE_MASK) != 0u)
304         {
305             Cy_BLE_ControllerEnablePhyUpdateFeature();
306         }
307 
308         apiResult = Cy_BLE_ControllerStackSetFeatureConfig(&stackInitParam.stackConfig);
309 
310         /* Application Callback Function */
311         stackInitParam.CyBleAppCbFunc = (cy_ble_app_ev_cb_t)&Cy_BLE_EventHandlerWrapper;
312 
313         if(apiResult == CY_BLE_SUCCESS)
314         {
315             /* Set pointer to memory RAM buffer */
316             stackInitParam.memParam.memoryHeapPtr = cy_ble_controllerConfigPtr->stackParam->memoryHeapPtr;
317 
318             /* Configure parameter for Radio PA calibration */
319             if(cy_ble_controllerConfigPtr->stackParam->paCalConfig != NULL)
320             {
321                 stackInitParam.stackConfig.paCalConfig = *cy_ble_controllerConfigPtr->stackParam->paCalConfig;
322             }
323 
324             /* Initialize the BLE Stack */
325             apiResult = Cy_BLE_ControllerStackInit(&stackInitParam);
326         }
327     }
328 #endif /* defined(COMPONENT_BLESS_CONTROLLER) */
329     return(apiResult);
330 }
331 
332 
333 /******************************************************************************
334 * Function Name: Cy_BLE_EnableControllerFromHost
335 ***************************************************************************//**
336 *
337 *  This function sends an IPC message to enable the BLE Stack controller and
338 *  waits until the controller starts.
339 *
340 *  \return
341 *  \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded
342 *       or failed. The following are possible error codes.
343 *
344 *  <table>
345 *    <tr>
346 *      <th>Error codes</th>
347 *      <th>Description</th>
348 *    </tr>
349 *    <tr>
350 *      <td>CY_BLE_SUCCESS</td>
351 *      <td>On successful operation.</td>
352 *    </tr>
353 *    <tr>
354 *      <td>CY_BLE_ERROR_REPEATED_ATTEMPTS</td>
355 *      <td>On invoking this function more than once without calling
356 *          Cy_BLE_Disable() function between calls to this function.</td>
357 *    </tr>
358 *    <tr>
359 *      <td>CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED</td>
360 *      <td>There is insufficient memory available.</td>
361 *    </tr>
362 *    <tr>
363 *      <td>CY_BLE_ERROR_INVALID_STATE</td>
364 *      <td>The PSoC 6 BLE Middleware was not initialized</td>
365 *    </tr>
366 *    <tr>
367 *      <td>CY_BLE_ERROR_INVALID_OPERATION</td>
368 *      <td>The timeout to enable the BLE controller (a problem with the IPC
369 *            communication, or other BLE controller's CPU core problem)</td>
370 *    </tr>
371 *  </table>
372 ******************************************************************************/
Cy_BLE_EnableControllerFromHost(void)373 cy_en_ble_api_result_t Cy_BLE_EnableControllerFromHost(void)
374 {
375     /** IPC mesage structure for enable controller */
376     static volatile cy_stc_ble_ipc_msg_t controllerMsg =
377     {
378         /* clientID          */  CY_BLE_CYPIPE_MSG_CMD_ID,
379         /* pktType           */  CY_BLE_CYPIPE_ENABLE_CONTR_CMD,
380         /* intrRelMask       */  0x00u,
381         /* controllerStarted */  false,
382         /* data              */  0x00u,
383         /* dataLen           */  0x00u
384     };
385 
386     cy_en_ipc_pipe_status_t ipcStatus;
387     uint32_t rTimeout = CY_BLE_SEND_IPC_MESSAGE_TIMEOUT;
388 
389     /* Check if controller is started  */
390     if ( !controllerMsg.controllerStarted )
391     {
392         /* Store pointer to stack param structure */
393         controllerMsg.data = (uint32_t) cy_ble_configPtr->stackParam;
394 
395         /* Send the address of the intrNotify structure to the controller core via CyPipe
396          * The IPC Pipe can be busy. If so, try sending a message again. */
397         do
398         {
399             ipcStatus = Cy_IPC_Pipe_SendMessage(CY_BLE_IPC_CONTROLLER_ADDR, CY_BLE_IPC_HOST_ADDR,
400                                                 (void *)&controllerMsg, NULL);
401             Cy_SysLib_DelayUs(1u);
402             rTimeout--;
403 
404         }while((ipcStatus != CY_IPC_PIPE_SUCCESS) && (rTimeout != 0u));
405 
406         /* Wait until controller starts */
407         rTimeout = CY_BLE_WAIT_CONTR_START_TIMEOUT;
408         do
409         {
410             Cy_SysLib_Delay(1u);
411             rTimeout--;
412         } while ((!controllerMsg.controllerStarted) && (rTimeout != 0u));
413     }
414 
415     return ((rTimeout == 0u) ? CY_BLE_ERROR_INVALID_OPERATION :
416                         (cy_en_ble_api_result_t) controllerMsg.data);
417 }
418 
419 
420 /*******************************************************************************
421  *  BLE LPM (low power mode)
422 *******************************************************************************/
423 
424 /******************************************************************************
425 * Function Name: Cy_BLE_EnableControllerLowPowerMode
426 ***************************************************************************//**
427 *
428 *  This function enables BLE low power mode for Controller
429 *
430 *  Register BLE callback for deep sleep / sleep
431 *
432 *  This function must used only in BLE dual CPU mode and called on CPU core,
433 *  where BLE controller is running.
434 *
435 ******************************************************************************/
Cy_BLE_EnableControllerLowPowerMode(void)436 void Cy_BLE_EnableControllerLowPowerMode(void)
437 {
438 
439     /* Structure with the SysPm callback parameters for BLESS deep sleep */
440     static cy_stc_syspm_callback_params_t bleDeepSleepCallbackParams =
441     {
442        /* base           */  NULL,
443        /* context        */  NULL
444     };
445 
446     static cy_stc_syspm_callback_t bleDeepSleepCallback =
447     {
448        /* callback       */  &Cy_BLE_ControllerDeepSleepCallback,
449        /* type           */  CY_SYSPM_DEEPSLEEP,
450        /* skipMode       */  CY_SYSPM_SKIP_BEFORE_TRANSITION | CY_SYSPM_SKIP_CHECK_FAIL,
451 
452        /* callbackParams */  &bleDeepSleepCallbackParams,
453        /* prevItm        */  NULL,
454        /* nextItm        */  NULL,
455        /* order          */  CY_BLE_LPM_SYSPM_CB_ORDER
456     };
457 
458     /* Register BLE callback for BLESS deep sleep support */
459     (void)Cy_SysPm_RegisterCallback(&bleDeepSleepCallback);
460 }
461 
462 
463 /*******************************************************************************
464 * Function Name: Cy_BLE_ControllerDeepSleepCallback
465 ****************************************************************************//**
466 *
467 *  This function requests the BLE Stack to put Bluetooth Low Energy Sub-System
468 *  (BLESS) to deep sleep mode.
469 *
470 *  It is registered to the system power mode by Cy_SysPm_RegisterCallback()
471 *  function with CY_SYSPM_DEEPSLEEP type. After registration it is called by
472 *  Cy_SysPm_DeepSleep() function prior entering the core into the CPU deep sleep
473 *  power mode.
474 *
475 *  When it is called with the enMode parameter set to CY_SYSPM_CHECK_READY,
476 *  function enters BLESS to CY_BLE_BLESS_DEEPSLEEP mode. It also checks the
477 *  BLE Subsystem's current operational mode. When the
478 *  Cy_BLE_StackGetBleSsState() function returns CY_BLE_BLESS_STATE_ECO_ON or
479 *  CY_BLE_BLESS_STATE_DEEPSLEEP state, this function returns CY_SYSPM_PASS and
480 *  allows to put the core into the deep-sleep power mode.
481 *  At all other times, the function tries to enter core into sleep mode.
482 *
483 *  This function is available only when BLE low power mode is enabled (called
484 *  Cy_BLE_EnableLowPowerMode() function).
485 *
486 *  \param
487 *  callbackParams  Pointer to the structure with the syspm callback parameters.
488 *
489 *  \param
490 *  mode            The associated syspm callback mode. See description of the
491 *                  cy_en_syspm_callback_mode_t type.
492 *
493 *  \return
494 *  * CY_SYSPM_SUCCESS  - Entered and exited from CPU deep sleep
495 *  * CY_SYSPM_FAIL     - CPU deep sleep not entered.
496 *
497 *******************************************************************************/
Cy_BLE_ControllerDeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams,cy_en_syspm_callback_mode_t mode)498 static cy_en_syspm_status_t Cy_BLE_ControllerDeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams,
499                                                                cy_en_syspm_callback_mode_t mode)
500 {
501     cy_en_syspm_status_t retVal;
502     static uint32_t interruptState = 0u;
503     cy_en_ble_bless_state_t blessState;
504 
505     /* Local variable to store the status of BLESS Hardware block */
506     cy_en_ble_lp_mode_t sleepMode;
507 
508     /* Suppress unused variable warning */
509     (void) callbackParams;
510 
511     switch(mode)
512     {
513         case (CY_SYSPM_CHECK_READY):
514             if(Cy_IPC_Sema_Status(CY_BLE_SEMA) == CY_IPC_SEMA_STATUS_LOCKED)
515             {
516                 /* System do not enter deep sleep if BLE Host start write operation */
517                 retVal = CY_SYSPM_FAIL;
518             }
519             else if (Cy_BLE_HAL_IsEcoCpuClockSrc() == 1u)
520             {
521                 /* System never enters deep sleep if BLE ECO is CPU source */
522                 retVal = CY_SYSPM_FAIL;
523             }
524             else
525             {
526                 cy_en_ble_api_result_t retIsControllerActive;
527 
528                 /* Put BLESS into deep sleep and check the return status */
529                 sleepMode = Cy_BLE_MappingStackEnterLPM(CY_BLE_BLESS_DEEPSLEEP);
530 
531                 /* Disable global interrupt to prevent changes from any other interrupt ISR */
532                 interruptState = Cy_SysLib_EnterCriticalSection();
533 
534                 /* Check the Status of BLESS */
535                 blessState = Cy_BLE_StackGetBleSsState();
536 
537                 if(blessState == CY_BLE_BLESS_STATE_STOPPED)
538                 {
539                     retVal = CY_SYSPM_SUCCESS;
540                 }
541                 else if(sleepMode == CY_BLE_BLESS_DEEPSLEEP)
542                 {
543                     retIsControllerActive = Cy_BLE_MappingIsControllerActive(CY_BLE_CONTROLLER_SLEEP_MODE_DEEPSLEEP);
544 
545                     if(((blessState == CY_BLE_BLESS_STATE_ECO_ON) || (blessState == CY_BLE_BLESS_STATE_DEEPSLEEP))
546                         && (retIsControllerActive == CY_BLE_SUCCESS))
547                     {
548                         /* Enter device deep sleep */
549                         retVal = CY_SYSPM_SUCCESS;
550                     }
551                     else
552                     {
553                         /* The BLESS hardware block cannot go to deep sleep, try sleep mode */
554                         retVal = CY_SYSPM_FAIL;
555                     }
556                 }
557                 else
558                 {
559                     retIsControllerActive = Cy_BLE_MappingIsControllerActive(CY_BLE_CONTROLLER_SLEEP_MODE_SLEEP);
560                     if((blessState != CY_BLE_BLESS_STATE_EVENT_CLOSE) && (retIsControllerActive == CY_BLE_SUCCESS))
561                     {
562                         /* If the BLESS hardware block cannot go to deep sleep and BLE event has not
563                          * closed yet, then place CPU to sleep */
564                         (void)Cy_SysPm_CpuEnterSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
565                     }
566                     retVal = CY_SYSPM_FAIL;
567                 }
568                 if(retVal == CY_SYSPM_FAIL)
569                 {
570                     /* Enable interrupts after failing check */
571                     Cy_SysLib_ExitCriticalSection(interruptState);
572                 }
573             }
574             break;
575 
576         /* Enable interrupts after wakeup */
577         case (CY_SYSPM_AFTER_TRANSITION):
578             Cy_SysLib_ExitCriticalSection(interruptState);
579             retVal = CY_SYSPM_SUCCESS;
580             break;
581 
582         default:
583             retVal = CY_SYSPM_FAIL;
584             break;
585     }
586 
587     return(retVal);
588 }
589 
590 
591 /*******************************************************************************
592  *  Internal
593 *******************************************************************************/
594 
595 /******************************************************************************
596 * Function Name: Cy_BLE_EventHandlerWrapper
597 ***************************************************************************//**
598 *
599 *  This event handler is used in HCI Soft mode, and dirrect calls registered by
600 *  application Cy_BLE_ApplCallback callback.
601 *
602 ******************************************************************************/
Cy_BLE_EventHandlerWrapper(cy_en_ble_event_t event,void * evParam)603 void Cy_BLE_EventHandlerWrapper(cy_en_ble_event_t event, void *evParam)
604 {
605     /* Call Cy_BLE_ApplCallback */
606     Cy_BLE_ApplCallback((uint32_t)event, evParam);
607 }
608 
609 
610 #endif /* CY_IP_MXBLESS */
611 
612 
613 /* [] END OF FILE */
614