You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by 范姜徐霖 <ja...@gmail.com> on 2021/03/13 11:24:15 UTC

hw/mcu/sifive/fe310/src/hal_timer.c question

I want to run ble_app sample code using SIFIVE mcu.
I modify the bsp from nordic to my board and change mcu to sifive.
I copy apache-mynewt-nimble/nimble/drivers/native and
modify it to simulate radio hardware. for now it just for not stuck code
running.

I load code and run , I got some ble log messages below.

after checking code, I found
inside hal_timer_start_at() function, it call fe310_tmr_check_first and
it seems not operate correctly.
It will issue pwm interrupt continuely, so it stuck.

is there anyone help ? or I missing something?

-----------------------------------------------------------------------
static void
fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
{
    struct hal_timer *ht;

    ht = TAILQ_FIRST(&tmr->sht_timers);
    if (ht) {
        uint32_t cnt = hal_timer_cnt(tmr);
        int32_t ticks = (int32_t)(ht->expiry - cnt);
        if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
            _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;   <====question code
            plic_enable_interrupt(tmr->pwmxcmp0_int + 1);    <====question
code
            return;
        }
    }
    _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
     /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used all the
time */
    plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
}
------------------------------------------------------------------------------


=================================================
000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0 ocf=0x0
000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0003
len=0
000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
ocf=0x3 status=0
000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04 ocf=0x0001
len=0
000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535 lmp_subver=0
000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0001
len=8
000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00 0x02 0x00
0x80 0x00 0x20
000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
ocf=0x1 status=0
000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0063
len=8
000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80 0x00 0x00
0x00 0x00 0x00
000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
ocf=0x63 status=0
000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0001
len=8
000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f 0x00 0x00
0x00 0x00 0x00
000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x1 status=0
000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0002 len=0
000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x2 status=0
000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0003 len=0
000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x3 status=0
000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
ocf=0x0009 len=0
000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x002d len=1
000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x2d status=0
000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0029 len=0
000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x29 status=0
000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x002d len=1
000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x2d status=0
000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
advertising.
000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x000a len=1
000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0xa status=0
000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0027 len=39
000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b 0xdd 0x34
0xc0 0x53 0x1e 0xb8
000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x27 status=7
000037 [ts=289044us, mod=4 level=0] looking up peer sec;
000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
000038 -ble_app_on_sync-
000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0018 len=0
000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x18 status=0 rand=0x0001020304050607
000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0005 len=6
000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02 0x03 0x04
0x05
000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x5 status=0
000044 addr:0x900019dd
000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0008 len=32
000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01 0x06 0x1a
0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x8 status=0
000049 [ts=382788us, mod=4 level=1] GAP procedure initiated: advertise;
disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
adv_itvl_min=0 adv_itvl_max=0
000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x0006 len=15
00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0 0x00 0x03
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
ocf=0x6 status=0
000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
ocf=0x000a len=1
000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
=================================================

it stuck here, no more any message..

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Jack,

I pushed more changes to the PR, since my previous mail.
It would be great if you confirmed that it helps with your problem.
There is no one  else verifying riscv code that I know of, PR is
already approved but
confirmation from someone that actually uses code would be valuable.

Thanks for finding out problem.

Best regards
Jerzy

pon., 15 mar 2021 o 11:44 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> Hi, Jerzy,
>
> my program first call hal_timer_config( freq_hz=32768 )
> pwm2 reg setting after call hal_timer_config() : PWM2_CMP0=0xffff,
> PWM2_CMP1=0xffff, PWM_CFG=0x1209
>
> and some time after,
> the problem happen at calling hal_timer_start_at(ticks) function which
> parameter ticks is < 0xffff  but > PWM_S
> in my case ticks = PWM_S+0x6a
>
> and inside hal_timer_start_at function it will call fe310_tmr_check_first(),
> -----------------------------------------------
>
> static void
> fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> {
>     struct hal_timer *ht;
>
>     ht = TAILQ_FIRST(&tmr->sht_timers);
>     if (ht) {
>         uint32_t cnt = hal_timer_cnt(tmr);
>         int32_t ticks = (int32_t)(ht->expiry - cnt);  ---> 0x6a
>         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {  ---> 0x6a < 0xffff
>             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;    ---> pwm_cmp1
> is assigned 0x6a, and now pwm_s > 0x6a
>             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);  --->enable
> pwm_cmp1 interrupt
>             return;
>         }
>     }
>     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
>      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> all the time */
>     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> }
>
> then interrupt forever..
>
>
>
> Jack
>
> Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午5:23寫道:
>
> > Hi Jack,
> >
> > I setup blinky-like project with default settings that hifive1 bsp set
> > with one
> > modification:
> >
> > SYS_CLOCK: HFXOSC_16_MHZ
> >
> > I also added two cpu timers like this:
> >
> > os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> > os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
> >
> > os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> > os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
> >
> > Code is using cpu timer that is using PWM2 that should be similar to
> > what you have.
> > My timer callbacks just toggle some GPIO to verify that frequencies are
> > correct.
> > So far everything works as expected.
> >
> > 1. Maybe you could share timer/clock related content of your syscfg.
> > 2. Maybe timer usage is different then mine (hal_timer api instead of
> > cpu_timer that I used for quick check)
> >
> > br
> > Jerzy
> >
> > pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >
> > > 3. frequency on PWM timer: 32768
> > >
> > > Jack
> > >
> > > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> > >
> > > > Hi,
> > > >
> > > > 1. system clock frequency:16MHz
> > > > 2. which PWM: PWM2
> > > > 3. frequency on PWM timer: 32758
> > > >
> > > > Jack
> > > >
> > > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一
> > 下午3:33寫道:
> > > >
> > > >> Hi,
> > > >>
> > > >> I don't remember details to answer number 3 out of my head. But we
> > > >> will find out soon.
> > > >> In the meanwhile can you give me:
> > > >> 1. system clock frequency that you have selected
> > > >> 2. which PWM is causing problem.
> > > >> 3. what is frequency on PWM timer.
> > > >> Those will help me setup environment closer to what you have.
> > > >>
> > > >> br
> > > >> Jerzy
> > > >>
> > > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >> >
> > > >> > Hi,
> > > >> >
> > > >> > 1. Do you know if tick is negative at line that you marked
> > > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > > >> >
> > > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff,
> > PEM_CFG=0xc0001209,
> > > >> ticks
> > > >> > =0x6a
> > > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> > > >> > (fe310_pwm_cmp1_handler)
> > > >> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> > > >> > interrupt, and so on..
> > > >> >
> > > >> > 2. I am sorry I can not share project with you, it is company
> > project.
> > > >> >     I can provide program running info
> > > >> >
> > > >> > 3. I have a question about hal_timer_cnt function .
> > > >> > how does the code check overflow condition?
> > > >> >
> > > >> > Thanks for your help.
> > > >> >
> > > >> > --------------------------------------------------
> > > >> > static uint32_t
> > > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > > >> > {
> > > >> >     uint32_t cnt;
> > > >> >     int sr;
> > > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > > >> >
> > > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > > >> >     /* Check if just overflowed */
> > > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > > >> >     }
> > > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > > >> >
> > > >> >     return cnt;
> > > >> > }
> > > >> > -----------------------------------------------------
> > > >> >
> > > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > > >> 下午11:35寫道:
> > > >> >
> > > >> > > Hi,
> > > >> > >
> > > >> > > 1. Do you know if tick is negative at line that you marked
> > > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > > >> > >
> > > >> > > 2. Can you share your project with me somehow so I could take a
> > look
> > > >> > > (presuming it is running on hifive1 board)?
> > > >> > >
> > > >> > > I can take a look at this next Monday.
> > > >> > >
> > > >> > > best regards
> > > >> > > Jerzy
> > > >> > >
> > > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >> > > >
> > > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > > >> > > > I modify the bsp from nordic to my board and change mcu to
> > sifive.
> > > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > >> > > > modify it to simulate radio hardware. for now it just for not
> > stuck
> > > >> code
> > > >> > > > running.
> > > >> > > >
> > > >> > > > I load code and run , I got some ble log messages below.
> > > >> > > >
> > > >> > > > after checking code, I found
> > > >> > > > inside hal_timer_start_at() function, it call
> > fe310_tmr_check_first
> > > >> and
> > > >> > > > it seems not operate correctly.
> > > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > > >> > > >
> > > >> > > > is there anyone help ? or I missing something?
> > > >> > > >
> > > >> > > >
> > > >>
> > -----------------------------------------------------------------------
> > > >> > > > static void
> > > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > >> > > > {
> > > >> > > >     struct hal_timer *ht;
> > > >> > > >
> > > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > > >> > > >     if (ht) {
> > > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > > >> <====question code
> > > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > > >>  <====question code
> > > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > > >> > > <====question
> > > >> > > > code
> > > >> > > >             return;
> > > >> > > >         }
> > > >> > > >     }
> > > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > > >> PWM_CMP0);
> > > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is
> > used
> > > >> all
> > > >> > > the
> > > >> > > > time */
> > > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > >> > > > }
> > > >> > > >
> > > >> > >
> > > >>
> > ------------------------------------------------------------------------------
> > > >> > > >
> > > >> > > >
> > > >> > > > =================================================
> > > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1
> > ogf=0x0
> > > >> > > ocf=0x0
> > > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0003
> > > >> > > > len=0
> > > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x3 status=0
> > > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > > >> > > ocf=0x0001
> > > >> > > > len=0
> > > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x4
> > > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > > >> lmp_subver=0
> > > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0001
> > > >> > > > len=8
> > > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
> > > >> 0x02
> > > >> > > 0x00
> > > >> > > > 0x80 0x00 0x20
> > > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x1 status=0
> > > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0063
> > > >> > > > len=8
> > > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00
> > > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x63 status=0
> > > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > >> > > ocf=0x0001
> > > >> > > > len=8
> > > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe
> > 0x0f
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00
> > > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x1 status=0
> > > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0002 len=0
> > > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2 status=0
> > > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0003 len=0
> > > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x3 status=0
> > > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x04
> > > >> > > > ocf=0x0009 len=0
> > > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x4
> > > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x002d len=1
> > > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2d status=0
> > > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0029 len=0
> > > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x29 status=0
> > > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x002d len=1
> > > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2d status=0
> > > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated:
> > stop
> > > >> > > > advertising.
> > > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x000a len=1
> > > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0xa status=0
> > > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0027 len=39
> > > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00
> > 0x00
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
> > > >> 0xdd
> > > >> > > 0x34
> > > >> > > > 0xc0 0x53 0x1e 0xb8
> > > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x27 status=7
> > > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > >> > > > 000038 -ble_app_on_sync-
> > > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0018 len=0
> > > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0005 len=6
> > > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01
> > 0x02
> > > >> 0x03
> > > >> > > 0x04
> > > >> > > > 0x05
> > > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x5 status=0
> > > >> > > > 000044 addr:0x900019dd
> > > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0008 len=32
> > > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02
> > 0x01
> > > >> 0x06
> > > >> > > 0x1a
> > > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > > >> 0x11
> > > >> > > 0x11
> > > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x8 status=0
> > > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > > >> advertise;
> > > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1
> > adv_filter_policy=0
> > > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0006 len=15
> > > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
> > > >> 0x00
> > > >> > > 0x03
> > > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x6 status=0
> > > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x000a len=1
> > > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > >> > > > =================================================
> > > >> > > >
> > > >> > > > it stuck here, no more any message..
> > > >> > >
> > > >>
> > > >
> >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Jack,

I know what you mean.
I also tried swapping code1/code2 which probably broke some other
interrupt handling.

When I tested, first interrupt for PWM handled timer and removed it from queue,
in user provided timer handler timer was added again with time value
from the future.
Second (unwanted interrupt) checked conditions again but did not
removed future timer handlers.

I tested with different timer settings though (f=32150, timer value
much higher then 0x6A,
that seems to be value that you have).

I will check some more...
If you come up with something don't hesitate to let me know.

br
Jerzy

