summaryrefslogtreecommitdiff
path: root/firmware/drivers/isp1583.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/isp1583.c')
-rw-r--r--firmware/drivers/isp1583.c114
1 files changed, 55 insertions, 59 deletions
diff --git a/firmware/drivers/isp1583.c b/firmware/drivers/isp1583.c
index 9e7d601278..f373741586 100644
--- a/firmware/drivers/isp1583.c
+++ b/firmware/drivers/isp1583.c
@@ -27,7 +27,7 @@
27#include "isp1583.h" 27#include "isp1583.h"
28#include "thread.h" 28#include "thread.h"
29#include "logf.h" 29#include "logf.h"
30#include <stdio.h> 30#include "stdio.h"
31 31
32#define DIR_RX 0 32#define DIR_RX 0
33#define DIR_TX 1 33#define DIR_TX 1
@@ -200,7 +200,9 @@ static int usb_receive(int n)
200 len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr, 200 len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr,
201 endpoints[n].in_max_len - endpoints[n].in_ptr); 201 endpoints[n].in_max_len - endpoints[n].in_ptr);
202 endpoints[n].in_ptr += len; 202 endpoints[n].in_ptr += len;
203 if (endpoints[n].in_ptr >= endpoints[n].in_min_len) { 203
204 if (endpoints[n].in_ptr >= endpoints[n].in_min_len)
205 {
204 endpoints[n].in_min_len = -1; 206 endpoints[n].in_min_len = -1;
205 if (endpoints[n].in_done) 207 if (endpoints[n].in_done)
206 (*(endpoints[n].in_done))(n, endpoints[n].in_buf, 208 (*(endpoints[n].in_done))(n, endpoints[n].in_buf,
@@ -229,10 +231,10 @@ static int usb_send(int n)
229 if (endpoints[n].halt[DIR_TX] 231 if (endpoints[n].halt[DIR_TX]
230 || !endpoints[n].enabled[DIR_TX] 232 || !endpoints[n].enabled[DIR_TX]
231 || !endpoints[n].out_in_progress) 233 || !endpoints[n].out_in_progress)
232 { 234 {
233 logf("NOT SEND TO EP!"); 235 logf("NOT SEND TO EP!");
234 return -1; 236 return -1;
235 } 237 }
236 238
237 if (endpoints[n].out_ptr < 0) 239 if (endpoints[n].out_ptr < 0)
238 { 240 {
@@ -246,9 +248,9 @@ static int usb_send(int n)
246 248
247 if (usb_out_buffer_full(n)) 249 if (usb_out_buffer_full(n))
248 { 250 {
249 logf("BUFFER FULL!"); 251 logf("BUFFER FULL!");
250 return -1; 252 return -1;
251 } 253 }
252 254
253 usb_select_endpoint(ep_index(n, DIR_TX)); 255 usb_select_endpoint(ep_index(n, DIR_TX));
254 max_pkt_size = endpoints[n].max_pkt_size[DIR_TX]; 256 max_pkt_size = endpoints[n].max_pkt_size[DIR_TX];
@@ -261,7 +263,8 @@ static int usb_send(int n)
261 263
262 p = endpoints[n].out_buf + endpoints[n].out_ptr; 264 p = endpoints[n].out_buf + endpoints[n].out_ptr;
263 i = 0; 265 i = 0;
264 while (len - i >= 2) { 266 while (len - i >= 2)
267 {
265 ISP1583_DFLOW_DATA = p[i] | (p[i + 1] << 8); 268 ISP1583_DFLOW_DATA = p[i] | (p[i + 1] << 8);
266 i += 2; 269 i += 2;
267 } 270 }
@@ -308,7 +311,11 @@ static void usb_unstall_endpoint(int idx)
308static void usb_status_ack(int ep, int dir) 311static void usb_status_ack(int ep, int dir)
309{ 312{
310 logf("usb_status_ack(%d)", dir); 313 logf("usb_status_ack(%d)", dir);
311 usb_select_endpoint(ep_index(ep, dir)); 314 if(ep == EP_CONTROL)
315 usb_select_setup_endpoint();
316 else
317 usb_select_endpoint(ep_index(ep, dir));
318
312 ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS; 319 ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS;
313} 320}
314 321
@@ -326,7 +333,10 @@ static void usb_handle_setup_rx(void)
326 len = usb_get_packet(setup_pkt_buf, 8); 333 len = usb_get_packet(setup_pkt_buf, 8);
327 334
328 if (len == 8) 335 if (len == 8)
336 {
337 ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS; /* Acknowledge packet */
329 usb_core_control_request((struct usb_ctrlrequest*)setup_pkt_buf); 338 usb_core_control_request((struct usb_ctrlrequest*)setup_pkt_buf);
339 }
330 else 340 else
331 { 341 {
332 usb_drv_stall(0, true, false); 342 usb_drv_stall(0, true, false);
@@ -388,9 +398,7 @@ void usb_helper(void)
388{ 398{
389 if(ISP1583_GEN_INT_READ & ISP1583_INIT_INTEN_READ) 399 if(ISP1583_GEN_INT_READ & ISP1583_INIT_INTEN_READ)
390 { 400 {
391 #ifdef DEBUG 401 logf("Helper detected interrupt... [%d]", (int)current_tick);
392 logf("Helper detected interrupt... [%d]", current_tick);
393 #endif
394 usb_drv_int(); 402 usb_drv_int();
395 } 403 }
396 return; 404 return;
@@ -413,14 +421,6 @@ void usb_drv_init(void)
413 /* Disable all OTG functions */ 421 /* Disable all OTG functions */
414 ISP1583_INIT_OTG = 0; 422 ISP1583_INIT_OTG = 0;
415 423
416#if 0
417 #ifdef USE_HIGH_SPEED
418 /* Force device to high speed */
419 ISP1583_GEN_TSTMOD = GEN_TSTMOD_FORCEHS;
420 high_speed_mode = true;
421 #endif
422#endif
423
424 #ifdef DEBUG 424 #ifdef DEBUG
425 logf("BUS_CONF/DA0:%d MODE0/DA1: %d MODE1: %d", (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST0), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST1), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST2)); 425 logf("BUS_CONF/DA0:%d MODE0/DA1: %d MODE1: %d", (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST0), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST1), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST2));
426 logf("Chip ID: 0x%x", ISP1583_GEN_CHIPID); 426 logf("Chip ID: 0x%x", ISP1583_GEN_CHIPID);
@@ -454,7 +454,7 @@ void usb_drv_init(void)
454 454
455 ZVM_SPECIFIC; 455 ZVM_SPECIFIC;
456 456
457 tick_add_task(usb_helper); 457 //tick_add_task(usb_helper);
458 458
459 logf("usb_init_device() finished"); 459 logf("usb_init_device() finished");
460} 460}
@@ -482,7 +482,7 @@ void usb_drv_exit(void)
482 ISP1583_INIT_MODE = INIT_MODE_GOSUSP; 482 ISP1583_INIT_MODE = INIT_MODE_GOSUSP;
483 ISP1583_INIT_MODE = 0; 483 ISP1583_INIT_MODE = 0;
484 484
485 tick_remove_task(usb_helper); 485 //tick_remove_task(usb_helper);
486 486
487 ZVM_SPECIFIC; 487 ZVM_SPECIFIC;
488} 488}
@@ -504,7 +504,7 @@ bool usb_drv_stalled(int endpoint, bool in)
504static void out_callback(int ep, unsigned char *buf, int len) 504static void out_callback(int ep, unsigned char *buf, int len)
505{ 505{
506 (void)buf; 506 (void)buf;
507 logf("out_callback(%d, 0x%x, %d)", ep, &buf, len); 507 logf("out_callback(%d, 0x%x, %d)", ep, (int)buf, len);
508 usb_status_ack(ep, DIR_RX); 508 usb_status_ack(ep, DIR_RX);
509 usb_core_transfer_complete(ep, true, 0, len); /* 0=>status succeeded, haven't worked out status failed yet... */ 509 usb_core_transfer_complete(ep, true, 0, len); /* 0=>status succeeded, haven't worked out status failed yet... */
510} 510}
@@ -512,14 +512,14 @@ static void out_callback(int ep, unsigned char *buf, int len)
512static void in_callback(int ep, unsigned char *buf, int len) 512static void in_callback(int ep, unsigned char *buf, int len)
513{ 513{
514 (void)buf; 514 (void)buf;
515 logf("in_callback(%d, 0x%x, %d)", ep, &buf, len); 515 logf("in_callback(%d, 0x%x, %d)", ep, (int)buf, len);
516 usb_status_ack(ep, DIR_TX); 516 usb_status_ack(ep, DIR_TX);
517 usb_core_transfer_complete(ep, false, 0, len); 517 usb_core_transfer_complete(ep, false, 0, len);
518} 518}
519 519
520int usb_drv_recv(int ep, void* ptr, int length) 520int usb_drv_recv(int ep, void* ptr, int length)
521{ 521{
522 logf("usb_drv_recv(%d, 0x%x, %d)", ep, &ptr, length); 522 logf("usb_drv_recv(%d, 0x%x, %d)", ep, (int)ptr, length);
523 if(ep == 0 && length == 0 && ptr == NULL) 523 if(ep == 0 && length == 0 && ptr == NULL)
524 { 524 {
525 usb_status_ack(ep, DIR_TX); 525 usb_status_ack(ep, DIR_TX);
@@ -562,7 +562,7 @@ static void usb_drv_wait(int ep, bool send)
562 562
563int usb_drv_send(int ep, void* ptr, int length) 563int usb_drv_send(int ep, void* ptr, int length)
564{ 564{
565 logf("usb_drv_send_nb(%d, 0x%x, %d)", ep, &ptr, length); 565 logf("usb_drv_send_nb(%d, 0x%x, %d)", ep, (int)ptr, length);
566 if(ep == 0 && length == 0 && ptr == NULL) 566 if(ep == 0 && length == 0 && ptr == NULL)
567 { 567 {
568 usb_status_ack(ep, DIR_RX); 568 usb_status_ack(ep, DIR_RX);
@@ -624,8 +624,6 @@ void usb_drv_release_endpoint(int ep)
624 endpoints[ep & 0x7f].allocation &= mask; 624 endpoints[ep & 0x7f].allocation &= mask;
625} 625}
626 626
627
628
629static void bus_reset(void) 627static void bus_reset(void)
630{ 628{
631 /* Enable CLKAON & GLINTENA */ 629 /* Enable CLKAON & GLINTENA */
@@ -656,13 +654,11 @@ void IRAM_ATTR usb_drv_int(void)
656 654
657 if(!ints) 655 if(!ints)
658 return; 656 return;
659 657
660 /* Unlock the device's registers */ 658 /* Unlock the device's registers */
661 ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE; 659 ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE;
662 660
663 #if 0 661 //logf(" handling int [0x%lx & 0x%lx = 0x%x]", ISP1583_GEN_INT_READ, ISP1583_INIT_INTEN_READ, (int)ints);
664 logf(" handling int [0x%x & 0x%x = 0x%x]", ISP1583_GEN_INT_READ, ISP1583_INIT_INTEN_READ, ints);
665 #endif
666 662
667 if(ints & INT_IEBRST) /* Bus reset */ 663 if(ints & INT_IEBRST) /* Bus reset */
668 { 664 {
@@ -732,10 +728,35 @@ void usb_drv_set_address(int address)
732 ISP1583_INIT_ADDRESS = (address & 0x7F) | INIT_ADDRESS_DEVEN; 728 ISP1583_INIT_ADDRESS = (address & 0x7F) | INIT_ADDRESS_DEVEN;
733 729
734 ZVM_SPECIFIC; 730 ZVM_SPECIFIC;
735
736 usb_status_ack(0, DIR_TX);
737} 731}
738 732
733void usb_drv_set_test_mode(int mode)
734{
735 logf("usb_drv_set_test_mode(%d)", mode);
736 switch(mode){
737 case 0:
738 ISP1583_GEN_TSTMOD = 0;
739 /* Power cycle... */
740 break;
741 case 1:
742 ISP1583_GEN_TSTMOD = GEN_TSTMOD_JSTATE;
743 break;
744 case 2:
745 ISP1583_GEN_TSTMOD = GEN_TSTMOD_KSTATE;
746 break;
747 case 3:
748 ISP1583_GEN_TSTMOD = GEN_TSTMOD_SE0_NAK;
749 break;
750 case 4:
751 //REG_PORTSC1 |= PORTSCX_PTC_PACKET;
752 break;
753 case 5:
754 //REG_PORTSC1 |= PORTSCX_PTC_FORCE_EN;
755 break;
756 }
757}
758
759#ifndef BOOTLOADER
739int dbg_usb_num_items(void) 760int dbg_usb_num_items(void)
740{ 761{
741 return 2+USB_NUM_ENDPOINTS*2; 762 return 2+USB_NUM_ENDPOINTS*2;
@@ -782,29 +803,4 @@ char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_le
782 return NULL; 803 return NULL;
783 (void)data; 804 (void)data;
784} 805}
785 806#endif
786void usb_drv_set_test_mode(int mode)
787{
788 logf("usb_drv_set_test_mode(%d)", mode);
789 switch(mode){
790 case 0:
791 ISP1583_GEN_TSTMOD = 0;
792 /* Power cycle... */
793 break;
794 case 1:
795 ISP1583_GEN_TSTMOD = GEN_TSTMOD_JSTATE;
796 break;
797 case 2:
798 ISP1583_GEN_TSTMOD = GEN_TSTMOD_KSTATE;
799 break;
800 case 3:
801 ISP1583_GEN_TSTMOD = GEN_TSTMOD_SE0_NAK;
802 break;
803 case 4:
804 //REG_PORTSC1 |= PORTSCX_PTC_PACKET;
805 break;
806 case 5:
807 //REG_PORTSC1 |= PORTSCX_PTC_FORCE_EN;
808 break;
809 }
810}