esp.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "compiler.h"
  2. #include "common.h"
  3. #include "io.h"
  4. #include "console.h"
  5. #include "esplink.h"
  6. struct esplink_head __esplink_head esplink_head;
  7. static volatile struct esplink_timesync tsync;
  8. uint32_t __esplink esplink[(65536 - sizeof(struct esplink_head)) >> 2];
  9. IRQHANDLER(esp,0)
  10. {
  11. uint32_t irqstatus = ESP_CPU_IRQ;
  12. ESP_CPU_IRQ_CLR = irqstatus;
  13. if (irqstatus & (1 << EL_DIRQ_UNDERRUN)) {
  14. con_printf("[ESP] ESP link memory underrun!!\n");
  15. ESP_SPI_IRQ = (1 << EL_UIRQ_READY); /* Block writes, reinitialize! */
  16. return;
  17. }
  18. if (irqstatus & (1 << EL_DIRQ_TIME)) {
  19. if (tsync.set.update) {
  20. SYSCLOCK_TICK_HOLD = tsync.set.tick;
  21. SYSCLOCK_DATETIME = tsync.set.td;
  22. tsync.set.update = 0;
  23. do_write_rtc = true;
  24. } else {
  25. tsync.get.td = SYSCLOCK_DATETIME;
  26. tsync.get.tick = SYSCLOCK_TICK_HOLD;
  27. ESP_SPI_IRQ_SET = 1 << EL_UIRQ_TIME;
  28. }
  29. }
  30. if (irqstatus & (1 << EL_DIRQ_HELLO)) {
  31. con_printf("[ESP] Got hello, sending ready...\n");
  32. /* Hello, are you there? Yes, I'm here, and you can write data now */
  33. ESP_SPI_IRQ_SET = (1 << EL_UIRQ_READY)|(1 << EL_UIRQ_WREN);
  34. }
  35. }
  36. void esp_init(void)
  37. {
  38. static char __dram_data esp_signature[] = "Hej tomtebuggar slå i glasen!";
  39. ESP_CPU_IRQ = 0;
  40. ESP_SPI_IRQ = 0;
  41. memset(&esplink_head, 0, sizeof esplink_head);
  42. esplink_head.hlen = sizeof esplink_head;
  43. esplink_head.board.cfg = SYS_BOARDCFG;
  44. memcpy(esplink_head.signature, esp_signature, sizeof esp_signature);
  45. esplink_head.tsync = &tsync;
  46. esplink_head.magic = ESPLINK_HEAD_MAGIC;
  47. ESP_SPI_IRQ = (1 << EL_UIRQ_READY);
  48. unmask_irq(ESP_IRQ);
  49. }