blinkenlights working w sonar

memlib
Ondřej Hruška 8 years ago
parent 11764cbd7a
commit d01e40e174
  1. 5
      Makefile
  2. 200
      f103.pro
  3. 223
      f103.pro.user
  4. 157
      openocd.cfg
  5. 21
      parsemap.php
  6. 159
      project/bus/event_handler.c
  7. 48
      project/bus/event_handler.h
  8. 66
      project/bus/event_queue.c
  9. 75
      project/bus/event_queue.h
  10. 66
      project/colorled.c
  11. 79
      project/colorled.h
  12. 96
      project/com/com_fileio.c
  13. 23
      project/com/com_fileio.h
  14. 179
      project/com/com_iface.c
  15. 168
      project/com/com_iface.h
  16. 48
      project/com/datalink.c
  17. 26
      project/com/datalink.h
  18. 108
      project/com/debug.c
  19. 73
      project/com/debug.h
  20. 91
      project/com/iface_noop.c
  21. 14
      project/com/iface_noop.h
  22. 328
      project/com/iface_usart.c
  23. 19
      project/com/iface_usart.h
  24. 94
      project/display.c
  25. 11
      project/display.h
  26. 125
      project/hw_init.c
  27. 6
      project/hw_init.h
  28. 70
      project/main.c
  29. 18
      project/main.h
  30. 40
      project/malloc_safe.c
  31. 17
      project/malloc_safe.h
  32. 24
      project/spl_assert.c
  33. 2
      project/stm32f10x_it.c
  34. 32
      project/syscalls.c
  35. 1429
      project/system_stm32f10x.c
  36. 161
      project/utils/circbuf.c
  37. 93
      project/utils/circbuf.h
  38. 171
      project/utils/debounce.c
  39. 62
      project/utils/debounce.h
  40. 33
      project/utils/matcher.c
  41. 39
      project/utils/matcher.h
  42. 70
      project/utils/meanbuf.c
  43. 33
      project/utils/meanbuf.h
  44. 4
      project/utils/minmax.h
  45. 286
      project/utils/str_utils.c
  46. 75
      project/utils/str_utils.h
  47. 331
      project/utils/timebase.c
  48. 159
      project/utils/timebase.h

@ -4,7 +4,7 @@ ARCH_FLAGS = -msoft-float -mfloat-abi=soft
ARCH_FLAGS += -mthumb -mcpu=cortex-m3
# Clock speed constants
DEFS += -DF_CPU=8000000UL
DEFS += -DF_CPU=72000000UL
DEFS += -DSTM32F10X_MD
DEFS += -DARM_MATH_CM3
@ -113,7 +113,7 @@ LIB_CFLAGS = -Wno-shadow -Wno-float-equal -Wno-inline -Wno-unused-parameter -W
###############################################################################
# Linker flags
LDFLAGS += --static -lm -lc -nostartfiles
LDFLAGS += --static -lm -lc -nostartfiles -specs=nano.specs
LDFLAGS += -Llib
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -Wl,-Map=$(*).map
@ -181,6 +181,7 @@ size: $(BINARY).elf
%.elf %.map: libcheck $(OBJS) $(HEADERS)
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(*).elf
$(Q)./parsemap.php
$(Q)$(SIZE) $(*).elf
%.o: %.c

