5 Replies Latest reply on Aug 4, 2014 9:42 PM by dmiya

    How to use real time tick clock?

    brch_2116806

      I'm trying to calculate the period between falling edge and rising edge interrupt in interrupt callback routine.

      The period is short as several usec.

      Do someone know how to get the CPU tick timer? or tick timer API that has resolution of micro second?

      Thank you,

        • 1. Re: How to use real time tick clock?
          ArvindS_76

          See bleapputils.h:

           

          /// This function gives a microsecond clock; this is a 16-bit counter,

          /// counting up.

          /// \return The 16-bit counter value, which rolls over every 65.5 ms.

          UINT16 bleapputils_currentTimeUs(void);


          EDIT:


          Sorry, the earlier method will not be accurate on the 2073* family of chips. Use these instead (all based on the Bluetooth clock, with min resolution of 312.5uS; there is no timer with a shorter resolution accessible from the application):

           

          /// This function returns the current native Bluetooth clock; this

          /// counter is 28 bits, and ticks every 312.5 us and is adjusted for

          /// drift through sleep, etc. To compute differences and times elapsed,

          /// use bleapputils_diffNativeBtClks() or bleapputils_BtClksSince().

          /// \return the counter value.

          /// \return The current BT clock value.

          UINT32 bleapputils_currentNativeBtClk(void);

           

          /// This function computes the signed difference between two BT

          /// clock instants. The general "garbage-in garbage-out" principle

          /// applies, so clocks must be from the same piconet, must be valid when

          /// they are taken, etc. BT clock is 28 bits only and cannot be relied upon when

          /// timings in the hours are desired.

          /// \param from is the "from" time.

          /// \param to is the "to" time.

          /// \return the signed difference (to - from); positive if "to" is after "from",

          /// negative otherwise.

          INT32 bleapputils_diffBtClks(UINT32 from, UINT32 to);

           

          /// This function computes the time elapsed since "before", in BT

          /// clocks. This functions handles rollovers. Clock resets will cause

          /// a large value to be returned.

          /// \param before is the previous counter value, as was returned by

          /// hiddcfa_currentNativeBtClk().

          /// \return the time elapsed, in BT clocks (312.5 us).

          UINT32 bleapputils_BtClksSince(UINT32 before);

          1 of 1 people found this helpful
          • 2. Re: How to use real time tick clock?
            brch_2116806

            Thank you, I've tested the function on my system and 312.5 us resolution is enough for the application.

            • 3. Re: How to use real time tick clock?
              user_1710756

              Hi arvinds,

               

              Our customer would like to add time stamp into vendor specific data using beason.

              So, they asked if BCM2073x could provides up to nano second resolution. As I know, H/W tick has 312.5 usec tick count, so it may be difficult to have up to nano second resolution. Am I right?

               

              Thanks,

              SM

              • 4. Re: How to use real time tick clock?
                ArvindS_76

                Nano second resolution is not possible on 2073x.

                1 of 1 people found this helpful
                • 5. Re: How to use real time tick clock?
                  dmiya

                  As arvinds said, 312.5[us] timer is the shortest for application I think.

                   

                  If your application doesn't use sleep mode,

                  you can calculate duration time from CPU clock cycle like below.

                  int systick_old;

                  static void systick_create(void) {

                      *(int *)0xe000e014 = 0xffffff;

                      *(int *)0xe000e018 = 0x00;

                      *(int *)0xe000e010 = 0x05;

                      systick_old = *(int *)0xe000e018;

                  }

                  static void systick_fine_timeout(UINT32 arg) {

                      int systick_new = *(int *)0xe000e018;

                      int cycles = systick_old - systick_new - 0x02; // about 41.67[ns] resolution @24MHz

                      systick_old = systick_new;

                  }

                  Note: Please use this very carefully at your own risk.

                  1 of 1 people found this helpful