请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TDA4VH 工具/软件:
如何在 TDA4 电路板上的 Linux 中启用 ECAP?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:
如何在 TDA4 电路板上的 Linux 中启用 ECAP?
尊敬的 Gokul:
以下步骤将在 TDA4VH 板上启用 eCAP。 类似的更改也可应用于其他 TDA4 板:
-------------------------------------------------------------------------------------------------------------------------------
From 156367f0a2ad26d5d56f38ceefeb7c3f9d4fdeed Mon Sep 17 00:00:00 2001 From: Gokul Praveen <g-praveen@ti.com> Date: Tue, 22 Apr 2025 15:30:48 +0530 Subject: [PATCH] ECAP ENABLE Enables ECAP in capture mode on J784S4 Similar changes can be made to other boards as well --- arch/arm64/boot/dts/ti/k3-j784s4-evm.dts | 41 ++++++++++++++++++++++ arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi | 30 ++++++++++++++++ arch/arm64/boot/dts/ti/k3-j784s4.dtsi | 3 ++ 3 files changed, 74 insertions(+) diff --git a/arch/arm64/boot/dts/ti/k3-j784s4-evm.dts b/arch/arm64/boot/dts/ti/k3-j784s4-evm.dts index de256005f..61ea53554 100644 --- a/arch/arm64/boot/dts/ti/k3-j784s4-evm.dts +++ b/arch/arm64/boot/dts/ti/k3-j784s4-evm.dts @@ -500,8 +500,49 @@ audio_ext_refclk1_pins_default: audio-ext-refclk1-default-pins { J784S4_IOPAD(0x078, PIN_OUTPUT, 1) /* (AH37) MCAN2_RX.AUDIO_EXT_REFCLK1 */ >; }; + + myecap0_pins_default: myecap0-default-pins { + pinctrl-single,pins = < + J784S4_IOPAD(0x0c4, PIN_INPUT, 0) /* (AD36) ECAP0_IN_APWM_OUT */ + >; + }; + + myecap1_pins_default: myecap1-default-pins { + pinctrl-single,pins = < + J784S4_IOPAD(0x0e8, PIN_INPUT, 1) /* (AR38) TIMER_IO0.ECAP1_IN_APWM_OUT */ + >; + }; + + myecap2_pins_default: myecap2-default-pins { + pinctrl-single,pins = < + J784S4_IOPAD(0x0ec, PIN_INPUT, 1) /* (AN37) TIMER_IO1.ECAP2_IN_APWM_OUT */ + >; + }; + }; +&ecap0 { + /* ECAP in Capture mode */ + pinctrl-names = "default"; + pinctrl-0 = <&myecap0_pins_default>; + status = "okay"; + }; + +&ecap1 { + /* ECAP in Capture mode */ + pinctrl-names = "default"; + pinctrl-0 = <&myecap1_pins_default>; + status = "okay"; +}; + +&ecap2 { + /* ECAP in Capture mode */ + pinctrl-names = "default"; + pinctrl-0 = <&myecap2_pins_default>; + status = "okay"; +}; + + &wkup_pmx2 { bootph-all; wkup_uart0_pins_default: wkup-uart0-default-pins { diff --git a/arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi b/arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi index a7cecbdbc..a6ad9b4b9 100644 --- a/arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi +++ b/arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi @@ -1425,6 +1425,36 @@ serdes4: serdes@5050000 { }; }; + ecap0: capture@3100000 { + compatible = "ti,am62-ecap-capture"; + reg = <0x00 0x3100000 0x00 0x100>; + power-domains = <&k3_pds 126 TI_SCI_PD_EXCLUSIVE>; + clocks = <&k3_clks 126 0>; + clock-names = "fck"; + interrupt-parent = <&gic500>; + interrupts = <GIC_SPI 293 IRQ_TYPE_EDGE_RISING>; + }; + + ecap1: capture@3110000 { + compatible = "ti,am62-ecap-capture"; + reg = <0x00 0x3110000 0x00 0x100>; + power-domains = <&k3_pds 127 TI_SCI_PD_EXCLUSIVE>; + clocks = <&k3_clks 127 0>; + clock-names = "fck"; + interrupt-parent = <&gic500>; + interrupts = <GIC_SPI 294 IRQ_TYPE_EDGE_RISING>; + }; + + ecap2: capture@3120000 { + compatible = "ti,am62-ecap-capture"; + reg = <0x00 0x3120000 0x00 0x100>; + power-domains = <&k3_pds 128 TI_SCI_PD_EXCLUSIVE>; + clocks = <&k3_clks 128 0>; + clock-names = "fck"; + interrupt-parent = <&gic500>; + interrupts = <GIC_SPI 295 IRQ_TYPE_EDGE_RISING>; + }; + main_navss: bus@30000000 { bootph-all; compatible = "simple-bus"; diff --git a/arch/arm64/boot/dts/ti/k3-j784s4.dtsi b/arch/arm64/boot/dts/ti/k3-j784s4.dtsi index 5b09c97cf..8c2a07436 100644 --- a/arch/arm64/boot/dts/ti/k3-j784s4.dtsi +++ b/arch/arm64/boot/dts/ti/k3-j784s4.dtsi @@ -259,6 +259,9 @@ cbass_main: bus@100000 { <0x44 0x00000000 0x44 0x00000000 0x00 0x08000000>, /* PCIe2 DAT0 */ <0x44 0x10000000 0x44 0x10000000 0x00 0x08000000>, /* PCIe3 DAT0 */ <0x4e 0x20000000 0x4e 0x20000000 0x00 0x00080000>, /* GPU */ + <0x00 0x03100000 0x00 0x03100000 0x00 0x00000100>, /* Ecap0 */ + <0x00 0x03110000 0x00 0x03110000 0x00 0x00000100>, /* Ecap1*/ + <0x00 0x03120000 0x00 0x03120000 0x00 0x00000100>, /* Ecap2*/ /* MCUSS_WKUP Range */ <0x00 0x28380000 0x00 0x28380000 0x00 0x03880000>, -- 2.34.1
-------------------------------------------------------------------------------------------------------------------------------
用户空间脚本:
#!/bin/bash cd /sys/bus/counter/devices/counter0/signal1 echo positive > polarity0 echo negative > polarity1 echo positive > polarity2 echo negative > polarity3 cd /sys/bus/counter/devices/counter0/count0/ freq=$(cat /sys/bus/counter/devices/counter0/signal0/frequency) ceiling=$(cat /sys/bus/counter/devices/counter0/count0/ceiling) echo 0 > num_overflows echo 0 > count echo 1 > enable devmem2 0x3100028 w 0x003600EE #ECCTL devmem2 0x310002C w 0x003E0000 #ECINT_EN echo 0 > enable echo 1 > enable while true; do sleep 5 cap0_val=$(cat capture0) cap1_val=$(cat capture1) cap2_val=$(cat capture2) cap3_val=$(cat capture3) if [ "$cap1_val" -lt "$cap2_val" ]; then period_cnt=$(( cap1_val + cap2_val )) period=$(echo "scale=2; $period_cnt / $freq" | bc) high_cnt=$(( cap2_val )) duty=$(bc <<< "scale=2; $high_cnt / $period_cnt * 100") echo "Valid capture detected." echo "Period Count: $period_cnt" echo "High Count: $high_cnt" echo "Period (s): $period" echo "Duty Cycle: $duty%" break else echo "Invalid capture: cap0_val=$cap0_val, cap1_val=$cap1_val, cap2_val=$cap2_val, cap3_val=$cap3_val" echo "Retrying..." sleep 1 fi done echo "Final captured values:" echo "cap0_val: $cap0_val" echo "cap1_val: $cap1_val" echo "cap2_val: $cap2_val" echo "cap3_val: $cap3_val" echo 0 > enable
-------------------------------------------------------------------------------------------------------------------------------
此致
Gokul