#include "compiler.h" #include "common.h" #include "io.h" #include "console.h" #include "esplink.h" struct esplink_head __esplink_head esplink_head; static volatile struct esplink_timesync tsync; uint32_t __esplink esplink[(65536 - sizeof(struct esplink_head)) >> 2]; IRQHANDLER(esp,0) { uint32_t irqstatus = ESP_CPU_IRQ; ESP_CPU_IRQ_CLR = irqstatus; if (irqstatus & (1 << EL_DIRQ_UNDERRUN)) { con_printf("[ESP] ESP link memory underrun!!\n"); ESP_SPI_IRQ = (1 << EL_UIRQ_READY); /* Block writes, reinitialize! */ return; } if (irqstatus & (1 << EL_DIRQ_TIME)) { if (tsync.set.update) { SYSCLOCK_TICK_HOLD = tsync.set.tick; SYSCLOCK_DATETIME = tsync.set.td; tsync.set.update = 0; do_write_rtc = true; } else { tsync.get.td = SYSCLOCK_DATETIME; tsync.get.tick = SYSCLOCK_TICK_HOLD; ESP_SPI_IRQ_SET = 1 << EL_UIRQ_TIME; } } if (irqstatus & (1 << EL_DIRQ_HELLO)) { con_printf("[ESP] Got hello, sending ready...\n"); /* Hello, are you there? Yes, I'm here, and you can write data now */ ESP_SPI_IRQ_SET = (1 << EL_UIRQ_READY)|(1 << EL_UIRQ_WREN); } } void esp_init(void) { static char __dram_data esp_signature[] = "Hej tomtebuggar slÄ i glasen!"; ESP_CPU_IRQ = 0; ESP_SPI_IRQ = 0; memset(&esplink_head, 0, sizeof esplink_head); esplink_head.hlen = sizeof esplink_head; esplink_head.board.cfg = SYS_BOARDCFG; memcpy(esplink_head.signature, esp_signature, sizeof esp_signature); esplink_head.tsync = &tsync; esplink_head.magic = ESPLINK_HEAD_MAGIC; ESP_SPI_IRQ = (1 << EL_UIRQ_READY); unmask_irq(ESP_IRQ); }