em_bitband.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Bitband Peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_BITBAND_H
  34. #define __EM_BITBAND_H
  35. #include "em_part.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /***************************************************************************//**
  40. * @addtogroup EM_Library
  41. * @{
  42. ******************************************************************************/
  43. /***************************************************************************//**
  44. * @addtogroup BITBAND
  45. * @brief BITBAND Peripheral API
  46. * @{
  47. ******************************************************************************/
  48. /***************************************************************************//**
  49. * @brief
  50. * Perform bit-band operation on peripheral memory location.
  51. *
  52. * @details
  53. * Bit-banding provides atomic read-modify-write cycle for single bit
  54. * modification. Please refer to the reference manual for further details
  55. * about bit-banding.
  56. *
  57. * @param[in,out] addr Peripheral address location to modify bit in.
  58. *
  59. * @param[in] bit Bit position to modify, 0-31.
  60. *
  61. * @param[in] val Value to set bit to, 0 or 1.
  62. ******************************************************************************/
  63. __STATIC_INLINE void BITBAND_Peripheral(volatile uint32_t *addr,
  64. uint32_t bit,
  65. uint32_t val)
  66. {
  67. uint32_t tmp = BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
  68. *((volatile uint32_t *)tmp) = (uint32_t)val;
  69. }
  70. /***************************************************************************//**
  71. * @brief
  72. * Perform bit-band operation on SRAM memory location.
  73. *
  74. * @details
  75. * Bit-banding provides atomic read-modify-write cycle for single bit
  76. * modification. Please refer to the reference manual for further details
  77. * about bit-banding.
  78. *
  79. * @param[in,out] addr SRAM address location to modify bit in.
  80. *
  81. * @param[in] bit Bit position to modify, 0-31.
  82. *
  83. * @param[in] val Value to set bit to, 0 or 1.
  84. ******************************************************************************/
  85. __STATIC_INLINE void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
  86. {
  87. uint32_t tmp = BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4);
  88. *((volatile uint32_t *)tmp) = (uint32_t)val;
  89. }
  90. /** @} (end addtogroup BITBAND) */
  91. /** @} (end addtogroup EM_Library) */
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* __EM_BITBAND_H */