@ -11,7 +11,7 @@ INCLUDEPATH += \
/usr/arm-none-eabi/include \
/usr/lib/gcc/arm-none-eabi/5.3.0/include/
DEFINES += F_CPU=8000000UL \
DEFINES += F_CPU=72000000UL \
STM32F10X_MD \
USE_STDPERIPH_DRIVER \
__null=0 \
@ -21,87 +21,127 @@ DEFINES += F_CPU=8000000UL \
__CORTEX_M=3 \
VERBOSE_LOGGING=1
HEADERS += \
lib/cmsis/core_cm3.h \
lib/cmsis/stm32f10x.h \
lib/sbmp/library/crc32.h \
lib/sbmp/library/payload_builder.h \
lib/sbmp/library/payload_parser.h \
lib/sbmp/library/sbmp.h \
lib/sbmp/library/sbmp_bulk.h \
lib/sbmp/library/sbmp_checksum.h \
lib/sbmp/library/sbmp_config.example.h \
lib/sbmp/library/sbmp_datagram.h \
lib/sbmp/library/sbmp_frame.h \
lib/sbmp/library/sbmp_session.h \
lib/sbmp/library/type_coerce.h \
lib/spl/inc/misc.h \
lib/spl/inc/stm32f10x_adc.h \
lib/spl/inc/stm32f10x_bkp.h \
lib/spl/inc/stm32f10x_can.h \
lib/spl/inc/stm32f10x_cec.h \
lib/spl/inc/stm32f10x_crc.h \
lib/spl/inc/stm32f10x_dac.h \
lib/spl/inc/stm32f10x_dbgmcu.h \
lib/spl/inc/stm32f10x_dma.h \
lib/spl/inc/stm32f10x_exti.h \
lib/spl/inc/stm32f10x_flash.h \
lib/spl/inc/stm32f10x_fsmc.h \
lib/spl/inc/stm32f10x_gpio.h \
lib/spl/inc/stm32f10x_i2c.h \
lib/spl/inc/stm32f10x_iwdg.h \
lib/spl/inc/stm32f10x_pwr.h \
lib/spl/inc/stm32f10x_rcc.h \
lib/spl/inc/stm32f10x_rtc.h \
lib/spl/inc/stm32f10x_sdio.h \
lib/spl/inc/stm32f10x_spi.h \
lib/spl/inc/stm32f10x_tim.h \
lib/spl/inc/stm32f10x_usart.h \
lib/spl/inc/stm32f10x_wwdg.h \
project/stm32f10x_conf.h \
project/stm32f10x_it.h \
project/system_stm32f10x.h \
project/sbmp_config.h
HEADERS += \
lib/cmsis/core_cm3.h \
lib/cmsis/stm32f10x.h \
lib/sbmp/library/crc32.h \
lib/sbmp/library/payload_builder.h \
lib/sbmp/library/payload_parser.h \
lib/sbmp/library/sbmp.h \
lib/sbmp/library/sbmp_bulk.h \
lib/sbmp/library/sbmp_checksum.h \
lib/sbmp/library/sbmp_config.example.h \
lib/sbmp/library/sbmp_datagram.h \
lib/sbmp/library/sbmp_frame.h \
lib/sbmp/library/sbmp_session.h \
lib/sbmp/library/type_coerce.h \
lib/spl/inc/misc.h \
lib/spl/inc/stm32f10x_adc.h \
lib/spl/inc/stm32f10x_bkp.h \
lib/spl/inc/stm32f10x_can.h \
lib/spl/inc/stm32f10x_cec.h \
lib/spl/inc/stm32f10x_crc.h \
lib/spl/inc/stm32f10x_dac.h \
lib/spl/inc/stm32f10x_dbgmcu.h \
lib/spl/inc/stm32f10x_dma.h \
lib/spl/inc/stm32f10x_exti.h \
lib/spl/inc/stm32f10x_flash.h \
lib/spl/inc/stm32f10x_fsmc.h \
lib/spl/inc/stm32f10x_gpio.h \
lib/spl/inc/stm32f10x_i2c.h \
lib/spl/inc/stm32f10x_iwdg.h \
lib/spl/inc/stm32f10x_pwr.h \
lib/spl/inc/stm32f10x_rcc.h \
lib/spl/inc/stm32f10x_rtc.h \
lib/spl/inc/stm32f10x_sdio.h \
lib/spl/inc/stm32f10x_spi.h \
lib/spl/inc/stm32f10x_tim.h \
lib/spl/inc/stm32f10x_usart.h \
lib/spl/inc/stm32f10x_wwdg.h \
project/stm32f10x_conf.h \
project/stm32f10x_it.h \
project/system_stm32f10x.h \
project/sbmp_config.h \
project/com/com_fileio.h \
project/com/com_iface.h \
project/com/datalink.h \
project/com/debug.h \
project/com/iface_noop.h \
project/com/iface_usart.h \
project/utils/circbuf.h \
project/utils/minmax.h \
project/utils/timebase.h \
project/colorled.h \
project/malloc_safe.h \
project/hw_init.h \
project/utils/debounce.h \
project/bus/event_handler.h \
project/bus/event_queue.h \
project/utils/str_utils.h \
project/main.h \
project/utils/matcher.h \
project/utils/meanbuf.h \
project/display.h
SOURCES += \
lib/cmsis/core_cm3.c \
lib/sbmp/library/crc32.c \
lib/sbmp/library/payload_builder.c \
lib/sbmp/library/payload_parser.c \
lib/sbmp/library/sbmp_bulk.c \
lib/sbmp/library/sbmp_checksum.c \
lib/sbmp/library/sbmp_datagram.c \
lib/sbmp/library/sbmp_frame.c \
lib/sbmp/library/sbmp_session.c \
lib/spl/src/misc.c \
lib/spl/src/stm32f10x_adc.c \
lib/spl/src/stm32f10x_bkp.c \
lib/spl/src/stm32f10x_can.c \
lib/spl/src/stm32f10x_cec.c \
lib/spl/src/stm32f10x_crc.c \
lib/spl/src/stm32f10x_dac.c \
lib/spl/src/stm32f10x_dbgmcu.c \
lib/spl/src/stm32f10x_dma.c \
lib/spl/src/stm32f10x_exti.c \
lib/spl/src/stm32f10x_flash.c \
lib/spl/src/stm32f10x_fsmc.c \
lib/spl/src/stm32f10x_gpio.c \
lib/spl/src/stm32f10x_i2c.c \
lib/spl/src/stm32f10x_iwdg.c \
lib/spl/src/stm32f10x_pwr.c \
lib/spl/src/stm32f10x_rcc.c \
lib/spl/src/stm32f10x_rtc.c \
lib/spl/src/stm32f10x_sdio.c \
lib/spl/src/stm32f10x_spi.c \
lib/spl/src/stm32f10x_tim.c \
lib/spl/src/stm32f10x_usart.c \
lib/spl/src/stm32f10x_wwdg.c \
project/main.c \
project/stm32f10x_it.c \
project/system_stm32f10x.c
SOURCES += \
lib/cmsis/core_cm3.c \
lib/sbmp/library/crc32.c \
lib/sbmp/library/payload_builder.c \
lib/sbmp/library/payload_parser.c \
lib/sbmp/library/sbmp_bulk.c \
lib/sbmp/library/sbmp_checksum.c \
lib/sbmp/library/sbmp_datagram.c \
lib/sbmp/library/sbmp_frame.c \
lib/sbmp/library/sbmp_session.c \
lib/spl/src/misc.c \
lib/spl/src/stm32f10x_adc.c \
lib/spl/src/stm32f10x_bkp.c \
lib/spl/src/stm32f10x_can.c \
lib/spl/src/stm32f10x_cec.c \
lib/spl/src/stm32f10x_crc.c \
lib/spl/src/stm32f10x_dac.c \
lib/spl/src/stm32f10x_dbgmcu.c \
lib/spl/src/stm32f10x_dma.c \
lib/spl/src/stm32f10x_exti.c \
lib/spl/src/stm32f10x_flash.c \
lib/spl/src/stm32f10x_fsmc.c \
lib/spl/src/stm32f10x_gpio.c \
lib/spl/src/stm32f10x_i2c.c \
lib/spl/src/stm32f10x_iwdg.c \
lib/spl/src/stm32f10x_pwr.c \
lib/spl/src/stm32f10x_rcc.c \
lib/spl/src/stm32f10x_rtc.c \
lib/spl/src/stm32f10x_sdio.c \
lib/spl/src/stm32f10x_spi.c \
lib/spl/src/stm32f10x_tim.c \
lib/spl/src/stm32f10x_usart.c \
lib/spl/src/stm32f10x_wwdg.c \
project/main.c \
project/stm32f10x_it.c \
project/system_stm32f10x.c \
project/com/com_fileio.c \
project/com/com_iface.c \
project/com/datalink.c \
project/com/debug.c \
project/com/iface_noop.c \
project/com/iface_usart.c \
project/utils/circbuf.c \
project/utils/debounce.c \
project/utils/timebase.c \
project/colorled.c \
project/hw_init.c \
project/malloc_safe.c \
project/spl_assert.c \
project/syscalls.c \
project/bus/event_handler.c \
project/bus/event_queue.c \
project/utils/str_utils.c \
project/utils/matcher.c \
project/utils/meanbuf.c \
project/display.c
DISTFILES += \
style.astylerc \
Makefile \
lib/cmsis/startup_stm32f10x_md.s \
lib/cmsis/stm32_flash.ld
lib/cmsis/startup_stm32f10x_md.s \
lib/cmsis/stm32_flash.ld

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.1, 2016-05-11T19:11:14. -->
<!-- Written by QtCreator 3.6.1, 2016-05-11T22:50:05. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -53,7 +53,12 @@
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="ClangProjectSettings">
<value type="QString" key="CustomPchFile"></value>
<value type="int" key="PchUsage">1</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
@ -63,22 +68,11 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{15262c8f-05de-48ee-9452-3d289b21ba3e}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">-1</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/build-f103-STLINK-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/f103</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
@ -88,10 +82,10 @@
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">-B -j 4</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
@ -119,132 +113,12 @@
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Main</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/build-f103-STLINK-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/build-f103-STLINK-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">true</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
@ -288,11 +162,11 @@
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments">flash</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/usr/bin/make</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /usr/bin/make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">make flash</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
@ -340,13 +214,66 @@
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="QString" key="BareMetal.CustomRunConfig.Executable"></value>
<value type="QString" key="BareMetal.RunConfig.WorkingDirectory"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run on GDB server or hardware debugger</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">f103 (via GDB server or hardware debugger)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">BareMetal.CustomRunConfig</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">BareMetal/home/ondra/devel/f103/f103.pro</value>
<value type="QString" key="Qt4ProjectManager.MaemoRunConfiguration.Arguments"></value>
<value type="QString" key="Qt4ProjectManager.MaemoRunConfiguration.ProFile"></value>
<value type="QString" key="Qt4ProjectManager.MaemoRunConfiguration.ProFile">f103.pro</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.2">
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/home/ondra/devel/f103/main.elf</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">/home/ondra/devel/f103</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /home/ondra/devel/f103/main.elf</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
@ -354,7 +281,7 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">3</value>
</valuemap>
</data>
<data>

