v1
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
/*!
|
||||
* \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 "xc6xxx_hal_timer.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
TimerStatus_t TimerStat = {
|
||||
.T0_Flag = false,
|
||||
.T1_Flag = false,
|
||||
.T2_Flag = false,
|
||||
.T3_Flag = false,
|
||||
.AO_T0_Flag = false,
|
||||
.AO_T1_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_BaseInitTypeDef Timer_Init;
|
||||
|
||||
Timer_Init.src_clk = TIMER_CLK_SRC_32M_DIV;
|
||||
Timer_Init.mode = TIMER_MODE_CYCLE_COUNT;
|
||||
Timer_Init.div_clk = TIMER_DIV_CLK_16MHzOr16K;
|
||||
// Timer0 Config & Start
|
||||
TIMER_Base_Init(XC_TIMER0, &Timer_Init);
|
||||
TIMER_SetUs(XC_TIMER0, us);
|
||||
TIMER_Start_IT(XC_TIMER0);
|
||||
// Timer1 Config & Start
|
||||
TIMER_Base_Init(XC_TIMER1, &Timer_Init);
|
||||
TIMER_SetUs(XC_TIMER1, us + 1000);
|
||||
TIMER_Start_IT(XC_TIMER1);
|
||||
// Timer2 Config & Start
|
||||
TIMER_Base_Init(XC_TIMER2, &Timer_Init);
|
||||
TIMER_SetUs(XC_TIMER2, us + 2000);
|
||||
TIMER_Start_IT(XC_TIMER2);
|
||||
// Timer3 Config & Start
|
||||
TIMER_Base_Init(XC_TIMER3, &Timer_Init);
|
||||
TIMER_SetUs(XC_TIMER3, us + 3000);
|
||||
TIMER_Start_IT(XC_TIMER3);
|
||||
|
||||
// AOTimer0 Config & Start
|
||||
Timer_Init.src_clk = TIMER_CLK_SRC_32K;
|
||||
TIMER_Base_Init(XC_AOTIMER0, &Timer_Init);
|
||||
TIMER_SetUs(XC_AOTIMER0, us + 4000);
|
||||
TIMER_Start_IT(XC_AOTIMER0);
|
||||
|
||||
// AOTimer1 Config & Start
|
||||
Timer_Init.src_clk = TIMER_CLK_SRC_32K;
|
||||
TIMER_Base_Init(XC_AOTIMER1, &Timer_Init);
|
||||
TIMER_SetUs(XC_AOTIMER1, us + 5000);
|
||||
TIMER_Start_IT(XC_AOTIMER1);
|
||||
|
||||
while (1) {
|
||||
if (TimerStat.T0_Flag == true) {
|
||||
DEBUG("__TIMER0__\n");
|
||||
TimerStat.T0_Flag = false;
|
||||
}
|
||||
|
||||
if (TimerStat.T1_Flag == true) {
|
||||
DEBUG("__TIMER1__\n");
|
||||
TimerStat.T1_Flag = false;
|
||||
}
|
||||
|
||||
if (TimerStat.T2_Flag == true) {
|
||||
DEBUG("__TIMER2__\n");
|
||||
TimerStat.T2_Flag = false;
|
||||
}
|
||||
|
||||
if (TimerStat.T3_Flag == true) {
|
||||
DEBUG("__TIMER3__\n");
|
||||
TimerStat.T3_Flag = false;
|
||||
}
|
||||
if (TimerStat.AO_T0_Flag == true) {
|
||||
DEBUG("__AOTIMER0__\n");
|
||||
TimerStat.AO_T0_Flag = false;
|
||||
}
|
||||
|
||||
if (TimerStat.AO_T1_Flag == true) {
|
||||
DEBUG("__AOTIMER1__\n");
|
||||
TimerStat.AO_T1_Flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer0_Callback
|
||||
* @details Timer0 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void Timer0_Callback(void *context) { TimerStat.T0_Flag = true; }
|
||||
|
||||
/**
|
||||
* @brief Timer1_Callback
|
||||
* @details Timer1 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void Timer1_Callback(void *context) { TimerStat.T1_Flag = true; }
|
||||
|
||||
/**
|
||||
* @brief Timer2_Callback
|
||||
* @details Timer2 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void Timer2_Callback(void *context) { TimerStat.T2_Flag = true; }
|
||||
|
||||
/**
|
||||
* @brief Timer3_Callback
|
||||
* @details Timer3 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void Timer3_Callback(void *context) { TimerStat.T3_Flag = true; }
|
||||
|
||||
/**
|
||||
* @brief AOTimer0_Callback
|
||||
* @details AOTimer0 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void AOTimer0_Callback(void *context) {
|
||||
TimerStat.AO_T0_Flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AOTimer1_Callback
|
||||
* @details AOTimer1 handler callback function
|
||||
* @param void *context
|
||||
* @retval void
|
||||
*/
|
||||
__RAM_CODE void AOTimer1_Callback(void *context) {
|
||||
TimerStat.AO_T1_Flag = true;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* \file timer.h
|
||||
*
|
||||
* \brief The head file of timer.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
TypeDef
|
||||
-------------------------------------------------------------------------------------*/
|
||||
typedef struct TimerStatus_s {
|
||||
uint8_t T0_Flag;
|
||||
uint8_t T1_Flag;
|
||||
uint8_t T2_Flag;
|
||||
uint8_t T3_Flag;
|
||||
uint8_t AO_T0_Flag;
|
||||
uint8_t AO_T1_Flag;
|
||||
|
||||
} TimerStatus_t;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Exported Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
void timer_demo(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TIMER_H__ */
|
||||
Reference in New Issue
Block a user