9 Replies Latest reply on Sep 23, 2014 9:58 AM by ArvindS_76 Branched to a new discussion.

    FineTimer

    frfu_1819646

      At the moment the lowest finetimer setting is 12.5msec.

      Can i adjust this to lower value like 1msec?

      Maybe by patching the cortex m3 registers directly ?

        • 1. Re: FineTimer
          ArvindS_76

          The 1s app timer and the fine timer are software times and the resolution if the fine timer is 12.5mS. This cannot be changed.

           

          With SDK 2.x, there is a different timer that can run at a resolution of 1.25mS as an optional library you can add to the app. See <SDK>/Wiced-Smart/tier2/brcm/libraries/inc/bt_clock_based_timer.h

           

          To include this library to your application, add the following line to your application's makefile.mk:

           

          # Include this library to the application.

          APP_PATCHES_AND_LIBS += bt_clock_based_periodic_timer.a

           

          Then initialize the library in your application_create function before starting the timer:

           

          #include "bleappevent.h"

          #include "bt_clock_based_timer.h"

           

          void application_create(void)

          {

               //// All other application initialization here.

           

               // Initialize the BT clock based periodic timer library

               bt_clock_based_periodic_timer_Init();

          }

           

           

          Then to start the timer at say 50mS interval:

          void application_start_50ms_timer(void)

          {

               // See header for more details

               bt_clock_based_periodic_timer_Enable(application_timer_expired_callback, NULL, 50000/625)

          }

           

          int application_timer_expired_callback(void* context)

          {

               // 50 ms timer callback, do something.

           

               // Context was not allocated and so does not need to be freed. So return no action.

               return BLE_APP_EVENT_NO_ACTION;

          }

           

          To stop timer, use bt_clock_based_periodic_timer_Disable()

          1 of 1 people found this helpful
          • 2. Re: FineTimer
            frfu_1819646

            Can i use SDK 2...  for a 20732s Design? Is there a solution for SDK 1.1?

            • 3. Re: FineTimer
              MichaelF_56

              Unfortunately, you will need to use SDK 1.1 for BCM20732S designs.  I will let the development team respond with a work around if one exists.

              • 4. Re: FineTimer
                userc_8140

                I am using BCM920737TAG board and the timer works with 2.5msec configuration.

                bt_clock_based_periodic_timer_Enable(application_timer_expired_callback, NULL, 2500/625); -- works

                 

                But it doesn't work with 1.25msec configuration

                bt_clock_based_periodic_timer_Enable(application_timer_expired_callback, NULL, 1250/625);

                 

                I am toggling one of port pin to monitor the timing

                 

                int application_timer_expired_callback(void* context)

                {

                     // 50 ms timer callback, do something.

                 

                    if(gpio_getPinOutput(APPLICATION_LED_GREEN_PORT, APPLICATION_LED_GREEN_PIN) == APPLICATION_LED_GREEN_ON)

                  {

                       application_turn_off_green_led();

                  }

                  else

                  {

                       application_turn_on_green_led();

                  }

                     // Context was not allocated and so does not need to be freed. So return no action.

                     return BLE_APP_EVENT_NO_ACTION;

                }

                 

                Is there any limitation on using 1.25msec as timer period?

                • 5. Re: FineTimer
                  ArvindS_76

                  Periods of less than ~5mS should not be used because this will severely affect connections/advertisements/scans. This timer uses the BT scheduler which runs off BT slots (625uS). Since most things BT are scheduled in periods of slots or frames (1.25mS), setting this timer to 1.25mS won't work because there are higher priority tasks that the BT scheduler has to perform and will always preempt this timer.

                  1 of 1 people found this helpful
                  • 6. Re: FineTimer
                    userc_8140

                    Is it possible t read the slot count(625usec) form application?

                    • 7. Re: FineTimer
                      ArvindS_76

                      No, this is not possible.

                      1 of 1 people found this helpful
                      • 8. Re: FineTimer
                        userc_8140

                        Thanks for information and I need more information about this timer.

                         

                        I want to configure this timer for 5msec and in call back function I want to execute my application code. Is there any limitation how much code we can execute without effecting the performance.

                        • 9. Re: FineTimer
                          ArvindS_76

                          The callback is serialized to the application thread. Since all time critical activity happens in interrupt context, you should be OK to use say 3-4mS of the processing time. Just remember that it is the idle thread that pets the watch dog (WD). If you don't let the idle thread run at least once in 2s, you will trip the watchdog and the chip will reset (you can pet the WD using wdog_restart() in your app code, but you should be a bit careful with this approach).

                           

                          Also remember that there are a number of commands and events the BT stack will need to handle (the stack runs in the same thread context). Your app will also need to handle other callbacks and interrupt handlers and these are also serialized to the application thread. So you cannot take up all the processing time in this timer callback (and you have to return from this function).

                          1 of 1 people found this helpful