@ -0,0 +1,157 @@
#daemon configuration
telnet_port 4444
gdb_port 3333
#interface
#cat /usr/lib/openocd/interface/olimex-arm-usb-ocd.cfg >> openocd.cfg
#
# STMicroelectronics ST-LINK/V2 in-circuit debugger/programmer
#
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2"
hla_vid_pid 0x0483 0x3748
# Optionally specify the serial number of ST-LINK/V2 usb device. ST-LINK/V2
# devices seem to have serial numbers with unreadable characters. ST-LINK/V2
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues.
# eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"
# target configuration
# cat /usr/lib/openocd/target/stm32.cfg >> openocd.cfg
# script for stm32f3x family
#
# stm32 devices support both JTAG and SWD transports.
#
source [find target/swj-dp.tcl]
source [find mem_helper.tcl]
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME stm32f3x
}
set _ENDIAN little
# Work-area is a space in RAM used for flash programming
# By default use 16kB
if { [info exists WORKAREASIZE] } {
set _WORKAREASIZE $WORKAREASIZE
} else {
set _WORKAREASIZE 0x4000
}
# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
#
# Since we may be running of an RC oscilator, we crank down the speed a
# bit more to be on the safe side. Perhaps superstition, but if are
# running off a crystal, we can run closer to the limit. Note
# that there can be a pretty wide band where things are more or less stable.
adapter_khz 1000
adapter_nsrst_delay 100
if {[using_jtag]} {
jtag_ntrst_delay 100
}
#jtag scan chain
if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
if { [using_jtag] } {
# See STM Document RM0316
# Section 29.6.3 - corresponds to Cortex-M4 r0p1
set _CPUTAPID 0x4ba00477
} {
set _CPUTAPID 0x2ba01477
}
}
swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
if { [info exists BSTAPID] } {
set _BSTAPID $BSTAPID
} else {
# STM Document RM0316 rev 5 for STM32F302/303 B/C size
set _BSTAPID1 0x06422041
# STM Document RM0313 rev 3 for STM32F37x
set _BSTAPID2 0x06432041
# STM Document RM364 rev 1 for STM32F334
set _BSTAPID3 0x06438041
# STM Document RM316 rev 5 for STM32F303 6/8 size
# STM Document RM365 rev 3 for STM32F302 6/8 size
# STM Document RM366 rev 2 for STM32F301 6/8 size
set _BSTAPID4 0x06439041
# STM Document RM016 rev 5 for STM32F303 D/E size
set _BSTAPID5 0x06446041
}
if {[using_jtag]} {
swj_newdap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \
-expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \
-expected-id $_BSTAPID4 -expected-id $_BSTAPID5
}
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f1x 0 0 0 0 $_TARGETNAME
reset_config srst_nogate
if {![using_hla]} {
# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_m reset_config sysresetreq
}
proc stm32f3x_default_reset_start {} {
# Reset clock is HSI (8 MHz)
adapter_khz 1000
}
proc stm32f3x_default_examine_end {} {
# Enable debug during low power modes (uses more power)
mmw 0xe0042004 0x00000007 0 ;# DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
# Stop watchdog counters during halt
mww 0xe0042008 0x00001800 ;# DBGMCU_APB1_FZ = DBG_IWDG_STOP | DBG_WWDG_STOP
}
proc stm32f3x_default_reset_init {} {
# Configure PLL to boost clock to HSI x 8 (64 MHz)
mww 0x40021004 0x00380400 ;# RCC_CFGR = PLLMUL[3:1] | PPRE1[2]
mmw 0x40021000 0x01000000 0 ;# RCC_CR |= PLLON
mww 0x40022000 0x00000012 ;# FLASH_ACR = PRFTBE | LATENCY[1]
sleep 10 ;# Wait for PLL to lock
mmw 0x40021004 0x00000002 0 ;# RCC_CFGR |= SW[1]
# Boost JTAG frequency
adapter_khz 8000
}
# Default hooks
$_TARGETNAME configure -event examine-end { stm32f3x_default_examine_end }
$_TARGETNAME configure -event reset-start { stm32f3x_default_reset_start }
$_TARGETNAME configure -event reset-init { stm32f3x_default_reset_init }
$_TARGETNAME configure -event trace-config {
# Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
# change this value accordingly to configure trace pins
# assignment
mmw 0xe0042004 0x00000020 0
}