wt., 16 mar 2021 o 13:29 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> Hi, Jeray,
>
> thank you for your help.
> The "repeatly pwm interrupt" is gone.
>
> But I encounter another problem.
>
> when pwm interrupt happen, this func ( external_interrupt_handler ) will be
> called.
> I check the PLIC document, it said that  gateway will be re-enabled after
> code1 execute.
> At this moment, pwm IP is still set, because pwm IP is cleared at code2.
> so code3 will read pwm interrupt ID again .
>
> for 1 pwm timeout event, it will do 2 times pwm interrupt-handler.
> this cause problems that eventually all timers are removed.
>
> I try swap code1 <--> code2, but has some other side-effect and doesnt work.
>
>
> Jack
> in plic.c
>
> void
> external_interrupt_handler(uintptr_t mcause)
> {
>     int num = PLIC_REG(PLIC_CLAIM_OFFSET);
>     /*
>      * Interrupts have some overhead, handle all pending interrupts.
>      */
>     while (num) {
>         /* Confirm interrupt*/
>         PLIC_REG(PLIC_CLAIM_OFFSET) = num;  --->code1
>         /* Call interrupt handler */
>         plic_interrupts[num](num);          ---->code2
>         /* Check if other interupt is already pending */
>         num = PLIC_REG(PLIC_CLAIM_OFFSET);   ----> code3
>     }
> }
>
>
> Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月16日 週二 上午12:48寫道:
>
> > Hi Jack
> >
> > Place that you found had wrong condition that resulted in stack in low
> > frequencies.
> >
> > There is pending pull request that should fix your problem
> > https://github.com/apache/mynewt-core/pull/2530
> >
> > Could you verify that this fixes you issue?
> >
> > br
> > Jerzy
> >
> > pon., 15 mar 2021 o 11:44 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >
> > > Hi, Jerzy,
> > >
> > > my program first call hal_timer_config( freq_hz=32768 )
> > > pwm2 reg setting after call hal_timer_config() : PWM2_CMP0=0xffff,
> > > PWM2_CMP1=0xffff, PWM_CFG=0x1209
> > >
> > > and some time after,
> > > the problem happen at calling hal_timer_start_at(ticks) function which
> > > parameter ticks is < 0xffff  but > PWM_S
> > > in my case ticks = PWM_S+0x6a
> > >
> > > and inside hal_timer_start_at function it will call
> > fe310_tmr_check_first(),
> > > -----------------------------------------------
> > >
> > > static void
> > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > {
> > >     struct hal_timer *ht;
> > >
> > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > >     if (ht) {
> > >         uint32_t cnt = hal_timer_cnt(tmr);
> > >         int32_t ticks = (int32_t)(ht->expiry - cnt);  ---> 0x6a
> > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {  ---> 0x6a <
> > 0xffff
> > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;    ---> pwm_cmp1
> > > is assigned 0x6a, and now pwm_s > 0x6a
> > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);  --->enable
> > > pwm_cmp1 interrupt
> > >             return;
> > >         }
> > >     }
> > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
> > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> > > all the time */
> > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > }
> > >
> > > then interrupt forever..
> > >
> > >
> > >
> > > Jack
> > >
> > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午5:23寫道:
> > >
> > > > Hi Jack,
> > > >
> > > > I setup blinky-like project with default settings that hifive1 bsp set
> > > > with one
> > > > modification:
> > > >
> > > > SYS_CLOCK: HFXOSC_16_MHZ
> > > >
> > > > I also added two cpu timers like this:
> > > >
> > > > os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> > > > os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
> > > >
> > > > os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> > > > os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
> > > >
> > > > Code is using cpu timer that is using PWM2 that should be similar to
> > > > what you have.
> > > > My timer callbacks just toggle some GPIO to verify that frequencies are
> > > > correct.
> > > > So far everything works as expected.
> > > >
> > > > 1. Maybe you could share timer/clock related content of your syscfg.
> > > > 2. Maybe timer usage is different then mine (hal_timer api instead of
> > > > cpu_timer that I used for quick check)
> > > >
> > > > br
> > > > Jerzy
> > > >
> > > > pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > > >
> > > > > 3. frequency on PWM timer: 32768
> > > > >
> > > > > Jack
> > > > >
> > > > > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > 1. system clock frequency:16MHz
> > > > > > 2. which PWM: PWM2
> > > > > > 3. frequency on PWM timer: 32758
> > > > > >
> > > > > > Jack
> > > > > >
> > > > > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一
> > > > 下午3:33寫道:
> > > > > >
> > > > > >> Hi,
> > > > > >>
> > > > > >> I don't remember details to answer number 3 out of my head. But we
> > > > > >> will find out soon.
> > > > > >> In the meanwhile can you give me:
> > > > > >> 1. system clock frequency that you have selected
> > > > > >> 2. which PWM is causing problem.
> > > > > >> 3. what is frequency on PWM timer.
> > > > > >> Those will help me setup environment closer to what you have.
> > > > > >>
> > > > > >> br
> > > > > >> Jerzy
> > > > > >>
> > > > > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com>
> > napisał(a):
> > > > > >> >
> > > > > >> > Hi,
> > > > > >> >
> > > > > >> > 1. Do you know if tick is negative at line that you marked
> > > > > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question
> > code
> > > > > >> >
> > > > > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff,
> > > > PEM_CFG=0xc0001209,
> > > > > >> ticks
> > > > > >> > =0x6a
> > > > > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm
> > interrupt
> > > > > >> > (fe310_pwm_cmp1_handler)
> > > > > >> >  and the handler call fe310_tmr_check_first again, then
> > trigger  pwm
> > > > > >> > interrupt, and so on..
> > > > > >> >
> > > > > >> > 2. I am sorry I can not share project with you, it is company
> > > > project.
> > > > > >> >     I can provide program running info
> > > > > >> >
> > > > > >> > 3. I have a question about hal_timer_cnt function .
> > > > > >> > how does the code check overflow condition?
> > > > > >> >
> > > > > >> > Thanks for your help.
> > > > > >> >
> > > > > >> > --------------------------------------------------
> > > > > >> > static uint32_t
> > > > > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > > > > >> > {
> > > > > >> >     uint32_t cnt;
> > > > > >> >     int sr;
> > > > > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > > > > >> >
> > > > > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > > > > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > > > > >> >     /* Check if just overflowed */
> > > > > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > > > > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > > > > >> >     }
> > > > > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > > > > >> >
> > > > > >> >     return cnt;
> > > > > >> > }
> > > > > >> > -----------------------------------------------------
> > > > > >> >
> > > > > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > > > > >> 下午11:35寫道:
> > > > > >> >
> > > > > >> > > Hi,
> > > > > >> > >
> > > > > >> > > 1. Do you know if tick is negative at line that you marked
> > > > > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question
> > code
> > > > > >> > >
> > > > > >> > > 2. Can you share your project with me somehow so I could take
> > a
> > > > look
> > > > > >> > > (presuming it is running on hifive1 board)?
> > > > > >> > >
> > > > > >> > > I can take a look at this next Monday.
> > > > > >> > >
> > > > > >> > > best regards
> > > > > >> > > Jerzy
> > > > > >> > >
> > > > > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com>
> > napisał(a):
> > > > > >> > > >
> > > > > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > > > > >> > > > I modify the bsp from nordic to my board and change mcu to
> > > > sifive.
> > > > > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > > > >> > > > modify it to simulate radio hardware. for now it just for
> > not
> > > > stuck
> > > > > >> code
> > > > > >> > > > running.
> > > > > >> > > >
> > > > > >> > > > I load code and run , I got some ble log messages below.
> > > > > >> > > >
> > > > > >> > > > after checking code, I found
> > > > > >> > > > inside hal_timer_start_at() function, it call
> > > > fe310_tmr_check_first
> > > > > >> and
> > > > > >> > > > it seems not operate correctly.
> > > > > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > > > > >> > > >
> > > > > >> > > > is there anyone help ? or I missing something?
> > > > > >> > > >
> > > > > >> > > >
> > > > > >>
> > > > -----------------------------------------------------------------------
> > > > > >> > > > static void
> > > > > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > > > >> > > > {
> > > > > >> > > >     struct hal_timer *ht;
> > > > > >> > > >
> > > > > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > > > > >> > > >     if (ht) {
> > > > > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > > > > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > > > > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > > > > >> <====question code
> > > > > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > > > > >>  <====question code
> > > > > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > > > > >> > > <====question
> > > > > >> > > > code
> > > > > >> > > >             return;
> > > > > >> > > >         }
> > > > > >> > > >     }
> > > > > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > > > > >> PWM_CMP0);
> > > > > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which
> > is
> > > > used
> > > > > >> all
> > > > > >> > > the
> > > > > >> > > > time */
> > > > > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > > > >> > > > }
> > > > > >> > > >
> > > > > >> > >
> > > > > >>
> > > >
> > ------------------------------------------------------------------------------
> > > > > >> > > >
> > > > > >> > > >
> > > > > >> > > > =================================================
> > > > > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1
> > > > ogf=0x0
> > > > > >> > > ocf=0x0
> > > > > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x03
> > > > > >> > > ocf=0x0003
> > > > > >> > > > len=0
> > > > > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > > > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x3
> > > > > >> > > > ocf=0x3 status=0
> > > > > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x04
> > > > > >> > > ocf=0x0001
> > > > > >> > > > len=0
> > > > > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > > > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x4
> > > > > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > > > > >> lmp_subver=0
> > > > > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x03
> > > > > >> > > ocf=0x0001
> > > > > >> > > > len=8
> > > > > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80
> > 0x00
> > > > > >> 0x02
> > > > > >> > > 0x00
> > > > > >> > > > 0x80 0x00 0x20
> > > > > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x3
> > > > > >> > > > ocf=0x1 status=0
> > > > > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x03
> > > > > >> > > ocf=0x0063
> > > > > >> > > > len=8
> > > > > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00
> > 0x80
> > > > > >> 0x00
> > > > > >> > > 0x00
> > > > > >> > > > 0x00 0x00 0x00
> > > > > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x3
> > > > > >> > > > ocf=0x63 status=0
> > > > > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > > > >> > > ocf=0x0001
> > > > > >> > > > len=8
> > > > > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe
> > > > 0x0f
> > > > > >> 0x00
> > > > > >> > > 0x00
> > > > > >> > > > 0x00 0x00 0x00
> > > > > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x1 status=0
> > > > > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0002 len=0
> > > > > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > > > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x2 status=0
> > > > > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0003 len=0
> > > > > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > > > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x3 status=0
> > > > > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x04
> > > > > >> > > > ocf=0x0009 len=0
> > > > > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > > > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x4
> > > > > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > > > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x002d len=1
> > > > > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > > > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x2d status=0
> > > > > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0029 len=0
> > > > > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > > > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x29 status=0
> > > > > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x002d len=1
> > > > > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > > > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x2d status=0
> > > > > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated:
> > > > stop
> > > > > >> > > > advertising.
> > > > > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x000a len=1
> > > > > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > > > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0xa status=0
> > > > > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0027 len=39
> > > > > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00
> > > > 0x00
> > > > > >> 0x00
> > > > > >> > > 0x00
> > > > > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > 0x00
> > > > > >> 0x00
> > > > > >> > > 0x00
> > > > > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf
> > 0x5b
> > > > > >> 0xdd
> > > > > >> > > 0x34
> > > > > >> > > > 0xc0 0x53 0x1e 0xb8
> > > > > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x27 status=7
> > > > > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > > > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > > > >> > > > 000038 -ble_app_on_sync-
> > > > > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0018 len=0
> > > > > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > > > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > > > > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0005 len=6
> > > > > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01
> > > > 0x02
> > > > > >> 0x03
> > > > > >> > > 0x04
> > > > > >> > > > 0x05
> > > > > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x5 status=0
> > > > > >> > > > 000044 addr:0x900019dd
> > > > > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0008 len=32
> > > > > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02
> > > > 0x01
> > > > > >> 0x06
> > > > > >> > > 0x1a
> > > > > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > 0x11
> > > > > >> 0x11
> > > > > >> > > 0x11
> > > > > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > > > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x8 status=0
> > > > > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > > > > >> advertise;
> > > > > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1
> > > > adv_filter_policy=0
> > > > > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > > > > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x0006 len=15
> > > > > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00
> > 0xf0
> > > > > >> 0x00
> > > > > >> > > 0x03
> > > > > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > > > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete:
> > cmd_pkts=1
> > > > > >> ogf=0x8
> > > > > >> > > > ocf=0x6 status=0
> > > > > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > > ogf=0x08
> > > > > >> > > > ocf=0x000a len=1
> > > > > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > > > >> > > > =================================================
> > > > > >> > > >
> > > > > >> > > > it stuck here, no more any message..
> > > > > >> > >
> > > > > >>
> > > > > >
> > > >
> >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by 范姜徐霖 <ja...@gmail.com>.
Hi, Jeray,

