4 Replies Latest reply on Aug 15, 2016 5:40 PM by suresh.joshi

    Why does RTC_SetUnixTime call RTC_UnixToDateTime

    suresh.joshi

      Hey all, I was digging into the RTC component (v1.10) because I managed to freeze my app by passing in a bad unix time (I flipped little and big endian, and I basically was stuck in a while loop until I gave up.

         

      While breakpointing in for the problem, I saw that it was caused here:

         

      void RTC_SetUnixTime(uint64 unixTime)
      {
          RTC_DATE_TIME tmpDateTime;

         

       

         

          RTC_unixTime = unixTime;
          RTC_UnixToDateTime(&tmpDateTime, unixTime, (uint32)RTC_24_HOURS_FORMAT);
      ...
      }

         

      So, since it seems to be that the unixTime is the internal accumulator, and the important public GET methods first call RTC_UnixToDateTime anyways, why are also running it in here? It seems a bit inefficient, as the UnixToDateTime is internally a ton of while loops - when this could just be a 1 line assignement. 

         

      For example, RTC_UnixToDateTime is internally called by the following methods:

         

      RTC_GetTime, RTC_GetDate, RTC_GetDateAndTime, RTC_SetUnixTime

         

      Disclaimer: I am nicely cheaping out by using only set and get UnixTime in my app :)

        • 1. Re: Why does RTC_SetUnixTime call RTC_UnixToDateTime
          user_1377889

          ...it seems to be that the unixTime is the internal accumulator,... This is not quite the case.

             

          When the time is incremented by the clock interrupt there is a complete different set of variables to check for alarm times. This is handled in the RTC_DATE_TIME structure which shows all significant values in BCD.

             

          So the unix time format is mostly because you may need it.

             

           

             

          Bob

          • 2. Re: Why does RTC_SetUnixTime call RTC_UnixToDateTime
            suresh.joshi

            Thanks Bob!

               

            I suppose a higher-level question might be, why are calling RTC_UnixToDateTime in the aforementioned 'get' methods? Are there two side-by-side internal formats being maintained?

               

            When RTC_Update is called, it increments the RTC_unixTime (which is why I referred to it as an internal accumulator). Also, the other lines of code in there (ifdef'd out for me) all refer to unix time.

               

            This is just curiousity at this point, as this is my first project using the PROC BLE and I'm trying to understand the system code better so I can void pitfalls - I corrected my previous bugs, so my code runs fine now.

            • 3. Re: Why does RTC_SetUnixTime call RTC_UnixToDateTime
              user_1377889

              Are there two side-by-side internal formats being maintained?   Yes, the unix date format and the struct RTC_DATE_TIME.

                 

              When RTC_Update is called, it increments the RTC_unixTime (which is why I referred to it as an internal accumulator) Yes, you're right.

                 

              This is just curiousity at this point, as this is my first project I can assure you that I very rarely look into the generated sources, the documentation is quite sufficient to answer any questions and to use the component. And: the RTC component seems to be a rather complicated one with many APIs available/needed.

                 

               

                 

              Bob

              • 4. Re: Why does RTC_SetUnixTime call RTC_UnixToDateTime
                suresh.joshi

                Thanks Bob! As I said, I ran into a freeze/crash which is why I started digging in and came up with my question.