@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
$map = file_get_contents('main.map');
$at_flash = strpos($map, '.text 0x0000000008000000');
$at_ram = strpos($map, '.data 0x0000000020000000');
$at_dbg = strpos($map, '.memory_b1_text');
$discard = substr($map, 0, $at_flash);
$flash = substr($map, $at_flash, $at_ram - $at_flash);
$ram = substr($map, $at_ram, $at_dbg - $at_ram);
$flash = str_replace("lib/gcc/arm-none-eabi/5.3.0/../../../../", "", $flash);
file_put_contents("main.flash.map", $flash);
file_put_contents("main.ram.map", $ram);
//preg_match("/\*\(\.eh_frame\)\n\s*0x00000000(2[0-9a-f]+)\s*\. = ALIGN \(0x4\)/i", $ram, $m);
//echo "Free RAM: " . (0x20010000 - hexdec($m[1])) . " B\n";

@ -0,0 +1,159 @@
#include "event_handler.h"
#include "com/debug.h"
typedef struct {
uint32_t handler_id;
uint32_t chained_handler; // if not 0, that handler is removed together with this handler.
EventType type; // event type
EventHandlerCallback handler; // returns True if event was handled.
bool used; // this slot is currently used
void *user_data;
} EventHandlerSlot;
#define EH_SLOT_COUNT 6
static EventHandlerSlot eh_slots[EH_SLOT_COUNT];
static uint32_t next_slot_pid = 1; // 0 is reserved
/** Get a valid free PID for a new handler slot. */
static uint32_t make_pid(void)
{
uint32_t pid = next_slot_pid++;
// make sure no task is given PID 0
if (next_slot_pid == 0) {
next_slot_pid++;
}
return pid;
}
/**
* @brief Register an event handler for event type
* @param type : handled event type
* @param handler : the handler func
* @return handler ID. Can be used to remove the handler.
*/
uint32_t register_event_handler(EventType type, EventHandlerCallback handler, void *user_data)
{
for (int i = 0; i < EH_SLOT_COUNT; i++) {
if (eh_slots[i].used) continue;
// Free slot found
EventHandlerSlot *slot = &eh_slots[i];
slot->handler = handler;
slot->type = type;
slot->handler_id = make_pid();
slot->used = true;
slot->chained_handler = 0;
slot->user_data = user_data;
return slot->handler_id;
}
error("Failed to register event handler for type %d", type);
return 0; // fail
}
/** Chain for common destruction */
bool chain_event_handler(uint32_t from, uint32_t to, bool reci)
{
uint8_t cnt = 0;
for (int i = 0; i < EH_SLOT_COUNT; i++) {
EventHandlerSlot *slot = &eh_slots[i];
if (!slot->used) continue;
if (slot->handler_id == from) {
slot->chained_handler = to;
cnt++;
}
// link back in two-handler reciprocal link
if (reci && slot->handler_id == to) {
slot->chained_handler = from;
cnt++;
}
if (cnt == (reci ? 2 : 1)) {
return true;
}
}
return false;
}
/**
* @brief check if exists
*/
bool event_handler_exists(uint32_t handler_id)
{
for (int i = 0; i < EH_SLOT_COUNT; i++) {
EventHandlerSlot *slot = &eh_slots[i];
if (!slot->used) continue;
if (slot->handler_id == handler_id) {
return true;
}
}
return false;
}
/**
* @brief Remove event handler by handler ID
* @param handler_id : handler ID, obtained when registering or in the callback.
* @return number of removed handlers
*/
int remove_event_handler(uint32_t handler_id)
{
int cnt = 0;
while (handler_id != 0) { // outer loop because of chained handlers
bool suc = false;
for (int i = 0; i < EH_SLOT_COUNT; i++) {
if (!eh_slots[i].used) {
continue; // skip empty slot
}
// Free slot found
EventHandlerSlot *slot = &eh_slots[i];
if (slot->handler_id == handler_id) {
slot->used = false;
slot->user_data = NULL;
suc = true;
cnt++;
handler_id = slot->chained_handler; // continue with the chained handler.
break;
}
}
if (!suc) break;
}
return cnt;
}
/** Handle an event */
void run_event_handler(Event *evt)
{
bool handled = false;
for (int i = 0; i < EH_SLOT_COUNT; i++) {
EventHandlerSlot *slot = &eh_slots[i];
if (!slot->used) continue; // unused
if (slot->type != evt->type) continue; // wrong type
handled = slot->handler(slot->handler_id, evt, &slot->user_data);
if (handled) break;
}
if (!handled) {
warn("Unhandled event, type %d", evt->type);
}
}

