Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

573 rindas
17KB

  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. Transfer_t *transfer = new_Transfer(dev->control_pipe, buffer, 8);
  254. //print(dev->control_pipe);
  255. if (transfer) queue_Transfer(transfer);
  256. return dev;
  257. }
  258. static uint32_t QH_capabilities1(uint32_t nak_count_reload, uint32_t control_endpoint_flag,
  259. uint32_t max_packet_length, uint32_t head_of_list, uint32_t data_toggle_control,
  260. uint32_t speed, uint32_t endpoint_number, uint32_t inactivate, uint32_t address)
  261. {
  262. return ( (nak_count_reload << 28) | (control_endpoint_flag << 27) |
  263. (max_packet_length << 16) | (head_of_list << 15) |
  264. (data_toggle_control << 14) | (speed << 12) | (endpoint_number << 8) |
  265. (inactivate << 7) | (address << 0) );
  266. }
  267. static uint32_t QH_capabilities2(uint32_t high_bw_mult, uint32_t hub_port_number,
  268. uint32_t hub_address, uint32_t split_completion_mask, uint32_t interrupt_schedule_mask)
  269. {
  270. return ( (high_bw_mult << 30) | (hub_port_number << 23) | (hub_address << 16) |
  271. (split_completion_mask << 8) | (interrupt_schedule_mask << 0) );
  272. }
  273. Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t direction,
  274. uint32_t max_packet_len)
  275. {
  276. Pipe_t *pipe;
  277. uint32_t c=0, dtc=0;
  278. Serial.println("new_Pipe");
  279. pipe = allocate_Pipe();
  280. if (!pipe) return NULL;
  281. pipe->device = dev;
  282. pipe->qh.current = 0;
  283. pipe->qh.next = 1;
  284. pipe->qh.alt_next = 1;
  285. pipe->qh.token = 0;
  286. pipe->qh.buffer[0] = 0;
  287. pipe->qh.buffer[1] = 0;
  288. pipe->qh.buffer[2] = 0;
  289. pipe->qh.buffer[3] = 0;
  290. pipe->qh.buffer[4] = 0;
  291. pipe->direction = direction;
  292. pipe->type = type;
  293. if (type == 0) {
  294. // control
  295. if (dev->speed < 2) c = 1;
  296. dtc = 1;
  297. } else if (type == 2) {
  298. // bulk
  299. } else if (type == 3) {
  300. // interrupt
  301. }
  302. pipe->qh.capabilities[0] = QH_capabilities1(15, c, max_packet_len, 0,
  303. dtc, dev->speed, endpoint, 0, dev->address);
  304. pipe->qh.capabilities[1] = QH_capabilities2(1, dev->hub_port,
  305. dev->hub_address, 0, 0);
  306. #if 1
  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. #endif
  327. return pipe;
  328. }
  329. // Fill in the qTD fields (token & data)
  330. // t the Transfer qTD to initialize
  331. // buf data to transfer
  332. // len length of data
  333. // pid type of packet: 0=OUT, 1=IN, 2=SETUP
  334. // data01 value of DATA0/DATA1 toggle on 1st packet
  335. // irq whether to generate an interrupt when transfer complete
  336. //
  337. void init_qTD(volatile Transfer_t *t, void *buf, uint32_t len,
  338. uint32_t pid, uint32_t data01, bool irq)
  339. {
  340. t->qtd.alt_next = 1; // 1=terminate
  341. if (data01) data01 = 0x80000000;
  342. t->qtd.token = data01 | (len << 16) | (irq ? 0x8000 : 0) | (pid << 8) | 0x80;
  343. uint32_t addr = (uint32_t)buf;
  344. t->qtd.buffer[0] = addr;
  345. addr &= 0xFFFFF000;
  346. t->qtd.buffer[1] = addr + 0x1000;
  347. t->qtd.buffer[2] = addr + 0x2000;
  348. t->qtd.buffer[3] = addr + 0x3000;
  349. t->qtd.buffer[4] = addr + 0x4000;
  350. }
  351. // Create a list of Transfers
  352. //
  353. Transfer_t * new_Transfer(Pipe_t *pipe, void *buffer, uint32_t len)
  354. {
  355. Serial.println("new_Transfer");
  356. Transfer_t *transfer = allocate_Transfer();
  357. if (!transfer) return NULL;
  358. transfer->pipe = pipe;
  359. if (pipe->type == 0) {
  360. // control transfer
  361. Transfer_t *data, *status;
  362. uint32_t status_direction;
  363. if (len > 16384) {
  364. free_Transfer(transfer);
  365. return NULL;
  366. }
  367. status = allocate_Transfer();
  368. if (!status) {
  369. free_Transfer(transfer);
  370. return NULL;
  371. }
  372. if (len > 0) {
  373. data = allocate_Transfer();
  374. if (!data) {
  375. free_Transfer(transfer);
  376. free_Transfer(status);
  377. return NULL;
  378. }
  379. init_qTD(data, buffer, len, pipe->direction, 1, false);
  380. transfer->qtd.next = (uint32_t)data;
  381. data->qtd.next = (uint32_t)status;
  382. data->pipe = pipe;
  383. status_direction = pipe->direction ^ 1;
  384. } else {
  385. transfer->qtd.next = (uint32_t)status;
  386. status_direction = 1; // always IN, USB 2.0 page 226
  387. }
  388. Serial.print("setup address ");
  389. Serial.println((uint32_t)&pipe->device->setup, HEX);
  390. init_qTD(transfer, &pipe->device->setup, 8, 2, 0, false);
  391. init_qTD(status, NULL, 0, status_direction, 1, true);
  392. status->pipe = pipe;
  393. status->qtd.next = 1;
  394. } else {
  395. // bulk, interrupt or isochronous transfer
  396. free_Transfer(transfer);
  397. return NULL;
  398. }
  399. return transfer;
  400. }
  401. void queue_Transfer(Transfer_t *transfer)
  402. {
  403. Serial.println("queue_Transfer");
  404. Pipe_t *pipe = transfer->pipe;
  405. Transfer_t *last = (Transfer_t *)(pipe->qh.next);
  406. if ((uint32_t)last & 1) {
  407. pipe->qh.next = (uint32_t)transfer;
  408. Serial.println(" first on QH");
  409. } else {
  410. while ((last->qtd.next & 1) == 0) last = (Transfer_t *)(last->qtd.next);
  411. // TODO: what happens if qTD is completed before we write to it?
  412. last->qtd.next = (uint32_t)transfer;
  413. Serial.println(" added to qTD list");
  414. }
  415. }
  416. void print(const Transfer_t *transfer)
  417. {
  418. if (!((uint32_t)transfer & 0xFFFFFFE0)) return;
  419. Serial.print("Transfer @ ");
  420. Serial.println(((uint32_t)transfer & 0xFFFFFFE0), HEX);
  421. Serial.print(" next: ");
  422. Serial.println(transfer->qtd.next, HEX);
  423. Serial.print(" anext: ");
  424. Serial.println(transfer->qtd.alt_next, HEX);
  425. Serial.print(" token: ");
  426. Serial.println(transfer->qtd.token, HEX);
  427. Serial.print(" bufs: ");
  428. for (int i=0; i < 5; i++) {
  429. Serial.print(transfer->qtd.buffer[i], HEX);
  430. if (i < 4) Serial.print(',');
  431. }
  432. Serial.println();
  433. }
  434. void print(const Pipe_t *pipe)
  435. {
  436. if (!((uint32_t)pipe & 0xFFFFFFE0)) return;
  437. Serial.print("Pipe ");
  438. if (pipe->type == 0) Serial.print("control");
  439. else if (pipe->type == 1) Serial.print("isochronous");
  440. else if (pipe->type == 2) Serial.print("bulk");
  441. else if (pipe->type == 3) Serial.print("interrupt");
  442. Serial.print(pipe->direction ? " IN" : " OUT");
  443. Serial.print(" @ ");
  444. Serial.println((uint32_t)pipe, HEX);
  445. Serial.print(" horiz link: ");
  446. Serial.println(pipe->qh.horizontal_link, HEX);
  447. Serial.print(" capabilities: ");
  448. Serial.print(pipe->qh.capabilities[0], HEX);
  449. Serial.print(',');
  450. Serial.println(pipe->qh.capabilities[1], HEX);
  451. Serial.println(" overlay:");
  452. Serial.print(" cur: ");
  453. Serial.println(pipe->qh.current, HEX);
  454. Serial.print(" next: ");
  455. Serial.println(pipe->qh.next, HEX);
  456. Serial.print(" anext: ");
  457. Serial.println(pipe->qh.alt_next, HEX);
  458. Serial.print(" token: ");
  459. Serial.println(pipe->qh.token, HEX);
  460. Serial.print(" bufs: ");
  461. for (int i=0; i < 5; i++) {
  462. Serial.print(pipe->qh.buffer[i], HEX);
  463. if (i < 4) Serial.print(',');
  464. }
  465. Serial.println();
  466. const Transfer_t *t = (Transfer_t *)pipe->qh.next;
  467. while (((uint32_t)t & 0xFFFFFFE0)) {
  468. print(t);
  469. t = (Transfer_t *)t->qtd.next;
  470. }
  471. //Serial.print();
  472. }
  473. void print(const char *s)
  474. {
  475. Serial.println(s);
  476. delay(10);
  477. }
  478. void print(const char *s, int num)
  479. {
  480. Serial.print(s);
  481. Serial.println(num);
  482. delay(10);
  483. }
  484. // Memory allocation... for now, just simplest leaky way to get started
  485. Device_t * allocate_Device(void)
  486. {
  487. static Device_t mem[3];
  488. static size_t count=0;
  489. if (count >= sizeof(mem)/sizeof(Device_t)) return NULL;
  490. return &mem[count++];
  491. }
  492. void free_Device(Device_t *q)
  493. {
  494. }
  495. Pipe_t * allocate_Pipe(void)
  496. {
  497. static Pipe_t mem[6] __attribute__ ((aligned(64)));
  498. static size_t count=0;
  499. if (count >= sizeof(mem)/sizeof(Pipe_t)) return NULL;
  500. return &mem[count++];
  501. }
  502. void free_Pipe(Pipe_t *q)
  503. {
  504. }
  505. Transfer_t * allocate_Transfer(void)
  506. {
  507. static Transfer_t mem[22] __attribute__ ((aligned(64)));
  508. static size_t count=0;
  509. if (count >= sizeof(mem)/sizeof(Transfer_t)) return NULL;
  510. return &mem[count++];
  511. }
  512. void free_Transfer(Transfer_t *q)
  513. {
  514. }