From e938075e1148fb74968c63d9cd34a5e024e0a56a Mon Sep 17 00:00:00 2001 From: NeoZng Date: Wed, 19 Jul 2023 13:58:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BD=8D=E9=94=81=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2mutex=E5=92=8Csemaphore=E5=AE=9E=E7=8E=B0,=E4=BB=85?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/c_cpp_properties.json | 20 ++++++++++++++++++++ bsp/can/bsp_can.c | 2 +- bsp/dwt/bsp_dwt.c | 23 +++++++++++------------ 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..0859405 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "windows-gcc-arm", + "configurationProvider": "ms-vscode.makefile-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/bsp/can/bsp_can.c b/bsp/can/bsp_can.c index 5f2b890..52d09e6 100644 --- a/bsp/can/bsp_can.c +++ b/bsp/can/bsp_can.c @@ -80,7 +80,7 @@ CANInstance *CANRegister(CAN_Init_Config_s *config) LOGERROR("[}bsp_can] CAN id crash ,tx [%d] or rx [%d] already registered", &config->tx_id, &config->rx_id); } } - + CANInstance *instance = (CANInstance *)malloc(sizeof(CANInstance)); // 分配空间 memset(instance, 0, sizeof(CANInstance)); // 分配的空间未必是0,所以要先清空 // 进行发送报文的配置 diff --git a/bsp/dwt/bsp_dwt.c b/bsp/dwt/bsp_dwt.c index 61d95d6..b9703d8 100644 --- a/bsp/dwt/bsp_dwt.c +++ b/bsp/dwt/bsp_dwt.c @@ -16,7 +16,6 @@ static uint32_t CPU_FREQ_Hz, CPU_FREQ_Hz_ms, CPU_FREQ_Hz_us; static uint32_t CYCCNT_RountCount; static uint32_t CYCCNT_LAST; static uint64_t CYCCNT64; -static osMutexId DWT_MUTEX; /** * @brief 私有函数,用于检查DWT CYCCNT寄存器是否溢出,并更新CYCCNT_RountCount @@ -28,16 +27,17 @@ static osMutexId DWT_MUTEX; */ static void DWT_CNT_Update(void) { - if (__get_CONTROL()) // 不在中断中,使用互斥锁;在中断则直接执行即可,本框架将所有中断优先级设置为相同,故不会被其他中断重入 - if (osOK != osMutexWait(DWT_MUTEX, 0)) - return; + static volatile uint8_t bit_locker = 0; + if (!bit_locker) + { + bit_locker = 1; + volatile uint32_t cnt_now = DWT->CYCCNT; + if (cnt_now < CYCCNT_LAST) + CYCCNT_RountCount++; - volatile uint32_t cnt_now = DWT->CYCCNT; - if (cnt_now < CYCCNT_LAST) - CYCCNT_RountCount++; - - CYCCNT_LAST = DWT->CYCCNT; - osMutexRelease(DWT_MUTEX); + CYCCNT_LAST = DWT->CYCCNT; + bit_locker = 0; + } } void DWT_Init(uint32_t CPU_Freq_mHz) @@ -55,8 +55,7 @@ void DWT_Init(uint32_t CPU_Freq_mHz) CPU_FREQ_Hz_ms = CPU_FREQ_Hz / 1000; CPU_FREQ_Hz_us = CPU_FREQ_Hz / 1000000; CYCCNT_RountCount = 0; - osMutexDef(dwt_mutex); - DWT_MUTEX = osMutexCreate(osMutex(dwt_mutex)); + DWT_CNT_Update(); }