1 2 Previous Next 22 Replies Latest reply on Nov 29, 2014 7:01 AM by user_14586677

    How to view value of calculated defines

    user_343349849

       Can someone please explain how I can view the value of calculated defines during debug?

         

      I have a set of addresses to use as pointers for an array. The first one is defined with a value and the rest are relative to this one.

         

      The subsequent item addresses are calculated by adding offset of number of bytes. This keeps it dynamic so if I want to say extend the number of charectors of a string in the array, I only need to change the define for size of that type of string and all the resulting addresses will be recalculated at run time.

         

      Ram is fine, I can hover over a variable or set up a watch and can see the value. When I hover over the define in code, I only see the formula I used in the define and not the calculated value. This make is diffcult to debug storage location bugs.

         

      Thanks

        • 1. Re: How to view value of calculated defines
          user_1377889

          No chance to see that! Use windows's calculator set to "programmer"-mode or assign the #defined value to a variable for inspection when debugging.

             

           

             

          Bob

          • 2. Re: How to view value of calculated defines
            user_343349849

             I changed then all to absulte values but will need to manually adjust them each time I change the size of an item.

               

            Next problem is I cannot figure out the EEPROM. I am attempting to write some data to it and read back but I seem to get back all "0". I understand the functions are blocking but added delays for good measure during test. Data sheet says you can write after 5us of starting the component. I stop it after to ensure no accidental write. Below is my attempt to use the compopent after looking at datasheet and example.

               

            WRITE TEST

               

              uint16 i;

               

              unsigned char *dataptr;

               

              EEPROM_1_Start();

               

             CyDelay(5);

               

              EEPROM_1_EraseSector(0);

               

              CyDelay(5);

               

              for(i=0;i<EEPROM_ROWS;i++)

               

              {

               

                dataptr = (unsigned char *) Settings+ i * EEPROM_ROWSIZE;

               

                EEPROM_1_Write(dataptr,i);

               

              }

               

            EEPROM_1_Stop();

               

            }

               

             

               

            READ TEST

               

            unsigned short i;

               

             reg8 * ReadPtr;

               

             EEPROM_1_Start();

               

              CyDelay(5);  

               

              ReadPtr = (reg8 *) CYDEV_EE_BASE;

               

              for(i = 0u; i < NUM_SETTING_WORDS; i++)

               

              {

               

                    Settings[i] = ReadPtr[i];

               

              }

               

              EEPROM_1_Stop();

            • 3. Re: How to view value of calculated defines
              user_14586677

              Based on write definition "i" wants to be uint8 -

                 

               

                 

              EEPROM_Write(const uint8 * rowData, uint8 rowNumber)

                 

               

                 

              Same thing for the data. Note char from one compiler to another not

                 

              necessarily same as uint8.

                 

               

                 

              Regards Dana.

              • 4. Re: How to view value of calculated defines
                ki.leung
                     I think the function prototype should be   
                   
                        
                   
                     EEPROM_Write(uint8 * rowData, uint8 rowNumber)   
                   
                        
                   
                    where   
                   
                        
                   
                     rowData is pointer to the array of 16bytes to be programmed   
                   
                        
                   
                     ie you load the array with data first then pass the pointer of the 1st byte to the function   
                • 5. Re: How to view value of calculated defines
                  user_14586677

                  EEPROM_Write(const uint8 * rowData, uint8 rowNumber)

                     

                   

                     

                  Above taken from datasheet. PSOC 5LP. Below is GCC handling of

                     

                  the const qualifier. Taken from GCC manual.

                     

                   

                     

                  A Note On const

                     

                  Many users bring up the idea of using C's keyword const as a means of declaring data to be in Program Space. Doing this would be an abuse of the intended meaning of the const keyword.

                     

                  const is used to tell the compiler that the data is to be "read-only". It is used to help make it easier for the compiler to make certain transformations, or to help the compiler check for incorrect usage of those variables.

                     

                  For example, the const keyword is commonly used in many functions as a modifier on the parameter type. This tells the compiler that the function will only use the parameter as read-only and will not modify the contents of the parameter variable.

                     

                  const was intended for uses such as this, not as a means to identify where the data should be stored. If it were used as a means to define data storage, then it loses its correct meaning (changes its semantics) in other situations such as in the function parameter example.

                  • 6. Re: How to view value of calculated defines
                    ki.leung

                     I copy mine from creator EEPROM data sheet.

                       

                    My previous post is  just to point out the issue with the write function that needs to get the values from an array, nothing to do with the "const".

                    • 7. Re: How to view value of calculated defines
                      user_14586677

                      I looked at datasheet, its "Document Number: 001 -85001 Rev. *B", shows a number

                         

                      of revs to write functions. Creator 3.0 SP2.

                         


                         

                      Regards, Dana.

                      • 8. Re: How to view value of calculated defines
                        user_302397898

                         Instead of #defines, try using typedef enum to set the values of your index pointers. These values should show up in your debug.

                        • 9. Re: How to view value of calculated defines
                          user_343349849

                          I didn't realise you could do calculated feilds inside an enum.

                          • 10. Re: How to view value of calculated defines
                            user_302397898

                             If I understand your intent, let me offer this:

                               

                            typedef enum

                               

                            {

                               

                            var1 = &addr1 // address of some variable put into var1

                               

                            var2 = &addr2 // etc.......

                               

                            var3 = &addr3

                               

                            NUM_VARS

                               

                            }var_select;

                               

                            So NUM_VARS gives the total number of variables which is 3. Now you can reference the addresses of your various arrays via var1, etc. Perhaps the var1, var2 and var4 could be elements of an array.  I haven't tried the actual compile but give it a try and use your code.

                            • 11. Re: How to view value of calculated defines
                              user_343349849

                              Does this mean that just to see the calculated addresses I need to do this....

                                 

                              #define addr1 0

                                 

                              #define addr2 addr1 + 3

                                 

                              #define addr3 addr 2 + 17

                                 

                              typedef enum

                                 

                              {

                                 

                              var1 = &addr1 // address of some variable put into var1

                                 

                              var2 = &addr2 // etc.......

                                 

                              var3 = &addr3 

                                 

                              NUM_VARS

                                 

                              }var_select;

                                 

                              And then set watch window on the enum values to see what the calculated addresses are?

                              • 12. Re: How to view value of calculated defines
                                user_302397898

                                 I don't see why you would need the defines with offsets hard coded. The & symbol just puts the address of the array or string into var1, var2, and var 3.  I'm not sure if you are using arrays or offsets into a particular string.  If you are using various string names, this just sets up addresses to the first element of each string.

                                   

                                I haven't tried it, but perhaps var1 var2 var3 could be replaced with var[0], var[1], var[2]. This would be an array containing the addresses of the arrays, variables, or strings you are trying to access. Don't take my word for it. Try it.

                                • 13. Re: How to view value of calculated defines
                                  user_302397898

                                  I'm not sure if I understand what you are trying to do but if the offsets are really the length of strings, you can use this code to determine the length of the string. It just searches the dereferenced pointer until it detects a null.  The length of the string is reported in i.  There's your string length to calculate the offset to the next string.

                                     

                                  uint8 i = 0;
                                  while(*p++)  i++;

                                     

                                  // i contains the length of the string.

                                     

                                  I re-read your original post. It seems that the length of strings can change dynamically. You might have to declare a variable as volatile since the compiler will not have any knowledge of dynamic changes at run time.

                                  • 14. Re: How to view value of calculated defines
                                    user_343349849

                                     Referring to my original post.

                                       

                                    I wanted to view the calculated addresses of #define I had set up. These are starting addresses for reading various types of information from EEPROM.

                                       

                                    I have an originating address and then all the other addresses are relative to it.

                                       

                                    Later I may want to add new data structure or make for entries in existing structure and I don't want to have to calculated new positions all the time.

                                       

                                    For instance, say one block was storing 5 phone numbers and I set the number of digits to 10, and the following block contained contact names

                                       

                                    #define PHONE_NUMBERS           0

                                       

                                    #define CONTACTS                           PHONE_NUMBERS + (NUM_PHONES * DIGITS)

                                       

                                    This way I can change PHONE_NUMS or DIGITS and not need to recalculate any addresses. But, when I debug to determine whether right data is in correct location, the #define does not show me the actual value assigned of say "Contacts", but it WILL show me that PHONE_NUMBERS has value of "0". It does not seem to like to show a calculated value for define.

                                       

                                    This si what my original post was talking about.

                                    1 2 Previous Next