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?

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.

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.

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:

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.

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 :) ).

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).

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.