+/rtos

git clone https://git.julia.blue/+/rtos

Joseph RyanRe-add usblib files83915e3

master
6.2 KiB164 linesraw
1//*****************************************************************************
2//
3// usbulpi.c - ULPI access functions.
4//
5// Copyright (c) 2013-2017 Texas Instruments Incorporated.  All rights reserved.
6// Software License Agreement
7//
8// Texas Instruments (TI) is supplying this software for use solely and
9// exclusively on TI's microcontroller products. The software is owned by
10// TI and/or its suppliers, and is protected under applicable copyright
11// laws. You may not combine this software with "viral" open-source
12// software in order to form a larger program.
13//
14// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19// DAMAGES, FOR ANY REASON WHATSOEVER.
20//
21// This is part of revision 2.1.4.178 of the Tiva USB Library.
22//
23//*****************************************************************************
24#include "usblib/usbulpi.h"
25#include "tivaware/hw_types.h"
26#include "tivaware/usb.h"
27#include <stdbool.h>
28#include <stdint.h>
29
30//*****************************************************************************
31//
32// Hardware ULPI registers.
33//
34//*****************************************************************************
35#define ULPI_FCTL 0x04
36#define ULPI_FCTL_SET 0x05
37#define ULPI_FCTL_CLEAR 0x06
38#define ULPI_ICTL 0x07
39#define ULPI_ICTL_SET 0x08
40#define ULPI_ICTL_CLEAR 0x09
41#define ULPI_OTGCTL 0x0A
42#define ULPI_OTGCTL_SET 0x0B
43#define ULPI_OTGCTL_CLEAR 0x0C
44
45//*****************************************************************************
46//
47// The following are defines for the bit fields in the ULPI_FCTL register.
48//
49//*****************************************************************************
50#define ULPI_FCTL_XCVR_M 0x03
51#define ULPI_FCTL_XCVR_HS 0x00
52#define ULPI_FCTL_XCVR_FS 0x01
53#define ULPI_FCTL_XCVR_LS 0x02
54#define ULPI_FCTL_XCVR_FSLS 0x03
55#define ULPI_FCTL_TERMSEL 0x04
56#define ULPI_FCTL_OPMODE_M 0x18
57#define ULPI_FCTL_OPMODE_NORM 0x00
58#define ULPI_FCTL_OPMODE_NODRV 0x08
59#define ULPI_FCTL_OPMODE_NONRZI 0x10
60#define ULPI_FCTL_OPMODE_DISAUTO 0x18
61#define ULPI_FCTL_OPMODE_RESET 0x20
62#define ULPI_FCTL_OPMODE_SUSPEND 0x40
63
64//*****************************************************************************
65//
66// The following are defines for the bit fields in the ULPI_ICTL register.
67//
68//*****************************************************************************
69#define ULPI_ICTL_SER6PIN 0x01
70#define ULPI_ICTL_SER3PIN 0x02
71#define ULPI_ICTL_AUTORESUME 0x10
72#define ULPI_ICTL_INDINV 0x20
73#define ULPI_ICTL_INDPASSTHRU 0x40
74#define ULPI_ICTL_PROTDIS 0x80
75
76//*****************************************************************************
77//
78// The following are defines for the bit fields in the ULPI_OTGCTL register.
79//
80//*****************************************************************************
81#define ULPI_OTGCTL_ID_EN 0x01
82#define ULPI_OTGCTL_DPPD_EN 0x02
83#define ULPI_OTGCTL_DMPD_EN 0x04
84#define ULPI_OTGCTL_DISCHRG_VBUS 0x08
85#define ULPI_OTGCTL_CHRG_VBUS 0x10
86#define ULPI_OTGCTL_VBUSINT_EN 0x20
87#define ULPI_OTGCTL_VBUSEXT_EN 0x40
88#define ULPI_OTGCTL_VBUSEXT_IND 0x80
89
90//*****************************************************************************
91//
92//! Sets the configuration of an external USB Phy.
93//!
94//! \param ui32Base specifies the USB module base address.
95//! \param ui32Config specifies the configuration options for the external Phy.
96//!
97//! This function sets the configuration options for an externally connected
98//! USB Phy that is connected using the ULPI interface.  The \e ui32Config
99//! parameter holds all of the configuration options defined by the
100//! \b UPLI_CFG_ values.  The values are grouped as follows:
101//!
102//! Connection speed, using one of the following:
103//! - \b UPLI_CFG_HS enables high speed operation.
104//! - \b UPLI_CFG_FS enables full speed operation.
105//! - \b UPLI_CFG_HS enables low speed operation.
106//!
107//! Any of the following can be included:
108//! - \b UPLI_CFG_AUTORESUME enable automatic transmission of resume signaling
109//!   from the Phy.
110//! - \b UPLI_CFG_INVVBUSIND inverts the external VBUS indicator if it is
111//!   selected.
112//! - \b UPLI_CFG_PASSTHRUIND passes the external VBUS indicator through
113//!   without using the Phy's VBUS comparator.
114//! - \b ULPI_CFG_EXTVBUSDRV enables an external VBUS drive source.
115//! - \b ULPI_CFG_EXTVBUSIND enables an external signal for VBUS valid.
116//!
117//! \return None.
118//
119//*****************************************************************************
120void ULPIConfigSet(uint32_t ui32Base, uint32_t ui32Config) {
121    uint8_t ui8Val;
122
123    ui8Val = USBULPIRegRead(ui32Base, ULPI_FCTL);
124    ui8Val &= ~(ULPI_FCTL_XCVR_M);
125    ui8Val = ui8Val | (uint8_t)ui32Config;
126
127    USBULPIRegWrite(ui32Base, ULPI_FCTL, ui8Val);
128
129    ui8Val = USBULPIRegRead(ui32Base, ULPI_ICTL);
130    ui8Val &=
131        ~(ULPI_ICTL_AUTORESUME | ULPI_ICTL_INDINV | ULPI_ICTL_INDPASSTHRU);
132    ui8Val = ui8Val | (uint8_t)((ui32Config >> 8) & 0xff);
133
134    USBULPIRegWrite(ui32Base, ULPI_ICTL, ui8Val);
135
136    ui8Val = USBULPIRegRead(ui32Base, ULPI_OTGCTL);
137    ui8Val &= ~(ULPI_OTGCTL_VBUSINT_EN | ULPI_OTGCTL_VBUSEXT_EN |
138                ULPI_OTGCTL_VBUSEXT_IND);
139    ui8Val = ui8Val | (uint8_t)((ui32Config >> 16) & 0xff);
140
141    USBULPIRegWrite(ui32Base, ULPI_OTGCTL, ui8Val);
142}
143
144//*****************************************************************************
145//
146//! Enables or disables power to the external USB Phy.
147//!
148//! \param ui32Base specifies the USB module base address.
149//! \param bEnable specifies if the Phy is fully powered or in suspend mode.
150//!
151//! This function sets the current power configuration for the external ULPI
152//! connected Phy.  When \e bEnable is \b true the Phy is fully powered and
153//! when \b false the USB Phy is in suspend mode.
154//!
155//! \return None.
156//
157//*****************************************************************************
158void ULPIPowerTransceiver(uint32_t ui32Base, bool bEnable) {
159    if (bEnable) {
160        USBULPIRegWrite(ui32Base, ULPI_FCTL_CLEAR, ULPI_FCTL_OPMODE_SUSPEND);
161    } else {
162        USBULPIRegWrite(ui32Base, ULPI_FCTL_SET, ULPI_FCTL_OPMODE_SUSPEND);
163    }
164}