Browse Source

Add MIT license and a few extra comments

main
PaulStoffregen 7 years ago
parent
commit
36ca432baa
2 changed files with 63 additions and 4 deletions
  1. +27
    -1
      host.h
  2. +36
    -3
      k66_usbhost.ino

+ 27
- 1
host.h View File

#include <stdint.h>
/* USB EHCI Host for Teensy 3.6
* Copyright 2017 Paul Stoffregen (paul@pjrc.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef USB_HOST_TEENSY36_
#define USB_HOST_TEENSY36_


#include <stdint.h>


typedef struct Device_struct Device_t; typedef struct Device_struct Device_t;
typedef struct Pipe_struct Pipe_t; typedef struct Pipe_struct Pipe_t;
Transfer_t * allocate_Transfer(void); Transfer_t * allocate_Transfer(void);
void free_Transfer(Transfer_t *q); void free_Transfer(Transfer_t *q);


#endif

+ 36
- 3
k66_usbhost.ino View File

// usb host experiments....
/* USB EHCI Host for Teensy 3.6
* Copyright 2017 Paul Stoffregen (paul@pjrc.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


#include "host.h" #include "host.h"


Serial.print("sizeof Transfer = "); Serial.print("sizeof Transfer = ");
Serial.println(sizeof(Transfer_t)); Serial.println(sizeof(Transfer_t));


// configure the MPU to allow USBHS DMA to access memory
MPU_RGDAAC0 |= 0x30000000; MPU_RGDAAC0 |= 0x30000000;
Serial.print("MPU_RGDAAC0 = "); Serial.print("MPU_RGDAAC0 = ");
Serial.println(MPU_RGDAAC0, HEX); Serial.println(MPU_RGDAAC0, HEX);

// turn on clocks
MCG_C1 |= MCG_C1_IRCLKEN; // enable MCGIRCLK 32kHz MCG_C1 |= MCG_C1_IRCLKEN; // enable MCGIRCLK 32kHz
OSC0_CR |= OSC_ERCLKEN; OSC0_CR |= OSC_ERCLKEN;
SIM_SOPT2 |= SIM_SOPT2_USBREGEN; // turn on USB regulator SIM_SOPT2 |= SIM_SOPT2_USBREGEN; // turn on USB regulator
} }
Serial.print("PLL locked, waited "); Serial.print("PLL locked, waited ");
Serial.println(count); Serial.println(count);

// turn on power to PHY // turn on power to PHY
USBPHY_PWD = 0; USBPHY_PWD = 0;
delay(10); delay(10);
//SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(4); // MCGIRCLK //SIM_SOPT2 = SIM_SOPT2 & (~SIM_SOPT2_CLKOUTSEL(7)) | SIM_SOPT2_CLKOUTSEL(4); // MCGIRCLK
//CORE_PIN9_CONFIG = PORT_PCR_MUX(5); // CLKOUT on PTC3 Alt5 (Arduino pin 9) //CORE_PIN9_CONFIG = PORT_PCR_MUX(5); // CLKOUT on PTC3 Alt5 (Arduino pin 9)


// now with the PHY up and running, start up USBHS
print("begin ehci reset"); print("begin ehci reset");
USBHS_USBCMD |= USBHS_USBCMD_RST; USBHS_USBCMD |= USBHS_USBCMD_RST;
count = 0; count = 0;
USBHS_USBCMD_ASP(3) | USBHS_USBCMD_ASPE | USBHS_USBCMD_ASP(3) | USBHS_USBCMD_ASPE |
USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(1); // periodic table is 32 pointers USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(1); // periodic table is 32 pointers


// turn on the USB port
//USBHS_PORTSC1 = USBHS_PORTSC_PP; //USBHS_PORTSC1 = USBHS_PORTSC_PP;
USBHS_PORTSC1 |= USBHS_PORTSC_PP; USBHS_PORTSC1 |= USBHS_PORTSC_PP;
//USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec //USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
Serial.print("periodictable = "); Serial.print("periodictable = ");
Serial.println((uint32_t)periodictable, HEX); Serial.println((uint32_t)periodictable, HEX);


// enable interrupts, after this point interruts to all the work
NVIC_ENABLE_IRQ(IRQ_USBHS); NVIC_ENABLE_IRQ(IRQ_USBHS);
USBHS_USBINTR = USBHS_USBINTR_PCE | USBHS_USBINTR_TIE0; USBHS_USBINTR = USBHS_USBINTR_PCE | USBHS_USBINTR_TIE0;
USBHS_USBINTR |= USBHS_USBINTR_UEE | USBHS_USBINTR_SEE; USBHS_USBINTR |= USBHS_USBINTR_UEE | USBHS_USBINTR_SEE;
if (stat & USBHS_USBSTS_TI0) Serial.println(" Timer0"); if (stat & USBHS_USBSTS_TI0) Serial.println(" Timer0");
if (stat & USBHS_USBSTS_TI1) Serial.println(" Timer1"); if (stat & USBHS_USBSTS_TI1) Serial.println(" Timer1");


if (stat & USBHS_USBSTS_UAI) {
if (stat & USBHS_USBSTS_UAI) { // completed qTD(s) from the async schedule
Serial.println("Async Followup"); Serial.println("Async Followup");


Transfer_t *p, *prev=NULL, *next; Transfer_t *p, *prev=NULL, *next;
async_followup_last = prev; async_followup_last = prev;


} }
if (stat & USBHS_USBSTS_UPI) {
if (stat & USBHS_USBSTS_UPI) { // completed qTD(s) from the periodic schedule


} }




} }


// Create a new device and begin the enumeration process
//
Device_t * new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port) Device_t * new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port)
{ {
Device_t *dev; Device_t *dev;
(split_completion_mask << 8) | (interrupt_schedule_mask << 0) ); (split_completion_mask << 8) | (interrupt_schedule_mask << 0) );
} }


// Create a new pipe. It's QH is added to the async or periodic schedule,
// and a halt qTD is added to the QH, so we can grow the qTD list later.
//
Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t direction, Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t direction,
uint32_t max_packet_len) uint32_t max_packet_len)
{ {

Loading…
Cancel
Save