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
74       .cdecls LIST ;;Used to populate __TI_COMPILER_VERSION__ macro
75       %{
76           #ifdef __TI_EABI__
77           #define __EABI__ 1
78           #else
79           #define __EABI__ 0
80           #endif
81       %}
82
83       .if __EABI__
84       .def F28x_usDelay
85       .else
86       .def _F28x_usDelay
87       .endif
88
89       .if __TI_COMPILER_VERSION__
90       .if __TI_COMPILER_VERSION__ >= 15009000
91       .sect ".TI.ramfunc"      ;;Used with compiler v15.9.0 and newer
92       .else
93       .sect "ramfuncs"         ;;Used with compilers older than v15.9.0
94       .endif
95       .endif
96
97        .global  __F28x_usDelay
98
99       .if __EABI__
100F28x_usDelay:
101       .else
102_F28x_usDelay:
103       .endif
104
105        SUB    ACC,#1
106       .if __EABI__
107        BF     F28x_usDelay,GEQ    ;; Loop if ACC >= 0
108       .else
109        BF     _F28x_usDelay,GEQ    ;; Loop if ACC >= 0
110       .endif
111
112        LRETR
113
114;There is a 9/10 cycle overhead and each loop
115;takes five cycles. The LoopCount is given by
116;the following formula:
117;  DELAY_CPU_CYCLES = 9 + 5*LoopCount
118; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
119; The macro DELAY_US(A) performs this calculation for you
120;
121;
122
123;//
124;// End of file
125;//
126