/**************************************************************************//**
 * @item     CosyOS-III Kernel
 * @file     os_timing.c
 * @brief    初始化定时中断、定时查询
 * @author   迟凯峰
 * @version  v3.0.0
 * @date     2026.07.21
 ******************************************************************************/

#include "os_var.h"

#if (OS_TIMINTTOTAL > 0 || OS_TIMQRYTOTAL > 0)

#define __EXT_TIMINT(tmid)  extern s_timinthand_ts _STATIC_MEM_ u_timinthand_##tmid;
#define __EXT_TIMQRY(tmid)  extern s_timqryhand_ts _STATIC_MEM_ u_timqryhand_##tmid;
#define __INIT_TIMINT(tmid) s_timint_handle[tmid] = &u_timinthand_##tmid;
#define __INIT_TIMQRY(tmid) s_timqry_handle[tmid] = &u_timqryhand_##tmid;

#if (OS_TIMINTTOTAL > 0)
__EXT_TIMINT(0)
#if (OS_TIMINTTOTAL > 1)
__EXT_TIMINT(1)
#if (OS_TIMINTTOTAL > 2)
__EXT_TIMINT(2)
#if (OS_TIMINTTOTAL > 3)
__EXT_TIMINT(3)
#if (OS_TIMINTTOTAL > 4)
__EXT_TIMINT(4)
#if (OS_TIMINTTOTAL > 5)
__EXT_TIMINT(5)
#if (OS_TIMINTTOTAL > 6)
__EXT_TIMINT(6)
#if (OS_TIMINTTOTAL > 7)
__EXT_TIMINT(7)
#if (OS_TIMINTTOTAL > 8)
__EXT_TIMINT(8)
#if (OS_TIMINTTOTAL > 9)
__EXT_TIMINT(9)
#if (OS_TIMINTTOTAL > 10)
__EXT_TIMINT(10)
#if (OS_TIMINTTOTAL > 11)
__EXT_TIMINT(11)
#if (OS_TIMINTTOTAL > 12)
__EXT_TIMINT(12)
#if (OS_TIMINTTOTAL > 13)
__EXT_TIMINT(13)
#if (OS_TIMINTTOTAL > 14)
__EXT_TIMINT(14)
#if (OS_TIMINTTOTAL > 15)
__EXT_TIMINT(15)
#if (OS_TIMINTTOTAL > 16)
__EXT_TIMINT(16)
#if (OS_TIMINTTOTAL > 17)
__EXT_TIMINT(17)
#if (OS_TIMINTTOTAL > 18)
__EXT_TIMINT(18)
#if (OS_TIMINTTOTAL > 19)
__EXT_TIMINT(19)
#if (OS_TIMINTTOTAL > 20)
__EXT_TIMINT(20)
#if (OS_TIMINTTOTAL > 21)
__EXT_TIMINT(21)
#if (OS_TIMINTTOTAL > 22)
__EXT_TIMINT(22)
#if (OS_TIMINTTOTAL > 23)
__EXT_TIMINT(23)
#if (OS_TIMINTTOTAL > 24)
__EXT_TIMINT(24)
#if (OS_TIMINTTOTAL > 25)
__EXT_TIMINT(25)
#if (OS_TIMINTTOTAL > 26)
__EXT_TIMINT(26)
#if (OS_TIMINTTOTAL > 27)
__EXT_TIMINT(27)
#if (OS_TIMINTTOTAL > 28)
__EXT_TIMINT(28)
#if (OS_TIMINTTOTAL > 29)
__EXT_TIMINT(29)
#if (OS_TIMINTTOTAL > 30)
__EXT_TIMINT(30)
#if (OS_TIMINTTOTAL > 31)
__EXT_TIMINT(31)
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif

