sorted sources per functionality in different subdirs

This commit is contained in:
Markus Fröschle
2013-12-19 13:02:39 +00:00
parent 515bc6cee3
commit 72c7b9a963
47 changed files with 48 additions and 148 deletions

1619
BaS_gcc/usb/usb.c Normal file

File diff suppressed because it is too large Load Diff

279
BaS_gcc/usb/usb_mem.c Normal file
View File

@@ -0,0 +1,279 @@
/*
* usb_mem.c
*
* based from Emutos / BDOS
*
* Copyright (c) 2001 Lineo, Inc.
*
* Authors: Karl T. Braun, Martin Doering, Laurent Vogel
*
* This file is distributed under the GPL, version 2 or at your
* option any later version.
*/
#include <stdint.h>
#include "bas_string.h"
#include "bas_printf.h"
#include "usb.h"
#include "exceptions.h" /* set_ipl() */
#if MACHINE_FIREBEE
#include "firebee.h"
#elif MACHINE_M5484LITE
#include "m5484l.h"
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#undef USB_MEM_DEBUG
#ifdef USB_MEM_DEBUG
#define USB_MEM_PRINTF(fmt, args...) xprintf(fmt, ##args)
#else
#define USB_MEM_PRINTF(fmt, args...)
#endif
extern void *info_fvdi;
extern long offscren_reserved(void);
extern uint8_t usb_buffer[USB_BUFFER_SIZE]; /* defined in linker control file */
/* MD - Memory Descriptor */
#define MD struct _md_
MD
{
MD *m_link;
long m_start;
long m_length;
void *m_own;
};
/* MPB - Memory Partition Block */
#define MPB struct _mpb
MPB
{
MD *mp_mfl;
MD *mp_mal;
MD *mp_rover;
};
#define MAXMD 256
static MD tab_md[MAXMD];
static MPB pmd;
static void *xmgetblk(void)
{
int i;
for(i = 0; i < MAXMD; i++)
{
if (tab_md[i].m_own == NULL)
{
tab_md[i].m_own = (void*)1L;
return(&tab_md[i]);
}
}
return(NULL);
}
static void xmfreblk(void *m)
{
int i = (int)(((long)m - (long)tab_md) / sizeof(MD));
if ((i > 0) && (i < MAXMD))
tab_md[i].m_own = NULL;
}
static MD *ffit(long amount, MPB *mp)
{
MD *p, *q, *p1; /* free list is composed of MD's */
int maxflg;
long maxval;
if (amount != -1)
{
amount += 15; /* 16 bytes alignment */
amount &= 0xFFFFFFF0;
}
if ((q = mp->mp_rover) == 0) /* get rotating pointer */
return(0) ;
maxval = 0;
maxflg = ((amount == -1) ? TRUE : FALSE) ;
p = q->m_link; /* start with next MD */
do /* search the list for an MD with enough space */
{
if (p == 0)
{
/* at end of list, wrap back to start */
q = (MD *) &mp->mp_mfl; /* q => mfl field */
p = q->m_link; /* p => 1st MD */
}
if ((!maxflg) && (p->m_length >= amount))
{
/* big enough */
if (p->m_length == amount)
q->m_link = p->m_link; /* take the whole thing */
else
{
/* break it up - 1st allocate a new
MD to describe the remainder */
p1 = xmgetblk();
if (p1 == NULL)
return(NULL);
/* init new MD */
p1->m_length = p->m_length - amount;
p1->m_start = p->m_start + amount;
p1->m_link = p->m_link;
p->m_length = amount; /* adjust allocated block */
q->m_link = p1;
}
/* link allocate block into allocated list,
mark owner of block, & adjust rover */
p->m_link = mp->mp_mal;
mp->mp_mal = p;
mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q);
return(p); /* got some */
}
else if (p->m_length > maxval)
maxval = p->m_length;
p = ( q=p )->m_link;
}
while(q != mp->mp_rover);
/* return either the max, or 0 (error) */
if (maxflg)
{
maxval -= 15; /* 16 bytes alignment */
if (maxval < 0)
maxval = 0;
else
maxval &= 0xFFFFFFF0;
}
return(maxflg ? (MD *) maxval : 0);
}
static void freeit(MD *m, MPB *mp)
{
MD *p, *q;
q = 0;
for(p = mp->mp_mfl; p ; p = (q=p) -> m_link)
{
if (m->m_start <= p->m_start)
break;
}
m->m_link = p;
if (q)
q->m_link = m;
else
mp->mp_mfl = m;
if (!mp->mp_rover)
mp->mp_rover = m;
if (p)
{
if (m->m_start + m->m_length == p->m_start)
{ /* join to higher neighbor */
m->m_length += p->m_length;
m->m_link = p->m_link;
if (p == mp->mp_rover)
mp->mp_rover = m;
xmfreblk(p);
}
}
if (q)
{
if (q->m_start + q->m_length == m->m_start)
{ /* join to lower neighbor */
q->m_length += m->m_length;
q->m_link = m->m_link;
if (m == mp->mp_rover)
mp->mp_rover = q;
xmfreblk(m);
}
}
}
int usb_free(void *addr)
{
int level;
MD *p, **q;
MPB *mpb;
mpb = &pmd;
level = set_ipl(7);
for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link))
{
if ((long)addr == p->m_start)
break;
}
if (!p)
{
set_ipl(level);
return(-1);
}
*q = p->m_link;
freeit(p, mpb);
set_ipl(level);
USB_MEM_PRINTF("usb_free(0x%08X)\r\n", addr);
return(0);
}
void *usb_malloc(long amount)
{
void *ret = NULL;
int level;
MD *m;
if (amount == -1L)
return((void *)ffit(-1L, &pmd));
if (amount <= 0 )
return(0);
if ((amount & 1))
amount++;
level = set_ipl(7);
m = ffit(amount, &pmd);
if (m != NULL)
ret = (void *)m->m_start;
set_ipl(level);
USB_MEM_PRINTF("usb_malloc(%d) = 0x%08X\r\n", amount, ret);
return(ret);
}
int usb_mem_init(void)
{
#ifdef USE_RADEON_MEMORY
usb_buffer = (void *)offscren_reserved();
if (usb_buffer == NULL)
#endif
memset(usb_buffer, 0, USB_BUFFER_SIZE);
if (usb_buffer == NULL)
return(-1);
pmd.mp_mfl = pmd.mp_rover = &tab_md[0];
tab_md[0].m_link = (MD *)NULL;
tab_md[0].m_start = ((long)usb_buffer + 15) & ~15;
tab_md[0].m_length = USB_BUFFER_SIZE;
tab_md[0].m_own = (void *)1L;
pmd.mp_mal = (MD *)NULL;
memset(usb_buffer, 0, tab_md[0].m_length);
USB_MEM_PRINTF("USB malloc buffer at 0x%08X size %d\r\n", tab_md[0].m_start, tab_md[0].m_length);
return(0);
}
void usb_mem_stop(void)
{
#ifndef CONFIG_USB_MEM_NO_CACHE
#ifdef USE_RADEON_MEMORY
if (usb_buffer == (void *)offscren_reserved())
return;
#endif
#endif
}

