aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/src/enc/fsl_enc_driver.c
blob: 053abd113f9294bfa9fb795aa6719d9ddcfaa7dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*******************************************************************************
*
* Copyright [2014-]2014 Freescale Semiconductor, Inc.

*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale License
* distributed with this Material.
* See the LICENSE file distributed for more details.
* 
*
*******************************************************************************/

#include <assert.h>
#include <string.h>
#include "fsl_enc_driver.h"
#include "fsl_clock_manager.h"
#include "fsl_interrupt_manager.h"
#if FSL_FEATURE_SOC_ENC_COUNT

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Code
 ******************************************************************************/

/*FUNCTION*********************************************************************
 *
 * Function Name : ENC_DRV_StructInitUserConfigNormal
 * Description   : This function  fills the initial user configuration. 
 * Calling the initialization function with the filled parameter configures 
 * the ENC module to function as a simple Quadrature Encoder.
 *
 *END*************************************************************************/
enc_status_t ENC_DRV_StructInitUserConfigNormal(enc_user_config_t * userConfigPtr)
{
    /* Test structure pointer. */
    if (!userConfigPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }
    
    /* Normal Encoder mode. */
    userConfigPtr->operationMode = kEncNormalMode;
    
    /* Reverse counting disabled. */
    userConfigPtr->reverseCounting = false;
    
    /* Positive edge of INDEX pulse. */
    userConfigPtr->indexInputNegativeEdge = false;
    
    /* Positive edge of HOME signal. */
    userConfigPtr->homeInputNegativeEdge = false;
    
    /* Init position register by INDEX pulse. */
    userConfigPtr->indexPulsePosInit = true;
    
    /* Initialization register value set to 0U. */
    userConfigPtr->posCntInitValue = 0U;
    
    /* Position compare register value set to 0xFFFFU. */
    userConfigPtr->posCmpValue = 0xFFFFU;
    
    /* Modulus register value set to 0U. */
    userConfigPtr->moduloValue = 0U;
    
    /* Update HOLD registers on trigger input disabled. */
    userConfigPtr->triggerUpdateHoldRegEnable = false;
    
    /* Clear position counter on trigger input disabled. */
    userConfigPtr->triggerClearPosRegEnable = false;
    
    /* Modulo counting revolution register disabled. */
    userConfigPtr->moduloRevolutionCounting = false;
    
    /* POSMATCH pulses when match occurs between position register and compare register value. */
    userConfigPtr->outputControlOnReading = false;
    
    /* Watchdog disabled. */
    userConfigPtr->watchdogTimeout = 0U;
    
    /* Filter number of counts set to 0. */
    userConfigPtr->filterCount = 0U;
    
    /* Filter period set to 0U. */
    userConfigPtr->filterPeriod = 0U;
    
    /* Return success status code. */
    return kStatus_ENC_Success;
}
   
