| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | #include "compiler.h"#include "common.h"#include "io.h"#include "console.h"#include "esplink.h"struct esplink_head __esplink_head esplink_head;static volatile __esplink struct esplink_timesync tsync;static volatile __esplink struct esplink_ota ota;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);    }    /*     * Check to see if we got hello after an OTA process was completed     * or aborted; ESP will send EL_DIRQ_DONE to wake us up.     */    if (!(ESP_SPI_IRQ & (1 << EL_UIRQ_OTA))) {	ota.data = NULL;	ota.len  = 0;    }}void esp_ota(const void *data, size_t len){    mask_irq(ESP_IRQ);        ota.data = data;    ota.len  = len;    ESP_SPI_IRQ_SET = 1 << EL_UIRQ_OTA;    unmask_irq(ESP_IRQ);    while (ota.data)	waitfor(ESP_IRQ);}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.ota           = &ota;    esplink_head.magic         = ESPLINK_HEAD_MAGIC;    ESP_SPI_IRQ                = (1 << EL_UIRQ_READY);    unmask_irq(ESP_IRQ);}
 |