thank you for your help.
The "repeatly pwm interrupt" is gone.

But I encounter another problem.

when pwm interrupt happen, this func ( external_interrupt_handler ) will be
called.
I check the PLIC document, it said that  gateway will be re-enabled after
code1 execute.
At this moment, pwm IP is still set, because pwm IP is cleared at code2.
so code3 will read pwm interrupt ID again .

for 1 pwm timeout event, it will do 2 times pwm interrupt-handler.
this cause problems that eventually all timers are removed.

I try swap code1 <--> code2, but has some other side-effect and doesnt work.


Jack
in plic.c

void
external_interrupt_handler(uintptr_t mcause)
{
    int num = PLIC_REG(PLIC_CLAIM_OFFSET);
    /*
     * Interrupts have some overhead, handle all pending interrupts.
     */
    while (num) {
        /* Confirm interrupt*/
        PLIC_REG(PLIC_CLAIM_OFFSET) = num;  --->code1
        /* Call interrupt handler */
        plic_interrupts[num](num);          ---->code2
        /* Check if other interupt is already pending */
        num = PLIC_REG(PLIC_CLAIM_OFFSET);   ----> code3
    }
}


Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月16日 週二 上午12:48寫道:

> Hi Jack
>
> Place that you found had wrong condition that resulted in stack in low
> frequencies.
>
> There is pending pull request that should fix your problem
> https://github.com/apache/mynewt-core/pull/2530
>
> Could you verify that this fixes you issue?
>
> br
> Jerzy
>
> pon., 15 mar 2021 o 11:44 范姜徐霖 <ja...@gmail.com> napisał(a):
> >
> > Hi, Jerzy,
> >
> > my program first call hal_timer_config( freq_hz=32768 )
> > pwm2 reg setting after call hal_timer_config() : PWM2_CMP0=0xffff,
> > PWM2_CMP1=0xffff, PWM_CFG=0x1209
> >
> > and some time after,
> > the problem happen at calling hal_timer_start_at(ticks) function which
> > parameter ticks is < 0xffff  but > PWM_S
> > in my case ticks = PWM_S+0x6a
> >
> > and inside hal_timer_start_at function it will call
> fe310_tmr_check_first(),
> > -----------------------------------------------
> >
> > static void
> > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > {
> >     struct hal_timer *ht;
> >
> >     ht = TAILQ_FIRST(&tmr->sht_timers);
> >     if (ht) {
> >         uint32_t cnt = hal_timer_cnt(tmr);
> >         int32_t ticks = (int32_t)(ht->expiry - cnt);  ---> 0x6a
> >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {  ---> 0x6a <
> 0xffff
> >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;    ---> pwm_cmp1
> > is assigned 0x6a, and now pwm_s > 0x6a
> >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);  --->enable
> > pwm_cmp1 interrupt
> >             return;
> >         }
> >     }
> >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
> >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> > all the time */
> >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > }
> >
> > then interrupt forever..
> >
> >
> >
> > Jack
> >
> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午5:23寫道:
> >
> > > Hi Jack,
> > >
> > > I setup blinky-like project with default settings that hifive1 bsp set
> > > with one
> > > modification:
> > >
> > > SYS_CLOCK: HFXOSC_16_MHZ
> > >
> > > I also added two cpu timers like this:
> > >
> > > os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> > > os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
> > >
> > > os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> > > os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
> > >
> > > Code is using cpu timer that is using PWM2 that should be similar to
> > > what you have.
> > > My timer callbacks just toggle some GPIO to verify that frequencies are
> > > correct.
> > > So far everything works as expected.
> > >
> > > 1. Maybe you could share timer/clock related content of your syscfg.
> > > 2. Maybe timer usage is different then mine (hal_timer api instead of
> > > cpu_timer that I used for quick check)
> > >
> > > br
> > > Jerzy
> > >
> > > pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >
> > > > 3. frequency on PWM timer: 32768
> > > >
> > > > Jack
> > > >
> > > > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> > > >
> > > > > Hi,
> > > > >
> > > > > 1. system clock frequency:16MHz
> > > > > 2. which PWM: PWM2
> > > > > 3. frequency on PWM timer: 32758
> > > > >
> > > > > Jack
> > > > >
> > > > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一
> > > 下午3:33寫道:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> I don't remember details to answer number 3 out of my head. But we
> > > > >> will find out soon.
> > > > >> In the meanwhile can you give me:
> > > > >> 1. system clock frequency that you have selected
> > > > >> 2. which PWM is causing problem.
> > > > >> 3. what is frequency on PWM timer.
> > > > >> Those will help me setup environment closer to what you have.
> > > > >>
> > > > >> br
> > > > >> Jerzy
> > > > >>
> > > > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com>
> napisał(a):
> > > > >> >
> > > > >> > Hi,
> > > > >> >
> > > > >> > 1. Do you know if tick is negative at line that you marked
> > > > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question
> code
> > > > >> >
> > > > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff,
> > > PEM_CFG=0xc0001209,
> > > > >> ticks
> > > > >> > =0x6a
> > > > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm
> interrupt
> > > > >> > (fe310_pwm_cmp1_handler)
> > > > >> >  and the handler call fe310_tmr_check_first again, then
> trigger  pwm
> > > > >> > interrupt, and so on..
> > > > >> >
> > > > >> > 2. I am sorry I can not share project with you, it is company
> > > project.
> > > > >> >     I can provide program running info
> > > > >> >
> > > > >> > 3. I have a question about hal_timer_cnt function .
> > > > >> > how does the code check overflow condition?
> > > > >> >
> > > > >> > Thanks for your help.
> > > > >> >
> > > > >> > --------------------------------------------------
> > > > >> > static uint32_t
> > > > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > > > >> > {
> > > > >> >     uint32_t cnt;
> > > > >> >     int sr;
> > > > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > > > >> >
> > > > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > > > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > > > >> >     /* Check if just overflowed */
> > > > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > > > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > > > >> >     }
> > > > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > > > >> >
> > > > >> >     return cnt;
> > > > >> > }
> > > > >> > -----------------------------------------------------
> > > > >> >
> > > > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > > > >> 下午11:35寫道:
> > > > >> >
> > > > >> > > Hi,
> > > > >> > >
> > > > >> > > 1. Do you know if tick is negative at line that you marked
> > > > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question
> code
> > > > >> > >
> > > > >> > > 2. Can you share your project with me somehow so I could take
> a
> > > look
> > > > >> > > (presuming it is running on hifive1 board)?
> > > > >> > >
> > > > >> > > I can take a look at this next Monday.
> > > > >> > >
> > > > >> > > best regards
> > > > >> > > Jerzy
> > > > >> > >
> > > > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com>
> napisał(a):
> > > > >> > > >
> > > > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > > > >> > > > I modify the bsp from nordic to my board and change mcu to
> > > sifive.
> > > > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > > >> > > > modify it to simulate radio hardware. for now it just for
> not
> > > stuck
> > > > >> code
> > > > >> > > > running.
> > > > >> > > >
> > > > >> > > > I load code and run , I got some ble log messages below.
> > > > >> > > >
> > > > >> > > > after checking code, I found
> > > > >> > > > inside hal_timer_start_at() function, it call
> > > fe310_tmr_check_first
> > > > >> and
> > > > >> > > > it seems not operate correctly.
> > > > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > > > >> > > >
> > > > >> > > > is there anyone help ? or I missing something?
> > > > >> > > >
> > > > >> > > >
> > > > >>
> > > -----------------------------------------------------------------------
> > > > >> > > > static void
> > > > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > > >> > > > {
> > > > >> > > >     struct hal_timer *ht;
> > > > >> > > >
> > > > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > > > >> > > >     if (ht) {
> > > > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > > > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > > > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > > > >> <====question code
> > > > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > > > >>  <====question code
> > > > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > > > >> > > <====question
> > > > >> > > > code
> > > > >> > > >             return;
> > > > >> > > >         }
> > > > >> > > >     }
> > > > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > > > >> PWM_CMP0);
> > > > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which
> is
> > > used
> > > > >> all
> > > > >> > > the
> > > > >> > > > time */
> > > > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > > >> > > > }
> > > > >> > > >
> > > > >> > >
> > > > >>
> > >
> ------------------------------------------------------------------------------
> > > > >> > > >
> > > > >> > > >
> > > > >> > > > =================================================
> > > > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1
> > > ogf=0x0
> > > > >> > > ocf=0x0
> > > > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x03
> > > > >> > > ocf=0x0003
> > > > >> > > > len=0
> > > > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x3
> > > > >> > > > ocf=0x3 status=0
> > > > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x04
> > > > >> > > ocf=0x0001
> > > > >> > > > len=0
> > > > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x4
> > > > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > > > >> lmp_subver=0
> > > > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x03
> > > > >> > > ocf=0x0001
> > > > >> > > > len=8
> > > > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80
> 0x00
> > > > >> 0x02
> > > > >> > > 0x00
> > > > >> > > > 0x80 0x00 0x20
> > > > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x3
> > > > >> > > > ocf=0x1 status=0
> > > > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x03
> > > > >> > > ocf=0x0063
> > > > >> > > > len=8
> > > > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00
> 0x80
> > > > >> 0x00
> > > > >> > > 0x00
> > > > >> > > > 0x00 0x00 0x00
> > > > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x3
> > > > >> > > > ocf=0x63 status=0
> > > > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > > > >> > > ocf=0x0001
> > > > >> > > > len=8
> > > > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe
> > > 0x0f
> > > > >> 0x00
> > > > >> > > 0x00
> > > > >> > > > 0x00 0x00 0x00
> > > > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x1 status=0
> > > > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0002 len=0
> > > > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x2 status=0
> > > > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0003 len=0
> > > > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x3 status=0
> > > > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x04
> > > > >> > > > ocf=0x0009 len=0
> > > > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x4
> > > > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x002d len=1
> > > > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x2d status=0
> > > > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0029 len=0
> > > > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x29 status=0
> > > > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x002d len=1
> > > > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x2d status=0
> > > > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated:
> > > stop
> > > > >> > > > advertising.
> > > > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x000a len=1
> > > > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0xa status=0
> > > > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0027 len=39
> > > > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00
> > > 0x00
> > > > >> 0x00
> > > > >> > > 0x00
> > > > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> 0x00
> > > > >> 0x00
> > > > >> > > 0x00
> > > > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf
> 0x5b
> > > > >> 0xdd
> > > > >> > > 0x34
> > > > >> > > > 0xc0 0x53 0x1e 0xb8
> > > > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x27 status=7
> > > > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > > >> > > > 000038 -ble_app_on_sync-
> > > > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0018 len=0
> > > > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > > > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0005 len=6
> > > > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01
> > > 0x02
> > > > >> 0x03
> > > > >> > > 0x04
> > > > >> > > > 0x05
> > > > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x5 status=0
> > > > >> > > > 000044 addr:0x900019dd
> > > > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0008 len=32
> > > > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02
> > > 0x01
> > > > >> 0x06
> > > > >> > > 0x1a
> > > > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> 0x11
> > > > >> 0x11
> > > > >> > > 0x11
> > > > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x8 status=0
> > > > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > > > >> advertise;
> > > > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1
> > > adv_filter_policy=0
> > > > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > > > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x0006 len=15
> > > > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00
> 0xf0
> > > > >> 0x00
> > > > >> > > 0x03
> > > > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete:
> cmd_pkts=1
> > > > >> ogf=0x8
> > > > >> > > > ocf=0x6 status=0
> > > > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send:
> > > ogf=0x08
> > > > >> > > > ocf=0x000a len=1
> > > > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > > >> > > > =================================================
> > > > >> > > >
> > > > >> > > > it stuck here, no more any message..
> > > > >> > >
> > > > >>
> > > > >
> > >
>

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Jack