/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_Init
 * Description   : This function initializes a ENC instance for operation.
 * This function initializes the run-time state structure to ungate the clock to the ENC module,
 * initializes the module to user-defined settings and default settings,
 * configures the IRQ state structure and enables the module-level interrupt to the core.
 * This example shows how to set up the enc_state_t and the
 * enc_user_config_t parameters and how to call the ENC_DRV_Init function by passing
 * in these parameters:
    enc_user_config_t encUserConfig;
    encUserConfig.operationMode = kEncNormalMode;
    encUserConfig.reverseCounting = false;
    encUserConfig.indexInputNegativeEdge = false;
    encUserConfig.homeInputNegativeEdge = false;
    encUserConfig.indexPulsePosInit = true;
    encUserConfig.posCntInitValue = 0U;
    encUserConfig.posCmpValue = 0xFFFFU;
    encUserConfig.moduloValue = 0U;
    encUserConfig.triggerUpdateHoldRegEnable = false;
    encUserConfig.triggerClearPosRegEnable = false;
    encUserConfig.moduloRevolutionCounting = false;
    encUserConfig.outputControlOnReading = false;
    encUserConfig.watchdogTimeout = 0U;
    encUserConfig.filterCount = 0U;
    encUserConfig.filterPeriod = 0U;
    ENC_DRV_Init(instance, &encUserConfig);
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_Init(uint32_t instance, const enc_user_config_t *userConfigPtr)
{    
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    bool mEnable;
    
    /* Test structure pointer. */
    if (!userConfigPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }
    
    /* Enable Clock to Quadrature Encoder peripheral. */
    mEnable = CLOCK_SYS_GetEncGateCmd(instance);
    if (!mEnable)
    {
        CLOCK_SYS_EnableEncClock(instance);
    }
  
    /* Reset the registers for ENC module to reset state. */
    ENC_HAL_Init(base);
    
    /* Set operation mode. */
    switch(userConfigPtr->operationMode)
    {
    case kEncModuloCountingMode:
        ENC_HAL_SetModuloCountingCmd(base, true);
        break;
        
    case kEncSignalPhaseCountMode:
        ENC_HAL_SetSignalPhaseCountModeCmd(base, true);
        break;
        
    case kEncNormalMode:
        ENC_HAL_SetModuloCountingCmd(base, false);
        ENC_HAL_SetSignalPhaseCountModeCmd(base, false);
        break;
        
    default:
        return kStatus_ENC_Error;
    }
    
    /* Set directiong of counting. */
    ENC_HAL_SetReverseCountingCmd(base, userConfigPtr->reverseCounting);
        
    /* INDEX input transition edge setting. */
    ENC_HAL_SetIndexPulseNegativeEdgeCmd(base, userConfigPtr->indexInputNegativeEdge);
    
    /* HOME input transition edge setting. */
    ENC_HAL_SetHomeSignalNegativeEdgeCmd(base, userConfigPtr->homeInputNegativeEdge);
    
    /* Position counter init signal. */
    ENC_HAL_SetIndexInitPosCmd(base, userConfigPtr->indexPulsePosInit);
    ENC_HAL_SetHomeInitPosCmd(base, !userConfigPtr->indexPulsePosInit);
        
    /* Position counter init value. */
    ENC_HAL_SetInitReg(base, userConfigPtr->posCntInitValue);
    
    /* Position compare init value. */
    ENC_HAL_SetCmpReg(base, userConfigPtr->posCmpValue);
    
    /* Modulo value. */
    ENC_HAL_SetModulusReg(base, userConfigPtr->moduloValue);
    
    /* Enable/disable update hold registers on input trigger. */
    ENC_HAL_SetTriggerUpdateHoldRegCmd(base, userConfigPtr->triggerUpdateHoldRegEnable);
        
    /* Enable/disable clear position registers on input trigger. */
    ENC_HAL_SetTriggerClearPosRegCmd(base, userConfigPtr->triggerClearPosRegEnable);
    
    /* Set revolution counting type - Index pulse or Modulus counting rollover, rollunder. */
    ENC_HAL_SetModulusRevCounterCmd(base, userConfigPtr->moduloRevolutionCounting); 
        
    /* POSMATCH output control. */
    ENC_HAL_SetPosmatchOnReadingCmd(base, userConfigPtr->outputControlOnReading);
        
    /* Setting watchdog timeout. */
    if (userConfigPtr->watchdogTimeout == 0)
    {
        ENC_HAL_SetWatchdogCmd(base, false);
    }
    else
    {
        ENC_HAL_SetWatchdogCmd(base, true);
        ENC_HAL_SetWatchdogTimeout(base, userConfigPtr->watchdogTimeout);
    }
    
    /* Set Filter values. */
    ENC_HAL_SetInputFilterSampleCount(base, userConfigPtr->filterCount);
    ENC_HAL_SetInputFilterSamplePeriod(base, userConfigPtr->filterPeriod);
    
    /* Clear position difference and revolution counter. */
    ENC_HAL_SetRevolutionCounterReg(base, 0);
    ENC_HAL_SetPosDiffCounterReg(base, 0);
    ENC_HAL_SetPosCounterReg(base, 0);
    
    /* Enable ENC interrupt on NVIC level. */
    INT_SYS_EnableIRQ(g_encCmpIrqId[instance]);
    INT_SYS_EnableIRQ(g_encWdtIrqId[instance]);
    INT_SYS_EnableIRQ(g_encHomeIrqId[instance]);
    INT_SYS_EnableIRQ(g_encIndexIrqId[instance]);
    
    /* Return succes status code. */
    return kStatus_ENC_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_Deinit
 * Description   : De-initialize the Quadrature Encoder module. It will
 * shut down its clock to reduce the power consumption. 
 *
 *END**************************************************************************/
void ENC_DRV_Deinit(uint32_t instance)
{
    assert(instance < ENC_INSTANCE_COUNT);

    /* Disables Clock to Quadrature Encoder peripheral. */
    CLOCK_SYS_DisableEncClock(instance);
    
    /* Disable ENC interrupt on NVIC level. */
    INT_SYS_DisableIRQ(g_encCmpIrqId[instance]);
    INT_SYS_DisableIRQ(g_encWdtIrqId[instance]);
    INT_SYS_DisableIRQ(g_encHomeIrqId[instance]);
    INT_SYS_DisableIRQ(g_encIndexIrqId[instance]);
}
  
/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_TestInit
 * Description   : This function initializes a Test Module of ENC.
 * This function initializes the run-time state structure to enable Test Module,
 * and sets the test period and test count values.
 * This example shows how to set up the enc_test_config_t parameters and 
 * how to call the ENC_DRV_TestInit function by passing
 * in these parameters:
    enc_test_config_t encTestConfig;
    encTestConfig.testNegativeSignalEnable = false;
    encTestConfig.testCount = 100;
    encTestConfig.testPeriod = 10;
    ENC_DRV_TestInit(&encTestConfig);
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_TestInit(uint32_t instance, const enc_test_config_t * userConfigPtr)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Test structure pointer. */
    if (!userConfigPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }

    /* Enable settings of Test Module. */
    ENC_HAL_SetNegativeTestSignalCmd(base, userConfigPtr->testNegativeSignalEnable);
    ENC_HAL_SetTestPeriod(base, userConfigPtr->testPeriod);
    ENC_HAL_SetTestCount(base, userConfigPtr->testCount);
    
    /* Enable Test Module. */
    ENC_HAL_SetTestModuleCmd(base, true);
    ENC_HAL_SetTestCounterCmd(base, true);
    
    /* Return succes status code. */
    return kStatus_ENC_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_TestDeinit
 * Description   : This function shuts down the ENC test module, disable test counter
 *                 and clears the test period and test count.
 *
 *END**************************************************************************/
void ENC_DRV_TestDeinit(uint32_t instance)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
  
    /* Disable Test Module. */
    ENC_HAL_SetTestModuleCmd(base, false);
    ENC_HAL_SetTestCounterCmd(base, false);
  
    /* Clear settings of Test Module. */
    ENC_HAL_SetTestPeriod(base, 0);
    ENC_HAL_SetTestCount(base, 0);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_SetIntMode
 * Description   : This function enables any ENC interrupt.
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_SetIntMode(uint32_t instance, enc_int_source_t intSrc, bool enable)
{  
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
  
    /* Switch to relevant ENC interrupt source. */
    switch(intSrc)
    {
      /* Encoder Compare interrupt enable/disable. */
    case kEncIntCmp:
      ENC_HAL_SetCmpIntCmd(base, enable); 
      break;
      
      /* Encoder Watchdog timeout enable/disable. */
    case kEncIntWatchdogTimeout:
      ENC_HAL_SetWatchdogIntCmd(base, enable);
      break;
      
      /* Encoder Home Signal interrupt enable/disable. */
    case kEncIntHomeSignal:
      ENC_HAL_SetHomeSignalIntCmd(base, enable);
      break;
      
      /* Encoder Index Pulse interrupt enable/disable. */
    case kEncIntIndexPulse:
      ENC_HAL_SetIndexPulseIntCmd(base, enable);
      break;
      
      /* Encoder Roll-under interrupt enable/disable. */
    case kEncIntRollunder:
      ENC_HAL_SetRollunderIntCmd(base, enable);
      break;
      
      /* Encoder Roll-over interrupt enable/disable. */
    case kEncIntRollover:
      ENC_HAL_SetRolloverIntCmd(base, enable);
      break;
      
      /* Encoder Simultaneous interrupt enable/disable. */
    case kEncIntSimultaneous:
      ENC_HAL_SetSimultaneousIntCmd(base, enable);
      break;
      
      /* Default. */
    default: return kStatus_ENC_Error;
    }
    
    /* Return succes status code. */
    return kStatus_ENC_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_GetIntMode
 * Description   : This function gets configuration of any ENC interrupt.
 *
 *END**************************************************************************/
bool ENC_DRV_GetIntMode(uint32_t instance, enc_int_source_t intSrc)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    bool bRet;
  
    /* Switch to relevant ENC interrupt source. */
    switch(intSrc)
    {
      /* Encoder Compare interrupt enable/disable. */
    case kEncIntCmp:
      bRet = ENC_HAL_GetCmpIntCmd(base);
      break;
      
      /* Encoder Watchdog timeout enable/disable. */
    case kEncIntWatchdogTimeout:
      bRet = ENC_HAL_GetWatchdogIntCmd(base);
      break;
      
      /* Encoder Home Signal interrupt enable/disable. */
    case kEncIntHomeSignal:
      bRet = ENC_HAL_GetHomeSignalIntCmd(base);
      break;
      
      /* Encoder Index Pulse interrupt enable/disable. */
    case kEncIntIndexPulse:
      bRet = ENC_HAL_GetIndexPulseIntCmd(base);
      break;
      
      /* Encoder Roll-under interrupt enable/disable. */
    case kEncIntRollunder:
      bRet = ENC_HAL_GetRollunderIntCmd(base);
      break;
      
      /* Encoder Roll-over interrupt enable/disable. */
    case kEncIntRollover:
      bRet = ENC_HAL_GetRolloverIntCmd(base);
      break;
      
      /* Encoder Simultaneous interrupt enable/disable. */
    case kEncIntSimultaneous:
      bRet = ENC_HAL_GetSimultaneousIntCmd(base);
      break;
      
      /* Default. */
    default:
      bRet = false;
      break;
    }
    
    /* Return value of interrupt status. */
    return bRet;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_GetStatusFlag
 * Description   : This function gets status flag of selected status.
 *
 *END**************************************************************************/
bool ENC_DRV_GetStatusFlag(uint32_t instance, enc_status_flag_t flag)
{
    assert(instance < ENC_INSTANCE_COUNT);
    ENC_Type* base = g_encBase[instance];
    bool bRet;
    
    /* Switch to relevant ENC interrupt source. */
    switch(flag)
    {
      /* Encoder Compare interrupt flag. */
    case kEncCmpFlag:
      bRet = ENC_HAL_GetCmpIntFlag(base);
      break;
      
      /* Encoder Watchdog timeout flag. */
    case kEncWatchdogTimeoutFlag:
      bRet = ENC_HAL_GetWatchdogIntFlag(base);
      break;
      
      /* Encoder Home Signal interrupt flag. */
    case kEncHomeSignalFlag:
      bRet = ENC_HAL_GetHomeSignalIntFlag(base);
      break;
      
      /* Encoder Index Pulse interrupt flag. */
    case kEncIndexPulseFlag:
      bRet = ENC_HAL_GetIndexPulseIntFlag(base);
      break;
      
      /* Encoder Roll-under interrupt flag. */
    case kEncRollunderFlag:
      bRet = ENC_HAL_GetRollunderIntFlag(base);
      break;
      
      /* Encoder Roll-over interrupt flag. */
    case kEncRolloverFlag:
      bRet = ENC_HAL_GetRolloverIntFlag(base);
      break;
      
      /* Encoder Simultaneous interrupt flag. */
    case kEncSimultaneousFlag:
      bRet = ENC_HAL_GetSimultaneousIntFlag(base);
      break;
      
      /* Encoder last count direction flag. */
    case kEncCountDirectionFlag:
      bRet = ENC_HAL_GetLastCountDirectionFlag(base);
      break;
      
    default: 
      bRet = false;
      break;
    }
    
    /* Return value of interrupt status flag. */
    return bRet;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_ClearStatusFlag
 * Description   : This function clears status flag of selected status.
 *
 *END**************************************************************************/
void ENC_DRV_ClearStatusFlag(uint32_t instance, enc_status_flag_t flag)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Switch to relevant ENC interrupt source. */
    switch(flag)
    {
      /* Encoder Compare interrupt flag. */
    case kEncCmpFlag:
      ENC_HAL_ClearCmpIntFlag(base); 
      break;
      
      /* Encoder Watchdog timeout flag. */
    case kEncWatchdogTimeoutFlag:
      ENC_HAL_ClearWatchdogIntFlag(base);
      break;
      
      /* Encoder Home Signal interrupt flag. */
    case kEncHomeSignalFlag:
      ENC_HAL_ClearHomeSignalIntFlag(base);
      break;
      
      /* Encoder Index Pulse interrupt flag. */
    case kEncIndexPulseFlag:
      ENC_HAL_ClearIndexPulseIntFlag(base);
      break;
      
      /* Encoder Roll-under interrupt flag. */
    case kEncRollunderFlag:
      ENC_HAL_ClearRollunderIntFlag(base);
      break;
      
      /* Encoder Roll-over interrupt flag. */
    case kEncRolloverFlag:
      ENC_HAL_ClearRolloverIntFlag(base);
      break;
      
      /* Encoder Simultaneous interrupt flag. */
    case kEncSimultaneousFlag:
      ENC_HAL_ClearSimultaneousIntFlag(base);
      break;
      
    default: 
      break;
    }
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_ReadCounters
 * Description   : This function reads the ENC Registers of Counters.
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_ReadCounters(uint32_t instance, enc_counter_t * countRegPtr)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Test structure pointer. */
    if (!countRegPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }
  
    /* At first read position difference COUNTER register. */
    countRegPtr->posDiff = ENC_HAL_GetPosDiffCounterReg(base);
    
    /* Other counter registers are automatically triggered to HOLD registers. */
    countRegPtr->position = ENC_HAL_GetPosHoldReg(base);
    countRegPtr->revolution = ENC_HAL_GetRevolutionHoldReg(base);
    
    /* Return succes status code. */
    return kStatus_ENC_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_ReadHoldReg
 * Description   : This function reads the ENC Hold Registers of counters.
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_ReadHoldReg(uint32_t instance, enc_counter_t * holdRegPtr)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Test structure pointer. */
    if (!holdRegPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }
  
    /* Read Hold registers. */
    holdRegPtr->position = ENC_HAL_GetPosHoldReg(base);
    holdRegPtr->posDiff = ENC_HAL_GetPosDiffHoldReg(base);
    holdRegPtr->revolution = ENC_HAL_GetRevolutionHoldReg(base);
    
    /* Return succes status code. */
    return kStatus_ENC_Success;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_ResetCounters
 * Description   : This function resets the ENC Position registers.
 *
 *END**************************************************************************/
void ENC_DRV_ResetCounters(uint32_t instance)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Re-init position counter. */
    ENC_HAL_InitPosCounter(base);
    
    /* Clear position difference and revolution counter. */
    ENC_HAL_SetRevolutionCounterReg(base, 0);
    ENC_HAL_SetPosDiffCounterReg(base, 0);
}

/*FUNCTION**********************************************************************
 *
 * Function Name : ENC_DRV_ReadInputMonitor
 * Description   : This function reads the ENC Input Monitor register.
 *
 *END**************************************************************************/
enc_status_t ENC_DRV_ReadInputMonitor
  (uint32_t instance, bool inputMonitorRaw, enc_input_monitor_t * inputMonitorPtr)
{
    assert(instance < ENC_INSTANCE_COUNT); 
    ENC_Type* base = g_encBase[instance];
    
    /* Test structure pointer. */
    if (!inputMonitorPtr)
    {
        return kStatus_ENC_InvalidArgument;
    }
    
    /* Switch to raw or filtered type of input monitor. */
    if (inputMonitorRaw)
    {
        /* Get raw inputs. */
        inputMonitorPtr->phaseA = ENC_HAL_GetRawPhaseAInput(base);
        inputMonitorPtr->phaseB = ENC_HAL_GetRawPhaseBInput(base);
        inputMonitorPtr->index = ENC_HAL_GetRawIndexInput(base);
        inputMonitorPtr->home = ENC_HAL_GetRawHomeInput(base);
    }
    else
    {
        /* Get filtered inputs. */
        inputMonitorPtr->phaseA = ENC_HAL_GetFilteredPhaseAInput(base);
        inputMonitorPtr->phaseB = ENC_HAL_GetFilteredPhaseBInput(base);
        inputMonitorPtr->index = ENC_HAL_GetFilteredIndexInput(base);
        inputMonitorPtr->home = ENC_HAL_GetFilteredHomeInput(base);
    }

    /* Return succes status code. */
    return kStatus_ENC_Success;
}
#endif

/*******************************************************************************
 * EOF
 ******************************************************************************/