Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_attr.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - compiler-specific attributes
  27. =============================================================================*/
  28. #ifndef VCOS_ATTR_H
  29. #define VCOS_ATTR_H
  30. /**
  31. * Type attribute indicating the enum should be stored in as few bytes as
  32. * possible. MetaWare does this by default, so the attribute is useful when
  33. * structs need to be portable to GCC too.
  34. *
  35. * MSVC doesn't support VCOS_ENUM_PACKED, so code that needs to be portable
  36. * across all platforms but wants the type-safety and debug-info benefits
  37. * of enum types when possible, should do:
  38. *
  39. * typedef enum VCOS_ENUM_PACKED { a = 0, b = 0xffff } EXAMPLE_T;
  40. * struct foo {
  41. * int bar;
  42. * #if VCOS_HAS_ENUM_PACKED
  43. * EXAMPLE_T baz;
  44. * #else
  45. * uint16_t baz;
  46. * #endif
  47. * };
  48. */
  49. #if defined(__VECTORC__)
  50. # define VCOS_ENUM_PACKED
  51. # define VCOS_HAS_ENUM_PACKED 0
  52. #elif defined(__GNUC__)
  53. # define VCOS_ENUM_PACKED __attribute__ ((packed))
  54. # define VCOS_HAS_ENUM_PACKED 1
  55. #elif defined(__HIGHC__)
  56. # define VCOS_ENUM_PACKED /* packed enums are default on Metaware */
  57. # define VCOS_HAS_ENUM_PACKED 1
  58. #else
  59. # define VCOS_ENUM_PACKED
  60. # define VCOS_HAS_ENUM_PACKED 0
  61. #endif
  62. /** Variable attribute indicating the variable must be emitted even if it appears unused. */
  63. #if defined(__GNUC__) || defined(__HIGHC__)
  64. # define VCOS_ATTR_USED __attribute__ ((used))
  65. #else
  66. # define VCOS_ATTR_USED
  67. #endif
  68. /** Variable attribute indicating the compiler should not warn if the variable is unused. */
  69. #if defined(__GNUC__) || defined(__HIGHC__)
  70. # define VCOS_ATTR_POSSIBLY_UNUSED __attribute__ ((unused))
  71. #else
  72. # define VCOS_ATTR_POSSIBLY_UNUSED
  73. #endif
  74. /** Variable attribute requiring specific alignment.
  75. *
  76. * Use as:
  77. * int VCOS_ATTR_ALIGNED(256) n;
  78. * or:
  79. * VCOS_ATTR_ALIGNED(256) int n;
  80. * or if you don't want to support MSVC:
  81. * int n VCOS_ATTR_ALIGNED(256);
  82. */
  83. #if defined(__GNUC__) || defined(__HIGHC__)
  84. # define VCOS_ATTR_ALIGNED(n) __attribute__ ((aligned(n)))
  85. #elif defined(_MSC_VER)
  86. # define VCOS_ATTR_ALIGNED(n) __declspec(align(n))
  87. #else
  88. /* Force a syntax error if this is used when the compiler doesn't support it,
  89. * instead of silently misaligning */
  90. # define VCOS_ATTR_ALIGNED(n) VCOS_ATTR_ALIGNED_NOT_SUPPORTED_ON_THIS_COMPILER
  91. #endif
  92. /** Variable attribute requiring specific ELF section.
  93. *
  94. * Use as:
  95. * int n VCOS_ATTR_SECTION(".foo") = 1;
  96. *
  97. * A pointer like &n will have type "VCOS_ATTR_SECTION_QUALIFIER int *".
  98. */
  99. #if defined(__HIGHC__) || defined(__VECTORC__)
  100. /* hcvc requires 'far' else it'll put small objects in .sdata/.rsdata/.sbss */
  101. # define VCOS_ATTR_SECTION(s) __attribute__ ((far, section(s)))
  102. # define VCOS_ATTR_SECTION_QUALIFIER _Far
  103. #elif defined(__GNUC__)
  104. # define VCOS_ATTR_SECTION(s) __attribute__ ((section(s)))
  105. # define VCOS_ATTR_SECTION_QUALIFIER
  106. #else
  107. /* Force a syntax error if this is used when the compiler doesn't support it */
  108. # define VCOS_ATTR_SECTION(s) VCOS_ATTR_SECTION_NOT_SUPPORTED_ON_THIS_COMPILER
  109. # define VCOS_ATTR_SECTION_QUALIFIER
  110. #endif
  111. /** Define a function as a weak alias to another function.
  112. * @param ret_type Function return type.
  113. * @param alias_name Name of the alias.
  114. * @param param_list Function parameter list, including the parentheses.
  115. * @param target_name Target function (bare function name, not a string).
  116. */
  117. #if defined(__GNUC__) || defined(__HIGHC__)
  118. /* N.B. gcc allows __attribute__ after parameter list, but hcvc seems to silently ignore it. */
  119. # define VCOS_WEAK_ALIAS(ret_type, alias_name, param_list, target_name) \
  120. __attribute__ ((weak, alias(#target_name))) ret_type alias_name param_list
  121. #else
  122. # define VCOS_WEAK_ALIAS(ret_type, alias, params, target) VCOS_CASSERT(0)
  123. #endif
  124. /** Define a function as a weak alias to another function, specified as a string.
  125. * @param ret_type Function return type.
  126. * @param alias_name Name of the alias.
  127. * @param param_list Function parameter list, including the parentheses.
  128. * @param target_name Target function name as a string.
  129. * @note Prefer the use of VCOS_WEAK_ALIAS - it is likely to be more portable.
  130. * Only use VCOS_WEAK_ALIAS_STR if you need to do pre-processor mangling of the target
  131. * symbol.
  132. */
  133. #if defined(__GNUC__) || defined(__HIGHC__)
  134. /* N.B. gcc allows __attribute__ after parameter list, but hcvc seems to silently ignore it. */
  135. # define VCOS_WEAK_ALIAS_STR(ret_type, alias_name, param_list, target_name) \
  136. __attribute__ ((weak, alias(target_name))) ret_type alias_name param_list
  137. #else
  138. # define VCOS_WEAK_ALIAS_STR(ret_type, alias, params, target) VCOS_CASSERT(0)
  139. #endif
  140. #endif /* VCOS_ATTR_H */