From c84887d021bc0d66352ead42366bd45868e1e4df Mon Sep 17 00:00:00 2001 From: heyuanjie87 Date: Wed, 2 Sep 2015 22:00:24 +0800 Subject: 加入定时器设备 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/drivers/hwtimer.h | 83 ++++++++++++++++++++++++++++ components/drivers/include/rtdevice.h | 4 ++ 2 files changed, 87 insertions(+) create mode 100644 components/drivers/include/drivers/hwtimer.h (limited to 'components/drivers/include') diff --git a/components/drivers/include/drivers/hwtimer.h b/components/drivers/include/drivers/hwtimer.h new file mode 100644 index 0000000000..e5b5d4661b --- /dev/null +++ b/components/drivers/include/drivers/hwtimer.h @@ -0,0 +1,83 @@ +#ifndef __HWTIMER_H__ +#define __HWTIMER_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ¶¨Ê±Æ÷¿ØÖÆÃüÁî */ +typedef enum +{ + HWTIMER_CTRL_TIMEOUT_SET = 0x01, /* ÉèÖó¬Ê±Öµ */ + HWTIMER_CTRL_FREQ_SET, /* ÉèÖüÆÊýƵÂÊ */ + HWTIMER_CTRL_START, /* Æô¶¯¶¨Ê±Æ÷ */ + HWTIMER_CTRL_STOP, /* Í£Ö¹¶¨Ê±Æ÷ */ + HWTIMER_CTRL_INFO_GET, /* »ñÈ¡¶¨Ê±Æ÷ÌØÕ÷ÐÅÏ¢ */ + HWTIMER_CTRL_MODE_SET /* ÉèÖö¨Ê±Ä£Ê½ */ +} rt_hwtimer_ctrl_t; + +/* ¶¨Ê±Ä£Ê½ */ +typedef enum +{ + HWTIMER_MODE_ONESHOT = 0x01, + HWTIMER_MODE_PERIOD +} rt_hwtimer_mode_t; + +/* ¶¨Ê±Æ÷¼ÆÊýÖµ */ +typedef struct rt_hwtimerval +{ + rt_int32_t sec; /* Ãë */ + rt_int32_t usec; /* ΢Ãë */ +} rt_hwtimerval_t; + +#define HWTIMER_CNTMODE_UP 0x01 /* ¶¨Ê±Æ÷µÝÔö¼ÆÊý·½Ê½ */ +#define HWTIMER_CNTMODE_DW 0x02 /* ¶¨Ê±Æ÷µÝ¼õ¼ÆÊý·½Ê½ */ + +struct rt_hwtimer_device; + +struct rt_hwtimer_ops +{ + void (*init)(struct rt_hwtimer_device *timer); + void (*deinit)(struct rt_hwtimer_device *timer); + void (*start)(struct rt_hwtimer_device *timer, rt_hwtimer_mode_t mode); + void (*stop)(struct rt_hwtimer_device *timer); + rt_err_t (*timeout_set)(struct rt_hwtimer_device *timer, rt_uint32_t t); + rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer); + rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args); +}; + +/* ¶¨Ê±Æ÷»ù±¾²ÎÊý(²»¿É¶¯Ì¬¸ü¸Ä) */ +struct rt_hwtimer_info +{ + rt_int32_t maxfreq; /* ¶¨Ê±Æ÷Ö§³ÖµÄ×î´ó¼ÆÊýʱÖÓ */ + rt_int32_t minfreq; /* ¶¨Ê±Æ÷Ö§³ÖµÄ×îС¼ÆÊýʱÖÓ */ + rt_uint32_t maxcnt; /* ¼ÆÊýÆ÷×î´ó³¬Ê±Öµ */ + rt_uint8_t cntmode; /* ¼ÆÊýģʽ(µÝÔö/µÝ¼õ,Ó¦ÓòãÎÞÐè¹ØÐĴ˲ÎÊý) */ +}; + +typedef struct rt_hwtimer_device +{ + struct rt_device parent; + const struct rt_hwtimer_ops *ops; + const struct rt_hwtimer_info *info; + + /* Çý¶¯²ã²»ÓùØÐÄÒÔϲÎÊý */ + rt_int32_t freq; /* ¼ÆÊýƵÂÊ */ + rt_int32_t overflow; /* Òç³ö´ÎÊý */ + float period_sec; /* Òç³öÖÜÆÚ(s) */ + rt_int32_t cycles; /* Ñ­»·´ÎÊý */ + rt_int32_t reload; /* ÖØÔØcycles */ + rt_hwtimer_mode_t mode; /* ¶¨Ê±Ä£Ê½ */ +} rt_hwtimer_t; + +rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data); +void rt_device_hwtimer_isr(rt_hwtimer_t *timer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index f4d967831c..475adebf80 100644 --- a/components/drivers/include/rtdevice.h +++ b/components/drivers/include/rtdevice.h @@ -370,6 +370,10 @@ rt_inline void rt_work_init(struct rt_work* work, void (*work_func)(struct rt_wo #include "drivers/can.h" #endif +#ifdef RT_USING_HWTIMER +#include "drivers/hwtimer.h" +#endif + #ifdef __cplusplus } #endif -- cgit v1.3.1