fc4e7bcc4c6a3ea4eca0513ed12de689f424879a
1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * ======== NotifyCircSetup.c ========
34 */
35 #include <xdc/std.h>
36 #include <xdc/runtime/Error.h>
38 #include <ti/sdo/ipc/notifyDrivers/NotifyDriverCirc.h>
39 #include <ti/sdo/ipc/_Notify.h>
40 #include <ti/sdo/utils/_MultiProc.h>
42 #include "package/internal/NotifyCircSetup.xdc.h"
44 /*
45 *************************************************************************
46 * Module functions
47 *************************************************************************
48 */
50 /*!
51 * ======== NotifyCircSetup_attach ========
52 * Initialize interrupt
53 */
54 Int NotifyCircSetup_attach(UInt16 remoteProcId, Ptr sharedAddr)
55 {
56 NotifyDriverCirc_Params notifyShmParams;
57 Error_Block eb;
58 Int status = Notify_S_SUCCESS;
60 #ifdef xdc_target__isaCompatible_64
61 NotifyDriverCirc_Handle armDriverHandle0, armDriverHandle1;
62 UInt armProcId = 1 - MultiProc_self();
64 /* Initialize the error block */
65 Error_init(&eb);
67 /*
68 * Setup the notify driver to the ARM (Line 0)
69 */
70 NotifyDriverCirc_Params_init(¬ifyShmParams);
71 notifyShmParams.localIntId = NotifyCircSetup_dspRecvIntId0;
72 notifyShmParams.remoteIntId = NotifyCircSetup_armRecvIntId0;
73 notifyShmParams.intVectorId = NotifyCircSetup_dspIntVectId0;
74 notifyShmParams.remoteProcId = armProcId;
75 notifyShmParams.sharedAddr = sharedAddr;
77 armDriverHandle0 = NotifyDriverCirc_create(¬ifyShmParams, &eb);
78 if (armDriverHandle0 == NULL) {
79 return (Notify_E_FAIL);
80 }
82 ti_sdo_ipc_Notify_create(NotifyDriverCirc_Handle_upCast(armDriverHandle0),
83 armProcId,
84 0,
85 NULL,
86 &eb);
87 if (Error_check(&eb)) {
88 /* Delete the driver and then return */
89 NotifyDriverCirc_delete(&armDriverHandle0);
90 return (Notify_E_FAIL);
91 }
93 if (!NotifyCircSetup_useSecondLine) {
94 return (status);
95 }
96 /*
97 * Setup the notify driver to the ARM (Line 1)
98 */
99 NotifyDriverCirc_Params_init(¬ifyShmParams);
100 notifyShmParams.localIntId = NotifyCircSetup_dspRecvIntId1;
101 notifyShmParams.remoteIntId = NotifyCircSetup_armRecvIntId1;
102 notifyShmParams.intVectorId = NotifyCircSetup_dspIntVectId1;
103 notifyShmParams.remoteProcId = armProcId;
104 notifyShmParams.sharedAddr = (Ptr)((UInt32)sharedAddr +
105 NotifyDriverCirc_sharedMemReq(¬ifyShmParams));
106 armDriverHandle1 = NotifyDriverCirc_create(¬ifyShmParams, &eb);
108 if (armDriverHandle1 == NULL) {
109 return (Notify_E_FAIL);
110 }
112 ti_sdo_ipc_Notify_create(NotifyDriverCirc_Handle_upCast(armDriverHandle1),
113 armProcId,
114 1,
115 NULL,
116 &eb);
117 if (Error_check(&eb)) {
118 /* Delete the driver and then return */
119 NotifyDriverCirc_delete(&armDriverHandle1);
120 return (Notify_E_FAIL);
121 }
123 #else /* ARM code */
124 NotifyDriverCirc_Handle dspDriverHandle0, dspDriverHandle1;
125 UInt dspProcId = 1 - MultiProc_self();
127 /* Initialize the error block */
128 Error_init(&eb);
130 /*
131 * Setup the notify driver to the DSP (Line 0)
132 */
133 NotifyDriverCirc_Params_init(¬ifyShmParams);
134 notifyShmParams.localIntId = NotifyCircSetup_armRecvIntId0;
135 notifyShmParams.remoteIntId = NotifyCircSetup_dspRecvIntId0;
136 notifyShmParams.remoteProcId = dspProcId;
137 notifyShmParams.sharedAddr = sharedAddr;
139 dspDriverHandle0 = NotifyDriverCirc_create(¬ifyShmParams, &eb);
140 if (dspDriverHandle0 == NULL) {
141 return (Notify_E_FAIL);
142 }
144 ti_sdo_ipc_Notify_create(NotifyDriverCirc_Handle_upCast(dspDriverHandle0),
145 dspProcId,
146 0,
147 NULL,
148 &eb);
149 if (Error_check(&eb)) {
150 /* Delete the driver and then return */
151 NotifyDriverCirc_delete(&dspDriverHandle0);
152 return (Notify_E_FAIL);
153 }
155 if (!NotifyCircSetup_useSecondLine) {
156 return (status);
157 }
158 /*
159 * Setup the notify driver to the DSP (Line 1)
160 */
161 NotifyDriverCirc_Params_init(¬ifyShmParams);
162 notifyShmParams.localIntId = NotifyCircSetup_armRecvIntId1;
163 notifyShmParams.remoteIntId = NotifyCircSetup_dspRecvIntId1;
164 notifyShmParams.remoteProcId = dspProcId;
165 notifyShmParams.sharedAddr = (Ptr)((UInt32)sharedAddr +
166 NotifyDriverCirc_sharedMemReq(¬ifyShmParams));
167 dspDriverHandle1 = NotifyDriverCirc_create(¬ifyShmParams, &eb);
168 if (dspDriverHandle1 == NULL) {
169 return (Notify_E_FAIL);
170 }
172 ti_sdo_ipc_Notify_create(NotifyDriverCirc_Handle_upCast(dspDriverHandle1),
173 dspProcId,
174 1,
175 NULL,
176 &eb);
177 if (Error_check(&eb)) {
178 /* Delete the driver and then return */
179 NotifyDriverCirc_delete(&dspDriverHandle1);
180 return (Notify_E_FAIL);
181 }
183 #endif
185 return (status);
186 }
188 /*!
189 * ======== NotifyCircSetup_sharedMemReq ========
190 * Return the amount of shared memory required
191 */
192 SizeT NotifyCircSetup_sharedMemReq(UInt16 remoteProcId, Ptr sharedAddr)
193 {
194 SizeT memReq;
195 NotifyDriverCirc_Params params;
197 NotifyDriverCirc_Params_init(¶ms);
198 params.sharedAddr = sharedAddr;
200 if (!NotifyCircSetup_useSecondLine) {
201 memReq = NotifyDriverCirc_sharedMemReq(¶ms);
202 }
203 else {
204 memReq = 2 * NotifyDriverCirc_sharedMemReq(¶ms);
205 }
207 return(memReq);
208 }
210 /*!
211 * ======== NotifyCircSetup_numIntLines ========
212 */
213 UInt16 NotifyCircSetup_numIntLines(UInt16 remoteProcId)
214 {
215 UInt16 numLines;
217 if (NotifyCircSetup_useSecondLine) {
218 numLines = 2;
219 }
220 else {
221 numLines = 1;
222 }
224 return (numLines);
225 }