CyBootAsmGnu.s 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*******************************************************************************
  2. * File Name: CyBootAsmGnu.s
  3. * Version 4.0
  4. *
  5. * Description:
  6. * Assembly routines for GNU as.
  7. *
  8. ********************************************************************************
  9. * Copyright 2010-2013, Cypress Semiconductor Corporation. All rights reserved.
  10. * You may use this file only in accordance with the license, terms, conditions,
  11. * disclaimers, and limitations in the end user license agreement accompanying
  12. * the software package with which this file was provided.
  13. *******************************************************************************/
  14. .include "cyfittergnu.inc"
  15. .syntax unified
  16. .text
  17. .thumb
  18. /*******************************************************************************
  19. * Function Name: CyDelayCycles
  20. ********************************************************************************
  21. *
  22. * Summary:
  23. * Delays for the specified number of cycles.
  24. *
  25. * Parameters:
  26. * uint32 cycles: number of cycles to delay.
  27. *
  28. * Return:
  29. * None
  30. *
  31. *******************************************************************************/
  32. /* void CyDelayCycles(uint32 cycles) */
  33. .align 3 /* Align to 8 byte boundary (2^n) */
  34. .global CyDelayCycles
  35. .func CyDelayCycles, CyDelayCycles
  36. .type CyDelayCycles, %function
  37. .thumb_func
  38. CyDelayCycles: /* cycles bytes */
  39. /* If ICache is enabled */
  40. .ifeq CYDEV_INSTRUCT_CACHE_ENABLED - 1
  41. ADDS r0, r0, #2 /* 1 2 Round to nearest multiple of 4 */
  42. LSRS r0, r0, #2 /* 1 2 Divide by 4 and set flags */
  43. BEQ CyDelayCycles_done /* 2 2 Skip if 0 */
  44. NOP /* 1 2 Loop alignment padding */
  45. CyDelayCycles_loop:
  46. SUBS r0, r0, #1 /* 1 2 */
  47. MOV r0, r0 /* 1 2 Pad loop to power of two cycles */
  48. BNE CyDelayCycles_loop /* 2 2 */
  49. CyDelayCycles_done:
  50. BX lr /* 3 2 */
  51. .else
  52. CMP r0, #20 /* 1 2 If delay is short - jump to cycle */
  53. BLS CyDelayCycles_short /* 1 2 */
  54. PUSH {r1} /* 2 2 PUSH r1 to stack */
  55. MOVS r1, #1 /* 1 2 */
  56. SUBS r0, r0, #20 /* 1 2 Subtract overhead */
  57. LDR r1,=CYREG_CACHE_CC_CTL/* 2 2 Load flash wait cycles value */
  58. LDRB r1, [r1, #0] /* 2 2 */
  59. ANDS r1, #0xC0 /* 1 2 */
  60. LSRS r1, r1, #6 /* 1 2 */
  61. PUSH {r2} /* 1 2 PUSH r2 to stack */
  62. LDR r2, =cy_flash_cycles /* 2 2 */
  63. LDRB r1, [r2, r1] /* 2 2 */
  64. POP {r2} /* 2 2 POP r2 from stack */
  65. NOP /* 1 2 Alignment padding */
  66. NOP /* 1 2 Alignment padding */
  67. NOP /* 1 2 Alignment padding */
  68. CyDelayCycles_loop:
  69. SBCS r0, r0, r1 /* 1 2 */
  70. BPL CyDelayCycles_loop /* 3 2 */
  71. NOP /* 1 2 Loop alignment padding */
  72. NOP /* 1 2 Loop alignment padding */
  73. POP {r1} /* 2 2 POP r1 from stack */
  74. CyDelayCycles_done:
  75. BX lr /* 3 2 */
  76. NOP /* 1 2 Alignment padding */
  77. NOP /* 1 2 Alignment padding */
  78. CyDelayCycles_short:
  79. SBCS r0, r0, #4 /* 1 2 */
  80. BPL CyDelayCycles_short /* 3 2 */
  81. BX lr /* 3 2 */
  82. cy_flash_cycles:
  83. .byte 0x0B
  84. .byte 0x05
  85. .byte 0x07
  86. .byte 0x09
  87. .endif
  88. .endfunc
  89. /*******************************************************************************
  90. * Function Name: CyEnterCriticalSection
  91. ********************************************************************************
  92. *
  93. * Summary:
  94. * CyEnterCriticalSection disables interrupts and returns a value indicating
  95. * whether interrupts were previously enabled (the actual value depends on
  96. * whether the device is PSoC 3 or PSoC 5).
  97. *
  98. * Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit
  99. * with interrupts still enabled. The test and set of the interrupt bits is not
  100. * atomic; this is true for both PSoC 3 and PSoC 5. Therefore, to avoid
  101. * corrupting processor state, it must be the policy that all interrupt routines
  102. * restore the interrupt enable bits as they were found on entry.
  103. *
  104. * Parameters:
  105. * None
  106. *
  107. * Return:
  108. * uint8
  109. * Returns 0 if interrupts were previously enabled or 1 if interrupts
  110. * were previously disabled.
  111. *
  112. *******************************************************************************/
  113. /* uint8 CyEnterCriticalSection(void) */
  114. .global CyEnterCriticalSection
  115. .func CyEnterCriticalSection, CyEnterCriticalSection
  116. .type CyEnterCriticalSection, %function
  117. .thumb_func
  118. CyEnterCriticalSection:
  119. MRS r0, PRIMASK /* Save and return interrupt state */
  120. CPSID I /* Disable interrupts */
  121. BX lr
  122. .endfunc
  123. /*******************************************************************************
  124. * Function Name: CyExitCriticalSection
  125. ********************************************************************************
  126. *
  127. * Summary:
  128. * CyExitCriticalSection re-enables interrupts if they were enabled before
  129. * CyEnterCriticalSection was called. The argument should be the value returned
  130. * from CyEnterCriticalSection.
  131. *
  132. * Parameters:
  133. * uint8 savedIntrStatus:
  134. * Saved interrupt status returned by the CyEnterCriticalSection function.
  135. *
  136. * Return:
  137. * None
  138. *
  139. *******************************************************************************/
  140. /* void CyExitCriticalSection(uint8 savedIntrStatus) */
  141. .global CyExitCriticalSection
  142. .func CyExitCriticalSection, CyExitCriticalSection
  143. .type CyExitCriticalSection, %function
  144. .thumb_func
  145. CyExitCriticalSection:
  146. MSR PRIMASK, r0 /* Restore interrupt state */
  147. BX lr
  148. .endfunc
  149. .end
  150. /* [] END OF FILE */