235
BaS_gcc/usb/usb_mouse.c Normal file
View File

@@ -0,0 +1,235 @@
/*
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include <stdint.h>
#include "bas_printf.h"
#include "usb.h"
#include "exceptions.h"
#undef USB_MOUSE_DEBUG
#ifdef USB_MOUSE_DEBUG
#define mse_printf(fmt,args...) bas_printf(fmt ,##args)
#else
#define mse_printf(fmt,args...)
#endif
extern void ltoa(char *buf, long n, unsigned long base);
extern void call_mousevec(unsigned char *data, void (**mousevec)(void *));
//extern void call_ikbdvec(unsigned char code, _IOREC *iorec, void (**ikbdvec)());
static unsigned char *new;
static unsigned char old[8];
static int mouse_installed;
/* forward declaration */
static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum);
/* deregistering the mouse */
int usb_mouse_deregister(struct usb_device *dev)
{
dev->irq_handle = NULL;
if(new != NULL)
{
usb_free(new);
new = NULL;
}
mouse_installed = 0;
mse_printf("USB MOUSE deregister\r\n");
return 1;
}
/* registering the mouse */
int usb_mouse_register(struct usb_device *dev)
{
if(!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1))
{ /* Ok, we found a mouse */
mse_printf("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum);
mouse_installed = 1;
dev->deregister = usb_mouse_deregister;
return 1;
}
/* no USB Mouse found */
return -1;
}
/* search for mouse and register it if found */
int drv_usb_mouse_init(void)
{
int i, j;
if(mouse_installed)
return -1;
/* scan all USB Devices */
for(j = 0; j < USB_MAX_BUS; j++)
{
for(i = 0; i < USB_MAX_DEVICE; i++)
{
struct usb_device *dev = usb_get_dev_index(i, j); /* get device */
if(dev == NULL)
break;
if(usb_mouse_register(dev) > 0)
return 1;
}
}
/* no USB Mouse found */
return -1;
}
/**************************************************************************
* Low Level drivers
*/
static void usb_kbd_send_code(unsigned char code)
{
mse_printf("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code);
}
/* Interrupt service routine */
static int usb_mouse_irq(struct usb_device *dev)
{
#ifdef CONFIG_USB_INTERRUPT_POLLING
int level;
#endif
int i, change = 0;
if((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8))
{
mse_printf("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len);
return 1;
}
for(i = 0; i < dev->irq_act_len; i++)
{
if(new[i] != old[i])
{
change = 1;
break;
}
}
if(change)
{
char wheel = 0, buttons, old_buttons;
mse_printf("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]);
#ifdef CONFIG_USB_INTERRUPT_POLLING
level = set_ipl(7); /* mask interrupts */
#endif
if((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */
{
buttons = new[1];
old_buttons = old[1];
new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8;
new[1] = new[2];
new[2] = new[3];
wheel = new[4];
}
else /* boot report */
{
buttons = new[0];
old_buttons = old[0];
new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8;
if(dev->irq_act_len >= 3)
wheel = new[3];
}
if((buttons ^ old_buttons) & 4) /* 3rd button */
{
if(buttons & 4)
{
usb_kbd_send_code(0x72); /* ENTER */
usb_kbd_send_code(0xF2);
}
}
if(wheel != 0) /* actually like Eiffel */
{
#define REPEAT_WHEEL 3
int i;
if(wheel > 0)
{
for(i = 0; i < REPEAT_WHEEL; i++)
{
usb_kbd_send_code(0x48); /* UP */
usb_kbd_send_code(0xC8);
}
}
else
{
for(i = 0; i < REPEAT_WHEEL; i++)
{
usb_kbd_send_code(0x50); /* DOWN */
usb_kbd_send_code(0xD0);
}
}
}
xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n");
//if(mousevec != NULL)
//call_mousevec(new, mousevec);
#ifdef CONFIG_USB_INTERRUPT_POLLING
set_ipl(level);
#endif
old[0] = new[0];
old[1] = new[1];
old[2] = new[2];
old[3] = new[3];
old[4] = new[4];
old[5] = new[5];
}
return 1; /* install IRQ Handler again */
}
/* probes the USB device dev for mouse type */
static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum)
{
struct usb_interface_descriptor *iface;
struct usb_endpoint_descriptor *ep;
int pipe, maxp;
if(dev->descriptor.bNumConfigurations != 1)
return 0;
iface = &dev->config.if_desc[ifnum];
if(iface->bInterfaceClass != 3)
return 0;
if(iface->bInterfaceSubClass != 1)
return 0;
if(iface->bInterfaceProtocol != 2)
return 0;
if(iface->bNumEndpoints != 1)
return 0;
ep = &iface->ep_desc[0];
if(!(ep->bEndpointAddress & 0x80))
return 0;
if((ep->bmAttributes & 3) != 3)
return 0;
new = (unsigned char *)usb_malloc(8);
if(new == NULL)
return 0;
mse_printf("USB MOUSE found set protocol...\r\n");
/* ok, we found a USB Mouse, install it */
pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
maxp = usb_maxpacket(dev, pipe);
// if(maxp < 6)
// usb_set_protocol(dev, iface->bInterfaceNumber, 0); /* boot */
// else
usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */
mse_printf("USB MOUSE found set idle...\r\n");
usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */
memset(&new[0], 0, 8);
memset(&old[0], 0, 8);
dev->irq_handle = usb_mouse_irq;
mse_printf("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp);
usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval);
return 1;
}