Place that you found had wrong condition that resulted in stack in low
frequencies.

There is pending pull request that should fix your problem
https://github.com/apache/mynewt-core/pull/2530

Could you verify that this fixes you issue?

br
Jerzy

pon., 15 mar 2021 o 11:44 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> Hi, Jerzy,
>
> my program first call hal_timer_config( freq_hz=32768 )
> pwm2 reg setting after call hal_timer_config() : PWM2_CMP0=0xffff,
> PWM2_CMP1=0xffff, PWM_CFG=0x1209
>
> and some time after,
> the problem happen at calling hal_timer_start_at(ticks) function which
> parameter ticks is < 0xffff  but > PWM_S
> in my case ticks = PWM_S+0x6a
>
> and inside hal_timer_start_at function it will call fe310_tmr_check_first(),
> -----------------------------------------------
>
> static void
> fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> {
>     struct hal_timer *ht;
>
>     ht = TAILQ_FIRST(&tmr->sht_timers);
>     if (ht) {
>         uint32_t cnt = hal_timer_cnt(tmr);
>         int32_t ticks = (int32_t)(ht->expiry - cnt);  ---> 0x6a
>         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {  ---> 0x6a < 0xffff
>             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;    ---> pwm_cmp1
> is assigned 0x6a, and now pwm_s > 0x6a
>             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);  --->enable
> pwm_cmp1 interrupt
>             return;
>         }
>     }
>     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
>      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> all the time */
>     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> }
>
> then interrupt forever..
>
>
>
> Jack
>
> Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午5:23寫道:
>
> > Hi Jack,
> >
> > I setup blinky-like project with default settings that hifive1 bsp set
> > with one
> > modification:
> >
> > SYS_CLOCK: HFXOSC_16_MHZ
> >
> > I also added two cpu timers like this:
> >
> > os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> > os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
> >
> > os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> > os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
> >
> > Code is using cpu timer that is using PWM2 that should be similar to
> > what you have.
> > My timer callbacks just toggle some GPIO to verify that frequencies are
> > correct.
> > So far everything works as expected.
> >
> > 1. Maybe you could share timer/clock related content of your syscfg.
> > 2. Maybe timer usage is different then mine (hal_timer api instead of
> > cpu_timer that I used for quick check)
> >
> > br
> > Jerzy
> >
> > pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >
> > > 3. frequency on PWM timer: 32768
> > >
> > > Jack
> > >
> > > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> > >
> > > > Hi,
> > > >
> > > > 1. system clock frequency:16MHz
> > > > 2. which PWM: PWM2
> > > > 3. frequency on PWM timer: 32758
> > > >
> > > > Jack
> > > >
> > > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一
> > 下午3:33寫道:
> > > >
> > > >> Hi,
> > > >>
> > > >> I don't remember details to answer number 3 out of my head. But we
> > > >> will find out soon.
> > > >> In the meanwhile can you give me:
> > > >> 1. system clock frequency that you have selected
> > > >> 2. which PWM is causing problem.
> > > >> 3. what is frequency on PWM timer.
> > > >> Those will help me setup environment closer to what you have.
> > > >>
> > > >> br
> > > >> Jerzy
> > > >>
> > > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >> >
> > > >> > Hi,
> > > >> >
> > > >> > 1. Do you know if tick is negative at line that you marked
> > > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > > >> >
> > > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff,
> > PEM_CFG=0xc0001209,
> > > >> ticks
> > > >> > =0x6a
> > > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> > > >> > (fe310_pwm_cmp1_handler)
> > > >> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> > > >> > interrupt, and so on..
> > > >> >
> > > >> > 2. I am sorry I can not share project with you, it is company
> > project.
> > > >> >     I can provide program running info
> > > >> >
> > > >> > 3. I have a question about hal_timer_cnt function .
> > > >> > how does the code check overflow condition?
> > > >> >
> > > >> > Thanks for your help.
> > > >> >
> > > >> > --------------------------------------------------
> > > >> > static uint32_t
> > > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > > >> > {
> > > >> >     uint32_t cnt;
> > > >> >     int sr;
> > > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > > >> >
> > > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > > >> >     /* Check if just overflowed */
> > > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > > >> >     }
> > > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > > >> >
> > > >> >     return cnt;
> > > >> > }
> > > >> > -----------------------------------------------------
> > > >> >
> > > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > > >> 下午11:35寫道:
> > > >> >
> > > >> > > Hi,
> > > >> > >
> > > >> > > 1. Do you know if tick is negative at line that you marked
> > > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > > >> > >
> > > >> > > 2. Can you share your project with me somehow so I could take a
> > look
> > > >> > > (presuming it is running on hifive1 board)?
> > > >> > >
> > > >> > > I can take a look at this next Monday.
> > > >> > >
> > > >> > > best regards
> > > >> > > Jerzy
> > > >> > >
> > > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >> > > >
> > > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > > >> > > > I modify the bsp from nordic to my board and change mcu to
> > sifive.
> > > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > >> > > > modify it to simulate radio hardware. for now it just for not
> > stuck
> > > >> code
> > > >> > > > running.
> > > >> > > >
> > > >> > > > I load code and run , I got some ble log messages below.
> > > >> > > >
> > > >> > > > after checking code, I found
> > > >> > > > inside hal_timer_start_at() function, it call
> > fe310_tmr_check_first
> > > >> and
> > > >> > > > it seems not operate correctly.
> > > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > > >> > > >
> > > >> > > > is there anyone help ? or I missing something?
> > > >> > > >
> > > >> > > >
> > > >>
> > -----------------------------------------------------------------------
> > > >> > > > static void
> > > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > >> > > > {
> > > >> > > >     struct hal_timer *ht;
> > > >> > > >
> > > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > > >> > > >     if (ht) {
> > > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > > >> <====question code
> > > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > > >>  <====question code
> > > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > > >> > > <====question
> > > >> > > > code
> > > >> > > >             return;
> > > >> > > >         }
> > > >> > > >     }
> > > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > > >> PWM_CMP0);
> > > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is
> > used
> > > >> all
> > > >> > > the
> > > >> > > > time */
> > > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > >> > > > }
> > > >> > > >
> > > >> > >
> > > >>
> > ------------------------------------------------------------------------------
> > > >> > > >
> > > >> > > >
> > > >> > > > =================================================
> > > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1
> > ogf=0x0
> > > >> > > ocf=0x0
> > > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0003
> > > >> > > > len=0
> > > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x3 status=0
> > > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > > >> > > ocf=0x0001
> > > >> > > > len=0
> > > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x4
> > > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > > >> lmp_subver=0
> > > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0001
> > > >> > > > len=8
> > > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
> > > >> 0x02
> > > >> > > 0x00
> > > >> > > > 0x80 0x00 0x20
> > > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x1 status=0
> > > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > >> > > ocf=0x0063
> > > >> > > > len=8
> > > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00
> > > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x3
> > > >> > > > ocf=0x63 status=0
> > > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > >> > > ocf=0x0001
> > > >> > > > len=8
> > > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe
> > 0x0f
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00
> > > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x1 status=0
> > > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0002 len=0
> > > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2 status=0
> > > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0003 len=0
> > > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x3 status=0
> > > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x04
> > > >> > > > ocf=0x0009 len=0
> > > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x4
> > > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x002d len=1
> > > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2d status=0
> > > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0029 len=0
> > > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x29 status=0
> > > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x002d len=1
> > > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x2d status=0
> > > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated:
> > stop
> > > >> > > > advertising.
> > > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x000a len=1
> > > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0xa status=0
> > > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0027 len=39
> > > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00
> > 0x00
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > > >> 0x00
> > > >> > > 0x00
> > > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
> > > >> 0xdd
> > > >> > > 0x34
> > > >> > > > 0xc0 0x53 0x1e 0xb8
> > > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x27 status=7
> > > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > >> > > > 000038 -ble_app_on_sync-
> > > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0018 len=0
> > > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0005 len=6
> > > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01
> > 0x02
> > > >> 0x03
> > > >> > > 0x04
> > > >> > > > 0x05
> > > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x5 status=0
> > > >> > > > 000044 addr:0x900019dd
> > > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0008 len=32
> > > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02
> > 0x01
> > > >> 0x06
> > > >> > > 0x1a
> > > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > > >> 0x11
> > > >> > > 0x11
> > > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x8 status=0
> > > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > > >> advertise;
> > > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1
> > adv_filter_policy=0
> > > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x0006 len=15
> > > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
> > > >> 0x00
> > > >> > > 0x03
> > > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> > > >> ogf=0x8
> > > >> > > > ocf=0x6 status=0
> > > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send:
> > ogf=0x08
> > > >> > > > ocf=0x000a len=1
> > > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > >> > > > =================================================
> > > >> > > >
> > > >> > > > it stuck here, no more any message..
> > > >> > >
> > > >>
> > > >
> >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by 范姜徐霖 <ja...@gmail.com>.
Hi, Jerzy,

my program first call hal_timer_config( freq_hz=32768 )
pwm2 reg setting after call hal_timer_config() : PWM2_CMP0=0xffff,
PWM2_CMP1=0xffff, PWM_CFG=0x1209

and some time after,
the problem happen at calling hal_timer_start_at(ticks) function which
parameter ticks is < 0xffff  but > PWM_S
in my case ticks = PWM_S+0x6a

and inside hal_timer_start_at function it will call fe310_tmr_check_first(),
-----------------------------------------------

static void
fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
{
    struct hal_timer *ht;

    ht = TAILQ_FIRST(&tmr->sht_timers);
    if (ht) {
        uint32_t cnt = hal_timer_cnt(tmr);
        int32_t ticks = (int32_t)(ht->expiry - cnt);  ---> 0x6a
        if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {  ---> 0x6a < 0xffff
            _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;    ---> pwm_cmp1
is assigned 0x6a, and now pwm_s > 0x6a
            plic_enable_interrupt(tmr->pwmxcmp0_int + 1);  --->enable
pwm_cmp1 interrupt
            return;
        }
    }
    _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
     /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
all the time */
    plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
}

then interrupt forever..



Jack

Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午5:23寫道:

