From 1702ce6ce430a66bb7af51644b91b7c196e719d9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 29 Jun 2022 11:03:02 +0300 Subject: =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9.=20=D0=9F=D1=80=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D0=B8=20NixieClock=5Fv2.=20=D0=A0=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=8B=20=D1=82=D0=B8=D0=BA=D0=B0=D1=8E=D1=82.=20=D0=95=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?,=20=D1=87=D1=82=D0=BE=20=D1=81=D0=BA=D0=B0=D1=87=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=80=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D0=B0=20(=D0=BE=D0=BD=D0=B0=20=D0=B2=20=D0=B4=D1=80?= =?UTF-8?q?=D1=83=D0=B3=D0=BE=D0=BC=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?).=20=D0=9F=D0=BE=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=B5=20=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0?= =?UTF-8?q?=D1=8E=D1=81=D1=8C=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B0=D0=BD=D1=82=D0=B8=D0=B4=D1=80=D0=B5=D0=B1=D0=B5=D0=B7?= =?UTF-8?q?=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TouchSense/STMTouch_Driver/src/tsl_time.c | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Libraries/TouchSense/STMTouch_Driver/src/tsl_time.c (limited to 'Libraries/TouchSense/STMTouch_Driver/src/tsl_time.c') diff --git a/Libraries/TouchSense/STMTouch_Driver/src/tsl_time.c b/Libraries/TouchSense/STMTouch_Driver/src/tsl_time.c new file mode 100644 index 0000000..d274575 --- /dev/null +++ b/Libraries/TouchSense/STMTouch_Driver/src/tsl_time.c @@ -0,0 +1,174 @@ +/** + ****************************************************************************** + * @file tsl_time.c + * @author MCD Application Team + * @version V1.4.4 + * @date 31-March-2014 + * @brief This file contains all functions to manage the timings in general. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2014 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "tsl_time.h" +#include "tsl_globals.h" + +/* Private typedefs ----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private functions prototype -----------------------------------------------*/ + +/** + * @brief Management of the timing module interrupt service routine. + * @param None + * @retval None + */ +void TSL_tim_ProcessIT(void) +{ + static TSL_tTick_ms_T count_1s = 0; + + // Count 1 global tick every xxx ms (defined by TSLPRM_TICK_FREQ parameter) + TSL_Globals.Tick_ms++; + + // Check if 1 second has elapsed + count_1s++; + if (count_1s > (TSLPRM_TICK_FREQ - 1)) + { + TSL_Globals.Tick_sec++; // 1 global tick every second + if (TSL_Globals.Tick_sec > 63) // Due to DTO counter on 6 bits... + { + TSL_Globals.Tick_sec = 0; + } + count_1s = 0; + } + +// Callback function +#if TSLPRM_USE_TIMER_CALLBACK > 0 + TSL_CallBack_TimerTick(); +#endif + +} + + +/** + * @brief Check if a delay (in ms) has elapsed. + * This function must be called regularly due to counter Roll-over only managed one time. + * @param[in] delay_ms Delay in ms + * @param[in] last_tick Variable holding the last tick value + * @retval Status + */ +TSL_Status_enum_T TSL_tim_CheckDelay_ms(TSL_tTick_ms_T delay_ms, __IO TSL_tTick_ms_T *last_tick) +{ + TSL_tTick_ms_T tick; + TSL_tTick_ms_T diff; + + disableInterrupts(); + + tick = TSL_Globals.Tick_ms; + + if (delay_ms == 0) + { + enableInterrupts(); + return TSL_STATUS_ERROR; + } + + // Counter Roll-over management + if (tick >= *last_tick) + { + diff = tick - *last_tick; + } + else + { + diff = (0xFFFF - *last_tick) + tick + 1; + } + +#if (TSLPRM_TICK_FREQ == 125) + if (diff >= (TSL_tTick_ms_T)(delay_ms >> 3)) // Divide by 8 for 8ms tick +#endif +#if (TSLPRM_TICK_FREQ == 250) + if (diff >= (TSL_tTick_ms_T)(delay_ms >> 2)) // Divide by 4 for 4ms tick +#endif +#if (TSLPRM_TICK_FREQ == 500) + if (diff >= (TSL_tTick_ms_T)(delay_ms >> 1)) // Divide by 2 for 2ms tick +#endif +#if (TSLPRM_TICK_FREQ == 1000) + if (diff >= (TSL_tTick_ms_T)delay_ms) // Direct value for 1ms tick +#endif +#if (TSLPRM_TICK_FREQ == 2000) + if (diff >= (TSL_tTick_ms_T)(delay_ms << 1)) // Multiply by 2 for 0.5ms tick +#endif + { + // Save current time + *last_tick = tick; + enableInterrupts(); + return TSL_STATUS_OK; + } + + enableInterrupts(); + return TSL_STATUS_BUSY; + +} + + +/** + * @brief Check if a delay (in s) has elapsed. + * @param[in] delay_sec Delay in seconds + * @param[in] last_tick Variable holding the last tick value + * @retval Status + */ +TSL_Status_enum_T TSL_tim_CheckDelay_sec(TSL_tTick_sec_T delay_sec, __IO TSL_tTick_sec_T *last_tick) +{ + TSL_tTick_sec_T tick; + TSL_tTick_sec_T diff; + + disableInterrupts(); + + tick = TSL_Globals.Tick_sec; + + if (delay_sec == 0) + { + enableInterrupts(); + return TSL_STATUS_ERROR; + } + + // Counter Roll-over management + if (tick >= *last_tick) + { + diff = (TSL_tTick_sec_T)(tick - *last_tick); + } + else + { + diff = (TSL_tTick_sec_T)((63 - *last_tick) + tick + 1); // DTO counter is on 6 bits + } + + if (diff >= delay_sec) + { + // Save current time + *last_tick = tick; + enableInterrupts(); + return TSL_STATUS_OK; + } + + enableInterrupts(); + return TSL_STATUS_BUSY; + +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -- cgit v1.2.3