DSP2803x_usDelay.asm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ;//###########################################################################
  2. ;//
  3. ;// FILE: DSP2803x_usDelay.asm
  4. ;//
  5. ;// TITLE: Simple delay function
  6. ;//
  7. ;// DESCRIPTION:
  8. ;//
  9. ;// This is a simple delay function that can be used to insert a specified
  10. ;// delay into code.
  11. ;//
  12. ;// This function is only accurate if executed from internal zero-waitstate
  13. ;// SARAM. If it is executed from waitstate memory then the delay will be
  14. ;// longer then specified.
  15. ;//
  16. ;// To use this function:
  17. ;//
  18. ;// 1 - update the CPU clock speed in the DSP2803x_Examples.h
  19. ;// file. For example:
  20. ;// #define CPU_RATE 16.667L // for a 60MHz CPU clock speed
  21. ;//
  22. ;// 2 - Call this function by using the DELAY_US(A) macro
  23. ;// that is defined in the DSP2803x_Examples.h file. This macro
  24. ;// will convert the number of microseconds specified
  25. ;// into a loop count for use with this function.
  26. ;// This count will be based on the CPU frequency you specify.
  27. ;//
  28. ;// 3 - For the most accurate delay
  29. ;// - Execute this function in 0 waitstate RAM.
  30. ;// - Disable interrupts before calling the function
  31. ;// If you do not disable interrupts, then think of
  32. ;// this as an "at least" delay function as the actual
  33. ;// delay may be longer.
  34. ;//
  35. ;// The C assembly call from the DELAY_US(time) macro will
  36. ;// look as follows:
  37. ;//
  38. ;// extern void Delay(long LoopCount);
  39. ;//
  40. ;// MOV AL,#LowLoopCount
  41. ;// MOV AH,#HighLoopCount
  42. ;// LCR _Delay
  43. ;//
  44. ;// Or as follows (if count is less then 16-bits):
  45. ;//
  46. ;// MOV ACC,#LoopCount
  47. ;// LCR _Delay
  48. ;//
  49. ;//
  50. ;//###########################################################################
  51. ;// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  52. ;// $Release Date: May 8, 2015 $
  53. ;// $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  54. ;// http://www.ti.com/ ALL RIGHTS RESERVED $
  55. ;//###########################################################################
  56. ;//
  57. ;// *IMPORTANT*
  58. ;// IF RUNNING FROM FLASH, PLEASE COPY OVER THE SECTION "ramfuncs" FROM FLASH
  59. ;// TO RAM PRIOR TO CALLING InitSysCtrl(). THIS PREVENTS THE MCU FROM THROWING AN EXCEPTION
  60. ;// WHEN A CALL TO DELAY_US() IS MADE.
  61. ;//
  62. .def _DSP28x_usDelay
  63. .sect "ramfuncs"
  64. .global __DSP28x_usDelay
  65. _DSP28x_usDelay:
  66. SUB ACC,#1
  67. BF _DSP28x_usDelay,GEQ ;; Loop if ACC >= 0
  68. LRETR
  69. ;There is a 9/10 cycle overhead and each loop
  70. ;takes five cycles. The LoopCount is given by
  71. ;the following formula:
  72. ; DELAY_CPU_CYCLES = 9 + 5*LoopCount
  73. ; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
  74. ; The macro DELAY_US(A) performs this calculation for you
  75. ;
  76. ;//===========================================================================
  77. ;// End of file.
  78. ;//===========================================================================