1 /****************************************************************************
2  *
3  *  Copyright (c) 2023, Michael Becker (michael.f.becker@gmail.com)
4  *
5  *  This file is part of the FreeRTOS Add-ons project.
6  *
7  *  Source Code:
8  *  https://github.com/michaelbecker/freertos-addons
9  *
10  *  Project Page:
11  *  http://michaelbecker.github.io/freertos-addons/
12  *
13  *  On-line Documentation:
14  *  http://michaelbecker.github.io/freertos-addons/docs/html/index.html
15  *
16  *  MIT License
17  *
18  *  Permission is hereby granted, free of charge, to any person obtaining a
19  *  copy of this software and associated documentation files
20  *  (the "Software"), to deal in the Software without restriction, including
21  *  without limitation the rights to use, copy, modify, merge, publish,
22  *  distribute, sublicense, and/or sell copies of the Software, and to
23  *  permit persons to whom the Software is furnished to do so,subject to the
24  *  following conditions:
25  *
26  *  + The above copyright notice and this permission notice shall be included
27  *    in all copies or substantial portions of the Software.
28  *  + Credit is appreciated, but not required, if you find this project
29  *    useful enough to include in your application, product, device, etc.
30  *
31  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32  *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35  *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36  *  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37  *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  *
39  ***************************************************************************/
40 /*
41  *  Copyright 2023-2024 NXP
42  *
43  *  SPDX-License-Identifier: BSD-3-Clause
44  *
45  */
46 
47 #include <stdlib.h>
48 #include "stack_simple.h"
49 
InitStack(Stack_t * Stack)50 void InitStack(Stack_t *Stack)
51 {
52     Stack->Count = 0;
53     SlInitHead(&Stack->Head);
54 }
55 
PushOnStack(Stack_t * Stack,SlNode_t * Node)56 void PushOnStack(Stack_t *Stack, SlNode_t *Node)
57 {
58     if (!Stack)
59         return;
60 
61     if (!Node)
62         return;
63 
64     SlAddNodeToHead(&Stack->Head, Node);
65     Stack->Count++;
66 }
67 
PopOffStack(Stack_t * Stack)68 SlNode_t *PopOffStack(Stack_t *Stack)
69 {
70     SlNode_t *Node;
71 
72     if (!Stack)
73         return NULL;
74 
75     if (Stack->Count == 0)
76     {
77         return NULL;
78     }
79     else
80     {
81         Stack->Count--;
82     }
83 
84     Node = SlRemoveNodeFromHead(&Stack->Head);
85 
86     return Node;
87 }
88