> Hi Jack,
>
> I setup blinky-like project with default settings that hifive1 bsp set
> with one
> modification:
>
> SYS_CLOCK: HFXOSC_16_MHZ
>
> I also added two cpu timers like this:
>
> os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
>
> os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
>
> Code is using cpu timer that is using PWM2 that should be similar to
> what you have.
> My timer callbacks just toggle some GPIO to verify that frequencies are
> correct.
> So far everything works as expected.
>
> 1. Maybe you could share timer/clock related content of your syscfg.
> 2. Maybe timer usage is different then mine (hal_timer api instead of
> cpu_timer that I used for quick check)
>
> br
> Jerzy
>
> pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> >
> > 3. frequency on PWM timer: 32768
> >
> > Jack
> >
> > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> >
> > > Hi,
> > >
> > > 1. system clock frequency:16MHz
> > > 2. which PWM: PWM2
> > > 3. frequency on PWM timer: 32758
> > >
> > > Jack
> > >
> > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一
> 下午3:33寫道:
> > >
> > >> Hi,
> > >>
> > >> I don't remember details to answer number 3 out of my head. But we
> > >> will find out soon.
> > >> In the meanwhile can you give me:
> > >> 1. system clock frequency that you have selected
> > >> 2. which PWM is causing problem.
> > >> 3. what is frequency on PWM timer.
> > >> Those will help me setup environment closer to what you have.
> > >>
> > >> br
> > >> Jerzy
> > >>
> > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >> >
> > >> > Hi,
> > >> >
> > >> > 1. Do you know if tick is negative at line that you marked
> > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >> >
> > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff,
> PEM_CFG=0xc0001209,
> > >> ticks
> > >> > =0x6a
> > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> > >> > (fe310_pwm_cmp1_handler)
> > >> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> > >> > interrupt, and so on..
> > >> >
> > >> > 2. I am sorry I can not share project with you, it is company
> project.
> > >> >     I can provide program running info
> > >> >
> > >> > 3. I have a question about hal_timer_cnt function .
> > >> > how does the code check overflow condition?
> > >> >
> > >> > Thanks for your help.
> > >> >
> > >> > --------------------------------------------------
> > >> > static uint32_t
> > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > >> > {
> > >> >     uint32_t cnt;
> > >> >     int sr;
> > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > >> >
> > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > >> >     /* Check if just overflowed */
> > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > >> >     }
> > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > >> >
> > >> >     return cnt;
> > >> > }
> > >> > -----------------------------------------------------
> > >> >
> > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > >> 下午11:35寫道:
> > >> >
> > >> > > Hi,
> > >> > >
> > >> > > 1. Do you know if tick is negative at line that you marked
> > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >> > >
> > >> > > 2. Can you share your project with me somehow so I could take a
> look
> > >> > > (presuming it is running on hifive1 board)?
> > >> > >
> > >> > > I can take a look at this next Monday.
> > >> > >
> > >> > > best regards
> > >> > > Jerzy
> > >> > >
> > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >> > > >
> > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > >> > > > I modify the bsp from nordic to my board and change mcu to
> sifive.
> > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > >> > > > modify it to simulate radio hardware. for now it just for not
> stuck
> > >> code
> > >> > > > running.
> > >> > > >
> > >> > > > I load code and run , I got some ble log messages below.
> > >> > > >
> > >> > > > after checking code, I found
> > >> > > > inside hal_timer_start_at() function, it call
> fe310_tmr_check_first
> > >> and
> > >> > > > it seems not operate correctly.
> > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > >> > > >
> > >> > > > is there anyone help ? or I missing something?
> > >> > > >
> > >> > > >
> > >>
> -----------------------------------------------------------------------
> > >> > > > static void
> > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > >> > > > {
> > >> > > >     struct hal_timer *ht;
> > >> > > >
> > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > >> > > >     if (ht) {
> > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > >> <====question code
> > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > >>  <====question code
> > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > >> > > <====question
> > >> > > > code
> > >> > > >             return;
> > >> > > >         }
> > >> > > >     }
> > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > >> PWM_CMP0);
> > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is
> used
> > >> all
> > >> > > the
> > >> > > > time */
> > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > >> > > > }
> > >> > > >
> > >> > >
> > >>
> ------------------------------------------------------------------------------
> > >> > > >
> > >> > > >
> > >> > > > =================================================
> > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x0
> > >> > > ocf=0x0
> > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0003
> > >> > > > len=0
> > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x3 status=0
> > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > >> > > ocf=0x0001
> > >> > > > len=0
> > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x4
> > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > >> lmp_subver=0
> > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0001
> > >> > > > len=8
> > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
> > >> 0x02
> > >> > > 0x00
> > >> > > > 0x80 0x00 0x20
> > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x1 status=0
> > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0063
> > >> > > > len=8
> > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00
> > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x63 status=0
> > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > ocf=0x0001
> > >> > > > len=8
> > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe
> 0x0f
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00
> > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x1 status=0
> > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0002 len=0
> > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2 status=0
> > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0003 len=0
> > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x3 status=0
> > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x04
> > >> > > > ocf=0x0009 len=0
> > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x4
> > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x002d len=1
> > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2d status=0
> > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0029 len=0
> > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x29 status=0
> > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x002d len=1
> > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2d status=0
> > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated:
> stop
> > >> > > > advertising.
> > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x000a len=1
> > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0xa status=0
> > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0027 len=39
> > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00
> 0x00
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
> > >> 0xdd
> > >> > > 0x34
> > >> > > > 0xc0 0x53 0x1e 0xb8
> > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x27 status=7
> > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > >> > > > 000038 -ble_app_on_sync-
> > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0018 len=0
> > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0005 len=6
> > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01
> 0x02
> > >> 0x03
> > >> > > 0x04
> > >> > > > 0x05
> > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x5 status=0
> > >> > > > 000044 addr:0x900019dd
> > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0008 len=32
> > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02
> 0x01
> > >> 0x06
> > >> > > 0x1a
> > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > >> 0x11
> > >> > > 0x11
> > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x8 status=0
> > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > >> advertise;
> > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1
> adv_filter_policy=0
> > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x0006 len=15
> > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
> > >> 0x00
> > >> > > 0x03
> > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x6 status=0
> > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send:
> ogf=0x08
> > >> > > > ocf=0x000a len=1
> > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > >> > > > =================================================
> > >> > > >
> > >> > > > it stuck here, no more any message..
> > >> > >
> > >>
> > >
>

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Jack,

I tested some more and did not found any problems.
What may be confusing is that when CPU is stopped in the debugger
timers continue to run so interrupts will be generated all the time,
then it may appear that code stuck in timer interrupt.
Same goes for watchdog.

1. Can you confirm that code stacks in timer interrupt handler without debugger
 (maybe some GPIO toggling)?

br
Jerzy

pon., 15 mar 2021 o 10:23 Jerzy Kasenberg
<je...@codecoup.pl> napisał(a):
>
> Hi Jack,
>
> I setup blinky-like project with default settings that hifive1 bsp set with one
> modification:
>
> SYS_CLOCK: HFXOSC_16_MHZ
>
> I also added two cpu timers like this:
>
> os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
> os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);
>
> os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
> os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);
>
> Code is using cpu timer that is using PWM2 that should be similar to
> what you have.
> My timer callbacks just toggle some GPIO to verify that frequencies are correct.
> So far everything works as expected.
>
> 1. Maybe you could share timer/clock related content of your syscfg.
> 2. Maybe timer usage is different then mine (hal_timer api instead of
> cpu_timer that I used for quick check)
>
> br
> Jerzy
>
> pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
> >
> > 3. frequency on PWM timer: 32768
> >
> > Jack
> >
> > 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
> >
> > > Hi,
> > >
> > > 1. system clock frequency:16MHz
> > > 2. which PWM: PWM2
> > > 3. frequency on PWM timer: 32758
> > >
> > > Jack
> > >
> > > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午3:33寫道:
> > >
> > >> Hi,
> > >>
> > >> I don't remember details to answer number 3 out of my head. But we
> > >> will find out soon.
> > >> In the meanwhile can you give me:
> > >> 1. system clock frequency that you have selected
> > >> 2. which PWM is causing problem.
> > >> 3. what is frequency on PWM timer.
> > >> Those will help me setup environment closer to what you have.
> > >>
> > >> br
> > >> Jerzy
> > >>
> > >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >> >
> > >> > Hi,
> > >> >
> > >> > 1. Do you know if tick is negative at line that you marked
> > >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >> >
> > >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209,
> > >> ticks
> > >> > =0x6a
> > >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> > >> > (fe310_pwm_cmp1_handler)
> > >> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> > >> > interrupt, and so on..
> > >> >
> > >> > 2. I am sorry I can not share project with you, it is company project.
> > >> >     I can provide program running info
> > >> >
> > >> > 3. I have a question about hal_timer_cnt function .
> > >> > how does the code check overflow condition?
> > >> >
> > >> > Thanks for your help.
> > >> >
> > >> > --------------------------------------------------
> > >> > static uint32_t
> > >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > >> > {
> > >> >     uint32_t cnt;
> > >> >     int sr;
> > >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> > >> >
> > >> >     __HAL_DISABLE_INTERRUPTS(sr);
> > >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> > >> >     /* Check if just overflowed */
> > >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> > >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> > >> >     }
> > >> >     __HAL_ENABLE_INTERRUPTS(sr);
> > >> >
> > >> >     return cnt;
> > >> > }
> > >> > -----------------------------------------------------
> > >> >
> > >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> > >> 下午11:35寫道:
> > >> >
> > >> > > Hi,
> > >> > >
> > >> > > 1. Do you know if tick is negative at line that you marked
> > >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >> > >
> > >> > > 2. Can you share your project with me somehow so I could take a look
> > >> > > (presuming it is running on hifive1 board)?
> > >> > >
> > >> > > I can take a look at this next Monday.
> > >> > >
> > >> > > best regards
> > >> > > Jerzy
> > >> > >
> > >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >> > > >
> > >> > > > I want to run ble_app sample code using SIFIVE mcu.
> > >> > > > I modify the bsp from nordic to my board and change mcu to sifive.
> > >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > >> > > > modify it to simulate radio hardware. for now it just for not stuck
> > >> code
> > >> > > > running.
> > >> > > >
> > >> > > > I load code and run , I got some ble log messages below.
> > >> > > >
> > >> > > > after checking code, I found
> > >> > > > inside hal_timer_start_at() function, it call fe310_tmr_check_first
> > >> and
> > >> > > > it seems not operate correctly.
> > >> > > > It will issue pwm interrupt continuely, so it stuck.
> > >> > > >
> > >> > > > is there anyone help ? or I missing something?
> > >> > > >
> > >> > > >
> > >> -----------------------------------------------------------------------
> > >> > > > static void
> > >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > >> > > > {
> > >> > > >     struct hal_timer *ht;
> > >> > > >
> > >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > >> > > >     if (ht) {
> > >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> > >> <====question code
> > >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> > >>  <====question code
> > >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > >> > > <====question
> > >> > > > code
> > >> > > >             return;
> > >> > > >         }
> > >> > > >     }
> > >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> > >> PWM_CMP0);
> > >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> > >> all
> > >> > > the
> > >> > > > time */
> > >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > >> > > > }
> > >> > > >
> > >> > >
> > >> ------------------------------------------------------------------------------
> > >> > > >
> > >> > > >
> > >> > > > =================================================
> > >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
> > >> > > ocf=0x0
> > >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0003
> > >> > > > len=0
> > >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x3 status=0
> > >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > >> > > ocf=0x0001
> > >> > > > len=0
> > >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x4
> > >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> > >> lmp_subver=0
> > >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0001
> > >> > > > len=8
> > >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
> > >> 0x02
> > >> > > 0x00
> > >> > > > 0x80 0x00 0x20
> > >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x1 status=0
> > >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > >> > > ocf=0x0063
> > >> > > > len=8
> > >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00
> > >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x3
> > >> > > > ocf=0x63 status=0
> > >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > ocf=0x0001
> > >> > > > len=8
> > >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00
> > >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x1 status=0
> > >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0002 len=0
> > >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2 status=0
> > >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0003 len=0
> > >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x3 status=0
> > >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > >> > > > ocf=0x0009 len=0
> > >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x4
> > >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x002d len=1
> > >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2d status=0
> > >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0029 len=0
> > >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x29 status=0
> > >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x002d len=1
> > >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x2d status=0
> > >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> > >> > > > advertising.
> > >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x000a len=1
> > >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0xa status=0
> > >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0027 len=39
> > >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > >> 0x00
> > >> > > 0x00
> > >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
> > >> 0xdd
> > >> > > 0x34
> > >> > > > 0xc0 0x53 0x1e 0xb8
> > >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x27 status=7
> > >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > >> > > > 000038 -ble_app_on_sync-
> > >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0018 len=0
> > >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0005 len=6
> > >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02
> > >> 0x03
> > >> > > 0x04
> > >> > > > 0x05
> > >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x5 status=0
> > >> > > > 000044 addr:0x900019dd
> > >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0008 len=32
> > >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01
> > >> 0x06
> > >> > > 0x1a
> > >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > >> 0x11
> > >> > > 0x11
> > >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x8 status=0
> > >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> > >> advertise;
> > >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> > >> > > > adv_itvl_min=0 adv_itvl_max=0
> > >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x0006 len=15
> > >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
> > >> 0x00
> > >> > > 0x03
> > >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> > >> ogf=0x8
> > >> > > > ocf=0x6 status=0
> > >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > >> > > > ocf=0x000a len=1
> > >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > >> > > > =================================================
> > >> > > >
> > >> > > > it stuck here, no more any message..
> > >> > >
> > >>
> > >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Jack,

I setup blinky-like project with default settings that hifive1 bsp set with one
modification:

SYS_CLOCK: HFXOSC_16_MHZ

I also added two cpu timers like this:

os_cputime_timer_init(&cpu_timer1, cpu_timer1_cb, NULL);
os_cputime_timer_relative(&cpu_timer1, CPU_TIMER1_TIMEOUT);

os_cputime_timer_init(&cpu_timer2, cpu_timer2_cb, NULL);
os_cputime_timer_relative(&cpu_timer2, CPU_TIMER2_TIMEOUT);

