/
anaera
/
timeService
Обзор
Документация
Войти
/
anaera
/
timeService
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
timerService.c
65 строк
1 KB
anaera
upload files
04 дек 2025, 19:39
04 дек 2025, 19:39
1b4c508
Код
Авторство
О чём код?
/* * File: timerService.c * Author: Chiper * * Created on 4 декабря 2025 г., 15:32 */ #include <xc.h> #define MAX_TIMERS 4 typedef struct { uint16_t coutTime; uint16_t(*funcAct)(void); } timers_t; timers_t *ptrTimer; uint16_t(*funcService)(void); void (*funcHandle)(uint8_t); timers_t myTimers[MAX_TIMERS]; void initServiceTimer(uint16_t(*funcSetFlag)(void), void(*funcSetHandle)(uint8_t)) { uint8_t handle = 0; ptrTimer = &myTimers[0]; while (MAX_TIMERS - handle) { if (ptrTimer->funcAct == NULL) { ptrTimer->coutTime = 0; ptrTimer->funcAct = funcSetFlag; funcSetHandle(handle); return; } handle++; ptrTimer++; } }; void checkTimers(void) { uint8_t handle = 0; ptrTimer = &myTimers[0]; while (MAX_TIMERS - handle) { if (ptrTimer->funcAct != NULL) { if (ptrTimer->coutTime == 0) { ptrTimer->coutTime = ptrTimer->funcAct(); } else { ptrTimer->coutTime--; } } handle++; ptrTimer++; } } void clrTimerHandle(uint8_t handle) { myTimers[handle].funcAct = NULL; } void updTimerHandle(uint8_t handle) { myTimers[handle].coutTime = 0; }