r_tauj_api.h 26.5 KB
Newer Older
hu's avatar
hu committed
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 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
/*
****************************************************************************
PROJECT : TAUJ driver
FILE    : $Id: r_tauj_api.h 7640 2016-02-12 13:14:23Z florian.zimmermann $
============================================================================ 
DESCRIPTION
Driver for TAUJ macro
============================================================================
                            C O P Y R I G H T
============================================================================
                       Copyright (c) 2013 - 2014
                                  by 
                       Renesas Electronics (Europe) GmbH. 
                           Arcadiastrasse 10
                          D-40472 Duesseldorf
                               Germany
                          All rights reserved.
============================================================================
Purpose: only for testing, not for mass production

DISCLAIMER

LICENSEE has read, understood and accepted the terms and conditions defined in
the license agreement, especially the usage rights. In any case, it is
LICENSEE's responsibility to make sure that any user of the software complies
with the terms and conditions of the signed license agreement.

SAMPLE CODE is not part of the licensed software, as such it must not be used in
mass-production applications. It can only be used for evaluation and
demonstration purposes at customer's premises listed in the signed license
agreement.

****************************************************************************
*/


#ifndef R_TAUJ_API_H_
#define R_TAUJ_API_H_


/***********************************************************
  Title: TAUJ API

  An application using the TAUJ should include this header file.

  General information:
  The TAUJ macro provides comprehensive timer functionalty for devices.
  There are 4 channels which can be set to a variety of modes including:
    - Interval timer function
    - TINn input pulse interval measurement function
    - TINn input interval timer function
    - TINn input signal width measurement function
    - Overflow interrupt output function (during TINn
      width measurement)
    - TINn input position detection function
    - TINn input period count detection function
    - Overflow interrupt output function (during TINn
      input period count detection)
    - PWM output function

    The are also 4 independent clocks available which can be set to a variety of
    frequencies and each timer channel can be assigned to one of these.

    The channels can also be linked in a series of master and slave
    configurations i.e. allowing the output of one channel to trigger
    another.
*/


/***********************************************************
  Section: Global Types
*/


/* option to use SVSTOP */
#define LOC_USE_SVSTOP        (0x0000)
#define LOC_DO_NOT_USE_SVSTOP (0x0080)

#define LOC_SVSTOP           (LOC_USE_SVSTOP)


/***********************************************************
  Enum: r_tauj_Error_t

  TAUJ macro driver error code.

  Values:
  R_TAUJ_ERR_OK                - No error
  R_TAUJ_ERR_INVALID_MODE      - option not allowed in this mode
  R_TAUJ_ERR_RANGE             - Unspecified error
  R_TAUJ_ERR_INSTANCE          - Unit, instance not supported
  R_TAUJ_ERR_PORTINIT          - port init failed
  R_TAUJ_ERR_REG_UPDATE_FAIL   - register update failed
  R_TAUJ_ERR_LAST              - Delimeter
*/

typedef enum {
    R_TAUJ_ERR_OK           = 0x00,
    R_TAUJ_ERR_INVALID_MODE = 0x01,
    R_TAUJ_ERR_RANGE        = 0x02,
    R_TAUJ_ERR_INSTANCE     = 0x03,
    R_TAUJ_ERR_PORTINIT,
    R_TAUJ_ERR_REG_UPDATE_FAIL,
    R_TAUJ_ERR_LAST
} r_tauj_Error_t;


/***********************************************************
  Enum: r_tauj_Interrupt_t

  TAUJ macro interrupt type. List of all available interrupts for this macro

  Values:
    R_TAUJ_INT_CH0-3  - General purpose interrupt
    R_TAUJ_INT_NUM    - Max number of interrupt channels, delimiter
*/

typedef enum {
    R_TAUJ_INT_CH0 = 0,
    R_TAUJ_INT_CH1,
    R_TAUJ_INT_CH2,
    R_TAUJ_INT_CH3,
    R_TAUJ_INT_NUM   /* delimiter */
} r_tauj_Interrupt_t;


