context.asm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. *
  15. * For : Renesas M16C
  16. * Toolchain : IAR's EW for M16C v3.401
  17. */
  18. RSEG CSTACK
  19. RSEG ISTACK
  20. RSEG CODE(1)
  21. EXTERN rt_thread_switch_interrput_flag
  22. EXTERN rt_interrupt_from_thread
  23. EXTERN rt_interrupt_to_thread
  24. EXTERN rt_interrupt_enter
  25. EXTERN rt_tick_increase
  26. EXTERN rt_interrupt_leave
  27. EXTERN u0rec_handler
  28. PUBLIC rt_hw_interrupt_disable
  29. PUBLIC rt_hw_interrupt_enable
  30. PUBLIC rt_hw_context_switch_to
  31. PUBLIC rt_hw_context_switch
  32. PUBLIC rt_hw_context_switch_interrupt
  33. PUBLIC rt_hw_timer_handler
  34. PUBLIC rt_hw_uart0_receive_handler
  35. PUBLIC os_context_switch
  36. rt_hw_interrupt_disable
  37. STC FLG, R0 ;fify 20100419
  38. FCLR I
  39. RTS
  40. rt_hw_interrupt_enable
  41. LDC R0, FLG ;fify 20100419
  42. RTS
  43. .EVEN
  44. os_context_switch:
  45. PUSHM R0,R1,R2,R3,A0,A1,SB,FB
  46. CMP.W #0,rt_thread_switch_interrput_flag
  47. JEQ exit
  48. MOV.W #0, rt_thread_switch_interrput_flag
  49. MOV.W rt_interrupt_from_thread, A0
  50. STC ISP, [A0]
  51. MOV.W rt_interrupt_to_thread, A0
  52. LDC [A0], ISP
  53. exit
  54. POPM R0,R1,R2,R3,A0,A1,SB,FB ; Restore registers from the new task's stack
  55. REIT ; Return from interrup
  56. /*
  57. * void rt_hw_context_switch_to(rt_uint32 to);
  58. * r0 --> to
  59. * this fucntion is used to perform the first thread switch
  60. */
  61. rt_hw_context_switch_to
  62. MOV.W R0, A0
  63. LDC [A0], ISP
  64. POPM R0,R1,R2,R3,A0,A1,SB,FB
  65. REIT
  66. rt_hw_context_switch
  67. CMP.W #1,rt_thread_switch_interrput_flag
  68. JEQ jump1
  69. MOV.W #1,rt_thread_switch_interrput_flag
  70. MOV.W R0, rt_interrupt_from_thread
  71. jump1
  72. MOV.W R1, rt_interrupt_to_thread
  73. INT #0
  74. RTS
  75. rt_hw_context_switch_interrupt
  76. CMP.W #1,rt_thread_switch_interrput_flag
  77. JEQ jump
  78. MOV.W #1,rt_thread_switch_interrput_flag
  79. MOV.W R0, rt_interrupt_from_thread
  80. jump
  81. MOV.W R1, rt_interrupt_to_thread
  82. RTS
  83. rt_hw_context_switch_interrupt_do
  84. MOV.W #0, rt_thread_switch_interrput_flag
  85. MOV.W rt_interrupt_from_thread, A0
  86. STC ISP, [A0]
  87. MOV.W rt_interrupt_to_thread, A0
  88. LDC [A0], ISP
  89. POPM R0,R1,R2,R3,A0,A1,SB,FB ; Restore all processor registers from the new task's stack
  90. REIT
  91. .EVEN
  92. rt_hw_timer_handler:
  93. PUSHM R0,R1,R2,R3,A0,A1,SB,FB ; Save current task's registers
  94. JSR rt_interrupt_enter
  95. JSR rt_tick_increase
  96. JSR rt_interrupt_leave
  97. CMP.W #1,rt_thread_switch_interrput_flag
  98. JEQ rt_hw_context_switch_interrupt_do
  99. POPM R0,R1,R2,R3,A0,A1,SB,FB ; Restore current task's registers
  100. REIT ; Return from interrup
  101. .EVEN
  102. rt_hw_uart0_receive_handler:
  103. PUSHM R0,R1,R2,R3,A0,A1,SB,FB ; Save current task's registers
  104. JSR rt_interrupt_enter
  105. JSR u0rec_handler
  106. JSR rt_interrupt_leave
  107. CMP.W #1, rt_thread_switch_interrput_flag
  108. JEQ rt_hw_context_switch_interrupt_do
  109. POPM R0,R1,R2,R3,A0,A1,SB,FB ; Restore current task's registers
  110. REIT ; Return from interrup
  111. END