mppt/Drivers/TimeSliceOffset/timeSliceOffset.c

149 lines
4.8 KiB
C
Raw Normal View History

2024-07-11 06:58:55 +00:00
/*
* timeSliceOffset.c
*
* Created on: 2024<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>22<EFBFBD><EFBFBD>
* Author: psx
*/
#include "TimeSliceOffset.h"
static STR_TimeSliceOffset* pTimeSliceList = NULL; /**< ʱ<><CAB1>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ָ<EFBFBD><D6B8><EFBFBD>豸ʵ<E8B1B8><EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<D5BC><E4A1A3><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) */
/**
* @brief ע<EFBFBD><EFBFBD>
* @param[in] pTSlice ʱ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param[in] taskFunc <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param[in] reloadVal ʱ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ*tick<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>м<EFBFBD><EFBFBD><EFBFBD>
* @param[in] offset ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD>λ<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* - 0 ע<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* - 1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* - -1 pTSliceΪ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @par ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* - reloadVal<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>Ƕ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>offsetƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
* @par ʾ<EFBFBD><EFBFBD>:
* @code
*
* TimeSliceOffset_Register(&m_timeSlice_1, Task_1, 0, 0); //0<><30><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>(ÿ<><C3BF><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>)
* TimeSliceOffset_Register(&m_timeSlice_2, Task_2, 10, 0); //10*1ms<6D><73><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
* TimeSliceOffset_Register(&m_timeSlice_3, Task_3, 10, 5); //10*1ms<6D><73><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>Task_2<5F><32><EFBFBD><EFBFBD>5ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD>е<EFBFBD>ͬһ<CDAC><D2BB>10ms<6D><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @endcode
*/
int TimeSliceOffset_Register(STR_TimeSliceOffset* pTSlice, \
void (*taskFunc)(void), \
unsigned short reloadVal, \
unsigned short offset)
{
if(NULL == pTSlice)return -1; /* <20><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD> */
pTSlice->reloadVal = reloadVal;
pTSlice->count = reloadVal + offset; /* <20><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ͬһ<CDAC><D2BB>ֵ<EFBFBD><D6B5>ʱ<EFBFBD><CAB1>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD> */
pTSlice->taskFunc = taskFunc;
if(0 == reloadVal) /* <20>Ƕ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
{
pTSlice->runFlag = 1; /* <20>Ƕ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>־Ĭ<D6BE><C4AC>Ϊһ */
}
else /* <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
{
pTSlice->runFlag = 0; /* <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>־Ĭ<D6BE><C4AC>Ϊ<EFBFBD><CEAA> */
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>*/
for(STR_TimeSliceOffset* pTemp = pTimeSliceList; pTemp != NULL; pTemp = pTemp->pNext)
{
if(pTemp == pTSlice)
{
return 1; /* <20><><EFBFBD>سɹ<D8B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
pTSlice->pNext = pTimeSliceList;
pTimeSliceList = pTSlice; /* <20>Ѷ<EFBFBD><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB5BD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7> */
return 0; /* <20><><EFBFBD>سɹ<D8B3><C9B9><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>ɹ<EFBFBD> */
}
/**
* @brief ȡ<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>
* @return ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* - 0 ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>óɹ<EFBFBD>
* - 1 ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>óɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󲻴<EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>
* - -1 pTSliceΪ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @endcode
*/
int TimeSliceOffset_Unregister(STR_TimeSliceOffset* pTSlice)
{
if (NULL == pTSlice) return -1; /* <20><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD> */
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
for (STR_TimeSliceOffset* pTemp = pTimeSliceList; pTemp != NULL; pTemp = pTemp->pNext) {
if (pTemp->pNext == pTSlice) {
pTemp->pNext = pTemp->pNext->pNext;
return 0; /* <20><><EFBFBD>سɹ<D8B3><C9B9><EFBFBD>ȡ<EFBFBD><C8A1>ע<EFBFBD><D7A2> */
} else if (pTemp == pTSlice) {
pTimeSliceList = pTemp->pNext;
// pTimeSliceList->pNext = pTemp->pNext->pNext;
return 0; /* <20><><EFBFBD>سɹ<D8B3><C9B9><EFBFBD>ȡ<EFBFBD><C8A1>ע<EFBFBD><D7A2> */
}
}
return 1; /* <20><><EFBFBD>سɹ<D8B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󲻴<EFBFBD><F3B2BBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ѯ(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>main<EFBFBD><EFBFBD>whileѭ<EFBFBD><EFBFBD>)
* @param null
* @return null
* @par ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* - null
*/
void TimeSliceOffset_Start(void)
{
while(1) /* <20><><EFBFBD><EFBFBD>main<69><6E>whileѭ<65><D1AD> */
{
/*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>*/
for(STR_TimeSliceOffset* pTemp = pTimeSliceList; pTemp != NULL; pTemp = pTemp->pNext)
{
if(pTemp->runFlag) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{
if(pTemp->reloadVal) /* <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
{
pTemp->runFlag = 0; /* <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ʱ */
}
pTemp->taskFunc();
}
}
}
}
/**
* @brief ʱ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ŵ<EFBFBD>systick<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
* @param null
* @return null
* @par ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* - null
*/
void TimeSliceOffset_Produce(void)
{
/*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>*/
for(STR_TimeSliceOffset* pTemp = pTimeSliceList; pTemp != NULL; pTemp = pTemp->pNext)
{
if(pTemp->reloadVal) /* <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
{
--pTemp->count; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD> */
if(0 == pTemp->count) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD> */
{
pTemp->runFlag = 1; /* <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4> */
pTemp->count = pTemp->reloadVal; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
}
}
}