/***********************************************************
  Enum: r_tauj_Mode_t

  TAUJ macro mode type, this set the mode for each channel.

  Values:
    R_TAUJ_INTERVAL_TIMER_MODE             - Interval timer mode
    R_TAUJ_RFU_JUDGE_MODE                  - RFU judge mode
    R_TAUJ_CAPTURE_MODE                    - capture mode
    R_TAUJ_RFU_EVENT_COUNT_MODE            - RFU event count mode
    R_TAUJ_ONE_COUNT_MODE                  - One count mode
    R_TAUJ_RFU_TRIGGER_START_MODE          - RFU trigger start mode
    R_TAUJ_CAPTURE_ONE_COUNT_MODE          - Capture one count mode
    R_TAUJ_RFU_JUDGE_ONE_COUNT_MODE        - RFU judge one count mode
    R_TAUJ_RFU_INTERVAL_ONE_COUNT_MODE     - RFU interval one count mode
    R_TAUJ_RFU_UP_DOWN_COUNT_MODE          - RFU up/down count mode
    R_TAUJ_RFU_PULSE_ONE_COUNT_MODE        - RFU pule one count mode
    R_TAUJ_COUNT_CAPTURE_MODE              - Count capture moe
    R_TAUJ_GATE_COUNT_MODE                 - Gate count mode
    R_TAUJ_CAPTURE_GATE_COUNT_MODE         - Capture gate count mode
*/

typedef enum {
    R_TAUJ_INTERVAL_TIMER_MODE = 0,
    R_TAUJ_RFU_JUDGE_MODE,
    R_TAUJ_CAPTURE_MODE,
    R_TAUJ_RFU_EVENT_COUNT_MODE,
    R_TAUJ_ONE_COUNT_MODE,
    R_TAUJ_RFU_TRIGGER_START_MODE,
    R_TAUJ_CAPTURE_ONE_COUNT_MODE,
    R_TAUJ_RFU_JUDGE_ONE_COUNT_MODE,
    R_TAUJ_RFU_INTERVAL_ONE_COUNT_MODE,
    R_TAUJ_RFU_UP_DOWN_COUNT_MODE,
    R_TAUJ_RFU_PULSE_ONE_COUNT_MODE,
    R_TAUJ_COUNT_CAPTURE_MODE,
    R_TAUJ_GATE_COUNT_MODE,
    R_TAUJ_CAPTURE_GATE_COUNT_MODE
} r_tauj_Mode_t;


/***********************************************************
  Enum: r_tauj_Trigger_t

  TAUJ macro trigger type, this set the trigger source for each channel (CMOR).

  Values:
    R_TAUJ_NONE                   - Valid only in software trigger start (Deselect other trigger sources)
    R_TAUJ_VALID_EDGE_TIN         - Selects the valid-edge-detected TINn input signal. (Select the TINn 
                                     valid edge, using CMURn:TIS1 and TIS0
    R_TAUJ_VALID_EITHER_TIN       - Selects the valid-edge-detected TINn input signal as a start signal, and the
                                     reverse-edge-detected TINn input signal as a stop signal (capture signal)
                                     (Sets both rising and falling edges as the valid edge using CMURn:TIS1 and TIS0
    R_TAUJ_START_TRIG_FROM_MASTER - RFU (Selects the start trigger signal of the master channel 
    
    R_TAUJ_INT_FROM_MASTER        - Selects the INTn output signal of the master channel
    R_TAUJ_INT_FROM_UPPER         - Selects the INTn output signal of the upper channel, regardless of the 
                                     setting of the master
    R_TAUJ_TOUT_DEAD_TIME         - Selects the dead-time control trigger signal of the TOUTn generation unit
    R_TAUJ_UP_DOWN_FROM_MASTER    - Selects the up/down control trigger signal of the master channel       
*/

typedef enum {
    R_TAUJ_NONE = 0,             
    R_TAUJ_VALID_EDGE_TIN,            
    R_TAUJ_VALID_EITHER_TIN,                                 
    R_TAUJ_RFU_START_TRIG_FROM_MASTER,     
    R_TAUJ_INT_FROM_MASTER,       
    R_TAUJ_RFU_INT_FROM_UPPER,               
    R_TAUJ_RFU_TOUT_DEAD_TIME,        
    R_TAUJ_RFU_UP_DOWN_FROM_MASTER
} r_tauj_Trigger_t;