@ -0,0 +1,48 @@
#pragma once
#include "main.h"
#include "event_queue.h"
typedef bool (*EventHandlerCallback) (uint32_t hdlr_id, Event *evt, void **user_data);
/**
* @brief Register an event handler for event type
* @param type : handled event type
* @param handler : the handler func
* @return handler ID. Can be used to remove the handler.
*/
uint32_t register_event_handler(EventType type, EventHandlerCallback handler, void *user_data);
/**
* @brief Remove event handler by handler ID
* @param handler_id : handler ID, obtained when registering or in the callback.
* @return number of removed handlers
*/
int remove_event_handler(uint32_t handler_id);
/**
* @brief Handle an event
* @param event : pointer to the event to handle
*/
void run_event_handler(Event *event);
/**
* @brief Check if hansler exists
* @param handler_id : handler
* @return exists
*/
bool event_handler_exists(uint32_t handler_id);
/**
* @brief Create a link between two handlers (one direction).
*
* If handler A is linked to handler B, and handler A is removed,
* both handlers will perish.
*
* Make a circle if you need to chain more than two handlers.
*
* @param from : handler A
* @param to : handler B
* @param reciprocal : link also from B to A
* @return
*/
bool chain_event_handler(uint32_t from, uint32_t to, bool reciprocal);

