From 28eb4a57d93f2cf13d3693ce4dba677f22cbf1cc Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 15 Oct 2006 20:21:40 +0000 Subject: - add svn:ignore property to make 'svn st' output more realistic - remove old copy+paste+edit port of parts of librfid - add ability to directly link librfid.a from mainline librfid - make usb string descriptors optional again (config.h) - fix TC_CDIV to reset correctly on swtrig (For OpenPICC) - temporarily re-implement ep0_send_data() in pcd_enumerate.c - make UDP_PUPv4 switching conditional to PCD - introduce DEBUG_UNBUFFERED define in dbgu.c - fix some signed/unsigned/typecast related compiler warnings - remove dead code from src/os/led.c - implement a 'mdelay' and 'usleep' stub function (FIXME!) - rename rc632_... functions into opcd_rc632_... to avoid confusion - introduce new 'main_librfid' TARGET - make main_{reqa,analog} work with librfid rather than old code - introduce mroe debugging options for FIQ handler code in Cstartup_app - lots of PICC work that doesn't need comments now git-svn-id: https://svn.openpcd.org:2342/trunk@266 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/src/os/dbgu.c | 8 +++- firmware/src/os/led.c | 10 ----- firmware/src/os/pcd_enumerate.c | 94 +++++++++++++++++++++++++++++++++++------ firmware/src/os/pio_irq.c | 4 +- firmware/src/os/pit.c | 12 +++++- firmware/src/os/pwm.c | 2 +- firmware/src/os/req_ctx.c | 2 +- firmware/src/os/req_ctx.h | 2 + firmware/src/os/syscalls.c | 2 +- firmware/src/os/tc_cdiv.c | 2 +- firmware/src/os/usb_benchmark.c | 17 -------- 11 files changed, 107 insertions(+), 48 deletions(-) (limited to 'firmware/src/os') diff --git a/firmware/src/os/dbgu.c b/firmware/src/os/dbgu.c index e71b62e..32432a3 100644 --- a/firmware/src/os/dbgu.c +++ b/firmware/src/os/dbgu.c @@ -41,9 +41,12 @@ #include #include #include +#include #include #include +//#define DEBUG_UNBUFFERED + #define USART_SYS_LEVEL 4 /*---------------------------- Global Variable ------------------------------*/ //*--------------------------1-------------------------------------------------- @@ -324,8 +327,11 @@ void debugp(const char *format, ...) dbg_buf[sizeof(dbg_buf)-1] = '\0'; //AT91F_DBGU_Frame(dbg_buf); - //AT91F_DBGU_Printk(dbg_buf); +#ifdef DEBUG_UNBUFFERED + AT91F_DBGU_Printk(dbg_buf); +#else dbgu_rb_append(dbg_buf, strlen(dbg_buf)); +#endif } #else void dbgu_rb_flush(void) {} diff --git a/firmware/src/os/led.c b/firmware/src/os/led.c index 2a57558..fbe3f58 100644 --- a/firmware/src/os/led.c +++ b/firmware/src/os/led.c @@ -31,16 +31,6 @@ static const int ledport[] = { [2] = OPENPCD_PIO_LED2, }; -static int led2port(int led) -{ - if (led == 1) - return OPENPCD_PIO_LED1; - else if (led == 2) - return OPENPCD_PIO_LED2; - else - return 0; -} - void led_switch(int led, int on) { int port; diff --git a/firmware/src/os/pcd_enumerate.c b/firmware/src/os/pcd_enumerate.c index f201a32..6c45af6 100644 --- a/firmware/src/os/pcd_enumerate.c +++ b/firmware/src/os/pcd_enumerate.c @@ -42,6 +42,8 @@ #include "../openpcd.h" #include +#include "../config.h" + //#define DEBUG_UDP_IRQ //#define DEBUG_UDP_IRQ_IN //#define DEBUG_UDP_IRQ_OUT @@ -65,13 +67,18 @@ #define DEBUGIO(x, args ...) do { } while (0) #endif +#ifdef DEBUG_UDP_EP0 +#define DEBUGE(x, args ...) DEBUGP(x, ## args) +#else +#define DEBUGE(x, args ...) do { } while (0) +#endif #define CONFIG_DFU #ifdef CONFIG_DFU static const struct dfuapi *dfu = DFU_API_LOCATION; #define udp_init dfu->udp_init -#define udp_ep0_send_data dfu->ep0_send_data +//#define udp_ep0_send_data dfu->ep0_send_data #define udp_ep0_send_zlp dfu->ep0_send_zlp #define udp_ep0_send_stall dfu->ep0_send_stall #else @@ -83,7 +90,7 @@ static struct udp_pcd upcd; const struct usb_device_descriptor dev_descriptor = { .bLength = USB_DT_DEVICE_SIZE, .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, + .bcdUSB = 0x0100, .bDeviceClass = USB_CLASS_VENDOR_SPEC, .bDeviceSubClass = 0xff, .bDeviceProtocol = 0xff, @@ -91,9 +98,15 @@ const struct usb_device_descriptor dev_descriptor = { .idVendor = USB_VENDOR_ID, .idProduct = USB_PRODUCT_ID, .bcdDevice = 0x0030, /* Version 0.3 */ +#ifdef CONFIG_USB_STRING .iManufacturer = 3, .iProduct = 4, - .iSerialNumber = 0x00, + .iSerialNumber = 0, +#else + .iManufacturer = 0, + .iProduct = 0, + .iSerialNumber = 0, +#endif .bNumConfigurations = 0x01, }; @@ -121,7 +134,11 @@ const struct _desc cfg_descriptor = { .bNumInterfaces = 1, #endif .bConfigurationValue = 1, +#ifdef CONFIG_USB_STRING .iConfiguration = 5, +#else + .iConfiguration = 0, +#endif .bmAttributes = USB_CONFIG_ATT_ONE, .bMaxPower = 250, /* 500mA */ }, @@ -134,7 +151,11 @@ const struct _desc cfg_descriptor = { .bInterfaceClass = USB_CLASS_VENDOR_SPEC, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0xff, +#ifdef CONFIG_SB_STRING .iInterface = 6, +#else + .iInterface = 0, +#endif }, .ep= { { @@ -179,6 +200,53 @@ static const struct epstate epstate[] = { .state_pending = RCTX_STATE_UDP_EP3_PENDING }, }; +/* Send Data through the control endpoint */ +static void udp_ep0_send_data(const char *pData, u_int32_t length) +{ + AT91PS_UDP pUdp = AT91C_BASE_UDP; + u_int32_t cpt = 0; + AT91_REG csr; + + DEBUGE("send_data: %u bytes ", length); + + do { + cpt = MIN(length, 8); + length -= cpt; + + DEBUGE("fifo_fill "); + while (cpt--) + pUdp->UDP_FDR[0] = *pData++; + + if (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) { + DEBUGE("wait_txcomp_clear "); + pUdp->UDP_CSR[0] &= ~(AT91C_UDP_TXCOMP); + while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) ; + } + + DEBUGE("set_txpktrdy "); + pUdp->UDP_CSR[0] |= AT91C_UDP_TXPKTRDY; + DEBUGE("wait_txcomp "); + do { + csr = pUdp->UDP_CSR[0]; + + /* Data IN stage has been stopped by a status OUT */ + if (csr & AT91C_UDP_RX_DATA_BK0) { + pUdp->UDP_CSR[0] &= ~(AT91C_UDP_RX_DATA_BK0); + DEBUGE("stopped by status out "); + return; + } + } while (!(csr & AT91C_UDP_TXCOMP)); + + } while (length); + + DEBUGE("clear_txcomp "); + if (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) { + pUdp->UDP_CSR[0] &= ~(AT91C_UDP_TXCOMP); + while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) ; + } + DEBUGE("done "); +} + static void reset_ep(unsigned int ep) { AT91PS_UDP pUDP = upcd.pUdp; @@ -490,13 +558,17 @@ out: void udp_pullup_on(void) { AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); +#ifdef PCD AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); +#endif } void udp_pullup_off(void) { AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); +#ifdef PCD AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); +#endif } /* Open USB Device Port */ @@ -519,8 +591,6 @@ void udp_open(void) /* End-of-Bus-Reset is always enabled */ /* Set the Pull up resistor */ - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); - AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); udp_pullup_on(); } @@ -534,12 +604,6 @@ void udp_reset(void) udp_pullup_on(); } -#ifdef DEBUG_UDP_EP0 -#define DEBUGE(x, args ...) DEBUGP(x, ## args) -#else -#define DEBUGE(x, args ...) do { } while (0) -#endif - /* Handle requests on the USB Control Endpoint */ static void udp_ep0_handler(void) { @@ -628,6 +692,7 @@ static void udp_ep0_handler(void) MIN(sizeof(cfg_descriptor), wLength)); break; case USB_DT_STRING: +#ifdef CONFIG_USB_STRING /* Return String descriptor */ if (desc_index > ARRAY_SIZE(usb_strings)) goto out_stall; @@ -636,6 +701,9 @@ static void udp_ep0_handler(void) udp_ep0_send_data((const char *) usb_strings[desc_index], MIN(usb_strings[desc_index]->bLength, wLength)); +#else + goto out_stall; +#endif break; case USB_DT_CS_DEVICE: /* Return Function descriptor */ @@ -852,8 +920,8 @@ static void udp_ep0_handler(void) upcd.cur_interface = wIndex; upcd.cur_altsett = wValue; /* USB spec mandates that if we only support one altsetting in - * the given interface, we shall respond with STALL in the status - * stage */ + * the given interface, we shall respond with STALL in the + * status stage */ udp_ep0_send_stall(); break; default: diff --git a/firmware/src/os/pio_irq.c b/firmware/src/os/pio_irq.c index 4e94350..5fb777a 100644 --- a/firmware/src/os/pio_irq.c +++ b/firmware/src/os/pio_irq.c @@ -35,14 +35,14 @@ static struct pioirq_state pirqs; /* low-level handler, used by Cstartup_app.S PIOA fast forcing and * by regular interrupt handler below */ -void __pio_irq_demux(u_int32_t pio) +void __ramfunc __pio_irq_demux(u_int32_t pio) { u_int8_t send_usb = 0; int i; DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio); - for (i = 0; i < NR_PIO; i++) { + for (i = 27; i < NR_PIO; i++) { if (pio & (1 << i) && pirqs.handlers[i]) pirqs.handlers[i](i); if (pirqs.usbmask & (1 << i)) diff --git a/firmware/src/os/pit.c b/firmware/src/os/pit.c index 6b68e84..50ec19f 100644 --- a/firmware/src/os/pit.c +++ b/firmware/src/os/pit.c @@ -106,7 +106,6 @@ void timer_add(struct timer_list *tl) static void pit_irq(u_int32_t sr) { struct timer_list *tl, *next; - unsigned long flags; if (!(sr & 0x1)) return; @@ -135,6 +134,17 @@ void pit_mdelay(u_int32_t ms) while (end < AT91F_PITGetPIIR(AT91C_BASE_PITC)) { } } +void mdelay(u_int32_t ms) +{ + return pit_mdelay(ms); +} + +void usleep(u_int32_t us) +{ + return; + return pit_mdelay(us/1000); +} + void pit_init(void) { AT91F_PITC_CfgPMC(); diff --git a/firmware/src/os/pwm.c b/firmware/src/os/pwm.c index 285f4e7..70858bb 100644 --- a/firmware/src/os/pwm.c +++ b/firmware/src/os/pwm.c @@ -138,7 +138,7 @@ static int pwm_usb_in(struct req_ctx *rctx) case OPENPCD_CMD_PWM_FREQ_SET: if (rctx->tot_len < sizeof(*poh)+4) break; - freq = (unsigned char *) poh + sizeof(*poh); + freq = (u_int32_t *) ((unsigned char *) poh) + sizeof(*poh); pwm_freq_set(0, *freq); break; case OPENPCD_CMD_PWM_FREQ_GET: diff --git a/firmware/src/os/req_ctx.c b/firmware/src/os/req_ctx.c index d03fcd1..36c3059 100644 --- a/firmware/src/os/req_ctx.c +++ b/firmware/src/os/req_ctx.c @@ -50,7 +50,7 @@ struct req_ctx __ramfunc *req_ctx_find_get(int large, else i = 0; - for (1; i < NUM_REQ_CTX; i++) { + for (; i < NUM_REQ_CTX; i++) { local_irq_save(flags); if (req_ctx[i].state == old_state) { req_ctx[i].state = new_state; diff --git a/firmware/src/os/req_ctx.h b/firmware/src/os/req_ctx.h index 2df8497..ac9ab3f 100644 --- a/firmware/src/os/req_ctx.h +++ b/firmware/src/os/req_ctx.h @@ -34,6 +34,8 @@ struct req_ctx { #define RCTX_STATE_SSC_RX_BUSY 0x20 +#define RCTX_STATE_LIBRFID_BUSY 0x30 + #define RCTX_STATE_PIOIRQ_BUSY 0x80 #define RCTX_STATE_INVALID 0xff diff --git a/firmware/src/os/syscalls.c b/firmware/src/os/syscalls.c index ed989f1..18f755a 100644 --- a/firmware/src/os/syscalls.c +++ b/firmware/src/os/syscalls.c @@ -40,7 +40,7 @@ _ssize_t _read_r( size_t len) { char c; - int i; + unsigned int i; unsigned char *p; p = (unsigned char*)ptr; diff --git a/firmware/src/os/tc_cdiv.c b/firmware/src/os/tc_cdiv.c index 99a0975..6f06ba5 100644 --- a/firmware/src/os/tc_cdiv.c +++ b/firmware/src/os/tc_cdiv.c @@ -80,7 +80,7 @@ void tc_cdiv_init(void) AT91C_TC_ACPA_SET | AT91C_TC_ACPC_CLEAR | AT91C_TC_BEEVT_SET | AT91C_TC_BCPB_CLEAR | AT91C_TC_EEVT_XC2 | AT91C_TC_ETRGEDG_RISING | - AT91C_TC_BSWTRG_CLEAR; /* clear on swtrg */ + AT91C_TC_BSWTRG_CLEAR | AT91C_TC_ASWTRG_CLEAR; tc_cdiv_set_divider(128); diff --git a/firmware/src/os/usb_benchmark.c b/firmware/src/os/usb_benchmark.c index 967efbb..2802d90 100644 --- a/firmware/src/os/usb_benchmark.c +++ b/firmware/src/os/usb_benchmark.c @@ -30,23 +30,6 @@ static struct req_ctx dummy_rctx; static struct req_ctx empty_rctx; -static void usbtest_tx_transfer(unsigned int num_pkts) -{ - unsigned int i; - -#if 0 -#warning please reimplement refill userspecified rctx - for (i = 0; i < num_pkts; i++) { - /* send 16 packets of 64byte */ - while (udp_refill_ep(2, &dummy_rctx) < 0) - ; - } - /* send one packet of 0 byte */ - while (udp_refill_ep(2, &empty_rctx) < 0) - ; -#endif -} - static int usbtest_rx(struct req_ctx *rctx) { struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data; -- cgit v1.2.3