summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/stm32/stm32_usbhost.c
blob: cfd33c1d9aedff2ae6523ee2a3dc811c010361e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/********************************************************************************************
 * arch/arm/src/stm32/stm32_usbhost.c
 *
 *   Copyright (C) 2014 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ********************************************************************************************/

/********************************************************************************************
 * Included Files
 ********************************************************************************************/

#include <nuttx/config.h>

#include <stdint.h>
#include <stdbool.h>
#include <assert.h>


#include "stm32_usbhost.h"

#ifdef HAVE_USBHOST_TRACE

/********************************************************************************************
 * Pre-processor Definitions
 ********************************************************************************************/

#define TR_FMT1 false
#define TR_FMT2 true

#define TRENTRY(id,fmt1,string) {string}

#ifndef NULL
#  define NULL ((FAR void *)0)
#endif

/********************************************************************************************
 * Private Types
 ********************************************************************************************/

struct stm32_usbhost_trace_s
{
#if 0
  uint16_t id;
  bool fmt2;
#endif
  FAR const char *string;
};

/********************************************************************************************
 * Private Data
 ********************************************************************************************/

static const struct stm32_usbhost_trace_s g_trace1[TRACE1_NSTRINGS] =
{
#ifdef CONFIG_STM32_OTGFS

  TRENTRY(OTGFS_TRACE1_DEVDISCONN,         TR_FMT1, "OTGFS ERROR: Host Port %d. Device disconnected\n"),
  TRENTRY(OTGFS_TRACE1_IRQATTACH,          TR_FMT1, "OTGFS ERROR: Failed to attach IRQ\n"),
  TRENTRY(OTGFS_TRACE1_TRNSFRFAILED,       TR_FMT1, "OTGFS  ERROR: Transfer Failed. ret=%d\n"),
  TRENTRY(OTGFS_TRACE1_SENDSETUP,          TR_FMT1, "OTGFS  ERROR: ctrl_sendsetup() failed with: %d\n"),
  TRENTRY(OTGFS_TRACE1_SENDDATA,           TR_FMT1, "OTGFS  ERROR: ctrl_senddata() failed with: %d\n"),
  TRENTRY(OTGFS_TRACE1_RECVDATA,           TR_FMT1, "OTGFS  ERROR: ctrl_recvdata() failed with: %d\n"),

#  ifdef HAVE_USBHOST_TRACE_VERBOSE

  TRENTRY(OTGFS_VTRACE1_CONNECTED,         TR_FMT1, "OTGFS Host Port %d connected.\n"),
  TRENTRY(OTGFS_VTRACE1_DISCONNECTED,      TR_FMT1, "OTGFS Host Port %d disconnected.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT,              TR_FMT1, "OTGFS Handling Interrupt. Entry Point.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_SOF,          TR_FMT1, "OTGFS Handle the start of frame interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_RXFLVL,       TR_FMT1, "OTGFS Handle the RxFIFO non-empty interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_NPTXFE,       TR_FMT1, "OTGFS Handle the non-periodic TxFIFO empty interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_PTXFE,        TR_FMT1, "OTGFS Handle the periodic TxFIFO empty interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HC,           TR_FMT1, "OTGFS Handle the host channels interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT,         TR_FMT1, "OTGFS Handle the host port interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_POCCHNG, TR_FMT1, "OTGFS  HPRT: Port Over-Current Change.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_PCDET,   TR_FMT1, "OTGFS  HPRT: Port Connect Detect.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_PENCHNG, TR_FMT1, "OTGFS  HPRT: Port Enable Changed.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_LSDEV,   TR_FMT1, "OTGFS  HPRT: Low Speed Device Connected.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_FSDEV,   TR_FMT1, "OTGFS  HPRT: Full Speed Device Connected.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_LSFSSW,  TR_FMT1, "OTGFS  HPRT: Host Switch: LS -> FS.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_HPRT_FSLSSW,  TR_FMT1, "OTGFS  HPRT: Host Switch: FS -> LS.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_DISC,         TR_FMT1, "OTGFS Handle the disconnect detected interrupt.\n"),
  TRENTRY(OTGFS_VTRACE1_GINT_IPXFR,        TR_FMT1, "OTGFS Handle the incomplete periodic transfer.\n"),

#  endif
#endif

#ifdef CONFIG_STM32_OTGHS

  TRENTRY(OTGHS_TRACE1_DEVDISCONN,         TR_FMT1, "OTGHS ERROR: Host Port %d. Device disconnected\n"),
  TRENTRY(OTGHS_TRACE1_IRQATTACH,          TR_FMT1, "OTGHS ERROR: Failed to attach IRQ\n"),
  TRENTRY(OTGHS_TRACE1_TRNSFRFAILED,       TR_FMT1, "OTGHS  ERROR: Transfer Failed. ret=%d\n"),
  TRENTRY(OTGHS_TRACE1_SENDSETUP,          TR_FMT1, "OTGHS  ERROR: ctrl_sendsetup() failed with: %d\n"),
  TRENTRY(OTGHS_TRACE1_SENDDATA,           TR_FMT1, "OTGHS  ERROR: ctrl_senddata() failed with: %d\n"),
  TRENTRY(OTGHS_TRACE1_RECVDATA,           TR_FMT1, "OTGHS  ERROR: ctrl_recvdata() failed with: %d\n"),

#  ifdef HAVE_USBHOST_TRACE_VERBOSE

  TRENTRY(OTGHS_VTRACE1_CONNECTED,         TR_FMT1, "OTGHS Host Port %d connected.\n"),
  TRENTRY(OTGHS_VTRACE1_DISCONNECTED,      TR_FMT1, "OTGHS Host Port %d disconnected.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT,              TR_FMT1, "OTGHS Handling Interrupt. Entry Point.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_SOF,          TR_FMT1, "OTGHS Handle the start of frame interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_RXFLVL,       TR_FMT1, "OTGHS Handle the RxFIFO non-empty interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_NPTXFE,       TR_FMT1, "OTGHS Handle the non-periodic TxFIFO empty interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_PTXFE,        TR_FMT1, "OTGHS Handle the periodic TxFIFO empty interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HC,           TR_FMT1, "OTGHS Handle the host channels interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT,         TR_FMT1, "OTGHS Handle the host port interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_POCCHNG, TR_FMT1, "OTGHS  HPRT: Port Over-Current Change.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_PCDET,   TR_FMT1, "OTGHS  HPRT: Port Connect Detect.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_PENCHNG, TR_FMT1, "OTGHS  HPRT: Port Enable Changed.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_LSDEV,   TR_FMT1, "OTGHS  HPRT: Low Speed Device Connected.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_HSDEV,   TR_FMT1, "OTGHS  HPRT: Full Speed Device Connected.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_LSHSSW,  TR_FMT1, "OTGHS  HPRT: Host Switch: LS -> HS.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_HPRT_HSLSSW,  TR_FMT1, "OTGHS  HPRT: Host Switch: HS -> LS.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_DISC,         TR_FMT1, "OTGHS Handle the disconnect detected interrupt.\n"),
  TRENTRY(OTGHS_VTRACE1_GINT_IPXFR,        TR_FMT1, "OTGHS Handle the incomplete periodic transfer.\n"),

#  endif
#endif

};

static const struct stm32_usbhost_trace_s g_trace2[TRACE2_NSTRINGS] =
{
#ifdef CONFIG_STM32_OTGFS

  TRENTRY(OTGFS_TRACE2_CLIP,                TR_FMT2, "OTGFS CLIP: chidx: %d buflen: %d\n"),

#  ifdef HAVE_USBHOST_TRACE_VERBOSE

  TRENTRY(OTGFS_VTRACE2_CHANWAKEUP_IN,      TR_FMT2, "OTGFS  EP%d(IN)  wake up with result: %d\n"),
  TRENTRY(OTGFS_VTRACE2_CHANWAKEUP_OUT,     TR_FMT2, "OTGFS  EP%d(OUT) wake up with result: %d\n"),
  TRENTRY(OTGFS_VTRACE2_CTRLIN,             TR_FMT2, "OTGFS CTRL_IN  type: %02x req: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_CTRLOUT,            TR_FMT2, "OTGFS CTRL_OUT type: %02x req: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_INTRIN,             TR_FMT2, "OTGFS INTR_IN  chidx: %02x len: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_INTROUT,            TR_FMT2, "OTGFS INTR_OUT chidx: %02x len: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_BULKIN,             TR_FMT2, "OTGFS BULK_IN  chidx: %02x len: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_BULKOUT,            TR_FMT2, "OTGFS BULK_OUT chidx: %02x len: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_ISOCIN,             TR_FMT2, "OTGFS ISOC_IN  chidx: %02x len: %04d\n"),
  TRENTRY(OTGFS_VTRACE2_ISOCOUT,            TR_FMT2, "OTGFS ISOC_OUT chidx: %02x req: %02x\n"),
  TRENTRY(OTGFS_VTRACE2_STARTTRANSFER,      TR_FMT2, "OTGFS  Transfer chidx: %d buflen: %d\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_CTRL_IN,   TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,IN ,CTRL)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_CTRL_OUT,  TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,OUT,CTRL)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_INTR_IN,   TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,IN ,INTR)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_INTR_OUT,  TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,OUT,INTR)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_BULK_IN,   TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,IN ,BULK)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_BULK_OUT,  TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,OUT,BULK)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_ISOC_IN,   TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,IN ,ISOC)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANCONF_ISOC_OUT,  TR_FMT2, "OTGFS Channel configured. chidx: %d: (EP%d,OUT,ISOC)\n"),
  TRENTRY(OTGFS_VTRACE2_CHANHALT,           TR_FMT2, "OTGFS Channel halted. chidx: %d, reason: %d\n"),

#  endif
#endif
#ifdef CONFIG_STM32_OTGHS

  TRENTRY(OTGHS_TRACE2_CLIP,                TR_FMT2, "OTGHS CLIP: chidx: %d buflen: %d\n"),

#  ifdef HAVE_USBHOST_TRACE_VERBOSE

  TRENTRY(OTGHS_VTRACE2_CHANWAKEUP_IN,      TR_FMT2, "OTGHS  EP%d(IN)  wake up with result: %d\n"),
  TRENTRY(OTGHS_VTRACE2_CHANWAKEUP_OUT,     TR_FMT2, "OTGHS  EP%d(OUT) wake up with result: %d\n"),
  TRENTRY(OTGHS_VTRACE2_CTRLIN,             TR_FMT2, "OTGHS CTRL_IN  type: %02x req: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_CTRLOUT,            TR_FMT2, "OTGHS CTRL_OUT type: %02x req: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_INTRIN,             TR_FMT2, "OTGHS INTR_IN  chidx: %02x len: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_INTROUT,            TR_FMT2, "OTGHS INTR_OUT chidx: %02x len: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_BULKIN,             TR_FMT2, "OTGHS BULK_IN  chidx: %02x len: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_BULKOUT,            TR_FMT2, "OTGHS BULK_OUT chidx: %02x len: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_ISOCIN,             TR_FMT2, "OTGHS ISOC_IN  chidx: %02x len: %04d\n"),
  TRENTRY(OTGHS_VTRACE2_ISOCOUT,            TR_FMT2, "OTGHS ISOC_OUT chidx: %02x req: %02x\n"),
  TRENTRY(OTGHS_VTRACE2_STARTTRANSFER,      TR_FMT2, "OTGHS  Transfer chidx: %d buflen: %d\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_CTRL_IN,   TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,IN ,CTRL)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_CTRL_OUT,  TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,OUT,CTRL)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_INTR_IN,   TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,IN ,INTR)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_INTR_OUT,  TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,OUT,INTR)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_BULK_IN,   TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,IN ,BULK)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_BULK_OUT,  TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,OUT,BULK)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_ISOC_IN,   TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,IN ,ISOC)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANCONF_ISOC_OUT,  TR_FMT2, "OTGHS Channel configured. chidx: %d: (EP%d,OUT,ISOC)\n"),
  TRENTRY(OTGHS_VTRACE2_CHANHALT,           TR_FMT2, "OTGHS Channel halted. chidx: %d, reason: %d\n"),

#  endif
#endif
};

/********************************************************************************************
 * Private Function Prototypes
 ********************************************************************************************/

/********************************************************************************************
 * Global Functions
 ********************************************************************************************/

/********************************************************************************************
 * Name: usbhost_trformat1 and usbhost_trformat2
 *
 * Description:
 *   This interface must be provided by platform specific logic that knows
 *   the HCDs encoding of USB trace data.
 *
 *   Given an 9-bit index, return a format string suitable for use with, say,
 *   printf.  The returned format is expected to handle two unsigned integer
 *   values.
 *
 ********************************************************************************************/

FAR const char *usbhost_trformat1(uint16_t id)
{
  int ndx = TRACE1_INDEX(id);

  if (ndx < TRACE1_NSTRINGS)
    {
      return g_trace1[ndx].string;
    }

  return NULL;
}

FAR const char *usbhost_trformat2(uint16_t id)
{
  int ndx = TRACE2_INDEX(id);

  if (ndx < TRACE2_NSTRINGS)
    {
      return g_trace2[ndx].string;
    }

  return NULL;
}

#endif /* HAVE_USBHOST_TRACE */