Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bsp][cvitek] update: add hwtimer driver #39

Closed
wants to merge 3 commits into from

Conversation

Z8MAN8
Copy link

@Z8MAN8 Z8MAN8 commented Jun 20, 2024

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@Z8MAN8
Copy link
Author

Z8MAN8 commented Jun 21, 2024

2024-06-21 00-06-15 的屏幕截图

@unicornx
Copy link
Collaborator

unicornx commented Jun 24, 2024

请检查并确保 PR 的 checklist 都已经正确执行 ,见上面 PR 的内容部分的勾选项。

@Z8MAN8
Copy link
Author

Z8MAN8 commented Jun 25, 2024

已检查并勾选

@@ -295,6 +295,32 @@ menu "General Drivers Configuration"
default n
endif

menuconfig BSP_USING_HWTIMER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么只支持了小核?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前实测小核驱动正常,大核不能正常进入定时器中断(中断号与datasheet一致,80-86)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前实测小核驱动正常,大核不能正常进入定时器中断(中断号与datasheet一致,80-86)

请继续解决这个问题,我记得在裸机下试过大核的 timer 中断是好的。请看看是哪里的问题?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

发现原因是大核最大中断号设置为64(定时器终端号大于该值),导致初始化时没有成功注册定时器中断。

config IRQ_MAX_NR
int
default 64


config TIMER_IRQ_BASE
int
default 51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 51 是针对的什么芯片?

我看 SG2002/SG2000 的小核上这个值是 55

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

针对的是CV1800B

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

针对的是CV1800B

那需要在 Kconfig 中用 board type 区分开才好。

@unicornx
Copy link
Collaborator

@Z8MAN8 上面你有个评论里的贴图好像出问题了,检查一下? 重贴还是删掉?

@unicornx unicornx requested a review from flyingcys June 25, 2024 06:01
@Z8MAN8
Copy link
Author

Z8MAN8 commented Jun 26, 2024

@Z8MAN8 上面你有个评论里的贴图好像出问题了,检查一下? 重贴还是删掉?

测试截图已更新

@unicornx
Copy link
Collaborator

@Z8MAN8 上面你有个评论里的贴图好像出问题了,检查一下? 重贴还是删掉?

测试截图已更新

看不到你的测试代码,所以贴图也看不出什么

@Z8MAN8
Copy link
Author

Z8MAN8 commented Jun 27, 2024

@Z8MAN8 上面你有个评论里的贴图好像出问题了,检查一下? 重贴还是删掉?

测试截图已更新

看不到你的测试代码,所以贴图也看不出什么

测试代码如下,由于定时器频率仅可选为25MHz /32KHz,当前驱动和测试均默认使用25MHz

/*

  • 程序清单:这是一个 hwtimer 设备使用例程
  • 例程导出了 hwtimer_sample 命令到控制终端
  • 命令调用格式:hwtimer_sample
  • 程序功能:硬件定时器超时回调函数周期性的打印当前tick值,2次tick值之差换算为时间等同于定时时间值。
    */

#include <rtthread.h>
#include <rtdevice.h>

#define HWTIMER_DEV_NAME "timer4" /* 定时器名称 */

/* 定时器超时回调函数 */
static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
{
rt_kprintf("this is hwtimer timeout callback fucntion!\n");
rt_kprintf("tick is :%d !\n", rt_tick_get());
return 0;
}

static int hwtimer_sample(int argc, char argv[])
{
rt_err_t ret = RT_EOK;
rt_hwtimerval_t timeout_s; /
定时器超时值 /
rt_device_t hw_dev = RT_NULL; /
定时器设备句柄 /
rt_hwtimer_mode_t mode; /
定时器模式 /
/
查找定时器设备 /
hw_dev = rt_device_find(HWTIMER_DEV_NAME);
if (hw_dev == RT_NULL)
{
rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
return RT_ERROR;
}
/
以读写方式打开设备 /
ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
if (ret != RT_EOK)
{
rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
return ret;
}
/
设置超时回调函数 /
rt_device_set_rx_indicate(hw_dev, timeout_cb);
/
设置模式为周期性定时器(若未设置,默认是HWTIMER_MODE_ONESHOT)/
mode = HWTIMER_MODE_PERIOD;
ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
if (ret != RT_EOK)
{
rt_kprintf("set mode failed! ret is :%d\n", ret);
return ret;
}
/
设置定时器超时值为5s并启动定时器 /
timeout_s.sec = 5; /
/
timeout_s.usec = 0; /
微秒 /
if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
{
rt_kprintf("set timeout value failed\n");
return RT_ERROR;
}
/
延时3500ms /
rt_thread_mdelay(3500);
/
读取定时器当前值 */
rt_device_read(hw_dev, 0, &timeout_s, sizeof(timeout_s));
rt_kprintf("Read: Sec = %d, Usec = %d\n", timeout_s.sec, timeout_s.usec);
return ret;
}

MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);

@Z8MAN8 Z8MAN8 closed this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants