2014年7月23日水曜日

マルチタスク2::SH7216 STM32F30x

hamayan さんのマルチタスク2を SH2A:SH7216 で動作させたので差分をメモします。

GR-SAKURAではじめる超お手軽マルチタスク2
http://hamayan.blog.so-net.ne.jp/2012-12-27

修正箇所はdispatcher_sh2a.srcのみ
 ;/****************************************************************************/  
 ;/* コンテキストの切り替え処理                        */  
 ;/*                                     */  
 ;/* designed by hamayan                           */  
 ;/*             Copyright (C) 2012 hamayan All Rights Reserved. */  
 ;/****************************************************************************/  
  .export _swi_ctx ;/*実行コンテキストの切替*/  
  .export _sta_ctx ;/*コンテキストをロードし、タスクを開始*/  
 ;/************************************************  
 ; コンテキストをロードし、タスクを開始  
 ; void sta_ctx(  
 ;  void *exe ) //実行コンテキストの保存先  
 ;************************************************/  
  .section P,CODE,ALIGN=4  
 _sta_ctx:  
  sts   pr,@-r15  ;/* pr 退避 */  
  mov.l  @r4,r15   ;/*スタックポインタ設定*/  
  movmu.l @r15+,r6  ;/*r6-r14,prを復帰*/  
  rts/n  
 ;/************************************************  
 ; 実行コンテキストの切替  
 ; void swi_ctx(  
 ;  void *pre,  //現在のコンテキストの保存先  
 ;  void *post) //切り替えるコンテキスト  
 ;************************************************/  
  .section P,CODE,ALIGN=4  
 _swi_ctx:  
  movmu.l r6,@-r15  ;/*r6-r14,prを退避。r6が最も若いアドレスになる*/  
  mov.l  r15,@r4   ;/*スタックポインタ保存*/  
  mov.l  @r5,r15   ;/*スタックポインタ復帰*/  
  movmu.l @r15+,r6  ;/*r6-r14,prを復帰*/  
  rts/n  
  .end  
 ;/****************************************************************************/  
 ;/* designed by hamayan                           */  
 ;/*             Copyright (C) 2012 hamayan All Rights Reserved. */  
 ;/****************************************************************************/  
mul_tsk.c::reg_tsk() を修正したくないので、
R6,R7は余分ですが、退避、回復させています。

また、 STM32F30x での GCC版 のコードもメモしておきます。

修正箇所はdispatcher_cm3.sのみ
 ;/****************************************************************************/  
 ;/* コンテキストの切り替え処理                        */  
 ;/*                                     */  
 ;/* designed by hamayan                           */  
 ;/*             Copyright (C) 2012 hamayan All Rights Reserved. */  
 ;/****************************************************************************/  
  .syntax unified  
  .arch armv7-m  
  .globl swi_ctx ;/*実行コンテキストの切替*/  
  .globl sta_ctx ;/*コンテキストをロードし、タスクを開始*/  
  .section .text  
 ;/************************************************  
 ; コンテキストをロードし、タスクを開始  
 ; void sta_ctx(  
 ;  void *exe ) //実行コンテキストの保存先  
 ;************************************************/  
 sta_ctx:  
  push {lr}     ;/*lrを退避*/  
  ldr r13,[r0]   ;/*スタックポインタ設定*/  
  pop {r4-r12,pc} ;/*r4-r12,pcを復帰*/  
 ;/************************************************  
 ; 実行コンテキストの切替  
 ; void swi_ctx(  
 ;  void *pre,  //現在のコンテキストの保存先  
 ;  void *post) //切り替えるコンテキスト  
 ;************************************************/  
 swi_ctx:  
  push {r4-r12,lr} ;/*r4-r12,lrを退避。r4が最も若いアドレスになる*/  
  str r13,[r0]   ;/*スタックポインタ保存*/  
  ldr r13,[r1]   ;/*スタックポインタ復帰*/  
  pop {r4-r12,pc} ;/*r4-r12,pcを復帰*/  
  .end  
 ;/****************************************************************************/  
 ;/* designed by hamayan                           */  
 ;/*             Copyright (C) 2012 hamayan All Rights Reserved. */  
 ;/****************************************************************************/  

STM32Fシリーズの統合開発環境はEm::Blocksが便利です。
デバッガーにSTLinkが使えるのがうれしい。
http://www.emblocks.org/web/

2014.07.23

0 件のコメント:

コメントを投稿