X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=teensy3%2Fusb_dev.c;h=5ff87267cf10ff7a7d53c0bb606bb1fc9e3be005;hb=be48e888050f18a31e788269c8f47358036a8e3b;hp=92dbd32981114dacfa5fee50168222e8e8b6089b;hpb=35f00b6caaac4a8b93247913f0863bcd8f419041;p=megadrive.git diff --git a/teensy3/usb_dev.c b/teensy3/usb_dev.c index 92dbd32..5ff8726 100644 --- a/teensy3/usb_dev.c +++ b/teensy3/usb_dev.c @@ -10,10 +10,10 @@ * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * - * 1. The above copyright notice and this permission notice shall be + * 1. The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * 2. If the Software is incorporated into a build system that allows + * 2. If the Software is incorporated into a build system that allows * selection among a list of target devices, then similar target * devices manufactured by PJRC.COM must be included in the list of * target devices and selectable in the same manner. @@ -28,9 +28,11 @@ * SOFTWARE. */ -#include "mk20dx128.h" -//#include "HardwareSerial.h" #include "usb_dev.h" +#if F_CPU >= 20000000 && defined(NUM_ENDPOINTS) + +#include "kinetis.h" +//#include "HardwareSerial.h" #include "usb_mem.h" // buffer descriptor table @@ -286,7 +288,7 @@ static void usb_setup(void) //serial_print("\n"); for (list = usb_descriptor_list; 1; list++) { if (list->addr == NULL) break; - //if (setup.wValue == list->wValue && + //if (setup.wValue == list->wValue && //(setup.wIndex == list->wIndex) || ((setup.wValue >> 8) == 3)) { if (setup.wValue == list->wValue && setup.wIndex == list->wIndex) { data = list->addr; @@ -529,13 +531,13 @@ usb_packet_t *usb_rx(uint32_t endpoint) usb_packet_t *ret; endpoint--; if (endpoint >= NUM_ENDPOINTS) return NULL; - __disable_irq(); + __mask_irq(); ret = rx_first[endpoint]; if (ret) { rx_first[endpoint] = ret->next; usb_rx_byte_count_data[endpoint] -= ret->len; } - __enable_irq(); + __unmask_irq(); //serial_print("rx, epidx="); //serial_phex(endpoint); //serial_print(", packet="); @@ -548,11 +550,11 @@ static uint32_t usb_queue_byte_count(const usb_packet_t *p) { uint32_t count=0; - __disable_irq(); + __mask_irq(); for ( ; p; p = p->next) { count += p->len; } - __enable_irq(); + __unmask_irq(); return count; } @@ -581,9 +583,9 @@ uint32_t usb_tx_packet_count(uint32_t endpoint) endpoint--; if (endpoint >= NUM_ENDPOINTS) return 0; - __disable_irq(); + __mask_irq(); for (p = tx_first[endpoint]; p; p = p->next) count++; - __enable_irq(); + __unmask_irq(); return count; } @@ -603,14 +605,14 @@ void usb_rx_memory(usb_packet_t *packet) cfg = usb_endpoint_config_table; //serial_print("rx_mem:"); - __disable_irq(); + __mask_irq(); for (i=1; i <= NUM_ENDPOINTS; i++) { if (*cfg++ & USB_ENDPT_EPRXEN) { if (table[index(i, RX, EVEN)].desc == 0) { table[index(i, RX, EVEN)].addr = packet->buf; table[index(i, RX, EVEN)].desc = BDT_DESC(64, 0); usb_rx_memory_needed--; - __enable_irq(); + __unmask_irq(); //serial_phex(i); //serial_print(",even\n"); return; @@ -619,17 +621,17 @@ void usb_rx_memory(usb_packet_t *packet) table[index(i, RX, ODD)].addr = packet->buf; table[index(i, RX, ODD)].desc = BDT_DESC(64, 1); usb_rx_memory_needed--; - __enable_irq(); + __unmask_irq(); //serial_phex(i); //serial_print(",odd\n"); return; } } } - __enable_irq(); + __unmask_irq(); // we should never reach this point. If we get here, it means // usb_rx_memory_needed was set greater than zero, but no memory - // was actually needed. + // was actually needed. usb_rx_memory_needed = 0; usb_free(packet); return; @@ -645,7 +647,7 @@ void usb_tx(uint32_t endpoint, usb_packet_t *packet) endpoint--; if (endpoint >= NUM_ENDPOINTS) return; - __disable_irq(); + __mask_irq(); //serial_print("txstate="); //serial_phex(tx_state[endpoint]); //serial_print("\n"); @@ -671,13 +673,13 @@ void usb_tx(uint32_t endpoint, usb_packet_t *packet) tx_last[endpoint]->next = packet; } tx_last[endpoint] = packet; - __enable_irq(); + __unmask_irq(); return; } tx_state[endpoint] = next; b->addr = packet->buf; b->desc = BDT_DESC(packet->len, ((uint32_t)b & 8) ? DATA1 : DATA0); - __enable_irq(); + __unmask_irq(); } @@ -688,7 +690,7 @@ void usb_tx(uint32_t endpoint, usb_packet_t *packet) void _reboot_Teensyduino_(void) { // TODO: initialize R0 with a code.... - asm volatile("bkpt"); + __asm__ volatile("bkpt"); } @@ -867,7 +869,7 @@ void usb_isr(void) table[index(0, RX, ODD)].addr = ep0_rx1_buf; table[index(0, TX, EVEN)].desc = 0; table[index(0, TX, ODD)].desc = 0; - + // activate endpoint 0 USB0_ENDPT0 = USB_ENDPT_EPRXEN | USB_ENDPT_EPTXEN | USB_ENDPT_EPHSHK; @@ -969,4 +971,10 @@ void usb_init(void) } +#else // F_CPU < 20 MHz && defined(NUM_ENDPOINTS) + +void usb_init(void) +{ +} +#endif // F_CPU >= 20 MHz && defined(NUM_ENDPOINTS)