You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * pru_ggpio.c
  3. *
  4. * Created on: Nov 1, 2016
  5. * Author: gagua
  6. */
  7. #include "pru_ggpio.h"
  8. void init_GPIO( void ){
  9. reset_GPIO();
  10. //keys
  11. GPIO5_CTRL.SYSCFG = 0;
  12. GPIO5_CTRL.OE = (1<<11)|(1<<13);
  13. GPIO5_CTRL.DEBOUNCEN = (1<<11)|(1<<13);
  14. GPIO5_CTRL.DEBOUNCINGTIME_bit.DEBOUNCETIME = 200;
  15. GPIO5_CTRL.FALLINGDETECT = (1<<11)|(1<<13);
  16. GPIO5_CTRL.RISINGDETECT = (1<<11)|(1<<13);
  17. GPIO5_CTRL.IRQSTS_SET_0 = (1<<11)|(1<<13);
  18. GPIO5_CTRL.IRQSTS_SET_1 = (1<<11)|(1<<13);
  19. GPIO5_CTRL.CTRL = 0; //Enable Module
  20. };
  21. void reset_GPIO(){
  22. GPIO5_CTRL.SYSCFG_bit.SOFTRESET = 1; // Reset GPIO5 HW
  23. };
  24. /***** HOST LED EXAMPLE
  25. #include <stdint.h>
  26. #include <pru_cfg.h>
  27. #include "resource_table_empty.h"
  28. // LED port address
  29. #define GPIO5_BASE_ADDR 0x48322000
  30. #define GPIO_OE_OFFSET 0x134
  31. #define GPIO_CLRDATAOUT_OFFSET 0x190
  32. #define GPIO_SETDATAOUT_OFFSET 0x194
  33. volatile register uint32_t __R30;
  34. volatile pruCfg CT_CFG __attribute__((cregister("PRU_CFG", near), peripheral));
  35. int main(void) {
  36. volatile uint32_t i;
  37. // GPI Mode 0, GPO Mode 0
  38. CT_CFG.GPCFG0 = 0;
  39. CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
  40. volatile unsigned int led_set_addr;
  41. volatile unsigned int led_modeset_addr;
  42. volatile unsigned int led_clr_addr;
  43. led_set_addr = GPIO5_BASE_ADDR + GPIO_SETDATAOUT_OFFSET;
  44. led_clr_addr = GPIO5_BASE_ADDR + GPIO_CLRDATAOUT_OFFSET;
  45. // set led port as output IO
  46. led_modeset_addr = GPIO5_BASE_ADDR + GPIO_OE_OFFSET;
  47. *(volatile unsigned int*)led_modeset_addr ^= 0xff00;
  48. while(1) {
  49. for (i = 0; i < 4; i++) {
  50. __R30 = 1<<(i + 10);
  51. *(volatile unsigned int*)led_set_addr |= __R30;
  52. __delay_cycles(100000000); // half-second delay
  53. *(volatile unsigned int*)led_clr_addr |= __R30;
  54. __delay_cycles(100000000); // half-second delay
  55. };
  56. };
  57. // Halt the PRU core - shouldn't get here
  58. __halt();
  59. };
  60. */