diff options
author | Keith Packard <keithp@keithp.com> | 2018-05-06 21:13:02 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2018-05-07 09:21:56 -0700 |
commit | bea42e45952df85d61428662caefbb100465a585 (patch) | |
tree | 34ec1af35c03183e42d4a7ae96b862640d83f330 /src/kernel/ao_flash_readout.c | |
parent | 4451f7b6bade66775a197b93c6e70ba15f1826ce (diff) |
altos/chaoskey-v1.0: Add endpoint for reading flash contents
This creates another IN endpoint which provides the contents of flash
for validation of the firmware load on the host.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/kernel/ao_flash_readout.c')
-rw-r--r-- | src/kernel/ao_flash_readout.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/kernel/ao_flash_readout.c b/src/kernel/ao_flash_readout.c new file mode 100644 index 00000000..46b5ba7a --- /dev/null +++ b/src/kernel/ao_flash_readout.c @@ -0,0 +1,50 @@ +/* + * Copyright © 2018 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <ao.h> +#include <ao_usb.h> +#include <ao_flash_readout.h> + +#ifndef AO_FLASH_READOUT_BASE +#define AO_FLASH_READOUT_BASE AO_BOOT_LOADER_BASE +#define AO_FLASH_READOUT_BOUND AO_BOOT_APPLICATION_BOUND +#endif + +static void +ao_flash_readout(void) +{ + uint8_t *base = (uint8_t *) AO_FLASH_READOUT_BASE; + uint8_t *bound = (uint8_t *) AO_FLASH_READOUT_BOUND; + uint8_t *p = base; + + for (;;) { + ao_arch_block_interrupts(); + while (!ao_usb_running) { + p = base; + ao_sleep(&ao_usb_running); + } + ao_arch_release_interrupts(); + ao_flash_readout_putchar(*p++); + if (p == bound) + p = base; + } +} + +static struct ao_task ao_flash_readout_task; + +void +ao_flash_readout_init(void) +{ + ao_add_task(&ao_flash_readout_task, ao_flash_readout, "flash_readout"); +} |