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