5 Replies Latest reply on Mar 31, 2018 1:58 PM by ssl.huynh_3143771

    How to attach callback function to bless interrupt?

    ssl.huynh_3143771

      We would like to run a block of code every time the bless interrupt is called. Is there a way to create a callback function that executes the code whenever the bless interrupt is triggered?

        • 1. Re: How to attach callback function to bless interrupt?
          msur

          Hello ssl.huynh_3143771,

           

          You can use one of the two methods below to register a callback to the BLESS interrupt -

          1. Use Cy_BLE_RegisterAppHostCallback to register a callback, this callback will be called everytime there is a BLESS interrupt.

          2. You can set the "CY_BLE_INTR_NOTIFY_FEATURE_ENABLE" in cy_ble_config.h file and then use "Cy_BLE_RegisterInterruptCallback" API to register your callback. The difference between '1' and '2' is that the second method passes the interrupt type that triggered the BLESS interrupt to the callback.

           

          Let me know if this answers your question.

           

          Regards,

          Meenakshi Sundaram R

          • 2. Re: How to attach callback function to bless interrupt?
            ssl.huynh_3143771

            Hey msur,

             

            We are trying to look for the Cy_BLE_RegisterAppHostCallback and Cy_BLE_RegisterInterruptCallback API's that you mentioned. When we try to call the API's, PSoC doesn't see it as declared functions. We also don't see the API's in the PDL library or datasheet.

             

            Also, cy_ble_config.h doesn't exist but we have searched through BLE_config.h and do not see "CY_BLE_INTR_NOTIFY_FEATURE_ENABLE". We have also searched through the whole project using the ctrl+f tool. Could you show us where to get more information on implementing these methods?

             

            Best,

            Steve

            • 3. Re: How to attach callback function to bless interrupt?
              msur

              Steve,

               

              Are you using the latest version of PSoC Creator 4.2? The older (beta#2) version did not have the Cy_BLE_RegisterAppHostCallback API.

               

              This API should be defined in cy_ble.c file. Note that this API is defined for the core which implements the Host. PSoC Creator does not have the capability to distinguish between the macros for the two cores - it only uses the macro definitions for one core (either CM4 or CM0+ - sort of a mystery for me too on which core it picks, guess depends on its mood ..). So as a result, you may not note the declaration/definition of the function but it ideally should build without errors if you call them from the host core.

               

              Coming to the "CY_BLE_INTR_NOTIFY_FEATURE_ENABLE" macro - now I strongly have a feeling that you are still using Beta#2? This macro is defined across multiple files in BLE PDL in the latest PSoC Creator.

               

              If you have "Cy_BLE_IPC_RegisterAppHostCallback" instead of "Cy_BLE_RegisterAppHostCallback" then yes you have PSoC Creator 4.2 Beta 2.

               

              Regards,

              Meenakshi Sundaram R

              • 4. Re: How to attach callback function to bless interrupt?
                ssl.huynh_3143771

                Msur,

                 

                You're right, we were still running the beta version of PSoC Creator 4.2. We haven't gotten to implementing the callback function yet because we've been having difficulties trying to get our code to work with the new PSoc Creator 4.2.

                 

                Bluetooth doesn't seem to be functioning properly, as we are observing the BLE events that get called. On initialization, the BLE events that get called are: 1000 (CY_BLE_EVT_STACK_ON) , 3002 (CY_BLE_EVT_SET_DEVICE_ADDR_COMPLETE), and 2004 (CY_BLE_EVT_LE_SET_EVENT_MASK_COMPLETE). We notice that a chunk of code in our BLE stack handler is causing this problem but we're unsure why. The code checks if the advertisement or connection state has changed which gets updated by BLE events, and restarts advertisement as necessary in an interrupt handler configured to AppControl_IRQ_cfg:

                 

                if((was_advertising != is_advertising) || (was_connected != is_connected))

                {

                     NVIC_SetPendingIRQ(AppControl_IRQ_cfg.intrSrc);

                }

                 

                However, when we remove this chunk of code the BLE initializes and advertises properly with the following BLE events occurring: 1000, 3002, 2004, 4013, 3006, 3006, and 4006. We are unsure why including the chunk of code is causing the problem.

                 

                Best,

                Steve

                • 5. Re: How to attach callback function to bless interrupt?
                  ssl.huynh_3143771

                  It turns out there was not enough space in the stack which is why the BLE events would generate when excluding the chunk of code, but not generate when including. After allocating to the heap, it fixed the problem.

                   

                  Best,

                  Steve