diff options
| author | Bernard Xiong <[email protected]> | 2018-06-10 17:59:17 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2018-06-10 17:59:17 +0800 |
| commit | 884fb70fe9973eaf01a7df04941cbcb0475ba8d5 (patch) | |
| tree | 7c8e3f42629e46b3d7ecb0c8507f67934d9fae47 /components/drivers/hwtimer/hwtimer.c | |
| parent | bca65f30a90857287dc1371ddbc8d5f165691c7f (diff) | |
[Kernel] Add device ops feature.
Diffstat (limited to 'components/drivers/hwtimer/hwtimer.c')
| -rw-r--r-- | components/drivers/hwtimer/hwtimer.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c index 066c5f6f6c..c3e5076343 100644 --- a/components/drivers/hwtimer/hwtimer.c +++ b/components/drivers/hwtimer/hwtimer.c @@ -35,13 +35,13 @@ rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv) float devi_min = 1; float devi; - /* �Ѷ�ʱ�����ʱ��Ͷ�ʱʱ�任����� */ + /* changed to second */ overflow = timer->info->maxcnt/(float)timer->freq; tv_sec = tv->sec + tv->usec/(float)1000000; if (tv_sec < (1/(float)timer->freq)) { - /* ��ʱʱ��С�ڼ������� */ + /* little timeout */ i = 0; timeout = 1/(float)timer->freq; } @@ -55,7 +55,7 @@ rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv) { counter = timeout*timer->freq; devi = tv_sec - (counter/(float)timer->freq)*i; - /* ������С��� */ + /* Minimum calculation error */ if (devi > devi_min) { i = index; @@ -89,7 +89,7 @@ static rt_err_t rt_hwtimer_init(struct rt_device *dev) rt_hwtimer_t *timer; timer = (rt_hwtimer_t *)dev; - /* ���Խ�Ĭ�ϼ���Ƶ����Ϊ1Mhz */ + /* try to change to 1MHz */ if ((1000000 <= timer->info->maxfreq) && (1000000 >= timer->info->minfreq)) { timer->freq = 1000000; @@ -330,6 +330,18 @@ void rt_device_hwtimer_isr(rt_hwtimer_t *timer) } } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops hwtimer_ops = +{ + rt_hwtimer_init, + rt_hwtimer_open, + rt_hwtimer_close, + rt_hwtimer_read, + rt_hwtimer_write, + rt_hwtimer_control +}; +#endif + rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data) { struct rt_device *device; @@ -344,12 +356,16 @@ rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void device->rx_indicate = RT_NULL; device->tx_complete = RT_NULL; +#ifdef RT_USING_DEVICE_OPS + device->ops = &hwtimer_ops; +#else device->init = rt_hwtimer_init; device->open = rt_hwtimer_open; device->close = rt_hwtimer_close; device->read = rt_hwtimer_read; device->write = rt_hwtimer_write; device->control = rt_hwtimer_control; +#endif device->user_data = user_data; return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); |
