context.asm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * File : context.asm
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-04-09 fify the first version
  13. * 2010-04-19 fify rewrite rt_hw_interrupt_disable/enable fuction
  14. * 2010-04-20 fify move peripheral ISR to bsp/interrupts.s34
  15. *
  16. * For : Renesas M16C
  17. * Toolchain : IAR's EW for M16C v3.401
  18. */
  19. RSEG CSTACK
  20. RSEG ISTACK
  21. RSEG CODE(1)
  22. EXTERN rt_thread_switch_interrput_flag
  23. EXTERN rt_interrupt_from_thread
  24. EXTERN rt_interrupt_to_thread
  25. PUBLIC rt_hw_interrupt_disable
  26. PUBLIC rt_hw_interrupt_enable
  27. PUBLIC rt_hw_context_switch_to
  28. PUBLIC rt_hw_context_switch
  29. PUBLIC rt_hw_context_switch_interrupt
  30. PUBLIC os_context_switch
  31. rt_hw_interrupt_disable
  32. STC FLG, R0 ;fify 20100419
  33. FCLR I
  34. RTS
  35. rt_hw_interrupt_enable
  36. LDC R0, FLG ;fify 20100419
  37. RTS
  38. .EVEN
  39. os_context_switch:
  40. PUSHM R0,R1,R2,R3,A0,A1,SB,FB
  41. CMP.W #0,rt_thread_switch_interrput_flag
  42. JEQ exit
  43. MOV.W #0, rt_thread_switch_interrput_flag
  44. MOV.W rt_interrupt_from_thread, A0
  45. STC ISP, [A0]
  46. MOV.W rt_interrupt_to_thread, A0
  47. LDC [A0], ISP
  48. exit
  49. POPM R0,R1,R2,R3,A0,A1,SB,FB ; Restore registers from the new task's stack
  50. REIT ; Return from interrup
  51. /*
  52. * void rt_hw_context_switch_to(rt_uint32 to);
  53. * r0 --> to
  54. * this fucntion is used to perform the first thread switch
  55. */
  56. rt_hw_context_switch_to
  57. MOV.W R0, A0
  58. LDC [A0], ISP
  59. POPM R0,R1,R2,R3,A0,A1,SB,FB
  60. REIT
  61. rt_hw_context_switch
  62. CMP.W #1,rt_thread_switch_interrput_flag
  63. JEQ jump1
  64. MOV.W #1,rt_thread_switch_interrput_flag
  65. MOV.W R0, rt_interrupt_from_thread
  66. jump1
  67. MOV.W R1, rt_interrupt_to_thread
  68. INT #0
  69. RTS
  70. rt_hw_context_switch_interrupt
  71. CMP.W #1,rt_thread_switch_interrput_flag
  72. JEQ jump
  73. MOV.W #1,rt_thread_switch_interrput_flag
  74. MOV.W R0, rt_interrupt_from_thread
  75. jump
  76. MOV.W R1, rt_interrupt_to_thread
  77. RTS
  78. END