@ -0,0 +1,66 @@
#include "event_queue.h"
#include "com/debug.h"
/** Task queue */
static CircBuf *tq;
/** Event queue */
static CircBuf *eq;
void queues_init(size_t tq_size, size_t eq_size)
{
tq = cbuf_create(tq_size, sizeof(QueuedTask));
eq = cbuf_create(eq_size, sizeof(Event));
}
bool tq_post(void (*handler)(void*), void *arg)
{
QueuedTask task;
task.handler = handler;
task.arg = arg;
bool suc = cbuf_append(tq, &task);
if (!suc) error("TQ overflow");
return suc;
}
bool eq_post(const Event *event)
{
bool suc = cbuf_append(eq, event);
if (!suc) {
error("EQ overflow, evt %d", event->type);
}
return suc;
}
bool tq_poll_one(void)
{
QueuedTask task;
// serve all tasks
bool suc = cbuf_pop(tq, &task);
if (suc) {
task.handler(task.arg);
}
return suc;
}
void tq_poll(void)
{
// serve all tasks
while (tq_poll_one());
}
bool eq_take(Event *dest)
{
bool suc = cbuf_pop(eq, dest);
return suc;
}

@ -0,0 +1,75 @@
#pragma once
#include "main.h"
#include "utils/circbuf.h"
#define TASK_QUEUE_SIZE 64
#define EVENT_QUEUE_SIZE 64
/** Application events */
typedef enum {
EVENT_ONE // placeholder
} EventType;
/** Event Queue entry */
typedef struct {
EventType type;
void *data;
} Event;
typedef struct {
void (*handler)(void*);
void* arg;
} QueuedTask;
/**
* @brief Set up the task and event queues
* @param tq_size : number of slots in the task queue
* @param eq_size : number of slots in the event queue
*/
void queues_init(size_t tq_size, size_t eq_size);
/**
* @brief Post a task on the task queue, with arg.
*
* @see tq_post()
*
* @param handler : task function
* @param arg : argument for the handler
* @return success
*/
bool tq_post(void (*handler)(void *), void *arg);
/**
* @brief Post an event on the event queue
* @param event : pointer to an event to post; will be copied.
* @return success
*/
bool eq_post(const Event *event);
/**
* @brief Run all pending tasks on the task queue
*/
void tq_poll(void);
/**
* @brief Run one pending task on the task queue
* @return true if a task was run.
*/
bool tq_poll_one(void);
/**
* @brief Take one event off the event queue.
* @param dest : pointer to a destination event variable.
* @return success
*/
bool eq_take(Event *dest);

