diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index bebf5c994..7e79f5ee0 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -22,9 +22,7 @@ jobs: new_release: ${{ steps.refs.outputs.new_release }} steps: - name: Source checkout - uses: actions/checkout@v3 - with: - submodules: recursive + uses: actions/checkout@v4 - name: Update SDKs if required run: make update-submodules - name: Semantic Release @@ -52,12 +50,11 @@ jobs: else export VERSION=${BRANCHTRANSLATED}_$(git rev-parse --short=12 HEAD) fi - echo "new_release: ${{ steps.semantic.outputs.new_release_published }}" - echo "version: ${VERSION}" - echo "::set-output name=new_release::${{ steps.semantic.outputs.new_release_published }}" - echo "::set-output name=short_ref::${BRANCHTRANSLATED}" - echo "::set-output name=sha_short::SHA-$(git rev-parse --short=12 HEAD)" - echo "::set-output name=version::${VERSION}" + echo "new_release=${{ steps.semantic.outputs.new_release_published }}" >> $GITHUB_OUTPUT + echo "short_ref=${BRANCHTRANSLATED}" >> $GITHUB_OUTPUT + echo "sha_short=SHA-$(git rev-parse --short=12 HEAD)" >> $GITHUB_OUTPUT + echo "version=${VERSION}" >> $GITHUB_OUTPUT + build2: name: Build Simulator @@ -66,10 +63,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup MSBuild - uses: microsoft/setup-msbuild@v1.0.2 + uses: microsoft/setup-msbuild@v2 - name: Checkout simulator repository run: | @@ -98,9 +95,9 @@ jobs: mkdir -Force output/${{ needs.refs.outputs.version }} cp obkSimulator_win32_${{ needs.refs.outputs.version }}.zip output/${{ needs.refs.outputs.version }}/obkSimulator_${{ needs.refs.outputs.version }}.zip - name: Upload build assets - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }} + name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}_sim path: output/${{ needs.refs.outputs.version }}/obkSimulator_${{ needs.refs.outputs.version }}.zip build: @@ -110,13 +107,11 @@ jobs: strategy: fail-fast: false matrix: - platform: [OpenBK7231T, OpenBK7231N, OpenXR809, OpenBL602, OpenW800, OpenW600, OpenLN882H, OpenTR6260] + platform: [OpenBK7231T, OpenBK7231N, OpenXR809, OpenBL602, OpenW800, OpenW600, OpenLN882H, OpenTR6260, OpenRTL87X0C] steps: - name: Source checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: actions/setup-python@v2 + uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' @@ -133,24 +128,21 @@ jobs: - name: Run make run: make APP_VERSION=${{ needs.refs.outputs.version }} APP_NAME=${{ matrix.platform }} ${{ matrix.platform }} - name: Save build assets - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }} + name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}_${{ matrix.platform }} path: | - output/${{ needs.refs.outputs.version }}/OpenBK7231T_UA_${{ needs.refs.outputs.version }}.bin - output/${{ needs.refs.outputs.version }}/OpenBK7231T_UG_${{ needs.refs.outputs.version }}.bin - output/${{ needs.refs.outputs.version }}/OpenBK7231T_QIO_${{ needs.refs.outputs.version }}.bin - output/${{ needs.refs.outputs.version }}/OpenBK7231N_QIO_${{ needs.refs.outputs.version }}.bin - output/${{ needs.refs.outputs.version }}/OpenBK7231N_UG_${{ needs.refs.outputs.version }}.bin - output/${{ needs.refs.outputs.version }}/OpenBK7231M_QIO_${{ needs.refs.outputs.version }}.bin + output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_UA_${{ needs.refs.outputs.version }}.bin + output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_UG_${{ needs.refs.outputs.version }}.bin + output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_QIO_${{ needs.refs.outputs.version }}.bin output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.rbl output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.img output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.bin output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.fls output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_ota.img output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_gz.img - output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin - output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin.xz + output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin + output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin.xz output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin.xz.ota if-no-files-found: warn @@ -164,10 +156,15 @@ jobs: platform: [OpenESP32, OpenESP32C3, OpenESP32C2, OpenESP32C6, OpenESP32S3, OpenESP32S2] steps: - name: Source checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + - name: SDK checkout + uses: actions/checkout@v4 with: - submodules: recursive - - uses: actions/setup-python@v2 + repository: espressif/esp-idf + path: sdk/esp-idf + ref: v5.3.2 + submodules: recursive + - uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' @@ -188,24 +185,36 @@ jobs: cd ../.. make APP_VERSION=${{ needs.refs.outputs.version }} APP_NAME=${{ matrix.platform }} ${{ matrix.platform }} - name: Save build assets - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }} + name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}_${{ matrix.platform }} path: | output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.img output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.factory.bin if-no-files-found: warn + merge: + name: Merge Artifacts + runs-on: ubuntu-20.04 + needs: [refs, build, build2, build_idf] + if: always() && needs.refs.outputs.new_release == 'true' && (github.ref == 'refs/heads/main' || github.ref_name == 'alpha') + steps: + - name: Merge Artifacts + uses: actions/upload-artifact/merge@v4 + with: + name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }} + delete-merged: true + release: name: Semantic Release Images and Artifacts runs-on: ubuntu-20.04 - needs: [ refs, build, build_idf, build2 ] + needs: [merge, refs] if: always() && needs.refs.outputs.new_release == 'true' && (github.ref == 'refs/heads/main' || github.ref_name == 'alpha') steps: - name: Source checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Fetch build assets - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }} path: output/${{ needs.refs.outputs.version }} diff --git a/.gitignore b/.gitignore index a85580d0b..5a579b596 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ configMemory.bin # MSVC enc_temp_folder/** + +*.su \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index ea1fc5f66..3df66dad4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -33,3 +33,7 @@ path = sdk/OpenTR6260 url = https://github.com/NonPIayerCharacter/OpenTR6260.git branch = master +[submodule "sdk/OpenRTL87X0C"] + path = sdk/OpenRTL87X0C + url = https://github.com/NonPIayerCharacter/OpenRTL87X0C.git + branch = main diff --git a/Makefile b/Makefile index 53ea7dce3..e22d1937e 100644 --- a/Makefile +++ b/Makefile @@ -31,11 +31,11 @@ submodules: ifdef GITHUB_ACTIONS @echo Submodules already checked out during setup else - git submodule update --init --recursive --remote + git submodule update --init --recursive endif update-submodules: submodules - git add sdk/OpenBK7231T sdk/OpenBK7231N sdk/OpenXR809 sdk/OpenBL602 sdk/OpenW800 sdk/OpenW600 sdk/OpenLN882H sdk/esp-idf + git add sdk/OpenBK7231T sdk/OpenBK7231N sdk/OpenXR809 sdk/OpenBL602 sdk/OpenW800 sdk/OpenW600 sdk/OpenLN882H sdk/esp-idf sdk/OpenTR6260 ifdef GITHUB_ACTIONS git config user.name github-actions git config user.email github-actions@github.com @@ -76,8 +76,10 @@ sdk/OpenLN882H/project/OpenBeken/app: .PHONY: prebuild_OpenBK7231N prebuild_OpenBK7231T prebuild_OpenBL602 prebuild_OpenLN882H .PHONY: prebuild_OpenW600 prebuild_OpenW800 prebuild_OpenXR809 prebuild_ESPIDF prebuild_OpenTR6260 +.PHONY: prebuild_OpenRTL87X0C prebuild_OpenBK7231N: + git submodule update --init --recursive sdk/OpenBK7231N @if [ -e platforms/BK7231N/pre_build.sh ]; then \ echo "prebuild found for OpenBK7231N"; \ sh platforms/BK7231N/pre_build.sh; \ @@ -85,6 +87,7 @@ prebuild_OpenBK7231N: fi prebuild_OpenBK7231T: + git submodule update --init --recursive sdk/OpenBK7231T @if [ -e platforms/BK7231T/pre_build.sh ]; then \ echo "prebuild found for OpenBK7231T"; \ sh platforms/BK7231T/pre_build.sh; \ @@ -92,6 +95,7 @@ prebuild_OpenBK7231T: fi prebuild_OpenBL602: + git submodule update --init --recursive sdk/OpenBL602 @if [ -e platforms/BL602/pre_build.sh ]; then \ echo "prebuild found for OpenBL602"; \ sh platforms/BL602/pre_build.sh; \ @@ -99,6 +103,7 @@ prebuild_OpenBL602: fi prebuild_OpenLN882H: + git submodule update --init --recursive sdk/OpenLN882H @if [ -e platforms/LN882H/pre_build.sh ]; then \ echo "prebuild found for OpenLN882H"; \ sh platforms/LN882H/pre_build.sh; \ @@ -106,6 +111,7 @@ prebuild_OpenLN882H: fi prebuild_OpenW600: + git submodule update --init --recursive sdk/OpenW600 @if [ -e platforms/W600/pre_build.sh ]; then \ echo "prebuild found for OpenW600"; \ sh platforms/W600/pre_build.sh; \ @@ -113,6 +119,7 @@ prebuild_OpenW600: fi prebuild_OpenW800: + git submodule update --init --recursive sdk/OpenW800 @if [ -e platforms/W800/pre_build.sh ]; then \ echo "prebuild found for OpenW800"; \ sh platforms/W800/pre_build.sh; \ @@ -120,6 +127,7 @@ prebuild_OpenW800: fi prebuild_OpenXR809: + git submodule update --init --recursive sdk/OpenXR809 @if [ -e platforms/XR809/pre_build.sh ]; then \ echo "prebuild found for OpenXR809"; \ sh platforms/XR809/pre_build.sh; \ @@ -127,6 +135,7 @@ prebuild_OpenXR809: fi prebuild_ESPIDF: + #git submodule update --init --recursive sdk/esp-idf @if [ -e platforms/ESP-IDF/pre_build.sh ]; then \ echo "prebuild found for ESP-IDF"; \ sh platforms/ESP-IDF/pre_build.sh; \ @@ -134,10 +143,19 @@ prebuild_ESPIDF: fi prebuild_OpenTR6260: + git submodule update --init --recursive sdk/OpenTR6260 @if [ -e platforms/TR6260/pre_build.sh ]; then \ - echo "prebuild found for TR6260"; \ + echo "prebuild found for OpenTR6260"; \ sh platforms/TR6260/pre_build.sh; \ - else echo "prebuild for TR6260 not found ... "; \ + else echo "prebuild for OpenTR6260 not found ... "; \ + fi + +prebuild_OpenRTL87X0C: + git submodule update --init --recursive sdk/OpenRTL87X0C + @if [ -e platforms/RTL87X0C/pre_build.sh ]; then \ + echo "prebuild found for OpenRTL87X0C"; \ + sh platforms/RTL87X0C/pre_build.sh; \ + else echo "prebuild for OpenRTL87X0C not found ... "; \ fi # Build main binaries @@ -159,7 +177,7 @@ OpenXR809: prebuild_OpenXR809 @echo Running build final time to check output $(MAKE) build-XR809; -build-XR809: submodules sdk/OpenXR809/project/oxr_sharedApp/shared sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2 +build-XR809: sdk/OpenXR809/project/oxr_sharedApp/shared sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2 $(MAKE) -C sdk/OpenXR809/src CC_DIR=$(PWD)/sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2/bin $(MAKE) -C sdk/OpenXR809/src install CC_DIR=$(PWD)/sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2/bin $(MAKE) -C sdk/OpenXR809/project/oxr_sharedApp/gcc CC_DIR=$(PWD)/sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2/bin @@ -168,12 +186,12 @@ build-XR809: submodules sdk/OpenXR809/project/oxr_sharedApp/shared sdk/OpenXR809 cp sdk/OpenXR809/project/oxr_sharedApp/image/xr809/xr_system.img output/$(APP_VERSION)/OpenXR809_$(APP_VERSION).img .PHONY: build-BK7231 -build-BK7231: submodules $(SDK_PATH)/apps/$(APP_NAME) +build-BK7231: $(SDK_PATH)/apps/$(APP_NAME) cd $(SDK_PATH)/platforms/$(TARGET_PLATFORM)/toolchain/$(APPS_BUILD_PATH) && sh $(APPS_BUILD_CMD) $(APP_NAME) $(APP_VERSION) $(TARGET_PLATFORM) rm $(SDK_PATH)/platforms/$(TARGET_PLATFORM)/toolchain/$(APPS_BUILD_PATH)/tools/generate/$(APP_NAME)_*.rbl || /bin/true rm $(SDK_PATH)/platforms/$(TARGET_PLATFORM)/toolchain/$(APPS_BUILD_PATH)/tools/generate/$(APP_NAME)_*.bin || /bin/true -OpenBL602: submodules sdk/OpenBL602/customer_app/bl602_sharedApp/bl602_sharedApp/shared prebuild_OpenBL602 +OpenBL602: prebuild_OpenBL602 sdk/OpenBL602/customer_app/bl602_sharedApp/bl602_sharedApp/shared $(MAKE) -C sdk/OpenBL602/customer_app/bl602_sharedApp USER_SW_VER=$(APP_VERSION) CONFIG_CHIP_NAME=BL602 CONFIG_LINK_ROM=1 -j $(MAKE) -C sdk/OpenBL602/customer_app/bl602_sharedApp USER_SW_VER=$(APP_VERSION) CONFIG_CHIP_NAME=BL602 bins mkdir -p output/$(APP_VERSION) @@ -192,21 +210,21 @@ sdk/OpenW600/tools/gcc-arm-none-eabi-4_9-2014q4/bin: submodules cd sdk/OpenW600/tools && tar -xf ../support/*.tar.bz2 .PHONY: OpenW800 -OpenW800: sdk/OpenW800/tools/w800/csky/bin sdk/OpenW800/sharedAppContainer/sharedApp prebuild_OpenW800 +OpenW800: prebuild_OpenW800 sdk/OpenW800/tools/w800/csky/bin sdk/OpenW800/sharedAppContainer/sharedApp $(MAKE) -C sdk/OpenW800 EXTRA_CCFLAGS=-DPLATFORM_W800 CONFIG_W800_USE_LIB=n CONFIG_W800_TOOLCHAIN_PATH="$(shell realpath sdk/OpenW800/tools/w800/csky/bin)/" mkdir -p output/$(APP_VERSION) cp sdk/OpenW800/bin/w800/w800.fls output/$(APP_VERSION)/OpenW800_$(APP_VERSION).fls cp sdk/OpenW800/bin/w800/w800_ota.img output/$(APP_VERSION)/OpenW800_$(APP_VERSION)_ota.img .PHONY: OpenW600 -OpenW600: sdk/OpenW600/tools/gcc-arm-none-eabi-4_9-2014q4/bin sdk/OpenW600/sharedAppContainer/sharedApp prebuild_OpenW600 +OpenW600: prebuild_OpenW600 sdk/OpenW600/tools/gcc-arm-none-eabi-4_9-2014q4/bin sdk/OpenW600/sharedAppContainer/sharedApp $(MAKE) -C sdk/OpenW600 TOOL_CHAIN_PATH="$(shell realpath sdk/OpenW600/tools/gcc-arm-none-eabi-4_9-2014q4/bin)/" APP_VERSION=$(APP_VERSION) mkdir -p output/$(APP_VERSION) cp sdk/OpenW600/bin/w600/w600.fls output/$(APP_VERSION)/OpenW600_$(APP_VERSION).fls cp sdk/OpenW600/bin/w600/w600_gz.img output/$(APP_VERSION)/OpenW600_$(APP_VERSION)_gz.img .PHONY: OpenLN882H -OpenLN882H: submodules sdk/OpenLN882H/project/OpenBeken/app prebuild_OpenLN882H +OpenLN882H: prebuild_OpenLN882H sdk/OpenLN882H/project/OpenBeken/app CROSS_TOOLCHAIN_ROOT="/usr/" cmake sdk/OpenLN882H -B sdk/OpenLN882H/build CROSS_TOOLCHAIN_ROOT="/usr/" cmake --build ./sdk/OpenLN882H/build mkdir -p output/$(APP_VERSION) @@ -273,6 +291,13 @@ OpenTR6260: prebuild_OpenTR6260 cd sdk/OpenTR6260/scripts && APP_VERSION=$(APP_VERSION) bash build_tr6260s1.sh mkdir -p output/$(APP_VERSION) cp sdk/OpenTR6260/out/tr6260s1/standalone/tr6260s1_0x007000.bin output/$(APP_VERSION)/OpenTR6260_$(APP_VERSION).bin + +.PHONY: OpenRTL87X0C +OpenRTL87X0C: prebuild_OpenRTL87X0C + $(MAKE) -C sdk/OpenRTL87X0C/project/OpenBeken/GCC-RELEASE APP_VERSION=$(APP_VERSION) -j $(shell nproc) + mkdir -p output/$(APP_VERSION) + cp sdk/OpenRTL87X0C/project/OpenBeken/GCC-RELEASE/application_is/Debug/bin/flash_is.bin output/$(APP_VERSION)/OpenRTL87X0C_$(APP_VERSION).bin + cp sdk/OpenRTL87X0C/project/OpenBeken/GCC-RELEASE/application_is/Debug/bin/firmware_is.bin output/$(APP_VERSION)/OpenRTL87X0C_$(APP_VERSION)_ota.img # clean .o files and output directory .PHONY: clean @@ -284,6 +309,7 @@ clean: $(MAKE) -C sdk/OpenW800 clean $(MAKE) -C sdk/OpenW600 clean $(MAKE) -C sdk/OpenTR6260/scripts tr6260s1_clean + $(MAKE) -C sdk/OpenRTL87X0C/project/OpenBeken/GCC-RELEASE clean test -d ./sdk/OpenLN882H/build && cmake --build ./sdk/OpenLN882H/build --target clean test -d ./platforms/ESP-IDF/build-32 && cmake --build ./platforms/ESP-IDF/build-32 --target clean test -d ./platforms/ESP-IDF/build-c3 && cmake --build ./platforms/ESP-IDF/build-c3 --target clean diff --git a/bouffalo.mk b/bouffalo.mk index 9b8e6b013..9dc0a2fed 100644 --- a/bouffalo.mk +++ b/bouffalo.mk @@ -9,13 +9,8 @@ COMPONENT_PRIV_INCLUDEDIRS := ## This component's src COMPONENT_SRCS := - COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS)) COMPONENT_OBJS := $(patsubst %.S,%.o, $(COMPONENT_OBJS)) -COMPONENT_SRCDIRS := src/ src/jsmn src/httpserver/ src/cmnds/ src/logging/ src/hal/bl602/ src/mqtt/ src/cJSON src/base64 src/driver src/devicegroups src/bitmessage src/littlefs - - - - +COMPONENT_SRCDIRS := src/ src/jsmn src/httpserver/ src/cmnds/ src/logging/ src/hal/bl602/ src/mqtt/ src/cJSON src/base64 src/driver src/devicegroups src/bitmessage src/littlefs src/hal/generic diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj index 7915f619d..e0be6fb0d 100644 --- a/openBeken_win32_mvsc2017.vcxproj +++ b/openBeken_win32_mvsc2017.vcxproj @@ -294,6 +294,7 @@ + true true diff --git a/platforms/ESP-IDF/main/CMakeLists.txt b/platforms/ESP-IDF/main/CMakeLists.txt index 30e2fb316..49dabce19 100644 --- a/platforms/ESP-IDF/main/CMakeLists.txt +++ b/platforms/ESP-IDF/main/CMakeLists.txt @@ -92,6 +92,15 @@ set(PROJ_ALL_SRC ../../../src/hal/espidf/hal_main_espidf.c ../../../src/hal/espidf/hal_pins_espidf.c ../../../src/hal/espidf/hal_wifi_espidf.c + ../../../src/hal/espidf/hal_uart_espidf.c + ../../../src/hal/generic/hal_adc_generic.c + ../../../src/hal/generic/hal_flashConfig_generic.c + ../../../src/hal/generic/hal_flashVars_generic.c + ../../../src/hal/generic/hal_generic.c + ../../../src/hal/generic/hal_main_generic.c + ../../../src/hal/generic/hal_pins_generic.c + ../../../src/hal/generic/hal_wifi_generic.c + ../../../src/hal/generic/hal_uart_generic.c ../../../src/httpserver/hass.c ../../../src/httpserver/http_basic_auth.c ../../../src/httpserver/http_fns.c diff --git a/platforms/ESP-IDF/sdkconfig.defaults b/platforms/ESP-IDF/sdkconfig.defaults index df345192c..9c37808a8 100644 --- a/platforms/ESP-IDF/sdkconfig.defaults +++ b/platforms/ESP-IDF/sdkconfig.defaults @@ -17,4 +17,6 @@ CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y CONFIG_HAL_LOG_LEVEL_ERROR=y CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1=n -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2=n \ No newline at end of file +CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2=n + +CONFIG_LWIP_TCP_MSL=1000 diff --git a/platforms/LN882H/CMakeLists.txt b/platforms/LN882H/CMakeLists.txt index 3b27e3dc5..a58c5d23d 100644 --- a/platforms/LN882H/CMakeLists.txt +++ b/platforms/LN882H/CMakeLists.txt @@ -96,6 +96,14 @@ set(PROJ_ALL_SRC app/src/hal/ln882h/hal_main_ln882h.c app/src/hal/ln882h/hal_pins_ln882h.c app/src/hal/ln882h/hal_wifi_ln882h.c + app/src/hal/generic/hal_adc_generic.c + app/src/hal/generic/hal_flashConfig_generic.c + app/src/hal/generic/hal_flashVars_generic.c + app/src/hal/generic/hal_generic.c + app/src/hal/generic/hal_main_generic.c + app/src/hal/generic/hal_pins_generic.c + app/src/hal/generic/hal_wifi_generic.c + app/src/hal/generic/hal_uart_generic.c app/src/httpserver/hass.c app/src/httpserver/http_basic_auth.c app/src/httpserver/http_fns.c diff --git a/platforms/RTL87X0C/OpenBeken.mk b/platforms/RTL87X0C/OpenBeken.mk new file mode 100644 index 000000000..db16f47b3 --- /dev/null +++ b/platforms/RTL87X0C/OpenBeken.mk @@ -0,0 +1,140 @@ +OBK_DIR = ../../../../.. + +CFLAGS += -DPLATFORM_RTL87X0C -DUSER_SW_VER='"$(APP_VERSION)"' + +SRC_C += ../../../../../platforms/RTL87X0C/main.c + +SRC_C += $(OBK_DIR)/src/base64/base64.c +SRC_C += $(OBK_DIR)/src/bitmessage/bitmessage_read.c +SRC_C += $(OBK_DIR)/src/bitmessage/bitmessage_write.c +SRC_C += $(OBK_DIR)/src/cJSON/cJSON.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_channels.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_eventHandlers.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_if.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_main.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_newLEDDriver_colors.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_newLEDDriver.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_repeatingEvents.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_script.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_simulatorOnly.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_tasmota.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_tcp.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_test.c +SRC_C += $(OBK_DIR)/src/cmnds/cmd_tokenizer.c +SRC_C += $(OBK_DIR)/src/devicegroups/deviceGroups_read.c +SRC_C += $(OBK_DIR)/src/devicegroups/deviceGroups_util.c +SRC_C += $(OBK_DIR)/src/devicegroups/deviceGroups_write.c +SRC_C += $(OBK_DIR)/src/driver/drv_main.c +#SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_adc_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_flashConfig_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_flashVars_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_generic_rtl87x0c.c +#SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_main_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_pins_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_wifi_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/rtl87x0c/hal_uart_rtl87x0c.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_adc_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_flashConfig_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_flashVars_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_main_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_pins_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_wifi_generic.c +SRC_C += $(OBK_DIR)/src/hal/generic/hal_uart_generic.c +SRC_C += $(OBK_DIR)/src/httpserver/hass.c +SRC_C += $(OBK_DIR)/src/httpserver/http_basic_auth.c +SRC_C += $(OBK_DIR)/src/httpserver/http_fns.c +SRC_C += $(OBK_DIR)/src/httpserver/http_tcp_server.c +SRC_C += $(OBK_DIR)/src/httpserver/new_tcp_server.c +SRC_C += $(OBK_DIR)/src/httpserver/json_interface.c +SRC_C += $(OBK_DIR)/src/httpserver/new_http.c +SRC_C += $(OBK_DIR)/src/httpserver/rest_interface.c +SRC_C += $(OBK_DIR)/src/mqtt/new_mqtt_deduper.c +SRC_C += $(OBK_DIR)/src/jsmn/jsmn.c +SRC_C += $(OBK_DIR)/src/logging/logging.c +SRC_C += $(OBK_DIR)/src/mqtt/new_mqtt.c +SRC_C += $(OBK_DIR)/src/new_cfg.c +SRC_C += $(OBK_DIR)/src/new_common.c +SRC_C += $(OBK_DIR)/src/new_ping.c +SRC_C += $(OBK_DIR)/src/new_pins.c +SRC_C += $(OBK_DIR)/src/rgb2hsv.c +SRC_C += $(OBK_DIR)/src/tiny_crc8.c +SRC_C += $(OBK_DIR)/src/user_main.c +#SRC_C += $(OBK_DIR)/src/cmnds/cmd_send.c +SRC_C += $(OBK_DIR)/src/driver/drv_adcButton.c +SRC_C += $(OBK_DIR)/src/driver/drv_adcSmoother.c +SRC_C += $(OBK_DIR)/src/driver/drv_aht2x.c +SRC_C += $(OBK_DIR)/src/driver/drv_battery.c +SRC_C += $(OBK_DIR)/src/driver/drv_bl_shared.c +SRC_C += $(OBK_DIR)/src/driver/drv_bl0937.c +SRC_C += $(OBK_DIR)/src/driver/drv_bl0942.c +#SRC_C += $(OBK_DIR)/src/driver/drv_bmp280.c +SRC_C += $(OBK_DIR)/src/driver/drv_bmpi2c.c +SRC_C += $(OBK_DIR)/src/driver/drv_bp1658cj.c +SRC_C += $(OBK_DIR)/src/driver/drv_bp5758d.c +SRC_C += $(OBK_DIR)/src/driver/drv_bridge_driver.c +SRC_C += $(OBK_DIR)/src/driver/drv_chargingLimit.c +SRC_C += $(OBK_DIR)/src/driver/drv_charts.c +SRC_C += $(OBK_DIR)/src/driver/drv_cht8305.c +SRC_C += $(OBK_DIR)/src/driver/drv_cse7766.c +SRC_C += $(OBK_DIR)/src/driver/drv_ddp.c +SRC_C += $(OBK_DIR)/src/driver/drv_debouncer.c +SRC_C += $(OBK_DIR)/src/driver/drv_dht_internal.c +SRC_C += $(OBK_DIR)/src/driver/drv_dht.c +SRC_C += $(OBK_DIR)/src/driver/drv_doorSensorWithDeepSleep.c +SRC_C += $(OBK_DIR)/src/driver/drv_gn6932.c +SRC_C += $(OBK_DIR)/src/driver/drv_hd2015.c +SRC_C += $(OBK_DIR)/src/driver/drv_ht16k33.c +SRC_C += $(OBK_DIR)/src/driver/drv_httpButtons.c +SRC_C += $(OBK_DIR)/src/driver/drv_hue.c +SRC_C += $(OBK_DIR)/src/driver/drv_kp18058.c +SRC_C += $(OBK_DIR)/src/driver/drv_kp18068.c +SRC_C += $(OBK_DIR)/src/driver/drv_max72xx_clock.c +SRC_C += $(OBK_DIR)/src/driver/drv_max72xx_internal.c +SRC_C += $(OBK_DIR)/src/driver/drv_max72xx_single.c +SRC_C += $(OBK_DIR)/src/driver/drv_mcp9808.c +SRC_C += $(OBK_DIR)/src/driver/drv_ntp_events.c +SRC_C += $(OBK_DIR)/src/driver/drv_ntp.c +SRC_C += $(OBK_DIR)/src/driver/drv_pt6523.c +SRC_C += $(OBK_DIR)/src/driver/drv_pwm_groups.c +SRC_C += $(OBK_DIR)/src/driver/drv_pwmToggler.c +SRC_C += $(OBK_DIR)/src/driver/drv_pwrCal.c +SRC_C += $(OBK_DIR)/src/driver/drv_rn8209.c +SRC_C += $(OBK_DIR)/src/driver/drv_sgp.c +SRC_C += $(OBK_DIR)/src/driver/drv_shiftRegister.c +SRC_C += $(OBK_DIR)/src/driver/drv_sht3x.c +#SRC_C += $(OBK_DIR)/src/driver/drv_sm15155e.c +#SRC_C += $(OBK_DIR)/src/driver/drv_sm16703P.c +SRC_C += $(OBK_DIR)/src/driver/drv_sm2135.c +SRC_C += $(OBK_DIR)/src/driver/drv_sm2235.c +SRC_C += $(OBK_DIR)/src/driver/drv_soft_i2c.c +#SRC_C += $(OBK_DIR)/src/driver/drv_soft_spi.c +#SRC_C += $(OBK_DIR)/src/driver/drv_spi_flash.c +#SRC_C += $(OBK_DIR)/src/driver/drv_spi.c +#SRC_C += $(OBK_DIR)/src/driver/drv_spidma.c +SRC_C += $(OBK_DIR)/src/driver/drv_ssdp.c +SRC_C += $(OBK_DIR)/src/driver/drv_tasmotaDeviceGroups.c +SRC_C += $(OBK_DIR)/src/driver/drv_test_drivers.c +SRC_C += $(OBK_DIR)/src/driver/drv_textScroller.c +SRC_C += $(OBK_DIR)/src/driver/drv_tm_gn_display_shared.c +SRC_C += $(OBK_DIR)/src/driver/drv_tm1637.c +SRC_C += $(OBK_DIR)/src/driver/drv_tm1638.c +SRC_C += $(OBK_DIR)/src/driver/drv_tuyaMCU.c +SRC_C += $(OBK_DIR)/src/driver/drv_tuyaMCUSensor.c +SRC_C += $(OBK_DIR)/src/driver/drv_uart.c +SRC_C += $(OBK_DIR)/src/driver/drv_ucs1912.c +SRC_C += $(OBK_DIR)/src/driver/drv_wemo.c +SRC_C += $(OBK_DIR)/src/driver/drv_ds1820_simple.c +#SRC_C += $(OBK_DIR)/src/httpclient/http_client.c +#SRC_C += $(OBK_DIR)/src/httpclient/utils_net.c +#SRC_C += $(OBK_DIR)/src/httpclient/utils_timer.c +SRC_C += $(OBK_DIR)/src/i2c/drv_i2c_lcd_pcf8574t.c +SRC_C += $(OBK_DIR)/src/i2c/drv_i2c_main.c +SRC_C += $(OBK_DIR)/src/i2c/drv_i2c_mcp23017.c +SRC_C += $(OBK_DIR)/src/i2c/drv_i2c_tc74.c +SRC_C += $(OBK_DIR)/src/littlefs/lfs_util.c +SRC_C += $(OBK_DIR)/src/littlefs/lfs.c +SRC_C += $(OBK_DIR)/src/littlefs/our_lfs.c +#SRC_C += $(OBK_DIR)/src/memory/memtest.c +#SRC_C += $(OBK_DIR)/src/ota/ota.c +#SRC_C += $(OBK_DIR)/src/sim/sim_uart.c diff --git a/platforms/RTL87X0C/main.c b/platforms/RTL87X0C/main.c new file mode 100644 index 000000000..0a5f85336 --- /dev/null +++ b/platforms/RTL87X0C/main.c @@ -0,0 +1,56 @@ +#include "FreeRTOS.h" +#include "task.h" +#include "diag.h" +#include "main.h" +#include "wifi_constants.h" +#include "hal_misc.h" +#include "hal_sys_ctrl.h" +#include "efuse_logical_api.h" + +extern uint32_t get_cur_fw_idx(void); +void Main_Init(); +void Main_OnEverySecond(); + +hal_reset_reason_t reset_reason; +rtw_mode_t wifi_mode = RTW_MODE_STA; +TaskHandle_t g_sys_task_handle1; +uint32_t current_fw_idx = 0; +uint8_t wmac[6] = { 0 }; + +void print_wlan_help(void* arg) {} +void hci_tp_close(void) {} +void sys_task1(void* pvParameters) +{ + Main_Init(); + for(;;) + { + vTaskDelay(1000 / portTICK_PERIOD_MS); + Main_OnEverySecond(); + } +} + +int main(void) +{ + rtl8710c_reset_reason_get(&reset_reason); + current_fw_idx = get_cur_fw_idx(); + + wlan_network(); + + hal_misc_swd_pin_ctrl(0); + + efuse_logical_read(0x11A, 6, (uint8_t*)wmac); + + xTaskCreate( + sys_task1, + "OpenBeken", + 8 * 256, + NULL, + 3, + &g_sys_task_handle1); + + /* Enable Schedule, Start Kernel */ + vTaskStartScheduler(); + + /* Should NEVER reach here */ + return 0; +} \ No newline at end of file diff --git a/platforms/TR6260/openbeken.mk b/platforms/TR6260/openbeken.mk index 1160d5488..45cde4542 100644 --- a/platforms/TR6260/openbeken.mk +++ b/platforms/TR6260/openbeken.mk @@ -1,6 +1,7 @@ VPATH += $(OBK_PATH) DEFINE += -DUSER_SW_VER='"$(APP_VERSION)"' DEFINE += -DPLATFORM_TR6260 +DEFINE += -DTCP_MSL=1000 CSRCS += base64/base64.c CSRCS += bitmessage/bitmessage_read.c @@ -30,6 +31,14 @@ CSRCS += hal/tr6260/hal_generic_tr6260.c CSRCS += hal/tr6260/hal_main_tr6260.c CSRCS += hal/tr6260/hal_pins_tr6260.c CSRCS += hal/tr6260/hal_wifi_tr6260.c +CSRCS += hal/generic/hal_adc_generic.c +CSRCS += hal/generic/hal_flashConfig_generic.c +CSRCS += hal/generic/hal_flashVars_generic.c +CSRCS += hal/generic/hal_generic.c +CSRCS += hal/generic/hal_main_generic.c +CSRCS += hal/generic/hal_pins_generic.c +CSRCS += hal/generic/hal_wifi_generic.c +CSRCS += hal/generic/hal_uart_generic.c CSRCS += httpserver/hass.c CSRCS += httpserver/http_basic_auth.c CSRCS += httpserver/http_fns.c diff --git a/platforms/W600/Makefile b/platforms/W600/Makefile index 8220e3e90..300483713 100644 --- a/platforms/W600/Makefile +++ b/platforms/W600/Makefile @@ -58,6 +58,14 @@ CSRCS += $(_SHARED_APP)/hal/w800/hal_generic_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_main_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_pins_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_wifi_w800.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_adc_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_flashConfig_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_flashVars_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_main_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_pins_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_wifi_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_uart_generic.c CSRCS += $(_SHARED_APP)/httpserver/hass.c CSRCS += $(_SHARED_APP)/httpserver/http_fns.c CSRCS += $(_SHARED_APP)/httpserver/http_tcp_server.c diff --git a/platforms/W800/Makefile b/platforms/W800/Makefile index cb22a29b4..9c8874db0 100644 --- a/platforms/W800/Makefile +++ b/platforms/W800/Makefile @@ -34,6 +34,14 @@ CSRCS += $(_SHARED_APP)/hal/w800/hal_generic_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_main_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_pins_w800.c CSRCS += $(_SHARED_APP)/hal/w800/hal_wifi_w800.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_adc_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_flashConfig_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_flashVars_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_main_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_pins_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_wifi_generic.c +CSRCS += $(_SHARED_APP)/hal/generic/hal_uart_generic.c CSRCS += $(_SHARED_APP)/httpserver/hass.c CSRCS += $(_SHARED_APP)/httpserver/http_fns.c CSRCS += $(_SHARED_APP)/httpserver/http_tcp_server.c diff --git a/platforms/XR809/Makefile b/platforms/XR809/Makefile index 2d9e3b842..60807473f 100644 --- a/platforms/XR809/Makefile +++ b/platforms/XR809/Makefile @@ -53,6 +53,15 @@ SRCS += ../shared/src/hal/xr809/hal_pins_xr809 SRCS += ../shared/src/hal/xr809/hal_flashConfig_xr809 SRCS += ../shared/src/hal/xr809/hal_flashVars_xr809 +SRCS += ../shared/src/hal/generic/hal_adc_generic +SRCS += ../shared/src/hal/generic/hal_flashConfig_generic +SRCS += ../shared/src/hal/generic/hal_flashVars_generic +SRCS += ../shared/src/hal/generic/hal_generic +SRCS += ../shared/src/hal/generic/hal_main_generic +SRCS += ../shared/src/hal/generic/hal_pins_generic +SRCS += ../shared/src/hal/generic/hal_wifi_generic +SRCS += ../shared/src/hal/generic/hal_uart_generic + SRCS += ../shared/src/user_main diff --git a/sdk/OpenRTL87X0C b/sdk/OpenRTL87X0C new file mode 160000 index 000000000..29dc19b7c --- /dev/null +++ b/sdk/OpenRTL87X0C @@ -0,0 +1 @@ +Subproject commit 29dc19b7cd4511ca1ff036863c6f513205606d72 diff --git a/src/cmnds/cmd_if.c b/src/cmnds/cmd_if.c index d1697297c..f4f7e1724 100644 --- a/src/cmnds/cmd_if.c +++ b/src/cmnds/cmd_if.c @@ -225,20 +225,23 @@ float getActiveRepeatingEvents(const char *s) { return RepeatingEvents_GetActiveCount(); } -#ifdef ENABLE_DRIVER_BL0937 - -float getVoltage(const char *s) { - return DRV_GetReading(OBK_VOLTAGE); -} #ifdef ENABLE_DRIVER_BATTERY -float getBatteryVoltage(const char *s) { +float getBatteryVoltage(const char* s) +{ return Battery_lastreading(OBK_BATT_VOLTAGE); } -float getBatteryLevel(const char *s) { +float getBatteryLevel(const char* s) +{ return Battery_lastreading(OBK_BATT_LEVEL); } #endif +#ifdef ENABLE_DRIVER_BL0937 + +float getVoltage(const char *s) { + return DRV_GetReading(OBK_VOLTAGE); +} + float getCurrent(const char *s) { return DRV_GetReading(OBK_CURRENT); } @@ -256,12 +259,6 @@ float getToday(const char *s) { return DRV_GetReading(OBK_CONSUMPTION_TODAY); } - - -float getNTPOn(const char *s) { - return NTP_IsTimeSynced(); -} - #endif float getRand(const char *s) { @@ -299,6 +296,15 @@ float getMDay(const char *s) { return NTP_GetMDay(); } +#ifdef ENABLE_NTP + +float getNTPOn(const char* s) +{ + return NTP_IsTimeSynced(); +} + +#endif + #if ENABLE_NTP_SUNRISE_SUNSET float getSunrise(const char *s) { @@ -465,6 +471,7 @@ const constant_t g_constants[] = { ////cnstdetail:"descr":"Current Year from NTP", ////cnstdetail:"requires":""} { "$year", &getYear }, +#ifdef ENABLE_DRIVER_BL0937 ////cnstdetail:{"name":"$yesterday", ////cnstdetail:"title":"$yesterday", ////cnstdetail:"descr":"", @@ -475,6 +482,7 @@ const constant_t g_constants[] = { ////cnstdetail:"descr":"", ////cnstdetail:"requires":""} { "$today", &getToday }, +#endif #if ENABLE_NTP_SUNRISE_SUNSET ////cnstdetail:{"name":"$sunrise", ////cnstdetail:"title":"$sunrise", @@ -532,11 +540,13 @@ const constant_t g_constants[] = { //cnstdetail:"requires":""} { "$rebootReason", &getRebootReason }, #endif +#ifndef NO_CHIP_TEMPERATURE //cnstdetail:{"name":"$intTemp", //cnstdetail:"title":"$intTemp", //cnstdetail:"descr":"Internal temperature (of WiFi module sensor)", //cnstdetail:"requires":""} { "$intTemp", &getInternalTemperature }, +#endif }; static int g_totalConstants = sizeof(g_constants) / sizeof(g_constants[0]); diff --git a/src/cmnds/cmd_main.c b/src/cmnds/cmd_main.c index df08b17f3..dd556bcaf 100644 --- a/src/cmnds/cmd_main.c +++ b/src/cmnds/cmd_main.c @@ -29,6 +29,8 @@ int cmd_uartInitIndex = 0; #include "driver/gpio.h" #include "driver/ledc.h" #include "esp_check.h" +#elif PLATFORM_RTL87X0C +#include "wifi_conf.h" #endif #define HASH_SIZE 128 @@ -161,6 +163,20 @@ static commandResult_t CMD_PowerSave(const void* context, const char* cmd, const ADDLOG_INFO(LOG_FEATURE_CMD, "PowerSave disabled"); esp_wifi_set_ps(WIFI_PS_NONE); } +#elif PLATFORM_RTL87X0C + if(!wifi_is_up(RTW_STA_INTERFACE)) + { + ADDLOG_ERROR(LOG_FEATURE_CMD, "Wifi is not on or in AP mode, failed setting powersave!"); + return CMD_RES_ERROR; + } + if(bOn) + { + wifi_enable_powersave(); + } + else + { + wifi_disable_powersave(); + } #else ADDLOG_INFO(LOG_FEATURE_CMD, "PowerSave is not implemented on this platform"); #endif @@ -293,7 +309,8 @@ static commandResult_t CMD_ClearAll(const void* context, const char* cmd, const CHANNEL_ClearAllChannels(); CMD_ClearAllHandlers(0, 0, 0, 0); RepeatingEvents_Cmd_ClearRepeatingEvents(0, 0, 0, 0); -#if defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_BEKEN) || defined(PLATFORM_LN882H) || defined(PLATFORM_TR6260) +#if defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_BEKEN) || defined(PLATFORM_LN882H) \ + || defined(PLATFORM_ESPIDF) || defined(PLATFORM_TR6260) || defined(PLATFORM_RTL87X0C) CMD_resetSVM(0, 0, 0, 0); #endif @@ -855,7 +872,8 @@ void CMD_Init_Early() { CMD_RegisterCommand("IndexRefreshInterval", CMD_IndexRefreshInterval, NULL); -#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) || (defined PLATFORM_LN882H) || (defined PLATFORM_ESPIDF) || defined(PLATFORM_TR6260) +#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) || (defined PLATFORM_LN882H) \ + || (defined PLATFORM_ESPIDF) || defined(PLATFORM_TR6260) || defined(PLATFORM_RTL87X0C) CMD_InitScripting(); #endif if (!bSafeMode) { @@ -872,7 +890,8 @@ void CMD_Init_Delayed() { if (CFG_HasFlag(OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER)) { CMD_StartTCPCommandLine(); } -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) +#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) \ + || defined(PLATFORM_RTL87X0C) UART_AddCommands(); #endif } diff --git a/src/driver/drv_dht_internal.c b/src/driver/drv_dht_internal.c index 2cc86c292..66011ca5e 100644 --- a/src/driver/drv_dht_internal.c +++ b/src/driver/drv_dht_internal.c @@ -33,48 +33,13 @@ our DHT sensors wrapper is in drv_dht.c #include "drv_local.h" #include "drv_dht_internal.h" #include +#include "../hal/hal_generic.h" #define TIMEOUT UINT32_MAX void usleep2(int r) //delay function do 10*r nops, because rtos_delay_milliseconds is too much { -#ifdef WIN32 - // not possible on Windows port -#elif PLATFORM_BL602 - for (volatile int i = 0; i < r; i++) { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#elif PLATFORM_W600 - for (volatile int i = 0; i < r; i++) { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#elif PLATFORM_ESPIDF - usleep(r); -#else - for (volatile int i = 0; i < r; i++) { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#endif + HAL_Delay_us(r); } #define delay(x) usleep2(x*1000); diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index 547684e68..8bbe02d83 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -1,4 +1,5 @@ #include "drv_ds1820_simple.h" +#include "../hal/hal_generic.h" #if PLATFORM_ESPIDF #include "freertos/task.h" #define noInterrupts() portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;taskENTER_CRITICAL(&mux) @@ -22,81 +23,7 @@ static int ds18_conversionPeriod = 0; // usleep adopted from DHT driver void usleepds(int r) { -#ifdef WIN32 - // not possible on Windows port -#elif PLATFORM_BL602 - for(volatile int i = 0; i < r; i++) - { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); // 5 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //10 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#elif PLATFORM_W600 - for(volatile int i = 0; i < r; i++) - { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); // 5 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#elif PLATFORM_W800 - for(volatile int i = 0; i < r; i++) - { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); // 5 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //10 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //15 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //20 - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#elif PLATFORM_BEKEN - float adj = 1; - if(g_powersave) adj = 1.5; - usleep((17 * r * adj) / 10); // "1" is to fast and "2" to slow, 1.7 seems better than 1.5 (only from observing readings, no scope involved) -#elif PLATFORM_LN882H - usleep(5 * r); // "5" seems o.k -#elif PLATFORM_ESPIDF - usleep(r); -#elif PLATFORM_TR6260 - usdelay(r); -#else - for(volatile int i = 0; i < r; i++) - { - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); - } -#endif + HAL_Delay_us(r); } // add some "special timing" for Beken - works w/o and with powerSave 1 for me diff --git a/src/driver/drv_uart.c b/src/driver/drv_uart.c index 201341a25..8c1a9c30a 100644 --- a/src/driver/drv_uart.c +++ b/src/driver/drv_uart.c @@ -5,108 +5,7 @@ #include "../cmnds/cmd_public.h" #include "../cmnds/cmd_local.h" #include "../logging/logging.h" - -#if PLATFORM_BK7231T | PLATFORM_BK7231N -#include "../../beken378/func/user_driver/BkDriverUart.h" -#endif - -#if PLATFORM_BL602 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -// backlog logtype none; startDriver BL0942 -#endif -#if PLATFORM_BK7231T | PLATFORM_BK7231N -// from uart_bk.c -extern void bk_send_byte(UINT8 uport, UINT8 data); -int g_chosenUART = BK_UART_1; -#elif WINDOWS - -#elif PLATFORM_BL602 -//int g_fd; -uint8_t g_id = 1; -int fd_console = -1; -#elif PLATFORM_ESPIDF -#include "driver/uart.h" -#include "driver/gpio.h" -#ifdef CONFIG_IDF_TARGET_ESP32C6 -#define RX1_PIN GPIO_NUM_7 -#define TX1_PIN GPIO_NUM_5 -#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 -#define RX1_PIN GPIO_NUM_6 -#define TX1_PIN GPIO_NUM_7 -#else -#define RX1_PIN UART_PIN_NO_CHANGE -#define TX1_PIN UART_PIN_NO_CHANGE -#endif -uart_port_t uartnum = UART_NUM_0; -static QueueHandle_t uart_queue; -uint8_t* data = NULL; -#else -#endif +#include "../hal/hal_uart.h" static byte *g_recvBuf = 0; static int g_recvBufSize = 0; @@ -158,114 +57,11 @@ void UART_AppendByteToReceiveRingBuffer(int rc) { } } -#if PLATFORM_BK7231T | PLATFORM_BK7231N -void test_ty_read_uart_data_to_buffer(int port, void* param) -{ - int rc = 0; - - while((rc = uart_read_byte(port)) != -1) - UART_AppendByteToReceiveRingBuffer(rc); -} -#endif - -#ifdef PLATFORM_BL602 -//void UART_RunQuickTick() { -//} -//void MY_UART1_IRQHandler(void) -//{ -// int length; -// byte buffer[16]; -// //length = aos_read(g_fd, buffer, 1); -// //if (length > 0) { -// // UART_AppendByteToReceiveRingBuffer(buffer[0]); -// //} -// int res = bl_uart_data_recv(g_id); -// if (res >= 0) { -// addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "UART received: %i\n", res); -// UART_AppendByteToReceiveRingBuffer(res); -// } -//} - -static void console_cb_read(int fd, void *param) -{ - char buffer[64]; /* adapt to usb cdc since usb fifo is 64 bytes */ - int ret; - int i; - - ret = aos_read(fd, buffer, sizeof(buffer)); - if (ret > 0) { - if (ret < sizeof(buffer)) { - fd_console = fd; - buffer[ret] = 0; - addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "BL602 received: %s\n", buffer); - for (i = 0; i < ret; i++) { - UART_AppendByteToReceiveRingBuffer(buffer[i]); - } - } - else { - printf("-------------BUG from aos_read for ret\r\n"); - } - } -} -#endif - -#ifdef PLATFORM_ESPIDF - -static void uart_event_task(void* pvParameters) +void UART_SendByte(byte b) { - uart_event_t event; - for(;;) - { - if(xQueueReceive(uart_queue, (void*)&event, (TickType_t)portMAX_DELAY)) - { - bzero(data, 256); - switch(event.type) - { - case UART_DATA: - uart_read_bytes(uartnum, data, event.size, portMAX_DELAY); - for(int i = 0; i < event.size; i++) - { - UART_AppendByteToReceiveRingBuffer(data[i]); - vTaskDelay(3); - } - break; - case UART_BUFFER_FULL: - case UART_FIFO_OVF: - addLogAdv(LOG_WARN, LOG_FEATURE_CMD, "%s", event.type == UART_BUFFER_FULL ? "UART_BUFFER_FULL" : "UART_FIFO_OVF"); - uart_flush_input(uartnum); - xQueueReset(uart_queue); - break; - default: - break; - } - } - } - free(data); - data = NULL; - vTaskDelete(NULL); + HAL_UART_SendByte(b); } -#endif - -void UART_SendByte(byte b) { -#if PLATFORM_BK7231T | PLATFORM_BK7231N - // BK_UART_1 is defined to 0 - bk_send_byte(g_chosenUART, b); -#elif WINDOWS - void SIM_AppendUARTByte(byte b); - // STUB - for testing - SIM_AppendUARTByte(b); -#if 1 - printf("%02X", b); -#endif - //addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"%02X", b); -#elif PLATFORM_BL602 - aos_write(fd_console, &b, 1); - //bl_uart_data_send(g_id, b); -#elif PLATFORM_ESPIDF - uart_write_bytes(uartnum, &b, 1); -#endif -} commandResult_t CMD_UART_Send_Hex(const void *context, const char *cmd, const char *args, int cmdFlags) { if (!(*args)) { addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "CMD_UART_Send_Hex: requires 1 argument (hex string, like FFAABB00CCDD\n"); @@ -339,107 +135,15 @@ commandResult_t CMD_UART_Send_ASCII(const void *context, const char *cmd, const return CMD_RES_OK; } -void UART_ResetForSimulator() { +void UART_ResetForSimulator() +{ g_uart_init_counter = 0; } int UART_InitUART(int baud, int parity) { g_uart_init_counter++; -#if PLATFORM_BK7231T | PLATFORM_BK7231N - bk_uart_config_t config; - - config.baud_rate = baud; - config.data_width = 0x03; - config.parity = parity; //0:no parity,1:odd,2:even - config.stop_bits = 0; //0:1bit,1:2bit - config.flow_control = 0; //FLOW_CTRL_DISABLED - config.flags = 0; - - - // BK_UART_1 is defined to 0 - if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) - { - g_chosenUART = BK_UART_2; - } - else - { - g_chosenUART = BK_UART_1; - } - bk_uart_initialize(g_chosenUART, &config, NULL); - bk_uart_set_rx_callback(g_chosenUART, test_ty_read_uart_data_to_buffer, NULL); -#elif PLATFORM_BL602 - if(fd_console < 0) - { - //uint8_t tx_pin = 16; - //uint8_t rx_pin = 7; - //bl_uart_init(g_id, tx_pin, rx_pin, 0, 0, baud); - //g_fd = aos_open(name, 0); - //bl_uart_int_rx_enable(1); - //bl_irq_register(UART1_IRQn, MY_UART1_IRQHandler); - //bl_irq_enable(UART1_IRQn); - //vfs_uart_init_simple_mode(0, 7, 16, baud, "/dev/ttyS0"); - - if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) - { - fd_console = aos_open("/dev/ttyS1", 0); - } - else - { - fd_console = aos_open("/dev/ttyS0", 0); - } - if(fd_console >= 0) - { - aos_ioctl(fd_console, IOCTL_UART_IOC_BAUD_MODE, baud); - addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "Init CLI with event Driven\r\n"); - aos_cli_init(0); - aos_poll_read_fd(fd_console, console_cb_read, (void*)0x12345678); - } - else - { - addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "failed CLI with event Driven\r\n"); - } - } -#elif PLATFORM_ESPIDF - if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) - { - uartnum = UART_NUM_1; - esp_log_level_set("*", ESP_LOG_INFO); - } - else - { - uartnum = UART_NUM_0; - esp_log_level_set("*", ESP_LOG_NONE); - } - if(uart_is_driver_installed(uartnum)) - { - uart_driver_delete(uartnum); - } - uart_config_t uart_config = - { - .baud_rate = baud, - .data_bits = UART_DATA_8_BITS, - .parity = parity > 0 ? parity + 1 : parity, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .source_clk = UART_SCLK_DEFAULT, - }; - uart_driver_install(uartnum, 256, 0, 20, &uart_queue, 0); - uart_param_config(uartnum, &uart_config); - if(uartnum == UART_NUM_0) - { - uart_set_pin(uartnum, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - else - { - uart_set_pin(uartnum, TX1_PIN, RX1_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - if(data == NULL) - { - data = (uint8_t*)malloc(256); - xTaskCreate(uart_event_task, "uart_event_task", 1024, NULL, 16, NULL); - } -#endif + HAL_UART_Init(baud, parity); return g_uart_init_counter; } diff --git a/src/hal/bk7231/hal_generic_bk7231.c b/src/hal/bk7231/hal_generic_bk7231.c index 466c7b717..17b77bc9b 100644 --- a/src/hal/bk7231/hal_generic_bk7231.c +++ b/src/hal/bk7231/hal_generic_bk7231.c @@ -1,8 +1,29 @@ - +#include "../../new_common.h" +#include "../hal_generic.h" +#include // from wlan_ui.c void bk_reboot(void); +extern bool g_powersave; -void HAL_RebootModule() { +void HAL_RebootModule() +{ bk_reboot(); -} \ No newline at end of file +} + +void HAL_Delay_us(int delay) +{ + float adj = 1; + if(g_powersave) adj = 1.5; + usleep((17 * delay * adj) / 10); // "1" is to fast and "2" to slow, 1.7 seems better than 1.5 (only from observing readings, no scope involved) +} + +void HAL_Configure_WDT() +{ + bk_wdg_initialize(10000); +} + +void HAL_Run_WDT() +{ + bk_wdg_reload(); +} diff --git a/src/hal/bk7231/hal_uart_bk7231.c b/src/hal/bk7231/hal_uart_bk7231.c new file mode 100644 index 000000000..dc591572a --- /dev/null +++ b/src/hal/bk7231/hal_uart_bk7231.c @@ -0,0 +1,51 @@ +#include "../hal_uart.h" +#include "../../new_pins.h" +#include "../../new_cfg.h" +#include "../../cmnds/cmd_public.h" +#include "../../cmnds/cmd_local.h" +#include "../../logging/logging.h" +#include "../../../beken378/func/user_driver/BkDriverUart.h" + +// from uart_bk.c +extern void bk_send_byte(UINT8 uport, UINT8 data); +int g_chosenUART = BK_UART_1; + +void test_ty_read_uart_data_to_buffer(int port, void* param) +{ + int rc = 0; + + while((rc = uart_read_byte(port)) != -1) + UART_AppendByteToReceiveRingBuffer(rc); +} + +void HAL_UART_SendByte(byte b) +{ + // BK_UART_1 is defined to 0 + bk_send_byte(g_chosenUART, b); +} + +int HAL_UART_Init(int baud, int parity) +{ + bk_uart_config_t config; + + config.baud_rate = baud; + config.data_width = 0x03; + config.parity = parity; //0:no parity,1:odd,2:even + config.stop_bits = 0; //0:1bit,1:2bit + config.flow_control = 0; //FLOW_CTRL_DISABLED + config.flags = 0; + + + // BK_UART_1 is defined to 0 + if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) + { + g_chosenUART = BK_UART_2; + } + else + { + g_chosenUART = BK_UART_1; + } + bk_uart_initialize(g_chosenUART, &config, NULL); + bk_uart_set_rx_callback(g_chosenUART, test_ty_read_uart_data_to_buffer, NULL); + return 1; +} \ No newline at end of file diff --git a/src/hal/bl602/hal_generic_bl602.c b/src/hal/bl602/hal_generic_bl602.c index 2809b965a..bcc516a7c 100644 --- a/src/hal/bl602/hal_generic_bl602.c +++ b/src/hal/bl602/hal_generic_bl602.c @@ -1,12 +1,43 @@ #ifdef PLATFORM_BL602 +#include "../hal_generic.h" #include "../../new_common.h" #include +#include -void HAL_RebootModule() { - +void HAL_RebootModule() +{ hal_reboot(); +} + +void HAL_Delay_us(int delay) +{ + for(volatile int i = 0; i < delay; i++) + { + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); // 5 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //10 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + } +} + +void HAL_Configure_WDT() +{ + bl_wdt_init(3000); +} +void HAL_Run_WDT() +{ + bl_wdt_feed(); } -#endif // PLATFORM_XR809 \ No newline at end of file +#endif // PLATFORM_BL602 diff --git a/src/hal/bl602/hal_uart_bl602.c b/src/hal/bl602/hal_uart_bl602.c new file mode 100644 index 000000000..1202c7d79 --- /dev/null +++ b/src/hal/bl602/hal_uart_bl602.c @@ -0,0 +1,166 @@ +#ifdef PLATFORM_BL602 + +#include "../../new_pins.h" +#include "../../new_cfg.h" +#include "../../cmnds/cmd_public.h" +#include "../../cmnds/cmd_local.h" +#include "../../logging/logging.h" + +#include "../hal_uart.h" +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +//int g_fd; +uint8_t g_id = 1; +int fd_console = -1; + +//void UART_RunQuickTick() { +//} +//void MY_UART1_IRQHandler(void) +//{ +// int length; +// byte buffer[16]; +// //length = aos_read(g_fd, buffer, 1); +// //if (length > 0) { +// // UART_AppendByteToReceiveRingBuffer(buffer[0]); +// //} +// int res = bl_uart_data_recv(g_id); +// if (res >= 0) { +// addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "UART received: %i\n", res); +// UART_AppendByteToReceiveRingBuffer(res); +// } +//} + +static void console_cb_read(int fd, void* param) +{ + char buffer[64]; /* adapt to usb cdc since usb fifo is 64 bytes */ + int ret; + int i; + + ret = aos_read(fd, buffer, sizeof(buffer)); + if(ret > 0) + { + if(ret < sizeof(buffer)) + { + fd_console = fd; + buffer[ret] = 0; + addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "BL602 received: %s\n", buffer); + for(i = 0; i < ret; i++) + { + UART_AppendByteToReceiveRingBuffer(buffer[i]); + } + } + else + { + printf("-------------BUG from aos_read for ret\r\n"); + } + } +} + +void HAL_UART_SendByte(byte b) +{ + aos_write(fd_console, &b, 1); + //bl_uart_data_send(g_id, b); +} + +int HAL_UART_Init(int baud, int parity) +{ + if(fd_console < 0) + { + //uint8_t tx_pin = 16; + //uint8_t rx_pin = 7; + //bl_uart_init(g_id, tx_pin, rx_pin, 0, 0, baud); + //g_fd = aos_open(name, 0); + //bl_uart_int_rx_enable(1); + //bl_irq_register(UART1_IRQn, MY_UART1_IRQHandler); + //bl_irq_enable(UART1_IRQn); + //vfs_uart_init_simple_mode(0, 7, 16, baud, "/dev/ttyS0"); + + if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) + { + fd_console = aos_open("/dev/ttyS1", 0); + } + else + { + fd_console = aos_open("/dev/ttyS0", 0); + } + if(fd_console >= 0) + { + aos_ioctl(fd_console, IOCTL_UART_IOC_BAUD_MODE, baud); + addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "Init CLI with event Driven\r\n"); + aos_cli_init(0); + aos_poll_read_fd(fd_console, console_cb_read, (void*)0x12345678); + } + else + { + addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "failed CLI with event Driven\r\n"); + } + } + return 1; +} + +#endif \ No newline at end of file diff --git a/src/hal/espidf/hal_generic_espidf.c b/src/hal/espidf/hal_generic_espidf.c index de5ae3265..5925b98c1 100644 --- a/src/hal/espidf/hal_generic_espidf.c +++ b/src/hal/espidf/hal_generic_espidf.c @@ -1,8 +1,11 @@ #ifdef PLATFORM_ESPIDF +#include +#include "../hal_generic.h" #include "esp_system.h" #include "nvs_flash.h" #include "nvs.h" +#include "freertos/FreeRTOS.h" static int bFlashReady = 0; @@ -27,4 +30,9 @@ void HAL_RebootModule() esp_restart(); } +void HAL_Delay_us(int delay) +{ + usleep(delay); +} + #endif // PLATFORM_ESPIDF diff --git a/src/hal/espidf/hal_uart_espidf.c b/src/hal/espidf/hal_uart_espidf.c new file mode 100644 index 000000000..ab4e453e1 --- /dev/null +++ b/src/hal/espidf/hal_uart_espidf.c @@ -0,0 +1,110 @@ +#ifdef PLATFORM_ESPIDF + +#include "../hal_uart.h" +#include "../../new_pins.h" +#include "../../new_cfg.h" +#include "../../cmnds/cmd_public.h" +#include "../../cmnds/cmd_local.h" +#include "../../logging/logging.h" +#include "driver/uart.h" +#include "driver/gpio.h" + +#ifdef CONFIG_IDF_TARGET_ESP32C6 +#define RX1_PIN GPIO_NUM_7 +#define TX1_PIN GPIO_NUM_5 +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 +#define RX1_PIN GPIO_NUM_6 +#define TX1_PIN GPIO_NUM_7 +#else +#define RX1_PIN UART_PIN_NO_CHANGE +#define TX1_PIN UART_PIN_NO_CHANGE +#endif + +uart_port_t uartnum = UART_NUM_0; +static QueueHandle_t uart_queue; +uint8_t* data = NULL; + +static void uart_event_task(void* pvParameters) +{ + uart_event_t event; + for(;;) + { + if(xQueueReceive(uart_queue, (void*)&event, (TickType_t)portMAX_DELAY)) + { + bzero(data, 512); + switch(event.type) + { + case UART_DATA: + uart_read_bytes(uartnum, data, event.size, portMAX_DELAY); + for(int i = 0; i < event.size; i++) + { + UART_AppendByteToReceiveRingBuffer(data[i]); + } + break; + case UART_BUFFER_FULL: + case UART_FIFO_OVF: + addLogAdv(LOG_WARN, LOG_FEATURE_CMD, "%s", event.type == UART_BUFFER_FULL ? "UART_BUFFER_FULL" : "UART_FIFO_OVF"); + uart_flush_input(uartnum); + xQueueReset(uart_queue); + break; + default: + break; + } + } + } + free(data); + data = NULL; + vTaskDelete(NULL); +} + +void HAL_UART_SendByte(byte b) +{ + uart_write_bytes(uartnum, &b, 1); +} + +int HAL_UART_Init(int baud, int parity) +{ + if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) + { + uartnum = UART_NUM_1; + esp_log_level_set("*", ESP_LOG_INFO); + } + else + { + uartnum = UART_NUM_0; + esp_log_level_set("*", ESP_LOG_NONE); + } + if(uart_is_driver_installed(uartnum)) + { + uart_disable_rx_intr(uartnum); + uart_driver_delete(uartnum); + } + uart_config_t uart_config = + { + .baud_rate = baud, + .data_bits = UART_DATA_8_BITS, + .parity = parity > 0 ? parity + 1 : parity, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .source_clk = UART_SCLK_DEFAULT, + }; + uart_driver_install(uartnum, 512, 0, 20, &uart_queue, 0); + uart_param_config(uartnum, &uart_config); + if(uartnum == UART_NUM_0) + { + uart_set_pin(uartnum, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + else + { + uart_set_pin(uartnum, TX1_PIN, RX1_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + if(data == NULL) + { + data = (uint8_t*)malloc(512); + xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, 16, NULL); + uart_enable_rx_intr(uartnum); + } + return 1; +} + +#endif diff --git a/src/hal/generic/hal_adc_generic.c b/src/hal/generic/hal_adc_generic.c new file mode 100644 index 000000000..ebdc0bf15 --- /dev/null +++ b/src/hal/generic/hal_adc_generic.c @@ -0,0 +1,11 @@ +#include "../hal_adc.h" + +void __attribute__((weak)) HAL_ADC_Init(int pinNumber) +{ + +} + +int __attribute__((weak)) HAL_ADC_Read(int pinNumber) +{ + return 0; +} diff --git a/src/hal/generic/hal_flashConfig_generic.c b/src/hal/generic/hal_flashConfig_generic.c new file mode 100644 index 000000000..9eee36c19 --- /dev/null +++ b/src/hal/generic/hal_flashConfig_generic.c @@ -0,0 +1,11 @@ +#include "../hal_flashConfig.h" + +int __attribute__((weak)) HAL_Configuration_ReadConfigMemory(void* target, int dataLen) +{ + return 0; +} + +int __attribute__((weak)) HAL_Configuration_SaveConfigMemory(void* src, int dataLen) +{ + return 0; +} diff --git a/src/hal/generic/hal_flashVars_generic.c b/src/hal/generic/hal_flashVars_generic.c new file mode 100644 index 000000000..19f2ff049 --- /dev/null +++ b/src/hal/generic/hal_flashVars_generic.c @@ -0,0 +1,72 @@ +#include "../../new_common.h" +#include "../hal_flashVars.h" +#include "../../logging/logging.h" + +// call at startup +void __attribute__((weak)) HAL_FlashVars_IncreaseBootCount() +{ + +} + +void __attribute__((weak)) HAL_FlashVars_SaveChannel(int index, int value) +{ + +} + +void __attribute__((weak)) HAL_FlashVars_ReadLED(byte* mode, short* brightness, short* temperature, byte* rgb, byte* bEnableAll) +{ + +} + +void __attribute__((weak)) HAL_FlashVars_SaveLED(byte mode, short brightness, short temperature, byte r, byte g, byte b, byte bEnableAll) +{ + +} + +short __attribute__((weak)) HAL_FlashVars_ReadUsage() +{ + return 0; +} + +void __attribute__((weak)) HAL_FlashVars_SaveTotalUsage(short usage) +{ + +} + +// call once started (>30s?) +void __attribute__((weak)) HAL_FlashVars_SaveBootComplete() +{ + +} + +// call to return the number of boots since a HAL_FlashVars_SaveBootComplete +int __attribute__((weak)) HAL_FlashVars_GetBootFailures() +{ + int diff = 0; + return diff; +} + +int __attribute__((weak)) HAL_FlashVars_GetBootCount() +{ + return 0; +} + +int __attribute__((weak)) HAL_FlashVars_GetChannelValue(int ch) +{ + return 0; +} + +int __attribute__((weak)) HAL_GetEnergyMeterStatus(ENERGY_METERING_DATA* data) +{ + return 0; +} + +int __attribute__((weak)) HAL_SetEnergyMeterStatus(ENERGY_METERING_DATA* data) +{ + return 0; +} + +void __attribute__((weak)) HAL_FlashVars_SaveTotalConsumption(float total_consumption) +{ + +} diff --git a/src/hal/generic/hal_generic.c b/src/hal/generic/hal_generic.c new file mode 100644 index 000000000..fbc22769b --- /dev/null +++ b/src/hal/generic/hal_generic.c @@ -0,0 +1,26 @@ +#include "../hal_generic.h" + +void __attribute__((weak)) HAL_RebootModule() +{ + +} + +void __attribute__((weak)) HAL_Delay_us(int delay) +{ + for(volatile int i = 0; i < delay; i++) + { + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + } +} + +void __attribute__((weak)) HAL_Configure_WDT() +{ + +} + +void __attribute__((weak)) HAL_Run_WDT() +{ + +} diff --git a/src/hal/generic/hal_main_generic.c b/src/hal/generic/hal_main_generic.c new file mode 100644 index 000000000..c4aa2856f --- /dev/null +++ b/src/hal/generic/hal_main_generic.c @@ -0,0 +1,3 @@ +#include "../../new_common.h" +#include "../../logging/logging.h" +#include "../../quicktick.h" diff --git a/src/hal/generic/hal_pins_generic.c b/src/hal/generic/hal_pins_generic.c new file mode 100644 index 000000000..e09dc3dd2 --- /dev/null +++ b/src/hal/generic/hal_pins_generic.c @@ -0,0 +1,70 @@ +#include "../../new_common.h" +#include "../../logging/logging.h" +#include "../../new_cfg.h" +#include "../../new_pins.h" + + +int __attribute__((weak)) PIN_GetPWMIndexForPinIndex(int pin) +{ + return -1; +} + +const char* __attribute__((weak)) HAL_PIN_GetPinNameAlias(int index) +{ + return "error"; +} + +int __attribute__((weak)) HAL_PIN_CanThisPinBePWM(int index) +{ + return 0; +} + +void __attribute__((weak)) HAL_PIN_SetOutputValue(int index, int iVal) +{ + return; +} + +int __attribute__((weak)) HAL_PIN_ReadDigitalInput(int index) +{ + return 0; +} + +void __attribute__((weak)) HAL_PIN_Setup_Input_Pullup(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_Setup_Input_Pulldown(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_Setup_Input(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_Setup_Output(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_PWM_Stop(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_PWM_Start(int index) +{ + return; +} + +void __attribute__((weak)) HAL_PIN_PWM_Update(int index, float value) +{ + return; +} + +unsigned int __attribute__((weak)) HAL_GetGPIOPin(int index) +{ + return index; +} diff --git a/src/hal/generic/hal_uart_generic.c b/src/hal/generic/hal_uart_generic.c new file mode 100644 index 000000000..b049c2325 --- /dev/null +++ b/src/hal/generic/hal_uart_generic.c @@ -0,0 +1,11 @@ +#include "../hal_uart.h" + +void __attribute__((weak)) HAL_UART_SendByte(byte b) +{ + +} + +int __attribute__((weak)) HAL_UART_Init(int baud, int parity) +{ + return 0; +} \ No newline at end of file diff --git a/src/hal/generic/hal_wifi_generic.c b/src/hal/generic/hal_wifi_generic.c new file mode 100644 index 000000000..b46e9fde3 --- /dev/null +++ b/src/hal/generic/hal_wifi_generic.c @@ -0,0 +1,68 @@ +#include "../hal_wifi.h" +#include "../../new_common.h" + +const char* __attribute__((weak)) HAL_GetMyIPString() +{ + return "error"; +} + +const char* __attribute__((weak)) HAL_GetMyGatewayString() +{ + return "error"; +} + +const char* __attribute__((weak)) HAL_GetMyDNSString() +{ + return "error"; +} + +const char* __attribute__((weak)) HAL_GetMyMaskString() +{ + return "error";; +} + +int __attribute__((weak)) WiFI_SetMacAddress(char* mac) +{ + + return 0; // error +} + +void __attribute__((weak)) WiFI_GetMacAddress(char* mac) +{ + +} + +const char* __attribute__((weak)) HAL_GetMACStr(char* macstr) +{ + return "error"; +} + +void __attribute__((weak)) HAL_PrintNetworkInfo() +{ + +} + +int __attribute__((weak)) HAL_GetWifiStrength() +{ + return 0; +} + +void __attribute__((weak)) HAL_WiFi_SetupStatusCallback(void (*cb)(int code)) +{ + +} + +void __attribute__((weak)) HAL_ConnectToWiFi(const char* oob_ssid, const char* connect_key, obkStaticIP_t* ip) +{ + +} + +void __attribute__((weak)) HAL_DisconnectFromWifi() +{ + +} + +int __attribute__((weak)) HAL_SetupWiFiOpenAccessPoint(const char* ssid) +{ + return 0; +} diff --git a/src/hal/hal_generic.h b/src/hal/hal_generic.h index 611d91ce9..17098c37c 100644 --- a/src/hal/hal_generic.h +++ b/src/hal/hal_generic.h @@ -1,2 +1,5 @@ void HAL_RebootModule(); +void HAL_Delay_us(int delay); +void HAL_Configure_WDT(); +void HAL_Run_WDT(); diff --git a/src/hal/hal_uart.h b/src/hal/hal_uart.h new file mode 100644 index 000000000..dd2ede748 --- /dev/null +++ b/src/hal/hal_uart.h @@ -0,0 +1,6 @@ +#include "../new_common.h" +#include "../driver/drv_uart.h" + +void HAL_UART_SendByte(byte b); + +int HAL_UART_Init(int baud, int parity); diff --git a/src/hal/ln882h/hal_generic_ln882h.c b/src/hal/ln882h/hal_generic_ln882h.c index 1ef8c7894..39314f631 100644 --- a/src/hal/ln882h/hal_generic_ln882h.c +++ b/src/hal/ln882h/hal_generic_ln882h.c @@ -1,9 +1,34 @@ #ifdef PLATFORM_LN882H +#include "hal/hal_wdt.h" #include "utils/reboot_trace/reboot_trace.h" -void HAL_RebootModule() { - ln_chip_reboot(); +void HAL_RebootModule() +{ + ln_chip_reboot(); } -#endif // PLATFORM_LN882H \ No newline at end of file +void HAL_Configure_WDT() +{ + /* Watchdog initialization */ + wdt_init_t_def wdt_init; + memset(&wdt_init, 0, sizeof(wdt_init)); + wdt_init.wdt_rmod = WDT_RMOD_1; // When equal to 0, the counter is reset directly when it overflows; when equal to 1, an interrupt is generated first when the counter overflows, and if it overflows again, it resets. + wdt_init.wdt_rpl = WDT_RPL_32_PCLK; // Set the reset delay time + wdt_init.top = WDT_TOP_VALUE_9; //wdt cnt value = 0x1FFFF Time = 4.095 s + hal_wdt_init(WDT_BASE, &wdt_init); + + /* Configure watchdog interrupt */ + NVIC_SetPriority(WDT_IRQn, 4); + NVIC_EnableIRQ(WDT_IRQn); + + /* Enable watchdog */ + hal_wdt_en(WDT_BASE, HAL_ENABLE); +} + +void HAL_Run_WDT() +{ + hal_wdt_cnt_restart(WDT_BASE); +} + +#endif // PLATFORM_LN882H diff --git a/src/hal/rtl87x0c/hal_flashConfig_rtl87x0c.c b/src/hal/rtl87x0c/hal_flashConfig_rtl87x0c.c new file mode 100644 index 000000000..32a63eee2 --- /dev/null +++ b/src/hal/rtl87x0c/hal_flashConfig_rtl87x0c.c @@ -0,0 +1,29 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../hal_flashConfig.h" +#include + +static int g_easyFlash_Ready = 0; +void InitEasyFlashIfNeeded() +{ + if(g_easyFlash_Ready == 0) + { + easyflash_init(); + g_easyFlash_Ready = 1; + } +} + +int HAL_Configuration_ReadConfigMemory(void* target, int dataLen) +{ + InitEasyFlashIfNeeded(); + return ef_get_env_blob("ObkCfg", target, dataLen, NULL); +} + +int HAL_Configuration_SaveConfigMemory(void* src, int dataLen) +{ + InitEasyFlashIfNeeded(); + ef_set_env_blob("ObkCfg", src, dataLen); + return 1; +} + +#endif // PLATFORM_RTL87X0C diff --git a/src/hal/rtl87x0c/hal_flashVars_rtl87x0c.c b/src/hal/rtl87x0c/hal_flashVars_rtl87x0c.c new file mode 100644 index 000000000..5840fea68 --- /dev/null +++ b/src/hal/rtl87x0c/hal_flashVars_rtl87x0c.c @@ -0,0 +1,182 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../../new_common.h" +#include "../hal_flashVars.h" +#include "../../logging/logging.h" +#include + +FLASH_VARS_STRUCTURE flash_vars; +static int g_loaded = 0; + +#define KV_KEY_FLASH_VARS "OBK_FV" +#define SAVE_CHANGE_IF_REQUIRED_AND_COUNT(target, source, counter) \ + if((target) != (source)) { \ + (target) = (source); \ + counter++; \ + } + +extern void InitEasyFlashIfNeeded(); + +static int ReadFlashVars(void* target, int dataLen) +{ + InitEasyFlashIfNeeded(); + int readLen; + ADDLOG_DEBUG(LOG_FEATURE_CFG, "ReadFlashVars: will read %d bytes", dataLen); + readLen = ef_get_env_blob(KV_KEY_FLASH_VARS, target, dataLen, NULL); + ADDLOG_DEBUG(LOG_FEATURE_CFG, "ReadFlashVars: really loaded %d bytes", readLen); + g_loaded = 1; + return dataLen; +} + +static int SaveFlashVars(void* src, int dataLen) +{ + InitEasyFlashIfNeeded(); + EfErrCode res; + + res = ef_set_env_blob(KV_KEY_FLASH_VARS, src, dataLen); + if(res == EF_ENV_INIT_FAILED) + { + ADDLOG_DEBUG(LOG_FEATURE_CFG, "SaveFlashVars: EF_ENV_INIT_FAILED for %d bytes", dataLen); + return 0; + } + if(res == EF_ENV_NAME_ERR) + { + ADDLOG_DEBUG(LOG_FEATURE_CFG, "SaveFlashVars: EF_ENV_ARG_ERR for %d bytes", dataLen); + return 0; + } + ADDLOG_DEBUG(LOG_FEATURE_CFG, "SaveFlashVars: saved %d bytes", dataLen); + return dataLen; +} + +// call at startup +void HAL_FlashVars_IncreaseBootCount() +{ + memset(&flash_vars, 0, sizeof(flash_vars)); + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + flash_vars.boot_count++; + SaveFlashVars(&flash_vars, sizeof(flash_vars)); +} + +void HAL_FlashVars_SaveChannel(int index, int value) +{ + if(index < 0 || index >= MAX_RETAIN_CHANNELS) + return; + if(g_loaded == 0) + { + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + } + flash_vars.savedValues[index] = value; + // save after increase + SaveFlashVars(&flash_vars, sizeof(flash_vars)); +} + +void HAL_FlashVars_ReadLED(byte* mode, short* brightness, short* temperature, byte* rgb, byte* bEnableAll) +{ + if(g_loaded == 0) + { + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + } + *bEnableAll = flash_vars.savedValues[MAX_RETAIN_CHANNELS - 4]; + *mode = flash_vars.savedValues[MAX_RETAIN_CHANNELS - 3]; + *temperature = flash_vars.savedValues[MAX_RETAIN_CHANNELS - 2]; + *brightness = flash_vars.savedValues[MAX_RETAIN_CHANNELS - 1]; + rgb[0] = flash_vars.rgb[0]; + rgb[1] = flash_vars.rgb[1]; + rgb[2] = flash_vars.rgb[2]; +} + +void HAL_FlashVars_SaveLED(byte mode, short brightness, short temperature, byte r, byte g, byte b, byte bEnableAll) +{ + int iChangesCount = 0; + + if(g_loaded == 0) + { + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + } + + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.savedValues[MAX_RETAIN_CHANNELS - 1], brightness, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.savedValues[MAX_RETAIN_CHANNELS - 2], temperature, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.savedValues[MAX_RETAIN_CHANNELS - 3], mode, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.savedValues[MAX_RETAIN_CHANNELS - 4], bEnableAll, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.rgb[0], r, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.rgb[1], g, iChangesCount); + SAVE_CHANGE_IF_REQUIRED_AND_COUNT(flash_vars.rgb[2], b, iChangesCount); + + if(iChangesCount > 0) + { + ADDLOG_INFO(LOG_FEATURE_CFG, "####### Flash Save LED #######"); + SaveFlashVars(&flash_vars, sizeof(flash_vars)); + } +} + +short HAL_FlashVars_ReadUsage() +{ + return 0; +} + +void HAL_FlashVars_SaveTotalUsage(short usage) +{ + +} + +// call once started (>30s?) +void HAL_FlashVars_SaveBootComplete() +{ + flash_vars.boot_success_count = flash_vars.boot_count; + SaveFlashVars(&flash_vars, sizeof(flash_vars)); +} + +// call to return the number of boots since a HAL_FlashVars_SaveBootComplete +int HAL_FlashVars_GetBootFailures() +{ + int diff = 0; + diff = flash_vars.boot_count - flash_vars.boot_success_count; + return diff; +} + +int HAL_FlashVars_GetBootCount() +{ + return flash_vars.boot_count; +} + +int HAL_FlashVars_GetChannelValue(int ch) +{ + if(ch < 0 || ch >= MAX_RETAIN_CHANNELS) + return 0; + if(g_loaded == 0) + { + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + } + return flash_vars.savedValues[ch]; +} + +int HAL_GetEnergyMeterStatus(ENERGY_METERING_DATA* data) +{ + if(data != NULL) + { + if(g_loaded == 0) + { + ReadFlashVars(&flash_vars, sizeof(flash_vars)); + } + memcpy(data, &flash_vars.emetering, sizeof(ENERGY_METERING_DATA)); + } + return 0; +} + +int HAL_SetEnergyMeterStatus(ENERGY_METERING_DATA* data) +{ + if(data != NULL) + { + memcpy(&flash_vars.emetering, data, sizeof(ENERGY_METERING_DATA)); + SaveFlashVars(&flash_vars, sizeof(flash_vars)); + } + return 0; +} + +void HAL_FlashVars_SaveTotalConsumption(float total_consumption) +{ + flash_vars.emetering.TotalConsumption = total_consumption; +} + +#endif // PLATFORM_RTL87X0C + diff --git a/src/hal/rtl87x0c/hal_generic_rtl87x0c.c b/src/hal/rtl87x0c/hal_generic_rtl87x0c.c new file mode 100644 index 000000000..f6378ffeb --- /dev/null +++ b/src/hal/rtl87x0c/hal_generic_rtl87x0c.c @@ -0,0 +1,29 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../hal_generic.h" +#include "sys_api.h" +#include "hal_timer.h" +#include "hal_wdt.h" + +void HAL_RebootModule() +{ + sys_cpu_reset(); +} + +void HAL_Delay_us(int delay) +{ + hal_delay_us(delay); +} + +void HAL_Configure_WDT() +{ + hal_misc_wdt_init(10 * 1000 * 1000); + hal_misc_wdt_enable(); +} + +void HAL_Run_WDT() +{ + hal_misc_wdt_refresh(); +} + +#endif // PLATFORM_RTL87X0C diff --git a/src/hal/rtl87x0c/hal_pins_rtl87x0c.c b/src/hal/rtl87x0c/hal_pins_rtl87x0c.c new file mode 100644 index 000000000..28569873a --- /dev/null +++ b/src/hal/rtl87x0c/hal_pins_rtl87x0c.c @@ -0,0 +1,168 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../../new_common.h" +#include "../../logging/logging.h" +#include "../../new_cfg.h" +#include "../../new_pins.h" +#include +#include "pwmout_api.h" + +extern int g_pwmFrequency; + +typedef struct trPinMapping_s +{ + const char* name; + PinName pin; + bool isInit; + gpio_t gpio; + pwmout_t pwm; +} rtlPinMapping_t; + +rtlPinMapping_t g_pins[] = { + { "PA0 (RX1)", PA_0, false }, + { "PA1 (TX1)", PA_1, false }, + { "PA2 (RX1)", PA_2, false }, + { "PA3 (TX1)", PA_3, false }, + { "PA4", PA_4, false }, + { "PA5", PA_5, false }, + { "PA6", PA_6, false }, + { "PA7", PA_7, false }, + { "PA8", PA_8, false }, + { "PA9", PA_9, false }, + { "PA10", PA_10, false }, + { "PA11", PA_11, false }, + { "PA12", PA_12, false }, + { "PA13 (RX0)", PA_13, false }, + { "PA14 (TX0)", PA_14, false }, + { "PA15 (RX2)", PA_15, false }, + { "PA16 (TX2)", PA_16, false }, + { "PA17", PA_17, false }, + { "PA18", PA_18, false }, + { "PA19", PA_19, false }, + { "PA20", PA_20, false }, + { "PA21", PA_21, false }, + { "PA22", PA_22, false }, + { "PA23", PA_23, false }, +}; + +static int g_numPins = sizeof(g_pins) / sizeof(g_pins[0]); + +int PIN_GetPWMIndexForPinIndex(int pin) +{ + return -1; +} + +const char* HAL_PIN_GetPinNameAlias(int index) +{ + if(index >= g_numPins) + return "error"; + return g_pins[index].name; +} + +int HAL_PIN_CanThisPinBePWM(int index) +{ + if(index > 6 && index < 11) return 0; + return 1; +} + +void RTL_Gpio_Init(rtlPinMapping_t* pin) +{ + if(pin->isInit) + { + return; + } + gpio_init(&pin->gpio, pin->pin); + pin->isInit = true; +} + +void HAL_PIN_SetOutputValue(int index, int iVal) +{ + if(index >= g_numPins) + return; + rtlPinMapping_t* pin = g_pins + index; + gpio_write(&pin->gpio, iVal ? 1 : 0); +} + +int HAL_PIN_ReadDigitalInput(int index) +{ + if(index >= g_numPins) + return 0; + rtlPinMapping_t* pin = g_pins + index; + return gpio_read(&pin->gpio); +} + +void HAL_PIN_Setup_Input_Pullup(int index) +{ + if(index >= g_numPins) + return; + rtlPinMapping_t* pin = g_pins + index; + RTL_Gpio_Init(pin); + gpio_dir(&pin->gpio, PIN_INPUT); + gpio_mode(&pin->gpio, PullUp); +} + +void HAL_PIN_Setup_Input_Pulldown(int index) +{ + if(index >= g_numPins) + return; + rtlPinMapping_t* pin = g_pins + index; + RTL_Gpio_Init(pin); + gpio_dir(&pin->gpio, PIN_INPUT); + gpio_mode(&pin->gpio, PullDown); +} + +void HAL_PIN_Setup_Input(int index) +{ + if(index >= g_numPins) + return; + rtlPinMapping_t* pin = g_pins + index; + RTL_Gpio_Init(pin); + gpio_dir(&pin->gpio, PIN_INPUT); + gpio_mode(&pin->gpio, PullNone); +} + +void HAL_PIN_Setup_Output(int index) +{ + if(index >= g_numPins) + return; + rtlPinMapping_t* pin = g_pins + index; + RTL_Gpio_Init(pin); + gpio_dir(&pin->gpio, PIN_OUTPUT); + gpio_mode(&pin->gpio, PullUp); +} + +void HAL_PIN_PWM_Stop(int index) +{ + if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) + return; + rtlPinMapping_t* pin = g_pins + index; + //pwmout_stop(&pin->pwm); + pwmout_free(&pin->pwm); + pin->isInit = false; +} + +void HAL_PIN_PWM_Start(int index) +{ + if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) + return; + rtlPinMapping_t* pin = g_pins + index; + pwmout_init(&pin->pwm, pin->pin); + pwmout_period_us(&pin->pwm, g_pwmFrequency); + pwmout_start(&pin->pwm); + pin->isInit = true; +} + +void HAL_PIN_PWM_Update(int index, float value) +{ + if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) + return; + rtlPinMapping_t* pin = g_pins + index; + pwmout_write(&pin->pwm, value / 100); +} + +unsigned int HAL_GetGPIOPin(int index) +{ + return index; +} + +#endif // PLATFORM_RTL87X0C diff --git a/src/hal/rtl87x0c/hal_uart_rtl87x0c.c b/src/hal/rtl87x0c/hal_uart_rtl87x0c.c new file mode 100644 index 000000000..a6f5b8044 --- /dev/null +++ b/src/hal/rtl87x0c/hal_uart_rtl87x0c.c @@ -0,0 +1,58 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../../new_pins.h" +#include "../../new_cfg.h" +#include "../hal_uart.h" +#include "serial_api.h" +#include "hal_uart.h" +#define UART0_TX PA_14 +#define UART0_RX PA_13 +#define UART1_0_TX PA_3 +#define UART1_0_RX PA_2 +#define UART1_1_TX PA_1 +#define UART1_1_RX PA_0 + +serial_t sobj; +static bool isInitialized; + +static void uart_cb(uint32_t id, SerialIrq event) +{ + if(event != RxIrq) + return; + + serial_t* obj = (void*)id; + uint8_t c; + while(hal_uart_rgetc(&obj->uart_adp, (char*)&c)) + { + UART_AppendByteToReceiveRingBuffer(c); + } +} + +void HAL_UART_SendByte(byte b) +{ + while(!hal_uart_writeable(&sobj.uart_adp)); + hal_uart_putc(&sobj.uart_adp, b); +} + +int HAL_UART_Init(int baud, int parity) +{ + if(isInitialized) + { + serial_free(&sobj); + } + PinName tx = UART0_TX, rx = UART0_RX; + if(CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) + { + tx = UART1_0_TX; + rx = UART1_0_RX; + } + serial_init(&sobj, tx, rx); + serial_baud(&sobj, baud); + serial_format(&sobj, 8, parity, 1); + serial_irq_handler(&sobj, uart_cb, (uint32_t)&sobj); + serial_irq_set(&sobj, RxIrq, 1); + isInitialized = true; + return 1; +} + +#endif \ No newline at end of file diff --git a/src/hal/rtl87x0c/hal_wifi_rtl87x0c.c b/src/hal/rtl87x0c/hal_wifi_rtl87x0c.c new file mode 100644 index 000000000..19bff3386 --- /dev/null +++ b/src/hal/rtl87x0c/hal_wifi_rtl87x0c.c @@ -0,0 +1,295 @@ +#ifdef PLATFORM_RTL87X0C + +#include "../hal_wifi.h" +#include "../../new_cfg.h" +#include "../../new_cfg.h" +#include "../../logging/logging.h" +#include +#include +#include +#include +#include +#include "tcpip.h" +#include + +extern struct netif xnetif[NET_IF_NUM]; + +typedef struct +{ + char ssid[32]; + char pwd[64]; +} wifi_data_t; + +bool g_STA_static_IP = 0; + +static void (*g_wifiStatusCallback)(int code) = NULL; +static int g_bOpenAccessPointMode = 0; +static wifi_data_t wdata = { 0 }; +extern uint8_t wmac[6]; + +const char* HAL_GetMyIPString() +{ + return ipaddr_ntoa((const ip4_addr_t*)&xnetif[g_bOpenAccessPointMode].ip_addr.addr); +} + +const char* HAL_GetMyGatewayString() +{ + return ipaddr_ntoa((const ip4_addr_t*)&xnetif[g_bOpenAccessPointMode].gw.addr); +} + +const char* HAL_GetMyDNSString() +{ + return NULL; +} + +const char* HAL_GetMyMaskString() +{ + return ipaddr_ntoa((const ip4_addr_t*)&xnetif[g_bOpenAccessPointMode].netmask.addr); +} + +int WiFI_SetMacAddress(char* mac) +{ + printf("WiFI_SetMacAddress"); + return 0; // error +} + +void WiFI_GetMacAddress(char* mac) +{ + memcpy(mac, (char*)wmac, sizeof(wmac)); +} + +const char* HAL_GetMACStr(char* macstr) +{ + unsigned char mac[6]; + WiFI_GetMacAddress((char*)mac); + sprintf(macstr, MACSTR, MAC2STR(mac)); + return macstr; +} + +void HAL_PrintNetworkInfo() +{ + uint8_t mac[6]; + WiFI_GetMacAddress((char*)mac); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "+--------------- net device info ------------+\r\n"); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "|netif type : %-16s |\r\n", g_bOpenAccessPointMode == 0 ? "STA" : "AP"); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "|netif ip = %-16s |\r\n", HAL_GetMyIPString()); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "|netif mask = %-16s |\r\n", HAL_GetMyMaskString()); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "|netif gateway = %-16s |\r\n", HAL_GetMyGatewayString()); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "|netif mac : [%02X:%02X:%02X:%02X:%02X:%02X] %-7s |\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ""); + ADDLOG_DEBUG(LOG_FEATURE_GENERAL, "+--------------------------------------------+\r\n"); +} + +int HAL_GetWifiStrength() +{ + int rssi; + wext_get_rssi(WLAN0_NAME, &rssi); + return rssi; +} + +void HAL_WiFi_SetupStatusCallback(void (*cb)(int code)) +{ + printf("HAL_WiFi_SetupStatusCallback"); + g_wifiStatusCallback = cb; +} + +static int _find_ap_from_scan_buf(char* buf, int buflen, char* target_ssid, void* user_data) +{ + rtw_wifi_setting_t* pwifi = (rtw_wifi_setting_t*)user_data; + int plen = 0; + + while(plen < buflen) + { + u8 len, ssid_len, security_mode; + char* ssid; + + // len offset = 0 + len = (int)*(buf + plen); + // check end + if(len == 0) + { + break; + } + // ssid offset = 14 + ssid_len = len - 14; + ssid = buf + plen + 14; + if((ssid_len == strlen(target_ssid)) + && (!memcmp(ssid, target_ssid, ssid_len))) + { + strncpy((char*)pwifi->ssid, target_ssid, 33); + // channel offset = 13 + pwifi->channel = *(buf + plen + 13); + // security_mode offset = 11 + security_mode = (u8) * (buf + plen + 11); + if(security_mode == IW_ENCODE_ALG_NONE) + { + pwifi->security_type = RTW_SECURITY_OPEN; + } + else if(security_mode == IW_ENCODE_ALG_WEP) + { + pwifi->security_type = RTW_SECURITY_WEP_PSK; + } + else if(security_mode == IW_ENCODE_ALG_CCMP) + { + pwifi->security_type = RTW_SECURITY_WPA2_AES_PSK; + } + else if(security_mode == IW_ENCODE_ALG_OWE) + { + pwifi->security_type = RTW_SECURITY_WPA3_OWE; + } + break; + } + plen += len; + } + return 0; +} + +static int _get_ap_security_mode(char* ssid, rtw_security_t* security_mode, u8* channel) +{ + rtw_wifi_setting_t wifi; + u32 scan_buflen = 1000; + + memset(&wifi, 0, sizeof(wifi)); + + if(wifi_scan_networks_with_ssid(_find_ap_from_scan_buf, (void*)&wifi, scan_buflen, ssid, strlen(ssid)) != RTW_SUCCESS) + { + printf("Wifi scan failed!\n"); + return 0; + } + + if(strcmp((char*)wifi.ssid, ssid) == 0) + { + *security_mode = wifi.security_type; + *channel = wifi.channel; + return 1; + } + + return 0; +} + +void wifi_dis_hdl(u8* buf, u32 buf_len, u32 flags, void* userdata) +{ + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_DISCONNECTED); + } +} + +void wifi_con_hdl(u8* buf, u32 buf_len, u32 flags, void* userdata) +{ + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_CONNECTING); + } +} + +void wifi_conned_hdl(u8* buf, u32 buf_len, u32 flags, void* userdata) +{ + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_CONNECTED); + } +} + +void wifi_af_hdl(u8* buf, u32 buf_len, u32 flags, void* userdata) +{ + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_AUTH_FAILED); + } +} + +void ConnectToWiFiTask(void* args) +{ + rtw_security_t security_type = RTW_SECURITY_OPEN; + int security_retry_count = 0; + uint8_t connect_channel = 0; + while(1) + { + if(_get_ap_security_mode(wdata.ssid, &security_type, &connect_channel)) + { + break; + } + security_retry_count++; + if(security_retry_count >= 3) + { + printf("Can't get AP security mode and channel.\r\n"); + goto exit; + } + } + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_CONNECTING); + } + int ret = wifi_connect(wdata.ssid, security_type, wdata.pwd, strlen(wdata.ssid), + strlen(wdata.pwd), NULL, NULL); + if(ret != RTW_SUCCESS) + { + printf("ERROR: Can't connect to AP\r\n"); + goto exit; + } + LwIP_DHCP(0, DHCP_START); +exit: + vTaskDelete(NULL); +} + +void HAL_ConnectToWiFi(const char* oob_ssid, const char* connect_key, obkStaticIP_t* ip) +{ + g_bOpenAccessPointMode = 0; + strcpy((char*)&wdata.ssid, oob_ssid); + strcpy((char*)&wdata.pwd, connect_key); + wifi_set_autoreconnect(0); + + netif_set_hostname(&xnetif[0], CFG_GetDeviceName()); + wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, (rtw_event_handler_t)wifi_dis_hdl, NULL); + //wifi_reg_event_handler(WIFI_EVENT_CONNECT, (rtw_event_handler_t)wifi_con_hdl, NULL); + wifi_reg_event_handler(WIFI_EVENT_STA_GOT_IP, (rtw_event_handler_t)wifi_conned_hdl, NULL); + wifi_reg_event_handler(WIFI_EVENT_CHALLENGE_FAIL, (rtw_event_handler_t)wifi_af_hdl, NULL); + + xTaskCreate( + (TaskFunction_t)ConnectToWiFiTask, + "WC", + 2048 / sizeof(StackType_t), + NULL, + 5, + NULL); +} + +void HAL_DisconnectFromWifi() +{ + printf("HAL_DisconnectFromWifi"); + wifi_disconnect(); + if(g_wifiStatusCallback != NULL) + { + g_wifiStatusCallback(WIFI_STA_DISCONNECTED); + } +} + +int HAL_SetupWiFiOpenAccessPoint(const char* ssid) +{ + g_bOpenAccessPointMode = 1; + struct ip_addr ipaddr; + struct ip_addr netmask; + struct ip_addr gw; + struct netif* pnetif = &xnetif[0]; + dhcps_deinit(); + wifi_off(); + vTaskDelay(20); + if(wifi_on(RTW_MODE_AP) < 0) + { + printf("wifi_on failed!\r\n"); + return 0; + } + + if(wifi_start_ap((char*)ssid, RTW_SECURITY_OPEN, NULL, strlen(ssid), 0, 1) < 0) + { + printf("wifi_start_ap failed!\r\n"); + } + IP4_ADDR(ip_2_ip4(&ipaddr), 192, 168, 4, 1); + IP4_ADDR(ip_2_ip4(&netmask), 255, 255, 255, 0); + IP4_ADDR(ip_2_ip4(&gw), 192, 168, 4, 1); + netif_set_addr(pnetif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw)); + dhcps_init(pnetif); + return 0; +} + +#endif // PLATFORM_RTL87X0C diff --git a/src/hal/tr6260/hal_generic_tr6260.c b/src/hal/tr6260/hal_generic_tr6260.c index a3c547c1e..b3791ac5f 100644 --- a/src/hal/tr6260/hal_generic_tr6260.c +++ b/src/hal/tr6260/hal_generic_tr6260.c @@ -1,8 +1,15 @@ #ifdef PLATFORM_TR6260 +#include "../hal_generic.h" + void HAL_RebootModule() { wdt_reset_chip(0); } -#endif // PLATFORM_TR6260 \ No newline at end of file +void HAL_Delay_us(int delay) +{ + usdelay(delay); +} + +#endif // PLATFORM_TR6260 diff --git a/src/hal/w800/hal_generic_w800.c b/src/hal/w800/hal_generic_w800.c index dba3f5b6f..95a2f3ed7 100644 --- a/src/hal/w800/hal_generic_w800.c +++ b/src/hal/w800/hal_generic_w800.c @@ -1,9 +1,53 @@ #if defined(PLATFORM_W800) || defined(PLATFORM_W600) +#include "../hal_generic.h" #include "wm_include.h" -void HAL_RebootModule() { - tls_sys_reset(); +void HAL_RebootModule() +{ + tls_sys_reset(); +} + +void HAL_Delay_us(int delay) +{ + for(volatile int i = 0; i < delay; i++) + { + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); // 5 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); +#if PLATFORM_W800 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //10 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //15 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); //20 + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); + __asm__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop"); +#endif + } +} + +void HAL_Configure_WDT() +{ + tls_watchdog_init(5 * 1000 * 1000); +} + +void HAL_Run_WDT() +{ + tls_watchdog_clr(); } #endif diff --git a/src/hal/win32/hal_generic_win32.c b/src/hal/win32/hal_generic_win32.c index 63a48dddc..e05fc173e 100644 --- a/src/hal/win32/hal_generic_win32.c +++ b/src/hal/win32/hal_generic_win32.c @@ -1,8 +1,24 @@ #ifdef WINDOWS +#include "../hal_generic.h" -void HAL_RebootModule() { +void HAL_RebootModule() +{ +} + +void HAL_Delay_us(int delay) +{ + +} + +void HAL_Configure_WDT() +{ + +} + +void HAL_Run_WDT() +{ } diff --git a/src/hal/win32/hal_uart_win32.c b/src/hal/win32/hal_uart_win32.c new file mode 100644 index 000000000..e9cd0a806 --- /dev/null +++ b/src/hal/win32/hal_uart_win32.c @@ -0,0 +1,21 @@ +#ifdef WINDOWS + +#include "../hal_uart.h" + +void HAL_UART_SendByte(byte b) +{ + void SIM_AppendUARTByte(byte b); + // STUB - for testing + SIM_AppendUARTByte(b); +#if 1 + printf("%02X", b); +#endif + //addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"%02X", b); +} + +int HAL_UART_Init(int baud, int parity) +{ + return 1; +} + +#endif \ No newline at end of file diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index a8889acac..31c8e44f5 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -40,6 +40,10 @@ static char SUBMIT_AND_END_FORM[] = "
Chip temperature: %.1f°C", g_wifi_temperature); +#endif inputName = CFG_GetPingHost(); if (inputName && *inputName && CFG_GetPingDisconnectedSecondsToRestart()) { @@ -875,6 +881,17 @@ typedef enum { default: break; } hprintf255(request, "
Reboot reason: %i - %s
", reason, s); +#elif PLATFORM_RTL87X0C + const char* s = "Unk"; + switch(reset_reason) + { + case HAL_RESET_REASON_POWER_ON: s = "Pwr"; break; + case HAL_RESET_REASON_SOFTWARE: s = "Soft"; break; + case HAL_RESET_REASON_WATCHDOG: s = "Wdt"; break; + default: break; + } + hprintf255(request, "
Reboot reason: %i - %s
", reset_reason, s); + hprintf255(request, "
Current fw: FW%i
", current_fw_idx); #endif if (CFG_GetMQTTHost()[0] == 0) { hprintf255(request, "
MQTT State: not configured
"); @@ -1308,6 +1325,8 @@ int http_fn_cfg_wifi(http_request_t* request) { } #elif PLATFORM_TR6260 poststr(request, "TODO TR6260
"); +#elif defined(PLATFORM_RTL87X0C) + poststr(request, "TODO RTL87X0C
"); #else #error "Unknown platform" poststr(request, "Unknown platform
"); @@ -2983,6 +3002,7 @@ void OTA_RequestDownloadFromHTTP(const char* s) { #elif PLATFORM_ESPIDF #elif PLATFORM_TR6260 +#elif PLATFORM_RTL87X0C #elif PLATFORM_W600 || PLATFORM_W800 t_http_fwup(s); #elif PLATFORM_XR809 diff --git a/src/httpserver/new_tcp_server.c b/src/httpserver/new_tcp_server.c index beda03985..705dc1aee 100644 --- a/src/httpserver/new_tcp_server.c +++ b/src/httpserver/new_tcp_server.c @@ -213,18 +213,21 @@ static void tcp_server_thread(beken_thread_arg_t arg) socklen_t addr_len = sizeof(source_addr); int new_idx = 0; - for(new_idx = 0; new_idx < max_socks; ++new_idx) + for(int i = 0; i < max_socks; ++i) { - if(sock[new_idx].isCompleted) + if(sock[i].isCompleted) { - if(sock[new_idx].thread != NULL) + if(sock[i].thread != NULL) { - rtos_delete_thread(&sock[new_idx].thread); - sock[new_idx].thread = NULL; + rtos_delete_thread(&sock[i].thread); + sock[i].thread = NULL; } - sock[new_idx].isCompleted = false; - sock[new_idx].fd = INVALID_SOCK; + sock[i].isCompleted = false; + sock[i].fd = INVALID_SOCK; } + } + for(new_idx = 0; new_idx < max_socks; ++new_idx) + { if(sock[new_idx].fd == INVALID_SOCK) { break; diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index 54f593965..8340204b6 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -50,6 +50,19 @@ uint32_t flash_read(uint32_t flash, uint32_t addr, void* buf, uint32_t size); #elif PLATFORM_ESPIDF +#elif PLATFORM_RTL87X0C + +#include "flash_api.h" +#include "device_lock.h" +#include "ota_8710c.h" +#include "sys_api.h" + +extern flash_t flash; +extern uint32_t sys_update_ota_get_curr_fw_idx(void); +extern uint32_t sys_update_ota_prepare_addr(void); +extern void sys_disable_fast_boot(void); +static flash_t flash_ota; + #else extern UINT32 flash_read(char* user_buf, UINT32 count, UINT32 address); @@ -248,6 +261,8 @@ static int http_rest_post(http_request_t* request) { return http_rest_post_flash(request, -1, -1); #elif PLATFORM_ESPIDF return http_rest_post_flash(request, -1, -1); +#elif PLATFORM_RTL87X0C + return http_rest_post_flash(request, 0, -1); #else // TODO ADDLOG_DEBUG(LOG_FEATURE_API, "No OTA"); @@ -1917,6 +1932,141 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa return -1; } +#elif PLATFORM_RTL87X0C + + uint32_t NewFWLen = 0, NewFWAddr = 0; + uint32_t address = 0; + uint32_t curr_fw_idx = 0; + uint32_t flash_checksum = 0; + uint32_t targetFWaddr; + uint32_t currentFWaddr; + uint32_t fw1_sn; + uint32_t fw2_sn; + _file_checksum file_checksum; + file_checksum.u = 0; + unsigned char sig_backup[32]; + int ret = 1; + + if(request->contentLength >= 0) + { + towrite = request->contentLength; + } + NewFWAddr = sys_update_ota_prepare_addr(); + if(NewFWAddr == -1) + { + ret = -1; + goto update_ota_exit; + } + get_fw_info(&targetFWaddr, ¤tFWaddr, &fw1_sn, &fw2_sn); + ADDLOG_INFO(LOG_FEATURE_OTA, "Current FW addr: 0x%08X, target FW addr: 0x%08X, fw1 sn: %u, fw2 sn: %u", currentFWaddr, targetFWaddr, fw1_sn, fw2_sn); + curr_fw_idx = sys_update_ota_get_curr_fw_idx(); + ADDLOG_INFO(LOG_FEATURE_OTA, "Current firmware index is %d", curr_fw_idx); + int reserase = update_ota_erase_upg_region(towrite, 0, NewFWAddr); + NewFWLen = towrite; + if(reserase == -1) + { + ret = -1; + goto update_ota_exit; + } + if(NewFWAddr != ~0x0) + { + address = NewFWAddr; + ADDLOG_INFO(LOG_FEATURE_OTA, "Start to read data %i bytes", NewFWLen); + } + do + { + // back up signature and only write it to flash till the end of OTA + if(startaddr < 32) + { + memcpy(sig_backup + startaddr, writebuf, (startaddr + writelen > 32 ? (32 - startaddr) : writelen)); + memset(writebuf, 0xFF, (startaddr + writelen > 32 ? (32 - startaddr) : writelen)); + ADDLOG_DEBUG(LOG_FEATURE_OTA, "sig_backup for% d bytes from index% d", (startaddr + writelen > 32 ? (32 - startaddr) : writelen), startaddr); + } + + device_mutex_lock(RT_DEV_LOCK_FLASH); + if(flash_burst_write(&flash_ota, address + startaddr, writelen, (uint8_t*)writebuf) < 0) + { + ADDLOG_DEBUG(LOG_FEATURE_OTA, "Write stream failed"); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + ret = -1; + goto update_ota_exit; + } + device_mutex_unlock(RT_DEV_LOCK_FLASH); + + rtos_delay_milliseconds(10); + ADDLOG_DEBUG(LOG_FEATURE_OTA, "Writelen %i at %i", writelen, total); + total += writelen; + startaddr += writelen; + towrite -= writelen; + + // checksum attached at file end + if(startaddr + writelen > NewFWLen - 4) + { + file_checksum.c[0] = writebuf[writelen - 4]; + file_checksum.c[1] = writebuf[writelen - 3]; + file_checksum.c[2] = writebuf[writelen - 2]; + file_checksum.c[3] = writebuf[writelen - 1]; + } + if(towrite > 0) + { + writebuf = request->received; + writelen = recv(request->fd, writebuf, request->receivedLenmax, 0); + if(writelen < 0) + { + ADDLOG_DEBUG(LOG_FEATURE_OTA, "recv returned %d - end of data - remaining %d", writelen, towrite); + } + } + } while((towrite > 0) && (writelen >= 0)); + ADDLOG_DEBUG(LOG_FEATURE_OTA, "%d total bytes written, verifying checksum", total); + uint8_t* buf = (uint8_t*)os_malloc(2048); + memset(buf, 0, 2048); + // read flash data back and calculate checksum + for(int i = 0; i < NewFWLen; i += 2048) + { + int k; + int rlen = (startaddr - 4 - i) > 2048 ? 2048 : (startaddr - 4 - i); + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_stream_read(&flash_ota, NewFWAddr + i, rlen, buf); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + for(k = 0; k < rlen; k++) + { + if(i + k < 32) + { + flash_checksum += sig_backup[i + k]; + } + else + { + flash_checksum += buf[k]; + } + } + } + + ADDLOG_INFO(LOG_FEATURE_OTA, "flash checksum 0x%8x attached checksum 0x%8x", flash_checksum, file_checksum.u); + + if(file_checksum.u != flash_checksum) + { + ADDLOG_INFO(LOG_FEATURE_OTA, "The checksum is wrong!"); + ret = -1; + goto update_ota_exit; + } + ret = update_ota_signature(sig_backup, NewFWAddr); + if(ret == -1) + { + ADDLOG_INFO(LOG_FEATURE_OTA, "Update signature fail"); + goto update_ota_exit; + } +update_ota_exit: + if(ret != -1) + { + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_write_word(&flash, targetFWaddr, 4294967295); + flash_write_word(&flash, currentFWaddr, 0); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + + sys_disable_fast_boot(); + if(buf) free(buf); + } + else return -1; #else init_ota(startaddr); @@ -1955,6 +2105,7 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa http_setup(request, httpMimeTypeJson); hprintf255(request, "{\"size\":%d}", total); poststr(request, NULL); + CFG_IncrementOTACount(); return 0; } @@ -2018,6 +2169,10 @@ static int http_rest_get_flash(http_request_t* request, int startaddr, int len) #elif PLATFORM_LN882H || PLATFORM_ESPIDF || PLATFORM_TR6260 // TODO:LN882H flash read? res = 0; +#elif PLATFORM_RTL87X0C + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_stream_read(&flash, startaddr, readlen, (uint8_t*)buffer); + device_mutex_unlock(RT_DEV_LOCK_FLASH); #else res = flash_read((char*)buffer, readlen, startaddr); #endif diff --git a/src/littlefs/our_lfs.c b/src/littlefs/our_lfs.c index 2cc44c24a..259c2af51 100644 --- a/src/littlefs/our_lfs.c +++ b/src/littlefs/our_lfs.c @@ -35,6 +35,11 @@ #include "esp_partition.h" esp_partition_t* esplfs = NULL; +#elif PLATFORM_RTL87X0C + +#include "flash_api.h" +#include "device_lock.h" + #endif @@ -724,6 +729,54 @@ static int lfs_erase(const struct lfs_config* c, lfs_block_t block) return res; } +#elif PLATFORM_RTL87X0C + +extern flash_t flash; + +static int lfs_read(const struct lfs_config* c, lfs_block_t block, + lfs_off_t off, void* buffer, lfs_size_t size) +{ + unsigned int startAddr = LFS_Start; + startAddr += block * LFS_BLOCK_SIZE; + startAddr += off; + + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_stream_read(&flash, startAddr, size, (uint8_t*)buffer); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + return LFS_ERR_OK; +} + +// Program a region in a block. The block must have previously +// been erased. Negative error codes are propogated to the user. +// May return LFS_ERR_CORRUPT if the block should be considered bad. +static int lfs_write(const struct lfs_config* c, lfs_block_t block, + lfs_off_t off, const void* buffer, lfs_size_t size) +{ + unsigned int startAddr = LFS_Start; + startAddr += block * LFS_BLOCK_SIZE; + startAddr += off; + + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_stream_write(&flash, startAddr, size, (uint8_t*)buffer); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + return LFS_ERR_OK; +} + +// Erase a block. A block must be erased before being programmed. +// The state of an erased block is undefined. Negative error codes +// are propogated to the user. +// May return LFS_ERR_CORRUPT if the block should be considered bad. +static int lfs_erase(const struct lfs_config* c, lfs_block_t block) +{ + unsigned int startAddr = LFS_Start; + startAddr += block * LFS_BLOCK_SIZE; + + device_mutex_lock(RT_DEV_LOCK_FLASH); + flash_erase_sector(&flash, startAddr); + device_mutex_unlock(RT_DEV_LOCK_FLASH); + return LFS_ERR_OK; +} + #endif // Sync the state of the underlying block device. Negative error codes diff --git a/src/littlefs/our_lfs.h b/src/littlefs/our_lfs.h index 031a3ec73..e8d391d08 100644 --- a/src/littlefs/our_lfs.h +++ b/src/littlefs/our_lfs.h @@ -74,6 +74,12 @@ #define LFS_BLOCKS_START_MIN PARTION_LMA_LFS #define LFS_BLOCKS_END PARTION_LMA_LFS + 0x20000 +#elif PLATFORM_RTL87X0C + +#define LFS_BLOCKS_START 0x1E8000 +#define LFS_BLOCKS_START_MIN 0x1E8000 +#define LFS_BLOCKS_END LFS_BLOCKS_START + 0x18000 + #else // TODO // start 0x1000 after OTA addr diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 663bc7c22..6121966fa 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -1634,7 +1634,7 @@ static BENCHMARK_TEST_INFO* info = NULL; #if WINDOWS -#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_ESPIDF || PLATFORM_TR6260 +#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_ESPIDF || PLATFORM_TR6260 || PLATFORM_RTL87X0C static void mqtt_timer_thread(void* param) { while (1) @@ -1674,7 +1674,7 @@ commandResult_t MQTT_StartMQTTTestThread(const void* context, const char* cmd, c #if WINDOWS -#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_ESPIDF || PLATFORM_TR6260 +#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_ESPIDF || PLATFORM_TR6260 || PLATFORM_RTL87X0C xTaskCreate(mqtt_timer_thread, "mqtt", 1024, (void*)info, 15, NULL); #elif PLATFORM_XR809 || PLATFORM_LN882H OS_TimerSetInvalid(&timer); @@ -1914,11 +1914,12 @@ OBK_Publish_Result MQTT_DoItemPublish(int idx) sprintf(dataStr, "%d", LWIP_GetActiveSockets()); return MQTT_DoItemPublishString("sockets", dataStr); - +#ifndef NO_CHIP_TEMPERATURE case PUBLISHITEM_SELF_TEMP: sprintf(dataStr, "%.2f", getInternalTemperature()); return MQTT_DoItemPublishString("temp", dataStr); - +#endif + case PUBLISHITEM_SELF_RSSI: sprintf(dataStr, "%d", HAL_GetWifiStrength()); return MQTT_DoItemPublishString("rssi", dataStr); diff --git a/src/new_cfg.c b/src/new_cfg.c index 71e4e7b8b..4f9e2a70f 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -151,6 +151,8 @@ void CFG_SetDefaultConfig() { strcpy_safe(g_cfg.mqtt_group, "esp", sizeof(g_cfg.mqtt_group)); #elif PLATFORM_TR6260 strcpy_safe(g_cfg.mqtt_group, "tr6260", sizeof(g_cfg.mqtt_group)); +#elif PLATFORM_RTL87X0C + strcpy_safe(g_cfg.mqtt_group, "rtl87x0c", sizeof(g_cfg.mqtt_group)); #elif WINDOWS strcpy_safe(g_cfg.mqtt_group, "bekens", sizeof(g_cfg.mqtt_group)); #else diff --git a/src/new_common.h b/src/new_common.h index 2b3475f54..1a7275ebd 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -105,6 +105,11 @@ typedef long BaseType_t; #define DEVICENAME_PREFIX_SHORT "tr6260" #define PLATFORM_MCU_NAME "TR6260" #define MANUFACTURER "Transa Semi" +#elif PLATFORM_RTL87X0C +#define DEVICENAME_PREFIX_FULL "OpenRTL87X0C" +#define DEVICENAME_PREFIX_SHORT "rtl87x0C" +#define PLATFORM_MCU_NAME "RTL87X0C" +#define MANUFACTURER "Realtek" #else #error "You must define a platform.." This platform is not supported, error! @@ -134,6 +139,8 @@ This platform is not supported, error! #define USER_SW_VER PLATFORM_MCU_NAME "_Test" #elif defined(PLATFORM_TR6260) #define USER_SW_VER "TR6260_Test" +#elif defined(PLATFORM_RTL87X0C) +#define USER_SW_VER "RTL87X0C_Test" #else #define USER_SW_VER "unknown" #endif @@ -266,6 +273,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg ); +OSStatus rtos_suspend_thread(beken_thread_t* thread); typedef unsigned int u32; @@ -309,6 +317,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg ); +OSStatus rtos_suspend_thread(beken_thread_t* thread); #include "common/framework/platform_init.h" @@ -356,6 +365,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg ); +OSStatus rtos_suspend_thread(beken_thread_t* thread); #elif PLATFORM_LN882H @@ -387,6 +397,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg ); +OSStatus rtos_suspend_thread(beken_thread_t* thread); #elif PLATFORM_ESPIDF @@ -422,6 +433,7 @@ OSStatus rtos_create_thread(beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg); +OSStatus rtos_suspend_thread(beken_thread_t* thread); #define portTICK_RATE_MS portTICK_PERIOD_MS #define portTickType TickType_t @@ -482,11 +494,65 @@ OSStatus rtos_create_thread(beken_thread_t* thread, uint8_t priority, const char* name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg); +OSStatus rtos_suspend_thread(beken_thread_t* thread); #define GLOBAL_INT_DECLARATION() ; #define GLOBAL_INT_DISABLE() ; #define GLOBAL_INT_RESTORE() ; +#elif PLATFORM_RTL87X0C + +#include +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "queue.h" +#include "event_groups.h" + +#include "lwip/err.h" +#include "lwip/sockets.h" +#include "lwip/sys.h" +#include "lwip/netdb.h" +#include "lwip/dns.h" +#include "cmsis_os.h" + +typedef unsigned int UINT32; + +#undef ASSERT +#define ASSERT + +#define os_malloc malloc +#define os_free free +#define os_memset memset +#define os_strcpy strcpy + +#define bk_printf printf + +// OS_MSleep? +#define rtos_delay_milliseconds(x) vTaskDelay(x / portTICK_PERIOD_MS) +#define delay_ms(x) vTaskDelay(x / portTICK_PERIOD_MS) + +#define kNoErr 0 //! No error occurred. +typedef void* beken_thread_arg_t; +typedef void* beken_thread_t; +typedef void (*beken_thread_function_t)(beken_thread_arg_t arg); +typedef int OSStatus; + +#define BEKEN_DEFAULT_WORKER_PRIORITY (6) +#define BEKEN_APPLICATION_PRIORITY (7) + +OSStatus rtos_delete_thread(beken_thread_t* thread); +OSStatus rtos_create_thread(beken_thread_t* thread, + uint8_t priority, const char* name, + beken_thread_function_t function, + uint32_t stack_size, beken_thread_arg_t arg); +OSStatus rtos_suspend_thread(beken_thread_t* thread); + +#define GLOBAL_INT_DECLARATION() ; +#define GLOBAL_INT_DISABLE() ; +#define GLOBAL_INT_RESTORE() ; + + #else #include "gw_intf.h" diff --git a/src/new_pins.h b/src/new_pins.h index b8e4bf5ab..f6521959f 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1018,6 +1018,8 @@ typedef enum channelType_e { #endif #elif PLATFORM_TR6260 #define PLATFORM_GPIO_MAX 25 +#elif PLATFORM_RTL87X0C +#define PLATFORM_GPIO_MAX 24 #else #define PLATFORM_GPIO_MAX 29 #endif diff --git a/src/obk_config.h b/src/obk_config.h index b26445123..0af569b9e 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -17,7 +17,8 @@ #if PLATFORM_XR809 -#define OBK_DISABLE_ALL_DRIVERS 1 +#define NO_CHIP_TEMPERATURE 1 +#define OBK_DISABLE_ALL_DRIVERS 1 #elif PLATFORM_W600 @@ -198,6 +199,7 @@ #elif PLATFORM_TR6260 +#define NO_CHIP_TEMPERATURE 1 #define ENABLE_LITTLEFS 1 #define NEW_TCP_SERVER 1 #define ENABLE_EXPAND_CONSTANT 1 @@ -208,6 +210,27 @@ #define ENABLE_DRIVER_LED 1 #define ENABLE_DRIVER_WEMO 1 +#elif PLATFORM_RTL87X0C + +#define NO_CHIP_TEMPERATURE 1 +#define ENABLE_LITTLEFS 1 +#define NEW_TCP_SERVER 1 +#define ENABLE_DRIVER_TUYAMCU 1 +#define ENABLE_TASMOTADEVICEGROUPS 1 +#define ENABLE_NTP 1 +#define ENABLE_CALENDAR_EVENTS 1 +#define ENABLE_EXPAND_CONSTANT 1 +#define ENABLE_TASMOTA_JSON 1 +#define ENABLE_I2C 1 +#define ENABLE_DRIVER_AHT2X 1 +#define ENABLE_DRIVER_BMPI2C 1 +#define ENABLE_DRIVER_DS1820 1 +#define ENABLE_DRIVER_LED 1 +#define ENABLE_DRIVER_WEMO 1 +#define ENABLE_DRIVER_CHT83XX 1 +#define ENABLE_DRIVER_DHT 1 +#define ENABLE_DRIVER_BL0942 1 + #else #error "Platform not defined" diff --git a/src/user_main.c b/src/user_main.c index ee7a873a1..6fc7eed2f 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -212,7 +212,7 @@ int LWIP_GetActiveSockets() { } #endif -#if defined(PLATFORM_BL602) || defined(PLATFORM_W800) || defined(PLATFORM_W600) || defined(PLATFORM_LN882H) || defined(PLATFORM_ESPIDF) || defined(PLATFORM_TR6260) +#if defined(PLATFORM_BL602) || defined(PLATFORM_W800) || defined(PLATFORM_W600) || defined(PLATFORM_LN882H) || defined(PLATFORM_ESPIDF) || defined(PLATFORM_TR6260) || defined(PLATFORM_RTL87X0C) OSStatus rtos_create_thread(beken_thread_t* thread, uint8_t priority, const char* name, @@ -616,7 +616,8 @@ void Main_OnEverySecond() LED_RunOnEverySecond(); #ifndef OBK_DISABLE_ALL_DRIVERS DRV_OnEverySecond(); -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) +#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) \ + || defined (PLATFORM_RTL87X0C) UART_RunEverySecond(); #endif #endif @@ -877,15 +878,7 @@ void Main_OnEverySecond() } } #endif -#ifdef PLATFORM_BEKEN - bk_wdg_reload(); -#elif PLATFORM_BL602 - bl_wdt_feed(); -#elif PLATFORM_W600 || PLATFORM_W800 - tls_watchdog_clr(); -#elif PLATFORM_LN882H - hal_wdt_cnt_restart(WDT_BASE); -#endif + HAL_Run_WDT(); // force it to sleep... we MUST have some idle task processing // else task memory doesn't get freed rtos_delay_milliseconds(1); @@ -940,7 +933,9 @@ void QuickTick(void* param) g_last_time = g_time; -#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) || (defined PLATFORM_LN882H) || (defined PLATFORM_ESPIDF) || (defined PLATFORM_TR6260) +#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) \ + || (defined PLATFORM_LN882H) || (defined PLATFORM_ESPIDF) || (defined PLATFORM_TR6260) \ + || (defined PLATFORM_RTL87X0C) SVM_RunThreads(g_deltaTimeMS); #endif RepeatingEvents_RunUpdate(g_deltaTimeMS * 0.001f); @@ -991,11 +986,11 @@ void QuickTick(void* param) // this is the bit which runs the quick tick timer #if WINDOWS -#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_TR6260 +#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_TR6260 || defined(PLATFORM_RTL87X0C) void quick_timer_thread(void* param) { while (1) { - vTaskDelay(QUICK_TMR_DURATION); + vTaskDelay(QUICK_TMR_DURATION / portTICK_PERIOD_MS); QuickTick(0); } } @@ -1010,7 +1005,7 @@ void QuickTick_StartThread(void) { #if WINDOWS -#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_TR6260 +#elif PLATFORM_BL602 || PLATFORM_W600 || PLATFORM_W800 || PLATFORM_TR6260 || defined(PLATFORM_RTL87X0C) xTaskCreate(quick_timer_thread, "quick", 1024, NULL, 15, NULL); #elif PLATFORM_ESPIDF @@ -1099,30 +1094,7 @@ void Main_Init_AfterDelay_Unsafe(bool bStartAutoRunScripts) { CMD_ExecuteCommand(CFG_GetShortStartupCommand(), COMMAND_FLAG_SOURCE_SCRIPT); CMD_ExecuteCommand("startScript autoexec.bat", COMMAND_FLAG_SOURCE_SCRIPT); } -#ifdef PLATFORM_BEKEN - bk_wdg_initialize(10000); -#elif PLATFORM_BL602 - // max is 4 seconds or so... - // #define MAX_MS_WDT (65535/16) - bl_wdt_init(3000); -#elif PLATFORM_W600 || PLATFORM_W800 - tls_watchdog_init(5*1000*1000); -#elif PLATFORM_LN882H - /* Watchdog initialization */ - wdt_init_t_def wdt_init; - memset(&wdt_init,0,sizeof(wdt_init)); - wdt_init.wdt_rmod = WDT_RMOD_1; // When equal to 0, the counter is reset directly when it overflows; when equal to 1, an interrupt is generated first when the counter overflows, and if it overflows again, it resets. - wdt_init.wdt_rpl = WDT_RPL_32_PCLK; // Set the reset delay time - wdt_init.top = WDT_TOP_VALUE_9; //wdt cnt value = 0x1FFFF Time = 4.095 s - hal_wdt_init(WDT_BASE, &wdt_init); - - /* Configure watchdog interrupt */ - NVIC_SetPriority(WDT_IRQn, 4); - NVIC_EnableIRQ(WDT_IRQn); - - /* Enable watchdog */ - hal_wdt_en(WDT_BASE,HAL_ENABLE); -#endif + HAL_Configure_WDT(); } void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { g_unsafeInitDone = true;