#if (OS_TIMQRYTOTAL > 0)
__EXT_TIMQRY(0)
#if (OS_TIMQRYTOTAL > 1)
__EXT_TIMQRY(1)
#if (OS_TIMQRYTOTAL > 2)
__EXT_TIMQRY(2)
#if (OS_TIMQRYTOTAL > 3)
__EXT_TIMQRY(3)
#if (OS_TIMQRYTOTAL > 4)
__EXT_TIMQRY(4)
#if (OS_TIMQRYTOTAL > 5)
__EXT_TIMQRY(5)
#if (OS_TIMQRYTOTAL > 6)
__EXT_TIMQRY(6)
#if (OS_TIMQRYTOTAL > 7)
__EXT_TIMQRY(7)
#if (OS_TIMQRYTOTAL > 8)
__EXT_TIMQRY(8)
#if (OS_TIMQRYTOTAL > 9)
__EXT_TIMQRY(9)
#if (OS_TIMQRYTOTAL > 10)
__EXT_TIMQRY(10)
#if (OS_TIMQRYTOTAL > 11)
__EXT_TIMQRY(11)
#if (OS_TIMQRYTOTAL > 12)
__EXT_TIMQRY(12)
#if (OS_TIMQRYTOTAL > 13)
__EXT_TIMQRY(13)
#if (OS_TIMQRYTOTAL > 14)
__EXT_TIMQRY(14)
#if (OS_TIMQRYTOTAL > 15)
__EXT_TIMQRY(15)
#if (OS_TIMQRYTOTAL > 16)
__EXT_TIMQRY(16)
#if (OS_TIMQRYTOTAL > 17)
__EXT_TIMQRY(17)
#if (OS_TIMQRYTOTAL > 18)
__EXT_TIMQRY(18)
#if (OS_TIMQRYTOTAL > 19)
__EXT_TIMQRY(19)
#if (OS_TIMQRYTOTAL > 20)
__EXT_TIMQRY(20)
#if (OS_TIMQRYTOTAL > 21)
__EXT_TIMQRY(21)
#if (OS_TIMQRYTOTAL > 22)
__EXT_TIMQRY(22)
#if (OS_TIMQRYTOTAL > 23)
__EXT_TIMQRY(23)
#if (OS_TIMQRYTOTAL > 24)
__EXT_TIMQRY(24)
#if (OS_TIMQRYTOTAL > 25)
__EXT_TIMQRY(25)
#if (OS_TIMQRYTOTAL > 26)
__EXT_TIMQRY(26)
#if (OS_TIMQRYTOTAL > 27)
__EXT_TIMQRY(27)
#if (OS_TIMQRYTOTAL > 28)
__EXT_TIMQRY(28)
#if (OS_TIMQRYTOTAL > 29)
__EXT_TIMQRY(29)
#if (OS_TIMQRYTOTAL > 30)
__EXT_TIMQRY(30)
#if (OS_TIMQRYTOTAL > 31)
__EXT_TIMQRY(31)
#if (OS_TIMQRYTOTAL > 32)
__EXT_TIMQRY(32)
#if (OS_TIMQRYTOTAL > 33)
__EXT_TIMQRY(33)
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif

