RXv3コアのレジスタ一括退避機能を使ってマルチスーパーループ実行ライブラリ(MultiSuperLoopExecLibrary)を作ってみるスレッド

こんにちは。NoMaYです。

今、以下のスレッドに投稿しているのですけれども、派生ネタが思い浮かびましたので、またひとつ立ててみました。

RXv3コアのレジスタ一括退避機能の使い方(Register Bank Save Function Usage)を調べてみるスレッド
community-ja.renesas.com/cafe_rene/forums-groups/mcu-mpu/rx/f/forum5/9572/rxv3-register-bank-save-function-usage

派生ネタ

・ スーパーループを複数同時実行する(複数のスーパーループを切り替えながら実行する)、という、ありがちなものです
・ RXv3コアのレジスタ一括退避機能の高速性を鑑みて10μsec程度で切り替えてみたいです
・ お遊びです

Parents
  • RXマイコンには昔から高速割り込みという機能がありますが、以下のハードウェア編の画面コピーの通り、割り込みの受け付け時に2クロック、割り込みからのリターン時に3クロック、それぞれ実行クロックが通常の割り込みより少なくなります。ものは試しとして、この機能を利用するコードの断片を考えてみました。残念ながら、高速割り込み機能で使用されるレジスタはレジスタ一括退避機能の対象に含まれておらず、結局のところは、メモリ(スタック)への退避とメモリ(スタック)からの復帰が必要になってしまい、落としどころとしては、今ひとつなコードになってしまいました。

    思い浮かんだコードの断片のネタ(ネタの状態ですので動作は試していません)

    以下の緑文字部分が高速割り込みを使う場合の落としどころな気がします、、、

    #if 0 /* Unfortunately CC-RX doesn't allow multiple #pragma for one function. */
    #pragma interrupt r_Config_CMT3_cmi3_interrupt(vect=VECT(PERIB,INTB129),fint)
    #endif
    #pragma inline_asm r_Config_CMT3_cmi3_interrupt
    void r_Config_CMT3_cmi3_interrupt(void)
    {
        /* Re-enable interrupt. */
        setpsw i

        /* Save the current super loop context. Be aware that the USP is used from now. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        setpsw u
        sub #8, sp
        push.l r1
        mov.l #_SuperLoopCurrentContextId, r1
        mov.b [r1], r1
        save r1

        /* Copy PSW, PC from BPSW, BPC registers to the current super loop's user stack. */
        mvfc bpsw, r2
        mov.l r2, 8[sp]
        mvfc bpc, r3
        mov.l r3, 4[sp]

        /* Select the next super loop. */
        add #1, r1
        and #1, r1
        mov.l #_SuperLoopCurrentContextId, r2
        mov.b r1, [r2]

        /* Restore the next super loop context. Be aware that the USP is used here. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        rstr r1
        pop r1
        rte ← rtfiでは無くてrteを使います
    }

     
    先日の高速割り込みを使わない場合は以下の通りです。

    #if 0 /* Unfortunately CC-RX doesn't allow multiple #pragma for one function. */
    #pragma interrupt r_Config_CMT3_cmi3_interrupt(vect=VECT(PERIB,INTB129))
    #endif
    #pragma inline_asm r_Config_CMT3_cmi3_interrupt
    void r_Config_CMT3_cmi3_interrupt(void)
    {
        /* Re-enable interrupt. */
        setpsw i

        /* Save the current super loop context. Be aware that the USP is used from now. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        setpsw u
        sub #8, sp
        push.l r1
        mov.l #_SuperLoopCurrentContextId, r1
        mov.b [r1], r1
        save r1

        /* Move PSW, PC from the interrupt stack to the current super loop's user stack. */
        mvfc isp, r2
        mov.l 4[r2], 8[sp]
        mov.l 0[r2], 4[sp]
        add #8, r2
        mvtc r2, isp

        /* Select the next super loop. */
        add #1, r1
        and #1, r1
        mov.l #_SuperLoopCurrentContextId, r2
        mov.b r1, [r2]

        /* Restore the next super loop context. Be aware that the USP is used here. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        rstr r1
        pop r1
        rte
    }

     
    以下、ハードウェアマニュアルの画面コピーです。

    RX660グループ ユーザーズマニュアル ハードウェア編
    R01UH0937JJ0100 Rev.1.00 Pages 2302 2022.03.18
    www.renesas.com/jp/ja/document/mah/rx660-group-users-manual-hardware



     

Reply
  • RXマイコンには昔から高速割り込みという機能がありますが、以下のハードウェア編の画面コピーの通り、割り込みの受け付け時に2クロック、割り込みからのリターン時に3クロック、それぞれ実行クロックが通常の割り込みより少なくなります。ものは試しとして、この機能を利用するコードの断片を考えてみました。残念ながら、高速割り込み機能で使用されるレジスタはレジスタ一括退避機能の対象に含まれておらず、結局のところは、メモリ(スタック)への退避とメモリ(スタック)からの復帰が必要になってしまい、落としどころとしては、今ひとつなコードになってしまいました。

    思い浮かんだコードの断片のネタ(ネタの状態ですので動作は試していません)

    以下の緑文字部分が高速割り込みを使う場合の落としどころな気がします、、、

    #if 0 /* Unfortunately CC-RX doesn't allow multiple #pragma for one function. */
    #pragma interrupt r_Config_CMT3_cmi3_interrupt(vect=VECT(PERIB,INTB129),fint)
    #endif
    #pragma inline_asm r_Config_CMT3_cmi3_interrupt
    void r_Config_CMT3_cmi3_interrupt(void)
    {
        /* Re-enable interrupt. */
        setpsw i

        /* Save the current super loop context. Be aware that the USP is used from now. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        setpsw u
        sub #8, sp
        push.l r1
        mov.l #_SuperLoopCurrentContextId, r1
        mov.b [r1], r1
        save r1

        /* Copy PSW, PC from BPSW, BPC registers to the current super loop's user stack. */
        mvfc bpsw, r2
        mov.l r2, 8[sp]
        mvfc bpc, r3
        mov.l r3, 4[sp]

        /* Select the next super loop. */
        add #1, r1
        and #1, r1
        mov.l #_SuperLoopCurrentContextId, r2
        mov.b r1, [r2]

        /* Restore the next super loop context. Be aware that the USP is used here. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        rstr r1
        pop r1
        rte ← rtfiでは無くてrteを使います
    }

     
    先日の高速割り込みを使わない場合は以下の通りです。

    #if 0 /* Unfortunately CC-RX doesn't allow multiple #pragma for one function. */
    #pragma interrupt r_Config_CMT3_cmi3_interrupt(vect=VECT(PERIB,INTB129))
    #endif
    #pragma inline_asm r_Config_CMT3_cmi3_interrupt
    void r_Config_CMT3_cmi3_interrupt(void)
    {
        /* Re-enable interrupt. */
        setpsw i

        /* Save the current super loop context. Be aware that the USP is used from now. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        setpsw u
        sub #8, sp
        push.l r1
        mov.l #_SuperLoopCurrentContextId, r1
        mov.b [r1], r1
        save r1

        /* Move PSW, PC from the interrupt stack to the current super loop's user stack. */
        mvfc isp, r2
        mov.l 4[r2], 8[sp]
        mov.l 0[r2], 4[sp]
        add #8, r2
        mvtc r2, isp

        /* Select the next super loop. */
        add #1, r1
        and #1, r1
        mov.l #_SuperLoopCurrentContextId, r2
        mov.b r1, [r2]

        /* Restore the next super loop context. Be aware that the USP is used here. */
        /* (As of today, the DPFPU registers are neither saved nor restored.) */
        rstr r1
        pop r1
        rte
    }

     
    以下、ハードウェアマニュアルの画面コピーです。

    RX660グループ ユーザーズマニュアル ハードウェア編
    R01UH0937JJ0100 Rev.1.00 Pages 2302 2022.03.18
    www.renesas.com/jp/ja/document/mah/rx660-group-users-manual-hardware



     

Children
No Data