atom.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. * Copyright (C) 2001-2010 by egnite Software GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log: atom.h,v $
  36. *
  37. */
  38. /*
  39. WHEN CHANGING PLEASE NOTICE:
  40. Errata 41.5.5.5 reads:
  41. "Need two NOPs instruction after instructions masking interrupts
  42. The instructions following in the pipeline the instruction masking the interrupt through SR
  43. may behave abnormally.
  44. Fix/Workaround
  45. Place two NOPs instructions after each SSRF or MTSR instruction setting IxM or GM in SR."
  46. */
  47. #ifndef _SYS_ATOM_H_
  48. #error "Do not include this file directly. Use sys/atom.h instead!"
  49. #endif
  50. #if (__GNUC__ && __AVR32__)
  51. #include <avr32/io.h>
  52. #if defined(NUT_CRITICAL_NESTING)
  53. #if defined(NUT_CRITICAL_NESTING_STACK)
  54. // This doesn't work right now. Not sure how to fix yet.
  55. // but this is unreacheable since critical neasting can't be enabled in the configurator
  56. // for AVR32
  57. #error Not Working
  58. #define NutEnterCritical() \
  59. { \
  60. register int temp_; \
  61. __asm__ volatile ( \
  62. "mfsr r10, %[SR]" "\n\t" \
  63. "pushm r10" "\n\t" \
  64. "ssrf %[SR_GM_OFFSET]" "\n\t" \
  65. : [temp] "=r" (temp_) \
  66. : [SR] "i" (AVR32_SR), \
  67. [SR_GM_OFFSET] "i" (AVR32_SR_GM_OFFSET) \
  68. : "memory", "cc", "r10"); \
  69. }
  70. #define NutExitCritical() \
  71. { \
  72. register int temp_; \
  73. __asm__ volatile ( \
  74. "popm r10" "\n\t" \
  75. "andl r10, LO(%[SR_GM_MASK])" "\n\t" \
  76. "andh r10, HI(%[SR_GM_MASK])" "\n\t" \
  77. "cp.w r10, 0" "\n\t" \
  78. "breq LABEL_INT_SKIP_ENABLE_INTERRUPTS_%[LINE]" "\n\t" \
  79. "csrf %[SR_GM_OFFSET]" "\n\t" \
  80. "LABEL_INT_SKIP_SAVE_CONTEXT_%[LINE]:" "\n\t" \
  81. : [temp] "=r" (temp_) \
  82. : [SR_GM_OFFSET] "i" (AVR32_SR_GM_OFFSET), \
  83. [SR_GM_MASK] "i" (AVR32_SR_GM_MASK), \
  84. [LINE] "i" (__LINE__) \
  85. : "memory", "cc", "r10"); \
  86. }
  87. #else /* NUT_CRITICAL_NESTING_STACK */
  88. // If we ever enable critical nesting, implement me.
  89. #error Not implemented
  90. extern unsigned int critical_nesting_level;
  91. #define NutEnterCritical()
  92. #define NutExitCritical()
  93. #endif /* NUT_CRITICAL_NESTING_STACK */
  94. #else /* NUT_CRITICAL_NESTING */
  95. #define NutEnterCritical() \
  96. { \
  97. __asm__ __volatile__ ( \
  98. "ssrf\t%0" "\n\t" \
  99. "nop" "\n\t" \
  100. "nop" "\n\t" \
  101. :: "i" (AVR32_SR_GM_OFFSET) \
  102. : "memory"); \
  103. }
  104. #define NutExitCritical() \
  105. { \
  106. __asm__ __volatile__ ( \
  107. "csrf\t%0" "\n\t" \
  108. :: "i" (AVR32_SR_GM_OFFSET) \
  109. : "memory"); \
  110. }
  111. #endif /* NUT_CRITICAL_NESTING */
  112. #define NutJumpOutCritical() NutExitCritical()
  113. #endif