3 Replies Latest reply on Jun 19, 2017 5:05 AM by user_1377889

    I think I understand callbacks but...

    allopis_2271821

      I have been looking at adding a 9-clock-cycles to an I2C application and since the component does not provide a function to reset a hung SDA, I was wondering if I could insert it in the I2C_Init function of the component.     It seems to me that the use of a callback would be perfect, but looking into how they work I ran into the following thoughts/questions:

         

      - If I understand it correctly, the component generated code has to have defined hooking points.    If that is the case, the callback functionality has limited value because components barely have any hooking points.   

         

      - If I develop a new component containing hooking points in the generated source, would just the existence of the hooking point(s) and the proper user request entry in cyapicallbacks.h,  result in executing the callback ?   Or does the developer need to do some additional work

         

      - Again, if I was to develop a new component X that uses an existing component Y that accepts a given callback, and I needed to use the callback, then it seems there is no way to perform the callback hook definition within the confine of the component X context.   The component X user will need to know the need to set in cyapicallbacks.h, which does not seem that desirable to me.   It would be nice if there was some kind of a definition mechanism to hook the callback in Y (other than typing in cyapicallbacks.h) 

         

      - Is it fair to assume the use of Merge Region has some similar peculiarities?

         

      May be I am a bit (or a lot) confused in my understanding...

         

      Tony

        • 1. Re: I think I understand callbacks but...
          user_1377889

          When you write your own component you are totally free of using any mechanism to get called back.

             

          For your problem a callback is not needed. To recover a "hung" I2C it is sufficient to hold sda high for 9 clock cycles. This you can do by accessing the I2C pins directly which have generated source files providing you with the required APIs.

             

           

             

          Bob

          • 2. Re: I think I understand callbacks but...
            allopis_2271821

            For your problem a callback is not needed. To recover a "hung" I2C it is sufficient to hold sda high for 9 clock cycles. This you can do by accessing the I2C pins directly which have generated source files providing you with the required APIs.

               

            I had already done that.   I am just exploring the possibilities provided by Creator.

               

            Thank you 

            • 3. Re: I think I understand callbacks but...
              user_1377889

              As a general rule of thumb: avoid tinkering with the generated files. Some components offer clearly marked sections where some user code may be inserted, but my feeling is that with the introduction of the callback macro scheme Cypress would like to cease those sections.

                 

              I even (as part of my archiving scheme ) delete the complete folder "Generated Files". There is one quick and dirty trick to change some code:

                 
                    
              • Build your project with the component you want to modify
              •     
              • Move the component's generated files (do not forget the pin's components and other helpers) to the sources folder
              •     
              • Then set for the component the Cy_Suppress_API_GEN to true
              •     
              • Rebuild, should be error free.
              •     
              • Change the component's source.
              •    
                 

               

                 

              Bob