1/***************************************************************************//**
2* \file cy_syslib_ext.s
3* \version 2.70
4*
5* \brief Assembly routines for IAR Embedded Workbench IDE.
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    SECTION .text:CODE:ROOT(4)
26    PUBLIC Cy_SysLib_DelayCycles
27    PUBLIC Cy_SysLib_EnterCriticalSection
28    PUBLIC Cy_SysLib_ExitCriticalSection
29    THUMB
30
31
32/*******************************************************************************
33* Function Name: Cy_SysLib_DelayCycles
34****************************************************************************//**
35*
36* Delays for the specified number of cycles.
37*
38* \param uint32_t cycles: The number of cycles to delay.
39*
40*******************************************************************************/
41/* void Cy_SysLib_DelayCycles(uint32_t cycles) */
42
43Cy_SysLib_DelayCycles:
44    ADDS r0, r0, #2
45    LSRS r0, r0, #2
46    BEQ Cy_DelayCycles_done
47Cy_DelayCycles_loop:
48    ADDS r0, r0, #1
49    SUBS r0, r0, #2
50    BNE Cy_DelayCycles_loop
51    NOP
52Cy_DelayCycles_done:
53    BX lr
54
55
56/*******************************************************************************
57* Function Name: Cy_SysLib_EnterCriticalSection
58****************************************************************************//**
59*
60* Cy_SysLib_EnterCriticalSection disables interrupts and returns a value
61* indicating whether interrupts were previously enabled.
62*
63* Note Implementation of Cy_SysLib_EnterCriticalSection manipulates the IRQ
64* enable bit with interrupts still enabled. The test and set of the interrupt
65* bits are not atomic. Therefore, to avoid corrupting processor state, it must
66* be the policy that all interrupt routines restore the interrupt enable bits
67* as they were found on entry.
68*
69* \return Returns 0 if interrupts were previously enabled or 1 if interrupts
70* were previously disabled.
71*
72*******************************************************************************/
73/* uint8_t Cy_SysLib_EnterCriticalSection(void) */
74
75Cy_SysLib_EnterCriticalSection:
76    MRS r0, PRIMASK         ; Save and return an interrupt state.
77    CPSID I                 ; Disable interrupts.
78    BX lr
79
80/*******************************************************************************
81* Function Name: Cy_SysLib_ExitCriticalSection
82****************************************************************************//**
83*
84* Cy_SysLib_ExitCriticalSection re-enables the interrupts if they were enabled
85* before Cy_SysLib_EnterCriticalSection was called. The argument should be the
86* value returned from Cy_SysLib_EnterCriticalSection.
87*
88*  \param uint8_t savedIntrStatus:
89*   The saved interrupt status returned by the
90*   \ref Cy_SysLib_EnterCriticalSection().
91*
92*******************************************************************************/
93/* void Cy_SysLib_ExitCriticalSection(uint8_t savedIntrStatus) */
94
95Cy_SysLib_ExitCriticalSection:
96    MSR PRIMASK, r0         ; Restore the interrupt state.
97    BX lr
98
99    END
100