1 /*
2 * @file MessageQCopy.c
3 *
4 * @brief User side MessageQCopy Manager
5 *
6 *
7 * @ver 02.00.00.53_alpha2
8 *
9 * ============================================================================
10 *
11 * Copyright (c) 2011-2015, 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 */
51 /* Standard headers*/
52 #include <ti/syslink/Std.h>
54 /* TBD: this should be removed as getpid should made as osal */
55 #include <unistd.h>
57 /* Osal headers*/
58 #include <ti/syslink/utils/Trace.h>
60 /* MessageQCopy Headers */
61 //#include <ti/ipc/MessageQCopy.h>
62 //#include <_MessageQCopy.h>
63 #include <MessageQCopyDrvDefs.h>
64 #include <MessageQCopyDrv.h>
67 #if defined (__cplusplus)
68 extern "C" {
69 #endif /* defined (__cplusplus) */
72 /* =============================================================================
73 * Macros and types
74 * =============================================================================
75 */
76 /*!
77 * @brief MessageQCopy Module state object
78 */
79 typedef struct MessageQCopy_ModuleObject_tag {
80 UInt32 setupRefCount;
81 /*!< Reference count for number of times setup/destroy were called in this
82 process. */
83 } MessageQCopy_ModuleObject;
86 /* =============================================================================
87 * Globals
88 * =============================================================================
89 */
90 /*!
91 * @var MessageQCopy_state
92 *
93 * @brief MessageQCopy state object variable
94 */
95 #if !defined(IPC_BUILD_DEBUG)
96 static
97 #endif /* if !defined(IPC_BUILD_DEBUG) */
98 MessageQCopy_ModuleObject MessageQCopy_state =
99 {
100 .setupRefCount = 0
101 };
103 /*!
104 * @var MessageQCopy_module
105 *
106 * @brief Pointer to the MessageQCopy module state.
107 */
108 #if !defined(IPC_BUILD_DEBUG)
109 static
110 #endif /* if !defined(IPC_BUILD_DEBUG) */
111 MessageQCopy_ModuleObject * MessageQCopy_module = &MessageQCopy_state;
114 /* =============================================================================
115 * APIs
116 * =============================================================================
117 */
118 /* Function to setup the MessageQCopy module. */
119 Int
120 MessageQCopy_setup (const MessageQCopy_Config * config)
121 {
122 Int status = MessageQCopy_S_SUCCESS;
124 GT_1trace (curTrace, GT_ENTER, "MessageQCopy_setup", config);
126 /* TBD: Protect from multiple threads. */
127 MessageQCopy_module->setupRefCount++;
128 /* This is needed at runtime so should not be in IPC_BUILD_OPTIMIZE. */
129 if (MessageQCopy_module->setupRefCount > 1) {
130 status = MessageQCopy_S_ALREADYSETUP;
131 GT_1trace (curTrace,
132 GT_1CLASS,
133 "MessageQCopy module has been already setup in this process.\n"
134 " RefCount: [%d]\n",
135 MessageQCopy_module->setupRefCount);
136 }
137 else {
138 /* Open the driver handle. */
139 status = MessageQCopyDrv_open ();
140 #if !defined(IPC_BUILD_OPTIMIZE)
141 if (status < 0) {
142 GT_setFailureReason (curTrace,
143 GT_4CLASS,
144 "MessageQCopy_setup",
145 status,
146 "Failed to open driver handle!");
147 }
148 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
149 }
151 GT_1trace (curTrace, GT_LEAVE, "MessageQCopy_setup", status);
153 return status;
154 }
157 /* Function to destroy the MessageQCopy module. */
158 Int
159 MessageQCopy_destroy (void)
160 {
161 Int status = MessageQCopy_S_SUCCESS;
163 GT_0trace (curTrace, GT_ENTER, "MessageQCopy_destroy");
165 /* TBD: Protect from multiple threads. */
166 MessageQCopy_module->setupRefCount--;
167 /* This is needed at runtime so should not be in IPC_BUILD_OPTIMIZE. */
168 if (MessageQCopy_module->setupRefCount >= 1) {
169 status = MessageQCopy_S_ALREADYSETUP;
170 GT_1trace (curTrace,
171 GT_1CLASS,
172 "MessageQCopy module has been already setup in this process.\n"
173 " RefCount: [%d]\n",
174 MessageQCopy_module->setupRefCount);
175 }
176 else {
177 /* Close the driver handle. */
178 MessageQCopyDrv_close ();
179 }
181 GT_1trace (curTrace, GT_LEAVE, "MessageQCopy_destroy", status);
183 return status;
184 }
187 /*!
188 * @brief This function runs a MessgeQ test in the kernel.
189 *
190 * @param testNo Test number to run.
191 *
192 * @return MessageQCopy_S_SUCCESS Success.
193 * MessageQCopy_E_OSFAILURE Failure in ioctl call.
194 *
195 * @sa MessageQCopyDrv_ioctl
196 */
197 Int
198 MessageQCopy_runtest (UInt32 testNo)
200 {
201 Int32 status = MessageQCopy_S_SUCCESS;
202 MessageQCopyDrv_CmdArgs cmdArgs;
204 GT_1trace (curTrace, GT_ENTER, "MessageQCopy_runtest",
205 testNo);
207 cmdArgs.args.runtest.testNo = testNo;
209 status = MessageQCopyDrv_ioctl (CMD_MESSAGEQCOPY_RUNTEST, &cmdArgs);
210 #if !defined(IPC_BUILD_OPTIMIZE)
211 if (status < 0) {
212 GT_setFailureReason (curTrace,
213 GT_4CLASS,
214 "MessageQCopy_runtest",
215 status,
216 "API (through IOCTL) failed!");
217 }
218 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
220 GT_1trace (curTrace, GT_LEAVE, "MessageQCopy_runtest", status);
222 /*! @retval MessageQCopy_S_SUCCESS Operation successful */
223 return (status);
224 }
226 #if defined (__cplusplus)
227 }
228 #endif /* defined (__cplusplus) */