/***********************************************************
  Enum: r_tauj_TimeInterval_t

  TAUJ macro time interval selection for the CK0-3.  The period
  depends on the clock freguency selected externally and will
  further divide the frequency by the factor below.

  i.e. assume clock is 100MHz externally
         100MHz / 2^9 about 195.3KHz about 5.12us
             100MHz / 2^16 about 1.525KHz about 0.6ms

  Configuration parameter for  interval.

  Values:

  R_TAUJ_TIME_INTERVAL_0   - time interval 2^0
  R_TAUJ_TIME_INTERVAL_1   - time interval 2^1
  R_TAUJ_TIME_INTERVAL_2   - time interval 2^2
  R_TAUJ_TIME_INTERVAL_3   - time interval 2^3
  R_TAUJ_TIME_INTERVAL_4   - time interval 2^4
  R_TAUJ_TIME_INTERVAL_5   - time interval 2^5
  R_TAUJ_TIME_INTERVAL_6   - time interval 2^6
  R_TAUJ_TIME_INTERVAL_7   - time interval 2^7
  R_TAUJ_TIME_INTERVAL_8   - time interval 2^8
  R_TAUJ_TIME_INTERVAL_8   - time interval 2^9 
  R_TAUJ_TIME_INTERVAL_10  - time interval 2^10
  R_TAUJ_TIME_INTERVAL_11  - time interval 2^11
  R_TAUJ_TIME_INTERVAL_12  - time interval 2^12
  R_TAUJ_TIME_INTERVAL_13  - time interval 2^13
  R_TAUJ_TIME_INTERVAL_14  - time interval 2^14
  R_TAUJ_TIME_INTERVAL_15  - time interval 2^15
*/

typedef enum {
    R_TAUJ_TIME_INTERVAL_0 = 0,
    R_TAUJ_TIME_INTERVAL_1,
    R_TAUJ_TIME_INTERVAL_2,
    R_TAUJ_TIME_INTERVAL_3,
    R_TAUJ_TIME_INTERVAL_4,
    R_TAUJ_TIME_INTERVAL_5,
    R_TAUJ_TIME_INTERVAL_6,
    R_TAUJ_TIME_INTERVAL_7,
    R_TAUJ_TIME_INTERVAL_8,       
    R_TAUJ_TIME_INTERVAL_9,
    R_TAUJ_TIME_INTERVAL_10,
    R_TAUJ_TIME_INTERVAL_11,
    R_TAUJ_TIME_INTERVAL_12,
    R_TAUJ_TIME_INTERVAL_13,
    R_TAUJ_TIME_INTERVAL_14,
    R_TAUJ_TIME_INTERVAL_15
} r_tauj_TimeInterval_t;


/***********************************************************
  Enum: r_tauj_Channel_t

  TAUJ channel selection 0 to xx

  Values:
  R_TAUJ_CHANNEL_0        - Channel 0
  R_TAUJ_CHANNEL_1        - Channel 1
  R_TAUJ_CHANNEL_2        - Channel 2
  R_TAUJ_CHANNEL_3        - Channel 3   
  R_TAUJ_CHANNEL_ALL      - option to combine all the channels
*/

typedef enum {
  R_TAUJ_CHANNEL_0   = 0,
  R_TAUJ_CHANNEL_1   = 1u,
  R_TAUJ_CHANNEL_2   = 2u,
  R_TAUJ_CHANNEL_3   = 3u,
  R_TAUJ_CHANNEL_ALL = 4u
} r_tauj_Channel_t;

/* 4 timer channels */
#define R_TAUJ_NUM_CHANNELS (4u)


/***********************************************************
  Enum: r_tauj_Clock_t

  TAUJ clock selection 0 to 3

  Values:
  R_TAUJ_CK_0        - CK0
  R_TAUJ_CK_1        - CK1
  R_TAUJ_CK_2        - CK2
  R_TAUJ_CK_3        - CK3
*/

typedef enum {
  R_TAUJ_CK_0 = 0,
  R_TAUJ_CK_1,
  R_TAUJ_CK_2,
  R_TAUJ_CK_3
} r_tauj_Clock_t;


/***********************************************************
  Enum: r_tauj_CountClock_t

  TAUJ count clock selection

  Values:
  R_TAUJ_COUNT_CLK_PRESCALER       - clock pre-scaler
  R_TAUJ_COUNT_CLK_TIN             - Tin clock
  R_TAUJ_COUNT_CLK_RFU             - RFU clock
  R_TAUJ_COUNT_CLK_MASTER_INT_RFU  - clock master RFU
*/

typedef enum {
  R_TAUJ_COUNT_CLK_PRESCALER = 0,
  R_TAUJ_COUNT_CLK_TIN,
  R_TAUJ_COUNT_CLK_RFU,
  R_TAUJ_COUNT_CLK_MASTER_INT_RFU
} r_tauj_CountClock_t;


