pin_map.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "pin_map.h"
  2. #include "eagle_soc.h"
  3. #include "mem.h"
  4. #include "osapi.h"
  5. uint32_t pin_mux[GPIO_PIN_NUM];
  6. uint8_t pin_num[GPIO_PIN_NUM];
  7. uint8_t pin_func[GPIO_PIN_NUM];
  8. #ifdef GPIO_INTERRUPT_ENABLE
  9. uint8_t pin_num_inv[GPIO_PIN_NUM_INV];
  10. uint8_t pin_int_type[GPIO_PIN_NUM];
  11. #endif
  12. typedef struct {
  13. int8 mux;
  14. uint8 num;
  15. uint8 func;
  16. uint8 intr_type;
  17. } pin_rec;
  18. #define DECLARE_PIN(n,p) { (PERIPHS_IO_MUX_##p##_U - PERIPHS_IO_MUX), n, FUNC_GPIO##n, GPIO_PIN_INTR_DISABLE}
  19. static const pin_rec pin_map[] = {
  20. {PAD_XPD_DCDC_CONF - PERIPHS_IO_MUX, 16, 0, GPIO_PIN_INTR_DISABLE},
  21. DECLARE_PIN( 5, GPIO5),
  22. DECLARE_PIN( 4, GPIO4),
  23. DECLARE_PIN( 0, GPIO0),
  24. DECLARE_PIN( 2, GPIO2),
  25. DECLARE_PIN(14, MTMS),
  26. DECLARE_PIN(12, MTDI),
  27. DECLARE_PIN(13, MTCK),
  28. DECLARE_PIN(15, MTDO),
  29. DECLARE_PIN( 3, U0RXD),
  30. DECLARE_PIN( 1, U0TXD),
  31. DECLARE_PIN( 9, SD_DATA2),
  32. DECLARE_PIN(10, SD_DATA3)
  33. };
  34. void get_pin_map(void) {
  35. /*
  36. * Flash copy of the pin map. This has to be copied to RAM to be accessible from the ISR.
  37. * Note that the mux field is a signed offset from PERIPHS_IO_MUX to allow the whole struct
  38. * to be stored in a single 32-bit record.
  39. */
  40. int i;
  41. /* Take temporary stack copy to avoid unaligned exceptions on Flash version */
  42. pin_rec pin[GPIO_PIN_NUM];
  43. os_memcpy(pin, pin_map, sizeof(pin_map) );
  44. for (i=0; i<GPIO_PIN_NUM; i++) {
  45. pin_mux[i] = pin[i].mux + PERIPHS_IO_MUX;
  46. pin_func[i] = pin[i].func;
  47. pin_num[i] = pin[i].num;
  48. #ifdef GPIO_INTERRUPT_ENABLE
  49. pin_num_inv[pin_num[i]] = i;
  50. pin_int_type[i] = pin[i].intr_type;
  51. #endif
  52. }
  53. }