some fixes from dfu branch

This commit is contained in:
Olaf Rempel 2008-02-04 01:51:29 +01:00
parent f7b1f465cc
commit 508ab7c94b
3 changed files with 38 additions and 38 deletions

View File

@ -26,7 +26,7 @@ CFLAGS += -nostdinc $(patsubst %,-I%,$(INCDIRS))
CFLAGS += -MD -MP -MF $(BUILD)/.dep/$(*F).d CFLAGS += -MD -MP -MF $(BUILD)/.dep/$(*F).d
CFLAGS += -Wall CFLAGS += -Wall
#CFLAGS += -Wextra #CFLAGS += -Wextra
#CFLAGS += -Wcast-align -Wimplicit -Wunused #CFLAGS += -Wcast-align -Wimplicit -Wunused
#CFLAGS += -Wpointer-arith -Wswitch #CFLAGS += -Wpointer-arith -Wswitch
#CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow #CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow
@ -50,7 +50,7 @@ all: $(BUILD)/$(TARGET).elf
$(BUILD)/$(TARGET).elf: $(patsubst %,$(BUILD)/%,$(AS_SRC:.s=.o) $(SRC:.c=.o)) $(BUILD)/$(TARGET).elf: $(patsubst %,$(BUILD)/%,$(AS_SRC:.s=.o) $(SRC:.c=.o))
@echo " Linking file: $@" @echo " Linking file: $@"
@$(shell mkdir -p $(BUILD)/$(*D)) @$(shell mkdir -p $(BUILD)/$(*D))
@$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null
@$(OBJCOPY) -O binary $@ $@.bin @$(OBJCOPY) -O binary $@ $@.bin
@$(OBJCOPY) -O ihex $@ $@.hex @$(OBJCOPY) -O ihex $@ $@.hex
@$(OBJDUMP) -h -S -C $@ > $@.lss @$(OBJDUMP) -h -S -C $@ > $@.lss

View File

