@@ -91,6 +91,93 @@ uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chnum)
91
91
// - URB_NOTREADY = a NAK, NYET, or not more than a couple of repeats of some of the errors that will
92
92
// become URB_ERROR if they repeat several times in a row
93
93
//
94
+ #if ARC_TICKER_BASED
95
+ void USBHALHost::tickerCallback (void )
96
+ {
97
+ HCD_HandleTypeDef *pHcd = (HCD_HandleTypeDef *)usb_hcca;
98
+ if (pHcd->State != HAL_HCD_STATE_BUSY)
99
+ {
100
+ USBHALHost_Private_t *pPriv = (USBHALHost_Private_t *)(pHcd->pData );
101
+
102
+ // 10 host channels
103
+ for (uint8_t uChannel=0 ; uChannel <11 ; uChannel++)
104
+ {
105
+ USB_OTG_URBStateTypeDef urbState = pHcd->hc [uChannel].urb_state ;
106
+
107
+ HCTD *pTransferDescriptor = (pPriv->addr [uChannel] == 0xffffffff ) ? nullptr : (HCTD *)pPriv->addr [uChannel];
108
+ uint32_t uEndpointType = pHcd->hc [uChannel].ep_type ;
109
+ uint32_t uEndpointDirection = pHcd->hc [uChannel].ep_is_in ;;
110
+
111
+ if (pTransferDescriptor)
112
+ {
113
+ if (uEndpointType == EP_TYPE_INTR)
114
+ {
115
+ // Disable the channel interupt
116
+ pTransferDescriptor->state = USB_TYPE_IDLE;
117
+ HAL_HCD_DisableInt (pHcd, uChannel);
118
+ }
119
+ else
120
+ {
121
+ // Handle USB NAKs
122
+ if (urbState == URB_NOTREADY)
123
+ {
124
+ // retry Acks imediately
125
+ // retry Bulk and Control after uRetryCounts ms
126
+ if ((uEndpointType == EP_TYPE_BULK) || (uEndpointType == EP_TYPE_CTRL))
127
+ {
128
+ constexpr uint32_t uRetryCount = 5 ;
129
+
130
+ pTransferDescriptor->retry ++;
131
+
132
+ if (urbState == URB_NOTREADY)
133
+ {
134
+ volatile uint32_t transferred = HAL_HCD_HC_GetXferCount (pHcd, uChannel);
135
+
136
+ if ((pTransferDescriptor->retry == uRetryCount) || (pTransferDescriptor->size ==0 ))
137
+ {
138
+ // Submit the same request again, because the device wasn't ready to accept the last one
139
+ // we need to be aware of any data that has already been transferred as it wont be again by the look of it.
140
+ pTransferDescriptor->currBufPtr += transferred;
141
+ pTransferDescriptor->size -= transferred;
142
+ pTransferDescriptor->retry = 0 ;
143
+ uint32_t uLength = pTransferDescriptor->size ;
144
+
145
+ HAL_HCD_HC_SubmitRequest (pHcd, uChannel, uEndpointDirection, uEndpointType, !pTransferDescriptor->setup , (uint8_t *) pTransferDescriptor->currBufPtr , uLength, 0 );
146
+ HAL_HCD_EnableInt (pHcd, uChannel);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ else
152
+ {
153
+ // set the transfer descriptor state based on the URB state
154
+ switch (urbState)
155
+ {
156
+ case URB_IDLE: // Guessing that we must have had a URB_DONE if we are idle
157
+ case URB_DONE: pTransferDescriptor->state = USB_TYPE_IDLE; break ;
158
+ case URB_ERROR: pTransferDescriptor->state = USB_TYPE_ERROR; break ;
159
+ default : pTransferDescriptor->state = USB_TYPE_PROCESSING; break ;
160
+ }
161
+ }
162
+ }
163
+
164
+ if (pTransferDescriptor->state == USB_TYPE_IDLE)
165
+ {
166
+ // reset retry count
167
+ pTransferDescriptor->retry = 0 ;
168
+
169
+ // Update transfer descriptor buffer pointer
170
+ pTransferDescriptor->currBufPtr += HAL_HCD_HC_GetXferCount (pHcd, uChannel);
171
+
172
+ // Call transferCompleted on correct object
173
+ void (USBHALHost::*func)(volatile uint32_t addr) = pPriv->transferCompleted ;
174
+ (pPriv->inst ->*func)(reinterpret_cast <std::uintptr_t >(pTransferDescriptor));
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ #else
94
181
void HAL_HCD_HC_NotifyURBChange_Callback (HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
95
182
{
96
183
USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData );
@@ -120,9 +207,6 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
120
207
uint32_t length;
121
208
if ((addr != 0 )) {
122
209
HCTD *td = (HCTD *)addr;
123
- LogicUint7 (0x70 + urb_state);
124
- LogicUint7 (0x50 + chnum);
125
- digitalWrite (PA_7, HIGH);
126
210
127
211
#if ARC_USB_FULL_SIZE
128
212
constexpr uint32_t uRetryCount = 10000 /20 ; // (TODO: should be done with timer, investigate)
@@ -217,6 +301,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
217
301
}
218
302
}
219
303
}
304
+ #endif
220
305
221
306
USBHALHost *USBHALHost::instHost;
222
307
0 commit comments