本帖最后由 lovzx 于 2024-6-3 13:36 编辑
问题已解决:根据泽哥的方案,换SDK,或者在aithinker_Ai-M6X_SDK/bsp/board/bl616dk/board.c,256行的#endif下加个中断复位函数,bflb_irq_restore(flag);
编译下载sdk下面的timer_int程序,跑起来发现无法触发定时器中断,尝试分析问题无果
main代码增加了一些log
- #include "bflb_mtimer.h"
- #include "bflb_timer.h"
- #include "board.h"
- #include "bflb_irq.h"
- #define TEST_TIMER_COMP_ID TIMER_COMP_ID_2
- struct bflb_device_s* timer0;
- struct bflb_device_s* timer1;
- extern struct bflb_irq_info_s g_irqvector[];
- void timer0_isr(int irq, void* arg)
- {
- int id = -1;
- bool status = bflb_timer_get_compint_status(timer0, TIMER_COMP_ID_0);
- if (status) {
- bflb_timer_compint_clear(timer0, TIMER_COMP_ID_0);
- printf("timer0 comp0 trigger\r\n");
- id = 0;
- }
- status = bflb_timer_get_compint_status(timer0, TIMER_COMP_ID_1);
- if (status) {
- bflb_timer_compint_clear(timer0, TIMER_COMP_ID_1);
- printf("timer0 comp1 trigger\r\n");
- id = 1;
- }
- status = bflb_timer_get_compint_status(timer0, TIMER_COMP_ID_2);
- if (status) {
- bflb_timer_compint_clear(timer0, TIMER_COMP_ID_2);
- printf("timer0 comp2 trigger\r\n");
- id = 2;
- }
- printf("timer0 isr,id: %d\n", id);
- }
- void timer1_isr(int irq, void* arg)
- {
- int id = -1;
- bool status = bflb_timer_get_compint_status(timer1, TIMER_COMP_ID_0);
- if (status) {
- id = 0;
- bflb_timer_compint_clear(timer1, TIMER_COMP_ID_0);
- printf("timer1 comp0 trigger\r\n");
- }
- status = bflb_timer_get_compint_status(timer1, TIMER_COMP_ID_1);
- if (status) {
- id = 1;
- bflb_timer_compint_clear(timer1, TIMER_COMP_ID_1);
- printf("timer1 comp1 trigger\r\n");
- }
- status = bflb_timer_get_compint_status(timer1, TIMER_COMP_ID_2);
- if (status) {
- id = 2;
- bflb_timer_compint_clear(timer1, TIMER_COMP_ID_2);
- printf("timer1 comp2 trigger\r\n");
- }
- printf("timer1 isr,id: %d\n", id);
- }
- int main(void)
- {
- board_init();
- printf("Timer basic test\n");
- /* timer clk = XCLK/(div + 1 )*/
- struct bflb_timer_config_s cfg0;
- cfg0.counter_mode = TIMER_COUNTER_MODE_PROLOAD; /* preload when match occur */
- cfg0.clock_source = TIMER_CLKSRC_XTAL;
- cfg0.clock_div = 39; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
- cfg0.trigger_comp_id = TEST_TIMER_COMP_ID;
- cfg0.comp0_val = 1000000; /* match value 0 */
- cfg0.comp1_val = 1500000; /* match value 1 */
- cfg0.comp2_val = 2500000; /* match value 2 */
- cfg0.preload_val = 0; /* preload value */
- struct bflb_timer_config_s cfg1;
- cfg1.counter_mode = TIMER_COUNTER_MODE_PROLOAD;
- cfg1.clock_source = TIMER_CLKSRC_XTAL;
- cfg1.clock_div = 39; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
- cfg1.trigger_comp_id = TEST_TIMER_COMP_ID;
- cfg1.comp0_val = 1000000; /* match value 0 */
- cfg1.comp1_val = 2000000; /* match value 1 */
- cfg1.comp2_val = 2500000; /* match value 2 */
- cfg1.preload_val = 0; /* preload value */
- timer0 = bflb_device_get_by_name("timer0");
- timer1 = bflb_device_get_by_name("timer1");
- /* Timer init with default configuration */
- bflb_timer_init(timer0, &cfg0);
- bflb_timer_init(timer1, &cfg1);
- //16 + 36 = 52
- bflb_irq_attach(timer0->irq_num, timer0_isr, NULL);
- //16 + 37 = 53
- bflb_irq_attach(timer1->irq_num, timer1_isr, NULL);
- bflb_irq_enable(timer0->irq_num);
- bflb_irq_enable(timer1->irq_num);
- /* Enable timer */
- bflb_timer_start(timer0);
- bflb_timer_start(timer1);
- printf("table: %p\n",g_irqvector);
- printf("timer0_isr: %p, timer1_isr: %p\n", timer0_isr, timer1_isr);
- for (int i = 0;i < 64;i++) {
- irq_callback call = g_irqvector[i].handler;
- // if (timer0_isr == call) {
- // printf("timer0_isr: %d,%p\n", i, timer0_isr);
- // }
- // if (timer1_isr == call) {
- // printf("timer1_isr: %d,%p\n", i, timer1_isr);
- // }
- if(call != NULL){
- printf("irq: %d, call: %p\n",i,call);
- }
- }
- printf("case success.\r\n");
- volatile uint32_t mcause = 0UL;
- uint32_t irq_num;
- while (1) {
- int v1 = bflb_timer_get_countervalue(timer1);
- int v0 = bflb_timer_get_countervalue(timer0);
- if (v1 == 1000000 || v1 == 2000000 || v1 == 2500000)
- {
-
- mcause = READ_CSR(CSR_MCAUSE);
- irq_num = mcause & 0x3FF;
- printf("irq_num: %d\n",irq_num);
- printf("v1: %d\n", v1);
- }
- if (v0 == 1000000 || v0 == 1500000 || v0 == 2500000)
- {
-
- mcause = READ_CSR(CSR_MCAUSE);
- irq_num = mcause & 0x3FF;
- printf("irq_num: %d\n", irq_num);
- printf("v0: %d\n", v0);
- }
- }
- }
复制代码
运行输入日志如下
- Timer basic test
- table: 0x62fc9770
- timer0_isr: 0xa0002d90, timer1_isr: 0xa0002e2a
- irq: 0, call: 0xa00047ca
- irq: 1, call: 0xa00047ca
- irq: 2, call: 0xa00047ca
- irq: 3, call: 0xa00047ca
- irq: 4, call: 0xa00047ca
- irq: 5, call: 0xa00047ca
- irq: 6, call: 0xa00047ca
- irq: 7, call: 0xa00047ca
- irq: 8, call: 0xa00047ca
- irq: 9, call: 0xa00047ca
- irq: 10, call: 0xa00047ca
- irq: 11, call: 0xa00047ca
- irq: 12, call: 0xa00047ca
- irq: 13, call: 0xa00047ca
- irq: 14, call: 0xa00047ca
- irq: 15, call: 0xa00047ca
- irq: 16, call: 0xa00047ca
- irq: 17, call: 0xa00047ca
- irq: 18, call: 0xa00047ca
- irq: 19, call: 0xa00047ca
- irq: 20, call: 0xa00047ca
- irq: 21, call: 0xa00047ca
- irq: 22, call: 0xa00047ca
- irq: 23, call: 0xa00047ca
- irq: 24, call: 0xa00047ca
- irq: 25, call: 0xa00047ca
- irq: 26, call: 0xa00047ca
- irq: 27, call: 0xa00047ca
- irq: 28, call: 0xa00047ca
- irq: 29, call: 0xa00047ca
- irq: 30, call: 0xa00047ca
- irq: 31, call: 0xa00047ca
- irq: 32, call: 0xa00047ca
- irq: 33, call: 0xa00047ca
- irq: 34, call: 0xa00047ca
- irq: 35, call: 0xa00047ca
- irq: 36, call: 0xa00047ca
- irq: 37, call: 0xa00047ca
- irq: 38, call: 0xa00047ca
- irq: 39, call: 0xa00047ca
- irq: 40, call: 0xa00047ca
- irq: 41, call: 0xa00047ca
- irq: 42, call: 0xa00047ca
- irq: 43, call: 0xa00047ca
- irq: 44, call: 0xa00047ca
- irq: 45, call: 0xa00047ca
- irq: 46, call: 0xa00047ca
- irq: 47, call: 0xa00047ca
- irq: 48, call: 0xa00047ca
- irq: 49, call: 0xa00047ca
- irq: 50, call: 0xa00047ca
- irq: 51, call: 0xa00047ca
- irq: 52, call: 0xa0002d90
- irq: 53, call: 0xa0002e2a
- irq: 54, call: 0xa00047ca
- irq: 55, call: 0xa00047ca
- irq: 56, call: 0xa00047ca
- irq: 57, call: 0xa00047ca
- irq: 58, call: 0xa00047ca
- irq: 59, call: 0xa00047ca
- irq: 60, call: 0xa00047ca
- irq: 61, call: 0xa00047ca
- irq: 62, call: 0xa00047ca
- irq: 63, call: 0xa00047ca
- case success.
- //上面log可以看出中断表里面已经正常设置了52号中断timer0_isr和53号中断timer1_isr, 当触发预设值后读取到的中断寄存器值却是0,也么有调用设置的中断函数,不知道哪里出问题了
- [2024/06/02 23:53:24.913] → irq_num: 0
- v0: 1000000
- [2024/06/02 23:53:25.419] → irq_num: 0
- v0: 1500000
- [2024/06/02 23:53:25.915] → irq_num: 0
- v1: 2000000
复制代码
上面log可以看出中断表里面已经正常设置了52号中断timer0_isr和53号中断timer1_isr, 当触发预设值后读取到的中断寄存器值却是0,也么有调用设置的中断函数,不知道哪里出问题了
|
|