DSP2803x_CpuTimers.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_CpuTimers.h
  4. //
  5. // TITLE: DSP2803x CPU 32-bit Timers Register Definitions.
  6. //
  7. //
  8. //###########################################################################
  9. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  10. // $Release Date: May 8, 2015 $
  11. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  12. // http://www.ti.com/ ALL RIGHTS RESERVED $
  13. //###########################################################################
  14. #ifndef DSP2803x_CPU_TIMERS_H
  15. #define DSP2803x_CPU_TIMERS_H
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //---------------------------------------------------------------------------
  20. // CPU Timer Register Bit Definitions:
  21. //
  22. //
  23. // TCR: Control register bit definitions:
  24. struct TCR_BITS { // bits description
  25. Uint16 rsvd1:4; // 3:0 reserved
  26. Uint16 TSS:1; // 4 Timer Start/Stop
  27. Uint16 TRB:1; // 5 Timer reload
  28. Uint16 rsvd2:4; // 9:6 reserved
  29. Uint16 SOFT:1; // 10 Emulation modes
  30. Uint16 FREE:1; // 11
  31. Uint16 rsvd3:2; // 12:13 reserved
  32. Uint16 TIE:1; // 14 Output enable
  33. Uint16 TIF:1; // 15 Interrupt flag
  34. };
  35. union TCR_REG {
  36. Uint16 all;
  37. struct TCR_BITS bit;
  38. };
  39. // TPR: Pre-scale low bit definitions:
  40. struct TPR_BITS { // bits description
  41. Uint16 TDDR:8; // 7:0 Divide-down low
  42. Uint16 PSC:8; // 15:8 Prescale counter low
  43. };
  44. union TPR_REG {
  45. Uint16 all;
  46. struct TPR_BITS bit;
  47. };
  48. // TPRH: Pre-scale high bit definitions:
  49. struct TPRH_BITS { // bits description
  50. Uint16 TDDRH:8; // 7:0 Divide-down high
  51. Uint16 PSCH:8; // 15:8 Prescale counter high
  52. };
  53. union TPRH_REG {
  54. Uint16 all;
  55. struct TPRH_BITS bit;
  56. };
  57. // TIM, TIMH: Timer register definitions:
  58. struct TIM_REG {
  59. Uint16 LSW;
  60. Uint16 MSW;
  61. };
  62. union TIM_GROUP {
  63. Uint32 all;
  64. struct TIM_REG half;
  65. };
  66. // PRD, PRDH: Period register definitions:
  67. struct PRD_REG {
  68. Uint16 LSW;
  69. Uint16 MSW;
  70. };
  71. union PRD_GROUP {
  72. Uint32 all;
  73. struct PRD_REG half;
  74. };
  75. //---------------------------------------------------------------------------
  76. // CPU Timer Register File:
  77. //
  78. struct CPUTIMER_REGS {
  79. union TIM_GROUP TIM; // Timer counter register
  80. union PRD_GROUP PRD; // Period register
  81. union TCR_REG TCR; // Timer control register
  82. Uint16 rsvd1; // reserved
  83. union TPR_REG TPR; // Timer pre-scale low
  84. union TPRH_REG TPRH; // Timer pre-scale high
  85. };
  86. //---------------------------------------------------------------------------
  87. // CPU Timer Support Variables:
  88. //
  89. struct CPUTIMER_VARS {
  90. volatile struct CPUTIMER_REGS *RegsAddr;
  91. Uint32 InterruptCount;
  92. float CPUFreqInMHz;
  93. float PeriodInUSec;
  94. };
  95. //---------------------------------------------------------------------------
  96. // Function prototypes and external definitions:
  97. //
  98. void InitCpuTimers(void);
  99. void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period);
  100. extern volatile struct CPUTIMER_REGS CpuTimer0Regs;
  101. extern struct CPUTIMER_VARS CpuTimer0;
  102. extern volatile struct CPUTIMER_REGS CpuTimer1Regs;
  103. extern volatile struct CPUTIMER_REGS CpuTimer2Regs;
  104. extern struct CPUTIMER_VARS CpuTimer1;
  105. extern struct CPUTIMER_VARS CpuTimer2;
  106. //---------------------------------------------------------------------------
  107. // Usefull Timer Operations:
  108. //
  109. // Start Timer:
  110. #define StartCpuTimer0() CpuTimer0Regs.TCR.bit.TSS = 0
  111. // Stop Timer:
  112. #define StopCpuTimer0() CpuTimer0Regs.TCR.bit.TSS = 1
  113. // Reload Timer With period Value:
  114. #define ReloadCpuTimer0() CpuTimer0Regs.TCR.bit.TRB = 1
  115. // Read 32-Bit Timer Value:
  116. #define ReadCpuTimer0Counter() CpuTimer0Regs.TIM.all
  117. // Read 32-Bit Period Value:
  118. #define ReadCpuTimer0Period() CpuTimer0Regs.PRD.all
  119. // Start Timer:
  120. #define StartCpuTimer1() CpuTimer1Regs.TCR.bit.TSS = 0
  121. #define StartCpuTimer2() CpuTimer2Regs.TCR.bit.TSS = 0
  122. // Stop Timer:
  123. #define StopCpuTimer1() CpuTimer1Regs.TCR.bit.TSS = 1
  124. #define StopCpuTimer2() CpuTimer2Regs.TCR.bit.TSS = 1
  125. // Reload Timer With period Value:
  126. #define ReloadCpuTimer1() CpuTimer1Regs.TCR.bit.TRB = 1
  127. #define ReloadCpuTimer2() CpuTimer2Regs.TCR.bit.TRB = 1
  128. // Read 32-Bit Timer Value:
  129. #define ReadCpuTimer1Counter() CpuTimer1Regs.TIM.all
  130. #define ReadCpuTimer2Counter() CpuTimer2Regs.TIM.all
  131. // Read 32-Bit Period Value:
  132. #define ReadCpuTimer1Period() CpuTimer1Regs.PRD.all
  133. #define ReadCpuTimer2Period() CpuTimer2Regs.PRD.all
  134. #ifdef __cplusplus
  135. }
  136. #endif /* extern "C" */
  137. #endif // end of DSP2803x_CPU_TIMERS_H definition
  138. //===========================================================================
  139. // End of file.
  140. //===========================================================================