From 497d5664c915744d1002ed2475c011ebdcdcdbad Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 22 Dec 2025 13:52:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/PwmCaptureFlagchip.h | 36 +++++++++++++++++++ Src/PwmCaptureFlagchip.c | 75 ++++++++++++++++++++++++++++++++++++++++ modular.json | 10 ++++++ 3 files changed, 121 insertions(+) create mode 100644 Inc/PwmCaptureFlagchip.h create mode 100644 Src/PwmCaptureFlagchip.c create mode 100644 modular.json diff --git a/Inc/PwmCaptureFlagchip.h b/Inc/PwmCaptureFlagchip.h new file mode 100644 index 0000000..3345f31 --- /dev/null +++ b/Inc/PwmCaptureFlagchip.h @@ -0,0 +1,36 @@ +// +// Created by cfif on 17.11.22. +// + +#ifndef PWM_CAPTURE_FLAGCHIP_H +#define PWM_CAPTURE_FLAGCHIP_H + +#include "PwmIO.h" +#include "cmsis_os2.h" +#include "fc7xxx_driver_tpu.h" +#include "interrupt_manager.h" + +typedef struct { + + TPU_InterruptCfgType etpu_Int_config_tbl; + TPU_CaptureCfgType etpu_captureconfig_tbl; + + uint8_t TPU_CAPTURE_CHANNEL; + +} tPwmCaptureFlagchip; + + +void PWM_Capture_Initial( + tPwmCaptureFlagchip *env, + uint32_t PeriodTime, + uint32_t ActiveTime, + uint8_t TPU_CAPTURE_CHANNEL, + uint8 TPU0_CH_PRIORITY, + TPU_EventCallbackType Bsp_Tpu_PwmCallback, + TPU_TCR1OverflowCallbackType Bsp_Tpu_OverflowCallBack); + +tPwmIO vPwmCaptureGetIo(tPwmCaptureFlagchip *env); + +void Get_Set_Tpu_PwmCaptureCallback(tPwmCaptureFlagchip *env); + +#endif //PWM_CAPTURE_FLAGCHIP_H diff --git a/Src/PwmCaptureFlagchip.c b/Src/PwmCaptureFlagchip.c new file mode 100644 index 0000000..7b1f473 --- /dev/null +++ b/Src/PwmCaptureFlagchip.c @@ -0,0 +1,75 @@ +// +// Created by cfif on 07.09.22. +// +#include +#include "PwmCaptureFlagchip.h" + + +void Get_Set_Tpu_PwmCaptureCallback(tPwmCaptureFlagchip *env) { + if (env->etpu_captureconfig_tbl.eMeasureMode == TPU_PeriodMeasurement) { + TPU_CaptureMeasPeriodServiceReq(env->TPU_CAPTURE_CHANNEL, &env->etpu_captureconfig_tbl); + } else { + TPU_CaptureMeasActivePeriodServiceReq(env->TPU_CAPTURE_CHANNEL, &env->etpu_captureconfig_tbl); + } +} + +void PWM_Capture_Initial( + tPwmCaptureFlagchip *env, + uint32_t PeriodTime, + uint32_t ActiveTime, + uint8_t TPU_CAPTURE_CHANNEL, + uint8 TPU0_CH_PRIORITY, + TPU_EventCallbackType Bsp_Tpu_PwmCallback, + TPU_TCR1OverflowCallbackType Bsp_Tpu_OverflowCallBack) { + + + env->etpu_captureconfig_tbl.u32PeriodTime = 0u; + env->etpu_captureconfig_tbl.eMeasureMode = TPU_DutyMeasurementActiveHigh; + env->etpu_captureconfig_tbl.eInputType = TPUE_DETECT_FALLING_EDGE_ONLY; + env->etpu_captureconfig_tbl.u32SampleTime = 80000; // Ensure sample time > period + env->etpu_captureconfig_tbl.u32ActiveTime = 0; + env->etpu_captureconfig_tbl.LastTime = 0; + env->etpu_captureconfig_tbl.StartTime = 0; + + env->etpu_Int_config_tbl.bEventIntEn = (bool) true; + env->etpu_Int_config_tbl.bTCR1OverFlowEventIntEn = (bool) true; + env->etpu_Int_config_tbl.bTCR2OverFlowEventIntEn = (bool) false; + env->etpu_Int_config_tbl.pEventNotify = Bsp_Tpu_PwmCallback; + env->etpu_Int_config_tbl.pHSANotify = NULL; + env->etpu_Int_config_tbl.pTCR1OverflowNotify = Bsp_Tpu_OverflowCallBack; + env->etpu_Int_config_tbl.pTCR2OverflowNotify = NULL; + env->etpu_Int_config_tbl.eChTrigType = TPUH_TDL1_OR_TDL2_EVENT_NOT_GATED_BY_TSR; + + env->TPU_CAPTURE_CHANNEL = TPU_CAPTURE_CHANNEL; + + + TPU_DeInit(); + TPU_Init(); + TPU_CaptureModeInit(TPU_CAPTURE_CHANNEL, &env->etpu_captureconfig_tbl); + TPU_InitChannelInterrupt(TPU_CAPTURE_CHANNEL, &env->etpu_Int_config_tbl); + + if (TPU_CAPTURE_CHANNEL <= 7) { + NVIC_EnableIRQ(TPU0_CH0_7_IRQn); + NVIC_SetPriority(TPU0_CH0_7_IRQn, 1); + } else if (TPU_CAPTURE_CHANNEL <= 15) { + NVIC_EnableIRQ(TPU0_CH8_15_IRQn); + NVIC_SetPriority(TPU0_CH8_15_IRQn, 2); + } else if (TPU_CAPTURE_CHANNEL <= 23) { + NVIC_EnableIRQ(TPU0_CH16_23_IRQn); + NVIC_SetPriority(TPU0_CH16_23_IRQn, 3); + } else if (TPU_CAPTURE_CHANNEL <= 31) { + NVIC_EnableIRQ(TPU0_CH24_31_IRQn); + NVIC_SetPriority(TPU0_CH24_31_IRQn, 4); + } + +} +/* +tPwmIO vPwmCaptureGetIo(tPwmCaptureFlagchip *env) { + tPwmIO io = { + .env = env, + .run = (PwmIOTransaction) vPwmRun, + .setActivePercent = (PwmIOTransactionSetActivePercent) setActivePercent + }; + return io; +} + */ \ No newline at end of file diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..71971cd --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file