fpgasvc.c 16 KB

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