You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

573 lines
18KB

  1. // usb host experiments....
  2. #include "host.h"
  3. uint32_t periodictable[32] __attribute__ ((aligned(4096), used));
  4. uint8_t port_state;
  5. #define PORT_STATE_DISCONNECTED 0
  6. #define PORT_STATE_DEBOUNCE 1
  7. #define PORT_STATE_RESET 2
  8. #define PORT_STATE_RECOVERY 3
  9. #define PORT_STATE_ACTIVE 4
  10. Device_t *rootdev=NULL;
  11. void setup()
  12. {
  13. // Test board has a USB data mux (this won't be on final Teensy 3.6)
  14. pinMode(32, OUTPUT); // pin 32 = USB switch, high=connect device
  15. digitalWrite(32, LOW);
  16. pinMode(30, OUTPUT); // pin 30 = debug info - use oscilloscope
  17. digitalWrite(30, LOW);
  18. // Teensy 3.6 has USB host power controlled by PTE6
  19. PORTE_PCR6 = PORT_PCR_MUX(1);
  20. GPIOE_PDDR |= (1<<6);
  21. GPIOE_PSOR = (1<<6); // turn on USB host power
  22. while (!Serial) ; // wait
  23. Serial.println("USB Host Testing");
  24. Serial.print("sizeof Device = ");
  25. Serial.println(sizeof(Device_t));
  26. Serial.print("sizeof Pipe = ");
  27. Serial.println(sizeof(Pipe_t));
  28. Serial.print("sizeof Transfer = ");
  29. Serial.println(sizeof(Transfer_t));
  30. MPU_RGDAAC0 |= 0x30000000;
  31. Serial.print("MPU_RGDAAC0 = ");
  32. Serial.println(MPU_RGDAAC0, HEX);
  33. MCG_C1 |= MCG_C1_IRCLKEN; // enable MCGIRCLK 32kHz
  34. OSC0_CR |= OSC_ERCLKEN;
  35. SIM_SOPT2 |= SIM_SOPT2_USBREGEN; // turn on USB regulator
  36. SIM_SOPT2 &= ~SIM_SOPT2_USBSLSRC; // use IRC for slow clock
  37. print("power up USBHS PHY");
  38. SIM_USBPHYCTL |= SIM_USBPHYCTL_USBDISILIM; // disable USB current limit
  39. //SIM_USBPHYCTL = SIM_USBPHYCTL_USBDISILIM | SIM_USBPHYCTL_USB3VOUTTRG(6); // pg 237
  40. SIM_SCGC3 |= SIM_SCGC3_USBHSDCD | SIM_SCGC3_USBHSPHY | SIM_SCGC3_USBHS;
  41. USBHSDCD_CLOCK = 33 << 2;
  42. print("init USBHS PHY & PLL");
  43. // init process: page 1681-1682
  44. USBPHY_CTRL_CLR = (USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE); // // CTRL pg 1698
  45. USBPHY_TRIM_OVERRIDE_EN_SET = 1;
  46. USBPHY_PLL_SIC = USBPHY_PLL_SIC_PLL_POWER | USBPHY_PLL_SIC_PLL_ENABLE |
  47. USBPHY_PLL_SIC_PLL_DIV_SEL(1) | USBPHY_PLL_SIC_PLL_EN_USB_CLKS;
  48. // wait for the PLL to lock
  49. int count=0;
  50. while ((USBPHY_PLL_SIC & USBPHY_PLL_SIC_PLL_LOCK) == 0) {
  51. count++;
  52. }
  53. Serial.print("PLL locked, waited ");
  54. Serial.println(count);
  55. // turn on power to PHY
  56. USBPHY_PWD = 0;
  57. delay(10);
  58. // sanity check, connect 470K pullup & 100K pulldown and watch D+ voltage change
  59. //USBPHY_ANACTRL_CLR = (1<<10); // turn off both 15K pulldowns... works! :)
  60. // sanity check, output clocks on pin 9 for testing
  61. //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(3); // LPO 1kHz
  62. //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(2); // Flash
  63. //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(6); // XTAL
  64. //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(7); // IRC 48MHz
  65. //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(4); // MCGIRCLK
  66. //CORE_PIN9_CONFIG = PORT_PCR_MUX(5); // CLKOUT on PTC3 Alt5 (Arduino pin 9)
  67. print("begin ehci reset");
  68. USBHS_USBCMD |= USBHS_USBCMD_RST;
  69. count = 0;
  70. while (USBHS_USBCMD & USBHS_USBCMD_RST) {
  71. count++;
  72. }
  73. print(" reset waited ", count);
  74. for (int i=0; i < 32; i++) {
  75. periodictable[i] = 1;
  76. }
  77. port_state = PORT_STATE_DISCONNECTED;
  78. USBHS_USB_SBUSCFG = 1; // System Bus Interface Configuration
  79. // turn on the USBHS controller
  80. //USBHS_USBMODE = USBHS_USBMODE_TXHSD(5) | USBHS_USBMODE_CM(3); // host mode
  81. USBHS_USBMODE = USBHS_USBMODE_CM(3); // host mode
  82. USBHS_USBINTR = 0;
  83. USBHS_PERIODICLISTBASE = (uint32_t)periodictable;
  84. USBHS_FRINDEX = 0;
  85. USBHS_ASYNCLISTADDR = 0;
  86. USBHS_USBCMD = USBHS_USBCMD_ITC(8) | USBHS_USBCMD_RS |
  87. USBHS_USBCMD_ASP(3) | USBHS_USBCMD_ASPE |
  88. USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(1); // periodic table is 32 pointers
  89. //USBHS_PORTSC1 = USBHS_PORTSC_PP;
  90. USBHS_PORTSC1 |= USBHS_PORTSC_PP;
  91. //USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
  92. //USBHS_PORTSC1 |= USBHS_PORTSC_PHCD; // phy off
  93. Serial.print("USBHS_ASYNCLISTADDR = ");
  94. Serial.println(USBHS_ASYNCLISTADDR, HEX);
  95. Serial.print("USBHS_PERIODICLISTBASE = ");
  96. Serial.println(USBHS_PERIODICLISTBASE, HEX);
  97. Serial.print("periodictable = ");
  98. Serial.println((uint32_t)periodictable, HEX);
  99. NVIC_ENABLE_IRQ(IRQ_USBHS);
  100. USBHS_USBINTR = USBHS_USBINTR_UE | USBHS_USBINTR_PCE | USBHS_USBINTR_TIE0;
  101. USBHS_USBINTR |= USBHS_USBINTR_UEE | USBHS_USBINTR_SEE;
  102. USBHS_USBINTR |= USBHS_USBINTR_AAE;
  103. delay(25);
  104. Serial.println("Plug in device...");
  105. digitalWrite(32, HIGH); // connect device
  106. delay(5000);
  107. Serial.println();
  108. Serial.println("Ring Doorbell");
  109. USBHS_USBCMD |= USBHS_USBCMD_IAA;
  110. if (rootdev) print(rootdev->control_pipe);
  111. }
  112. void loop()
  113. {
  114. }
  115. void pulse(int usec)
  116. {
  117. // connect oscilloscope to see these pulses....
  118. digitalWriteFast(30, HIGH);
  119. delayMicroseconds(usec);
  120. digitalWriteFast(30, LOW);
  121. }
  122. // EHCI registers page default
  123. // -------------- ---- -------
  124. // USBHS_USBCMD 1599 00080000 USB Command
  125. // USBHS_USBSTS 1602 00000000 USB Status
  126. // USBHS_USBINTR 1606 00000000 USB Interrupt Enable
  127. // USBHS_FRINDEX 1609 00000000 Frame Index Register
  128. // USBHS_PERIODICLISTBASE 1610 undefine Periodic Frame List Base Address
  129. // USBHS_ASYNCLISTADDR 1612 undefine Asynchronous List Address
  130. // USBHS_PORTSC1 1619 00002000 Port Status and Control
  131. // USBHS_USBMODE 1629 00005000 USB Mode
  132. // USBHS_GPTIMERnCTL 1591 00000000 General Purpose Timer n Control
  133. // PORT_STATE_DISCONNECTED 0
  134. // PORT_STATE_DEBOUNCE 1
  135. // PORT_STATE_RESET 2
  136. // PORT_STATE_RECOVERY 3
  137. // PORT_STATE_ACTIVE 4
  138. void usbhs_isr(void)
  139. {
  140. uint32_t stat = USBHS_USBSTS;
  141. USBHS_USBSTS = stat; // clear pending interrupts
  142. //stat &= USBHS_USBINTR; // mask away unwanted interrupts
  143. Serial.println();
  144. Serial.print("ISR: ");
  145. Serial.print(stat, HEX);
  146. Serial.println();
  147. if (stat & USBHS_USBSTS_UI) Serial.println(" USB Interrupt");
  148. if (stat & USBHS_USBSTS_UEI) Serial.println(" USB Error");
  149. if (stat & USBHS_USBSTS_PCI) Serial.println(" Port Change");
  150. if (stat & USBHS_USBSTS_FRI) Serial.println(" Frame List Rollover");
  151. if (stat & USBHS_USBSTS_SEI) Serial.println(" System Error");
  152. if (stat & USBHS_USBSTS_AAI) Serial.println(" Async Advance (doorbell)");
  153. if (stat & USBHS_USBSTS_URI) Serial.println(" Reset Recv");
  154. if (stat & USBHS_USBSTS_SRI) Serial.println(" SOF");
  155. if (stat & USBHS_USBSTS_SLI) Serial.println(" Suspend");
  156. if (stat & USBHS_USBSTS_HCH) Serial.println(" Host Halted");
  157. if (stat & USBHS_USBSTS_RCL) Serial.println(" Reclamation");
  158. if (stat & USBHS_USBSTS_PS) Serial.println(" Periodic Sched En");
  159. if (stat & USBHS_USBSTS_AS) Serial.println(" Async Sched En");
  160. if (stat & USBHS_USBSTS_NAKI) Serial.println(" NAK");
  161. if (stat & USBHS_USBSTS_UAI) Serial.println(" USB Async");
  162. if (stat & USBHS_USBSTS_UPI) Serial.println(" USB Periodic");
  163. if (stat & USBHS_USBSTS_TI0) Serial.println(" Timer0");
  164. if (stat & USBHS_USBSTS_TI1) Serial.println(" Timer1");
  165. if (stat & USBHS_USBSTS_PCI) { // port change detected
  166. const uint32_t portstat = USBHS_PORTSC1;
  167. Serial.print("port change: ");
  168. Serial.print(portstat, HEX);
  169. Serial.println();
  170. USBHS_PORTSC1 = portstat | (USBHS_PORTSC_OCC|USBHS_PORTSC_PEC|USBHS_PORTSC_CSC);
  171. if (portstat & USBHS_PORTSC_OCC) {
  172. Serial.println(" overcurrent change");
  173. }
  174. if (portstat & USBHS_PORTSC_CSC) {
  175. if (portstat & USBHS_PORTSC_CCS) {
  176. Serial.println(" connect");
  177. if (port_state == PORT_STATE_DISCONNECTED
  178. || port_state == PORT_STATE_DEBOUNCE) {
  179. // 100 ms debounce (USB 2.0: TATTDB, page 150 & 188)
  180. port_state = PORT_STATE_DEBOUNCE;
  181. USBHS_GPTIMER0LD = 100000; // microseconds
  182. USBHS_GPTIMER0CTL =
  183. USBHS_GPTIMERCTL_RST | USBHS_GPTIMERCTL_RUN;
  184. stat &= ~USBHS_USBSTS_TI0;
  185. }
  186. // TODO: should ENHOSTDISCONDETECT be set? K66 ref, page 1701
  187. } else {
  188. Serial.println(" disconnect");
  189. port_state = PORT_STATE_DISCONNECTED;
  190. // TODO: delete & clean up device state...
  191. }
  192. }
  193. if (portstat & USBHS_PORTSC_PEC) {
  194. // PEC bit only detects disable
  195. Serial.println(" disable");
  196. } else if (port_state == PORT_STATE_RESET && portstat & USBHS_PORTSC_PE) {
  197. Serial.println(" port enabled");
  198. port_state = PORT_STATE_RECOVERY;
  199. // 10 ms reset recover (USB 2.0: TRSTRCY, page 151 & 188)
  200. USBHS_GPTIMER0LD = 10000; // microseconds
  201. USBHS_GPTIMER0CTL = USBHS_GPTIMERCTL_RST | USBHS_GPTIMERCTL_RUN;
  202. }
  203. if (portstat & USBHS_PORTSC_FPR) {
  204. Serial.println(" force resume");
  205. }
  206. pulse(1);
  207. }
  208. if (stat & USBHS_USBSTS_TI0) { // timer 0
  209. Serial.println("timer");
  210. pulse(2);
  211. if (port_state == PORT_STATE_DEBOUNCE) {
  212. port_state = PORT_STATE_RESET;
  213. USBHS_PORTSC1 |= USBHS_PORTSC_PR; // begin reset sequence
  214. Serial.println(" begin reset");
  215. } else if (port_state == PORT_STATE_RECOVERY) {
  216. port_state = PORT_STATE_ACTIVE;
  217. Serial.println(" end recovery");
  218. // HCSPARAMS TTCTRL page 1671
  219. uint32_t speed = (USBHS_PORTSC1 >> 26) & 3;
  220. rootdev = new_Device(speed, 0, 0);
  221. }
  222. }
  223. }
  224. Device_t * new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port)
  225. {
  226. Device_t *dev;
  227. Serial.print("new_Device: ");
  228. switch (speed) {
  229. case 0: Serial.print("12"); break;
  230. case 1: Serial.print("1.5"); break;
  231. case 2: Serial.print("480"); break;
  232. default: Serial.print("??");
  233. }
  234. Serial.println(" Mbit/sec");
  235. dev = allocate_Device();
  236. if (!dev) return NULL;
  237. dev->speed = speed;
  238. dev->address = 0;
  239. dev->hub_address = hub_addr;
  240. dev->hub_port = hub_port;
  241. dev->control_pipe = new_Pipe(dev, 0, 0, 0, 8);
  242. if (!dev->control_pipe) {
  243. free_Device(dev);
  244. return NULL;
  245. }
  246. static uint8_t buffer[8];
  247. dev->control_pipe->direction = 1; // 1=IN
  248. dev->setup.bmRequestType = 0x80;
  249. dev->setup.bRequest = 0x06; // 6=GET_DESCRIPTOR
  250. dev->setup.wValue = 0x0100;
  251. dev->setup.wIndex = 0x0000;
  252. dev->setup.wLength = 8;
  253. new_Transfer(dev->control_pipe, buffer, 8);
  254. return dev;
  255. }
  256. static uint32_t QH_capabilities1(uint32_t nak_count_reload, uint32_t control_endpoint_flag,
  257. uint32_t max_packet_length, uint32_t head_of_list, uint32_t data_toggle_control,
  258. uint32_t speed, uint32_t endpoint_number, uint32_t inactivate, uint32_t address)
  259. {
  260. return ( (nak_count_reload << 28) | (control_endpoint_flag << 27) |
  261. (max_packet_length << 16) | (head_of_list << 15) |
  262. (data_toggle_control << 14) | (speed << 12) | (endpoint_number << 8) |
  263. (inactivate << 7) | (address << 0) );
  264. }
  265. static uint32_t QH_capabilities2(uint32_t high_bw_mult, uint32_t hub_port_number,
  266. uint32_t hub_address, uint32_t split_completion_mask, uint32_t interrupt_schedule_mask)
  267. {
  268. return ( (high_bw_mult << 30) | (hub_port_number << 23) | (hub_address << 16) |
  269. (split_completion_mask << 8) | (interrupt_schedule_mask << 0) );
  270. }
  271. Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t direction,
  272. uint32_t max_packet_len)
  273. {
  274. Pipe_t *pipe;
  275. Transfer_t *halt;
  276. uint32_t c=0, dtc=0;
  277. Serial.println("new_Pipe");
  278. pipe = allocate_Pipe();
  279. if (!pipe) return NULL;
  280. halt = allocate_Transfer();
  281. if (!halt) {
  282. free_Pipe(pipe);
  283. return NULL;
  284. }
  285. memset(pipe, 0, sizeof(Pipe_t));
  286. memset(halt, 0, sizeof(Transfer_t));
  287. halt->qtd.next = 1;
  288. halt->qtd.token = 0x40;
  289. pipe->device = dev;
  290. pipe->qh.next = (uint32_t)halt;
  291. pipe->qh.alt_next = 1;
  292. pipe->direction = direction;
  293. pipe->type = type;
  294. if (type == 0) {
  295. // control
  296. if (dev->speed < 2) c = 1;
  297. dtc = 1;
  298. } else if (type == 2) {
  299. // bulk
  300. } else if (type == 3) {
  301. // interrupt
  302. }
  303. pipe->qh.capabilities[0] = QH_capabilities1(15, c, max_packet_len, 0,
  304. dtc, dev->speed, endpoint, 0, dev->address);
  305. pipe->qh.capabilities[1] = QH_capabilities2(1, dev->hub_port,
  306. dev->hub_address, 0, 0);
  307. if (type == 0 || type == 2) {
  308. // control or bulk: add to async queue
  309. Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR;
  310. if (list == NULL) {
  311. pipe->qh.capabilities[0] |= 0x8000; // H bit
  312. pipe->qh.horizontal_link = (uint32_t)&(pipe->qh) | 2; // 2=QH
  313. USBHS_ASYNCLISTADDR = (uint32_t)&(pipe->qh);
  314. USBHS_USBCMD |= USBHS_USBCMD_ASE; // enable async schedule
  315. Serial.println(" first in async list");
  316. } else {
  317. // EHCI 1.0: section 4.8.1, page 72
  318. pipe->qh.horizontal_link = list->qh.horizontal_link;
  319. list->qh.horizontal_link = (uint32_t)&(pipe->qh) | 2;
  320. Serial.println(" added to async list");
  321. }
  322. } else if (type == 3) {
  323. // interrupt: add to periodic schedule
  324. // TODO: link it into the periodic table
  325. }
  326. return pipe;
  327. }
  328. // Fill in the qTD fields (token & data)
  329. // t the Transfer qTD to initialize
  330. // buf data to transfer
  331. // len length of data
  332. // pid type of packet: 0=OUT, 1=IN, 2=SETUP
  333. // data01 value of DATA0/DATA1 toggle on 1st packet
  334. // irq whether to generate an interrupt when transfer complete
  335. //
  336. void init_qTD(volatile Transfer_t *t, void *buf, uint32_t len,
  337. uint32_t pid, uint32_t data01, bool irq)
  338. {
  339. t->qtd.alt_next = 1; // 1=terminate
  340. if (data01) data01 = 0x80000000;
  341. t->qtd.token = data01 | (len << 16) | (irq ? 0x8000 : 0) | (pid << 8) | 0x80;
  342. uint32_t addr = (uint32_t)buf;
  343. t->qtd.buffer[0] = addr;
  344. addr &= 0xFFFFF000;
  345. t->qtd.buffer[1] = addr + 0x1000;
  346. t->qtd.buffer[2] = addr + 0x2000;
  347. t->qtd.buffer[3] = addr + 0x3000;
  348. t->qtd.buffer[4] = addr + 0x4000;
  349. }
  350. // Create a Transfer and queue it
  351. //
  352. bool new_Transfer(Pipe_t *pipe, void *buffer, uint32_t len)
  353. {
  354. Serial.println("new_Transfer");
  355. Transfer_t *transfer = allocate_Transfer();
  356. if (!transfer) return false;
  357. transfer->pipe = pipe;
  358. if (pipe->type == 0) {
  359. // control transfer
  360. Transfer_t *data, *status;
  361. uint32_t status_direction;
  362. if (len > 16384) {
  363. free_Transfer(transfer);
  364. return false;
  365. }
  366. status = allocate_Transfer();
  367. if (!status) {
  368. free_Transfer(transfer);
  369. return false;
  370. }
  371. if (len > 0) {
  372. data = allocate_Transfer();
  373. if (!data) {
  374. free_Transfer(transfer);
  375. free_Transfer(status);
  376. return false;
  377. }
  378. init_qTD(data, buffer, len, pipe->direction, 1, false);
  379. transfer->qtd.next = (uint32_t)data;
  380. data->qtd.next = (uint32_t)status;
  381. data->pipe = pipe;
  382. status_direction = pipe->direction ^ 1;
  383. } else {
  384. transfer->qtd.next = (uint32_t)status;
  385. status_direction = 1; // always IN, USB 2.0 page 226
  386. }
  387. Serial.print("setup address ");
  388. Serial.println((uint32_t)&pipe->device->setup, HEX);
  389. init_qTD(transfer, &pipe->device->setup, 8, 2, 0, false);
  390. init_qTD(status, NULL, 0, status_direction, 1, true);
  391. status->pipe = pipe;
  392. status->qtd.next = 1;
  393. } else {
  394. // bulk, interrupt or isochronous transfer
  395. free_Transfer(transfer);
  396. return false;
  397. }
  398. Transfer_t *halt = (Transfer_t *)(pipe->qh.next);
  399. while (!(halt->qtd.token & 0x40)) halt = (Transfer_t *)(halt->qtd.next);
  400. uint32_t token = transfer->qtd.token;
  401. transfer->qtd.token = 0x40; // transfer becomes new halt qTD
  402. halt->qtd.next = transfer->qtd.next;
  403. halt->qtd.alt_next = transfer->qtd.alt_next;
  404. halt->qtd.buffer[0] = transfer->qtd.buffer[0];
  405. halt->qtd.buffer[1] = transfer->qtd.buffer[1];
  406. halt->qtd.buffer[2] = transfer->qtd.buffer[2];
  407. halt->qtd.buffer[3] = transfer->qtd.buffer[3];
  408. halt->qtd.buffer[4] = transfer->qtd.buffer[4];
  409. halt->pipe = pipe;
  410. Transfer_t *last = transfer;
  411. while ((uint32_t)(last->qtd.next) != 1) last = (Transfer_t *)(last->qtd.next);
  412. last->qtd.next = (uint32_t)transfer;
  413. transfer->qtd.next = 1;
  414. halt->qtd.token = token; // old halt becomes new transfer
  415. return true;
  416. }
  417. void print(const Transfer_t *transfer)
  418. {
  419. if (!((uint32_t)transfer & 0xFFFFFFE0)) return;
  420. Serial.print("Transfer @ ");
  421. Serial.println(((uint32_t)transfer & 0xFFFFFFE0), HEX);
  422. Serial.print(" next: ");
  423. Serial.println(transfer->qtd.next, HEX);
  424. Serial.print(" anext: ");
  425. Serial.println(transfer->qtd.alt_next, HEX);
  426. Serial.print(" token: ");
  427. Serial.println(transfer->qtd.token, HEX);
  428. Serial.print(" bufs: ");
  429. for (int i=0; i < 5; i++) {
  430. Serial.print(transfer->qtd.buffer[i], HEX);
  431. if (i < 4) Serial.print(',');
  432. }
  433. Serial.println();
  434. }
  435. void print(const Pipe_t *pipe)
  436. {
  437. if (!((uint32_t)pipe & 0xFFFFFFE0)) return;
  438. Serial.print("Pipe ");
  439. if (pipe->type == 0) Serial.print("control");
  440. else if (pipe->type == 1) Serial.print("isochronous");
  441. else if (pipe->type == 2) Serial.print("bulk");
  442. else if (pipe->type == 3) Serial.print("interrupt");
  443. Serial.print(pipe->direction ? " IN" : " OUT");
  444. Serial.print(" @ ");
  445. Serial.println((uint32_t)pipe, HEX);
  446. Serial.print(" horiz link: ");
  447. Serial.println(pipe->qh.horizontal_link, HEX);
  448. Serial.print(" capabilities: ");
  449. Serial.print(pipe->qh.capabilities[0], HEX);
  450. Serial.print(',');
  451. Serial.println(pipe->qh.capabilities[1], HEX);
  452. Serial.println(" overlay:");
  453. Serial.print(" cur: ");
  454. Serial.println(pipe->qh.current, HEX);
  455. Serial.print(" next: ");
  456. Serial.println(pipe->qh.next, HEX);
  457. Serial.print(" anext: ");
  458. Serial.println(pipe->qh.alt_next, HEX);
  459. Serial.print(" token: ");
  460. Serial.println(pipe->qh.token, HEX);
  461. Serial.print(" bufs: ");
  462. for (int i=0; i < 5; i++) {
  463. Serial.print(pipe->qh.buffer[i], HEX);
  464. if (i < 4) Serial.print(',');
  465. }
  466. Serial.println();
  467. const Transfer_t *t = (Transfer_t *)pipe->qh.next;
  468. while (((uint32_t)t & 0xFFFFFFE0)) {
  469. print(t);
  470. t = (Transfer_t *)t->qtd.next;
  471. }
  472. //Serial.print();
  473. }
  474. void print(const char *s)
  475. {
  476. Serial.println(s);
  477. delay(10);
  478. }
  479. void print(const char *s, int num)
  480. {
  481. Serial.print(s);
  482. Serial.println(num);
  483. delay(10);
  484. }
  485. // Memory allocation... for now, just simplest leaky way to get started
  486. Device_t * allocate_Device(void)
  487. {
  488. static Device_t mem[3];
  489. static size_t count=0;
  490. if (count >= sizeof(mem)/sizeof(Device_t)) return NULL;
  491. return &mem[count++];
  492. }
  493. void free_Device(Device_t *q)
  494. {
  495. }
  496. Pipe_t * allocate_Pipe(void)
  497. {
  498. static Pipe_t mem[6] __attribute__ ((aligned(64)));
  499. static size_t count=0;
  500. if (count >= sizeof(mem)/sizeof(Pipe_t)) return NULL;
  501. return &mem[count++];
  502. }
  503. void free_Pipe(Pipe_t *q)
  504. {
  505. }
  506. Transfer_t * allocate_Transfer(void)
  507. {
  508. static Transfer_t mem[22] __attribute__ ((aligned(64)));
  509. static size_t count=0;
  510. if (count >= sizeof(mem)/sizeof(Transfer_t)) return NULL;
  511. return &mem[count++];
  512. }
  513. void free_Transfer(Transfer_t *q)
  514. {
  515. }