1/***************************************************************************//**
2* \file cy_syslib_ext.S
3* \version 2.70
4*
5* \brief Assembly routines for Apple Clang.
6*
7********************************************************************************
8* \copyright
9* Copyright 2016-2020 Cypress Semiconductor Corporation
10* SPDX-License-Identifier: Apache-2.0
11*
12* Licensed under the Apache License, Version 2.0 (the "License");
13* you may not use this file except in compliance with the License.
14* You may obtain a copy of the License at
15*
16*     http://www.apache.org/licenses/LICENSE-2.0
17*
18* Unless required by applicable law or agreed to in writing, software
19* distributed under the License is distributed on an "AS IS" BASIS,
20* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21* See the License for the specific language governing permissions and
22* limitations under the License.
23*******************************************************************************/
24
25.syntax unified
26.text
27.thumb
28
29
30/*******************************************************************************
31* Function Name: Cy_SysLib_DelayCycles
32****************************************************************************//**
33*
34* Delays for the specified number of cycles.
35*
36* \param uint32_t cycles: The number of cycles to delay.
37*
38*******************************************************************************/
39/* void Cy_SysLib_DelayCycles(uint32_t cycles) */
40.align 3                    /* Align to 8 byte boundary (2^n) */
41.global _Cy_SysLib_DelayCycles
42.thumb_func
43
44_Cy_SysLib_DelayCycles:      /* cycles bytes */
45    ADDS r0, r0, #2         /*    1    2    Round to nearest multiple of 4 */
46    LSRS r0, r0, #2         /*    1    2    Divide by 4 and set flags */
47    BEQ Cy_DelayCycles_done /*    2    2    Skip if 0 */
48
49    .align 2                    /* Align to 8 byte boundary (2^n) */
50Cy_DelayCycles_loop:
51    ADDS r0, r0, #1         /*    1    2    Increment counter */
52    SUBS r0, r0, #2         /*    1    2    Decrement counter by 2 */
53    BNE Cy_DelayCycles_loop /*   (1)2  2    2 CPU cycles (if branch is taken) */
54    NOP                     /*    1    2    Loop alignment padding */
55
56    .align 2                    /* Align to 8 byte boundary (2^n) */
57Cy_DelayCycles_done:
58    NOP                     /*    1    2    Loop alignment padding */
59    BX lr                   /*    3    2 */
60
61
62/*******************************************************************************
63* Function Name: Cy_SysLib_EnterCriticalSection
64****************************************************************************//**
65*
66* Cy_SysLib_EnterCriticalSection disables interrupts and returns a value
67* indicating whether interrupts were previously enabled.
68*
69* Note Implementation of Cy_SysLib_EnterCriticalSection manipulates the IRQ
70* enable bit with interrupts still enabled.
71*
72* \return Returns 0 if interrupts were previously enabled or 1 if interrupts
73* were previously disabled.
74*
75*******************************************************************************/
76/* uint8_t Cy_SysLib_EnterCriticalSection(void) */
77.global _Cy_SysLib_EnterCriticalSection
78.thumb_func
79
80_Cy_SysLib_EnterCriticalSection:
81    MRS r0, PRIMASK         /* Save and return interrupt state */
82    cpsid i                 /* Disable interrupts */
83    BX lr
84
85
86/*******************************************************************************
87* Function Name: Cy_SysLib_ExitCriticalSection
88****************************************************************************//**
89*
90*  Re-enables interrupts if they were enabled before
91*  Cy_SysLib_EnterCriticalSection() was called. The argument should be the value
92*  returned from \ref Cy_SysLib_EnterCriticalSection().
93*
94*  \param uint8_t savedIntrStatus:
95*   Saved interrupt status returned by the \ref Cy_SysLib_EnterCriticalSection().
96*
97*******************************************************************************/
98/* void Cy_SysLib_ExitCriticalSection(uint8_t savedIntrStatus) */
99.global _Cy_SysLib_ExitCriticalSection
100.thumb_func
101
102_Cy_SysLib_ExitCriticalSection:
103    MSR PRIMASK, r0         /* Restore interrupt state */
104    BX lr
105
106.end
107
108/* [] END OF FILE */
109