From b2baa22b71de98931e95b4b62e5ed00fd957ea6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98rn=20E=2E=20Hansen?= Date: Sun, 21 Apr 2013 21:28:45 +0000 Subject: [PATCH] USB, to add ohci/ehci. Make fifo comply with iorec --- i2cspi_BaS_gcc/Makefile | 4 +++- i2cspi_BaS_gcc/include/config.h | 4 ++++ i2cspi_BaS_gcc/include/fifo.h | 31 +++++++++++++++++++++++-------- i2cspi_BaS_gcc/sources/ehci-hcd.c | 7 ------- i2cspi_BaS_gcc/sources/fifo.c | 27 +++++++++++++-------------- i2cspi_BaS_gcc/sources/ohci-hcd.c | 8 -------- i2cspi_BaS_gcc/sources/usb.c | 18 +++--------------- 7 files changed, 46 insertions(+), 53 deletions(-) diff --git a/i2cspi_BaS_gcc/Makefile b/i2cspi_BaS_gcc/Makefile index 3b02850..f3a9e80 100644 --- a/i2cspi_BaS_gcc/Makefile +++ b/i2cspi_BaS_gcc/Makefile @@ -78,7 +78,9 @@ CSRCS= \ $(SRCDIR)/usb_kbd.c \ $(SRCDIR)/usb_mem.c \ $(SRCDIR)/usb_mouse.c \ - $(SRCDIR)/usb_storage.c + $(SRCDIR)/usb_storage.c \ + $(SRCDIR)/ehci-hcd.c \ + $(SRCDIR)/ohci-hcd.c ASRCS= \ $(SRCDIR)/startcf.S \ diff --git a/i2cspi_BaS_gcc/include/config.h b/i2cspi_BaS_gcc/include/config.h index 391e448..9a51fa5 100644 --- a/i2cspi_BaS_gcc/include/config.h +++ b/i2cspi_BaS_gcc/include/config.h @@ -1,6 +1,10 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ +#ifndef COLDFIRE +#define COLDFIRE +#endif + /* DEBUG */ #define DEBUG diff --git a/i2cspi_BaS_gcc/include/fifo.h b/i2cspi_BaS_gcc/include/fifo.h index 287fdff..b82182a 100644 --- a/i2cspi_BaS_gcc/include/fifo.h +++ b/i2cspi_BaS_gcc/include/fifo.h @@ -12,16 +12,31 @@ #include +/* + * FIFO + * + * Make this look exactly like IOREC, so that + * we can interchange the two. But ignore the + * low, high watermarks. For now. + * + * in IOREC, the notion of head/tail is opposite + * to ours. So we place our head/tail, in the + * equivalent positions as TOS use is. So + * we can use this structure, intermittantly + * with TOS. + */ typedef struct { - char * buf; - int head; - int tail; - int size; + char * buf; + int16_t size; + int16_t tail; + int16_t head; + int16_t low; + int16_t high; } fifo_t; -void fifo_init(fifo_t*, char*, int); -void fifo_advance(fifo_t*, int*); +void fifo_init(fifo_t*, char*, int16_t); +void fifo_advance(fifo_t*, int16_t*); uint8_t fifo_get(fifo_t*); void fifo_put(fifo_t*, uint8_t); @@ -34,7 +49,7 @@ int fifo_unused(fifo_t*); int fifo_full(fifo_t*); int fifo_empty(fifo_t*); -int fifo_read(fifo_t*, unsigned char *, int); -int fifo_write(fifo_t*, const unsigned char*, int); +int fifo_read(fifo_t*, unsigned char *, int16_t); +int fifo_write(fifo_t*, const unsigned char*, int16_t); #endif diff --git a/i2cspi_BaS_gcc/sources/ehci-hcd.c b/i2cspi_BaS_gcc/sources/ehci-hcd.c index 253e4f8..1079f31 100644 --- a/i2cspi_BaS_gcc/sources/ehci-hcd.c +++ b/i2cspi_BaS_gcc/sources/ehci-hcd.c @@ -28,13 +28,6 @@ #include "usb.h" #include "ehci.h" -#if defined(COLDFIRE) && defined(NETWORK) && defined(LWIP) -#include "../freertos/FreeRTOS.h" -#include "../freertos/queue.h" -extern xQueueHandle queue_poll_hub; -#define USB_POLL_HUB -#endif - #undef DEBUG #undef SHOW_INFO diff --git a/i2cspi_BaS_gcc/sources/fifo.c b/i2cspi_BaS_gcc/sources/fifo.c index 8338490..4d49620 100644 --- a/i2cspi_BaS_gcc/sources/fifo.c +++ b/i2cspi_BaS_gcc/sources/fifo.c @@ -8,12 +8,14 @@ #include //This initializes the FIFO structure with the given buffer and size -void fifo_init(fifo_t * f, char * buf, int size) +void fifo_init(fifo_t * f, char * buf, int16_t size) { f->head = 0; f->tail = 0; f->size = size; f->buf = buf; + f->low = 0; + f->high = 0; } // Get one byte from the fifo buffer @@ -21,11 +23,10 @@ uint8_t fifo_get(fifo_t *f) { uint8_t ch = 0; - if( f->tail != f->head && f->tail < f->size ) + if( !fifo_empty(f) ) { - ch = f->buf[f->tail++]; - if( f->tail >= f->size ) - f->tail = 0; + fifo_advance(f,&f->tail); + ch = f->buf[f->tail]; } return ch; @@ -34,10 +35,10 @@ uint8_t fifo_get(fifo_t *f) // Put one byte into the buffer void fifo_put(fifo_t *f, uint8_t byte) { - if( f->head == f->tail || f->head >= f->size ) + if( fifo_unused(f) <= 0 ) return; - f->buf[f->head] = byte; fifo_advance(f,&f->head); + f->buf[f->head] = byte; } void fifo_clear(fifo_t *f) @@ -71,7 +72,7 @@ int fifo_empty(fifo_t *f) return (f->head == f->tail); } -void fifo_advance(fifo_t *f, int *ix) +void fifo_advance(fifo_t *f, int16_t *ix) { if( ++*ix > f->size ) *ix=0; @@ -79,14 +80,13 @@ void fifo_advance(fifo_t *f, int *ix) //This reads at most nbytes bytes from the FIFO //The number of bytes read is returned -int fifo_read(fifo_t *f, unsigned char *buf, int nbytes){ +int fifo_read(fifo_t *f, unsigned char *buf, int16_t nbytes){ int n = 0; while( n < nbytes && !fifo_empty(f) ) { n++; - *buf++ = f->buf[f->tail]; - fifo_advance(f,&f->tail); + *buf++ = fifo_get(f); } return n; @@ -95,13 +95,12 @@ int fifo_read(fifo_t *f, unsigned char *buf, int nbytes){ //This writes up to nbytes bytes to the FIFO //If the head runs in to the tail, not all bytes are written //The number of bytes written is returned -int fifo_write(fifo_t *f, const unsigned char *buf, int nbytes){ +int fifo_write(fifo_t *f, const unsigned char *buf, int16_t nbytes){ int n = 0; while( n < nbytes && !fifo_full(f) ) { - f->buf[f->head] = *buf++; - fifo_advance(f,&f->head); + fifo_put(f,*buf++); n++; } diff --git a/i2cspi_BaS_gcc/sources/ohci-hcd.c b/i2cspi_BaS_gcc/sources/ohci-hcd.c index 506cf50..094ac26 100644 --- a/i2cspi_BaS_gcc/sources/ohci-hcd.c +++ b/i2cspi_BaS_gcc/sources/ohci-hcd.c @@ -49,14 +49,6 @@ #include "usb.h" #include "ohci.h" -#if defined(COLDFIRE) && defined(NETWORK) && defined(LWIP) -#include "../freertos/FreeRTOS.h" -#include "../freertos/queue.h" -extern xQueueHandle queue_poll_hub; -#define USB_POLL_HUB -#endif - - #undef OHCI_USE_NPS /* force NoPowerSwitching mode */ #undef OHCI_VERBOSE_DEBUG /* not always helpful */ diff --git a/i2cspi_BaS_gcc/sources/usb.c b/i2cspi_BaS_gcc/sources/usb.c index 736daae..5177ea9 100644 --- a/i2cspi_BaS_gcc/sources/usb.c +++ b/i2cspi_BaS_gcc/sources/usb.c @@ -48,18 +48,6 @@ #include "config.h" #include "usb.h" -#if defined(COLDFIRE) && defined(NETWORK) && defined(LWIP) -#include "../freertos/FreeRTOS.h" -#include "../freertos/task.h" -#include "../freertos/queue.h" -#include "../freertos/semphr.h" -#define USB_POLL_HUB -#ifdef CONFIG_USB_STORAGE -extern int usb_stor_curr_dev; -extern unsigned long usb_1st_disk_drive; -#endif -#endif - #if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || defined(CONFIG_USB_EHCI) #undef USB_DEBUG @@ -1181,7 +1169,7 @@ void usb_scan_devices(void *priv) dev = usb_alloc_new_device(bus_index, priv); if (usb_new_device(dev)) { - Cconws("No USB Device found\r\n"); + xprintf("No USB Device found\r\n"); USB_PRINTF("No USB Device found\r\n"); if (dev != NULL ) dev_index[bus_index]--; @@ -1197,13 +1185,13 @@ void usb_scan_devices(void *priv) if (drv_usb_kbd_init() < 0) USB_PRINTF("No USB keyboard found\r\n"); else - Cconws("USB HID keyboard driver installed\r\n"); + xprintf("USB HID keyboard driver installed\r\n"); #endif /* CONFIG_USB_KEYBOARD */ #ifdef CONFIG_USB_MOUSE if (drv_usb_mouse_init() < 0) USB_PRINTF("No USB mouse found\r\n"); else - Cconws("USB HID mouse driver installed\r\n"); + xprintf("USB HID mouse driver installed\r\n"); #endif /* CONFIG_USB_MOUSE */ #endif USB_PRINTF("Scan end\r\n");