[keystone-rtos/edma3_lld.git] / packages / ti / sdo / edma3 / drv / sample / src / platforms / sample_am335x_arm_int_reg.c
1 /*
2 * sample_am335x_arm_int_reg.c
3 *
4 * Platform specific interrupt registration and un-registration routines.
5 *
6 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
39 #include <ti/sysbios/knl/Semaphore.h>
41 #include <ti/sysbios/hal/Hwi.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/System.h>
45 #include <ti/sdo/edma3/drv/sample/bios6_edma3_drv_sample.h>
47 // #include <stdio.h>
48 /**
49 * EDMA3 TC ISRs which need to be registered with the underlying OS by the user
50 * (Not all TC error ISRs need to be registered, register only for the
51 * available Transfer Controllers).
52 */
53 void (*ptrEdma3TcIsrHandler[EDMA3_MAX_TC])(uint32_t arg) =
54 {
55 &lisrEdma3TC0ErrHandler0,
56 &lisrEdma3TC1ErrHandler0,
57 &lisrEdma3TC2ErrHandler0,
58 &lisrEdma3TC3ErrHandler0,
59 &lisrEdma3TC4ErrHandler0,
60 &lisrEdma3TC5ErrHandler0,
61 &lisrEdma3TC6ErrHandler0,
62 &lisrEdma3TC7ErrHandler0,
63 };
65 extern uint32_t ccXferCompInt[][EDMA3_MAX_REGIONS];
66 extern uint32_t ccErrorInt[];
67 extern uint32_t tcErrorInt[][EDMA3_MAX_TC];
68 extern uint32_t numEdma3Tc[];
70 /**
71 * Variables which will be used internally for referring the hardware interrupt
72 * for various EDMA3 interrupts.
73 */
74 extern uint32_t hwIntXferComp;
75 extern uint32_t hwIntCcErr;
76 extern uint32_t hwIntTcErr;
78 extern uint32_t dsp_num;
79 /* This variable has to be used as an extern */
80 //uint32_t gpp_num = 4;
82 Hwi_Handle hwiCCXferCompInt;
83 Hwi_Handle hwiCCErrInt;
84 Hwi_Handle hwiTCErrInt[EDMA3_MAX_TC];
86 /** To Register the ISRs with the underlying OS, if required. */
87 void registerEdma3Interrupts (uint32_t edma3Id)
88 {
89 static UInt32 cookie = 0;
90 uint32_t numTc = 0;
91 Hwi_Params hwiParams;
92 Error_Block eb;
94 /* Initialize the Error Block */
95 Error_init(&eb);
97 /* Disabling the global interrupts */
98 cookie = Hwi_disable();
100 /* Initialize the HWI parameters with user specified values */
101 Hwi_Params_init(&hwiParams);
103 /* argument for the ISR */
104 hwiParams.arg = edma3Id;
105 /* set the priority ID */
106 hwiParams.priority = hwIntXferComp;
107 //hwiParams.enableInt = TRUE;
109 hwiCCXferCompInt = Hwi_create( ccXferCompInt[edma3Id][dsp_num],
110 (&lisrEdma3ComplHandler0),
111 (const Hwi_Params *) (&hwiParams),
112 &eb);
113 if (TRUE == Error_check(&eb))
114 {
115 System_printf("HWI Create Failed\n",Error_getCode(&eb));
116 }
119 /* Initialize the HWI parameters with user specified values */
120 Hwi_Params_init(&hwiParams);
121 /* argument for the ISR */
122 hwiParams.arg = edma3Id;
123 /* set the priority ID */
124 hwiParams.priority = hwIntCcErr;
125 //hwiParams.enableInt = TRUE;
127 hwiCCErrInt = Hwi_create( ccErrorInt[edma3Id],
128 (&lisrEdma3CCErrHandler0),
129 (const Hwi_Params *) (&hwiParams),
130 &eb);
132 if (TRUE == Error_check(&eb))
133 {
134 System_printf("HWI Create Failed\n",Error_getCode(&eb));
135 }
137 while (numTc < numEdma3Tc[edma3Id])
138 {
139 /* Initialize the HWI parameters with user specified values */
140 Hwi_Params_init(&hwiParams);
141 /* argument for the ISR */
142 hwiParams.arg = edma3Id;
143 /* set the priority ID */
144 hwiParams.priority = hwIntTcErr;
145 //hwiParams.enableInt = TRUE;
147 hwiTCErrInt[numTc] = Hwi_create( tcErrorInt[edma3Id][numTc],
148 (ptrEdma3TcIsrHandler[numTc]),
149 (const Hwi_Params *) (&hwiParams),
150 &eb);
151 if (TRUE == Error_check(&eb))
152 {
153 System_printf("HWI Create Failed\n",Error_getCode(&eb));
154 }
155 numTc++;
156 }
157 /**
158 * Enabling the HWI_ID.
159 * EDMA3 interrupts (transfer completion, CC error etc.)
160 * correspond to different ECM events (SoC specific). These ECM events come
161 * under ECM block XXX (handling those specific ECM events). Normally, block
162 * 0 handles events 4-31 (events 0-3 are reserved), block 1 handles events
163 * 32-63 and so on. This ECM block XXX (or interrupt selection number XXX)
164 * is mapped to a specific HWI_INT YYY in the tcf file. So to enable this
165 * mapped HWI_INT YYY, one should use the corresponding bitmask in the
166 * API C64_enableIER(), in which the YYY bit is SET.
167 */
168 Hwi_enableInterrupt(ccErrorInt[edma3Id]);
169 Hwi_enableInterrupt(ccXferCompInt[edma3Id][dsp_num]);
170 numTc = 0;
171 while (numTc < numEdma3Tc[edma3Id])
172 {
173 Hwi_enableInterrupt(tcErrorInt[edma3Id][numTc]);
174 numTc++;
175 }
177 /* Restore interrupts */
178 Hwi_restore(cookie);
179 }
181 /** To Unregister the ISRs with the underlying OS, if previously registered. */
182 void unregisterEdma3Interrupts (uint32_t edma3Id)
183 {
184 static UInt32 cookie = 0;
185 uint32_t numTc = 0;
187 /* Disabling the global interrupts */
188 cookie = Hwi_disable();
190 Hwi_delete(&hwiCCXferCompInt);
191 Hwi_delete(&hwiCCErrInt);
192 while (numTc < numEdma3Tc[edma3Id])
193 {
194 Hwi_delete(&hwiTCErrInt[numTc]);
195 numTc++;
196 }
197 /* Restore interrupts */
198 Hwi_restore(cookie);
199 }