F2837xD_usDelay.asm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;//###########################################################################
  2. ;//
  3. ;// FILE: F2837xD_usDelay.asm
  4. ;//
  5. ;// TITLE: Simple delay function
  6. ;//
  7. ;// DESCRIPTION:
  8. ;// This is a simple delay function that can be used to insert a specified
  9. ;// delay into code.
  10. ;// This function is only accurate if executed from internal zero-waitstate
  11. ;// SARAM. If it is executed from waitstate memory then the delay will be
  12. ;// longer then specified.
  13. ;// To use this function:
  14. ;// 1 - update the CPU clock speed in the F2837xD_Examples.h
  15. ;// file. For example:
  16. ;// #define CPU_RATE 6.667L // for a 150MHz CPU clock speed
  17. ;// 2 - Call this function by using the DELAY_US(A) macro
  18. ;// that is defined in the F2837xD_Device.h file. This macro
  19. ;// will convert the number of microseconds specified
  20. ;// into a loop count for use with this function.
  21. ;// This count will be based on the CPU frequency you specify.
  22. ;// 3 - For the most accurate delay
  23. ;// - Execute this function in 0 waitstate RAM.
  24. ;// - Disable interrupts before calling the function
  25. ;// If you do not disable interrupts, then think of
  26. ;// this as an "at least" delay function as the actual
  27. ;// delay may be longer.
  28. ;// The C assembly call from the DELAY_US(time) macro will
  29. ;// look as follows:
  30. ;// extern void Delay(long LoopCount);
  31. ;// MOV AL,#LowLoopCount
  32. ;// MOV AH,#HighLoopCount
  33. ;// LCR _Delay
  34. ;// Or as follows (if count is less then 16-bits):
  35. ;// MOV ACC,#LoopCount
  36. ;// LCR _Delay
  37. ;//
  38. ;//###########################################################################
  39. ;// $TI Release: F2837xD Support Library v3.05.00.00 $
  40. ;// $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  41. ;// $Copyright:
  42. ;// Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  43. ;//
  44. ;// Redistribution and use in source and binary forms, with or without
  45. ;// modification, are permitted provided that the following conditions
  46. ;// are met:
  47. ;//
  48. ;// Redistributions of source code must retain the above copyright
  49. ;// notice, this list of conditions and the following disclaimer.
  50. ;//
  51. ;// Redistributions in binary form must reproduce the above copyright
  52. ;// notice, this list of conditions and the following disclaimer in the
  53. ;// documentation and/or other materials provided with the
  54. ;// distribution.
  55. ;//
  56. ;// Neither the name of Texas Instruments Incorporated nor the names of
  57. ;// its contributors may be used to endorse or promote products derived
  58. ;// from this software without specific prior written permission.
  59. ;//
  60. ;// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  61. ;// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  62. ;// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  63. ;// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  64. ;// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  65. ;// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  66. ;// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  67. ;// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  68. ;// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69. ;// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  70. ;// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  71. ;// $
  72. ;//###########################################################################
  73. .def _F28x_usDelay
  74. .cdecls LIST ;;Used to populate __TI_COMPILER_VERSION__ macro
  75. %{
  76. %}
  77. .if __TI_COMPILER_VERSION__
  78. .if __TI_COMPILER_VERSION__ >= 15009000
  79. .sect ".TI.ramfunc" ;;Used with compiler v15.9.0 and newer
  80. .else
  81. .sect "ramfuncs" ;;Used with compilers older than v15.9.0
  82. .endif
  83. .endif
  84. .global __F28x_usDelay
  85. _F28x_usDelay:
  86. SUB ACC,#1
  87. BF _F28x_usDelay,GEQ ;; Loop if ACC >= 0
  88. LRETR
  89. ;There is a 9/10 cycle overhead and each loop
  90. ;takes five cycles. The LoopCount is given by
  91. ;the following formula:
  92. ; DELAY_CPU_CYCLES = 9 + 5*LoopCount
  93. ; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
  94. ; The macro DELAY_US(A) performs this calculation for you
  95. ;
  96. ;
  97. ;//
  98. ;// End of file
  99. ;//