@ -0,0 +1,66 @@
#include "colorled.h"
#include "utils/timebase.h"
#define LONG_DELAY() for (volatile uint32_t __j = 4; __j > 0; __j--)
#define SHORT_DELAY() for (volatile uint32_t __j = 1; __j > 0; __j--)
static inline
__attribute__((always_inline))
void colorled_byte(uint8_t b)
{
for (register volatile uint8_t i = 0; i < 8; i++) {
COLORLED_GPIO->BSRR = COLORLED_PIN; // set pin high
// duty cycle determines bit value
if (b & 0x80) {
LONG_DELAY();
COLORLED_GPIO->BRR = COLORLED_PIN; // set pin low
SHORT_DELAY();
} else {
SHORT_DELAY();
COLORLED_GPIO->BRR = COLORLED_PIN; // set pin low
LONG_DELAY();
}
b <<= 1; // shift to next bit
}
}
/** Set one RGB LED color */
void colorled_set(uint32_t rgb)
{
__disable_irq(); // SysTick interrupt when sending data would break the timing
colorled_byte((rgb & 0x00FF00) >> 8);
colorled_byte((rgb & 0xFF0000) >> 16);
colorled_byte(rgb & 0x0000FF);
__enable_irq();
delay_us(50); // show
}
/** Set many RGBs */
void colorled_set_many(uint32_t *rgbs, int count)
{
__disable_irq();
for (int i = 0; i < count; i++) {
uint32_t rgb = *rgbs++;
colorled_byte((rgb & 0x00FF00) >> 8);
colorled_byte((rgb & 0xFF0000) >> 16);
colorled_byte(rgb & 0x0000FF);
}
__enable_irq();
delay_us(50); // show
}
void colorled_off(void)
{
colorled_set(RGB_BLACK);
}

@ -0,0 +1,79 @@
#pragma once
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
// PB8 - WS2812B data line
#define COLORLED_GPIO GPIOB
#define COLORLED_PIN GPIO_Pin_12
#define RGB_RED rgb(255, 0, 0)
#define RGB_ORANGE rgb(255, 110, 0)
#define RGB_YELLOW rgb(255, 255, 0)
#define RGB_LIME rgb(160, 255, 0)
#define RGB_GREEN rgb( 0, 255, 0)
#define RGB_CYAN rgb( 0, 255, 120)
#define RGB_BLUE rgb( 0, 0, 255)
#define RGB_MAGENTA rgb(255, 0, 255)
#define RGB_WHITE rgb(255, 255, 255)
#define RGB_BLACK rgb( 0, 0, 0)
/**
* @brief Struct for easy manipulation of RGB colors.
*
* Set components in the xrgb.r (etc.) and you will get
* the hex in xrgb.num.
*/
typedef union {
/** Struct for access to individual color components */
struct __attribute__((packed)) {
uint8_t b;
uint8_t g;
uint8_t r;
};
/** RGB color as a single uint32_t */
uint32_t num;
} ws2812_rgb_t;
/* Exported macros -----------------------------------------------------------*/
/**
* @brief Compose an RGB color.
* @param r, g, b - components 0xFF
* @returns integer 0xRRGGBB
*/
#define rgb(r, g, b) (((0xFF & (r)) << 16) | ((0xFF & (g)) << 8) | (0xFF & (b)))
/* Get components */
#define rgb_r(rgb) (((rgb) >> 16) & 0xFF)
#define rgb_g(rgb) (((rgb) >> 8) & 0xFF)
#define rgb_b(rgb) ((rgb) & 0xFF)
/* Exported functions --------------------------------------------------------*/
/**
* @brief Turn OFF the rgb LED
*/
void colorled_off(void);
/**
* @brief Set color of a WS2812B
* @param rgb - color 0xRRGGBB
*/
void colorled_set(uint32_t rgb);
/**
* @brief Set color of multiple chained RGB leds
* @param rgbs - array of colors (0xRRGGBB)
* @param count - number of LEDs
*/
void colorled_set_many(uint32_t *rgbs, int count);

