@@ -199,7 +199,6 @@ static int32_t iso_trans_doing(hced_t *p_ed, uint32_t index);
199
199
static void chk_iso_td_done (genelal_ed_t * p_g_ed );
200
200
static int32_t chk_iso_ed (genelal_ed_t * p_g_ed );
201
201
static void iso_trans_setting (genelal_ed_t * p_g_ed , uint32_t index );
202
- static uint32_t iso_chk_starting_frame (genelal_ed_t * p_g_ed );
203
202
static void iso_trans (genelal_ed_t * p_g_ed );
204
203
#endif
205
204
static void connect_check (void );
@@ -215,6 +214,7 @@ static usb_ohci_reg_t *p_usb_reg = &usb_reg;
215
214
static usbisr_fnc_t * p_usbisr_cb = NULL ;
216
215
static osSemaphoreId semid_cb = NULL ;
217
216
static uint32_t connect_change = 0xFFFFFFFF ;
217
+ static uint32_t connect_status = 0 ;
218
218
static uint32_t init_end = 0 ;
219
219
static genelal_ed_t ctl_ed ;
220
220
static genelal_ed_t blk_ed ;
@@ -283,13 +283,13 @@ osThreadDef(int_ed_task_4, osPriorityNormal, 512);
283
283
static void iso_ed_task_1 (void const * argument ) {
284
284
iso_ed_task (argument );
285
285
}
286
- osThreadDef (iso_ed_task_1 , osPriorityNormal , 512 );
286
+ osThreadDef (iso_ed_task_1 , osPriorityAboveNormal , 512 );
287
287
#endif
288
288
#if (ISO_TRANS_MAX_NUM >= 2 )
289
289
static void iso_ed_task_2 (void const * argument ) {
290
290
iso_ed_task (argument );
291
291
}
292
- osThreadDef (iso_ed_task_2 , osPriorityNormal , 512 );
292
+ osThreadDef (iso_ed_task_2 , osPriorityAboveNormal , 512 );
293
293
#endif
294
294
295
295
void ohciwrapp_init (usbisr_fnc_t * p_usbisr_fnc ) {
@@ -878,25 +878,28 @@ static void control_trans(genelal_ed_t *p_g_ed) {
878
878
p_g_ed -> pipe_no = USB_HOST_PIPE0 ;
879
879
880
880
p_g_ed -> trans_wait = 1 ;
881
-
882
- if (td_info .direction == 0 ) {
883
- uint16_t Req = (p_td -> currBufPtr [1 ] << 8 ) + p_td -> currBufPtr [0 ];
884
- uint16_t Val = (p_td -> currBufPtr [3 ] << 8 ) + p_td -> currBufPtr [2 ];
885
- uint16_t Indx = (p_td -> currBufPtr [5 ] << 8 ) + p_td -> currBufPtr [4 ];
886
- uint16_t Len = (p_td -> currBufPtr [7 ] << 8 ) + p_td -> currBufPtr [6 ];
887
-
888
- g_usbx_host_data_pointer [USB_HOST_PIPE0 ] = p_td -> bufEnd ;
889
- usbx_host_SetupStage (Req , Val , Indx , Len );
890
- } else if (td_info .direction == 1 ) {
891
- usbx_host_CtrlWriteStart (td_info .count , p_td -> currBufPtr );
881
+ if (connect_status == 0 ) {
882
+ ohciwrapp_loc_TransEnd (p_g_ed -> pipe_no , TD_CC_DEVICENOTRESPONDING );
892
883
} else {
893
- usbx_host_CtrlReadStart (td_info .count , p_td -> currBufPtr );
894
- }
884
+ if (td_info .direction == 0 ) {
885
+ uint16_t Req = (p_td -> currBufPtr [1 ] << 8 ) + p_td -> currBufPtr [0 ];
886
+ uint16_t Val = (p_td -> currBufPtr [3 ] << 8 ) + p_td -> currBufPtr [2 ];
887
+ uint16_t Indx = (p_td -> currBufPtr [5 ] << 8 ) + p_td -> currBufPtr [4 ];
888
+ uint16_t Len = (p_td -> currBufPtr [7 ] << 8 ) + p_td -> currBufPtr [6 ];
889
+
890
+ g_usbx_host_data_pointer [USB_HOST_PIPE0 ] = p_td -> bufEnd ;
891
+ usbx_host_SetupStage (Req , Val , Indx , Len );
892
+ } else if (td_info .direction == 1 ) {
893
+ usbx_host_CtrlWriteStart (td_info .count , p_td -> currBufPtr );
894
+ } else {
895
+ usbx_host_CtrlReadStart (td_info .count , p_td -> currBufPtr );
896
+ }
895
897
896
- (void )osSemaphoreWait (p_g_ed -> semid_wait , CTL_TRANS_TIMEOUT );
897
- if (p_g_ed -> trans_wait == 1 ) {
898
- p_g_ed -> trans_wait = 0 ;
899
- RZA_IO_RegWrite_32 (& p_td -> control , TD_CC_DEVICENOTRESPONDING , TD_CTL_SHFT_CC , TD_CTL_MSK_CC );
898
+ (void )osSemaphoreWait (p_g_ed -> semid_wait , CTL_TRANS_TIMEOUT );
899
+ if (p_g_ed -> trans_wait == 1 ) {
900
+ p_g_ed -> trans_wait = 0 ;
901
+ RZA_IO_RegWrite_32 (& p_td -> control , TD_CC_DEVICENOTRESPONDING , TD_CTL_SHFT_CC , TD_CTL_MSK_CC );
902
+ }
900
903
}
901
904
902
905
g_usbx_host_CmdStage &= (~USB_HOST_CMD_FIELD );
@@ -928,14 +931,18 @@ static void bulk_trans(genelal_ed_t *p_g_ed) {
928
931
set_togle (p_g_ed -> pipe_no , p_td , p_ed );
929
932
930
933
p_g_ed -> trans_wait = 1 ;
931
- if (td_info . direction == 1 ) {
932
- usbx_host_start_send_transfer (p_g_ed -> pipe_no , td_info . count , p_td -> currBufPtr );
934
+ if (connect_status == 0 ) {
935
+ ohciwrapp_loc_TransEnd (p_g_ed -> pipe_no , TD_CC_DEVICENOTRESPONDING );
933
936
} else {
934
- usbx_host_start_receive_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
935
- }
937
+ if (td_info .direction == 1 ) {
938
+ usbx_host_start_send_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
939
+ } else {
940
+ usbx_host_start_receive_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
941
+ }
936
942
937
- (void )osSemaphoreWait (p_g_ed -> semid_wait , BLK_TRANS_TIMEOUT );
938
- usbx_host_stop_transfer (p_g_ed -> pipe_no );
943
+ (void )osSemaphoreWait (p_g_ed -> semid_wait , BLK_TRANS_TIMEOUT );
944
+ usbx_host_stop_transfer (p_g_ed -> pipe_no );
945
+ }
939
946
}
940
947
941
948
static void int_trans_setting (genelal_ed_t * p_g_ed , uint32_t index ) {
@@ -1023,10 +1030,14 @@ static void int_trans(genelal_ed_t *p_g_ed) {
1023
1030
1024
1031
get_td_info (p_g_ed , & td_info );
1025
1032
p_g_ed -> trans_wait = 1 ;
1026
- if (td_info . direction == 1 ) {
1027
- usbx_host_start_send_transfer (p_g_ed -> pipe_no , td_info . count , p_td -> currBufPtr );
1033
+ if (connect_status == 0 ) {
1034
+ ohciwrapp_loc_TransEnd (p_g_ed -> pipe_no , TD_CC_DEVICENOTRESPONDING );
1028
1035
} else {
1029
- usbx_host_start_receive_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
1036
+ if (td_info .direction == 1 ) {
1037
+ usbx_host_start_send_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
1038
+ } else {
1039
+ usbx_host_start_receive_transfer (p_g_ed -> pipe_no , td_info .count , p_td -> currBufPtr );
1040
+ }
1030
1041
}
1031
1042
}
1032
1043
@@ -1089,7 +1100,6 @@ static void set_togle(uint32_t pipe, hctd_t *p_td, hced_t *p_ed) {
1089
1100
static void iso_ed_task (void const * argument ) {
1090
1101
genelal_ed_t * p_iso_ed = & iso_ed [(uint32_t )argument ];
1091
1102
uint32_t wait_cnt = 0 ;
1092
- uint32_t wait_time = 0 ;
1093
1103
hcca_t * p_hcca ;
1094
1104
hced_t * p_ed ;
1095
1105
@@ -1115,17 +1125,26 @@ static void iso_ed_task(void const * argument) {
1115
1125
if (p_iso_ed -> p_curr_ed != NULL ) {
1116
1126
while ((p_usb_reg -> HcControl & OR_CONTROL_IE ) != 0 ) {
1117
1127
if (chk_iso_ed (p_iso_ed ) != 0 ) {
1118
- wait_time = iso_chk_starting_frame (p_iso_ed );
1119
- if (wait_time != 0 ) {
1120
- osDelay (wait_time );
1121
- p_usb_reg -> HcFmNumber += wait_time ;
1122
- p_usb_reg -> HcFmNumber &= 0x0000FFFF ;
1128
+ hcisotd_t * p_isotd = (hcisotd_t * )p_iso_ed -> p_curr_td ;
1129
+ uint32_t starting_frame = p_isotd -> control & 0x0000FFFF ;
1130
+ uint32_t wait_time = 0 ;
1131
+ uint32_t wk_HcFmNumber = p_usb_reg -> HcFmNumber ;
1132
+
1133
+ if (starting_frame > wk_HcFmNumber ) {
1134
+ wait_time = starting_frame - wk_HcFmNumber ;
1135
+ } else {
1136
+ wait_time = (0xFFFF - wk_HcFmNumber ) + starting_frame ;
1137
+ }
1138
+ if ((wait_time >= 2 ) && (wait_time <= 1000 )) {
1139
+ for (int cnt = 0 ; cnt < (wait_time - 1 ); cnt ++ ) {
1140
+ osDelay (1 );
1141
+ p_usb_reg -> HcFmNumber = (wk_HcFmNumber + cnt ) & 0x0000FFFF ;
1142
+ }
1123
1143
}
1124
1144
p_iso_ed -> psw_idx = 0 ;
1125
1145
iso_trans (p_iso_ed );
1126
1146
(void )osSemaphoreWait (p_iso_ed -> semid_wait , osWaitForever );
1127
- usbx_host_stop_transfer (p_iso_ed -> pipe_no );
1128
- wait_cnt = 1 ;
1147
+ wait_cnt = 8 ;
1129
1148
} else {
1130
1149
if (wait_cnt > 0 ) {
1131
1150
wait_cnt -- ;
@@ -1234,18 +1253,6 @@ static void iso_trans_setting(genelal_ed_t *p_g_ed, uint32_t index) {
1234
1253
usbx_api_host_SetEndpointTable (td_info .devadr , user_table , wk_table );
1235
1254
}
1236
1255
1237
- static uint32_t iso_chk_starting_frame (genelal_ed_t * p_g_ed ) {
1238
- hcisotd_t * p_isotd = (hcisotd_t * )p_g_ed -> p_curr_td ;
1239
- uint32_t starting_frame = p_isotd -> control & 0x0000FFFF ;
1240
- uint32_t wait_time = 0 ;
1241
-
1242
- if ((p_g_ed -> psw_idx == 0 ) && (starting_frame > p_usb_reg -> HcFmNumber )) {
1243
- wait_time = starting_frame - p_usb_reg -> HcFmNumber ;
1244
- }
1245
-
1246
- return wait_time ;
1247
- }
1248
-
1249
1256
static void iso_trans (genelal_ed_t * p_g_ed ) {
1250
1257
hcisotd_t * p_isotd = (hcisotd_t * )p_g_ed -> p_curr_td ;
1251
1258
tdinfo_t td_info ;
@@ -1268,10 +1275,14 @@ static void iso_trans(genelal_ed_t *p_g_ed) {
1268
1275
1269
1276
get_td_info (p_g_ed , & td_info );
1270
1277
p_g_ed -> trans_wait = 1 ;
1271
- if (td_info . direction == 1 ) {
1272
- usbx_host_start_send_transfer (p_g_ed -> pipe_no , data_size , ( uint8_t * ) buff_addr );
1278
+ if (connect_status == 0 ) {
1279
+ ohciwrapp_loc_TransEnd (p_g_ed -> pipe_no , TD_CC_DEVICENOTRESPONDING );
1273
1280
} else {
1274
- usbx_host_start_receive_transfer (p_g_ed -> pipe_no , data_size , (uint8_t * )buff_addr );
1281
+ if (td_info .direction == 1 ) {
1282
+ usbx_host_start_send_transfer (p_g_ed -> pipe_no , data_size , (uint8_t * )buff_addr );
1283
+ } else {
1284
+ usbx_host_start_receive_transfer (p_g_ed -> pipe_no , data_size , (uint8_t * )buff_addr );
1285
+ }
1275
1286
}
1276
1287
}
1277
1288
#endif
@@ -1326,6 +1337,7 @@ static void connect_check(void) {
1326
1337
void ohciwrapp_loc_Connect (uint32_t type ) {
1327
1338
uint32_t cnt ;
1328
1339
1340
+ connect_status = type ;
1329
1341
connect_change = type ;
1330
1342
if (type == 0 ) {
1331
1343
if (ctl_ed .trans_wait == 1 ) {
@@ -1445,11 +1457,7 @@ void ohciwrapp_loc_TransEnd(uint32_t pipe, uint32_t ConditionCode) {
1445
1457
1446
1458
if (p_isotd != NULL ) {
1447
1459
usbx_host_stop_transfer (pipe );
1448
- if (p_usb_reg -> HcFmNumber < 0x0000FFFF ) {
1449
- p_usb_reg -> HcFmNumber ++ ;
1450
- } else {
1451
- p_usb_reg -> HcFmNumber = 0 ;
1452
- }
1460
+ p_usb_reg -> HcFmNumber = ((p_isotd -> control & 0x0000FFFF ) + p_wait_ed -> psw_idx ) & 0x0000FFFF ;
1453
1461
1454
1462
/* Size of packet */
1455
1463
p_isotd -> offsetPSW [p_wait_ed -> psw_idx ] -= g_usbx_host_data_count [pipe ];
@@ -1469,10 +1477,8 @@ void ohciwrapp_loc_TransEnd(uint32_t pipe, uint32_t ConditionCode) {
1469
1477
p_wait_ed -> psw_idx ++ ;
1470
1478
}
1471
1479
if (chk_iso_ed (p_wait_ed ) != 0 ) {
1472
- if (iso_chk_starting_frame (p_wait_ed ) == 0 ) {
1473
- iso_trans (p_wait_ed );
1474
- next_trans = 1 ;
1475
- }
1480
+ iso_trans (p_wait_ed );
1481
+ next_trans = 1 ;
1476
1482
}
1477
1483
if (next_trans == 0 ) {
1478
1484
p_wait_ed -> trans_wait = 0 ;
0 commit comments