void os_init_timing(void)
{
	#if (OS_TIMINTTOTAL > 0)
	__INIT_TIMINT(0)
	#if (OS_TIMINTTOTAL > 1)
	__INIT_TIMINT(1)
	#if (OS_TIMINTTOTAL > 2)
	__INIT_TIMINT(2)
	#if (OS_TIMINTTOTAL > 3)
	__INIT_TIMINT(3)
	#if (OS_TIMINTTOTAL > 4)
	__INIT_TIMINT(4)
	#if (OS_TIMINTTOTAL > 5)
	__INIT_TIMINT(5)
	#if (OS_TIMINTTOTAL > 6)
	__INIT_TIMINT(6)
	#if (OS_TIMINTTOTAL > 7)
	__INIT_TIMINT(7)
	#if (OS_TIMINTTOTAL > 8)
	__INIT_TIMINT(8)
	#if (OS_TIMINTTOTAL > 9)
	__INIT_TIMINT(9)
	#if (OS_TIMINTTOTAL > 10)
	__INIT_TIMINT(10)
	#if (OS_TIMINTTOTAL > 11)
	__INIT_TIMINT(11)
	#if (OS_TIMINTTOTAL > 12)
	__INIT_TIMINT(12)
	#if (OS_TIMINTTOTAL > 13)
	__INIT_TIMINT(13)
	#if (OS_TIMINTTOTAL > 14)
	__INIT_TIMINT(14)
	#if (OS_TIMINTTOTAL > 15)
	__INIT_TIMINT(15)
	#if (OS_TIMINTTOTAL > 16)
	__INIT_TIMINT(16)
	#if (OS_TIMINTTOTAL > 17)
	__INIT_TIMINT(17)
	#if (OS_TIMINTTOTAL > 18)
	__INIT_TIMINT(18)
	#if (OS_TIMINTTOTAL > 19)
	__INIT_TIMINT(19)
	#if (OS_TIMINTTOTAL > 20)
	__INIT_TIMINT(20)
	#if (OS_TIMINTTOTAL > 21)
	__INIT_TIMINT(21)
	#if (OS_TIMINTTOTAL > 22)
	__INIT_TIMINT(22)
	#if (OS_TIMINTTOTAL > 23)
	__INIT_TIMINT(23)
	#if (OS_TIMINTTOTAL > 24)
	__INIT_TIMINT(24)
	#if (OS_TIMINTTOTAL > 25)
	__INIT_TIMINT(25)
	#if (OS_TIMINTTOTAL > 26)
	__INIT_TIMINT(26)
	#if (OS_TIMINTTOTAL > 27)
	__INIT_TIMINT(27)
	#if (OS_TIMINTTOTAL > 28)
	__INIT_TIMINT(28)
	#if (OS_TIMINTTOTAL > 29)
	__INIT_TIMINT(29)
	#if (OS_TIMINTTOTAL > 30)
	__INIT_TIMINT(30)
	#if (OS_TIMINTTOTAL > 31)
	__INIT_TIMINT(31)
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	
	#if (OS_TIMQRYTOTAL > 0)
	__INIT_TIMQRY(0)
	#if (OS_TIMQRYTOTAL > 1)
	__INIT_TIMQRY(1)
	#if (OS_TIMQRYTOTAL > 2)
	__INIT_TIMQRY(2)
	#if (OS_TIMQRYTOTAL > 3)
	__INIT_TIMQRY(3)
	#if (OS_TIMQRYTOTAL > 4)
	__INIT_TIMQRY(4)
	#if (OS_TIMQRYTOTAL > 5)
	__INIT_TIMQRY(5)
	#if (OS_TIMQRYTOTAL > 6)
	__INIT_TIMQRY(6)
	#if (OS_TIMQRYTOTAL > 7)
	__INIT_TIMQRY(7)
	#if (OS_TIMQRYTOTAL > 8)
	__INIT_TIMQRY(8)
	#if (OS_TIMQRYTOTAL > 9)
	__INIT_TIMQRY(9)
	#if (OS_TIMQRYTOTAL > 10)
	__INIT_TIMQRY(10)
	#if (OS_TIMQRYTOTAL > 11)
	__INIT_TIMQRY(11)
	#if (OS_TIMQRYTOTAL > 12)
	__INIT_TIMQRY(12)
	#if (OS_TIMQRYTOTAL > 13)
	__INIT_TIMQRY(13)
	#if (OS_TIMQRYTOTAL > 14)
	__INIT_TIMQRY(14)
	#if (OS_TIMQRYTOTAL > 15)
	__INIT_TIMQRY(15)
	#if (OS_TIMQRYTOTAL > 16)
	__INIT_TIMQRY(16)
	#if (OS_TIMQRYTOTAL > 17)
	__INIT_TIMQRY(17)
	#if (OS_TIMQRYTOTAL > 18)
	__INIT_TIMQRY(18)
	#if (OS_TIMQRYTOTAL > 19)
	__INIT_TIMQRY(19)
	#if (OS_TIMQRYTOTAL > 20)
	__INIT_TIMQRY(20)
	#if (OS_TIMQRYTOTAL > 21)
	__INIT_TIMQRY(21)
	#if (OS_TIMQRYTOTAL > 22)
	__INIT_TIMQRY(22)
	#if (OS_TIMQRYTOTAL > 23)
	__INIT_TIMQRY(23)
	#if (OS_TIMQRYTOTAL > 24)
	__INIT_TIMQRY(24)
	#if (OS_TIMQRYTOTAL > 25)
	__INIT_TIMQRY(25)
	#if (OS_TIMQRYTOTAL > 26)
	__INIT_TIMQRY(26)
	#if (OS_TIMQRYTOTAL > 27)
	__INIT_TIMQRY(27)
	#if (OS_TIMQRYTOTAL > 28)
	__INIT_TIMQRY(28)
	#if (OS_TIMQRYTOTAL > 29)
	__INIT_TIMQRY(29)
	#if (OS_TIMQRYTOTAL > 30)
	__INIT_TIMQRY(30)
	#if (OS_TIMQRYTOTAL > 31)
	__INIT_TIMQRY(31)
	#if (OS_TIMQRYTOTAL > 32)
	__INIT_TIMQRY(32)
	#if (OS_TIMQRYTOTAL > 33)
	__INIT_TIMQRY(33)
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	#endif
	
	#if (SYSCFG_DEBUGGING == __ENABLED__)
	#if (SYSCFG_USERTIMQRYINIT - 1)
	  s_timqry_handle[OS_TMID_DEBUGGER]->timer
	= s_timqry_handle[OS_TMID_DEBUGGER]->reload
	= 0;
	#endif
	  s_timqry_handle[OS_TMID_TASKMGR]->timer
	= s_timqry_handle[OS_TMID_TASKMGR]->reload
	= (SYSCFG_TASKMGR_UPSPEED * 1000UL) / SYSCFG_SYSTICK_CYCLE;
	#endif
}

#endif