@ -0,0 +1,96 @@
#include "main.h"
#include "com_fileio.h"
#include "com_iface.h"
#include "utils/str_utils.h"
// Holding fields for ifaces
ComIface *debug_iface = NULL;
ComIface *data_iface = NULL;
// --- File descriptor names ------------------------------
struct name_fd {
const char *name;
const int fd;
};
#define NAME_FD_MAP_LEN 1
/** pre-assigned file descriptors for names */
static const struct name_fd name_fd_map[NAME_FD_MAP_LEN] = {
{FNAME_DLNK, FD_DLNK}
};
// --- Syscalls -------------------------------------------
/**
* @brief Write to a file by file descriptor.
*
* @param fd : open file descriptor
* @param buf : data to write
* @param len : buffer size
* @return number of written bytes
*/
int _write(int fd, const char *buf, int len)
{
switch (fd) {
case FD_STDOUT: return (int)com_tx_block(debug_iface, buf, (size_t)len);
case FD_STDERR: return (int)com_tx_block(debug_iface, buf, (size_t)len);
case FD_DLNK: return (int)com_tx_block(data_iface, buf, (size_t)len);
default:
return 0;
}
}
// For some reason, reading does not work.
#if 0
/**
* @brief Read from a file descriptor
*
* @param fd : file descriptor
* @param buf : destination buffer
* @param len : number of bytes to read
* @return actual number of read bytes
*/
int _read(int fd, char *buf, int len)
{
switch (fd) {
case FD_STDIN: return com_rx_block(debug_iface, buf, len);
case FD_ESP: return com_rx_block(esp_iface, buf, len);
default:
return 0;
}
}
#endif
/**
* @brief Open a file by name.
*
* This stub is called by newlib when fopen is used.
* It returns a pre-assigned file descriptor based
* on the name.
*
* @note
* stdout, stderr, stdin are open implicitly
*
* @param name : file name
* @param flags : file flags (ignored)
* @return file descriptor
*/
int _open(const char *name, int flags, ...)
{
(void)flags;
for (int i = 0; i < NAME_FD_MAP_LEN; i++) {
if (streq(name_fd_map[i].name, name)) {
return name_fd_map[i].fd;
}
}
return -1;
}

@ -0,0 +1,23 @@
#pragma once
#include "com_iface.h"
/** Debug USART iface */
extern ComIface *debug_iface;
/** ESP8266 com iface */
extern ComIface *data_iface;
/** Do-nothing iface */
extern ComIface *com_iface_noop;
/** File descriptors for use with built-in "files" */
enum {
FD_STDIN = 0,
FD_STDOUT = 1,
FD_STDERR = 2,
FD_DLNK = 3,
};
#define FNAME_DLNK "dlnk"

@ -0,0 +1,179 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "com_iface.h"
#include "utils/timebase.h"
// ---- accessor methods ----------------------
bool com_rx_rdy(ComIface *iface)
{
return iface->rx_rdy(iface);
}
bool com_tx_rdy(ComIface *iface)
{
return iface->tx_rdy(iface);
}
bool com_tx_done(ComIface *iface)
{
return iface->tx_done(iface);
}
bool com_tx(ComIface *iface, uint8_t b)
{
return iface->tx(iface, b);
}
bool com_rx(ComIface *iface, uint8_t *b)
{
return iface->rx(iface, (uint8_t*) b);
}
bool com_unrx(ComIface *iface, uint8_t b)
{
if (!iface->unrx) {
return false; // not all may have it implemented
}
return iface->unrx(iface, b);
}
size_t com_tx_block(ComIface *iface, const void *blob, size_t size)
{
return iface->txb(iface, blob, size);
}
size_t com_rx_block(ComIface *iface, void *buf, size_t length)
{
return iface->rxb(iface, buf, length);
}
void com_poll(ComIface *iface)
{
iface->poll(iface);
}
bool com_rx_char(ComIface *iface, char * c)
{
return iface->rx(iface, (uint8_t*) c);
}