From b7a21bf6a086748b4907c0577eaa114445995783 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Sep 2018 00:07:38 -0700 Subject: altos/stm32f4: Start adding support for STM32F413 Enough to get clocks lit up at least. Signed-off-by: Keith Packard --- src/stm32f4/ao_arch.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/stm32f4/ao_arch.h (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h new file mode 100644 index 00000000..805d756d --- /dev/null +++ b/src/stm32f4/ao_arch.h @@ -0,0 +1,104 @@ +/* + * Copyright © 2018 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. + */ + +#ifndef _AO_ARCH_H_ +#define _AO_ARCH_H_ + +#include +#include + +#ifndef AO_STACK_SIZE +#define AO_STACK_SIZE 512 +#endif + +#define AO_PORT_TYPE uint16_t + +#define ao_arch_nop() asm("nop") + +#define ao_arch_task_members\ + uint32_t *sp; /* saved stack pointer */ + +#define ao_arch_block_interrupts() asm("cpsid i") +#define ao_arch_release_interrupts() asm("cpsie i") + +#define ao_arch_naked_declare __attribute__((naked)) +#define ao_arch_naked_define + +/* + * ao_timer.c + * + * We'll generally use the HSE clock through the PLL + */ + +#define AO_STM_NVIC_CLOCK_PRIORITY 0xf0 /* low priority for clock */ + +#if AO_HSE +#define AO_PLLSRC AO_HSE +#endif + +#if AO_HSI +#define AO_PLLSRC STM_HSI_FREQ +#endif + +#if AO_PLL_M +#define AO_PLLIN (AO_PLLSRC / AO_PLL_M) +#endif + +#if AO_PLL1_N + +#define AO_PLL1_VCO (AO_PLLIN * AO_PLL1_N) +#define AO_PLL1_CLK_P (AO_PLL1_VCO / AO_PLL1_P) +#define AO_SYSCLK (AO_PLL1_CLK_P) + +# if AO_PLL1_Q +#define AO_PLL1_CLK_Q (AO_PLL1_VCO / AO_PLL1_Q) +# endif + +#else + +#define AO_SYSCLK AO_PLLSRC + +#endif + +#if AO_PLL2_N + +#define AO_PLL2_VCO (AO_PLLIN * AO_PLL2_N) + +# if AO_PLL2_Q +#define AO_PLL2_CLK_Q (AL_PLL2_VCO / AO_PLL2_Q) +# endif + +# if AO_PLL2_R +#define AO_PLL2_CLK_R (AL_PLL2_VCO / AO_PLL2_R) +# endif + +#endif + +#define AO_HCLK (AO_SYSCLK / AO_AHB_PRESCALER) +#define AO_P1CLK (AO_HCLK / AO_APB1_PRESCALER) +#if AO_ABP1_PRESCALER == 1 +#define AO_P1_TIMER_CLK AO_P1CLK +#else +#define AO_P1_TIMER_CLK (AO_P1CLK * 2) +#endif +#define AO_P2CLK (AO_HCLK / AO_APB2_PRESCALER) +#if AO_ABP2_PRESCALER == 1 +#define AO_P2_TIMER_CLK AO_P2CLK +#else +#define AO_P2_TIMER_CLK (AO_P2CLK * 2) +#endif +#define AO_SYSTICK (AO_HCLK) +#define AO_PANIC_DELAY_SCALE (AO_SYSCLK / 12000000) + +#endif /* _AO_ARCH_H_ */ -- cgit v1.2.3 From 2cdb1f30c49ba460b0850d23ba9c85e0336af290 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Sep 2018 11:57:50 -0700 Subject: altos: Add generic LED driver. This driver uses the generic GPIO functions and allows per-LED port and pin configuration. It supports up to 32 LEDs. Rename SoC-specific LED drivers. Remove enabled parameter to ao_led_init Signed-off-by: Keith Packard --- src/attiny/ao_arch.h | 2 + src/attiny/ao_led.c | 64 --------- src/attiny/ao_led_tiny.c | 61 ++++++++ src/avr-demo/Makefile | 2 +- src/avr/ao_led.c | 68 --------- src/avr/ao_led_avr.c | 68 +++++++++ src/chaoskey-v0.1/Makefile | 2 +- src/chaoskey-v1.0/Makefile | 2 +- src/chaoskey-v1.0/ao_chaoskey.c | 2 +- src/detherm/Makefile | 2 +- src/drivers/ao_led.c | 174 +++++++++++++++++++++++ src/easymega-v1.0/Makefile | 2 +- src/easymega-v1.0/ao_easymega.c | 2 +- src/fox1ihu/Makefile | 2 +- src/fox1ihu/ao_fox1ihu.c | 2 +- src/kernel/ao.h | 2 +- src/kernel/ao_led.h | 202 +++++++++++++++++++++++++- src/kernel/ao_task.c | 1 + src/kernel/ao_task.h | 2 +- src/lambdakey-v1.0/Makefile | 2 +- src/lpc/ao_led_lpc.c | 17 ++- src/megadongle-v0.1/Makefile | 2 +- src/microkite/Makefile | 2 +- src/micropeak-v2.0/Makefile | 2 +- src/micropeak-v2.0/ao_micropeak.c | 2 +- src/micropeak/Makefile | 2 +- src/microsplash/Makefile | 2 +- src/nanopeak-v0.1/Makefile | 2 +- src/nucleao-32/Makefile | 2 +- src/pnpservo-v1/Makefile | 2 +- src/product/ao_micropeak.c | 2 +- src/stm-demo/Makefile | 2 +- src/stm-scheme-newlib/Makefile | 2 +- src/stm-vga/Makefile | 2 +- src/stm/ao_led.c | 216 ---------------------------- src/stm/ao_led_stm.c | 144 +++++++++++++++++++ src/stm32f4-disco/Makefile | 5 +- src/stm32f4-disco/ao_disco.c | 41 ++++-- src/stm32f4-disco/ao_pins.h | 29 ++-- src/stm32f4/ao_arch.h | 3 - src/stm32f4/ao_arch_funcs.h | 228 ++++++++++++++++++++++++++++++ src/stmf0/ao_led.c | 126 ----------------- src/stmf0/ao_led_stmf0.c | 123 ++++++++++++++++ src/teleballoon-v2.0/Makefile | 2 +- src/teleballoon-v2.0/ao_teleballoon.c | 7 +- src/telebt-v3.0/Makefile | 2 +- src/telebt-v3.0/ao_telebt.c | 2 +- src/telebt-v4.0/Makefile | 2 +- src/telebt-v4.0/ao_telebt.c | 2 +- src/teledongle-v1.8/Makefile | 2 +- src/teledongle-v3.0/ao_teledongle.c | 2 +- src/telefireeight-v1.0/ao_pins.h | 29 +--- src/telefireeight-v1.0/ao_telefireeight.c | 5 +- src/telefireone-v1.0/Makefile | 2 +- src/telefiretwo-v0.1/Makefile | 2 +- src/telefiretwo-v0.1/ao_telefiretwo.c | 5 +- src/telefiretwo-v0.2/Makefile | 2 +- src/telegps-v0.1/Makefile | 2 +- src/telegps-v2.0/Makefile | 2 +- src/telegps-v2.0/ao_telegps.c | 7 +- src/telelco-v0.2-cc1200/Makefile | 2 +- src/telelco-v0.2-cc1200/ao_telelco.c | 7 +- src/telelco-v0.2/Makefile | 2 +- src/telelco-v0.2/ao_telelco.c | 14 +- src/telelco-v0.3/Makefile | 2 +- src/telelco-v0.3/ao_telelco.c | 6 +- src/telelco-v2.0/ao_lco_v2.c | 4 +- src/telelco-v2.0/ao_pins.h | 73 +++------- src/telelco-v2.0/ao_telelco.c | 6 +- src/telelcotwo-v0.1/Makefile | 2 +- src/telelcotwo-v0.1/ao_telelcotwo.c | 6 +- src/telemega-v0.1/Makefile | 2 +- src/telemega-v0.1/ao_telemega.c | 5 +- src/telemega-v1.0/Makefile | 2 +- src/telemega-v1.0/ao_telemega.c | 2 +- src/telemega-v2.0/Makefile | 2 +- src/telemega-v2.0/ao_telemega.c | 2 +- src/telemega-v3.0/Makefile | 2 +- src/telemega-v3.0/ao_telemega.c | 2 +- src/telemetrum-v2.0/Makefile | 2 +- src/telemetrum-v2.0/ao_telemetrum.c | 2 +- src/telemetrum-v3.0/Makefile | 2 +- src/telemetrum-v3.0/ao_telemetrum.c | 5 +- src/telepyro-v0.1/Makefile | 2 +- src/telescience-pwm/Makefile | 2 +- src/telescience-v0.1/Makefile | 2 +- src/telescience-v0.2/Makefile | 2 +- src/tmgps-v2.0/Makefile | 2 +- src/usbtrng-v2.0/Makefile | 2 +- 89 files changed, 1186 insertions(+), 679 deletions(-) delete mode 100644 src/attiny/ao_led.c create mode 100644 src/attiny/ao_led_tiny.c delete mode 100644 src/avr/ao_led.c create mode 100644 src/avr/ao_led_avr.c create mode 100644 src/drivers/ao_led.c delete mode 100644 src/stm/ao_led.c create mode 100644 src/stm/ao_led_stm.c delete mode 100644 src/stmf0/ao_led.c create mode 100644 src/stmf0/ao_led_stmf0.c (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/attiny/ao_arch.h b/src/attiny/ao_arch.h index 84a94be7..a9c450fc 100644 --- a/src/attiny/ao_arch.h +++ b/src/attiny/ao_arch.h @@ -34,6 +34,8 @@ #define AO_PORT_TYPE uint8_t +#define AO_LED_TYPE uint8_t + /* Various definitions to make GCC look more like SDCC */ #define ao_arch_naked_declare __attribute__((naked)) diff --git a/src/attiny/ao_led.c b/src/attiny/ao_led.c deleted file mode 100644 index 88505490..00000000 --- a/src/attiny/ao_led.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © 2009 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 "ao.h" - -uint8_t ao_led_enable; - -#define LED_PORT PORTB -#define LED_DDR DDRB - -void -ao_led_on(uint8_t colors) -{ - LED_PORT |= (colors & ao_led_enable); -} - -void -ao_led_off(uint8_t colors) -{ - LED_PORT &= ~(colors & ao_led_enable); -} - -void -ao_led_set(uint8_t colors) -{ - LED_PORT = (LED_PORT & ~(ao_led_enable)) | (colors & ao_led_enable); -} - -void -ao_led_toggle(uint8_t colors) -{ - LED_PORT ^= (colors & ao_led_enable); -} - -void -ao_led_for(uint8_t colors, uint16_t ticks) -{ - ao_led_on(colors); - ao_delay(ticks); - ao_led_off(colors); -} - -void -ao_led_init(uint8_t enable) -{ - ao_led_enable = enable; - LED_PORT &= ~enable; - LED_DDR |= enable; -} diff --git a/src/attiny/ao_led_tiny.c b/src/attiny/ao_led_tiny.c new file mode 100644 index 00000000..cd620f46 --- /dev/null +++ b/src/attiny/ao_led_tiny.c @@ -0,0 +1,61 @@ +/* + * Copyright © 2009 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 "ao.h" + +#define LED_PORT PORTB +#define LED_DDR DDRB + +void +ao_led_on(uint8_t colors) +{ + LED_PORT |= colors; +} + +void +ao_led_off(uint8_t colors) +{ + LED_PORT &= ~colors; +} + +void +ao_led_set(uint8_t colors) +{ + LED_PORT = (LED_PORT & ~LEDS_AVAILABLE) | (colors & LEDS_AVAILABLE); +} + +void +ao_led_toggle(uint8_t colors) +{ + LED_PORT ^= (colors & LEDS_AVAILABLE); +} + +void +ao_led_for(uint8_t colors, AO_TICK_TYPE ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +void +ao_led_init(void) +{ + LED_PORT &= ~LEDS_AVAILABLE; + LED_DDR |= LEDS_AVAILABLE; +} diff --git a/src/avr-demo/Makefile b/src/avr-demo/Makefile index e21ad047..0aca6f8a 100644 --- a/src/avr-demo/Makefile +++ b/src/avr-demo/Makefile @@ -38,7 +38,7 @@ ALTOS_SRC = \ ao_stdio.c \ ao_task.c \ ao_timer.c \ - ao_led.c \ + ao_led_avr.c \ ao_usb_avr.c \ ao_lcd.c diff --git a/src/avr/ao_led.c b/src/avr/ao_led.c deleted file mode 100644 index 165e95d3..00000000 --- a/src/avr/ao_led.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2009 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 "ao.h" - -uint8_t ao_led_enable; - -#define LED_PORT PORTB -#define LED_DDR DDRB - -void -ao_led_on(uint8_t colors) -{ - LED_PORT |= (colors & ao_led_enable); -} - -void -ao_led_off(uint8_t colors) -{ - LED_PORT &= ~(colors & ao_led_enable); -} - -void -ao_led_set(uint8_t colors) -{ - LED_PORT = (LED_PORT & ~(ao_led_enable)) | (colors & ao_led_enable); -} - -void -ao_led_toggle(uint8_t colors) -{ - LED_PORT ^= (colors & ao_led_enable); -} - -void -ao_led_for(uint8_t colors, uint16_t ticks) -{ - ao_led_on(colors); - ao_delay(ticks); - ao_led_off(colors); -} - -void -ao_led_init(uint8_t enable) -{ - ao_led_enable = enable; - if ((LED_DDR & enable)) { - printf ("oops! restarted\n"); - ao_panic(AO_PANIC_REBOOT); - } - LED_PORT &= ~enable; - LED_DDR |= enable; -} diff --git a/src/avr/ao_led_avr.c b/src/avr/ao_led_avr.c new file mode 100644 index 00000000..165e95d3 --- /dev/null +++ b/src/avr/ao_led_avr.c @@ -0,0 +1,68 @@ +/* + * Copyright © 2009 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 "ao.h" + +uint8_t ao_led_enable; + +#define LED_PORT PORTB +#define LED_DDR DDRB + +void +ao_led_on(uint8_t colors) +{ + LED_PORT |= (colors & ao_led_enable); +} + +void +ao_led_off(uint8_t colors) +{ + LED_PORT &= ~(colors & ao_led_enable); +} + +void +ao_led_set(uint8_t colors) +{ + LED_PORT = (LED_PORT & ~(ao_led_enable)) | (colors & ao_led_enable); +} + +void +ao_led_toggle(uint8_t colors) +{ + LED_PORT ^= (colors & ao_led_enable); +} + +void +ao_led_for(uint8_t colors, uint16_t ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +void +ao_led_init(uint8_t enable) +{ + ao_led_enable = enable; + if ((LED_DDR & enable)) { + printf ("oops! restarted\n"); + ao_panic(AO_PANIC_REBOOT); + } + LED_PORT &= ~enable; + LED_DDR |= enable; +} diff --git a/src/chaoskey-v0.1/Makefile b/src/chaoskey-v0.1/Makefile index 85392280..faa4a291 100644 --- a/src/chaoskey-v0.1/Makefile +++ b/src/chaoskey-v0.1/Makefile @@ -28,7 +28,7 @@ ALTOS_SRC = \ ao_adc_fast.c \ ao_crc_stm.c \ ao_stdio.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_romconfig.c \ ao_boot_chain.c \ ao_usb_stm.c \ diff --git a/src/chaoskey-v1.0/Makefile b/src/chaoskey-v1.0/Makefile index c6cf45bd..329f603d 100644 --- a/src/chaoskey-v1.0/Makefile +++ b/src/chaoskey-v1.0/Makefile @@ -30,7 +30,7 @@ ALTOS_SRC = \ ao_adc_fast.c \ ao_crc_stm.c \ ao_stdio.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_romconfig.c \ ao_boot_chain.c \ ao_usb_stm.c \ diff --git a/src/chaoskey-v1.0/ao_chaoskey.c b/src/chaoskey-v1.0/ao_chaoskey.c index 1165e454..80f5a4ba 100644 --- a/src/chaoskey-v1.0/ao_chaoskey.c +++ b/src/chaoskey-v1.0/ao_chaoskey.c @@ -24,7 +24,7 @@ void main(void) { - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_clock_init(); ao_task_init(); ao_timer_init(); diff --git a/src/detherm/Makefile b/src/detherm/Makefile index 6b0e0bf8..7681a049 100644 --- a/src/detherm/Makefile +++ b/src/detherm/Makefile @@ -27,7 +27,7 @@ ALTOS_SRC = \ ao_spi_stm.c \ ao_exti_stm.c \ ao_stdio.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_log.c \ ao_log_mini.c \ ao_sample.c \ diff --git a/src/drivers/ao_led.c b/src/drivers/ao_led.c new file mode 100644 index 00000000..0f7b7c27 --- /dev/null +++ b/src/drivers/ao_led.c @@ -0,0 +1,174 @@ +/* + * Copyright © 2018 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 "ao.h" + +static const struct { + struct stm_gpio *port; + uint16_t pin; +} ao_leds[] = { +#ifdef LED_0_PORT + [0] { LED_0_PORT, LED_0_PIN }, +#endif +#ifdef LED_1_PORT + [1] { LED_1_PORT, LED_1_PIN }, +#endif +#ifdef LED_2_PORT + [2] { LED_2_PORT, LED_2_PIN }, +#endif +#ifdef LED_3_PORT + [3] { LED_3_PORT, LED_3_PIN }, +#endif +#ifdef LED_4_PORT + [4] { LED_4_PORT, LED_4_PIN }, +#endif +#ifdef LED_5_PORT + [5] { LED_5_PORT, LED_5_PIN }, +#endif +#ifdef LED_6_PORT + [6] { LED_6_PORT, LED_6_PIN }, +#endif +#ifdef LED_7_PORT + [7] { LED_7_PORT, LED_7_PIN }, +#endif +#ifdef LED_8_PORT + [8] { LED_8_PORT, LED_8_PIN }, +#endif +#ifdef LED_9_PORT + [9] { LED_9_PORT, LED_9_PIN }, +#endif +#ifdef LED_10_PORT + [10] { LED_10_PORT, LED_10_PIN }, +#endif +#ifdef LED_11_PORT + [11] { LED_11_PORT, LED_11_PIN }, +#endif +#ifdef LED_12_PORT + [12] { LED_12_PORT, LED_12_PIN }, +#endif +#ifdef LED_13_PORT + [13] { LED_13_PORT, LED_13_PIN }, +#endif +#ifdef LED_14_PORT + [14] { LED_14_PORT, LED_14_PIN }, +#endif +#ifdef LED_15_PORT + [15] { LED_15_PORT, LED_15_PIN }, +#endif +#ifdef LED_16_PORT + [16] { LED_16_PORT, LED_16_PIN }, +#endif +#ifdef LED_17_PORT + [17] { LED_17_PORT, LED_17_PIN }, +#endif +#ifdef LED_18_PORT + [18] { LED_18_PORT, LED_18_PIN }, +#endif +#ifdef LED_19_PORT + [19] { LED_19_PORT, LED_19_PIN }, +#endif +#ifdef LED_20_PORT + [20] { LED_20_PORT, LED_20_PIN }, +#endif +#ifdef LED_21_PORT + [21] { LED_21_PORT, LED_21_PIN }, +#endif +#ifdef LED_22_PORT + [22] { LED_22_PORT, LED_22_PIN }, +#endif +#ifdef LED_23_PORT + [23] { LED_23_PORT, LED_23_PIN }, +#endif +#ifdef LED_24_PORT + [24] { LED_24_PORT, LED_24_PIN }, +#endif +#ifdef LED_25_PORT + [25] { LED_25_PORT, LED_25_PIN }, +#endif +#ifdef LED_26_PORT + [26] { LED_26_PORT, LED_26_PIN }, +#endif +#ifdef LED_27_PORT + [27] { LED_27_PORT, LED_27_PIN }, +#endif +#ifdef LED_28_PORT + [28] { LED_28_PORT, LED_28_PIN }, +#endif +#ifdef LED_29_PORT + [29] { LED_29_PORT, LED_29_PIN }, +#endif +#ifdef LED_30_PORT + [30] { LED_30_PORT, LED_30_PIN }, +#endif +#ifdef LED_31_PORT + [31] { LED_31_PORT, LED_31_PIN }, +#endif +}; +#define N_LED (sizeof (ao_leds)/sizeof(ao_leds[0])) + +void +ao_led_on(AO_LED_TYPE colors) +{ + AO_LED_TYPE i; + for (i = 0; i < N_LED; i++) + if (colors & (1 << i)) + ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 1); +} + +void +ao_led_off(AO_LED_TYPE colors) +{ + AO_LED_TYPE i; + for (i = 0; i < N_LED; i++) + if (colors & (1 << i)) + ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 0); +} + +void +ao_led_set(AO_LED_TYPE colors) +{ + AO_LED_TYPE i; + for (i = 0; i < N_LED; i++) + ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, (colors >> i) & 1); +} + +void +ao_led_toggle(AO_LED_TYPE colors) +{ + AO_LED_TYPE i; + for (i = 0; i < N_LED; i++) + if (colors & (1 << i)) + ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, ~ao_gpio_get(ao_leds[i].port, ao_leds[i].pin)); +} + +void +ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +void +ao_led_init(void) +{ + AO_LED_TYPE bit; + + for (bit = 0; bit < N_LED; bit++) + ao_enable_output(ao_leds[bit].port, ao_leds[bit].pin, 0); +} diff --git a/src/easymega-v1.0/Makefile b/src/easymega-v1.0/Makefile index 3344da06..76e7319e 100644 --- a/src/easymega-v1.0/Makefile +++ b/src/easymega-v1.0/Makefile @@ -53,7 +53,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/easymega-v1.0/ao_easymega.c b/src/easymega-v1.0/ao_easymega.c index 9848c367..d00585f9 100644 --- a/src/easymega-v1.0/ao_easymega.c +++ b/src/easymega-v1.0/ao_easymega.c @@ -43,7 +43,7 @@ main(void) #endif ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/fox1ihu/Makefile b/src/fox1ihu/Makefile index e3226a24..61314db9 100644 --- a/src/fox1ihu/Makefile +++ b/src/fox1ihu/Makefile @@ -37,7 +37,7 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_cmd.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/fox1ihu/ao_fox1ihu.c b/src/fox1ihu/ao_fox1ihu.c index 2e1a2fdf..5ebb4b54 100644 --- a/src/fox1ihu/ao_fox1ihu.c +++ b/src/fox1ihu/ao_fox1ihu.c @@ -31,7 +31,7 @@ main(void) #endif ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(AO_LED_RED|AO_LED_GREEN|AO_LED_RED_2|AO_LED_GREEN_2); ao_timer_init(); diff --git a/src/kernel/ao.h b/src/kernel/ao.h index 9c0c8604..1b269d73 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -230,7 +230,7 @@ ao_cmd_filter(void); #include #endif -#if LEDS_AVAILABLE +#if LEDS_AVAILABLE || HAS_LED #include #endif diff --git a/src/kernel/ao_led.h b/src/kernel/ao_led.h index 803f85b3..5d982ca6 100644 --- a/src/kernel/ao_led.h +++ b/src/kernel/ao_led.h @@ -26,7 +26,7 @@ #define AO_LED_NONE 0 #ifndef AO_LED_TYPE -#define AO_LED_TYPE uint8_t +#define AO_LED_TYPE uint32_t #endif /* Turn on the specified LEDs */ @@ -55,6 +55,204 @@ ao_led_for(AO_LED_TYPE colors, uint16_t ticks); /* Initialize the LEDs */ void -ao_led_init(AO_LED_TYPE enable); +ao_led_init(void); + +#ifdef LED_0_PORT +#define AO_LED_0 (1 << 0) +#else +#define AO_LED_0 0 +#endif +#ifdef LED_1_PORT +#define AO_LED_1 (1 << 1) +#else +#define AO_LED_1 0 +#endif +#ifdef LED_2_PORT +#define AO_LED_2 (1 << 2) +#else +#define AO_LED_2 0 +#endif +#ifdef LED_3_PORT +#define AO_LED_3 (1 << 3) +#else +#define AO_LED_3 0 +#endif +#ifdef LED_4_PORT +#define AO_LED_4 (1 << 4) +#else +#define AO_LED_4 0 +#endif +#ifdef LED_5_PORT +#define AO_LED_5 (1 << 5) +#else +#define AO_LED_5 0 +#endif +#ifdef LED_6_PORT +#define AO_LED_6 (1 << 6) +#else +#define AO_LED_6 0 +#endif +#ifdef LED_7_PORT +#define AO_LED_7 (1 << 7) +#else +#define AO_LED_7 0 +#endif +#ifdef LED_8_PORT +#define AO_LED_8 (1 << 8) +#else +#define AO_LED_8 0 +#endif +#ifdef LED_9_PORT +#define AO_LED_9 (1 << 9) +#else +#define AO_LED_9 0 +#endif +#ifdef LED_10_PORT +#define AO_LED_10 (1 << 10) +#else +#define AO_LED_10 0 +#endif +#ifdef LED_11_PORT +#define AO_LED_11 (1 << 11) +#else +#define AO_LED_11 0 +#endif +#ifdef LED_12_PORT +#define AO_LED_12 (1 << 12) +#else +#define AO_LED_12 0 +#endif +#ifdef LED_13_PORT +#define AO_LED_13 (1 << 13) +#else +#define AO_LED_13 0 +#endif +#ifdef LED_14_PORT +#define AO_LED_14 (1 << 14) +#else +#define AO_LED_14 0 +#endif +#ifdef LED_15_PORT +#define AO_LED_15 (1 << 15) +#else +#define AO_LED_15 0 +#endif +#ifdef LED_16_PORT +#define AO_LED_16 (1 << 16) +#else +#define AO_LED_16 0 +#endif +#ifdef LED_17_PORT +#define AO_LED_17 (1 << 17) +#else +#define AO_LED_17 0 +#endif +#ifdef LED_18_PORT +#define AO_LED_18 (1 << 18) +#else +#define AO_LED_18 0 +#endif +#ifdef LED_19_PORT +#define AO_LED_19 (1 << 19) +#else +#define AO_LED_19 0 +#endif +#ifdef LED_20_PORT +#define AO_LED_20 (1 << 20) +#else +#define AO_LED_20 0 +#endif +#ifdef LED_21_PORT +#define AO_LED_21 (1 << 21) +#else +#define AO_LED_21 0 +#endif +#ifdef LED_22_PORT +#define AO_LED_22 (1 << 22) +#else +#define AO_LED_22 0 +#endif +#ifdef LED_23_PORT +#define AO_LED_23 (1 << 23) +#else +#define AO_LED_23 0 +#endif +#ifdef LED_24_PORT +#define AO_LED_24 (1 << 24) +#else +#define AO_LED_24 0 +#endif +#ifdef LED_25_PORT +#define AO_LED_25 (1 << 25) +#else +#define AO_LED_25 0 +#endif +#ifdef LED_26_PORT +#define AO_LED_26 (1 << 26) +#else +#define AO_LED_26 0 +#endif +#ifdef LED_27_PORT +#define AO_LED_27 (1 << 27) +#else +#define AO_LED_27 0 +#endif +#ifdef LED_28_PORT +#define AO_LED_28 (1 << 28) +#else +#define AO_LED_28 0 +#endif +#ifdef LED_29_PORT +#define AO_LED_29 (1 << 29) +#else +#define AO_LED_29 0 +#endif +#ifdef LED_30_PORT +#define AO_LED_30 (1 << 30) +#else +#define AO_LED_30 0 +#endif +#ifdef LED_31_PORT +#define AO_LED_31 (1 << 31) +#else +#define AO_LED_31 0 +#endif + +#define AO_LEDS_AVAILABLE (AO_LED_0 | \ + AO_LED_1 | \ + AO_LED_2 | \ + AO_LED_3 | \ + AO_LED_4 | \ + AO_LED_5 | \ + AO_LED_6 | \ + AO_LED_7 | \ + AO_LED_8 | \ + AO_LED_9 | \ + AO_LED_10 | \ + AO_LED_11 | \ + AO_LED_12 | \ + AO_LED_13 | \ + AO_LED_14 | \ + AO_LED_15 | \ + AO_LED_16 | \ + AO_LED_17 | \ + AO_LED_18 | \ + AO_LED_19 | \ + AO_LED_20 | \ + AO_LED_21 | \ + AO_LED_22 | \ + AO_LED_23 | \ + AO_LED_24 | \ + AO_LED_25 | \ + AO_LED_26 | \ + AO_LED_27 | \ + AO_LED_28 | \ + AO_LED_29 | \ + AO_LED_30 | \ + AO_LED_31) + +#ifndef LEDS_AVAILABLE +#define LEDS_AVAILABLE AO_LEDS_AVAILABLE +#endif #endif /* _AO_LED_H_ */ diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index 4f7072cb..dc5c1913 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -569,4 +569,5 @@ ao_start_scheduler(void) ao_arch_start_scheduler(); #endif ao_yield(); + __builtin_unreachable(); } diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h index ffeb7313..f3789fa2 100644 --- a/src/kernel/ao_task.h +++ b/src/kernel/ao_task.h @@ -134,7 +134,7 @@ ao_task_info(void); /* Start the scheduler. This will not return */ void -ao_start_scheduler(void); +ao_start_scheduler(void) __attribute__((noreturn)); #if HAS_TASK_QUEUE void diff --git a/src/lambdakey-v1.0/Makefile b/src/lambdakey-v1.0/Makefile index b94c3873..f8b5c7f5 100644 --- a/src/lambdakey-v1.0/Makefile +++ b/src/lambdakey-v1.0/Makefile @@ -27,7 +27,7 @@ ALTOS_SRC = \ ao_interrupt.c \ ao_product.c \ ao_cmd.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_notask.c \ ao_stdio.c \ ao_panic.c \ diff --git a/src/lpc/ao_led_lpc.c b/src/lpc/ao_led_lpc.c index 5fc726c0..3a2d4c98 100644 --- a/src/lpc/ao_led_lpc.c +++ b/src/lpc/ao_led_lpc.c @@ -35,8 +35,8 @@ ao_led_off(AO_PORT_TYPE colors) void ao_led_set(AO_PORT_TYPE colors) { - AO_PORT_TYPE on = colors & ao_led_enable; - AO_PORT_TYPE off = ~colors & ao_led_enable; + AO_PORT_TYPE on = colors & LEDS_AVAILABLE; + AO_PORT_TYPE off = ~colors & LEDS_AVAILABLE; ao_led_off(off); ao_led_on(on); @@ -57,18 +57,17 @@ ao_led_for(AO_PORT_TYPE colors, uint16_t ticks) } void -ao_led_init(AO_PORT_TYPE enable) +ao_led_init(void) { - ao_led_enable = enable; ao_enable_port(LED_PORT); if (LED_PORT == 0) { - if (enable & (1 << 11)) + if (LEDS_AVAILABLE & (1 << 11)) lpc_ioconf.pio0_11 = LPC_IOCONF_FUNC_PIO0_11 | (1 << LPC_IOCONF_ADMODE); - if (enable & (1 << 12)) + if (LEDS_AVAILABLE & (1 << 12)) lpc_ioconf.pio0_12 = LPC_IOCONF_FUNC_PIO0_12 | (1 << LPC_IOCONF_ADMODE); - if (enable & (1 << 14)) + if (LEDS_AVAILABLE & (1 << 14)) lpc_ioconf.pio0_14 = LPC_IOCONF_FUNC_PIO0_14 | (1 << LPC_IOCONF_ADMODE); } - lpc_gpio.dir[LED_PORT] |= enable; - ao_led_off(enable); + lpc_gpio.dir[LED_PORT] |= LEDS_AVAILABLE; + ao_led_off(LEDS_AVAILABLE); } diff --git a/src/megadongle-v0.1/Makefile b/src/megadongle-v0.1/Makefile index bbe2ea58..4290e088 100644 --- a/src/megadongle-v0.1/Makefile +++ b/src/megadongle-v0.1/Makefile @@ -36,7 +36,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/microkite/Makefile b/src/microkite/Makefile index b7523758..5eb97206 100644 --- a/src/microkite/Makefile +++ b/src/microkite/Makefile @@ -29,7 +29,7 @@ LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: ALTOS_SRC = \ ao_micropeak.c \ ao_spi_attiny.c \ - ao_led.c \ + ao_led_tiny.c \ ao_clock.c \ ao_ms5607.c \ ao_exti.c \ diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile index 32154fa6..c7d1b22d 100644 --- a/src/micropeak-v2.0/Makefile +++ b/src/micropeak-v2.0/Makefile @@ -18,7 +18,7 @@ ALTOS_SRC = \ ao_micropeak.c \ ao_spi_stm.c \ ao_dma_stm.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_timer.c \ ao_ms5607.c \ ao_exti_stm.c \ diff --git a/src/micropeak-v2.0/ao_micropeak.c b/src/micropeak-v2.0/ao_micropeak.c index 1cfa1209..df557e60 100644 --- a/src/micropeak-v2.0/ao_micropeak.c +++ b/src/micropeak-v2.0/ao_micropeak.c @@ -252,7 +252,7 @@ main(void) else ao_hsi_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_task_init(); ao_timer_init(); ao_serial_init(); diff --git a/src/micropeak/Makefile b/src/micropeak/Makefile index 6e8cae14..f80d61b0 100644 --- a/src/micropeak/Makefile +++ b/src/micropeak/Makefile @@ -29,7 +29,7 @@ LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: ALTOS_SRC = \ ao_micropeak.c \ ao_spi_attiny.c \ - ao_led.c \ + ao_led_tiny.c \ ao_clock.c \ ao_ms5607.c \ ao_exti.c \ diff --git a/src/microsplash/Makefile b/src/microsplash/Makefile index 9bb636f1..0342838e 100644 --- a/src/microsplash/Makefile +++ b/src/microsplash/Makefile @@ -29,7 +29,7 @@ LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: ALTOS_SRC = \ ao_micropeak.c \ ao_spi_attiny.c \ - ao_led.c \ + ao_led_tiny.c \ ao_clock.c \ ao_ms5607.c \ ao_exti.c \ diff --git a/src/nanopeak-v0.1/Makefile b/src/nanopeak-v0.1/Makefile index d3779594..774d4adc 100644 --- a/src/nanopeak-v0.1/Makefile +++ b/src/nanopeak-v0.1/Makefile @@ -19,7 +19,7 @@ LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: ALTOS_SRC = \ ao_micropeak.c \ ao_spi_attiny.c \ - ao_led.c \ + ao_led_tiny.c \ ao_clock.c \ ao_ms5607.c \ ao_exti.c \ diff --git a/src/nucleao-32/Makefile b/src/nucleao-32/Makefile index 2b9fe14f..1ab2eea1 100644 --- a/src/nucleao-32/Makefile +++ b/src/nucleao-32/Makefile @@ -26,7 +26,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_beep_stm.c \ ao_dma_stm.c \ ao_stdio.c \ diff --git a/src/pnpservo-v1/Makefile b/src/pnpservo-v1/Makefile index 8606b1ae..443a6afb 100644 --- a/src/pnpservo-v1/Makefile +++ b/src/pnpservo-v1/Makefile @@ -24,7 +24,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_dma_stm.c \ ao_stdio.c \ ao_mutex.c \ diff --git a/src/product/ao_micropeak.c b/src/product/ao_micropeak.c index 8aac79cd..8fed3069 100644 --- a/src/product/ao_micropeak.c +++ b/src/product/ao_micropeak.c @@ -57,7 +57,7 @@ ao_pips(void) int main(void) { - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_timer_init(); /* Init external hardware */ diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile index d4569c1a..ccce37a5 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -23,7 +23,7 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_cmd.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/stm-scheme-newlib/Makefile b/src/stm-scheme-newlib/Makefile index a4c249a3..1db58f10 100644 --- a/src/stm-scheme-newlib/Makefile +++ b/src/stm-scheme-newlib/Makefile @@ -30,7 +30,7 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_cmd.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio_newlib.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/stm-vga/Makefile b/src/stm-vga/Makefile index 46a77272..fa0d008f 100644 --- a/src/stm-vga/Makefile +++ b/src/stm-vga/Makefile @@ -28,7 +28,7 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_cmd.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/stm/ao_led.c b/src/stm/ao_led.c deleted file mode 100644 index 481a6e87..00000000 --- a/src/stm/ao_led.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright © 2012 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 "ao.h" - -#if LED_PER_LED -static const struct { - struct stm_gpio *port; - uint16_t pin; -} ao_leds[] = { -#ifdef LED_0_PORT - [0] { LED_0_PORT, LED_0_PIN }, -#endif -#ifdef LED_1_PORT - [1] { LED_1_PORT, LED_1_PIN }, -#endif -#ifdef LED_2_PORT - [2] { LED_2_PORT, LED_2_PIN }, -#endif -#ifdef LED_3_PORT - [3] { LED_3_PORT, LED_3_PIN }, -#endif -#ifdef LED_4_PORT - [4] { LED_4_PORT, LED_4_PIN }, -#endif -#ifdef LED_5_PORT - [5] { LED_5_PORT, LED_5_PIN }, -#endif -#ifdef LED_6_PORT - [6] { LED_6_PORT, LED_6_PIN }, -#endif -#ifdef LED_7_PORT - [7] { LED_7_PORT, LED_7_PIN }, -#endif -#ifdef LED_8_PORT - [8] { LED_8_PORT, LED_8_PIN }, -#endif -#ifdef LED_9_PORT - [9] { LED_9_PORT, LED_9_PIN }, -#endif -#ifdef LED_10_PORT - [10] { LED_10_PORT, LED_10_PIN }, -#endif -#ifdef LED_11_PORT - [11] { LED_11_PORT, LED_11_PIN }, -#endif -#ifdef LED_12_PORT - [12] { LED_12_PORT, LED_12_PIN }, -#endif -#ifdef LED_13_PORT - [13] { LED_13_PORT, LED_13_PIN }, -#endif -#ifdef LED_14_PORT - [14] { LED_14_PORT, LED_14_PIN }, -#endif -#ifdef LED_15_PORT - [15] { LED_15_PORT, LED_15_PIN }, -#endif -}; -#define N_LED (sizeof (ao_leds)/sizeof(ao_leds[0])) -#endif -static AO_LED_TYPE ao_led_enable; - -void -ao_led_on(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 1); -#else -#ifdef LED_PORT - LED_PORT->bsrr = (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -#endif -} - -void -ao_led_off(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 0); -#else -#ifdef LED_PORT - LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16; -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); -#endif -#endif -#endif -} - -void -ao_led_set(AO_LED_TYPE colors) -{ - AO_LED_TYPE on = colors & ao_led_enable; - AO_LED_TYPE off = ~colors & ao_led_enable; - - ao_led_off(off); - ao_led_on(on); -} - -void -ao_led_toggle(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, ~ao_gpio_get(ao_leds[i].port, ao_leds[i].pin)); -#else -#ifdef LED_PORT - LED_PORT->odr ^= (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->odr ^= ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->odr ^= ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -#endif -} - -void -ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks) -{ - ao_led_on(colors); - ao_delay(ticks); - ao_led_off(colors); -} - -#define init_led_pin(port, bit) do { \ - stm_moder_set(port, bit, STM_MODER_OUTPUT); \ - stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ - } while (0) - -void -ao_led_init(AO_LED_TYPE enable) -{ - AO_LED_TYPE bit; - - ao_led_enable = enable; -#if LED_PER_LED - for (bit = 0; bit < N_LED; bit++) - ao_enable_output(ao_leds[bit].port, ao_leds[bit].pin, 0); -#else -#ifdef LED_PORT - stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); - LED_PORT->odr &= ~enable; -#else -#ifdef LED_PORT_0 - stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); - LED_PORT_0->odr &= ~((enable & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); - LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#ifdef LED_PORT_2 - stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); - LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif - for (bit = 0; bit < 16; bit++) { - if (enable & (1 << bit)) { -#ifdef LED_PORT - init_led_pin(LED_PORT, bit); -#else -#ifdef LED_PORT_0 - if (LED_PORT_0_MASK & (1 << bit)) - init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); -#endif -#ifdef LED_PORT_1 - if (LED_PORT_1_MASK & (1 << bit)) - init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); -#endif -#ifdef LED_PORT_2 - if (LED_PORT_2_MASK & (1 << bit)) - init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT); -#endif -#endif - } - } -#endif -} diff --git a/src/stm/ao_led_stm.c b/src/stm/ao_led_stm.c new file mode 100644 index 00000000..7dcbb661 --- /dev/null +++ b/src/stm/ao_led_stm.c @@ -0,0 +1,144 @@ +/* + * Copyright © 2012 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 "ao.h" + +#if LED_PER_LED +#error LED_PER_LED support is in ao_led.c now +#endif + +void +ao_led_on(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + LED_PORT_2->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif +} + +void +ao_led_off(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (uint32_t) (colors & LEDS_AVAILABLE) << 16; +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); +#endif +#ifdef LED_PORT_2 + LED_PORT_2->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << (LED_PORT_2_SHIFT + 16); +#endif +#endif +} + +void +ao_led_set(AO_LED_TYPE colors) +{ + AO_LED_TYPE on = colors & LEDS_AVAILABLE; + AO_LED_TYPE off = ~colors & LEDS_AVAILABLE; + + ao_led_off(off); + ao_led_on(on); +} + +void +ao_led_toggle(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->odr ^= (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + LED_PORT_2->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif +} + +void +ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +#define init_led_pin(port, bit) do { \ + stm_moder_set(port, bit, STM_MODER_OUTPUT); \ + stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ + } while (0) + +void +ao_led_init(void) +{ + AO_LED_TYPE bit; + +#ifdef LED_PORT + stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); + LED_PORT->odr &= ~LEDS_AVAILABLE; +#else +#ifdef LED_PORT_0 + stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); + LED_PORT_0->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); + LED_PORT_1->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + stm_rcc.ahbenr |= (1 << LED_PORT_2_ENABLE); + LED_PORT_2->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif + for (bit = 0; bit < sizeof (AO_LED_TYPE) * 8; bit++) { + if (LEDS_AVAILABLE & (1 << bit)) { +#ifdef LED_PORT + init_led_pin(LED_PORT, bit); +#else +#ifdef LED_PORT_0 + if (LED_PORT_0_MASK & (1 << bit)) + init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); +#endif +#ifdef LED_PORT_1 + if (LED_PORT_1_MASK & (1 << bit)) + init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); +#endif +#ifdef LED_PORT_2 + if (LED_PORT_2_MASK & (1 << bit)) + init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT); +#endif +#endif + } + } +} diff --git a/src/stm32f4-disco/Makefile b/src/stm32f4-disco/Makefile index 2d912b22..c970b879 100644 --- a/src/stm32f4-disco/Makefile +++ b/src/stm32f4-disco/Makefile @@ -3,7 +3,10 @@ include ../stm32f4/Makefile-raw.defs ALTOS_SRC = \ ao_interrupt.c \ ao_panic.c \ - ao_timer.c + ao_timer.c \ + ao_led.c \ + ao_task.c \ + ao_stdio.c CFLAGS = $(STM32F4_CFLAGS) diff --git a/src/stm32f4-disco/ao_disco.c b/src/stm32f4-disco/ao_disco.c index efbed947..c6cdbd23 100644 --- a/src/stm32f4-disco/ao_disco.c +++ b/src/stm32f4-disco/ao_disco.c @@ -14,24 +14,35 @@ #include -void main(void) +static struct ao_task red_task; +static struct ao_task green_task; + +static void +red(void) { - float x; - int r = 1; - int g = 0; + for (;;) { + ao_led_toggle(LED_RED); + ao_delay(AO_MS_TO_TICKS(500)); + } +} - ao_clock_init(); +static void +green(void) +{ + for (;;) { + ao_led_toggle(LED_GREEN); + ao_delay(AO_MS_TO_TICKS(450)); + } +} +void main(void) +{ + ao_clock_init(); ao_timer_init(); + ao_led_init(); + ao_task_init(); - ao_enable_output(LED_GREEN_PORT, LED_GREEN_PIN, 0); - ao_enable_output(LED_RED_PORT, LED_RED_PIN, 1); - for (;;) { - ao_gpio_set(LED_GREEN_PORT, LED_GREEN_PIN, g); - ao_gpio_set(LED_RED_PORT, LED_RED_PIN, r); - g ^= 1; - r ^= 1; - for (x = 0.0f; x < 100000.0f; x = x + 0.1f) - ao_arch_nop(); - } + ao_add_task(&red_task, red, "red"); + ao_add_task(&green_task, green, "green"); + ao_start_scheduler(); } diff --git a/src/stm32f4-disco/ao_pins.h b/src/stm32f4-disco/ao_pins.h index c4dc5b4b..bbbc306e 100644 --- a/src/stm32f4-disco/ao_pins.h +++ b/src/stm32f4-disco/ao_pins.h @@ -14,16 +14,7 @@ #ifndef _AO_PINS_H_ #define _AO_PINS_H_ -#define HAS_BEEP 0 - -#define B_USER_PORT (&stm_gpioa) -#define B_USER_PIN 0 - -#define LED_GREEN_PORT (&stm_gpioc) -#define LED_GREEN_PIN 5 -#define LED_RED_PORT (&stm_gpioe) -#define LED_RED_PIN 3 - +/* Clock tree configuration */ #define AO_HSE 8000000 /* fed from st/link processor */ #define AO_HSE_BYPASS 1 /* no xtal, directly fed */ @@ -43,4 +34,22 @@ #define DEBUG_THE_CLOCK 1 +#define HAS_USB 0 +#define HAS_BEEP 0 + +#define B_USER_PORT (&stm_gpioa) +#define B_USER_PIN 0 + +/* LEDs */ + +#define HAS_LED 1 + +#define LED_0_PORT (&stm_gpioc) +#define LED_0_PIN 5 +#define LED_GREEN (1 << 0) + +#define LED_1_PORT (&stm_gpioe) +#define LED_1_PIN 3 +#define LED_RED (1 << 1) + #endif /* _AO_PINS_H_ */ diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h index 805d756d..73eb793f 100644 --- a/src/stm32f4/ao_arch.h +++ b/src/stm32f4/ao_arch.h @@ -29,9 +29,6 @@ #define ao_arch_task_members\ uint32_t *sp; /* saved stack pointer */ -#define ao_arch_block_interrupts() asm("cpsid i") -#define ao_arch_release_interrupts() asm("cpsie i") - #define ao_arch_naked_declare __attribute__((naked)) #define ao_arch_naked_define diff --git a/src/stm32f4/ao_arch_funcs.h b/src/stm32f4/ao_arch_funcs.h index 252fe77a..8c0da03b 100644 --- a/src/stm32f4/ao_arch_funcs.h +++ b/src/stm32f4/ao_arch_funcs.h @@ -15,6 +15,234 @@ #ifndef _AO_ARCH_FUNCS_H_ #define _AO_ARCH_FUNCS_H_ +/* task functions */ + +#define ARM_PUSH32(stack, val) (*(--(stack)) = (val)) + +typedef uint32_t ao_arch_irq_t; + +static inline void +ao_arch_block_interrupts(void) { +#ifdef AO_NONMASK_INTERRUPTS + asm("msr basepri,%0" : : "r" (AO_STM_NVIC_BASEPRI_MASK)); +#else + asm("cpsid i"); +#endif +} + +static inline void +ao_arch_release_interrupts(void) { +#ifdef AO_NONMASK_INTERRUPTS + asm("msr basepri,%0" : : "r" (0x0)); +#else + asm("cpsie i"); +#endif +} + +static inline uint32_t +ao_arch_irqsave(void) { + uint32_t val; +#ifdef AO_NONMASK_INTERRUPTS + asm("mrs %0,basepri" : "=r" (val)); +#else + asm("mrs %0,primask" : "=r" (val)); +#endif + ao_arch_block_interrupts(); + return val; +} + +static inline void +ao_arch_irqrestore(uint32_t basepri) { +#ifdef AO_NONMASK_INTERRUPTS + asm("msr basepri,%0" : : "r" (basepri)); +#else + asm("msr primask,%0" : : "r" (basepri)); +#endif +} + +static inline void +ao_arch_memory_barrier() { + asm volatile("" ::: "memory"); +} + +static inline void +ao_arch_irq_check(void) { +#ifdef AO_NONMASK_INTERRUPTS + uint32_t basepri; + asm("mrs %0,basepri" : "=r" (basepri)); + if (basepri == 0) + ao_panic(AO_PANIC_IRQ); +#else + uint32_t primask; + asm("mrs %0,primask" : "=r" (primask)); + if ((primask & 1) == 0) + ao_panic(AO_PANIC_IRQ); +#endif +} + +#if HAS_TASK +static inline void +ao_arch_init_stack(struct ao_task *task, void *start) +{ + uint32_t *sp = (uint32_t *) ((void*) task->stack + AO_STACK_SIZE); + uint32_t a = (uint32_t) start; + int i; + + /* Return address (goes into LR) */ + ARM_PUSH32(sp, a); + + /* Clear register values r0-r12 */ + i = 13; + while (i--) + ARM_PUSH32(sp, 0); + + /* APSR */ + ARM_PUSH32(sp, 0); + + /* Clear register values s0-s31 */ + i = 32; + while (i--) + ARM_PUSH32(sp, 0); + + /* FPSCR */ + ARM_PUSH32(sp, 0); + + /* BASEPRI with interrupts enabled */ + ARM_PUSH32(sp, 0); + + task->sp = sp; +} + +static inline void ao_arch_save_regs(void) { + /* Save general registers */ + asm("push {r0-r12,lr}"); + + /* Save APSR */ + asm("mrs r0,apsr"); + asm("push {r0}"); + + /* Save FPU registers */ + asm("vpush {s0-s15}"); + asm("vpush {s16-s31}"); + + /* Save FPSCR */ + asm("vmrs r0,fpscr"); + asm("push {r0}"); + +#ifdef AO_NONMASK_INTERRUPTS + /* Save BASEPRI */ + asm("mrs r0,basepri"); +#else + /* Save PRIMASK */ + asm("mrs r0,primask"); +#endif + asm("push {r0}"); +} + +static inline void ao_arch_save_stack(void) { + uint32_t *sp; + asm("mov %0,sp" : "=&r" (sp) ); + ao_cur_task->sp = (sp); +} + +static inline void ao_arch_restore_stack(void) { + /* Switch stacks */ + asm("mov sp, %0" : : "r" (ao_cur_task->sp) ); + +#ifdef AO_NONMASK_INTERRUPTS + /* Restore BASEPRI */ + asm("pop {r0}"); + asm("msr basepri,r0"); +#else + /* Restore PRIMASK */ + asm("pop {r0}"); + asm("msr primask,r0"); +#endif + + /* Restore FPSCR */ + asm("pop {r0}"); + asm("vmsr fpscr,r0"); + + /* Restore FPU registers */ + asm("vpop {s16-s31}"); + asm("vpop {s0-s15}"); + + /* Restore APSR */ + asm("pop {r0}"); + asm("msr apsr_nczvq,r0"); + + /* Restore general registers */ + asm("pop {r0-r12,lr}\n"); + + /* Return to calling function */ + asm("bx lr"); +} + +#ifndef HAS_SAMPLE_PROFILE +#define HAS_SAMPLE_PROFILE 0 +#endif + +#if DEBUG +#define HAS_ARCH_VALIDATE_CUR_STACK 1 + +static inline void +ao_validate_cur_stack(void) +{ + uint8_t *psp; + + asm("mrs %0,psp" : "=&r" (psp)); + if (ao_cur_task && + psp <= ao_cur_task->stack && + psp >= ao_cur_task->stack - 256) + ao_panic(AO_PANIC_STACK); +} +#endif + +#if !HAS_SAMPLE_PROFILE +#define HAS_ARCH_START_SCHEDULER 1 + +static inline void ao_arch_start_scheduler(void) { + uint32_t sp; + uint32_t control; + + asm("mrs %0,msp" : "=&r" (sp)); + asm("msr psp,%0" : : "r" (sp)); + asm("mrs %0,control" : "=r" (control)); + control |= (1 << 1); + asm("msr control,%0" : : "r" (control)); + asm("isb"); +} +#endif + +#define ao_arch_isr_stack() + +#endif + +static inline void +ao_arch_wait_interrupt(void) { +#ifdef AO_NONMASK_INTERRUPTS + asm( + "dsb\n" /* Serialize data */ + "isb\n" /* Serialize instructions */ + "cpsid i\n" /* Block all interrupts */ + "msr basepri,%0\n" /* Allow all interrupts through basepri */ + "wfi\n" /* Wait for an interrupt */ + "cpsie i\n" /* Allow all interrupts */ + "msr basepri,%1\n" /* Block interrupts through basepri */ + : : "r" (0), "r" (AO_STM_NVIC_BASEPRI_MASK)); +#else + asm("\twfi\n"); + ao_arch_release_interrupts(); + ao_arch_block_interrupts(); +#endif +} + +#define ao_arch_critical(b) do { \ + uint32_t __mask = ao_arch_irqsave(); \ + do { b } while (0); \ + ao_arch_irqrestore(__mask); \ + } while (0) + /* GPIO functions */ #define ao_power_register(gpio) diff --git a/src/stmf0/ao_led.c b/src/stmf0/ao_led.c deleted file mode 100644 index a162932a..00000000 --- a/src/stmf0/ao_led.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright © 2012 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 "ao.h" - -uint16_t ao_led_enable; - -void -ao_led_on(uint16_t colors) -{ -#ifdef LED_PORT - LED_PORT->bsrr = (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -} - -void -ao_led_off(uint16_t colors) -{ -#ifdef LED_PORT - LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16; -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); -#endif -#endif -} - -void -ao_led_set(uint16_t colors) -{ - uint16_t on = colors & ao_led_enable; - uint16_t off = ~colors & ao_led_enable; - - ao_led_off(off); - ao_led_on(on); -} - -void -ao_led_toggle(uint16_t colors) -{ -#ifdef LED_PORT - LED_PORT->odr ^= (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->odr ^= ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->odr ^= ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -} - -void -ao_led_for(uint16_t colors, uint16_t ticks) -{ - ao_led_on(colors); - ao_delay(ticks); - ao_led_off(colors); -} - -#define init_led_pin(port, bit) do { \ - stm_moder_set(port, bit, STM_MODER_OUTPUT); \ - stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ - } while (0) - -void -ao_led_init(uint16_t enable) -{ - int bit; - - ao_led_enable = enable; -#ifdef LED_PORT - stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); - LED_PORT->odr &= ~enable; -#else -#ifdef LED_PORT_0 - stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); - LED_PORT_0->odr &= ~((enable & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); - LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif - for (bit = 0; bit < 16; bit++) { - if (enable & (1 << bit)) { -#ifdef LED_PORT - init_led_pin(LED_PORT, bit); -#else -#ifdef LED_PORT_0 - if (LED_PORT_0_MASK & (1 << bit)) - init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); -#endif -#ifdef LED_PORT_1 - if (LED_PORT_1_MASK & (1 << bit)) - init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); -#endif -#endif - } - } -} diff --git a/src/stmf0/ao_led_stmf0.c b/src/stmf0/ao_led_stmf0.c new file mode 100644 index 00000000..1564535e --- /dev/null +++ b/src/stmf0/ao_led_stmf0.c @@ -0,0 +1,123 @@ +/* + * Copyright © 2012 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 "ao.h" + +void +ao_led_on(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#endif +} + +void +ao_led_off(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (uint32_t) (colors & LEDS_AVAILABLE) << 16; +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); +#endif +#endif +} + +void +ao_led_set(AO_LED_TYPE colors) +{ + AO_LED_TYPE on = colors & LEDS_AVAILABLE; + AO_LED_TYPE off = ~colors & LEDS_AVAILABLE; + + ao_led_off(off); + ao_led_on(on); +} + +void +ao_led_toggle(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->odr ^= (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#endif +} + +void +ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +#define init_led_pin(port, bit) do { \ + stm_moder_set(port, bit, STM_MODER_OUTPUT); \ + stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ + } while (0) + +void +ao_led_init(void) +{ + int bit; + +#ifdef LED_PORT + stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); + LED_PORT->odr &= ~LEDS_AVAILABLE; +#else +#ifdef LED_PORT_0 + stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); + LED_PORT_0->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); + LED_PORT_1->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#endif + for (bit = 0; bit < 16; bit++) { + if (LEDS_AVAILABLE & (1 << bit)) { +#ifdef LED_PORT + init_led_pin(LED_PORT, bit); +#else +#ifdef LED_PORT_0 + if (LED_PORT_0_MASK & (1 << bit)) + init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); +#endif +#ifdef LED_PORT_1 + if (LED_PORT_1_MASK & (1 << bit)) + init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); +#endif +#endif + } + } +} diff --git a/src/teleballoon-v2.0/Makefile b/src/teleballoon-v2.0/Makefile index cb2ce253..ddbfaf5f 100644 --- a/src/teleballoon-v2.0/Makefile +++ b/src/teleballoon-v2.0/Makefile @@ -46,7 +46,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/teleballoon-v2.0/ao_teleballoon.c b/src/teleballoon-v2.0/ao_teleballoon.c index acb11f44..94393da0 100644 --- a/src/teleballoon-v2.0/ao_teleballoon.c +++ b/src/teleballoon-v2.0/ao_teleballoon.c @@ -43,8 +43,8 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_RED); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_timer_init(); ao_spi_init(); @@ -87,7 +87,8 @@ main(void) #if HAS_SAMPLE_PROFILE ao_sample_profile_init(); #endif - + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telebt-v3.0/Makefile b/src/telebt-v3.0/Makefile index 4636c046..9892ad5f 100644 --- a/src/telebt-v3.0/Makefile +++ b/src/telebt-v3.0/Makefile @@ -37,7 +37,7 @@ ALTOS_SRC = \ ao_config.c \ ao_data.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telebt-v3.0/ao_telebt.c b/src/telebt-v3.0/ao_telebt.c index 63633c90..3d48b6b9 100644 --- a/src/telebt-v3.0/ao_telebt.c +++ b/src/telebt-v3.0/ao_telebt.c @@ -34,7 +34,7 @@ main(void) ao_clock_init(); ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telebt-v4.0/Makefile b/src/telebt-v4.0/Makefile index 38ac7513..4ad3287d 100644 --- a/src/telebt-v4.0/Makefile +++ b/src/telebt-v4.0/Makefile @@ -27,7 +27,7 @@ ALTOS_SRC = \ ao_config.c \ ao_data.c \ ao_task.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telebt-v4.0/ao_telebt.c b/src/telebt-v4.0/ao_telebt.c index 953ec4bc..7c3c6e2a 100644 --- a/src/telebt-v4.0/ao_telebt.c +++ b/src/telebt-v4.0/ao_telebt.c @@ -29,7 +29,7 @@ main(void) ao_clock_init(); ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/teledongle-v1.8/Makefile b/src/teledongle-v1.8/Makefile index 6c05ce9f..461b5855 100644 --- a/src/teledongle-v1.8/Makefile +++ b/src/teledongle-v1.8/Makefile @@ -38,7 +38,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/teledongle-v3.0/ao_teledongle.c b/src/teledongle-v3.0/ao_teledongle.c index 32899af2..69abea6e 100644 --- a/src/teledongle-v3.0/ao_teledongle.c +++ b/src/teledongle-v3.0/ao_teledongle.c @@ -31,7 +31,7 @@ main(void) #endif ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telefireeight-v1.0/ao_pins.h b/src/telefireeight-v1.0/ao_pins.h index 15e1fa11..ef533b36 100644 --- a/src/telefireeight-v1.0/ao_pins.h +++ b/src/telefireeight-v1.0/ao_pins.h @@ -107,7 +107,7 @@ #define AO_CC1200_INT_GPIO 2 #define AO_CC1200_INT_GPIO_IOCFG CC1200_IOCFG2 -#define LED_PER_LED 1 +#define HAS_LED 1 #define LED_TYPE uint16_t /* Continuity leds 1-8 */ @@ -128,14 +128,8 @@ #define LED_7_PORT (&stm_gpioa) #define LED_7_PIN 10 -#define LED_PIN_CONTINUITY_0 0 -#define LED_PIN_CONTINUITY_1 1 -#define LED_PIN_CONTINUITY_2 2 -#define LED_PIN_CONTINUITY_3 3 -#define LED_PIN_CONTINUITY_4 4 -#define LED_PIN_CONTINUITY_5 5 -#define LED_PIN_CONTINUITY_6 6 -#define LED_PIN_CONTINUITY_7 7 +#define AO_LED_CONTINUITY(c) (1 << (c)) +#define AO_LED_CONTINUITY_MASK (0xff) /* ARM */ #define LED_8_PORT (&stm_gpioe) @@ -151,19 +145,10 @@ #define LED_11_PORT (&stm_gpioe) #define LED_11_PIN 6 -#define LED_PIN_GREEN 9 -#define LED_PIN_AMBER 10 -#define LED_PIN_RED 11 - -#define AO_LED_CONTINUITY(c) (1 << (c)) -#define AO_LED_CONTINUITY_MASK (0xff) - -#define AO_LED_ARMED (1 << LED_PIN_ARMED) -#define AO_LED_GREEN (1 << LED_PIN_GREEN) -#define AO_LED_AMBER (1 << LED_PIN_AMBER) -#define AO_LED_RED (1 << LED_PIN_RED) - -#define LEDS_AVAILABLE (0xfff) +#define AO_LED_ARMED AO_LED_8 +#define AO_LED_GREEN AO_LED_9 +#define AO_LED_AMBER AO_LED_10 +#define AO_LED_RED AO_LED_11 /* Alarm A */ #define AO_SIREN diff --git a/src/telefireeight-v1.0/ao_telefireeight.c b/src/telefireeight-v1.0/ao_telefireeight.c index bdcf3213..89541a02 100644 --- a/src/telefireeight-v1.0/ao_telefireeight.c +++ b/src/telefireeight-v1.0/ao_telefireeight.c @@ -26,7 +26,8 @@ main(void) { ao_clock_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_task_init(); @@ -51,5 +52,7 @@ main(void) // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); } diff --git a/src/telefireone-v1.0/Makefile b/src/telefireone-v1.0/Makefile index 53f088cb..773c8f69 100644 --- a/src/telefireone-v1.0/Makefile +++ b/src/telefireone-v1.0/Makefile @@ -34,7 +34,7 @@ ALTOS_SRC = \ ao_data.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telefiretwo-v0.1/Makefile b/src/telefiretwo-v0.1/Makefile index 6454d6fd..72171fac 100644 --- a/src/telefiretwo-v0.1/Makefile +++ b/src/telefiretwo-v0.1/Makefile @@ -33,7 +33,7 @@ ALTOS_SRC = \ ao_data.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telefiretwo-v0.1/ao_telefiretwo.c b/src/telefiretwo-v0.1/ao_telefiretwo.c index bdcf3213..89541a02 100644 --- a/src/telefiretwo-v0.1/ao_telefiretwo.c +++ b/src/telefiretwo-v0.1/ao_telefiretwo.c @@ -26,7 +26,8 @@ main(void) { ao_clock_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_task_init(); @@ -51,5 +52,7 @@ main(void) // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); } diff --git a/src/telefiretwo-v0.2/Makefile b/src/telefiretwo-v0.2/Makefile index 30985f9c..f43ece71 100644 --- a/src/telefiretwo-v0.2/Makefile +++ b/src/telefiretwo-v0.2/Makefile @@ -33,7 +33,7 @@ ALTOS_SRC = \ ao_data.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telegps-v0.1/Makefile b/src/telegps-v0.1/Makefile index 46eb0ac5..0365f91f 100644 --- a/src/telegps-v0.1/Makefile +++ b/src/telegps-v0.1/Makefile @@ -44,7 +44,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telegps-v2.0/Makefile b/src/telegps-v2.0/Makefile index 19d088d3..617efa65 100644 --- a/src/telegps-v2.0/Makefile +++ b/src/telegps-v2.0/Makefile @@ -21,7 +21,7 @@ INC = \ ALTOS_SRC = \ ao_adc_stm.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_interrupt.c \ ao_boot_chain.c \ ao_product.c \ diff --git a/src/telegps-v2.0/ao_telegps.c b/src/telegps-v2.0/ao_telegps.c index 998c2008..1ba67f67 100644 --- a/src/telegps-v2.0/ao_telegps.c +++ b/src/telegps-v2.0/ao_telegps.c @@ -29,8 +29,8 @@ main(void) ao_cmd_init(); ao_config_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); /* internal systems */ ao_timer_init(); @@ -53,8 +53,7 @@ main(void) ao_telemetry_init(); ao_tracker_init(); - ao_led_off(AO_LED_GREEN); + ao_led_off(LEDS_AVAILABLE); ao_start_scheduler(); - return 0; } diff --git a/src/telelco-v0.2-cc1200/Makefile b/src/telelco-v0.2-cc1200/Makefile index 4ccf494c..9307aa2d 100644 --- a/src/telelco-v0.2-cc1200/Makefile +++ b/src/telelco-v0.2-cc1200/Makefile @@ -40,7 +40,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telelco-v0.2-cc1200/ao_telelco.c b/src/telelco-v0.2-cc1200/ao_telelco.c index 3266da00..26f49d59 100644 --- a/src/telelco-v0.2-cc1200/ao_telelco.c +++ b/src/telelco-v0.2-cc1200/ao_telelco.c @@ -45,9 +45,8 @@ main(void) ao_timer_init(); ao_dma_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); - + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_spi_init(); ao_exti_init(); @@ -74,6 +73,8 @@ main(void) ao_lco_cmd_init(); // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telelco-v0.2/Makefile b/src/telelco-v0.2/Makefile index 8279cac1..91ae67f0 100644 --- a/src/telelco-v0.2/Makefile +++ b/src/telelco-v0.2/Makefile @@ -39,7 +39,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telelco-v0.2/ao_telelco.c b/src/telelco-v0.2/ao_telelco.c index 7b04d386..4eba3597 100644 --- a/src/telelco-v0.2/ao_telelco.c +++ b/src/telelco-v0.2/ao_telelco.c @@ -35,9 +35,9 @@ int main(void) { ao_clock_init(); - - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_task_init(); ao_timer_init(); @@ -55,17 +55,19 @@ main(void) ao_button_init(); ao_eeprom_init(); - + ao_radio_init(); ao_usb_init(); ao_config_init(); - + ao_lco_init(); ao_lco_cmd_init(); // ao_radio_cmac_cmd_init(); - + + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telelco-v0.3/Makefile b/src/telelco-v0.3/Makefile index c2592bf8..567ddf41 100644 --- a/src/telelco-v0.3/Makefile +++ b/src/telelco-v0.3/Makefile @@ -40,7 +40,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telelco-v0.3/ao_telelco.c b/src/telelco-v0.3/ao_telelco.c index 7b04d386..c2ca68aa 100644 --- a/src/telelco-v0.3/ao_telelco.c +++ b/src/telelco-v0.3/ao_telelco.c @@ -36,8 +36,8 @@ main(void) { ao_clock_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_task_init(); ao_timer_init(); @@ -66,6 +66,8 @@ main(void) ao_lco_cmd_init(); // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telelco-v2.0/ao_lco_v2.c b/src/telelco-v2.0/ao_lco_v2.c index 90324cc8..daecf380 100644 --- a/src/telelco-v2.0/ao_lco_v2.c +++ b/src/telelco-v2.0/ao_lco_v2.c @@ -243,9 +243,9 @@ ao_lco_display_test() ao_seven_segment_set(AO_LCO_BOX_DIGIT_1, 8 | 0x10); ao_seven_segment_set(AO_LCO_BOX_DIGIT_10, 8 | 0x10); ao_mutex_put(&ao_lco_display_mutex); - ao_led_on(LEDS_AVAILABLE); + ao_led_on(AO_LEDS_AVAILABLE); ao_delay(AO_MS_TO_TICKS(1000)); - ao_led_off(LEDS_AVAILABLE); + ao_led_off(AO_LEDS_AVAILABLE); } static void diff --git a/src/telelco-v2.0/ao_pins.h b/src/telelco-v2.0/ao_pins.h index 95998dc7..ea709c1d 100644 --- a/src/telelco-v2.0/ao_pins.h +++ b/src/telelco-v2.0/ao_pins.h @@ -99,13 +99,7 @@ #define LOW_LEVEL_DEBUG 0 -#define LED_PER_LED 1 -#define LED_TYPE uint16_t - -#define LED_ENABLE_BITS ((1 << STM_RCC_AHBENR_GPIOAEN) | \ - (1 << STM_RCC_AHBENR_GPIOCEN) | \ - (1 << STM_RCC_AHBENR_GPIODEN) | \ - (1 << STM_RCC_AHBENR_GPIOEEN)) +#define HAS_LED 1 /* PC7 - PC9, LED 0 - 2 */ #define LED_0_PORT (&stm_gpioc) @@ -147,56 +141,23 @@ #define LED_15_PORT (&stm_gpioa) #define LED_15_PIN 5 -#define LED_PIN_RED 0 -#define LED_PIN_AMBER 1 -#define LED_PIN_GREEN 2 -#define LED_PIN_BOX 3 -#define LED_PIN_PAD 4 -#define LED_PIN_DRAG 5 -#define LED_PIN_CONTINUITY_7 6 -#define LED_PIN_CONTINUITY_6 7 -#define LED_PIN_CONTINUITY_5 8 -#define LED_PIN_CONTINUITY_4 9 -#define LED_PIN_CONTINUITY_3 10 -#define LED_PIN_CONTINUITY_2 11 -#define LED_PIN_CONTINUITY_1 12 -#define LED_PIN_CONTINUITY_0 13 -#define LED_PIN_REMOTE_ARM 14 -#define LED_PIN_FIRE 15 -#define AO_LED_RED (1 << LED_PIN_RED) -#define AO_LED_AMBER (1 << LED_PIN_AMBER) -#define AO_LED_GREEN (1 << LED_PIN_GREEN) -#define AO_LED_BOX (1 << LED_PIN_BOX) -#define AO_LED_PAD (1 << LED_PIN_PAD) -#define AO_LED_DRAG (1 << LED_PIN_DRAG) -#define AO_LED_CONTINUITY_7 (1 << LED_PIN_CONTINUITY_7) -#define AO_LED_CONTINUITY_6 (1 << LED_PIN_CONTINUITY_6) -#define AO_LED_CONTINUITY_5 (1 << LED_PIN_CONTINUITY_5) -#define AO_LED_CONTINUITY_4 (1 << LED_PIN_CONTINUITY_4) -#define AO_LED_CONTINUITY_3 (1 << LED_PIN_CONTINUITY_3) -#define AO_LED_CONTINUITY_2 (1 << LED_PIN_CONTINUITY_2) -#define AO_LED_CONTINUITY_1 (1 << LED_PIN_CONTINUITY_1) -#define AO_LED_CONTINUITY_0 (1 << LED_PIN_CONTINUITY_0) +#define AO_LED_RED AO_LED_0 +#define AO_LED_AMBER AO_LED_1 +#define AO_LED_GREEN AO_LED_2 +#define AO_LED_BOX AO_LED_3 +#define AO_LED_PAD AO_LED_4 +#define AO_LED_DRAG AO_LED_5 +#define AO_LED_CONTINUITY_7 AO_LED_6 +#define AO_LED_CONTINUITY_6 AO_LED_7 +#define AO_LED_CONTINUITY_5 AO_LED_8 +#define AO_LED_CONTINUITY_4 AO_LED_9 +#define AO_LED_CONTINUITY_3 AO_LED_10 +#define AO_LED_CONTINUITY_2 AO_LED_11 +#define AO_LED_CONTINUITY_1 AO_LED_12 +#define AO_LED_CONTINUITY_0 AO_LED_13 #define AO_LED_CONTINUITY_NUM 8 -#define AO_LED_REMOTE_ARM (1 << LED_PIN_REMOTE_ARM) -#define AO_LED_FIRE (1 << LED_PIN_FIRE) - -#define LEDS_AVAILABLE (AO_LED_RED | \ - AO_LED_AMBER | \ - AO_LED_GREEN | \ - AO_LED_BOX | \ - AO_LED_PAD | \ - AO_LED_DRAG | \ - AO_LED_CONTINUITY_7 | \ - AO_LED_CONTINUITY_6 | \ - AO_LED_CONTINUITY_5 | \ - AO_LED_CONTINUITY_4 | \ - AO_LED_CONTINUITY_3 | \ - AO_LED_CONTINUITY_2 | \ - AO_LED_CONTINUITY_1 | \ - AO_LED_CONTINUITY_0 | \ - AO_LED_REMOTE_ARM | \ - AO_LED_FIRE) +#define AO_LED_REMOTE_ARM AO_LED_14 +#define AO_LED_FIRE AO_LED_15 /* LCD displays */ diff --git a/src/telelco-v2.0/ao_telelco.c b/src/telelco-v2.0/ao_telelco.c index 9693c657..59582569 100644 --- a/src/telelco-v2.0/ao_telelco.c +++ b/src/telelco-v2.0/ao_telelco.c @@ -37,8 +37,8 @@ main(void) { ao_clock_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_task_init(); ao_timer_init(); @@ -68,6 +68,8 @@ main(void) ao_lco_cmd_init(); // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telelcotwo-v0.1/Makefile b/src/telelcotwo-v0.1/Makefile index c68f3eb5..6a114aae 100644 --- a/src/telelcotwo-v0.1/Makefile +++ b/src/telelcotwo-v0.1/Makefile @@ -36,7 +36,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telelcotwo-v0.1/ao_telelcotwo.c b/src/telelcotwo-v0.1/ao_telelcotwo.c index b3fcd200..6ced1912 100644 --- a/src/telelcotwo-v0.1/ao_telelcotwo.c +++ b/src/telelcotwo-v0.1/ao_telelcotwo.c @@ -34,8 +34,8 @@ main(void) { ao_clock_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_beep_init(); ao_task_init(); @@ -61,6 +61,8 @@ main(void) ao_lco_cmd_init(); // ao_radio_cmac_cmd_init(); + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); return 0; } diff --git a/src/telemega-v0.1/Makefile b/src/telemega-v0.1/Makefile index 78cfdefd..fde35aae 100644 --- a/src/telemega-v0.1/Makefile +++ b/src/telemega-v0.1/Makefile @@ -53,7 +53,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemega-v0.1/ao_telemega.c b/src/telemega-v0.1/ao_telemega.c index f8b7ecfa..d6ecbf31 100644 --- a/src/telemega-v0.1/ao_telemega.c +++ b/src/telemega-v0.1/ao_telemega.c @@ -45,8 +45,8 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_timer_init(); ao_i2c_init(); @@ -98,6 +98,7 @@ main(void) ao_sample_profile_init(); #endif + ao_led_off(LEDS_AVAILABLE); ao_start_scheduler(); return 0; } diff --git a/src/telemega-v1.0/Makefile b/src/telemega-v1.0/Makefile index 372d53b8..62eda4ad 100644 --- a/src/telemega-v1.0/Makefile +++ b/src/telemega-v1.0/Makefile @@ -55,7 +55,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemega-v1.0/ao_telemega.c b/src/telemega-v1.0/ao_telemega.c index 50428b61..328c17ff 100644 --- a/src/telemega-v1.0/ao_telemega.c +++ b/src/telemega-v1.0/ao_telemega.c @@ -45,7 +45,7 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telemega-v2.0/Makefile b/src/telemega-v2.0/Makefile index 2592587a..78829fff 100644 --- a/src/telemega-v2.0/Makefile +++ b/src/telemega-v2.0/Makefile @@ -55,7 +55,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemega-v2.0/ao_telemega.c b/src/telemega-v2.0/ao_telemega.c index 6a58547e..623e8d1e 100644 --- a/src/telemega-v2.0/ao_telemega.c +++ b/src/telemega-v2.0/ao_telemega.c @@ -46,7 +46,7 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telemega-v3.0/Makefile b/src/telemega-v3.0/Makefile index df0f4dbb..b449b397 100644 --- a/src/telemega-v3.0/Makefile +++ b/src/telemega-v3.0/Makefile @@ -53,7 +53,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemega-v3.0/ao_telemega.c b/src/telemega-v3.0/ao_telemega.c index 2577f90c..d987c1ec 100644 --- a/src/telemega-v3.0/ao_telemega.c +++ b/src/telemega-v3.0/ao_telemega.c @@ -45,7 +45,7 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telemetrum-v2.0/Makefile b/src/telemetrum-v2.0/Makefile index 0196936b..e0192f61 100644 --- a/src/telemetrum-v2.0/Makefile +++ b/src/telemetrum-v2.0/Makefile @@ -46,7 +46,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemetrum-v2.0/ao_telemetrum.c b/src/telemetrum-v2.0/ao_telemetrum.c index 65f9be2c..dbf6090c 100644 --- a/src/telemetrum-v2.0/ao_telemetrum.c +++ b/src/telemetrum-v2.0/ao_telemetrum.c @@ -43,7 +43,7 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); diff --git a/src/telemetrum-v3.0/Makefile b/src/telemetrum-v3.0/Makefile index c72e781a..071fd8dd 100644 --- a/src/telemetrum-v3.0/Makefile +++ b/src/telemetrum-v3.0/Makefile @@ -46,7 +46,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/telemetrum-v3.0/ao_telemetrum.c b/src/telemetrum-v3.0/ao_telemetrum.c index 2bb5192a..d75f339d 100644 --- a/src/telemetrum-v3.0/ao_telemetrum.c +++ b/src/telemetrum-v3.0/ao_telemetrum.c @@ -43,8 +43,8 @@ main(void) ao_task_init(); ao_serial_init(); - ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_RED); + ao_led_init(); + ao_led_on(LEDS_AVAILABLE); ao_timer_init(); ao_spi_init(); @@ -88,6 +88,7 @@ main(void) #if HAS_SAMPLE_PROFILE ao_sample_profile_init(); #endif + ao_led_off(LEDS_AVAILABLE); ao_start_scheduler(); return 0; diff --git a/src/telepyro-v0.1/Makefile b/src/telepyro-v0.1/Makefile index dcac03dc..9b51d466 100644 --- a/src/telepyro-v0.1/Makefile +++ b/src/telepyro-v0.1/Makefile @@ -29,7 +29,7 @@ ALTOS_SRC = \ ao_stdio.c \ ao_task.c \ ao_timer.c \ - ao_led.c \ + ao_led_avr.c \ ao_avr_stdio.c \ ao_romconfig.c \ ao_usb_avr.c \ diff --git a/src/telescience-pwm/Makefile b/src/telescience-pwm/Makefile index 493bd480..10c63d49 100644 --- a/src/telescience-pwm/Makefile +++ b/src/telescience-pwm/Makefile @@ -42,7 +42,7 @@ ALTOS_SRC = \ ao_stdio.c \ ao_task.c \ ao_timer.c \ - ao_led.c \ + ao_led_avr.c \ ao_avr_stdio.c \ ao_romconfig.c \ ao_usb_avr.c \ diff --git a/src/telescience-v0.1/Makefile b/src/telescience-v0.1/Makefile index c55c48e2..8445c64d 100644 --- a/src/telescience-v0.1/Makefile +++ b/src/telescience-v0.1/Makefile @@ -42,7 +42,7 @@ ALTOS_SRC = \ ao_stdio.c \ ao_task.c \ ao_timer.c \ - ao_led.c \ + ao_led_avr.c \ ao_avr_stdio.c \ ao_romconfig.c \ ao_usb_avr.c \ diff --git a/src/telescience-v0.2/Makefile b/src/telescience-v0.2/Makefile index 6b7ea8c7..bc0a1986 100644 --- a/src/telescience-v0.2/Makefile +++ b/src/telescience-v0.2/Makefile @@ -35,7 +35,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/tmgps-v2.0/Makefile b/src/tmgps-v2.0/Makefile index 9e3965c6..8a1293d2 100644 --- a/src/tmgps-v2.0/Makefile +++ b/src/tmgps-v2.0/Makefile @@ -46,7 +46,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ diff --git a/src/usbtrng-v2.0/Makefile b/src/usbtrng-v2.0/Makefile index 49798f1c..678a24de 100644 --- a/src/usbtrng-v2.0/Makefile +++ b/src/usbtrng-v2.0/Makefile @@ -27,7 +27,7 @@ ALTOS_SRC = \ ao_adc_fast.c \ ao_crc_stm.c \ ao_stdio.c \ - ao_led.c \ + ao_led_stmf0.c \ ao_romconfig.c \ ao_boot_chain.c \ ao_cmd.c \ -- cgit v1.2.3 From 23075d174d2bff8ff3f3deef3c3d90b83da6bd2e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Sep 2018 18:46:52 -0700 Subject: altos/stm32f4: Align stack to 8 bytes This makes sure that doubles are aligned properly when passed on the stack. Signed-off-by: Keith Packard --- src/kernel/ao_task.h | 6 ++---- src/stm32f4/ao_arch.h | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h index f3789fa2..709e10c6 100644 --- a/src/kernel/ao_task.h +++ b/src/kernel/ao_task.h @@ -27,14 +27,12 @@ #endif /* arm stacks must be 32-bit aligned */ +#ifndef AO_STACK_ALIGNMENT #ifdef __arm__ #define AO_STACK_ALIGNMENT __attribute__ ((aligned(4))) -#endif -#ifdef SDCC +#else #define AO_STACK_ALIGNMENT #endif -#ifdef __AVR__ -#define AO_STACK_ALIGNMENT #endif /* An AltOS task */ diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h index 73eb793f..d4c78f60 100644 --- a/src/stm32f4/ao_arch.h +++ b/src/stm32f4/ao_arch.h @@ -19,9 +19,11 @@ #include #ifndef AO_STACK_SIZE -#define AO_STACK_SIZE 512 +#define AO_STACK_SIZE 1024 #endif +#define AO_STACK_ALIGNMENT __attribute__ ((aligned(8))) + #define AO_PORT_TYPE uint16_t #define ao_arch_nop() asm("nop") -- cgit v1.2.3 From 0b5ac831d2e63a091833c702b07b0331fba32e72 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Sep 2018 18:49:22 -0700 Subject: altos/stm32f4: Add usart driver for usart6 This is what the disco board hooks up. Signed-off-by: Keith Packard --- src/stm32f4/ao_arch.h | 28 ++++ src/stm32f4/ao_arch_funcs.h | 6 + src/stm32f4/ao_interrupt.c | 5 +- src/stm32f4/ao_usart_stm32f4.c | 350 +++++++++++++++++++++++++++++++++++++++++ src/stm32f4/registers.ld | 20 +++ src/stm32f4/stm32f4.h | 317 ++++++++++++++++++++++++++++++++++++- 6 files changed, 723 insertions(+), 3 deletions(-) create mode 100644 src/stm32f4/ao_usart_stm32f4.c (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h index d4c78f60..083a4e5b 100644 --- a/src/stm32f4/ao_arch.h +++ b/src/stm32f4/ao_arch.h @@ -100,4 +100,32 @@ #define AO_SYSTICK (AO_HCLK) #define AO_PANIC_DELAY_SCALE (AO_SYSCLK / 12000000) +/* The stm32f413 implements only 4 bits of the priority fields? */ + +#if AO_NONMASK_INTERRUPT +#define AO_STM_NVIC_NONMASK_PRIORITY 0x00 + +/* Set the basepri register to this value to mask all + * non-maskable priorities + */ +#define AO_STM_NVIC_BASEPRI_MASK 0x10 +#endif + +#define AO_STM_NVIC_HIGH_PRIORITY 0x40 +#define AO_STM_NVIC_MED_PRIORITY 0x80 +#define AO_STM_NVIC_LOW_PRIORITY 0xC0 +#define AO_STM_NVIC_CLOCK_PRIORITY 0xf0 + +#define AO_GPIO_MODE_PULL_NONE 0 +#define AO_GPIO_MODE_PULL_UP 4 +#define AO_GPIO_MODE_PULL_DOWN 8 + +/* usart stuff */ + +#define AO_SERIAL_SPEED_4800 4800 +#define AO_SERIAL_SPEED_9600 9600 +#define AO_SERIAL_SPEED_19200 19200 +#define AO_SERIAL_SPEED_57600 57600 +#define AO_SERIAL_SPEED_115200 115200 + #endif /* _AO_ARCH_H_ */ diff --git a/src/stm32f4/ao_arch_funcs.h b/src/stm32f4/ao_arch_funcs.h index 8c0da03b..b1ffb5b6 100644 --- a/src/stm32f4/ao_arch_funcs.h +++ b/src/stm32f4/ao_arch_funcs.h @@ -331,4 +331,10 @@ static inline void ao_disable_port(struct stm_gpio *port) ao_gpio_set_mode(port, bit, mode); \ } while (0) +/* usart */ + +void +ao_usart_init(void); + + #endif /* _AO_ARCH_FUNCS_H_ */ diff --git a/src/stm32f4/ao_interrupt.c b/src/stm32f4/ao_interrupt.c index a00df54b..f1cb8eee 100644 --- a/src/stm32f4/ao_interrupt.c +++ b/src/stm32f4/ao_interrupt.c @@ -119,7 +119,7 @@ isr(spi2) isr(usart1) isr(usart2) isr(usart3) -isr(exti5_10) +isr(exti15_10) isr(rtc_alarm) isr(otg_fs_wkup) isr(tim8_brk_tim12) @@ -231,9 +231,10 @@ const void *stm_interrupt_vector[] = { i(0xd4, usart1), i(0xd8, usart2), i(0xdc, usart3), - i(0xe0, exti5_10), + i(0xe0, exti15_10), i(0xe4, rtc_alarm), i(0xe8, otg_fs_wkup), i(0xec, tim8_brk_tim12), i(0xf0, tim8_up_tim13), + i(0x15c, usart6), }; diff --git a/src/stm32f4/ao_usart_stm32f4.c b/src/stm32f4/ao_usart_stm32f4.c new file mode 100644 index 00000000..28331b1e --- /dev/null +++ b/src/stm32f4/ao_usart_stm32f4.c @@ -0,0 +1,350 @@ +/* + * Copyright © 2018 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 + +/* ao_serial_stm.c */ +struct ao_stm_usart { + struct ao_fifo rx_fifo; + struct ao_fifo tx_fifo; + struct stm_usart *reg; + uint32_t clk; + uint8_t tx_running; + uint8_t draining; +#if HAS_SERIAL_SW_FLOW + /* RTS - 0 if we have FIFO space, 1 if not + * CTS - 0 if we can send, 0 if not + */ + struct stm_gpio *gpio_rts; + struct stm_gpio *gpio_cts; + uint8_t pin_rts; + uint8_t pin_cts; + uint8_t rts; +#endif +}; + +static int +_ao_usart_tx_start(struct ao_stm_usart *usart) +{ + if (!ao_fifo_empty(usart->tx_fifo)) { +#if HAS_SERIAL_SW_FLOW + if (usart->gpio_cts && ao_gpio_get(usart->gpio_cts, usart->pin_cts) == 1) { + ao_exti_enable(usart->gpio_cts, usart->pin_cts); + return 0; + } +#endif + if (usart->reg->sr & (1 << STM_USART_SR_TXE)) + { + usart->tx_running = 1; + usart->reg->cr1 |= (1 << STM_USART_CR1_TXEIE) | (1 << STM_USART_CR1_TCIE); + ao_fifo_remove(usart->tx_fifo, usart->reg->dr); + ao_wakeup(&usart->tx_fifo); + return 1; + } + } + return 0; +} + +#if HAS_SERIAL_SW_FLOW +static void +_ao_usart_cts(struct ao_stm_usart *usart) +{ + if (_ao_usart_tx_start(usart)) + ao_exti_disable(usart->gpio_cts, usart->pin_cts); +} +#endif + +static void +_ao_usart_rx(struct ao_stm_usart *usart, int is_stdin) +{ + if (usart->reg->sr & (1 << STM_USART_SR_RXNE)) { + if (!ao_fifo_full(usart->rx_fifo)) { + ao_fifo_insert(usart->rx_fifo, usart->reg->dr); + ao_wakeup(&usart->rx_fifo); + if (is_stdin) + ao_wakeup(&ao_stdin_ready); +#if HAS_SERIAL_SW_FLOW + /* If the fifo is nearly full, turn off RTS and wait + * for it to drain a bunch + */ + if (usart->gpio_rts && ao_fifo_mostly(usart->rx_fifo)) { + ao_gpio_set(usart->gpio_rts, usart->pin_rts, 1); + usart->rts = 0; + } +#endif + } else { + usart->reg->cr1 &= ~(1 << STM_USART_CR1_RXNEIE); + } + } +} + +static void +ao_usart_isr(struct ao_stm_usart *usart, int is_stdin) +{ + _ao_usart_rx(usart, is_stdin); + + if (!_ao_usart_tx_start(usart)) + usart->reg->cr1 &= ~(1<< STM_USART_CR1_TXEIE); + + if (usart->reg->sr & (1 << STM_USART_SR_TC)) { + usart->tx_running = 0; + usart->reg->cr1 &= ~(1 << STM_USART_CR1_TCIE); + if (usart->draining) { + usart->draining = 0; + ao_wakeup(&usart->tx_fifo); + } + } +} + +static int +_ao_usart_pollchar(struct ao_stm_usart *usart) +{ + int c; + + if (ao_fifo_empty(usart->rx_fifo)) + c = AO_READ_AGAIN; + else { + uint8_t u; + ao_fifo_remove(usart->rx_fifo,u); + if ((usart->reg->cr1 & (1 << STM_USART_CR1_RXNEIE)) == 0) { + if (ao_fifo_barely(usart->rx_fifo)) + usart->reg->cr1 |= (1 << STM_USART_CR1_RXNEIE); + } +#if HAS_SERIAL_SW_FLOW + /* If we've cleared RTS, check if there's space now and turn it back on */ + if (usart->gpio_rts && usart->rts == 0 && ao_fifo_barely(usart->rx_fifo)) { + ao_gpio_set(usart->gpio_rts, usart->pin_rts, 0); + usart->rts = 1; + } +#endif + c = u; + } + return c; +} + +static char +ao_usart_getchar(struct ao_stm_usart *usart) +{ + int c; + ao_arch_block_interrupts(); + while ((c = _ao_usart_pollchar(usart)) == AO_READ_AGAIN) + ao_sleep(&usart->rx_fifo); + ao_arch_release_interrupts(); + return (char) c; +} + +static inline uint8_t +_ao_usart_sleep_for(struct ao_stm_usart *usart, uint16_t timeout) +{ + return ao_sleep_for(&usart->rx_fifo, timeout); +} + +static void +ao_usart_putchar(struct ao_stm_usart *usart, char c) +{ + ao_arch_block_interrupts(); + while (ao_fifo_full(usart->tx_fifo)) + ao_sleep(&usart->tx_fifo); + ao_fifo_insert(usart->tx_fifo, c); + _ao_usart_tx_start(usart); + ao_arch_release_interrupts(); +} + +static void +ao_usart_drain(struct ao_stm_usart *usart) +{ + ao_arch_block_interrupts(); + while (!ao_fifo_empty(usart->tx_fifo) || usart->tx_running) { + usart->draining = 1; + ao_sleep(&usart->tx_fifo); + } + ao_arch_release_interrupts(); +} + +static void +ao_usart_set_speed(struct ao_stm_usart *usart, uint32_t speed) +{ + if (speed > 115200) + return; + usart->reg->brr = usart->clk / speed; +} + +static void +_ao_usart_init(struct ao_stm_usart *usart, int hw_flow) +{ + usart->reg->cr1 = ((0 << STM_USART_CR1_OVER8) | + (1 << STM_USART_CR1_UE) | + (0 << STM_USART_CR1_M) | + (0 << STM_USART_CR1_WAKE) | + (0 << STM_USART_CR1_PCE) | + (0 << STM_USART_CR1_PS) | + (0 << STM_USART_CR1_PEIE) | + (0 << STM_USART_CR1_TXEIE) | + (0 << STM_USART_CR1_TCIE) | + (1 << STM_USART_CR1_RXNEIE) | + (0 << STM_USART_CR1_IDLEIE) | + (1 << STM_USART_CR1_TE) | + (1 << STM_USART_CR1_RE) | + (0 << STM_USART_CR1_RWU) | + (0 << STM_USART_CR1_SBK)); + + usart->reg->cr2 = ((0 << STM_USART_CR2_LINEN) | + (STM_USART_CR2_STOP_1 << STM_USART_CR2_STOP) | + (0 << STM_USART_CR2_CLKEN) | + (0 << STM_USART_CR2_CPOL) | + (0 << STM_USART_CR2_CPHA) | + (0 << STM_USART_CR2_LBCL) | + (0 << STM_USART_CR2_LBDIE) | + (0 << STM_USART_CR2_LBDL) | + (0 << STM_USART_CR2_ADD)); + + usart->reg->cr3 = ((0 << STM_USART_CR3_ONEBIT) | + (0 << STM_USART_CR3_CTSIE) | + (0 << STM_USART_CR3_CTSE) | + (0 << STM_USART_CR3_RTSE) | + (0 << STM_USART_CR3_DMAT) | + (0 << STM_USART_CR3_DMAR) | + (0 << STM_USART_CR3_SCEN) | + (0 << STM_USART_CR3_NACK) | + (0 << STM_USART_CR3_HDSEL) | + (0 << STM_USART_CR3_IRLP) | + (0 << STM_USART_CR3_IREN) | + (0 << STM_USART_CR3_EIE)); + + if (hw_flow) + usart->reg->cr3 |= ((1 << STM_USART_CR3_CTSE) | + (1 << STM_USART_CR3_RTSE)); + + /* Pick a 9600 baud rate */ + ao_usart_set_speed(usart, 9600); +} + +#if HAS_SERIAL_HW_FLOW +static void +ao_usart_set_flow(struct ao_stm_usart *usart) +{ +} +#endif + +#if HAS_SERIAL_6 + +struct ao_stm_usart ao_stm_usart6; + +void stm_usart6_isr(void) { ao_usart_isr(&ao_stm_usart6, USE_SERIAL_6_STDIN); } + +char +ao_serial6_getchar(void) +{ + return ao_usart_getchar(&ao_stm_usart6); +} + +void +ao_serial6_putchar(char c) +{ + ao_usart_putchar(&ao_stm_usart6, c); +} + +int +_ao_serial6_pollchar(void) +{ + return _ao_usart_pollchar(&ao_stm_usart6); +} + +uint8_t +_ao_serial6_sleep_for(uint16_t timeout) +{ + return _ao_usart_sleep_for(&ao_stm_usart6, timeout); +} + +void +ao_serial6_set_speed(uint32_t speed) +{ + ao_usart_drain(&ao_stm_usart6); + ao_usart_set_speed(&ao_stm_usart6, speed); +} + +void +ao_serial6_drain(void) +{ + ao_usart_drain(&ao_stm_usart6); +} +#endif /* HAS_SERIAL_6 */ + +#if HAS_SERIAL_SW_FLOW +static void +ao_serial_set_sw_rts_cts(struct ao_stm_usart *usart, + void (*isr)(void), + struct stm_gpio *port_rts, + int pin_rts, + struct stm_gpio *port_cts, + int pin_cts) +{ + /* Pull RTS low to note that there's space in the FIFO */ + ao_enable_output(port_rts, pin_rts, 0); + usart->gpio_rts = port_rts; + usart->pin_rts = pin_rts; + usart->rts = 1; + + ao_exti_setup(port_cts, pin_cts, AO_EXTI_MODE_FALLING|AO_EXTI_PRIORITY_MED, isr); + usart->gpio_cts = port_cts; + usart->pin_cts = pin_cts; +} +#endif + +void +ao_usart_init(void) +{ +#if HAS_SERIAL_6 + stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_USART6EN); + + ao_stm_usart6.reg = &stm_usart6; + ao_stm_usart6.clk = AO_P2CLK; + + ao_enable_port(SERIAL_6_RX_PORT); + ao_enable_port(SERIAL_6_TX_PORT); + + stm_afr_set(SERIAL_6_RX_PORT, SERIAL_6_RX_PIN, STM_AFR_AF8); + stm_afr_set(SERIAL_6_TX_PORT, SERIAL_6_TX_PIN, STM_AFR_AF8); + + stm_nvic_set_enable(STM_ISR_USART6_POS); + stm_nvic_set_priority(STM_ISR_USART6_POS, AO_STM_NVIC_MED_PRIORITY); + + _ao_usart_init(&ao_stm_usart6, USE_SERIAL_6_FLOW && !USE_SERIAL_6_SW_FLOW); + +# if USE_SERIAL_6_FLOW +# if USE_SERIAL_6_SW_FLOW + ao_serial_set_sw_rts_cts(&ao_stm_usart6, + ao_serial6_cts, + SERIAL_6_PORT_RTS, + SERIAL_6_PIN_RTS, + SERIAL_6_PORT_CTS, + SERIAL_6_PIN_CTS); +# else + stm_afr_set(SERIAL_6_PORT_RTS, SERIAL_6_PIN_RTS, STM_AFR_AF8); + stm_afr_set(SERIAL_6_PORT_CTS, SERIAL_6_PIN_CTS, STM_AFR_AF8); +# endif +#endif + +#if USE_SERIAL_6_STDIN && !DELAY_SERIAL_6_STDIN + ao_add_stdio(_ao_serial6_pollchar, + ao_serial6_putchar, + NULL); +#endif +#endif +} diff --git a/src/stm32f4/registers.ld b/src/stm32f4/registers.ld index b36b2098..20ffa0a0 100644 --- a/src/stm32f4/registers.ld +++ b/src/stm32f4/registers.ld @@ -19,6 +19,26 @@ stm_dac1 = 0x40007400; stm_uart7 = 0x40007800; stm_uart8 = 0x40007c00; +stm_tim1 = 0x40010000; +stm_tim8 = 0x40010400; +stm_usart1 = 0x40011000; +stm_usart6 = 0x40011400; +stm_uart9 = 0x40011800; +stm_uart10 = 0x40011c00; +stm_adc = 0x40012000; +stm_sdio = 0x40012c00; +stm_spi1 = 0x40013000; +stm_spi4 = 0x40013400; +stm_syscfg = 0x40013800; +stm_exti = 0x40013c00; +stm_tim9 = 0x40014000; +stm_tim10 = 0x40014400; +stm_tim11 = 0x40014800; +stm_spi5 = 0x40015000; +stm_sai1 = 0x40015800; +stm_dfsdm1 = 0x40016000; +stm_dfsdm2 = 0x40016400; + stm_gpioa = 0x40020000; stm_gpiob = 0x40020400; stm_gpioc = 0x40020800; diff --git a/src/stm32f4/stm32f4.h b/src/stm32f4/stm32f4.h index 3429e458..715a2c92 100644 --- a/src/stm32f4/stm32f4.h +++ b/src/stm32f4/stm32f4.h @@ -223,6 +223,26 @@ extern struct stm_rcc stm_rcc; #define STM_RCC_APB1ENR_TIM3EN 1 #define STM_RCC_APB1ENR_TIM2EN 0 +#define STM_RCC_APB2ENR_DFSDM2EN 25 +#define STM_RCC_APB2ENR_DFSDM1EN 24 +#define STM_RCC_APB2ENR_SAI1EN 22 +#define STM_RCC_APB2ENR_SPI5EN 20 +#define STM_RCC_APB2ENR_TIM11EN 18 +#define STM_RCC_APB2ENR_TIM10EN 17 +#define STM_RCC_APB2ENR_TIM9EN 16 +#define STM_RCC_APB2ENR_EXITEN 15 +#define STM_RCC_APB2ENR_SYSCFGEN 14 +#define STM_RCC_APB2ENR_SPI4EN 13 +#define STM_RCC_APB2ENR_SPI1EN 12 +#define STM_RCC_APB2ENR_SDIOEN 11 +#define STM_RCC_APB2ENR_ADC1EN 8 +#define STM_RCC_APB2ENR_UART10EN 7 +#define STM_RCC_APB2ENR_UART9EN 5 +#define STM_RCC_APB2ENR_USART6EN 5 +#define STM_RCC_APB2ENR_USART1EN 4 +#define STM_RCC_APB2ENR_TIM8EN 1 +#define STM_RCC_APB2ENR_TIM1EN 0 + #define STM_RCC_CSR_RMVF 24 struct stm_ictr { @@ -283,7 +303,7 @@ static inline int stm_nvic_enabled(int irq) { return IRQ_BOOL(stm_nvic.iser[IRQ_REG(irq)], irq); } - + static inline void stm_nvic_set_pending(int irq) { stm_nvic.ispr[IRQ_REG(irq)] = IRQ_MASK(irq); @@ -324,6 +344,152 @@ stm_nvic_get_priority(int irq) { return (stm_nvic.ipr[IRQ_PRIO_REG(irq)] >> IRQ_PRIO_BIT(irq)) & IRQ_PRIO_MASK(0); } +#define isr(name) void stm_ ## name ## _isr(void) + +isr(nmi); +isr(hardfault); +isr(memmanage); +isr(busfault); +isr(usagefault); +isr(svc); +isr(debugmon); +isr(pendsv); +isr(systick); +isr(wwdg); +isr(pvd); +isr(tamper_stamp); +isr(rtc_wkup); +isr(flash); +isr(rcc); +isr(exti0); +isr(exti1); +isr(exti2); +isr(exti3); +isr(exti4); +isr(dma1_stream0); +isr(dma1_stream1); +isr(dma1_stream2); +isr(dma1_stream3); +isr(dma1_stream4); +isr(dma1_stream5); +isr(dma1_stream6); +isr(adc); +isr(can1_tx); +isr(can1_rx0); +isr(can1_rx1); +isr(can1_sce); +isr(exti9_5); +isr(tim1_brk_tim9); +isr(tim1_up_tim10); +isr(tim_trg_com_tim11); +isr(tim1_cc); +isr(tim2); +isr(tim3); +isr(tim4); +isr(i2c1_evt); +isr(i2c1_err); +isr(i2c2_evt); +isr(i2c2_err); +isr(spi1); +isr(spi2); +isr(usart1); +isr(usart2); +isr(usart3); +isr(exti15_10); +isr(rtc_alarm); +isr(otg_fs_wkup); +isr(tim8_brk_tim12); +isr(tim8_up_tim13); +isr(tim8_trg_com_tim14); +isr(tim8_cc); +isr(dma1_stream7); +isr(fsmc); +isr(sdio); +isr(tim5); +isr(spi3); +isr(uart4); +isr(uart5); +isr(tim6_glb_it); +isr(tim7); +isr(dma2_stream0); +isr(dma2_stream1); +isr(dma2_stream2); +isr(dma2_stream3); +isr(dma2_stream4); +isr(dfsdm1_flt0); +isr(dfsdm1_flt1); +isr(can2_tx); +isr(can2_rx0); +isr(can2_rx1); +isr(can2_sce); +isr(otg_fs); +isr(dma2_stream5); +isr(dma2_stream6); +isr(dma2_stream7); +isr(usart6); +isr(i2c3_ev); +isr(i2c3_er); +isr(can3_tx); +isr(can3_rx0); +isr(can3_rx1); +isr(can3_sce); +isr(crypto); +isr(rng); +isr(fpu); +isr(uart7); +isr(uart8); +isr(spi4); +isr(spi5); +isr(sai1); +isr(uart9); +isr(uart10); +isr(quad_spi); +isr(i2cfmp1_ev); +isr(i2cfmp1_er); +isr(exti23); +isr(dfsdm2_flt0); +isr(dfsdm2_flt1); +isr(dfsdm2_flt2); +isr(dfsdm2_flt3); + +#undef isr + +#define STM_ISR_WWDG_POS 0 +#define STM_ISR_PVD_POS 1 +#define STM_ISR_TAMPER_STAMP_POS 2 +#define STM_ISR_RTC_WKUP_POS 3 +#define STM_ISR_FLASH_POS 4 +#define STM_ISR_RCC_POS 5 +#define STM_ISR_EXTI0_POS 6 +#define STM_ISR_EXTI1_POS 7 +#define STM_ISR_EXTI2_POS 8 +#define STM_ISR_EXTI3_POS 9 +#define STM_ISR_EXTI4_POS 10 +#define STM_ISR_DMA1_STREAM0_POS 11 +#define STM_ISR_DMA1_STREAM1_POS 12 +#define STM_ISR_DMA1_STREAM2_POS 13 +#define STM_ISR_DMA1_STREAM3_POS 14 +#define STM_ISR_DMA1_STREAM4_POS 15 +#define STM_ISR_DMA1_STREAM5_POS 16 +#define STM_ISR_DMA1_STREAM6_POS 17 +#define STM_ISR_ADC_POS 18 +#define STM_ISR_CAN1_TX_POS 19 +#define STM_ISR_CAN1_RX0_POS 20 +#define STM_ISR_CAN1_RX1_POS 21 +#define STM_ISR_CAN1_SCE_POS 22 +#define STM_ISR_EXTI9_5_POS 23 +#define STM_ISR_USART1_POS 37 +#define STM_ISR_USART2_POS 38 +#define STM_ISR_USART3_POS 39 +#define STM_ISR_UART4_POS 52 +#define STM_ISR_UART5_POS 53 +#define STM_ISR_USART6_POS 71 +#define STM_ISR_UART7_POS 82 +#define STM_ISR_UART9_POS 88 +#define STM_ISR_UART10_POS 89 + +#define STM_ISR_EXTI15_10_POS 40 + struct stm_flash { vuint32_t acr; vuint32_t keyr; @@ -595,6 +761,13 @@ extern struct stm_scb stm_scb; #define STM_SCB_CPACR_FP0 STM_SCB_CPACR_CP(10) #define STM_SCB_CPACR_FP1 STM_SCB_CPACR_CP(11) +#define STM_SCB_AIRCR_VECTKEY 16 +#define STM_SCB_AIRCR_VECTKEY_KEY 0x05fa +#define STM_SCB_AIRCR_PRIGROUP 8 +#define STM_SCB_AIRCR_SYSRESETREQ 2 +#define STM_SCB_AIRCR_VECTCLRACTIVE 1 +#define STM_SCB_AIRCR_VECTRESET 0 + /* The SYSTICK starts at 0xe000e010 */ struct stm_systick { @@ -615,6 +788,148 @@ extern struct stm_systick stm_systick; #define STM_SYSTICK_CSR_CLKSOURCE_AHB 1 #define STM_SYSTICK_CSR_COUNTFLAG 16 +#define STM_SYSCFG_EXTICR_PA 0 +#define STM_SYSCFG_EXTICR_PB 1 +#define STM_SYSCFG_EXTICR_PC 2 +#define STM_SYSCFG_EXTICR_PD 3 +#define STM_SYSCFG_EXTICR_PE 4 +#define STM_SYSCFG_EXTICR_PF 5 +#define STM_SYSCFG_EXTICR_PG 6 +#define STM_SYSCFG_EXTICR_PH 7 + +struct stm_syscfg { + vuint32_t memrmp; + vuint32_t pmc; + vuint32_t exticr[4]; +}; + +extern struct stm_syscfg stm_syscfg; + +#define stm_syscfg (*((struct stm_syscfg *) 0x40013800)) + +#define STM_SYSCFG_MEMRMP_MEM_MODE 0 +#define STM_SYSCFG_MEMRMP_MEM_MODE_MAIN_FLASH 0 +#define STM_SYSCFG_MEMRMP_MEM_MODE_SYSTEM_FLASH 1 +#define STM_SYSCFG_MEMRMP_MEM_MODE_SRAM 3 +#define STM_SYSCFG_MEMRMP_MEM_MODE_MASK 3 + +#define STM_SYSCFG_PMC_ADC1DC2 0 + +static inline void +stm_exticr_set(struct stm_gpio *gpio, int pin) { + uint8_t reg = pin >> 2; + uint8_t shift = (pin & 3) << 2; + uint8_t val = 0; + + /* Enable SYSCFG */ + stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGEN); + + if (gpio == &stm_gpioa) + val = STM_SYSCFG_EXTICR_PA; + else if (gpio == &stm_gpiob) + val = STM_SYSCFG_EXTICR_PB; + else if (gpio == &stm_gpioc) + val = STM_SYSCFG_EXTICR_PC; + else if (gpio == &stm_gpiod) + val = STM_SYSCFG_EXTICR_PD; + else if (gpio == &stm_gpioe) + val = STM_SYSCFG_EXTICR_PE; + else if (gpio == &stm_gpiof) + val = STM_SYSCFG_EXTICR_PF; + else if (gpio == &stm_gpiog) + val = STM_SYSCFG_EXTICR_PG; + else if (gpio == &stm_gpioh) + val = STM_SYSCFG_EXTICR_PH; + + stm_syscfg.exticr[reg] = (stm_syscfg.exticr[reg] & ~(0xf << shift)) | val << shift; +} + +struct stm_exti { + vuint32_t imr; + vuint32_t emr; + vuint32_t rtsr; + vuint32_t ftsr; + + vuint32_t swier; + vuint32_t pr; +}; + +extern struct stm_exti stm_exti; + +#define stm_exti (*((struct stm_exti *) 0x40013c00)) + +struct stm_usart { + vuint32_t sr; /* status register */ + vuint32_t dr; /* data register */ + vuint32_t brr; /* baud rate register */ + vuint32_t cr1; /* control register 1 */ + + vuint32_t cr2; /* control register 2 */ + vuint32_t cr3; /* control register 3 */ + vuint32_t gtpr; /* guard time and prescaler */ +}; + +extern struct stm_usart stm_usart6; + +#define stm_usart6 (*((struct stm_usart *) 0x40011400)) + +#define STM_USART_SR_CTS (9) /* CTS flag */ +#define STM_USART_SR_LBD (8) /* LIN break detection flag */ +#define STM_USART_SR_TXE (7) /* Transmit data register empty */ +#define STM_USART_SR_TC (6) /* Transmission complete */ +#define STM_USART_SR_RXNE (5) /* Read data register not empty */ +#define STM_USART_SR_IDLE (4) /* IDLE line detected */ +#define STM_USART_SR_ORE (3) /* Overrun error */ +#define STM_USART_SR_NF (2) /* Noise detected flag */ +#define STM_USART_SR_FE (1) /* Framing error */ +#define STM_USART_SR_PE (0) /* Parity error */ + +#define STM_USART_CR1_OVER8 (15) /* Oversampling mode */ +#define STM_USART_CR1_UE (13) /* USART enable */ +#define STM_USART_CR1_M (12) /* Word length */ +#define STM_USART_CR1_WAKE (11) /* Wakeup method */ +#define STM_USART_CR1_PCE (10) /* Parity control enable */ +#define STM_USART_CR1_PS (9) /* Parity selection */ +#define STM_USART_CR1_PEIE (8) /* PE interrupt enable */ +#define STM_USART_CR1_TXEIE (7) /* TXE interrupt enable */ +#define STM_USART_CR1_TCIE (6) /* Transmission complete interrupt enable */ +#define STM_USART_CR1_RXNEIE (5) /* RXNE interrupt enable */ +#define STM_USART_CR1_IDLEIE (4) /* IDLE interrupt enable */ +#define STM_USART_CR1_TE (3) /* Transmitter enable */ +#define STM_USART_CR1_RE (2) /* Receiver enable */ +#define STM_USART_CR1_RWU (1) /* Receiver wakeup */ +#define STM_USART_CR1_SBK (0) /* Send break */ + +#define STM_USART_CR2_LINEN (14) /* LIN mode enable */ +#define STM_USART_CR2_STOP (12) /* STOP bits */ +#define STM_USART_CR2_STOP_MASK 3 +#define STM_USART_CR2_STOP_1 0 +#define STM_USART_CR2_STOP_0_5 1 +#define STM_USART_CR2_STOP_2 2 +#define STM_USART_CR2_STOP_1_5 3 + +#define STM_USART_CR2_CLKEN (11) /* Clock enable */ +#define STM_USART_CR2_CPOL (10) /* Clock polarity */ +#define STM_USART_CR2_CPHA (9) /* Clock phase */ +#define STM_USART_CR2_LBCL (8) /* Last bit clock pulse */ +#define STM_USART_CR2_LBDIE (6) /* LIN break detection interrupt enable */ +#define STM_USART_CR2_LBDL (5) /* lin break detection length */ +#define STM_USART_CR2_ADD (0) +#define STM_USART_CR2_ADD_MASK 0xf + +#define STM_USART_CR3_ONEBIT (11) /* One sample bit method enable */ +#define STM_USART_CR3_CTSIE (10) /* CTS interrupt enable */ +#define STM_USART_CR3_CTSE (9) /* CTS enable */ +#define STM_USART_CR3_RTSE (8) /* RTS enable */ +#define STM_USART_CR3_DMAT (7) /* DMA enable transmitter */ +#define STM_USART_CR3_DMAR (6) /* DMA enable receiver */ +#define STM_USART_CR3_SCEN (5) /* Smartcard mode enable */ +#define STM_USART_CR3_NACK (4) /* Smartcard NACK enable */ +#define STM_USART_CR3_HDSEL (3) /* Half-duplex selection */ +#define STM_USART_CR3_IRLP (2) /* IrDA low-power */ +#define STM_USART_CR3_IREN (1) /* IrDA mode enable */ +#define STM_USART_CR3_EIE (0) /* Error interrupt enable */ + /* Errata 2.1.5 Delay after an RCC peripheral clock enabling -- cgit v1.2.3 From 44ae8b9317fa4aaccabbe9d07b5972f7dfd3baa2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Sep 2018 18:53:15 -0700 Subject: altos: Clean up AO_ROMCONFIG bits Remove address parameter (doesn't work with gcc), create shared ao_romconfig in kernel. Signed-off-by: Keith Packard --- src/attiny/ao_arch.h | 2 ++ src/avr/ao_romconfig.c | 21 --------------------- src/kernel/ao.h | 13 +++++++++++++ src/kernel/ao_product.c | 2 +- src/kernel/ao_romconfig.c | 26 ++++++++++++++++++++++++++ src/lpc/ao_arch.h | 9 +-------- src/lpc/ao_romconfig.c | 26 -------------------------- src/stm/ao_arch.h | 9 +-------- src/stm/ao_romconfig.c | 29 ----------------------------- src/stm32f4/ao_arch.h | 6 ++++++ src/stmf0/ao_arch.h | 4 +--- src/stmf0/ao_romconfig.c | 28 ---------------------------- 12 files changed, 51 insertions(+), 124 deletions(-) delete mode 100644 src/avr/ao_romconfig.c create mode 100644 src/kernel/ao_romconfig.c delete mode 100644 src/lpc/ao_romconfig.c delete mode 100644 src/stm/ao_romconfig.c delete mode 100644 src/stmf0/ao_romconfig.c (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/attiny/ao_arch.h b/src/attiny/ao_arch.h index a9c450fc..dfd41afe 100644 --- a/src/attiny/ao_arch.h +++ b/src/attiny/ao_arch.h @@ -49,6 +49,8 @@ #define ao_arch_interrupt(n) /* nothing */ +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const + #undef putchar #undef getchar #define putchar(c) ao_putchar(c) diff --git a/src/avr/ao_romconfig.c b/src/avr/ao_romconfig.c deleted file mode 100644 index 4acfc1c8..00000000 --- a/src/avr/ao_romconfig.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright © 2011 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 "ao.h" - -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; diff --git a/src/kernel/ao.h b/src/kernel/ao.h index 1b269d73..9baae8b4 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -81,6 +81,19 @@ typedef AO_PORT_TYPE ao_port_t; void ao_panic(uint8_t reason); +/* + * ao_romconfig.c + */ + +#define AO_ROMCONFIG_VERSION 2 + +extern AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_version; +extern AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_check; +extern AO_ROMCONFIG_SYMBOL uint16_t ao_serial_number; +#if HAS_RADIO +extern AO_ROMCONFIG_SYMBOL uint32_t ao_radio_cal; +#endif + /* * ao_timer.c */ diff --git a/src/kernel/ao_product.c b/src/kernel/ao_product.c index 4c2d83ef..72488654 100644 --- a/src/kernel/ao_product.c +++ b/src/kernel/ao_product.c @@ -61,7 +61,7 @@ const char ao_product[] = AO_iProduct_STRING; #define NUM_INTERFACES (AO_USB_HAS_INT + 1) /* USB descriptors in one giant block of bytes */ -AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] = +AO_ROMCONFIG_SYMBOL uint8_t ao_usb_descriptors [] = { /* Device descriptor */ 0x12, diff --git a/src/kernel/ao_romconfig.c b/src/kernel/ao_romconfig.c new file mode 100644 index 00000000..b75142f5 --- /dev/null +++ b/src/kernel/ao_romconfig.c @@ -0,0 +1,26 @@ +/* + * Copyright © 2011 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 "ao.h" + +AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION; +AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION; +AO_ROMCONFIG_SYMBOL uint16_t ao_serial_number = 0; +#if HAS_RADIO +AO_ROMCONFIG_SYMBOL uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; +#endif diff --git a/src/lpc/ao_arch.h b/src/lpc/ao_arch.h index 889be53e..35dcc9de 100644 --- a/src/lpc/ao_arch.h +++ b/src/lpc/ao_arch.h @@ -58,14 +58,7 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_VERSION 2 - -#define AO_ROMCONFIG_SYMBOL(a) __attribute__((section(".romconfig"))) const - -extern const uint16_t ao_romconfig_version; -extern const uint16_t ao_romconfig_check; -extern const uint16_t ao_serial_number; -extern const uint32_t ao_radio_cal; +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const #define ao_arch_task_members\ uint32_t *sp; /* saved stack pointer */ diff --git a/src/lpc/ao_romconfig.c b/src/lpc/ao_romconfig.c deleted file mode 100644 index 4e7bab8d..00000000 --- a/src/lpc/ao_romconfig.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2011 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 "ao.h" - -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; -#ifdef AO_RADIO_CAL_DEFAULT -AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; -#endif diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index aee9df3c..e56375ca 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -56,14 +56,7 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_VERSION 2 - -#define AO_ROMCONFIG_SYMBOL(a) __attribute__((section(".romconfig"))) const - -extern const uint16_t ao_romconfig_version; -extern const uint16_t ao_romconfig_check; -extern const uint16_t ao_serial_number; -extern const uint32_t ao_radio_cal; +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const #define ao_arch_task_members\ uint32_t *sp; /* saved stack pointer */ diff --git a/src/stm/ao_romconfig.c b/src/stm/ao_romconfig.c deleted file mode 100644 index 63a48bec..00000000 --- a/src/stm/ao_romconfig.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2011 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 "ao.h" - -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; -#ifndef AO_RADIO_CAL_DEFAULT -#define AO_RADIO_CAL_DEFAULT 0x01020304 -#endif -#if HAS_RADIO -AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; -#endif diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h index 083a4e5b..4e9bdeb6 100644 --- a/src/stm32f4/ao_arch.h +++ b/src/stm32f4/ao_arch.h @@ -26,8 +26,14 @@ #define AO_PORT_TYPE uint16_t +#define ao_arch_reboot() \ + (stm_scb.aircr = ((STM_SCB_AIRCR_VECTKEY_KEY << STM_SCB_AIRCR_VECTKEY) | \ + (1 << STM_SCB_AIRCR_SYSRESETREQ))) + #define ao_arch_nop() asm("nop") +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const + #define ao_arch_task_members\ uint32_t *sp; /* saved stack pointer */ diff --git a/src/stmf0/ao_arch.h b/src/stmf0/ao_arch.h index 15642951..22e706b2 100644 --- a/src/stmf0/ao_arch.h +++ b/src/stmf0/ao_arch.h @@ -58,9 +58,7 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_VERSION 2 - -#define AO_ROMCONFIG_SYMBOL(a) __attribute__((section(".romconfig"))) const +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const extern const uint16_t ao_romconfig_version; extern const uint16_t ao_romconfig_check; diff --git a/src/stmf0/ao_romconfig.c b/src/stmf0/ao_romconfig.c deleted file mode 100644 index 9d5fd6fb..00000000 --- a/src/stmf0/ao_romconfig.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2011 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 "ao.h" - -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION; -AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; -#ifndef AO_RADIO_CAL_DEFAULT -#define AO_RADIO_CAL_DEFAULT 0x01020304 -#endif -AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; - -- cgit v1.2.3 From 015d3055a52532070e96469907683c3aa3eda44e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 2 Oct 2018 12:44:58 -0700 Subject: altos/stm32f4: Add more stm32f413 definitions and support code Signed-off-by: Keith Packard --- src/stm32f4/ao_arch.h | 6 +- src/stm32f4/ao_interrupt.c | 50 +++++ src/stm32f4/ao_timer.c | 14 +- src/stm32f4/registers.ld | 8 + src/stm32f4/stm32f4.h | 509 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 580 insertions(+), 7 deletions(-) (limited to 'src/stm32f4/ao_arch.h') diff --git a/src/stm32f4/ao_arch.h b/src/stm32f4/ao_arch.h index 4e9bdeb6..73dc3e93 100644 --- a/src/stm32f4/ao_arch.h +++ b/src/stm32f4/ao_arch.h @@ -19,7 +19,11 @@ #include #ifndef AO_STACK_SIZE -#define AO_STACK_SIZE 1024 +#define AO_STACK_SIZE 2048 +#endif + +#ifndef HAS_TASK_QUEUE +#define HAS_TASK_QUEUE 1 #endif #define AO_STACK_ALIGNMENT __attribute__ ((aligned(8))) diff --git a/src/stm32f4/ao_interrupt.c b/src/stm32f4/ao_interrupt.c index f1cb8eee..24f56abc 100644 --- a/src/stm32f4/ao_interrupt.c +++ b/src/stm32f4/ao_interrupt.c @@ -236,5 +236,55 @@ const void *stm_interrupt_vector[] = { i(0xe8, otg_fs_wkup), i(0xec, tim8_brk_tim12), i(0xf0, tim8_up_tim13), + i(0xf4, tim8_trg_com_tim14), + i(0xf8, tim8_cc), + i(0xfc, dma1_stream7), + i(0x100, fsmc), + i(0x104, sdio), + i(0x108, tim5), + i(0x10c, spi3), + i(0x110, uart4), + i(0x114, uart5), + i(0x118,tim6_glb_it), + i(0x11c, tim7), + i(0x120, dma2_stream0), + i(0x124, dma2_stream1), + i(0x128, dma2_stream2), + i(0x12c, dma2_stream3), + i(0x130, dma2_stream4), + i(0x134, dfsdm1_flt0), + i(0x138, dfsdm1_flt1), + i(0x13c, can2_tx), + i(0x140, can2_rx0), + i(0x144, can2_rx1), + i(0x148, can2_sce), + i(0x14c, otg_fs), + i(0x150, dma2_stream5), + i(0x154, dma2_stream6), + i(0x158, dma2_stream7), i(0x15c, usart6), + i(0x160, i2c3_ev), + i(0x164, i2c3_er), + i(0x168, can3_tx), + i(0x16c, can3_rx0), + i(0x170, can3_rx1), + i(0x174, can3_sce), + i(0x17c, crypto), + i(0x180, rng), + i(0x184, fpu), + i(0x188, uart7), + i(0x18c, uart8), + i(0x190, spi4), + i(0x194, spi5), + i(0x19c, sai1), + i(0x1a0, uart9), + i(0x1a4, uart10), + i(0x1b0, quad_spi), + i(0x1bc, i2cfmp1_ev), + i(0x1c0, i2cfmp1_er), + i(0x1c4, exti23), + i(0x1c8, dfsdm2_flt0), + i(0x1cc, dfsdm2_flt1), + i(0x1d0, dfsdm2_flt2), + i(0x1d4, dfsdm2_flt3), }; diff --git a/src/stm32f4/ao_timer.c b/src/stm32f4/ao_timer.c index e378ed07..d6ef9bc3 100644 --- a/src/stm32f4/ao_timer.c +++ b/src/stm32f4/ao_timer.c @@ -181,6 +181,14 @@ ao_clock_init(void) cfgr |= (AO_RCC_CFGR_PPRE2_DIV << STM_RCC_CFGR_PPRE2); stm_rcc.cfgr = cfgr; + /* Clock configuration register DCKCFGR2; mostly make sure USB + * gets clocked from PLL_Q + */ + stm_rcc.dckcfgr2 = ((STM_RCC_DCKCFGR2_LPTIMER1SEL_APB << STM_RCC_DCKCFGR2_LPTIMER1SEL) | + (STM_RCC_DCKCFGR2_SDIOSEL_CK_48MHZ << STM_RCC_DCKCFGR2_SDIOSEL) | + (STM_RCC_DCKCFGR2_CK48MSEL_PLL_Q << STM_RCC_DCKCFGR2_CK48MSEL) | + (STM_RCC_DCKCFGR2_I2CFMP1SEL_APB << STM_RCC_DCKCFGR2_I2CFMP1SEL)); + /* Disable the PLL */ stm_rcc.cr &= ~(1 << STM_RCC_CR_PLLON); while (stm_rcc.cr & (1 << STM_RCC_CR_PLLRDY)) @@ -196,7 +204,6 @@ ao_clock_init(void) pllcfgr |= (AO_PLL_M << STM_RCC_PLLCFGR_PLLM); pllcfgr |= (AO_PLL1_N << STM_RCC_PLLCFGR_PLLN); -#if AO_PLL1_P #if AO_PLL1_P == 2 #define AO_RCC_PLLCFGR_PLLP STM_RCC_PLLCFGR_PLLP_DIV_2 #endif @@ -210,13 +217,8 @@ ao_clock_init(void) #define AO_RCC_PLLCFGR_PLLP STM_RCC_PLLCFGR_PLLP_DIV_8 #endif pllcfgr |= (AO_RCC_PLLCFGR_PLLP << STM_RCC_PLLCFGR_PLLP); -#endif -#if AO_PLL1_Q pllcfgr |= (AO_PLL1_Q << STM_RCC_PLLCFGR_PLLQ); -#endif -#if AO_PLL1_R pllcfgr |= (AO_PLL1_R << STM_RCC_PLLCFGR_PLLR); -#endif /* PLL source */ pllcfgr &= ~(1 << STM_RCC_PLLCFGR_PLLSRC); #if AO_HSI diff --git a/src/stm32f4/registers.ld b/src/stm32f4/registers.ld index 20ffa0a0..bc924106 100644 --- a/src/stm32f4/registers.ld +++ b/src/stm32f4/registers.ld @@ -1,3 +1,4 @@ + stm_tim2 = 0x40000000; stm_tim3 = 0x40000400; stm_tim4 = 0x40000800; @@ -39,6 +40,8 @@ stm_sai1 = 0x40015800; stm_dfsdm1 = 0x40016000; stm_dfsdm2 = 0x40016400; +/* AHB1 */ + stm_gpioa = 0x40020000; stm_gpiob = 0x40020400; stm_gpioc = 0x40020800; @@ -54,6 +57,11 @@ stm_flash = 0x40023c00; stm_dma1 = 0x40026000; stm_dma2 = 0x40026400; +/* AHB2 */ + +stm_usb = 0x50000000; +stm_rng = 0x50060800; + stm_systick = 0xe000e010; stm_ictr = 0xe000e004; diff --git a/src/stm32f4/stm32f4.h b/src/stm32f4/stm32f4.h index 715a2c92..dcdce667 100644 --- a/src/stm32f4/stm32f4.h +++ b/src/stm32f4/stm32f4.h @@ -193,6 +193,10 @@ extern struct stm_rcc stm_rcc; #define STM_RCC_AHB1ENR_IOPGEN 6 #define STM_RCC_AHB1ENR_IOPHEN 7 +#define STM_RCC_AHB2ENR_OTGFSEN 7 +#define STM_RCC_AHB2ENR_RNGEN 6 +#define STM_RCC_AHB2ENR_CRYPEN 4 + #define STM_RCC_APB1ENR_UART8EN 31 #define STM_RCC_APB1ENR_UART7EN 30 #define STM_RCC_APB1ENR_DACEN 29 @@ -245,6 +249,34 @@ extern struct stm_rcc stm_rcc; #define STM_RCC_CSR_RMVF 24 +#define STM_RCC_DCKCFGR_CKDFSDMSEL 31 +#define STM_RCC_DCKCFGR_I2S2SRC 27 +#define STM_RCC_DCKCFGR_I2S1SRC 25 +#define STM_RCC_DCKCFGR_TIMPRE 24 +#define STM_RCC_DCKCFGR_SAII1BSRC 22 +#define STM_RCC_DCKCFGR_SAII1ASRC 20 +#define STM_RCC_DCKCFGR_CKDFSDM1ASEL 15 +#define STM_RCC_DCKCFGR_CKDFSDM2ASEL 14 +#define STM_RCC_DCKCFGR_PLLDIVR 8 +#define STM_RCC_DCKCFGR_PLLI2SDIVR 0 + +#define STM_RCC_DCKCFGR2_LPTIMER1SEL 30 +#define STM_RCC_DCKCFGR2_LPTIMER1SEL_APB 0 +#define STM_RCC_DCKCFGR2_LPTIMER1SEL_HSI 1 +#define STM_RCC_DCKCFGR2_LPTIMER1SEL_LSI 2 +#define STM_RCC_DCKCFGR2_LPTIMER1SEL_LSE 3 +#define STM_RCC_DCKCFGR2_SDIOSEL 28 +#define STM_RCC_DCKCFGR2_SDIOSEL_CK_48MHZ 0 +#define STM_RCC_DCKCFGR2_SDIOSEL_SYSTEM_CLOCK 1 +#define STM_RCC_DCKCFGR2_CK48MSEL 27 +#define STM_RCC_DCKCFGR2_CK48MSEL_PLL_Q 1 +#define STM_RCC_DCKCFGR2_CK48MSEL_PLLI2S_Q 1 +#define STM_RCC_DCKCFGR2_I2CFMP1SEL 22 +#define STM_RCC_DCKCFGR2_I2CFMP1SEL_APB 0 +#define STM_RCC_DCKCFGR2_I2CFMP1SEL_SYSTEM_CLOCK 1 +#define STM_RCC_DCKCFGR2_I2CFMP1SEL_HSI 2 +#define STM_RCC_DCKCFGR2_I2CFMP1SEL_APB_ALSO 3 + struct stm_ictr { vuint32_t ictr; }; @@ -478,11 +510,53 @@ isr(dfsdm2_flt3); #define STM_ISR_CAN1_RX1_POS 21 #define STM_ISR_CAN1_SCE_POS 22 #define STM_ISR_EXTI9_5_POS 23 +#define STM_ISR_TIM1_BRK_TIM9_POS 24 +#define STM_ISR_TIM1_UP_TIM10_POS 25 +#define STM_ISR_TIM_TRG_COM_TIM11_POS 26 +#define STM_ISR_TIM1_CC_POS 27 +#define STM_ISR_TIM2_POS 28 +#define STM_ISR_TIM3_POS 29 +#define STM_ISR_TIM4_POS 30 +#define STM_ISR_I2C1_EVT_POS 31 +#define STM_ISR_I2C1_ERR_POS 32 +#define STM_ISR_I2C2_EVT_POS 33 +#define STM_ISR_I2C2_ERR_POS 34 +#define STM_ISR_SPI1_POS 35 +#define STM_ISR_SPI2_POS 36 #define STM_ISR_USART1_POS 37 #define STM_ISR_USART2_POS 38 #define STM_ISR_USART3_POS 39 +#define STM_ISR_EXTI15_10_POS 40 +#define STM_ISR_EXTI17_RTC_ALARM_POS 41 +#define STM_ISR_EXTI18_OTG_FS_WKUP_POS 42 +#define STM_ISR_TIM2_BRK_TIM12_POS 43 +#define STM_ISR_TIM8_UP_TIM13_POS 44 +#define STM_ISR_TIM8_TRG_COM_TIM14_POS 45 +#define STM_ISR_TIM8_CC_POS 46 +#define STM_ISR_DMA1_STREAM7_POS 47 +#define STM_ISR_FSMC_POS 48 +#define STM_ISR_SDIO_POS 49 +#define STM_ISR_TIM5_POS 50 +#define STM_ISR_SPI3_POS 41 #define STM_ISR_UART4_POS 52 #define STM_ISR_UART5_POS 53 +#define STM_ISR_TIM6_GLB_IT_DAC1_DAC2_POS 54 +#define STM_ISR_TIM7_POS 55 +#define STM_ISR_DMA2_STREAM0_POS 56 +#define STM_ISR_DMA2_STREAM1_POS 57 +#define STM_ISR_DMA2_STREAM2_POS 58 +#define STM_ISR_DMA2_STREAM3_POS 59 +#define STM_ISR_DMA2_STREAM4_POS 60 +#define STM_ISR_DFSDM1_FLT0_POS 61 +#define STM_ISR_DFSDM1_FLT1_POS 62 +#define STM_ISR_CAN2_TX_POS 63 +#define STM_ISR_CAN2_RX0_POS 64 +#define STM_ISR_CAN2_RX1_POS 65 +#define STM_ISR_CAN2_SCE_POS 66 +#define STM_ISR_OTG_FS_POS 67 +#define STM_ISR_DMA2_STREAM5_POS 68 +#define STM_ISR_DMA2_STREAM6_POS 69 +#define STM_ISR_DMA2_STREAM7_POS 70 #define STM_ISR_USART6_POS 71 #define STM_ISR_UART7_POS 82 #define STM_ISR_UART9_POS 88 @@ -930,6 +1004,441 @@ extern struct stm_usart stm_usart6; #define STM_USART_CR3_IREN (1) /* IrDA mode enable */ #define STM_USART_CR3_EIE (0) /* Error interrupt enable */ +/* USB */ +struct stm_usb { + vuint32_t gotgctl; + vuint32_t gotgint; + vuint32_t gahbcfg; + vuint32_t gusbcfg; + + vuint32_t grstctl; + vuint32_t gintsts; + vuint32_t gintmsk; + vuint32_t grxstsr; + + vuint32_t grxstsp; + vuint32_t grxfsiz; + vuint32_t dieptxf0; + vuint32_t hnptxsts; + + vuint32_t pad_30; + vuint32_t pad_34; + vuint32_t gccfg; + vuint32_t cid; + + vuint32_t pad_40; + vuint32_t pad_44; + vuint32_t pad_48; + vuint32_t ghwcfg3; /* not in docs? */ + + vuint32_t pad_50; + vuint32_t glpmcfg; + vuint32_t pad_58; + vuint32_t gdfifocfg; /* not in docs? */ + + uint8_t pad_60[0x100 - 0x60]; + + vuint32_t hptxfsiz; /* 0x100 */ + vuint32_t dieptxf[0xf]; /* 0x104 5 in docs? */ + + uint8_t pad_140[0x400 - 0x140]; + + vuint32_t hcfg; + vuint32_t hfir; + vuint32_t hfnum; + vuint32_t pad_40c; + + vuint32_t hptxsts; + vuint32_t haint; + vuint32_t haintmsk; + vuint32_t pad_41c; + + uint8_t pad_420[0x440-0x420]; + + vuint32_t hprt; + + uint8_t pad_444[0x500 - 0x444]; + + vuint32_t hcchar0; + vuint32_t pad_504; + vuint32_t hcint0; + vuint32_t hcintmsk0; + + vuint32_t hctsiz0; + vuint32_t pad_514; + vuint32_t pad_518; + vuint32_t pad_51c; + + struct { + vuint32_t hcchar; + vuint32_t pad_4; + vuint32_t hcint; + vuint32_t hcintmsk; + + vuint32_t hctsiz; + vuint32_t pad_14; + vuint32_t pad_18; + vuint32_t pad_1c; + } h[11]; + + uint8_t pad_680[0x800 - 0x680]; + + vuint32_t dcfg; + vuint32_t dctl; + vuint32_t dsts; + vuint32_t pad_80c; + + vuint32_t diepmsk; + vuint32_t doepmsk; + vuint32_t daint; + vuint32_t daintmsk; + + vuint32_t pad_820; + vuint32_t pad_824; + vuint32_t dvbusdis; + vuint32_t dvbuspulse; + + vuint32_t pad_830; + vuint32_t diepempmsk; + + uint8_t pad_838[0x900 - 0x838]; + + struct { + vuint32_t diepctl; + vuint32_t pad_04; + vuint32_t diepint; + vuint32_t pad_0c; + + vuint32_t dieptsiz; + vuint32_t pad_14; + vuint32_t dtxfsts; + vuint32_t pad_1c; + } diep[6]; + + uint8_t pad_9c0[0xb00 - 0x9c0]; + + struct { + vuint32_t doepctl; + vuint32_t pad_04; + vuint32_t doepint; + vuint32_t pad_0c; + + vuint32_t doeptsiz; + vuint32_t pad_14; + vuint32_t pad_18; + vuint32_t pad_1c; + } doep[6]; + + uint8_t pad_bc0[0xe00 - 0xbc0]; + + vuint32_t pcgcctl; + + uint8_t pad_e04[0x1000 - 0xe04]; + + struct { + vuint32_t fifo; + uint8_t pad_004[0x1000 - 0x004]; + } dfifo[6]; +}; + +extern struct stm_usb stm_usb; + +#define stm_usb (*((struct stm_usb *) 0x50000000)) + +#define STM_USB_GOTGCTL_CURMOD 21 +#define STM_USB_GOTGCTL_OTGVER 20 +#define STM_USB_GOTGCTL_BSVLD 19 +#define STM_USB_GOTGCTL_ASVLD 18 +#define STM_USB_GOTGCTL_DBCT 17 +#define STM_USB_GOTGCTL_CIDSTS 16 +#define STM_USB_GOTGCTL_EHEN 12 +#define STM_USB_GOTGCTL_DHNPEN 11 +#define STM_USB_GOTGCTL_HSHNPEN 10 +#define STM_USB_GOTGCTL_HNPRQ 9 +#define STM_USB_GOTGCTL_HNGSCS 8 +#define STM_USB_GOTGCTL_BVALOVAL 7 +#define STM_USB_GOTGCTL_BVALOEN 6 +#define STM_USB_GOTGCTL_AVALOVAL 5 +#define STM_USB_GOTGCTL_AVALOEN 4 +#define STM_USB_GOTGCTL_VBVALOVAL 3 +#define STM_USB_GOTGCTL_VBVALOEN 2 +#define STM_USB_GOTGCTL_SRQ 1 +#define STM_USB_GOTGCTL_SRQSCS 0 + +#define STM_USB_GOTGINT_IDCHNG 20 +#define STM_USB_GOTGINT_DBCDNE 19 +#define STM_USB_GOTGINT_ADTOCHG 18 +#define STM_USB_GOTGINT_HNGDET 17 +#define STM_USB_GOTGINT_HNSSCHG 9 +#define STM_USB_GOTGINT_SRSSCHG 8 +#define STM_USB_GOTGINT_SEDET 2 + +#define STM_USB_GAHBCFG_PTXFELVL 8 +#define STM_USB_GAHBCFG_TXFELVL 7 +#define STM_USB_GAHBCFG_GINTMSK 0 + +#define STM_USB_GUSBCFG_FDMOD 30 +#define STM_USB_GUSBCFG_FHMOD 29 +#define STM_USB_GUSBCFG_TRDT 10 +#define STM_USB_GUSBCFG_TRDT_MASK 0xf +#define STM_USB_GUSBCFG_HNPCAP 9 +#define STM_USB_GUSBCFG_SRPCAP 8 +#define STM_USB_GUSBCFG_PHYSEL 6 +#define STM_USB_GUSBCFG_TOCAL 0 +#define STM_USB_GUSBCFG_TOCAL_MASK 0x7 + +#define STM_USB_GRSTCTL_AHBIDL 31 +#define STM_USB_GRSTCTL_TXFNUM 6 +#define STM_USB_GRSTCTL_TXFNUM_ALL 0x10 +#define STM_USB_GRSTCTL_TXFNUM_MASK 0x1f +#define STM_USB_GRSTCTL_TXFFLSH 5 +#define STM_USB_GRSTCTL_RXFFLSH 4 +#define STM_USB_GRSTCTL_FCRST 2 +#define STM_USB_GRSTCTL_PSRST 1 +#define STM_USB_GRSTCTL_CSRST 0 + +#define STM_USB_GINTSTS_WKUPINT 31 +#define STM_USB_GINTSTS_SRQINT 30 +#define STM_USB_GINTSTS_DISCINT 29 +#define STM_USB_GINTSTS_CIDSCHG 28 +#define STM_USB_GINTSTS_LPMINT 27 +#define STM_USB_GINTSTS_PTXFE 26 +#define STM_USB_GINTSTS_HCINT 25 +#define STM_USB_GINTSTS_HPRTINT 24 +#define STM_USB_GINTSTS_RSTDET 23 +#define STM_USB_GINTSTS_IPXFER 21 +#define STM_USB_GINTSTS_IISOIXFR 20 +#define STM_USB_GINTSTS_OEPINT 19 +#define STM_USB_GINTSTS_IEPINT 18 +#define STM_USB_GINTSTS_EOPF 15 +#define STM_USB_GINTSTS_ISOODRP 14 +#define STM_USB_GINTSTS_ENUMDNE 13 +#define STM_USB_GINTSTS_USBRST 12 +#define STM_USB_GINTSTS_USBSUSP 11 +#define STM_USB_GINTSTS_ESUSP 10 +#define STM_USB_GINTSTS_GONAKEFF 7 +#define STM_USB_GINTSTS_GINAKEFF 6 +#define STM_USB_GINTSTS_NPTXFE 5 +#define STM_USB_GINTSTS_RXFLVL 4 +#define STM_USB_GINTSTS_SOF 3 +#define STM_USB_GINTSTS_OTGINT 2 +#define STM_USB_GINTSTS_MMIS 1 +#define STM_USB_GINTSTS_CMOD 0 + +#define STM_USB_GINTMSK_WUIM 31 +#define STM_USB_GINTMSK_SRQIM 30 +#define STM_USB_GINTMSK_DISCINT 29 +#define STM_USB_GINTMSK_CIDSCHGM 28 +#define STM_USB_GINTMSK_LPMINTM 27 +#define STM_USB_GINTMSK_PTXFEM 26 +#define STM_USB_GINTMSK_HCIM 25 +#define STM_USB_GINTMSK_PRTIM 24 +#define STM_USB_GINTMSK_RSTDETM 23 +#define STM_USB_GINTMSK_IPXFERM 21 /* host mode */ +#define STM_USB_GINTMSK_IISOOXFRM 21 /* device mode */ +#define STM_USB_GINTMSK_IISOIXFRM 20 +#define STM_USB_GINTMSK_OEPINT 19 +#define STM_USB_GINTMSK_IEPINT 18 +#define STM_USB_GINTMSK_EOPFM 15 +#define STM_USB_GINTMSK_ISOODRPM 14 +#define STM_USB_GINTMSK_ENUMDNEM 13 +#define STM_USB_GINTMSK_USBRST 12 +#define STM_USB_GINTMSK_USBSUSPM 11 +#define STM_USB_GINTMSK_ESUSPM 10 +#define STM_USB_GINTMSK_GONAKEFFM 7 +#define STM_USB_GINTMSK_GINAKEFFM 6 +#define STM_USB_GINTMSK_NPTXFEM 5 +#define STM_USB_GINTMSK_RXFLVLM 4 +#define STM_USB_GINTMSK_SOFM 3 +#define STM_USB_GINTMSK_OTGINT 2 +#define STM_USB_GINTMSK_MMISM 1 + +#define STM_USB_GRXSTSP_STSPHST 27 +#define STM_USB_GRXSTSP_FRMNUM 21 +#define STM_USB_GRXSTSP_FRMNUM_MASK 0xf +#define STM_USB_GRXSTSP_PKTSTS 17 +#define STM_USB_GRXSTSP_PKTSTS_NAK 1 +#define STM_USB_GRXSTSP_PKTSTS_OUT_DATA 2 +#define STM_USB_GRXSTSP_PKTSTS_OUT_COMPLETE 3 +#define STM_USB_GRXSTSP_PKTSTS_SETUP_COMPLETE 4 +#define STM_USB_GRXSTSP_PKTSTS_SETUP_DATA 5 +#define STM_USB_GRXSTSP_PKTSTS_MASK 0xf +#define STM_USB_GRXSTSP_DPID 15 +#define STM_USB_GRXSTSP_DPID_MASK 3 +#define STM_USB_GRXSTSP_BCNT 4 +#define STM_USB_GRXSTSP_BCNT 4 +#define STM_USB_GRXSTSP_BCNT_MASK 0x3ff +#define STM_USB_GRXSTSP_EPNUM 0 +#define STM_USB_GRXSTSP_EPNUM_MASK 0xf + +#define STM_USB_GRXFSIZ_RXFD 0 +#define STM_USB_GRXFSIZ_RXFD_MASK 0xffff + +#define STM_USB_GCCFG_VBDEN 21 +#define STM_USB_GCCFG_SDEN 20 +#define STM_USB_GCCFG_PDEN 19 +#define STM_USB_GCCFG_DCDEN 18 +#define STM_USB_GCCFG_BCDEN 17 +#define STM_USB_GCCFG_PWRDWN 16 +#define STM_USB_GCCFG_PS2DET 3 +#define STM_USB_GCCFG_SDET 2 +#define STM_USB_GCCFG_PDET 1 +#define STM_USB_GCCFG_DCDET 0 + +#define STM_USB_DIEPTXF0_TX0FD 16 +#define STM_USB_DIEPTXF0_TX0FSA 0 + +#define STM_USB_DCFG_ERRATIM 15 +#define STM_USB_DCFG_PFIVL 11 +#define STM_USB_DCFG_PFIVL_80 0 +#define STM_USB_DCFG_PFIVL_85 1 +#define STM_USB_DCFG_PFIVL_90 2 +#define STM_USB_DCFG_PFIVL_95 3 +#define STM_USB_DCFG_PFIVL_MASK 3 +#define STM_USB_DCFG_DAD 4 +#define STM_USB_DCFG_DAD_MASK 0x7f +#define STM_USB_DCFG_NZLSOHSK 2 +#define STM_USB_DCFG_DSPD 0 +#define STM_USB_DCFG_DSPD_FULL_SPEED 3 +#define STM_USB_DCFG_DSPD_MASK 3 +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ +#define STM_USB_DCFG_ + +#define STM_USB_DCTL_DSBESLRJCT 18 +#define STM_USB_DCTL_POPRGDNE 11 +#define STM_USB_DCTL_CGONAK 10 +#define STM_USB_DCTL_SGONAK 9 +#define STM_USB_DCTL_CGINAK 8 +#define STM_USB_DCTL_SGINAK 7 +#define STM_USB_DCTL_TCTL 4 +#define STM_USB_DCTL_GONSTS 3 +#define STM_USB_DCTL_GINSTS 2 +#define STM_USB_DCTL_SDIS 1 +#define STM_USB_DCTL_RWUSIG 0 + +#define STM_USB_DSTS_DEVLNSTS 22 +#define STM_USB_DSTS_DEVLNSTS_MASK 0x3 +#define STM_USB_DSTS_FNSOF 8 +#define STM_USB_DSTS_FNSOF_MASK 0x3fff +#define STM_USB_DSTS_EERR 3 +#define STM_USB_DSTS_ENUMSPD 1 +#define STM_USB_DSTS_ENUMSPD_MASK 3 +#define STM_USB_DSTS_SUSPSTS 0 + +#define STM_USB_DIEPMSK_NAKM 13 +#define STM_USB_DIEPMSK_TXFURM 8 +#define STM_USB_DIEPMSK_INEPNEM 6 +#define STM_USB_DIEPMSK_INEPNMM 5 +#define STM_USB_DIEPMSK_ITTXFEMSK 4 +#define STM_USB_DIEPMSK_TOM 3 +#define STM_USB_DIEPMSK_EPDM 1 +#define STM_USB_DIEPMSK_XFRCM 0 + +#define STM_USB_DOEPMSK_NYETMSK 14 +#define STM_USB_DOEPMSK_NAKMSK 13 +#define STM_USB_DOEPMSK_BERRM 12 +#define STM_USB_DOEPMSK_OUTPKTERRM 8 +#define STM_USB_DOEPMSK_STSPHSRXM 5 +#define STM_USB_DOEPMSK_OTEPDM 4 +#define STM_USB_DOEPMSK_STUPM 3 +#define STM_USB_DOEPMSK_EPDM 1 +#define STM_USB_DOEPMSK_XFRCM 0 + +#define STM_USB_DAINT_OEPINT 16 +#define STM_USB_DAINT_OEPINT_MASK 0xffff +#define STM_USB_DAINT_IEPINT 16 +#define STM_USB_DAINT_IEPINT_MASK 0xffff + +#define STM_USB_DAINTMSK_OEPM 16 +#define STM_USB_DAINTMSK_OEPM_MASK 0xffff +#define STM_USB_DAINTMSK_IEPM 0 +#define STM_USB_DAINTMSK_IEPM_MASK 0xffff + +#define STM_USB_DIEPCTL_EPENA 31 +#define STM_USB_DIEPCTL_EPDIS 30 +#define STM_USB_DIEPCTL_SNAK 27 +#define STM_USB_DIEPCTL_CNAK 26 +#define STM_USB_DIEPCTL_TXFNUM 22 +#define STM_USB_DIEPCTL_TXFNUM_MASK 0xf +#define STM_USB_DIEPCTL_STALL 21 +#define STM_USB_DIEPCTL_EPTYP 18 +#define STM_USB_DIEPCTL_EPTYP_CONTROL 0 +#define STM_USB_DIEPCTL_EPTYP_ISOCHRONOUS 1 +#define STM_USB_DIEPCTL_EPTYP_BULK 2 +#define STM_USB_DIEPCTL_EPTYP_INTERRUPT 3 +#define STM_USB_DIEPCTL_EPTYP_MASK 3 +#define STM_USB_DIEPCTL_NAKSTS 17 +#define STM_USB_DIEPCTL_EONUM 16 +#define STM_USB_DIEPCTL_USBAEP 15 +#define STM_USB_DIEPCTL_MPSIZ 0 +#define STM_USB_DIEPCTL_MPSIZ0_64 0 +#define STM_USB_DIEPCTL_MPSIZ0_32 1 +#define STM_USB_DIEPCTL_MPSIZ0_16 2 +#define STM_USB_DIEPCTL_MPSIZ0_8 3 +#define STM_USB_DIEPCTL_MPSIZ0_MASK 3 +#define STM_USB_DIEPCTL_MPSIZ_MASK 0x7f + +#define STM_USB_DIEPINT_NAK 13 +#define STM_USB_DIEPINT_PKTDRPSTS 11 +#define STM_USB_DIEPINT_TXFIFOUDRN 8 +#define STM_USB_DIEPINT_TXFE 7 +#define STM_USB_DIEPINT_INEPNE 6 +#define STM_USB_DIEPINT_INEPNM 5 +#define STM_USB_DIEPINT_ITTXFE 4 +#define STM_USB_DIEPINT_TOC 3 +#define STM_USB_DIEPINT_EPDISD 1 +#define STM_USB_DIEPINT_XFRC 0 + +#define STM_USB_DIEPTSIZ_MCNT 29 +#define STM_USB_DIEPTSIZ_MCNT_MASK 3 +#define STM_USB_DIEPTSIZ_PKTCNT 19 +#define STM_USB_DIEPTSIZ_PKTCNT0_MASK 3 +#define STM_USB_DIEPTSIZ_PKTCNT_MASK 0x3ff +#define STM_USB_DIEPTSIZ_XFRSIZ 0 +#define STM_USB_DIEPTSIZ_XFRSIZ0_MASK 0x7f +#define STM_USB_DIEPTSIZ_XFRSIZ_MASK 0x7ffff + +#define STM_USB_DOEPCTL_EPENA 31 +#define STM_USB_DOEPCTL_EPDIS 30 +#define STM_USB_DOEPCTL_SNAK 27 +#define STM_USB_DOEPCTL_CNAK 26 +#define STM_USB_DOEPCTL_STALL 21 +#define STM_USB_DOEPCTL_SNPM 20 +#define STM_USB_DOEPCTL_EPTYP 18 +#define STM_USB_DOEPCTL_EPTYP_CONTROL 0 +#define STM_USB_DOEPCTL_EPTYP_ISOCHRONOUS 1 +#define STM_USB_DOEPCTL_EPTYP_BULK 2 +#define STM_USB_DOEPCTL_EPTYP_INTERRUPT 3 +#define STM_USB_DOEPCTL_EPTYP_MASK 3 +#define STM_USB_DOEPCTL_NAKSTS 17 +#define STM_USB_DOEPCTL_USBAEP 15 +#define STM_USB_DOEPCTL_MPSIZ 0 +#define STM_USB_DOEPCTL_MPSIZ0_64 0 +#define STM_USB_DOEPCTL_MPSIZ0_32 1 +#define STM_USB_DOEPCTL_MPSIZ0_16 2 +#define STM_USB_DOEPCTL_MPSIZ0_8 3 +#define STM_USB_DOEPCTL_MPSIZ0_MASK 3 + +#define STM_USB_DOEPINT_NAK 13 +#define STM_USB_DOEPINT_BERR 12 +#define STM_USB_DOEPINT_OUTPKTERR 8 +#define STM_USB_DOEPINT_STSPHSRX 5 +#define STM_USB_DOEPINT_OTEPDIS 4 +#define STM_USB_DOEPINT_STUP 3 +#define STM_USB_DOEPINT_EPDISD 1 +#define STM_USB_DOEPINT_XFRC 0 + +#define STM_USB_DOEPTSIZ_STUPCNT 29 +#define STM_USB_DOEPTSIZ_STUPCNT_MASK 3 +#define STM_USB_DOEPTSIZ_PKTCNT 19 +#define STM_USB_DOEPTSIZ_XFRSIZ 0 +#define STM_USB_DOEPTSIZ_XFRSIZ_MASK 0x7f + /* Errata 2.1.5 Delay after an RCC peripheral clock enabling -- cgit v1.2.3