Compare commits
405 Commits
mbusTxCplt
...
configurat
Author | SHA1 | Date | |
---|---|---|---|
e2384d01ec
|
|||
fe1b2e5b40
|
|||
765c3b077c
|
|||
f019f7eb77
|
|||
0ed710e652
|
|||
24f2d0a01d
|
|||
78d32a7cc9
|
|||
a14928b035
|
|||
11265fc979
|
|||
fe694e75d2
|
|||
bde9f148a0
|
|||
77141319ea
|
|||
b4170ec6dc
|
|||
6a2646b93c
|
|||
243c487546
|
|||
7d03900ada
|
|||
98c0a9d7a2
|
|||
f22c821ca3
|
|||
76ff0d8e24 | |||
518abe4e1c
|
|||
bc15e23f10
|
|||
2c392cce53
|
|||
a26a2878f4
|
|||
6e96a27141
|
|||
a43e42a99f
|
|||
d2c5943014
|
|||
f409d3fb22
|
|||
ba6ac21069
|
|||
39ca9d963b
|
|||
4e3f086fa0
|
|||
44523a4ed3
|
|||
9a7e8ee297
|
|||
eaf658de51
|
|||
9e99d5510d
|
|||
159750bcf6
|
|||
aaad534d21
|
|||
e0c3394725
|
|||
638171b494
|
|||
d4b00cf391
|
|||
544163f4a3
|
|||
6d7119c0e2
|
|||
cb5dd5f79a
|
|||
9223cbda73
|
|||
975ecf40f9
|
|||
0b1c6217c4
|
|||
3c25a7d9e1
|
|||
b4ef9d29f9
|
|||
7aded82145
|
|||
8894036679
|
|||
3e1a7946c2
|
|||
4e04ad6567
|
|||
cbc3ca6f20 | |||
73c1360978 | |||
56ac741079
|
|||
7a12bba4df
|
|||
397c3d2a56
|
|||
f5f8aa0660
|
|||
1357b17bb8
|
|||
e2ed18e71d
|
|||
c9b5f16542
|
|||
7b8535e84e
|
|||
3b3894b3f0
|
|||
03cadcdd58
|
|||
8fe627e6b0
|
|||
e1640be4c0
|
|||
b328e41984
|
|||
02c093723e
|
|||
802fec74e2
|
|||
96d0599e20
|
|||
d86f767dc3
|
|||
3e31693cf8
|
|||
4bae6dce3c
|
|||
f5d33445d9
|
|||
30cfa20855
|
|||
d8bd9eae5d
|
|||
c308b0ba89
|
|||
622aad3cc1
|
|||
ab6fc41acf
|
|||
081fe26daf
|
|||
354a1670ee
|
|||
c14d4fe892
|
|||
edf1942ad3
|
|||
7c63579390
|
|||
d171dced70
|
|||
b15321d774 | |||
a05598d89a | |||
950c7b07d2 | |||
d5c568a63c
|
|||
14bf178664
|
|||
bdba2a79cd
|
|||
53ccd32a0c
|
|||
f88a4984be
|
|||
9198753e4b
|
|||
6d3b3e12ca
|
|||
ae9c397e85
|
|||
a9b71f481a
|
|||
0397d61e56
|
|||
a1c602a021
|
|||
d2c4efc8db
|
|||
f37361b659 | |||
7a088f19f2
|
|||
eb47d41e5a
|
|||
7d816f6ed0
|
|||
89edf7f7bb
|
|||
5cae5a1de3
|
|||
c1949f4cd3
|
|||
491a60f515
|
|||
b8513b2112
|
|||
04405d1b84 | |||
3dd954d379 | |||
bd435dd5d6 | |||
3fd30aaa36 | |||
eea6b7de3b | |||
1408c4942c | |||
f1c3cb33e3 | |||
aff85b6d3e
|
|||
63f993c130
|
|||
b1fdc04366
|
|||
206e371d48
|
|||
3807e2fa9f
|
|||
5ba461adf6
|
|||
ada748edbb | |||
1d69022e1d
|
|||
155abea66a | |||
b122d836ed | |||
33fcf6c080 | |||
5605a3d1d5
|
|||
bab3d71bf7
|
|||
8805b392b2
|
|||
ad682bb847
|
|||
54ce7adf27
|
|||
8a7560a00a | |||
24b25b710f | |||
af5da11cb1
|
|||
8e0d072571
|
|||
f584c7b543
|
|||
b749bc8538
|
|||
31cbe4fc7e
|
|||
5ed7fdce0f
|
|||
5e4f9063e1
|
|||
5714d3f6ed
|
|||
857ed8ad68
|
|||
d57ea7a9f9
|
|||
cf695023d7
|
|||
2fc1aafab9
|
|||
ad379a3e22
|
|||
8c6af80a11
|
|||
737a2ce3ac
|
|||
e563a9b772
|
|||
f27c2327b8
|
|||
59e6482b3f | |||
a17b01f0cd
|
|||
29b98cf4fa
|
|||
c9f1ba9fa9
|
|||
7bcfa7070d
|
|||
c7ac9a9dc3
|
|||
0eba87a107
|
|||
c6ba4914f3
|
|||
e369c51c96
|
|||
f6e10183db
|
|||
e1a77d4fbf
|
|||
cd249e5ad8
|
|||
34c723b7ae
|
|||
287b062114
|
|||
c5978df389
|
|||
d613d278ec
|
|||
e3c16ef712
|
|||
8e5ece822c
|
|||
804e8c8acf
|
|||
eb64cc8dce
|
|||
fb04857772
|
|||
5d3a2bbff3
|
|||
dc91b5317a
|
|||
46549cbc9f
|
|||
23568db1b5
|
|||
ccf6982b62
|
|||
6b593988ec
|
|||
8b37d39f14
|
|||
0b443f7bd5
|
|||
eb5267771f | |||
5786304c6c
|
|||
54e6e448d8
|
|||
e239655e7f
|
|||
313efe9770
|
|||
878da97ace
|
|||
4468cc1368
|
|||
06ee315f11
|
|||
ebfcba13bb
|
|||
6c81b1bf5f
|
|||
0a2e630231
|
|||
ab3a6ac5ac
|
|||
4a71801170
|
|||
2266ce6f7e
|
|||
699fea520f
|
|||
dabf838bbe
|
|||
cdc47dfd4f
|
|||
8d57095ac2
|
|||
5a4544bd97
|
|||
ec1eeb7ff9
|
|||
28106630c2
|
|||
7541ab0ae2
|
|||
1dbcd966fc
|
|||
17264c1c1a
|
|||
a1d0f7395f
|
|||
51ac61a921
|
|||
71af9bbd04
|
|||
d88b0726ab
|
|||
873f26bf4d
|
|||
cc50b2b93c
|
|||
b504b97655
|
|||
8c72ff1f16
|
|||
c9fa80f77f
|
|||
9244de5884
|
|||
47a9a413f2
|
|||
2fedba69ec
|
|||
5e29ecf356
|
|||
bd09d4db45
|
|||
961e5a73aa | |||
b9e1baee5b | |||
4f27f18970 | |||
79d9d2fd7c | |||
e79cc5f54d | |||
e20abb0e61 | |||
fc5e6ab151 | |||
e921ab59e3 | |||
7339e404b9 | |||
2a93c96345
|
|||
f10ac76fdb
|
|||
943dab7594
|
|||
6ba5e088b6
|
|||
77e83a3d44
|
|||
f5ba1a4f7d | |||
a48fcccc40
|
|||
07b2ad7a32
|
|||
9d7f739be5
|
|||
7df4f53741
|
|||
59cc6bc263
|
|||
d0409dc843
|
|||
36a1a09d93
|
|||
bf4ebb66df | |||
7bdf0de148
|
|||
8eca0cdc3f
|
|||
09a6612888
|
|||
a0b0915629
|
|||
251cf71647
|
|||
9c1bc47033
|
|||
c7c0cc12b4
|
|||
3654ebb36e
|
|||
2ba8eebd97
|
|||
8ea735ebac
|
|||
bf73cf2351
|
|||
8d1f24aac1
|
|||
02194ca679
|
|||
61551556b4
|
|||
90cabf613b
|
|||
8ffa23888d
|
|||
d97c08f859
|
|||
118228fec1
|
|||
28ee8061ff
|
|||
497f66892a
|
|||
83df40b534
|
|||
9275dcf0a3
|
|||
e306089188
|
|||
a8ded4a4f4 | |||
c98c5dd8a5 | |||
15d8afa207
|
|||
bf5d9b4bae
|
|||
fa66527d9c | |||
00cedd5e6a | |||
662a440179
|
|||
8a36a3da82
|
|||
30d17c5e5c
|
|||
0bd9174e91
|
|||
0cbc9e2d56
|
|||
6f4cc803be
|
|||
60ad31bf5e | |||
5a39c044b4 | |||
b64e9b5a73 | |||
25c0b74552 | |||
f433f3a28b | |||
d286756310
|
|||
b1b8cf1aa9
|
|||
7e9cc0051d
|
|||
7f79f53691 | |||
fd37e9b46c
|
|||
5650a758f8
|
|||
f1736f0369
|
|||
2eb9582c88
|
|||
bd99728827
|
|||
5c80167610
|
|||
c39e6cb5eb | |||
598ca471d2
|
|||
9865c42ed9
|
|||
d1138382fe
|
|||
21b22c322d | |||
dfba52b939
|
|||
ba1bcee18c | |||
65690775fb
|
|||
d033412bdf
|
|||
e72c5c0f44 | |||
a5d23ebfb7 | |||
14cf03b68b | |||
f017e80315 | |||
47a70a7ab7 | |||
bd78c7afa1
|
|||
3bd79b1741
|
|||
61bebbcfc9
|
|||
cd72ca317c
|
|||
dad1033a2b
|
|||
30dd82e895
|
|||
f4dfd922ed
|
|||
17304140fa
|
|||
ab8a97b1d2 | |||
371c22768a | |||
7c7e1c4725 | |||
5e6093377f | |||
264664763b
|
|||
dbb8e5eeb4 | |||
5173c6469e
|
|||
a94536c7b9
|
|||
bca4605b19
|
|||
238d4ae4b0
|
|||
6b4cb2037e
|
|||
594f0c5d68
|
|||
6719a2274d
|
|||
89b8955763
|
|||
9d273f3440 | |||
08fcb20d0b
|
|||
f22f15d036 | |||
c73d8381dc
|
|||
d07093c46a | |||
cc24dc9640
|
|||
019f1b5cd0
|
|||
78ff38043e
|
|||
076eca0a49
|
|||
a875b34958 | |||
052f9b6345 | |||
918cd706ed | |||
28876eaa14 | |||
747cbd3658
|
|||
6bbe4d7eaf
|
|||
bef20bcaed | |||
e3bbc8e61b | |||
11bce773b1
|
|||
020cdb497e
|
|||
f3986379d4
|
|||
98b6e37737
|
|||
6ddc415a45
|
|||
47df03e9e5
|
|||
c2efa9d8f3
|
|||
b1e2277ef5
|
|||
43fe49f90d
|
|||
a928e15e74
|
|||
54233f4a99
|
|||
9c76689e06
|
|||
e9c27607b5
|
|||
e708da9178
|
|||
9f35a6e338
|
|||
471114fdd4
|
|||
81f494e6e7
|
|||
8d1308cdef
|
|||
68691b4220
|
|||
880b3d26ec
|
|||
37623502cd
|
|||
01d29a1207
|
|||
dcd5589252
|
|||
f49ad09699
|
|||
538cff818b
|
|||
2032dab64e
|
|||
3285773212
|
|||
a13588f97f
|
|||
83c6d65172
|
|||
92d31980c8
|
|||
1a01995e48
|
|||
229bcb5367
|
|||
a82431c529 | |||
b696d854e3 | |||
192d6c2f0c
|
|||
669eca760a
|
|||
8f81672266
|
|||
545fe203df
|
|||
e5e0001a0e
|
|||
7aa330af95
|
|||
387f562629
|
|||
bff688884b
|
|||
8978e2aee9
|
|||
229259f410
|
|||
dcb6ee0953
|
|||
6ecba172ad
|
|||
7f4dacb284
|
|||
60dc9b133c
|
|||
25c02dc6ba
|
|||
be3be6709c
|
|||
358642c2b7
|
|||
902af2df0c
|
|||
eab39ff9d3
|
|||
29f28bb51d
|
|||
bf7a059d2d
|
|||
3e47fc60e5
|
|||
31a34068ad
|
|||
eb78c046f6
|
|||
c7677e7c79
|
|||
fd05813cdf | |||
ed02d75f45
|
|||
7ec5d0ba35
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +1,10 @@
|
||||
cube/build/
|
||||
cube/w5500.a
|
||||
cube/pubsubc.a
|
||||
.*.sw?
|
||||
*.o
|
||||
test
|
||||
.bash_history
|
||||
.vscode
|
||||
|
||||
|
||||
|
14
.gitmodules
vendored
14
.gitmodules
vendored
@ -1,3 +1,17 @@
|
||||
[submodule "cube/hottislib"]
|
||||
path = cube/hottislib
|
||||
url = ../hottislib
|
||||
[submodule "cube/ioLibrary_Driver"]
|
||||
path = cube/ioLibrary_Driver
|
||||
url = ../ioLibrary_Driver
|
||||
branch = WolfgangsOwnBranch
|
||||
[submodule "cube/libmbus"]
|
||||
path = cube/libmbus
|
||||
url = ../libmbus
|
||||
branch = WolfgangsOwnBranch
|
||||
[submodule "cube/pubsub"]
|
||||
path = cube/pubsub
|
||||
url = ../Pubsubclient
|
||||
[submodule "cube/pubsubc"]
|
||||
path = cube/pubsubc
|
||||
url = ../pubsubc
|
||||
|
215
Makefile-adjusted
Normal file
215
Makefile-adjusted
Normal file
@ -0,0 +1,215 @@
|
||||
# Processed by ../tools/insertMyCode.sh
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Mon Nov 09 10:47:02 CET 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
# Generic Makefile (based on gcc)
|
||||
#
|
||||
# ChangeLog :
|
||||
# 2017-02-10 - Several enhancements + project update mode
|
||||
# 2015-07-22 - first version
|
||||
# ------------------------------------------------
|
||||
|
||||
######################################
|
||||
# target
|
||||
######################################
|
||||
TARGET = cube
|
||||
|
||||
|
||||
######################################
|
||||
# building variables
|
||||
######################################
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -Og
|
||||
|
||||
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
######################################
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/cmdHandler.c User/Src/ports.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
||||
libmbus/mbus/mbus-protocol.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
Core/Src/spi.c \
|
||||
Core/Src/usart.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
Core/Src/system_stm32f1xx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
startup_stm32f103xe.s
|
||||
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
PREFIX = arm-none-eabi-
|
||||
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
|
||||
# either it can be added to the PATH environment variable.
|
||||
ifdef GCC_PATH
|
||||
CC = $(GCC_PATH)/$(PREFIX)gcc
|
||||
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(GCC_PATH)/$(PREFIX)objcopy
|
||||
SZ = $(GCC_PATH)/$(PREFIX)size
|
||||
else
|
||||
CC = $(PREFIX)gcc
|
||||
AS = $(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(PREFIX)objcopy
|
||||
SZ = $(PREFIX)size
|
||||
endif
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
# cpu
|
||||
CPU = -mcpu=cortex-m3
|
||||
|
||||
# fpu
|
||||
# NONE for Cortex-M0/M0+/M3
|
||||
|
||||
# float-abi
|
||||
|
||||
|
||||
# mcu
|
||||
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
|
||||
# macros for gcc
|
||||
# AS defines
|
||||
AS_DEFS =
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32F103xE
|
||||
|
||||
|
||||
# AS includes
|
||||
AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-Ihottislib \
|
||||
-Ilibmbus \
|
||||
-IUser/Inc \
|
||||
-IioLibrary_Driver/Ethernet \
|
||||
-IioLibrary_Driver/Internet/DHCP \
|
||||
-IioLibrary_Driver/Internet/httpServer \
|
||||
-Ipubsubc/src \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
endif
|
||||
|
||||
|
||||
# Generate dependency information
|
||||
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
||||
|
||||
|
||||
#######################################
|
||||
# LDFLAGS
|
||||
#######################################
|
||||
# link script
|
||||
LDSCRIPT = STM32F103VCTx_FLASH.ld
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||
|
||||
|
||||
#######################################
|
||||
# build the application
|
||||
#######################################
|
||||
# list of objects
|
||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,pubsubc.a w5500.a)
|
||||
# list of ASM program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||
|
||||
|
||||
$(BUILD_DIR)/w5500.a:
|
||||
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
|
||||
|
||||
$(BUILD_DIR)/pubsubc.a:
|
||||
(cd pubsubc && $(MAKE) && cp pubsubc.a ../$(BUILD_DIR) && cd ..)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||
$(AS) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(HEX) $< $@
|
||||
|
||||
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(BIN) $< $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir $@
|
||||
|
||||
#######################################
|
||||
# clean up
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
@ -1,5 +1,5 @@
|
||||
[PreviousLibFiles]
|
||||
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm7.h;
|
||||
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_sc300.h;
|
||||
|
||||
[PreviousUsedIarFiles]
|
||||
SourceFiles=../Core/Src/main.c;../Core/Src/gpio.c;../Core/Src/adc.c;../Core/Src/spi.c;../Core/Src/usart.c;../Core/Src/stm32f1xx_it.c;../Core/Src/stm32f1xx_hal_msp.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;../Core/Src/system_stm32f1xx.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;../Core/Src/system_stm32f1xx.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;;
|
||||
|
@ -61,6 +61,10 @@ void Error_Handler(void);
|
||||
#define debugUart huart4
|
||||
#define mbusUart huart5
|
||||
#define frontendAdc hadc1
|
||||
#define eepromSpi hspi2
|
||||
#define etherSpi hspi1
|
||||
#define displaySpi hspi3
|
||||
#define debugUartIRQn UART4_IRQn
|
||||
#define Loop_Enable_Pin GPIO_PIN_2
|
||||
#define Loop_Enable_GPIO_Port GPIOE
|
||||
#define Loop_Disable_Pin GPIO_PIN_3
|
||||
@ -74,10 +78,30 @@ void Error_Handler(void);
|
||||
#define LED_Red_GPIO_Port GPIOE
|
||||
#define Frontend_In_Pin GPIO_PIN_1
|
||||
#define Frontend_In_GPIO_Port GPIOA
|
||||
#define ETHER_RES_Pin GPIO_PIN_2
|
||||
#define ETHER_RES_GPIO_Port GPIOA
|
||||
#define ETHER_INT_Pin GPIO_PIN_3
|
||||
#define ETHER_INT_GPIO_Port GPIOA
|
||||
#define ETHER_CS_Pin GPIO_PIN_4
|
||||
#define ETHER_CS_GPIO_Port GPIOA
|
||||
#define ETHER_SCLK_Pin GPIO_PIN_5
|
||||
#define ETHER_SCLK_GPIO_Port GPIOA
|
||||
#define ETHER_MISO_Pin GPIO_PIN_6
|
||||
#define ETHER_MISO_GPIO_Port GPIOA
|
||||
#define ETHER_MOSI_Pin GPIO_PIN_7
|
||||
#define ETHER_MOSI_GPIO_Port GPIOA
|
||||
#define Debug_Signal_2_Pin GPIO_PIN_12
|
||||
#define Debug_Signal_2_GPIO_Port GPIOE
|
||||
#define Debug_Signal_1_Pin GPIO_PIN_10
|
||||
#define Debug_Signal_1_GPIO_Port GPIOB
|
||||
#define EEPROM_CS_Pin GPIO_PIN_12
|
||||
#define EEPROM_CS_GPIO_Port GPIOB
|
||||
#define EEPROM_SCLK_Pin GPIO_PIN_13
|
||||
#define EEPROM_SCLK_GPIO_Port GPIOB
|
||||
#define EEPROM_MISO_Pin GPIO_PIN_14
|
||||
#define EEPROM_MISO_GPIO_Port GPIOB
|
||||
#define EEPROM_MOSI_Pin GPIO_PIN_15
|
||||
#define EEPROM_MOSI_GPIO_Port GPIOB
|
||||
#define Debug_TX_Pin GPIO_PIN_10
|
||||
#define Debug_TX_GPIO_Port GPIOC
|
||||
#define Debug_RX_Pin GPIO_PIN_11
|
||||
@ -88,6 +112,18 @@ void Error_Handler(void);
|
||||
#define Frontend_Out_GPIO_Port GPIOD
|
||||
#define MBus_RX_Pin GPIO_PIN_2
|
||||
#define MBus_RX_GPIO_Port GPIOD
|
||||
#define Display_CS_Pin GPIO_PIN_7
|
||||
#define Display_CS_GPIO_Port GPIOD
|
||||
#define Display_SCLK_Pin GPIO_PIN_3
|
||||
#define Display_SCLK_GPIO_Port GPIOB
|
||||
#define Display_MISO_Pin GPIO_PIN_4
|
||||
#define Display_MISO_GPIO_Port GPIOB
|
||||
#define Display_MOSI_Pin GPIO_PIN_5
|
||||
#define Display_MOSI_GPIO_Port GPIOB
|
||||
#define Display_DC_Pin GPIO_PIN_6
|
||||
#define Display_DC_GPIO_Port GPIOB
|
||||
#define Display_RES_Pin GPIO_PIN_7
|
||||
#define Display_RES_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
extern SPI_HandleTypeDef hspi3;
|
||||
|
||||
@ -37,6 +38,7 @@ extern SPI_HandleTypeDef hspi3;
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_SPI1_Init(void);
|
||||
void MX_SPI2_Init(void);
|
||||
void MX_SPI3_Init(void);
|
||||
|
||||
|
@ -58,6 +58,7 @@ void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void EXTI4_IRQHandler(void);
|
||||
void ADC1_2_IRQHandler(void);
|
||||
void SPI2_IRQHandler(void);
|
||||
void UART4_IRQHandler(void);
|
||||
void UART5_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
@ -54,10 +54,13 @@ void MX_GPIO_Init(void)
|
||||
|Debug_Signal_2_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(Debug_Signal_1_GPIO_Port, Debug_Signal_1_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, ETHER_RES_Pin|ETHER_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, Debug_Signal_1_Pin|EEPROM_CS_Pin|Display_DC_Pin|Display_RES_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, Frontend_Out_Pin|Display_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin PEPin PEPin
|
||||
PEPin */
|
||||
@ -74,19 +77,32 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(Loop_Status_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = Debug_Signal_1_Pin;
|
||||
/*Configure GPIO pins : PAPin PAPin */
|
||||
GPIO_InitStruct.Pin = ETHER_RES_Pin|ETHER_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(Debug_Signal_1_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = Frontend_Out_Pin;
|
||||
GPIO_InitStruct.Pin = ETHER_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(ETHER_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = Debug_Signal_1_Pin|EEPROM_CS_Pin|Display_DC_Pin|Display_RES_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(Frontend_Out_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = Frontend_Out_Pin|Display_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
|
||||
|
@ -98,6 +98,7 @@ int main(void)
|
||||
MX_SPI3_Init();
|
||||
MX_UART4_Init();
|
||||
MX_UART5_Init();
|
||||
MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
my_setup_2();
|
||||
|
||||
|
@ -93,6 +93,7 @@ int main(void)
|
||||
MX_SPI3_Init();
|
||||
MX_UART4_Init();
|
||||
MX_UART5_Init();
|
||||
MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
@ -24,9 +24,32 @@
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
SPI_HandleTypeDef hspi2;
|
||||
SPI_HandleTypeDef hspi3;
|
||||
|
||||
/* SPI1 init function */
|
||||
void MX_SPI1_Init(void)
|
||||
{
|
||||
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 10;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
/* SPI2 init function */
|
||||
void MX_SPI2_Init(void)
|
||||
{
|
||||
@ -38,7 +61,7 @@ void MX_SPI2_Init(void)
|
||||
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
@ -76,7 +99,35 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(spiHandle->Instance==SPI2)
|
||||
if(spiHandle->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 0 */
|
||||
/* SPI1 clock enable */
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = ETHER_SCLK_Pin|ETHER_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = ETHER_MISO_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(ETHER_MISO_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 1 */
|
||||
}
|
||||
else if(spiHandle->Instance==SPI2)
|
||||
{
|
||||
/* USER CODE BEGIN SPI2_MspInit 0 */
|
||||
|
||||
@ -90,16 +141,19 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
PB14 ------> SPI2_MISO
|
||||
PB15 ------> SPI2_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
|
||||
GPIO_InitStruct.Pin = EEPROM_SCLK_Pin|EEPROM_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_14;
|
||||
GPIO_InitStruct.Pin = EEPROM_MISO_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(EEPROM_MISO_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* SPI2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(SPI2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(SPI2_IRQn);
|
||||
/* USER CODE BEGIN SPI2_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI2_MspInit 1 */
|
||||
@ -118,15 +172,15 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
PB4 ------> SPI3_MISO
|
||||
PB5 ------> SPI3_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5;
|
||||
GPIO_InitStruct.Pin = Display_SCLK_Pin|Display_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4;
|
||||
GPIO_InitStruct.Pin = Display_MISO_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(Display_MISO_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN SPI3_MspInit 1 */
|
||||
|
||||
@ -137,7 +191,26 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||
{
|
||||
|
||||
if(spiHandle->Instance==SPI2)
|
||||
if(spiHandle->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, ETHER_SCLK_Pin|ETHER_MISO_Pin|ETHER_MOSI_Pin);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 1 */
|
||||
}
|
||||
else if(spiHandle->Instance==SPI2)
|
||||
{
|
||||
/* USER CODE BEGIN SPI2_MspDeInit 0 */
|
||||
|
||||
@ -150,8 +223,10 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||
PB14 ------> SPI2_MISO
|
||||
PB15 ------> SPI2_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
|
||||
HAL_GPIO_DeInit(GPIOB, EEPROM_SCLK_Pin|EEPROM_MISO_Pin|EEPROM_MOSI_Pin);
|
||||
|
||||
/* SPI2 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(SPI2_IRQn);
|
||||
/* USER CODE BEGIN SPI2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI2_MspDeInit 1 */
|
||||
@ -169,7 +244,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||
PB4 ------> SPI3_MISO
|
||||
PB5 ------> SPI3_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
|
||||
HAL_GPIO_DeInit(GPIOB, Display_SCLK_Pin|Display_MISO_Pin|Display_MOSI_Pin);
|
||||
|
||||
/* USER CODE BEGIN SPI3_MspDeInit 1 */
|
||||
|
||||
|
@ -60,6 +60,7 @@
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
extern UART_HandleTypeDef huart4;
|
||||
extern UART_HandleTypeDef huart5;
|
||||
/* USER CODE BEGIN EV */
|
||||
@ -232,6 +233,20 @@ void ADC1_2_IRQHandler(void)
|
||||
/* USER CODE END ADC1_2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPI2 global interrupt.
|
||||
*/
|
||||
void SPI2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SPI2_IRQn 0 */
|
||||
|
||||
/* USER CODE END SPI2_IRQn 0 */
|
||||
HAL_SPI_IRQHandler(&hspi2);
|
||||
/* USER CODE BEGIN SPI2_IRQn 1 */
|
||||
|
||||
/* USER CODE END SPI2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles UART4 global interrupt.
|
||||
*/
|
||||
@ -246,6 +261,9 @@ void UART4_IRQHandler(void)
|
||||
/* USER CODE END UART4_IRQn 1 */
|
||||
}
|
||||
|
||||
|
||||
void mbusCommISR();
|
||||
|
||||
/**
|
||||
* @brief This function handles UART5 global interrupt.
|
||||
*/
|
||||
@ -254,9 +272,11 @@ void UART5_IRQHandler(void)
|
||||
/* USER CODE BEGIN UART5_IRQn 0 */
|
||||
|
||||
/* USER CODE END UART5_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart5);
|
||||
// HAL_UART_IRQHandler(&huart5);
|
||||
/* USER CODE BEGIN UART5_IRQn 1 */
|
||||
|
||||
mbusCommISR();
|
||||
|
||||
/* USER CODE END UART5_IRQn 1 */
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
extern UART_HandleTypeDef huart4;
|
||||
extern UART_HandleTypeDef huart5;
|
||||
/* USER CODE BEGIN EV */
|
||||
@ -227,6 +228,20 @@ void ADC1_2_IRQHandler(void)
|
||||
/* USER CODE END ADC1_2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPI2 global interrupt.
|
||||
*/
|
||||
void SPI2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SPI2_IRQn 0 */
|
||||
|
||||
/* USER CODE END SPI2_IRQn 0 */
|
||||
HAL_SPI_IRQHandler(&hspi2);
|
||||
/* USER CODE BEGIN SPI2_IRQn 1 */
|
||||
|
||||
/* USER CODE END SPI2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles UART4 global interrupt.
|
||||
*/
|
||||
|
@ -2014,6 +2014,10 @@ HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
inline void dts(uint8_t v) {
|
||||
while (v--) HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles UART interrupt request.
|
||||
* @param huart Pointer to a UART_HandleTypeDef structure that contains
|
||||
@ -2022,6 +2026,8 @@ HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
|
||||
*/
|
||||
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_12);
|
||||
|
||||
uint32_t isrflags = READ_REG(huart->Instance->SR);
|
||||
uint32_t cr1its = READ_REG(huart->Instance->CR1);
|
||||
uint32_t cr3its = READ_REG(huart->Instance->CR3);
|
||||
@ -2035,6 +2041,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
|
||||
/* UART in mode Receiver -------------------------------------------------*/
|
||||
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
||||
{
|
||||
dts(1);
|
||||
UART_Receive_IT(huart);
|
||||
return;
|
||||
}
|
||||
@ -2043,6 +2050,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
|
||||
/* If some errors occur */
|
||||
if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
|
||||
{
|
||||
dts(2);
|
||||
/* UART parity error interrupt occurred ----------------------------------*/
|
||||
if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
|
||||
{
|
||||
@ -2070,10 +2078,14 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
|
||||
/* Call UART Error Call back function if need be --------------------------*/
|
||||
if (huart->ErrorCode != HAL_UART_ERROR_NONE)
|
||||
{
|
||||
dts(3);
|
||||
/* UART in mode Receiver -----------------------------------------------*/
|
||||
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
||||
{
|
||||
dts(4);
|
||||
UART_Receive_IT(huart);
|
||||
} else {
|
||||
dts(5);
|
||||
}
|
||||
|
||||
/* If Overrun error occurs, or if any error occurs in DMA mode reception,
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Processed by ../tools/insertMyCode.sh
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Nov 01 15:55:46 CET 2020]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Nov 19 18:53:40 CET 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
@ -37,7 +37,8 @@ BUILD_DIR = build
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
User/Src/frontend.c User/Src/signal.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \
|
||||
User/Src/regularCmds.c User/Src/adminCmds.c User/Src/configCmds.c User/Src/config.c User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
||||
libmbus/mbus/mbus-protocol.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
@ -120,7 +121,12 @@ AS_INCLUDES =
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-Ihottislib \
|
||||
-Ipubsubc/src \
|
||||
-Ilibmbus \
|
||||
-IUser/Inc \
|
||||
-IioLibrary_Driver/Internet/DHCP \
|
||||
-IioLibrary_Driver/Internet/DNS \
|
||||
-IioLibrary_Driver/Ethernet \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
@ -130,9 +136,9 @@ C_INCLUDES = \
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
|
||||
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
@ -152,7 +158,7 @@ LDSCRIPT = STM32F103VCTx_FLASH.ld
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||
@ -164,10 +170,17 @@ all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET
|
||||
# list of objects
|
||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a pubsubc.a)
|
||||
# list of ASM program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||
|
||||
$(BUILD_DIR)/w5500.a:
|
||||
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
|
||||
|
||||
$(BUILD_DIR)/pubsubc.a:
|
||||
(cd pubsubc && $(MAKE) && cp pubsubc.a ../$(BUILD_DIR) && cd ..)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Nov 01 15:55:46 CET 2020]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Nov 19 18:53:40 CET 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
9
cube/User/Inc/cmdHandler.h
Normal file
9
cube/User/Inc/cmdHandler.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _CMDHANDLER_H_
|
||||
#define _CMDHANDLER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void cmdHandlerInit();
|
||||
|
||||
|
||||
#endif /* _CMDHANDLER_H_ */
|
23
cube/User/Inc/cmdHelper.h
Normal file
23
cube/User/Inc/cmdHelper.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef _CMDHELPER_H_
|
||||
#define _CMDHELPER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
|
||||
|
||||
typedef struct {
|
||||
char name[16];
|
||||
char help[512];
|
||||
cmdFunc_t cmdFunc;
|
||||
} cmd_t;
|
||||
|
||||
void sendString(const char *buf);
|
||||
bool sendFormatString(const char *format, ...);
|
||||
|
||||
const cmd_t *getRegularCommands();
|
||||
const cmd_t *getAdminCommands();
|
||||
const cmd_t *getConfigCommands();
|
||||
|
||||
#endif /* _CMDHELPER_H_ */
|
42
cube/User/Inc/config.h
Normal file
42
cube/User/Inc/config.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <spi.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define CONFIG_MAGIC 0xdead000a
|
||||
#define DEVICE_MAGIC 0xaffe0000
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_configBlock {
|
||||
uint32_t configMagic;
|
||||
char deviceName[16];
|
||||
uint8_t macAddress[6];
|
||||
int32_t frontendThreshold;
|
||||
char brokerName[64];
|
||||
char watchdogTopic[64];
|
||||
char startupTopic[64];
|
||||
char statusTopic[64];
|
||||
char mbusDataTopic[64];
|
||||
char syslogServerName[64];
|
||||
uint8_t numOfDeviceBlocks;
|
||||
uint8_t filler[1];
|
||||
} t_configBlock;
|
||||
|
||||
|
||||
#define MBUSDEVICE_NAMELENGTH 16
|
||||
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_deviceBlock {
|
||||
uint32_t deviceMagic;
|
||||
char deviceName[MBUSDEVICE_NAMELENGTH];
|
||||
uint8_t address;
|
||||
int8_t consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
int32_t period;
|
||||
uint8_t filler[3];
|
||||
} t_deviceBlock;
|
||||
|
||||
void configInit();
|
||||
t_configBlock* getConfig();
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
50
cube/User/Inc/eeprom.h
Normal file
50
cube/User/Inc/eeprom.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef EEPROM_H_
|
||||
#define EEPROM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <spi.h>
|
||||
#include <config.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
|
||||
#define EEPROM_WRITE_BLOCK_SIZE 32
|
||||
#define EEPROM_AFTER_WRITE_DELAY 7
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_eepromHeader {
|
||||
uint32_t magic;
|
||||
uint32_t writeCounter;
|
||||
} t_eepromHeader;
|
||||
static_assert((sizeof(t_eepromHeader) <= EEPROM_WRITE_BLOCK_SIZE), "t_eepromHeader has illegal size, must be less than or equal 32");
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_deviceStats {
|
||||
uint32_t totalRunningHours;
|
||||
uint32_t totalPowercycles;
|
||||
uint32_t totalRequests;
|
||||
uint32_t totalFailures;
|
||||
} t_deviceStats;
|
||||
static_assert((sizeof(t_deviceStats) <= EEPROM_WRITE_BLOCK_SIZE), "t_deviceStats has illegal size, must be less than or equal 32");
|
||||
|
||||
static_assert((sizeof(t_configBlock) % 32 == 0), "t_configBlock has illegal size, must be dividable by 32");
|
||||
static_assert((sizeof(t_deviceBlock) % 32 == 0), "t_deviceBlock has illegal size, must be dividable by 32");
|
||||
|
||||
|
||||
#define EEPROM_BASE_ADDR 0
|
||||
#define EEPROM_DEVICE_STATS_ADDR 32
|
||||
#define EEPROM_CONFIG_BLOCK_ADDR 64
|
||||
#define EEPROM_DEVICE_BLOCK_BASE_ADDR (EEPROM_CONFIG_BLOCK_ADDR + sizeof(t_configBlock))
|
||||
|
||||
|
||||
|
||||
void eepromInit();
|
||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||
t_deviceStats* getGlobalDeviceStats();
|
||||
void eepromReadConfigBlock(t_configBlock *destConfigBlock);
|
||||
void eepromWriteConfigBlock(t_configBlock *srcConfigBlock);
|
||||
void eepromReadDeviceBlock(uint8_t blockNum, t_deviceBlock *destDeviceBlock);
|
||||
void eepromWriteDeviceBlock(uint8_t blockNum, t_deviceBlock *srcDeviceBlock);
|
||||
|
||||
#endif /* EEPROM_H_ */
|
@ -9,6 +9,5 @@ void frontendInit();
|
||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc);
|
||||
void frontendEnable();
|
||||
void frontendDisable();
|
||||
void frontendSetThreshold(int32_t threshold);
|
||||
|
||||
#endif // _FRONTEND_H_
|
@ -1,7 +1,23 @@
|
||||
#ifndef _LOGGER_H_
|
||||
#define _LOGGER_H_
|
||||
|
||||
#include <main.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
// Disabling this option is preferred. However, when debugging system hangs
|
||||
// this option needs to be enabled.
|
||||
// #define LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
typedef enum {
|
||||
LOG_NORMAL,
|
||||
LOG_HIGH,
|
||||
LOG_RED,
|
||||
LOG_GREEN,
|
||||
LOG_BLUE,
|
||||
LOG_YELLOW
|
||||
} t_logColor;
|
||||
|
||||
// initialize the logger, creates a ringbuffer
|
||||
void logInit();
|
||||
@ -13,9 +29,14 @@ void logFree();
|
||||
// return value can be ignored, it is only used in test
|
||||
int logMsg(const char *format, ...);
|
||||
|
||||
// reads the ringbuffer and transfers data to output channel
|
||||
// call this from the idle-loop
|
||||
// return value can be ignored, it is only used in test
|
||||
int coloredMsg(const t_logColor color, bool syslogToo, const char *format, ...);
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void debugTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
#endif
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
int logExec();
|
||||
#endif
|
||||
|
||||
#endif // _LOGGER_H_
|
||||
|
@ -3,8 +3,48 @@
|
||||
|
||||
#include <main.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <config.h>
|
||||
|
||||
void mbusCommRequest(uint8_t cmd, uint8_t addr);
|
||||
|
||||
typedef struct {
|
||||
char deviceName[MBUSDEVICE_NAMELENGTH];
|
||||
uint8_t address;
|
||||
int8_t consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
uint32_t requests;
|
||||
uint32_t failures;
|
||||
int32_t period;
|
||||
int32_t delay;
|
||||
bool waiting;
|
||||
bool active;
|
||||
} t_mbusDevice;
|
||||
|
||||
typedef enum {
|
||||
MBCRR_TRIGGERED = 0,
|
||||
MBCRR_BUSY = 1,
|
||||
MBCRR_DISABLED = 2
|
||||
} e_mbusCommRequestResult;
|
||||
|
||||
typedef struct {
|
||||
uint32_t mbusRequestCnt;
|
||||
uint32_t mbusErrorCnt;
|
||||
uint32_t uartOctetCnt;
|
||||
uint32_t uartOverrunCnt;
|
||||
uint32_t uartFramingErrCnt;
|
||||
uint32_t uartParityErrCnt;
|
||||
uint32_t uartNoiseErrCnt;
|
||||
} t_mbusCommStats;
|
||||
|
||||
// e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||
void mbusCommInit();
|
||||
void mbusCommExec();
|
||||
void mbusCommEnable(bool enable);
|
||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommErrorCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommSetStats(t_mbusCommStats stats);
|
||||
t_mbusCommStats *mbusCommGetStats();
|
||||
void mbusCommAddDevice(t_deviceBlock *deviceBlock);
|
||||
|
||||
|
||||
#endif // _MBUSCOMM_H_
|
||||
|
20
cube/User/Inc/mbusParserExt.h
Normal file
20
cube/User/Inc/mbusParserExt.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _MBUSPARSEREXT_H_
|
||||
#define _MBUSPARSEREXT_H_
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *unit;
|
||||
int8_t exponent;
|
||||
bool found;
|
||||
} parsedVIB_t;
|
||||
|
||||
parsedVIB_t parseVIB(mbus_value_information_block vib);
|
||||
|
||||
|
||||
|
||||
#endif //_MBUSPARSEREXT_H_
|
13
cube/User/Inc/mqttComm.h
Normal file
13
cube/User/Inc/mqttComm.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _MQTTCOMM_H_
|
||||
#define _MQTTCOMM_H_
|
||||
|
||||
|
||||
void mqttCommInit();
|
||||
void mqttPublish(const char *topic, char *message);
|
||||
void mqttPublishf(const char *topic, char *messageFormat, ...);
|
||||
|
||||
|
||||
|
||||
#endif // _MQTTCOMM_H_
|
||||
|
||||
|
226
cube/User/Inc/oled-fonts.h
Normal file
226
cube/User/Inc/oled-fonts.h
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* oled-fonts.h
|
||||
*
|
||||
* Created on: May 29, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef OLED_FONTS_H_
|
||||
#define OLED_FONTS_H_
|
||||
|
||||
|
||||
/*
|
||||
* Code found at http://www.instructables.com/id/How-to-use-OLED-display-arduino-module/
|
||||
* Thank you very much!
|
||||
* Adapted from Arduino to STM32 HAL by wollud1969
|
||||
*/
|
||||
|
||||
|
||||
|
||||
const unsigned char F6x8[][6] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
|
||||
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
|
||||
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
|
||||
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
|
||||
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
|
||||
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
|
||||
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
|
||||
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
|
||||
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
|
||||
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
|
||||
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
|
||||
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
|
||||
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
|
||||
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
|
||||
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
|
||||
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
|
||||
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
|
||||
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
|
||||
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
|
||||
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
|
||||
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
|
||||
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
|
||||
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
|
||||
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
|
||||
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
|
||||
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
|
||||
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
|
||||
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
|
||||
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
|
||||
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
|
||||
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
|
||||
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
|
||||
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
|
||||
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
|
||||
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
|
||||
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
|
||||
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
|
||||
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
|
||||
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
|
||||
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
|
||||
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
|
||||
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
|
||||
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
|
||||
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
|
||||
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
|
||||
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
|
||||
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
|
||||
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
|
||||
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
|
||||
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
|
||||
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
|
||||
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
|
||||
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
|
||||
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
|
||||
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
|
||||
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
|
||||
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
|
||||
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
|
||||
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
|
||||
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ 91
|
||||
{ 0x00, 0x02, 0x04 ,0x08, 0x10, 0x20 }, // \92
|
||||
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
|
||||
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
|
||||
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
|
||||
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
|
||||
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
|
||||
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
|
||||
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
|
||||
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
|
||||
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
|
||||
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
|
||||
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
|
||||
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
|
||||
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
|
||||
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
|
||||
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
|
||||
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
|
||||
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
|
||||
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
|
||||
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
|
||||
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
|
||||
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
|
||||
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
|
||||
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
|
||||
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
|
||||
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
|
||||
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
|
||||
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
|
||||
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
|
||||
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
|
||||
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
|
||||
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const unsigned char F8X16[]=
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
|
||||
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
|
||||
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
|
||||
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
|
||||
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
|
||||
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
|
||||
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
|
||||
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
|
||||
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
|
||||
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
|
||||
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
|
||||
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
|
||||
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
|
||||
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
|
||||
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
|
||||
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
|
||||
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
|
||||
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
|
||||
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
|
||||
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
|
||||
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
|
||||
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
|
||||
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
|
||||
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
|
||||
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
|
||||
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
|
||||
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
|
||||
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
|
||||
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
|
||||
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
|
||||
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
|
||||
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
|
||||
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
|
||||
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
|
||||
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
|
||||
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
|
||||
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
|
||||
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
|
||||
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
|
||||
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
|
||||
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
|
||||
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
|
||||
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
|
||||
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
|
||||
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
|
||||
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
|
||||
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
|
||||
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
|
||||
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
|
||||
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
|
||||
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
|
||||
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
|
||||
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
|
||||
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
|
||||
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
|
||||
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
|
||||
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
|
||||
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
|
||||
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
|
||||
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
|
||||
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
|
||||
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//unsigned char5
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
|
||||
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
|
||||
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
|
||||
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
|
||||
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
|
||||
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
|
||||
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* OLED_FONTS_H_ */
|
32
cube/User/Inc/oled.h
Normal file
32
cube/User/Inc/oled.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* oled.h
|
||||
*
|
||||
* Created on: May 29, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef OLED_H_
|
||||
#define OLED_H_
|
||||
|
||||
|
||||
/*
|
||||
* Code found at http://www.instructables.com/id/How-to-use-OLED-display-arduino-module/
|
||||
* Thank you very much!
|
||||
* Adapted from Arduino to STM32 HAL by wollud1969
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
OLED_SCREEN0 = 0,
|
||||
OLED_SCREEN1
|
||||
} oledScreen_t;
|
||||
|
||||
void oledInit(void);
|
||||
void oledClearActiveScreen();
|
||||
void oledClearAllScreens();
|
||||
void oledPrint(oledScreen_t screen, char msg[]);
|
||||
void oledPrintf(oledScreen_t screen, const char *format, ...);
|
||||
void oledSetActiveScreen(oledScreen_t screen);
|
||||
|
||||
#endif /* OLED_H_ */
|
20
cube/User/Inc/show.h
Normal file
20
cube/User/Inc/show.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _SHOW_H_
|
||||
#define _SHOW_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
DEBUG_1 = 0,
|
||||
DEBUG_2 = 1,
|
||||
LED_RED = 2,
|
||||
LED_GREEN = 3
|
||||
} signalPin_t;
|
||||
|
||||
typedef enum { ON, OFF, TOGGLE, BLINK } signalAction_t;
|
||||
|
||||
void showInit();
|
||||
void show(signalPin_t signalPin, signalAction_t action);
|
||||
|
||||
|
||||
#endif // _SHOW_H_
|
@ -1,13 +0,0 @@
|
||||
#ifndef _DEBUG_H_
|
||||
#define _DEBUG_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum { DEBUG_1, DEBUG_2, LED_RED, LED_GREEN } signalPin_t;
|
||||
typedef enum { ON, OFF, TOGGLE } signalAction_t;
|
||||
|
||||
void signal(signalPin_t signalPin, signalAction_t action);
|
||||
|
||||
|
||||
#endif // _DEBUG_H_
|
8
cube/User/Inc/utils.h
Normal file
8
cube/User/Inc/utils.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef _UTILS_H_
|
||||
#define _UTILS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void activeDelay(uint8_t delay_ms);
|
||||
|
||||
#endif // _UTILS_H_
|
13
cube/User/Inc/wizHelper.h
Normal file
13
cube/User/Inc/wizHelper.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _WIZHELPER_H_
|
||||
#define _WIZHELPER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
int wizInit();
|
||||
bool isNetworkAvailable();
|
||||
uint8_t* wizGetIPAddress();
|
||||
bool wizDnsQuery(char *name, uint8_t *ip);
|
||||
|
||||
#endif // _WIZHELPER_H_
|
81
cube/User/Src/adminCmds.c
Normal file
81
cube/User/Src/adminCmds.c
Normal file
@ -0,0 +1,81 @@
|
||||
#include <cmdHelper.h>
|
||||
#include <logger.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mbusComm.h>
|
||||
#include <loopCtrl.h>
|
||||
|
||||
|
||||
// clear statistics
|
||||
static bool clearCmd(uint8_t argc, char **args) {
|
||||
t_mbusCommStats zeroedStats = { .mbusRequestCnt = 0, .mbusErrorCnt = 0, .uartOctetCnt = 0, .uartOverrunCnt = 0, .uartFramingErrCnt = 0, .uartParityErrCnt = 0, .uartNoiseErrCnt = 0 };
|
||||
mbusCommSetStats(zeroedStats);
|
||||
coloredMsg(LOG_YELLOW, true, "ch cc global statistics cleared");
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool mbusCommEnableCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
mbusCommEnable(false);
|
||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication disabled");
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
mbusCommEnable(true);
|
||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication enabled");
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static bool loopEnableCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
loopDisable();
|
||||
coloredMsg(LOG_YELLOW, true, "ch lec loop disabled");
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
loopEnable();
|
||||
coloredMsg(LOG_YELLOW, true, "ch lec loop enabled");
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const cmd_t ADMIN_COMMANDS[] = {
|
||||
{ .name = "clear", .cmdFunc = clearCmd,
|
||||
.help = \
|
||||
"clear ................................ Clears the global Meterbus\n\r" \
|
||||
" statistics\n\r"
|
||||
},
|
||||
{ .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
|
||||
.help = \
|
||||
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
|
||||
" communication\n\r"
|
||||
},
|
||||
{ .name = "loopEnable", .cmdFunc = loopEnableCmd,
|
||||
.help = \
|
||||
"loopEnable true|false ................ Enables or disables the loop.\n\r" \
|
||||
" Disable Meterbus communication\n\r" \
|
||||
" first if you want to disable the\n\r" \
|
||||
" for a longer time, otherwise the\n\r" \
|
||||
" request will enable it again\n\r"
|
||||
},
|
||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
const cmd_t *getAdminCommands() {
|
||||
return ADMIN_COMMANDS;
|
||||
}
|
336
cube/User/Src/cmdHandler.c
Normal file
336
cube/User/Src/cmdHandler.c
Normal file
@ -0,0 +1,336 @@
|
||||
#include <cmdHandler.h>
|
||||
#include <cmdHelper.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <socket.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <wizHelper.h>
|
||||
|
||||
extern const uint8_t CMD_SOCK;
|
||||
|
||||
const uint16_t cmdPort = 23;
|
||||
|
||||
typedef enum {
|
||||
CH_INIT,
|
||||
CH_LISTEN,
|
||||
CH_WAITING,
|
||||
CH_BANNER,
|
||||
CH_PROMPT,
|
||||
CH_RECEIVE,
|
||||
CH_DISCONNECT,
|
||||
CH_DISCONNECT_WAIT,
|
||||
CH_ERROR
|
||||
} chState_t;
|
||||
|
||||
void sendString(const char *buf) {
|
||||
send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
|
||||
}
|
||||
|
||||
bool sendFormatString(const char *format, ...) {
|
||||
bool retCode = true;
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
char buf[4096];
|
||||
int vcnt = vsnprintf(buf, sizeof(buf), format, vl);
|
||||
retCode = (vcnt < sizeof(buf));
|
||||
va_end(vl);
|
||||
sendString(buf);
|
||||
return retCode;
|
||||
}
|
||||
|
||||
// returns 0 to continue waiting for input
|
||||
// returns -1 to close the connection
|
||||
// returns 1 to toggle to admin mode
|
||||
// returns 2 to toggle to config mode
|
||||
// returns 3 to toggle back to default mode
|
||||
static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
|
||||
const static char HELP_MSG[] = \
|
||||
"Usage\n\r" \
|
||||
"\n\r" \
|
||||
"help ................................. Show this help page\n\r" \
|
||||
"quit ................................. Terminate the console session\n\r" \
|
||||
"enable ............................... Enable admin mode\n\r" \
|
||||
"config ............................... Enter configuration mode\n\r" \
|
||||
"disable .............................. Disable admin/config mode\n\r" \
|
||||
;
|
||||
const static char CONFIG_INTRO_MSG[] = \
|
||||
"In configuration mode each command changing the configuration\n\r" \
|
||||
"will save changes directly to the EEPROM.\n\r" \
|
||||
"However, the system will only consider these changes after a\n\r" \
|
||||
"restart since only in this sitution the EEPROM is read.\n\r" \
|
||||
"\n\r" \
|
||||
;
|
||||
const static char GOODBYE_MSG[] = "Good bye\n\r";
|
||||
const static char OK_MSG[] = "OK\n\r";
|
||||
const static char FAILED_MSG[] = "Failed\n\r";
|
||||
const static char UNKNOWN_COMMAND[] = "Unknown command\n\r";
|
||||
uint8_t *messageToSend = NULL;
|
||||
|
||||
static bool adminMode = false;
|
||||
static bool configMode = false;
|
||||
|
||||
if (resetSpecialModes) {
|
||||
adminMode = false;
|
||||
configMode = false;
|
||||
}
|
||||
|
||||
cmd_t const * commands = getRegularCommands();
|
||||
if (adminMode) {
|
||||
commands = getAdminCommands();
|
||||
} else if (configMode) {
|
||||
commands = getConfigCommands();
|
||||
}
|
||||
|
||||
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
|
||||
|
||||
#define MAX_NUM_OF_ARGS 8
|
||||
char *args[MAX_NUM_OF_TASKS];
|
||||
uint8_t argc = 0;
|
||||
char *inCmdLine = (char*)cmdLine;
|
||||
do {
|
||||
args[argc++] = strtok(inCmdLine, " ");
|
||||
inCmdLine = NULL;
|
||||
} while (args[argc - 1] != NULL);
|
||||
if (argc > 0) {
|
||||
argc--;
|
||||
}
|
||||
char *cmd = args[0];
|
||||
|
||||
int8_t retCode = 0;
|
||||
coloredMsg(LOG_YELLOW, false, "ch cec cmd is %s, number of arguments %d", cmd, argc);
|
||||
|
||||
if (0 == strcmp(cmd, "quit")) {
|
||||
messageToSend = (uint8_t*)GOODBYE_MSG;
|
||||
retCode = -1;
|
||||
} else if (0 == strcmp(cmd, "help")) {
|
||||
if (configMode) {
|
||||
sendString(CONFIG_INTRO_MSG);
|
||||
}
|
||||
sendString(HELP_MSG);
|
||||
uint8_t cmdIdx = 0;
|
||||
while (true) {
|
||||
cmd_t command = commands[cmdIdx];
|
||||
if (0 == strcmp("END_OF_CMDS", command.name)) {
|
||||
break;
|
||||
}
|
||||
sendString(command.help);
|
||||
cmdIdx++;
|
||||
}
|
||||
messageToSend = NULL;
|
||||
} else if (0 == strcmp(cmd, "enable")) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch cec enable admin mode");
|
||||
adminMode = true;
|
||||
retCode = 1;
|
||||
} else if (0 == strcmp(cmd, "disable")) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode");
|
||||
adminMode = false;
|
||||
configMode = false;
|
||||
retCode = 3;
|
||||
} else if (0 == strcmp(cmd, "config")) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");
|
||||
configMode = true;
|
||||
retCode = 2;
|
||||
} else {
|
||||
uint8_t cmdIdx = 0;
|
||||
while (true) {
|
||||
cmd_t command = commands[cmdIdx];
|
||||
if (0 == strcmp("END_OF_CMDS", command.name)) {
|
||||
messageToSend = (uint8_t*) UNKNOWN_COMMAND;
|
||||
break;
|
||||
}
|
||||
if (0 == strcmp(cmd, command.name)) {
|
||||
messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
|
||||
break;
|
||||
}
|
||||
cmdIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (messageToSend) {
|
||||
send(CMD_SOCK, messageToSend, strlen((char*)messageToSend));
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static void cmdHandlerEngine(void *handle) {
|
||||
static uint8_t receiveBuffer[256];
|
||||
|
||||
static chState_t state = CH_INIT;
|
||||
static bool resetSpecialModes = false;
|
||||
|
||||
static char banner[] = \
|
||||
"MBGW3\n\r" \
|
||||
"Type help for usage help\n\r" \
|
||||
"or quit to close the connection.\n\r";
|
||||
|
||||
static char *prompt;
|
||||
static char defaultPrompt[] = "MBGW3 > ";
|
||||
static char adminPrompt[] = "MBGW3 (admin) # ";
|
||||
static char configPrompt[] = "MBGW3 (config) $ ";
|
||||
|
||||
|
||||
int8_t res = 0;
|
||||
uint8_t sockState;
|
||||
int32_t resultSend;
|
||||
int16_t receivedOctets;
|
||||
int32_t resultRecv;
|
||||
uint8_t resultDisconnect;
|
||||
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
switch (state) {
|
||||
case CH_INIT:
|
||||
coloredMsg(LOG_YELLOW, false, "ch che initializing socket");
|
||||
|
||||
res = socket(CMD_SOCK, Sn_MR_TCP, cmdPort, SF_IO_NONBLOCK);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket returns %d", res);
|
||||
|
||||
if (res == CMD_SOCK) {
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket is initialized");
|
||||
state = CH_LISTEN;
|
||||
} else {
|
||||
state = CH_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_LISTEN:
|
||||
coloredMsg(LOG_YELLOW, false, "ch che listening");
|
||||
|
||||
res = listen(CMD_SOCK);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che listen returns %d", res);
|
||||
|
||||
if (res == SOCK_OK) {
|
||||
coloredMsg(LOG_YELLOW, false, "ch che ok, waiting for established");
|
||||
state = CH_WAITING;
|
||||
} else {
|
||||
state = CH_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_WAITING:
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_LISTEN) {
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket state is 0x%02x", sockState);
|
||||
}
|
||||
|
||||
if (sockState == SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch che connection is established");
|
||||
state = CH_BANNER;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_BANNER:
|
||||
coloredMsg(LOG_YELLOW, false, "ch che send banner");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send banner", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
resultSend = send(CMD_SOCK, (uint8_t*)banner, strlen(banner));
|
||||
coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend);
|
||||
prompt = defaultPrompt;
|
||||
resetSpecialModes = true;
|
||||
state = CH_PROMPT;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_PROMPT:
|
||||
coloredMsg(LOG_YELLOW, false, "ch che send prompt");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send promt", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
resultSend = send(CMD_SOCK, (uint8_t*)prompt, strlen(prompt));
|
||||
coloredMsg(LOG_YELLOW, false, "ch che sent prompt %s, send returns 0x%02x", prompt, resultSend);
|
||||
state = CH_RECEIVE;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_RECEIVE:
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to receive something", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
receivedOctets = getSn_RX_RSR(CMD_SOCK);
|
||||
|
||||
if (receivedOctets > 0) {
|
||||
memset(receiveBuffer, 0, sizeof(receiveBuffer));
|
||||
resultRecv = recv(CMD_SOCK, receiveBuffer, sizeof(receiveBuffer));
|
||||
coloredMsg(LOG_YELLOW, false, "ch che recv returns 0x%02x", resultRecv);
|
||||
if (resultRecv > 0) {
|
||||
if ((receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0a) ||
|
||||
(receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0d)) {
|
||||
receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0;
|
||||
}
|
||||
if ((receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0a) ||
|
||||
(receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0d)) {
|
||||
receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0;
|
||||
}
|
||||
coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer);
|
||||
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetSpecialModes);
|
||||
resetSpecialModes = false;
|
||||
switch (resCEC) {
|
||||
case 0:
|
||||
state = CH_PROMPT;
|
||||
break;
|
||||
case -1:
|
||||
state = CH_DISCONNECT;
|
||||
break;
|
||||
case 1:
|
||||
prompt = adminPrompt;
|
||||
state = CH_PROMPT;
|
||||
break;
|
||||
case 2:
|
||||
prompt = configPrompt;
|
||||
state = CH_PROMPT;
|
||||
break;
|
||||
case 3:
|
||||
prompt = defaultPrompt;
|
||||
state = CH_PROMPT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_DISCONNECT:
|
||||
coloredMsg(LOG_YELLOW, true, "ch che close our end");
|
||||
resultDisconnect = disconnect(CMD_SOCK);
|
||||
coloredMsg(LOG_YELLOW, true, "ch che disconnect returns 0x%02x", resultDisconnect);
|
||||
state = CH_DISCONNECT_WAIT;
|
||||
break;
|
||||
|
||||
case CH_DISCONNECT_WAIT:
|
||||
//coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
//coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
|
||||
if (sockState == SOCK_CLOSED) {
|
||||
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
|
||||
state = CH_INIT;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CH_ERROR:
|
||||
coloredMsg(LOG_YELLOW, true, "ch che error state, will stop here");
|
||||
schDel(cmdHandlerEngine, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmdHandlerInit() {
|
||||
schAdd(cmdHandlerEngine, NULL, 0, 100);
|
||||
}
|
158
cube/User/Src/config.c
Normal file
158
cube/User/Src/config.c
Normal file
@ -0,0 +1,158 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <eeprom.h>
|
||||
#include <logger.h>
|
||||
#include <mbusComm.h>
|
||||
|
||||
|
||||
|
||||
#define NUM_OF_DEFAULT_DEVICES 8
|
||||
t_deviceBlock defaultDeviceBlock[] = {
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Total",
|
||||
.address = 80,
|
||||
.consideredField = { 0, 17, -1, -1 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Computer",
|
||||
.address = 85,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Dryer",
|
||||
.address = 81,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Laundry",
|
||||
.address = 82,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Dishwasher",
|
||||
.address = 83,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Light",
|
||||
.address = 84,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Freezer",
|
||||
.address = 86,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
},
|
||||
{
|
||||
.deviceMagic = DEVICE_MAGIC,
|
||||
.deviceName = "Fridge",
|
||||
.address = 87,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.period = 10,
|
||||
.filler = { 0, 0, 0 }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
t_configBlock defaultConfigBlock = {
|
||||
.configMagic = CONFIG_MAGIC,
|
||||
.deviceName = "MBGW3",
|
||||
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
||||
.frontendThreshold = 240,
|
||||
.brokerName = "mqttbroker",
|
||||
.watchdogTopic = "IoT/Watchdog",
|
||||
.startupTopic = "IoT/MBGW3/Startup",
|
||||
.statusTopic = "IoT/MBGW3/Status",
|
||||
.mbusDataTopic = "IoT/MBGW3/Measurement",
|
||||
.syslogServerName = "syslogserver",
|
||||
.numOfDeviceBlocks = NUM_OF_DEFAULT_DEVICES,
|
||||
.filler = { 0 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
t_configBlock mainConfigBlock;
|
||||
|
||||
|
||||
|
||||
t_configBlock* getConfig() {
|
||||
return &mainConfigBlock;
|
||||
}
|
||||
|
||||
|
||||
void configInit() {
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom");
|
||||
eepromReadConfigBlock(&mainConfigBlock);
|
||||
|
||||
if (mainConfigBlock.configMagic != CONFIG_MAGIC) {
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Invalid configuration block read from eeprom");
|
||||
|
||||
eepromWriteConfigBlock(&defaultConfigBlock);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Default configuration block written to eeprom");
|
||||
|
||||
for (uint8_t i = 0; i < NUM_OF_DEFAULT_DEVICES; i++) {
|
||||
eepromWriteDeviceBlock(i, &defaultDeviceBlock[i]);
|
||||
}
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Default device blocks written to eeprom");
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom again");
|
||||
eepromReadConfigBlock(&mainConfigBlock);
|
||||
}
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci configMagic: %lx", mainConfigBlock.configMagic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci deviceName: %s", mainConfigBlock.deviceName);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci MAC address: %02x:%02x:%02x:%02x:%02x:%02x", mainConfigBlock.macAddress[0],
|
||||
mainConfigBlock.macAddress[1],
|
||||
mainConfigBlock.macAddress[2],
|
||||
mainConfigBlock.macAddress[3],
|
||||
mainConfigBlock.macAddress[4],
|
||||
mainConfigBlock.macAddress[5]);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci frontend threshold: %ld", mainConfigBlock.frontendThreshold);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci broker: %s", mainConfigBlock.brokerName);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci watchdogTopic: %s", mainConfigBlock.watchdogTopic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci startupTopic: %s", mainConfigBlock.startupTopic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci statusTopic: %s", mainConfigBlock.statusTopic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci mbusDataTopic: %s", mainConfigBlock.mbusDataTopic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci syslog server: %s", mainConfigBlock.syslogServerName);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci device block cnt: %d", mainConfigBlock.numOfDeviceBlocks);
|
||||
|
||||
for (uint8_t i = 0; i < mainConfigBlock.numOfDeviceBlocks; i++) {
|
||||
t_deviceBlock tmpDeviceBlock;
|
||||
eepromReadDeviceBlock(i, &tmpDeviceBlock);
|
||||
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci device %d: ", i);
|
||||
coloredMsg(LOG_BLUE, false, " Name: %s, Address: %d, Period: %d",
|
||||
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
|
||||
coloredMsg(LOG_BLUE, false, " Considered Fields: %d %d %d %d",
|
||||
tmpDeviceBlock.consideredField[0],
|
||||
tmpDeviceBlock.consideredField[1],
|
||||
tmpDeviceBlock.consideredField[2],
|
||||
tmpDeviceBlock.consideredField[3]);
|
||||
mbusCommAddDevice(&tmpDeviceBlock);
|
||||
} else {
|
||||
coloredMsg(LOG_BLUE, false, "magic of device %d does not match, ignored", i);
|
||||
}
|
||||
}
|
||||
}
|
76
cube/User/Src/configCmds.c
Normal file
76
cube/User/Src/configCmds.c
Normal file
@ -0,0 +1,76 @@
|
||||
#include <cmdHelper.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <eeprom.h>
|
||||
#include <config.h>
|
||||
|
||||
|
||||
static bool showConfigCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
|
||||
t_configBlock configBlock;
|
||||
eepromReadConfigBlock(&configBlock);
|
||||
sendFormatString("configMagic: %lx\n\r", configBlock.configMagic);
|
||||
sendFormatString("deviceName: %s\n\r", configBlock.deviceName);
|
||||
sendFormatString("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n\r", configBlock.macAddress[0],
|
||||
configBlock.macAddress[1],
|
||||
configBlock.macAddress[2],
|
||||
configBlock.macAddress[3],
|
||||
configBlock.macAddress[4],
|
||||
configBlock.macAddress[5]);
|
||||
sendFormatString("frontend threshold: %ld\n\r", configBlock.frontendThreshold);
|
||||
sendFormatString("broker: %s\n\r", configBlock.brokerName);
|
||||
sendFormatString("watchdogTopic: %s\n\r", configBlock.watchdogTopic);
|
||||
sendFormatString("startupTopic: %s\n\r", configBlock.startupTopic);
|
||||
sendFormatString("statusTopic: %s\n\r", configBlock.statusTopic);
|
||||
sendFormatString("mbusDataTopic: %s\n\r", configBlock.mbusDataTopic);
|
||||
sendFormatString("syslog server: %s\n\r", configBlock.syslogServerName);
|
||||
sendFormatString("device block cnt: %d\n\r", configBlock.numOfDeviceBlocks);
|
||||
|
||||
for (uint8_t i = 0; i < configBlock.numOfDeviceBlocks; i++) {
|
||||
t_deviceBlock tmpDeviceBlock;
|
||||
eepromReadDeviceBlock(i, &tmpDeviceBlock);
|
||||
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
|
||||
sendFormatString("device %d: \n\r", i);
|
||||
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
|
||||
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
|
||||
sendFormatString(" Considered Fields: %d %d %d %d\n\r",
|
||||
tmpDeviceBlock.consideredField[0],
|
||||
tmpDeviceBlock.consideredField[1],
|
||||
tmpDeviceBlock.consideredField[2],
|
||||
tmpDeviceBlock.consideredField[3]);
|
||||
if (tmpDeviceBlock.deviceMagic != DEVICE_MAGIC) {
|
||||
sendString(" DEVICE MAGIC DOES NOT MATCH\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static bool restartCmd(uint8_t argc, char **args) {
|
||||
HAL_NVIC_SystemReset();
|
||||
// you want come here ...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const cmd_t CONFIG_COMMANDS[] = {
|
||||
{ .name = "show", .cmdFunc = showConfigCmd,
|
||||
.help = \
|
||||
"show ................................. Show the configuration\n\r"
|
||||
},
|
||||
{ .name = "restart", .cmdFunc = restartCmd,
|
||||
.help = \
|
||||
"restart .............................. Restart the system,\n\r" \
|
||||
" Required to reload config\n\r"
|
||||
},
|
||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
const cmd_t *getConfigCommands() {
|
||||
return CONFIG_COMMANDS;
|
||||
}
|
218
cube/User/Src/eeprom.c
Normal file
218
cube/User/Src/eeprom.c
Normal file
@ -0,0 +1,218 @@
|
||||
#include <main.h>
|
||||
#include <spi.h>
|
||||
#include <eeprom.h>
|
||||
#include <string.h>
|
||||
#include <logger.h>
|
||||
#include <mbusComm.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define HIGH GPIO_PIN_SET
|
||||
#define LOW GPIO_PIN_RESET
|
||||
|
||||
|
||||
|
||||
static const uint8_t EEPROM_READ = 0x03;
|
||||
static const uint8_t EEPROM_WRITE = 0x02;
|
||||
// static const uint8_t EEPROM_WRDI = 0x04;
|
||||
static const uint8_t EEPROM_WREN = 0x06;
|
||||
// static const uint8_t EEPROM_RDSR = 0x05;
|
||||
// static const uint8_t EEPROM_WRSR = 0x01;
|
||||
|
||||
|
||||
static const uint32_t EEPROM_MAGIC = 0xaffe0009;
|
||||
|
||||
|
||||
static const uint16_t EEPROM_HEADER_ADDR = EEPROM_BASE_ADDR;
|
||||
|
||||
|
||||
typedef union {
|
||||
t_eepromHeader s;
|
||||
uint8_t b[sizeof(struct s_eepromHeader)];
|
||||
} t_eepromHeaderBlock;
|
||||
|
||||
static t_eepromHeaderBlock eepromHeader;
|
||||
|
||||
|
||||
typedef union {
|
||||
t_deviceStats s;
|
||||
uint8_t b[sizeof(t_deviceStats)];
|
||||
} t_deviceStatsBlock;
|
||||
|
||||
static const uint16_t DEVICE_STATS_ADDR = EEPROM_DEVICE_STATS_ADDR;
|
||||
static t_deviceStatsBlock deviceStats;
|
||||
|
||||
static const uint16_t CONFIG_BLOCK_ADDR = EEPROM_CONFIG_BLOCK_ADDR;
|
||||
static const uint16_t DEVICE_BLOCK_ADDR = EEPROM_DEVICE_BLOCK_BASE_ADDR;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef union {
|
||||
struct __attribute__((__packed__)) s_spiMsg {
|
||||
uint8_t cmd;
|
||||
uint16_t addr;
|
||||
uint8_t data[32];
|
||||
} s;
|
||||
uint8_t b[sizeof(struct s_spiMsg)];
|
||||
} t_spiMsg;
|
||||
|
||||
t_deviceStats* getGlobalDeviceStats() {
|
||||
return &(deviceStats.s);
|
||||
}
|
||||
|
||||
inline static void __EEPROM_CS(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
|
||||
}
|
||||
|
||||
static uint16_t swap(uint16_t i) {
|
||||
return ((i & 0x00ff) << 8) | ((i & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
|
||||
// active waiting, use only during initialization!
|
||||
static void eepromActiveDelay(uint8_t delay_ms) {
|
||||
activeDelay(delay_ms);
|
||||
}
|
||||
|
||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
|
||||
t_spiMsg msg = {
|
||||
.s.cmd = EEPROM_WRITE,
|
||||
.s.addr = swap(addr)
|
||||
};
|
||||
memcpy(msg.s.data, buf, len);
|
||||
|
||||
|
||||
uint8_t writeEnable = EEPROM_WREN;
|
||||
__EEPROM_CS(LOW);
|
||||
HAL_SPI_Transmit(&eepromSpi, &writeEnable, 1, HAL_MAX_DELAY);
|
||||
__EEPROM_CS(HIGH);
|
||||
|
||||
__EEPROM_CS(LOW);
|
||||
HAL_SPI_Transmit(&eepromSpi, msg.b, ((uint16_t)(len+3)), HAL_MAX_DELAY);
|
||||
__EEPROM_CS(HIGH);
|
||||
}
|
||||
|
||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) {
|
||||
t_spiMsg txMsg = {
|
||||
.s.cmd = EEPROM_READ,
|
||||
.s.addr = swap(addr)
|
||||
};
|
||||
|
||||
t_spiMsg rxMsg;
|
||||
|
||||
__EEPROM_CS(LOW);
|
||||
HAL_SPI_TransmitReceive(&eepromSpi, txMsg.b, rxMsg.b, ((uint16_t)(len+3)), HAL_MAX_DELAY);
|
||||
__EEPROM_CS(HIGH);
|
||||
|
||||
memcpy(buf, rxMsg.s.data, len);
|
||||
}
|
||||
|
||||
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
|
||||
}
|
||||
|
||||
static void eepromHourlyUpdateDeviceStats(void *handle) {
|
||||
deviceStats.s.totalRunningHours += 1;
|
||||
|
||||
t_mbusCommStats *stats = mbusCommGetStats();
|
||||
|
||||
deviceStats.s.totalRequests += stats->mbusRequestCnt;
|
||||
deviceStats.s.totalFailures += stats->mbusErrorCnt;
|
||||
|
||||
logMsg("eeHUDS, about to write updated device stats");
|
||||
logMsg("eeHUDS, total powercycles so far: %d", deviceStats.s.totalPowercycles);
|
||||
logMsg("eeHUDS, total running hours so far: %d", deviceStats.s.totalRunningHours);
|
||||
logMsg("eeHUDS, total requests so far: %d", deviceStats.s.totalRequests);
|
||||
logMsg("eeHUDS, total failures so far: %d", deviceStats.s.totalFailures);
|
||||
|
||||
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
||||
}
|
||||
|
||||
void eepromReadConfigBlock(t_configBlock *destConfigBlock) {
|
||||
// static_assert((sizeof(*destConfigBlock) % EEPROM_WRITE_BLOCK_SIZE == 0), "config block has illegal size, must be dividable by 32");
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(*destConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
|
||||
eepromRead(CONFIG_BLOCK_ADDR + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)destConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void eepromWriteConfigBlock(t_configBlock *srcConfigBlock) {
|
||||
for (uint8_t i = 0; i < (sizeof(*srcConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
|
||||
eepromWrite(CONFIG_BLOCK_ADDR + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)srcConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE);
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void eepromReadDeviceBlock(uint8_t blockNum, t_deviceBlock *destDeviceBlock) {
|
||||
static_assert((sizeof(*destDeviceBlock) % EEPROM_WRITE_BLOCK_SIZE == 0), "device block has illegal size, must be dividable by 32");
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(*destDeviceBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
|
||||
eepromRead(DEVICE_BLOCK_ADDR + (blockNum * sizeof(*destDeviceBlock)) + (i * EEPROM_WRITE_BLOCK_SIZE),
|
||||
((uint8_t*)destDeviceBlock) + (i * EEPROM_WRITE_BLOCK_SIZE),
|
||||
EEPROM_WRITE_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void eepromWriteDeviceBlock(uint8_t blockNum, t_deviceBlock *srcDeviceBlock) {
|
||||
for (uint8_t i = 0; i < (sizeof(*srcDeviceBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
|
||||
eepromWrite(DEVICE_BLOCK_ADDR + (blockNum * sizeof(*srcDeviceBlock)) + (i * EEPROM_WRITE_BLOCK_SIZE),
|
||||
((uint8_t*)srcDeviceBlock) + (i * EEPROM_WRITE_BLOCK_SIZE),
|
||||
EEPROM_WRITE_BLOCK_SIZE);
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void eepromInit() {
|
||||
__EEPROM_CS(HIGH);
|
||||
|
||||
logMsg("eeI, read header");
|
||||
eepromRead(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader));
|
||||
logMsg("eeI, magic: %08x", eepromHeader.s.magic);
|
||||
|
||||
if (eepromHeader.s.magic != EEPROM_MAGIC) {
|
||||
logMsg("eeI, eeprom is uninitialized");
|
||||
|
||||
deviceStats.s.totalPowercycles = 0;
|
||||
deviceStats.s.totalRunningHours = 0;
|
||||
deviceStats.s.totalRequests = 0;
|
||||
deviceStats.s.totalFailures = 0;
|
||||
logMsg("eeI, about to write device stats for the first time");
|
||||
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
|
||||
uint8_t emptyBlock[EEPROM_WRITE_BLOCK_SIZE];
|
||||
memset(emptyBlock, 0, sizeof(emptyBlock));
|
||||
eepromWrite(CONFIG_BLOCK_ADDR, emptyBlock, EEPROM_WRITE_BLOCK_SIZE);
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
logMsg("eeI, config block initialized");
|
||||
|
||||
eepromHeader.s.magic = EEPROM_MAGIC;
|
||||
eepromHeader.s.writeCounter = 1;
|
||||
logMsg("eeI, about to write header for the first time");
|
||||
eepromWrite(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader));
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
logMsg("eeI, eeprom has been initialized");
|
||||
} else {
|
||||
logMsg("eeI, eeprom is initialized");
|
||||
}
|
||||
|
||||
logMsg("eeI, about to read device stats");
|
||||
eepromRead(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
||||
logMsg("eeI, total powercycles so far: %d", deviceStats.s.totalPowercycles);
|
||||
logMsg("eeI, total running hours so far: %d", deviceStats.s.totalRunningHours);
|
||||
logMsg("eeI, total requests so far: %d", deviceStats.s.totalRequests);
|
||||
logMsg("eeI, total failures so far: %d", deviceStats.s.totalFailures);
|
||||
|
||||
deviceStats.s.totalPowercycles += 1;
|
||||
logMsg("eeI, about to write device stats with updated power cycles counter");
|
||||
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
||||
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
|
||||
|
||||
schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 60 * 60 * 1000);
|
||||
logMsg("eeI, hourly device stats update scheduled");
|
||||
}
|
@ -5,10 +5,11 @@
|
||||
|
||||
#include <frontend.h>
|
||||
#include <logger.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <show.h>
|
||||
#include <config.h>
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
|
||||
static volatile int32_t frontendAdcThreshold = 0;
|
||||
@ -16,16 +17,15 @@ static volatile bool frontendEnabled = false;
|
||||
|
||||
|
||||
void frontendInit() {
|
||||
config = getConfig();
|
||||
frontendAdcThreshold = config->frontendThreshold;
|
||||
|
||||
HAL_ADCEx_Calibration_Start(&frontendAdc);
|
||||
logMsg("frontendInit, calibration done");
|
||||
HAL_ADC_Start_IT(&frontendAdc);
|
||||
logMsg("frontendInit, adc started");
|
||||
}
|
||||
|
||||
void frontendSetThreshold(int32_t threshold) {
|
||||
frontendAdcThreshold = threshold;
|
||||
}
|
||||
|
||||
void frontendEnable() {
|
||||
frontendEnabled = true;
|
||||
}
|
||||
@ -37,8 +37,6 @@ void frontendDisable() {
|
||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
|
||||
static int32_t holdValue = 0;
|
||||
|
||||
signal(DEBUG_2, TOGGLE);
|
||||
|
||||
if (frontendEnabled) {
|
||||
int32_t currentValue = (int32_t) HAL_ADC_GetValue(hadc);
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
#ifndef TEST
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <signal.h>
|
||||
#include <show.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#endif
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <wizHelper.h>
|
||||
#include <socket.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -11,23 +14,30 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
#include <stm32f103xe.h>
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
#include <stm32f1xx_hal_uart.h>
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
#define LOGBUFFER_SIZE 32
|
||||
#define MSGBUFFER_SIZE 16
|
||||
#else
|
||||
#define LOGBUFFER_SIZE 1024
|
||||
#define MSGBUFFER_SIZE 64
|
||||
#endif // TEST
|
||||
#define LOGBUFFER_SIZE 4096
|
||||
#define MSGBUFFER_SIZE 256
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
extern const uint8_t SYSLOG_SOCK;
|
||||
uint8_t syslogAddr[4];
|
||||
|
||||
uint8_t singleOctetTXBuffer;
|
||||
|
||||
static ringbuffer_t logBuffer;
|
||||
|
||||
void logInit() {
|
||||
config = getConfig();
|
||||
ringbufferInit(&logBuffer, LOGBUFFER_SIZE);
|
||||
}
|
||||
|
||||
@ -35,52 +45,154 @@ void logFree() {
|
||||
ringbufferFree(&logBuffer);
|
||||
}
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void debugTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
int c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
singleOctetTXBuffer = (uint8_t) c;
|
||||
HAL_UART_Transmit_IT(&debugUart, &singleOctetTXBuffer, 1);
|
||||
}
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
int logExec() {
|
||||
int c = -1;
|
||||
#ifndef TEST
|
||||
if (__HAL_UART_GET_FLAG(&debugUart, UART_FLAG_TXE)) { // is the TX channel free
|
||||
#endif // TEST
|
||||
c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
#ifndef TEST
|
||||
// transfer to TX channel
|
||||
uint8_t cc = (uint8_t) c;
|
||||
HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY);
|
||||
#endif // TEST
|
||||
}
|
||||
#ifndef TEST
|
||||
}
|
||||
#endif // TEST
|
||||
return c;
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#ifndef TEST
|
||||
static void flashGreenLed(void *handle) {
|
||||
signal(LED_GREEN, TOGGLE);
|
||||
void syslog(char *msg) {
|
||||
static uint8_t state = 0;
|
||||
int8_t res8 = 0;
|
||||
int32_t res32 = 0;
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
res8 = socket(SYSLOG_SOCK, Sn_MR_UDP, 514, SF_IO_NONBLOCK);
|
||||
if (res8 != SYSLOG_SOCK) {
|
||||
break;
|
||||
}
|
||||
state = 1;
|
||||
// no break
|
||||
case 1:
|
||||
if (! wizDnsQuery(config->syslogServerName, syslogAddr)) {
|
||||
disconnect(SYSLOG_SOCK);
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
state = 2;
|
||||
// no break
|
||||
case 2:
|
||||
res32 = sendto(SYSLOG_SOCK, (uint8_t*)msg, strlen(msg), syslogAddr, 514);
|
||||
if (res32 != strlen(msg)) {
|
||||
disconnect(SYSLOG_SOCK);
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // TEST
|
||||
|
||||
int logMsg(const char *format, ...) {
|
||||
static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const char *format, va_list vl) {
|
||||
const static char SYSLOG_HEADER[] = "<133>1 ";
|
||||
#define MAX_PREFIX_SIZE 20
|
||||
int res = -1;
|
||||
char msgBuffer[MSGBUFFER_SIZE];
|
||||
char msgBuffer[MSGBUFFER_SIZE+MAX_PREFIX_SIZE];
|
||||
char *bufferStart;
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int vcnt = vsnprintf(msgBuffer, MSGBUFFER_SIZE-2, format, vl);
|
||||
va_end(vl);
|
||||
memset(msgBuffer, 0, MSGBUFFER_SIZE+MAX_PREFIX_SIZE);
|
||||
|
||||
uint16_t syslogHeaderSize = strlen(SYSLOG_HEADER);
|
||||
uint16_t preSize = (pre) ? strlen(pre) : 0;
|
||||
uint16_t prefixSize = (syslogHeaderSize > preSize) ? syslogHeaderSize : preSize;
|
||||
if (prefixSize > MAX_PREFIX_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
bufferStart = msgBuffer + prefixSize;
|
||||
|
||||
int vcnt = vsnprintf(bufferStart, MSGBUFFER_SIZE, format, vl);
|
||||
if (vcnt < MSGBUFFER_SIZE) {
|
||||
strcat(msgBuffer, "\r\n");
|
||||
if (syslogToo) {
|
||||
memcpy(bufferStart - syslogHeaderSize, SYSLOG_HEADER, syslogHeaderSize);
|
||||
syslog(bufferStart - syslogHeaderSize);
|
||||
}
|
||||
|
||||
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
|
||||
#ifndef TEST
|
||||
// blink the green light or so
|
||||
flashGreenLed(NULL);
|
||||
schAdd(flashGreenLed, NULL, 100, 0);
|
||||
#else
|
||||
printf("\n*** green blink ***\n");
|
||||
#endif // TEST
|
||||
if (pre) {
|
||||
memcpy(bufferStart - preSize, pre, preSize);
|
||||
}
|
||||
if (post) {
|
||||
strcat(bufferStart - preSize, post);
|
||||
}
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
HAL_NVIC_DisableIRQ(UART4_IRQn);
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
res = ringbufferPut(&logBuffer, (uint8_t*) (bufferStart - preSize), strlen(bufferStart - preSize));
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
HAL_NVIC_EnableIRQ(UART4_IRQn);
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
debugTxCpltCallback(NULL);
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int logMsg(const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(NULL, "\r\n", false, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
|
||||
int coloredMsg(const t_logColor color, bool syslogToo, const char *format, ...) {
|
||||
const static char POST[] = "\x1b[0m\r\n";
|
||||
const static char HIGH[] = "\x1b[1m";
|
||||
const static char RED[] = "\x1b[31;1m";
|
||||
const static char GREEN[] = "\x1b[32;1m";
|
||||
const static char BLUE[] = "\x1b[34;1m";
|
||||
const static char YELLOW[] = "\x1b[33;1m";
|
||||
const char *pre = NULL;
|
||||
switch (color) {
|
||||
case LOG_HIGH:
|
||||
pre = HIGH;
|
||||
break;
|
||||
case LOG_RED:
|
||||
pre = RED;
|
||||
break;
|
||||
case LOG_BLUE:
|
||||
pre = BLUE;
|
||||
break;
|
||||
case LOG_GREEN:
|
||||
pre = GREEN;
|
||||
break;
|
||||
case LOG_YELLOW:
|
||||
pre = YELLOW;
|
||||
break;
|
||||
case LOG_NORMAL:
|
||||
pre = NULL;
|
||||
break;
|
||||
}
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(pre, POST, syslogToo, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <main.h>
|
||||
#include <loopCtrl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <show.h>
|
||||
#include <logger.h>
|
||||
#include <oled.h>
|
||||
|
||||
bool loopActive = false;
|
||||
|
||||
@ -9,18 +10,22 @@ void loopEnable() {
|
||||
loopActive = true;
|
||||
HAL_GPIO_WritePin(Loop_Enable_GPIO_Port, Loop_Enable_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Loop_Enable_GPIO_Port, Loop_Enable_Pin, GPIO_PIN_RESET);
|
||||
coloredMsg(LOG_HIGH, true, "lc le loop is enabled");
|
||||
oledPrint(OLED_SCREEN0, "loop enabled");
|
||||
}
|
||||
|
||||
void loopDisable() {
|
||||
HAL_GPIO_WritePin(Loop_Disable_GPIO_Port, Loop_Disable_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Loop_Disable_GPIO_Port, Loop_Disable_Pin, GPIO_PIN_RESET);
|
||||
loopActive = false;
|
||||
coloredMsg(LOG_HIGH, true, "lc ld loop is disabled");
|
||||
oledPrint(OLED_SCREEN0, "loop disabled");
|
||||
}
|
||||
|
||||
void loopStatusCallback() {
|
||||
GPIO_PinState status = HAL_GPIO_ReadPin(Loop_Status_GPIO_Port, Loop_Status_Pin);
|
||||
if (status == GPIO_PIN_SET) {
|
||||
signal(LED_RED, ON);
|
||||
show(LED_RED, ON);
|
||||
loopActive = false;
|
||||
}
|
||||
}
|
@ -6,47 +6,76 @@
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <adc.h>
|
||||
#include <spi.h>
|
||||
|
||||
#include <PontCoopScheduler.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <show.h>
|
||||
#include <loopCtrl.h>
|
||||
#include <mbusComm.h>
|
||||
#include <logger.h>
|
||||
#include <frontend.h>
|
||||
#include <eeprom.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mqttComm.h>
|
||||
#include <cmdHandler.h>
|
||||
#include <oled.h>
|
||||
#include <config.h>
|
||||
|
||||
|
||||
void my_setup_1() {
|
||||
schInit();
|
||||
logInit();
|
||||
showInit();
|
||||
}
|
||||
|
||||
void my_errorHandler() {
|
||||
signal(LED_RED, ON);
|
||||
}
|
||||
|
||||
void helloMeterbus(void *handle) {
|
||||
mbusCommRequest(0x5b, 80);
|
||||
// static char msg[] = "Hello";
|
||||
// HAL_UART_Transmit_IT(&mbusUart, &msg, strlen(msg));
|
||||
|
||||
show(LED_RED, ON);
|
||||
}
|
||||
|
||||
|
||||
void my_setup_2() {
|
||||
signal(LED_RED, OFF);
|
||||
signal(LED_GREEN, ON);
|
||||
show(LED_RED, OFF);
|
||||
show(LED_GREEN, BLINK);
|
||||
logMsg("Application starting");
|
||||
|
||||
oledInit();
|
||||
oledClearAllScreens();
|
||||
oledSetActiveScreen(OLED_SCREEN0);
|
||||
oledPrint(OLED_SCREEN0, "App starting");
|
||||
|
||||
eepromInit();
|
||||
oledPrint(OLED_SCREEN0, "eeprom init");
|
||||
|
||||
configInit();
|
||||
oledPrint(OLED_SCREEN0, "config init");
|
||||
|
||||
wizInit();
|
||||
oledPrint(OLED_SCREEN0, "network init");
|
||||
|
||||
mqttCommInit();
|
||||
oledPrint(OLED_SCREEN0, "mqtt init");
|
||||
cmdHandlerInit();
|
||||
oledPrint(OLED_SCREEN0, "cmdhandler init");
|
||||
|
||||
frontendInit();
|
||||
frontendSetThreshold(240);
|
||||
oledPrint(OLED_SCREEN0, "frontend init");
|
||||
|
||||
schAdd(helloMeterbus, NULL, 0, 1000);
|
||||
mbusCommInit();
|
||||
oledPrint(OLED_SCREEN0, "Meterbus init");
|
||||
oledPrint(OLED_SCREEN0, "App running");
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
signal(DEBUG_1, TOGGLE);
|
||||
// show(DEBUG_2, TOGGLE);
|
||||
|
||||
schExec();
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
logExec();
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
mbusCommExec();
|
||||
}
|
||||
|
||||
void SYSTICK_Callback() {
|
||||
@ -59,7 +88,6 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
if (hadc == &frontendAdc) {
|
||||
frontendAdcCallback(hadc);
|
||||
@ -67,7 +95,15 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
}
|
||||
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
if (huart == &mbusUart) {
|
||||
mbusCommTxCpltCallback(huart);
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
if (huart == &debugUart) {
|
||||
debugTxCpltCallback(huart);
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
}
|
||||
|
||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
if (hspi == &eepromSpi) {
|
||||
eepromSpiTxCpltCallback(hspi);
|
||||
}
|
||||
}
|
@ -1,116 +1,824 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <mbusComm.h>
|
||||
#include <loopCtrl.h>
|
||||
#include <signal.h>
|
||||
#include <show.h>
|
||||
#include <logger.h>
|
||||
#include <frontend.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mbusParserExt.h>
|
||||
#include <mqttComm.h>
|
||||
#include <oled.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
static const uint8_t MBUS_QUERY_CMD = 0x5b;
|
||||
|
||||
// Delay between end of last bit of sent request telegram
|
||||
// and enabling the frontend for receiving the response.
|
||||
// Standard says client must wait at least 11 bit times.
|
||||
// 1 / 2400 * 11 = 4.5e-3ms
|
||||
static const uint32_t DELAY_AFTER_SENDING = 4; // ms
|
||||
|
||||
typedef enum {
|
||||
IDLE,
|
||||
SEND,
|
||||
SEND_CONT,
|
||||
SENDING,
|
||||
SENDING_DONE,
|
||||
ENABLE_FRONTEND,
|
||||
DISABLE_FRONTEND
|
||||
MBCR_SUCCESS = 0,
|
||||
MBCR_ERROR_TIMEOUT,
|
||||
MBCR_ERROR_LOOP_FAILURE,
|
||||
MBCR_ERROR_TX_REG_UNACCESSIBLE,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__FRAME,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__USERDATA,
|
||||
MBCR_ERROR_STATE_ENGINE__START1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH2,
|
||||
MBCR_ERROR_STATE_ENGINE__START2,
|
||||
MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM,
|
||||
MBCR_ERROR_STATE_ENGINE__STOP,
|
||||
MBCR_ERROR_STATE_ENGINE__ILLEGAL_STATE,
|
||||
MBCR_ERROR_STATE_ENGINE__UNKNOWN
|
||||
} e_mbusCommResult;
|
||||
|
||||
typedef enum {
|
||||
MBCS_IDLE,
|
||||
MBCS_SEND,
|
||||
MBCS_SEND_CONTINUED,
|
||||
MBCS_SENDING,
|
||||
MBCS_SENDING_DONE,
|
||||
MBCS_WAIT_AFTER_SENDING,
|
||||
MBCS_ENABLE_FRONTEND,
|
||||
MBCS_START1,
|
||||
MBCS_LENGTH1,
|
||||
MBCS_LENGTH2,
|
||||
MBCS_START2,
|
||||
MBCS_C_FIELD,
|
||||
MBCS_A_FIELD,
|
||||
MBCS_CI_FIELD,
|
||||
MBCS_USERDATA,
|
||||
MBCS_CHKSUM,
|
||||
MBCS_STOP,
|
||||
MBCS_DONE,
|
||||
MBCS_TIMEOUT,
|
||||
MBCS_DISABLE_FRONTEND,
|
||||
MBCS_ERROR,
|
||||
MBCS_ERROR_CONTINUED
|
||||
} e_mbusCommState;
|
||||
|
||||
typedef struct {
|
||||
uint8_t start1;
|
||||
uint8_t length1;
|
||||
uint8_t length2;
|
||||
uint8_t start2;
|
||||
uint8_t l;
|
||||
uint8_t c;
|
||||
uint8_t a;
|
||||
uint8_t ci;
|
||||
uint8_t *userdata;
|
||||
uint8_t chksum;
|
||||
uint8_t stop;
|
||||
} t_longframe;
|
||||
|
||||
typedef struct {
|
||||
uint16_t size;
|
||||
uint16_t readIdx;
|
||||
uint16_t writeIdx;
|
||||
uint8_t *buffer;
|
||||
} linearBuffer_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t requestId;
|
||||
e_mbusCommState state;
|
||||
uint8_t retryCnt;
|
||||
uint8_t cmd;
|
||||
uint8_t addr;
|
||||
uint8_t sendBuf[5];
|
||||
linearBuffer_t sendBuffer;
|
||||
linearBuffer_t receiveBuffer;
|
||||
uint32_t startTime;
|
||||
uint8_t receiveCnt;
|
||||
bool waitForOctet;
|
||||
e_mbusCommResult result;
|
||||
t_longframe frame;
|
||||
t_mbusDevice *device;
|
||||
} t_mbusCommHandle;
|
||||
|
||||
static t_mbusCommHandle mbusCommHandle = { .state = IDLE, .retryCnt = 0, .cmd = 0, .addr = 0 };
|
||||
|
||||
static t_mbusCommHandle mbusCommHandle = { .requestId = 0, .state = MBCS_IDLE, .retryCnt = 0, .cmd = 0, .addr = 0, .startTime = 0, .receiveCnt = 0, .waitForOctet = false };
|
||||
|
||||
static t_mbusCommStats mbusCommStats = { .mbusRequestCnt = 0, .mbusErrorCnt = 0, .uartOctetCnt = 0, .uartOverrunCnt = 0, .uartFramingErrCnt = 0, .uartParityErrCnt = 0, .uartNoiseErrCnt = 0 };
|
||||
|
||||
static bool mbusCommEnabled = true;
|
||||
|
||||
void mbusCommSetStats(t_mbusCommStats stats) {
|
||||
mbusCommStats = stats;
|
||||
}
|
||||
|
||||
t_mbusCommStats *mbusCommGetStats() {
|
||||
return &mbusCommStats;
|
||||
}
|
||||
|
||||
|
||||
static void handleRequestEngine(void *handle) {
|
||||
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
|
||||
static void printError() {
|
||||
float errorRatio = ((float) mbusCommHandle.device->failures) / ((float) mbusCommHandle.device->requests);
|
||||
coloredMsg(LOG_YELLOW, true, "mbc pe [%d] Error ratio is %.2f",
|
||||
mbusCommHandle.requestId,
|
||||
errorRatio);
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
|
||||
oledPrintf(OLED_SCREEN0, "Err:%d/%d %.2f", mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
|
||||
}
|
||||
|
||||
switch (localMbusCommHandle->state) {
|
||||
case IDLE:
|
||||
logMsg("hre state IDLE");
|
||||
|
||||
|
||||
static void parseAndPrintFrame() {
|
||||
t_longframe *frame = &(mbusCommHandle.frame);
|
||||
|
||||
mbus_frame reply;
|
||||
memset(&reply, 0, sizeof(reply));
|
||||
|
||||
//mbus_parse(&reply, buf, len);
|
||||
reply.start1 = frame->start1;
|
||||
reply.length1 = frame->length1;
|
||||
reply.length2 = frame->length2;
|
||||
reply.start2 = frame->start2;
|
||||
reply.control = frame->c;
|
||||
reply.address = frame->a;
|
||||
reply.control_information = frame->ci;
|
||||
memcpy(reply.data, frame->userdata, frame->length1 - 3);
|
||||
reply.checksum = frame->chksum;
|
||||
reply.stop = frame->stop;
|
||||
reply.type = MBUS_FRAME_TYPE_LONG;
|
||||
reply.data_size = frame->length1 - 3;
|
||||
|
||||
mbus_frame_data frame_data;
|
||||
memset(&frame_data, 0, sizeof(frame_data));
|
||||
|
||||
int r = mbus_frame_data_parse(&reply, &frame_data);
|
||||
if (r == 0) {
|
||||
mbus_data_variable *data_var = &(frame_data.data_var);
|
||||
if (data_var->header.status) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: %02x", mbusCommHandle.requestId, data_var->header.status);
|
||||
}
|
||||
if ((data_var->header.status & 0x01)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Application Busy", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x02)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Any Application Error", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x04)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Power Low", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x08)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Permanent Error", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x10)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Temporary Error", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x20)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 1", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x40)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 2", mbusCommHandle.requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x80)) {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 3", mbusCommHandle.requestId);
|
||||
}
|
||||
mbus_data_record *record;
|
||||
int i;
|
||||
const char *keys[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
float values[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
uint8_t numOfConsideredFields = 0;
|
||||
for (record = data_var->record, i = 0;
|
||||
record;
|
||||
record = record->next, i++) {
|
||||
for (uint8_t j = 0; j < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; j++) {
|
||||
if (mbusCommHandle.device->consideredField[j] == i) {
|
||||
parsedVIB_t parsedVIB = parseVIB(record->drh.vib);
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
|
||||
// mbusCommHandle.requestId,
|
||||
// parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
|
||||
if (parsedVIB.found) {
|
||||
uint32_t value = strtol(mbus_data_record_value(record), NULL, 10);
|
||||
float weightedValue = ((float) value) * powf(10.0, ((float) parsedVIB.exponent));
|
||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] %s is %.1f %s (%d * 10^%d)",
|
||||
mbusCommHandle.requestId, parsedVIB.name, weightedValue, parsedVIB.unit,
|
||||
value, parsedVIB.exponent);
|
||||
keys[numOfConsideredFields] = parsedVIB.name;
|
||||
values[numOfConsideredFields] = weightedValue;
|
||||
numOfConsideredFields++;
|
||||
} else {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] L:%d, VIF: 0x%02x U:%s V:%s",
|
||||
mbusCommHandle.requestId,
|
||||
mbusCommHandle.device->consideredField[j],
|
||||
record->drh.vib.vif,
|
||||
mbus_data_record_unit(record),
|
||||
mbus_data_record_value(record));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
float errorRatio = ((float) mbusCommHandle.device->failures) / ((float) mbusCommHandle.device->requests);
|
||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] Error ratio is %.2f",
|
||||
mbusCommHandle.requestId,
|
||||
errorRatio);
|
||||
if (numOfConsideredFields == 1) {
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0]);
|
||||
} else if (numOfConsideredFields == 2) {
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1]);
|
||||
} else if (numOfConsideredFields == 3) {
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1], keys[2], values[2]);
|
||||
} else if (numOfConsideredFields == 4) {
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3]);
|
||||
}
|
||||
oledPrintf(OLED_SCREEN0, "Ok:%d/%d %.2f", mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
|
||||
mbus_data_record_free(data_var->record);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", mbusCommHandle.requestId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mbusCommISR() {
|
||||
uint32_t isrflags = READ_REG(mbusUart.Instance->SR);
|
||||
uint32_t cr1its = READ_REG(mbusUart.Instance->CR1);
|
||||
|
||||
// RXNEIE doesn't need to be considered since it is always on and more over the
|
||||
// RXNE flag is cleared by reading the DR, which is done in any case
|
||||
if (((isrflags & USART_SR_RXNE) != RESET) || ((isrflags & (USART_SR_ORE | USART_SR_FE | USART_SR_PE | USART_SR_NE)) != RESET)) {
|
||||
// Error flags are only valid together with the RX flag.
|
||||
// They will be cleared by reading SR (already done above) followed by reading DR (below).
|
||||
bool errorFound = false;
|
||||
if ((isrflags & USART_SR_ORE) != RESET) {
|
||||
mbusCommStats.uartOverrunCnt += 1;
|
||||
errorFound = true;
|
||||
}
|
||||
if ((isrflags & USART_SR_FE) != RESET) {
|
||||
mbusCommStats.uartFramingErrCnt += 1;
|
||||
errorFound = true;
|
||||
}
|
||||
if ((isrflags & USART_SR_PE) != RESET) {
|
||||
mbusCommStats.uartParityErrCnt += 1;
|
||||
errorFound = true;
|
||||
}
|
||||
if ((isrflags & USART_SR_NE) != RESET) {
|
||||
mbusCommStats.uartNoiseErrCnt += 1;
|
||||
errorFound = true;
|
||||
}
|
||||
mbusCommStats.uartOctetCnt += 1;
|
||||
// it is required to read the DR in any case here, not only when the buffer has space
|
||||
// otherwise the interrupt flag won't be reset, particularly important in case of ORE
|
||||
uint8_t data = (uint8_t)(mbusUart.Instance->DR & (uint8_t)0x00FF);
|
||||
if ((! errorFound) &&
|
||||
(mbusCommHandle.receiveBuffer.writeIdx < mbusCommHandle.receiveBuffer.size)) {
|
||||
mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.writeIdx] = data;
|
||||
mbusCommHandle.receiveBuffer.writeIdx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// TXEIE needs to be considered since TXE is cleared by writing the DR, which isn't done
|
||||
// after the last octet sent
|
||||
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) {
|
||||
if (mbusCommHandle.sendBuffer.readIdx < mbusCommHandle.sendBuffer.writeIdx) {
|
||||
mbusUart.Instance->DR = mbusCommHandle.sendBuffer.buffer[mbusCommHandle.sendBuffer.readIdx];
|
||||
mbusCommHandle.sendBuffer.readIdx += 1;
|
||||
if (mbusCommHandle.sendBuffer.readIdx == mbusCommHandle.sendBuffer.writeIdx) {
|
||||
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TXE);
|
||||
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// advance the state for the engine only when the last octet is shifted out completely
|
||||
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) {
|
||||
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TC);
|
||||
mbusCommHandle.state = MBCS_SENDING_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mbusCommExec() {
|
||||
static uint8_t userdataIdx = 0;
|
||||
static uint8_t calculatedChksum = 0;
|
||||
uint8_t receivedOctet = 0;
|
||||
static uint32_t delayAfterSendStartTime = 0;
|
||||
|
||||
if ((mbusCommHandle.startTime != 0) && ((mbusCommHandle.startTime + 2500) < HAL_GetTick())) {
|
||||
mbusCommHandle.state = MBCS_TIMEOUT;
|
||||
} else if (mbusCommHandle.waitForOctet) {
|
||||
if (mbusCommHandle.receiveBuffer.readIdx >= mbusCommHandle.receiveBuffer.writeIdx) {
|
||||
return; // no data available, wait
|
||||
}
|
||||
receivedOctet = mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.readIdx];
|
||||
mbusCommHandle.receiveBuffer.readIdx += 1;
|
||||
mbusCommHandle.waitForOctet = false;
|
||||
}
|
||||
|
||||
switch (mbusCommHandle.state) {
|
||||
case MBCS_IDLE:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state IDLE", mbusCommHandle.requestId);
|
||||
break;
|
||||
|
||||
case SEND:
|
||||
logMsg("hre state SEND");
|
||||
localMbusCommHandle->sendBuf[0] = 0x10;
|
||||
localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd;
|
||||
localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr;
|
||||
localMbusCommHandle->sendBuf[3] = localMbusCommHandle->cmd + localMbusCommHandle->addr; // checksum
|
||||
localMbusCommHandle->sendBuf[4] = 0x16;
|
||||
localMbusCommHandle->state = SEND_CONT;
|
||||
case MBCS_SEND:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", mbusCommHandle.requestId);
|
||||
mbusCommHandle.sendBuffer.buffer[0] = 0x10;
|
||||
mbusCommHandle.sendBuffer.buffer[1] = mbusCommHandle.cmd;
|
||||
mbusCommHandle.sendBuffer.buffer[2] = mbusCommHandle.addr;
|
||||
mbusCommHandle.sendBuffer.buffer[3] = mbusCommHandle.cmd + mbusCommHandle.addr; // checksum
|
||||
mbusCommHandle.sendBuffer.buffer[4] = 0x16;
|
||||
mbusCommHandle.sendBuffer.readIdx = 0;
|
||||
mbusCommHandle.sendBuffer.writeIdx = 5;
|
||||
mbusCommHandle.state = MBCS_SEND_CONTINUED;
|
||||
// no break !!
|
||||
|
||||
case SEND_CONT:
|
||||
logMsg("hre state SEND_CONT");
|
||||
signal(LED_RED, OFF);
|
||||
case MBCS_SEND_CONTINUED:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", mbusCommHandle.requestId);
|
||||
show(LED_RED, OFF);
|
||||
if (! loopActive) {
|
||||
logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt);
|
||||
localMbusCommHandle->retryCnt++;
|
||||
coloredMsg(LOG_YELLOW, true, "mbc hre [%d] enabling loop, try %d", mbusCommHandle.requestId, mbusCommHandle.retryCnt);
|
||||
mbusCommHandle.retryCnt++;
|
||||
loopEnable();
|
||||
schAdd(handleRequestEngine, handle, 10, 0); // give 10ms to settled the loop
|
||||
} else {
|
||||
localMbusCommHandle->retryCnt = 0;
|
||||
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
|
||||
localMbusCommHandle->state = SENDING;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
// enable transmitter interrupt
|
||||
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] enable transmitter interrupt", mbusCommHandle.requestId);
|
||||
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TXE);
|
||||
mbusCommHandle.state = MBCS_SENDING;
|
||||
}
|
||||
break;
|
||||
|
||||
// transition from SENDING to SENDING_DONE is initiate by mbusCommTxCpltCallback
|
||||
// interrupt callback
|
||||
case SENDING:
|
||||
logMsg("hre state SENDING");
|
||||
case MBCS_SENDING:
|
||||
// transition from here to MBCS_SENDING_DONE is done by TX ISR
|
||||
break;
|
||||
|
||||
case SENDING_DONE:
|
||||
logMsg("hre state SENDING_DONE");
|
||||
localMbusCommHandle->state = ENABLE_FRONTEND;
|
||||
schAdd(handleRequestEngine, handle, 3, 0);
|
||||
case MBCS_SENDING_DONE:
|
||||
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", mbusCommHandle.requestId);
|
||||
delayAfterSendStartTime = HAL_GetTick();
|
||||
mbusCommHandle.state = MBCS_WAIT_AFTER_SENDING;
|
||||
break;
|
||||
|
||||
case ENABLE_FRONTEND:
|
||||
logMsg("hre state ENABLE_FRONTEND");
|
||||
case MBCS_WAIT_AFTER_SENDING:
|
||||
// Avoids switching on the frontend while there is still noise from sending on the loop
|
||||
// Make sure to wait not too long otherwise the beginning of the response is missed
|
||||
if ((delayAfterSendStartTime + DELAY_AFTER_SENDING) < HAL_GetTick()) {
|
||||
mbusCommHandle.state = MBCS_ENABLE_FRONTEND;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_ENABLE_FRONTEND:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", mbusCommHandle.requestId);
|
||||
frontendEnable();
|
||||
localMbusCommHandle->state = DISABLE_FRONTEND;
|
||||
schAdd(handleRequestEngine, handle, 500, 0);
|
||||
calculatedChksum = 0;
|
||||
userdataIdx = 0;
|
||||
mbusCommHandle.receiveBuffer.readIdx = 0;
|
||||
mbusCommHandle.receiveBuffer.writeIdx = 0;
|
||||
mbusCommHandle.waitForOctet = true; // start receiver
|
||||
mbusCommHandle.startTime = HAL_GetTick(); // start receiver timeout
|
||||
mbusCommHandle.state = MBCS_START1;
|
||||
break;
|
||||
|
||||
case DISABLE_FRONTEND:
|
||||
logMsg("hre state DISABLE_FRONTEND");
|
||||
case MBCS_START1:
|
||||
if (receivedOctet == 0x68) {
|
||||
mbusCommHandle.frame.start1 = receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_LENGTH1;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start1 symbol %02x", mbusCommHandle.requestId, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__START1;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_LENGTH1:
|
||||
if (receivedOctet <= 3) {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: length to small %02x", mbusCommHandle.requestId, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__LENGTH1;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
} else {
|
||||
mbusCommHandle.frame.length1 = receivedOctet;
|
||||
mbusCommHandle.frame.userdata = (uint8_t*) malloc(mbusCommHandle.frame.length1 - 3);
|
||||
if (! mbusCommHandle.frame.userdata) {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: unable to allocate memory for userdata", mbusCommHandle.requestId);
|
||||
mbusCommHandle.result = MBCR_ERROR_OUT_OF_MEMORY__USERDATA;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
} else {
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_LENGTH2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_LENGTH2:
|
||||
if (mbusCommHandle.frame.length1 != receivedOctet) {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid length2 %02x vs. %02x",
|
||||
mbusCommHandle.requestId, mbusCommHandle.frame.length1, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__LENGTH2;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
} else {
|
||||
mbusCommHandle.frame.length2 = receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_START2;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_START2:
|
||||
if (receivedOctet == 0x68) {
|
||||
mbusCommHandle.frame.start2 = receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_C_FIELD;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start2 symbol %02x",
|
||||
mbusCommHandle.requestId, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__START2;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_C_FIELD:
|
||||
mbusCommHandle.frame.c = receivedOctet;
|
||||
calculatedChksum += receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_A_FIELD;
|
||||
break;
|
||||
|
||||
case MBCS_A_FIELD:
|
||||
mbusCommHandle.frame.a = receivedOctet;
|
||||
calculatedChksum += receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_CI_FIELD;
|
||||
break;
|
||||
|
||||
case MBCS_CI_FIELD:
|
||||
mbusCommHandle.frame.ci = receivedOctet;
|
||||
calculatedChksum += receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_USERDATA;
|
||||
break;
|
||||
|
||||
case MBCS_USERDATA:
|
||||
mbusCommHandle.frame.userdata[userdataIdx] = receivedOctet;
|
||||
calculatedChksum += receivedOctet;
|
||||
userdataIdx++;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
if (userdataIdx == (mbusCommHandle.frame.length1 - 3)) {
|
||||
mbusCommHandle.state = MBCS_CHKSUM;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_CHKSUM:
|
||||
if (receivedOctet != calculatedChksum) {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid checksum %02x vs %02x",
|
||||
mbusCommHandle.requestId, calculatedChksum, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
} else {
|
||||
mbusCommHandle.frame.chksum = receivedOctet;
|
||||
mbusCommHandle.waitForOctet = true;
|
||||
mbusCommHandle.state = MBCS_STOP;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_STOP:
|
||||
if (receivedOctet == 0x16) {
|
||||
mbusCommHandle.frame.stop = receivedOctet;
|
||||
mbusCommHandle.state = MBCS_DONE;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid stop symbol %02x",
|
||||
mbusCommHandle.requestId, receivedOctet);
|
||||
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__STOP;
|
||||
mbusCommHandle.state = MBCS_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_DONE:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DONE", mbusCommHandle.requestId);
|
||||
parseAndPrintFrame();
|
||||
if (mbusCommHandle.frame.userdata != NULL) {
|
||||
free(mbusCommHandle.frame.userdata);
|
||||
mbusCommHandle.frame.userdata = NULL;
|
||||
}
|
||||
mbusCommHandle.result = MBCR_SUCCESS;
|
||||
mbusCommHandle.state = MBCS_DISABLE_FRONTEND;
|
||||
break;
|
||||
|
||||
case MBCS_ERROR:
|
||||
// coloredMsg(LOG_RED, false, "mbc hre [%d] state ERROR", mbusCommHandle.requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] error", mbusCommHandle.requestId);
|
||||
show(LED_RED, ON);
|
||||
// disable frontend immediately in case of error since no more data in relevant
|
||||
// this avoids strange noise on RX line/led
|
||||
frontendDisable();
|
||||
localMbusCommHandle->state = IDLE;
|
||||
mbusCommHandle.state = MBCS_ERROR_CONTINUED;
|
||||
// no break
|
||||
|
||||
case MBCS_ERROR_CONTINUED:
|
||||
// every error will be collected by a timeout to receive all data still on the wire
|
||||
// to avoid leaking old data in responses for new requests
|
||||
break;
|
||||
|
||||
case MBCS_TIMEOUT:
|
||||
// coloredMsg(LOG_RED, false, "mbc hre [%d] state TIMEOUT", mbusCommHandle.requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] timeout", mbusCommHandle.requestId);
|
||||
mbusCommStats.mbusErrorCnt += 1;
|
||||
mbusCommHandle.device->failures += 1;
|
||||
mbusCommHandle.startTime = 0; // disable timeout
|
||||
mbusCommHandle.waitForOctet = false; // disable receiver
|
||||
printError();
|
||||
if (mbusCommHandle.frame.userdata != NULL) {
|
||||
free(mbusCommHandle.frame.userdata);
|
||||
mbusCommHandle.frame.userdata = NULL;
|
||||
}
|
||||
// no break
|
||||
|
||||
case MBCS_DISABLE_FRONTEND:
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DISABLE_FRONTEND", mbusCommHandle.requestId);
|
||||
frontendDisable();
|
||||
mbusCommHandle.startTime = 0; // disable timeout
|
||||
mbusCommHandle.state = MBCS_IDLE;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
localMbusCommHandle->state = IDLE;
|
||||
mbusCommHandle.state = MBCS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
logMsg("mctx: mbus tx done");
|
||||
if (mbusCommHandle.state == SENDING) {
|
||||
mbusCommHandle.state = SENDING_DONE;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
}
|
||||
void mbusCommEnable(bool enable) {
|
||||
mbusCommEnabled = enable;
|
||||
}
|
||||
|
||||
void mbusCommRequest(uint8_t cmd, uint8_t addr) {
|
||||
if (mbusCommHandle.state == IDLE) {
|
||||
mbusCommHandle.state = SEND;
|
||||
static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
e_mbusCommRequestResult res = MBCRR_BUSY;
|
||||
|
||||
if (mbusCommEnabled) {
|
||||
if (mbusCommHandle.state == MBCS_IDLE) {
|
||||
mbusCommHandle.requestId += 1;
|
||||
mbusCommHandle.state = MBCS_SEND;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
mbusCommHandle.cmd = cmd;
|
||||
mbusCommHandle.addr = addr;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
mbusCommHandle.cmd = MBUS_QUERY_CMD;
|
||||
mbusCommHandle.addr = mbusDevice->address;
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
mbusDevice->requests += 1;
|
||||
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcr [%d] new request %s",
|
||||
mbusCommHandle.requestId,
|
||||
mbusDevice->deviceName);
|
||||
|
||||
oledPrint(OLED_SCREEN0, mbusDevice->deviceName);
|
||||
res = MBCRR_TRIGGERED;
|
||||
|
||||
mbusCommStats.mbusRequestCnt += 1;
|
||||
}
|
||||
} else {
|
||||
// busy
|
||||
res = MBCRR_DISABLED;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#define PERIOD 10
|
||||
|
||||
static uint8_t numOfDevices = 0;
|
||||
static t_mbusDevice *devices = NULL;
|
||||
|
||||
void mbusCommAddDevice(t_deviceBlock *deviceBlock) {
|
||||
devices = (t_mbusDevice*) realloc((void*) devices, (numOfDevices + 1) * sizeof(t_mbusDevice));
|
||||
strcpy(devices[numOfDevices].deviceName, deviceBlock->deviceName);
|
||||
devices[numOfDevices].address = deviceBlock->address;
|
||||
memcpy(devices[numOfDevices].consideredField, deviceBlock->consideredField, sizeof(deviceBlock->consideredField));
|
||||
devices[numOfDevices].period = deviceBlock->period;
|
||||
devices[numOfDevices].requests = 0;
|
||||
devices[numOfDevices].failures = 0;
|
||||
devices[numOfDevices].delay = 0;
|
||||
devices[numOfDevices].waiting = false;
|
||||
devices[numOfDevices].active = true;
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mbcad device added %d %s %d", numOfDevices, devices[numOfDevices].deviceName, devices[numOfDevices].address);
|
||||
numOfDevices += 1;
|
||||
}
|
||||
|
||||
/*
|
||||
static t_mbusDevice devices[] = {
|
||||
{
|
||||
.deviceName = "Total",
|
||||
.address = 80,
|
||||
.consideredField = { 0, 17, -1, -1 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Computer",
|
||||
.address = 85,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Dryer",
|
||||
.address = 81,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Laundry",
|
||||
.address = 82,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Dishwasher",
|
||||
.address = 83,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Light",
|
||||
.address = 84,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Freezer",
|
||||
.address = 86,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
},
|
||||
{
|
||||
.deviceName = "Fridge",
|
||||
.address = 87,
|
||||
.consideredField = { 0, 4, 2, 3 },
|
||||
.requests = 0,
|
||||
.failures = 0,
|
||||
.period = PERIOD,
|
||||
.delay = 0,
|
||||
.waiting = false,
|
||||
.active = true
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
static void triggerMBusRequest(void *handle) {
|
||||
static uint8_t deviceIndex = 0;
|
||||
|
||||
if (devices[deviceIndex].waiting) {
|
||||
e_mbusCommRequestResult r = mbusCommRequest(&(devices[deviceIndex]));
|
||||
if (r == MBCRR_TRIGGERED) {
|
||||
devices[deviceIndex].waiting = false;
|
||||
deviceIndex++;
|
||||
}
|
||||
} else {
|
||||
deviceIndex++;
|
||||
}
|
||||
if (deviceIndex >= numOfDevices) {
|
||||
deviceIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void mbusCommScheduler(void *handle) {
|
||||
static uint8_t state = 0;
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (isNetworkAvailable()) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcs activate scheduler by network");
|
||||
schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||
state = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (mbusCommEnabled) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcs activate scheduler by request");
|
||||
schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||
state = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (! isNetworkAvailable()) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcs deactivate scheduler by network");
|
||||
schDel(triggerMBusRequest, NULL);
|
||||
loopDisable();
|
||||
state = 0;
|
||||
}
|
||||
if (! mbusCommEnabled) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcs deactivate scheduler by request");
|
||||
schDel(triggerMBusRequest, NULL);
|
||||
loopDisable();
|
||||
state = 1;
|
||||
}
|
||||
for (uint8_t i = 0; i < numOfDevices; i++) {
|
||||
if (devices[i].active) {
|
||||
devices[i].delay -= 1;
|
||||
if (devices[i].delay <= 0) {
|
||||
devices[i].delay = devices[i].period;
|
||||
devices[i].waiting = true;
|
||||
coloredMsg(LOG_YELLOW, false, "mbc mcs scheduled: %s", devices[i].deviceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// state = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
coloredMsg(LOG_YELLOW, false, "mbc mcs waiting for godot");
|
||||
state = 4;
|
||||
// no break
|
||||
|
||||
case 4:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void mbusCommInit() {
|
||||
config = getConfig();
|
||||
|
||||
coloredMsg(LOG_GREEN, true, "mbc mci initializing Meterbus communication");
|
||||
|
||||
// enable receive interrupts
|
||||
// __HAL_UART_ENABLE_IT(&mbusUart, UART_IT_PE);
|
||||
// __HAL_UART_ENABLE_IT(&mbusUart, UART_IT_ERR);
|
||||
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_RXNE);
|
||||
|
||||
// init buffers
|
||||
mbusCommHandle.receiveBuffer.size = 256;
|
||||
mbusCommHandle.receiveBuffer.buffer = (uint8_t*) malloc(mbusCommHandle.receiveBuffer.size);
|
||||
mbusCommHandle.receiveBuffer.readIdx = 0;
|
||||
mbusCommHandle.receiveBuffer.writeIdx = 0;
|
||||
|
||||
mbusCommHandle.sendBuffer.size = 8;
|
||||
mbusCommHandle.sendBuffer.buffer = (uint8_t*) malloc(mbusCommHandle.sendBuffer.size);
|
||||
mbusCommHandle.sendBuffer.readIdx = 0;
|
||||
mbusCommHandle.sendBuffer.writeIdx = 0;
|
||||
|
||||
|
||||
// FIXME
|
||||
schAdd(mbusCommScheduler, NULL, 0, 1000);
|
||||
}
|
||||
|
85
cube/User/Src/mbusParserExt.c
Normal file
85
cube/User/Src/mbusParserExt.c
Normal file
@ -0,0 +1,85 @@
|
||||
#include <mbus/mbus-protocol.h>
|
||||
#include <mbusParserExt.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
|
||||
static const char NAME_VOLTAGE[] = "Voltage";
|
||||
static const char NAME_CURRENT[] = "Current";
|
||||
static const char NAME_POWER[] = "Power";
|
||||
static const char NAME_ENERGY[] = "Energy";
|
||||
static const char NAME_UNKNOWN[] = "unknown";
|
||||
|
||||
static const char UNIT_VOLT[] = "V";
|
||||
static const char UNIT_AMPERE[] = "A";
|
||||
static const char UNIT_WATT[] = "W";
|
||||
static const char UNIT_WATTHOUR[] = "Wh";
|
||||
static const char UNIT_UNKNOWN[] = "?";
|
||||
|
||||
static parsedVIB_t parseVIB_FB(mbus_value_information_block vib) {
|
||||
parsedVIB_t parsedVIB = { .name = NAME_UNKNOWN, .unit = UNIT_UNKNOWN, .exponent = 1, .found = false };
|
||||
|
||||
coloredMsg(LOG_RED, true, "mpe pvd_fb unknown vife 0x%02x", vib.vife[0]);
|
||||
|
||||
return parsedVIB;
|
||||
}
|
||||
|
||||
static parsedVIB_t parseVIB_FD(mbus_value_information_block vib) {
|
||||
parsedVIB_t parsedVIB = { .name = NAME_UNKNOWN, .unit = UNIT_UNKNOWN, .exponent = 1, .found = false };
|
||||
|
||||
if ((vib.vife[0] & 0b01110000) == 0b01000000) {
|
||||
parsedVIB.name = NAME_VOLTAGE;
|
||||
parsedVIB.unit = UNIT_VOLT;
|
||||
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 9;
|
||||
parsedVIB.found = true;
|
||||
} else if ((vib.vife[0] & 0b01110000) == 0b01010000) {
|
||||
parsedVIB.name = NAME_CURRENT;
|
||||
parsedVIB.unit = UNIT_AMPERE;
|
||||
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 12;
|
||||
parsedVIB.found = true;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mpe pvd_fd unknown vife 0x%02x", vib.vife[0]);
|
||||
}
|
||||
|
||||
return parsedVIB;
|
||||
}
|
||||
|
||||
static parsedVIB_t parseVIB_default(mbus_value_information_block vib) {
|
||||
parsedVIB_t parsedVIB = { .name = NAME_UNKNOWN, .unit = UNIT_UNKNOWN, .exponent = 1, .found = false };
|
||||
|
||||
if ((vib.vif & 0b01111000) == 0b00000000) {
|
||||
parsedVIB.name = NAME_ENERGY;
|
||||
parsedVIB.unit = UNIT_WATTHOUR;
|
||||
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
||||
parsedVIB.found = true;
|
||||
} else if ((vib.vif & 0b01111000) == 0b00101000) {
|
||||
parsedVIB.name = NAME_POWER;
|
||||
parsedVIB.unit = UNIT_WATT;
|
||||
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
||||
parsedVIB.found = true;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mpe pvd unknown vif 0x%02x", vib.vif);
|
||||
}
|
||||
|
||||
return parsedVIB;
|
||||
}
|
||||
|
||||
|
||||
parsedVIB_t parseVIB(mbus_value_information_block vib) {
|
||||
parsedVIB_t parsedVIB;
|
||||
|
||||
if (vib.vif == 0xfb) {
|
||||
parsedVIB = parseVIB_FB(vib);
|
||||
} else if (vib.vif == 0xfd) {
|
||||
parsedVIB = parseVIB_FD(vib);
|
||||
} else {
|
||||
parsedVIB = parseVIB_default(vib);
|
||||
}
|
||||
|
||||
return parsedVIB;
|
||||
}
|
||||
|
180
cube/User/Src/mqttComm.c
Normal file
180
cube/User/Src/mqttComm.c
Normal file
@ -0,0 +1,180 @@
|
||||
#include <mqttComm.h>
|
||||
#include <logger.h>
|
||||
#include <main.h>
|
||||
|
||||
#include <pubsubc.h>
|
||||
#include <platformAdaption.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mbusComm.h>
|
||||
#include <oled.h>
|
||||
#include <eeprom.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern const uint8_t MQTT_SOCK;
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
client_t client;
|
||||
mqttClient_t mqttClient;
|
||||
|
||||
uint8_t brokerAddress[4];
|
||||
uint16_t brokerPort = 1883;
|
||||
|
||||
static uint32_t watchdogCounter = 0;
|
||||
|
||||
void watchdogHandler(void *handle) {
|
||||
if (watchdogCounter > 0) {
|
||||
coloredMsg(LOG_GREEN, false, "Watchdog received in between");
|
||||
watchdogCounter = 0;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "No watchdog received in between, booting the system ...");
|
||||
// boot the system
|
||||
}
|
||||
}
|
||||
|
||||
// typedef void (*callback_t)(char*, uint8_t*, uint16_t);
|
||||
static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) {
|
||||
if (0 == strcmp(topic, config->watchdogTopic)) {
|
||||
watchdogCounter++;
|
||||
} else {
|
||||
coloredMsg(LOG_GREEN, false, "mqcb: %s : %.*s", topic, payloadLength, payload);
|
||||
}
|
||||
}
|
||||
|
||||
static void mqttStatusPublisher(void *handle) {
|
||||
coloredMsg(LOG_GREEN, false, "mqsp: publishing status");
|
||||
t_mbusCommStats *mbusCommStats = mbusCommGetStats();
|
||||
t_deviceStats* globalDeviceStats = getGlobalDeviceStats();
|
||||
|
||||
char buf[256];
|
||||
uint32_t uptime = HAL_GetTick() / 1000;
|
||||
snprintf(buf, sizeof(buf), "{\"uptime\":\"%ld\", \"runningHours\":\"%ld\", \"powerCycles\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\", \"octets\":\"%ld\", \"overrun\":\"%ld\", \"framing\":\"%ld\", \"parity\":\"%ld\", \"noise\":\"%ld\"}",
|
||||
uptime, globalDeviceStats->totalRunningHours, globalDeviceStats->totalPowercycles, schTaskCnt(), mbusCommStats->mbusRequestCnt, mbusCommStats->mbusErrorCnt,
|
||||
mbusCommStats->uartOctetCnt, mbusCommStats->uartOverrunCnt, mbusCommStats->uartFramingErrCnt, mbusCommStats->uartParityErrCnt, mbusCommStats->uartNoiseErrCnt);
|
||||
bool res = publish(&mqttClient, config->statusTopic, (const uint8_t*)buf, strlen(buf), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
|
||||
oledSetActiveScreen(OLED_SCREEN1);
|
||||
oledClearActiveScreen();
|
||||
uint8_t *addr = wizGetIPAddress();
|
||||
oledPrintf(OLED_SCREEN1, "Addr:%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
|
||||
oledPrintf(OLED_SCREEN1, "Network available:%d", isNetworkAvailable());
|
||||
oledPrintf(OLED_SCREEN1, "Uptime:%ld", uptime);
|
||||
oledPrintf(OLED_SCREEN1, "PowerCycl:%d", globalDeviceStats->totalPowercycles);
|
||||
oledPrintf(OLED_SCREEN1, "Req:%ld", mbusCommStats->mbusRequestCnt);
|
||||
oledPrintf(OLED_SCREEN1, "Err:%ld", mbusCommStats->mbusErrorCnt);
|
||||
oledPrintf(OLED_SCREEN1, "Uart:%d", mbusCommStats->uartOverrunCnt + mbusCommStats->uartFramingErrCnt + mbusCommStats->uartParityErrCnt + mbusCommStats->uartNoiseErrCnt);
|
||||
}
|
||||
|
||||
void mqttCommHandler(void *handle) {
|
||||
static uint8_t state = 0;
|
||||
static uint8_t message[] = "MeterbusGateway3Variant starting";
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, initializing mqtt client");
|
||||
client.sockNum = MQTT_SOCK;
|
||||
mqttClientInit(&mqttClient, &client, mqttCallback);
|
||||
coloredMsg(LOG_GREEN, false, "mqch: mqtt client initialized");
|
||||
|
||||
state = 1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, resolving broker name");
|
||||
if (! wizDnsQuery(config->brokerName, brokerAddress)) {
|
||||
coloredMsg(LOG_GREEN, false, "mqch, query for broker address failed, going to error state");
|
||||
state = 255;
|
||||
}
|
||||
coloredMsg(LOG_GREEN, false, "mqch, connecting to broker ");
|
||||
bool res = mqttConnect(&mqttClient, brokerAddress, 1883, "mbv3gw-client", NULL, NULL, NULL, 0, false, NULL, false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, mqttConnect returns %d", res);
|
||||
|
||||
if (res) {
|
||||
coloredMsg(LOG_GREEN, false, "mqch, ok, connected");
|
||||
state = 2;
|
||||
} else {
|
||||
state = 255;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish start-up");
|
||||
res = publish(&mqttClient, config->startupTopic, (const uint8_t*)message, strlen((char*)message), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
schAdd(mqttStatusPublisher, NULL, 0, 60000);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, status publisher scheduled");
|
||||
state = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, subscribe watchdog");
|
||||
res = subscribe(&mqttClient, config->watchdogTopic, MQTTQOS0);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, subscribe returned %d", res);
|
||||
schAdd(watchdogHandler, NULL, 60000, 60000);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, watchdogHandler scheduled");
|
||||
state = 4;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, now entering the loop");
|
||||
state = 5;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (! mqttLoop(&mqttClient)) {
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 255:
|
||||
coloredMsg(LOG_RED, true, "mqch, error state, will stop here");
|
||||
schDel(mqttCommHandler, NULL);
|
||||
schDel(watchdogHandler, NULL);
|
||||
coloredMsg(LOG_RED, true, "mqch, trying again in one minute");
|
||||
schAdd(mqttCommHandler, NULL, 60000, 100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mqttCommInit() {
|
||||
config = getConfig();
|
||||
schAdd(mqttCommHandler, NULL, 0, 100);
|
||||
}
|
||||
|
||||
void mqttPublish(const char *topic, char *message) {
|
||||
bool res = false;
|
||||
if (isNetworkAvailable()) {
|
||||
res = publish(&mqttClient, topic, (const uint8_t*)message, strlen(message), false);
|
||||
}
|
||||
if (res) {
|
||||
coloredMsg(LOG_GREEN, false, "mqp: %s -> %s successfully published", message, topic);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mqp: %s -> %s failed to publish", message, topic);
|
||||
}
|
||||
}
|
||||
|
||||
void mqttPublishf(const char *topic, char *messageFormat, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, messageFormat);
|
||||
char buf[2048];
|
||||
int res = vsnprintf(buf, sizeof(buf), messageFormat, vl);
|
||||
va_end(vl);
|
||||
if (res < sizeof(buf)) {
|
||||
mqttPublish(topic, buf);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mqc mpf buffer overflow, truncated message not published");
|
||||
}
|
||||
}
|
||||
|
||||
|
461
cube/User/Src/oled.c
Normal file
461
cube/User/Src/oled.c
Normal file
@ -0,0 +1,461 @@
|
||||
/*
|
||||
* Code found at http://www.instructables.com/id/How-to-use-OLED-display-arduino-module/
|
||||
* Thank you very much!
|
||||
* Adapted from Arduino to STM32 HAL by wollud1969
|
||||
*/
|
||||
|
||||
#include <main.h>
|
||||
#include <spi.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <oled.h>
|
||||
#include <oled-fonts.h>
|
||||
#include <stm32f1xx_hal.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
|
||||
|
||||
#define HIGH GPIO_PIN_SET
|
||||
#define LOW GPIO_PIN_RESET
|
||||
|
||||
static void __LEDPIN_RST(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(Display_RES_GPIO_Port, Display_RES_Pin, v);
|
||||
}
|
||||
|
||||
static void __LEDPIN_DC(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(Display_DC_GPIO_Port, Display_DC_Pin, v);
|
||||
}
|
||||
|
||||
static void __LEDPIN_CS(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(Display_CS_GPIO_Port, Display_CS_Pin, v);
|
||||
}
|
||||
|
||||
static void oled_WrDat(unsigned char data)
|
||||
{
|
||||
__LEDPIN_CS(LOW);
|
||||
__LEDPIN_DC(HIGH);
|
||||
|
||||
HAL_SPI_Transmit(&displaySpi, &data, 1, 0);
|
||||
|
||||
__LEDPIN_CS(HIGH);
|
||||
}
|
||||
|
||||
static void oled_WrCmd(unsigned char cmd)
|
||||
{
|
||||
__LEDPIN_CS(LOW);
|
||||
__LEDPIN_DC(LOW);
|
||||
|
||||
HAL_SPI_Transmit(&displaySpi, &cmd, 1, 0);
|
||||
|
||||
__LEDPIN_CS(HIGH);
|
||||
}
|
||||
|
||||
static void oled_Set_Pos(unsigned char x, unsigned char y)
|
||||
{
|
||||
oled_WrCmd(0xb0+y);
|
||||
oled_WrCmd(((x&0xf0)>>4)|0x10);
|
||||
oled_WrCmd((x&0x0f)|0x00);
|
||||
}
|
||||
|
||||
|
||||
static void oled_Fill(unsigned char bmp_data)
|
||||
{
|
||||
unsigned char y,x;
|
||||
|
||||
for(y=0;y<8;y++)
|
||||
{
|
||||
oled_WrCmd(0xb0+y);
|
||||
oled_WrCmd(0x00);
|
||||
oled_WrCmd(0x10);
|
||||
for(x=0;x<128;x++)
|
||||
oled_WrDat(bmp_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void oled_CLS(void)
|
||||
{
|
||||
unsigned char y,x;
|
||||
for(y=0;y<8;y++)
|
||||
{
|
||||
oled_WrCmd(0xb0+y);
|
||||
oled_WrCmd(0x00);
|
||||
oled_WrCmd(0x10);
|
||||
for(x=0;x<128;x++)
|
||||
oled_WrDat(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void oled_DLY_ms(unsigned int ms)
|
||||
{
|
||||
uint32_t start = HAL_GetTick();
|
||||
while (HAL_GetTick() < start + ms);
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void SetStartColumn(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0x00+d%16); // Set Lower Column Start Address for Page Addressing Mode
|
||||
// Default => 0x00
|
||||
oled_WrCmd(0x10+d/16); // Set Higher Column Start Address for Page Addressing Mode
|
||||
// Default => 0x10
|
||||
}
|
||||
*/
|
||||
|
||||
static void SetAddressingMode(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0x20); // Set Memory Addressing Mode
|
||||
oled_WrCmd(d); // Default => 0x02
|
||||
// 0x00 => Horizontal Addressing Mode
|
||||
// 0x01 => Vertical Addressing Mode
|
||||
// 0x02 => Page Addressing Mode
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void SetColumnAddress(unsigned char a, unsigned char b)
|
||||
{
|
||||
oled_WrCmd(0x21); // Set Column Address
|
||||
oled_WrCmd(a); // Default => 0x00 (Column Start Address)
|
||||
oled_WrCmd(b); // Default => 0x7F (Column End Address)
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* unused
|
||||
static void SetPageAddress(unsigned char a, unsigned char b)
|
||||
{
|
||||
oled_WrCmd(0x22); // Set Page Address
|
||||
oled_WrCmd(a); // Default => 0x00 (Page Start Address)
|
||||
oled_WrCmd(b); // Default => 0x07 (Page End Address)
|
||||
}
|
||||
*/
|
||||
|
||||
static void SetStartLine(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0x40|d); // Set Display Start Line
|
||||
// Default => 0x40 (0x00)
|
||||
}
|
||||
|
||||
static void SetContrastControl(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0x81); // Set Contrast Control
|
||||
oled_WrCmd(d); // Default => 0x7F
|
||||
}
|
||||
|
||||
static void Set_Charge_Pump(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0x8D); // Set Charge Pump
|
||||
oled_WrCmd(0x10|d); // Default => 0x10
|
||||
// 0x10 (0x00) => Disable Charge Pump
|
||||
// 0x14 (0x04) => Enable Charge Pump
|
||||
}
|
||||
|
||||
static void Set_Segment_Remap(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xA0|d); // Set Segment Re-Map
|
||||
// Default => 0xA0
|
||||
// 0xA0 (0x00) => Column Address 0 Mapped to SEG0
|
||||
// 0xA1 (0x01) => Column Address 0 Mapped to SEG127
|
||||
}
|
||||
|
||||
static void Set_Entire_Display(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xA4|d); // Set Entire Display On / Off
|
||||
// Default => 0xA4
|
||||
// 0xA4 (0x00) => Normal Display
|
||||
// 0xA5 (0x01) => Entire Display On
|
||||
}
|
||||
|
||||
static void Set_Inverse_Display(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xA6|d); // Set Inverse Display On/Off
|
||||
// Default => 0xA6
|
||||
// 0xA6 (0x00) => Normal Display
|
||||
// 0xA7 (0x01) => Inverse Display On
|
||||
}
|
||||
|
||||
static void Set_Multiplex_Ratio(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xA8); // Set Multiplex Ratio
|
||||
oled_WrCmd(d); // Default => 0x3F (1/64 Duty)
|
||||
}
|
||||
|
||||
static void Set_Display_On_Off(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xAE|d); // Set Display On/Off
|
||||
// Default => 0xAE
|
||||
// 0xAE (0x00) => Display Off
|
||||
// 0xAF (0x01) => Display On
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void SetStartPage(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xB0|d); // Set Page Start Address for Page Addressing Mode
|
||||
// Default => 0xB0 (0x00)
|
||||
}
|
||||
*/
|
||||
|
||||
static void Set_Common_Remap(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xC0|d); // Set COM Output Scan Direction
|
||||
// Default => 0xC0
|
||||
// 0xC0 (0x00) => Scan from COM0 to 63
|
||||
// 0xC8 (0x08) => Scan from COM63 to 0
|
||||
}
|
||||
|
||||
static void Set_Display_Offset(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xD3); // Set Display Offset
|
||||
oled_WrCmd(d); // Default => 0x00
|
||||
}
|
||||
|
||||
static void Set_Display_Clock(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xD5); // Set Display Clock Divide Ratio / Oscillator Frequency
|
||||
oled_WrCmd(d); // Default => 0x80
|
||||
// D[3:0] => Display Clock Divider
|
||||
// D[7:4] => Oscillator Frequency
|
||||
}
|
||||
|
||||
static void Set_Precharge_Period(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xD9); // Set Pre-Charge Period
|
||||
oled_WrCmd(d); // Default => 0x22 (2 Display Clocks [Phase 2] / 2 Display Clocks [Phase 1])
|
||||
// D[3:0] => Phase 1 Period in 1~15 Display Clocks
|
||||
// D[7:4] => Phase 2 Period in 1~15 Display Clocks
|
||||
}
|
||||
|
||||
static void Set_Common_Config(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xDA); // Set COM Pins Hardware Configuration
|
||||
oled_WrCmd(0x02|d); // Default => 0x12 (0x10)
|
||||
// Alternative COM Pin Configuration
|
||||
// Disable COM Left/Right Re-Map
|
||||
}
|
||||
|
||||
static void Set_VCOMH(unsigned char d)
|
||||
{
|
||||
oled_WrCmd(0xDB); // Set VCOMH Deselect Level
|
||||
oled_WrCmd(d); // Default => 0x20 (0.77*VCC)
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void Set_NOP(void)
|
||||
{
|
||||
oled_WrCmd(0xE3); // Command for No Operation
|
||||
}
|
||||
*/
|
||||
|
||||
void oledInit(void)
|
||||
{
|
||||
// LEDPIN_Init();
|
||||
// LED_PORT=0X0F;
|
||||
//LED_SCLH;;;
|
||||
//LED_RSTL;;;
|
||||
//digitalWrite(SCL_PIN,HIGH);;;
|
||||
__LEDPIN_RST(LOW);
|
||||
// for(i=0;i<100;i++)asm("nop");
|
||||
oled_DLY_ms(50);
|
||||
//LED_RSTH;;;
|
||||
__LEDPIN_RST(HIGH);
|
||||
|
||||
Set_Display_On_Off(0x00); // Display Off (0x00/0x01)
|
||||
Set_Display_Clock(0x80); // Set Clock as 100 Frames/Sec
|
||||
Set_Multiplex_Ratio(0x3F); // 1/64 Duty (0x0F~0x3F)
|
||||
Set_Display_Offset(0x00); // Shift Mapping RAM Counter (0x00~0x3F)
|
||||
SetStartLine(0x00); // Set Mapping RAM Display Start Line (0x00~0x3F)
|
||||
Set_Charge_Pump(0x04); // Enable Embedded DC/DC Converter (0x00/0x04)
|
||||
SetAddressingMode(0x02); // Set Page Addressing Mode (0x00/0x01/0x02)
|
||||
Set_Segment_Remap(0x01); // Set SEG/Column Mapping
|
||||
Set_Common_Remap(0x08); // Set COM/Row Scan Direction
|
||||
Set_Common_Config(0x10); // Set Sequential Configuration (0x00/0x10)
|
||||
SetContrastControl(0xCF); // Set SEG Output Current
|
||||
Set_Precharge_Period(0xF1); // Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
|
||||
Set_VCOMH(0x40); // Set VCOM Deselect Level
|
||||
Set_Entire_Display(0x00); // Disable Entire Display On (0x00/0x01)
|
||||
Set_Inverse_Display(0x00); // Disable Inverse Display On (0x00/0x01)
|
||||
Set_Display_On_Off(0x01); // Display On (0x00/0x01)
|
||||
oled_Fill(0x00); //clear all
|
||||
oled_Set_Pos(0,0);
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void oled_P6x8Char(unsigned char x,unsigned char y,unsigned char ch)
|
||||
{
|
||||
unsigned char c=0,i=0;
|
||||
|
||||
c =ch-32;
|
||||
if(x>122)
|
||||
{
|
||||
x=0;
|
||||
y++;
|
||||
}
|
||||
oled_Set_Pos(x,y);
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
oled_WrDat(F6x8[c][i]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
static void oled_P6x8Str(unsigned char x,unsigned char y,char ch[])
|
||||
{
|
||||
// coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
|
||||
|
||||
unsigned char c=0,i=0,j=0;
|
||||
while (ch[j]!='\0')
|
||||
{
|
||||
c =ch[j]-32;
|
||||
if(x>126)
|
||||
{
|
||||
x=0;
|
||||
y++;
|
||||
}
|
||||
oled_Set_Pos(x,y);
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
oled_WrDat(F6x8[c][i]);
|
||||
}
|
||||
x+=6;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void oled_P8x16Str(unsigned char x,unsigned char y,char ch[])
|
||||
{
|
||||
unsigned char c=0,i=0,j=0;
|
||||
while (ch[j]!='\0')
|
||||
{
|
||||
c =ch[j]-32;
|
||||
if(x>120)
|
||||
{
|
||||
x=0;
|
||||
y++;
|
||||
}
|
||||
oled_Set_Pos(x,y);
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
oled_WrDat(F8X16[(c<<4)+i]);
|
||||
}
|
||||
oled_Set_Pos(x,y+1);
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
oled_WrDat(F8X16[(c<<4)+i+8]);
|
||||
}
|
||||
x+=8;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void oled_PrintBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char bmp[])
|
||||
{
|
||||
int ii=0;
|
||||
unsigned char x,y;
|
||||
for(y=y0;y<=y1;y++)
|
||||
{
|
||||
oled_Set_Pos(x0,y);
|
||||
for(x=x0;x<x1;x++)
|
||||
{
|
||||
oled_WrDat(bmp[ii++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* unused
|
||||
static void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row)
|
||||
{
|
||||
if(cursor_row != 0)
|
||||
{
|
||||
if(cursor_column == 1) oled_Set_Pos(0, cursor_row + 2);
|
||||
else oled_Set_Pos(80 + (cursor_column - 2)*6, cursor_row + 2);
|
||||
oled_WrDat(0xFF);
|
||||
oled_WrDat(0xFF);
|
||||
oled_WrDat(0xFF);
|
||||
oled_WrDat(0xFF);
|
||||
oled_WrDat(0xFF);
|
||||
oled_WrDat(0xFF);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#define MAX_LINES 8
|
||||
#define MAX_CHARS 21
|
||||
#define NUM_OF_SCREENS 2
|
||||
|
||||
static uint8_t currentLine = 0;
|
||||
static char lines[NUM_OF_SCREENS][MAX_LINES+1][MAX_CHARS+1];
|
||||
static oledScreen_t activeScreen = OLED_SCREEN0;
|
||||
|
||||
void oledClearActiveScreen() {
|
||||
oled_CLS();
|
||||
memset(lines[activeScreen], 0, sizeof(lines[activeScreen]));
|
||||
currentLine = 0;
|
||||
}
|
||||
|
||||
void oledClearAllScreens() {
|
||||
oled_CLS();
|
||||
memset(lines, 0, sizeof(lines));
|
||||
currentLine = 0;
|
||||
}
|
||||
|
||||
void oledPrint(oledScreen_t screen, char msg[]) {
|
||||
if (currentLine < MAX_LINES) {
|
||||
strncpy(lines[screen][currentLine], msg, MAX_CHARS);
|
||||
memset(lines[screen][currentLine] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
|
||||
lines[screen][currentLine][MAX_CHARS - 1] = 0;
|
||||
currentLine++;
|
||||
} else {
|
||||
for (uint8_t i = 1; i < MAX_LINES; i++) {
|
||||
memcpy(lines[screen][i-1], lines[screen][i], MAX_CHARS);
|
||||
}
|
||||
strncpy(lines[screen][MAX_LINES - 1], msg, MAX_CHARS);
|
||||
memset(lines[screen][MAX_LINES - 1] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
|
||||
lines[screen][MAX_LINES - 1][MAX_CHARS - 1] = 0;
|
||||
}
|
||||
|
||||
if (screen == activeScreen) {
|
||||
for (uint8_t line = 0; line < MAX_LINES; line++) {
|
||||
oled_P6x8Str(1, line, lines[activeScreen][line]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void oledSwitchBackToScreen0(void *handle) {
|
||||
oledSetActiveScreen(OLED_SCREEN0);
|
||||
}
|
||||
|
||||
void oledSetActiveScreen(oledScreen_t screen) {
|
||||
activeScreen = screen;
|
||||
if (screen == OLED_SCREEN1) {
|
||||
schAdd(oledSwitchBackToScreen0, NULL, 10000, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void oledPrintf(oledScreen_t screen, const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
char buf[MAX_CHARS+1];
|
||||
vsnprintf(buf, MAX_CHARS, format, vl);
|
||||
va_end(vl);
|
||||
oledPrint(screen, buf);
|
||||
}
|
11
cube/User/Src/ports.c
Normal file
11
cube/User/Src/ports.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// on the W5500 there are eight ports available
|
||||
|
||||
const uint8_t DHCP_SOCK = 0;
|
||||
const uint8_t MQTT_SOCK = 1;
|
||||
const uint8_t CMD_SOCK = 2;
|
||||
const uint8_t SYSLOG_SOCK = 3;
|
||||
const uint8_t DNS_SOCK = 4;
|
57
cube/User/Src/regularCmds.c
Normal file
57
cube/User/Src/regularCmds.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <cmdHelper.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <mbusComm.h>
|
||||
#include <eeprom.h>
|
||||
|
||||
|
||||
static bool globalStatsCmd(uint8_t argc, char **args) {
|
||||
uint32_t uptime = HAL_GetTick() / 1000;
|
||||
sendFormatString(\
|
||||
"Current uptime: %ld\n\r" \
|
||||
"\n\r",
|
||||
uptime
|
||||
);
|
||||
|
||||
t_deviceStats *deviceStats = getGlobalDeviceStats();
|
||||
sendFormatString(\
|
||||
"Global Device statistics\n\r" \
|
||||
" Total running hours: %ld\n\r" \
|
||||
" Total power cycles: %ld\n\r" \
|
||||
" Total requests: %ld\n\r" \
|
||||
" Total failures: %ld\n\r" \
|
||||
"\n\r",
|
||||
deviceStats->totalRunningHours, deviceStats->totalPowercycles,
|
||||
deviceStats->totalRequests, deviceStats->totalFailures
|
||||
);
|
||||
|
||||
t_mbusCommStats *mbusStats = mbusCommGetStats();
|
||||
sendFormatString(\
|
||||
"Global Meterbus/UART statistics\n\r" \
|
||||
" Meterbus Requests: %ld\n\r" \
|
||||
" Meterbus Errors: %ld\n\r" \
|
||||
" UART Octets: %ld\n\r" \
|
||||
" UART Overruns: %ld\n\r" \
|
||||
" UART Framing Errs: %ld\n\r" \
|
||||
" UART Parity Errs: %ld\n\r" \
|
||||
" UART Noise Errs: %ld\n\r",
|
||||
mbusStats->mbusRequestCnt, mbusStats->mbusErrorCnt,
|
||||
mbusStats->uartOctetCnt, mbusStats->uartOverrunCnt, mbusStats->uartFramingErrCnt, mbusStats->uartParityErrCnt, mbusStats->uartNoiseErrCnt
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const cmd_t COMMANDS[] = {
|
||||
{ .name = "globalStats", .cmdFunc = globalStatsCmd,
|
||||
.help = \
|
||||
"globalStats .......................... Show the global statistics\n\r" \
|
||||
" counters requestCnt and errorCnt\n\r"
|
||||
},
|
||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
||||
};
|
||||
|
||||
const cmd_t *getRegularCommands() {
|
||||
return COMMANDS;
|
||||
}
|
@ -19,6 +19,7 @@ void ringbufferFree(ringbuffer_t *handle) {
|
||||
handle->bufferWriteIdx = 0;
|
||||
}
|
||||
|
||||
|
||||
int ringbufferPut(ringbuffer_t *handle, uint8_t *data, uint32_t dataLen) {
|
||||
uint32_t freeSpace = 0;
|
||||
if (handle->bufferReadIdx == handle->bufferWriteIdx) {
|
||||
@ -61,7 +62,7 @@ uint8_t *ringbufferGet(ringbuffer_t *handle, uint32_t dataLen) {
|
||||
|
||||
int ringbufferGetOne(ringbuffer_t *handle) {
|
||||
int res = -1;
|
||||
if (! ringbufferEmpty(handle)) {
|
||||
if (handle->bufferReadIdx != handle->bufferWriteIdx) {
|
||||
uint8_t r = *(handle->buffer + handle->bufferReadIdx);
|
||||
handle->bufferReadIdx += 1;
|
||||
if (handle->bufferReadIdx == handle->bufferSize) {
|
||||
|
46
cube/User/Src/show.c
Normal file
46
cube/User/Src/show.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <main.h>
|
||||
#include <show.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stm32f103xe.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef *port;
|
||||
uint16_t pin;
|
||||
signalAction_t currentState;
|
||||
} showElement_t;
|
||||
|
||||
showElement_t showElement[] = {
|
||||
{ .port = Debug_Signal_1_GPIO_Port, .pin = Debug_Signal_1_Pin, .currentState = OFF },
|
||||
{ .port = Debug_Signal_2_GPIO_Port, .pin = Debug_Signal_2_Pin, .currentState = OFF },
|
||||
{ .port = LED_Red_GPIO_Port, .pin = LED_Red_Pin, .currentState = OFF },
|
||||
{ .port = LED_Green_GPIO_Port, .pin = LED_Green_Pin, .currentState = OFF },
|
||||
{ .port = NULL, .pin = 0, .currentState = OFF }
|
||||
};
|
||||
|
||||
static void showHandler(void *handle) {
|
||||
uint8_t idx = 0;
|
||||
while (showElement[idx].port) {
|
||||
if (showElement[idx].currentState == BLINK) {
|
||||
HAL_GPIO_TogglePin(showElement[idx].port, showElement[idx].pin);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
void show(signalPin_t signalPin, signalAction_t action) {
|
||||
showElement[signalPin].currentState = action;
|
||||
if (action == ON || action == OFF) {
|
||||
HAL_GPIO_WritePin(showElement[signalPin].port, showElement[signalPin].pin, ((action == ON) ? GPIO_PIN_SET : GPIO_PIN_RESET));
|
||||
} else if (action == TOGGLE) {
|
||||
HAL_GPIO_TogglePin(showElement[signalPin].port, showElement[signalPin].pin);
|
||||
}
|
||||
}
|
||||
|
||||
void showInit() {
|
||||
schAdd(showHandler, NULL, 0, 250);
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
#include <main.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stm32f103xe.h>
|
||||
|
||||
|
||||
void signal(signalPin_t signalPin, signalAction_t action) {
|
||||
GPIO_TypeDef *port = NULL;
|
||||
uint16_t pin = 0;
|
||||
|
||||
switch (signalPin) {
|
||||
case DEBUG_1:
|
||||
port = Debug_Signal_1_GPIO_Port;
|
||||
pin = Debug_Signal_1_Pin;
|
||||
break;
|
||||
|
||||
case DEBUG_2:
|
||||
port = Debug_Signal_2_GPIO_Port;
|
||||
pin = Debug_Signal_2_Pin;
|
||||
break;
|
||||
|
||||
case LED_RED:
|
||||
port = LED_Red_GPIO_Port;
|
||||
pin = LED_Red_Pin;
|
||||
break;
|
||||
|
||||
case LED_GREEN:
|
||||
port = LED_Green_GPIO_Port;
|
||||
pin = LED_Green_Pin;
|
||||
break;
|
||||
}
|
||||
|
||||
if (port != NULL) {
|
||||
switch (action) {
|
||||
case ON:
|
||||
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
|
||||
break;
|
||||
|
||||
case OFF:
|
||||
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case TOGGLE:
|
||||
HAL_GPIO_TogglePin(port, pin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
10
cube/User/Src/utils.c
Normal file
10
cube/User/Src/utils.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <utils.h>
|
||||
#include <main.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// active waiting, use only during initialization!
|
||||
void activeDelay(uint8_t delay_ms) {
|
||||
uint32_t startTime = HAL_GetTick();
|
||||
while (startTime + delay_ms > HAL_GetTick());
|
||||
}
|
232
cube/User/Src/wizHelper.c
Normal file
232
cube/User/Src/wizHelper.c
Normal file
@ -0,0 +1,232 @@
|
||||
#include <wizHelper.h>
|
||||
#include <stdint.h>
|
||||
#include <main2.h>
|
||||
#include <spi.h>
|
||||
#include <stdbool.h>
|
||||
#include <logger.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <utils.h>
|
||||
#include <wizchip_conf.h>
|
||||
#include <string.h>
|
||||
#include <dhcp.h>
|
||||
#include <show.h>
|
||||
#include <oled.h>
|
||||
#include <dns.h>
|
||||
#include <config.h>
|
||||
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
wiz_NetInfo netInfo;
|
||||
|
||||
#define DHCP_BUFFER_SIZE 2048
|
||||
static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
|
||||
|
||||
#define DNS_BUFFER_SIZE MAX_DNS_BUF_SIZE
|
||||
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
|
||||
|
||||
extern const uint8_t DHCP_SOCK;
|
||||
extern const uint8_t DNS_SOCK;
|
||||
|
||||
static bool networkAvailable = false;
|
||||
|
||||
bool isNetworkAvailable() {
|
||||
return networkAvailable;
|
||||
}
|
||||
|
||||
uint8_t* wizGetIPAddress() {
|
||||
return netInfo.ip;
|
||||
}
|
||||
static void wiz_cs_select(void) {
|
||||
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
static void wiz_cs_deselect(void) {
|
||||
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
static uint8_t wiz_spi_readbyte(void) {
|
||||
uint8_t rbuf;
|
||||
HAL_SPI_Receive(ðerSpi, &rbuf, 1, HAL_MAX_DELAY);
|
||||
return rbuf;
|
||||
}
|
||||
|
||||
static void wiz_spi_writebyte(uint8_t wb) {
|
||||
HAL_SPI_Transmit(ðerSpi, &wb, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
static void wiz_spi_readburst(uint8_t* pBuf, uint16_t len) {
|
||||
HAL_SPI_Receive(ðerSpi, pBuf, len, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
static void wiz_spi_writeburst(uint8_t* pBuf, uint16_t len) {
|
||||
HAL_SPI_Transmit(ðerSpi, pBuf, len, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
static void wizReset(bool b) {
|
||||
HAL_GPIO_WritePin(ETHER_RES_GPIO_Port, ETHER_RES_Pin, b ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
|
||||
static void wizDHCPAssign() {
|
||||
coloredMsg(LOG_BLUE, false, "wizda");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, set netinfo again");
|
||||
|
||||
networkAvailable = true;
|
||||
show(LED_GREEN, ON);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, network is available");
|
||||
|
||||
oledPrintf(OLED_SCREEN0, "Addr:%d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
}
|
||||
|
||||
static void wizDHCPUpdate() {
|
||||
coloredMsg(LOG_BLUE, false, "wizdu");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, netinfo updated");
|
||||
}
|
||||
|
||||
static void wizDHCPHandler(void *handle) {
|
||||
static uint8_t lastDhcpRes = 255;
|
||||
|
||||
uint8_t res = DHCP_run();
|
||||
|
||||
if (lastDhcpRes != res) {
|
||||
coloredMsg(LOG_BLUE, false, "wizdh, dhcp state has changed: %d", res);
|
||||
lastDhcpRes = res;
|
||||
}
|
||||
}
|
||||
|
||||
bool wizDnsQuery(char *name, uint8_t *ip) {
|
||||
bool retCode = false;
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, querying for %s", name);
|
||||
int8_t res = DNS_run(netInfo.dns, (uint8_t*) name, ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, DNS_run returns %d", res);
|
||||
retCode = (res == 1);
|
||||
if (retCode) {
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, got address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static void wizPhyLinkHandler(void *handle) {
|
||||
// this handler is anyhow called with a 1s period, so we reuse it for the DNS timer
|
||||
DNS_time_handler();
|
||||
|
||||
static uint8_t lastStablePhyLink = 255;
|
||||
static bool dhcpInitialized = false;
|
||||
|
||||
uint8_t phyLink = 0;
|
||||
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
||||
if (lastStablePhyLink != phyLink) {
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||
lastStablePhyLink = phyLink;
|
||||
|
||||
if (phyLink == PHY_LINK_ON) {
|
||||
oledPrint(OLED_SCREEN0, "Link available");
|
||||
// start DHCP handler
|
||||
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
||||
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
||||
DHCP_init(DHCP_SOCK, dhcpBuffer);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP initialized");
|
||||
|
||||
// run the dhcp handler the first time after 1s and then every 100ms
|
||||
schAdd(wizDHCPHandler, NULL, 1000, 1000);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler scheduled");
|
||||
|
||||
dhcpInitialized = true;
|
||||
} else {
|
||||
oledPrint(OLED_SCREEN0, "Link lost");
|
||||
|
||||
networkAvailable = false;
|
||||
show(LED_GREEN, BLINK);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable");
|
||||
|
||||
// stop DHCP handler
|
||||
if (dhcpInitialized) {
|
||||
DHCP_stop();
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP stopped");
|
||||
|
||||
schDel(wizDHCPHandler, NULL);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler unscheduled");
|
||||
|
||||
dhcpInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int wizInit() {
|
||||
config = getConfig();
|
||||
netInfo.dhcp = NETINFO_DHCP;
|
||||
memcpy(netInfo.mac, config->macAddress, 6);
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
||||
wizReset(true);
|
||||
activeDelay(2);
|
||||
wizReset(false);
|
||||
activeDelay(50);
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, registering callbacks");
|
||||
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, cs funcs registed");
|
||||
reg_wizchip_spi_cbfunc(wiz_spi_readbyte, wiz_spi_writebyte);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi funcs registed");
|
||||
reg_wizchip_spiburst_cbfunc(wiz_spi_readburst, wiz_spi_writeburst);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi burst funcs registed");
|
||||
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, initializing Ethernet module");
|
||||
uint8_t bufSizes[] = { 2, 2, 2, 2, 2, 2, 2, 2 };
|
||||
int8_t res = wizchip_init(bufSizes, bufSizes);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, module driver returned %d", res);
|
||||
|
||||
wizphy_reset();
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, reset phy");
|
||||
|
||||
wiz_PhyConf wpc;
|
||||
wpc.mode = PHY_MODE_MANUAL;
|
||||
wpc.speed = PHY_MODE_MANUAL;
|
||||
wpc.duplex = PHY_DUPLEX_FULL;
|
||||
wizphy_setphyconf(&wpc);
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, phy config set");
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, netinfo set to Ethernet module");
|
||||
|
||||
res = wizchip_setnetmode(NM_FORCEARP); // and not NM_PINGBLOCK
|
||||
coloredMsg(LOG_BLUE, false, "wizI, set netmode, result is %d", res);
|
||||
|
||||
uint8_t buf[6];
|
||||
res = ctlwizchip(CW_GET_ID, (void*) buf);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
|
||||
DNS_init(DNS_SOCK, dnsBuffer);
|
||||
|
||||
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
||||
|
||||
return 0;
|
||||
}
|
128
cube/cube.ioc
128
cube/cube.ioc
@ -14,41 +14,52 @@ Mcu.Family=STM32F1
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=NVIC
|
||||
Mcu.IP2=RCC
|
||||
Mcu.IP3=SPI2
|
||||
Mcu.IP4=SPI3
|
||||
Mcu.IP5=SYS
|
||||
Mcu.IP6=UART4
|
||||
Mcu.IP7=UART5
|
||||
Mcu.IPNb=8
|
||||
Mcu.IP3=SPI1
|
||||
Mcu.IP4=SPI2
|
||||
Mcu.IP5=SPI3
|
||||
Mcu.IP6=SYS
|
||||
Mcu.IP7=UART4
|
||||
Mcu.IP8=UART5
|
||||
Mcu.IPNb=9
|
||||
Mcu.Name=STM32F103V(C-D-E)Tx
|
||||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PE2
|
||||
Mcu.Pin1=PE3
|
||||
Mcu.Pin10=PB13
|
||||
Mcu.Pin11=PB14
|
||||
Mcu.Pin12=PB15
|
||||
Mcu.Pin13=PA13
|
||||
Mcu.Pin14=PA14
|
||||
Mcu.Pin15=PC10
|
||||
Mcu.Pin16=PC11
|
||||
Mcu.Pin17=PC12
|
||||
Mcu.Pin18=PD1
|
||||
Mcu.Pin19=PD2
|
||||
Mcu.Pin10=PA4
|
||||
Mcu.Pin11=PA5
|
||||
Mcu.Pin12=PA6
|
||||
Mcu.Pin13=PA7
|
||||
Mcu.Pin14=PE12
|
||||
Mcu.Pin15=PB10
|
||||
Mcu.Pin16=PB12
|
||||
Mcu.Pin17=PB13
|
||||
Mcu.Pin18=PB14
|
||||
Mcu.Pin19=PB15
|
||||
Mcu.Pin2=PE4
|
||||
Mcu.Pin20=PB3
|
||||
Mcu.Pin21=PB4
|
||||
Mcu.Pin22=PB5
|
||||
Mcu.Pin23=VP_SYS_VS_Systick
|
||||
Mcu.Pin20=PA13
|
||||
Mcu.Pin21=PA14
|
||||
Mcu.Pin22=PC10
|
||||
Mcu.Pin23=PC11
|
||||
Mcu.Pin24=PC12
|
||||
Mcu.Pin25=PD1
|
||||
Mcu.Pin26=PD2
|
||||
Mcu.Pin27=PD7
|
||||
Mcu.Pin28=PB3
|
||||
Mcu.Pin29=PB4
|
||||
Mcu.Pin3=PE5
|
||||
Mcu.Pin30=PB5
|
||||
Mcu.Pin31=PB6
|
||||
Mcu.Pin32=PB7
|
||||
Mcu.Pin33=VP_SYS_VS_Systick
|
||||
Mcu.Pin4=PE6
|
||||
Mcu.Pin5=OSC_IN
|
||||
Mcu.Pin6=OSC_OUT
|
||||
Mcu.Pin7=PA1
|
||||
Mcu.Pin8=PE12
|
||||
Mcu.Pin9=PB10
|
||||
Mcu.PinsNb=24
|
||||
Mcu.Pin8=PA2
|
||||
Mcu.Pin9=PA3
|
||||
Mcu.PinsNb=34
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=debugUart,huart4;mbusUart,huart5;frontendAdc,hadc1
|
||||
Mcu.UserConstants=debugUart,huart4;mbusUart,huart5;frontendAdc,hadc1;eepromSpi,hspi2;etherSpi,hspi1;displaySpi,hspi3;debugUartIRQn,UART4_IRQn
|
||||
Mcu.UserName=STM32F103VCTx
|
||||
MxCube.Version=6.0.0
|
||||
MxDb.Version=DB.6.0.0
|
||||
@ -62,6 +73,7 @@ NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||
NVIC.SPI2_IRQn=true\:0\:0\:false\:false\:true\:true\:true
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
|
||||
NVIC.UART4_IRQn=true\:0\:0\:false\:false\:true\:true\:true
|
||||
@ -78,22 +90,70 @@ PA13.Mode=Serial_Wire
|
||||
PA13.Signal=SYS_JTMS-SWDIO
|
||||
PA14.Mode=Serial_Wire
|
||||
PA14.Signal=SYS_JTCK-SWCLK
|
||||
PA2.GPIOParameters=GPIO_Label
|
||||
PA2.GPIO_Label=ETHER_RES
|
||||
PA2.Locked=true
|
||||
PA2.Signal=GPIO_Output
|
||||
PA3.GPIOParameters=GPIO_Label
|
||||
PA3.GPIO_Label=ETHER_INT
|
||||
PA3.Locked=true
|
||||
PA3.Signal=GPXTI3
|
||||
PA4.GPIOParameters=GPIO_Label
|
||||
PA4.GPIO_Label=ETHER_CS
|
||||
PA4.Locked=true
|
||||
PA4.Signal=GPIO_Output
|
||||
PA5.GPIOParameters=GPIO_Label
|
||||
PA5.GPIO_Label=ETHER_SCLK
|
||||
PA5.Mode=Full_Duplex_Master
|
||||
PA5.Signal=SPI1_SCK
|
||||
PA6.GPIOParameters=GPIO_Label
|
||||
PA6.GPIO_Label=ETHER_MISO
|
||||
PA6.Mode=Full_Duplex_Master
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.GPIOParameters=GPIO_Label
|
||||
PA7.GPIO_Label=ETHER_MOSI
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PB10.GPIOParameters=GPIO_Label
|
||||
PB10.GPIO_Label=Debug_Signal_1
|
||||
PB10.Locked=true
|
||||
PB10.Signal=GPIO_Output
|
||||
PB12.GPIOParameters=GPIO_Label
|
||||
PB12.GPIO_Label=EEPROM_CS
|
||||
PB12.Locked=true
|
||||
PB12.Signal=GPIO_Output
|
||||
PB13.GPIOParameters=GPIO_Label
|
||||
PB13.GPIO_Label=EEPROM_SCLK
|
||||
PB13.Mode=Full_Duplex_Master
|
||||
PB13.Signal=SPI2_SCK
|
||||
PB14.GPIOParameters=GPIO_Label
|
||||
PB14.GPIO_Label=EEPROM_MISO
|
||||
PB14.Mode=Full_Duplex_Master
|
||||
PB14.Signal=SPI2_MISO
|
||||
PB15.GPIOParameters=GPIO_Label
|
||||
PB15.GPIO_Label=EEPROM_MOSI
|
||||
PB15.Mode=Full_Duplex_Master
|
||||
PB15.Signal=SPI2_MOSI
|
||||
PB3.GPIOParameters=GPIO_Label
|
||||
PB3.GPIO_Label=Display_SCLK
|
||||
PB3.Mode=Full_Duplex_Master
|
||||
PB3.Signal=SPI3_SCK
|
||||
PB4.GPIOParameters=GPIO_Label
|
||||
PB4.GPIO_Label=Display_MISO
|
||||
PB4.Mode=Full_Duplex_Master
|
||||
PB4.Signal=SPI3_MISO
|
||||
PB5.GPIOParameters=GPIO_Label
|
||||
PB5.GPIO_Label=Display_MOSI
|
||||
PB5.Mode=Full_Duplex_Master
|
||||
PB5.Signal=SPI3_MOSI
|
||||
PB6.GPIOParameters=GPIO_Label
|
||||
PB6.GPIO_Label=Display_DC
|
||||
PB6.Locked=true
|
||||
PB6.Signal=GPIO_Output
|
||||
PB7.GPIOParameters=GPIO_Label
|
||||
PB7.GPIO_Label=Display_RES
|
||||
PB7.Locked=true
|
||||
PB7.Signal=GPIO_Output
|
||||
PC10.GPIOParameters=GPIO_Label
|
||||
PC10.GPIO_Label=Debug_TX
|
||||
PC10.Mode=Asynchronous
|
||||
@ -114,6 +174,10 @@ PD2.GPIOParameters=GPIO_Label
|
||||
PD2.GPIO_Label=MBus_RX
|
||||
PD2.Mode=Asynchronous
|
||||
PD2.Signal=UART5_RX
|
||||
PD7.GPIOParameters=GPIO_Label
|
||||
PD7.GPIO_Label=Display_CS
|
||||
PD7.Locked=true
|
||||
PD7.Signal=GPIO_Output
|
||||
PE12.GPIOParameters=GPIO_Label
|
||||
PE12.GPIO_Label=Debug_Signal_2
|
||||
PE12.Locked=true
|
||||
@ -168,7 +232,7 @@ ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=Makefile
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_UART5_Init-UART5-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_UART5_Init-UART5-false-HAL-true,8-MX_SPI1_Init-SPI1-false-HAL-true
|
||||
RCC.ADCFreqValue=4500000
|
||||
RCC.ADCPresc=RCC_ADCPCLK2_DIV8
|
||||
RCC.AHBFreq_Value=72000000
|
||||
@ -199,11 +263,21 @@ RCC.USBFreq_Value=72000000
|
||||
RCC.VCOOutput2Freq_Value=8000000
|
||||
SH.ADCx_IN1.0=ADC1_IN1,IN1
|
||||
SH.ADCx_IN1.ConfNb=1
|
||||
SH.GPXTI3.0=GPIO_EXTI3
|
||||
SH.GPXTI3.ConfNb=1
|
||||
SH.GPXTI4.0=GPIO_EXTI4
|
||||
SH.GPXTI4.ConfNb=1
|
||||
SPI2.CalculateBaudRate=18.0 MBits/s
|
||||
SPI1.CalculateBaudRate=18.0 MBits/s
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
||||
SPI2.CLKPhase=SPI_PHASE_1EDGE
|
||||
SPI2.CLKPolarity=SPI_POLARITY_LOW
|
||||
SPI2.CalculateBaudRate=9.0 MBits/s
|
||||
SPI2.Direction=SPI_DIRECTION_2LINES
|
||||
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler,CLKPolarity,CLKPhase
|
||||
SPI2.Mode=SPI_MODE_MASTER
|
||||
SPI2.VirtualType=VM_MASTER
|
||||
SPI3.CalculateBaudRate=18.0 MBits/s
|
||||
|
BIN
cube/cube.pdf
BIN
cube/cube.pdf
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
Configuration cube
|
||||
STM32CubeMX 6.0.0
|
||||
Date 10/18/2020
|
||||
Date 11/18/2020
|
||||
MCU STM32F103VCTx
|
||||
|
||||
|
||||
@ -9,6 +9,9 @@ PERIPHERALS MODES FUNCTIONS PINS
|
||||
ADC1 IN1 ADC1_IN1 PA1
|
||||
RCC Crystal/Ceramic Resonator RCC_OSC_IN OSC_IN
|
||||
RCC Crystal/Ceramic Resonator RCC_OSC_OUT OSC_OUT
|
||||
SPI1 Full-Duplex Master SPI1_MISO PA6
|
||||
SPI1 Full-Duplex Master SPI1_MOSI PA7
|
||||
SPI1 Full-Duplex Master SPI1_SCK PA5
|
||||
SPI2 Full-Duplex Master SPI2_MISO PB14
|
||||
SPI2 Full-Duplex Master SPI2_MOSI PB15
|
||||
SPI2 Full-Duplex Master SPI2_SCK PB13
|
||||
@ -28,15 +31,24 @@ UART5 Asynchronous UART5_TX PC12
|
||||
Pin Nb PINs FUNCTIONs LABELs
|
||||
1 PE2 GPIO_Output Loop_Enable
|
||||
2 PE3 GPIO_Output Loop_Disable
|
||||
3 PE4 GPIO_Input Loop_Status
|
||||
3 PE4 GPIO_EXTI4 Loop_Status
|
||||
4 PE5 GPIO_Output LED_Green
|
||||
5 PE6 GPIO_Output LED_Red
|
||||
12 OSC_IN RCC_OSC_IN
|
||||
13 OSC_OUT RCC_OSC_OUT
|
||||
24 PA1 ADC1_IN1 Frontend_In
|
||||
52 PB13 SPI2_SCK
|
||||
53 PB14 SPI2_MISO
|
||||
54 PB15 SPI2_MOSI
|
||||
25 PA2 GPIO_Output ETHER_RES
|
||||
26 PA3 GPIO_EXTI3 ETHER_INT
|
||||
29 PA4 GPIO_Output ETHER_CS
|
||||
30 PA5 SPI1_SCK ETHER_SCLK
|
||||
31 PA6 SPI1_MISO ETHER_MISO
|
||||
32 PA7 SPI1_MOSI ETHER_MOSI
|
||||
43 PE12 GPIO_Output Debug_Signal_2
|
||||
47 PB10 GPIO_Output Debug_Signal_1
|
||||
51 PB12 GPIO_Output EEPROM_CS
|
||||
52 PB13 SPI2_SCK EEPROM_SCLK
|
||||
53 PB14 SPI2_MISO EEPROM_MISO
|
||||
54 PB15 SPI2_MOSI EEPROM_MOSI
|
||||
72 PA13 SYS_JTMS-SWDIO
|
||||
76 PA14 SYS_JTCK-SWCLK
|
||||
78 PC10 UART4_TX Debug_TX
|
||||
@ -44,13 +56,19 @@ Pin Nb PINs FUNCTIONs LABELs
|
||||
80 PC12 UART5_TX MBus_TX
|
||||
82 PD1 GPIO_Output Frontend_Out
|
||||
83 PD2 UART5_RX MBus_RX
|
||||
89 PB3 SPI3_SCK
|
||||
90 PB4 SPI3_MISO
|
||||
91 PB5 SPI3_MOSI
|
||||
88 PD7 GPIO_Output Display_CS
|
||||
89 PB3 SPI3_SCK Display_SCLK
|
||||
90 PB4 SPI3_MISO Display_MISO
|
||||
91 PB5 SPI3_MOSI Display_MOSI
|
||||
92 PB6 GPIO_Output Display_DC
|
||||
93 PB7 GPIO_Output Display_RES
|
||||
PERIPHERALS MODES FUNCTIONS PINS
|
||||
ADC1 IN1 ADC1_IN1 PA1
|
||||
RCC Crystal/Ceramic Resonator RCC_OSC_IN OSC_IN
|
||||
RCC Crystal/Ceramic Resonator RCC_OSC_OUT OSC_OUT
|
||||
SPI1 Full-Duplex Master SPI1_MISO PA6
|
||||
SPI1 Full-Duplex Master SPI1_MOSI PA7
|
||||
SPI1 Full-Duplex Master SPI1_SCK PA5
|
||||
SPI2 Full-Duplex Master SPI2_MISO PB14
|
||||
SPI2 Full-Duplex Master SPI2_MOSI PB15
|
||||
SPI2 Full-Duplex Master SPI2_SCK PB13
|
||||
@ -70,15 +88,24 @@ UART5 Asynchronous UART5_TX PC12
|
||||
Pin Nb PINs FUNCTIONs LABELs
|
||||
1 PE2 GPIO_Output Loop_Enable
|
||||
2 PE3 GPIO_Output Loop_Disable
|
||||
3 PE4 GPIO_Input Loop_Status
|
||||
3 PE4 GPIO_EXTI4 Loop_Status
|
||||
4 PE5 GPIO_Output LED_Green
|
||||
5 PE6 GPIO_Output LED_Red
|
||||
12 OSC_IN RCC_OSC_IN
|
||||
13 OSC_OUT RCC_OSC_OUT
|
||||
24 PA1 ADC1_IN1 Frontend_In
|
||||
52 PB13 SPI2_SCK
|
||||
53 PB14 SPI2_MISO
|
||||
54 PB15 SPI2_MOSI
|
||||
25 PA2 GPIO_Output ETHER_RES
|
||||
26 PA3 GPIO_EXTI3 ETHER_INT
|
||||
29 PA4 GPIO_Output ETHER_CS
|
||||
30 PA5 SPI1_SCK ETHER_SCLK
|
||||
31 PA6 SPI1_MISO ETHER_MISO
|
||||
32 PA7 SPI1_MOSI ETHER_MOSI
|
||||
43 PE12 GPIO_Output Debug_Signal_2
|
||||
47 PB10 GPIO_Output Debug_Signal_1
|
||||
51 PB12 GPIO_Output EEPROM_CS
|
||||
52 PB13 SPI2_SCK EEPROM_SCLK
|
||||
53 PB14 SPI2_MISO EEPROM_MISO
|
||||
54 PB15 SPI2_MOSI EEPROM_MOSI
|
||||
72 PA13 SYS_JTMS-SWDIO
|
||||
76 PA14 SYS_JTCK-SWCLK
|
||||
78 PC10 UART4_TX Debug_TX
|
||||
@ -86,9 +113,12 @@ Pin Nb PINs FUNCTIONs LABELs
|
||||
80 PC12 UART5_TX MBus_TX
|
||||
82 PD1 GPIO_Output Frontend_Out
|
||||
83 PD2 UART5_RX MBus_RX
|
||||
89 PB3 SPI3_SCK
|
||||
90 PB4 SPI3_MISO
|
||||
91 PB5 SPI3_MOSI
|
||||
88 PD7 GPIO_Output Display_CS
|
||||
89 PB3 SPI3_SCK Display_SCLK
|
||||
90 PB4 SPI3_MISO Display_MISO
|
||||
91 PB5 SPI3_MOSI Display_MOSI
|
||||
92 PB6 GPIO_Output Display_DC
|
||||
93 PB7 GPIO_Output Display_RES
|
||||
|
||||
|
||||
|
||||
@ -96,7 +126,7 @@ SOFTWARE PROJECT
|
||||
|
||||
Project Settings :
|
||||
Project Name : cube
|
||||
Project Folder : /home/wn/Workspaces/MBusGateway3Variant/cube
|
||||
Project Folder : /home/wn/Workspaces/mbusgateway3variant/cube
|
||||
Toolchain / IDE : Makefile
|
||||
Firmware Package Name and Version : STM32Cube FW_F1 V1.8.2
|
||||
|
||||
|
Submodule cube/hottislib updated: 1ac9a37755...b7b7d6e95d
1
cube/ioLibrary_Driver
Submodule
1
cube/ioLibrary_Driver
Submodule
Submodule cube/ioLibrary_Driver added at 27f646860d
1
cube/libmbus
Submodule
1
cube/libmbus
Submodule
Submodule cube/libmbus added at d063561b27
1
cube/pubsub
Submodule
1
cube/pubsub
Submodule
Submodule cube/pubsub added at 8b3a05fec2
1
cube/pubsubc
Submodule
1
cube/pubsubc
Submodule
Submodule cube/pubsubc added at 1ac129a027
@ -1,6 +1,6 @@
|
||||
CFLAGS=-I../cube/User/Inc -DTEST
|
||||
|
||||
test: ringbuffer.o logger.o test.o
|
||||
test: ringbuffer.o test.o
|
||||
gcc -o $@ -lcunit $^
|
||||
|
||||
ringbuffer.o: ../cube/User/Src/ringbuffer.c
|
||||
|
77
tests/test.c
77
tests/test.c
@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <logger.h>
|
||||
//#include <logger.h>
|
||||
|
||||
|
||||
// #define DEBUG
|
||||
@ -10,6 +10,7 @@
|
||||
ringbuffer_t rb;
|
||||
|
||||
|
||||
|
||||
void printRingbuffer(ringbuffer_t *rb) {
|
||||
printf("Ringbuffer:\n");
|
||||
printf(" Size: %u\n", rb->bufferSize);
|
||||
@ -817,8 +818,75 @@ void testRingbuffer99() {
|
||||
}
|
||||
|
||||
|
||||
void testRingbuffer100() {
|
||||
#ifdef DEBUG
|
||||
printf("Initialize ringbuffer\n");
|
||||
#endif
|
||||
ringbufferInit(&rb, 16);
|
||||
#ifdef DEBUG
|
||||
printRingbuffer(&rb);
|
||||
#endif
|
||||
|
||||
CU_ASSERT(rb.buffer != NULL);
|
||||
CU_ASSERT(rb.bufferSize == 16);
|
||||
CU_ASSERT(rb.bufferWriteIdx == 0);
|
||||
CU_ASSERT(rb.bufferReadIdx == 0);
|
||||
|
||||
CU_ASSERT(rb.buffer[0] == 0);
|
||||
CU_ASSERT(rb.buffer[1] == 0);
|
||||
CU_ASSERT(rb.buffer[2] == 0);
|
||||
CU_ASSERT(rb.buffer[3] == 0);
|
||||
CU_ASSERT(rb.buffer[4] == 0);
|
||||
CU_ASSERT(rb.buffer[5] == 0);
|
||||
CU_ASSERT(rb.buffer[6] == 0);
|
||||
CU_ASSERT(rb.buffer[7] == 0);
|
||||
CU_ASSERT(rb.buffer[8] == 0);
|
||||
CU_ASSERT(rb.buffer[9] == 0);
|
||||
CU_ASSERT(rb.buffer[10] == 0);
|
||||
CU_ASSERT(rb.buffer[11] == 0);
|
||||
CU_ASSERT(rb.buffer[12] == 0);
|
||||
CU_ASSERT(rb.buffer[13] == 0);
|
||||
CU_ASSERT(rb.buffer[14] == 0);
|
||||
CU_ASSERT(rb.buffer[15] == 0);
|
||||
}
|
||||
|
||||
|
||||
void testRingbuffer101() {
|
||||
#ifdef DEBUG
|
||||
printf("\nPut 1 chars in buffer\n");
|
||||
#endif
|
||||
int r = ringbufferPutOne(&rb, 'a');
|
||||
#ifdef DEBUG
|
||||
printf("r = %d\n", r);
|
||||
printRingbuffer(&rb);
|
||||
#endif
|
||||
|
||||
CU_ASSERT(r == 0);
|
||||
CU_ASSERT(rb.buffer != NULL);
|
||||
CU_ASSERT(rb.bufferSize == 16);
|
||||
CU_ASSERT(rb.bufferWriteIdx == 1);
|
||||
CU_ASSERT(rb.bufferReadIdx == 0);
|
||||
|
||||
CU_ASSERT(rb.buffer[0] == 'a');
|
||||
CU_ASSERT(rb.buffer[1] == 0);
|
||||
CU_ASSERT(rb.buffer[2] == 0);
|
||||
CU_ASSERT(rb.buffer[3] == 0);
|
||||
CU_ASSERT(rb.buffer[4] == 0);
|
||||
CU_ASSERT(rb.buffer[5] == 0);
|
||||
CU_ASSERT(rb.buffer[6] == 0);
|
||||
CU_ASSERT(rb.buffer[7] == 0);
|
||||
CU_ASSERT(rb.buffer[8] == 0);
|
||||
CU_ASSERT(rb.buffer[9] == 0);
|
||||
CU_ASSERT(rb.buffer[10] == 0);
|
||||
CU_ASSERT(rb.buffer[11] == 0);
|
||||
CU_ASSERT(rb.buffer[12] == 0);
|
||||
CU_ASSERT(rb.buffer[13] == 0);
|
||||
CU_ASSERT(rb.buffer[14] == 0);
|
||||
CU_ASSERT(rb.buffer[15] == 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int init_suite_logger(void) {
|
||||
logInit();
|
||||
return 0;
|
||||
@ -949,7 +1017,7 @@ void testLogger2() {
|
||||
CU_ASSERT(strcmp(goldValueFullNotOk, buffer) != 0);
|
||||
CU_ASSERT(strcmp(goldValueFullOk, buffer) == 0);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int main() {
|
||||
@ -980,11 +1048,14 @@ int main() {
|
||||
(NULL == CU_add_test(ringbufferSuite, "test 14 of ringbuffer", testRingbuffer15)) ||
|
||||
(NULL == CU_add_test(ringbufferSuite, "test 14 of ringbuffer", testRingbuffer16)) ||
|
||||
(NULL == CU_add_test(ringbufferSuite, "test 99 of ringbuffer, free", testRingbuffer99)) ||
|
||||
(NULL == CU_add_test(ringbufferSuite, "test 100 of ringbuffer, free", testRingbuffer100)) ||
|
||||
(NULL == CU_add_test(ringbufferSuite, "test 101 of ringbuffer, free", testRingbuffer101)) ||
|
||||
0 ) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
/*
|
||||
CU_pSuite loggerSuite = CU_add_suite("Suite_Logger", init_suite_logger, clean_suite_logger);
|
||||
if (NULL == loggerSuite) {
|
||||
CU_cleanup_registry();
|
||||
@ -999,7 +1070,7 @@ int main() {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
|
@ -9,8 +9,6 @@ IT_C_BAK=${IT_C}-bak
|
||||
MAKEFILE=./Makefile
|
||||
MAKEFILE_BAK=${MAKEFILE}-bak
|
||||
|
||||
|
||||
|
||||
PROCESSED="Processed by $0"
|
||||
|
||||
checkFile () {
|
||||
@ -49,8 +47,18 @@ cat $MAIN_C_BAK | \
|
||||
cp $IT_C $IT_C_BAK
|
||||
echo "// $PROCESSED" > $IT_C
|
||||
cat $IT_C_BAK | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN SysTick_IRQn 1 \*/\),\1\n SYSTICK_Callback();\n,' >> $IT_C
|
||||
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' \
|
||||
-e 's,\(/\* USER CODE BEGIN SysTick_IRQn 1 \*/\),\1\n SYSTICK_Callback();\n,' \
|
||||
-e 's,\(HAL_UART_IRQHandler(&huart5);\),// \1,' \
|
||||
-e 's,\(/\* USER CODE BEGIN UART5_IRQn 1 \*/\),\1\n mbusCommISR();\n,' \
|
||||
>> $IT_C
|
||||
|
||||
# mkdir w5500
|
||||
# pushd ioLibrary_Driver
|
||||
# for D in Ethernet Ethernet/W5500 Internet/DHCP Internet/DNS Internet/httpServer Internet/MQTT; do
|
||||
# cp $D/*.c $D/*.h ../w5500
|
||||
# done
|
||||
# popd
|
||||
|
||||
|
||||
SRC_EXT=''
|
||||
@ -60,10 +68,31 @@ done
|
||||
for I in hottislib/*.c; do
|
||||
SRC_EXT+="$I "
|
||||
done
|
||||
# for I in w5500/*.c; do
|
||||
# SRC_EXT+="$I "
|
||||
# done
|
||||
|
||||
cp $MAKEFILE $MAKEFILE_BAK
|
||||
echo "# $PROCESSED" > $MAKEFILE
|
||||
cat $MAKEFILE_BAK | \
|
||||
sed -e 's/\(-specs=nano.specs\)/\1 -u _printf_float/' | \
|
||||
sed -e 's/\(-Wall\)/\1 -Werror/' | \
|
||||
sed -e 's%\(# list of ASM program objects\)%OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a pubsubc.a)\n\1%' | \
|
||||
sed -e 's,\($(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)\),$(BUILD_DIR)/w5500.a:\n\t(cd ioLibrary_Driver \&\& $(MAKE) \&\& cp w5500.a ../$(BUILD_DIR) \&\& cd ..)\n\n\1,' | \
|
||||
sed -e 's,\($(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)\),$(BUILD_DIR)/pubsubc.a:\n\t(cd pubsubc \&\& $(MAKE) \&\& cp pubsubc.a ../$(BUILD_DIR) \&\& cd ..)\n\n\1,' | \
|
||||
sed -e 's,\(C_SOURCES = \\\),\1\nlibmbus/mbus/mbus-protocol.c \\,' | \
|
||||
sed -e 's,\(C_SOURCES = \\\),\1\n'"$SRC_EXT"' \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Ethernet \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DHCP \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DNS \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ilibmbus \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ipubsubc/src \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ihottislib \\,' >> $MAKEFILE
|
||||
|
||||
# sed -e 's,\(C_INCLUDES = \\\),\1\n-Iw5500 \\,' | \
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user