1
0
Fork 0
forked from len0rd/rockbox

code police part one...

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14499 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Peter D'Hoye 2007-08-29 00:33:16 +00:00
parent c04dd32772
commit 5f59f94554
2 changed files with 70 additions and 46 deletions

View file

@ -147,14 +147,18 @@ void usb_arcotg_dcd_init(void)
ep_num++;
}
logf("pipe %d -> ep %d %s", dcd_controller.endpoints[i].pipe_num, dcd_controller.endpoints[i].ep_num, dcd_controller.endpoints[i].name);
logf("pipe %d -> ep %d %s", dcd_controller.endpoints[i].pipe_num,
dcd_controller.endpoints[i].ep_num,
dcd_controller.endpoints[i].name);
if (ep_name[i] != NULL) {
memcpy(&dcd_controller.endpoints[i].name, ep_name[i], sizeof(dcd_controller.endpoints[i].name));
memcpy(&dcd_controller.endpoints[i].name, ep_name[i],
sizeof(dcd_controller.endpoints[i].name));
if (i != 0) {
/* add to list of configurable endpoints */
list_add_tail(&dcd_controller.endpoints[i].list, &arcotg_dcd.endpoints.list);
list_add_tail(&dcd_controller.endpoints[i].list,
&arcotg_dcd.endpoints.list);
}
}
}
@ -230,7 +234,8 @@ void usb_arcotg_dcd_irq(void)
/* setup packet, we only support ep0 as control ep */
if (UDC_ENDPTSETUPSTAT & EP_SETUP_STATUS_EP0) {
/* copy data from queue head to local buffer */
memcpy(&dcd_controller.local_setup_buff, (uint8_t *) &dev_qh[0].setup_buffer, 8);
memcpy(&dcd_controller.local_setup_buff,
(uint8_t *) &dev_qh[0].setup_buffer, 8);
/* ack setup packet*/
UDC_ENDPTSETUPSTAT = UDC_ENDPTSETUPSTAT;
setup_received_int(&dcd_controller.local_setup_buff);
@ -306,7 +311,9 @@ static void setup_received_int(struct usb_ctrlrequest* request)
int num = (request->wIndex & 0x000f);
struct usb_ep *ep;
if (request->wValue != 0 || request->wLength != 0 || (num * 2 + dir) > USB_MAX_PIPES) {
if (request->wValue != 0 ||
request->wLength != 0 ||
(num * 2 + dir) > USB_MAX_PIPES) {
break;
}
ep = &dcd_controller.endpoints[num * 2 + dir];
@ -335,7 +342,8 @@ static void setup_received_int(struct usb_ctrlrequest* request)
/* if dcd can not handle reqeust, ask driver */
if (handled == 0) {
if (arcotg_dcd.device_driver != NULL && arcotg_dcd.device_driver->request != NULL) {
if (arcotg_dcd.device_driver != NULL &&
arcotg_dcd.device_driver->request != NULL) {
handled = arcotg_dcd.device_driver->request(request);
logf("result from driver %d", handled);
}
@ -389,7 +397,8 @@ static void port_change_int(void)
}
/* inform device driver */
if (arcotg_dcd.device_driver != NULL && arcotg_dcd.device_driver->speed != NULL) {
if (arcotg_dcd.device_driver != NULL &&
arcotg_dcd.device_driver->speed != NULL) {
arcotg_dcd.device_driver->speed(speed);
}
}
@ -401,7 +410,8 @@ static void suspend_int(void)
dcd_controller.usb_state = USB_STATE_SUSPENDED;
/* report suspend to the driver */
if (arcotg_dcd.device_driver != NULL && arcotg_dcd.device_driver->suspend != NULL) {
if (arcotg_dcd.device_driver != NULL &&
arcotg_dcd.device_driver->suspend != NULL) {
arcotg_dcd.device_driver->suspend();
}
}
@ -413,7 +423,8 @@ static void resume_int(void)
dcd_controller.resume_state = USB_STATE_NOTATTACHED;
/* report resume to the driver */
if (arcotg_dcd.device_driver != NULL && arcotg_dcd.device_driver->resume != NULL) {
if (arcotg_dcd.device_driver != NULL &&
arcotg_dcd.device_driver->resume != NULL) {
arcotg_dcd.device_driver->resume();
}
}
@ -455,7 +466,8 @@ static void reset_int(void)
/*-------------------------------------------------------------------------*/
/* usb controller ops */
int usb_arcotg_dcd_enable(struct usb_ep* ep, struct usb_endpoint_descriptor* desc)
int usb_arcotg_dcd_enable(struct usb_ep* ep,
struct usb_endpoint_descriptor* desc)
{
unsigned short max = 0;
unsigned char mult = 0, zlt = 0;
@ -610,7 +622,8 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep, struct usb_endpoint_descriptor* des
/* Init endpoint x at here */
ep_setup(ep->ep_num,
(unsigned char)(desc->bEndpointAddress & USB_DIR_IN) ? USB_RECV : USB_SEND,
(unsigned char)(desc->bEndpointAddress & USB_DIR_IN) ?
USB_RECV : USB_SEND,
(unsigned char)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK));
/* Now HW will be NAKing transfers to that EP,
@ -810,8 +823,9 @@ int usb_arcotg_dcd_receive(struct usb_ep* ep, struct usb_response* res)
/*-------------------------------------------------------------------------*/
/* lifecylce */
static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_type,
unsigned int max_pkt_len, unsigned int zlt, unsigned char mult)
static void qh_init(unsigned char ep_num, unsigned char dir,
unsigned char ep_type, unsigned int max_pkt_len,
unsigned int zlt, unsigned char mult)
{
struct dqh *qh = &dev_qh[2 * ep_num + dir];
uint32_t tmp = 0;
@ -824,7 +838,8 @@ static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_ty
tmp = (max_pkt_len << LENGTH_BIT_POS) | INTERRUPT_ON_COMPLETE;
break;
case USB_ENDPOINT_XFER_ISOC:
tmp = (max_pkt_len << LENGTH_BIT_POS) | (mult << EP_QUEUE_HEAD_MULT_POS);
tmp = (max_pkt_len << LENGTH_BIT_POS) |
(mult << EP_QUEUE_HEAD_MULT_POS);
break;
case USB_ENDPOINT_XFER_BULK:
case USB_ENDPOINT_XFER_INT:
@ -840,7 +855,8 @@ static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_ty
/* see 32.14.4.1 Queue Head Initialization */
/* write the wMaxPacketSize field as required by the USB Chapter9 or application specific portocol */
/* write the wMaxPacketSize field as required by the USB Chapter9 or
application specific portocol */
qh->endpt_cap = tmp;
/* write the next dTD Terminate bit fild to 1 */
@ -871,13 +887,15 @@ static void td_init(struct dtd* td, void* buffer, uint32_t todo)
/* set interrupt on compilte if desierd */
td->dtd_token |= INTERRUPT_ON_COMPLETE;
/* initialize the status field with the active bit set to 1 and all remaining status bits to 0 */
/* initialize the status field with the active bit set to 1 and all
remaining status bits to 0 */
td->dtd_token |= STATUS_ACTIVE;
td->buf_ptr0 = (uint32_t)buffer;
}
static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type)
static void ep_setup(unsigned char ep_num, unsigned char dir,
unsigned char ep_type)
{
unsigned int tmp_epctrl = 0;
struct timer t;
@ -904,7 +922,8 @@ static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_t
/* wait for the write reg to finish */
timer_set(&t, SETUP_TIMER);
while (!(UDC_ENDPTCTRL(ep_num) & (tmp_epctrl & (EPCTRL_TX_ENABLE | EPCTRL_RX_ENABLE)))) {
while (!(UDC_ENDPTCTRL(ep_num) &
(tmp_epctrl & (EPCTRL_TX_ENABLE | EPCTRL_RX_ENABLE)))) {
if (timer_expired(&t)) {
logf("TIMEOUT: enable ep");
return;

View file

@ -40,7 +40,7 @@
/*-------------------------------------------------------------------------*/
#define ep_is_in(EP) (((EP)->desc->bEndpointAddress & USB_DIR_IN)==USB_DIR_IN)
#define ep_is_in(EP) (((EP)->desc->bEndpointAddress & USB_DIR_IN)==USB_DIR_IN)
#define EP_DIR_IN 1
#define EP_DIR_OUT 0
@ -52,30 +52,30 @@
#define USB_SEND (1) /* IN EP */
/* Shared Bit Masks for Endpoint Queue Head and Endpoint Transfer Descriptor */
#define TERMINATE (1 << 0)
#define STATUS_ACTIVE (1 << 7)
#define STATUS_HALTED (1 << 6)
#define STATUS_DATA_BUFF_ERR (1 << 5)
#define STATUS_TRANSACTION_ERR (1 << 4)
#define INTERRUPT_ON_COMPLETE (1 << 15)
#define LENGTH_BIT_POS (16)
#define ADDRESS_MASK (0xFFFFFFE0)
#define ERROR_MASK (DTD_STATUS_HALTED | \
DTD_STATUS_DATA_BUFF_ERR | \
DTD_STATUS_TRANSACTION_ERR)
#define TERMINATE (1 << 0)
#define STATUS_ACTIVE (1 << 7)
#define STATUS_HALTED (1 << 6)
#define STATUS_DATA_BUFF_ERR (1 << 5)
#define STATUS_TRANSACTION_ERR (1 << 4)
#define INTERRUPT_ON_COMPLETE (1 << 15)
#define LENGTH_BIT_POS (16)
#define ADDRESS_MASK (0xFFFFFFE0)
#define ERROR_MASK (DTD_STATUS_HALTED | \
DTD_STATUS_DATA_BUFF_ERR | \
DTD_STATUS_TRANSACTION_ERR)
#define RESERVED_FIELDS ((1 << 0) | (1 << 2) | (1 << 4) | \
(1 << 8) | (1 << 9) | (1 << 12)| \
(1 << 13)| (1 << 14)| (1 << 31))
#define RESERVED_FIELDS ((1 << 0) | (1 << 2) | (1 << 4) | \
(1 << 8) | (1 << 9) | (1 << 12)| \
(1 << 13)| (1 << 14)| (1 << 31))
/* Endpoint Queue Head Bit Masks */
#define EP_QUEUE_HEAD_MULT_POS (30)
#define EP_QUEUE_HEAD_ZLT_SEL (0x20000000)
#define EP_QUEUE_HEAD_MAX_PKT_LEN(ep_info) (((ep_info)>>16)&0x07ff)
#define EP_QUEUE_HEAD_MULTO (0x00000C00)
#define EP_QUEUE_CURRENT_OFFSET_MASK (0x00000FFF)
#define EP_QUEUE_FRINDEX_MASK (0x000007FF)
#define EP_MAX_LENGTH_TRANSFER (0x4000)
#define EP_QUEUE_HEAD_MULT_POS (30)
#define EP_QUEUE_HEAD_ZLT_SEL (0x20000000)
#define EP_QUEUE_HEAD_MAX_PKT_LEN(ep_info) (((ep_info)>>16)&0x07ff)
#define EP_QUEUE_HEAD_MULTO (0x00000C00)
#define EP_QUEUE_CURRENT_OFFSET_MASK (0x00000FFF)
#define EP_QUEUE_FRINDEX_MASK (0x000007FF)
#define EP_MAX_LENGTH_TRANSFER (0x4000)
/*-------------------------------------------------------------------------*/
@ -104,8 +104,10 @@ static const char* ep_name[] = {
/* Endpoint Transfer Descriptor data struct */
struct dtd {
uint32_t next_dtd; /* Next TD pointer(31-5), T(0) set indicate invalid */
uint32_t dtd_token; /* Total bytes (30-16), IOC (15), MultO(11-10), STS (7-0) */
uint32_t next_dtd; /* Next TD pointer(31-5),
T(0) set indicate invalid */
uint32_t dtd_token; /* Total bytes (30-16), IOC (15),
MultO(11-10), STS (7-0) */
uint32_t buf_ptr0; /* Buffer pointer Page 0 */
uint32_t buf_ptr1; /* Buffer pointer Page 1 */
uint32_t buf_ptr2; /* Buffer pointer Page 2 */
@ -146,7 +148,8 @@ void usb_arcotg_dcd_start(void);
void usb_arcotg_dcd_stop(void);
/* usb controller ops */
int usb_arcotg_dcd_enable(struct usb_ep* ep, struct usb_endpoint_descriptor* desc);
int usb_arcotg_dcd_enable(struct usb_ep* ep,
struct usb_endpoint_descriptor* desc);
int usb_arcotg_dcd_disable(struct usb_ep* ep);
int usb_arcotg_dcd_set_halt(struct usb_ep* ep, bool halt);
int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* request);
@ -160,10 +163,12 @@ static void suspend_int(void);
static void resume_int(void);
/* life cycle */
static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_type,
unsigned int max_pkt_len, unsigned int zlt, unsigned char mult);
static void qh_init(unsigned char ep_num, unsigned char dir,
unsigned char ep_type, unsigned int max_pkt_len,
unsigned int zlt, unsigned char mult);
static void td_init(struct dtd* td, void* buffer, uint32_t todo);
static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type);
static void ep_setup(unsigned char ep_num, unsigned char dir,
unsigned char ep_type);
/* helpers for tx/rx */
static int td_enqueue(struct dtd* td, struct dqh* qh, unsigned int mask);