utils.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2003-2005 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  21. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. */
  31. /*
  32. * $Log$
  33. * Revision 1.1 2005/11/03 15:14:27 haraldkipp
  34. * First import.
  35. *
  36. */
  37. #include "utils.h"
  38. /*!
  39. * \brief Delay by executing a given number of nops.
  40. */
  41. void MicroDelay(u_short nops)
  42. {
  43. u_short i;
  44. for (i = 0; i < nops; i++) {
  45. asm volatile ("nop");
  46. }
  47. }
  48. /*!
  49. * \brief Delay by executing a given number of nops, multiplied by 100000.
  50. */
  51. void Delay(u_char val)
  52. {
  53. u_char i;
  54. for(i = 0; i < val; i++) {
  55. MicroDelay(0xFFFF);
  56. MicroDelay(0xFFFF);
  57. MicroDelay(0xFFFF);
  58. }
  59. }
  60. /*
  61. * Conversion of 16 bit value to network order.
  62. */
  63. u_short __byte_swap2(u_short val)
  64. {
  65. asm volatile(
  66. "mov __tmp_reg__, %A0\n\t"
  67. "mov %A0, %B0\n\t"
  68. "mov %B0, __tmp_reg__\n\t"
  69. : "=r" (val)
  70. : "0" (val)
  71. );
  72. return val;
  73. }
  74. /*
  75. * Conversion of 32 bit value to network order.
  76. */
  77. u_long __byte_swap4(u_long val)
  78. {
  79. asm volatile(
  80. "mov __tmp_reg__, %A0\n\t"
  81. "mov %A0, %D0\n\t"
  82. "mov %D0, __tmp_reg__\n\t"
  83. "mov __tmp_reg__, %B0\n\t"
  84. "mov %B0, %C0\n\t"
  85. "mov %C0, __tmp_reg__\n\t"
  86. : "=r" (val)
  87. : "0" (val)
  88. );
  89. return val;
  90. }
  91. void memcpy_(u_char *dst, const u_char *src, u_char len)
  92. {
  93. while(len--) {
  94. *dst++ = *src++;
  95. }
  96. }
  97. void memset_(u_char *dst, u_char val, u_char len)
  98. {
  99. while(len--) {
  100. *dst++ = val;
  101. }
  102. }