pin_map.c 1.6 KB

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