Code is using cpu timer that is using PWM2 that should be similar to
what you have.
My timer callbacks just toggle some GPIO to verify that frequencies are correct.
So far everything works as expected.

1. Maybe you could share timer/clock related content of your syscfg.
2. Maybe timer usage is different then mine (hal_timer api instead of
cpu_timer that I used for quick check)

br
Jerzy

pon., 15 mar 2021 o 09:05 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> 3. frequency on PWM timer: 32768
>
> Jack
>
> 范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:
>
> > Hi,
> >
> > 1. system clock frequency:16MHz
> > 2. which PWM: PWM2
> > 3. frequency on PWM timer: 32758
> >
> > Jack
> >
> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午3:33寫道:
> >
> >> Hi,
> >>
> >> I don't remember details to answer number 3 out of my head. But we
> >> will find out soon.
> >> In the meanwhile can you give me:
> >> 1. system clock frequency that you have selected
> >> 2. which PWM is causing problem.
> >> 3. what is frequency on PWM timer.
> >> Those will help me setup environment closer to what you have.
> >>
> >> br
> >> Jerzy
> >>
> >> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> >> >
> >> > Hi,
> >> >
> >> > 1. Do you know if tick is negative at line that you marked
> >> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> >> >
> >> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209,
> >> ticks
> >> > =0x6a
> >> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> >> > (fe310_pwm_cmp1_handler)
> >> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> >> > interrupt, and so on..
> >> >
> >> > 2. I am sorry I can not share project with you, it is company project.
> >> >     I can provide program running info
> >> >
> >> > 3. I have a question about hal_timer_cnt function .
> >> > how does the code check overflow condition?
> >> >
> >> > Thanks for your help.
> >> >
> >> > --------------------------------------------------
> >> > static uint32_t
> >> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> >> > {
> >> >     uint32_t cnt;
> >> >     int sr;
> >> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> >> >
> >> >     __HAL_DISABLE_INTERRUPTS(sr);
> >> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> >> >     /* Check if just overflowed */
> >> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> >> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> >> >     }
> >> >     __HAL_ENABLE_INTERRUPTS(sr);
> >> >
> >> >     return cnt;
> >> > }
> >> > -----------------------------------------------------
> >> >
> >> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
> >> 下午11:35寫道:
> >> >
> >> > > Hi,
> >> > >
> >> > > 1. Do you know if tick is negative at line that you marked
> >> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> >> > >
> >> > > 2. Can you share your project with me somehow so I could take a look
> >> > > (presuming it is running on hifive1 board)?
> >> > >
> >> > > I can take a look at this next Monday.
> >> > >
> >> > > best regards
> >> > > Jerzy
> >> > >
> >> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> >> > > >
> >> > > > I want to run ble_app sample code using SIFIVE mcu.
> >> > > > I modify the bsp from nordic to my board and change mcu to sifive.
> >> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> >> > > > modify it to simulate radio hardware. for now it just for not stuck
> >> code
> >> > > > running.
> >> > > >
> >> > > > I load code and run , I got some ble log messages below.
> >> > > >
> >> > > > after checking code, I found
> >> > > > inside hal_timer_start_at() function, it call fe310_tmr_check_first
> >> and
> >> > > > it seems not operate correctly.
> >> > > > It will issue pwm interrupt continuely, so it stuck.
> >> > > >
> >> > > > is there anyone help ? or I missing something?
> >> > > >
> >> > > >
> >> -----------------------------------------------------------------------
> >> > > > static void
> >> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> >> > > > {
> >> > > >     struct hal_timer *ht;
> >> > > >
> >> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> >> > > >     if (ht) {
> >> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> >> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> >> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
> >> <====question code
> >> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
> >>  <====question code
> >> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> >> > > <====question
> >> > > > code
> >> > > >             return;
> >> > > >         }
> >> > > >     }
> >> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> >> PWM_CMP0);
> >> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> >> all
> >> > > the
> >> > > > time */
> >> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> >> > > > }
> >> > > >
> >> > >
> >> ------------------------------------------------------------------------------
> >> > > >
> >> > > >
> >> > > > =================================================
> >> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
> >> > > ocf=0x0
> >> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> >> > > ocf=0x0003
> >> > > > len=0
> >> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> >> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x3
> >> > > > ocf=0x3 status=0
> >> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> >> > > ocf=0x0001
> >> > > > len=0
> >> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> >> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x4
> >> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> >> lmp_subver=0
> >> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> >> > > ocf=0x0001
> >> > > > len=8
> >> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
> >> 0x02
> >> > > 0x00
> >> > > > 0x80 0x00 0x20
> >> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x3
> >> > > > ocf=0x1 status=0
> >> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> >> > > ocf=0x0063
> >> > > > len=8
> >> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
> >> 0x00
> >> > > 0x00
> >> > > > 0x00 0x00 0x00
> >> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x3
> >> > > > ocf=0x63 status=0
> >> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > ocf=0x0001
> >> > > > len=8
> >> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f
> >> 0x00
> >> > > 0x00
> >> > > > 0x00 0x00 0x00
> >> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x1 status=0
> >> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0002 len=0
> >> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> >> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x2 status=0
> >> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0003 len=0
> >> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> >> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x3 status=0
> >> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> >> > > > ocf=0x0009 len=0
> >> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> >> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x4
> >> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> >> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x002d len=1
> >> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> >> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x2d status=0
> >> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0029 len=0
> >> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> >> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x29 status=0
> >> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x002d len=1
> >> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> >> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x2d status=0
> >> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> >> > > > advertising.
> >> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x000a len=1
> >> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> >> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0xa status=0
> >> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0027 len=39
> >> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00
> >> 0x00
> >> > > 0x00
> >> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> >> 0x00
> >> > > 0x00
> >> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
> >> 0xdd
> >> > > 0x34
> >> > > > 0xc0 0x53 0x1e 0xb8
> >> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x27 status=7
> >> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> >> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> >> > > > 000038 -ble_app_on_sync-
> >> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0018 len=0
> >> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> >> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x18 status=0 rand=0x0001020304050607
> >> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0005 len=6
> >> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02
> >> 0x03
> >> > > 0x04
> >> > > > 0x05
> >> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x5 status=0
> >> > > > 000044 addr:0x900019dd
> >> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0008 len=32
> >> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01
> >> 0x06
> >> > > 0x1a
> >> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> >> 0x11
> >> > > 0x11
> >> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> >> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x8 status=0
> >> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> >> advertise;
> >> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> >> > > > adv_itvl_min=0 adv_itvl_max=0
> >> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x0006 len=15
> >> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
> >> 0x00
> >> > > 0x03
> >> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> >> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> >> ogf=0x8
> >> > > > ocf=0x6 status=0
> >> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> >> > > > ocf=0x000a len=1
> >> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> >> > > > =================================================
> >> > > >
> >> > > > it stuck here, no more any message..
> >> > >
> >>
> >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by 范姜徐霖 <ja...@gmail.com>.
3. frequency on PWM timer: 32768

Jack

范姜徐霖 <ja...@gmail.com> 於 2021年3月15日 週一 下午3:33寫道:

> Hi,
>
> 1. system clock frequency:16MHz
> 2. which PWM: PWM2
> 3. frequency on PWM timer: 32758
>
> Jack
>
> Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午3:33寫道:
>
>> Hi,
>>
>> I don't remember details to answer number 3 out of my head. But we
>> will find out soon.
>> In the meanwhile can you give me:
>> 1. system clock frequency that you have selected
>> 2. which PWM is causing problem.
>> 3. what is frequency on PWM timer.
>> Those will help me setup environment closer to what you have.
>>
>> br
>> Jerzy
>>
>> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
>> >
>> > Hi,
>> >
>> > 1. Do you know if tick is negative at line that you marked
>> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
>> >
>> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209,
>> ticks
>> > =0x6a
>> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
>> > (fe310_pwm_cmp1_handler)
>> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
>> > interrupt, and so on..
>> >
>> > 2. I am sorry I can not share project with you, it is company project.
>> >     I can provide program running info
>> >
>> > 3. I have a question about hal_timer_cnt function .
>> > how does the code check overflow condition?
>> >
>> > Thanks for your help.
>> >
>> > --------------------------------------------------
>> > static uint32_t
>> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
>> > {
>> >     uint32_t cnt;
>> >     int sr;
>> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
>> >
>> >     __HAL_DISABLE_INTERRUPTS(sr);
>> >     cnt = _REG32(regs, PWM_S) + tmr->value;
>> >     /* Check if just overflowed */
>> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
>> >         cnt += _REG32(regs, PWM_CMP0) + 1;
>> >     }
>> >     __HAL_ENABLE_INTERRUPTS(sr);
>> >
>> >     return cnt;
>> > }
>> > -----------------------------------------------------
>> >
>> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六
>> 下午11:35寫道:
>> >
>> > > Hi,
>> > >
>> > > 1. Do you know if tick is negative at line that you marked
>> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
>> > >
>> > > 2. Can you share your project with me somehow so I could take a look
>> > > (presuming it is running on hifive1 board)?
>> > >
>> > > I can take a look at this next Monday.
>> > >
>> > > best regards
>> > > Jerzy
>> > >
>> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
>> > > >
>> > > > I want to run ble_app sample code using SIFIVE mcu.
>> > > > I modify the bsp from nordic to my board and change mcu to sifive.
>> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
>> > > > modify it to simulate radio hardware. for now it just for not stuck
>> code
>> > > > running.
>> > > >
>> > > > I load code and run , I got some ble log messages below.
>> > > >
>> > > > after checking code, I found
>> > > > inside hal_timer_start_at() function, it call fe310_tmr_check_first
>> and
>> > > > it seems not operate correctly.
>> > > > It will issue pwm interrupt continuely, so it stuck.
>> > > >
>> > > > is there anyone help ? or I missing something?
>> > > >
>> > > >
>> -----------------------------------------------------------------------
>> > > > static void
>> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
>> > > > {
>> > > >     struct hal_timer *ht;
>> > > >
>> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
>> > > >     if (ht) {
>> > > >         uint32_t cnt = hal_timer_cnt(tmr);
>> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
>> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) {
>> <====question code
>> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;
>>  <====question code
>> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
>> > > <====question
>> > > > code
>> > > >             return;
>> > > >         }
>> > > >     }
>> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
>> PWM_CMP0);
>> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
>> all
>> > > the
>> > > > time */
>> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
>> > > > }
>> > > >
>> > >
>> ------------------------------------------------------------------------------
>> > > >
>> > > >
>> > > > =================================================
>> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
>> > > ocf=0x0
>> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
>> > > ocf=0x0003
>> > > > len=0
>> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
>> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x3
>> > > > ocf=0x3 status=0
>> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
>> > > ocf=0x0001
>> > > > len=0
>> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
>> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x4
>> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
>> lmp_subver=0
>> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
>> > > ocf=0x0001
>> > > > len=8
>> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00
>> 0x02
>> > > 0x00
>> > > > 0x80 0x00 0x20
>> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x3
>> > > > ocf=0x1 status=0
>> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
>> > > ocf=0x0063
>> > > > len=8
>> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80
>> 0x00
>> > > 0x00
>> > > > 0x00 0x00 0x00
>> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x3
>> > > > ocf=0x63 status=0
>> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > ocf=0x0001
>> > > > len=8
>> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f
>> 0x00
>> > > 0x00
>> > > > 0x00 0x00 0x00
>> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x1 status=0
>> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0002 len=0
>> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
>> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x2 status=0
>> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0003 len=0
>> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
>> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x3 status=0
>> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
>> > > > ocf=0x0009 len=0
>> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
>> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x4
>> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
>> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x002d len=1
>> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
>> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x2d status=0
>> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0029 len=0
>> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
>> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x29 status=0
>> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x002d len=1
>> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
>> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x2d status=0
>> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
>> > > > advertising.
>> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x000a len=1
>> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
>> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0xa status=0
>> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0027 len=39
>> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00
>> 0x00
>> > > 0x00
>> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
>> 0x00
>> > > 0x00
>> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b
>> 0xdd
>> > > 0x34
>> > > > 0xc0 0x53 0x1e 0xb8
>> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x27 status=7
>> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
>> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
>> > > > 000038 -ble_app_on_sync-
>> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0018 len=0
>> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
>> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x18 status=0 rand=0x0001020304050607
>> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0005 len=6
>> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02
>> 0x03
>> > > 0x04
>> > > > 0x05
>> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x5 status=0
>> > > > 000044 addr:0x900019dd
>> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0008 len=32
>> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01
>> 0x06
>> > > 0x1a
>> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
>> 0x11
>> > > 0x11
>> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
>> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x8 status=0
>> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
>> advertise;
>> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
>> > > > adv_itvl_min=0 adv_itvl_max=0
>> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x0006 len=15
>> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0
>> 0x00
>> > > 0x03
>> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
>> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
>> ogf=0x8
>> > > > ocf=0x6 status=0
>> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
>> > > > ocf=0x000a len=1
>> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
>> > > > =================================================
>> > > >
>> > > > it stuck here, no more any message..
>> > >
>>
>

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by 范姜徐霖 <ja...@gmail.com>.
Hi,

