|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
-
-
- #include "usb_dev.h"
- #if F_CPU >= 20000000 && defined(NUM_ENDPOINTS)
-
- #include "kinetis.h"
-
- #include "usb_mem.h"
-
- __attribute__ ((section(".usbbuffers"), used))
- unsigned char usb_buffer_memory[NUM_USB_BUFFERS * sizeof(usb_packet_t)];
-
- static uint32_t usb_buffer_available = 0xFFFFFFFF;
-
-
-
-
-
-
- usb_packet_t * usb_malloc(void)
- {
- unsigned int n, avail;
- uint8_t *p;
-
- __disable_irq();
- avail = usb_buffer_available;
- n = __builtin_clz(avail);
- if (n >= NUM_USB_BUFFERS) {
- __enable_irq();
- return NULL;
- }
-
-
-
-
- usb_buffer_available = avail & ~(0x80000000 >> n);
- __enable_irq();
- p = usb_buffer_memory + (n * sizeof(usb_packet_t));
-
-
-
- *(uint32_t *)p = 0;
- *(uint32_t *)(p + 4) = 0;
- return (usb_packet_t *)p;
- }
-
-
- extern uint8_t usb_rx_memory_needed;
- extern void usb_rx_memory(usb_packet_t *packet);
-
- void usb_free(usb_packet_t *p)
- {
- unsigned int n, mask;
-
-
- n = ((uint8_t *)p - usb_buffer_memory) / sizeof(usb_packet_t);
- if (n >= NUM_USB_BUFFERS) return;
-
-
-
-
-
- if (usb_rx_memory_needed && usb_configuration) {
-
-
-
- usb_rx_memory(p);
- return;
- }
-
- mask = (0x80000000 >> n);
- __disable_irq();
- usb_buffer_available |= mask;
- __enable_irq();
-
-
-
-
- }
-
- #endif
|