]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/ipc/family/dm6446/NotifySetup.c
ipc-bios.bld: Add "-cr" lnkOpt in for C66 target for remoteproc loaded images.
[ipc/ipcdev.git] / packages / ti / sdo / ipc / family / dm6446 / NotifySetup.c
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  *  ======== NotifySetup.c ========
34  */
35 #include <xdc/std.h>
36 #include <xdc/runtime/Error.h>
38 #include <ti/sdo/ipc/notifyDrivers/NotifyDriverShm.h>
39 #include <ti/sdo/ipc/_Notify.h>
40 #include <ti/sdo/utils/_MultiProc.h>
42 #include "package/internal/NotifySetup.xdc.h"
44 /*
45  *************************************************************************
46  *                      Module functions
47  *************************************************************************
48  */
50 /*!
51  *  ======== NotifySetup_attach ========
52  *  Initialize interrupt
53  */
54 Int NotifySetup_attach(UInt16 remoteProcId, Ptr sharedAddr)
55 {
56     NotifyDriverShm_Params notifyShmParams;
57     Error_Block eb;
58     Int status = Notify_S_SUCCESS;
60 #ifdef xdc_target__isaCompatible_64
61     NotifyDriverShm_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     NotifyDriverShm_Params_init(&notifyShmParams);
71     notifyShmParams.localIntId     = NotifySetup_dspRecvIntId0;
72     notifyShmParams.remoteIntId    = NotifySetup_armRecvIntId0;
73     notifyShmParams.intVectorId    = NotifySetup_dspIntVectId0;
74     notifyShmParams.remoteProcId   = armProcId;
75     notifyShmParams.sharedAddr     = sharedAddr;
77     armDriverHandle0 = NotifyDriverShm_create(&notifyShmParams, &eb);
78     if (armDriverHandle0 == NULL) {
79         return (Notify_E_FAIL);
80     }
82     ti_sdo_ipc_Notify_create(NotifyDriverShm_Handle_upCast(armDriverHandle0),
83                   armProcId,
84                   0,
85                   NULL,
86                   &eb);
87     if (Error_check(&eb)) {
88         /* Delete the driver and then return */
89         NotifyDriverShm_delete(&armDriverHandle0);
90         return (Notify_E_FAIL);
91     }
93     if (!NotifySetup_useSecondLine) {
94         return (status);
95     }
96     /*
97      *  Setup the notify driver to the ARM (Line 1)
98      */
99     NotifyDriverShm_Params_init(&notifyShmParams);
100     notifyShmParams.localIntId     = NotifySetup_dspRecvIntId1;
101     notifyShmParams.remoteIntId    = NotifySetup_armRecvIntId1;
102     notifyShmParams.intVectorId    = NotifySetup_dspIntVectId1;
103     notifyShmParams.remoteProcId   = armProcId;
104     notifyShmParams.sharedAddr     = (Ptr)((UInt32)sharedAddr +
105         NotifyDriverShm_sharedMemReq(&notifyShmParams));
106     armDriverHandle1 = NotifyDriverShm_create(&notifyShmParams, &eb);
108     if (armDriverHandle1 == NULL) {
109         return (Notify_E_FAIL);
110     }
112     ti_sdo_ipc_Notify_create(NotifyDriverShm_Handle_upCast(armDriverHandle1),
113                   armProcId,
114                   1,
115                   NULL,
116                   &eb);
117     if (Error_check(&eb)) {
118         /* Delete the driver and then return */
119         NotifyDriverShm_delete(&armDriverHandle1);
120         return (Notify_E_FAIL);
121     }
123 #else /* ARM code */
124     NotifyDriverShm_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     NotifyDriverShm_Params_init(&notifyShmParams);
134     notifyShmParams.localIntId     = NotifySetup_armRecvIntId0;
135     notifyShmParams.remoteIntId    = NotifySetup_dspRecvIntId0;
136     notifyShmParams.remoteProcId   = dspProcId;
137     notifyShmParams.sharedAddr     = sharedAddr;
139     dspDriverHandle0 = NotifyDriverShm_create(&notifyShmParams, &eb);
140     if (dspDriverHandle0 == NULL) {
141         return (Notify_E_FAIL);
142     }
144     ti_sdo_ipc_Notify_create(NotifyDriverShm_Handle_upCast(dspDriverHandle0),
145                   dspProcId,
146                   0,
147                   NULL,
148                   &eb);
149     if (Error_check(&eb)) {
150         /* Delete the driver and then return */
151         NotifyDriverShm_delete(&dspDriverHandle0);
152         return (Notify_E_FAIL);
153     }
155     if (!NotifySetup_useSecondLine) {
156         return (status);
157     }
158     /*
159      *  Setup the notify driver to the DSP (Line 1)
160      */
161     NotifyDriverShm_Params_init(&notifyShmParams);
162     notifyShmParams.localIntId     = NotifySetup_armRecvIntId1;
163     notifyShmParams.remoteIntId    = NotifySetup_dspRecvIntId1;
164     notifyShmParams.remoteProcId   = dspProcId;
165     notifyShmParams.sharedAddr     = (Ptr)((UInt32)sharedAddr +
166         NotifyDriverShm_sharedMemReq(&notifyShmParams));
167     dspDriverHandle1 = NotifyDriverShm_create(&notifyShmParams, &eb);
168     if (dspDriverHandle1 == NULL) {
169         return (Notify_E_FAIL);
170     }
172     ti_sdo_ipc_Notify_create(NotifyDriverShm_Handle_upCast(dspDriverHandle1),
173                   dspProcId,
174                   1,
175                   NULL,
176                   &eb);
177     if (Error_check(&eb)) {
178         /* Delete the driver and then return */
179         NotifyDriverShm_delete(&dspDriverHandle1);
180         return (Notify_E_FAIL);
181     }
183 #endif
185     return (status);
188 /*!
189  *  ======== NotifySetup_sharedMemReq ========
190  *  Return the amount of shared memory required
191  */
192 SizeT NotifySetup_sharedMemReq(UInt16 remoteProcId, Ptr sharedAddr)
194     SizeT memReq;
195     NotifyDriverShm_Params params;
197     NotifyDriverShm_Params_init(&params);
198     params.sharedAddr = sharedAddr;
200     if (!NotifySetup_useSecondLine) {
201         memReq = NotifyDriverShm_sharedMemReq(&params);
202     }
203     else {
204         memReq = 2 * NotifyDriverShm_sharedMemReq(&params);
205     }
207     return(memReq);
210 /*!
211  * ======== NotifySetup_numIntLines ========
212  */
213 UInt16 NotifySetup_numIntLines(UInt16 remoteProcId)
215     UInt16 numLines;
217     if (NotifySetup_useSecondLine) {
218         numLines = 2;
219     }
220     else {
221         numLines = 1;
222     }
224     return (numLines);