hpw421初始版本
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
/*!
|
||||
* \file xc_drv_timer.h
|
||||
*
|
||||
* \brief The header of xc_drv_aotimer.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef _XC_DRV_TIMER_H_
|
||||
#define _XC_DRV_TIMER_H_
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xc6xxx.h"
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
#define TIMER_MIN_TLC_VAL 0x04
|
||||
#define TIMER_CLKSRC_32K_CAL(us) ( (CLOCK_RC_LFCLK_IN_32K / 1000)*us / 1000)
|
||||
#define TIMER_CLKSRC_32K_DIV_CAL(us, div) (32000 /(2 * (div + 1)) /100 * us / 10000)
|
||||
#define TIMER_CLKSRC_32M_DIV_CAL(us, div) (32000000 / (2 * (div + 1)) /100000 * us / 10)
|
||||
|
||||
|
||||
|
||||
#define TIMER_TCR_TIM_DISABLE (0x00UL)
|
||||
#define TIMER_TCR_TIM_ENABLE (0x01UL)
|
||||
|
||||
#define TIMER_TCR_TES_ENABLE (0x01UL)
|
||||
#define TIMER_TCR_TES_DISABLE (0x00UL)
|
||||
/*------------------------------------------------------------------------------------
|
||||
TypeDef
|
||||
-------------------------------------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
TIMER_CLK_SRC_32M_DIV = 0, /* Timer CLK SRC 32MHz div. */
|
||||
TIMER_CLK_SRC_32K_DIV = 1, /* Timer CLK SRC 32kHz div. */
|
||||
TIMER_CLK_SRC_32K = 3, /* Timer CLK SRC 32kHz. */
|
||||
} TIMER_SrcClkTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TIMER_DIV_CLK_16MHzOr16K = 0, /* Timer ref clk 16 MHz or 16KHz */
|
||||
TIMER_DIV_CLK_8MHzOr8K = 1, /* Timer ref clk 8 MHz or 8KHz */
|
||||
TIMER_DIV_CLK_4MHzOr4K = 2, /* Timer ref clk 4 MHz or 4KHz.*/
|
||||
TIMER_DIV_CLK_2MHzOr2K = 3, /* Timer ref clk 2 MHz or 2KHz.*/
|
||||
TIMER_DIV_CLK_1MHzOr1K = 4, /* Timer ref clk 1 MHz or 1KHz.*/
|
||||
TIMER_DIV_CLK_500KHzOr500 = 5, /* Timer ref clk 500 kHz or 500Hz.*/
|
||||
TIMER_DIV_CLK_250KHzOr250 = 6, /* Timer ref clk 250 kHz or 250Hz.*/
|
||||
TIMER_DIV_CLK_125KHzOr125 = 7, /* Timer ref clk 125 kHz or 125Hz.*/
|
||||
TIMER_DIV_CLK_62500HzOr62_5 = 8, /* Timer ref clk 62500 Hz or 62.5Hz.*/
|
||||
TIMER_DIV_CLK_32000Hz = 9 /* Timer ref clk 32000 Hz.*/
|
||||
} Timer_DivClkTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TIMER_MODE_SINGLE = 0,
|
||||
TIMER_MODE_CYCLE = 1,
|
||||
} Timer_ModeTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TIMER_SrcClkTypeDef timer_src_clk; /* Timer src clk. */
|
||||
Timer_DivClkTypeDef timer_div_clk; /* Timer div clk. */
|
||||
Timer_ModeTypeDef timer_mode; /* Timer mode. */
|
||||
uint32_t ticks; /* Timer ticks. */
|
||||
} Timer_InitCfg_t;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
typedef void (*timer_handler_callback)(void *context);
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Exported Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
void xc_timer_init(uint8_t reg_idx, Timer_InitCfg_t *init_cfg);
|
||||
void xc_timer_set_value(uint8_t reg_idx, uint32_t us);
|
||||
void xc_timer_start(uint8_t reg_idx);
|
||||
void xc_timer_stop(uint8_t reg_idx);
|
||||
|
||||
void timer0_callback(void *context);
|
||||
void timer1_callback(void *context);
|
||||
void timer2_callback(void *context);
|
||||
void timer3_callback(void *context);
|
||||
|
||||
#endif // _XC_DRV_AOTIMER_H_
|
||||
Reference in New Issue
Block a user