From: Bdale Garbee Date: Sat, 13 Oct 2018 16:17:47 +0000 (-0600) Subject: altos: remove usbtrng support (chaoskey prototypes) X-Git-Tag: 1.9~27^2~9 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=facf790f469df374257440ba9482321cbab7cecb altos: remove usbtrng support (chaoskey prototypes) --- diff --git a/src/usbtrng-v2.0/.gitignore b/src/usbtrng-v2.0/.gitignore deleted file mode 100644 index 93b38d11..00000000 --- a/src/usbtrng-v2.0/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -ao_product.h -usbtrng-* diff --git a/src/usbtrng-v2.0/Makefile b/src/usbtrng-v2.0/Makefile deleted file mode 100644 index 678a24de..00000000 --- a/src/usbtrng-v2.0/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -# AltOS build -# -# - -include ../stmf0/Makefile.defs - -INC = \ - ao.h \ - ao_arch.h \ - ao_arch_funcs.h \ - ao_pins.h \ - ao_product.h \ - ao_task.h \ - ao_adc_fast.h \ - stm32f0.h - -# -# Common AltOS sources -# -ALTOS_SRC = \ - ao_interrupt.c \ - ao_timer.c \ - ao_panic.c \ - ao_mutex.c \ - ao_dma_stm.c \ - ao_adc_fast.c \ - ao_crc_stm.c \ - ao_stdio.c \ - ao_led_stmf0.c \ - ao_romconfig.c \ - ao_boot_chain.c \ - ao_cmd.c \ - ao_usb_stm.c \ - ao_trng.c \ - ao_task.c \ - ao_product.c - -PRODUCT=usbtrng-v2.0 -PRODUCT_DEF=-DUSBTRNG_V_2_0 -IDPRODUCT=0x0028 - -CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) -g -Os - -PROGNAME=usbtrng-v2.0 -PROG=$(PROGNAME)-$(VERSION).elf -HEX=$(PROGNAME)-$(VERSION).ihx - -SRC=$(ALTOS_SRC) ao_usbtrng.c -OBJ=$(SRC:.c=.o) - -all: $(PROG) $(HEX) - -$(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) - -ao_product.h: ao-make-product.5c ../Version - $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ - -$(OBJ): $(INC) - -distclean: clean - -clean: - rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx - rm -f ao_product.h - -install: - -uninstall: diff --git a/src/usbtrng-v2.0/ao_pins.h b/src/usbtrng-v2.0/ao_pins.h deleted file mode 100644 index 2b23f967..00000000 --- a/src/usbtrng-v2.0/ao_pins.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2015 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#ifndef _AO_PINS_H_ -#define _AO_PINS_H_ - -#define LED_PORT_ENABLE STM_RCC_AHBENR_IOPAEN -#define LED_PORT (&stm_gpioa) -#define LED_PIN_RED 2 -#define LED_PIN_GREEN 3 -#define AO_LED_RED (1 << LED_PIN_RED) -#define AO_LED_GREEN (1 << LED_PIN_GREEN) - -#define LEDS_AVAILABLE (AO_LED_RED | AO_LED_GREEN) - -#define HAS_BEEP 0 - -/* 48MHz clock based on USB */ -#define AO_HSI48 1 - -/* HCLK = 48MHz */ -#define AO_AHB_PRESCALER 1 -#define AO_RCC_CFGR_HPRE_DIV STM_RCC_CFGR_HPRE_DIV_1 - -/* APB = 48MHz */ -#define AO_APB_PRESCALER 1 -#define AO_RCC_CFGR_PPRE_DIV STM_RCC_CFGR_PPRE_DIV_1 - -#define HAS_USB 1 -#define AO_USB_DIRECTIO 1 -#define AO_PA11_PA12_RMP 0 - -#define IS_FLASH_LOADER 0 - -/* ADC */ - -#define AO_ADC_PIN0_PORT (&stm_gpioa) -#define AO_ADC_PIN0_PIN 6 -#define AO_ADC_PIN0_CH 6 - -#define AO_ADC_RCC_AHBENR ((1 << STM_RCC_AHBENR_IOPAEN)) - -#define AO_NUM_ADC 1 - -/* CRC */ -#define AO_CRC_WIDTH 32 -#define AO_CRC_INIT 0xffffffff - -/* TRNG */ -#define AO_LED_TRNG_READ AO_LED_RED -#define AO_LED_TRNG_WRITE AO_LED_GREEN - -#endif /* _AO_PINS_H_ */ diff --git a/src/usbtrng-v2.0/ao_usbtrng.c b/src/usbtrng-v2.0/ao_usbtrng.c deleted file mode 100644 index e34babec..00000000 --- a/src/usbtrng-v2.0/ao_usbtrng.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#include -#include -#include -#include - -void main(void) -{ - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_RED); - ao_clock_init(); - ao_task_init(); - ao_timer_init(); - ao_dma_init(); - ao_adc_init(); - ao_crc_init(); - - ao_cmd_init(); - - ao_usb_init(); - - ao_trng_init(); - - ao_led_off(AO_LED_RED); - - ao_start_scheduler(); -} diff --git a/src/usbtrng-v2.0/flash-loader/.gitignore b/src/usbtrng-v2.0/flash-loader/.gitignore deleted file mode 100644 index 32dbbbcf..00000000 --- a/src/usbtrng-v2.0/flash-loader/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -ao_product.h -usbtrng* diff --git a/src/usbtrng-v2.0/flash-loader/Makefile b/src/usbtrng-v2.0/flash-loader/Makefile deleted file mode 100644 index a2bf199f..00000000 --- a/src/usbtrng-v2.0/flash-loader/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# -# AltOS flash loader build -# -# - -TOPDIR=../.. -HARDWARE=usbtrng-v2.0 -include $(TOPDIR)/stmf0/Makefile-flash.defs diff --git a/src/usbtrng-v2.0/flash-loader/ao_pins.h b/src/usbtrng-v2.0/flash-loader/ao_pins.h deleted file mode 100644 index 9e7c2c33..00000000 --- a/src/usbtrng-v2.0/flash-loader/ao_pins.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2013 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#ifndef _AO_PINS_H_ -#define _AO_PINS_H_ - -#include - -/* Red LED */ - -#define AO_BOOT_PIN 1 -#define AO_BOOT_APPLICATION_GPIO stm_gpioa -#define AO_BOOT_APPLICATION_PIN 2 -#define AO_BOOT_APPLICATION_VALUE 0 -#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_DOWN - -#endif /* _AO_PINS_H_ */ diff --git a/src/usbtrng/Makefile b/src/usbtrng/Makefile deleted file mode 100644 index 80e137e7..00000000 --- a/src/usbtrng/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -# AltOS build -# -# - -include ../lpc/Makefile.defs - -INC = \ - ao.h \ - ao_arch.h \ - ao_arch_funcs.h \ - ao_pins.h \ - ao_product.h \ - lpc.h - -# -# Common AltOS sources -# -ALTOS_SRC = \ - ao_interrupt.c \ - ao_boot_chain.c \ - ao_romconfig.c \ - ao_product.c \ - ao_mutex.c \ - ao_panic.c \ - ao_stdio.c \ - ao_task.c \ - ao_cmd.c \ - ao_timer_lpc.c \ - ao_exti_lpc.c \ - ao_usb_lpc.c \ - ao_serial_lpc.c \ - ao_spi_lpc.c \ - ao_led_lpc.c - -PRODUCT=usbtrng-v0.1 -PRODUCT_DEF=-DUSBTRNG_V_0_1 -IDPRODUCT=0x0028 - -CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS) -g -Os - -PROGNAME=usbtrng-v0.1 -PROG=$(PROGNAME)-$(VERSION).elf -HEX=$(PROGNAME)-$(VERSION).ihx - -SRC=$(ALTOS_SRC) ao_usbtrng.c -OBJ=$(SRC:.c=.o) - -all: $(PROG) $(HEX) - -$(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) - -ao_product.h: ao-make-product.5c ../Version - $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ - -$(OBJ): $(INC) - -load: $(PROG) - lpc-load $(PROG) - -distclean: clean - -clean: - rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx - rm -f ao_product.h - -install: - -uninstall: diff --git a/src/usbtrng/ao_pins.h b/src/usbtrng/ao_pins.h deleted file mode 100644 index 2fd5df33..00000000 --- a/src/usbtrng/ao_pins.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2013 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#define HAS_BEEP 0 - -#define AO_STACK_SIZE 384 - -#define IS_FLASH_LOADER 0 - -/* Crystal on the board */ -#define AO_LPC_CLKIN 12000000 - -/* Main clock frequency. 48MHz for USB so we don't use the USB PLL */ -#define AO_LPC_CLKOUT 48000000 - -/* System clock frequency */ -#define AO_LPC_SYSCLK 24000000 - -#define HAS_USB 1 - -#define HAS_USB_CONNECT 0 -#define HAS_USB_VBUS 0 -#define HAS_USB_PULLUP 1 -#define AO_USB_PULLUP_PORT 0 -#define AO_USB_PULLUP_PIN 6 - -/* USART */ - -#define HAS_SERIAL 1 -#define USE_SERIAL_0_STDIN 0 -#define SERIAL_0_18_19 1 -#define SERIAL_0_14_15 0 -#define SERIAL_0_17_18 0 -#define SERIAL_0_26_27 0 - -/* SPI */ - -#define HAS_SPI_0 0 -#define SPI_SCK0_P0_6 0 -#define HAS_SPI_1 1 -#define SPI_SCK1_P1_15 0 -#define SPI_MISO1_P0_22 1 -#define SPI_MOSI1_P0_21 0 - -/* LED */ - -#define LED_PORT 0 -#define LED_PIN_RED 3 -#define LED_PIN_GREEN 21 -#define AO_LED_RED (1 << LED_PIN_RED) -#define AO_LED_GREEN (1 << LED_PIN_GREEN) - -#define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN) - -/* Kludge the SPI driver to not configure any - * pin for SCK or MOSI - */ -#define HAS_SCK1 0 -#define HAS_MOSI1 0 - -#define AO_ADC_6 1 diff --git a/src/usbtrng/ao_usbtrng.c b/src/usbtrng/ao_usbtrng.c deleted file mode 100644 index cb15a250..00000000 --- a/src/usbtrng/ao_usbtrng.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#include - -#define AO_TRNG_SPI_BUS 1 - -static uint32_t spi_speed = AO_SPI_SPEED_4MHz; - -#define AO_TRNG_SPI_BUF 1024 - -#if 0 - -static uint8_t *spi_buf; -static uint8_t *spi_head, *spi_tail; -static uint8_t spi_wakeup; - -static void -ao_trng_run(void) -{ - int this_time; - uint8_t *end; - - if (!spi_buf) - spi_buf = ao_usb_alloc(AO_TRNG_SPI_BUF); - flush(); - ao_spi_get(AO_TRNG_SPI_BUS, spi_speed); - spi_tail = spi_buf; - spi_head = spi_buf; - ao_spi_recv_ring_start(spi_buf, AO_TRNG_SPI_BUF, &spi_head, &spi_tail, &spi_wakeup, AO_TRNG_SPI_BUS); - while (!ao_usb_out_avail) { - ao_arch_block_interrupts(); - while (spi_head == spi_tail) { - spi_wakeup = 0; - ao_sleep(&spi_wakeup); - } - ao_arch_release_interrupts(); - if (spi_tail > spi_head) - end = spi_buf + AO_TRNG_SPI_BUF; - else - end = spi_head; - this_time = end - spi_tail; - if (this_time > 64) - this_time = 64; - ao_usb_write(spi_tail, this_time); - spi_tail += this_time; - if (spi_tail == spi_buf + AO_TRNG_SPI_BUF) - spi_tail = spi_buf; - } - ao_spi_put(AO_TRNG_SPI_BUS); - getchar(); -} - - -static void -ao_trng_test(void) -{ - static uint8_t random[32]; - uint8_t i; - - ao_spi_get(AO_TRNG_SPI_BUS, spi_speed); - ao_spi_recv(random, sizeof (random), AO_TRNG_SPI_BUS); - ao_spi_put(AO_TRNG_SPI_BUS); - for (i = 0; i < sizeof (random); i++) - printf (" %02x", random[i]); - printf ("\n"); -} -#endif - -#define ADC_RING_SIZE 512 - -static uint8_t *adc_ring; -static uint16_t adc_head, adc_tail; -static uint16_t adc_wake; - -void lpc_adc_isr(void) -{ - uint16_t avail; - uint16_t this, next; - - this = adc_head; - next = (this + 1) & (ADC_RING_SIZE - 1); - if (next == adc_tail) { - lpc_adc.inten = 0; - return; - } - adc_ring[this] = lpc_adc.dr[6] >> 8; - adc_head = next; - - /* If there are enough entries, wake up any waiters - */ - avail = (next - adc_tail) & (ADC_RING_SIZE - 1); - if (avail >= adc_wake) { - adc_wake = 0; - ao_wakeup(&adc_wake); - } -} - -#define AO_ADC_CLKDIV (AO_LPC_SYSCLK / 450000) - -static void -ao_trng_adc_init(void) -{ - adc_ring = ao_usb_alloc(ADC_RING_SIZE); - - lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_ADC); - lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_ADC_PD); - - /* Enable interrupt when AO_ADC_6 is complete */ - lpc_adc.inten = 0; - - lpc_nvic_set_enable(LPC_ISR_ADC_POS); - lpc_nvic_set_priority(LPC_ISR_ADC_POS, AO_LPC_NVIC_CLOCK_PRIORITY); - -#if AO_ADC_0 - ao_enable_analog(0, 11, 0); -#endif -#if AO_ADC_1 - ao_enable_analog(0, 12, 1); -#endif -#if AO_ADC_2 - ao_enable_analog(0, 13, 2); -#endif -#if AO_ADC_3 - ao_enable_analog(0, 14, 3); -#endif -#if AO_ADC_4 - ao_enable_analog(0, 15, 4); -#endif -#if AO_ADC_5 - ao_enable_analog(0, 16, 5); -#endif -#if AO_ADC_6 - ao_enable_analog(0, 22, 6); -#endif -#if AO_ADC_7 - ao_enable_analog(0, 23, 7); -#endif - - lpc_adc.cr = ((1 << (LPC_ADC_CR_SEL + 6)) | - (AO_ADC_CLKDIV << LPC_ADC_CR_CLKDIV) | - (1 << LPC_ADC_CR_BURST) | - (LPC_ADC_CR_CLKS_9 << LPC_ADC_CR_CLKS)); -} - -static void -ao_trng_adc_dump(void) -{ - int i; - - while (((adc_head - adc_tail) & (ADC_RING_SIZE - 1)) < 16) { - lpc_adc.inten = (1 << (LPC_ADC_INTEN_ADINTEN + 6)); - adc_wake = 16; - ao_sleep(&adc_wake); - } - printf("adc_head %d tail %d\n", adc_head, adc_tail); - - for (i = 0; i < 16; i++) { - printf(" %4d", adc_ring[adc_tail]); - adc_tail = (adc_tail + 1) & (ADC_RING_SIZE - 1); - } - printf("\n"); - lpc_adc.inten = 0; -} - -static void -ao_trng_run(void) -{ - uint16_t this_time; - flush(); - - while (!ao_usb_out_avail) { - ao_arch_block_interrupts(); - while (((adc_head - adc_tail) & (ADC_RING_SIZE - 1)) < 64) { - lpc_adc.inten = (1 << (LPC_ADC_INTEN_ADINTEN + 6)); - adc_wake = 64; - ao_sleep(&adc_wake); - } - ao_arch_release_interrupts(); - - this_time = ADC_RING_SIZE - adc_tail; - if (this_time > 64) - this_time = 64; - ao_usb_write(&adc_ring[adc_tail], this_time); - adc_tail = (adc_tail + this_time) & (ADC_RING_SIZE - 1); - } - lpc_adc.inten = 0; -} - -static void -ao_trng_speed(void) -{ - ao_cmd_decimal(); - - if (ao_cmd_lex_u32 == 0 || ao_cmd_status != ao_cmd_success) { - ao_cmd_status = ao_cmd_success; - printf ("Current spi speed %d\n", spi_speed); - } else { - spi_speed = ao_cmd_lex_u32; - } -} - -static const struct ao_cmds ao_trng_cmds[] = { -// { ao_trng_test, "R\0Dump some random numbers" }, - { ao_trng_run, "s\0Send random bits until char" }, - { ao_trng_speed, "S \0Set SPI speed (48MHz/speed)" }, - { ao_trng_adc_dump, "a\0Dump ADC data" }, - { 0, NULL } -}; - -void -main(void) -{ - ao_clock_init(); - ao_task_init(); - ao_timer_init(); - -// ao_spi_init(); - ao_usb_init(); - - ao_trng_adc_init(); - - ao_serial_init(); - - ao_led_init(LEDS_AVAILABLE); - - ao_cmd_init(); - - ao_cmd_register(ao_trng_cmds); - - ao_start_scheduler(); -} diff --git a/src/usbtrng/flash-loader/Makefile b/src/usbtrng/flash-loader/Makefile deleted file mode 100644 index e34f1089..00000000 --- a/src/usbtrng/flash-loader/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# -# AltOS flash loader build -# -# - -TOPDIR=../.. -HARDWARE=usbtrng-v0.1 -include $(TOPDIR)/lpc/Makefile-flash.defs diff --git a/src/usbtrng/flash-loader/ao_pins.h b/src/usbtrng/flash-loader/ao_pins.h deleted file mode 100644 index cb385600..00000000 --- a/src/usbtrng/flash-loader/ao_pins.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2013 Keith Packard - * - * 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#ifndef _AO_PINS_H_ -#define _AO_PINS_H_ - -#include - -#define AO_BOOT_PIN 1 -#define AO_BOOT_APPLICATION_GPIO 0 -#define AO_BOOT_APPLICATION_PIN 19 -#define AO_BOOT_APPLICATION_VALUE 1 -#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP - -#define HAS_USB_PULLUP 1 -#define AO_USB_PULLUP_PORT 0 -#define AO_USB_PULLUP_PIN 6 - -#endif /* _AO_PINS_H_ */