xos_regaccess.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // xos_regaccess.h - Access routines for various processor special registers.
  2. // Copyright (c) 2003-2015 Cadence Design Systems, Inc.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included
  13. // in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #ifndef __REGACCESS_H__
  23. #define __REGACCESS_H__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include "xos_types.h"
  28. #include <xtensa/config/core.h>
  29. #if defined (__XCC__)
  30. #if XCHAL_HAVE_CCOUNT
  31. #include <xtensa/tie/xt_timer.h>
  32. #endif
  33. #endif
  34. //-----------------------------------------------------------------------------
  35. // Read CCOUNT register.
  36. //-----------------------------------------------------------------------------
  37. static __inline__ uint32_t xos_get_ccount(void)
  38. {
  39. #if XCHAL_HAVE_CCOUNT
  40. #if defined (__XCC__)
  41. return XT_RSR_CCOUNT();
  42. #else
  43. uint32_t ccount;
  44. __asm__ __volatile__ ( "rsr %0, ccount" : "=a" (ccount) );
  45. return ccount;
  46. #endif
  47. #else
  48. return 0;
  49. #endif
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Read CCOMPARE0
  53. //-----------------------------------------------------------------------------
  54. static __inline__ uint32_t xos_get_ccompare0(void)
  55. {
  56. #if XCHAL_HAVE_CCOUNT
  57. #if defined (__XCC__)
  58. return XT_RSR_CCOMPARE0();
  59. #else
  60. uint32_t ccompare0;
  61. __asm__ __volatile__ ( "rsr %0, ccompare0" : "=a" (ccompare0));
  62. return ccompare0;
  63. #endif
  64. #else
  65. return 0;
  66. #endif
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Read CCOMPARE1
  70. //-----------------------------------------------------------------------------
  71. #if (XCHAL_NUM_TIMERS > 1)
  72. static __inline__ uint32_t xos_get_ccompare1(void)
  73. {
  74. #if defined (__XCC__)
  75. return XT_RSR_CCOMPARE1();
  76. #else
  77. uint32_t ccompare1;
  78. __asm__ __volatile__ ( "rsr %0, ccompare1" : "=a" (ccompare1));
  79. return ccompare1;
  80. #endif
  81. }
  82. #endif
  83. //-----------------------------------------------------------------------------
  84. // Read CCOMPARE2
  85. //-----------------------------------------------------------------------------
  86. #if (XCHAL_NUM_TIMERS > 2)
  87. static __inline__ uint32_t xos_get_ccompare2(void)
  88. {
  89. #if defined (__XCC__)
  90. return XT_RSR_CCOMPARE2();
  91. #else
  92. uint32_t ccompare2;
  93. __asm__ __volatile__ ( "rsr %0, ccompare2" : "=a" (ccompare2));
  94. return ccompare2;
  95. #endif
  96. }
  97. #endif
  98. //-----------------------------------------------------------------------------
  99. // Write CCOMPARE0
  100. //-----------------------------------------------------------------------------
  101. static __inline__ void xos_set_ccompare0(uint32_t val)
  102. {
  103. #if XCHAL_HAVE_CCOUNT
  104. #if defined (__XCC__)
  105. XT_WSR_CCOMPARE0(val);
  106. XT_ISYNC();
  107. #else
  108. __asm__ __volatile__ (
  109. "wsr %0, ccompare0\n"
  110. "isync"
  111. :
  112. : "a" (val)
  113. );
  114. #endif
  115. #else
  116. // Empty
  117. #endif
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Write CCOMPARE1
  121. //-----------------------------------------------------------------------------
  122. #if (XCHAL_NUM_TIMERS > 1)
  123. static __inline__ void xos_set_ccompare1(uint32_t val)
  124. {
  125. #if defined (__XCC__)
  126. XT_WSR_CCOMPARE1(val);
  127. XT_ISYNC();
  128. #else
  129. __asm__ __volatile__ (
  130. "wsr %0, ccompare1\n"
  131. "isync"
  132. :
  133. : "a" (val)
  134. );
  135. #endif
  136. }
  137. #endif
  138. //-----------------------------------------------------------------------------
  139. // Write CCOMPARE2
  140. //-----------------------------------------------------------------------------
  141. #if (XCHAL_NUM_TIMERS > 2)
  142. static __inline__ void xos_set_ccompare2(uint32_t val)
  143. {
  144. #if defined (__XCC__)
  145. XT_WSR_CCOMPARE2(val);
  146. XT_ISYNC();
  147. #else
  148. __asm__ __volatile__ (
  149. "wsr %0, ccompare2\n"
  150. "isync"
  151. :
  152. : "a" (val)
  153. );
  154. #endif
  155. }
  156. #endif
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif // __REGACCESS_H__