/***********************************************************
  Enum: r_tauj_TinEdge_t

  TAUJ TIN edge selection

  Values:
  R_TAUJ_FALLING_EDGE      - falling edge
  R_TAUJ_RISING_EDGE       - rising edge
  R_TAUJ_BOTH_LOW_WIDTH    - both low width
  R_TAUJ_BOTH_HIGH_WIDTH   - both high width

*/

typedef enum {
  R_TAUJ_FALLING_EDGE = 0,
  R_TAUJ_RISING_EDGE,
  R_TAUJ_BOTH_LOW_WIDTH,
  R_TAUJ_BOTH_HIGH_WIDTH
} r_tauj_TinEdge_t;


/***********************************************************
  Enum: r_tauj_Overflow_t

  TAUJ TIN overflow selection (COSC)

  Values:
  
  R_TAUJ_OVERFLOW_OPTION_0 - Captures the OVF and counter values upon detection of a valid edge of capture input.

  R_TAUJ_OVERFLOW_OPTION_1 - Sets OVF when the counter overflows (FFFFH ? 0000H).
                              Captures the counter value upon detection of a valid edge of capture input.

  R_TAUJ_OVERFLOW_OPTION_2 - Captures the OVF value upon detection of a valid edge of capture input.
                              Captures FFFFH and stores it to CDRn when the counter overflows (FFFFH ? 0000H).
                              The valid edge of the capture input detected the next time is ignored.

  R_TAUJ_OVERFLOW_OPTION_3 - Sets OVF when the counter overflows (FFFFH ? 0000H) and captures FFFFH and stores it
                              to CDRn.
                              The valid edge of the capture input detected the next time is ignored.
*/

typedef enum {
  R_TAUJ_OVERFLOW_OPTION_0 = 0,
  R_TAUJ_OVERFLOW_OPTION_1,
  R_TAUJ_OVERFLOW_OPTION_2,
  R_TAUJ_OVERFLOW_OPTION_3
} r_tauj_Overflow_t;


/***********************************************************
  Enum: r_tauj_SimultaneousTrigger_t

  TAUJ simultaneous rewrite mode

  Values:
  R_TAUJ_FROM_MASTER - Controls simultaneous rewrite of the data register by 
                        using the signal of master channel
  R_TAUJ_FROM_UPPER  - Controls simultaneous rewrite of the data register by 
                        using the signal of another upper channel
*/

typedef enum {
  R_TAUJ_FROM_MASTER = 0,
  R_TAUJ_FROM_UPPER
} r_tauj_SimultaneousTrigger_t;

/***********************************************************
  Section: Global Functions
  
*/

/***********************************************************
  Function: R_TAUJ_Init

  Driver init function. Provides a complete initialization of the TAUJ.

  Parameters:
  Unit       - Instance number

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_Init(uint32_t Unit);


/***********************************************************
  Function: R_TAUJ_InitChannel

  Initialisation function for TAUJ channel. Provides a complete initialization of one of
  the TAUJ Channels.

  Parameters:
  Unit             - Instance number
  Channel          - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_InitChannel(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_SetClockPeriod

  Set the timer period for one of the four channel clocks CK0-3.

  Parameters:
  Unit          - Instance number
  int           - TAUJ clock <r_tauj_Clock_t>
  TimeInterval  - TAUJ time interval <r_tauj_TimeInterval_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetClockPeriod(uint32_t Unit, r_tauj_Clock_t Clock, r_tauj_TimeInterval_t TimeInterval);


/***********************************************************
  Function: R_TAUJ_SetCK3BaudRateClock

  Set the timer period for the CK3 channel clocks CK0-3.

  Parameters:
  Unit       - Instance number
  Period     - TAUJ baud rate clock divisor, range is 0 - 255

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetCK3BaudRateClock(uint32_t Unit, uint8_t Period);


/***********************************************************
  Function: R_TAUJ_SetClkSource

  Set the clock source for a TAUJ channel can be either CK0-3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Clock      - TAUJ clock <r_tauj_Clock_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetClkSource(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_Clock_t Clock);


/***********************************************************
  Function: R_TAUJ_SetMode

  Set the mode for a TAUJ channel 0-3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Mode       - TAUJ Mode <r_tauj_Mode_t>

   Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetMode(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_Mode_t Mode);


/***********************************************************
  Function: R_TAUJ_SetCaptureOverflow

  Set the Capture overflow option for a TAUJ channel 0-3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Overflow   - TAUJ Mode <r_tauj_Overflow_t>

   Returns:
  see: <r_tauj_Overflow_t>
*/

