OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [src/] [alt_busy_sleep.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
/*
2
 * Copyright (c) 2003-2004 Altera Corporation, San Jose, California, USA.
3
 * All rights reserved.
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to
7
 * deal in the Software without restriction, including without limitation the
8
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9
 * sell copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 * ------------
24
 *
25
 * Altera does not recommend, suggest or require that this reference design
26
 * file be used in conjunction or combination with any other product.
27
 *
28
 * alt_busy_sleep.c - Microsecond delay routine which uses a calibrated busy
29
 *                    loop to perform the delay. This is used to implement
30
 *                    usleep for both uC/OS-II and the standalone HAL.
31
 *
32
 * Author PRR
33
 *
34
 * Calibrated delay with no timer required
35
 *
36
 * The ASM instructions in the routine are equivalent to
37
 *
38
 * for (i=0;i<us*(ALT_CPU_FREQ/3);i++);
39
 *
40
 * and takes three cycles each time around the loop
41
 *
42
 */
43
 
44
#include <limits.h>
45
#include <string.h>
46
 
47
#include "system.h"
48
#include "alt_types.h"
49
 
50
#include "priv/alt_busy_sleep.h"
51
 
52
unsigned int alt_busy_sleep (unsigned int us)
53
{
54
/*
55
 * Only delay if ALT_SIM_OPTIMIZE is not defined; i.e., if software
56
 * is built targetting ModelSim RTL simulation, the delay will be
57
 * skipped to speed up simulation.
58
 */
59
#ifndef ALT_SIM_OPTIMIZE
60
  int i;
61
  int big_loops;
62
  alt_u32 cycles_per_loop;
63
 
64
  if (!strcmp(NIOS2_CPU_IMPLEMENTATION,"tiny"))
65
  {
66
    cycles_per_loop = 9;
67
  }
68
  else
69
  {
70
    cycles_per_loop = 3;
71
  }
72
 
73
 
74
  big_loops = us / (INT_MAX/
75
  (ALT_CPU_FREQ/(cycles_per_loop * 1000000)));
76
 
77
  if (big_loops)
78
  {
79
    for(i=0;i<big_loops;i++)
80
    {
81
      /*
82
      * Do NOT Try to single step the asm statement below
83
      * (single step will never return)
84
      * Step out of this function or set a breakpoint after the asm statements
85
      */
86
      __asm__ volatile (
87
        "\n0:"
88
        "\n\taddi %0,%0, -1"
89
        "\n\tbne %0,zero,0b"
90
        "\n1:"
91
        "\n\t.pushsection .debug_alt_sim_info"
92
        "\n\t.int 4, 0, 0b, 1b"
93
        "\n\t.popsection"
94
        :: "r" (INT_MAX));
95
      us -= (INT_MAX/(ALT_CPU_FREQ/
96
      (cycles_per_loop * 1000000)));
97
    }
98
 
99
    /*
100
    * Do NOT Try to single step the asm statement below
101
    * (single step will never return)
102
    * Step out of this function or set a breakpoint after the asm statements
103
    */
104
    __asm__ volatile (
105
      "\n0:"
106
      "\n\taddi %0,%0, -1"
107
      "\n\tbne %0,zero,0b"
108
      "\n1:"
109
      "\n\t.pushsection .debug_alt_sim_info"
110
      "\n\t.int 4, 0, 0b, 1b"
111
      "\n\t.popsection"
112
      :: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000))));
113
  }
114
  else
115
  {
116
    /*
117
    * Do NOT Try to single step the asm statement below
118
    * (single step will never return)
119
    * Step out of this function or set a breakpoint after the asm statements
120
    */
121
    __asm__ volatile (
122
      "\n0:"
123
      "\n\taddi %0,%0, -1"
124
      "\n\tbgt %0,zero,0b"
125
      "\n1:"
126
      "\n\t.pushsection .debug_alt_sim_info"
127
      "\n\t.int 4, 0, 0b, 1b"
128
      "\n\t.popsection"
129
      :: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000))));
130
  }
131
#endif /* #ifndef ALT_SIM_OPTIMIZE */
132
  return 0;
133
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.