efm32_bitband.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /***************************************************************************//**
  2. * @file
  3. * @brief EFM32 bitband utilities.
  4. * @author Energy Micro AS
  5. * @version 1.3.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_BITBAND_H
  29. #define __EFM32_BITBAND_H
  30. #include "efm32.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /***************************************************************************//**
  35. * @addtogroup EFM32_Library
  36. * @{
  37. ******************************************************************************/
  38. /***************************************************************************//**
  39. * @addtogroup BITBAND
  40. * @brief EFM32 bit-band utilities.
  41. * @{
  42. ******************************************************************************/
  43. /***************************************************************************//**
  44. * @brief
  45. * Perform bit-band operation on peripheral memory location.
  46. *
  47. * @details
  48. * Bit-banding provides atomic read-modify-write cycle for single bit
  49. * modification. Please refer to the reference manual for further details
  50. * about bit-banding.
  51. *
  52. * @param[in,out] addr Peripheral address location to modify bit in.
  53. *
  54. * @param[in] bit Bit position to modify, 0-31.
  55. *
  56. * @param[in] val Value to set bit to, 0 or 1.
  57. ******************************************************************************/
  58. static __INLINE void BITBAND_Peripheral(volatile uint32_t *addr,
  59. uint32_t bit,
  60. uint32_t val)
  61. {
  62. uint32_t tmp = BITBAND_PER_BASE + (((uint32_t) addr - PER_MEM_BASE) * 32) + (bit * 4);
  63. *((volatile uint32_t *) tmp) = (uint32_t) val;
  64. }
  65. /***************************************************************************//**
  66. * @brief
  67. * Perform bit-band operation on SRAM memory location.
  68. *
  69. * @details
  70. * Bit-banding provides atomic read-modify-write cycle for single bit
  71. * modification. Please refer to the reference manual for further details
  72. * about bit-banding.
  73. *
  74. * @param[in,out] addr SRAM address location to modify bit in.
  75. *
  76. * @param[in] bit Bit position to modify, 0-31.
  77. *
  78. * @param[in] val Value to set bit to, 0 or 1.
  79. ******************************************************************************/
  80. static __INLINE void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
  81. {
  82. uint32_t tmp = BITBAND_RAM_BASE + (((uint32_t) addr - RAM_MEM_BASE) * 32) + (bit * 4);
  83. *((volatile uint32_t *) tmp) = (uint32_t) val;
  84. }
  85. /** @} (end addtogroup BITBAND) */
  86. /** @} (end addtogroup EFM32_Library) */
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* __EFM32_BITBAND_H */