r_tauj_Error_t R_TAUJ_SetCaptureOverflow(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_Overflow_t Overflow);


/***********************************************************
  Function: R_TAUJ_SetIntAtStartUp

  Enables the INT at startup, bit MD0 in the CMOR.

  Parameters:
  Unit          - Instance number
  Channel       - TAUJ channel number <r_tauj_Channel_t>
  IntAtStartUp  - TRUE enable int at start up, FALSE do not

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_EnableIntAtStartUp(uint32_t Unit, r_tauj_Channel_t Channel, uint8_t IntAtStartUp);


/***********************************************************
  Function: R_TAUJ_SetMaster

  Set the mode for a TAUJ channel 0 to 3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Master     - Sets either a Master channel (TRUE) or Slave (FALSE)

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetMaster(uint32_t Unit, r_tauj_Channel_t Channel, uint8_t Master);


/***********************************************************
  Function: R_TAUJ_SetTrigger

  Set the trigger source for a TAUJ channel 0 to 3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Trigger    - see <r_tauj_Trigger_t> 

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetTrigger(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_Trigger_t Trigger);


/***********************************************************
  Function: R_TAUJ_ClearOverflow

  Clear the overflow flag for a channel.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_ClearOverflow(uint32_t Unit, r_tauj_Channel_t Channel);

/***********************************************************
  Function: R_TAUJ_EnableSimultaneousRewrite
  
  Set the trigger source for a TAUJ channel 0 to 3.

  Parameters:
  Unit                      - Instance number
  Channel                   - TAUJ channel number <r_tauj_Channel_t>
  SimultaneousTriggerSource - see <r_tauj_SimultaneousTrigger_t> 

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_EnableSimultaneousRewrite(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_SimultaneousTrigger_t SimultaneousTriggerSource);


/***********************************************************
  Function: R_TAUJ_EnableSynchronousChannelOperation
  
  Enables Synchronous Channel Operation for a TAUJ channel 0 to 3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>


  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_EnableSynchronousChannelOperation(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_SetCountClock

  Set the count clock source for a TAUJ channel 0 to 3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  CountClock - see <r_tauj_CountClock_t> 

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetCountClock(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_CountClock_t CountClock);


/***********************************************************
  Function: R_TAUJ_SetTinEdge

  Set the edge for the TIN detection TAUJ channel 0 to 3.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  CountClock - see <r_tauj_TinEdge_t> 

  Returns:
  see: <r_tauj_Error_t>
*/

 r_tauj_Error_t R_TAUJ_SetTinEdge(uint32_t Unit, r_tauj_Channel_t Channel, r_tauj_TinEdge_t Edge);


/***********************************************************
  Function: R_TAUJ_SetPeriod

  Set the period for the channel counter, this is used for the CDR this is
  effectivety a count value for the CDR register.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Period     - TAUJ count period

  Returns:
  see: <r_tauj_Error_t>
*/

 r_tauj_Error_t R_TAUJ_SetPeriod(uint32_t Unit, r_tauj_Channel_t Channel, uint32_t Period);


/***********************************************************
  Function: R_TAUJ_Start

  Starts the selected timer channel.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_Start(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_Stop

  Stops the selected timer channel.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_Stop(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_OutputEnable

  Enables the selected timer channel output enable pin for use
  with the count operation.  

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_OutputEnable(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_OutputWrite

  Writes the specified value to the timer output. For use with
  Independent Channel Output Mode Controlled by Software.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>
  Value      - Value to write to the output

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_OutputWrite(uint32_t Unit, r_tauj_Channel_t Channel, uint8_t Value);


/***********************************************************
  Function: R_TAUJ_OutputDisable

  Disables the selected timer channel output enable pin for use
  with the count operation.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_OutputDisable(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_Disable

  Disables the selected timer channel.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_Disable(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_SetInvertOutputTOUT

  Invert the output of the TOUTn pin.

  Parameters:
  Unit          - Instance number
  Channel       - TAUJ channel number <r_tauj_Channel_t>
  InvertOutput  - TRUE invert output, FALSE normal no invert

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_SetInvertOutputTOUT(uint32_t Unit, r_tauj_Channel_t Channel, uint8_t InvertOutput);


/***********************************************************
  Function: R_TAUJ_ReloadDataTrigger

  specifies the channel for which simultaneous rewrite is executed

  Parameters:
  Unit          - Instance number
  Channel       - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  see: <r_tauj_Error_t>
*/

