• AVR Freaks

Hot!Harmony Timers API - migration H1/H2 to H3

Author
ElwoodBlues
Junior Member
  • Total Posts : 42
  • Reward points : 0
  • Joined: 2015/10/26 11:00:37
  • Location: 0
  • Status: offline
2019/12/27 15:01:56 (permalink)
0

Harmony Timers API - migration H1/H2 to H3

We're migrating a PIC32MX Harmony v1 project to v3.  I'm nearly there... partially building, but so far I have run into some interface differences in the Timer system...
 
- H1/H2 has the "Timer Driver Library", and the "Timer System Service Library". 
- H3 has the "Time System Service Library" (notice subtle difference in name)
 
I do see ..\firmware\src\config\pic32mz_ef_sk\system\sys_time_h2_adapter.h which apparently adapts from H1/H2 calls to H3.  However, I'm not finding any documentation on this, or on how setup the H3 timer with settings equivalent to H1/H2. 
 
For example, following are the relevant defines that effect my H1 timer config...
/*** Timer Driver Configuration ***/
#define DRV_TMR_INTERRUPT_MODE true
#define DRV_TMR_INSTANCES_NUMBER 1
#define DRV_TMR_CLIENTS_NUMBER 1

/*** Timer Driver 0 Configuration ***/
#define DRV_TMR_PERIPHERAL_ID_IDX0 TMR_ID_1
#define DRV_TMR_INTERRUPT_SOURCE_IDX0 INT_SOURCE_TIMER_1
#define DRV_TMR_INTERRUPT_VECTOR_IDX0 INT_VECTOR_T1
#define DRV_TMR_ISR_VECTOR_IDX0 _TIMER_1_VECTOR
#define DRV_TMR_INTERRUPT_PRIORITY_IDX0 INT_PRIORITY_LEVEL1
#define DRV_TMR_INTERRUPT_SUB_PRIORITY_IDX0 INT_SUBPRIORITY_LEVEL0
#define DRV_TMR_CLOCK_SOURCE_IDX0 DRV_TMR_CLKSOURCE_INTERNAL
#define DRV_TMR_PRESCALE_IDX0 TMR_PRESCALE_VALUE_256
#define DRV_TMR_OPERATION_MODE_IDX0 DRV_TMR_OPERATION_MODE_16_BIT
#define DRV_TMR_ASYNC_WRITE_ENABLE_IDX0 false
#define DRV_TMR_POWER_STATE_IDX0 SYS_MODULE_POWER_RUN_FULL

/*** Timer System Service Configuration ***/
#define SYS_TMR_POWER_STATE SYS_MODULE_POWER_RUN_FULL
#define SYS_TMR_DRIVER_INDEX DRV_TMR_INDEX_0
#define SYS_TMR_MAX_CLIENT_OBJECTS 5
#define SYS_TMR_FREQUENCY 1000
#define SYS_TMR_FREQUENCY_TOLERANCE 10
#define SYS_TMR_UNIT_RESOLUTION 10000
#define SYS_TMR_CLIENT_TOLERANCE 10
#define SYS_TMR_INTERRUPT_NOTIFICATION false
#define SYS_CONSOLE_DEVICE_MAX_INSTANCES 1
#define SYS_CONSOLE_INSTANCES_NUMBER 1

 
In H3, all I find in the way of configuration is the following...
/* TIME System Service Configuration Options */
#define SYS_TIME_INDEX_0 0
#define SYS_TIME_MAX_TIMERS 5
#define SYS_TIME_HW_COUNTER_WIDTH 32
#define SYS_TIME_HW_COUNTER_PERIOD 4294967295U
#define SYS_TIME_HW_COUNTER_HALF_PERIOD (SYS_TIME_HW_COUNTER_PERIOD>>1)
#define SYS_TIME_CPU_CLOCK_FREQUENCY 25000000
#define SYS_TIME_COMPARE_UPDATE_EXECUTION_CYCLES (460)

 
Also, in sys_time_h2_adapter.h, many of the functions headers reference "SYS_TMR_Initialize()" which does not exist.  
 
Am I missing something?  It would expect there to be more documentation for this.  Before I try to deep-dive and hack through the code, I'm hoping maybe someone can't point me towards some docs or other info. 
 
Thank you
post edited by ElwoodBlues - 2019/12/27 15:06:58
#1

1 Reply Related Threads

    BillP
    Super Member
    • Total Posts : 393
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: Harmony Timers API - migration H1/H2 to H3 2019/12/28 11:01:20 (permalink)
    0
     
    However, I'm not finding any documentation on this, or on how setup the H3 timer with settings equivalent to H1/H2.


    What a surprise!
    Here is one "gotcha" that I found when converting from Hv2 to Hv3.

     

    In Hv2 I created a millisecond timer with a callback.  In the app.c init section I used:

    void tmrcallback(uintptr_t context, uint32_t currtick); // the prototype
    void tmrcallback(uintptr_t context, uint32_t currtick)
    {
         appData.appstate = APP_STATE_EVENT;
    }



    In the run-time loop, I used:

    #define PERIODMS 1
          appData.sysTmrHandle = SYS_TMR_CallbackPeriodic(PERIODMS,1,tmrcallback);


    Note:  In the Timer Driver setup for timer 0, the  timer is linked to TMR_ID_2 and the interrupt vectors, etc.

    For Hv3, the period is a microsecond value, thereby requiring a 32-bit number and you must tie the timer to a specific hardware timer (i.e. TMR_2 configured as a  32-bit timer) so in Hv3 I used:

    void TMR_CallbackFn (uintptr_t context ); // the prototype - note there is only 1 arg in Hv3
    void TMR_CallbackFn (uintptr_t context )
    {
        clkData.clkstate = CLKS_STATE_EVENT;
    }
    Now, if you look in the interrupt code, the interrupt vectors are linked to TMR_3 (because of the 32-bit value).

    #define PERIODMS 99999 // microseconds*100 = 1 ms for a 100 MHz CPU
                TMR2_Stop(); // not sure if this is needed
                TMR2_CallbackRegister(TMR_CallbackFn, NULL);
                TMR2_PeriodSet(PERIODMS); // Set the period (ms)
                TMR2_Start(); // Start the timer

    This is one of many differences that have to be tracked down when converting to Hv3.  I am trying to do this in a new book that shows how to implement the same examples as my MZ book, especially how to use the USB and TCP/IP libraries in Hv3.  So far I have stumbled on a lot of issues in the USB CDC library.

    To make matters worse, the Curiosity Dev 2.0 boards I have received from MicrochipDirect do not work.  I have has a trouble ticket in for almost 2 months with no solution.  There is one post on this forum that says the Dev 2.0 board from DigiKey works, so I am waiting to try that one.  When I get a working board, I can (hopefully) finish my book, including documentation on the how and why of the USB and TCP/IP libraries.
    post edited by BillP - 2019/12/28 11:06:55
    #2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5