@ -8,7 +8,8 @@
* - linux/include/linux/usb/ch9.h * - linux/include/linux/usb/ch9.h
* with minor modifications: * with minor modifications:
* - type conversion (e.g. __u8 -> uint8_t) * - type conversion (e.g. __u8 -> uint8_t)
* - usb_endpoint_descriptor: removed last 2 bytes * - usb_endpoint_descriptor: removed last 2 bytes
* - usb_string_descriptor: wData has no size
*/ */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
@ -258,7 +259,7 @@ struct usb_string_descriptor {
uint8_t bLength; uint8_t bLength;
uint8_t bDescriptorType; uint8_t bDescriptorType;
uint16_t wData[1]; /* UTF-16LE encoded */ uint16_t wData[]; /* UTF-16LE encoded */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* note that "string" zero is special, it holds language codes that /* note that "string" zero is special, it holds language codes that

View File

@ -39,11 +39,11 @@ struct udp_transfer {
uint16_t address; uint16_t address;
uint16_t maxpkt; uint16_t maxpkt;
// TODO: last bank used / ping pong // TODO: last bank used / ping pong
// TODO: direction (IN/OUT) // TODO: direction (IN/OUT)
uint16_t length; uint16_t length;
uint16_t curpos; uint16_t curpos;
char *data; char *data;
void (*complete_cb)(void); void (*complete_cb)(void);
// TODO: privdata? // TODO: privdata?
@ -183,7 +183,7 @@ static void udp_configure_ep(const struct usb_endpoint_descriptor *desc)
/* get endpoint type (ctrl, iso, bulb, int) */ /* get endpoint type (ctrl, iso, bulb, int) */
uint32_t eptype = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; uint32_t eptype = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
eptype |= 0x04; eptype |= 0x04;
/* get endpoint address, set Max Packet Size */ /* get endpoint address, set Max Packet Size */
uint32_t address = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; uint32_t address = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
@ -191,13 +191,13 @@ static void udp_configure_ep(const struct usb_endpoint_descriptor *desc)
/* configure UDP endpoint and enable interrupt */ /* configure UDP endpoint and enable interrupt */
AT91C_UDP_CSR[address] = AT91C_UDP_EPEDS | (eptype << 8); AT91C_UDP_CSR[address] = AT91C_UDP_EPEDS | (eptype << 8);
*AT91C_UDP_IER = (1 << address); *AT91C_UDP_IER = (1 << address);
} }
static void udp_fill_fifo(struct udp_transfer *trans) static void udp_fill_fifo(struct udp_transfer *trans)
{ {
uint16_t ep = trans->address; uint16_t ep = trans->address;
if (AT91C_UDP_CSR[ep] & AT91C_UDP_TXPKTRDY) { if (AT91C_UDP_CSR[ep] & AT91C_UDP_TXPKTRDY) {
printf("TX!RDY\n\r"); printf("TX!RDY\n\r");
return; return;
@ -212,7 +212,7 @@ static void udp_fill_fifo(struct udp_transfer *trans)
AT91C_UDP_CSR[ep] |= AT91C_UDP_TXPKTRDY; AT91C_UDP_CSR[ep] |= AT91C_UDP_TXPKTRDY;
} }
static void udp_send_data(struct udp_transfer *trans, const char *data, static void udp_send_data(struct udp_transfer *trans, const char *data,
uint32_t length, void (*complete_cb)(void)) uint32_t length, void (*complete_cb)(void))
{ {
if (trans->length != trans->curpos) { if (trans->length != trans->curpos) {
@ -239,7 +239,7 @@ static void udp_send_stall(uint32_t ep)
/* /*
* set local address * set local address
* (USB_REQ_SET_ADDRESS callback) * (USB_REQ_SET_ADDRESS callback)
*/ */
static void udp_txcb_setaddress(void) static void udp_txcb_setaddress(void)
{ {
*AT91C_UDP_FADDR = (AT91C_UDP_FEN | current_address); *AT91C_UDP_FADDR = (AT91C_UDP_FEN | current_address);
@ -249,7 +249,7 @@ static void udp_txcb_setaddress(void)
/* /*
* configure endpoints * configure endpoints
* (USB_REQ_SET_CONFIGURATION callback) * (USB_REQ_SET_CONFIGURATION callback)
*/ */
static void udp_txcb_setconfig(void) static void udp_txcb_setconfig(void)
{ {
udp_configure_ep(&cfg_descriptor.notify_ep); udp_configure_ep(&cfg_descriptor.notify_ep);
@ -262,14 +262,14 @@ static void udp_txcb_setconfig(void)
static void udp_txcb_setinterface(void) static void udp_txcb_setinterface(void)
{ {
printf("claim interface %d\n\r", current_interface); printf("claim interface %d\n\r", current_interface);
} }
static void udp_handle_ctrlrequest(struct usb_ctrlrequest *req) static void udp_handle_ctrlrequest(struct usb_ctrlrequest *req)
{ {
printf("typ:0x%02x req:0x%02x val:0x%04x idx:0x%04x len:0x%04x\n\r", printf("typ:0x%02x req:0x%02x val:0x%04x idx:0x%04x len:0x%04x\n\r",
req->bRequestType, req->bRequest, req->wValue, req->wIndex, req->wLength); req->bRequestType, req->bRequest, req->wValue, req->wIndex, req->wLength);
switch (req->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK)) { switch (req->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK)) {
case (USB_TYPE_STANDARD | USB_RECIP_DEVICE): /* 0x00/0x80 */ case (USB_TYPE_STANDARD | USB_RECIP_DEVICE): /* 0x00/0x80 */
switch (req->bRequest) { switch (req->bRequest) {
@ -277,7 +277,7 @@ static void udp_handle_ctrlrequest(struct usb_ctrlrequest *req)
current_address = req->wValue; current_address = req->wValue;
udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setaddress); udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setaddress);
break; break;
case USB_REQ_GET_DESCRIPTOR: /* 0x06 */ case USB_REQ_GET_DESCRIPTOR: /* 0x06 */
switch (req->wValue >> 8) { switch (req->wValue >> 8) {
case USB_DT_DEVICE: /* 0x01 */ case USB_DT_DEVICE: /* 0x01 */
@ -300,18 +300,18 @@ static void udp_handle_ctrlrequest(struct usb_ctrlrequest *req)
current_config = req->wValue; current_config = req->wValue;
udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setconfig); udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setconfig);
break; break;
default: default:
udp_send_stall(0); udp_send_stall(0);
break; break;
} }
break; break;
case (USB_TYPE_STANDARD | USB_RECIP_INTERFACE): /* 0x01/0x81 */ case (USB_TYPE_STANDARD | USB_RECIP_INTERFACE): /* 0x01/0x81 */
// TODO: follow current_interface // TODO: follow current_interface
switch (req->bRequest) { switch (req->bRequest) {
case USB_REQ_SET_INTERFACE: /* 0x0b */ case USB_REQ_SET_INTERFACE: /* 0x0b */
current_interface = req->wIndex; current_interface = req->wValue;
udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setinterface); udp_send_data(&ep_transfer[0], NULL, 0, udp_txcb_setinterface);
break; break;
@ -332,10 +332,9 @@ static void udp_handle_ctrlrequest(struct usb_ctrlrequest *req)
udp_send_data(&ep_transfer[0], (const char *)&dfu_status, udp_send_data(&ep_transfer[0], (const char *)&dfu_status,
MIN(sizeof(struct dfu_status), req->wLength), NULL); MIN(sizeof(struct dfu_status), req->wLength), NULL);
break; break;
case USB_CDC_REQ_SET_LINE_CODING: /* 0x20 */ case USB_CDC_REQ_SET_LINE_CODING: /* 0x20 */
// TODO: read 7 data bytes // TODO: read 7 data bytes
udp_send_data(&ep_transfer[0], NULL, 0, NULL);
break; break;
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: /* 0x22 */ case USB_CDC_REQ_SET_CONTROL_LINE_STATE: /* 0x22 */
@ -368,21 +367,21 @@ static void udp_handle_ep(uint32_t ep)
uint8_t *p; uint8_t *p;
for (p = (uint8_t *)&req; p < (uint8_t *)(&req +1); p++) for (p = (uint8_t *)&req; p < (uint8_t *)(&req +1); p++)
*p = AT91C_UDP_FDR[ep]; *p = AT91C_UDP_FDR[ep];
/* set data phase transfer direction */ /* set data phase transfer direction */
if (req.bRequestType & USB_DIR_IN) if (req.bRequestType & USB_DIR_IN)
*csr |= AT91C_UDP_DIR; *csr |= AT91C_UDP_DIR;
/* clear interrupt (THIS MUST USE csr_clear_flags()!) */ /* clear interrupt (THIS MUST USE csr_clear_flags()!) */
csr_clear_flags(*csr, AT91C_UDP_RXSETUP); csr_clear_flags(*csr, AT91C_UDP_RXSETUP);
udp_handle_ctrlrequest(&req); udp_handle_ctrlrequest(&req);
} }
/* transmit complete? */ /* transmit complete? */
if (*csr & AT91C_UDP_TXCOMP) { if (*csr & AT91C_UDP_TXCOMP) {
struct udp_transfer *trans = &ep_transfer[ep]; struct udp_transfer *trans = &ep_transfer[ep];
/* refill fifo, if transfer is incomplete */ /* refill fifo, if transfer is incomplete */
if (trans->length != trans->curpos) if (trans->length != trans->curpos)
udp_fill_fifo(trans); udp_fill_fifo(trans);
@ -390,7 +389,7 @@ static void udp_handle_ep(uint32_t ep)
/* execute callback when transfer is complete */ /* execute callback when transfer is complete */
else if (trans->complete_cb) else if (trans->complete_cb)
trans->complete_cb(); trans->complete_cb();
/* clear interrupt */ /* clear interrupt */
*csr &= ~(AT91C_UDP_TXCOMP); *csr &= ~(AT91C_UDP_TXCOMP);
} }
@ -398,7 +397,7 @@ static void udp_handle_ep(uint32_t ep)
/* clear STALLSENT interrupt */ /* clear STALLSENT interrupt */
if (*csr & AT91C_UDP_STALLSENT) if (*csr & AT91C_UDP_STALLSENT)
csr_clear_flags(*csr, (AT91C_UDP_STALLSENT | AT91C_UDP_FORCESTALL)); csr_clear_flags(*csr, (AT91C_UDP_STALLSENT | AT91C_UDP_FORCESTALL));
/* data ready to read? */ /* data ready to read? */
if (*csr & (AT91C_UDP_RX_DATA_BK0 | AT91C_UDP_RX_DATA_BK1)) { if (*csr & (AT91C_UDP_RX_DATA_BK0 | AT91C_UDP_RX_DATA_BK1)) {
uint16_t len = (*csr & AT91C_UDP_RXBYTECNT) >> 16; uint16_t len = (*csr & AT91C_UDP_RXBYTECNT) >> 16;
@ -406,14 +405,14 @@ static void udp_handle_ep(uint32_t ep)
printf("rx: "); printf("rx: ");
while (len--) while (len--)
printf("0x%02x ", AT91C_UDP_FDR[ep]); printf("0x%02x ", AT91C_UDP_FDR[ep]);
printf("\n\r"); printf("\n\r");
} else { } else {
/* clear a pending transfer! */ /* clear a pending transfer! */
ep_transfer[ep].length = 0; ep_transfer[ep].length = 0;
ep_transfer[ep].curpos = 0; ep_transfer[ep].curpos = 0;
} }
/* TODO: ping pong FIFOs */ /* TODO: ping pong FIFOs */
if (*csr & AT91C_UDP_RX_DATA_BK0) if (*csr & AT91C_UDP_RX_DATA_BK0)
@ -430,9 +429,9 @@ static void udp_isr(void)
if (isr & AT91C_UDP_ENDBUSRES) { if (isr & AT91C_UDP_ENDBUSRES) {
printf("usb reset\n\r"); printf("usb reset\n\r");
AT91S_UDP *udp = AT91C_BASE_UDP; AT91S_UDP *udp = AT91C_BASE_UDP;
/* reset all endpoints */ /* reset all endpoints */
udp->UDP_RSTEP = (AT91C_UDP_EP0 | AT91C_UDP_EP1 | udp->UDP_RSTEP = (AT91C_UDP_EP0 | AT91C_UDP_EP1 |
AT91C_UDP_EP2 | AT91C_UDP_EP3) ; AT91C_UDP_EP2 | AT91C_UDP_EP3) ;
@ -447,7 +446,7 @@ static void udp_isr(void)
ep_transfer[i].curpos = 0; ep_transfer[i].curpos = 0;
} }
ep_transfer[0].maxpkt = 8; ep_transfer[0].maxpkt = 8;
/* Configure endpoint0 as Control EP */ /* Configure endpoint0 as Control EP */
udp->UDP_CSR[0] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL); udp->UDP_CSR[0] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL);
@ -457,7 +456,7 @@ static void udp_isr(void)
AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_SOFINT | AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_SOFINT |
AT91C_UDP_WAKEUP; AT91C_UDP_WAKEUP;
} }
/* Handle Endpoint Interrupts */ /* Handle Endpoint Interrupts */
uint32_t i; uint32_t i;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -466,7 +465,7 @@ static void udp_isr(void)
} }
/* clear all unhandled interrupts */ /* clear all unhandled interrupts */
*AT91C_UDP_ICR = isr & (AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | *AT91C_UDP_ICR = isr & (AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM |
AT91C_UDP_ENDBUSRES | AT91C_UDP_WAKEUP); AT91C_UDP_ENDBUSRES | AT91C_UDP_WAKEUP);
} }
@ -479,7 +478,7 @@ void at91_udp_init(void)
pio->PIO_OER = UDP_PULLUP; pio->PIO_OER = UDP_PULLUP;
// TODO: needed? // TODO: needed?
pio->PIO_PPUDR = UDP_VBUS_MON; pio->PIO_PPUDR = UDP_VBUS_MON;
/* UDPCK (48MHz) = PLLCK / 2 */ /* UDPCK (48MHz) = PLLCK / 2 */
*AT91C_CKGR_PLLR |= AT91C_CKGR_USBDIV_1; *AT91C_CKGR_PLLR |= AT91C_CKGR_USBDIV_1;
@ -494,7 +493,7 @@ void at91_udp_init(void)
*AT91C_UDP_IDR = AT91C_UDP_EPINT0 | AT91C_UDP_EPINT1 | AT91C_UDP_EPINT2 | *AT91C_UDP_IDR = AT91C_UDP_EPINT0 | AT91C_UDP_EPINT1 | AT91C_UDP_EPINT2 |
AT91C_UDP_EPINT3 | AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_EPINT3 | AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM |
AT91C_UDP_SOFINT | AT91C_UDP_WAKEUP; AT91C_UDP_SOFINT | AT91C_UDP_WAKEUP;
*AT91C_UDP_ICR = AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_SOFINT | *AT91C_UDP_ICR = AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_SOFINT |
AT91C_UDP_ENDBUSRES | AT91C_UDP_WAKEUP ; AT91C_UDP_ENDBUSRES | AT91C_UDP_WAKEUP ;
@ -503,7 +502,7 @@ void at91_udp_init(void)
aic->AIC_SMR[AT91C_ID_UDP] = IRQPRIO_UDP | AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL; aic->AIC_SMR[AT91C_ID_UDP] = IRQPRIO_UDP | AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL;
aic->AIC_SVR[AT91C_ID_UDP] = (uint32_t)udp_isr; aic->AIC_SVR[AT91C_ID_UDP] = (uint32_t)udp_isr;
aic->AIC_IECR = (1 << AT91C_ID_UDP); aic->AIC_IECR = (1 << AT91C_ID_UDP);
pio_trigger_isr(UDP_VBUS_MON); pio_trigger_isr(UDP_VBUS_MON);
} }