1
0

gpio.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * File : interrupt.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-04-14 ArdaFu first version
  23. */
  24. #include "asm9260t.h"
  25. #include "rtthread.h"
  26. void HW_SetPinMux(rt_uint8_t port, rt_uint8_t pin, rt_uint8_t mux_type)
  27. {
  28. rt_uint32_t addr = HW_IOCON(port, pin);
  29. rt_uint32_t val = inl(addr); // read origin value
  30. val &= ~7UL; // clear MUX field
  31. val |= mux_type; // set MUX field with new value
  32. outl(val ,addr); // Set new value
  33. }
  34. void HW_GpioSetDir(rt_uint8_t port, rt_uint8_t pin, rt_uint8_t isOut)
  35. {
  36. rt_uint32_t addr = HW_GPIO_DATA_BASE | ((port>>2)<<16) | 0x8000;
  37. rt_uint32_t val;
  38. addr = isOut? REG_SET(addr) : REG_CLR(addr);
  39. val = (1 << ((port%4)*8+pin));
  40. outl(val, addr);
  41. }
  42. void HW_GpioSetVal(rt_uint8_t port, rt_uint8_t pin)
  43. {
  44. rt_uint32_t addr, val;
  45. addr = REG_SET(HW_GPIO_DATA_BASE | ((port>>2)<<16));
  46. val = (1 << ((port%4)*8+pin));
  47. outl(val, addr);
  48. }
  49. void HW_GpioClrVal(rt_uint8_t port, rt_uint8_t pin)
  50. {
  51. rt_uint32_t addr, val;
  52. addr = REG_CLR(HW_GPIO_DATA_BASE | ((port>>2)<<16));
  53. val = (1 << ((port%4)*8+pin));
  54. outl(val, addr);
  55. }