cpu_a.asm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ;********************************************************************************************************
  2. ; uC/CPU
  3. ; CPU CONFIGURATION & PORT LAYER
  4. ;
  5. ; (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
  6. ;
  7. ; All rights reserved. Protected by international copyright laws.
  8. ;
  9. ; uC/CPU is provided in source form to registered licensees ONLY. It is
  10. ; illegal to distribute this source code to any third party unless you receive
  11. ; written permission by an authorized Micrium representative. Knowledge of
  12. ; the source code may NOT be used to develop a similar product.
  13. ;
  14. ; Please help us continue to provide the Embedded community with the finest
  15. ; software available. Your honesty is greatly appreciated.
  16. ;
  17. ; You can contact us at www.micrium.com.
  18. ;********************************************************************************************************
  19. ;********************************************************************************************************
  20. ;
  21. ; CPU PORT FILE
  22. ;
  23. ; ARM-Cortex-M3
  24. ; IAR C Compiler
  25. ;
  26. ; Filename : cpu_a.asm
  27. ; Version : V1.28.01.00
  28. ; Programmer(s) : JJL
  29. ;********************************************************************************************************
  30. ;********************************************************************************************************
  31. ; PUBLIC FUNCTIONS
  32. ;********************************************************************************************************
  33. EXPORT CPU_IntDis
  34. EXPORT CPU_IntEn
  35. EXPORT CPU_SR_Save
  36. EXPORT CPU_SR_Restore
  37. EXPORT CPU_CntLeadZeros
  38. EXPORT CPU_RevBits
  39. EXPORT CPU_WaitForInt
  40. EXPORT CPU_WaitForExcept
  41. ;********************************************************************************************************
  42. ; CODE GENERATION DIRECTIVES
  43. ;********************************************************************************************************
  44. ;RSEG CODE:CODE:NOROOT(2)
  45. ;THUMB
  46. PRESERVE8
  47. AREA |.text|,CODE,READONLY
  48. THUMB
  49. ;$PAGE
  50. ;********************************************************************************************************
  51. ; DISABLE and ENABLE INTERRUPTS
  52. ;
  53. ; Description: Disable/Enable interrupts.
  54. ;
  55. ; Prototypes : void CPU_IntDis(void);
  56. ; void CPU_IntEn (void);
  57. ;********************************************************************************************************
  58. CPU_IntDis
  59. CPSID I
  60. BX LR
  61. CPU_IntEn
  62. CPSIE I
  63. BX LR
  64. ;********************************************************************************************************
  65. ; CRITICAL SECTION FUNCTIONS
  66. ;
  67. ; Description : Disable/Enable interrupts by preserving the state of interrupts. Generally speaking, the
  68. ; state of the interrupt disable flag is stored in the local variable 'cpu_sr' & interrupts
  69. ; are then disabled ('cpu_sr' is allocated in all functions that need to disable interrupts).
  70. ; The previous interrupt state is restored by copying 'cpu_sr' into the CPU's status register.
  71. ;
  72. ; Prototypes : CPU_SR CPU_SR_Save (void);
  73. ; void CPU_SR_Restore(CPU_SR cpu_sr);
  74. ;
  75. ; Note(s) : (1) These functions are used in general like this :
  76. ;
  77. ; void Task (void *p_arg)
  78. ; {
  79. ; CPU_SR_ALLOC(); /* Allocate storage for CPU status register */
  80. ; :
  81. ; :
  82. ; CPU_CRITICAL_ENTER(); /* cpu_sr = CPU_SR_Save(); */
  83. ; :
  84. ; :
  85. ; CPU_CRITICAL_EXIT(); /* CPU_SR_Restore(cpu_sr); */
  86. ; :
  87. ; }
  88. ;********************************************************************************************************
  89. CPU_SR_Save
  90. MRS R0, PRIMASK ; Set prio int mask to mask all (except faults)
  91. CPSID I
  92. BX LR
  93. CPU_SR_Restore ; See Note #2.
  94. MSR PRIMASK, R0
  95. BX LR
  96. ;$PAGE
  97. ;********************************************************************************************************
  98. ; CPU_CntLeadZeros()
  99. ; COUNT LEADING ZEROS
  100. ;
  101. ; Description : Counts the number of contiguous, most-significant, leading zero bits before the first
  102. ; binary one bit in a data value.
  103. ;
  104. ; Prototype : CPU_DATA CPU_CntLeadZeros(CPU_DATA val);
  105. ;
  106. ; Argument(s) : val Data value to count leading zero bits.
  107. ;
  108. ; Return(s) : Number of contiguous, most-significant, leading zero bits in 'val'.
  109. ;
  110. ; Caller(s) : Application.
  111. ;
  112. ; This function is an INTERNAL CPU module function but MAY be called by application function(s).
  113. ;
  114. ; Note(s) : (1) If the argument is zero, the value 32 is returned.
  115. ;
  116. ; (2) MUST be implemented in cpu_a.asm if and only if CPU_CFG_LEAD_ZEROS_ASM_PRESENT is
  117. ; #define'd in 'cpu_cfg.h' or 'cpu.h'.
  118. ;********************************************************************************************************
  119. CPU_CntLeadZeros
  120. CLZ R0, R0 ; Count leading zeros
  121. BX LR
  122. ;********************************************************************************************************
  123. ; REVERSE BITS
  124. ;
  125. ; Description : Reverses the bits in the argument.
  126. ;
  127. ; Prototypes : CPU_DATA CPU_RevBits (CPU_DATA val)
  128. ;
  129. ; Argument(s) : val variable to reverse
  130. ;********************************************************************************************************
  131. CPU_RevBits
  132. RBIT R0, R0 ; Reverse bits
  133. BX LR
  134. ;$PAGE
  135. ;********************************************************************************************************
  136. ; WAIT FOR INTERRUPT
  137. ;
  138. ; Description : Enters sleep state, which will be exited when an interrupt is received.
  139. ;
  140. ; Prototypes : void CPU_WaitForInt (void)
  141. ;
  142. ; Argument(s) : none.
  143. ;********************************************************************************************************
  144. CPU_WaitForInt
  145. WFI ; Wait for interrupt
  146. BX LR
  147. ;********************************************************************************************************
  148. ; WAIT FOR EXCEPTION
  149. ;
  150. ; Description : Enters sleep state, which will be exited when an exception is received.
  151. ;
  152. ; Prototypes : void CPU_WaitForExcept (void)
  153. ;
  154. ; Argument(s) : none.
  155. ;********************************************************************************************************
  156. CPU_WaitForExcept
  157. WFE ; Wait for exception
  158. BX LR
  159. ;$PAGE
  160. ;********************************************************************************************************
  161. ; CPU ASSEMBLY PORT FILE END
  162. ;********************************************************************************************************
  163. END