fh_pmu.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #include "rtdebug.h"
  27. #include "arch.h"
  28. #include "fh_pmu.h"
  29. #include "fh_def.h"
  30. #define FH_PMU_WRITEL(offset,value) SET_REG((PMU_REG_BASE + offset),value)
  31. #define FH_PMU_WRITEL_MASK(offset,value, mask) SET_REG_M((PMU_REG_BASE + offset), value, mask)
  32. #define FH_PMU_READL(offset) GET_REG((PMU_REG_BASE + offset))
  33. #define PMU_OFFSET_MAX 0x1d0
  34. int fh_pmu_read(rt_uint32_t offset, rt_uint32_t *value)
  35. {
  36. RT_ASSERT(offset < PMU_OFFSET_MAX);
  37. *value = FH_PMU_READL(offset);
  38. return 0;
  39. }
  40. int fh_pmu_write(rt_uint32_t offset, const rt_uint32_t value)
  41. {
  42. RT_ASSERT(offset < PMU_OFFSET_MAX);
  43. FH_PMU_WRITEL(offset, value);
  44. return 0;
  45. }
  46. int fh_pmu_write_mask(rt_uint32_t offset, const rt_uint32_t value,
  47. const rt_uint32_t mask)
  48. {
  49. RT_ASSERT(offset < PMU_OFFSET_MAX);
  50. FH_PMU_WRITEL_MASK(offset, value, mask);
  51. return 0;
  52. }