r_tauj_Error_t R_TAUJ_ReloadDataTrigger(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_GetCaptureData

  Retrevies the data count value in the CDR register.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  uint32_t   - CDR register value
*/

uint32_t R_TAUJ_GetCaptureData(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_GetCntData
   Retrevies the data count value in the CNT register.

  Parameters:
  Unit       - Instance number
  Channel    - TAUJ channel number <r_tauj_Channel_t>

  Returns:
  uint32_t   - CNT register value
*/

uint32_t R_TAUJ_GetCntData(uint32_t Unit, r_tauj_Channel_t Channel);


/***********************************************************
  Function: R_TAUJ_ReadReg

  Retrevies the value in one the TAUJ registers.

  Parameters:
  Unit       - Instance number
  Offset     - Register offset

  Returns:
  see: <r_tauj_Error_t>
*/

 uint16_t R_TAUJ_ReadReg(uint32_t Unit, uint32_t Offset);


/***********************************************************
  Function: R_TAUJ_WriteReg

  Writes the value in one the TAUJ registers.

  Parameters:
  Unit       - Instance number
  Offset     - Register offset
  Data       - Data to write

  Returns:
  none
*/

 void R_TAUJ_WriteReg(uint32_t Unit, uint32_t Offset, uint16_t Data);


/***********************************************************
  Function: R_TAUJ_SetErrorCallback

  Set a user function as an the error handler.

  Parameters:
  *ErrorHandler - a pointer to a user function (callback)
                  with two paramerters (unit and error number)

  Returns:
  void

*/

 void R_TAUJ_SetErrorCallback(void ( *ErrorCallback )(uint32_t Unit, uint32_t Error));


/***********************************************************
  Function: R_TAUJ_SetIsrCallback

  Assign a user callback for the given interrupt of a unit.

  The function will be called after the driver ISR has
  processed the interrupt.

  Parameters:
  Unit          - Instance number
  IntType       - type of interrupt; see: <r_tauj_Interrupt_t>
  Isr           - Isr function pointer

  Returns:
  see: <r_tauj_Error_t>
*/

 r_tauj_Error_t R_TAUJ_SetIsrCallback(uint32_t Unit, r_tauj_Interrupt_t IntType,
                                 void (*Isr)(void));


/***********************************************************
  Function: R_TAUJ_Isr

  Driver interrupt service routine. 
  
  This function shall be called by sevice interrupt handler 

  Parameters:
  Unit       - Instance number
  Interrupt  - channel interrupt
  
  Returns:
  void
*/

 void R_TAUJ_Isr(uint32_t Unit, r_tauj_Interrupt_t Interrupt);


/***********************************************************
  Function: R_TAUJ_EnableInt

  Enable interrupt 'Id'.
  
  Parameters:
  Unit       - Unit number of TAUJ in device
  Interrupt  - Identifier of interrupt
    
  Returns:
  void
*/
 r_tauj_Error_t R_TAUJ_EnableInt(uint32_t Unit, r_tauj_Interrupt_t Interrupt);


/***********************************************************
  Function: R_TAUJ_DisableInt

  Disable interrupt 'Id'.
  
  Parameters:
  Unit       - Unit number of TAUJ in device
  Interrupt  - Identifier of interrupt
    
  Returns:
  void
*/
 r_tauj_Error_t R_TAUJ_DisableInt(uint32_t Unit, r_tauj_Interrupt_t Interrupt);


/***********************************************************
  Function: R_TAUJ_PortInit

  Initialise the port

  Parameters:
  None

  Returns:
  void

*/

 void R_TAUJ_PortInit(void);



/***********************************************************
  Function: R_TAUJ_GetClock

  Gets the clock for the selected TauJ unit

  Parameters:
  Unit         - TAUJ instance number

  Returns:
  clock frequency

*/
 uint32_t R_TAUJ_GetClock(uint32_t Unit);


/***********************************************************
  Function: R_TAUJ_SetFilterBypass

  Sets the filter bypass for the selected TauJ unit

  Parameters:
  Unit      - TAUJ isntance number
  ID        - clock domain Clock Selector ID
  
  Returns:
  0            - TAUJ unit in range
  1            - TAUJ unit out of range

*/
 uint32_t R_TAUJ_SetFilterBypass(uint32_t Unit);

#endif /* R_TAUJ_API_H_  */