utils.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _UTILS_H
  2. #define _UTILS_H
  3. /*
  4. * Copyright (C) 2003-2007 by egnite Software GmbH
  5. * Copyright (C) 2010 by egnite GmbH
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. *
  37. */
  38. /*
  39. * $Id: utils.h 2935 2010-04-01 12:14:17Z haraldkipp $
  40. */
  41. extern void MicroDelay(unsigned int nops);
  42. extern void Delay(unsigned char val);
  43. extern void memset_(unsigned char *dst, unsigned char val, unsigned char len);
  44. extern void memcpy_(unsigned char *dst, const unsigned char *src, unsigned char len);
  45. extern void strcpy_(char *dst, const char *src);
  46. extern int memcmp_(const unsigned char *dst, const unsigned char *src, unsigned char len);
  47. extern unsigned long inet_addr(char *str);
  48. extern int hex2bin(char c);
  49. extern char *inet_ntoa(unsigned long addr);
  50. /*!
  51. * \brief Convert short value from host to network byte order.
  52. */
  53. #define htons(x) __byte_swap2(x)
  54. /*!
  55. * \brief Convert long value from host to network byte order.
  56. */
  57. #define htonl(x) __byte_swap4(x)
  58. /*!
  59. * \brief Convert short value from network to host byte order.
  60. */
  61. #define ntohs(x) __byte_swap2(x)
  62. /*!
  63. * \brief Convert long value from network to host byte order.
  64. */
  65. #define ntohl(x) __byte_swap4(x)
  66. #define __byte_swap2(val) \
  67. ((((val) & 0xff) << 8) | \
  68. (((val) & 0xff00) >> 8))
  69. #define __byte_swap4(val) \
  70. ((((val) & 0xff) << 24) | \
  71. (((val) & 0xff00) << 8) | \
  72. (((val) & 0xff0000) >> 8) | \
  73. (((val) & 0xff000000) >> 24))
  74. #define _NOP() __asm__ __volatile__ ("mov r0, r0")
  75. #endif