LL01/code_app_out/Source/common/logic_timer.c
2025-04-26 16:03:23 +08:00

255 lines
8.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ##########################################################################
** Filename : logic_time.c
** Project :
** Module :
** Processor :
** Version : 1.0
** Compiler :
** Date/Time :
** Abstract :
** Contents :
** Note :
**
** (c) Copyright dmdz Co.,Ltd
** --------------------------------------------------------------------------
** R E V I S I O N H I S T O R Y
** --------------------------------------------------------------------------
** Date Ver Author Description
** -20191106- --V01-- --LYJ--- --初版--
** -20230602- --V1.0-- --mingyea--- --修改--
** #########################################################################*/
/*---------------------------------------------------------------------------
- I N C L U D E F I L E S
----------------------------------------------------------------------------*/
#include "common_types.h"
#include "logic_timer.h"
#include "cpu.h"
/*---------------------------------------------------------------------------
- D E F I N E S / M A C R O S
----------------------------------------------------------------------------*/
#define LOGICTIME_CONTEXT_ENABLE 1u /*隊列操作時開啟上下文切換*/
//注意上下文切换要在单片机的cpu.h中定义
#define LOGICTIME_CRITICAL_ENTER() System_DisableIrqGlobal()
#define LOGICTIME_CRITICAL_EXIT() System_EnableIrqGlobal()
/*---------------------------------------------------------------------------
- T Y P E D E F I N I T I O N S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- S T A T I C V A R I A B L E S
----------------------------------------------------------------------------*/
static logic_timer_t g_logic_time_tick;
/*---------------------------------------------------------------------------
- G L O B A L V A R I A B L E S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- F U N C T I O N P R O T O T Y P E
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_tick_init(void)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 初始化定時器
----------------------------------------------------------------------------*/
void logic_timer_tick_init (void)
{
LOGICTIME_CRITICAL_ENTER(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
g_logic_time_tick = 0u;
LOGICTIME_CRITICAL_EXIT(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
} /* End of function logic_timer_tick_init*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_tick_count(void)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 定時器中斷處理; 計數;
----------------------------------------------------------------------------*/
void logic_timer_tick_count(void)
{
LOGICTIME_CRITICAL_ENTER(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
g_logic_time_tick ++; /* Increment the current time */
LOGICTIME_CRITICAL_EXIT(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
} /* End of function logic_timer_tick_count*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_get_tick(void)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 读取tick
----------------------------------------------------------------------------*/
logic_timer_t logic_timer_get_tick(void)
{
logic_timer_t tmp;
LOGICTIME_CRITICAL_ENTER(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
tmp = g_logic_time_tick; /* Increment the current time */
LOGICTIME_CRITICAL_EXIT(); /*PCLINT_ERROS*/ /*lint !e717 */ /*do while*/
return tmp ; /* Increment the current time */
} /* End of function logic_timer_get_tick*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_start(logic_timer_s* delay_cb, void (*p_fun)(void),logic_timer_t delay_tick)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 启动逻辑定时器/延时
----------------------------------------------------------------------------*/
void logic_timer_start(logic_timer_s* delay_cb, void (*p_fun)(void),logic_timer_t delay_tick)
{
delay_cb->current_time = logic_timer_get_tick();
delay_cb->delay_time = delay_tick;
delay_cb->p_func = p_fun;
delay_cb->state = (u8)LOGIC_TIMER_FALSE;
/*delay_cb->abort_en = LOGIC_TIMER_FALSE;*/
} /* End of function logic_timer_start*/
/*---------------------------------------------------------------------------
|Prototype : u8 logic_timer_out(logic_timer_s* delay_cb)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 判断超时
----------------------------------------------------------------------------*/
u8 logic_timer_out(logic_timer_s* delay_cb)
{
u8 l_result=LOGIC_TIMER_FALSE;
/*
if(delay_cb->abort_en)
return TIME_ABORT;
*/
if(delay_cb->state == (u8)LOGIC_TIMER_FALSE)
{
delay_cb->get_offset_time = logic_timer_get_tick() - delay_cb->current_time;
if ((delay_cb->get_offset_time) >= delay_cb->delay_time)
{
if(delay_cb->p_func != (void*)NULL_POINT)
{
delay_cb->p_func();
}
logic_timer_abort(delay_cb);
l_result = LOGIC_TIMER_TRUE;
/*return LOGIC_TIMER_TRUE;*/
}
else
{
}
}
else
{
}
//return delay_cb->state; /*return TIME_RUNNING;*/
return l_result; /*return TIME_RUNNING;*/
} /* End of function logic_timer_out*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_abort(logic_timer_s *delay_cb)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 忽略
----------------------------------------------------------------------------*/
void logic_timer_abort(logic_timer_s *delay_cb)
{
/*delay_cb->abort_en = LOGIC_TIMER_TRUE;*/
delay_cb->p_func = (void*)NULL_POINT;
delay_cb->state = (u8)LOGIC_TIMER_TRUE;
} /* End of function logic_timer_abort*/
#if 0
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_tick_start(logic_timer_t *tick_counter, logic_timer_t tick_counts)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 没什么用
----------------------------------------------------------------------------*/
void logic_timer_tick_start(logic_timer_t *tick_counter, logic_timer_t tick_counts)
{
*tick_counter = tick_counts;
} /* End of function logic_timer_tick_start*/
/*---------------------------------------------------------------------------
|Prototype : u8 logic_timer_tick_time_out(logic_timer_t *tick_counter)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 没什么用
----------------------------------------------------------------------------*/
u8 logic_timer_tick_time_out(logic_timer_t *tick_counter)
{
u8 l_result;
if(*tick_counter !=0u)
{
(*tick_counter)--;
l_result = LOGIC_TIMER_FALSE; /*PRQA S 4420*/
}
else
{
l_result = LOGIC_TIMER_FALSE; /*PRQA S 4420*/
}
return l_result;
} /* End of function logic_timer_tick_time_out*/
/*---------------------------------------------------------------------------
|Prototype : void logic_timer_tick_abort(logic_timer_t* tick_counter)
|Called by : None
|Preconditions : None
|Input parameters : None
|Output parameters : None
|Return value : None
|Description : 没什么用
----------------------------------------------------------------------------*/
void logic_timer_tick_abort(logic_timer_t* tick_counter)
{
*tick_counter = 0u;
} /* End of function logic_timer_tick_abort*/
#endif
/* [] END OF FILE */