altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / kernel / ao_flash_readout.c
1 /*
2  * Copyright © 2018 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include <ao.h>
16 #include <ao_usb.h>
17 #include <ao_flash_readout.h>
18
19 #ifndef AO_FLASH_READOUT_BASE
20 #define AO_FLASH_READOUT_BASE   AO_BOOT_LOADER_BASE
21 #define AO_FLASH_READOUT_BOUND  AO_BOOT_APPLICATION_BOUND
22 #endif
23
24 static void
25 ao_flash_readout(void)
26 {
27         uint8_t *base = (uint8_t *) AO_FLASH_READOUT_BASE;
28         uint8_t *bound = (uint8_t *) AO_FLASH_READOUT_BOUND;
29         uint8_t *p = base;
30
31         for (;;) {
32                 ao_arch_block_interrupts();
33                 while (!ao_usb_running) {
34                         p = base;
35                         ao_sleep(&ao_usb_running);
36                 }
37                 ao_arch_release_interrupts();
38                 ao_flash_readout_putchar(*p++);
39                 if (p == bound)
40                         p = base;
41         }
42 }
43
44 static struct ao_task   ao_flash_readout_task;
45
46 void
47 ao_flash_readout_init(void)
48 {
49         ao_add_task(&ao_flash_readout_task, ao_flash_readout, "flash_readout");
50 }