1 /*
2 * @file Gate.c
3 *
4 * @brief gate wrapper implementation
5 *
6 *
7 * @ver 02.00.00.46_alpha1
8 *
9 * ============================================================================
10 *
11 * Copyright (c) 2008-2009, Texas Instruments Incorporated
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * * Neither the name of Texas Instruments Incorporated nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
32 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * Contact information for paper mail:
40 * Texas Instruments
41 * Post Office Box 655303
42 * Dallas, Texas 75265
43 * Contact information:
44 * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
45 * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
46 * ============================================================================
47 *
48 */
52 /* Standard headers */
53 #include <ti/syslink/Std.h>
55 /* OSAL & Utils headers */
56 #include <ti/syslink/utils/Trace.h>
58 /* Module level headers */
59 #include <ti/syslink/utils/IGateProvider.h>
60 #include <ti/syslink/utils/Gate.h>
62 #ifdef __QNX__
63 #include <sys/neutrino.h>
64 static intrspin_t spinlock;
65 #endif
68 #if defined (__cplusplus)
69 extern "C" {
70 #endif
72 /* Structure defining internal object for the Gate Peterson.*/
73 struct Gate_Object {
74 IGateProvider_SuperObject; /* For inheritance from IGateProvider */
75 };
77 /* Function to enter a Gate */
78 IArg Gate_enterSystem (void)
79 {
80 unsigned long flags;
82 #ifndef __QNX__
83 local_irq_save (flags);
84 #else
85 // in the kernel version of this, we really never call any system calls while the
86 // lock is held, so we can actually just do a InterruptLock
87 InterruptLock(&spinlock);
88 flags = 0;
89 #endif
91 return (IArg)flags;
92 }
95 /* Function to leave a Gate */
96 Void Gate_leaveSystem (IArg key)
97 {
98 #ifndef __QNX__
99 local_irq_restore ((unsigned long) key);
100 #else
101 // in the kernel version of this, we just do a InterruptUnlock
102 InterruptUnlock(&spinlock);
103 #endif
104 }
106 /* Match with IGateProvider */
107 static inline IArg _Gate_enterSystem (struct Gate_Object * obj)
108 {
109 (Void) obj;
110 return Gate_enterSystem ();
111 }
113 /* Match with IGateProvider */
114 static inline Void _Gate_leaveSystem (struct Gate_Object * obj, IArg key)
115 {
116 (Void) obj;
117 Gate_leaveSystem (key);
118 }
120 struct Gate_Object Gate_systemObject =
121 {
122 .enter = (IGateProvider_ENTER)_Gate_enterSystem,
123 .leave = (IGateProvider_LEAVE)_Gate_leaveSystem,
124 };
126 IGateProvider_Handle Gate_systemHandle = (IGateProvider_Handle)&Gate_systemObject;
128 #if defined (__cplusplus)
129 }
130 #endif /* defined (__cplusplus) */