1. system clock frequency:16MHz
2. which PWM: PWM2
3. frequency on PWM timer: 32758

Jack

Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月15日 週一 下午3:33寫道:

> Hi,
>
> I don't remember details to answer number 3 out of my head. But we
> will find out soon.
> In the meanwhile can you give me:
> 1. system clock frequency that you have selected
> 2. which PWM is causing problem.
> 3. what is frequency on PWM timer.
> Those will help me setup environment closer to what you have.
>
> br
> Jerzy
>
> niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
> >
> > Hi,
> >
> > 1. Do you know if tick is negative at line that you marked
> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> >
> > In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209,
> ticks
> > =0x6a
> > my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> > (fe310_pwm_cmp1_handler)
> >  and the handler call fe310_tmr_check_first again, then trigger  pwm
> > interrupt, and so on..
> >
> > 2. I am sorry I can not share project with you, it is company project.
> >     I can provide program running info
> >
> > 3. I have a question about hal_timer_cnt function .
> > how does the code check overflow condition?
> >
> > Thanks for your help.
> >
> > --------------------------------------------------
> > static uint32_t
> > hal_timer_cnt(struct fe310_hal_tmr *tmr)
> > {
> >     uint32_t cnt;
> >     int sr;
> >     uint32_t regs = (uint32_t) tmr->pwm_regs;
> >
> >     __HAL_DISABLE_INTERRUPTS(sr);
> >     cnt = _REG32(regs, PWM_S) + tmr->value;
> >     /* Check if just overflowed */
> >     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
> >         cnt += _REG32(regs, PWM_CMP0) + 1;
> >     }
> >     __HAL_ENABLE_INTERRUPTS(sr);
> >
> >     return cnt;
> > }
> > -----------------------------------------------------
> >
> > Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六 下午11:35寫道:
> >
> > > Hi,
> > >
> > > 1. Do you know if tick is negative at line that you marked
> > > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >
> > > 2. Can you share your project with me somehow so I could take a look
> > > (presuming it is running on hifive1 board)?
> > >
> > > I can take a look at this next Monday.
> > >
> > > best regards
> > > Jerzy
> > >
> > > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > > >
> > > > I want to run ble_app sample code using SIFIVE mcu.
> > > > I modify the bsp from nordic to my board and change mcu to sifive.
> > > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > > modify it to simulate radio hardware. for now it just for not stuck
> code
> > > > running.
> > > >
> > > > I load code and run , I got some ble log messages below.
> > > >
> > > > after checking code, I found
> > > > inside hal_timer_start_at() function, it call fe310_tmr_check_first
> and
> > > > it seems not operate correctly.
> > > > It will issue pwm interrupt continuely, so it stuck.
> > > >
> > > > is there anyone help ? or I missing something?
> > > >
> > > >
> -----------------------------------------------------------------------
> > > > static void
> > > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > > {
> > > >     struct hal_timer *ht;
> > > >
> > > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > > >     if (ht) {
> > > >         uint32_t cnt = hal_timer_cnt(tmr);
> > > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question
> code
> > > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;   <====question
> code
> > > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > > <====question
> > > > code
> > > >             return;
> > > >         }
> > > >     }
> > > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs,
> PWM_CMP0);
> > > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used
> all
> > > the
> > > > time */
> > > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > > }
> > > >
> > >
> ------------------------------------------------------------------------------
> > > >
> > > >
> > > > =================================================
> > > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
> > > ocf=0x0
> > > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > ocf=0x0003
> > > > len=0
> > > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x3
> > > > ocf=0x3 status=0
> > > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > > ocf=0x0001
> > > > len=0
> > > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x4
> > > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535
> lmp_subver=0
> > > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > ocf=0x0001
> > > > len=8
> > > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00 0x02
> > > 0x00
> > > > 0x80 0x00 0x20
> > > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x3
> > > > ocf=0x1 status=0
> > > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > > ocf=0x0063
> > > > len=8
> > > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80 0x00
> > > 0x00
> > > > 0x00 0x00 0x00
> > > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x3
> > > > ocf=0x63 status=0
> > > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0001
> > > > len=8
> > > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f
> 0x00
> > > 0x00
> > > > 0x00 0x00 0x00
> > > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x1 status=0
> > > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0002 len=0
> > > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x2 status=0
> > > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0003 len=0
> > > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x3 status=0
> > > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > > > ocf=0x0009 len=0
> > > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x4
> > > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x002d len=1
> > > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x2d status=0
> > > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0029 len=0
> > > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x29 status=0
> > > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x002d len=1
> > > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x2d status=0
> > > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> > > > advertising.
> > > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x000a len=1
> > > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0xa status=0
> > > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0027 len=39
> > > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00
> 0x00
> > > 0x00
> > > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > > 0x00
> > > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b 0xdd
> > > 0x34
> > > > 0xc0 0x53 0x1e 0xb8
> > > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x27 status=7
> > > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > > 000038 -ble_app_on_sync-
> > > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0018 len=0
> > > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x18 status=0 rand=0x0001020304050607
> > > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0005 len=6
> > > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02
> 0x03
> > > 0x04
> > > > 0x05
> > > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x5 status=0
> > > > 000044 addr:0x900019dd
> > > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0008 len=32
> > > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01
> 0x06
> > > 0x1a
> > > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > > 0x11
> > > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x8 status=0
> > > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated:
> advertise;
> > > > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> > > > adv_itvl_min=0 adv_itvl_max=0
> > > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x0006 len=15
> > > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0 0x00
> > > 0x03
> > > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1
> ogf=0x8
> > > > ocf=0x6 status=0
> > > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > > ocf=0x000a len=1
> > > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > > =================================================
> > > >
> > > > it stuck here, no more any message..
> > >
>

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi,

I don't remember details to answer number 3 out of my head. But we
will find out soon.
In the meanwhile can you give me:
1. system clock frequency that you have selected
2. which PWM is causing problem.
3. what is frequency on PWM timer.
Those will help me setup environment closer to what you have.

br
Jerzy

niedz., 14 mar 2021 o 02:28 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> Hi,
>
> 1. Do you know if tick is negative at line that you marked
> if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
>
> In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209, ticks
> =0x6a
> my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
> (fe310_pwm_cmp1_handler)
>  and the handler call fe310_tmr_check_first again, then trigger  pwm
> interrupt, and so on..
>
> 2. I am sorry I can not share project with you, it is company project.
>     I can provide program running info
>
> 3. I have a question about hal_timer_cnt function .
> how does the code check overflow condition?
>
> Thanks for your help.
>
> --------------------------------------------------
> static uint32_t
> hal_timer_cnt(struct fe310_hal_tmr *tmr)
> {
>     uint32_t cnt;
>     int sr;
>     uint32_t regs = (uint32_t) tmr->pwm_regs;
>
>     __HAL_DISABLE_INTERRUPTS(sr);
>     cnt = _REG32(regs, PWM_S) + tmr->value;
>     /* Check if just overflowed */
>     if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
>         cnt += _REG32(regs, PWM_CMP0) + 1;
>     }
>     __HAL_ENABLE_INTERRUPTS(sr);
>
>     return cnt;
> }
> -----------------------------------------------------
>
> Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六 下午11:35寫道:
>
> > Hi,
> >
> > 1. Do you know if tick is negative at line that you marked
> > if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> >
> > 2. Can you share your project with me somehow so I could take a look
> > (presuming it is running on hifive1 board)?
> >
> > I can take a look at this next Monday.
> >
> > best regards
> > Jerzy
> >
> > sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> > >
> > > I want to run ble_app sample code using SIFIVE mcu.
> > > I modify the bsp from nordic to my board and change mcu to sifive.
> > > I copy apache-mynewt-nimble/nimble/drivers/native and
> > > modify it to simulate radio hardware. for now it just for not stuck code
> > > running.
> > >
> > > I load code and run , I got some ble log messages below.
> > >
> > > after checking code, I found
> > > inside hal_timer_start_at() function, it call fe310_tmr_check_first and
> > > it seems not operate correctly.
> > > It will issue pwm interrupt continuely, so it stuck.
> > >
> > > is there anyone help ? or I missing something?
> > >
> > > -----------------------------------------------------------------------
> > > static void
> > > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > > {
> > >     struct hal_timer *ht;
> > >
> > >     ht = TAILQ_FIRST(&tmr->sht_timers);
> > >     if (ht) {
> > >         uint32_t cnt = hal_timer_cnt(tmr);
> > >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> > >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> > >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;   <====question code
> > >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> > <====question
> > > code
> > >             return;
> > >         }
> > >     }
> > >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
> > >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used all
> > the
> > > time */
> > >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > > }
> > >
> > ------------------------------------------------------------------------------
> > >
> > >
> > > =================================================
> > > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
> > ocf=0x0
> > > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > ocf=0x0003
> > > len=0
> > > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > > ocf=0x3 status=0
> > > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > ocf=0x0001
> > > len=0
> > > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> > > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535 lmp_subver=0
> > > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > ocf=0x0001
> > > len=8
> > > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00 0x02
> > 0x00
> > > 0x80 0x00 0x20
> > > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > > ocf=0x1 status=0
> > > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> > ocf=0x0063
> > > len=8
> > > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80 0x00
> > 0x00
> > > 0x00 0x00 0x00
> > > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > > ocf=0x63 status=0
> > > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0001
> > > len=8
> > > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f 0x00
> > 0x00
> > > 0x00 0x00 0x00
> > > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x1 status=0
> > > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0002 len=0
> > > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x2 status=0
> > > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0003 len=0
> > > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x3 status=0
> > > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > > ocf=0x0009 len=0
> > > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> > > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x002d len=1
> > > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x2d status=0
> > > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0029 len=0
> > > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x29 status=0
> > > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x002d len=1
> > > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x2d status=0
> > > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> > > advertising.
> > > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x000a len=1
> > > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0xa status=0
> > > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0027 len=39
> > > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00 0x00
> > 0x00
> > > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > 0x00
> > > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b 0xdd
> > 0x34
> > > 0xc0 0x53 0x1e 0xb8
> > > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x27 status=7
> > > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > > 000038 -ble_app_on_sync-
> > > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0018 len=0
> > > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x18 status=0 rand=0x0001020304050607
> > > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0005 len=6
> > > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02 0x03
> > 0x04
> > > 0x05
> > > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x5 status=0
> > > 000044 addr:0x900019dd
> > > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0008 len=32
> > > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01 0x06
> > 0x1a
> > > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> > 0x11
> > > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x8 status=0
> > > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated: advertise;
> > > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> > > adv_itvl_min=0 adv_itvl_max=0
> > > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x0006 len=15
> > > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0 0x00
> > 0x03
> > > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > > ocf=0x6 status=0
> > > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > > ocf=0x000a len=1
> > > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > > =================================================
> > >
> > > it stuck here, no more any message..
> >

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by 范姜徐霖 <ja...@gmail.com>.
Hi,

1. Do you know if tick is negative at line that you marked
if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code

In my program : PWM_CMP0=0xffff, PWM_CMP1=0xffff, PEM_CFG=0xc0001209, ticks
=0x6a
my observation: 0x6a written in PWM_CMP1, this trigger pwm interrupt
(fe310_pwm_cmp1_handler)
 and the handler call fe310_tmr_check_first again, then trigger  pwm
