hpw421初始版本
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
/*!
|
||||
* \file timer.c
|
||||
*
|
||||
* \brief Target timer implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "timer.h"
|
||||
#include "xc_drv_timer.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
TimerStatus_t timer_status =
|
||||
{
|
||||
.t0_flag = false,
|
||||
.t1_flag = false,
|
||||
.t2_flag = false,
|
||||
.t3_flag = false,
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief timer_demo
|
||||
* @details
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void timer_demo(void)
|
||||
{
|
||||
DEBUG("__TIMER_DEMO__\r");
|
||||
|
||||
uint32_t us = 1000*1000;
|
||||
Timer_InitCfg_t timer_cfg;
|
||||
|
||||
timer_cfg.timer_src_clk = TIMER_CLK_SRC_32K;
|
||||
timer_cfg.timer_div_clk = TIMER_DIV_CLK_16MHzOr16K;
|
||||
timer_cfg.timer_mode = TIMER_MODE_CYCLE;
|
||||
|
||||
// Timer0 Config & Start
|
||||
xc_timer_init(TIMER0_IDX, &timer_cfg);
|
||||
xc_timer_set_value(TIMER0_IDX, us);for(int i=0;i<0x455000;i++);
|
||||
xc_timer_start(TIMER0_IDX);
|
||||
// Timer1 Config & Start
|
||||
xc_timer_init(TIMER1_IDX, &timer_cfg);
|
||||
xc_timer_set_value(TIMER1_IDX, us);
|
||||
xc_timer_start(TIMER1_IDX);
|
||||
// Timer2 Config & Start
|
||||
xc_timer_init(TIMER2_IDX, &timer_cfg);
|
||||
xc_timer_set_value(TIMER2_IDX, us);
|
||||
xc_timer_start(TIMER2_IDX);
|
||||
// Timer3 Config & Start
|
||||
xc_timer_init(TIMER3_IDX, &timer_cfg);
|
||||
xc_timer_set_value(TIMER3_IDX, us);
|
||||
xc_timer_start(TIMER3_IDX);
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(timer_status.t0_flag == true)
|
||||
{
|
||||
DEBUG("__TIMER0__\n");
|
||||
timer_status.t0_flag = false;
|
||||
}
|
||||
|
||||
if(timer_status.t1_flag == true)
|
||||
{
|
||||
DEBUG("__TIMER1__\n");
|
||||
timer_status.t1_flag = false;
|
||||
}
|
||||
|
||||
if(timer_status.t2_flag == true)
|
||||
{
|
||||
DEBUG("__TIMER2__\n");
|
||||
timer_status.t2_flag = false;
|
||||
}
|
||||
|
||||
if(timer_status.t3_flag == true)
|
||||
{
|
||||
DEBUG("__TIMER3__\n");
|
||||
timer_status.t3_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer0_Callback
|
||||
* @details Timer0 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void timer0_callback(void *context)
|
||||
{
|
||||
timer_status.t0_flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer1_Callback
|
||||
* @details Timer1 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void timer1_callback(void *context)
|
||||
{
|
||||
timer_status.t1_flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer2_Callback
|
||||
* @details Timer2 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void timer2_callback(void *context)
|
||||
{
|
||||
timer_status.t2_flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer3_Callback
|
||||
* @details Timer3 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void timer3_callback(void *context)
|
||||
{
|
||||
timer_status.t3_flag = true;
|
||||
}
|
||||
Reference in New Issue
Block a user