1/*
2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 *
27 */
28
29#if defined( __PIC24E__ ) || defined ( __PIC24F__ ) || defined( __PIC24FK__ ) || defined( __PIC24H__ )
30
31        .global _vPortYield
32        .extern _vTaskSwitchContext
33        .extern uxCriticalNesting
34
35_vPortYield:
36
37        PUSH    SR                      /* Save the SR used by the task.... */
38        PUSH    W0                      /* ....then disable interrupts. */
39        MOV     #32, W0
40        MOV     W0, SR
41        PUSH    W1                      /* Save registers to the stack. */
42        PUSH.D  W2
43        PUSH.D  W4
44        PUSH.D  W6
45        PUSH.D  W8
46        PUSH.D  W10
47        PUSH.D  W12
48        PUSH    W14
49        PUSH    RCOUNT
50        PUSH    TBLPAG
51
52        PUSH    CORCON
53        #ifdef __HAS_EDS__
54            PUSH    DSRPAG
55            PUSH    DSWPAG
56        #else
57            PUSH    PSVPAG
58        #endif /* __HAS_EDS__ */
59        MOV     _uxCriticalNesting, W0      /* Save the critical nesting counter for the task. */
60        PUSH    W0
61        MOV     _pxCurrentTCB, W0           /* Save the new top of stack into the TCB. */
62        MOV     W15, [W0]
63
64        call    _vTaskSwitchContext
65
66        MOV     _pxCurrentTCB, W0           /* Restore the stack pointer for the task. */
67        MOV     [W0], W15
68        POP     W0                          /* Restore the critical nesting counter for the task. */
69        MOV     W0, _uxCriticalNesting
70        #ifdef __HAS_EDS__
71            POP     DSWPAG
72            POP     DSRPAG
73        #else
74            POP     PSVPAG
75        #endif /* __HAS_EDS__ */
76        POP     CORCON
77        POP     TBLPAG
78        POP     RCOUNT                      /* Restore the registers from the stack. */
79        POP     W14
80        POP.D   W12
81        POP.D   W10
82        POP.D   W8
83        POP.D   W6
84        POP.D   W4
85        POP.D   W2
86        POP.D   W0
87        POP     SR
88
89        return
90
91        .end
92
93#endif /* defined( __PIC24E__ ) || defined ( __PIC24F__ ) || defined( __PIC24FK__ ) || defined( __PIC24H__ ) */
94