1 //###########################################################################
2 //
3 // FILE: usb_hal.c
4 //
5 // TITLE: Wrapper for interrupt functions and USB support pins.
6 //
7 //###########################################################################
8 // $TI Release: F2837xD Support Library v3.05.00.00 $
9 // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
10 // $Copyright:
11 // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
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
23 // distribution.
24 //
25 // Neither the name of Texas Instruments Incorporated nor the names of
26 // its contributors may be used to endorse or promote products derived
27 // from this software without specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 // $
41 //###########################################################################
42
43 #include "F2837xD_device.h"
44 #include "F2837xD_Examples.h"
45 #include "inc/hw_types.h"
46 #include "inc/hw_memmap.h"
47 #include "inc/hw_usb.h"
48 #include "usb_hal.h"
49 #include "usb.h"
50 #include "include/usblib.h"
51 #include "include/usblibpriv.h"
52 #include "include/device/usbdevice.h"
53 #include "include/host/usbhost.h"
54 #include "include/host/usbhostpriv.h"
55 #include "include/usblibpriv.h"
56
57 //*****************************************************************************
58 //
59 //! \addtogroup c2000_specific
60 //! @{
61 //
62 //*****************************************************************************
63
64 //*****************************************************************************
65 //
66 //! Enables USB related GPIOs to perform their USB function.
67 //
68 //*****************************************************************************
USBGPIOEnable(void)69 void USBGPIOEnable(void)
70 {
71 EALLOW;
72 GpioCtrlRegs.GPBLOCK.all = 0x00000000;
73 GpioCtrlRegs.GPBAMSEL.bit.GPIO42 = 1;
74 GpioCtrlRegs.GPBAMSEL.bit.GPIO43 = 1;
75
76 //VBUS
77 GpioCtrlRegs.GPBDIR.bit.GPIO46 = 0;
78 //ID
79 GpioCtrlRegs.GPBDIR.bit.GPIO47 = 0;
80
81 GpioCtrlRegs.GPDGMUX2.bit.GPIO120 = 3;
82 GpioCtrlRegs.GPDMUX2.bit.GPIO120 = 3;
83 GpioCtrlRegs.GPDGMUX2.bit.GPIO121 = 3;
84 GpioCtrlRegs.GPDMUX2.bit.GPIO121 = 3;
85 EDIS;
86 }
87
88 //*****************************************************************************
89 //
90 //! Disables USB related GPIOs from performing their USB function.
91 //
92 //*****************************************************************************
USBGPIODisable(void)93 void USBGPIODisable(void)
94 {
95 EALLOW;
96 GpioCtrlRegs.GPBLOCK.all = 0x00000000;
97 GpioCtrlRegs.GPBAMSEL.bit.GPIO42 = 0;
98 GpioCtrlRegs.GPBAMSEL.bit.GPIO43 = 0;
99
100 GpioCtrlRegs.GPDGMUX2.bit.GPIO120 = 0;
101 GpioCtrlRegs.GPDMUX2.bit.GPIO120 = 0;
102 GpioCtrlRegs.GPDGMUX2.bit.GPIO121 = 0;
103 GpioCtrlRegs.GPDMUX2.bit.GPIO121 = 0;
104 EDIS;
105 }
106
107
108 //*****************************************************************************
109 //
110 //! Wrapper function to implement mS based delay for USB functions
111 //
112 //*****************************************************************************
USBDelay(uint32_t ui32Delay)113 void USBDelay(uint32_t ui32Delay)
114 {
115 DELAY_US(ui32Delay*1000);
116 }
117
118 //*****************************************************************************
119 //
120 //! Device interrupt service routine wrapper to make ISR compatible with
121 //! C2000 PIE controller.
122 //
123 //*****************************************************************************
124
125 __interrupt void
f28x_USB0DeviceIntHandler(void)126 f28x_USB0DeviceIntHandler(void)
127 {
128 USB0DeviceIntHandler();
129 PieCtrlRegs.PIEACK.all |= 0x0100;
130 }
131 //*****************************************************************************
132 //
133 //! Host interrupt service routine wrapper to make ISR compatible with
134 //! C2000 PIE controller.
135 //
136 //*****************************************************************************
137 __interrupt void
f28x_USB0HostIntHandler(void)138 f28x_USB0HostIntHandler(void)
139 {
140 USB0HostIntHandler();
141 PieCtrlRegs.PIEACK.all |= 0x0100;
142 }
143
144 //*****************************************************************************
145 //
146 //! Dual mode interrupt service routine wrapper to make ISR compatible with
147 //! C2000 PIE controller.
148 //
149 //*****************************************************************************
150 __interrupt void
f28x_USB0DualModeIntHandler(void)151 f28x_USB0DualModeIntHandler(void)
152 {
153 USB0DualModeIntHandler();
154 PieCtrlRegs.PIEACK.all |= 0x0100;
155 }
156
157 //*****************************************************************************
158 //
159 // Close the c2000_specific Doxygen group.
160 //! @}
161 //
162 //*****************************************************************************
163
164