summaryrefslogtreecommitdiff
path: root/src/portable/nxp/lpc_ip3516/hcd_lpc_ip3516.h
blob: 2b8758a9e1f099756786af89187163655df0dc04 (plain)
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
/*
 * SPDX-FileCopyrightText: Copyright (c) 2025 HiFiPhile (Zixun LI)
 * SPDX-FileCopyrightText: Copyright (c) 2025 Ha Thach (tinyusb.org)
 * SPDX-License-Identifier: MIT
 *
 * This file is part of the TinyUSB stack.
 */

#ifndef TUSB_HCD_IP3516_H_
#define TUSB_HCD_IP3516_H_

#ifdef __cplusplus
extern "C" {
#endif

//--------------------------------------------------------------------+
// IP3516 CONFIGURATION & CONSTANTS
//--------------------------------------------------------------------+

#define IP3516_ATL_NUM 32
#define IP3516_PTL_NUM 32

#define IP3516_PTD_TOKEN_OUT 0x00U
#define IP3516_PTD_TOKEN_IN 0x01U
#define IP3516_PTD_TOKEN_SETUP 0x02U

#define IP3516_PTD_EPTYPE_OUT 0x00U
#define IP3516_PTD_EPTYPE_IN 0x01U
#define IP3516_PTD_EPTYPE_SETUP 0x02U

#define IP3516_PTD_MAX_TRANSFER_LENGTH 0x7FFFU

#define IP3516_PTD_DATA_ADDR_MASK 0xFFFFU

#define IP3516_MAX_UFRAME (1UL << 8)

#define IP3516_PERIODIC_TRANSFER_GAP (3U)
#define IP3516_ISO_MULTIPLE_TRANSFER (8U)


//--------------------------------------------------------------------+
// IP3516 PTD Data Structure
//--------------------------------------------------------------------+

// Control Word 1
typedef union {
  uint32_t value;
  struct {
    uint32_t valid    : 1;
    uint32_t next_ptd : 5;
    uint32_t          : 1;
    uint32_t jump     : 1;
    uint32_t uframe   : 8;
    uint32_t mps      : 11;
    uint32_t          : 1;
    uint32_t mult     : 2;
    uint32_t          : 2;
  };
} ptd_ctrl1_t;

TU_VERIFY_STATIC(sizeof(ptd_ctrl1_t) == 4, "size is not correct");

// Control Word 2
typedef union {
  uint32_t value;
  struct {
    uint32_t ep_num   : 4;
    uint32_t dev_addr : 7;
    uint32_t split    : 1;
    uint32_t reload   : 4;
    uint32_t speed    : 2;
    uint32_t hub_port : 7;
    uint32_t hub_addr : 7;
  };
} ptd_ctrl2_t;

TU_VERIFY_STATIC(sizeof(ptd_ctrl2_t) == 4, "size is not correct");

// Data Word
typedef union {
  uint32_t value;
  struct {
    uint32_t xfer_len  : 15;
    uint32_t intr      : 1;
    uint32_t data_addr : 16;
  };
} ptd_data_t;

TU_VERIFY_STATIC(sizeof(ptd_data_t) == 4, "size is not correct");

// State Word
typedef union {
  uint32_t value;
  struct {
    uint32_t xferred_len    : 15;
    uint32_t token          : 2;
    uint32_t ep_type        : 2;
    uint32_t nak_cnt        : 4;
    uint32_t err_cnt        : 2;
    uint32_t data_toggle    : 1;
    uint32_t ping           : 1;
    uint32_t start_complete : 1;
    uint32_t error          : 1;
    uint32_t babble         : 1;
    uint32_t halt           : 1;
    uint32_t active         : 1;
  };
} ptd_state_t;

TU_VERIFY_STATIC(sizeof(ptd_state_t) == 4, "size is not correct");

// Status Word
typedef union {
  uint32_t value;
  struct {
    uint32_t uframe_active : 8;
    uint32_t iso_status0   : 3;
    uint32_t iso_status1   : 3;
    uint32_t iso_status2   : 3;
    uint32_t iso_status3   : 3;
    uint32_t iso_status4   : 3;
    uint32_t iso_status5   : 3;
    uint32_t iso_status6   : 3;
    uint32_t iso_status7   : 3;
  };
} ptd_status_t;

TU_VERIFY_STATIC(sizeof(ptd_status_t) == 4, "size is not correct");

// ATL (Asynchronous Transfer List) structure
typedef volatile struct {
  ptd_ctrl1_t ctrl1;
  ptd_ctrl2_t ctrl2;
  ptd_data_t  data;
  ptd_state_t state;
} ip3516_atl_t;

TU_VERIFY_STATIC(sizeof(ip3516_atl_t) == 16, "size is not correct");

// PTL (Periodic Transfer List) structure
typedef volatile struct {
  ptd_ctrl1_t  ctrl1;
  ptd_ctrl2_t  ctrl2;
  ptd_data_t   data;
  ptd_state_t  state;
  ptd_status_t status;
  union {
    uint32_t value;
    struct {
      uint32_t uframe_complete : 8;
      uint32_t spl_iso_in_0    : 24;
    };
  } iso_in_0;
  uint32_t iso_in_1;
  uint32_t iso_in_2;
} ip3516_ptl_t;

TU_VERIFY_STATIC(sizeof(ip3516_ptl_t) == 32, "size is not correct");

// Proprietary Transfer Descriptor
typedef struct {
  ip3516_ptl_t intr[IP3516_PTL_NUM];
  ip3516_ptl_t iso[IP3516_PTL_NUM];
  ip3516_atl_t atl[IP3516_ATL_NUM];
} ip3516_ptd_t;

#ifdef __cplusplus
}
#endif
#endif /* TUSB_HCD_IP3516_H_ */