1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/notrynohigh-BabyOS

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
b_mod_timer.c 4.3 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
liklon Отправлено 3 лет назад ee07240
/**
*!
* \file b_mod_timer.c
* \version v0.0.1
* \date 2020/05/16
* \author Bean(notrynohigh@outlook.com)
*******************************************************************************
* @attention
*
* Copyright (c) 2020 Bean
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************
*/
/*Includes ----------------------------------------------*/
#include "modules/inc/b_mod_timer.h"
#include "hal/inc/b_hal.h"
#include "core/inc/b_section.h"
#if _TIMER_ENABLE
/**
* \addtogroup BABYOS
* \{
*/
/**
* \addtogroup MODULES
* \{
*/
/**
* \addtogroup TIMER
* \{
*/
/**
* \defgroup TIMER_Private_TypesDefinitions
* \{
*/
/**
* \}
*/
/**
* \defgroup TIMER_Private_Defines
* \{
*/
/**
* \}
*/
/**
* \defgroup TIMER_Private_Macros
* \{
*/
/**
* \}
*/
/**
* \defgroup TIMER_Private_Variables
* \{
*/
static bSoftTimerInstance_t *pSoftTimer = NULL;
/**
* \}
*/
/**
* \defgroup TIMER_Private_FunctionPrototypes
* \{
*/
/**
* \}
*/
/**
* \defgroup TIMER_Private_Functions
* \{
*/
static int _bSoftTimerDelete(bSoftTimerInstance_t *pTimerInstance)
{
bSoftTimerStruct_t *ptmp = pSoftTimer;
if (ptmp == NULL)
{
return -1;
}
if (pSoftTimer == pTimerInstance)
{
pSoftTimer = pSoftTimer->next;
return 0;
}
while (ptmp)
{
if (ptmp->next == pTimerInstance)
{
ptmp->next = pTimerInstance->next;
return 0;
}
ptmp = ptmp->next;
}
return -1;
}
static void _bSoftTimerCore()
{
bSoftTimerStruct_t *ptmp = pSoftTimer;
while (ptmp)
{
if (bHalGetSysTick() - ptmp->tick >= MS2TICKS(ptmp->period))
{
ptmp->handler();
if (ptmp->repeat)
{
ptmp->tick = bHalGetSysTick();
}
else
{
_bSoftTimerDelete(ptmp);
}
}
ptmp = ptmp->next;
}
}
BOS_REG_POLLING_FUNC(_bSoftTimerCore);
/**
* \}
*/
/**
* \addtogroup TIMER_Exported_Functions
* \{
*/
int bSoftTimerStart(bSoftTimerInstance_t *pTimerInstance, pTimerHandler handler)
{
if (pTimerInstance == NULL || handler == NULL)
{
return -1;
}
if (pSoftTimer == NULL)
{
pSoftTimer = pTimerInstance;
pTimerInstance->next = NULL;
}
else
{
pTimerInstance->next = pSoftTimer->next;
pSoftTimer->next = pTimerInstance;
}
pTimerInstance->handler = handler;
pTimerInstance->tick = bHalGetSysTick();
return 0;
}
int bSoftTimerStop(bSoftTimerInstance_t *pTimerInstance)
{
if (pTimerInstance == NULL)
{
return -1;
}
_bSoftTimerDelete(pTimerInstance);
return 0;
}
int bSoftTimerReset(bSoftTimerInstance_t *pTimerInstance)
{
if (pTimerInstance == NULL)
{
return -1;
}
pTimerInstance->tick = bHalGetSysTick();
return 0;
}
int bSoftTimerSetPeriod(bSoftTimerInstance_t *pTimerInstance, uint32_t ms)
{
if (pTimerInstance == NULL)
{
return -1;
}
pTimerInstance->period = ms;
return 0;
}
/**
* \}
*/
/**
* \}
*/
/**
* \}
*/
/**
* \}
*/
#endif
/************************ Copyright (c) 2020 Bean *****END OF FILE****/

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/notrynohigh-BabyOS.git
git@gitlife.ru:oschina-mirror/notrynohigh-BabyOS.git
oschina-mirror
notrynohigh-BabyOS
notrynohigh-BabyOS
V7.0.0