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 * ======== InterruptDsp.c ========
34 * Dsp interrupt manager.
35 */
37 #include <xdc/std.h>
38 #include <xdc/runtime/Assert.h>
39 #include <ti/sysbios/family/c64p/Hwi.h>
41 #include <ti/sdo/ipc/Ipc.h>
42 #include <ti/sdo/ipc/notifyDrivers/IInterrupt.h>
43 #include "package/internal/InterruptDsp.xdc.h"
45 /* register use to generate interrupt between cores */
46 #define CHIPSIGREG 0x01C14174
48 /* event ids associated with inter-core interrupts */
49 #define DSP2ARM_CHIPINT0 28
50 #define DSP2ARM_CHIPINT1 29
51 #define ARM2DSP_CHIPINT2 5
52 #define ARM2DSP_CHIPINT3 67
54 /*
55 *************************************************************************
56 * Module functions
57 *************************************************************************
58 */
60 /*!
61 * ======== InterruptDsp_intEnable ========
62 * Enable GPP interrupt
63 */
64 Void InterruptDsp_intEnable(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo)
65 {
66 Hwi_enableInterrupt(intInfo->intVectorId);
67 }
69 /*!
70 * ======== InterruptDsp_intDisable ========
71 * Disables GPP interrupt
72 */
73 Void InterruptDsp_intDisable(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo)
74 {
75 Hwi_disableInterrupt(intInfo->intVectorId);
76 }
78 /*!
79 * ======== InterruptDsp_intRegister ========
80 * Register ISR for remote processor interrupt
81 */
82 Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo,
83 Fxn func, UArg arg)
84 {
85 Hwi_Params hwiAttrs;
86 UInt key;
88 Assert_isTrue(intInfo->intVectorId <= 15,
89 ti_sdo_ipc_Ipc_A_internal);
91 Assert_isTrue(intInfo->localIntId == ARM2DSP_CHIPINT2 ||
92 intInfo->localIntId == ARM2DSP_CHIPINT3,
93 ti_sdo_ipc_Ipc_A_internal);
95 /* Disable global interrupts */
96 key = Hwi_disable();
98 InterruptDsp_intClear(remoteProcId, intInfo); //TODO
100 /* Register interrupt for communication between ARM and DSP */
101 Hwi_Params_init(&hwiAttrs);
102 hwiAttrs.maskSetting = Hwi_MaskingOption_SELF;
103 hwiAttrs.arg = arg;
104 hwiAttrs.eventId = intInfo->localIntId;
106 Hwi_create(intInfo->intVectorId,
107 (Hwi_FuncPtr)func,
108 &hwiAttrs,
109 NULL);
111 /* Restore global interrupts */
112 Hwi_restore(key);
114 /* enable the interrupt vector */
115 Hwi_enableInterrupt(intInfo->intVectorId);
116 }
118 /*!
119 * ======== InterruptDsp_intUnregister ========
120 */
121 Void InterruptDsp_intUnregister(UInt16 remoteProcId,
122 IInterrupt_IntInfo *intInfo)
123 {
124 Hwi_Handle hwiHandle;
126 /* Delete the Hwi (and disable the corresponding interrupt) */
127 hwiHandle = Hwi_getHandle(intInfo->intVectorId);
128 Hwi_delete(&hwiHandle);
129 }
131 /*!
132 * ======== InterruptDsp_intSend ========
133 * Send interrupt to the remote processor
134 */
135 Void InterruptDsp_intSend(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo,
136 UArg arg)
137 {
138 UInt32 intBitPos;
139 volatile UInt32 *chipSigReg = (volatile UInt32 *)CHIPSIGREG;
141 switch (intInfo->remoteIntId) {
142 case DSP2ARM_CHIPINT0:
143 intBitPos = 0;
144 break;
145 case DSP2ARM_CHIPINT1:
146 intBitPos = 1;
147 break;
148 default:
149 intBitPos = 0; /* keep Coverity happy */
150 break;
151 }
153 chipSigReg[0] = (1 << intBitPos);
154 }
156 /*!
157 * ======== InterruptDsp_intPost ========
158 */
159 Void InterruptDsp_intPost(UInt16 srcProcId, IInterrupt_IntInfo *intInfo,
160 UArg arg)
161 {
162 UInt16 intBitPos;
163 volatile UInt32 *chipSigReg = (volatile UInt32 *)CHIPSIGREG;
165 switch (intInfo->localIntId) {
166 case ARM2DSP_CHIPINT2:
167 intBitPos = 2;
168 break;
169 case ARM2DSP_CHIPINT3:
170 intBitPos = 3;
171 break;
172 default:
173 intBitPos = 0; /* keep Coverity happy */
174 break;
175 }
177 chipSigReg[0] = (1 << intBitPos);
178 }
180 /*!
181 * ======== InterruptDsp_intClear ========
182 * Clear interrupt
183 */
184 UInt InterruptDsp_intClear(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo)
185 {
186 UInt32 statBitPos;
187 volatile UInt32 *chipSigReg = (volatile UInt32 *)CHIPSIGREG;
189 switch (intInfo->localIntId) {
190 case ARM2DSP_CHIPINT2:
191 statBitPos = 2;
192 break;
193 case ARM2DSP_CHIPINT3:
194 statBitPos = 3;
195 break;
196 default:
197 statBitPos = 0; /* keep Coverity happy */
198 break;
199 }
201 chipSigReg[1] = (1 << statBitPos);
203 return (0);
204 }
206 Bool InterruptDsp_isIntSet(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo)
207 {
208 UInt32 statBitPos;
209 volatile UInt32 *chipSigReg = (volatile UInt32 *)CHIPSIGREG;
210 UInt32 mask;
212 switch (intInfo->localIntId) {
213 case ARM2DSP_CHIPINT2:
214 statBitPos = 2;
215 break;
216 case ARM2DSP_CHIPINT3:
217 statBitPos = 3;
218 break;
219 default:
220 statBitPos = 0; /* keep Coverity happy */
221 break;
222 }
224 mask = 1 << statBitPos;
225 if ((chipSigReg[0] & mask) == mask) {
226 return TRUE;
227 }
228 else {
229 return FALSE;
230 }
231 }