11 Replies Latest reply on Mar 20, 2017 10:02 AM by e.pratt_1639216

    PSOC 4 Ble callback functions

    gokul7.gokul_2285351

      I'm  currently using Cypress PSOC 4 BLE pioneer kit .Trying out Ledcapsense in it.

         

      i have doubt regarding Blecallback functions ,are these functions generated automatically when the project is build after topdesign or Do we have to write program?

        • 1. Re:  PSOC 4 Ble callback functions
          user_1377889

          Welcome in the forum.

             

          The callback macros are explained in Creator Help. You have to provide a #define and a function with a corresponding name as listed in the component's datasheet.

             

           

             

          Bob

          • 2. Re:  PSOC 4 Ble callback functions
            user_13524663

            I don't see "callback" or "macro" in the Help system index.

               

            I'm trying to figure the callback thing out. Looking at the BLE_Proximity example and reading the PSoC4 System Reference and the Component Author Guide confuses me, which isn't surprising. I see in cyapicallbacks.h where I'm supposed to add those callback #defines, however I see that:

               

            - common.h is #included in main.c

               

            - Both lls.h and tps.h are #included in common.h

               

            - project.h is #included in common.h

               

            - both CYBLE_lls.h and CYBLE_tps.h are #included in project.h

               

            So, in a nutshell, if Creator has generated these files and the #includes, what does section 6.1.6 of the Component Author Guide and Macro Callbacks of the PSoC4 System Reference require me to do in cyapicallbacks.h?

            • 3. Re:  PSOC 4 Ble callback functions
              user_1377889

              Sorry, BLE callbacks are handled differently. I didn't notice that.

                 

              It is not too difficult, do a "search" in the Creator Help for "callback" to get info for the general component callback macros.

                 

              Info for the BLE callbacks you get in the BLE datasheet, again do a search for "callback".

                 

              The "Component Author Guide" is useful only when you want to build up own components which you put into the component catalog.

                 

               

                 

              Bob

              • 4. Re:  PSOC 4 Ble callback functions
                user_13524663

                OK, I was looking in the index.

                   

                However, the Help text is from the PSoCCreator User Guide. What is said doesn't align with what I see in the example code, where BLE_Proximity01's cyapicallbacks.h is essentially empty and the declarations and definitions are in other files, as noted. As far as I can tell, all that is required is that the automatically generated files are declared/defined somewhere, the cyapicallbacks.h file doesn't seem to be necessary from the example code.

                • 5. Re:  PSOC 4 Ble callback functions
                  e.pratt_1639216

                  There is more than one method to handle the callback events for the BLE events; You can declare a #define  (as @Bob Marlowe stated) for the specific components callback function, and then write that function declaration in cyapicallbacks.h. (It uses macros to internally call the function name that you declare with the #define preprocessor declarative).

                     

                  Another method is to declare hardware ISR components in the "TopDesign.cysch" file and then define those ISR functions in code. (Method I personally used, as it happened to be the one I found first).

                     

                  Example of the #define macro method:

                     

                  #define SimpleComp_1_START_CALLBACK

                     

                  void SimpleComp_1_Start_Callback( void );

                     

                   

                     

                  Example of the "component" method:

                     

                  Create an ISR component, wire to device you want it to handle interrupts for, then:

                     

                  isr_TIMER_1_StartEx(GENERIC_TIMER_ISR); //Start interrupt handler; Put this in the initialization/startup code to start the interrupt/callback and to start handling it when events occur.

                     

                  CY_ISR_PROTO(GENERIC_TIMER_ISR); //Prototype declaration

                     

                  CY_ISR(GENERIC_TIMER_ISR) { //Function definition
                      uint8 i;
                      for(i=0;i<MAX_NUMBER_TIMERS;i++) {
                          if(VectorEntry[i].CmdFunc) {
                              if(VectorEntry[i].Data-- == 0) {
                                  VectorEntry[i].CmdFunc();
                                  VectorEntry[i].CmdFunc = 0;
                                  tmrcount--;
                              }
                          }
                      }
                  }

                  • 6. Re:  PSOC 4 Ble callback functions
                    e.pratt_1639216

                    Using the "component" method, you can also choose to use the default ISR handler function defined by the component's generated files, and just write your code inside of the default ISR within the generated files in the area that looks like this:

                       

                    CY_ISR(isr_TIMER_Interrupt)
                    {
                        #ifdef isr_TIMER_INTERRUPT_INTERRUPT_CALLBACK
                            isr_TIMER_Interrupt_InterruptCallback();
                        #endif /* isr_TIMER_INTERRUPT_INTERRUPT_CALLBACK */ 

                       

                        /*  Place your Interrupt code here. */
                        /* `#START isr_TIMER_Interrupt` */

                       

                        LED_Write(1);//turn on LED as an example

                       

                        /* `#END` */
                    }

                    1 of 1 people found this helpful
                    • 7. Re:  PSOC 4 Ble callback functions
                      user_13524663

                      Thanks for that explanation. One thing that makes their instructions confusing is that for their own example, BLE_Proximity01 in my case, cyapicallbacks.h has no #defines for any of the callbacks. They use the header file, such as lls.h, to declare and the c file to define. I expected that the cyapicallbacks.h file would conform to what the Component Author guide (Help file too) presents.

                      • 8. Re:  PSOC 4 Ble callback functions
                        user_13524663

                        So, in your example, the callback function is LED_Write(1) but it doesn't need teh curly braces? It it's simple enough and only one callback function is required, then that's enough?

                        • 9. Re:  PSOC 4 Ble callback functions
                          e.pratt_1639216

                          Yeah, like I listed above there are multiple ways to get a callback function being associated/attached to the hardware/interrupts.

                             

                          They list using a define and writing the callback declaration in the cyapicallbacks.h file, but I have yet to see an example that directly implements it that way.

                             

                          Usually I see it the way they do in the BLE_Proximity01 example where they register the callback in their startup routine in main, thus making it irrelevant whether or not you use their default callback or setup a #define for the callback in cyapicallbacks.h

                             

                           

                             

                          I've found that the only way to be sure what code is doing in embedded projects is to look at the source code and follow it yourself, or to look at the disassembly (if you like opcodes :) ).

                          • 10. Re:  PSOC 4 Ble callback functions
                            e.pratt_1639216

                            In my example:

                               

                            The callback function is "void isr_TIMER_Interrupt(void)", but the CY_ISR() macro handles the void parameter/return values, and ensures that the callback function is in the correct format for the interrupt to correctly call the callback.

                               

                            The callback function itself is named "isr_TIMER_Interrupt", which is declared in the generated component timer files.

                               

                            "LED_Write(1);" is a simple function to set the pin "LED" to a high voltage state when the interrupt callback is called (whenever the timer component interrupts and calls the callback).

                            1 of 1 people found this helpful
                            • 11. Re:  PSOC 4 Ble callback functions
                              e.pratt_1639216

                              For the BLE_Proximity01 example, the callback is declared in lls.h, and defined in lls.c, but isn't setup as the callback vector for the interrupts until main() when the function CyBle_LlsRegisterAttrCallback(LlsServiceAppEventHandler); is called.