|
|
|
|
|
|
|
|
volatile uint8_t usb_configuration = 0; // non-zero when USB host as configured device |
|
|
volatile uint8_t usb_configuration = 0; // non-zero when USB host as configured device |
|
|
volatile uint8_t usb_high_speed = 0; // non-zero if running at 480 Mbit/sec speed |
|
|
volatile uint8_t usb_high_speed = 0; // non-zero if running at 480 Mbit/sec speed |
|
|
static uint8_t endpoint0_buffer[8]; |
|
|
static uint8_t endpoint0_buffer[8]; |
|
|
|
|
|
static uint8_t sof_usage = 0; |
|
|
static uint8_t usb_reboot_timer = 0; |
|
|
static uint8_t usb_reboot_timer = 0; |
|
|
|
|
|
|
|
|
extern uint8_t usb_descriptor_buffer[]; // defined in usb_desc.c |
|
|
extern uint8_t usb_descriptor_buffer[]; // defined in usb_desc.c |
|
|
|
|
|
|
|
|
printf("sof %d\n", usb_reboot_timer); |
|
|
printf("sof %d\n", usb_reboot_timer); |
|
|
if (usb_reboot_timer) { |
|
|
if (usb_reboot_timer) { |
|
|
if (--usb_reboot_timer == 0) { |
|
|
if (--usb_reboot_timer == 0) { |
|
|
|
|
|
usb_stop_sof_interrupts(NUM_INTERFACE); |
|
|
asm("bkpt #251"); // run bootloader |
|
|
asm("bkpt #251"); // run bootloader |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
// turn off the SOF interrupt if nothing using it |
|
|
|
|
|
USB1_USBINTR &= ~USB_USBINTR_SRE; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
#ifdef MIDI_INTERFACE |
|
|
|
|
|
usb_midi_flush_output(); |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void usb_start_sof_interrupts(int interface) |
|
|
|
|
|
{ |
|
|
|
|
|
__disable_irq(); |
|
|
|
|
|
sof_usage |= (1 << interface); |
|
|
|
|
|
uint32_t intr = USB1_USBINTR; |
|
|
|
|
|
if (!(intr & USB_USBINTR_SRE)) { |
|
|
|
|
|
USB1_USBSTS = USB_USBSTS_SRI; // clear prior SOF before SOF IRQ enable |
|
|
|
|
|
USB1_USBINTR = intr | USB_USBINTR_SRE; |
|
|
|
|
|
} |
|
|
|
|
|
__enable_irq(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void usb_stop_sof_interrupts(int interface) |
|
|
|
|
|
{ |
|
|
|
|
|
sof_usage &= ~(1 << interface); |
|
|
|
|
|
if (sof_usage == 0) { |
|
|
|
|
|
USB1_USBINTR &= ~USB_USBINTR_SRE; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
struct transfer_struct { // table 55-60, pg 3159 |
|
|
struct transfer_struct { // table 55-60, pg 3159 |
|
|
uint32_t next; |
|
|
uint32_t next; |
|
|
|
|
|
|
|
|
memcpy(usb_cdc_line_coding, endpoint0_buffer, 7); |
|
|
memcpy(usb_cdc_line_coding, endpoint0_buffer, 7); |
|
|
printf("usb_cdc_line_coding, baud=%u\n", usb_cdc_line_coding[0]); |
|
|
printf("usb_cdc_line_coding, baud=%u\n", usb_cdc_line_coding[0]); |
|
|
if (usb_cdc_line_coding[0] == 134) { |
|
|
if (usb_cdc_line_coding[0] == 134) { |
|
|
USB1_USBINTR |= USB_USBINTR_SRE; |
|
|
|
|
|
|
|
|
usb_start_sof_interrupts(NUM_INTERFACE); |
|
|
usb_reboot_timer = 80; // TODO: 10 if only 12 Mbit/sec |
|
|
usb_reboot_timer = 80; // TODO: 10 if only 12 Mbit/sec |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
&& endpoint0_buffer[0] == 0xA9 && endpoint0_buffer[1] == 0x45 |
|
|
&& endpoint0_buffer[0] == 0xA9 && endpoint0_buffer[1] == 0x45 |
|
|
&& endpoint0_buffer[2] == 0xC2 && endpoint0_buffer[3] == 0x6B) { |
|
|
&& endpoint0_buffer[2] == 0xC2 && endpoint0_buffer[3] == 0x6B) { |
|
|
printf("seremu reboot request\n"); |
|
|
printf("seremu reboot request\n"); |
|
|
USB1_USBINTR |= USB_USBINTR_SRE; |
|
|
|
|
|
|
|
|
usb_start_sof_interrupts(NUM_INTERFACE); |
|
|
usb_reboot_timer = 80; // TODO: 10 if only 12 Mbit/sec |
|
|
usb_reboot_timer = 80; // TODO: 10 if only 12 Mbit/sec |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |