1 /***************************************************************************//**
2 * \file cy_ble_hal_int.c
3 * \version 3.60
4 *
5 * \brief
6 *  This file contains the source code for the Interrupt service Routine for the
7 *  HAL section of the PSoC 6 BLE Middleware.
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright 2017-2021, Cypress Semiconductor Corporation.  All rights reserved.
12 * You may use this file only in accordance with the license, terms, conditions,
13 * disclaimers, and limitations in the end user license agreement accompanying
14 * the software package with which this file was provided.
15 *******************************************************************************/
16 #include "cy_ble.h"
17 #include "cy_ble_hal_pvt.h"
18 #include "cy_ble.h"
19 
20 #if defined(CY_IP_MXBLESS)
21 
22 /*******************************************************************************
23 * Function Name: Cy_BLE_IntrNotifyIsrHandler
24 ****************************************************************************//**
25 *
26 *  This function sends notification (with interrupt type information) to user
27 *  callback for the BLE interrupts subscribed by user. The list of supported
28 *  interrupts described in the enumeration cy_en_ble_interrupt_callback_feature_t.
29 *  Cy_BLE_RegisterInterruptCallback() API used to register callback for receiving
30 *  the BLE interrupts.
31 *
32 *  This function must be called inside the user-defined BLESS
33 *  interrupt service routine (ISR) if user uses Interrupt Notifications Feature.
34 *
35 *******************************************************************************/
Cy_BLE_IntrNotifyIsrHandler(void)36 void Cy_BLE_IntrNotifyIsrHandler(void)
37 {
38     if((intrNotifyPtr != NULL) && (intrNotifyPtr->mask != 0u))
39     {
40         uint32_t interruptType = (uint32_t)CY_BLE_INTR_CALLBACK_NONE;
41 
42         /* Read BLE_BLELL->EVENT_INTR */
43         if((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLESS_STACK_ISR) != 0u)
44         {
45             interruptType |= CY_BLE_INTR_CALLBACK_BLESS_STACK_ISR;
46         }
47         else
48         {
49             if(((BLE_BLESS_INTR_STAT & BLE_BLESS_INTR_STAT_DSM_ENTERED_INTR_Msk) != 0u) &&
50                ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLESS_INTR_STAT_DSM_ENTERED)!= 0u))
51             {
52                 interruptType |= CY_BLE_INTR_CALLBACK_BLESS_INTR_STAT_DSM_ENTERED;
53             }
54 
55             if(((BLE_BLESS_INTR_STAT & BLE_BLESS_INTR_STAT_DSM_EXITED_INTR_Msk) != 0u) &&
56                ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLESS_INTR_STAT_DSM_EXITED) != 0u))
57             {
58                 interruptType |= CY_BLE_INTR_CALLBACK_BLESS_INTR_STAT_DSM_EXITED;
59             }
60 
61             if(((BLE_BLESS_INTR_STAT & BLE_BLESS_INTR_STAT_LL_INTR_Msk) != 0u))
62             {
63                 /**
64                  *  Updates the firmware and hardware to exit sleep mode, when
65                  *  called from the interrupt mode, after checking the state machine.
66                  */
67                 Cy_BLE_MappingLlIsrExitLowPowerMode();
68 
69                 if(BLE_BLELL_EVENT_INTR != 0x0u)
70                 {
71                     if((BLE_BLELL_EVENT_INTR & BLE_BLELL_EVENT_INTR_CONN_INTR_Msk) != 0u)
72                     {
73                         if(((BLE_BLELL_CONN_INTR & BLE_BLELL_CONN_INTR_CLOSE_CE_Msk) != 0u) &&
74                             ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CLOSE_CE) != 0u))
75                         {
76                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CLOSE_CE */
77                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CLOSE_CE;
78                         }
79 
80                         if(((BLE_BLELL_CONN_INTR & BLE_BLELL_CONN_INTR_CE_TX_ACK_Msk) != 0u) &&
81                            ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_TX_ACK) != 0u))
82                         {
83                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_TX_ACK */
84                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_TX_ACK;
85                         }
86 
87                         if(((BLE_BLELL_CONN_EXT_INTR & BLE_BLELL_CONN_EXT_INTR_EARLY_INTR_Msk) != 0u) &&
88                            ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_CONN_EXT_INTR_EARLY) != 0u))
89                         {
90                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_CONN_EXT_INTR_EARLY */
91                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_CONN_EXT_INTR_EARLY;
92                         }
93 
94                         if(((BLE_BLELL_CONN_INTR & BLE_BLELL_CONN_INTR_CE_RX_Msk) != 0u) &&
95                             ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_RX) != 0u))
96                         {
97                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_RX */
98                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_CONN_INTR_CE_RX;
99                         }
100                     }
101 
102                     if((BLE_BLELL_EVENT_INTR & BLE_BLELL_EVENT_INTR_SCAN_INTR_Msk) != 0u)
103                     {
104                         if(((BLE_BLELL_SCAN_INTR & BLE_BLELL_SCAN_INTR_ADV_RX_INTR_Msk) != 0u) &&
105                            ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_ADV_RX) != 0u))
106                         {
107                             /* Return interrupt type Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_ADV_RX */
108                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_ADV_RX;
109                         }
110 
111                         if(((BLE_BLELL_SCAN_INTR & BLE_BLELL_SCAN_INTR_SCAN_RSP_RX_INTR_Msk) != 0u) &&
112                            ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_SCAN_RSP_RX) != 0u))
113                         {
114                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_SCAN_RSP_RX */
115                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_SCAN_INTR_SCAN_RSP_RX;
116                         }
117                     }
118 
119                     if((BLE_BLELL_EVENT_INTR & BLE_BLELL_EVENT_INTR_ADV_INTR_Msk) != 0u)
120                     {
121                         if(((BLE_BLELL_ADV_INTR & BLE_BLELL_ADV_INTR_CONN_REQ_RX_INTR_Msk) != 0u) &&
122                            ((intrNotifyPtr->mask & CY_BLE_INTR_CALLBACK_BLELL_ADV_INTR_CONN_REQ_RX) != 0u))
123                         {
124                             /* Return interrupt type CY_BLE_INTR_CALLBACK_BLELL_ADV_INTR_CONN_REQ_RX */
125                             interruptType |= CY_BLE_INTR_CALLBACK_BLELL_ADV_INTR_CONN_REQ_RX;
126                         }
127                     }
128                 }
129             }
130         }
131 
132         /* Send interrupt type information to registered callback */
133         if(interruptType != (uint32_t)CY_BLE_INTR_CALLBACK_NONE)
134         {
135             if((!intrNotifyPtr->configFlag) && (Cy_BLE_InterruptCallback != NULL))
136             {
137                 /* Single BLE mode */
138                 Cy_BLE_InterruptCallback((uint32_t)interruptType);
139             }
140             else
141             {
142                 /* Dual BLE mode */
143                 uint32_t rTimeout = 100u; /* us */
144                 intrNotifyPtr->data = (uint32_t)interruptType;
145 
146                 /* Check whether IPC is released */
147                 while((Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress((uint32_t)intrNotifyPtr->userIpcChan))) &&
148                       (rTimeout !=0u))
149                 {
150                     Cy_SysLib_DelayUs(1u);
151                     rTimeout--;
152                 }
153 
154                 /* Generates a notify event by IPC interrupt structures */
155                 if(rTimeout != 0u)
156                 {
157                     (void)Cy_IPC_Drv_AcquireNotify(Cy_IPC_Drv_GetIpcBaseAddress((uint32_t)intrNotifyPtr->userIpcChan),
158                                    (1uL << (uint32_t)intrNotifyPtr->userIpcIntr));
159                 }
160 
161             }
162         }
163     }
164 }
165 
166 
167 /*******************************************************************************
168 * Function Name: Cy_BLE_BlessIsrHandler
169 ****************************************************************************//**
170 *
171 *  Process interrupt events generated by the BLE sub-system.
172 *
173 *  The interrupts are mandatory for BLE Device operation and this function must
174 *  be called inside the user-defined interrupt service routine (ISR).
175 *
176 *******************************************************************************/
Cy_BLE_BlessIsrHandler(void)177 void Cy_BLE_BlessIsrHandler(void)
178 {
179     bool sendNotification = false;
180 
181     /* Call BLE Stack manager bless function handler */
182     sendNotification = Cy_BLE_HAL_MappingBlessInterruptHandler();
183     /* Host stack takes care of clearing interrupts */
184 
185     /**
186      * Call the application Host callback.
187      * This notification indicates that user should call Cy_BLE_ProcessEvents()
188      * to process pending Stack events. */
189     if((Cy_BLE_HostRegisteredCallback != NULL) && sendNotification)
190     {
191         Cy_BLE_HostRegisteredCallback();
192     }
193 }
194 
195 #endif /* CY_IP_MXBLESS */
196 
197 
198 /* [] END OF FILE */
199