interrupt, and so on..

2. I am sorry I can not share project with you, it is company project.
    I can provide program running info

3. I have a question about hal_timer_cnt function .
how does the code check overflow condition?

Thanks for your help.

--------------------------------------------------
static uint32_t
hal_timer_cnt(struct fe310_hal_tmr *tmr)
{
    uint32_t cnt;
    int sr;
    uint32_t regs = (uint32_t) tmr->pwm_regs;

    __HAL_DISABLE_INTERRUPTS(sr);
    cnt = _REG32(regs, PWM_S) + tmr->value;
    /* Check if just overflowed */
    if (_REG32(regs, PWM_CFG) & PWM_CMP0) {  <====question code
        cnt += _REG32(regs, PWM_CMP0) + 1;
    }
    __HAL_ENABLE_INTERRUPTS(sr);

    return cnt;
}
-----------------------------------------------------

Jerzy Kasenberg <je...@codecoup.pl> 於 2021年3月13日 週六 下午11:35寫道:

> Hi,
>
> 1. Do you know if tick is negative at line that you marked
> if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
>
> 2. Can you share your project with me somehow so I could take a look
> (presuming it is running on hifive1 board)?
>
> I can take a look at this next Monday.
>
> best regards
> Jerzy
>
> sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
> >
> > I want to run ble_app sample code using SIFIVE mcu.
> > I modify the bsp from nordic to my board and change mcu to sifive.
> > I copy apache-mynewt-nimble/nimble/drivers/native and
> > modify it to simulate radio hardware. for now it just for not stuck code
> > running.
> >
> > I load code and run , I got some ble log messages below.
> >
> > after checking code, I found
> > inside hal_timer_start_at() function, it call fe310_tmr_check_first and
> > it seems not operate correctly.
> > It will issue pwm interrupt continuely, so it stuck.
> >
> > is there anyone help ? or I missing something?
> >
> > -----------------------------------------------------------------------
> > static void
> > fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> > {
> >     struct hal_timer *ht;
> >
> >     ht = TAILQ_FIRST(&tmr->sht_timers);
> >     if (ht) {
> >         uint32_t cnt = hal_timer_cnt(tmr);
> >         int32_t ticks = (int32_t)(ht->expiry - cnt);
> >         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
> >             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;   <====question code
> >             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);
> <====question
> > code
> >             return;
> >         }
> >     }
> >     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
> >      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used all
> the
> > time */
> >     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> > }
> >
> ------------------------------------------------------------------------------
> >
> >
> > =================================================
> > 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0
> ocf=0x0
> > 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> ocf=0x0003
> > len=0
> > 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> > 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > ocf=0x3 status=0
> > 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> ocf=0x0001
> > len=0
> > 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> > 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> > ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535 lmp_subver=0
> > 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> ocf=0x0001
> > len=8
> > 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00 0x02
> 0x00
> > 0x80 0x00 0x20
> > 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > ocf=0x1 status=0
> > 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03
> ocf=0x0063
> > len=8
> > 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80 0x00
> 0x00
> > 0x00 0x00 0x00
> > 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> > ocf=0x63 status=0
> > 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0001
> > len=8
> > 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f 0x00
> 0x00
> > 0x00 0x00 0x00
> > 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x1 status=0
> > 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0002 len=0
> > 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> > 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x2 status=0
> > 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0003 len=0
> > 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> > 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x3 status=0
> > 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> > ocf=0x0009 len=0
> > 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> > 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> > ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> > 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x002d len=1
> > 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> > 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x2d status=0
> > 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0029 len=0
> > 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> > 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x29 status=0
> > 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x002d len=1
> > 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> > 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x2d status=0
> > 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> > advertising.
> > 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x000a len=1
> > 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> > 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0xa status=0
> > 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0027 len=39
> > 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00 0x00
> 0x00
> > 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> 0x00
> > 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b 0xdd
> 0x34
> > 0xc0 0x53 0x1e 0xb8
> > 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x27 status=7
> > 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> > 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> > 000038 -ble_app_on_sync-
> > 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0018 len=0
> > 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> > 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x18 status=0 rand=0x0001020304050607
> > 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0005 len=6
> > 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02 0x03
> 0x04
> > 0x05
> > 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x5 status=0
> > 000044 addr:0x900019dd
> > 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0008 len=32
> > 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01 0x06
> 0x1a
> > 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> 0x11
> > 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> > 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x8 status=0
> > 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated: advertise;
> > disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> > adv_itvl_min=0 adv_itvl_max=0
> > 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x0006 len=15
> > 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0 0x00
> 0x03
> > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> > 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> > ocf=0x6 status=0
> > 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> > ocf=0x000a len=1
> > 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> > =================================================
> >
> > it stuck here, no more any message..
>

Re: hw/mcu/sifive/fe310/src/hal_timer.c question

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi,

1. Do you know if tick is negative at line that you marked
if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code

2. Can you share your project with me somehow so I could take a look
(presuming it is running on hifive1 board)?

I can take a look at this next Monday.

best regards
Jerzy

sob., 13 mar 2021 o 12:24 范姜徐霖 <ja...@gmail.com> napisał(a):
>
> I want to run ble_app sample code using SIFIVE mcu.
> I modify the bsp from nordic to my board and change mcu to sifive.
> I copy apache-mynewt-nimble/nimble/drivers/native and
> modify it to simulate radio hardware. for now it just for not stuck code
> running.
>
> I load code and run , I got some ble log messages below.
>
> after checking code, I found
> inside hal_timer_start_at() function, it call fe310_tmr_check_first and
> it seems not operate correctly.
> It will issue pwm interrupt continuely, so it stuck.
>
> is there anyone help ? or I missing something?
>
> -----------------------------------------------------------------------
> static void
> fe310_tmr_check_first(struct fe310_hal_tmr *tmr)
> {
>     struct hal_timer *ht;
>
>     ht = TAILQ_FIRST(&tmr->sht_timers);
>     if (ht) {
>         uint32_t cnt = hal_timer_cnt(tmr);
>         int32_t ticks = (int32_t)(ht->expiry - cnt);
>         if (ticks < _REG32(tmr->pwm_regs, PWM_CMP0)) { <====question code
>             _REG32(tmr->pwm_regs, PWM_CMP1) = ticks;   <====question code
>             plic_enable_interrupt(tmr->pwmxcmp0_int + 1);    <====question
> code
>             return;
>         }
>     }
>     _REG32(tmr->pwm_regs, PWM_CMP1) = _REG32(tmr->pwm_regs, PWM_CMP0);
>      /* Disable PWMxCMP1 interrupt, leaving only CMP0 which is used all the
> time */
>     plic_disable_interrupt(tmr->pwmxcmp0_int + 1);
> }
> ------------------------------------------------------------------------------
>
>
> =================================================
> 000000 [ts=0us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x0 ocf=0x0
> 000001 [ts=7812us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0003
> len=0
> 000002 [ts=15624us, mod=4 level=0] 0x03 0x0c 0x00
> 000002 [ts=15624us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> ocf=0x3 status=0
> 000003 [ts=23436us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04 ocf=0x0001
> len=0
> 000004 [ts=31248us, mod=4 level=0] 0x01 0x10 0x00
> 000005 [ts=39060us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> ocf=0x1 status=0 hci_ver=9 hci_rev=0 lmp_ver=9 mfrg=65535 lmp_subver=0
> 000006 [ts=46872us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0001
> len=8
> 000007 [ts=54684us, mod=4 level=0] 0x01 0x0c 0x08 0x90 0x80 0x00 0x02 0x00
> 0x80 0x00 0x20
> 000008 [ts=62496us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> ocf=0x1 status=0
> 000009 [ts=70308us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x03 ocf=0x0063
> len=8
> 000010 [ts=78120us, mod=4 level=0] 0x63 0x0c 0x08 0x00 0x00 0x80 0x00 0x00
> 0x00 0x00 0x00
> 000011 [ts=85932us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x3
> ocf=0x63 status=0
> 000012 [ts=93744us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0001
> len=8
> 000013 [ts=101556us, mod=4 level=0] 0x01 0x20 0x08 0x7f 0xfe 0x0f 0x00 0x00
> 0x00 0x00 0x00
> 000014 [ts=109368us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x1 status=0
> 000015 [ts=117180us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0002 len=0
> 000016 [ts=124992us, mod=4 level=0] 0x02 0x20 0x00
> 000016 [ts=124992us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x2 status=0
> 000017 [ts=132804us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0003 len=0
> 000018 [ts=140616us, mod=4 level=0] 0x03 0x20 0x00
> 000019 [ts=148428us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x3 status=0
> 000020 [ts=156240us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x04
> ocf=0x0009 len=0
> 000020 [ts=156240us, mod=4 level=0] 0x09 0x10 0x00
> 000021 [ts=164052us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x4
> ocf=0x9 status=0 bd_addr=0:0:0:0:0:0
> 000022 [ts=171864us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x002d len=1
> 000023 [ts=179676us, mod=4 level=0] 0x2d 0x20 0x01 0x00
> 000024 [ts=187488us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x2d status=0
> 000025 [ts=195300us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0029 len=0
> 000026 [ts=203112us, mod=4 level=0] 0x29 0x20 0x00
> 000026 [ts=203112us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x29 status=0
> 000027 [ts=210924us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x002d len=1
> 000028 [ts=218736us, mod=4 level=0] 0x2d 0x20 0x01 0x01
> 000029 [ts=226548us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x2d status=0
> 000030 [ts=234360us, mod=4 level=1] GAP procedure initiated: stop
> advertising.
> 000030 [ts=234360us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x000a len=1
> 000031 [ts=242172us, mod=4 level=0] 0x0a 0x20 0x01 0x00
> 000032 [ts=249984us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0xa status=0
> 000033 [ts=257796us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0027 len=39
> 000034 [ts=265608us, mod=4 level=0] 0x27 0x20 0x27 0x00 0x00 0x00 0x00 0x00
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> 0x00 0x00 0x00 0xef 0x8d 0xe2 0x16 0x4f 0xec 0x43 0x0d 0xbf 0x5b 0xdd 0x34
> 0xc0 0x53 0x1e 0xb8
> 000037 [ts=289044us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x27 status=7
> 000037 [ts=289044us, mod=4 level=0] looking up peer sec;
> 000038 [ts=296856us, mod=4 level=1] ble_hs_cfg
> 000038 -ble_app_on_sync-
> 000039 [ts=304668us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0018 len=0
> 000040 [ts=312480us, mod=4 level=0] 0x18 0x20 0x00
> 000040 [ts=312480us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x18 status=0 rand=0x0001020304050607
> 000042 [ts=328104us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0005 len=6
> 000042 [ts=328104us, mod=4 level=0] 0x05 0x20 0x06 0x00 0x01 0x02 0x03 0x04
> 0x05
> 000043 [ts=335916us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x5 status=0
> 000044 addr:0x900019dd
> 000045 [ts=351540us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0008 len=32
> 000045 [ts=351540us, mod=4 level=0] 0x08 0x20 0x20 0x1e 0x02 0x01 0x06 0x1a
> 0xff 0x4c 0x00 0x02 0x15 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11
> 0x11 0x11 0x11 0x11 0x11 0x11 0x00 0x02 0x00 0x0a 0x00 0x00
> 000048 [ts=374976us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x8 status=0
> 000049 [ts=382788us, mod=4 level=1] GAP procedure initiated: advertise;
> disc_mode=0 adv_channel_map=0 own_addr_type=1 adv_filter_policy=0
> adv_itvl_min=0 adv_itvl_max=0
> 000051 [ts=398412us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x0006 len=15
> 00001 [ts=398412us, mod=4 level=0] 0x06 0x20 0x0f 0xa0 0x00 0xf0 0x00 0x03
> 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x00
> 000053 [ts=414036us, mod=4 level=0] Command complete: cmd_pkts=1 ogf=0x8
> ocf=0x6 status=0
> 000054 [ts=421848us, mod=4 level=0] ble_hs_hci_cmd_send: ogf=0x08
> ocf=0x000a len=1
> 000055 [ts=429660us, mod=4 level=0] 0x0a 0x20 0x01 0x01
> =================================================
>
> it stuck here, no more any message..