2
0

fpgasvc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. #include "common.h"
  2. #include "config.h"
  3. #include "fpga.h"
  4. #include "esplink.h"
  5. #include "xmalloc.h"
  6. #include <driver/gpio.h>
  7. #include <driver/spi_common.h>
  8. #include <driver/spi_master.h>
  9. #define PIN_FPGA_INT 9
  10. #define PIN_FPGA_CS 10
  11. #define PIN_FPGA_IO0 11
  12. #define PIN_FPGA_CLK 12
  13. #define PIN_FPGA_IO1 13
  14. #define FPGA_SPI_HOST FSPI /* SPI2 */
  15. #define FPGA_PRIORITY 10
  16. #define FPGA_SVC_STACK 4096
  17. #define RTC_TIMESYNC_PERIOD (511*configTICK_RATE_HZ)
  18. static spi_bus_config_t spi_bus_config = {
  19. .data0_io_num = PIN_FPGA_IO0,
  20. .data1_io_num = PIN_FPGA_IO1,
  21. .sclk_io_num = PIN_FPGA_CLK,
  22. .data2_io_num = -1,
  23. .data3_io_num = -1,
  24. .data4_io_num = -1,
  25. .data5_io_num = -1,
  26. .data6_io_num = -1,
  27. .data7_io_num = -1,
  28. .max_transfer_sz = 4096,
  29. .flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_DUAL
  30. };
  31. #define FPGA_IOV_MAX 4
  32. static void ARDUINO_ISR_ATTR spi_callback(spi_transaction_t *);
  33. static const spi_device_interface_config_t spi_device_interface_config = {
  34. .command_bits = 8,
  35. .address_bits = 32,
  36. .dummy_bits = 0,
  37. .mode = 0,
  38. .cs_ena_pretrans = 0,
  39. .cs_ena_posttrans = 0,
  40. .clock_speed_hz = SPI_MASTER_FREQ_40M,
  41. .spics_io_num = PIN_FPGA_CS,
  42. .flags = SPI_DEVICE_HALFDUPLEX,
  43. .queue_size = FPGA_IOV_MAX,
  44. .post_cb = spi_callback
  45. };
  46. static spi_device_handle_t spi_handle;
  47. static TaskHandle_t fpga_task;
  48. static TimerHandle_t fpga_timesync_timer;
  49. static SemaphoreHandle_t spi_mutex;
  50. static EventGroupHandle_t spi_done_evgroup;
  51. static volatile bool spi_abort_all;
  52. static struct esplink_head head;
  53. #define NOTIFY_INDEX 0
  54. #define NOTIFY_FPGA (1 << 0)
  55. #define NOTIFY_ENABLE (1 << 1)
  56. #define NOTIFY_DISABLE (1 << 2)
  57. #define NOTIFY_TIMESYNC (1 << 3)
  58. #if 0
  59. #define NOTIFY_SPI (1 << 3)
  60. #define NOTIFY_RINGBUF (1 << 4)
  61. #endif
  62. static uint32_t notify_poll_for(uint32_t flags)
  63. {
  64. return ulTaskNotifyValueClearIndexed(NULL, NOTIFY_INDEX, flags);
  65. }
  66. /* This supports multiple flags set */
  67. static uint32_t notify_wait_for(uint32_t flags)
  68. {
  69. uint32_t notify_value;
  70. /* Already received? Might already have been waited for... */
  71. notify_value = notify_poll_for(flags);
  72. while (!(notify_value & flags)) {
  73. xTaskNotifyWaitIndexed(NOTIFY_INDEX, 0, flags,
  74. &notify_value, portMAX_DELAY);
  75. }
  76. return notify_value;
  77. }
  78. static void ARDUINO_ISR_ATTR fpga_notify_from_isr(uint32_t flags)
  79. {
  80. BaseType_t wakeup = pdFALSE;
  81. if (xTaskNotifyIndexedFromISR(fpga_task, NOTIFY_INDEX, flags, eSetBits,
  82. &wakeup) != pdFAIL)
  83. portYIELD_FROM_ISR(wakeup);
  84. }
  85. static void fpga_notify_from_task(uint32_t flags)
  86. {
  87. xTaskNotifyIndexed(fpga_task, NOTIFY_INDEX, flags, eSetBits);
  88. }
  89. static void ARDUINO_ISR_ATTR fpga_interrupt(void)
  90. {
  91. fpga_notify_from_isr(NOTIFY_FPGA);
  92. }
  93. void fpga_timesync_trigger(void)
  94. {
  95. fpga_notify_from_task(NOTIFY_TIMESYNC);
  96. }
  97. static void ARDUINO_ISR_ATTR spi_callback(spi_transaction_t *t)
  98. {
  99. size_t flags = (size_t)t->user;
  100. if (!flags)
  101. return;
  102. BaseType_t wakeup = pdFALSE;
  103. if (xEventGroupSetBitsFromISR(spi_done_evgroup, (size_t)t->user,
  104. &wakeup) != pdFAIL)
  105. portYIELD_FROM_ISR(wakeup);
  106. }
  107. static void fpga_service_task(void *);
  108. static EventGroupHandle_t fpga_service_evgroup;
  109. void fpga_service_enable(bool on)
  110. {
  111. uint32_t flag = on ? NOTIFY_ENABLE : NOTIFY_DISABLE;
  112. fpga_notify_from_task(flag);
  113. xEventGroupWaitBits(fpga_service_evgroup, flag, 0, pdTRUE, portMAX_DELAY);
  114. }
  115. esp_err_t fpga_service_init(void)
  116. {
  117. esp_err_t err;
  118. pinMode(PIN_FPGA_INT, INPUT);
  119. setenv_bool("status.max80.fpga", false);
  120. fpga_service_evgroup = null_check(xEventGroupCreate());
  121. spi_mutex = null_check(xSemaphoreCreateRecursiveMutex());
  122. spi_done_evgroup = null_check(xEventGroupCreate());
  123. /* The ordering here attempts to avoid race conditions... */
  124. if (xTaskCreate(fpga_service_task, "fpga_svc", FPGA_SVC_STACK, NULL,
  125. FPGA_PRIORITY, &fpga_task) != pdPASS)
  126. return ESP_FAIL;
  127. fpga_timesync_timer =
  128. null_check(xTimerCreate("rtc_sync", RTC_TIMESYNC_PERIOD, pdTRUE, NULL,
  129. (TimerCallbackFunction_t)fpga_timesync_trigger));
  130. esplink_init();
  131. xEventGroupSetBits(fpga_service_evgroup, NOTIFY_DISABLE);
  132. return ESP_OK;
  133. }
  134. static bool fpga_link_enable(void)
  135. {
  136. esp_err_t err;
  137. if (spi_handle)
  138. return true; /* Already started */
  139. xEventGroupClearBits(fpga_service_evgroup, NOTIFY_DISABLE);
  140. err = spi_bus_initialize(FPGA_SPI_HOST, &spi_bus_config, SPI_DMA_CH_AUTO);
  141. if (err)
  142. goto init_fail;
  143. err = spi_bus_add_device(FPGA_SPI_HOST, &spi_device_interface_config,
  144. &spi_handle);
  145. if (err)
  146. goto free_bus_fail;
  147. /* Only device on this bus, so acquire it permanently */
  148. err = spi_device_acquire_bus(spi_handle, portMAX_DELAY);
  149. if (err)
  150. goto release_bus_fail;
  151. xEventGroupClearBits(spi_done_evgroup, EVENT_ALL_BITS);
  152. pinMode(PIN_FPGA_INT, INPUT);
  153. attachInterrupt(PIN_FPGA_INT, fpga_interrupt, FALLING);
  154. xEventGroupSetBits(fpga_service_evgroup, NOTIFY_ENABLE);
  155. xSemaphoreGiveRecursive(spi_mutex);
  156. fpga_notify_from_task(NOTIFY_FPGA); /* In case FPGA_INT was already low */
  157. goto done;
  158. release_bus_fail:
  159. spi_bus_remove_device(spi_handle);
  160. spi_handle = NULL;
  161. free_bus_fail:
  162. spi_bus_free(FPGA_SPI_HOST);
  163. init_fail:
  164. xEventGroupSetBits(fpga_service_evgroup, NOTIFY_DISABLE);
  165. done:
  166. return !err;
  167. }
  168. static void fpga_link_disable(void)
  169. {
  170. if (!spi_handle)
  171. return; /* Already stopped */
  172. xEventGroupClearBits(fpga_service_evgroup, NOTIFY_ENABLE);
  173. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  174. detachInterrupt(PIN_FPGA_INT);
  175. spi_device_release_bus(spi_handle);
  176. spi_bus_remove_device(spi_handle);
  177. spi_bus_free(FPGA_SPI_HOST);
  178. spi_handle = NULL;
  179. xEventGroupSetBits(fpga_service_evgroup, NOTIFY_DISABLE);
  180. }
  181. static void fpga_poll_set_time(void);
  182. static bool fpga_online(void)
  183. {
  184. fpga_io_read(FPGA_CMD_ACK(EL_UIRQ_READY), ESPLINK_HDR_ADDR,
  185. &head, sizeof head);
  186. if (head.magic != ESPLINK_HEAD_MAGIC || head.hlen <= 8) {
  187. printf("[FPGA] Bad header received, magic = 0x%08x len = %u\n",
  188. head.magic, head.hlen);
  189. return false;
  190. }
  191. if (unlikely(head.hlen < sizeof head)) {
  192. /* Clear any fields not provided */
  193. memset((char *)&head + head.hlen, 0, sizeof head - head.hlen);
  194. }
  195. printf("[FPGA] Ready, board = %u.%u fixes %02x fpga %u\n",
  196. head.board.major, head.board.minor,
  197. head.board.fixes, head.board.fpga);
  198. printf("[FPGA] online, signature \"%.*s\"\n",
  199. (int)(sizeof head.signature - 1), head.signature);
  200. esplink_start(&head);
  201. setenv_bool("status.max80.fpga", true);
  202. xSemaphoreGiveRecursive(spi_mutex);
  203. xTimerStart(fpga_timesync_timer, portMAX_DELAY);
  204. fpga_poll_set_time();
  205. return true;
  206. }
  207. static void fpga_offline(void)
  208. {
  209. memset(&head, 0, sizeof head);
  210. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  211. xTimerStop(fpga_timesync_timer, portMAX_DELAY);
  212. setenv_bool("status.max80.fpga", false);
  213. esplink_start(NULL); /* Stop esplink */
  214. }
  215. esp_err_t fpga_iov(const struct fpga_iov *iov, size_t niov)
  216. {
  217. spi_transaction_ext_t trans[FPGA_IOV_MAX];
  218. size_t ntrans = 0;
  219. if (niov > FPGA_IOV_MAX)
  220. return ESP_ERR_INVALID_ARG;
  221. for (size_t i = 0; i < niov; i++) {
  222. const struct fpga_iov *iv = &iov[i];
  223. if (!iv->len && !(iv->cmd & FPGA_CMD_NULL))
  224. continue;
  225. spi_transaction_ext_t *t = &trans[ntrans];
  226. memset(t, 0, sizeof *t);
  227. t->base.flags =
  228. SPI_TRANS_MODE_DIO |
  229. SPI_TRANS_VARIABLE_DUMMY |
  230. SPI_TRANS_MULTILINE_CMD |
  231. SPI_TRANS_MULTILINE_ADDR;
  232. t->base.cmd = iv->cmd;
  233. t->base.addr = iv->iaddr;
  234. if (iv->cmd & FPGA_CMD_RD) {
  235. t->base.rxlength = iv->len << 3;
  236. t->base.rx_buffer = iv->rdata;
  237. /* Emulate partial word read by adding dummy bits for offset */
  238. t->dummy_bits = 16 + ((iv->iaddr & 3) << 2);
  239. if (iv->cmd & FPGA_CMD_STATUS) {
  240. /*
  241. * Include the status "dummy" bits
  242. * THIS REQUIRES THE REMOTE ADDRESS TO BE 32-BIT ALIGNED
  243. */
  244. t->base.rxlength += 32;
  245. t->dummy_bits -= 16;
  246. }
  247. } else {
  248. t->base.length = iv->len << 3;
  249. t->base.tx_buffer = iv->wdata;
  250. }
  251. ntrans++;
  252. }
  253. if (!ntrans)
  254. return ESP_OK;
  255. esp_err_t err = ESP_OK;
  256. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  257. if (!spi_handle) {
  258. err = ESP_FAIL;
  259. goto fail;
  260. }
  261. xEventGroupClearBits(spi_done_evgroup, EVENT_ALL_BITS);
  262. size_t tbit = 1;
  263. for (size_t i = 0; i < ntrans; i++) {
  264. spi_transaction_ext_t *t = &trans[i];
  265. t->base.user = (void *)tbit;
  266. err = spi_device_queue_trans(spi_handle, &t->base, portMAX_DELAY);
  267. if (err) {
  268. ntrans = i;
  269. break;
  270. }
  271. tbit <<= 1;
  272. }
  273. if (likely(ntrans)) {
  274. xEventGroupWaitBits(spi_done_evgroup, tbit-1, pdTRUE, pdTRUE,
  275. portMAX_DELAY);
  276. while (ntrans--) {
  277. /* This is insanely stupid to have to do when not needed */
  278. spi_transaction_t *tp;
  279. spi_device_get_trans_result(spi_handle, &tp, 0);
  280. }
  281. }
  282. fail:
  283. xSemaphoreGiveRecursive(spi_mutex);
  284. return err;
  285. }
  286. esp_err_t fpga_io_write(unsigned int cmd, const volatile void *addr,
  287. const void *data, size_t len)
  288. {
  289. struct fpga_iov iov;
  290. iov.cmd = cmd | ~FPGA_CMD_RD;
  291. iov.addr = addr;
  292. iov.wdata = data;
  293. iov.len = len;
  294. return fpga_iov(&iov, 1);
  295. }
  296. esp_err_t fpga_io_read(unsigned int cmd, const volatile void *addr,
  297. void *data, size_t len)
  298. {
  299. struct fpga_iov iov;
  300. iov.cmd = cmd | FPGA_CMD_RD;
  301. iov.addr = addr;
  302. iov.rdata = data;
  303. iov.len = len;
  304. return fpga_iov(&iov, 1);
  305. }
  306. /*
  307. * This should be executed after getting an EL_UIRQ_TIME notification;
  308. * do this in polling mode for best latency.
  309. */
  310. static void fpga_get_time(void)
  311. {
  312. esp_err_t err;
  313. struct tm tm;
  314. struct timeval tv;
  315. struct tsbuf {
  316. /* These two words are the status word normally considered "dummy" */
  317. uint16_t status;
  318. uint16_t tick;
  319. struct esplink_timesync_buf get;
  320. } tsbuf;
  321. if (!head.tsync) {
  322. fpga_io_status(FPGA_CMD_ACK(EL_UIRQ_TIME));
  323. return;
  324. }
  325. spi_transaction_ext_t trans;
  326. memset(&trans, 0, sizeof trans);
  327. trans.base.flags =
  328. SPI_TRANS_MODE_DIO |
  329. SPI_TRANS_VARIABLE_DUMMY |
  330. SPI_TRANS_MULTILINE_CMD |
  331. SPI_TRANS_MULTILINE_ADDR;
  332. trans.base.rxlength = sizeof tsbuf << 3;
  333. trans.base.rx_buffer = &tsbuf;
  334. trans.base.addr = (size_t)&head.tsync->get;
  335. trans.base.cmd = FPGA_CMD_RD | FPGA_CMD_ACK(EL_UIRQ_TIME);
  336. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  337. err = spi_device_polling_transmit(spi_handle, &trans.base);
  338. xSemaphoreGiveRecursive(spi_mutex);
  339. if (err)
  340. return;
  341. if (time_net_sync_status)
  342. return; /* Ignore time from RTC if SNTP active now */
  343. tm.tm_sec = tsbuf.get.tm.sec2 << 1;
  344. tm.tm_min = tsbuf.get.tm.min;
  345. tm.tm_hour = tsbuf.get.tm.hour;
  346. tm.tm_mday = tsbuf.get.tm.mday;
  347. tm.tm_mon = tsbuf.get.tm.mon - 1;
  348. tm.tm_year = tsbuf.get.tm.year + 80;
  349. tm.tm_isdst = -1; /* Unknown */
  350. /* The third term handles wraparounds due to delay in transit */
  351. tv.tv_sec = mktime(&tm) + (tsbuf.tick >> 15) +
  352. ((tsbuf.get.tick >= tsbuf.tick) << 1);
  353. tv.tv_usec = (((uint32_t)tsbuf.tick << 17) * UINT64_C(1000000)) >> 32;
  354. settimeofday(&tv, NULL);
  355. print_time("[FPGA] Time set from RTC: ", &tv);
  356. }
  357. static void fpga_poll_set_time(void)
  358. {
  359. if (!head.tsync)
  360. return;
  361. if (!time_net_sync_status) {
  362. /* Poll for current time; will call fpga_get_time() later */
  363. fpga_io_status(FPGA_CMD_IRQ(EL_DIRQ_TIME));
  364. return;
  365. }
  366. /* Otherwise transmit time to set the RTC */
  367. esp_err_t err;
  368. struct timeval tv;
  369. struct esplink_timesync_buf tset;
  370. spi_transaction_t trans;
  371. memset(&trans, 0, sizeof trans);
  372. tset.update = 1;
  373. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  374. gettimeofday(&tv, NULL);
  375. const struct tm *tm = localtime(&tv.tv_sec);
  376. tset.tick = ((tv.tv_usec * ((1ULL << (32+15))/1000000+1)) >> 32)
  377. + ((tv.tv_sec & 1) << 15);
  378. tset.tm.sec2 = tm->tm_sec >> 1;
  379. tset.tm.min = tm->tm_min;
  380. tset.tm.hour = tm->tm_hour;
  381. tset.tm.mday = tm->tm_mday;
  382. tset.tm.mon = tm->tm_mon + 1;
  383. tset.tm.year = tm->tm_year - 80;
  384. trans.flags =
  385. SPI_TRANS_MODE_DIO |
  386. SPI_TRANS_MULTILINE_CMD |
  387. SPI_TRANS_MULTILINE_ADDR;
  388. trans.length = sizeof tset << 3;
  389. trans.tx_buffer = &tset;
  390. trans.addr = (size_t)&head.tsync->set;
  391. trans.cmd = FPGA_CMD_WR | FPGA_CMD_IRQ(EL_DIRQ_TIME) |
  392. FPGA_CMD_ACK(EL_UIRQ_TIME);
  393. err = spi_device_polling_transmit(spi_handle, &trans);
  394. xSemaphoreGiveRecursive(spi_mutex);
  395. if (err)
  396. return;
  397. print_time("[FPGA] RTC update: ", &tv);
  398. }
  399. /*
  400. * Get status in polling mode (small transaction, < 256 CPU cycles).
  401. * cmd typically would be IRQ/ACK bits.
  402. */
  403. uint32_t fpga_io_status(unsigned int cmd)
  404. {
  405. spi_transaction_t trans;
  406. memset(&trans, 0, sizeof trans);
  407. trans.flags =
  408. SPI_TRANS_MODE_DIO |
  409. SPI_TRANS_MULTILINE_CMD |
  410. SPI_TRANS_MULTILINE_ADDR |
  411. SPI_TRANS_USE_RXDATA;
  412. trans.cmd = cmd | FPGA_CMD_RD;
  413. trans.addr = 0;
  414. trans.rxlength = 32;
  415. esp_err_t err = ESP_OK;
  416. xSemaphoreTakeRecursive(spi_mutex, portMAX_DELAY);
  417. err = spi_device_polling_transmit(spi_handle, &trans);
  418. xSemaphoreGiveRecursive(spi_mutex);
  419. return err ? 0 : *(const uint32_t *)trans.rx_data;
  420. }
  421. static int fpga_read_func(token_t token, void *buf, size_t len)
  422. {
  423. const void **pp = token;
  424. const char *p = *pp;
  425. esp_err_t err;
  426. err = fpga_io_read(0, p, buf, len);
  427. if (err)
  428. return -1;
  429. p += len;
  430. *pp = p;
  431. return len;
  432. }
  433. static void fpga_ota_update(void)
  434. {
  435. struct esplink_ota ota;
  436. fpga_io_read(0, head.ota, &ota, sizeof ota);
  437. if (!ota.data)
  438. return;
  439. esp_update(fpga_read_func, &ota.data, ota.len);
  440. fpga_io_status(FPGA_CMD_ACK(EL_UIRQ_OTA)|FPGA_CMD_IRQ(EL_DIRQ_DONE));
  441. reboot_delayed();
  442. }
  443. static void fpga_service_task(void *dummy)
  444. {
  445. (void)dummy;
  446. uint32_t status;
  447. bool fpga_initialized = false;
  448. enum fpga_state {
  449. FPGA_DISABLED, /* FPGA services disabled */
  450. FPGA_OFFLINE, /* FPGA services enabled, waiting for FPGA */
  451. FPGA_ONLINE /* FPGA services active */
  452. } fpga_state = FPGA_DISABLED;
  453. fputs("[FPGA] Starting FPGA services task\n", stdout);
  454. while (1) {
  455. uint32_t notifiers, status;
  456. switch (fpga_state) {
  457. case FPGA_DISABLED:
  458. notifiers = notify_wait_for(NOTIFY_ENABLE);
  459. if ((notifiers & NOTIFY_ENABLE) && fpga_link_enable()) {
  460. fputs("[FPGA] Enabling FPGA services\n", stdout);
  461. fpga_state = FPGA_OFFLINE;
  462. }
  463. break;
  464. case FPGA_OFFLINE:
  465. status = fpga_io_status(FPGA_CMD_ACK(EL_UIRQ_READY)|
  466. FPGA_CMD_IRQ(EL_DIRQ_HELLO));
  467. printf("[FPGA] FPGA status flags = 0x%08x\n", status);
  468. if (!digitalRead(PIN_FPGA_INT)) {
  469. for (unsigned int i = 1; i < 8; i++) {
  470. if (status & (0x100 << i))
  471. status = fpga_io_status(FPGA_CMD_ACK(i));
  472. }
  473. if ((status & 0x301) == 0x300) {
  474. if (fpga_online()) {
  475. fpga_state = FPGA_ONLINE;
  476. break;
  477. }
  478. }
  479. }
  480. notifiers = notify_wait_for(NOTIFY_FPGA|NOTIFY_DISABLE);
  481. break;
  482. case FPGA_ONLINE:
  483. notifiers = notify_wait_for(NOTIFY_FPGA|NOTIFY_DISABLE|
  484. NOTIFY_TIMESYNC);
  485. if (notifiers & NOTIFY_DISABLE) {
  486. fpga_offline();
  487. break;
  488. }
  489. while (!digitalRead(PIN_FPGA_INT)) {
  490. status = fpga_io_status(0);
  491. if ((status & 0x301) != 0x100) {
  492. fpga_offline();
  493. printf("[FPGA] FPGA offline, status = 0x%08x\n", status);
  494. fpga_state = FPGA_OFFLINE;
  495. notifiers = 0;
  496. break;
  497. }
  498. if (status & (0x100 << EL_UIRQ_TIME))
  499. fpga_get_time();
  500. if (status & (0x100 << EL_UIRQ_RINGBUF))
  501. esplink_poll();
  502. if (status & (0x100 << EL_UIRQ_OTA))
  503. fpga_ota_update();
  504. for (unsigned int i = 5; i < 8; i++) {
  505. if (status & (0x100 << i)) {
  506. printf("[FPGA] Invalid interrupt %u received\n", i);
  507. status = fpga_io_status(FPGA_CMD_ACK(i));
  508. }
  509. }
  510. }
  511. if (notifiers & NOTIFY_TIMESYNC)
  512. fpga_poll_set_time();
  513. break;
  514. }
  515. if (notifiers & NOTIFY_DISABLE) {
  516. fputs("[FPGA] Disabling FPGA services\n", stdout);
  517. fpga_link_disable();
  518. fpga_state = FPGA_DISABLED;
  519. }
  520. }
  521. }